diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2012-03-17 21:56:00 +0100 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2012-03-17 23:40:12 +0100 |
commit | a6c3eed2b9a91e9768ec6ce137879cac13703dea (patch) | |
tree | b85bd802a6169dfd2e99f99d3150004d7e90e6a0 /src/game-server | |
parent | f98ba725442348584810c089111501a07ac59905 (diff) | |
download | manaserv-a6c3eed2b9a91e9768ec6ce137879cac13703dea.tar.gz manaserv-a6c3eed2b9a91e9768ec6ce137879cac13703dea.tar.bz2 manaserv-a6c3eed2b9a91e9768ec6ce137879cac13703dea.tar.xz manaserv-a6c3eed2b9a91e9768ec6ce137879cac13703dea.zip |
Added map update function, moved schedules there to keep map context
Reviewed-by: bjorn.
Diffstat (limited to 'src/game-server')
-rw-r--r-- | src/game-server/mapcomposite.cpp | 30 | ||||
-rw-r--r-- | src/game-server/mapcomposite.h | 4 | ||||
-rw-r--r-- | src/game-server/state.cpp | 30 |
3 files changed, 35 insertions, 29 deletions
diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp index 6b2b74f9..7d377d18 100644 --- a/src/game-server/mapcomposite.cpp +++ b/src/game-server/mapcomposite.cpp @@ -457,6 +457,7 @@ MapZone& MapContent::getZone(const Point &pos) const *****************************************************************************/ Script::Ref MapComposite::mInitializeCallback; +Script::Ref MapComposite::mUpdateCallback; MapComposite::MapComposite(int id, const std::string &name): mMap(NULL), @@ -607,6 +608,35 @@ void MapComposite::remove(Thing *ptr) void MapComposite::update() { + // Update object status + const std::vector< Thing * > &things = getEverything(); + for (std::vector< Thing * >::const_iterator it = things.begin(), + it_end = things.end(); it != it_end; ++it) + { + (*it)->update(); + } + + if (mUpdateCallback.isValid()) + { + Script *s = ScriptManager::currentState(); + s->setMap(this); + s->prepare(mUpdateCallback); + s->push(mID); + s->execute(); + } + + // Perform actions + for (BeingIterator it(getWholeMapIterator()); it; ++it) + { + (*it)->perform(); + } + + // Move objects around and update zones. + for (BeingIterator it(getWholeMapIterator()); it; ++it) + { + (*it)->move(); + } + for (int i = 0; i < mContent->mapHeight * mContent->mapWidth; ++i) { mContent->zones[i].destinations.clear(); diff --git a/src/game-server/mapcomposite.h b/src/game-server/mapcomposite.h index 15310a97..96939a9c 100644 --- a/src/game-server/mapcomposite.h +++ b/src/game-server/mapcomposite.h @@ -356,6 +356,9 @@ class MapComposite static void setInitializeCallback(Script *script) { script->assignCallback(mInitializeCallback); } + static void setUpdateCallback(Script *script) + { script->assignCallback(mUpdateCallback); } + private: MapComposite(const MapComposite &); @@ -374,6 +377,7 @@ class MapComposite std::map<const std::string, Script::Ref> mWorldVariableCallbacks; static Script::Ref mInitializeCallback; + static Script::Ref mUpdateCallback; }; #endif diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp index 34ede681..0e7bea25 100644 --- a/src/game-server/state.cpp +++ b/src/game-server/state.cpp @@ -70,34 +70,6 @@ static DelayedEvents delayedEvents; */ static std::map< std::string, std::string > mScriptVariables; - -/** - * Updates object states on the map. - */ -static void updateMap(MapComposite *map) -{ - // Update object status - const std::vector< Thing * > &things = map->getEverything(); - for (std::vector< Thing * >::const_iterator it = things.begin(), - it_end = things.end(); it != it_end; ++it) - { - (*it)->update(); - } - - // Perform actions - for (BeingIterator it(map->getWholeMapIterator()); it; ++it) - { - (*it)->perform(); - } - - // Move objects around and update zones. - for (BeingIterator it(map->getWholeMapIterator()); it; ++it) - { - (*it)->move(); - } - map->update(); -} - /** * Sets message fields describing character look. */ @@ -456,7 +428,7 @@ void GameState::update(int worldTime) if (!map->isActive()) continue; - updateMap(map); + map->update(); for (CharacterIterator p(map->getWholeMapIterator()); p; ++p) { |