kralhakan2009 1
kralhakan2009
Vahsi Uzman 1
Vahsi Uzman
romegames 1
romegames
Bvural41 1
Bvural41
Best Studio 1
Best Studio
BlackFullMoon 1
BlackFullMoon
Hikaye Ekle
Reklam vermek için turkmmo@gmail.com

Metin2'yi özgür bırakın!

  • Konuyu başlatan Konuyu başlatan dormammu
  • Başlangıç tarihi Başlangıç tarihi
  • Cevaplar Cevaplar 43
  • Görüntüleme Görüntüleme 5K

ROHAN2 WORLD 1-120 TR TİPİ OFFICIAL YOHARA, BALATHOR VE AMON! 80. GÜNÜNDE! +10.000 ONLİNE! HİLE VE BOT %100 ENGELLİ HEMEN TIKLA!

hocam common/singleton.h güncelle; demişiniz insanları uyarırmısınız eterbasedeki singleton.hda güncellesin
 
teşekkürler çok işimi gördü..
 
Metin2'nin single-theard yapısı için oldukça gereksiz ve maliyetli bir refactoring olmuş maalesef, konunun açılışından çok süre geçmiş ama gözden kaçırmışım, şimdi görünce yorum yapmadan geçmek istemedim, hala bu konuyu görüp uygulamaya çalışan birileri olabilir. Oyun çoğu senaryoda single-theard garanti ettiği için mutex kullanımı gereksiz yük ve anlamsız bir maliyet, oyunun belki de en çok kullanılan header dosyası, performansın en kritik oldu dosya dolayısıyla buna uygun şekilde yazılmalı ve kullanılmalı. Kendi projemde kullandığım versiyonu paylaşıyorum belki birilerinin işine yarar;

C++:
#ifndef __INC_SINGLETON_H__
#define __INC_SINGLETON_H__

#include <cassert>
#include "service.h"
#include "../libthecore/include/log.h"

// After a critic ASan (-fsantinizer) warning, i've made a full rework for this header.
// It's now fully compatible with modern C++ and also much more faster/optimized. - [MT2Dev Note] - 20/06/2025

#ifdef __WIN32__
#define FORCE_INLINE [[nodiscard]] __forceinline
#else
#define FORCE_INLINE [[gnu::always_inline]] [[nodiscard]]
#endif //__WIN32__

template <typename T>
class singleton
{
    private:
        static inline T* ms_singleton = nullptr;
        #ifdef TEST_SINGLETON_MODE
        static inline bool ms_destroying = false;  // Debugging - Lifecycle tracking. - [MT2Dev Note]
        #endif //TEST_SINGLETON_MODE

    public:
        singleton()
        {
            // Debugging - Double initialization control. - [MT2Dev Note]
            #ifdef TEST_SINGLETON_MODE
            #ifdef __WIN32__
            assert (!ms_singleton  && "Singleton already exists! Multiple instances not allowed!");
            assert (!ms_destroying && "Cannot create singleton during destruction phase!");
            #else
            if (ms_singleton)
            {
                sys_err ("<FATAL ERROR> Singleton already exists! Multiple instances not allowed!");
            }

            if (ms_destroying)
            {
                sys_err ("<FATAL ERROR> Cannot create singleton during destruction phase!");
            }
            #endif //__WIN32__
            #endif //TEST_SINGLETON_MODE
            ms_singleton = static_cast<T*> (this);
        }

        virtual ~singleton()
        {
            #ifdef TEST_SINGLETON_MODE
            #ifdef __WIN32__
            assert (ms_singleton && "Singleton destructor called but instance is nullptr!");
            #else
            if (!ms_singleton)
            {
                sys_err ("<FATAL ERROR> Singleton destructor called but instance is nullptr!");
            }
            #endif //__WIN32__
            ms_destroying = true;
            #endif //TEST_SINGLETON_MODE
            ms_singleton = nullptr;
            #ifdef TEST_SINGLETON_MODE
            ms_destroying = false;
            #endif //TEST_SINGLETON_MODE
        }

        FORCE_INLINE static T& Instance()
        {
            #ifdef TEST_SINGLETON_MODE
            #ifdef __WIN32__
            assert (ms_singleton   && "Singleton not initialized! Create instance first!");
            assert (!ms_destroying && "Accessing singleton during destruction!");
            #else
            if (!ms_singleton)
            {
                sys_err ("<FATAL ERROR> Singleton not initialized! Create instance first!");
            }

            if (ms_destroying)
            {
                sys_err ("<FATAL ERROR> Accessing singleton during destruction!");
            }
            #endif //__WIN32__
            #endif //TEST_SINGLETON_MODE
            return *ms_singleton;
        }

        FORCE_INLINE static T& instance()  // For old compatibility support. - [MT2Dev Note]
        {
            return Instance();
        }

        // Copy/Move semantics. - [MT2Dev Note]
        singleton (const singleton&) = delete;
        singleton& operator= (const singleton&) = delete;
        singleton (singleton&&) = delete;
        singleton& operator= (singleton&&) = delete;
};
#endif //__INC_SINGLETON_H__

// MT2DevCore Project | Modern Base SF by MT2Dev | 2025
 
başlığı

Metin2'yi özgür bırakın!​

yerine

Metin2'yi rahat bırakın!​

yapılsaydı daha fazla hit alacak olan konu :D
 

Şu an konuyu görüntüleyenler (Toplam : 0, Üye: 0, Misafir: 0)

Geri
Üst