|
@@ -19,7 +19,7 @@ Game::Game()
|
|
|
: _initialized(false), _state(UNINITIALIZED),
|
|
: _initialized(false), _state(UNINITIALIZED),
|
|
|
_frameLastFPS(0), _frameCount(0), _frameRate(0),
|
|
_frameLastFPS(0), _frameCount(0), _frameRate(0),
|
|
|
_clearDepth(1.0f), _clearStencil(0), _properties(NULL),
|
|
_clearDepth(1.0f), _clearStencil(0), _properties(NULL),
|
|
|
- _animationController(NULL), _audioController(NULL), _physicsController(NULL), _audioListener(NULL)
|
|
|
|
|
|
|
+ _animationController(NULL), _audioController(NULL), _physicsController(NULL), _aiController(NULL), _audioListener(NULL)
|
|
|
{
|
|
{
|
|
|
GP_ASSERT(__gameInstance == NULL);
|
|
GP_ASSERT(__gameInstance == NULL);
|
|
|
__gameInstance = this;
|
|
__gameInstance = this;
|
|
@@ -100,6 +100,9 @@ bool Game::startup()
|
|
|
_physicsController = new PhysicsController();
|
|
_physicsController = new PhysicsController();
|
|
|
_physicsController->initialize();
|
|
_physicsController->initialize();
|
|
|
|
|
|
|
|
|
|
+ _aiController = new AIController();
|
|
|
|
|
+ _aiController->initialize();
|
|
|
|
|
+
|
|
|
loadGamepads();
|
|
loadGamepads();
|
|
|
|
|
|
|
|
_state = RUNNING;
|
|
_state = RUNNING;
|
|
@@ -115,6 +118,7 @@ void Game::shutdown()
|
|
|
GP_ASSERT(_animationController);
|
|
GP_ASSERT(_animationController);
|
|
|
GP_ASSERT(_audioController);
|
|
GP_ASSERT(_audioController);
|
|
|
GP_ASSERT(_physicsController);
|
|
GP_ASSERT(_physicsController);
|
|
|
|
|
+ GP_ASSERT(_aiController);
|
|
|
|
|
|
|
|
Platform::signalShutdown();
|
|
Platform::signalShutdown();
|
|
|
finalize();
|
|
finalize();
|
|
@@ -134,6 +138,9 @@ void Game::shutdown()
|
|
|
_physicsController->finalize();
|
|
_physicsController->finalize();
|
|
|
SAFE_DELETE(_physicsController);
|
|
SAFE_DELETE(_physicsController);
|
|
|
|
|
|
|
|
|
|
+ _aiController->finalize();
|
|
|
|
|
+ SAFE_DELETE(_aiController);
|
|
|
|
|
+
|
|
|
SAFE_DELETE(_audioListener);
|
|
SAFE_DELETE(_audioListener);
|
|
|
|
|
|
|
|
RenderState::finalize();
|
|
RenderState::finalize();
|
|
@@ -151,11 +158,13 @@ void Game::pause()
|
|
|
GP_ASSERT(_animationController);
|
|
GP_ASSERT(_animationController);
|
|
|
GP_ASSERT(_audioController);
|
|
GP_ASSERT(_audioController);
|
|
|
GP_ASSERT(_physicsController);
|
|
GP_ASSERT(_physicsController);
|
|
|
|
|
+ GP_ASSERT(_aiController);
|
|
|
_state = PAUSED;
|
|
_state = PAUSED;
|
|
|
_pausedTimeLast = Platform::getAbsoluteTime();
|
|
_pausedTimeLast = Platform::getAbsoluteTime();
|
|
|
_animationController->pause();
|
|
_animationController->pause();
|
|
|
_audioController->pause();
|
|
_audioController->pause();
|
|
|
_physicsController->pause();
|
|
_physicsController->pause();
|
|
|
|
|
+ _aiController->pause();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -166,11 +175,13 @@ void Game::resume()
|
|
|
GP_ASSERT(_animationController);
|
|
GP_ASSERT(_animationController);
|
|
|
GP_ASSERT(_audioController);
|
|
GP_ASSERT(_audioController);
|
|
|
GP_ASSERT(_physicsController);
|
|
GP_ASSERT(_physicsController);
|
|
|
|
|
+ GP_ASSERT(_aiController);
|
|
|
_state = RUNNING;
|
|
_state = RUNNING;
|
|
|
_pausedTimeTotal += Platform::getAbsoluteTime() - _pausedTimeLast;
|
|
_pausedTimeTotal += Platform::getAbsoluteTime() - _pausedTimeLast;
|
|
|
_animationController->resume();
|
|
_animationController->resume();
|
|
|
_audioController->resume();
|
|
_audioController->resume();
|
|
|
_physicsController->resume();
|
|
_physicsController->resume();
|
|
|
|
|
+ _aiController->resume();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -192,6 +203,7 @@ void Game::frame()
|
|
|
GP_ASSERT(_animationController);
|
|
GP_ASSERT(_animationController);
|
|
|
GP_ASSERT(_audioController);
|
|
GP_ASSERT(_audioController);
|
|
|
GP_ASSERT(_physicsController);
|
|
GP_ASSERT(_physicsController);
|
|
|
|
|
+ GP_ASSERT(_aiController);
|
|
|
|
|
|
|
|
// Update Time.
|
|
// Update Time.
|
|
|
static double lastFrameTime = Game::getGameTime();
|
|
static double lastFrameTime = Game::getGameTime();
|
|
@@ -207,7 +219,10 @@ void Game::frame()
|
|
|
|
|
|
|
|
// Update the physics.
|
|
// Update the physics.
|
|
|
_physicsController->update(elapsedTime);
|
|
_physicsController->update(elapsedTime);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // Update AI.
|
|
|
|
|
+ _aiController->update(elapsedTime);
|
|
|
|
|
+
|
|
|
// Application Update.
|
|
// Application Update.
|
|
|
update(elapsedTime);
|
|
update(elapsedTime);
|
|
|
|
|
|
|
@@ -241,6 +256,7 @@ void Game::updateOnce()
|
|
|
GP_ASSERT(_animationController);
|
|
GP_ASSERT(_animationController);
|
|
|
GP_ASSERT(_audioController);
|
|
GP_ASSERT(_audioController);
|
|
|
GP_ASSERT(_physicsController);
|
|
GP_ASSERT(_physicsController);
|
|
|
|
|
+ GP_ASSERT(_aiController);
|
|
|
|
|
|
|
|
// Update Time.
|
|
// Update Time.
|
|
|
static double lastFrameTime = getGameTime();
|
|
static double lastFrameTime = getGameTime();
|
|
@@ -251,6 +267,7 @@ void Game::updateOnce()
|
|
|
// Update the internal controllers.
|
|
// Update the internal controllers.
|
|
|
_animationController->update(elapsedTime);
|
|
_animationController->update(elapsedTime);
|
|
|
_physicsController->update(elapsedTime);
|
|
_physicsController->update(elapsedTime);
|
|
|
|
|
+ _aiController->update(elapsedTime);
|
|
|
_audioController->update(elapsedTime);
|
|
_audioController->update(elapsedTime);
|
|
|
}
|
|
}
|
|
|
|
|
|