From 453f8c05a4fc2ef03ba1d4f7bac43ba871c52fbd Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Sun, 29 Aug 2021 19:32:22 +0300 Subject: script revision p1 --- src/leeds/CustomSoundTrack.cpp | 11 +++++++ src/leeds/CustomSoundTrack.h | 20 +++++++++++++ src/leeds/base/singletonManager.cpp | 36 ++++++++++++++++++++++ src/leeds/base/singletonManager.h | 60 +++++++++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 src/leeds/CustomSoundTrack.cpp create mode 100644 src/leeds/CustomSoundTrack.h create mode 100644 src/leeds/base/singletonManager.cpp create mode 100644 src/leeds/base/singletonManager.h (limited to 'src/leeds') diff --git a/src/leeds/CustomSoundTrack.cpp b/src/leeds/CustomSoundTrack.cpp new file mode 100644 index 00000000..bcbfb82f --- /dev/null +++ b/src/leeds/CustomSoundTrack.cpp @@ -0,0 +1,11 @@ +#include "common.h" + +#include "CustomSoundTrack.h" + +// TODO - implement + +cCustomSoundTrack* base::cSingleton::mspInstance = nil; + +cCustomSoundTrack::cCustomSoundTrack() : + m_bIsPlaying(false) +{} diff --git a/src/leeds/CustomSoundTrack.h b/src/leeds/CustomSoundTrack.h new file mode 100644 index 00000000..e7b97fbc --- /dev/null +++ b/src/leeds/CustomSoundTrack.h @@ -0,0 +1,20 @@ +#pragma once + +#include "common.h" +#include "singletonManager.h" + +class cCustomSoundTrack : public base::cSingleton +{ +public: + bool m_bIsPlaying; + + cCustomSoundTrack(); + bool IsPlaying() + { +#ifdef CUSTOM_SOUND_TRACK + return m_bIsPlaying; +#else + return false; +#endif + } +}; \ No newline at end of file diff --git a/src/leeds/base/singletonManager.cpp b/src/leeds/base/singletonManager.cpp new file mode 100644 index 00000000..9ff9f28c --- /dev/null +++ b/src/leeds/base/singletonManager.cpp @@ -0,0 +1,36 @@ +#include "common.h" + +#include "singletonManager.h" + +namespace base +{ + +cSingletonManager& SingletonManager() +{ + static cSingletonManager manager; + return manager; +} + +cSingletonManager::~cSingletonManager() +{ + Purge(); +} + +void cSingletonManager::Add(cSingletonBase* node) +{ + node->next = head; + if (!head) + tail = node; + head = node; +} + +void cSingletonManager::Purge() +{ + for (cSingletonBase* node = tail; node; node = tail) { + tail = node->next; + delete node; + } +} + + +} \ No newline at end of file diff --git a/src/leeds/base/singletonManager.h b/src/leeds/base/singletonManager.h new file mode 100644 index 00000000..833e178b --- /dev/null +++ b/src/leeds/base/singletonManager.h @@ -0,0 +1,60 @@ +#pragma once + +#include "common.h" + +namespace base +{ + +class cSingletonBase +{ + friend class cSingletonManager; + + cSingletonBase* next; + +public: + virtual ~cSingletonBase() {} +}; + +template +class cSingleton : public cSingletonBase +{ + static T* mspInstance; + static void cSingleton::CreateInstance() + { + mspInstance = new T(); + SingletonManager().Add(mspInstance); + } + +public: + static T* Instance() + { + if (!mspInstance) + CreateInstance(); + return mspInstance; + } + + ~cSingleton() + { + mspInstance = nil; + } +}; + +class cSingletonManager +{ + cSingletonBase* head; + cSingletonBase* tail; + +public: + cSingletonManager() : + head(nil), + tail(nil) + {} + + void Add(cSingletonBase*); + void Purge(); + ~cSingletonManager(); +}; + +cSingletonManager& SingletonManager(); + +} \ No newline at end of file -- cgit v1.2.3