From: Andy D. <kha...@us...> - 2006-11-19 23:48:20
|
Update of /cvsroot/planeshift/planeshift/src/npcclient In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5836/src/npcclient Modified Files: npcclient.cpp npcclient.h Log Message: - Added the ability for npcclient to defer loading of pets and familiars. Index: npcclient.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/npcclient/npcclient.cpp,v retrieving revision 1.122 retrieving revision 1.123 diff -C2 -d -r1.122 -r1.123 *** npcclient.cpp 15 Nov 2006 21:30:42 -0000 1.122 --- npcclient.cpp 19 Nov 2006 23:48:16 -0000 1.123 *************** *** 381,385 **** } ! bool psNPCClient::ReadSingleNPC(int char_id) { Result result(db->Select("select * from sc_npc_definitions where char_id=%d",char_id)); --- 381,385 ---- } ! NPC* psNPCClient::ReadSingleNPC(int char_id) { Result result(db->Select("select * from sc_npc_definitions where char_id=%d",char_id)); *************** *** 387,391 **** { Error2("Error loading char_id %d.",char_id); ! return false; } NPC *newnpc = new NPC; --- 387,391 ---- { Error2("Error loading char_id %d.",char_id); ! return NULL; } NPC *newnpc = new NPC; *************** *** 393,402 **** { npcs.Push(newnpc); ! return true; } else { delete newnpc; ! return false; } } --- 393,402 ---- { npcs.Push(newnpc); ! return newnpc; } else { delete newnpc; ! return NULL; } } *************** *** 410,415 **** return false; } ! for (int i=0; i<(int)rs.Count(); i++) { NPC *npc = new NPC; if (npc->Load(rs[i],npctypes)) --- 410,423 ---- return false; } ! for (unsigned long i=0; i<rs.Count(); i++) { + csString name = rs[i]["name"]; + // Familiars are not loaded until neeeded. + if(name.StartsWith("FAMILIAR:")) + { + npcsDeferred.InsertSorted(rs[i].GetInt("char_id")); + continue; + } + NPC *npc = new NPC; if (npc->Load(rs[i],npctypes)) *************** *** 946,949 **** --- 954,968 ---- return npcs[x]; } + + csArrayCmp<int, int> compare(character_id); + size_t i = npcsDeferred.FindSortedKey(compare); + + if (i != csArrayItemNotFound) + { + NPC * npc = ReadSingleNPC(character_id); + if(npc) + npcsDeferred.DeleteIndex(i); + return npc; + } return NULL; } Index: npcclient.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/npcclient/npcclient.h,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** npcclient.h 10 Nov 2006 22:58:50 -0000 1.64 --- npcclient.h 19 Nov 2006 23:48:16 -0000 1.65 *************** *** 301,305 **** NPC* FindAttachedNPC(iCelEntity *entity); ! bool ReadSingleNPC(int char_id); NPC *FindNPC(int character_id); --- 301,305 ---- NPC* FindAttachedNPC(iCelEntity *entity); ! NPC *ReadSingleNPC(int char_id); NPC *FindNPC(int character_id); *************** *** 354,357 **** --- 354,358 ---- BinaryRBTree<Waypoint> waypoints; csArray<NPC*> npcs; + csArray<int> npcsDeferred; csArray<psTribe*> tribes; csHash<iCelEntity*> npc_entities; |