- observers now hear sounds from units of all team units in visible quad

This commit is contained in:
Mark Vejvoda 2011-03-18 21:23:34 +00:00
parent 07f56669b7
commit 505abbd1ec
5 changed files with 55 additions and 23 deletions

View File

@ -39,7 +39,7 @@ namespace Glest{ namespace Game{
const int PathFinder::maxFreeSearchRadius = 10;
//const int PathFinder::pathFindNodesMax= 400;
int PathFinder::pathFindNodesMax = 500;
int PathFinder::pathFindNodesMax = 350;
const int PathFinder::pathFindRefresh = 10;
const int PathFinder::pathFindBailoutRadius = 20;
@ -393,6 +393,9 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
throw runtime_error("map == NULL");
}
const bool showConsoleDebugInfo = Config::getInstance().getBool("EnablePathfinderDistanceOutput","false");
const bool tryLastPathCache = Config::getInstance().getBool("EnablePathfinderCache","false");
UnitPathInterface *path= unit->getPath();
factions[unit->getFactionIndex()].nodePoolCount= 0;
@ -439,9 +442,13 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
if(i < pathFindRefresh) {
path->add(nodePos);
}
else {
else if(tryLastPathCache == false) {
break;
}
if(tryLastPathCache == true && basicPathFinder) {
basicPathFinder->addToLastPathCache(nodePos);
}
}
return factions[unit->getFactionIndex()].precachedTravelState[unit->getId()];
}
@ -474,10 +481,9 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
// Check the previous path find cache for the unit to see if its good to
// use
const bool showConsoleDebugInfo = Config::getInstance().getBool("EnablePathfinderDistanceOutput","false");
const bool tryLastPathCache = Config::getInstance().getBool("EnablePathfinderCache","false");
if((showConsoleDebugInfo || tryLastPathCache) && dist > 60) {
if(showConsoleDebugInfo) printf("Distance from [%d - %s] to destination is %.2f tryLastPathCache = %d\n",unit->getId(),unit->getFullName().c_str(), dist,tryLastPathCache);
@ -501,17 +507,25 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
//store path
basicPathFinder->clear();
if(frameIndex < 0) {
basicPathFinder->clear();
}
int pathCount=0;
for(int k=i+1; k <= j; k++) {
if(k >= cachedPath.size()) {
throw runtime_error("k >= cachedPath.size() k = " + intToStr(k) + " cachedPath.size() = " + intToStr(cachedPath.size()));
}
if(pathCount < pathFindRefresh) {
basicPathFinder->add(cachedPath[k]);
if(frameIndex >= 0) {
factions[unit->getFactionIndex()].precachedPath[unit->getId()].push_back(cachedPath[k]);
}
else {
if(pathCount < pathFindRefresh) {
basicPathFinder->add(cachedPath[k]);
}
basicPathFinder->addToLastPathCache(cachedPath[k]);
}
basicPathFinder->addToLastPathCache(cachedPath[k]);
pathCount++;
}
@ -548,7 +562,9 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
//store path
basicPathFinder->clear();
if(frameIndex < 0) {
basicPathFinder->clear();
}
int pathCount=0;
for(int k=i+1; k < cachedPath.size(); k++) {
@ -556,10 +572,15 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
throw runtime_error("#2 k >= cachedPath.size() k = " + intToStr(k) + " cachedPath.size() = " + intToStr(cachedPath.size()));
}
if(pathCount < pathFindRefresh) {
basicPathFinder->add(cachedPath[k]);
if(frameIndex >= 0) {
factions[unit->getFactionIndex()].precachedPath[unit->getId()].push_back(cachedPath[k]);
}
else {
if(pathCount < pathFindRefresh) {
basicPathFinder->add(cachedPath[k]);
}
basicPathFinder->addToLastPathCache(cachedPath[k]);
}
basicPathFinder->addToLastPathCache(cachedPath[k]);
pathCount++;
}
@ -600,7 +621,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
}
}
//path find algorithm
//a) push starting pos into openNodes

View File

@ -656,7 +656,8 @@ void Faction::applyCostsOnInterval(const ResourceType *rtApply) {
scriptManager->onUnitDied(unit);
}
StaticSound *sound= unit->getType()->getFirstStOfClass(scDie)->getSound();
if(sound != NULL && thisFaction) {
if(sound != NULL &&
(thisFaction == true || (world->getThisTeamIndex() == GameConstants::maxPlayers -1 + fpt_Observer))) {
SoundRenderer::getInstance().playFx(sound);
}
}

View File

@ -1032,12 +1032,18 @@ void Unit::kill() {
//clear commands
clearCommands();
UnitUpdater *unitUpdater = game->getWorld()->getUnitUpdater();
unitUpdater->clearUnitPrecache(this);
}
void Unit::undertake() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to undertake unit id = %d [%s] [%s]\n",
__FILE__,__FUNCTION__,__LINE__,this->id, this->getFullName().c_str(),this->getDesc().c_str());
UnitUpdater *unitUpdater = game->getWorld()->getUnitUpdater();
unitUpdater->clearUnitPrecache(this);
livingUnits.erase(id);
livingUnitsp.erase(this);
faction->removeUnit(this);
@ -1287,7 +1293,9 @@ void Unit::tick() {
game->getScriptManager()->onUnitDied(this);
}
StaticSound *sound= this->getType()->getFirstStOfClass(scDie)->getSound();
if(sound != NULL && this->getFactionIndex() == Unit::game->getWorld()->getThisFactionIndex()) {
if(sound != NULL &&
(this->getFactionIndex() == Unit::game->getWorld()->getThisFactionIndex() ||
(game->getWorld()->getThisTeamIndex() == GameConstants::maxPlayers -1 + fpt_Observer))) {
SoundRenderer::getInstance().playFx(sound);
}
}

View File

@ -115,10 +115,11 @@ void UnitUpdater::updateUnit(Unit *unit) {
//play skill sound
const SkillType *currSkill= unit->getCurrSkill();
if(currSkill->getSound()!=NULL) {
if(currSkill->getSound() != NULL) {
float soundStartTime= currSkill->getSoundStartTime();
if(soundStartTime>=unit->getLastAnimProgress() && soundStartTime<unit->getAnimProgress()) {
if(map->getSurfaceCell(Map::toSurfCoords(unit->getPos()))->isVisible(world->getThisTeamIndex())) {
if(soundStartTime >= unit->getLastAnimProgress() && soundStartTime < unit->getAnimProgress()) {
if(map->getSurfaceCell(Map::toSurfCoords(unit->getPos()))->isVisible(world->getThisTeamIndex()) ||
(game->getWorld()->getThisTeamIndex() == GameConstants::maxPlayers -1 + fpt_Observer)) {
soundRenderer.playFx(currSkill->getSound(), unit->getCurrVector(), gameCamera->getPos());
}
}
@ -665,7 +666,8 @@ void UnitUpdater::updateBuild(Unit *unit, int frameIndex) {
command->setUnit(builtUnit);
//play start sound
if(unit->getFactionIndex() == world->getThisFactionIndex()) {
if(unit->getFactionIndex() == world->getThisFactionIndex() ||
(game->getWorld()->getThisTeamIndex() == GameConstants::maxPlayers -1 + fpt_Observer)) {
SoundRenderer::getInstance().playFx(
bct->getStartSound(),
unit->getCurrVector(),
@ -736,7 +738,8 @@ void UnitUpdater::updateBuild(Unit *unit, int frameIndex) {
builtUnit->born();
scriptManager->onUnitCreated(builtUnit);
if(unit->getFactionIndex() == world->getThisFactionIndex()) {
if(unit->getFactionIndex() == world->getThisFactionIndex() ||
(game->getWorld()->getThisTeamIndex() == GameConstants::maxPlayers -1 + fpt_Observer)) {
SoundRenderer::getInstance().playFx(
bct->getBuiltSound(),
unit->getCurrVector(),
@ -2078,7 +2081,7 @@ void ParticleDamager::update(ParticleSystem *particleSystem) {
//play sound
StaticSound *projSound= ast->getProjSound();
if(particleSystem->getVisible() && projSound!=NULL){
if(particleSystem->getVisible() && projSound != NULL) {
SoundRenderer::getInstance().playFx(projSound, attacker->getCurrVector(), gameCamera->getPos());
}
}

View File

@ -112,6 +112,8 @@ public:
void updateUpgrade(Unit *unit, int frameIndex);
void updateMorph(Unit *unit, int frameIndex);
void clearUnitPrecache(Unit *unit);
private:
//attack
void hit(Unit *attacker);
@ -132,8 +134,6 @@ private:
void SwapActiveCommandState(Unit *unit, CommandStateType commandStateType,
const CommandType *commandType,
int originalValue,int newValue);
void clearUnitPrecache(Unit *unit);
};
// =====================================================