Some organisational prep work before I start working on a new navigation method (ie replacement for CardSelector). The current design was to allocate a CardSelector and pass in its pointer to a variety of classes via their constructors. To simplify things, now we use a singleton style pattern with an Instance() function - this means that when I implement a new class to replace CardSelector, I only need to modify what's returned by the singleton callback - as long as the new pointer class supports the same function calls, it'll be a straight drop-in.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <assert.h>
|
||||
|
||||
#include "../include/PlayGuiObject.h"
|
||||
#include "../include/CardGui.h"
|
||||
#include "../include/CardSelector.h"
|
||||
@@ -299,3 +301,29 @@ void CardSelector::PopLimitor() {
|
||||
Limit(limitorStack.top().first, limitorStack.top().second);
|
||||
limitorStack.pop();
|
||||
}
|
||||
|
||||
|
||||
namespace CardSelectorSingleton
|
||||
{
|
||||
static CardSelector* sCardSelectorInstance = NULL;
|
||||
|
||||
CardSelector* Create(DuelLayers* inDuelLayers)
|
||||
{
|
||||
if (sCardSelectorInstance == NULL)
|
||||
sCardSelectorInstance = NEW CardSelector(inDuelLayers);
|
||||
|
||||
return sCardSelectorInstance;
|
||||
}
|
||||
|
||||
CardSelector* Instance()
|
||||
{
|
||||
assert(sCardSelectorInstance);
|
||||
return sCardSelectorInstance;
|
||||
}
|
||||
|
||||
void Terminate()
|
||||
{
|
||||
SAFE_DELETE(sCardSelectorInstance);
|
||||
sCardSelectorInstance = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user