mirror of
https://github.com/glest/glest-source.git
synced 2025-08-23 00:12:49 +02:00
better performance for attack warnings ( old code is just commented, will be removed after testing in multiplayer )
This commit is contained in:
@@ -188,11 +188,11 @@ void UnitUpdater::updateUnitCommand(Unit *unit) {
|
|||||||
//if unit has command process it
|
//if unit has command process it
|
||||||
if(unit->anyCommand()) {
|
if(unit->anyCommand()) {
|
||||||
CommandClass cc=unit->getCurrCommand()->getCommandType()->commandTypeClass;
|
CommandClass cc=unit->getCurrCommand()->getCommandType()->commandTypeClass;
|
||||||
if(unit->isOperative() && (!(cc==ccStop || cc==ccAttack)) )
|
// if(unit->isOperative() && (!(cc==ccStop || cc==ccAttack)) )
|
||||||
{//stop and attack already check for themselves
|
// {//stop and attack already check for themselves
|
||||||
Unit *sighted;
|
// Unit *sighted;
|
||||||
attackerOnSight(unit, &sighted);
|
// attackerOnSight(unit, &sighted);
|
||||||
}
|
// }
|
||||||
unit->getCurrCommand()->getCommandType()->update(this, unit);
|
unit->getCurrCommand()->getCommandType()->update(this, unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,12 +207,12 @@ void UnitUpdater::updateUnitCommand(Unit *unit) {
|
|||||||
//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__);
|
||||||
unit->giveCommand(new Command(unit->getType()->getFirstCtOfClass(ccStop)));
|
unit->giveCommand(new Command(unit->getType()->getFirstCtOfClass(ccStop)));
|
||||||
}
|
}
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
// buidings have no stop skill but hav to check for attackers too.
|
// // buidings have no stop skill but have to check for attackers too.
|
||||||
Unit *sighted;
|
// Unit *sighted;
|
||||||
attackerOnSight(unit, &sighted);
|
// attackerOnSight(unit, &sighted);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld --------------------------- [END OF METHOD] ---------------------------\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld --------------------------- [END OF METHOD] ---------------------------\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
@@ -367,7 +367,6 @@ void UnitUpdater::updateAttack(Unit *unit) {
|
|||||||
else {
|
else {
|
||||||
//compute target pos
|
//compute target pos
|
||||||
Vec2i pos;
|
Vec2i pos;
|
||||||
//Command *nextCommand;
|
|
||||||
if(command->getUnit()!=NULL) {
|
if(command->getUnit()!=NULL) {
|
||||||
pos= command->getUnit()->getCenteredPos();
|
pos= command->getUnit()->getCenteredPos();
|
||||||
}
|
}
|
||||||
@@ -1792,62 +1791,136 @@ bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( result &&
|
if(result)
|
||||||
unit->getTeam()==world->getThisTeamIndex() && //must be in local players team.
|
|
||||||
!(unit->isAlly(enemySeen)))
|
|
||||||
{
|
{
|
||||||
// find nearest Attack and cleanup old dates
|
const Unit* teamUnit;
|
||||||
AttackWarningData *nearest=NULL;
|
const Unit* enemyUnit;
|
||||||
float currentDistance;
|
bool onlyEnemyUnits=true;
|
||||||
float nearestDistance;
|
if(unit->getTeam()==world->getThisTeamIndex())
|
||||||
for(int i = attackWarnings.size()-1; i>-1; --i) {
|
{
|
||||||
if(world->getFrameCount()-attackWarnings[i]->lastFrameCount>200) { //after 200 frames attack break we warn again
|
teamUnit=unit;
|
||||||
AttackWarningData *toDelete=attackWarnings[i];
|
enemyUnit=enemySeen;
|
||||||
attackWarnings.erase(attackWarnings.begin()+i);
|
onlyEnemyUnits=false;
|
||||||
delete toDelete; // old one
|
}
|
||||||
}
|
else if(enemySeen->getTeam()==world->getThisTeamIndex() )
|
||||||
else {
|
{
|
||||||
currentDistance=floor(floatCenter.dist(attackWarnings[i]->attackPosition)); // no need for streflops here!
|
teamUnit=enemySeen;
|
||||||
if( nearest==NULL ){
|
enemyUnit=unit;
|
||||||
nearest=attackWarnings[i];
|
onlyEnemyUnits=false;
|
||||||
nearestDistance=currentDistance;
|
}
|
||||||
|
|
||||||
|
if(!onlyEnemyUnits && enemyUnit->getTeam()!=world->getThisTeamIndex())
|
||||||
|
{
|
||||||
|
Vec2f enemyFloatCenter = enemyUnit->getFloatCenteredPos();
|
||||||
|
// find nearest Attack and cleanup old dates
|
||||||
|
AttackWarningData *nearest=NULL;
|
||||||
|
float currentDistance;
|
||||||
|
float nearestDistance;
|
||||||
|
for(int i = attackWarnings.size()-1; i>-1; --i) {
|
||||||
|
if(world->getFrameCount()-attackWarnings[i]->lastFrameCount>200) { //after 200 frames attack break we warn again
|
||||||
|
AttackWarningData *toDelete=attackWarnings[i];
|
||||||
|
attackWarnings.erase(attackWarnings.begin()+i);
|
||||||
|
delete toDelete; // old one
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
currentDistance=floor(enemyFloatCenter.dist(attackWarnings[i]->attackPosition)); // no need for streflops here!
|
||||||
if( currentDistance< nearestDistance ){
|
if( nearest==NULL ){
|
||||||
nearest=attackWarnings[i];
|
nearest=attackWarnings[i];
|
||||||
nearestDistance=currentDistance;
|
nearestDistance=currentDistance;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
}
|
|
||||||
|
|
||||||
if(nearest!=NULL)
|
if( currentDistance< nearestDistance ){
|
||||||
{ // does it fit?
|
nearest=attackWarnings[i];
|
||||||
if(nearestDistance<attackWarnRange)
|
nearestDistance=currentDistance;
|
||||||
{// update entry with current values
|
}
|
||||||
nearest->lastFrameCount=world->getFrameCount();
|
}
|
||||||
nearest->attackPosition.x=enemySeen->getFloatCenteredPos().x;
|
}
|
||||||
nearest->attackPosition.y=enemySeen->getFloatCenteredPos().y;
|
}
|
||||||
}
|
|
||||||
else
|
if(nearest!=NULL)
|
||||||
{//Must be a different Attack!
|
{ // does it fit?
|
||||||
nearest=NULL; //set to null to force a new entry in next step
|
if(nearestDistance<attackWarnRange)
|
||||||
}
|
{// update entry with current values
|
||||||
}
|
nearest->lastFrameCount=world->getFrameCount();
|
||||||
// add new attack
|
nearest->attackPosition.x=enemyFloatCenter.x;
|
||||||
if(nearest==NULL) // no else!
|
nearest->attackPosition.y=enemyFloatCenter.y;
|
||||||
{
|
}
|
||||||
AttackWarningData* awd= new AttackWarningData();
|
else
|
||||||
awd->lastFrameCount=world->getFrameCount();
|
{//Must be a different Attack!
|
||||||
awd->attackPosition.x=enemySeen->getFloatCenteredPos().x;
|
nearest=NULL; //set to null to force a new entry in next step
|
||||||
awd->attackPosition.y=enemySeen->getFloatCenteredPos().y;
|
}
|
||||||
attackWarnings.push_back(awd);
|
}
|
||||||
SoundRenderer::getInstance().playFx(CoreData::getInstance().getAttentionSound());
|
// add new attack
|
||||||
world->addAttackEffects(enemySeen);
|
if(nearest==NULL) // no else!
|
||||||
}
|
{
|
||||||
|
AttackWarningData* awd= new AttackWarningData();
|
||||||
|
awd->lastFrameCount=world->getFrameCount();
|
||||||
|
awd->attackPosition.x=enemyFloatCenter.x;
|
||||||
|
awd->attackPosition.y=enemyFloatCenter.y;
|
||||||
|
attackWarnings.push_back(awd);
|
||||||
|
SoundRenderer::getInstance().playFx(CoreData::getInstance().getAttentionSound());
|
||||||
|
world->addAttackEffects(enemyUnit);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if( result &&
|
||||||
|
// unit->getTeam()==world->getThisTeamIndex() && //must be in local players team.
|
||||||
|
// !(unit->isAlly(enemySeen)))
|
||||||
|
// {
|
||||||
|
// // find nearest Attack and cleanup old dates
|
||||||
|
// AttackWarningData *nearest=NULL;
|
||||||
|
// float currentDistance;
|
||||||
|
// float nearestDistance;
|
||||||
|
// for(int i = attackWarnings.size()-1; i>-1; --i) {
|
||||||
|
// if(world->getFrameCount()-attackWarnings[i]->lastFrameCount>200) { //after 200 frames attack break we warn again
|
||||||
|
// AttackWarningData *toDelete=attackWarnings[i];
|
||||||
|
// attackWarnings.erase(attackWarnings.begin()+i);
|
||||||
|
// delete toDelete; // old one
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// currentDistance=floor(floatCenter.dist(attackWarnings[i]->attackPosition)); // no need for streflops here!
|
||||||
|
// if( nearest==NULL ){
|
||||||
|
// nearest=attackWarnings[i];
|
||||||
|
// nearestDistance=currentDistance;
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
//
|
||||||
|
// if( currentDistance< nearestDistance ){
|
||||||
|
// nearest=attackWarnings[i];
|
||||||
|
// nearestDistance=currentDistance;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if(nearest!=NULL)
|
||||||
|
// { // does it fit?
|
||||||
|
// if(nearestDistance<attackWarnRange)
|
||||||
|
// {// update entry with current values
|
||||||
|
// nearest->lastFrameCount=world->getFrameCount();
|
||||||
|
// nearest->attackPosition.x=enemySeen->getFloatCenteredPos().x;
|
||||||
|
// nearest->attackPosition.y=enemySeen->getFloatCenteredPos().y;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {//Must be a different Attack!
|
||||||
|
// nearest=NULL; //set to null to force a new entry in next step
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// // add new attack
|
||||||
|
// if(nearest==NULL) // no else!
|
||||||
|
// {
|
||||||
|
// AttackWarningData* awd= new AttackWarningData();
|
||||||
|
// awd->lastFrameCount=world->getFrameCount();
|
||||||
|
// awd->attackPosition.x=enemySeen->getFloatCenteredPos().x;
|
||||||
|
// awd->attackPosition.y=enemySeen->getFloatCenteredPos().y;
|
||||||
|
// attackWarnings.push_back(awd);
|
||||||
|
// SoundRenderer::getInstance().playFx(CoreData::getInstance().getAttentionSound());
|
||||||
|
// world->addAttackEffects(enemySeen);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user