Jump to content

[11398][patch] Fix timers code in World.cpp


Guest Neo2003

Recommended Posts

Hello,

What features does the patch add?

Fix timers code in World.cpp, remove unneeded timers and fix diff in map update.

For which repository revision was the patch created?

11315

Is there a thread in the bug report section or at lighthouse?

None, since they work fine currently just because the diff is not used in MapMgr.Update

Who has been writing this patch? Please include either forum user names or email addresses.

Me

Patch:

diff --git a/src/game/Map.cpp b/src/game/Map.cpp
index 747088e..6686316 100644
--- a/src/game/Map.cpp
+++ b/src/game/Map.cpp
@@ -444,7 +444,7 @@ void Map::Update(const uint32 &t_diff)
            WorldSession * pSession = plr->GetSession();
            MapSessionFilter updater(pSession);

-            pSession->Update(t_diff, updater);
+            pSession->Update(updater);
        }
    }

diff --git a/src/game/World.cpp b/src/game/World.cpp
index 04e0820..79699fb 100644
--- a/src/game/World.cpp
+++ b/src/game/World.cpp
@@ -1299,8 +1299,6 @@ void World::SetInitialWorldSettings()
    LoginDatabase.PExecute("INSERT INTO uptime (realmid, starttime, startstring, uptime) VALUES('%u', " UI64FMTD ", '%s', 0)",
        realmID, uint64(m_startTime), isoDate);

-    m_timers[WUPDATE_OBJECTS].SetInterval(0);
-    m_timers[WUPDATE_SESSIONS].SetInterval(0);
    m_timers[WUPDATE_WEATHERS].SetInterval(1*IN_MILLISECONDS);
    m_timers[WUPDATE_AUCTIONS].SetInterval(MINUTE*IN_MILLISECONDS);
    m_timers[WUPDATE_UPTIME].SetInterval(getConfig(CONFIG_UINT32_UPTIME_UPDATE)*MINUTE*IN_MILLISECONDS);
@@ -1450,13 +1448,8 @@ void World::Update(uint32 diff)
        sAuctionMgr.Update();
    }

-    /// [*] Handle session updates when the timer has passed
-    if (m_timers[WUPDATE_SESSIONS].Passed())
-    {
-        m_timers[WUPDATE_SESSIONS].Reset();
-
-        UpdateSessions(diff);
-    }
+    /// [*] Handle session updates
+    UpdateSessions(diff);

    /// [*] Handle weather updates when the timer has passed
    if (m_timers[WUPDATE_WEATHERS].Passed())
@@ -1488,14 +1481,10 @@ void World::Update(uint32 diff)
    }

    /// [*] Handle all other objects
-    if (m_timers[WUPDATE_OBJECTS].Passed())
-    {
-        m_timers[WUPDATE_OBJECTS].Reset();
-        ///- Update objects when the timer has passed (maps, transport, creatures,...)
-        sMapMgr.Update(diff);                // As interval = 0
+    ///- Update objects (maps, transport, creatures,...)
+    sMapMgr.Update(diff);

-        sBattleGroundMgr.Update(diff);
-    }
+    sBattleGroundMgr.Update(diff);

    ///- Delete all characters which have been deleted X days before
    if (m_timers[WUPDATE_DELETECHARS].Passed())
@@ -1911,7 +1900,7 @@ void World::UpdateSessions( uint32 diff )
        WorldSession * pSession = itr->second;
        WorldSessionFilter updater(pSession);

-        if(!pSession->Update(diff, updater))    // As interval = 0
+        if(!pSession->Update(updater))
        {
            RemoveQueuedSession(pSession);
            m_sessions.erase(itr);
diff --git a/src/game/World.h b/src/game/World.h
index 32ef77b..44acb21 100644
--- a/src/game/World.h
+++ b/src/game/World.h
@@ -71,15 +71,13 @@ enum ShutdownExitCode
/// Timers for different object refresh rates
enum WorldTimers
{
-    WUPDATE_OBJECTS     = 0,
-    WUPDATE_SESSIONS    = 1,
-    WUPDATE_AUCTIONS    = 2,
-    WUPDATE_WEATHERS    = 3,
-    WUPDATE_UPTIME      = 4,
-    WUPDATE_CORPSES     = 5,
-    WUPDATE_EVENTS      = 6,
-    WUPDATE_DELETECHARS = 7,
-    WUPDATE_COUNT       = 8
+    WUPDATE_AUCTIONS    = 0,
+    WUPDATE_WEATHERS    = 1,
+    WUPDATE_UPTIME      = 2,
+    WUPDATE_CORPSES     = 3,
+    WUPDATE_EVENTS      = 4,
+    WUPDATE_DELETECHARS = 5,
+    WUPDATE_COUNT       = 6
};

/// Configuration elements
diff --git a/src/game/WorldSession.cpp b/src/game/WorldSession.cpp
index 2db93f4..9bbf11d 100644
--- a/src/game/WorldSession.cpp
+++ b/src/game/WorldSession.cpp
@@ -198,7 +198,7 @@ void WorldSession::LogUnprocessedTail(WorldPacket *packet)
}

/// Update the WorldSession (triggered by World update)
-bool WorldSession::Update(uint32 diff, PacketFilter& updater)
+bool WorldSession::Update(PacketFilter& updater)
{
    ///- Retrieve packets from the receive queue and call the appropriate handlers
    /// not process packets if socket already closed
diff --git a/src/game/WorldSession.h b/src/game/WorldSession.h
index 8ac7d17..f11793f 100644
--- a/src/game/WorldSession.h
+++ b/src/game/WorldSession.h
@@ -242,7 +242,7 @@ class MANGOS_DLL_SPEC WorldSession

        void QueuePacket(WorldPacket* new_packet);

-        bool Update(uint32 diff, PacketFilter& updater);
+        bool Update(PacketFilter& updater);

        /// Handle the authentication waiting queue (to be completed)
        void SendAuthWaitQue(uint32 position);

Reason:

WUPDATE_SESSIONS and WUPDATE_OBJECTS are used to make a 0 interval timers! useless and:

    if (m_timers[WUPDATE_OBJECTS].Passed())
   {
       m_timers[WUPDATE_OBJECTS].Reset();
       ///- Update objects when the timer has passed (maps, transport, creatures,...)
       sMapMgr.Update(diff);                // As interval = 0

       sBattleGroundMgr.Update(diff);
   }

- We update a 0 timer, so always passed

- We call some other object update when the timer is Passed, so the update are done with a ~50ms diff instead of the real diff, this works only because the timer serves nothing with an interval 0. Set the interval to 1000 and the update will be called with diff=50 every 1000ms.

- "// As interval = 0": No, the diff is ~50ms here.

- Here sMapMgr.Update::Update() must be called with 0, not the ~50ms diff since it's called also from elsewhere.

I did not understand why my warden timer where strange, now I know :D

Edit: New version of the patch.

I did not remind properly since I saw this long ago, it's WorldSession::Update() which was called twice with a diff making it having an internal unused diff at double speed. So I simply remove the diff from this method.

Link to comment
Share on other sites

Neo, isn't is easier to remove this code from MapManager::Update(uint32) function:

    i_timer.Update(diff);
   if( !i_timer.Passed() )
       return;

plus setup correct value for WUPDATE_OBJECTS timer to not invent brute hacks with Update(0)? :) Also, what do you mean by 'set interval = 1000 and get diff = 50'? We always send to Map::Update()/Transport::Update() methods real diffs between updates. So I'm not quite sure what are you trying to fix :/

P.S. MapManager uses its own timer to handle Map updates, which is different from World tick update timer.

Link to comment
Share on other sites

I mean that the "sMapMgr.Update(diff);" is in the code section under if (m_timers[WUPDATE_OBJECTS].Passed()), so called only when the timer is finished. This works because the timer is set to interval 0 so always passed. If you try to give a value to this timer interval like 1000, it will be passed every 20 cycles of 50ms so you will call Update(diff) with diff=50 (the real time passed in the main loop) every 1000ms (when timer is passed) which is wrong.

Moreover you pass a 50ms diff here every 50ms and same in worldsession so the diff in map is double speed, which again is not yet a problem because it has no use currently, but made my warden patch twice speed when called from map::update(diff), with this diff. So better to send 0 in one of these both calls.

Link to comment
Share on other sites

Moreover you pass a 50ms diff here every 50ms and same in worldsession so the diff in map is double speed

Why would map update be twice as fast? If you are right then why periodic auras do not expire with double speed? Current packet processing system does not care about MapManager update timer - it simply does not need any of those. Also, if you are aware, some packets are currently executed in Map::Update() function.

So I'd like to get an example of the code which proves your findings - at current stage I do not believe in problems of such sort.

Link to comment
Share on other sites

  • 3 weeks later...
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use