Jump to content

Multi threaded AC


Guest therapist
 Share

Recommended Posts

Wat does this Patch do

Adds Multi threaded support to Acution house

diff --git a/src/game/AuctionHouseMgr.cpp b/src/game/AuctionHouseMgr.cpp
index ed8a059..95a94b6 100644
--- a/src/game/AuctionHouseMgr.cpp
+++ b/src/game/AuctionHouseMgr.cpp
@@ -35,6 +35,11 @@

#include "Policies/SingletonImp.h"

+#ifdef WIN32
+#include "ServiceWin32.h"
+extern int m_ServiceStatus;
+#endif
+
INSTANTIATE_SINGLETON_1( AuctionHouseMgr );

AuctionHouseMgr::AuctionHouseMgr()
@@ -47,6 +52,40 @@ AuctionHouseMgr::~AuctionHouseMgr()
        delete itr->second;
}

+void AuctionHouseMgr::run()
+{
+    ACE_DEBUG
+        ((LM_DEBUG, ACE_TEXT ("(%t) Handler Thread running\\n")));
+
+    runUpdate = false;
+    initLoading = false;
+
+    LoadAuctionItems();
+    LoadAuctions();
+
+    initLoading = true;
+
+    while (!World::IsStopped())
+    {
+        if (runUpdate)
+        {
+            Update();
+            runUpdate = false;
+        }
+
+        #ifdef WIN32
+        ACE_Based::Thread::Sleep(50);
+        #else
+        ACE_Based::Thread::Sleep(100);
+        #endif
+
+        #ifdef WIN32
+            if (m_ServiceStatus == 0) World::StopNow(SHUTDOWN_EXIT_CODE);
+            while (m_ServiceStatus == 2) Sleep(1000);
+        #endif
+    }
+}
+
AuctionHouseObject * AuctionHouseMgr::GetAuctionsMap( uint32 factionTemplateId )
{
    if(sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION))
@@ -278,6 +317,8 @@ void AuctionHouseMgr::SendAuctionExpiredMail( AuctionEntry * auction )

+ void AuctionHouseMgr::Update()
+{
+    mHordeAuctions.Update();
+    mAllianceAuctions.Update();
+    mNeutralAuctions.Update();
+
+    if((++loopcount % 100))
+        return;
+        
+    vector<AuctionHouse*>::iterator itr = auctionHouses.begin();
+    for(; itr != auctionHouses.end(); ++itr)
+    {
+        (*itr)->UpdateDeletionQueue();
+
+        // Actual auction loop is on a seperate timer.
+        if(!(loopcount % 1200))
+            (*itr)->UpdateAuctions();
+    }
+}

void AuctionHouseMgr::LoadAuctionItems()
{
+    ACE_DEBUG
+        ((LM_DEBUG, ACE_TEXT ("(%t) LoadAuctionItems Thread running\\n")));
    // data needs to be at first place for Item::LoadFromDB
    QueryResult *result = CharacterDatabase.Query( "SELECT data,itemguid,item_template FROM auctionhouse JOIN item_instance ON itemguid = guid" );

@@ -331,6 +372,8 @@ void AuctionHouseMgr::LoadAuctionItems()

void AuctionHouseMgr::LoadAuctions()
{
+    ACE_DEBUG
+        ((LM_DEBUG, ACE_TEXT ("(%t) LoadAuctions Thread running\\n")));
    QueryResult *result = CharacterDatabase.Query("SELECT COUNT(*) FROM auctionhouse");
    if( !result )
    {
diff --git a/src/game/AuctionHouseMgr.h b/src/game/AuctionHouseMgr.h
index 2775838..164f637 100644
--- a/src/game/AuctionHouseMgr.h
+++ b/src/game/AuctionHouseMgr.h
@@ -114,7 +114,7 @@ class AuctionHouseObject
        AuctionEntryMap AuctionsMap;
};

-class AuctionHouseMgr
+class AuctionHouseMgr : public ACE_Based::Runnable
{
    public:
        AuctionHouseMgr();
@@ -152,7 +152,12 @@ class AuctionHouseMgr

        +~AuctionHouseMgr()
       +{
       +vector<AuctionHouseMgr*>::iterator itr = auctionHouses.begin();
       +for(; itr != auctionHouses.end(); ++itr)
       +    delete (*itr);
       +}

        void Update();

+        bool runUpdate;
+        bool initLoading;
+
    private:
+        void run();
+        Mutex lock;
+         uint32 loopcount;
+
        AuctionHouseObject  mHordeAuctions;
        AuctionHouseObject  mAllianceAuctions;
        AuctionHouseObject  mNeutralAuctions;

+#define sAuctionHouseMgr AuctionHouseMgr::getSingleton()
+#endif    

diff --git a/src/game/World.cpp b/src/game/World.cpp
index bf20ccf..7bf2501 100644
--- a/src/game/World.cpp
+++ b/src/game/World.cpp
@@ -1309,8 +1309,13 @@ void World::SetInitialWorldSettings()
    ///- Load dynamic data tables from the database
    sLog.outString( "Loading Auctions..." );
    sLog.outString();
-    auctionmgr.LoadAuctionItems();
-    auctionmgr.LoadAuctions();
+    ACE_DEBUG
+        ((LM_DEBUG, ACE_TEXT ("(%t) Main Thread running\\n")));
+    ACE_Based::Thread t(*new AuctionHouseMgr);
+    while(auctionmgr.initLoading == false)
+        ACE_Based::Thread::Sleep(100);
+    //auctionmgr.LoadAuctionItems();
+    //auctionmgr.LoadAuctions();
    sLog.outString( ">>> Auctions loaded" );
    sLog.outString();

@@ -1529,7 +1534,8 @@ void World::Update(uint32 diff)
        }

        ///- Handle expired auctions
-        auctionmgr.Update();
+        auctionmgr.runUpdate = true;
+        //auctionmgr.Update();
    }

    /// [*] Handle session updates when the timer has passed

My c++ ain't that good but i have tested this works fine so far if people cud post fixes for this that would be great

Link to comment
Share on other sites

 Share

×
×
  • 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