aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Scripting/ScriptMgr.h
diff options
context:
space:
mode:
authorXTZGZoReX <none@none>2010-08-09 19:53:21 +0200
committerXTZGZoReX <none@none>2010-08-09 19:53:21 +0200
commit70fc93da7b022f441b92d83fa2f4df48c2be2ae4 (patch)
treea01725c85fb5866442b4150679a79d01bff8bd43 /src/server/game/Scripting/ScriptMgr.h
parenta094d3e281ad03a4258027d5b3d02037f81be1cd (diff)
* Get rid of virtual function calls completely, seeing as they weren't necessary. Thanks to Ge0rG and Derex for enlightening me about this.....
* Also add map ID for EoE instance script (thanks Silinoron). --HG-- branch : trunk
Diffstat (limited to 'src/server/game/Scripting/ScriptMgr.h')
-rw-r--r--src/server/game/Scripting/ScriptMgr.h313
1 files changed, 93 insertions, 220 deletions
diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h
index c226e783d38..c98a1574d9d 100644
--- a/src/server/game/Scripting/ScriptMgr.h
+++ b/src/server/game/Scripting/ScriptMgr.h
@@ -91,7 +91,7 @@ void DoScriptText(int32 textEntry, WorldObject* pSource, Unit *pTarget = NULL);
MyScriptType(const char* name, uint32 someId)
: ScriptObject(name), _someId(someId)
{
- RegisterSelf();
+ ScriptMgr::ScriptRegistry<MyScriptType>::AddScript(this);
}
public:
@@ -107,14 +107,6 @@ void DoScriptText(int32 textEntry, WorldObject* pSource, Unit *pTarget = NULL);
virtual void OnAnotherEvent(uint32 someArg) = 0;
}
- RegisterSelf() should be defined in ScriptMgr.cpp, and simply registers the script
- with ScriptRegistry:
-
- void MyScriptType::RegisterSelf()
- {
- ScriptMgr::ScriptRegistry<MyScriptType>::AddScript(this);
- }
-
Next, you need to add a specialization for ScriptRegistry. Put this in the bottom of
ScriptMgr.cpp:
@@ -168,9 +160,6 @@ class ScriptObject
protected:
- // Call this to register the script with ScriptMgr.
- virtual void RegisterSelf() = 0;
-
ScriptObject(const char* name)
: _name(std::string(name))
{
@@ -204,17 +193,9 @@ template<class TObject> class UpdatableScript
class SpellHandlerScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- SpellHandlerScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ SpellHandlerScript(const char* name);
public:
@@ -226,17 +207,9 @@ class SpellHandlerScript : public ScriptObject
class AuraHandlerScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- AuraHandlerScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ AuraHandlerScript(const char* name);
public:
@@ -248,17 +221,9 @@ class AuraHandlerScript : public ScriptObject
class ServerScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- ServerScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ ServerScript(const char* name);
public:
@@ -290,17 +255,9 @@ class ServerScript : public ScriptObject
class WorldScript : public ScriptObject, public UpdatableScript<void>
{
- private:
-
- void RegisterSelf();
-
protected:
- WorldScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ WorldScript(const char* name);
public:
@@ -331,17 +288,9 @@ class WorldScript : public ScriptObject, public UpdatableScript<void>
class FormulaScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- FormulaScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ FormulaScript(const char* name);
public:
@@ -412,38 +361,16 @@ template<class TMap> class MapScript : public UpdatableScript<TMap>
class WorldMapScript : public ScriptObject, public MapScript<Map>
{
- private:
-
- void RegisterSelf();
-
protected:
- WorldMapScript(const char* name, uint32 mapId)
- : ScriptObject(name), MapScript<Map>(mapId)
- {
- if (GetEntry() && !GetEntry()->IsContinent())
- sLog.outError("WorldMapScript for map %u is invalid.", mapId);
- else
- RegisterSelf();
- }
+ WorldMapScript(const char* name, uint32 mapId);
};
class InstanceMapScript : public ScriptObject, public MapScript<InstanceMap>
{
- private:
-
- void RegisterSelf();
-
protected:
- InstanceMapScript(const char* name, uint32 mapId = 0)
- : ScriptObject(name), MapScript<InstanceMap>(mapId)
- {
- if (GetEntry() && !GetEntry()->IsDungeon())
- sLog.outError("InstanceMapScript for map %u is invalid.", mapId);
- else
- RegisterSelf();
- }
+ InstanceMapScript(const char* name, uint32 mapId);
public:
@@ -457,31 +384,14 @@ class BattlegroundMapScript : public ScriptObject, public MapScript<Battleground
{
protected:
- BattlegroundMapScript(const char* name, uint32 mapId)
- : ScriptObject(name), MapScript<BattlegroundMap>(mapId)
- {
- if (GetEntry() && !GetEntry()->IsBattleground())
- sLog.outError("BattlegroundMapScript for map %u is invalid.", mapId);
- else
- RegisterSelf();
- }
-
- void RegisterSelf();
+ BattlegroundMapScript(const char* name, uint32 mapId);
};
class ItemScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- ItemScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ ItemScript(const char* name);
public:
@@ -502,17 +412,9 @@ class ItemScript : public ScriptObject
class CreatureScript : public ScriptObject, public UpdatableScript<Creature>
{
- private:
-
- void RegisterSelf();
-
protected:
- CreatureScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ CreatureScript(const char* name);
public:
@@ -551,17 +453,9 @@ class CreatureScript : public ScriptObject, public UpdatableScript<Creature>
class GameObjectScript : public ScriptObject, public UpdatableScript<GameObject>
{
- private:
-
- void RegisterSelf();
-
protected:
- GameObjectScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ GameObjectScript(const char* name);
public:
@@ -594,17 +488,9 @@ class GameObjectScript : public ScriptObject, public UpdatableScript<GameObject>
class AreaTriggerScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- AreaTriggerScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ AreaTriggerScript(const char* name);
public:
@@ -616,17 +502,9 @@ class AreaTriggerScript : public ScriptObject
class BattlegroundScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- BattlegroundScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ BattlegroundScript(const char* name);
public:
@@ -638,17 +516,9 @@ class BattlegroundScript : public ScriptObject
class OutdoorPvPScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- OutdoorPvPScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ OutdoorPvPScript(const char* name);
public:
@@ -660,17 +530,9 @@ class OutdoorPvPScript : public ScriptObject
class CommandScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- CommandScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ CommandScript(const char* name);
public:
@@ -680,17 +542,9 @@ class CommandScript : public ScriptObject
class WeatherScript : public ScriptObject, public UpdatableScript<Weather>
{
- private:
-
- void RegisterSelf();
-
protected:
- WeatherScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ WeatherScript(const char* name);
public:
@@ -702,17 +556,9 @@ class WeatherScript : public ScriptObject, public UpdatableScript<Weather>
class AuctionHouseScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- AuctionHouseScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ AuctionHouseScript(const char* name);
public:
@@ -731,17 +577,9 @@ class AuctionHouseScript : public ScriptObject
class ConditionScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- ConditionScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ ConditionScript(const char* name);
public:
@@ -753,17 +591,9 @@ class ConditionScript : public ScriptObject
class VehicleScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- VehicleScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ VehicleScript(const char* name);
public:
@@ -791,32 +621,16 @@ class VehicleScript : public ScriptObject
class DynamicObjectScript : public ScriptObject, public UpdatableScript<DynamicObject>
{
- private:
-
- void RegisterSelf();
-
protected:
- DynamicObjectScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ DynamicObjectScript(const char* name);
};
class TransportScript : public ScriptObject, public UpdatableScript<Transport>
{
- private:
-
- void RegisterSelf();
-
protected:
- TransportScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ TransportScript(const char* name);
public:
@@ -837,17 +651,9 @@ class TransportScript : public ScriptObject, public UpdatableScript<Transport>
class AchievementCriteriaScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- AchievementCriteriaScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ AchievementCriteriaScript(const char* name);
public:
@@ -1047,6 +853,76 @@ class ScriptMgr
// after server startup.
static ScriptMap ScriptPointerList;
+ static void AddScript(TScript* const script)
+ {
+ ASSERT(script);
+
+ // See if the script is using the same memory as another script. If this happens, it means that
+ // someone forgot to allocate new memory for a script.
+ for (ScriptMapIterator it = ScriptPointerList.begin(); it != ScriptPointerList.end(); ++it)
+ {
+ if (it->second == script)
+ {
+ sLog.outError("Script '%s' has same memory pointer as '%s'.",
+ script->GetName().c_str(), it->second->GetName().c_str());
+
+ return;
+ }
+ }
+
+ if (script->IsDatabaseBound())
+ {
+ // Get an ID for the script. An ID only exists if it's a script that is assigned in the database
+ // through a script name (or similar).
+ uint32 id = GetScriptId(script->GetName().c_str());
+ if (id)
+ {
+ // Try to find an existing script.
+ bool existing = false;
+ for (ScriptMapIterator it = ScriptPointerList.begin(); it != ScriptPointerList.end(); ++it)
+ {
+ // If the script names match...
+ if (it->second->GetName() == script->GetName())
+ {
+ // ... It exists.
+ existing = true;
+ break;
+ }
+ }
+
+ // If the script isn't assigned -> assign it!
+ if (!existing)
+ {
+ ScriptPointerList[id] = script;
+ sScriptMgr.IncrementScriptCount();
+ }
+ else
+ {
+ // If the script is already assigned -> delete it!
+ sLog.outError("Script '%s' already assigned with the same script name, so the script can't work.",
+ script->GetName().c_str());
+
+ delete script;
+ }
+ }
+ else
+ {
+ // The script uses a script name from database, but isn't assigned to anything.
+ if (script->GetName().find("example") == std::string::npos)
+ sLog.outErrorDb("Script named '%s' does not have a script name assigned in database.",
+ script->GetName().c_str());
+
+ delete script;
+ }
+ }
+ else
+ {
+ // We're dealing with a code-only script; just add it.
+ ScriptPointerList[_scriptIdCounter++] = script;
+ sScriptMgr.IncrementScriptCount();
+ }
+ }
+
// Gets a script by its ID (assigned by ObjectMgr).
static TScript* GetScriptById(uint32 id)
{
@@ -1056,9 +932,6 @@ class ScriptMgr
return NULL;
}
-
- // Attempts to add a new script to the list.
- static void AddScript(TScript* const script);
};
};