00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "pent_include.h"
00020 #include "SpriteProcess.h"
00021 #include "ItemFactory.h"
00022 #include "Item.h"
00023 #include "CurrentMap.h"
00024 #include "Kernel.h"
00025 #include "getObject.h"
00026
00027 #include "IDataSource.h"
00028 #include "ODataSource.h"
00029
00030
00031 DEFINE_RUNTIME_CLASSTYPE_CODE(SpriteProcess,Process);
00032
00033 SpriteProcess::SpriteProcess()
00034 : Process()
00035 {
00036
00037 }
00038
00039 SpriteProcess::SpriteProcess(int Shape, int Frame, int LastFrame,
00040 int Repeats, int Delay, int X, int Y, int Z,
00041 bool delayed_init) :
00042 shape(Shape), frame(Frame), first_frame(Frame), last_frame(LastFrame),
00043 repeats(Repeats), delay(Delay*2), x(X), y(Y), z(Z), delay_counter(0),
00044 initialized(false)
00045 {
00046 if (!delayed_init)
00047 init();
00048 }
00049
00050 void SpriteProcess::init()
00051 {
00052 Item *item = ItemFactory::createItem(shape, frame,
00053 0, Item::FLG_DISPOSABLE, 0, 0, Item::EXT_SPRITE, true);
00054 item->move(x,y,z);
00055 setItemNum(item->getObjId());
00056 initialized = true;
00057 }
00058
00059 SpriteProcess::~SpriteProcess(void)
00060 {
00061 Item *item = getItem(item_num);
00062 if (item) item->destroy();
00063 }
00064
00065 bool SpriteProcess::run(const uint32)
00066 {
00067 if (!initialized) init();
00068
00069 Item *item = getItem(item_num);
00070
00071 if (!item || (frame > last_frame && repeats==1 && !delay_counter))
00072 {
00073 terminate();
00074 return true;
00075 }
00076
00077 if (delay_counter)
00078 {
00079 delay_counter = (delay_counter+1)%delay;
00080 return false;
00081 }
00082
00083 if (frame > last_frame )
00084 {
00085 frame = first_frame;
00086 repeats--;
00087 }
00088
00089 item->setFrame(frame);
00090 frame++;
00091 delay_counter = (delay_counter+1)%delay;
00092 return true;
00093 }
00094
00095
00096
00097 uint32 SpriteProcess::I_createSprite(const uint8* args, unsigned int argsize)
00098 {
00099 int repeats = 1;
00100 ARG_SINT16(shape);
00101 ARG_SINT16(frame);
00102 ARG_SINT16(last_frame);
00103
00104 if (argsize == 18)
00105 {
00106 ARG_SINT16(unknown);
00107 ARG_SINT16(repeats_count);
00108 repeats = repeats_count;
00109 }
00110
00111 ARG_SINT16(delay);
00112 ARG_UINT16(x);
00113 ARG_UINT16(y);
00114 ARG_UINT8(z);
00115 Process *p = new SpriteProcess(shape, frame, last_frame, repeats, delay, x, y, z);
00116 return Kernel::get_instance()->addProcess(p);
00117 }
00118
00119 void SpriteProcess::saveData(ODataSource* ods)
00120 {
00121 Process::saveData(ods);
00122
00123 ods->write4(static_cast<uint32>(shape));
00124 ods->write4(static_cast<uint32>(frame));
00125 ods->write4(static_cast<uint32>(first_frame));
00126 ods->write4(static_cast<uint32>(last_frame));
00127 ods->write4(static_cast<uint32>(repeats));
00128 ods->write4(static_cast<uint32>(delay));
00129 ods->write4(static_cast<uint32>(x));
00130 ods->write4(static_cast<uint32>(y));
00131 ods->write4(static_cast<uint32>(z));
00132 ods->write4(static_cast<uint32>(delay_counter));
00133 ods->write1(initialized ? 1 : 0);
00134 }
00135
00136 bool SpriteProcess::loadData(IDataSource* ids, uint32 version)
00137 {
00138 if (!Process::loadData(ids, version)) return false;
00139
00140 shape = static_cast<int>(ids->read4());
00141 frame = static_cast<int>(ids->read4());
00142 first_frame = static_cast<int>(ids->read4());
00143 last_frame = static_cast<int>(ids->read4());
00144 repeats = static_cast<int>(ids->read4());
00145 delay = static_cast<int>(ids->read4());
00146 x = static_cast<int>(ids->read4());
00147 y = static_cast<int>(ids->read4());
00148 z = static_cast<int>(ids->read4());
00149 delay_counter = static_cast<int>(ids->read4());
00150 initialized = (ids->read1() != 0);
00151
00152 return true;
00153 }