Skip to content

Commit

Permalink
CHANGED: Applied observer pattern to WorldStatesHandler.
Browse files Browse the repository at this point in the history
  • Loading branch information
dfighter1985 committed Aug 5, 2012
1 parent 2569f14 commit 7c0ad5e
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 105 deletions.
2 changes: 0 additions & 2 deletions cmake/world/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ SET(sources
Map.cpp
MapScriptInterface.cpp
MapMgr.cpp
MapMgrEventHandlers.cpp
MiscHandler.cpp
MovementHandler.cpp
NPCHandler.cpp
Expand Down Expand Up @@ -203,7 +202,6 @@ SET( headers
Guild.h
HonorHandler.h
Hunter.h
IEventListener.h
Item.h
ItemInterface.h
ItemPrototype.h
Expand Down
29 changes: 0 additions & 29 deletions src/arcemu-world/IEventListener.h

This file was deleted.

13 changes: 10 additions & 3 deletions src/arcemu-world/MapMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ MapMgr::MapMgr(Map* map, uint32 mapId, uint32 instanceid) :
CellHandler<MapCell>(map),
_mapId(mapId),
eventHolder(instanceid),
worldstateshandler( mapId, this )
worldstateshandler( mapId )
{
_terrain = new TerrainHolder(mapId);
CollideInterface.ActivateMap(mapId);
Expand Down Expand Up @@ -1278,6 +1278,7 @@ bool MapMgr::Do()
/* load corpses */
objmgr.LoadCorpses(this);
worldstateshandler.InitWorldStates( objmgr.GetWorldStatesForMap( _mapId ) );
worldstateshandler.setObserver( this );

// always declare local variables outside of the loop!
// otherwise there's a lot of sub esp; going on.
Expand Down Expand Up @@ -1952,6 +1953,12 @@ uint16 MapMgr::GetAreaID(float x, float y)
return itr->second->AreaId;
}

void MapMgr::Notify( uint32 type, uint32 data1, uint32 data2, uint32 data3 ){
CALL_MAPMGR_EVENT_HANDLER( this, type, data1, data2, data3 );
void MapMgr::onWorldStateUpdate( uint32 zone, uint32 field, uint32 value )
{
WorldPacket data( SMSG_UPDATE_WORLD_STATE, 8 );
data << uint32( field );
data << uint32( value );

SendPacketToPlayersInZone( zone, &data );
}

8 changes: 2 additions & 6 deletions src/arcemu-world/MapMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Transporter;

#define CALL_INSTANCE_SCRIPT_EVENT( Mgr, Func ) if ( Mgr != NULL && Mgr->GetScript() != NULL ) Mgr->GetScript()->Func

class SERVER_DECL MapMgr : public CellHandler <MapCell>, public EventableObject, public IEventListener, public CThread
class SERVER_DECL MapMgr : public CellHandler <MapCell>, public EventableObject, public CThread, public WorldStatesHandler::WorldStatesObserver
{
friend class MapCell;
friend class MapScriptInterface;
Expand Down Expand Up @@ -364,7 +364,7 @@ class SERVER_DECL MapMgr : public CellHandler <MapCell>, public EventableObject,

WorldStatesHandler& GetWorldStatesHandler(){ return worldstateshandler; }

void Notify( uint32 type = 0, uint32 data1 = 0, uint32 data2 = 0, uint32 data3 = 0 );
void onWorldStateUpdate( uint32 zone, uint32 field, uint32 value );

protected:
InstanceScript* mInstanceScript;
Expand All @@ -374,8 +374,4 @@ class SERVER_DECL MapMgr : public CellHandler <MapCell>, public EventableObject,

};

typedef void(*MapMgrEventHandler)( MapMgr*, uint32, uint32, uint32 );
void REGISTER_MAPMGR_EVENT_HANDLERS();
void CALL_MAPMGR_EVENT_HANDLER( MapMgr *mgr, uint32 type, uint32 data1, uint32 data2, uint32 data3 );

#endif
58 changes: 0 additions & 58 deletions src/arcemu-world/MapMgrEventHandlers.cpp

This file was deleted.

1 change: 0 additions & 1 deletion src/arcemu-world/StdAfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ extern SERVER_DECL SessionLogWriter* Player_Log;
#include "../arcemu-shared/CallBack.h"
#include "WordFilter.h"
#include "Events.h"
#include "IEventListener.h"
#include "EventMgr.h"
#include "EventableObject.h"
#include "Object.h"
Expand Down
2 changes: 0 additions & 2 deletions src/arcemu-world/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,6 @@ bool World::SetInitialWorldSettings()
}
}

REGISTER_MAPMGR_EVENT_HANDLERS();

new ObjectMgr;
new QuestMgr;
new LootMgr;
Expand Down
3 changes: 2 additions & 1 deletion src/arcemu-world/WorldStatesHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ void WorldStatesHandler::SetWorldStateForZone( uint32 zone, uint32 area, uint32

itr2->second = value;

eventlistener->Notify( EVENT_MAPMGR_WORLDSTATE_UPDATE, zone, field, value );
if( observer != NULL )
observer->onWorldStateUpdate( zone, field, value );
}

uint32 WorldStatesHandler::GetWorldStateForZone( uint32 zone, uint32 area, uint32 field ) const{
Expand Down
15 changes: 12 additions & 3 deletions src/arcemu-world/WorldStatesHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@ struct WorldState;

class SERVER_DECL WorldStatesHandler{
public:
WorldStatesHandler( uint32 mapid, IEventListener *listener ){

class SERVER_DECL WorldStatesObserver{
public:
virtual ~WorldStatesObserver(){}
virtual void onWorldStateUpdate( uint32 zone, uint32 field, uint32 value ) = 0;
};

WorldStatesHandler( uint32 mapid ){
map = mapid;
eventlistener = listener;
observer = NULL;
}

~WorldStatesHandler(){}
Expand Down Expand Up @@ -99,10 +106,12 @@ class SERVER_DECL WorldStatesHandler{
////////////////////////////////////////////////////////////////////////////////////////////
void InitWorldStates( std::multimap< uint32, WorldState > *states );

void setObserver( WorldStatesObserver *observer ){ this->observer = observer; }

private:
HM_NAMESPACE::hash_map< uint32, HM_NAMESPACE::hash_map< uint32, uint32 > > worldstates;
uint32 map;
IEventListener *eventlistener;
WorldStatesObserver *observer;
};

#endif

0 comments on commit 7c0ad5e

Please sign in to comment.