1 | //||||||||||||||||||||||||||||||||||||||||||||||| |
---|
2 | |
---|
3 | #include "DemoApp.hpp" |
---|
4 | |
---|
5 | #include <OgreLight.h> |
---|
6 | #include <OgreWindowEventUtilities.h> |
---|
7 | |
---|
8 | //||||||||||||||||||||||||||||||||||||||||||||||| |
---|
9 | |
---|
10 | DemoApp::DemoApp() |
---|
11 | { |
---|
12 | |
---|
13 | } |
---|
14 | |
---|
15 | //||||||||||||||||||||||||||||||||||||||||||||||| |
---|
16 | |
---|
17 | DemoApp::~DemoApp() |
---|
18 | { |
---|
19 | StereoConfig_Write() ; // write out the stereo configuration. Just rough for now, a binary file |
---|
20 | |
---|
21 | |
---|
22 | } |
---|
23 | |
---|
24 | //||||||||||||||||||||||||||||||||||||||||||||||| |
---|
25 | |
---|
26 | void DemoApp::startDemo() |
---|
27 | { |
---|
28 | |
---|
29 | |
---|
30 | m_bShutdown = false; |
---|
31 | |
---|
32 | |
---|
33 | |
---|
34 | |
---|
35 | |
---|
36 | |
---|
37 | |
---|
38 | new OgreFramework(); |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | OgreFramework::getSingletonPtr()->initOgre("Video Start", this, 0); |
---|
43 | |
---|
44 | BZNConfig_Read() ; |
---|
45 | |
---|
46 | OgreFramework::getSingletonPtr()->AdditionalSetup() ; |
---|
47 | |
---|
48 | if(!setupDemoScene()) return ; // failure setting up level |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | //runDemo_Default(); |
---|
53 | runDemo_MethodA(); |
---|
54 | |
---|
55 | OgreFramework::getSingletonPtr()->UnloadMap(true) ; |
---|
56 | //OgreFramework::getSingletonPtr()->OFBug.MessageInt(333) ; |
---|
57 | //delete OgreFramework::getSingletonPtr(); // causes a crash on exit in 1.7, was ok in 1.6.3 |
---|
58 | //OgreFramework::getSingletonPtr()-> |
---|
59 | |
---|
60 | OgreFramework::getSingletonPtr()->FinalShutdown() ; |
---|
61 | |
---|
62 | |
---|
63 | //OgreFramework::getSingletonPtr()->OFBug.MessageInt(333) ; |
---|
64 | |
---|
65 | } |
---|
66 | |
---|
67 | //||||||||||||||||||||||||||||||||||||||||||||||| |
---|
68 | |
---|
69 | int DemoApp::setupDemoScene() |
---|
70 | { |
---|
71 | return OgreFramework::getSingletonPtr()->LoadMap() ; |
---|
72 | } |
---|
73 | |
---|
74 | //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |
---|
75 | |
---|
76 | // four different versions of runDemo() depending on method of GPUBuffer flushing. |
---|
77 | |
---|
78 | int DemoApp::runDemo_Default() |
---|
79 | { |
---|
80 | |
---|
81 | OgreFramework::getSingletonPtr()->m_pLog->logMessage("Start main loop (Default)..."); |
---|
82 | |
---|
83 | char chMessage[1024] ; |
---|
84 | |
---|
85 | UINT uFrameStartTime=OgreFramework::getSingletonPtr()->m_pTimer->getMilliseconds(); |
---|
86 | UINT uFrameTotalTime=0 ; |
---|
87 | |
---|
88 | OgreFramework::getSingletonPtr()->m_pRenderWnd->resetStatistics() ; |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | |
---|
94 | while(!m_bShutdown && !OgreFramework::getSingletonPtr()->isOgreToBeShutDown()) |
---|
95 | { |
---|
96 | |
---|
97 | |
---|
98 | |
---|
99 | |
---|
100 | if(OgreFramework::getSingletonPtr()->m_pRenderWnd->isClosed())m_bShutdown = true; |
---|
101 | |
---|
102 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
103 | Ogre::WindowEventUtilities::messagePump() ; |
---|
104 | #endif |
---|
105 | |
---|
106 | |
---|
107 | |
---|
108 | |
---|
109 | if(OgreFramework::getSingletonPtr()->m_pRenderWnd->isActive()) |
---|
110 | { |
---|
111 | |
---|
112 | |
---|
113 | // get start time of frame |
---|
114 | uFrameStartTime=OgreFramework::getSingletonPtr()->m_pTimer->getMicroseconds() ; |
---|
115 | |
---|
116 | // update input and physics |
---|
117 | OgreFramework::getSingletonPtr()->m_pKeyboard->capture(); |
---|
118 | OgreFramework::getSingletonPtr()->m_pMouse->capture(); |
---|
119 | OgreFramework::getSingletonPtr()->updateOgre(uFrameTotalTime/1000.0f); |
---|
120 | |
---|
121 | |
---|
122 | // render the frame |
---|
123 | OgreFramework::getSingletonPtr()->UpdateRenderTargets() ; |
---|
124 | |
---|
125 | |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | // calculate frame time. |
---|
130 | uFrameTotalTime=OgreFramework::getSingletonPtr()->m_pTimer->getMicroseconds()-uFrameStartTime ; |
---|
131 | |
---|
132 | } |
---|
133 | else |
---|
134 | { |
---|
135 | Sleep(1000); |
---|
136 | } |
---|
137 | |
---|
138 | |
---|
139 | } |
---|
140 | |
---|
141 | |
---|
142 | |
---|
143 | OgreFramework::getSingletonPtr()->m_pLog->logMessage("Main loop quit (Default)"); |
---|
144 | OgreFramework::getSingletonPtr()->m_pLog->logMessage("Shutdown OGRE..."); |
---|
145 | |
---|
146 | |
---|
147 | return 1 ; |
---|
148 | } |
---|
149 | |
---|
150 | int DemoApp::runDemo_MethodA() |
---|
151 | { |
---|
152 | |
---|
153 | OgreFramework::getSingletonPtr()->m_pLog->logMessage("Start main loop (MethodA)..."); |
---|
154 | |
---|
155 | char chMessage[1024] ; |
---|
156 | |
---|
157 | UINT uFrameStartTime=OgreFramework::getSingletonPtr()->m_pTimer->getMilliseconds(); |
---|
158 | UINT uFrameTotalTime=0 ; |
---|
159 | |
---|
160 | OgreFramework::getSingletonPtr()->m_pRenderWnd->resetStatistics() ; |
---|
161 | |
---|
162 | |
---|
163 | |
---|
164 | |
---|
165 | ///////////////////////////////////////////////////////////////////////////////////////////// |
---|
166 | // use a renderQueueListener with 1 to 4 HardwareOcclusionQueries to prevent the CPU from |
---|
167 | // getting too far ahead of the GPU and causing input lag from keyboard and mouse. |
---|
168 | // thanks to Sinbad for this suggestion and code outline. |
---|
169 | // We aren't actually doing Hardware Occlusion Culling, just exploiting the way we can |
---|
170 | // make it flush the GPU buffer for prior frames. |
---|
171 | // Messing with the GPU command buffer can be turned off completely by seting m_nMaxGPUQuery to 0 |
---|
172 | |
---|
173 | |
---|
174 | // get the maximum gpu queries to be used. |
---|
175 | int nMaxGPUQuery=OgreFramework::getSingletonPtr()->m_nMaxGPUQuery ; |
---|
176 | unsigned int dummy=0 ; |
---|
177 | int nNewQuery=0 ; |
---|
178 | int nOldQuery=0 ; |
---|
179 | rQueueListener* rqListener=NULL ; |
---|
180 | Ogre::HardwareOcclusionQuery** pHOQ=NULL ; |
---|
181 | |
---|
182 | int nQueryReady[MAXGPUQUERY] ; |
---|
183 | |
---|
184 | |
---|
185 | if(nMaxGPUQuery!=0) // if querying is turned on |
---|
186 | { |
---|
187 | // make sure it is in range. |
---|
188 | if(nMaxGPUQuery<1) |
---|
189 | nMaxGPUQuery=1 ; |
---|
190 | else |
---|
191 | if(nMaxGPUQuery>MAXGPUQUERY) |
---|
192 | nMaxGPUQuery=MAXGPUQUERY ; |
---|
193 | |
---|
194 | |
---|
195 | rqListener = new rQueueListener ; |
---|
196 | |
---|
197 | OgreFramework::getSingletonPtr()->m_pSceneMgr->addRenderQueueListener(rqListener) ; |
---|
198 | |
---|
199 | // create our queries |
---|
200 | pHOQ=rqListener->Query ; |
---|
201 | for(nNewQuery=0 ; nNewQuery<nMaxGPUQuery ; nNewQuery++) |
---|
202 | pHOQ[nNewQuery] = OgreFramework::getSingletonPtr()->m_pRoot->getRenderSystem()->createHardwareOcclusionQuery() ; |
---|
203 | |
---|
204 | nNewQuery=nOldQuery-1 ; |
---|
205 | if(nNewQuery<0) |
---|
206 | nNewQuery+=nMaxGPUQuery ; |
---|
207 | |
---|
208 | // set the queries to not ready |
---|
209 | for(int nReadyLoop=0 ; nReadyLoop<MAXGPUQUERY ; nReadyLoop++) |
---|
210 | nQueryReady[nReadyLoop]=0 ; |
---|
211 | } |
---|
212 | // |
---|
213 | ///////////////////////////////////////////////////////////////////////////////////////////// |
---|
214 | |
---|
215 | |
---|
216 | |
---|
217 | while(!m_bShutdown && !OgreFramework::getSingletonPtr()->isOgreToBeShutDown()) |
---|
218 | { |
---|
219 | |
---|
220 | |
---|
221 | |
---|
222 | |
---|
223 | if(OgreFramework::getSingletonPtr()->m_pRenderWnd->isClosed())m_bShutdown = true; |
---|
224 | |
---|
225 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
226 | Ogre::WindowEventUtilities::messagePump() ; |
---|
227 | #endif |
---|
228 | |
---|
229 | |
---|
230 | //OgreFramework::getSingletonPtr()->m_pLog->logMessage("Update START"); |
---|
231 | |
---|
232 | |
---|
233 | if(OgreFramework::getSingletonPtr()->m_pRenderWnd->isActive()) |
---|
234 | { |
---|
235 | |
---|
236 | // get start time of frame |
---|
237 | uFrameStartTime=OgreFramework::getSingletonPtr()->m_pTimer->getMicroseconds() ; |
---|
238 | |
---|
239 | // update input and physics |
---|
240 | OgreFramework::getSingletonPtr()->m_pKeyboard->capture(); |
---|
241 | OgreFramework::getSingletonPtr()->m_pMouse->capture(); |
---|
242 | OgreFramework::getSingletonPtr()->updateOgre(uFrameTotalTime/1000.0f); |
---|
243 | |
---|
244 | |
---|
245 | if(nMaxGPUQuery==0) // querying the GPU command buffer is disabled |
---|
246 | { |
---|
247 | // render the frame |
---|
248 | OgreFramework::getSingletonPtr()->UpdateRenderTargets() ; |
---|
249 | } |
---|
250 | else // querying the GPU command buffer is enabled |
---|
251 | { |
---|
252 | // increment the buffer. |
---|
253 | nNewQuery=nOldQuery ; |
---|
254 | nOldQuery++ ; |
---|
255 | if(nOldQuery==nMaxGPUQuery) |
---|
256 | nOldQuery=0 ; |
---|
257 | |
---|
258 | |
---|
259 | // define query beginning for this frame |
---|
260 | pHOQ[ nNewQuery ]->beginOcclusionQuery() ; |
---|
261 | |
---|
262 | // render the frame |
---|
263 | //OgreFramework::getSingletonPtr()->m_pRoot->renderOneFrame(); |
---|
264 | OgreFramework::getSingletonPtr()->UpdateRenderTargets() ; |
---|
265 | |
---|
266 | // define query end for this frame |
---|
267 | pHOQ[ nNewQuery ]->endOcclusionQuery() ; |
---|
268 | nQueryReady[ nNewQuery ]=1 ; |
---|
269 | |
---|
270 | |
---|
271 | |
---|
272 | // pull query for a prior frame. Flushes GPU command buffer up to the end of a prior frame but no further. |
---|
273 | if(nQueryReady[ nOldQuery ]) |
---|
274 | { |
---|
275 | pHOQ[ nOldQuery ]->pullOcclusionQuery(&dummy) ; |
---|
276 | nQueryReady[ nOldQuery ]=0 ; |
---|
277 | } |
---|
278 | } |
---|
279 | |
---|
280 | |
---|
281 | |
---|
282 | // calculate frame time. |
---|
283 | uFrameTotalTime=OgreFramework::getSingletonPtr()->m_pTimer->getMicroseconds()-uFrameStartTime ; |
---|
284 | |
---|
285 | } |
---|
286 | else |
---|
287 | { |
---|
288 | Sleep(1000); |
---|
289 | } |
---|
290 | |
---|
291 | |
---|
292 | } |
---|
293 | |
---|
294 | if(nMaxGPUQuery>0) // if necessary, clean up our HOQ queries and renderQueueListener |
---|
295 | { |
---|
296 | |
---|
297 | for(nNewQuery=0 ; nNewQuery<nMaxGPUQuery ; nNewQuery++) |
---|
298 | OgreFramework::getSingletonPtr()->m_pRoot->getRenderSystem()->destroyHardwareOcclusionQuery( pHOQ[nNewQuery] ) ; |
---|
299 | |
---|
300 | OgreFramework::getSingletonPtr()->m_pSceneMgr->removeRenderQueueListener(rqListener) ; |
---|
301 | delete rqListener ; |
---|
302 | } |
---|
303 | |
---|
304 | |
---|
305 | OgreFramework::getSingletonPtr()->m_pLog->logMessage("Main loop quit (MethodA)"); |
---|
306 | OgreFramework::getSingletonPtr()->m_pLog->logMessage("Shutdown OGRE..."); |
---|
307 | |
---|
308 | |
---|
309 | return 1 ; |
---|
310 | } |
---|
311 | |
---|
312 | int DemoApp::runDemo_MethodB() |
---|
313 | { |
---|
314 | |
---|
315 | OgreFramework::getSingletonPtr()->m_pLog->logMessage("Start main loop (MethodB)..."); |
---|
316 | |
---|
317 | char chMessage[1024] ; |
---|
318 | |
---|
319 | UINT uFrameStartTime=OgreFramework::getSingletonPtr()->m_pTimer->getMilliseconds(); |
---|
320 | UINT uFrameTotalTime=0 ; |
---|
321 | |
---|
322 | OgreFramework::getSingletonPtr()->m_pRenderWnd->resetStatistics() ; |
---|
323 | |
---|
324 | |
---|
325 | |
---|
326 | int numberOfQueuedFrames=1 ; |
---|
327 | bool GPUBufferSetupDone=false ; |
---|
328 | |
---|
329 | |
---|
330 | while(!m_bShutdown && !OgreFramework::getSingletonPtr()->isOgreToBeShutDown()) |
---|
331 | { |
---|
332 | |
---|
333 | |
---|
334 | |
---|
335 | |
---|
336 | if(OgreFramework::getSingletonPtr()->m_pRenderWnd->isClosed())m_bShutdown = true; |
---|
337 | |
---|
338 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
339 | Ogre::WindowEventUtilities::messagePump() ; |
---|
340 | #endif |
---|
341 | |
---|
342 | |
---|
343 | if(OgreFramework::getSingletonPtr()->m_pRenderWnd->isActive()) |
---|
344 | { |
---|
345 | |
---|
346 | |
---|
347 | if(GPUBufferSetupDone==false) // I added it here because I assume I can be very sure there's an active render window by now. |
---|
348 | { |
---|
349 | GPUBufferSetupDone=true ; |
---|
350 | mBufferFlush.start(numberOfQueuedFrames); |
---|
351 | } |
---|
352 | |
---|
353 | // get start time of frame |
---|
354 | uFrameStartTime=OgreFramework::getSingletonPtr()->m_pTimer->getMicroseconds() ; |
---|
355 | |
---|
356 | // update input and physics |
---|
357 | OgreFramework::getSingletonPtr()->m_pKeyboard->capture(); |
---|
358 | OgreFramework::getSingletonPtr()->m_pMouse->capture(); |
---|
359 | OgreFramework::getSingletonPtr()->updateOgre(uFrameTotalTime/1000.0f); |
---|
360 | |
---|
361 | |
---|
362 | // render the frame |
---|
363 | OgreFramework::getSingletonPtr()->UpdateRenderTargets() ; |
---|
364 | |
---|
365 | |
---|
366 | |
---|
367 | |
---|
368 | // calculate frame time. |
---|
369 | uFrameTotalTime=OgreFramework::getSingletonPtr()->m_pTimer->getMicroseconds()-uFrameStartTime ; |
---|
370 | |
---|
371 | } |
---|
372 | else |
---|
373 | { |
---|
374 | Sleep(1000); |
---|
375 | } |
---|
376 | |
---|
377 | |
---|
378 | |
---|
379 | } |
---|
380 | |
---|
381 | |
---|
382 | mBufferFlush.stop() ; |
---|
383 | |
---|
384 | OgreFramework::getSingletonPtr()->m_pLog->logMessage("Main loop quit (MethodB)"); |
---|
385 | OgreFramework::getSingletonPtr()->m_pLog->logMessage("Shutdown OGRE..."); |
---|
386 | |
---|
387 | |
---|
388 | return 1 ; |
---|
389 | } |
---|
390 | |
---|
391 | |
---|
392 | int DemoApp::runDemo_MethodC() |
---|
393 | { |
---|
394 | |
---|
395 | OgreFramework::getSingletonPtr()->m_pLog->logMessage("Start main loop (MethodC)..."); |
---|
396 | |
---|
397 | char chMessage[1024] ; |
---|
398 | |
---|
399 | int uFrameStartTime=OgreFramework::getSingletonPtr()->m_pTimer->getMilliseconds(); |
---|
400 | int uFrameRenderTime=0 ; |
---|
401 | int uFrameTargetTime=10000 ; |
---|
402 | |
---|
403 | OgreFramework::getSingletonPtr()->m_pRenderWnd->resetStatistics() ; |
---|
404 | |
---|
405 | |
---|
406 | |
---|
407 | int uSleepTime=0 ; |
---|
408 | |
---|
409 | while(!m_bShutdown && !OgreFramework::getSingletonPtr()->isOgreToBeShutDown()) |
---|
410 | { |
---|
411 | |
---|
412 | |
---|
413 | |
---|
414 | |
---|
415 | if(OgreFramework::getSingletonPtr()->m_pRenderWnd->isClosed())m_bShutdown = true; |
---|
416 | |
---|
417 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
418 | Ogre::WindowEventUtilities::messagePump() ; |
---|
419 | #endif |
---|
420 | |
---|
421 | |
---|
422 | |
---|
423 | |
---|
424 | if(OgreFramework::getSingletonPtr()->m_pRenderWnd->isActive()) |
---|
425 | { |
---|
426 | |
---|
427 | |
---|
428 | // get start time of frame |
---|
429 | uFrameStartTime=OgreFramework::getSingletonPtr()->m_pTimer->getMicroseconds() ; |
---|
430 | |
---|
431 | // update input and physics |
---|
432 | OgreFramework::getSingletonPtr()->m_pKeyboard->capture(); |
---|
433 | OgreFramework::getSingletonPtr()->m_pMouse->capture(); |
---|
434 | OgreFramework::getSingletonPtr()->updateOgre(uFrameTargetTime/1000.0f); |
---|
435 | |
---|
436 | |
---|
437 | // render the frame |
---|
438 | OgreFramework::getSingletonPtr()->UpdateRenderTargets() ; |
---|
439 | |
---|
440 | |
---|
441 | // calculate frame time. |
---|
442 | uFrameRenderTime=OgreFramework::getSingletonPtr()->m_pTimer->getMicroseconds()-uFrameStartTime ; |
---|
443 | |
---|
444 | |
---|
445 | uFrameTargetTime-=1000 ; |
---|
446 | if(uFrameTargetTime<0) uFrameTargetTime=0 ; |
---|
447 | |
---|
448 | if(uFrameRenderTime>uFrameTargetTime-10000) |
---|
449 | uFrameTargetTime=uFrameRenderTime+20000 ; |
---|
450 | |
---|
451 | if(uFrameTargetTime>100000) uFrameTargetTime=100000 ; |
---|
452 | |
---|
453 | |
---|
454 | |
---|
455 | |
---|
456 | |
---|
457 | uSleepTime=(uFrameTargetTime-uFrameRenderTime)/1000.0f ; |
---|
458 | if(uSleepTime>0) Sleep(uSleepTime) ; |
---|
459 | |
---|
460 | sprintf(chMessage, "render %i, target %i, sleep %i", uFrameRenderTime, uFrameTargetTime, uSleepTime) ; |
---|
461 | OgreFramework::getSingletonPtr()->m_pLog->logMessage(chMessage); |
---|
462 | |
---|
463 | } |
---|
464 | else |
---|
465 | { |
---|
466 | Sleep(1000); |
---|
467 | } |
---|
468 | |
---|
469 | |
---|
470 | } |
---|
471 | |
---|
472 | |
---|
473 | |
---|
474 | OgreFramework::getSingletonPtr()->m_pLog->logMessage("Main loop quit (MethodC)"); |
---|
475 | OgreFramework::getSingletonPtr()->m_pLog->logMessage("Shutdown OGRE..."); |
---|
476 | |
---|
477 | |
---|
478 | return 1 ; |
---|
479 | } |
---|
480 | |
---|
481 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
482 | |
---|
483 | |
---|
484 | |
---|
485 | |
---|
486 | |
---|
487 | |
---|
488 | |
---|
489 | void DemoApp::ResetSectionTimer() |
---|
490 | { |
---|
491 | m_uLastTime=OgreFramework::getSingletonPtr()->m_pTimer->getMicroseconds() ; |
---|
492 | } |
---|
493 | |
---|
494 | UINT DemoApp::GetSectionTimer() |
---|
495 | { |
---|
496 | UINT uThisTime=OgreFramework::getSingletonPtr()->m_pTimer->getMicroseconds() ; |
---|
497 | UINT uSectionTime=uThisTime-m_uLastTime ; |
---|
498 | m_uLastTime=uThisTime ; |
---|
499 | return uSectionTime ; |
---|
500 | } |
---|
501 | |
---|
502 | //||||||||||||||||||||||||||||||||||||||||||||||| |
---|
503 | |
---|
504 | |
---|
505 | bool DemoApp::keyPressed(const OIS::KeyEvent &keyEventRef) |
---|
506 | { |
---|
507 | |
---|
508 | OgreFramework::getSingletonPtr()->keyPressed(keyEventRef); |
---|
509 | |
---|
510 | if(OgreFramework::getSingletonPtr()->m_pKeyboard->isKeyDown(OIS::KC_F)) |
---|
511 | { |
---|
512 | //do something |
---|
513 | } |
---|
514 | |
---|
515 | return true; |
---|
516 | } |
---|
517 | |
---|
518 | //||||||||||||||||||||||||||||||||||||||||||||||| |
---|
519 | |
---|
520 | bool DemoApp::keyReleased(const OIS::KeyEvent &keyEventRef) |
---|
521 | { |
---|
522 | OgreFramework::getSingletonPtr()->keyReleased(keyEventRef); |
---|
523 | |
---|
524 | return true; |
---|
525 | } |
---|
526 | |
---|
527 | |
---|
528 | //||||||||||||||||||||||||||||||||||||||||||||||| |
---|
529 | |
---|
530 | void DemoApp::StereoConfig_Write( void ) |
---|
531 | { |
---|
532 | int fh; |
---|
533 | if( (fh = _open( "stereoscopic.cfg", _O_RDWR | _O_BINARY | _O_CREAT | _O_TRUNC, |
---|
534 | _S_IREAD | _S_IWRITE )) != -1 ) |
---|
535 | { |
---|
536 | write( fh, (void*)&OgreFramework::getSingletonPtr()->m_nGoggleMode, sizeof(int)) ; |
---|
537 | write( fh, (void*)&OgreFramework::getSingletonPtr()->m_flGoggleZPos, sizeof(float)) ; |
---|
538 | write( fh, (void*)&OgreFramework::getSingletonPtr()->m_flGoggleXGap, sizeof(float)) ; |
---|
539 | write( fh, (void*)&OgreFramework::getSingletonPtr()->m_flGoggleXScale, sizeof(float)) ; |
---|
540 | write( fh, (void*)&OgreFramework::getSingletonPtr()->m_flGoggleYScale, sizeof(float)) ; |
---|
541 | _close( fh ); |
---|
542 | } |
---|
543 | } |
---|
544 | bool DemoApp::StereoConfig_Read(void) |
---|
545 | { |
---|
546 | int fh; |
---|
547 | bool found_file=true ; |
---|
548 | |
---|
549 | // Open file for input |
---|
550 | if( (fh = _open( "stereoscopic.cfg", _O_RDONLY | _O_BINARY )) == -1 ) |
---|
551 | { |
---|
552 | found_file=false ; |
---|
553 | } |
---|
554 | else |
---|
555 | { |
---|
556 | read( fh, (void*)&OgreFramework::getSingletonPtr()->m_nGoggleMode, sizeof(int)) ; |
---|
557 | read( fh, (void*)&OgreFramework::getSingletonPtr()->m_flGoggleZPos, sizeof(float)) ; |
---|
558 | read( fh, (void*)&OgreFramework::getSingletonPtr()->m_flGoggleXGap, sizeof(float)) ; |
---|
559 | read( fh, (void*)&OgreFramework::getSingletonPtr()->m_flGoggleXScale, sizeof(float)) ; |
---|
560 | read( fh, (void*)&OgreFramework::getSingletonPtr()->m_flGoggleYScale, sizeof(float)) ; |
---|
561 | _close( fh ); |
---|
562 | }// end if else |
---|
563 | return found_file ; |
---|
564 | } |
---|
565 | |
---|
566 | |
---|
567 | void DemoApp::BZNConfig_Write(void) |
---|
568 | { |
---|
569 | int fh; |
---|
570 | if( (fh = _open( "bzn.cfg", _O_RDWR | _O_BINARY | _O_CREAT | _O_TRUNC, |
---|
571 | _S_IREAD | _S_IWRITE )) != -1 ) |
---|
572 | { |
---|
573 | write( fh, (void*)OgreFramework::getSingletonPtr()->m_chBZNConfig, BZN_CONFIG_SIZE) ; |
---|
574 | _close( fh ); |
---|
575 | } |
---|
576 | } |
---|
577 | |
---|
578 | bool DemoApp::BZNConfig_Read(void) |
---|
579 | { |
---|
580 | |
---|
581 | int fh; |
---|
582 | bool found_file=true ; |
---|
583 | |
---|
584 | // make sure the config memory is blank |
---|
585 | ZeroMemory((void*)OgreFramework::getSingletonPtr()->m_chBZNConfig, BZN_CONFIG_SIZE) ; |
---|
586 | |
---|
587 | // Open file for input |
---|
588 | if( (fh = _open( "bzn.cfg", _O_RDONLY | _O_BINARY )) == -1 ) |
---|
589 | { |
---|
590 | found_file=false ; |
---|
591 | } |
---|
592 | else |
---|
593 | { |
---|
594 | read( fh, (void*)OgreFramework::getSingletonPtr()->m_chBZNConfig, BZN_CONFIG_SIZE) ; |
---|
595 | _close( fh ); |
---|
596 | OgreFramework::getSingletonPtr()->ParseBZNConfig() ; |
---|
597 | }// end if else |
---|
598 | |
---|
599 | |
---|
600 | return found_file ; |
---|
601 | |
---|
602 | } |
---|