Added and updated map mthread

Thanks to the original mtmaps and openmaps creators
This commit is contained in:
Foereaper 2015-03-31 19:52:19 +02:00
parent 0491c3d5a7
commit a1f33ffd9f
12 changed files with 457 additions and 4 deletions

View File

@ -23,6 +23,7 @@ include_directories(
"${CMAKE_CURRENT_SOURCE_DIR}/AuctionHouseBot" "${CMAKE_CURRENT_SOURCE_DIR}/AuctionHouseBot"
"${CMAKE_CURRENT_SOURCE_DIR}/BattleGround" "${CMAKE_CURRENT_SOURCE_DIR}/BattleGround"
"${CMAKE_CURRENT_SOURCE_DIR}/ChatCommands" "${CMAKE_CURRENT_SOURCE_DIR}/ChatCommands"
"${CMAKE_CURRENT_SOURCE_DIR}/Maps"
"${CMAKE_CURRENT_SOURCE_DIR}/MotionGenerators" "${CMAKE_CURRENT_SOURCE_DIR}/MotionGenerators"
"${CMAKE_CURRENT_SOURCE_DIR}/Object" "${CMAKE_CURRENT_SOURCE_DIR}/Object"
"${CMAKE_CURRENT_SOURCE_DIR}/OutdoorPvP" "${CMAKE_CURRENT_SOURCE_DIR}/OutdoorPvP"
@ -39,9 +40,11 @@ include_directories(
"${CMAKE_SOURCE_DIR}/dep/include" "${CMAKE_SOURCE_DIR}/dep/include"
"${CMAKE_SOURCE_DIR}/src/shared" "${CMAKE_SOURCE_DIR}/src/shared"
"${CMAKE_SOURCE_DIR}/src/shared/Common" "${CMAKE_SOURCE_DIR}/src/shared/Common"
"${CMAKE_SOURCE_DIR}/src/shared/Database"
"${CMAKE_SOURCE_DIR}/src/shared/DataStores"
"${CMAKE_SOURCE_DIR}/src/shared/Utilities" "${CMAKE_SOURCE_DIR}/src/shared/Utilities"
"${CMAKE_SOURCE_DIR}/src/shared/Log" "${CMAKE_SOURCE_DIR}/src/shared/Log"
"${CMAKE_SOURCE_DIR}/src/shared/DataStores" "${CMAKE_SOURCE_DIR}/src/shared/Threading"
"${CMAKE_SOURCE_DIR}/src/framework" "${CMAKE_SOURCE_DIR}/src/framework"
"${CMAKE_BINARY_DIR}/src/shared" "${CMAKE_BINARY_DIR}/src/shared"
"${MYSQL_INCLUDE_DIR}" "${MYSQL_INCLUDE_DIR}"
@ -71,6 +74,13 @@ source_group("Chat Commands"
${SRC_GRP_CHAT_COMMANDS} ${SRC_GRP_CHAT_COMMANDS}
) )
#Map Threading group
file(GLOB SRC_GRP_MAP_THREAD Maps/*.cpp Maps/*.h)
source_group("Map Threading"
FILES
${SRC_GRP_MAP_THREAD}
)
#Motion Generator group #Motion Generator group
file(GLOB SRC_GRP_MOTION_GEN MotionGenerators/*.cpp MotionGenerators/*.h) file(GLOB SRC_GRP_MOTION_GEN MotionGenerators/*.cpp MotionGenerators/*.h)
source_group("Motion generators" source_group("Motion generators"
@ -138,6 +148,7 @@ set(LIBRARY_SRCS
${SRC_GRP_AHBOT} ${SRC_GRP_AHBOT}
${SRC_GRP_BATTLEGROUND} ${SRC_GRP_BATTLEGROUND}
${SRC_GRP_CHAT_COMMANDS} ${SRC_GRP_CHAT_COMMANDS}
${SRC_GRP_MAP_THREAD}
${SRC_GRP_MOTION_GEN} ${SRC_GRP_MOTION_GEN}
${SRC_GRP_MOVEMENT} ${SRC_GRP_MOVEMENT}
${SRC_GRP_OBJECT} ${SRC_GRP_OBJECT}

View File

@ -0,0 +1,151 @@
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2015 MaNGOS project <http://getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
#include "MapUpdater.h"
#include "DelayExecutor.h"
#include "Map.h"
#include "DatabaseEnv.h"
#include <ace/Guard_T.h>
#include <ace/Method_Request.h>
class WDBThreadStartReq1 : public ACE_Method_Request
{
public:
WDBThreadStartReq1()
{
}
virtual int call()
{
return 0;
}
};
class WDBThreadEndReq1 : public ACE_Method_Request
{
public:
WDBThreadEndReq1()
{
}
virtual int call()
{
return 0;
}
};
class MapUpdateRequest : public ACE_Method_Request
{
private:
Map& m_map;
MapUpdater& m_updater;
ACE_UINT32 m_diff;
public:
MapUpdateRequest(Map& m, MapUpdater& u, ACE_UINT32 d)
: m_map(m), m_updater(u), m_diff(d)
{
}
virtual int call()
{
m_map.Update (m_diff);
m_updater.update_finished();
return 0;
}
};
MapUpdater::MapUpdater():
m_executor(), m_mutex(), m_condition(m_mutex), pending_requests(0)
{
}
MapUpdater::~MapUpdater()
{
deactivate();
}
int MapUpdater::activate(size_t num_threads)
{
return m_executor.activate((int)num_threads, new WDBThreadStartReq1, new WDBThreadEndReq1);
}
int MapUpdater::deactivate()
{
wait();
return m_executor.deactivate();
}
int MapUpdater::wait()
{
ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, m_mutex, -1);
while (pending_requests > 0)
m_condition.wait();
return 0;
}
int MapUpdater::schedule_update(Map& map, ACE_UINT32 diff)
{
ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, m_mutex, -1);
++pending_requests;
if (m_executor.execute(new MapUpdateRequest(map, *this, diff)) == -1)
{
ACE_DEBUG((LM_ERROR, ACE_TEXT("(%t) \n"), ACE_TEXT("Failed to schedule Map Update")));
--pending_requests;
return -1;
}
return 0;
}
bool MapUpdater::activated()
{
return m_executor.activated();
}
void MapUpdater::update_finished()
{
ACE_GUARD(ACE_Thread_Mutex, guard, m_mutex);
if (pending_requests == 0)
{
ACE_ERROR((LM_ERROR, ACE_TEXT("(%t)\n"), ACE_TEXT("MapUpdater::update_finished BUG, report to devs")));
return;
}
--pending_requests;
m_condition.broadcast();
}

View File

@ -0,0 +1,64 @@
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2015 MaNGOS project <http://getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
#ifndef _MAP_UPDATER_H_INCLUDED
#define _MAP_UPDATER_H_INCLUDED
#include <ace/Thread_Mutex.h>
#include <ace/Condition_Thread_Mutex.h>
#include "DelayExecutor.h"
class Map;
class MapUpdater
{
public:
MapUpdater();
virtual ~MapUpdater();
friend class MapUpdateRequest;
int schedule_update(Map& map, ACE_UINT32 diff);
int wait();
int activate(size_t num_threads);
int deactivate();
bool activated();
private:
DelayExecutor m_executor;
ACE_Thread_Mutex m_mutex;
ACE_Condition_Thread_Mutex m_condition;
size_t pending_requests;
void update_finished();
};
#endif //_MAP_UPDATER_H_INCLUDED

View File

@ -58,6 +58,11 @@ MapManager::~MapManager()
void void
MapManager::Initialize() MapManager::Initialize()
{ {
int num_threads(sWorld.getConfig(CONFIG_UINT32_NUMTHREADS));
// Start mtmaps if needed.
if (num_threads > 0 && m_updater.activate(num_threads) == -1)
abort();
InitStateMachine(); InitStateMachine();
InitMaxInstanceId(); InitMaxInstanceId();
} }
@ -180,8 +185,16 @@ void MapManager::Update(uint32 diff)
if (!i_timer.Passed()) if (!i_timer.Passed())
{ return; } { return; }
for (MapMapType::iterator iter = i_maps.begin(); iter != i_maps.end(); ++iter) for (MapMapType::iterator iter=i_maps.begin(); iter != i_maps.end(); ++iter)
{ iter->second->Update((uint32)i_timer.GetCurrent()); } {
if (m_updater.activated())
m_updater.schedule_update(*iter->second, (uint32)i_timer.GetCurrent());
else
iter->second->Update((uint32)i_timer.GetCurrent());
}
if (m_updater.activated())
m_updater.wait();
for (TransportSet::iterator iter = m_Transports.begin(); iter != m_Transports.end(); ++iter) for (TransportSet::iterator iter = m_Transports.begin(); iter != m_Transports.end(); ++iter)
{ {
@ -244,6 +257,9 @@ void MapManager::UnloadAll()
} }
TerrainManager::Instance().UnloadAll(); TerrainManager::Instance().UnloadAll();
if (m_updater.activated())
m_updater.deactivate();
} }
void MapManager::InitMaxInstanceId() void MapManager::InitMaxInstanceId()
@ -260,6 +276,8 @@ void MapManager::InitMaxInstanceId()
uint32 MapManager::GetNumInstances() uint32 MapManager::GetNumInstances()
{ {
Guard guard(*this);
uint32 ret = 0; uint32 ret = 0;
for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr) for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr)
{ {
@ -272,6 +290,8 @@ uint32 MapManager::GetNumInstances()
uint32 MapManager::GetNumPlayersInInstances() uint32 MapManager::GetNumPlayersInInstances()
{ {
Guard guard(*this);
uint32 ret = 0; uint32 ret = 0;
for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr) for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr)
{ {

View File

@ -31,6 +31,7 @@
#include <ace/Recursive_Thread_Mutex.h> #include <ace/Recursive_Thread_Mutex.h>
#include "Map.h" #include "Map.h"
#include "GridStates.h" #include "GridStates.h"
#include "MapUpdater.h"
class Transport; class Transport;
class BattleGround; class BattleGround;
@ -183,6 +184,7 @@ class MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::ClassLevelLockab
uint32 i_gridCleanUpDelay; uint32 i_gridCleanUpDelay;
MapMapType i_maps; MapMapType i_maps;
IntervalTimer i_timer; IntervalTimer i_timer;
MapUpdater m_updater;
uint32 i_MaxInstanceId; uint32 i_MaxInstanceId;
}; };

View File

@ -483,6 +483,8 @@ void World::LoadConfigSettings(bool reload)
if (reload) if (reload)
{ sMapMgr.SetGridCleanUpDelay(getConfig(CONFIG_UINT32_INTERVAL_GRIDCLEAN)); } { sMapMgr.SetGridCleanUpDelay(getConfig(CONFIG_UINT32_INTERVAL_GRIDCLEAN)); }
setConfig(CONFIG_UINT32_NUMTHREADS, "MapUpdateThreads", 2);
setConfigMin(CONFIG_UINT32_INTERVAL_MAPUPDATE, "MapUpdateInterval", 100, MIN_MAP_UPDATE_DELAY); setConfigMin(CONFIG_UINT32_INTERVAL_MAPUPDATE, "MapUpdateInterval", 100, MIN_MAP_UPDATE_DELAY);
if (reload) if (reload)
{ sMapMgr.SetMapUpdateInterval(getConfig(CONFIG_UINT32_INTERVAL_MAPUPDATE)); } { sMapMgr.SetMapUpdateInterval(getConfig(CONFIG_UINT32_INTERVAL_MAPUPDATE)); }

View File

@ -182,6 +182,7 @@ enum eConfigUInt32Values
CONFIG_UINT32_CHARDELETE_KEEP_DAYS, CONFIG_UINT32_CHARDELETE_KEEP_DAYS,
CONFIG_UINT32_CHARDELETE_METHOD, CONFIG_UINT32_CHARDELETE_METHOD,
CONFIG_UINT32_CHARDELETE_MIN_LEVEL, CONFIG_UINT32_CHARDELETE_MIN_LEVEL,
CONFIG_UINT32_NUMTHREADS,
CONFIG_UINT32_GUID_RESERVE_SIZE_CREATURE, CONFIG_UINT32_GUID_RESERVE_SIZE_CREATURE,
CONFIG_UINT32_GUID_RESERVE_SIZE_GAMEOBJECT, CONFIG_UINT32_GUID_RESERVE_SIZE_GAMEOBJECT,
CONFIG_UINT32_CREATURE_RESPAWN_AGGRO_DELAY, CONFIG_UINT32_CREATURE_RESPAWN_AGGRO_DELAY,

View File

@ -59,6 +59,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/src/game/BattleGround ${CMAKE_SOURCE_DIR}/src/game/BattleGround
${CMAKE_SOURCE_DIR}/src/game/Server ${CMAKE_SOURCE_DIR}/src/game/Server
${CMAKE_SOURCE_DIR}/src/game/WorldHandlers ${CMAKE_SOURCE_DIR}/src/game/WorldHandlers
${CMAKE_SOURCE_DIR}/src/game/Maps
${CMAKE_SOURCE_DIR}/src/game/Object ${CMAKE_SOURCE_DIR}/src/game/Object
${CMAKE_SOURCE_DIR}/src/game/Tools ${CMAKE_SOURCE_DIR}/src/game/Tools
${CMAKE_SOURCE_DIR}/src/game/References ${CMAKE_SOURCE_DIR}/src/game/References

View File

@ -131,6 +131,10 @@ BindIP = "0.0.0.0"
# Map update interval (in milliseconds) # Map update interval (in milliseconds)
# Default: 100 # Default: 100
# #
# MapUpdateThreads
# Number of map update threads to run
# Default: 2
#
# ChangeWeatherInterval # ChangeWeatherInterval
# Weather update interval (in milliseconds) # Weather update interval (in milliseconds)
# Default: 600000 (10 min) # Default: 600000 (10 min)
@ -220,6 +224,7 @@ GridUnload = 1
LoadAllGridsOnMaps = "" LoadAllGridsOnMaps = ""
GridCleanUpDelay = 300000 GridCleanUpDelay = 300000
MapUpdateInterval = 100 MapUpdateInterval = 100
MapUpdateThreads = 2
ChangeWeatherInterval = 600000 ChangeWeatherInterval = 600000
PlayerSave.Interval = 900000 PlayerSave.Interval = 900000
PlayerSave.Stats.MinLevel = 0 PlayerSave.Stats.MinLevel = 0

@ -1 +1 @@
Subproject commit f552a6edcdbca2da02a0293175c51c8758583999 Subproject commit c093690c3b148baa08cce8a2a62b13bbf613d383

View File

@ -0,0 +1,135 @@
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2015 MaNGOS project <http://getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
#include <ace/Singleton.h>
#include <ace/Thread_Mutex.h>
#include <ace/Log_Msg.h>
#include "DelayExecutor.h"
DelayExecutor* DelayExecutor::instance()
{
return ACE_Singleton<DelayExecutor, ACE_Thread_Mutex>::instance();
}
DelayExecutor::DelayExecutor()
: pre_svc_hook_(0), post_svc_hook_(0), activated_(false)
{
}
DelayExecutor::~DelayExecutor()
{
if (pre_svc_hook_)
delete pre_svc_hook_;
if (post_svc_hook_)
delete post_svc_hook_;
deactivate();
}
int DelayExecutor::deactivate()
{
if (!activated())
return -1;
activated(false);
queue_.queue()->deactivate();
wait();
return 0;
}
int DelayExecutor::svc()
{
if (pre_svc_hook_)
pre_svc_hook_->call();
for (;;)
{
ACE_Method_Request* rq = queue_.dequeue();
if (!rq)
break;
rq->call();
delete rq;
}
if (post_svc_hook_)
post_svc_hook_->call();
return 0;
}
int DelayExecutor::activate(int num_threads, ACE_Method_Request* pre_svc_hook, ACE_Method_Request* post_svc_hook)
{
if (activated())
return -1;
if (num_threads < 1)
return -1;
if (pre_svc_hook_)
delete pre_svc_hook_;
if (post_svc_hook_)
delete post_svc_hook_;
pre_svc_hook_ = pre_svc_hook;
post_svc_hook_ = post_svc_hook;
queue_.queue()->activate();
if (ACE_Task_Base::activate(THR_NEW_LWP | THR_JOINABLE | THR_INHERIT_SCHED, num_threads) == -1)
return -1;
activated(true);
return true;
}
int DelayExecutor::execute(ACE_Method_Request* new_req)
{
if (new_req == NULL)
return -1;
if (queue_.enqueue(new_req, (ACE_Time_Value*)&ACE_Time_Value::zero) == -1)
{
delete new_req;
ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%t) %p\n"), ACE_TEXT("DelayExecutor::execute enqueue")), -1);
}
return 0;
}
bool DelayExecutor::activated()
{
return activated_;
}
void DelayExecutor::activated(bool s)
{
activated_ = s;
}

View File

@ -0,0 +1,61 @@
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2015 MaNGOS project <http://getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
#ifndef _M_DELAY_EXECUTOR_H
#define _M_DELAY_EXECUTOR_H
#include <ace/Task.h>
#include <ace/Activation_Queue.h>
#include <ace/Method_Request.h>
class DelayExecutor : protected ACE_Task_Base
{
public:
DelayExecutor();
virtual ~DelayExecutor();
static DelayExecutor* instance();
int execute(ACE_Method_Request* new_req);
int activate(int num_threads = 1, ACE_Method_Request* pre_svc_hook = NULL, ACE_Method_Request* post_svc_hook = NULL);
int deactivate();
bool activated();
virtual int svc();
private:
ACE_Activation_Queue queue_;
ACE_Method_Request* pre_svc_hook_;
ACE_Method_Request* post_svc_hook_;
bool activated_;
void activated(bool s);
};
#endif // _M_DELAY_EXECUTOR_H