- attempted some speed improvements for unit lookup as well as exploreCells
This commit is contained in:
parent
5f16b486d7
commit
206170bc76
|
@ -60,7 +60,6 @@ void UnitUpdater::init(Game *game){
|
||||||
|
|
||||||
//skill dependent actions
|
//skill dependent actions
|
||||||
void UnitUpdater::updateUnit(Unit *unit){
|
void UnitUpdater::updateUnit(Unit *unit){
|
||||||
|
|
||||||
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
||||||
|
|
||||||
//play skill sound
|
//play skill sound
|
||||||
|
@ -121,8 +120,7 @@ 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){
|
||||||
|
//if unit has command process it
|
||||||
//if unis has command process it
|
|
||||||
if(unit->anyCommand()) {
|
if(unit->anyCommand()) {
|
||||||
unit->getCurrCommand()->getCommandType()->update(this, unit);
|
unit->getCurrCommand()->getCommandType()->update(this, unit);
|
||||||
}
|
}
|
||||||
|
@ -132,7 +130,7 @@ 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->setCurrSkill(scStop);
|
unit->setCurrSkill(scStop);
|
||||||
if(unit->getType()->hasCommandClass(ccStop)){
|
if(unit->getType()->hasCommandClass(ccStop)){
|
||||||
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)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -247,6 +247,9 @@ void World::update(){
|
||||||
//tick
|
//tick
|
||||||
if(frameCount%GameConstants::updateFps==0){
|
if(frameCount%GameConstants::updateFps==0){
|
||||||
computeFow();
|
computeFow();
|
||||||
|
|
||||||
|
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\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
@ -296,7 +299,11 @@ void World::tick(){
|
||||||
Unit* World::findUnitById(int id){
|
Unit* World::findUnitById(int id){
|
||||||
for(int i= 0; i<getFactionCount(); ++i){
|
for(int i= 0; i<getFactionCount(); ++i){
|
||||||
Faction* faction= getFaction(i);
|
Faction* faction= getFaction(i);
|
||||||
|
Unit* unit = faction->findUnit(id);
|
||||||
|
if(unit != NULL) {
|
||||||
|
return unit;
|
||||||
|
}
|
||||||
|
/*
|
||||||
for(int j= 0; j<faction->getUnitCount(); ++j){
|
for(int j= 0; j<faction->getUnitCount(); ++j){
|
||||||
Unit* unit= faction->getUnit(j);
|
Unit* unit= faction->getUnit(j);
|
||||||
|
|
||||||
|
@ -304,6 +311,7 @@ Unit* World::findUnitById(int id){
|
||||||
return unit;
|
return unit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -727,6 +735,28 @@ void World::initMap(){
|
||||||
// ==================== exploration ====================
|
// ==================== exploration ====================
|
||||||
|
|
||||||
void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex){
|
void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex){
|
||||||
|
// Experimental cache lookup of previously calculated cells + sight range
|
||||||
|
for(int idx = 0; idx < ExploredCellsLookupItemCache.size(); ++idx) {
|
||||||
|
ExploredCellsLookupItem &item = ExploredCellsLookupItemCache[idx];
|
||||||
|
if(item.pos == newPos && item.sightRange == sightRange && item.teamIndex == teamIndex) {
|
||||||
|
std::vector<SurfaceCell *> &cellList = item.exploredCellList;
|
||||||
|
for(int idx2 = 0; idx2 < cellList.size(); ++idx2) {
|
||||||
|
SurfaceCell *sc = cellList[idx2];
|
||||||
|
sc->setExplored(teamIndex, true);
|
||||||
|
}
|
||||||
|
cellList = item.visibleCellList;
|
||||||
|
for(int idx2 = 0; idx2 < cellList.size(); ++idx2) {
|
||||||
|
SurfaceCell *sc = cellList[idx2];
|
||||||
|
sc->setVisible(teamIndex, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ExploredCellsLookupItem item;
|
||||||
|
item.pos = newPos;
|
||||||
|
item.sightRange = sightRange;
|
||||||
|
item.teamIndex = teamIndex;
|
||||||
|
|
||||||
Vec2i newSurfPos= Map::toSurfCoords(newPos);
|
Vec2i newSurfPos= Map::toSurfCoords(newPos);
|
||||||
int surfSightRange= sightRange/Map::cellScale+1;
|
int surfSightRange= sightRange/Map::cellScale+1;
|
||||||
|
@ -743,23 +773,34 @@ void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex){
|
||||||
//explore
|
//explore
|
||||||
if(Vec2i(0).dist(currRelPos) < surfSightRange+indirectSightRange+1){
|
if(Vec2i(0).dist(currRelPos) < surfSightRange+indirectSightRange+1){
|
||||||
sc->setExplored(teamIndex, true);
|
sc->setExplored(teamIndex, true);
|
||||||
|
|
||||||
|
item.exploredCellList.push_back(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
//visible
|
//visible
|
||||||
if(Vec2i(0).dist(currRelPos) < surfSightRange){
|
if(Vec2i(0).dist(currRelPos) < surfSightRange){
|
||||||
sc->setVisible(teamIndex, true);
|
sc->setVisible(teamIndex, true);
|
||||||
|
item.visibleCellList.push_back(sc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(item.exploredCellList.size() > 0 || item.visibleCellList.size() > 0) {
|
||||||
|
ExploredCellsLookupItemCache.push_back(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//computes the fog of war texture, contained in the minimap
|
//computes the fog of war texture, contained in the minimap
|
||||||
void World::computeFow(){
|
void World::computeFow(){
|
||||||
|
Chrono chrono;
|
||||||
|
chrono.start();
|
||||||
|
|
||||||
//reset texture
|
//reset texture
|
||||||
minimap.resetFowTex();
|
minimap.resetFowTex();
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
|
||||||
//reset cells
|
//reset cells
|
||||||
for(int i=0; i<map.getSurfaceW(); ++i){
|
for(int i=0; i<map.getSurfaceW(); ++i){
|
||||||
for(int j=0; j<map.getSurfaceH(); ++j){
|
for(int j=0; j<map.getSurfaceH(); ++j){
|
||||||
|
@ -771,6 +812,8 @@ void World::computeFow(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
|
||||||
//compute cells
|
//compute cells
|
||||||
for(int i=0; i<getFactionCount(); ++i){
|
for(int i=0; i<getFactionCount(); ++i){
|
||||||
for(int j=0; j<getFaction(i)->getUnitCount(); ++j){
|
for(int j=0; j<getFaction(i)->getUnitCount(); ++j){
|
||||||
|
@ -783,6 +826,8 @@ void World::computeFow(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
|
||||||
//fire
|
//fire
|
||||||
for(int i=0; i<getFactionCount(); ++i){
|
for(int i=0; i<getFactionCount(); ++i){
|
||||||
for(int j=0; j<getFaction(i)->getUnitCount(); ++j){
|
for(int j=0; j<getFaction(i)->getUnitCount(); ++j){
|
||||||
|
@ -796,6 +841,8 @@ void World::computeFow(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
|
|
||||||
//compute texture
|
//compute texture
|
||||||
for(int i=0; i<getFactionCount(); ++i){
|
for(int i=0; i<getFactionCount(); ++i){
|
||||||
Faction *faction= getFaction(i);
|
Faction *faction= getFaction(i);
|
||||||
|
@ -839,6 +886,8 @@ void World::computeFow(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
// WARNING! This id is critical! MAke sure it fits inside the network packet
|
// WARNING! This id is critical! MAke sure it fits inside the network packet
|
||||||
|
|
|
@ -52,10 +52,23 @@ class RoutePlanner;
|
||||||
/// The game world: Map + Tileset + TechTree
|
/// The game world: Map + Tileset + TechTree
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
|
class ExploredCellsLookupItem {
|
||||||
|
public:
|
||||||
|
|
||||||
|
Vec2i pos;
|
||||||
|
int sightRange;
|
||||||
|
int teamIndex;
|
||||||
|
|
||||||
|
std::vector<SurfaceCell *> exploredCellList;
|
||||||
|
std::vector<SurfaceCell *> visibleCellList;
|
||||||
|
};
|
||||||
|
|
||||||
class World{
|
class World{
|
||||||
private:
|
private:
|
||||||
typedef vector<Faction> Factions;
|
typedef vector<Faction> Factions;
|
||||||
|
|
||||||
|
std::vector<ExploredCellsLookupItem> ExploredCellsLookupItemCache;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const int generationArea= 100;
|
static const int generationArea= 100;
|
||||||
static const float airHeight;
|
static const float airHeight;
|
||||||
|
|
Loading…
Reference in New Issue