00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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
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);
00079 }
00080
00081 void Object::writeObjectHeader(ODataSource* ods)
00082 {
00083 const char* cname = GetClassType().class_name;
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
00093
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 }