From f2e497f855a9f6356af7c7269e10310d18cd3ad9 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 28 Oct 2011 00:22:03 +0000 Subject: [PATCH] bugfix for switching to another command should be immediate and not wait until the current skill in finished --- source/glest_game/type_instances/unit.cpp | 12 ++++++++++++ source/glest_game/type_instances/unit.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index f35d484f..7394e725 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -281,6 +281,7 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos, const UnitType Unit::mapMemoryList[this]=true; #endif + changedActiveCommand = false; lastSynchDataString=""; modelFacing = CardinalDir::NORTH; lastStuckFrame = 0; @@ -1141,6 +1142,9 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue) { if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + //printf("In [%s::%s] Line: %d unit [%d - %s] command [%s] tryQueue = %d command->getCommandType()->isQueuable(tryQueue) = %d\n",__FILE__,__FUNCTION__,__LINE__,this->getId(),this->getType()->getName().c_str(), command->getCommandType()->getName().c_str(), tryQueue,command->getCommandType()->isQueuable(tryQueue)); + + if(command->getCommandType()->isQueuable(tryQueue)) { if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] Command is Queable\n",__FILE__,__FUNCTION__,__LINE__); @@ -1187,7 +1191,9 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue) { //empty command queue if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] Clear commands because current is NOT queable.\n",__FILE__,__FUNCTION__,__LINE__); + changedActiveCommand = (commands.size() > 0); clearCommands(); + //printf("In [%s::%s] Line: %d cleared existing commands\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); } @@ -1198,6 +1204,7 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue) { CommandResult result= checkCommand(command); if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] checkCommand returned: [%d]\n",__FILE__,__FUNCTION__,__LINE__,result); + //printf("In [%s::%s] Line: %d check command returned %d, commands.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,result,commands.size()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); @@ -1528,6 +1535,11 @@ void Unit::updateTimedParticles() { bool Unit::update() { assert(progress <= 1.f); + if(changedActiveCommand) { + changedActiveCommand = false; + return true; + } + //highlight if(highlight > 0.f) { const Game *game = Renderer::getInstance().getGame(); diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 157c4164..50c21c02 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -401,6 +401,8 @@ private: //static Mutex mutexDeletedUnits; //static std::map deletedUnits; + bool changedActiveCommand; + public: Unit() : id(-1) { assert(false);