From: Keith F. <ven...@us...> - 2003-06-22 09:19:40
|
Update of /cvsroot/planeshift/planeshift/src/npcclient In directory sc8-pr-cvs1:/tmp/cvs-serv8284 Modified Files: npcclient.h npcclient.cpp npcbehave.h networkmgr.h networkmgr.cpp command.cpp Log Message: Added a TYPE parm to all Debug(), etc. macros. See log.h for list. Index: npcclient.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/npcclient/npcclient.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** npcclient.h 14 Jun 2003 17:31:47 -0000 1.8 --- npcclient.h 22 Jun 2003 09:19:37 -0000 1.9 *************** *** 153,156 **** --- 153,162 ---- { return network; } + /** + * Disconnect from server nicely, before quitting. + */ + void Disconnect(); + + protected: Index: npcclient.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/npcclient/npcclient.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** npcclient.cpp 14 Jun 2003 17:31:47 -0000 1.9 --- npcclient.cpp 22 Jun 2003 09:19:37 -0000 1.10 *************** *** 167,175 **** } ! // This starts the NPC AI processing loop. ! psNPCTick *tick = new psNPCTick(1000,this); ! eventmanager->Push(tick); ServerConsole::MainLoop (); } --- 167,180 ---- } ! // This starts the NPC AI processing loop. ! psNPCTick *tick = new psNPCTick(1000,this); ! eventmanager->Push(tick); ServerConsole::MainLoop (); + } + + void psNPCClient::Disconnect() + { + network->Disconnect(); } Index: npcbehave.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/npcclient/npcbehave.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** npcbehave.h 19 Jun 2003 17:36:40 -0000 1.10 --- npcbehave.h 22 Jun 2003 09:19:37 -0000 1.11 *************** *** 306,309 **** --- 306,310 ---- MoveOperation() { consec_collisions=0; vel.Set(0,0,0); inside_rgn = true; } + virtual ~MoveOperation() { } virtual bool Load(iDocumentNode *node); virtual ScriptOperation *MakeCopy(); *************** *** 327,330 **** --- 328,332 ---- public: MoveToOperation() { dest.Set(0,0,0); vel=0; } + virtual ~MoveToOperation() { } virtual bool Run(NPC *npc,EventManager *eventmgr); *************** *** 363,366 **** --- 365,369 ---- RotateOperation() { op_type=ROT_UNKNOWN; ang_vel=999; } + virtual ~RotateOperation() { } virtual bool Load(iDocumentNode *node); virtual ScriptOperation *MakeCopy(); *************** *** 388,391 **** --- 391,395 ---- LocateOperation() { range = 0; static_loc=true; located=false; } + virtual ~LocateOperation() { } virtual bool Run(NPC *npc,EventManager *eventmgr); *************** *** 406,409 **** --- 410,414 ---- NavigateOperation() {}; + virtual ~NavigateOperation() {}; virtual bool Run(NPC *npc,EventManager *eventmgr); *************** *** 426,429 **** --- 431,435 ---- PickupOperation() {}; + virtual ~PickupOperation() {}; virtual bool Run(NPC *npc,EventManager *eventmgr); virtual bool Load(iDocumentNode *node); *************** *** 445,448 **** --- 451,455 ---- BeginLoopOperation() { iterations=0; } + virtual ~BeginLoopOperation() { } virtual bool Run(NPC *npc,EventManager *eventmgr); *************** *** 463,466 **** --- 470,474 ---- EndLoopOperation(int which) { loopback_op = which; } + virtual ~EndLoopOperation() { } virtual bool Run(NPC *npc,EventManager *eventmgr); virtual bool Load(iDocumentNode *node); *************** *** 482,485 **** --- 490,494 ---- WaitOperation() { duration=0; } + virtual ~WaitOperation() { } virtual bool Run(NPC *npc,EventManager *eventmgr); *************** *** 500,503 **** --- 509,513 ---- DropOperation() {}; + virtual ~DropOperation() {}; virtual bool Run(NPC *npc,EventManager *eventmgr); virtual bool Load(iDocumentNode *node); Index: networkmgr.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/npcclient/networkmgr.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** networkmgr.h 4 Jun 2003 06:24:48 -0000 1.7 --- networkmgr.h 22 Jun 2003 09:19:37 -0000 1.8 *************** *** 22,25 **** --- 22,26 ---- #include <csutil/csstring.h> + #include "engine/netpersist.h" #include "interface/subscriber.h" // Subscriber class *************** *** 41,45 **** bool ReceiveNPCList(MsgEntry *msg); bool ReceiveMapList(MsgEntry *msg); ! bool ReceiveActorList(MsgEntry *msg); void HandlePersistMessage(MsgEntry *msg); --- 42,47 ---- bool ReceiveNPCList(MsgEntry *msg); bool ReceiveMapList(MsgEntry *msg); ! bool ReceiveActorList(psCelPersistMessage& pmsg); ! void ReceiveEntity(psCelPersistMessage& pmsg); void HandlePersistMessage(MsgEntry *msg); *************** *** 49,53 **** public: NetworkManager(MsgHandler *mh); ! ~NetworkManager(); SCF_DECLARE_IBASE; --- 51,55 ---- public: NetworkManager(MsgHandler *mh); ! virtual ~NetworkManager(); SCF_DECLARE_IBASE; *************** *** 57,60 **** --- 59,63 ---- void Authenticate(csString& user,csString& pass); bool IsReady() { return ready; } + void Disconnect(); void QueueDRData(int entity_id,iDataBuffer *data); Index: networkmgr.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/npcclient/networkmgr.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** networkmgr.cpp 4 Jun 2003 06:24:48 -0000 1.6 --- networkmgr.cpp 22 Jun 2003 09:19:37 -0000 1.7 *************** *** 21,25 **** --- 21,27 ---- #include <csutil/csstring.h> #include <iutil/vfs.h> + #include <bl/behave.h> + #include "util/sleep.h" #include "util/log.h" #include "net/msghandler.h" *************** *** 66,69 **** --- 68,79 ---- } + void NetworkManager::Disconnect() + { + psDisconnectMessage discon(0, 0, ""); + msghandler->SendMessage(discon.msg); + psSleep(500); // hopefully let the network send the quit msg. + } + + void NetworkManager::HandleMessage(MsgEntry *me) { *************** *** 89,93 **** case MSGTYPECELPERSIST: { ! ReceiveActorList(me); break; } --- 99,103 ---- case MSGTYPECELPERSIST: { ! HandlePersistMessage(me); break; } *************** *** 129,144 **** switch (pmsg.cmd) { ! case CELPERSISTCMD_REQUEST_ACTORLIST: ! ReceiveActorList(msg); ! break; } return; } ! bool NetworkManager::ReceiveActorList(MsgEntry *msg) { ! psCelPersistMessage pmsg(msg); ! ! Debug1("Receiving actor list.\n"); csRef<iVFS> vfs = CS_QUERY_REGISTRY(npcclient->GetObjectReg(), iVFS); --- 139,155 ---- switch (pmsg.cmd) { ! case CELPERSISTCMD_SEND_ACTORLIST: ! ReceiveActorList(pmsg); ! break; ! case CELPERSISTCMD_SEND_ENTITY: ! ReceiveEntity(pmsg); ! break; } return; } ! bool NetworkManager::ReceiveActorList(psCelPersistMessage& pmsg) { ! Debug1(LOG_CELPERSIST,"Receiving actor list.\n"); csRef<iVFS> vfs = CS_QUERY_REGISTRY(npcclient->GetObjectReg(), iVFS); *************** *** 161,176 **** npcclient->SetActors(entity); ! /***************** ! iCelEntity* newactor = netpersist->GetMappedEntity(pmsg.id); ! if (!newactor) ! { ! Error1("Couldn't find myself!?!\n"); ! vfs->ChDir(pwd); ! return; ! } ! SetMainActor(newactor); ! *******************/ ! ! Debug1("Received actor list!\n"); // Change directory back to what it was. --- 172,176 ---- npcclient->SetActors(entity); ! Debug1(LOG_CELPERSIST,"Received actor list!\n"); // Change directory back to what it was. *************** *** 180,183 **** --- 180,244 ---- return true; } + + void NetworkManager::ReceiveEntity(psCelPersistMessage& pmsg) + { + Debug1(LOG_CELPERSIST,"Receiving Entity Net Msg...\n"); + + csRef<iVFS> vfs = CS_QUERY_REGISTRY(npcclient->GetObjectReg(), iVFS); + csString pwd = vfs->GetCwd(); + + if (!vfs->ChDir("/planeshift/models")) + Error1 ("Could not change directory in VFS to /planeshift/art\n"); + + csRef<iEngine> engine = CS_QUERY_REGISTRY(npcclient->GetObjectReg(), iEngine); + engine->SetCacheManager(NULL); // Make cache manager use ChDir directory + + csRef<iCelEntity> entity = netpersist->ReadEntity(&pmsg); + if (!entity) + { + Error1 ("Error while reading entity!\n"); + vfs->ChDir(pwd); + return; + } + + Debug4(LOG_CELPERSIST,"Received entity %s:%d and Refcount is %d.\n", + entity->GetName(), + entity->GetID(), + entity->GetRefCount() ); + + // is it an actor? + if (entity->GetBehaviour() && + !strcmp (entity->GetBehaviour()->GetName(), "actor")) + { + // Actor entities should not be sent before the actor list. + if (!npcclient->GetActors() ) + { + Warning2(LOG_CELPERSIST,"Received actor entity %s before actor list! Ignored.\n",entity->GetName() ); + vfs->ChDir(pwd); + return; + } + + if (!npcclient->FindActor(entity)) + npcclient->AddActor(entity); + else + Warning2(LOG_CELPERSIST,"Received double copy of %s!\n",entity->GetName() ); + } + else + { + npcclient->AddEntity(entity); + } + + Debug4(LOG_CELPERSIST,"After Add: Got entity %s:%lu with refcount %d in celclient\n", + entity->GetName(), + entity->GetID(), + entity->GetRefCount() ); + + Debug3(LOG_CELPERSIST,"Mapping Entity %d to player id %d.\n",entity->GetID(), pmsg.id); + npcclient->AttachNPCtoEntity( pmsg.id,entity->GetID() ); + + vfs->ChDir(pwd); + engine->SetCacheManager(NULL); + } + void NetworkManager::PrepareMessage() Index: command.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/npcclient/command.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** command.cpp 2 Jun 2003 07:12:55 -0000 1.3 --- command.cpp 22 Jun 2003 09:19:37 -0000 1.4 *************** *** 40,43 **** --- 40,45 ---- int com_quit(char *) { + npcclient->Disconnect(); + ServerConsole::Stop(); |