Optimize storage for eventAI. Store as Map of creature id's linked to vectors of events used by that creature id

Author of both commits: NoFantasy.

--HG--
branch : trunk
This commit is contained in:
raczman
2009-03-31 00:15:17 +02:00
parent 8e308da259
commit 075d8a44a5
3 changed files with 25 additions and 18 deletions

View File

@@ -52,7 +52,7 @@ UNORDERED_MAP<int32, StringTextData> TextMap;
//*** EventAI data ***
//Event AI structure. Used exclusivly by mob_event_ai.cpp (60 bytes each)
std::list<EventAI_Event> EventAI_Event_List;
UNORDERED_MAP<uint32, std::vector<EventAI_Event> > EventAI_Event_Map;
//Event AI summon structure. Used exclusivly by mob_event_ai.cpp.
UNORDERED_MAP<uint32, EventAI_Summon> EventAI_Summon_Map;
@@ -901,7 +901,7 @@ void LoadDatabase()
"FROM eventai_scripts");
//Drop Existing EventAI List
EventAI_Event_List.clear();
EventAI_Event_Map.clear();
outstring_log("TSCR: Loading EventAI scripts...");
if (result)
@@ -919,6 +919,7 @@ void LoadDatabase()
temp.event_id = fields[0].GetUInt32();
uint32 i = temp.event_id;
temp.creature_id = fields[1].GetUInt32();
uint32 creature_id = temp.creature_id;
temp.event_type = fields[2].GetUInt16();
temp.event_inverse_phase_mask = fields[3].GetUInt32();
temp.event_chance = fields[4].GetUInt8();
@@ -1282,7 +1283,8 @@ void LoadDatabase()
}
//Add to list
EventAI_Event_List.push_back(temp);
EventAI_Event_Map[creature_id].push_back(temp);
++Count;
} while (result->NextRow());

View File

@@ -1381,15 +1381,17 @@ CreatureAI* GetAI_Mob_EventAI(Creature *pCreature)
{
//Select events by creature id
std::list<EventHolder> EventList;
uint32 ID = pCreature->GetEntry();
std::list<EventAI_Event>::iterator i;
//Find creature id in the Event map
UNORDERED_MAP<uint32, std::vector<EventAI_Event> >::iterator CreatureEvents = EventAI_Event_Map.find(pCreature->GetEntry());
for (i = EventAI_Event_List.begin(); i != EventAI_Event_List.end(); ++i)
if (CreatureEvents != EventAI_Event_Map.end())
{
if ((*i).creature_id == ID)
std::vector<EventAI_Event>::iterator i;
for (i = (*CreatureEvents).second.begin(); i != (*CreatureEvents).second.end(); ++i)
{
//Debug check
//Debug check
#ifndef _DEBUG
if ((*i).event_flags & EFLAG_DEBUG_ONLY)
continue;
@@ -1404,16 +1406,19 @@ CreatureAI* GetAI_Mob_EventAI(Creature *pCreature)
EventList.push_back(EventHolder(*i));
}
}
//EventAI is pointless to use without events and may cause crashes
if (EventList.empty())
{
if (EAI_ErrorLevel > 1)
error_db_log("SD2: Eventlist for Creature %u is empty but creature is using Mob_EventAI. Preventing EventAI on this creature.", pCreature->GetEntry());
return NULL;
}
//EventMap had events but they were not added because they must be for instance
if (EventList.empty())
{
if (EAI_ErrorLevel > 1)
error_db_log("SD2: CreatureId has events but no events added to list because of instance flags.", pCreature->GetEntry());
}
}
else
{
if (EAI_ErrorLevel > 1)
error_db_log("SD2: EventMap for Creature %u is empty but creature is using Mob_EventAI.", pCreature->GetEntry());
}
return new Mob_EventAI (pCreature, EventList);
}

View File

@@ -186,7 +186,7 @@ struct EventAI_Event
};
//Event_Map
extern std::list<EventAI_Event> EventAI_Event_List;
extern UNORDERED_MAP<uint32, std::vector<EventAI_Event> > EventAI_Event_Map;
struct EventAI_Summon
{