forked from vpinball/vpinball
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ieditable.h
281 lines (240 loc) · 11.2 KB
/
ieditable.h
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#pragma once
class HitTimer;
class Hitable;
class Collection;
class IScriptable;
#define BLUEPRINT_SOLID_COLOR RGB(0,0,0)
class IFireEvents
{
public:
virtual void FireGroupEvent(const int dispid) = 0;
virtual IDispatch *GetDispatch() = 0;
virtual const IDispatch *GetDispatch() const = 0;
virtual IDebugCommands *GetDebugCommands() = 0;
float m_currentHitThreshold; // while playing and the ball hits the mesh the hit threshold is updated here
};
#define STARTUNDO \
BeginUndo(); \
MarkForUndo();
#define STOPUNDO \
EndUndo(); \
SetDirtyDraw();
#define STARTUNDOSELECT \
GetIEditable()->BeginUndo(); \
GetIEditable()->MarkForUndo();
#define STOPUNDOSELECT \
GetIEditable()->EndUndo(); \
GetIEditable()->SetDirtyDraw();
#define INITVBA(ItemType) \
virtual HRESULT InitVBA(BOOL fNew, int id, WCHAR * const wzName) \
{ \
WCHAR wzUniqueName[128]; \
if (fNew && !wzName) \
{ \
{ \
GetPTable()->GetUniqueName(ItemType, wzUniqueName, 128); \
WideStrNCopy(wzUniqueName, (WCHAR *)m_wzName, sizeof(m_wzName)/sizeof(m_wzName[0]));/*lstrcpyW((WCHAR *)m_wzName, wzUniqueName);*/ \
} \
} \
InitScript(); \
return S_OK; \
}
// Explanation for AllowedViews:
// Value gets and'ed with 1 (table view) or 2 (backglass view).
// If you want to allow an element to be pasted only into the table view, use 1,
// for only backglass view, use 2, and for both, use 3.
// declare and implement some methods for an IEditable which supports scripting
#define STANDARD_EDITABLE_DECLARES(T, ItemType, ResName, AllowedViews) \
_STANDARD_EDITABLE_CONSTANTS(ItemType, ResName, AllowedViews) \
_STANDARD_DISPATCH_INDEPENDANT_EDITABLE_DECLARES(T, ItemType) \
_STANDARD_DISPATCH_EDITABLE_DECLARES(ItemType)
// declare and implement some methods for an IEditable which does not support scripting
#define STANDARD_NOSCRIPT_EDITABLE_DECLARES(T, ItemType, ResName, AllowedViews) \
_STANDARD_EDITABLE_CONSTANTS(ItemType, ResName, AllowedViews) \
_STANDARD_DISPATCH_INDEPENDANT_EDITABLE_DECLARES(T, ItemType) \
virtual EventProxyBase *GetEventProxyBase() {return nullptr;} \
inline IFireEvents *GetIFireEvents() {return nullptr;} \
inline IDebugCommands *GetDebugCommands() {return nullptr;} \
virtual IScriptable *GetScriptable() {return nullptr;}
// used above, do not invoke directly
#define _STANDARD_DISPATCH_EDITABLE_DECLARES(itemType) \
inline IFireEvents *GetIFireEvents() {return (IFireEvents *)this;} \
inline IDebugCommands *GetDebugCommands() {return nullptr;} \
virtual EventProxyBase *GetEventProxyBase() {return (EventProxyBase *)this;} \
STDMETHOD(get_Name)(/*[out, retval]*/ BSTR *pVal) \
{ \
*pVal = SysAllocString((WCHAR *)m_wzName); \
return S_OK; \
} \
STDMETHOD(put_Name)(/*[in]*/ BSTR newVal) \
{ \
const int len = lstrlenW(newVal); \
if (len > MAXNAMEBUFFER || len < 1) \
{ \
return E_FAIL; \
} \
if (GetPTable()->m_pcv->ReplaceName(this, newVal) == S_OK) \
{ \
WideStrNCopy(newVal, (WCHAR *)m_wzName, sizeof(m_wzName)/sizeof(m_wzName[0]));/*lstrcpyW((WCHAR *)m_wzName, newVal);*/ \
return S_OK; \
} \
return E_FAIL; \
} \
STDMETHOD(get_TimerInterval)(/*[out, retval]*/ long *pVal) {*pVal = m_d.m_tdr.m_TimerInterval; return S_OK;} \
STDMETHOD(put_TimerInterval)(/*[in]*/ long newVal) {return IEditable::put_TimerInterval(newVal, &m_d.m_tdr.m_TimerInterval);} \
STDMETHOD(get_TimerEnabled)(/*[out, retval]*/ VARIANT_BOOL *pVal) {*pVal = FTOVB(m_d.m_tdr.m_TimerEnabled); return S_OK;} \
STDMETHOD(put_TimerEnabled)(/*[in]*/ VARIANT_BOOL newVal) {BOOL tmp = m_d.m_tdr.m_TimerEnabled ? 1 : 0; const HRESULT res = IEditable::put_TimerEnabled(newVal, &tmp); m_d.m_tdr.m_TimerEnabled = (tmp != 0); return res;} \
STDMETHOD(get_UserValue)(VARIANT *pVal) {return IEditable::get_UserValue(pVal);} \
STDMETHOD(put_UserValue)(VARIANT *newVal) {return IEditable::put_UserValue(newVal);} \
virtual IScriptable *GetScriptable() {return (IScriptable *)this;} \
virtual void FireGroupEvent(const int dispid) {FireVoidGroupEvent(dispid);}
// used above, do not invoke directly
#define _STANDARD_DISPATCH_INDEPENDANT_EDITABLE_DECLARES(T, ItemType) \
static T* COMCreate() \
{ \
CComObject<T> *obj = nullptr; \
if (FAILED(CComObject<T>::CreateInstance(&obj))) \
{ \
MessageBox(0, "Failed to create COM object.", "Visual Pinball", MB_ICONEXCLAMATION); \
} \
obj->AddRef(); \
return obj; \
} \
static IEditable* COMCreateEditable() { return static_cast<IEditable*>(COMCreate()); } \
static IEditable* COMCreateAndInit(PinTable * const ptable, const float x, const float y) \
{ \
T *obj = T::COMCreate(); \
obj->Init(ptable, x, y, true); \
return obj; \
} \
HRESULT Init(PinTable * const ptable, const float x, const float y, const bool fromMouseClick, const bool forPlay = false); \
INITVBA(ItemType) \
virtual void UIRenderPass1(Sur * const psur); \
virtual void UIRenderPass2(Sur * const psur); \
virtual PinTable *GetPTable() { return m_ptable; } \
virtual const PinTable *GetPTable() const { return m_ptable; } \
virtual void GetHitShapes(vector<HitObject*> &pvho); \
virtual void GetHitShapesDebug(vector<HitObject*> &pvho); \
virtual void GetTimers(vector<HitTimer*> &pvht); \
virtual void EndPlay(); \
virtual void Delete() {IEditable::Delete();} \
virtual void Uncreate() {IEditable::Uncreate();} \
virtual HRESULT SaveData(IStream *pstm, HCRYPTHASH hcrypthash, const bool saveForUndo); \
virtual ItemTypeEnum GetItemType() const { return ItemType; } \
virtual HRESULT InitLoad(IStream *pstm, PinTable *ptable, int *pid, int version, HCRYPTHASH hcrypthash, HCRYPTKEY hcryptkey); \
virtual HRESULT InitPostLoad(); \
virtual bool LoadToken(const int id, BiffReader * const pbr); \
virtual IDispatch *GetDispatch() {return static_cast<IDispatch *>(this);} \
virtual const IDispatch *GetDispatch() const {return static_cast<const IDispatch *>(this);} \
virtual IEditable *GetIEditable() {return static_cast<IEditable*>(this);} \
virtual const IEditable *GetIEditable() const {return static_cast<const IEditable*>(this);} \
virtual ISelect *GetISelect() {return static_cast<ISelect*>(this);} \
virtual const ISelect *GetISelect() const {return static_cast<const ISelect*>(this);} \
virtual Hitable *GetIHitable() {return static_cast<Hitable *>(this);} \
virtual const Hitable *GetIHitable() const {return static_cast<const Hitable *>(this);} \
virtual void RenderSetup(RenderDevice *device); \
virtual void UpdateAnimation(const float diff_time_msec); \
virtual void Render(const unsigned int renderMask); \
virtual void RenderRelease(); \
STDMETHOD(GetDisplayString)(DISPID dispID, BSTR *pbstr) {return hrNotImplemented;} \
STDMETHOD(MapPropertyToPage)(DISPID dispID, CLSID *pclsid) {return hrNotImplemented;} \
STDMETHOD(GetPredefinedStrings)(DISPID dispID, CALPOLESTR *pcaStringsOut, CADWORD *pcaCookiesOut) {return GetPTable()->GetPredefinedStrings(dispID, pcaStringsOut, pcaCookiesOut, this);} \
STDMETHOD(GetPredefinedValue)(DISPID dispID, DWORD dwCookie, VARIANT *pVarOut) {return GetPTable()->GetPredefinedValue(dispID, dwCookie, pVarOut, this);} \
virtual void SetDefaults(const bool fromMouseClick);
#define _STANDARD_EDITABLE_CONSTANTS(ItTy, ResName, AllwdViews) \
static const ItemTypeEnum ItemType = ItTy; \
static const int TypeNameID = IDS_TB_##ResName; \
static const int ToolID = ID_INSERT_##ResName; \
static const int CursorID = IDC_##ResName; \
static const unsigned AllowedViews = AllwdViews;
#define STANDARD_EDITABLE_COPY_FOR_PLAY_IMPL(type, table) \
type *dst = type::COMCreate(); \
dst->Init(table, 0.f, 0.f, false, true); \
memcpy(dst->m_wzName, m_wzName, MAXNAMEBUFFER * sizeof(m_wzName[0])); \
if (dst->GetScriptable()) \
table->m_pcv->AddItem(dst->GetScriptable(), false); \
dst->m_oldLayerIndex = m_oldLayerIndex; \
dst->m_layerName = m_layerName; \
dst->m_isVisible = m_isVisible; \
dst->m_locked = m_locked; \
dst->m_d = m_d;
#define STANDARD_EDITABLE_WITH_DRAGPOINT_COPY_FOR_PLAY_IMPL(type, table, points) \
STANDARD_EDITABLE_COPY_FOR_PLAY_IMPL(type, table) \
for (size_t i = 0; i < dst->points.size(); i++) \
dst->points[i]->Release(); \
dst->points.clear(); \
for (size_t i = 0; i < points.size(); i++) \
{ \
points[i]->AddRef(); \
dst->points.push_back(points[i]); \
}
class EventProxyBase;
class ObjLoader;
// IEditable is the subclass for anything class which is a self-contained table element.
// It knows how to draw itself, interact with event and properties,
// And talk to the player
// Example: Bumper is an IEditable and ISelect, but DragPoint is only ISelect.
class IEditable
{
public:
IEditable();
virtual ~IEditable();
// this function draws the shape of the object with a solid fill
// only used in the UI/editor and not the game
//
// this is called before the grid lines are drawn on the map
virtual void UIRenderPass1(Sur * const psur) = 0;
// this function draws the shape of the object with a black outline (no solid fill)
// only used in the UI/editor and not the game
//
// this is called after the grid lines have been drawn on the map.
// draws a solid outline over the grid lines
virtual void UIRenderPass2(Sur * const psur) = 0;
virtual void RenderBlueprint(Sur *psur, const bool solid);
virtual void ExportMesh(ObjLoader& loader) {}
virtual ULONG STDMETHODCALLTYPE AddRef() = 0;
virtual ULONG STDMETHODCALLTYPE Release() = 0;
virtual PinTable *GetPTable() = 0;
virtual const PinTable *GetPTable() const = 0;
void SetDirtyDraw();
virtual Hitable *GetIHitable() { return nullptr; }
virtual const Hitable *GetIHitable() const { return nullptr; }
virtual HRESULT SaveData(IStream *pstm, HCRYPTHASH hcrypthash, const bool saveForUndo) = 0;
virtual void ClearForOverwrite();
virtual HRESULT InitLoad(IStream *pstm, PinTable *ptable, int *pid, int version, HCRYPTHASH hcrypthash, HCRYPTKEY hcryptkey) = 0;
virtual HRESULT InitPostLoad() = 0;
virtual HRESULT InitVBA(BOOL fNew, int id, WCHAR * const wzName) = 0;
virtual ISelect *GetISelect() = 0;
virtual const ISelect *GetISelect() const = 0;
virtual void SetDefaults(const bool fromMouseClick) = 0;
virtual IScriptable *GetScriptable() = 0;
virtual IFireEvents *GetIFireEvents() = 0;
virtual ItemTypeEnum GetItemType() const = 0;
virtual void GetBoundingVertices(vector<Vertex3Ds>& pvvertex3D, const bool isLegacy) {}
virtual void WriteRegDefaults() {}
void BeginUndo();
void EndUndo();
void MarkForUndo();
void MarkForDelete();
void Undelete();
const char *GetName();
void SetName(const string& name);
void Delete();
void Uncreate();
void InitScript();
HRESULT put_TimerEnabled(VARIANT_BOOL newVal, BOOL *pte);
HRESULT put_TimerInterval(long newVal, int *pti);
HRESULT get_UserValue(VARIANT *pVal);
HRESULT put_UserValue(VARIANT *newVal);
void BeginPlay();
void EndPlay();
HitTimer *m_phittimer;
VARIANT m_uservalue;
vector<Collection*> m_vCollection;
vector<int> m_viCollection;
// Optimizations for in-game
vector<Collection*> m_vEventCollection;
vector<int> m_viEventCollection;
bool m_singleEvents;
bool m_backglass; // if the light/decal (+dispreel/textbox is always true) is on the table (false) or a backglass view
};