forked from secred/Tachycardia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.cs
387 lines (314 loc) · 12.2 KB
/
core.cs
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Tachycardia
{
class Core
{
public static Core Singleton()
{
return new Core();
}
public Core()
{
m_config = 0;
//!config
m_stateManager = 0;
m_root = null;
m_renderWnd = null;
m_viewport = null;
m_log = null;
m_timer = null;
m_inputMgr = null;
m_keyboard = null;
m_mouse = null;
m_update = 1.0f / 120;
m_elapsed = 0.0f;
/*
for (int i = 0; i < 256; ++i)
m_keyStates[i] = false;
*/
}
public Boolean Start()
{
//GameState.create(m_stateManager, "GameState");
//MenuState.create(m_stateManager, "MenuState");
//PauseState.create(m_stateManager, "PauseState");
m_stateManager->pushState( "MenuState" );
m_stateManager->start();
return true;
}
public Boolean Init(String wndTitle, MOIS.KeyListener keyListener = null, MOIS.MouseListener mouseListener = null)
{
#if DEBUG
m_resourcesCfg = "../../res/resources_d.cfg";
m_pluginsCfg = "../../res/plugins_d.cfg";
#else
m_ResourcesCfg = "../../res/resources.cfg";
m_luginsCfg = "../../res/plugins.cfg";
#endif
//m_ResourcesCfg = "../../res/resources.cfg";
//m_luginsCfg = "../../res/plugins.cfg";
SetupLog();
GetLog().LogMessage("Initialize SECred Framework...");
m_root = new Mogre.Root( m_pluginsCfg );
if(!m_root.ShowConfigDialog())
{
return false;
}
m_renderWnd = m_root.Initialise(true, wndTitle);
GetRoot().AddFrameListener(this);
SetupViewport();
GetLog().LogMessage("ViewPort ready.");
SetupInputSystem( keyListener, mouseListener );
GetLog().LogMessage("InputSystem ready.");
SetupResources();
GetLog().LogMessage("Resources ready.");
Mogre.TextureManager.Singleton.DefaultNumMipmaps = 5;
Mogre.ResourceGroupManager.Singleton.InitialiseAllResourceGroups();
GetLog().LogMessage("TrayManager ready.");
m_timer = new Mogre.Timer();
m_timer.Reset();
GetLog().LogMessage("Timer ready.");
//config
//m_config = new Config( "../../res/game_config.xml" );
GetLog().LogMessage("ConfigManager ready.");
//!config
//m_stateManager = new StateManager();
GetLog().LogMessage("StateManager ready.");
/*
//CEgui initialization
mainRenderer = &CEGUI.OgreRenderer.bootstrapSystem();
// set the default resource groups to be used
CEGUI.Imageset.setDefaultResourceGroup((CEGUI.utf8*)"Imagesets");
CEGUI.Font.setDefaultResourceGroup((CEGUI.utf8*)"Fonts");
CEGUI.Scheme.setDefaultResourceGroup((CEGUI.utf8*)"Schemes");
CEGUI.WidgetLookManager.setDefaultResourceGroup((CEGUI.utf8*)"LookNFeel");
CEGUI.WindowManager.setDefaultResourceGroup((CEGUI.utf8*)"Layouts");
//setup default group for validation schemas
CEGUI.XMLParser* parser = CEGUI.System.getSingleton().getXMLParser();
if (parser->isPropertyPresent((CEGUI.utf8*)"SchemaDefaultResourceGroup"))
parser->setProperty((CEGUI.utf8*)"SchemaDefaultResourceGroup", (CEGUI.utf8*)"schemas");
//wybranie stylu CEgui
CEGUI.SchemeManager.getSingleton().create((CEGUI.utf8*)"SECred.scheme");
//kursor
CEGUI.System.getSingleton().setDefaultMouseCursor((CEGUI.utf8*)"SECred", (CEGUI.utf8*)"MouseArrow");
//Tooltips - jeszcze nie wiem czy bedziemy tego uzywac
CEGUI.System.getSingleton().setDefaultTooltip((CEGUI.utf8*)"SECred/Tooltip");
GetLog().LogMessage("CEgui has been initiliazed!");
*/
m_renderWnd.IsActive = true;
//MissionsCreator missions;
GetLog().LogMessage("SECred Framework initialized!");
return true;
}
public Boolean FrameRenderingQueued( Mogre.FrameEvent evt)
{
if( m_stateManager->getActiveState() )
m_stateManager->getActiveState()->updateFrameEvent( evt );
double time = evt.timeSinceLastFrame;
///// Bullet time tymczasowo wyci?ty
//if( m_keyStates[OIS.KC_B] )
// time = 0.3 * evt.timeSinceLastFrame;
//else
// time = 1.0 * evt.timeSinceLastFrame;
double tElapsed = m_elapsed += time;
double tUpdate = m_update;
// loop through and update as many times as necessary (up to 10 times maximum).
if ((tElapsed > tUpdate) && (tElapsed < (tUpdate * 10)) )
{
while (tElapsed > tUpdate)
{
//for( std.list<TimeObserver *>.iterator it = m_TimeObservers.begin(); it != m_TimeObservers.end(); it++ )
// (*it)->update( tUpdate );
m_stateManager->update( tUpdate );
tElapsed -= tUpdate;
}
}
else
{
if (tElapsed < tUpdate)
{
// not enough time has passed this loop, so ignore for now.
}
else
{
// too much time has passed (would require more than 10 updates!), so just update once and reset.
// this often happens on the first frame of a game, where assets and other things were loading, then
// the elapsed time since the last drawn frame is very long.
//for( std.list<TimeObserver *>.iterator it = m_TimeObservers.begin(); it != m_TimeObservers.end(); it++ )
// (*it)->update( tUpdate );
m_stateManager->update( tUpdate );
tElapsed = 0.0f; // reset the elapsed time so we don't become "eternally behind".
}
}
Core.Singleton().m_elapsed = tElapsed;
Core.Singleton().m_update = tUpdate;
//wstrzykiwanie uplywu czasu do CEgui
//CEGUI.System.getSingleton().injectTimePulse(evt.timeSinceLastFrame);
return true;
}
public Boolean KeyPressed( MOIS.KeyEvent keyEventRef)
{
m_stateManager.keyPressed( keyEventRef );
m_keyStates[ keyEventRef.key ] = true;
return true;
}
public Boolean KeyReleased( MOIS.KeyEvent keyEventRef)
{
if (keyEventRef.key == MOIS.KeyCode.KC_KANJI || keyEventRef.key == MOIS.KeyCode.KC_GRAVE || keyEventRef.key == OIS.KC_TAB)
/*{
if (Console.getSingleton().isVisible())
Console.getSingleton().hide();
else
Console.getSingleton().show();
}*/
m_stateManager.keyReleased( keyEventRef );
m_keyStates[ keyEventRef.key ] = false;
return true;
}
public Boolean MouseMoved( MOIS.MouseEvent evt)
{
m_stateManager.mouseMoved( evt );
return true;
}
public Boolean MousePressed( MOIS.MouseEvent evt, MOIS.MouseButtonID id)
{
m_stateManager.mousePressed( evt, id );
return true;
}
public Boolean MouseReleased( MOIS.MouseEvent evt, MOIS.MouseButtonID id)
{
m_stateManager.mouseReleased( evt, id );
return true;
}
public Config GetConfig()
{
return m_config;
}
public StateManager GetStateManager()
{
return m_stateManager;
}
public Mogre.Root GetRoot()
{
return m_root;
}
public Mogre.RenderWindow GetRenderWnd()
{
return m_renderWnd;
}
public Mogre.Viewport GetViewport()
{
return m_viewport;
}
public Mogre.Log GetLog()
{
return m_log;
}
public Mogre.Timer GetTimer()
{
return m_timer;
}
public MOIS.InputManager GetInputMgr()
{
return m_inputMgr;
}
public MOIS.Keyboard GetKeyboard()
{
return m_keyboard;
}
public MOIS.Mouse GetMouse()
{
return m_mouse;
}
//public CEGUI.MogreRenderer getMogreRenderer();
public Boolean GetKeyState( MOIS.KeyCode keyCode )
{
return m_keyStates[ keyCode ];
}
private void SetupLog()
{
Mogre.LogManager logMgr = new Mogre.LogManager();
m_log = Mogre.LogManager.Singleton.CreateLog("OgreLogfile.log", true, true, false);
m_log.SetDebugOutputEnabled(true);
}
private void SetupViewport()
{
m_viewport = m_renderWnd.AddViewport( null );
m_viewport.BackgroundColour = new Mogre.ColourValue(0.5f, 0.5f, 0.5f, 1.0f);
}
private void SetupInputSystem(MOIS.KeyListener pKeyListener, MOIS.MouseListener pMouseListener)
{
ulong hWnd = 0;
MOIS.ParamList paramList;
paramList.Insert( "WINDOW", Mogre.StringConverter.ToString(hWnd));
m_inputMgr = MOIS.InputManager.CreateInputSystem(paramList);
m_keyboard = (MOIS.Keyboard) m_inputMgr.CreateInputObject( MOIS.Type.OISKeyboard, true);
m_mouse = (MOIS.Mouse) m_inputMgr.CreateInputObject(MOIS.Type.OISMouse, true));
/*m_mouse.MouseState.height = m_renderWnd.height;
m_mouse.MouseState.width = m_renderWnd.width;
if(pKeyListener == 0)
m_Keyboard->setEventCallback(this);
else
m_Keyboard->setEventCallback(pKeyListener);
if(pMouseListener == 0)
m_Mouse->setEventCallback(this);
else
m_Mouse->setEventCallback(pMouseListener);
*/
}
private void SetupResources()
{
String secName, typeName, archName;
Mogre.ConfigFile cf;
cf.Load( m_resourcesCfg, "", false );
Mogre.ConfigFile.SectionIterator seci = cf.GetSectionIterator();
while (seci.HasMoreElements())
{
secName = seci.PeekNextKey();
Mogre.ConfigFile.SettingsMultiMap settings = seci.GetNext();
Mogre.ConfigFile.SettingsMultiMap.Iterator i;
for (i = settings.Begin(); i != settings.End(); ++i)
{
typeName = i.Key;
archName = i.Value;
Mogre.ResourceGroupManager.Singleton.AddResourceLocation(archName, typeName, secName);
}
}
/*
new SoundDict();
SoundDict.Singleton().SetDirectory( "../../res/sfx/" );
SoundDict.Singleton().LoadAndInsert( "button.wav" );
SoundDict.Singleton().LoadAndInsert( "player/die_01.wav" );
SoundDict.Singleton().LoadAndInsert( "impact/box_01.wav" );
SoundDict.Singleton().LoadAndInsert( "player/jump_01.wav" );
SoundDict.Singleton().LoadAndInsert( "player/step_concrete_01.wav" );
SoundDict.Singleton().LoadAndInsert( "player/step_concrete_02.wav" );
SoundDict.Singleton().LoadAndInsert( "player/step_concrete_03.wav" );
SoundDict.Singleton().LoadAndInsert( "player/step_concrete_04.wav" );
SoundDict.Singleton().LoadAndInsert( "player/step_concrete_05.wav" );
SoundDict.Singleton().LoadAndInsert( "ambient/siren_01.wav" );
SoundDict.Singleton().Init();
*/
}
private Config m_config;
private StateManager m_stateManager;
private Mogre.Root m_root;
private Mogre.RenderWindow m_renderWnd;
private Mogre.Viewport m_viewport;
private Mogre.Log m_log;
private Mogre.Timer m_timer;
private MOIS.InputManager m_inputMgr;
private MOIS.Keyboard m_keyboard;
private MOIS.Mouse m_mouse;
//CEgui - renderer dla CEgui
//private CEGUI.MogreRenderer mainRenderer;
private String m_resourcesCfg;
private String m_pluginsCfg;
private Double m_update;
private Double m_elapsed;
private Dictionary<MOIS.KeyCode, Boolean> m_keyStates;
}
}