-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeatre.hpp
More file actions
166 lines (139 loc) · 5.44 KB
/
Copy paththeatre.hpp
File metadata and controls
166 lines (139 loc) · 5.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#ifndef THEATRE_H
#define THEATRE_H
#include <Nostalgia/fwd/things.hpp>
#include <Nostalgia/things/thinkers/thinker.hpp>
#include <Nostalgia/things/resources/resource.hpp>
#include <Nostalgia/theatre/theatre_file.hpp>
#include <Nostalgia/theatre/call_sheet.hpp>
class Theatre
{
public:
using Things_t = std::unordered_map<ID, Shared<Thing>>;
using Names_t = std::map<std::string, ID>;
static Theatre* Current();
Theatre() noexcept;
virtual ~Theatre() noexcept;
template<typename T> requires std::derived_from<T, Theatre>
void Copy(Farg<T> inTheatre) noexcept
{
LockGuard<RMutex> _things_lock{mThingsMutex};
LockGuard<RMutex> _callsheet_lock{mCallSheetMutex};
mName = inTheatre.mName;
mIndex = inTheatre.mIndex;
mIsStarted = inTheatre.mIsStarted;
mWasLoadedFromFile = inTheatre.mWasLoadedFromFile;
mInitStatus = inTheatre.mInitStatus;
mThings = inTheatre.mThings;
mNames = inTheatre.mNames;
mRootViewportCurrentCamera3D = inTheatre.mRootViewportCurrentCamera3D;
mRootViewportCurrentCamera2D = inTheatre.mRootViewportCurrentCamera2D;
mThinkerUIDs = inTheatre.mThinkerUIDs;
mResourceUIDs = inTheatre.mResourceUIDs;
mLightIDs = inTheatre.mLightIDs;
mVisual3DIDs = inTheatre.mVisual3DIDs;
mVisual2DIDs = inTheatre.mVisual2DIDs;
mViewportIDs = inTheatre.mViewportIDs;
mCallSheet = inTheatre.mCallSheet;
m_pPlayer = inTheatre.m_pPlayer;
m_pInitialState = inTheatre.m_pInitialState;
}
virtual void Update();
virtual void Tick();
virtual void Input(InputEvent*);
virtual Shared<Image> TakeScreenshot(ID inViewportUID = ID::Invalid);
virtual void LoadTheatreData(Farg<TheatreFile::TheatreData> inTheatreData);
virtual Error LoadData(Farg<FileData> inData);
virtual Error LoadFile(std::string inFilePath);
virtual std::string GetSaveData();
virtual Error SaveToFile(Sarg inOutputFilePath, FileSystem::OverwriteAction = FileSystem::RENAME);
virtual bool Startup();
virtual bool Shutdown();
virtual void Draw();
Sarg Name() const;
uint Index() const;
bool WasLoadedFromFile() const;
Sarg TheatreFilePath() const;
std::string TheatreFileDirectory() const;
std::string TheatreFileName() const;
Error InitStatus() const;
bool IsStarted() const;
Farg<TheatreFile::TheatreData> InitialState() const;
TheatreFile::TheatreData CurrentState();
ID GetCurrentCamera2D(ID inViewportID = {});
ID GetCurrentCamera3D(ID inViewportID = {});
Error SetCurrentCamera(ID inCameraID, ID inViewportID = {});
IdVec_t ThingUIDs();
IdVec_t ThinkersWithNoParents();
IdSet_arg ThinkerUIDs();
IdSet_arg ResourceUIDs();
bool ThingExists(ID);
bool ThingExists(Sarg inName);
FPID TypeOf(ID);
bool DerivedFrom(ID, FPID);
ID CreateThing(Farg<TheatreFile::ThingData>, bool inDoReadyThing = true);
Error DestroyThing(ID);
ID GetUID(Sarg inName);
Sarg GetName(ID);
Error SetName(ID inUID, Sarg inNewName);
Error SetName(Sarg inOldName, Sarg inNewName);
Shared<Thinker> GetPlayer();
IdSet_arg GetViewports();
IdSet_t GetChildren(ID inParentID);
ID GetParent(ID inChildID);
IdSet_t GetAllChildren(ID inParentID);
IdSet_t GetAllParents(ID inChildID);
Error SetParent(ID inChildID, ID inParentID);
Error DropParent(ID inChildID);
Shared<Thing> GetThing(Sarg ThingName);
Shared<Thing> GetThing(ID ObjectID);
Shared<Resource> GetResource(ID ObjectID);
Shared<Thinker> GetThinker(ID ObjectID);
const LockGuard<RMutex> GetThingsLock();
const LockGuard<RMutex> GetCallSheetLock();
template<typename T> requires std::derived_from<T, NostalgiaPlayer>
Shared<T> GetPlayer()
{
if(auto player{DCast<T>(m_pPlayer)})
{ return player; }
return MakeShared<T>();
}
template<typename T> requires std::derived_from<T,Resource>
Shared<T> GetResource(ID ObjectID)
{
if(auto resource{DCast<T>(GetResource(ObjectID))})
{ return resource; }
return MakeShared<T>();
}
template<typename T> requires std::derived_from<T,Thinker>
Shared<T> GetThinker(ID ObjectID)
{
if(auto thinker{DCast<T>(GetThinker(ObjectID))})
{ return thinker; }
return MakeShared<T>();
}
protected:
std::string mName{"Untitled Theatre"};
uint mIndex{ID::Invalid};
bool mIsStarted{false},
mWasLoadedFromFile{false};
Error mInitStatus{ERR_UNINITIALIZED};
RMutex mThingsMutex{},
mCallSheetMutex{};
Things_t mThings{};
Names_t mNames{};
ID mRootViewportCurrentCamera3D{},
mRootViewportCurrentCamera2D{};
IdSet_t mThinkerUIDs{}, mResourceUIDs{},
mLightIDs{},
mVisual3DIDs{},
mVisual2DIDs{},
mViewportIDs{};
CallSheet mCallSheet{};
Shared<Thinker> m_pPlayer{nullptr};
Shared<TheatreFile::TheatreData> m_pInitialState{MakeShared<TheatreFile::TheatreData>()};
static Error SetThingName(Sarg,Sarg);
virtual void UpdateCallsheet(ID, Farg<TheatreFile::ThingData>);
virtual void UpdateIdSetsAndSpecialThings(FPID, ID);
virtual Error DestroyThingOnly(ID);
};
#endif // THEATRE_H