diff options
author | Paul Gilbert | 2017-03-05 20:11:49 -0500 |
---|---|---|
committer | Paul Gilbert | 2017-03-05 20:11:49 -0500 |
commit | cf37d0148d6efa2396e4816963d20ebc56238a2d (patch) | |
tree | d09a27ff8fb54ecd765a8f2ba1db3862c0b93dfd | |
parent | 56206fef9f57567248c2c926659cbc4ec1535095 (diff) | |
download | scummvm-rg350-cf37d0148d6efa2396e4816963d20ebc56238a2d.tar.gz scummvm-rg350-cf37d0148d6efa2396e4816963d20ebc56238a2d.tar.bz2 scummvm-rg350-cf37d0148d6efa2396e4816963d20ebc56238a2d.zip |
TITANIC: Implementing CStarControlSub5 class
-rw-r--r-- | engines/titanic/star_control/star_control_sub5.cpp | 178 | ||||
-rw-r--r-- | engines/titanic/star_control/star_control_sub5.h | 56 | ||||
-rw-r--r-- | engines/titanic/star_control/star_control_sub8.cpp | 4 | ||||
-rw-r--r-- | engines/titanic/star_control/star_control_sub8.h | 3 |
4 files changed, 233 insertions, 8 deletions
diff --git a/engines/titanic/star_control/star_control_sub5.cpp b/engines/titanic/star_control/star_control_sub5.cpp index 731d81f246..4b2ff79ef5 100644 --- a/engines/titanic/star_control/star_control_sub5.cpp +++ b/engines/titanic/star_control/star_control_sub5.cpp @@ -22,28 +22,200 @@ #include "titanic/star_control/star_control_sub5.h" #include "titanic/star_control/star_control_sub12.h" +#include "titanic/titanic.h" namespace Titanic { -CStarControlSub5::CStarControlSub5() : _flag(true) { +void CStarControlSub5::SubEntry::clear() { + if (_data2P) { + delete[] _data2P; + _data2P = nullptr; + _field4 = 0; + } + + if (_data1P) { + delete[] _data1P; + _data1P = nullptr; + _field0 = 0; + } } -bool CStarControlSub5::setup() { +/*------------------------------------------------------------------------*/ + +bool CStarControlSub5::MemoryBlock::allocate() { // TODO return true; } +/*------------------------------------------------------------------------*/ + +CStarControlSub5::CStarControlSub5() : _flag(true), _dataP(nullptr), + _field78B0(0) { +} + +CStarControlSub5::~CStarControlSub5() { + delete[] _dataP; + _dataP = nullptr; +} + +bool CStarControlSub5::setup() { + bool success = setupEntry(5, 5, 4, 1024.0) + && setupEntry(7, 7, 3, 1024.0) + && setupEntry(8, 8, 2, 1024.0) + && setupEntry(16, 16, 1, 1024.0) + && setupEntry(24, 24, 0, 1024.0); + if (success) + success = setup2(24, 24); + + return success; +} + +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 int VALUES1[] = { 0x800, 0xC00, 0x1000, 0x1400, 0x1800 }; + const int VALUES2[] = { + 0xF95BCD, 0xA505A0, 0xFFAD43, 0x98F4EB, 0xF3EFA5, 0, + 0xFFFFFF, 0x81EEF5, 0x5FFD3, 0x4EE4FA, 0x11C3FF, 0x28F3F4, + 0x36FCF2, 0x29F1FD, 0x29BCFD, 0x98E3F4, 0xBBF3D9, 0x8198F5, + 0x5BE4F9, 0x0D6E2, 0x74EEF6, 0x68DEF8 + }; + + Entry *e = &_entries[0]; + for (int idx = 0; idx < 256; ++idx) { + if (idx == 0) { + e->_field0 = 0x4C8; + e->_field4 = 0x40; + e->_field5 = 0x40; + e->_field6 = 0x40; + e->_field8 = g_vm->getRandomNumber(3) + 3; + e->_fieldC = g_vm->getRandomNumber(255); + e->_field10 = FACTOR * 7.0; + e->_field14 = 0.0084687499; + + ++e; + e->_field0 = 0x574; + e->_field4 = 0x7f; + e->_field5 = 0; + e->_field6 = 0; + e->_field8 = g_vm->getRandomNumber(3) + 3; + e->_fieldC = g_vm->getRandomNumber(255); + e->_field10 = FACTOR * 3.0; + e->_field14 = 0.021011719; + + ++e; + e->_field0 = 0x603; + e->_field4 = 0; + e->_field5 = 0; + e->_field6 = 0xff; + e->_field8 = g_vm->getRandomNumber(3) + 3; + e->_fieldC = g_vm->getRandomNumber(255); + e->_field10 = 0; + e->_field14 = 0.022144532; + + ++e; + e->_field0 = 0x712; + e->_field4 = 0xff; + e->_field5 = 0; + e->_field6 = 0; + e->_field8 = g_vm->getRandomNumber(3) + 3; + e->_fieldC = g_vm->getRandomNumber(255); + e->_field10 = FACTOR * 2.0; + e->_field14 = 0.01178125; + + ++e; + e->_field0 = 0xe7f; + e->_field4 = 0xe6; + e->_field5 = 0xbe; + e->_field6 = 0; + e->_field8 = g_vm->getRandomNumber(3) + 3; + e->_fieldC = g_vm->getRandomNumber(255); + e->_field10 = FACTOR * 1.0; + e->_field14 = 0.24791406; + + ++e; + e->_field0 = 0x173f; + e->_field4 = 0xf0; + e->_field5 = 0xf0; + e->_field6 = 0xe6; + e->_field8 = g_vm->getRandomNumber(3) + 3; + e->_fieldC = g_vm->getRandomNumber(255); + e->_field10 = FACTOR * 3.0; + e->_field14 = 0.20832032; + + ++e; + e->_field0 = 0x2ab8; + e->_field4 = 0x28; + e->_field5 = 0x32; + e->_field6 = 0x28; + e->_field8 = g_vm->getRandomNumber(3) + 3; + e->_fieldC = g_vm->getRandomNumber(255); + e->_field10 = FACTOR * 1.0; + e->_field14 = 0.088164061; + + ++e; + e->_field0 = 0x40ac; + e->_field4 = 0x0; + e->_field5 = 0xbe; + e->_field6 = 0xf0; + e->_field8 = g_vm->getRandomNumber(3) + 3; + e->_fieldC = g_vm->getRandomNumber(255); + e->_field10 = FACTOR * 2.0; + e->_field14 = 0.084375001; + + ++e; + e->_field0 = 0x539c; + e->_field4 = 0x20; + e->_field5 = 0x20; + e->_field6 = 0x20; + e->_field8 = g_vm->getRandomNumber(3) + 3; + e->_fieldC = g_vm->getRandomNumber(255); + e->_field10 = FACTOR * 17.0; + e->_field14 = 0.00390625; + } else { + for (int ctr = 0; ctr < 5; ++ctr) { + e->_field0 = static_cast<int>(g_vm->getRandomFloat() * 1350.0 + - 675.0) + VALUES1[idx]; + int val = VALUES2[g_vm->getRandomNumber(15)]; + e->_field4 = val & 0xff; + e->_field5 = (val >> 8) & 0xff; + e->_field6 = (val >> 16) & 0xff; + e->_field8 = g_vm->getRandomNumber(3) + 3; + + e->_fieldC = g_vm->getRandomNumber(255); + e->_field10 = FACTOR * (double)g_vm->getRandomNumber(15); + e->_field14 = ((double)g_vm->getRandomNumber(0xffffffff) + * 50.0 * 0.000015259022) * 0.00390625; + } + } + } + + if (_memoryBlock.allocate()) { + _dataP = new byte[((val2 - 2) * val1 + 2) * 24]; + return true; + } + + return false; +} + void CStarControlSub5::proc2(CStarControlSub6 *sub6, FVector *vector, double v1, double v2, double v3, CSurfaceArea *surfaceArea, CStarControlSub12 *sub12) { // TODO } void CStarControlSub5::proc3(CErrorCode *errorCode) { - // TODO + ++_field78B0; + errorCode->set(); } void CStarControlSub5::fn1() { _flag = !_flag; } +bool CStarControlSub5::setupEntry(int val1, int val2, int index, double val3) { + // TODO + return true; +} + } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub5.h b/engines/titanic/star_control/star_control_sub5.h index 4927a144cd..17f339994d 100644 --- a/engines/titanic/star_control/star_control_sub5.h +++ b/engines/titanic/star_control/star_control_sub5.h @@ -35,21 +35,67 @@ class CStarControlSub5 { struct SubEntry { int _field0; int _field4; + byte *_data1P; + byte *_data2P; + SubEntry() : _field0(0), _field4(0), _data1P(nullptr), _data2P(nullptr) {} + ~SubEntry() { clear(); } + + /** + * Clears the entry + */ + void clear(); + }; + + struct Entry { + int _field0; + byte _field4; + byte _field5; + byte _field6; int _field8; int _fieldC; + double _field10; + byte _field14; + byte _field15; + + Entry() : _field0(0), _field4(0), _field5(0), _field6(0), _field8(0), + _fieldC(0), _field10(0), _field14(0), _field15(0) {} + }; + + struct MemoryBlock { + public: + byte *_ptr; + public: + MemoryBlock() : _ptr(nullptr) {} + ~MemoryBlock() { delete[] _ptr; } + + /** + * Allocates the memory block + */ + bool allocate(); }; private: bool _flag; CStarControlSub6 _sub1, _sub2; -#if 0 SubEntry _array[5]; - int _field7914; - int _field78AC; + Entry _entries[1284]; int _field78B0; -#endif + MemoryBlock _memoryBlock; + byte *_dataP; +private: + /** + * Sets up the data for an array entry + * @return True if success + */ + bool setupEntry(int val1, int val2, int index, double val3); + + /** + * Secondary setup method + * @return True if success + */ + bool setup2(int val1, int val2); public: CStarControlSub5(); - virtual ~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_sub8.cpp b/engines/titanic/star_control/star_control_sub8.cpp index 3bcbdd0d2c..5840c9670e 100644 --- a/engines/titanic/star_control/star_control_sub8.cpp +++ b/engines/titanic/star_control/star_control_sub8.cpp @@ -69,4 +69,8 @@ void CStarControlSub8::draw(CSurfaceArea *surfaceArea) { // TODO } +void CStarControlSub8::clear() { + // TODO +} + } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub8.h b/engines/titanic/star_control/star_control_sub8.h index 0b0a7f6f11..97409fd059 100644 --- a/engines/titanic/star_control/star_control_sub8.h +++ b/engines/titanic/star_control/star_control_sub8.h @@ -51,6 +51,7 @@ public: int _fieldC; public: CStarControlSub8(); + ~CStarControlSub8() { clear(); } /** * Load the data for the class from file @@ -73,6 +74,8 @@ public: void fn2(CVideoSurface *surface, CStarField *starField, CStarControlSub7 *sub7); void fn3(); FPoint getPosition() const; + + void clear(); }; } // End of namespace Titanic |