aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2017-03-08 22:05:43 -0500
committerPaul Gilbert2017-03-08 22:05:43 -0500
commitfaaaab9d891735c8aa9a90a9df650210187aea48 (patch)
tree4630e8d165bdf384a9a5df4f7b53a9905f4422d5 /engines
parent65ef0c8ff84588962a32ddc2df2e1de17325d0a5 (diff)
downloadscummvm-rg350-faaaab9d891735c8aa9a90a9df650210187aea48.tar.gz
scummvm-rg350-faaaab9d891735c8aa9a90a9df650210187aea48.tar.bz2
scummvm-rg350-faaaab9d891735c8aa9a90a9df650210187aea48.zip
TITANIC: In progress code for CStarControlSub5 class
Diffstat (limited to 'engines')
-rw-r--r--engines/titanic/star_control/base_star.cpp2
-rw-r--r--engines/titanic/star_control/fvector.h7
-rw-r--r--engines/titanic/star_control/star_control_sub5.cpp128
-rw-r--r--engines/titanic/star_control/star_control_sub5.h50
-rw-r--r--engines/titanic/star_control/star_control_sub6.cpp12
-rw-r--r--engines/titanic/star_control/star_control_sub6.h4
-rw-r--r--engines/titanic/star_control/star_control_sub8.cpp4
-rw-r--r--engines/titanic/star_control/star_control_sub8.h2
8 files changed, 152 insertions, 57 deletions
diff --git a/engines/titanic/star_control/base_star.cpp b/engines/titanic/star_control/base_star.cpp
index df25f91897..e68d3cf9a6 100644
--- a/engines/titanic/star_control/base_star.cpp
+++ b/engines/titanic/star_control/base_star.cpp
@@ -164,7 +164,7 @@ void CBaseStar::draw1(CSurfaceArea *surfaceArea, CStarControlSub12 *sub12, CStar
CBaseStarEntry &entry = _data[idx];
vector = entry._position;
v4 = vector._x * sub6._row1._z + vector._y * sub6._row2._z
- + vector._z * sub6._row3._z + sub6._field2C;
+ + vector._z * sub6._row3._z + sub6._vector._z;
if (v4 <= minVal)
continue;
diff --git a/engines/titanic/star_control/fvector.h b/engines/titanic/star_control/fvector.h
index b85cbb1e65..e19419bf20 100644
--- a/engines/titanic/star_control/fvector.h
+++ b/engines/titanic/star_control/fvector.h
@@ -40,6 +40,13 @@ public:
FVector() : _x(0), _y(0), _z(0) {}
FVector(double x, double y, double z) : _x(x), _y(y), _z(z) {}
+ /**
+ * Clears the vector
+ */
+ void clear() {
+ _x = _y = _z = 0.0;
+ }
+
void fn1(FVector *v);
void multiply(FVector *dest, const FVector *src);
void fn3();
diff --git a/engines/titanic/star_control/star_control_sub5.cpp b/engines/titanic/star_control/star_control_sub5.cpp
index 4b2ff79ef5..5023a59383 100644
--- a/engines/titanic/star_control/star_control_sub5.cpp
+++ b/engines/titanic/star_control/star_control_sub5.cpp
@@ -27,35 +27,25 @@
namespace Titanic {
void CStarControlSub5::SubEntry::clear() {
- if (_data2P) {
- delete[] _data2P;
- _data2P = nullptr;
- _field4 = 0;
- }
-
- if (_data1P) {
- delete[] _data1P;
- _data1P = nullptr;
- _field0 = 0;
- }
+ _data1.clear();
+ _data2.clear();
}
/*------------------------------------------------------------------------*/
-bool CStarControlSub5::MemoryBlock::allocate() {
- // TODO
+bool CStarControlSub5::SineTable::setup() {
+ if (_data.empty()) {
+ _data.resize(1024);
+ for (int idx = 0; idx < 1024; ++idx)
+ _data[idx] = sin((double)idx * 6.283185307179586 * 0.001953125);
+ }
+
return true;
}
/*------------------------------------------------------------------------*/
-CStarControlSub5::CStarControlSub5() : _flag(true), _dataP(nullptr),
- _field78B0(0) {
-}
-
-CStarControlSub5::~CStarControlSub5() {
- delete[] _dataP;
- _dataP = nullptr;
+CStarControlSub5::CStarControlSub5() : _flag(true), _multiplier(0) {
}
bool CStarControlSub5::setup() {
@@ -73,7 +63,7 @@ bool CStarControlSub5::setup() {
bool CStarControlSub5::setup2(int val1, int val2) {
// TODO: Original set an explicit random seed here. Could be
// problematic if following random values need to be deterministic
- double FACTOR = 3.1415927 * 0.0055555557;
+ const double FACTOR = 3.1415927 * 0.0055555557;
const int VALUES1[] = { 0x800, 0xC00, 0x1000, 0x1400, 0x1800 };
const int VALUES2[] = {
0xF95BCD, 0xA505A0, 0xFFAD43, 0x98F4EB, 0xF3EFA5, 0,
@@ -191,8 +181,8 @@ bool CStarControlSub5::setup2(int val1, int val2) {
}
}
- if (_memoryBlock.allocate()) {
- _dataP = new byte[((val2 - 2) * val1 + 2) * 24];
+ if (_sineTable.setup()) {
+ _grid.resize((val2 - 2) * val1 + 2);
return true;
}
@@ -201,11 +191,66 @@ bool CStarControlSub5::setup2(int val1, int val2) {
void CStarControlSub5::proc2(CStarControlSub6 *sub6, FVector *vector, double v1, double v2, double v3,
CSurfaceArea *surfaceArea, CStarControlSub12 *sub12) {
+ const int VALUES[] = { 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4 };
+ double val1 = sub12->proc25();
+ int val2 = sub12->proc27();
+
+ if (v3 >= 6.0e9) {
+ int count, start;
+ if (vector->_x != 0.0 && (vector->_y != 0.0 || vector->_z != 0.0)) {
+ // TODO: Non-sensical randSeed((int)vector->_x);
+ count = VALUES[g_vm->getRandomNumber(15)];
+ start = g_vm->getRandomNumber(255);
+ } else {
+ count = 9;
+ start = 0;
+ }
+
+ Entry *entryP = &_entries[start];
+ for (; count > 0; --count, ++entryP) {
+ //eax=sineIndex1, ecx=sineIndex2,
+ int sineIndex1 = (entryP->_field8 * _multiplier) & 0x1ff;
+ int sineIndex2 = (entryP->_fieldC * _multiplier + entryP->_fieldC) & 0x1ff;
+
+ double t1 = _sineTable[sineIndex2];
+ double t2 = sin(_sineTable[sineIndex1] * entryP->_field10);
+ double t3 = cos(_sineTable[sineIndex1] * entryP->_field10);
+ double t4 = _sineTable[sineIndex2 + 512];
+ double t5 = t3 * t4;
+ t3 = t3 * t1;
+ double t6 = entryP->_field14 * t5;
+ double t7 = t2 * entryP->_field14;
+ double t8 = entryP->_field14 * t3;
+ double t9 = -(t2 * t4 * entryP->_field14);
+ double t10 = t3 * entryP->_field14;
+ double t11 = -(t2 * t1 * entryP->_field14);
+ t4 = -(t1 * entryP->_field14);
+ t1 = t4 * entryP->_field14;
+
+ _sub1._row1._x = t6;
+ _sub1._row1._y = t2 * entryP->_field14;
+ _sub1._row1._z = entryP->_field14 * t3;
+ _sub1._row2._x = -(t2 * t4 * entryP->_field14);
+ _sub1._row2._y = t3 * entryP->_field14;
+ _sub1._row2._z = -(t2 * t1 * entryP->_field14);
+ _sub1._row3._x = -(t1 * entryP->_field14);
+ _sub1._row3._z = t4 * entryP->_field14;
+
+ double t12 = entryP->_field0;
+ _sub1._vector._x = t12 * t5 + vector->_x;
+ _sub1._vector._y = t12 * t2 + vector->_y;
+ _sub1._vector._z = t12 * t3 + vector->_z;
+
+ // TODO
+ warning("TODO: %f %f %f %f %f %f %d", t7, t8, t9, t10, t11, val1, val2);
+ }
+ }
+
// TODO
}
void CStarControlSub5::proc3(CErrorCode *errorCode) {
- ++_field78B0;
+ ++_multiplier;
errorCode->set();
}
@@ -213,8 +258,41 @@ void CStarControlSub5::fn1() {
_flag = !_flag;
}
-bool CStarControlSub5::setupEntry(int val1, int val2, int index, double val3) {
+bool CStarControlSub5::setupEntry(int width, int height, int index, double val) {
+ /*
+ if (width < 2 || height < 3)
+ return false;
+
+ SubEntry &entry = _array[index];
+ entry.clear();
+
+ int height2 = height - 2;
+ int height1 = height - 1;
+ entry._data1.resize((2 * height - 3) * width);
+ entry._data2.resize(width * height2 + 2);
+ entry._data2[0] = FVector(0.0, val, 0.0);
+
+ index = 1;
+ double vy = 180.0 / (double)height1;
+ double vx = 360.0 / (double)width;
+ const double FACTOR = 3.1415927 * 0.0055555557;
+
+ if (height1 > 1) {
+ double yAmount = vy;
+ int width12 = width * 12;
+ for (int yCtr = height1 - 1; yCtr > 0; --yCtr, yAmount += vy) {
+ double sineVal = sin(yAmount * FACTOR);
+
+
+ | 0.0 * FACTOR |
+ | cos(yAmount * FACTOR) * val |
+ | 0.0 |
+ |yAmount|
+ }
+ }
// TODO
+
+ */
return true;
}
diff --git a/engines/titanic/star_control/star_control_sub5.h b/engines/titanic/star_control/star_control_sub5.h
index 17f339994d..2636d6dda2 100644
--- a/engines/titanic/star_control/star_control_sub5.h
+++ b/engines/titanic/star_control/star_control_sub5.h
@@ -23,6 +23,7 @@
#ifndef TITANIC_STAR_CONTROL_SUB5_H
#define TITANIC_STAR_CONTROL_SUB5_H
+#include "common/array.h"
#include "titanic/star_control/star_control_sub6.h"
#include "titanic/star_control/error_code.h"
#include "titanic/star_control/surface_area.h"
@@ -33,11 +34,8 @@ class CStarControlSub12;
class CStarControlSub5 {
struct SubEntry {
- int _field0;
- int _field4;
- byte *_data1P;
- byte *_data2P;
- SubEntry() : _field0(0), _field4(0), _data1P(nullptr), _data2P(nullptr) {}
+ Common::Array<FPoint> _data1;
+ Common::Array<FVector> _data2;
~SubEntry() { clear(); }
/**
@@ -61,32 +59,51 @@ class CStarControlSub5 {
_fieldC(0), _field10(0), _field14(0), _field15(0) {}
};
- struct MemoryBlock {
- public:
- byte *_ptr;
+ struct GridEntry {
+ int _field0;
+ int _field4;
+ int _field8;
+ int _fieldC;
+ int _field10;
+ int _field14;
+
+ GridEntry() : _field0(0), _field4(0), _field8(0), _fieldC(0),
+ _field10(0), _field14(0) {}
+ };
+
+ /**
+ * Maintains a pre-calculated table of sine values
+ */
+ struct SineTable {
+ private:
+ Common::Array<double> _data;
public:
- MemoryBlock() : _ptr(nullptr) {}
- ~MemoryBlock() { delete[] _ptr; }
+ SineTable() {}
+
+ /**
+ * Sets up the table
+ */
+ bool setup();
/**
- * Allocates the memory block
+ * Get a value
*/
- bool allocate();
+ double operator[](int idx) { return _data[idx]; }
};
private:
bool _flag;
CStarControlSub6 _sub1, _sub2;
SubEntry _array[5];
Entry _entries[1284];
- int _field78B0;
- MemoryBlock _memoryBlock;
- byte *_dataP;
+ int _multiplier;
+ SineTable _sineTable;
+ Common::Array<GridEntry> _grid;
private:
/**
* Sets up the data for an array entry
* @return True if success
*/
- bool setupEntry(int val1, int val2, int index, double val3);
+ bool setupEntry(int width, int height, int index, double val);
/**
* Secondary setup method
@@ -95,7 +112,6 @@ private:
bool setup2(int val1, int val2);
public:
CStarControlSub5();
- virtual ~CStarControlSub5();
virtual bool setup();
virtual void proc2(CStarControlSub6 *sub6, FVector *vector, double v1, double v2, double v3,
diff --git a/engines/titanic/star_control/star_control_sub6.cpp b/engines/titanic/star_control/star_control_sub6.cpp
index 97eb5971ef..925f93330b 100644
--- a/engines/titanic/star_control/star_control_sub6.cpp
+++ b/engines/titanic/star_control/star_control_sub6.cpp
@@ -49,9 +49,7 @@ void CStarControlSub6::deinit() {
void CStarControlSub6::clear() {
FMatrix::clear();
- _field24 = 0;
- _field28 = 0;
- _field2C = 0;
+ _vector.clear();
}
void CStarControlSub6::set(int mode, double amount) {
@@ -100,18 +98,14 @@ void CStarControlSub6::set(int mode, double amount) {
break;
}
- _field24 = 0.0;
- _field28 = 0.0;
- _field2C = 0.0;
+ _vector.clear();
}
void CStarControlSub6::copyFrom(const CStarControlSub6 *src) {
_row1 = src->_row1;
_row2 = src->_row2;
_row3 = src->_row3;
- _field24 = src->_field24;
- _field28 = src->_field28;
- _field2C = src->_field2C;
+ _vector = src->_vector;
}
} // End of namespace Titanic
diff --git a/engines/titanic/star_control/star_control_sub6.h b/engines/titanic/star_control/star_control_sub6.h
index 645eb45c00..06d0c2ece7 100644
--- a/engines/titanic/star_control/star_control_sub6.h
+++ b/engines/titanic/star_control/star_control_sub6.h
@@ -34,9 +34,7 @@ public:
static void init();
static void deinit();
public:
- int _field24;
- int _field28;
- int _field2C;
+ FVector _vector;
public:
CStarControlSub6();
CStarControlSub6(int mode, double amount);
diff --git a/engines/titanic/star_control/star_control_sub8.cpp b/engines/titanic/star_control/star_control_sub8.cpp
index 5840c9670e..50c90d2bc1 100644
--- a/engines/titanic/star_control/star_control_sub8.cpp
+++ b/engines/titanic/star_control/star_control_sub8.cpp
@@ -27,9 +27,9 @@
namespace Titanic {
-CStarControlSub8::CStarControlSub8() : _field8(-1) {
+CStarControlSub8::CStarControlSub8() : _field8(-1), _fieldC(-1) {
#if 0
- _field4(0), _field8(-1), _fieldC(-1)
+ _field4(0), _field8(-1)
#endif
}
diff --git a/engines/titanic/star_control/star_control_sub8.h b/engines/titanic/star_control/star_control_sub8.h
index 97409fd059..f7f8ba4fb5 100644
--- a/engines/titanic/star_control/star_control_sub8.h
+++ b/engines/titanic/star_control/star_control_sub8.h
@@ -39,6 +39,8 @@ class CStarControlSub8 {
FPoint _position;
int _field8;
int _fieldC;
+
+ StructEntry() : _field8(0), _fieldC(0) {}
};
private:
#if 0