Object.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003-2004 The Pentagram team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #include "pent_include.h"
00020 
00021 #include "Object.h"
00022 #include "Kernel.h"
00023 #include "ObjectManager.h"
00024 #include "World.h"
00025 #include "MemoryManager.h"
00026 
00027 #include "UCProcess.h"
00028 #include "UCMachine.h"
00029 #include "IDataSource.h"
00030 #include "ODataSource.h"
00031 
00032 // p_dynamic_cast stuff
00033 DEFINE_RUNTIME_CLASSTYPE_CODE_BASE_CLASS(Object);
00034 
00035 DEFINE_CUSTOM_MEMORY_ALLOCATION(Object);
00036 
00037 Object::~Object()
00038 {
00039         if (objid != 0xFFFF)
00040                 ObjectManager::get_instance()->clearObjId(objid);
00041 }
00042 
00043 ObjId Object::assignObjId()
00044 {
00045         if (objid == 0xFFFF)
00046                 objid = ObjectManager::get_instance()->assignObjId(this);
00047         return objid;
00048 }
00049 
00050 void Object::clearObjId()
00051 {
00052         // On clearObjId we kill all processes that belonged to us
00053         Kernel::get_instance()->killProcesses(objid, 6, true);
00054 
00055         if (objid != 0xFFFF)
00056                 ObjectManager::get_instance()->clearObjId(objid);
00057         objid = 0xFFFF;
00058 }
00059 
00060 void Object::dumpInfo()
00061 {
00062         pout << "Object " << getObjId() << " (class "
00063                  << GetClassType().class_name << ")" << std::endl;
00064 }
00065 
00066 ProcId Object::callUsecode(uint16 classid, uint16 offset,
00067                                                    const uint8* args, int argsize)
00068 {
00069         uint32 objptr = UCMachine::objectToPtr(getObjId());
00070         UCProcess* p = new UCProcess(classid, offset, objptr, 2, args, argsize);
00071         return Kernel::get_instance()->addProcess(p);
00072 }
00073 
00074 
00075 void Object::save(ODataSource* ods)
00076 {
00077         writeObjectHeader(ods);
00078         saveData(ods); // virtual
00079 }
00080 
00081 void Object::writeObjectHeader(ODataSource* ods)
00082 {
00083         const char* cname = GetClassType().class_name; // note: virtual
00084         uint16 clen = strlen(cname);
00085 
00086         ods->write2(clen);
00087         ods->write(cname, clen);
00088 }
00089 
00090 void Object::saveData(ODataSource* ods)
00091 {
00092         // note: Object is unversioned. If we ever want to version it,
00093         // increase the global savegame version
00094 
00095         ods->write2(objid);
00096 }
00097 
00098 bool Object::loadData(IDataSource* ids, uint32 version)
00099 {
00100         objid = ids->read2();
00101 
00102         return true;
00103 }

Generated on Fri Jul 27 22:27:26 2007 for pentagram by  doxygen 1.4.7