forked from scummvm/scummvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TINSEL: Implement a container for accessing the INV_OBJECTs
This way we encapsulate the iteration, thus making sure that the appropriate stride is used (Noir has more fields).
- Loading branch information
Showing
6 changed files
with
193 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* ScummVM - Graphic Adventure Engine | ||
* | ||
* ScummVM is the legal property of its developers, whose names | ||
* are too numerous to list here. Please refer to the COPYRIGHT | ||
* file distributed with this source distribution. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include "tinsel/inv_objects.h" | ||
#include "tinsel/tinsel.h" | ||
|
||
namespace Tinsel { | ||
|
||
template<typename T> | ||
class InventoryObjectsImpl : public InventoryObjects { | ||
public: | ||
InventoryObjectsImpl(T* invObjects, int numObjects) : _invObjects(invObjects), _numObjects(numObjects) {} | ||
/** | ||
* Convert item ID number to pointer to item's compiled data | ||
* i.e. Image data and Glitter code. | ||
*/ | ||
INV_OBJECT* GetInvObject(int id) { | ||
int index = GetObjectIndexIfExists(id); | ||
if (index == -1) { | ||
return nullptr; | ||
} | ||
return (INV_OBJECT*)&_invObjects[index]; | ||
} | ||
|
||
INV_OBJECT_T3* GetInvObjectT3(int id); | ||
|
||
/** | ||
* Convert item ID number to index. | ||
*/ | ||
int GetObjectIndexIfExists(int id) const { | ||
T *pObject = _invObjects; | ||
|
||
for (int i = 0; i < _numObjects; i++, pObject++) { | ||
if (pObject->id == id) | ||
return i; | ||
} | ||
return -1; | ||
} | ||
|
||
INV_OBJECT* GetObjectByIndex(int index) const { | ||
return (INV_OBJECT*)&_invObjects[index]; | ||
} | ||
|
||
int NumObjects() const { | ||
return _numObjects; | ||
} | ||
private: | ||
T *_invObjects = nullptr; // Inventory objects' data | ||
int _numObjects = 0; // Number of inventory objects | ||
}; | ||
|
||
// Template specializations for the Noir-query, so that we can error cleanly in non-Noir | ||
template<> | ||
INV_OBJECT_T3* InventoryObjectsImpl<INV_OBJECT_T3>::GetInvObjectT3(int id) { | ||
int index = GetObjectIndexIfExists(id); | ||
if (index == -1) { | ||
return nullptr; | ||
} | ||
return &_invObjects[index]; | ||
} | ||
|
||
// Version for TinselVersion <= 2 | ||
template<> | ||
INV_OBJECT_T3* InventoryObjectsImpl<INV_OBJECT>::GetInvObjectT3(int id) { | ||
error("Requesting INV_OBJECT_T3 from non-Noir-game"); | ||
} | ||
|
||
InventoryObjects *InstantiateInventoryObjects(INV_OBJECT *invObjects, int numObjects) { | ||
if (TinselVersion == 3) { | ||
return new InventoryObjectsImpl<INV_OBJECT_T3>((INV_OBJECT_T3*)invObjects, numObjects); | ||
} else { | ||
return new InventoryObjectsImpl<INV_OBJECT>(invObjects, numObjects); | ||
} | ||
} | ||
|
||
} // End of namespace Tinsel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* ScummVM - Graphic Adventure Engine | ||
* | ||
* ScummVM is the legal property of its developers, whose names | ||
* are too numerous to list here. Please refer to the COPYRIGHT | ||
* file distributed with this source distribution. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#ifndef TINSEL_INV_OBJECT_H | ||
#define TINSEL_INV_OBJECT_H | ||
|
||
#include "tinsel/dw.h" | ||
|
||
namespace Tinsel { | ||
|
||
/** structure of each inventory object */ | ||
struct INV_OBJECT { | ||
int32 id; // inventory objects id | ||
SCNHANDLE hIconFilm; // inventory objects animation film | ||
SCNHANDLE hScript; // inventory objects event handling script | ||
int32 attribute; // inventory object's attribute | ||
}; | ||
|
||
struct INV_OBJECT_T3 : public INV_OBJECT { | ||
int32 unknown; | ||
int32 title; // id of associated notebook title | ||
}; | ||
|
||
class InventoryObjects { | ||
public: | ||
virtual ~InventoryObjects(){}; | ||
virtual INV_OBJECT *GetInvObject(int id) = 0; | ||
virtual INV_OBJECT_T3 *GetInvObjectT3(int id) = 0; | ||
virtual int GetObjectIndexIfExists(int id) const = 0; | ||
virtual INV_OBJECT *GetObjectByIndex(int index) const = 0; | ||
virtual int NumObjects() const = 0; | ||
}; | ||
|
||
InventoryObjects *InstantiateInventoryObjects(INV_OBJECT *invObjects, int numObjects); | ||
|
||
} // End of namespace Tinsel | ||
|
||
#endif // TINSEL_INV_OBJECT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters