Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 167 vs 168 for /trunk/Source Code/Scenes/AITenisScene/AITenisScene.cpp

Diff revisions: vs.
  @@ -26,9 +26,8 @@
26 26 }
27 27
28 28 void AITenisScene::processTasks(const U32 time){
29 - F32 timeSec = getMsToSec(time); ///<convert to seconds
30 29 F32 FpsDisplay = 0.75f;
31 - if (timeSec - _taskTimers[0] >= FpsDisplay){
30 + if (getMsToSec(time) - _taskTimers[0] >= FpsDisplay){
32 31 GUI::getInstance().modifyText("fpsDisplay", "FPS: %3.0f. FrameTime: %3.1f", Framerate::getInstance().getFps(), Framerate::getInstance().getFrameTime());
33 32 GUI::getInstance().modifyText("RenderBinCount", "Number of items in Render Bin: %d", GFX_RENDER_BIN_SIZE);
34 33 _taskTimers[0] += FpsDisplay;
  @@ -217,17 +216,15 @@
217 216 }
218 217
219 218 void AITenisScene::processInput(){
220 - if(state()->_angleLR) renderState()->getCamera()->RotateX(state()->_angleLR / 5);
221 - if(state()->_angleUD) renderState()->getCamera()->RotateY(state()->_angleUD /5);
222 - if(state()->_moveFB || state()->_moveLR){
223 - if(state()->_moveFB) renderState()->getCamera()->MoveForward(state()->_moveFB);
224 - if(state()->_moveLR) renderState()->getCamera()->MoveStrafe(state()->_moveLR);
225 - }
219 + if(state()._angleLR) renderState().getCamera().rotateYaw(state()._angleLR);
220 + if(state()._angleUD) renderState().getCamera().rotatePitch(state()._angleUD);
221 + if(state()._moveFB) renderState().getCamera().moveForward(state()._moveFB);
222 + if(state()._moveLR) renderState().getCamera().moveStrafe(state()._moveLR);
226 223 }
227 224
228 - bool AITenisScene::load(const std::string& name){
229 - ///Load scene resources
230 - SCENE_LOAD(name,true,true);
225 + bool AITenisScene::load(const std::string& name, CameraManager* const cameraMgr){
226 + //Load scene resources
227 + bool loadState = SCENE_LOAD(name,cameraMgr,true,true);
231 228
232 229 //Add a light
233 230 Light* light = addDefaultLight();
  @@ -243,9 +240,9 @@
243 240 // addLight(light1);
244 241
245 242 //Position camera
246 - renderState()->getCamera()->RotateX(RADIANS(45));
247 - renderState()->getCamera()->RotateY(RADIANS(25));
248 - renderState()->getCamera()->setEye(vec3<F32>(14,5.5f,11.5f));
243 + //renderState().getCamera().setEye(vec3<F32>(14,5.5f,11.5f));
244 + //renderState().getCamera().setRotation(10/*yaw*/,-45/*pitch*/);
245 +
249 246
250 247 //------------------------ Load up game elements -----------------------------///
251 248 _net = _sceneGraph->findNode("Net");
  @@ -255,6 +252,7 @@
255 252 _floor = _sceneGraph->findNode("Floor");
256 253 _floor->getNode<SceneNode>()->getMaterial()->setCastsShadows(false);
257 254
255 + AIManager::getInstance().pauseUpdate(false);
258 256 return loadState;
259 257 }
260 258
  @@ -325,6 +323,7 @@
325 323 }
326 324
327 325 bool AITenisScene::deinitializeAI(bool continueOnErrors){
326 + AIManager::getInstance().pauseUpdate(true);
328 327 AIManager::getInstance().destroyEntity(_aiPlayer1->getGUID());
329 328 AIManager::getInstance().destroyEntity(_aiPlayer2->getGUID());
330 329 AIManager::getInstance().destroyEntity(_aiPlayer3->getGUID());
  @@ -352,22 +351,22 @@
352 351 _ball->getMaterial()->setSpecular(vec4<F32>(0.7f,0.7f,0.7f,1.0f));
353 352
354 353 GUIElement* btn = GUI::getInstance().addButton("Serve", "Serve",
355 - vec2<I32>(renderState()->cachedResolution().width-220,60),
354 + vec2<I32>(renderState().cachedResolution().width-220,60),
356 355 vec2<U32>(100,25),
357 356 vec3<F32>(0.65f,0.65f,0.65f),
358 357 DELEGATE_BIND(&AITenisScene::startGame,this));
359 358 btn->setTooltip("Start a new game!");
360 359
361 - GUI::getInstance().addText("Team1Score",vec2<I32>(renderState()->cachedResolution().width - 250,
362 - renderState()->cachedResolution().height/1.3f),
360 + GUI::getInstance().addText("Team1Score",vec2<I32>(renderState().cachedResolution().width - 250,
361 + renderState().cachedResolution().height/1.3f),
363 362 Font::DIVIDE_DEFAULT,vec3<F32>(0,0.8f,0.8f), "Team 1 Score: %d",0);
364 363
365 - GUI::getInstance().addText("Team2Score",vec2<I32>(renderState()->cachedResolution().width - 250,
366 - renderState()->cachedResolution().height/1.5f),
364 + GUI::getInstance().addText("Team2Score",vec2<I32>(renderState().cachedResolution().width - 250,
365 + renderState().cachedResolution().height/1.5f),
367 366 Font::DIVIDE_DEFAULT,vec3<F32>(0.2f,0.8f,0), "Team 2 Score: %d",0);
368 367
369 - GUI::getInstance().addText("Message",vec2<I32>(renderState()->cachedResolution().width - 250,
370 - renderState()->cachedResolution().height/1.7f),
368 + GUI::getInstance().addText("Message",vec2<I32>(renderState().cachedResolution().width - 250,
369 + renderState().cachedResolution().height/1.7f),
371 370 Font::DIVIDE_DEFAULT,vec3<F32>(0,1,0), "");
372 371
373 372 GUI::getInstance().addText("fpsDisplay", //Unique ID
  @@ -388,20 +387,11 @@
388 387 void AITenisScene::onKeyDown(const OIS::KeyEvent& key){
389 388 Scene::onKeyDown(key);
390 389 switch(key.key) {
391 - case OIS::KC_W:
392 - state()->_moveFB = 0.25f;
393 - break;
394 - case OIS::KC_A:
395 - state()->_moveLR = 0.25f;
396 - break;
397 - case OIS::KC_S:
398 - state()->_moveFB = -0.25f;
399 - break;
400 - case OIS::KC_D:
401 - state()->_moveLR = -0.25f;
402 - break;
403 - default:
404 - break;
390 + default: break;
391 + case OIS::KC_W: state()._moveFB = 1; break;
392 + case OIS::KC_A: state()._moveLR = -1; break;
393 + case OIS::KC_S: state()._moveFB = -1; break;
394 + case OIS::KC_D: state()._moveLR = 1; break;
405 395 }
406 396 }
407 397
  @@ -409,72 +399,53 @@
409 399 Scene::onKeyUp(key);
410 400 switch(key.key) {
411 401 case OIS::KC_W:
412 - case OIS::KC_S:
413 - state()->_moveFB = 0;
414 - break;
402 + case OIS::KC_S: state()._moveFB = 0; break;
415 403 case OIS::KC_A:
416 - case OIS::KC_D:
417 - state()->_moveLR = 0;
418 - break;
419 - case OIS::KC_F1:
420 - _sceneGraph->print();
421 - break;
422 - default:
423 - break;
404 + case OIS::KC_D: state()._moveLR = 0; break;
405 + case OIS::KC_F1: _sceneGraph->print(); break;
406 + default: break;
424 407 }
425 408 }
426 409
427 410 void AITenisScene::onJoystickMovePOV(const OIS::JoyStickEvent& key,I8 pov){
428 411 Scene::onJoystickMovePOV(key,pov);
429 412 if( key.state.mPOV[pov].direction & OIS::Pov::North ) //Going up
430 - state()->_moveFB = 0.25f;
413 + state()._moveFB = 1;
431 414 else if( key.state.mPOV[pov].direction & OIS::Pov::South ) //Going down
432 - state()->_moveFB = -0.25f;
415 + state()._moveFB = -1;
433 416
434 417 if( key.state.mPOV[pov].direction & OIS::Pov::East ) //Going right
435 - state()->_moveLR = -0.25f;
418 + state()._moveLR = -1;
436 419
437 420 else if( key.state.mPOV[pov].direction & OIS::Pov::West ) //Going left
438 - state()->_moveLR = 0.25f;
421 + state()._moveLR = 1;
439 422
440 423 if( key.state.mPOV[pov].direction == OIS::Pov::Centered ){ //stopped/centered out
441 - state()->_moveLR = 0;
442 - state()->_moveFB = 0;
424 + state()._moveLR = 0;
425 + state()._moveFB = 0;
443 426 }
444 427 }
445 428
446 429 void AITenisScene::onMouseMove(const OIS::MouseEvent& key){
447 - if(_mousePressed){
448 - if(_prevMouse.x - key.state.X.abs > 1 )
449 - state()->_angleLR = -0.15f;
450 - else if(_prevMouse.x - key.state.X.abs < -1 )
451 - state()->_angleLR = 0.15f;
452 - else
453 - state()->_angleLR = 0;
454 -
455 - if(_prevMouse.y - key.state.Y.abs > 1 )
456 - state()->_angleUD = -0.1f;
457 - else if(_prevMouse.y - key.state.Y.abs < -1 )
458 - state()->_angleUD = 0.1f;
459 - else
460 - state()->_angleUD = 0;
461 - }
462 -
463 - _prevMouse.x = key.state.X.abs;
464 - _prevMouse.y = key.state.Y.abs;
465 - }
466 -
467 - void AITenisScene::onMouseClickDown(const OIS::MouseEvent& key,OIS::MouseButtonID button){
468 - Scene::onMouseClickDown(key,button);
469 - if(button == 0)
470 - _mousePressed = true;
430 + if(_mousePressed[OIS::MB_Right]){
431 + if(_previousMousePos.x - key.state.X.abs > 1 ) state()._angleLR = -1;
432 + else if(_previousMousePos.x - key.state.X.abs < -1 ) state()._angleLR = 1;
433 + else state()._angleLR = 0;
434 +
435 + if(_previousMousePos.y - key.state.Y.abs > 1 ) state()._angleUD = -1;
436 + else if(_previousMousePos.y - key.state.Y.abs < -1 ) state()._angleUD = 1;
437 + else state()._angleUD = 0;
438 + }
439 +
440 + _previousMousePos.x = key.state.X.abs;
441 + _previousMousePos.y = key.state.Y.abs;
471 442 }
472 443
444 +
473 445 void AITenisScene::onMouseClickUp(const OIS::MouseEvent& key,OIS::MouseButtonID button){
474 446 Scene::onMouseClickUp(key,button);
475 - if(button == 0) {
476 - _mousePressed = false;
477 - state()->_angleUD = 0;
478 - state()->_angleLR = 0;
447 + if(!_mousePressed[OIS::MB_Right]){
448 + state()._angleUD = 0;
449 + state()._angleLR = 0;
479 450 }
480 451 }