2012-01-06 23:29:45 +01:00
|
|
|
/* ResidualVM - A 3D game interpreter
|
2011-04-14 12:41:26 +02:00
|
|
|
*
|
2012-01-06 23:29:45 +01:00
|
|
|
* ResidualVM 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.
|
|
|
|
*
|
2012-12-19 23:15:43 +01:00
|
|
|
* 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 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2014-04-05 18:18:42 +02:00
|
|
|
*
|
2012-12-19 23:15:43 +01:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2011-04-14 12:41:26 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-12-19 23:15:43 +01:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-04-05 18:18:42 +02:00
|
|
|
*
|
2012-12-19 23:15:43 +01:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2011-04-14 12:41:26 +02:00
|
|
|
*
|
|
|
|
*/
|
2011-03-21 05:16:27 +08:00
|
|
|
|
2011-04-14 12:41:26 +02:00
|
|
|
#include "engines/grim/object.h"
|
|
|
|
|
2011-04-12 20:41:22 +08:00
|
|
|
namespace Grim {
|
2011-03-21 05:16:27 +08:00
|
|
|
|
2011-05-01 18:51:26 +02:00
|
|
|
int32 Object::s_id = 0;
|
|
|
|
|
|
|
|
Object::Object() :
|
2013-10-26 13:57:55 -07:00
|
|
|
_refCount(0) {
|
2011-03-21 05:16:27 +08:00
|
|
|
|
2011-05-01 18:51:26 +02:00
|
|
|
++s_id;
|
|
|
|
_id = s_id;
|
2011-03-21 05:16:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Object::~Object() {
|
|
|
|
for (Common::List<Pointer *>::iterator i = _pointers.begin(); i != _pointers.end(); ++i) {
|
|
|
|
(*i)->resetPointer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-04 15:16:07 +02:00
|
|
|
int32 Object::getId() const {
|
2011-05-01 18:51:26 +02:00
|
|
|
return _id;
|
2011-03-21 05:16:27 +08:00
|
|
|
}
|
|
|
|
|
2011-05-24 22:18:01 -07:00
|
|
|
void Object::setId(int32 id) {
|
|
|
|
if (id > s_id) {
|
|
|
|
s_id = id;
|
|
|
|
}
|
|
|
|
_id = id;
|
|
|
|
}
|
|
|
|
|
2011-03-21 05:16:27 +08:00
|
|
|
}
|