From 50bdd2039e0baa7783dc73be14dafd6642242944 Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Sat, 1 Feb 2014 22:33:59 -0800 Subject: [PATCH] - changed command speed change to only change speed min every 160 frames or more as required. --- source/glest_game/type_instances/unit.cpp | 57 +++++++--- source/glest_game/type_instances/unit.h | 2 + .../shared_lib/streflop/streflop_test.cpp | 101 ++++++++++-------- 3 files changed, 101 insertions(+), 59 deletions(-) diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index cceac3ef..df642c71 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -35,7 +35,8 @@ using namespace Shared::Util; namespace Glest{ namespace Game{ -const int CHANGE_COMMAND_SPEED = 325; +const int CHANGE_COMMAND_SPEED = 325; +const int MIN_FRAMECOUNT_CHANGE_COMMAND_SPEED = 160; //Mutex Unit::mutexDeletedUnits; //map Unit::deletedUnits; @@ -515,6 +516,9 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos, mutexCommands = new Mutex(CODE_AT_LINE); changedActiveCommand = false; + lastChangedActiveCommandFrame = 0; + changedActiveCommandFrame = 0; + lastSynchDataString=""; modelFacing = CardinalDir::NORTH; lastStuckFrame = 0; @@ -1783,26 +1787,37 @@ std::pair Unit::giveCommand(Command *command, bool tryQueu //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",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - bool willChangedActiveCommand= (commands.empty() == false); - if(willChangedActiveCommand){ - CommandClass currCommandClass=getCurrCommand()->getCommandType()->getClass(); - CommandClass commandClass=command->getCommandType()->getClass(); - if(currCommandClass - == commandClass){ - willChangedActiveCommand= false; + bool willChangedActiveCommand = (commands.empty() == false); + if(willChangedActiveCommand == true) { + + CommandClass currCommandClass = getCurrCommand()->getCommandType()->getClass(); + CommandClass commandClass = command->getCommandType()->getClass(); + if(currCommandClass == commandClass) { + + willChangedActiveCommand = false; } - else if(currCommandClass==ccAttack || currCommandClass==ccAttackStopped || - commandClass==ccAttack || commandClass==ccAttackStopped){ + else if(currCommandClass == ccAttack || + currCommandClass == ccAttackStopped || + commandClass == ccAttack || + commandClass == ccAttackStopped) { + willChangedActiveCommand= true; } - else{ + else { willChangedActiveCommand= false; } } + + if(willChangedActiveCommand == true) { + + lastChangedActiveCommandFrame = changedActiveCommandFrame; + changedActiveCommandFrame = getFrameCount(); + + //printf("Line: %d getCurrCommand() [%s] command [%s]\n",__LINE__,getCurrCommand()->toString(false).c_str(),command->toString(false).c_str()); + } + clearCommands(); - changedActiveCommand= willChangedActiveCommand; - - + changedActiveCommand = willChangedActiveCommand; //printf("In [%s::%s] Line: %d cleared existing commands\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); @@ -2153,8 +2168,12 @@ int64 Unit::getUpdateProgress() { //speed int speed = currSkill->getTotalSpeed(&totalUpgrade); - if(changedActiveCommand) { - speed = CHANGE_COMMAND_SPEED; + if(changedActiveCommand == true) { + if(changedActiveCommandFrame - lastChangedActiveCommandFrame >= MIN_FRAMECOUNT_CHANGE_COMMAND_SPEED) { + //printf("Line: %d speed = %d changedActiveCommandFrame [%u] lastChangedActiveCommandFrame [%u] skill [%s] command [%s]\n",__LINE__,speed,changedActiveCommandFrame,lastChangedActiveCommandFrame,currSkill->toString(false).c_str(),getCurrCommand()->toString(false).c_str()); + //printf("Line: %d speed = %d changedActiveCommandFrame [%u] lastChangedActiveCommandFrame [%u] total = %u\n",__LINE__,speed,changedActiveCommandFrame,lastChangedActiveCommandFrame,(changedActiveCommandFrame - lastChangedActiveCommandFrame)); + speed = CHANGE_COMMAND_SPEED; + } } //speed modifier @@ -2532,7 +2551,11 @@ bool Unit::update() { int speed= currSkill->getTotalSpeed(&totalUpgrade); if(changedActiveCommand) { - speed = CHANGE_COMMAND_SPEED; + if(changedActiveCommandFrame - lastChangedActiveCommandFrame >= MIN_FRAMECOUNT_CHANGE_COMMAND_SPEED) { + //printf("Line: %d speed = %d changedActiveCommandFrame [%u] lastChangedActiveCommandFrame [%u] skill [%s] command [%s]\n",__LINE__,speed,changedActiveCommandFrame,lastChangedActiveCommandFrame,currSkill->toString(false).c_str(),getCurrCommand()->toString(false).c_str()); + //printf("Line: %d speed = %d changedActiveCommandFrame [%u] lastChangedActiveCommandFrame [%u] total = %u\n",__LINE__,speed,changedActiveCommandFrame,lastChangedActiveCommandFrame,(changedActiveCommandFrame - lastChangedActiveCommandFrame)); + speed = CHANGE_COMMAND_SPEED; + } } //speed modifier diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 2eb639a7..e21e161d 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -471,6 +471,8 @@ private: //static std::map deletedUnits; bool changedActiveCommand; + uint32 lastChangedActiveCommandFrame; + uint32 changedActiveCommandFrame; int32 lastAttackerUnitId; int32 lastAttackedUnitId; diff --git a/source/tests/shared_lib/streflop/streflop_test.cpp b/source/tests/shared_lib/streflop/streflop_test.cpp index 4c41830f..4a1df68f 100644 --- a/source/tests/shared_lib/streflop/streflop_test.cpp +++ b/source/tests/shared_lib/streflop/streflop_test.cpp @@ -59,9 +59,27 @@ private: Vec2i lastPos; Vec2i pos; + void reset() { + cellHeight = 0; + currField = fLand; + tileSetAirHeight = standardAirHeight; + cellLandUnitHeight = 0; + cellObjectHeight = 0; + currSkill = scStop; + curUnitTypeSize = 0; + progress = 0; + lastPos = Vec2i(0,0); + pos = Vec2i(0,0); + } + public: + StreflopTest() { + reset(); + } + void test_warmup_cases() { + int unitTypeHeight = 0; cellHeight = 1.1; currField = fLand; @@ -73,62 +91,61 @@ public: progress = 10; lastPos = Vec2i(1,1); pos = Vec2i(1,2); - - int unitTypeHeight = 1; - Vec3f result = getCurrVector(unitTypeHeight); + unitTypeHeight = 1; + Vec3f result = getCurrVector(unitTypeHeight); CPPUNIT_ASSERT_EQUAL( string("x [1] y [1.6] z [1.0001]"), result.getString() ); - unitTypeHeight = 0; - result = getCurrVector(unitTypeHeight); + unitTypeHeight = 0; + result = getCurrVector(unitTypeHeight); CPPUNIT_ASSERT_EQUAL( string("x [1] y [1.1] z [1.0001]"), result.getString() ); - unitTypeHeight = 2; - result = getCurrVector(unitTypeHeight); + unitTypeHeight = 2; + result = getCurrVector(unitTypeHeight); CPPUNIT_ASSERT_EQUAL( string("x [1] y [2.1] z [1.0001]"), result.getString() ); - unitTypeHeight = 1; - currField = fAir; - result = getCurrVector(unitTypeHeight); + unitTypeHeight = 1; + currField = fAir; + result = getCurrVector(unitTypeHeight); CPPUNIT_ASSERT_EQUAL( string("x [1] y [6.6] z [1.0001]"), result.getString() ); - unitTypeHeight = 1; - currField = fAir; - currSkill = scAttack; - result = getCurrVector(unitTypeHeight); + unitTypeHeight = 1; + currField = fAir; + currSkill = scAttack; + result = getCurrVector(unitTypeHeight); CPPUNIT_ASSERT_EQUAL( string("x [1] y [6.6] z [2]"), result.getString() ); - unitTypeHeight = 1; - currField = fLand; - currSkill = scAttack; - result = getCurrVector(unitTypeHeight); + unitTypeHeight = 1; + currField = fLand; + currSkill = scAttack; + result = getCurrVector(unitTypeHeight); CPPUNIT_ASSERT_EQUAL( string("x [1] y [1.6] z [2]"), result.getString() ); unitTypeHeight = 1; currField = fLand; currSkill = scAttack; cellLandUnitHeight = -1; - result = getCurrVector(unitTypeHeight); + result = getCurrVector(unitTypeHeight); CPPUNIT_ASSERT_EQUAL( string("x [1] y [1.6] z [2]"), result.getString() ); unitTypeHeight = 1; currField = fAir; currSkill = scAttack; cellLandUnitHeight = -1; - result = getCurrVector(unitTypeHeight); + result = getCurrVector(unitTypeHeight); CPPUNIT_ASSERT_EQUAL( string("x [1] y [6.6] z [2]"), result.getString() ); unitTypeHeight = 1; currField = fLand; currSkill = scMove; cellLandUnitHeight = 2; - result = getCurrVector(unitTypeHeight); + result = getCurrVector(unitTypeHeight); CPPUNIT_ASSERT_EQUAL( string("x [1] y [1.6] z [1.0001]"), result.getString() ); unitTypeHeight = 1; currField = fAir; currSkill = scMove; cellLandUnitHeight = 2; - result = getCurrVector(unitTypeHeight); + result = getCurrVector(unitTypeHeight); CPPUNIT_ASSERT_EQUAL( string("x [1] y [6.6] z [1.0001]"), result.getString() ); unitTypeHeight = 1; @@ -136,7 +153,7 @@ public: currSkill = scMove; cellLandUnitHeight = -1; cellObjectHeight = 0; - result = getCurrVector(unitTypeHeight); + result = getCurrVector(unitTypeHeight); CPPUNIT_ASSERT_EQUAL( string("x [1] y [1.6] z [1.0001]"), result.getString() ); unitTypeHeight = 1; @@ -144,7 +161,7 @@ public: currSkill = scMove; cellLandUnitHeight = -1; cellObjectHeight = 1; - result = getCurrVector(unitTypeHeight); + result = getCurrVector(unitTypeHeight); CPPUNIT_ASSERT_EQUAL( string("x [1] y [1.6] z [1.0001]"), result.getString() ); unitTypeHeight = 1; @@ -152,14 +169,14 @@ public: currSkill = scMove; cellLandUnitHeight = -1; cellObjectHeight = 1; - result = getCurrVector(unitTypeHeight); + result = getCurrVector(unitTypeHeight); CPPUNIT_ASSERT_EQUAL( string("x [1] y [6.6] z [1.0001]"), result.getString() ); - unitTypeHeight = 1; - currField = fLand; - currSkill = scMove; - progress = 1324312; - result = getCurrVector(unitTypeHeight); + unitTypeHeight = 1; + currField = fLand; + currSkill = scMove; + progress = 1324312; + result = getCurrVector(unitTypeHeight); CPPUNIT_ASSERT_EQUAL( string("x [1] y [1.6] z [14.2431]"), result.getString() ); cellHeight = 2.870369; @@ -172,7 +189,6 @@ public: progress = 21250; lastPos = Vec2i(96,34); pos = Vec2i(95,35); - unitTypeHeight = 3; result = getCurrVector(unitTypeHeight); CPPUNIT_ASSERT_EQUAL( string("x [95] y [4.37037] z [35]"), result.getString() ); @@ -180,22 +196,23 @@ public: } void test_known_out_of_synch_cases() { + // Documented cases of out of synch go here to test cross platform for + // consistency +// int unitTypeHeight = 0; -// cellHeight = 2.870369; +// cellHeight = 1.1; // currField = fLand; // tileSetAirHeight = standardAirHeight; -// cellLandUnitHeight = 0; +// cellLandUnitHeight = 1; // cellObjectHeight = 0; -// currSkill = scAttack; +// currSkill = scMove; // curUnitTypeSize = 1; -// progress = 21250; -// lastPos = Vec2i(96,34); -// pos = Vec2i(95,35); -// -// int unitTypeHeight = 3; -// Vec3f result = getCurrVector(unitTypeHeight); -// CPPUNIT_ASSERT_EQUAL( string("x [95] y [4.37037] z [35]"), result.getString() ); - +// progress = 10; +// lastPos = Vec2i(1,1); +// pos = Vec2i(1,2); +// unitTypeHeight = 1; +// Vec3f result = getCurrVector(unitTypeHeight); +// CPPUNIT_ASSERT_EQUAL( string("x [1] y [1.6] z [1.0001]"), result.getString() ); } // =========================== Helper Methods =================================