aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorathrxx2011-06-09 16:30:41 +0200
committerJohannes Schickel2011-12-26 16:18:10 +0100
commitaa031bf98ef1b6da485122fabef1178f6101aded (patch)
treeb3e78ac69da45d50f409a0f3c00be8d66df5dc5a /engines
parentff8a030c379e70d9f90ece071ff9a63495db36cf (diff)
downloadscummvm-rg350-aa031bf98ef1b6da485122fabef1178f6101aded.tar.gz
scummvm-rg350-aa031bf98ef1b6da485122fabef1178f6101aded.tar.bz2
scummvm-rg350-aa031bf98ef1b6da485122fabef1178f6101aded.zip
KYRA: (EOB) - minor code size reduction
Diffstat (limited to 'engines')
-rw-r--r--engines/kyra/eobcommon.cpp5
-rw-r--r--engines/kyra/eobcommon.h19
-rw-r--r--engines/kyra/lol.cpp6
-rw-r--r--engines/kyra/lol.h3
-rw-r--r--engines/kyra/loleobbase.cpp5
-rw-r--r--engines/kyra/loleobbase.h25
-rw-r--r--engines/kyra/saveload_eob.cpp37
-rw-r--r--engines/kyra/saveload_lol.cpp21
8 files changed, 56 insertions, 65 deletions
diff --git a/engines/kyra/eobcommon.cpp b/engines/kyra/eobcommon.cpp
index d82a3dd012..12a0a0d9ba 100644
--- a/engines/kyra/eobcommon.cpp
+++ b/engines/kyra/eobcommon.cpp
@@ -297,8 +297,9 @@ Common::Error EobCoreEngine::init() {
memset(_itemNames[i], 0, 35);
}
- _flyingObjects = new EobFlyingObject[10];
- memset(_flyingObjects, 0, 10 * sizeof(EobFlyingObject));
+ _flyingObjects = new EobFlyingObject[_numFlyingObjects];
+ _flyingObjectsPtr = _flyingObjects;
+ memset(_flyingObjects, 0, _numFlyingObjects * sizeof(EobFlyingObject));
_spellAnimBuffer = new uint8[4096];
memset(_spellAnimBuffer, 0, 4096);
diff --git a/engines/kyra/eobcommon.h b/engines/kyra/eobcommon.h
index 201c1dfa11..1ad7b91aca 100644
--- a/engines/kyra/eobcommon.h
+++ b/engines/kyra/eobcommon.h
@@ -228,22 +228,6 @@ struct ScriptTimer {
uint32 next;
};
-struct EobFlyingObject {
- uint8 enable;
- uint8 objectType;
- int16 attackerId;
- Item item;
- uint16 curBlock;
- uint16 u2;
- uint8 u1;
- uint8 direction;
- uint8 distance;
- int8 callBackIndex;
- uint8 curPos;
- uint8 flags;
- uint8 unused;
-};
-
class EobInfProcessor;
class EobCoreEngine : public LolEobBaseEngine {
@@ -770,11 +754,8 @@ protected:
Common::Error saveGameStateIntern(int slot, const char *saveName, const Graphics::Surface *thumbnail);
void *generateMonsterTempData(LevelTempData *tmp);
- void *generateFlyingObjectTempData(LevelTempData *tmp);
void restoreMonsterTempData(LevelTempData *tmp);
- void restoreFlyingObjectTempData(LevelTempData *tmp);
void releaseMonsterTempData(LevelTempData *tmp);
- void releaseFlyingObjectTempData(LevelTempData *tmp);
int _saveLoadMode;
diff --git a/engines/kyra/lol.cpp b/engines/kyra/lol.cpp
index 6cb3b51370..ebe6ea6e19 100644
--- a/engines/kyra/lol.cpp
+++ b/engines/kyra/lol.cpp
@@ -417,8 +417,10 @@ Common::Error LoLEngine::init() {
_tempBuffer5120 = new uint8[5120];
memset(_tempBuffer5120, 0, 5120);
- _flyingObjects = new FlyingObject[8];
- memset(_flyingObjects, 0, 8 * sizeof(FlyingObject));
+ _flyingObjects = new FlyingObject[_numFlyingObjects];
+ _flyingObjectsPtr = _flyingObjects;
+ _flyingObjectStructSize = sizeof(FlyingObject);
+ memset(_flyingObjects, 0, _numFlyingObjects * sizeof(FlyingObject));
memset(_globalScriptVars, 0, sizeof(_globalScriptVars));
diff --git a/engines/kyra/lol.h b/engines/kyra/lol.h
index 20519b78fb..f4fcbeb269 100644
--- a/engines/kyra/lol.h
+++ b/engines/kyra/lol.h
@@ -1299,12 +1299,9 @@ private:
Common::Error saveGameStateIntern(int slot, const char *saveName, const Graphics::Surface *thumbnail);
void *generateMonsterTempData(LevelTempData *tmp);
- void *generateFlyingObjectTempData(LevelTempData *tmp);
void restoreBlockTempData(int levelIndex);
void restoreMonsterTempData(LevelTempData *tmp);
- void restoreFlyingObjectTempData(LevelTempData *tmp);
void releaseMonsterTempData(LevelTempData *tmp);
- void releaseFlyingObjectTempData(LevelTempData *tmp);
Graphics::Surface *generateSaveThumbnail() const;
};
diff --git a/engines/kyra/loleobbase.cpp b/engines/kyra/loleobbase.cpp
index 05b683b830..1c4068de20 100644
--- a/engines/kyra/loleobbase.cpp
+++ b/engines/kyra/loleobbase.cpp
@@ -29,7 +29,7 @@
namespace Kyra {
-LolEobBaseEngine::LolEobBaseEngine(OSystem *system, const GameFlags &flags) : KyraEngine_v1(system, flags) {
+LolEobBaseEngine::LolEobBaseEngine(OSystem *system, const GameFlags &flags) : KyraEngine_v1(system, flags), _numFlyingObjects(_flags.gameID == GI_LOL ? 8 : 10) {
_txt = 0;
_mouseClick = 0;
_preserveEvents = _buttonListChanged = false;
@@ -75,6 +75,9 @@ LolEobBaseEngine::LolEobBaseEngine(OSystem *system, const GameFlags &flags) : Ky
_updateFlags = _clickedSpecialFlag = 0;
_sceneDefaultUpdate = 0;
_sceneUpdateRequired = false;
+
+ _flyingObjectsPtr = 0;
+ _flyingObjectStructSize = sizeof(EobFlyingObject);
_clickedShapeXOffs = _clickedShapeYOffs = 0;
diff --git a/engines/kyra/loleobbase.h b/engines/kyra/loleobbase.h
index 042f9c0e78..43a86465bc 100644
--- a/engines/kyra/loleobbase.h
+++ b/engines/kyra/loleobbase.h
@@ -63,6 +63,22 @@ struct LevelTempData {
uint8 monsterDifficulty;
};
+struct EobFlyingObject {
+ uint8 enable;
+ uint8 objectType;
+ int16 attackerId;
+ Item item;
+ uint16 curBlock;
+ uint16 u2;
+ uint8 u1;
+ uint8 direction;
+ uint8 distance;
+ int8 callBackIndex;
+ uint8 curPos;
+ uint8 flags;
+ uint8 unused;
+};
+
class LolEobBaseEngine : public KyraEngine_v1 {
friend class TextDisplayer_Eob;
public:
@@ -289,13 +305,16 @@ protected:
void restoreBlockTempData(int levelIndex);
void releaseTempData();
virtual void *generateMonsterTempData(LevelTempData *tmp) = 0;
- virtual void *generateFlyingObjectTempData(LevelTempData *tmp) = 0;
virtual void restoreMonsterTempData(LevelTempData *tmp) = 0;
- virtual void restoreFlyingObjectTempData(LevelTempData *tmp) = 0;
virtual void releaseMonsterTempData(LevelTempData *tmp) = 0;
- virtual void releaseFlyingObjectTempData(LevelTempData *tmp) = 0;
+ void restoreFlyingObjectTempData(LevelTempData *tmp);
+ void *generateFlyingObjectTempData(LevelTempData *tmp);
+ void releaseFlyingObjectTempData(LevelTempData *tmp);
LevelTempData *_lvlTempData[29];
+ const int _numFlyingObjects;
+ uint32 _flyingObjectStructSize;
+ void *_flyingObjectsPtr;
// sound
virtual bool snd_processEnvironmentalSoundEffect(int soundId, int block);
diff --git a/engines/kyra/saveload_eob.cpp b/engines/kyra/saveload_eob.cpp
index 3b3964bdc5..90192a4e51 100644
--- a/engines/kyra/saveload_eob.cpp
+++ b/engines/kyra/saveload_eob.cpp
@@ -127,6 +127,23 @@ void LolEobBaseEngine::releaseTempData() {
}
}
+void *LolEobBaseEngine::generateFlyingObjectTempData(LevelTempData *tmp) {
+ assert(_flyingObjectStructSize == sizeof(EobFlyingObject));
+ EobFlyingObject *f = new EobFlyingObject[_numFlyingObjects];
+ memcpy(f, _flyingObjectsPtr, sizeof(EobFlyingObject) * _numFlyingObjects);
+ return f;
+}
+
+void LolEobBaseEngine::restoreFlyingObjectTempData(LevelTempData *tmp) {
+ assert(_flyingObjectStructSize == sizeof(EobFlyingObject));
+ memcpy(_flyingObjectsPtr, tmp->flyingObjects, sizeof(EobFlyingObject) * _numFlyingObjects);
+}
+
+void LolEobBaseEngine::releaseFlyingObjectTempData(LevelTempData *tmp) {
+ EobFlyingObject *p = (EobFlyingObject*)tmp->flyingObjects;
+ delete[] p;
+}
+
#ifdef ENABLE_EOB
Common::Error EobCoreEngine::loadGameState(int slot) {
@@ -269,7 +286,7 @@ Common::Error EobCoreEngine::loadGameState(int slot) {
_lvlTempData[i]->flags = new uint16[1024];
EobMonsterInPlay *lm = new EobMonsterInPlay[30];
_lvlTempData[i]->monsters = lm;
- EobFlyingObject *lf = new EobFlyingObject[10];
+ EobFlyingObject *lf = new EobFlyingObject[_numFlyingObjects];
_lvlTempData[i]->flyingObjects = lf;
LevelTempData *l = _lvlTempData[i];
@@ -305,7 +322,7 @@ Common::Error EobCoreEngine::loadGameState(int slot) {
m->sub = in.readByte();
}
- for (int ii = 0; ii < 10; ii++) {
+ for (int ii = 0; ii < _numFlyingObjects; ii++) {
EobFlyingObject *m = &lf[ii];
m->enable = in.readByte();
m->objectType = in.readByte();
@@ -481,7 +498,7 @@ Common::Error EobCoreEngine::saveGameStateIntern(int slot, const char *saveName,
out->writeByte(m->sub);
}
- for (int ii = 0; ii < 10; ii++) {
+ for (int ii = 0; ii < _numFlyingObjects; ii++) {
EobFlyingObject *m = &lf[ii];
out->writeByte(m->enable);
out->writeByte(m->objectType);
@@ -519,29 +536,15 @@ void *EobCoreEngine::generateMonsterTempData(LevelTempData *tmp) {
return m;
}
-void *EobCoreEngine::generateFlyingObjectTempData(LevelTempData *tmp) {
- EobFlyingObject *f = new EobFlyingObject[10];
- memcpy(f, _flyingObjects, sizeof(EobFlyingObject) * 10);
- return f;
-}
-
void EobCoreEngine::restoreMonsterTempData(LevelTempData *tmp) {
memcpy(_monsters, tmp->monsters, sizeof(EobMonsterInPlay) * 30);
}
-void EobCoreEngine::restoreFlyingObjectTempData(LevelTempData *tmp) {
- memcpy(_flyingObjects, tmp->flyingObjects, sizeof(EobFlyingObject) * 10);
-}
-
void EobCoreEngine::releaseMonsterTempData(LevelTempData *tmp) {
EobMonsterInPlay *p = (EobMonsterInPlay*)tmp->monsters;
delete[] p;
}
-void EobCoreEngine::releaseFlyingObjectTempData(LevelTempData *tmp) {
-
-}
-
#endif // ENABLE_EOB
} // End of namespace Kyra
diff --git a/engines/kyra/saveload_lol.cpp b/engines/kyra/saveload_lol.cpp
index 7d8e6c32d9..33097a86a3 100644
--- a/engines/kyra/saveload_lol.cpp
+++ b/engines/kyra/saveload_lol.cpp
@@ -195,7 +195,7 @@ Common::Error LoLEngine::loadGameState(int slot) {
_lvlTempData[i]->flags = new uint16[1024];
LolMonsterInPlay *lm = new LolMonsterInPlay[30];
_lvlTempData[i]->monsters = lm;
- FlyingObject *lf = new FlyingObject[8];
+ FlyingObject *lf = new FlyingObject[_numFlyingObjects];
_lvlTempData[i]->flyingObjects = lf;
LevelTempData *l = _lvlTempData[i];
@@ -236,7 +236,7 @@ Common::Error LoLEngine::loadGameState(int slot) {
in.read(m->equipmentShapes, 4);
}
- for (int ii = 0; ii < 8; ii++) {
+ for (int ii = 0; ii < _numFlyingObjects; ii++) {
FlyingObject *m = &lf[ii];
m->enable = in.readByte();
m->objectType = in.readByte();
@@ -420,7 +420,7 @@ Common::Error LoLEngine::saveGameStateIntern(int slot, const char *saveName, con
out->write(m->equipmentShapes, 4);
}
- for (int ii = 0; ii < 8; ii++) {
+ for (int ii = 0; ii < _numFlyingObjects; ii++) {
FlyingObject *m = &lf[ii];
out->writeByte(m->enable);
out->writeByte(m->objectType);
@@ -489,12 +489,6 @@ void *LoLEngine::generateMonsterTempData(LevelTempData *tmp) {
return m;
}
-void *LoLEngine::generateFlyingObjectTempData(LevelTempData *tmp) {
- FlyingObject *f = new FlyingObject[8];
- memcpy(f, _flyingObjects, sizeof(FlyingObject) * 8);
- return f;
-}
-
void LoLEngine::restoreTempDataAdjustMonsterStrength(int index) {
if (_lvlTempData[index]->monsterDifficulty == _monsterDifficulty)
return;
@@ -525,20 +519,11 @@ void LoLEngine::restoreMonsterTempData(LevelTempData *tmp) {
}
}
-void LoLEngine::restoreFlyingObjectTempData(LevelTempData *tmp) {
- memcpy(_flyingObjects, tmp->flyingObjects, sizeof(FlyingObject) * 8);
-}
-
void LoLEngine::releaseMonsterTempData(LevelTempData *tmp) {
LolMonsterInPlay *p = (LolMonsterInPlay*)tmp->monsters;
delete[] p;
}
-void LoLEngine::releaseFlyingObjectTempData(LevelTempData *tmp) {
- FlyingObject *p = (FlyingObject*)tmp->flyingObjects;
- delete[] p;
-}
-
} // End of namespace Kyra
#endif // ENABLE_LOL