-
Notifications
You must be signed in to change notification settings - Fork 1
/
Runtime.cpp
128 lines (101 loc) · 3.34 KB
/
Runtime.cpp
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
// Runtime.cpp - Runtime implementation of object
//
// Include StdAfx
#include "StdAfx.h"
//////////////////////////////////////////////////////////////////////////////////
// Runtime functions
//////////////////////////////////////////////////////////////////////////////////
#ifdef RUN_ONLY
// ExtObject constructor:
// Only use for class initializer list. Object initialisation must be done in OnCreate.
// It is not safe to make runtime calls here: do so in OnCreate.
ExtObject::ExtObject(initialObject* editObject, VRuntime* pVRuntime):
renderer( pVRuntime->pRenderer )
{
pRuntime = pVRuntime;
info.editObject = editObject;
}
// This is called just after the constructor when your object has been created. Construct has set
// up your object here so it is safe to make runtime calls.
void ExtObject::OnCreate()
{
// Load the edittime data that was serialized.
bin ar;
ar.attach(info.editObject->eData, info.editObject->eSize);
// Read the data. Same format as you exported in EditExt::Serialize.
// Your runtime loader must be able to load all versions!
int Version = 0;
int gameID;
CString gamePrivateKey;
ar >> Version;
////////////////////////////////
// Load your edittime data here
ar >> gameID >> gamePrivateKey >> m_LoadScoresCount;
// Finished reading data
ar.detach();
// Set up the GJ API.
api.SetGameID( gameID );
api.SetGamePrivateKey( CStdString( gamePrivateKey ) );
// Set default dimensions
info.x = info.editObject->eX;
info.y = info.editObject->eY;
info.w = info.editObject->eWidth;
info.h = info.editObject->eHeight;
info.angle = 0.0f;
// Update bounding box
pRuntime->UpdateBoundingBox(this);
}
// Destructor: called when an instance of your object is destroyed.
ExtObject::~ExtObject()
{
}
// Called every frame, before the events and after drawing, for you to update your object if necessary
// Return 1 (do not call again) or 0 (continue calling)
BOOL ExtObject::OnFrame()
{
return 1; // Do not call again
}
// Called every frame, after the events and before drawing, for you to update your object if necessary
// Return 1 (do not call again) or 0 (continue calling)
// It is not safe to destroy objects in OnFrame2(). If you have to do this, use OnFrame().
// If you are storing any pointers to CRunObjects, check the info.destroying flag here. If it is true,
// you must reset the pointer to NULL as it is no longer valid.
BOOL ExtObject::OnFrame2()
{
return 1; // Do not call again
}
// WindowProc: called when a window message, or WM_COMMAND specifying your window,
// is sent to Construct. You must call RegisterWindow() before Construct will send
// you messages for the given window.
LRESULT ExtObject::WindowProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
return DefWindowProc(hWnd, uMessage, wParam, lParam);
}
BOOL ExtObject::PreTranslateMessage(MSG* msg)
{
return 0;
}
// For global objects
void ExtObject::OnFrameChange(int oldFrame, int newFrame)
{
// Do anything your global object needs when the frame changes
// oldFrame is -1 on start of app, newFrame is -1 on end of app
}
// User defined functions
long ExtObject::GetData(int id, void* param)
{
return 0;
}
long ExtObject::CallFunction(int id, void* param)
{
return 0;
}
#else //ifdef RUN_ONLY
CRunObject* WINAPI RTCreateObject(bin& ar, VRuntime* pRuntime)
{
return NULL;
}
void WINAPI RTDestroyObject(ExtObject* object)
{
}
#endif