New hook, E_PLUGIN_CHUNK_GENERATED, called after each chunk is generated (the chunk is already present in cWorld)

git-svn-id: http://mc-server.googlecode.com/svn/trunk@558 0a769ca7-a7f5-676a-18bf-c427514a06d6
master
madmaxoft@gmail.com 2012-06-05 15:20:48 +00:00
parent e99263f4d0
commit d832996e19
10 changed files with 287 additions and 856 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 06/04/12 10:48:42.
** Generated automatically by tolua++-1.0.92 on 06/05/12 17:10:08.
*/
/* Exported function */

View File

@ -9,6 +9,8 @@
#include "CompoGen.h"
#include "StructGen.h"
#include "FinishGen.h"
#include "cRoot.h"
#include "cPluginManager.h"
@ -484,6 +486,8 @@ void cChunkGenerator::DoGenerate(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
Entities, BlockEntities,
true
);
cRoot::Get()->GetPluginManager()->CallHook(cPluginManager::E_PLUGIN_CHUNK_GENERATED, 3, m_World, a_ChunkX, a_ChunkZ);
}

View File

@ -13,8 +13,13 @@ class cPickup;
class cItem;
class cEntity;
class cPawn;
class cWorld;
struct TakeDamageInfo;
// tolua_begin
class cPlugin
{
@ -43,6 +48,7 @@ public:
virtual void OnPlayerMove( cPlayer* a_Player ) { (void)a_Player; }
virtual void OnTakeDamage( cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo ) { (void)a_Pawn; (void)a_TakeDamageInfo; }
virtual bool OnKilled( cPawn* a_Killed, cEntity* a_Killer ) { (void)a_Killed; (void)a_Killer; return false; }
virtual void OnChunkGenerated(cWorld * a_World, int a_ChunkX, int a_ChunkZ) {}
// Accessors
const char* GetName() const { return m_Name.c_str(); }
@ -85,3 +91,7 @@ private:
std::string m_Name;
int m_Version;
}; //tolua_export

View File

@ -363,6 +363,25 @@ bool cPluginManager::CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... )
break;
}
case E_PLUGIN_CHUNK_GENERATED:
{
if (a_NumArgs != 3)
{
break;
}
va_list argptr;
va_start( argptr, a_NumArgs);
cWorld * World = va_arg(argptr, cWorld *);
int ChunkX = va_arg(argptr, int);
int ChunkZ = va_arg(argptr, int);
va_end (argptr);
for( PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr )
{
(*itr)->OnChunkGenerated(World, ChunkX, ChunkZ);
}
break;
}
default:
{
LOGWARNING("cPluginManager: Calling Unknown hook: %i", a_Hook );

View File

@ -12,22 +12,24 @@ public: //tolua_export
// Called each tick
virtual void Tick(float a_Dt);
enum PluginHook //tolua_export
{ //tolua_export
E_PLUGIN_TICK, //tolua_export
E_PLUGIN_CHAT, //tolua_export
E_PLUGIN_COLLECT_ITEM, //tolua_export
E_PLUGIN_BLOCK_DIG, //tolua_export
E_PLUGIN_BLOCK_PLACE, //tolua_export
E_PLUGIN_DISCONNECT, //tolua_export
E_PLUGIN_HANDSHAKE, //tolua_export
E_PLUGIN_LOGIN, //tolua_export
E_PLUGIN_PLAYER_SPAWN, //tolua_export
E_PLUGIN_PLAYER_JOIN, //tolua_export
E_PLUGIN_PLAYER_MOVE, //tolua_export
E_PLUGIN_TAKE_DAMAGE, //tolua_export
E_PLUGIN_KILLED, //tolua_export
}; //tolua_export
enum PluginHook // tolua_export
{ // tolua_export
E_PLUGIN_TICK, // tolua_export
E_PLUGIN_CHAT, // tolua_export
E_PLUGIN_COLLECT_ITEM, // tolua_export
E_PLUGIN_BLOCK_DIG, // tolua_export
E_PLUGIN_BLOCK_PLACE, // tolua_export
E_PLUGIN_DISCONNECT, // tolua_export
E_PLUGIN_HANDSHAKE, // tolua_export
E_PLUGIN_LOGIN, // tolua_export
E_PLUGIN_PLAYER_SPAWN, // tolua_export
E_PLUGIN_PLAYER_JOIN, // tolua_export
E_PLUGIN_PLAYER_MOVE, // tolua_export
E_PLUGIN_TAKE_DAMAGE, // tolua_export
E_PLUGIN_KILLED, // tolua_export
E_PLUGIN_CHUNK_GENERATED, // tolua_export
E_PLUGIN_CHUNK_GENERATING, // tolua_export
}; // tolua_export
static cPluginManager * GetPluginManager(); //tolua_export

View File

@ -135,6 +135,10 @@ void cPlugin_NewLua::Tick(float a_Dt)
CallFunction(1, 0, "Tick");
}
bool cPlugin_NewLua::OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player )
{
cCSLock Lock( m_CriticalSection );
@ -151,6 +155,10 @@ bool cPlugin_NewLua::OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player )
return bRetVal;
}
bool cPlugin_NewLua::OnDisconnect( std::string a_Reason, cPlayer* a_Player )
{
cCSLock Lock( m_CriticalSection );
@ -167,6 +175,10 @@ bool cPlugin_NewLua::OnDisconnect( std::string a_Reason, cPlayer* a_Player )
return bRetVal;
}
bool cPlugin_NewLua::OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player )
{
cCSLock Lock( m_CriticalSection );
@ -183,6 +195,10 @@ bool cPlugin_NewLua::OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_
return bRetVal;
}
bool cPlugin_NewLua::OnBlockDig( cPacket_BlockDig* a_PacketData, cPlayer* a_Player, cItem* a_PickupItem )
{
cCSLock Lock( m_CriticalSection );
@ -200,6 +216,10 @@ bool cPlugin_NewLua::OnBlockDig( cPacket_BlockDig* a_PacketData, cPlayer* a_Play
return bRetVal;
}
bool cPlugin_NewLua::OnChat( const char* a_Chat, cPlayer* a_Player )
{
cCSLock Lock( m_CriticalSection );
@ -216,6 +236,10 @@ bool cPlugin_NewLua::OnChat( const char* a_Chat, cPlayer* a_Player )
return bRetVal;
}
bool cPlugin_NewLua::OnLogin( cPacket_Login* a_PacketData )
{
cCSLock Lock( m_CriticalSection );
@ -231,6 +255,10 @@ bool cPlugin_NewLua::OnLogin( cPacket_Login* a_PacketData )
return bRetVal;
}
void cPlugin_NewLua::OnPlayerSpawn( cPlayer* a_Player )
{
cCSLock Lock( m_CriticalSection );
@ -242,6 +270,10 @@ void cPlugin_NewLua::OnPlayerSpawn( cPlayer* a_Player )
CallFunction(1, 0, "OnPlayerSpawn");
}
bool cPlugin_NewLua::OnPlayerJoin( cPlayer* a_Player )
{
cCSLock Lock( m_CriticalSection );
@ -257,6 +289,10 @@ bool cPlugin_NewLua::OnPlayerJoin( cPlayer* a_Player )
return bRetVal;
}
void cPlugin_NewLua::OnPlayerMove( cPlayer* a_Player )
{
cCSLock Lock( m_CriticalSection );
@ -268,6 +304,10 @@ void cPlugin_NewLua::OnPlayerMove( cPlayer* a_Player )
CallFunction(1, 0, "OnPlayerMove");
}
void cPlugin_NewLua::OnTakeDamage( cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo )
{
cCSLock Lock( m_CriticalSection );
@ -280,6 +320,10 @@ void cPlugin_NewLua::OnTakeDamage( cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageIn
CallFunction(2, 0, "OnTakeDamage");
}
bool cPlugin_NewLua::OnKilled( cPawn* a_Killed, cEntity* a_Killer )
{
cCSLock Lock( m_CriticalSection );
@ -297,6 +341,28 @@ bool cPlugin_NewLua::OnKilled( cPawn* a_Killed, cEntity* a_Killer )
}
void cPlugin_NewLua::OnChunkGenerated(cWorld * a_World, int a_ChunkX, int a_ChunkZ)
{
cCSLock Lock(m_CriticalSection);
if (!PushFunction("OnChunkGenerated"))
{
return;
}
tolua_pushusertype(m_LuaState, a_World, "cWorld");
tolua_pushnumber (m_LuaState, a_ChunkX);
tolua_pushnumber (m_LuaState, a_ChunkZ);
CallFunction(3, 0, "OnChunkGenerated");
}
cWebPlugin_Lua* cPlugin_NewLua::CreateWebPlugin(lua_State* a_LuaState)
{
cCSLock Lock( m_CriticalSection );

View File

@ -25,19 +25,19 @@ public: //tolua_export
virtual void Tick(float a_Dt); //tolua_export
//tolua_begin
virtual bool OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player );
virtual bool OnDisconnect( std::string a_Reason, cPlayer* a_Player );
virtual bool OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player );
virtual bool OnBlockDig( cPacket_BlockDig* a_PacketData, cPlayer* a_Player, cItem* a_PickupItem );
virtual bool OnChat( const char* a_Chat, cPlayer* a_Player );
virtual bool OnLogin( cPacket_Login* a_PacketData );
virtual void OnPlayerSpawn( cPlayer* a_Player );
virtual bool OnPlayerJoin( cPlayer* a_Player );
virtual void OnPlayerMove( cPlayer* a_Player );
virtual void OnTakeDamage( cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo );
virtual bool OnKilled( cPawn* a_Killed, cEntity* a_Killer );
//tolua_end
virtual bool OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player ) override;
virtual bool OnDisconnect( std::string a_Reason, cPlayer* a_Player ) override;
virtual bool OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player ) override;
virtual bool OnBlockDig( cPacket_BlockDig* a_PacketData, cPlayer* a_Player, cItem* a_PickupItem ) override;
virtual bool OnChat( const char* a_Chat, cPlayer* a_Player ) override;
virtual bool OnLogin( cPacket_Login* a_PacketData ) override;
virtual void OnPlayerSpawn( cPlayer* a_Player ) override;
virtual bool OnPlayerJoin( cPlayer* a_Player ) override;
virtual void OnPlayerMove( cPlayer* a_Player ) override;
virtual void OnTakeDamage( cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo ) override;
virtual bool OnKilled( cPawn* a_Killed, cEntity* a_Killer ) override;
virtual void OnChunkGenerated(cWorld * a_World, int a_ChunkX, int a_ChunkZ) override;
lua_State* GetLuaState() { return m_LuaState; }

View File

@ -141,6 +141,9 @@ void cRoot::Start()
LOG("Starting Authenticator...");
m_Authenticator.Start();
LOG("Starting worlds...");
StartWorlds();
LOG("Starting server...");
m_Server->StartListenThread();
//cHeartBeat* HeartBeat = new cHeartBeat();
@ -202,35 +205,49 @@ void cRoot::LoadGlobalSettings()
void cRoot::LoadWorlds()
void cRoot::LoadWorlds(void)
{
cIniFile IniFile("settings.ini"); IniFile.ReadFile();
// First get the default world
AString DefaultWorldName = IniFile.GetValue("Worlds", "DefaultWorld", "world");
m_pState->pDefaultWorld = new cWorld( DefaultWorldName.c_str() );
m_pState->pDefaultWorld->InitializeSpawn();
m_pState->WorldsByName[ DefaultWorldName ] = m_pState->pDefaultWorld;
// Then load the other worlds
unsigned int KeyNum = IniFile.FindKey("Worlds");
unsigned int NumWorlds = IniFile.GetNumValues( KeyNum );
if ( NumWorlds > 0 )
if (NumWorlds <= 0)
{
for (unsigned int i = 0; i < NumWorlds; i++)
return;
}
for (unsigned int i = 0; i < NumWorlds; i++)
{
std::string ValueName = IniFile.GetValueName(KeyNum, i );
if (ValueName.compare("World") != 0)
{
std::string ValueName = IniFile.GetValueName(KeyNum, i );
if( ValueName.compare("World") == 0 )
{
std::string WorldName = IniFile.GetValue(KeyNum, i );
if (!WorldName.empty())
{
cWorld* NewWorld = new cWorld( WorldName.c_str() );
NewWorld->InitializeSpawn();
m_pState->WorldsByName[ WorldName ] = NewWorld;
}
}
continue;
}
std::string WorldName = IniFile.GetValue(KeyNum, i );
if (WorldName.empty())
{
continue;
}
cWorld* NewWorld = new cWorld( WorldName.c_str() );
m_pState->WorldsByName[ WorldName ] = NewWorld;
} // for i - Worlds
}
void cRoot::StartWorlds(void)
{
for( WorldMap::iterator itr = m_pState->WorldsByName.begin(); itr != m_pState->WorldsByName.end(); ++itr )
{
itr->second->InitializeSpawn();
}
}
@ -238,7 +255,7 @@ void cRoot::LoadWorlds()
void cRoot::UnloadWorlds()
void cRoot::UnloadWorlds(void)
{
for( WorldMap::iterator itr = m_pState->WorldsByName.begin(); itr != m_pState->WorldsByName.end(); ++itr )
{

View File

@ -74,8 +74,13 @@ public:
private:
void LoadGlobalSettings();
void LoadWorlds();
void UnloadWorlds();
/// Loads the worlds from settings.ini, creates the worldmap
void LoadWorlds(void);
/// Starts each world's life
void StartWorlds(void);
void UnloadWorlds(void);
cServer * m_Server;
cMonsterConfig * m_MonsterConfig;