- Katılım
- 24 Eki 2017
- Konular
- 173
- Mesajlar
- 1,320
- Çözüm
- 1
- Online süresi
- 7mo 29d
- Reaksiyon Skoru
- 801
- Altın Konu
- 1
- TM Yaşı
- 8 Yıl 7 Ay 20 Gün
- Başarım Puanı
- 249
- Yaş
- 33
- MmoLira
- 4,296
- DevLira
- 9
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
- Katılım
- 4 Nis 2022
- Konular
- 16
- Mesajlar
- 225
- Online süresi
- 17d 7h
- Reaksiyon Skoru
- 21
- Altın Konu
- 0
- TM Yaşı
- 4 Yıl 2 Ay 6 Gün
- Başarım Puanı
- 67
- MmoLira
- 2,134
- DevLira
- 3
teşekkürler çok işimi gördü..
- Katılım
- 30 Ocak 2020
- Konular
- 50
- Mesajlar
- 812
- Çözüm
- 6
- Online süresi
- 26d 15h
- Reaksiyon Skoru
- 735
- Altın Konu
- 1
- Başarım Puanı
- 184
- MmoLira
- 8,746
- DevLira
- 123
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
- Katılım
- 8 Haz 2024
- Konular
- 85
- Mesajlar
- 526
- Online süresi
- 2mo 12d
- Reaksiyon Skoru
- 407
- Altın Konu
- 0
- Başarım Puanı
- 121
- MmoLira
- 3,278
- DevLira
- 189
Şu an konuyu görüntüleyenler (Toplam : 0, Üye: 0, Misafir: 0)
Benzer konular
- Cevaplar
- 8
- Görüntüleme
- 223
- Cevaplar
- 18
- Görüntüleme
- 5K
- Cevaplar
- 8
- Görüntüleme
- 1K
- Cevaplar
- 37
- Görüntüleme
- 2K





