2011-04-14 12:41:26 +02:00
|
|
|
/* Residual - A 3D game interpreter
|
|
|
|
*
|
|
|
|
* Residual is the legal property of its developers, whose names
|
2011-04-16 14:12:44 +02:00
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
2011-04-14 12:41:26 +02:00
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
2011-03-21 05:16:27 +08:00
|
|
|
|
|
|
|
#include "engines/grim/lua/lobject.h"
|
|
|
|
|
2011-04-14 12:41:26 +02:00
|
|
|
#include "engines/grim/savegame.h"
|
2011-03-21 06:58:36 +08:00
|
|
|
#include "engines/grim/font.h"
|
2011-04-14 12:41:26 +02:00
|
|
|
#include "engines/grim/object.h"
|
|
|
|
|
2011-03-21 06:58:36 +08:00
|
|
|
|
2011-04-14 12:41:26 +02:00
|
|
|
DECLARE_SINGLETON(Grim::ObjectManager);
|
2011-03-21 05:16:27 +08:00
|
|
|
|
2011-04-12 20:41:22 +08:00
|
|
|
namespace Grim {
|
2011-03-21 05:16:27 +08:00
|
|
|
|
|
|
|
Object::Object() : _refCount(0) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Object::~Object() {
|
2011-03-23 23:13:53 +01:00
|
|
|
if (lua_isopen()) {
|
|
|
|
luaO_resetObject(this); //after climbing the ties rope an ObjectState gets deleted but not removed
|
|
|
|
} //from the lua's userdata list, resulting in a dangling pointer
|
|
|
|
//that breaks the saving. We need to reset to NULL the pointer manually.
|
2011-03-21 05:16:27 +08:00
|
|
|
for (Common::List<Pointer *>::iterator i = _pointers.begin(); i != _pointers.end(); ++i) {
|
|
|
|
(*i)->resetPointer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-10 11:24:03 +02:00
|
|
|
void Object::saveState(SaveGame *) const {
|
2011-03-21 05:16:27 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-04-10 11:24:03 +02:00
|
|
|
bool Object::restoreState(SaveGame *) {
|
2011-03-21 05:16:27 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-21 06:58:36 +08:00
|
|
|
void Object::reference() {
|
2011-03-21 05:16:27 +08:00
|
|
|
++_refCount;
|
|
|
|
}
|
|
|
|
|
2011-03-21 06:58:36 +08:00
|
|
|
void Object::dereference() {
|
2011-03-21 05:16:27 +08:00
|
|
|
if (_refCount > 0) {
|
|
|
|
--_refCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_refCount == 0) {
|
|
|
|
_refCount = -1;
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ObjectManager::saveObject(SaveGame *state, Object *object) {
|
|
|
|
const char *str = object->typeName();
|
|
|
|
int32 len = strlen(str);
|
|
|
|
|
|
|
|
state->writeLEUint32(len);
|
|
|
|
state->write(str, len);
|
|
|
|
|
2011-03-21 06:58:36 +08:00
|
|
|
object->saveState(state);
|
2011-03-21 05:16:27 +08:00
|
|
|
}
|
|
|
|
|
2011-03-21 06:58:36 +08:00
|
|
|
ObjectPtr<Object> ObjectManager::restoreObject(SaveGame *state) {
|
|
|
|
const char *str = state->readCharString();
|
2011-03-21 05:16:27 +08:00
|
|
|
|
2011-03-21 06:58:36 +08:00
|
|
|
ObjectPtr<Object> ptr;
|
|
|
|
Common::String type = str;
|
2011-03-21 05:16:27 +08:00
|
|
|
delete[] str;
|
|
|
|
if (_creators.contains(type)) {
|
|
|
|
CreatorFunc func = _creators.getVal(type);
|
2011-03-21 06:58:36 +08:00
|
|
|
ptr = (func)(state);
|
2011-03-21 05:16:27 +08:00
|
|
|
} else {
|
2011-03-21 06:58:36 +08:00
|
|
|
error("Type name \"%s\" not registered", type.c_str());
|
2011-03-21 05:16:27 +08:00
|
|
|
}
|
|
|
|
|
2011-03-21 06:58:36 +08:00
|
|
|
return ptr;
|
2011-03-21 05:16:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|