void LoadZombie( game g, chr z ) { if( g == NULL || z == NULL ) return; if( g->ZombieListHead != NULL ) { creature Z = CreateCreature(g); CopyCharacter( Z->Character, z ); InsertCreatureNode( g->ZombieListHead, Z ); } else { g->ZombieListHead = CreateCreature(g); CopyCharacter( g->ZombieListHead->Character, z ); } wrefresh(g->arena); }
void RunGame( int load) { game g = NULL; if(load) { g = LoadGame(); } else { g = NewGame(); } if(g==NULL) { return; } wrefresh(g->arena); wrefresh(g->status); if(g!=NULL) { if(g->pc) g->print(g->pc); creature G = CreateCreature(g); G = g->ZombieListHead; while(G) { g->print(G->Character); G = G->Next; } PrintAllBuildings(g->gameMap, g->pc->pos); PlayLoop(g); if(G) { PurgeCreatureNode(G); DESTROY(G); } PurgeGame(g); DESTROY(g); } }
Creature* Puzzle::CreateBaby(const Creature* in_parent1, const Creature* in_parent2) const { Creature* const baby = CreateCreature(); baby->SetParents(*in_parent1, *in_parent2); baby->OnInit(); baby->m_generation = m_generation; return baby; }
void Puzzle::CreatePopulation(unsigned int in_populationSize) { for (unsigned int i = m_polulation->size(); i < in_populationSize; i++) { Creature* newCreature = CreateCreature(); newCreature->OnInit(); newCreature->m_generation = m_generation; m_polulation->push_back(newCreature); } }
game NewGame() { game g = CreateGame(); if( g == NULL ) return NULL; RandomMap(g->gameMap); g->pc = CreateCharacter(g); wrefresh(g->win); init_pc(g->pc); box(g->arena, 0, 0); wrefresh(g->arena); int nzombies = NumZombies(g->arena); g->ZombieListHead = CreateCreature(g); init_npc(g->ZombieListHead->Character); wrefresh(g->arena); int n = 1; while( n < nzombies ) { wrefresh(g->arena); creature Z = CreateCreature(g); init_npc(Z->Character); InsertCreatureNode( g->ZombieListHead, Z ); ++n; } return g; }
bool MapMgr::Do() { #ifdef WIN32 threadid=GetCurrentThreadId(); #endif thread_running = true; ThreadState =THREADSTATE_BUSY; SetThreadName("Map mgr - M%u|I%u",this->_mapId ,this->m_instanceID); ObjectSet::iterator i; uint32 last_exec=getMSTime(); /* create static objects */ for(GOSpawnList::iterator itr = _map->staticSpawns.GOSpawns.begin(); itr != _map->staticSpawns.GOSpawns.end(); ++itr) { GameObject * obj = CreateGameObject((*itr)->entry); obj->Load((*itr)); _mapWideStaticObjects.insert(obj); } for(CreatureSpawnList::iterator itr = _map->staticSpawns.CreatureSpawns.begin(); itr != _map->staticSpawns.CreatureSpawns.end(); ++itr) { Creature * obj = CreateCreature((*itr)->entry); obj->Load(*itr, 0, pMapInfo); _mapWideStaticObjects.insert(obj); } /* add static objects */ for(set<Object*>::iterator itr = _mapWideStaticObjects.begin(); itr != _mapWideStaticObjects.end(); ++itr) PushStaticObject(*itr); /* load corpses */ objmgr.LoadCorpses(this); // always declare local variables outside of the loop! // otherwise theres a lot of sub esp; going on. uint32 exec_time, exec_start; #ifdef WIN32 HANDLE hThread = GetCurrentThread(); #endif while((ThreadState != THREADSTATE_TERMINATE) && !_shutdown) { exec_start=getMSTime(); //first push to world new objects m_objectinsertlock.Acquire();//<<<<<<<<<<<<<<<< if(m_objectinsertpool.size()) { for(i=m_objectinsertpool.begin();i!=m_objectinsertpool.end();i++) { //PushObject(*i); (*i)->PushToWorld(this); } m_objectinsertpool.clear(); } m_objectinsertlock.Release();//>>>>>>>>>>>>>>>> //------------------------------------------------------- //Now update sessions of this map + objects _PerformObjectDuties(); last_exec=getMSTime(); exec_time=last_exec-exec_start; if(exec_time<MAP_MGR_UPDATE_PERIOD) { /* The common place I see this is waiting for a Win32 thread to exit. I used to come up with all sorts of goofy, elaborate event-based systems to do this myself until I discovered that thread handles are waitable. Just use WaitForSingleObject() on the thread handle and you're done. No risking race conditions with the thread exit code. I think pthreads has pthread_join() for this too. - http://www.virtualdub.org/blog/pivot/entry.php?id=62 */ #ifdef WIN32 WaitForSingleObject(hThread, MAP_MGR_UPDATE_PERIOD-exec_time); #else Sleep(MAP_MGR_UPDATE_PERIOD-exec_time); #endif } ////////////////////////////////////////////////////////////////////////// // Check if we have to die :P ////////////////////////////////////////////////////////////////////////// if(InactiveMoveTime && UNIXTIME >= InactiveMoveTime) break; } // Clear the instance's reference to us. if(m_battleground) { BattlegroundManager.DeleteBattleground(m_battleground); sInstanceMgr.DeleteBattlegroundInstance( GetMapId(), GetInstanceID() ); } if(pInstance) { // check for a non-raid instance, these expire after 10 minutes. if(GetMapInfo()->type == INSTANCE_NONRAID || pInstance->m_isBattleground) { pInstance->m_mapMgr = NULL; sInstanceMgr._DeleteInstance(pInstance, true); } else { // just null out the pointer pInstance->m_mapMgr=NULL; } } else if(GetMapInfo()->type == INSTANCE_NULL) sInstanceMgr.m_singleMaps[GetMapId()] = NULL; // Teleport any left-over players out. TeleportPlayers(); thread_running = false; if(thread_kill_only) return false; // delete ourselves delete this; // already deleted, so the threadpool doesn't have to. return false; }
bool MapMgr::Do() { #ifdef WIN32 threadid = GetCurrentThreadId(); #endif t_currentMapContext.set(this); thread_running = true; ThreadState.SetVal(THREADSTATE_BUSY); SetThreadName("Map mgr - M%u|I%u", this->_mapId , this->m_instanceID); ObjectSet::iterator i; uint32 last_exec = getMSTime(); // Create Instance script LoadInstanceScript(); /* create static objects */ for(GOSpawnList::iterator itr = _map->staticSpawns.GOSpawns.begin(); itr != _map->staticSpawns.GOSpawns.end(); ++itr) { GameObject* obj = CreateGameObject((*itr)->entry); obj->Load((*itr)); PushStaticObject(obj); } // Call script OnLoad virtual procedure CALL_INSTANCE_SCRIPT_EVENT(this, OnLoad)(); for(CreatureSpawnList::iterator itr = _map->staticSpawns.CreatureSpawns.begin(); itr != _map->staticSpawns.CreatureSpawns.end(); ++itr) { Creature* obj = CreateCreature((*itr)->entry); obj->Load(*itr, 0, pMapInfo); PushStaticObject(obj); } /* load corpses */ objmgr.LoadCorpses(this); worldstateshandler.InitWorldStates( objmgr.GetWorldStatesForMap( _mapId ) ); worldstateshandler.setObserver( this ); // always declare local variables outside of the loop! // otherwise there's a lot of sub esp; going on. uint32 exec_time, exec_start; while((GetThreadState() != THREADSTATE_TERMINATE) && !_shutdown) { exec_start = getMSTime(); ///////////////////////////////////////////// first push to world new objects //////////////////////////////////////////// m_objectinsertlock.Acquire(); if(m_objectinsertpool.size()) { for(i = m_objectinsertpool.begin(); i != m_objectinsertpool.end(); ++i) { Object* o = *i; o->PushToWorld(this); } m_objectinsertpool.clear(); } m_objectinsertlock.Release(); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Now update sessions of this map + objects _PerformObjectDuties(); last_exec = getMSTime(); exec_time = last_exec - exec_start; if(exec_time < MAP_MGR_UPDATE_PERIOD) { Arcemu::Sleep(MAP_MGR_UPDATE_PERIOD - exec_time); } ////////////////////////////////////////////////////////////////////////// // Check if we have to die :P ////////////////////////////////////////////////////////////////////////// if(InactiveMoveTime && UNIXTIME >= InactiveMoveTime) break; } // Teleport any left-over players out. TeleportPlayers(); // Clear the instance's reference to us. if(m_battleground) { BattlegroundManager.DeleteBattleground(m_battleground); sInstanceMgr.DeleteBattlegroundInstance(GetMapId(), GetInstanceID()); } if(pInstance) { // check for a non-raid instance, these expire after 10 minutes. if(GetMapInfo()->type == INSTANCE_NONRAID || pInstance->m_isBattleground) { pInstance->m_mapMgr = NULL; sInstanceMgr._DeleteInstance(pInstance, true); pInstance = NULL; } else { // just null out the pointer pInstance->m_mapMgr = NULL; } } else if(GetMapInfo()->type == INSTANCE_NULL) sInstanceMgr.m_singleMaps[GetMapId()] = NULL; thread_running = false; if(thread_kill_only) return false; // delete ourselves delete this; // already deleted, so the threadpool doesn't have to. return false; }