HowtoServerSpawnsAstroid
From SfzWiki
Ghoulsblade 00:54, 4 May 2007 (CEST): OBSOLETE. this process has been redesigned, now there is just a single spawn function for server and client without variable argument count, also no object-constructor is called directly from spawn, so the confusing metatable based object-orientation is avoided in the spawn process, this is now realised by object-types.
How the Server Spawns an Astroid ============================================ main.lua: local a = ServerSpawn(cObjAsteroid,math.random(0,3),Vector.random3(2000)) lib.obj.lua: function ServerSpawn (objecttype,...) local o = objecttype:new(0,unpack(arg)) o:SendSpawnToClient(0) obj.astroid.lua: function cObjAsteroid:SendSpawnToClient (playerid,...) self.parentType.SendSpawnToClient(self,playerid,self.meshname,x,y,z,qw,qx,qy,qz,self.mfRad) calls SendSpawnToClient of the parents ... until the baseobj ist reached obj.base.lua: function cObjBase:SendSpawnToClient (playerid,...) ServerSendMsgToClient(playerid,MsgType("S_SpawnObj"),self.miID,self.iObjType,self.miLifeCounter,unpack(arg)) scripting.cpp: static int l_ServerSendMsgToClient (lua_State *L) LuaSendMsg(L,1,player->mpCon->mpOutBuffer); void LuaSendMsg (lua_State *L,const int offset,cFIFO* fifo) message roadtrip into packetuniverse! ... void cScripting::ClientRecvLuaMsg (cMessageReader& reader) const char* func = "ClientRecvMsg"; // ClientRecvMsg(msgtype,objid,...) lua_getglobal(L,func); //printf("ClientRecvLuaMsg:pre\n"); int narg = LuaRecvMsg(L,reader); if (lua_pcall(L, narg, 0, 0) != 0) /* do the call */ lib.msg.lua: function ClientRecvMsg (msgtype,iObjID,...) client.RecvMsg(msgtype,iObjID,unpack(arg)) lib.client.lua: function client.RecvMsg(msgtype,iObjID,...) if (msgtype == MsgType("S_SpawnObj")) then ClientSpawn(iObjID,unpack(arg)) lib.obj.lua: function ClientSpawn (iObjID,iObjType,...) local o = gGameObjs[iObjID] -- the object might have been already created by the local server if (o == nil) then o = objecttype:new(iObjID) end -- no local server here, client has to create the object o:ClientSpawn(unpack(arg)) o.udata:Spawn() obj.asteroid.lua: function cObjAsteroid:ClientSpawn (iLifeCounter,meshname,x,y,z,qw,qx,qy,qz,frad,...) creates the object