- added a lookup cache for unit updater's frequently called unitOnRange logic
This commit is contained in:
parent
c9ca56e91b
commit
855443d98f
|
@ -223,7 +223,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos){
|
||||||
|
|
||||||
Node *lastNode= node;
|
Node *lastNode= node;
|
||||||
|
|
||||||
//if consumed all nodes find best node (to avoid strage behaviour)
|
//if consumed all nodes find best node (to avoid strange behaviour)
|
||||||
if(nodeLimitReached){
|
if(nodeLimitReached){
|
||||||
for(Nodes::iterator it= closedNodes.begin(); it!=closedNodes.end(); ++it){
|
for(Nodes::iterator it= closedNodes.begin(); it!=closedNodes.end(); ++it){
|
||||||
if((*it)->heuristic < lastNode->heuristic){
|
if((*it)->heuristic < lastNode->heuristic){
|
||||||
|
|
|
@ -614,60 +614,34 @@ void Game::updateCamera(){
|
||||||
|
|
||||||
//render
|
//render
|
||||||
void Game::render() {
|
void Game::render() {
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps);
|
|
||||||
|
|
||||||
// Ensure the camera starts in the right position
|
// Ensure the camera starts in the right position
|
||||||
if(isFirstRender == true) {
|
if(isFirstRender == true) {
|
||||||
isFirstRender = false;
|
isFirstRender = false;
|
||||||
|
|
||||||
/*
|
|
||||||
Map *map= world.getMap();
|
|
||||||
const Vec2i &v= map->getStartLocation(world.getThisFaction()->getStartLocationIndex());
|
|
||||||
gameCamera.init(map->getW(), map->getH());
|
|
||||||
gameCamera.setPos(Vec2f(v.x, v.y));
|
|
||||||
|
|
||||||
//const Vec2i &mapPos = Map::toSurfCoords(v);
|
|
||||||
Renderer &renderer= Renderer::getInstance();
|
|
||||||
Vec3f screenPos = renderer.computeScreenPosition(gameCamera.getPos());
|
|
||||||
SDL_WarpMouse(v.x, v.y);
|
|
||||||
*/
|
|
||||||
|
|
||||||
gameCamera.resetPosition();
|
gameCamera.resetPosition();
|
||||||
this->restoreToStartXY();
|
this->restoreToStartXY();
|
||||||
}
|
}
|
||||||
|
|
||||||
renderFps++;
|
renderFps++;
|
||||||
renderWorker();
|
renderWorker();
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::renderWorker() {
|
void Game::renderWorker() {
|
||||||
//Chrono chrono;
|
Chrono chrono;
|
||||||
//chrono.start();
|
chrono.start();
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
|
|
||||||
//program->getWindow()->makeCurrentGl();
|
|
||||||
|
|
||||||
//renderFps++;
|
|
||||||
//if(renderFps >= MIN_RENDER_FPS_ALLOWED) {
|
|
||||||
render3d();
|
render3d();
|
||||||
//}
|
|
||||||
//if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %d [render3d]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
//chrono.start();
|
|
||||||
render2d();
|
render2d();
|
||||||
//if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %d [render2d]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
//chrono.start();
|
|
||||||
Renderer::getInstance().swapBuffers();
|
Renderer::getInstance().swapBuffers();
|
||||||
//if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %d [swap buffers]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== tick ====================
|
// ==================== tick ====================
|
||||||
|
@ -1204,30 +1178,28 @@ void Game::render3d(){
|
||||||
Renderer &renderer= Renderer::getInstance();
|
Renderer &renderer= Renderer::getInstance();
|
||||||
|
|
||||||
//init
|
//init
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
renderer.reset3d();
|
renderer.reset3d();
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [reset3d]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||||
if(chrono.getMillis() > 0) chrono.start();
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
renderer.computeVisibleQuad();
|
renderer.computeVisibleQuad();
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [computeVisibleQuad]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||||
if(chrono.getMillis() > 0) chrono.start();
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
renderer.loadGameCameraMatrix();
|
renderer.loadGameCameraMatrix();
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [loadGameCameraMatrix]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||||
if(chrono.getMillis() > 0) chrono.start();
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
renderer.setupLighting();
|
renderer.setupLighting();
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [setupLighting]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||||
if(chrono.getMillis() > 0) chrono.start();
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
//shadow map
|
//shadow map
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
renderer.renderShadowsToTexture(avgRenderFps);
|
renderer.renderShadowsToTexture(avgRenderFps);
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderShadowsToTexture]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||||
if(chrono.getMillis() > 0) chrono.start();
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
//clear buffers
|
//clear buffers
|
||||||
|
@ -1239,44 +1211,44 @@ void Game::render3d(){
|
||||||
//surface
|
//surface
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
renderer.renderSurface(avgRenderFps,world.getFrameCount());
|
renderer.renderSurface(avgRenderFps,world.getFrameCount());
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderSurface]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||||
if(chrono.getMillis() > 0) chrono.start();
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
//selection circles
|
//selection circles
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
renderer.renderSelectionEffects();
|
renderer.renderSelectionEffects();
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderSelectionEffects]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||||
if(chrono.getMillis() > 0) chrono.start();
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
//units
|
//units
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
renderer.renderUnits(avgRenderFps,world.getFrameCount());
|
renderer.renderUnits(avgRenderFps,world.getFrameCount());
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderUnits]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||||
if(chrono.getMillis() > 0) chrono.start();
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
//objects
|
//objects
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
renderer.renderObjects(avgRenderFps,world.getFrameCount());
|
renderer.renderObjects(avgRenderFps,world.getFrameCount());
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderObjects]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||||
if(chrono.getMillis() > 0) chrono.start();
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
//water
|
//water
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
renderer.renderWater();
|
renderer.renderWater();
|
||||||
renderer.renderWaterEffects();
|
renderer.renderWaterEffects();
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderWater]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||||
if(chrono.getMillis() > 0) chrono.start();
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
//particles
|
//particles
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
renderer.renderParticleManager(rsGame);
|
renderer.renderParticleManager(rsGame);
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderParticleManager]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||||
if(chrono.getMillis() > 0) chrono.start();
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
//mouse 3d
|
//mouse 3d
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
renderer.renderMouse3d();
|
renderer.renderMouse3d();
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderMouse3d]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::render2d(){
|
void Game::render2d(){
|
||||||
|
|
|
@ -34,7 +34,7 @@ using namespace Shared::Util;
|
||||||
|
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
const int UnitPathBasic::maxBlockCount= 10;
|
const int UnitPathBasic::maxBlockCount= GameConstants::updateFps / 2;
|
||||||
|
|
||||||
UnitPathBasic::UnitPathBasic() {
|
UnitPathBasic::UnitPathBasic() {
|
||||||
this->blockCount = 0;
|
this->blockCount = 0;
|
||||||
|
|
|
@ -53,6 +53,7 @@ UnitUpdater::UnitUpdater() {
|
||||||
this->scriptManager= NULL;
|
this->scriptManager= NULL;
|
||||||
this->routePlanner = NULL;
|
this->routePlanner = NULL;
|
||||||
this->pathFinder = NULL;
|
this->pathFinder = NULL;
|
||||||
|
UnitRangeCellsLookupItemCacheTimerCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnitUpdater::init(Game *game){
|
void UnitUpdater::init(Game *game){
|
||||||
|
@ -66,6 +67,7 @@ void UnitUpdater::init(Game *game){
|
||||||
this->scriptManager= game->getScriptManager();
|
this->scriptManager= game->getScriptManager();
|
||||||
this->routePlanner = NULL;
|
this->routePlanner = NULL;
|
||||||
this->pathFinder = NULL;
|
this->pathFinder = NULL;
|
||||||
|
UnitRangeCellsLookupItemCacheTimerCount = 0;
|
||||||
|
|
||||||
switch(this->game->getGameSettings()->getPathFinderType()) {
|
switch(this->game->getGameSettings()->getPathFinderType()) {
|
||||||
case pfBasic:
|
case pfBasic:
|
||||||
|
@ -88,7 +90,10 @@ UnitUpdater::~UnitUpdater() {
|
||||||
// ==================== progress skills ====================
|
// ==================== progress skills ====================
|
||||||
|
|
||||||
//skill dependent actions
|
//skill dependent actions
|
||||||
void UnitUpdater::updateUnit(Unit *unit){
|
void UnitUpdater::updateUnit(Unit *unit) {
|
||||||
|
Chrono chrono;
|
||||||
|
chrono.start();
|
||||||
|
|
||||||
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
||||||
|
|
||||||
//play skill sound
|
//play skill sound
|
||||||
|
@ -102,6 +107,9 @@ void UnitUpdater::updateUnit(Unit *unit){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld [play skill sound]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
//start attack particle system
|
//start attack particle system
|
||||||
if(unit->getCurrSkill()->getClass()==scAttack){
|
if(unit->getCurrSkill()->getClass()==scAttack){
|
||||||
const AttackSkillType *ast= static_cast<const AttackSkillType*>(unit->getCurrSkill());
|
const AttackSkillType *ast= static_cast<const AttackSkillType*>(unit->getCurrSkill());
|
||||||
|
@ -111,22 +119,37 @@ void UnitUpdater::updateUnit(Unit *unit){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld [start attack particles]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
//update unit
|
//update unit
|
||||||
if(unit->update()){
|
if(unit->update()){
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld [update unit check]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
updateUnitCommand(unit);
|
updateUnitCommand(unit);
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld [update unit command]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
//if unit is out of EP, it stops
|
//if unit is out of EP, it stops
|
||||||
if(unit->computeEp()){
|
if(unit->computeEp()){
|
||||||
unit->setCurrSkill(scStop);
|
unit->setCurrSkill(scStop);
|
||||||
unit->cancelCommand();
|
unit->cancelCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld [compute ep]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
//move unit in cells
|
//move unit in cells
|
||||||
if(unit->getCurrSkill()->getClass()==scMove){
|
if(unit->getCurrSkill()->getClass()==scMove){
|
||||||
world->moveUnitCells(unit);
|
world->moveUnitCells(unit);
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld [move unit cells]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
//play water sound
|
//play water sound
|
||||||
if(map->getCell(unit->getPos())->getHeight()<map->getWaterLevel() && unit->getCurrField()==fLand){
|
if(map->getCell(unit->getPos())->getHeight()<map->getWaterLevel() && unit->getCurrField()==fLand){
|
||||||
soundRenderer.playFx(
|
soundRenderer.playFx(
|
||||||
|
@ -134,6 +157,9 @@ void UnitUpdater::updateUnit(Unit *unit){
|
||||||
unit->getCurrVector(),
|
unit->getCurrVector(),
|
||||||
gameCamera->getPos()
|
gameCamera->getPos()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld [play water sound]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,6 +167,8 @@ void UnitUpdater::updateUnit(Unit *unit){
|
||||||
//unit death
|
//unit death
|
||||||
if(unit->isDead() && unit->getCurrSkill()->getClass()!=scDie){
|
if(unit->isDead() && unit->getCurrSkill()->getClass()!=scDie){
|
||||||
unit->kill();
|
unit->kill();
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld [kill unit]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,6 +177,9 @@ void UnitUpdater::updateUnit(Unit *unit){
|
||||||
|
|
||||||
//VERY IMPORTANT: compute next state depending on the first order of the list
|
//VERY IMPORTANT: compute next state depending on the first order of the list
|
||||||
void UnitUpdater::updateUnitCommand(Unit *unit){
|
void UnitUpdater::updateUnitCommand(Unit *unit){
|
||||||
|
Chrono chrono;
|
||||||
|
chrono.start();
|
||||||
|
|
||||||
//if unit has command process it
|
//if unit has command process it
|
||||||
if(unit->anyCommand()) {
|
if(unit->anyCommand()) {
|
||||||
unit->getCurrCommand()->getCommandType()->update(this, unit);
|
unit->getCurrCommand()->getCommandType()->update(this, unit);
|
||||||
|
@ -163,11 +194,16 @@ void UnitUpdater::updateUnitCommand(Unit *unit){
|
||||||
unit->giveCommand(new Command(unit->getType()->getFirstCtOfClass(ccStop)));
|
unit->giveCommand(new Command(unit->getType()->getFirstCtOfClass(ccStop)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== updateStop ====================
|
// ==================== updateStop ====================
|
||||||
|
|
||||||
void UnitUpdater::updateStop(Unit *unit){
|
void UnitUpdater::updateStop(Unit *unit){
|
||||||
|
Chrono chrono;
|
||||||
|
chrono.start();
|
||||||
|
|
||||||
Command *command= unit->getCurrCommand();
|
Command *command= unit->getCurrCommand();
|
||||||
const StopCommandType *sct = static_cast<const StopCommandType*>(command->getCommandType());
|
const StopCommandType *sct = static_cast<const StopCommandType*>(command->getCommandType());
|
||||||
|
@ -208,11 +244,16 @@ void UnitUpdater::updateStop(Unit *unit){
|
||||||
unit->giveCommand(new Command(unit->getType()->getFirstCtOfClass(ccMove), escapePos));
|
unit->giveCommand(new Command(unit->getType()->getFirstCtOfClass(ccMove), escapePos));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ==================== updateMove ====================
|
// ==================== updateMove ====================
|
||||||
void UnitUpdater::updateMove(Unit *unit){
|
void UnitUpdater::updateMove(Unit *unit){
|
||||||
|
Chrono chrono;
|
||||||
|
chrono.start();
|
||||||
|
|
||||||
Command *command= unit->getCurrCommand();
|
Command *command= unit->getCurrCommand();
|
||||||
const MoveCommandType *mct= static_cast<const MoveCommandType*>(command->getCommandType());
|
const MoveCommandType *mct= static_cast<const MoveCommandType*>(command->getCommandType());
|
||||||
|
@ -246,12 +287,17 @@ void UnitUpdater::updateMove(Unit *unit){
|
||||||
default:
|
default:
|
||||||
unit->finishCommand();
|
unit->finishCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ==================== updateAttack ====================
|
// ==================== updateAttack ====================
|
||||||
|
|
||||||
void UnitUpdater::updateAttack(Unit *unit){
|
void UnitUpdater::updateAttack(Unit *unit){
|
||||||
|
Chrono chrono;
|
||||||
|
chrono.start();
|
||||||
|
|
||||||
Command *command= unit->getCurrCommand();
|
Command *command= unit->getCurrCommand();
|
||||||
const AttackCommandType *act= static_cast<const AttackCommandType*>(command->getCommandType());
|
const AttackCommandType *act= static_cast<const AttackCommandType*>(command->getCommandType());
|
||||||
|
@ -306,12 +352,17 @@ void UnitUpdater::updateAttack(Unit *unit){
|
||||||
unit->finishCommand();
|
unit->finishCommand();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ==================== updateAttackStopped ====================
|
// ==================== updateAttackStopped ====================
|
||||||
|
|
||||||
void UnitUpdater::updateAttackStopped(Unit *unit){
|
void UnitUpdater::updateAttackStopped(Unit *unit){
|
||||||
|
Chrono chrono;
|
||||||
|
chrono.start();
|
||||||
|
|
||||||
Command *command= unit->getCurrCommand();
|
Command *command= unit->getCurrCommand();
|
||||||
const AttackStoppedCommandType *asct= static_cast<const AttackStoppedCommandType*>(command->getCommandType());
|
const AttackStoppedCommandType *asct= static_cast<const AttackStoppedCommandType*>(command->getCommandType());
|
||||||
|
@ -324,12 +375,17 @@ void UnitUpdater::updateAttackStopped(Unit *unit){
|
||||||
else{
|
else{
|
||||||
unit->setCurrSkill(asct->getStopSkillType());
|
unit->setCurrSkill(asct->getStopSkillType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ==================== updateBuild ====================
|
// ==================== updateBuild ====================
|
||||||
|
|
||||||
void UnitUpdater::updateBuild(Unit *unit){
|
void UnitUpdater::updateBuild(Unit *unit){
|
||||||
|
Chrono chrono;
|
||||||
|
chrono.start();
|
||||||
|
|
||||||
Command *command= unit->getCurrCommand();
|
Command *command= unit->getCurrCommand();
|
||||||
const BuildCommandType *bct= static_cast<const BuildCommandType*>(command->getCommandType());
|
const BuildCommandType *bct= static_cast<const BuildCommandType*>(command->getCommandType());
|
||||||
|
@ -466,12 +522,17 @@ void UnitUpdater::updateBuild(Unit *unit){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ==================== updateHarvest ====================
|
// ==================== updateHarvest ====================
|
||||||
|
|
||||||
void UnitUpdater::updateHarvest(Unit *unit){
|
void UnitUpdater::updateHarvest(Unit *unit){
|
||||||
|
Chrono chrono;
|
||||||
|
chrono.start();
|
||||||
|
|
||||||
Command *command= unit->getCurrCommand();
|
Command *command= unit->getCurrCommand();
|
||||||
const HarvestCommandType *hct= static_cast<const HarvestCommandType*>(command->getCommandType());
|
const HarvestCommandType *hct= static_cast<const HarvestCommandType*>(command->getCommandType());
|
||||||
|
@ -609,9 +670,8 @@ void UnitUpdater::updateHarvest(Unit *unit){
|
||||||
// hct has changed to a different harvest command.
|
// hct has changed to a different harvest command.
|
||||||
unit->setCurrSkill(hct->getStopLoadedSkillType()); // this is actually the wrong animation
|
unit->setCurrSkill(hct->getStopLoadedSkillType()); // this is actually the wrong animation
|
||||||
unit->getPath()->clear();
|
unit->getPath()->clear();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
// if there is a resource, continue working, until loaded
|
// if there is a resource, continue working, until loaded
|
||||||
unit->update2();
|
unit->update2();
|
||||||
if (unit->getProgress2() >= hct->getHitsPerUnit()) {
|
if (unit->getProgress2() >= hct->getHitsPerUnit()) {
|
||||||
|
@ -643,18 +703,24 @@ void UnitUpdater::updateHarvest(Unit *unit){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else{
|
else{
|
||||||
//if there is no resource, just stop
|
//if there is no resource, just stop
|
||||||
unit->setCurrSkill(hct->getStopLoadedSkillType());
|
unit->setCurrSkill(hct->getStopLoadedSkillType());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ==================== updateRepair ====================
|
// ==================== updateRepair ====================
|
||||||
|
|
||||||
void UnitUpdater::updateRepair(Unit *unit){
|
void UnitUpdater::updateRepair(Unit *unit){
|
||||||
|
Chrono chrono;
|
||||||
|
chrono.start();
|
||||||
|
|
||||||
Command *command= unit->getCurrCommand();
|
Command *command= unit->getCurrCommand();
|
||||||
const RepairCommandType *rct= static_cast<const RepairCommandType*>(command->getCommandType());
|
const RepairCommandType *rct= static_cast<const RepairCommandType*>(command->getCommandType());
|
||||||
|
@ -723,12 +789,17 @@ void UnitUpdater::updateRepair(Unit *unit){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ==================== updateProduce ====================
|
// ==================== updateProduce ====================
|
||||||
|
|
||||||
void UnitUpdater::updateProduce(Unit *unit){
|
void UnitUpdater::updateProduce(Unit *unit){
|
||||||
|
Chrono chrono;
|
||||||
|
chrono.start();
|
||||||
|
|
||||||
Command *command= unit->getCurrCommand();
|
Command *command= unit->getCurrCommand();
|
||||||
const ProduceCommandType *pct= static_cast<const ProduceCommandType*>(command->getCommandType());
|
const ProduceCommandType *pct= static_cast<const ProduceCommandType*>(command->getCommandType());
|
||||||
|
@ -779,12 +850,17 @@ void UnitUpdater::updateProduce(Unit *unit){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ==================== updateUpgrade ====================
|
// ==================== updateUpgrade ====================
|
||||||
|
|
||||||
void UnitUpdater::updateUpgrade(Unit *unit){
|
void UnitUpdater::updateUpgrade(Unit *unit){
|
||||||
|
Chrono chrono;
|
||||||
|
chrono.start();
|
||||||
|
|
||||||
Command *command= unit->getCurrCommand();
|
Command *command= unit->getCurrCommand();
|
||||||
const UpgradeCommandType *uct= static_cast<const UpgradeCommandType*>(command->getCommandType());
|
const UpgradeCommandType *uct= static_cast<const UpgradeCommandType*>(command->getCommandType());
|
||||||
|
@ -802,11 +878,16 @@ void UnitUpdater::updateUpgrade(Unit *unit){
|
||||||
unit->getFaction()->finishUpgrade(uct->getProducedUpgrade());
|
unit->getFaction()->finishUpgrade(uct->getProducedUpgrade());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== updateMorph ====================
|
// ==================== updateMorph ====================
|
||||||
|
|
||||||
void UnitUpdater::updateMorph(Unit *unit){
|
void UnitUpdater::updateMorph(Unit *unit){
|
||||||
|
Chrono chrono;
|
||||||
|
chrono.start();
|
||||||
|
|
||||||
Command *command= unit->getCurrCommand();
|
Command *command= unit->getCurrCommand();
|
||||||
const MorphCommandType *mct= static_cast<const MorphCommandType*>(command->getCommandType());
|
const MorphCommandType *mct= static_cast<const MorphCommandType*>(command->getCommandType());
|
||||||
|
@ -871,6 +952,9 @@ void UnitUpdater::updateMorph(Unit *unit){
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== PRIVATE ====================
|
// ==================== PRIVATE ====================
|
||||||
|
@ -882,6 +966,8 @@ void UnitUpdater::hit(Unit *attacker){
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnitUpdater::hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &targetPos, Field targetField){
|
void UnitUpdater::hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &targetPos, Field targetField){
|
||||||
|
Chrono chrono;
|
||||||
|
chrono.start();
|
||||||
|
|
||||||
//hit attack positions
|
//hit attack positions
|
||||||
if(ast->getSplash()){
|
if(ast->getSplash()){
|
||||||
|
@ -904,9 +990,13 @@ void UnitUpdater::hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, float distance){
|
void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, float distance){
|
||||||
|
Chrono chrono;
|
||||||
|
chrono.start();
|
||||||
|
|
||||||
//get vars
|
//get vars
|
||||||
float damage= ast->getTotalAttackStrength(attacker->getTotalUpgrade());
|
float damage= ast->getTotalAttackStrength(attacker->getTotalUpgrade());
|
||||||
|
@ -941,6 +1031,9 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac
|
||||||
}
|
}
|
||||||
scriptManager->onUnitDied(attacked);
|
scriptManager->onUnitDied(attacked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnitUpdater::startAttackParticleSystem(Unit *unit){
|
void UnitUpdater::startAttackParticleSystem(Unit *unit){
|
||||||
|
@ -992,6 +1085,8 @@ void UnitUpdater::startAttackParticleSystem(Unit *unit){
|
||||||
//looks for a resource of type rt, if rt==NULL looks for any
|
//looks for a resource of type rt, if rt==NULL looks for any
|
||||||
//resource the unit can harvest
|
//resource the unit can harvest
|
||||||
bool UnitUpdater::searchForResource(Unit *unit, const HarvestCommandType *hct){
|
bool UnitUpdater::searchForResource(Unit *unit, const HarvestCommandType *hct){
|
||||||
|
Chrono chrono;
|
||||||
|
chrono.start();
|
||||||
|
|
||||||
Vec2i pos= unit->getCurrCommand()->getPos();
|
Vec2i pos= unit->getCurrCommand()->getPos();
|
||||||
|
|
||||||
|
@ -1003,6 +1098,10 @@ bool UnitUpdater::searchForResource(Unit *unit, const HarvestCommandType *hct){
|
||||||
if(r!=NULL){
|
if(r!=NULL){
|
||||||
if(hct->canHarvest(r->getType())){
|
if(hct->canHarvest(r->getType())){
|
||||||
unit->getCurrCommand()->setPos(Vec2i(i, j));
|
unit->getCurrCommand()->setPos(Vec2i(i, j));
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1010,6 +1109,10 @@ bool UnitUpdater::searchForResource(Unit *unit, const HarvestCommandType *hct){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1028,52 +1131,107 @@ bool UnitUpdater::attackableOnRange(const Unit *unit, Unit **rangedPtr, const At
|
||||||
return unitOnRange(unit, range, rangedPtr, ast);
|
return unitOnRange(unit, range, rangedPtr, ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
//if the unit has any enemy on range
|
bool UnitUpdater::findCachedCellsEnemies(Vec2i center, Vec2f floatCenter,
|
||||||
bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr, const AttackSkillType *ast){
|
int range, int size, vector<Unit*> &enemies,
|
||||||
|
const AttackSkillType *ast, const Unit *unit,
|
||||||
|
const Unit *commandTarget) {
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
vector<Unit*> enemies;
|
std::map<Vec2i, std::map<Vec2f, std::map<int, std::map<int, UnitRangeCellsLookupItem > > > >::iterator iterFind = UnitRangeCellsLookupItemCache.find(center);
|
||||||
|
if(iterFind != UnitRangeCellsLookupItemCache.end()) {
|
||||||
|
std::map<Vec2f, std::map<int, std::map<int, UnitRangeCellsLookupItem > > >::iterator iterFind2 = iterFind->second.find(floatCenter);
|
||||||
|
if(iterFind2 != iterFind->second.end()) {
|
||||||
|
std::map<int, std::map<int, UnitRangeCellsLookupItem > >::iterator iterFind3 = iterFind2->second.find(range);
|
||||||
|
if(iterFind3 != iterFind2->second.end()) {
|
||||||
|
std::map<int, UnitRangeCellsLookupItem>::iterator iterFind4 = iterFind3->second.find(size);
|
||||||
|
if(iterFind4 != iterFind3->second.end()) {
|
||||||
|
result = true;
|
||||||
|
|
||||||
//we check command target
|
std::vector<Cell *> &cellList = iterFind4->second.rangeCellList;
|
||||||
const Unit *commandTarget= NULL;
|
for(int idx = 0; idx < cellList.size(); ++idx) {
|
||||||
if(unit->anyCommand()){
|
Cell *cell = cellList[idx];
|
||||||
commandTarget= static_cast<const Unit*>(unit->getCurrCommand()->getUnit());
|
|
||||||
|
findEnemiesForCell(ast,cell,unit,commandTarget,enemies);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(commandTarget!=NULL && commandTarget->isDead()){
|
|
||||||
commandTarget= NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//aux vars
|
return result;
|
||||||
int size= unit->getType()->getSize();
|
}
|
||||||
Vec2i center= unit->getPos();
|
|
||||||
Vec2f floatCenter= unit->getFloatCenteredPos();
|
|
||||||
|
|
||||||
//nearby cells
|
void UnitUpdater::findEnemiesForCell(const AttackSkillType *ast, Cell *cell, const Unit *unit,
|
||||||
for(int i=center.x-range; i<center.x+range+size; ++i){
|
const Unit *commandTarget,vector<Unit*> &enemies) {
|
||||||
for(int j=center.y-range; j<center.y+range+size; ++j){
|
|
||||||
|
|
||||||
//cells insede map and in range
|
|
||||||
#ifdef USE_STREFLOP
|
|
||||||
if(map->isInside(i, j) && streflop::floor(floatCenter.dist(Vec2f((float)i, (float)j))) <= (range+1)){
|
|
||||||
#else
|
|
||||||
if(map->isInside(i, j) && floor(floatCenter.dist(Vec2f((float)i, (float)j))) <= (range+1)){
|
|
||||||
#endif
|
|
||||||
//all fields
|
//all fields
|
||||||
for(int k=0; k<fieldCount; k++){
|
for(int k=0; k<fieldCount; k++) {
|
||||||
Field f= static_cast<Field>(k);
|
Field f= static_cast<Field>(k);
|
||||||
|
|
||||||
//check field
|
//check field
|
||||||
if((ast==NULL || ast->getAttackField(f))){
|
if((ast == NULL || ast->getAttackField(f))) {
|
||||||
Unit *possibleEnemy= map->getCell(i, j)->getUnit(f);
|
Unit *possibleEnemy = cell->getUnit(f);
|
||||||
|
|
||||||
//check enemy
|
//check enemy
|
||||||
if(possibleEnemy!=NULL && possibleEnemy->isAlive()){
|
if(possibleEnemy != NULL && possibleEnemy->isAlive()) {
|
||||||
if((!unit->isAlly(possibleEnemy) && commandTarget==NULL) || commandTarget==possibleEnemy){
|
if((!unit->isAlly(possibleEnemy) && commandTarget == NULL) ||
|
||||||
|
commandTarget == possibleEnemy) {
|
||||||
enemies.push_back(possibleEnemy);
|
enemies.push_back(possibleEnemy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//if the unit has any enemy on range
|
||||||
|
bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr,
|
||||||
|
const AttackSkillType *ast){
|
||||||
|
Chrono chrono;
|
||||||
|
chrono.start();
|
||||||
|
|
||||||
|
vector<Unit*> enemies;
|
||||||
|
|
||||||
|
//we check command target
|
||||||
|
const Unit *commandTarget = NULL;
|
||||||
|
if(unit->anyCommand()) {
|
||||||
|
commandTarget = static_cast<const Unit*>(unit->getCurrCommand()->getUnit());
|
||||||
}
|
}
|
||||||
|
if(commandTarget != NULL && commandTarget->isDead()) {
|
||||||
|
commandTarget = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
//aux vars
|
||||||
|
int size = unit->getType()->getSize();
|
||||||
|
Vec2i center = unit->getPos();
|
||||||
|
Vec2f floatCenter = unit->getFloatCenteredPos();
|
||||||
|
|
||||||
|
bool foundInCache = true;
|
||||||
|
if(findCachedCellsEnemies(center,floatCenter,range,size,enemies,ast,
|
||||||
|
unit,commandTarget) == false) {
|
||||||
|
foundInCache = false;
|
||||||
|
|
||||||
|
//nearby cells
|
||||||
|
UnitRangeCellsLookupItem cacheItem;
|
||||||
|
for(int i=center.x-range; i<center.x+range+size; ++i){
|
||||||
|
for(int j=center.y-range; j<center.y+range+size; ++j){
|
||||||
|
|
||||||
|
//cells inside map and in range
|
||||||
|
#ifdef USE_STREFLOP
|
||||||
|
if(map->isInside(i, j) && streflop::floor(floatCenter.dist(Vec2f((float)i, (float)j))) <= (range+1)){
|
||||||
|
#else
|
||||||
|
if(map->isInside(i, j) && floor(floatCenter.dist(Vec2f((float)i, (float)j))) <= (range+1)){
|
||||||
|
#endif
|
||||||
|
Cell *cell = map->getCell(i,j);
|
||||||
|
findEnemiesForCell(ast,cell,unit,commandTarget,enemies);
|
||||||
|
|
||||||
|
cacheItem.rangeCellList.push_back(cell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ok update our caches with the latest info
|
||||||
|
if(cacheItem.rangeCellList.size() > 0) {
|
||||||
|
cacheItem.UnitRangeCellsLookupItemCacheTimerCountIndex = UnitRangeCellsLookupItemCacheTimerCount++;
|
||||||
|
UnitRangeCellsLookupItemCache[center][floatCenter][range][size] = cacheItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1081,6 +1239,10 @@ bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr, con
|
||||||
for(int i=0; i<enemies.size(); ++i){
|
for(int i=0; i<enemies.size(); ++i){
|
||||||
if(enemies[i]->getType()->hasSkillClass(scAttack)){
|
if(enemies[i]->getType()->hasSkillClass(scAttack)){
|
||||||
*rangedPtr= enemies[i];
|
*rangedPtr= enemies[i];
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld, unit %s, range = %d, size = %d, foundInCache = %d, enemies.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),unit->getFullName().c_str(),range,size,foundInCache,enemies.size());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1088,9 +1250,16 @@ bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr, con
|
||||||
//any enemy
|
//any enemy
|
||||||
if(enemies.size()>0){
|
if(enemies.size()>0){
|
||||||
*rangedPtr= enemies.front();
|
*rangedPtr= enemies.front();
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld, unit %s, range = %d, size = %d, foundInCache = %d, enemies.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),unit->getFullName().c_str(),range,size,foundInCache,enemies.size());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld, unit %s, range = %d, size = %d, foundInCache = %d, enemies.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),unit->getFullName().c_str(),range,size,foundInCache,enemies.size());
|
||||||
|
if(chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,18 @@ class RoutePlanner;
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class ParticleDamager;
|
class ParticleDamager;
|
||||||
|
class Cell;
|
||||||
|
|
||||||
class UnitUpdater{
|
class UnitRangeCellsLookupItem {
|
||||||
|
public:
|
||||||
|
|
||||||
|
int UnitRangeCellsLookupItemCacheTimerCountIndex;
|
||||||
|
std::vector<Cell *> rangeCellList;
|
||||||
|
|
||||||
|
static time_t lastDebug;
|
||||||
|
};
|
||||||
|
|
||||||
|
class UnitUpdater {
|
||||||
private:
|
private:
|
||||||
friend class ParticleDamager;
|
friend class ParticleDamager;
|
||||||
|
|
||||||
|
@ -59,6 +69,17 @@ private:
|
||||||
Game *game;
|
Game *game;
|
||||||
RandomGen random;
|
RandomGen random;
|
||||||
|
|
||||||
|
std::map<Vec2i, std::map<Vec2f, std::map<int, std::map<int, UnitRangeCellsLookupItem > > > > UnitRangeCellsLookupItemCache;
|
||||||
|
//std::map<int,ExploredCellsLookupKey> ExploredCellsLookupItemCacheTimer;
|
||||||
|
int UnitRangeCellsLookupItemCacheTimerCount;
|
||||||
|
|
||||||
|
bool findCachedCellsEnemies(Vec2i center, Vec2f floatCenter, int range,
|
||||||
|
int size, vector<Unit*> &enemies,
|
||||||
|
const AttackSkillType *ast, const Unit *unit,
|
||||||
|
const Unit *commandTarget);
|
||||||
|
void findEnemiesForCell(const AttackSkillType *ast, Cell *cell, const Unit *unit,
|
||||||
|
const Unit *commandTarget,vector<Unit*> &enemies);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UnitUpdater();
|
UnitUpdater();
|
||||||
void init(Game *game);
|
void init(Game *game);
|
||||||
|
|
|
@ -355,10 +355,9 @@ void World::update(){
|
||||||
bool needToTick = canTickWorld();
|
bool needToTick = canTickWorld();
|
||||||
if(needToTick == true) {
|
if(needToTick == true) {
|
||||||
//if(frameCount % (GameConstants::updateFps / GameConstants::maxPlayers) == 0) {
|
//if(frameCount % (GameConstants::updateFps / GameConstants::maxPlayers) == 0) {
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
|
||||||
tick();
|
tick();
|
||||||
}
|
}
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [world tick]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::canTickWorld() const {
|
bool World::canTickWorld() const {
|
||||||
|
|
Loading…
Reference in New Issue