Implemented the OnWorldTick hook.
Triggerred for each world every time it ticks, parameters are the cWorld and the previous tick length (a_Dt)
This commit is contained in:
parent
909a9c6973
commit
dd030fa892
@ -94,6 +94,7 @@ public:
|
||||
virtual bool OnUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player) = 0;
|
||||
virtual bool OnWeatherChanged (cWorld & a_World) = 0;
|
||||
virtual bool OnWeatherChanging (cWorld & a_World, eWeather & a_NewWeather) = 0;
|
||||
virtual bool OnWorldTick (cWorld & a_World, float a_Dt) = 0;
|
||||
|
||||
/** Handles the command split into a_Split, issued by player a_Player.
|
||||
Command permissions have already been checked.
|
||||
|
@ -734,6 +734,17 @@ bool cPlugin_NewLua::OnWeatherChanging(cWorld & a_World, eWeather & a_NewWeather
|
||||
|
||||
|
||||
|
||||
bool cPlugin_NewLua::OnWorldTick(cWorld & a_World, float a_Dt)
|
||||
{
|
||||
cCSLock Lock(m_CriticalSection);
|
||||
m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_WORLD_TICK), &a_World, a_Dt);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin_NewLua::HandleCommand(const AStringVector & a_Split, cPlayer * a_Player)
|
||||
{
|
||||
ASSERT(!a_Split.empty());
|
||||
@ -908,6 +919,7 @@ const char * cPlugin_NewLua::GetHookFnName(cPluginManager::PluginHook a_Hook)
|
||||
case cPluginManager::HOOK_UPDATING_SIGN: return "OnUpdatingSign";
|
||||
case cPluginManager::HOOK_WEATHER_CHANGED: return "OnWeatherChanged";
|
||||
case cPluginManager::HOOK_WEATHER_CHANGING: return "OnWeatherChanging";
|
||||
case cPluginManager::HOOK_WORLD_TICK: return "OnWorldTick";
|
||||
default: return NULL;
|
||||
} // switch (a_Hook)
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ public:
|
||||
virtual bool OnUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player) override;
|
||||
virtual bool OnWeatherChanged (cWorld & a_World) override;
|
||||
virtual bool OnWeatherChanging (cWorld & a_World, eWeather & a_NewWeather) override;
|
||||
virtual bool OnWorldTick (cWorld & a_World, float a_Dt) override;
|
||||
|
||||
virtual bool HandleCommand(const AStringVector & a_Split, cPlayer * a_Player) override;
|
||||
|
||||
|
@ -1180,6 +1180,27 @@ bool cPluginManager::CallHookWeatherChanging(cWorld & a_World, eWeather & a_NewW
|
||||
|
||||
|
||||
|
||||
bool cPluginManager::CallHookWorldTick(cWorld & a_World, float a_Dt)
|
||||
{
|
||||
HookMap::iterator Plugins = m_Hooks.find(HOOK_WORLD_TICK);
|
||||
if (Plugins == m_Hooks.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
|
||||
{
|
||||
if ((*itr)->OnWorldTick(a_World, a_Dt))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPluginManager::HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions)
|
||||
{
|
||||
ASSERT(a_Player != NULL);
|
||||
|
@ -106,6 +106,7 @@ public: // tolua_export
|
||||
HOOK_UPDATING_SIGN,
|
||||
HOOK_WEATHER_CHANGED,
|
||||
HOOK_WEATHER_CHANGING,
|
||||
HOOK_WORLD_TICK,
|
||||
|
||||
// Note that if a hook type is added, it may need processing in cPlugin::CanAddHook() descendants,
|
||||
// and it definitely needs adding in cPlugin_NewLua::GetHookFnName() !
|
||||
@ -184,6 +185,7 @@ public: // tolua_export
|
||||
bool CallHookUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player);
|
||||
bool CallHookWeatherChanged (cWorld & a_World);
|
||||
bool CallHookWeatherChanging (cWorld & a_World, eWeather & a_NewWeather);
|
||||
bool CallHookWorldTick (cWorld & a_World, float a_Dt);
|
||||
|
||||
bool DisablePlugin(const AString & a_PluginName); // tolua_export
|
||||
bool LoadPlugin (const AString & a_PluginName); // tolua_export
|
||||
|
@ -576,6 +576,9 @@ void cWorld::Stop(void)
|
||||
|
||||
void cWorld::Tick(float a_Dt)
|
||||
{
|
||||
// Call the plugins
|
||||
cPluginManager::Get()->CallHookWorldTick(*this, a_Dt);
|
||||
|
||||
// We need sub-tick precision here, that's why we store the time in seconds and calculate ticks off of it
|
||||
m_WorldAgeSecs += (double)a_Dt / 1000.0;
|
||||
m_TimeOfDaySecs += (double)a_Dt / 1000.0;
|
||||
|
Loading…
Reference in New Issue
Block a user