- added a new skill to toggle fog of war for any command.

This commit is contained in:
Mark Vejvoda 2013-01-11 18:18:58 +00:00
parent 563bd8ac57
commit 7b99501697
11 changed files with 241 additions and 158 deletions

View File

@ -135,8 +135,6 @@ Game::Game() : ProgramState(NULL) {
pauseGamePopupMenuIndex = -1; pauseGamePopupMenuIndex = -1;
saveGamePopupMenuIndex = -1; saveGamePopupMenuIndex = -1;
loadGamePopupMenuIndex = -1; loadGamePopupMenuIndex = -1;
//markCellPopupMenuIndex = -1;
//unmarkCellPopupMenuIndex = -1;
keyboardSetupPopupMenuIndex = -1; keyboardSetupPopupMenuIndex = -1;
disconnectPlayerPopupMenuIndex = -1; disconnectPlayerPopupMenuIndex = -1;
@ -201,8 +199,6 @@ void Game::resetMembers() {
pauseGamePopupMenuIndex = -1; pauseGamePopupMenuIndex = -1;
saveGamePopupMenuIndex = -1; saveGamePopupMenuIndex = -1;
loadGamePopupMenuIndex = -1; loadGamePopupMenuIndex = -1;
//markCellPopupMenuIndex = -1;
//unmarkCellPopupMenuIndex = -1;
keyboardSetupPopupMenuIndex = -1; keyboardSetupPopupMenuIndex = -1;
disconnectPlayerPopupMenuIndex = -1; disconnectPlayerPopupMenuIndex = -1;
@ -215,7 +211,6 @@ void Game::resetMembers() {
currentUIState = NULL; currentUIState = NULL;
//this->gameSettings= NULL;
scrollSpeed = Config::getInstance().getFloat("UiScrollSpeed","1.5"); scrollSpeed = Config::getInstance().getFloat("UiScrollSpeed","1.5");
photoModeEnabled = Config::getInstance().getBool("PhotoMode","false"); photoModeEnabled = Config::getInstance().getBool("PhotoMode","false");
visibleHUD = Config::getInstance().getBool("VisibleHud","true"); visibleHUD = Config::getInstance().getBool("VisibleHud","true");

View File

@ -979,6 +979,17 @@ void Unit::setCurrSkill(const SkillType *currSkill) {
} }
unitParticleSystems.pop_back(); unitParticleSystems.pop_back();
} }
Command *cmd = getCurrrentCommandThreadSafe();
// Remove old fog of war skill type if need be
game->getWorld()->removeFogOfWarSkillType(this);
// Set mew fog of war skill type if need be
if(cmd != NULL && cmd->getCommandType() != NULL &&
cmd->getCommandType()->hasFogOfWarSkillType(currSkill->getName())) {
const FogOfWarSkillType *fowst = cmd->getCommandType()->getFogOfWarSkillType();
game->getWorld()->addFogOfWarSkillType(this,fowst);
}
} }
if(showUnitParticles == true && if(showUnitParticles == true &&
currSkill->unitParticleSystemTypes.empty() == false && currSkill->unitParticleSystemTypes.empty() == false &&

View File

@ -78,9 +78,30 @@ void CommandType::load(int id, const XmlNode *n, const string &dir,
upgradeReqs.push_back(ft->getUpgradeType(name)); upgradeReqs.push_back(ft->getUpgradeType(name));
} }
//fog of war
if(n->hasChild("fog-of-war-skill") == true) {
string skillName= n->getChild("fog-of-war-skill")->getAttribute("value")->getRestrictedValue();
fogOfWarSkillType = static_cast<const FogOfWarSkillType*>(ut.getSkillType(skillName, scFogOfWar));
string skillAttachmentNames = n->getChild("fog-of-war-skill")->getAttribute("skill-attachments")->getRestrictedValue();
std::vector<std::string> skillList;
Tokenize(skillAttachmentNames,skillList,",");
for(unsigned int i = 0; i < skillList.size(); ++i) {
string skillAttachName = skillList[i];
fogOfWarSkillAttachments[skillAttachName] = true;
}
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
bool CommandType::hasFogOfWarSkillType(string name) const {
std::map<string,bool>::const_iterator iterFind = fogOfWarSkillAttachments.find(name);
bool result = (iterFind != fogOfWarSkillAttachments.end());
return result;
}
// ===================================================== // =====================================================
// class StopCommandType // class StopCommandType
// ===================================================== // =====================================================

View File

@ -76,6 +76,9 @@ protected:
Clicks clicks; Clicks clicks;
int id; int id;
std::map<string,bool> fogOfWarSkillAttachments;
const FogOfWarSkillType* fogOfWarSkillType;
public: public:
static const int invalidId= -1; static const int invalidId= -1;
CommandClass commandTypeClass; CommandClass commandTypeClass;
@ -85,6 +88,8 @@ public:
commandTypeClass = ccNull; commandTypeClass = ccNull;
clicks = cOne; clicks = cOne;
id = -1; id = -1;
fogOfWarSkillType = NULL;
fogOfWarSkillAttachments.clear();
} }
virtual void update(UnitUpdater *unitUpdater, Unit *unit, int frameIndex) const= 0; virtual void update(UnitUpdater *unitUpdater, Unit *unit, int frameIndex) const= 0;
virtual void load(int id, const XmlNode *n, const string &dir, virtual void load(int id, const XmlNode *n, const string &dir,
@ -110,6 +115,10 @@ public:
CommandClass getClass() const; CommandClass getClass() const;
Clicks getClicks() const {return clicks;} Clicks getClicks() const {return clicks;}
int getId() const {return id;} int getId() const {return id;}
const FogOfWarSkillType *getFogOfWarSkillType() const {return fogOfWarSkillType;};
bool hasFogOfWarSkillType(string name) const;
}; };
// =============================== // ===============================

View File

@ -583,6 +583,7 @@ string SkillType::skillClassToStr(SkillClass skillClass) {
case scBeBuilt: return "Be Built"; case scBeBuilt: return "Be Built";
case scProduce: return "Produce"; case scProduce: return "Produce";
case scUpgrade: return "Upgrade"; case scUpgrade: return "Upgrade";
case scFogOfWar: return "Fog Of War";
default: default:
assert(false); assert(false);
break; break;
@ -1116,6 +1117,44 @@ void DieSkillType::saveGame(XmlNode *rootNode) {
dieSkillTypeNode->addAttribute("fade",intToStr(fade), mapTagReplacements); dieSkillTypeNode->addAttribute("fade",intToStr(fade), mapTagReplacements);
} }
// =====================================================
// class FogOfWarSkillType
// =====================================================
FogOfWarSkillType::FogOfWarSkillType(){
skillClass= scFogOfWar;
fowEnable = false;
applyToTeam = false;
durationTime = 0;
}
void FogOfWarSkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode,
const string &dir, const TechTree *tt,
const FactionType *ft, std::map<string,vector<pair<string, string> > > &loadedFileList,
string parentLoader) {
SkillType::load(sn, attackBoostsNode,dir, tt, ft, loadedFileList, parentLoader);
fowEnable = sn->getChild("enable-fog")->getAttribute("value")->getBoolValue();
applyToTeam = sn->getChild("apply-team")->getAttribute("value")->getBoolValue();
durationTime = sn->getChild("duration")->getAttribute("value")->getFloatValue();
}
string FogOfWarSkillType::toString() const{
return "FogOfWar";
}
void FogOfWarSkillType::saveGame(XmlNode *rootNode) {
SkillType::saveGame(rootNode);
std::map<string,string> mapTagReplacements;
XmlNode *fogSkillTypeNode = rootNode->addChild("FogOfWarSkillType");
fogSkillTypeNode->addAttribute("enable-fog",intToStr(fowEnable), mapTagReplacements);
fogSkillTypeNode->addAttribute("apply-team",intToStr(applyToTeam), mapTagReplacements);
fogSkillTypeNode->addAttribute("duration",floatToStr(durationTime), mapTagReplacements);
}
// ===================================================== // =====================================================
// class SkillTypeFactory // class SkillTypeFactory
// ===================================================== // =====================================================
@ -1132,6 +1171,7 @@ SkillTypeFactory::SkillTypeFactory(){
registerClass<UpgradeSkillType>("upgrade"); registerClass<UpgradeSkillType>("upgrade");
registerClass<MorphSkillType>("morph"); registerClass<MorphSkillType>("morph");
registerClass<DieSkillType>("die"); registerClass<DieSkillType>("die");
registerClass<FogOfWarSkillType>("fog_of_war");
} }
SkillTypeFactory &SkillTypeFactory::getInstance(){ SkillTypeFactory &SkillTypeFactory::getInstance(){

View File

@ -68,6 +68,7 @@ enum SkillClass{
scUpgrade, scUpgrade,
scMorph, scMorph,
scDie, scDie,
scFogOfWar,
scCount scCount
}; };
@ -410,6 +411,30 @@ public:
virtual void saveGame(XmlNode *rootNode); virtual void saveGame(XmlNode *rootNode);
}; };
// ===============================
// class FogOfWarSkillType
// ===============================
class FogOfWarSkillType: public SkillType {
private:
bool fowEnable;
bool applyToTeam;
float durationTime;
public:
FogOfWarSkillType();
bool getFowEnable() const {return fowEnable;}
bool getApplyToTeam() const {return applyToTeam;}
float getDurationTime() const {return durationTime;}
virtual void load(const XmlNode *sn, const XmlNode *attackBoostsNode, const string &dir, const TechTree *tt,
const FactionType *ft, std::map<string,vector<pair<string, string> > > &loadedFileList,
string parentLoader);
virtual string toString() const;
virtual void saveGame(XmlNode *rootNode);
};
// =============================== // ===============================
// class SkillFactory // class SkillFactory
// =============================== // ===============================

View File

@ -34,7 +34,9 @@ const float Minimap::exploredAlpha= 0.5f;
Minimap::Minimap() { Minimap::Minimap() {
fowPixmap0= NULL; fowPixmap0= NULL;
fowPixmap1= NULL; fowPixmap1= NULL;
fogOfWar= true;//Config::getInstance().getBool("FogOfWar"); fowPixmap0Copy = NULL;
fowPixmap1Copy = NULL;
fogOfWar= true;
gameSettings= NULL; gameSettings= NULL;
tex=NULL; tex=NULL;
fowTex=NULL; fowTex=NULL;
@ -59,7 +61,9 @@ void Minimap::init(int w, int h, const World *world, bool fogOfWar) {
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) { if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) {
fowPixmap0 = new Pixmap2D(potW, potH, 1); fowPixmap0 = new Pixmap2D(potW, potH, 1);
fowPixmap0Copy = new Pixmap2D(potW, potH, 1);
fowPixmap1 = new Pixmap2D(potW, potH, 1); fowPixmap1 = new Pixmap2D(potW, potH, 1);
fowPixmap1Copy = new Pixmap2D(potW, potH, 1);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -112,21 +116,46 @@ Minimap::~Minimap() {
Logger::getInstance().add(Lang::getInstance().get("LogScreenGameUnLoadingMiniMap","",true), true); Logger::getInstance().add(Lang::getInstance().get("LogScreenGameUnLoadingMiniMap","",true), true);
delete fowPixmap0; delete fowPixmap0;
fowPixmap0=NULL; fowPixmap0=NULL;
delete fowPixmap0Copy;
fowPixmap0Copy = NULL;
delete fowPixmap1; delete fowPixmap1;
fowPixmap1=NULL; fowPixmap1=NULL;
delete fowPixmap1Copy;
fowPixmap1Copy=NULL;
} }
// ==================== set ==================== // ==================== set ====================
void Minimap::incFowTextureAlphaSurface(const Vec2i &sPos, float alpha) { void Minimap::incFowTextureAlphaSurface(const Vec2i &sPos, float alpha,
bool isIncrementalUpdate) {
if(fowPixmap1) { if(fowPixmap1) {
assert(sPos.x<fowPixmap1->getW() && sPos.y<fowPixmap1->getH()); assert(sPos.x<fowPixmap1->getW() && sPos.y<fowPixmap1->getH());
if(fowPixmap1->getPixelf(sPos.x, sPos.y)<alpha){ if(fowPixmap1->getPixelf(sPos.x, sPos.y)<alpha){
fowPixmap1->setPixel(sPos.x, sPos.y, alpha); fowPixmap1->setPixel(sPos.x, sPos.y, alpha);
} }
if(fowPixmap1Copy != NULL && isIncrementalUpdate == true) {
if(fowPixmap1Copy->getPixelf(sPos.x, sPos.y)<alpha){
fowPixmap1Copy->setPixel(sPos.x, sPos.y, alpha);
} }
} }
}
}
void Minimap::setFogOfWar(bool value) {
fogOfWar = value;
resetFowTex();
}
void Minimap::copyFowTex() {
fowPixmap0Copy->copy(fowPixmap0);
fowPixmap1Copy->copy(fowPixmap1);
}
void Minimap::restoreFowTex() {
fowPixmap0->copy(fowPixmap0Copy);
fowPixmap1->copy(fowPixmap1Copy);
}
void Minimap::resetFowTex() { void Minimap::resetFowTex() {
if(fowTex) { if(fowTex) {
@ -224,8 +253,6 @@ void Minimap::saveGame(XmlNode *rootNode) {
std::map<string,string> mapTagReplacements; std::map<string,string> mapTagReplacements;
XmlNode *minimapNode = rootNode->addChild("Minimap"); XmlNode *minimapNode = rootNode->addChild("Minimap");
// Pixmap2D *fowPixmap0;
// Pixmap2D *fowPixmap1;
if(fowPixmap1 != NULL) { if(fowPixmap1 != NULL) {
for(unsigned int i = 0; i < fowPixmap1->getPixelByteCount(); ++i) { for(unsigned int i = 0; i < fowPixmap1->getPixelByteCount(); ++i) {
if(fowPixmap1->getPixels()[i] != 0) { if(fowPixmap1->getPixels()[i] != 0) {
@ -235,11 +262,6 @@ void Minimap::saveGame(XmlNode *rootNode) {
} }
} }
} }
// Texture2D *tex;
// Texture2D *fowTex; //Fog Of War Texture2D
// bool fogOfWar;
// const GameSettings *gameSettings;
} }
void Minimap::loadGame(const XmlNode *rootNode) { void Minimap::loadGame(const XmlNode *rootNode) {

View File

@ -50,6 +50,9 @@ class Minimap{
private: private:
Pixmap2D *fowPixmap0; Pixmap2D *fowPixmap0;
Pixmap2D *fowPixmap1; Pixmap2D *fowPixmap1;
Pixmap2D *fowPixmap0Copy;
Pixmap2D *fowPixmap1Copy;
Texture2D *tex; Texture2D *tex;
Texture2D *fowTex; //Fog Of War Texture2D Texture2D *fowTex; //Fog Of War Texture2D
bool fogOfWar; bool fogOfWar;
@ -66,10 +69,13 @@ public:
const Texture2D *getFowTexture() const {return fowTex;} const Texture2D *getFowTexture() const {return fowTex;}
const Texture2D *getTexture() const {return tex;} const Texture2D *getTexture() const {return tex;}
void incFowTextureAlphaSurface(const Vec2i &sPos, float alpha); void incFowTextureAlphaSurface(const Vec2i &sPos, float alpha, bool isIncrementalUpdate=false);
void resetFowTex(); void resetFowTex();
void updateFowTex(float t); void updateFowTex(float t);
void setFogOfWar(bool value) { fogOfWar = value; resetFowTex(); } void setFogOfWar(bool value);
void copyFowTex();
void restoreFowTex();
void saveGame(XmlNode *rootNode); void saveGame(XmlNode *rootNode);
void loadGame(const XmlNode *rootNode); void loadGame(const XmlNode *rootNode);

View File

@ -406,7 +406,6 @@ void UnitUpdater::updateStop(Unit *unit, int frameIndex) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && 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(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld --------------------------- [END OF METHOD] ---------------------------\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
} }
// ==================== updateMove ==================== // ==================== updateMove ====================
void UnitUpdater::updateMove(Unit *unit, int frameIndex) { void UnitUpdater::updateMove(Unit *unit, int frameIndex) {
Chrono chrono; Chrono chrono;

View File

@ -54,19 +54,18 @@ World::World() {
ExploredCellsLookupItemCache.clear(); ExploredCellsLookupItemCache.clear();
ExploredCellsLookupItemCacheTimer.clear(); ExploredCellsLookupItemCacheTimer.clear();
ExploredCellsLookupItemCacheTimerCount = 0; ExploredCellsLookupItemCacheTimerCount = 0;
//FowAlphaCellsLookupItemCache.clear();
// Disable this cache as it takes too much RAM (not sure if its worth the performance gain) // Disable this cache as it takes too much RAM (not sure if its worth the performance gain)
enableFowAlphaCellsLookupItemCache = config.getBool("EnableFowCache","true"); enableFowAlphaCellsLookupItemCache = config.getBool("EnableFowCache","true");
nextCommandGroupId = 0; nextCommandGroupId = 0;
techTree = NULL; techTree = NULL;
fogOfWarOverride = false; fogOfWarOverride = false;
fogOfWarSkillTypeValue = -1;
fogOfWarSmoothing= config.getBool("FogOfWarSmoothing"); fogOfWarSmoothing= config.getBool("FogOfWarSmoothing");
fogOfWarSmoothingFrameSkip= config.getInt("FogOfWarSmoothingFrameSkip"); fogOfWarSmoothingFrameSkip= config.getInt("FogOfWarSmoothingFrameSkip");
MaxExploredCellsLookupItemCache= config.getInt("MaxExploredCellsLookupItemCache",intToStr(MaxExploredCellsLookupItemCache).c_str()); MaxExploredCellsLookupItemCache= config.getInt("MaxExploredCellsLookupItemCache",intToStr(MaxExploredCellsLookupItemCache).c_str());
//MaxExploredCellsLookupItemCache = 0;
frameCount= 0; frameCount= 0;
//nextUnitId= 0; //nextUnitId= 0;
@ -77,6 +76,7 @@ World::World() {
thisFactionIndex=0; thisFactionIndex=0;
thisTeamIndex=0; thisTeamIndex=0;
fogOfWar=false; fogOfWar=false;
originalGameFogOfWar = fogOfWar;
perfTimerEnabled=false; perfTimerEnabled=false;
queuedScenarioName=""; queuedScenarioName="";
queuedScenarioKeepFactions=false; queuedScenarioKeepFactions=false;
@ -151,9 +151,10 @@ void World::endScenario() {
ExploredCellsLookupItemCache.clear(); ExploredCellsLookupItemCache.clear();
ExploredCellsLookupItemCacheTimer.clear(); ExploredCellsLookupItemCacheTimer.clear();
//FowAlphaCellsLookupItemCache.clear();
fogOfWarOverride = false; fogOfWarOverride = false;
originalGameFogOfWar = fogOfWar;
fogOfWarSkillTypeValue = -1;
map.end(); map.end();
@ -167,7 +168,6 @@ void World::end(){
ExploredCellsLookupItemCache.clear(); ExploredCellsLookupItemCache.clear();
ExploredCellsLookupItemCacheTimer.clear(); ExploredCellsLookupItemCacheTimer.clear();
//FowAlphaCellsLookupItemCache.clear();
for(int i= 0; i<factions.size(); ++i){ for(int i= 0; i<factions.size(); ++i){
factions[i]->end(); factions[i]->end();
@ -186,6 +186,8 @@ void World::end(){
#endif #endif
fogOfWarOverride = false; fogOfWarOverride = false;
originalGameFogOfWar = fogOfWar;
fogOfWarSkillTypeValue = -1;
map.end(); map.end();
@ -195,18 +197,76 @@ void World::end(){
// ========================== init =============================================== // ========================== init ===============================================
void World::setFogOfWar(bool value) { void World::addFogOfWarSkillType(const Unit *unit,const FogOfWarSkillType *fowst) {
fogOfWar = value; std::pair<const Unit *,const FogOfWarSkillType *> fowData;
fogOfWarOverride = true; fowData.first = unit;
fowData.second = fowst;
if(game != NULL && game->getGameSettings() != NULL) { mapFogOfWarUnitList[unit->getId()] = fowData;
game->getGameSettings()->setFogOfWar(fogOfWar);
initCells(fogOfWar); //must be done after knowing faction number and dimensions if((fowst->getApplyToTeam() == true && unit->getTeam() == this->getThisTeamIndex()) ||
//initMinimap(); (fowst->getApplyToTeam() == false && unit->getFactionIndex() == this->getThisFactionIndex())) {
minimap.setFogOfWar(fogOfWar); if((fowst->getFowEnable() == false && fogOfWarSkillTypeValue != 0) ||
computeFow(); (fowst->getFowEnable() == true && fogOfWarSkillTypeValue != 1)) {
//printf("In [%s::%s Line: %d] current = %d new = %d\n",__FILE__,__FUNCTION__,__LINE__,fogOfWar,fowst->getFowEnable());
setFogOfWar(fowst->getFowEnable());
} }
} }
}
void World::removeFogOfWarSkillType(const Unit *unit) {
if(mapFogOfWarUnitList.find(unit->getId()) != mapFogOfWarUnitList.end()) {
mapFogOfWarUnitList.erase(unit->getId());
if(mapFogOfWarUnitList.empty() == true) {
//printf("In [%s::%s Line: %d] current = %d new = %d\n",__FILE__,__FUNCTION__,__LINE__,fogOfWar,originalGameFogOfWar);
fogOfWarSkillTypeValue = -1;
fogOfWarOverride = false;
minimap.restoreFowTex();
}
else {
bool fowEnabled = false;
for(std::map<int,std::pair<const Unit *,const FogOfWarSkillType *> >::const_iterator iterMap = mapFogOfWarUnitList.begin();
iterMap != mapFogOfWarUnitList.end(); ++iterMap) {
const Unit *unit = iterMap->second.first;
const FogOfWarSkillType *fowst = iterMap->second.second;
if((fowst->getApplyToTeam() == true && unit->getTeam() == this->getThisTeamIndex()) ||
(fowst->getApplyToTeam() == false && unit->getFactionIndex() == this->getThisFactionIndex())) {
if(fowst->getFowEnable() == true) {
fowEnabled = true;
break;
}
}
}
if((fowEnabled == false && fogOfWarSkillTypeValue != 0) ||
(fowEnabled == true && fogOfWarSkillTypeValue != 1)) {
//printf("In [%s::%s Line: %d] current = %d new = %d\n",__FILE__,__FUNCTION__,__LINE__,fogOfWar,fowEnabled);
setFogOfWar(fowEnabled);
}
}
}
}
void World::setFogOfWar(bool value) {
//printf("In [%s::%s Line: %d] current = %d new = %d\n",__FILE__,__FUNCTION__,__LINE__,fogOfWar,value);
if(fogOfWarOverride == false) {
minimap.copyFowTex();
}
if(value == true) {
fogOfWarSkillTypeValue = 1;
}
else {
fogOfWarSkillTypeValue = 0;
}
fogOfWarOverride = true;
}
void World::clearTileset() { void World::clearTileset() {
tileset = Tileset(); tileset = Tileset();
@ -218,7 +278,6 @@ void World::init(Game *game, bool createUnits, bool initFactions){
ExploredCellsLookupItemCache.clear(); ExploredCellsLookupItemCache.clear();
ExploredCellsLookupItemCacheTimer.clear(); ExploredCellsLookupItemCacheTimer.clear();
//FowAlphaCellsLookupItemCache.clear();
this->game = game; this->game = game;
scriptManager= game->getScriptManager(); scriptManager= game->getScriptManager();
@ -227,6 +286,7 @@ void World::init(Game *game, bool createUnits, bool initFactions){
if(fogOfWarOverride == false) { if(fogOfWarOverride == false) {
fogOfWar = gs->getFogOfWar(); fogOfWar = gs->getFogOfWar();
} }
originalGameFogOfWar = fogOfWar;
if(loadWorldNode != NULL) { if(loadWorldNode != NULL) {
timeFlow.loadGame(loadWorldNode); timeFlow.loadGame(loadWorldNode);
@ -418,9 +478,6 @@ void World::updateAllFactionUnits() {
// Clear pathfinder list restrictions // Clear pathfinder list restrictions
for(int i = 0; i < factionCount; ++i) { for(int i = 0; i < factionCount; ++i) {
Faction *faction = getFaction(i); Faction *faction = getFaction(i);
//if(faction == NULL) {
// throw megaglest_runtime_error("faction == NULL");
//}
faction->clearUnitsPathfinding(); faction->clearUnitsPathfinding();
faction->clearAproxCanMoveSoonCached(); faction->clearAproxCanMoveSoonCached();
} }
@ -439,13 +496,9 @@ void World::updateAllFactionUnits() {
// Signal the faction threads to do any pre-processing // Signal the faction threads to do any pre-processing
for(int i = 0; i < factionCount; ++i) { for(int i = 0; i < factionCount; ++i) {
Faction *faction = getFaction(i); Faction *faction = getFaction(i);
//if(faction == NULL) {
// throw megaglest_runtime_error("faction == NULL");
//}
faction->signalWorkerThread(frameCount); faction->signalWorkerThread(frameCount);
} }
//sleep(0);
bool workThreadsFinished = false; bool workThreadsFinished = false;
Chrono chrono; Chrono chrono;
chrono.start(); chrono.start();
@ -455,18 +508,12 @@ void World::updateAllFactionUnits() {
workThreadsFinished = true; workThreadsFinished = true;
for(int i = 0; i < factionCount; ++i) { for(int i = 0; i < factionCount; ++i) {
Faction *faction = getFaction(i); Faction *faction = getFaction(i);
//if(faction == NULL) {
// throw megaglest_runtime_error("faction == NULL");
//}
if(faction->isWorkerThreadSignalCompleted(frameCount) == false) { if(faction->isWorkerThreadSignalCompleted(frameCount) == false) {
workThreadsFinished = false; workThreadsFinished = false;
break; break;
} }
} }
if(workThreadsFinished == false) { if(workThreadsFinished == true) {
//sleep(0);
}
else {
break; break;
} }
} }
@ -477,9 +524,6 @@ void World::updateAllFactionUnits() {
//units //units
for(int i = 0; i < factionCount; ++i) { for(int i = 0; i < factionCount; ++i) {
Faction *faction = getFaction(i); Faction *faction = getFaction(i);
//if(faction == NULL) {
// throw megaglest_runtime_error("faction == NULL");
//}
faction->clearUnitsPathfinding(); faction->clearUnitsPathfinding();
int unitCount = faction->getUnitCount(); int unitCount = faction->getUnitCount();
@ -512,9 +556,6 @@ void World::underTakeDeadFactionUnits() {
for(int i = 0; i< factionCount; ++i) { for(int i = 0; i< factionCount; ++i) {
if(factionIdxToTick == -1 || factionIdxToTick == i) { if(factionIdxToTick == -1 || factionIdxToTick == i) {
Faction *faction = getFaction(i); Faction *faction = getFaction(i);
if(faction == NULL) {
throw megaglest_runtime_error("faction == NULL");
}
int unitCount = faction->getUnitCount(); int unitCount = faction->getUnitCount();
if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] factionIdxToTick = %d, i = %d, unitCount = %d\n",__FILE__,__FUNCTION__,__LINE__,factionIdxToTick,i,unitCount); if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] factionIdxToTick = %d, i = %d, unitCount = %d\n",__FILE__,__FUNCTION__,__LINE__,factionIdxToTick,i,unitCount);
@ -528,7 +569,6 @@ void World::underTakeDeadFactionUnits() {
if(unit->getToBeUndertaken() == true) { if(unit->getToBeUndertaken() == true) {
unit->undertake(); unit->undertake();
delete unit; delete unit;
//j--;
} }
} }
} }
@ -582,14 +622,6 @@ void World::update() {
perfList.push_back(perfBuf); perfList.push_back(perfBuf);
} }
//bool needToUpdateUnits = true;
//if(staggeredFactionUpdates == true) {
// needToUpdateUnits = (frameCount % (GameConstants::updateFps / GameConstants::maxPlayers) == 0);
//}
//if(needToUpdateUnits == true) {
// SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] needToUpdateUnits = %d, frameCount = %d\n",__FILE__,__FUNCTION__,__LINE__,needToUpdateUnits,frameCount);
// objects on the map from tilesets // objects on the map from tilesets
updateAllTilesetObjects(); updateAllTilesetObjects();
@ -737,7 +769,6 @@ void World::tick() {
} }
//increase hp //increase hp
//int i = factionIdxToTick;
int factionCount = getFactionCount(); int factionCount = getFactionCount();
for(int i = 0; i < factionCount; ++i) { for(int i = 0; i < factionCount; ++i) {
if(factionIdxToTick == -1 || i == factionIdxToTick) { if(factionIdxToTick == -1 || i == factionIdxToTick) {
@ -761,7 +792,6 @@ void World::tick() {
} }
//compute resources balance //compute resources balance
//int k = factionIdxToTick;
factionCount = getFactionCount(); factionCount = getFactionCount();
for(int k = 0; k < factionCount; ++k) { for(int k = 0; k < factionCount; ++k) {
if(factionIdxToTick == -1 || k == factionIdxToTick) { if(factionIdxToTick == -1 || k == factionIdxToTick) {
@ -870,7 +900,6 @@ void World::moveUnitCells(Unit *unit) {
Vec2i newPos= unit->getTargetPos(); Vec2i newPos= unit->getTargetPos();
//newPos must be free or the same pos as current //newPos must be free or the same pos as current
//assert(map.getCell(unit->getPos())->getUnit(unit->getCurrField())==unit || map.isFreeCell(newPos, unit->getCurrField()));
// Only change cell placement in map if the new position is different // Only change cell placement in map if the new position is different
// from the old one // from the old one
@ -1466,13 +1495,10 @@ void World::setUnitPosition(int unitId, Vec2i pos) {
throw megaglest_runtime_error("Can not find unit to set position unitId = " + intToStr(unitId)); throw megaglest_runtime_error("Can not find unit to set position unitId = " + intToStr(unitId));
} }
unit->setTargetPos(pos); unit->setTargetPos(pos);
//unit->setPos(pos,true);
this->moveUnitCells(unit); this->moveUnitCells(unit);
} }
void World::addCellMarker(Vec2i pos, int factionIndex, const string &note, const string textureFile) { void World::addCellMarker(Vec2i pos, int factionIndex, const string &note, const string textureFile) {
//Vec2i surfaceCellPos = map.toSurfCoords(pos);
//Vec2i surfaceCellPos = pos;
const Faction *faction = NULL; const Faction *faction = NULL;
if(factionIndex >= 0) { if(factionIndex >= 0) {
faction = this->getFaction(factionIndex); faction = this->getFaction(factionIndex);
@ -1493,8 +1519,6 @@ void World::addCellMarker(Vec2i pos, int factionIndex, const string &note, const
} }
void World::removeCellMarker(Vec2i pos, int factionIndex) { void World::removeCellMarker(Vec2i pos, int factionIndex) {
//Vec2i surfaceCellPos = map.toSurfCoords(pos);
//Vec2i surfaceCellPos = pos;
const Faction *faction = NULL; const Faction *faction = NULL;
if(factionIndex >= 0) { if(factionIndex >= 0) {
faction = this->getFaction(factionIndex); faction = this->getFaction(factionIndex);
@ -1506,8 +1530,6 @@ void World::removeCellMarker(Vec2i pos, int factionIndex) {
} }
void World::showMarker(Vec2i pos, int factionIndex, const string &note, const string textureFile, int flashCount) { void World::showMarker(Vec2i pos, int factionIndex, const string &note, const string textureFile, int flashCount) {
//Vec2i surfaceCellPos = map.toSurfCoords(pos);
//Vec2i surfaceCellPos = pos;
const Faction *faction = NULL; const Faction *faction = NULL;
if(factionIndex >= 0) { if(factionIndex >= 0) {
faction = this->getFaction(factionIndex); faction = this->getFaction(factionIndex);
@ -2076,9 +2098,13 @@ void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex) {
} }
} }
bool World::showWorldForPlayer(int factionIndex) const { bool World::showWorldForPlayer(int factionIndex, bool excludeFogOfWarCheck) const {
bool ret = false; bool ret = false;
if(factionIndex == thisFactionIndex && game != NULL) {
if(excludeFogOfWarCheck == false && fogOfWarSkillTypeValue == 0 && fogOfWarOverride == true) {
ret = true;
}
else if(factionIndex == thisFactionIndex && game != NULL) {
// Player is an Observer // Player is an Observer
if(thisTeamIndex == GameConstants::maxPlayers -1 + fpt_Observer) { if(thisTeamIndex == GameConstants::maxPlayers -1 + fpt_Observer) {
ret = true; ret = true;
@ -2249,14 +2275,10 @@ void World::computeFow(int factionIdxToTick) {
} }
//compute texture //compute texture
//printf("Masterserver = %d\n",game->isMasterserverMode());
//if(fogOfWar == true && game->isMasterserverMode() == false) {
if(fogOfWar == true) { if(fogOfWar == true) {
for(int i=0; i<getFactionCount(); ++i) { for(int i=0; i<getFactionCount(); ++i) {
Faction *faction= getFaction(i); Faction *faction= getFaction(i);
if(faction->getTeam() == thisTeamIndex) { if(faction->getTeam() == thisTeamIndex) {
//if(thisTeamIndex == GameConstants::maxPlayers + fpt_Observer) {
for(int j=0; j<faction->getUnitCount(); ++j){ for(int j=0; j<faction->getUnitCount(); ++j){
const Unit *unit= faction->getUnit(j); const Unit *unit= faction->getUnit(j);
if(unit->isOperative()){ if(unit->isOperative()){
@ -2268,7 +2290,7 @@ void World::computeFow(int factionIdxToTick) {
const Vec2i &surfPos = cellList.surfPosList[k]; const Vec2i &surfPos = cellList.surfPosList[k];
const float &alpha = cellList.alphaList[k]; const float &alpha = cellList.alphaList[k];
minimap.incFowTextureAlphaSurface(surfPos, alpha); minimap.incFowTextureAlphaSurface(surfPos, alpha, true);
} }
} }
else { else {
@ -2277,69 +2299,9 @@ void World::computeFow(int factionIdxToTick) {
const Vec2i &surfPos = cellList.surfPosList[k]; const Vec2i &surfPos = cellList.surfPosList[k];
const float &alpha = cellList.alphaList[k]; const float &alpha = cellList.alphaList[k];
minimap.incFowTextureAlphaSurface(surfPos, alpha); minimap.incFowTextureAlphaSurface(surfPos, alpha, true);
} }
} }
/*
bool foundInCache = false;
if(enableFowAlphaCellsLookupItemCache == true) {
std::map<Vec2i, std::map<int, FowAlphaCellsLookupItem > >::iterator iterMap = FowAlphaCellsLookupItemCache.find(unit->getPos());
if(iterMap != FowAlphaCellsLookupItemCache.end()) {
std::map<int, FowAlphaCellsLookupItem>::iterator iterMap2 = iterMap->second.find(sightRange);
if(iterMap2 != iterMap->second.end()) {
foundInCache = true;
FowAlphaCellsLookupItem &cellList = iterMap2->second;
for(int k = 0; k < cellList.surfPosList.size(); ++k) {
Vec2i &surfPos = cellList.surfPosList[k];
float &alpha = cellList.alphaList[k];
minimap.incFowTextureAlphaSurface(surfPos, alpha);
}
}
}
}
if(foundInCache == false) {
FowAlphaCellsLookupItem itemCache;
//iterate through all cells
PosCircularIterator pci(&map, unit->getPos(), sightRange+indirectSightRange);
while(pci.next()){
const Vec2i pos= pci.getPos();
Vec2i surfPos= Map::toSurfCoords(pos);
//compute max alpha
float maxAlpha= 0.0f;
if(surfPos.x>1 && surfPos.y>1 && surfPos.x<map.getSurfaceW()-2 && surfPos.y<map.getSurfaceH()-2){
maxAlpha= 1.f;
}
else if(surfPos.x>0 && surfPos.y>0 && surfPos.x<map.getSurfaceW()-1 && surfPos.y<map.getSurfaceH()-1){
maxAlpha= 0.3f;
}
//compute alpha
float alpha=maxAlpha;
float dist= unit->getPos().dist(pos);
if(dist>sightRange){
alpha= clamp(1.f-(dist-sightRange)/(indirectSightRange), 0.f, maxAlpha);
}
minimap.incFowTextureAlphaSurface(surfPos, alpha);
if(enableFowAlphaCellsLookupItemCache == true) {
itemCache.surfPosList.push_back(surfPos);
itemCache.alphaList.push_back(alpha);
}
}
if(enableFowAlphaCellsLookupItemCache == true) {
if(itemCache.surfPosList.empty() == false) {
FowAlphaCellsLookupItemCache[unit->getPos()][sightRange] = itemCache;
}
}
}
*/
} }
} }
} }
@ -2356,7 +2318,6 @@ void World::computeFow(int factionIdxToTick) {
printf("%s",perfList[x].c_str()); printf("%s",perfList[x].c_str());
} }
} }
} }
GameSettings * World::getGameSettingsPtr() { GameSettings * World::getGameSettingsPtr() {
@ -2416,7 +2377,6 @@ string World::getExploredCellsLookupItemCacheStats() {
int exploredCellCount = 0; int exploredCellCount = 0;
int visibleCellCount = 0; int visibleCellCount = 0;
//std::map<Vec2i, std::map<int, ExploredCellsLookupItem > > ExploredCellsLookupItemCache;
for(std::map<Vec2i, std::map<int, ExploredCellsLookupItem > >::iterator iterMap1 = ExploredCellsLookupItemCache.begin(); for(std::map<Vec2i, std::map<int, ExploredCellsLookupItem > >::iterator iterMap1 = ExploredCellsLookupItemCache.begin();
iterMap1 != ExploredCellsLookupItemCache.end(); ++iterMap1) { iterMap1 != ExploredCellsLookupItemCache.end(); ++iterMap1) {
posCount++; posCount++;
@ -2449,19 +2409,6 @@ string World::getFowAlphaCellsLookupItemCacheStats() {
int surfPosCount = 0; int surfPosCount = 0;
int alphaListCount = 0; int alphaListCount = 0;
//std::map<Vec2i, std::map<int, FowAlphaCellsLookupItem > > FowAlphaCellsLookupItemCache;
// for(std::map<Vec2i, std::map<int, FowAlphaCellsLookupItem > >::iterator iterMap1 = FowAlphaCellsLookupItemCache.begin();
// iterMap1 != FowAlphaCellsLookupItemCache.end(); ++iterMap1) {
// posCount++;
//
// for(std::map<int, FowAlphaCellsLookupItem >::iterator iterMap2 = iterMap1->second.begin();
// iterMap2 != iterMap1->second.end(); ++iterMap2) {
// sightCount++;
//
// surfPosCount += iterMap2->second.surfPosList.size();
// alphaListCount += iterMap2->second.alphaList.size();
// }
// }
for(int i=0; i<getFactionCount(); ++i) { for(int i=0; i<getFactionCount(); ++i) {
Faction *faction= getFaction(i); Faction *faction= getFaction(i);
if(faction->getTeam() == thisTeamIndex) { if(faction->getTeam() == thisTeamIndex) {

View File

@ -125,6 +125,8 @@ private:
bool fogOfWar; bool fogOfWar;
int fogOfWarSmoothingFrameSkip; int fogOfWarSmoothingFrameSkip;
bool fogOfWarSmoothing; bool fogOfWarSmoothing;
int fogOfWarSkillTypeValue;
Game *game; Game *game;
Chrono chronoPerfTimer; Chrono chronoPerfTimer;
bool perfTimerEnabled; bool perfTimerEnabled;
@ -145,6 +147,9 @@ private:
MasterSlaveThreadController masterController; MasterSlaveThreadController masterController;
bool originalGameFogOfWar;
std::map<int,std::pair<const Unit *,const FogOfWarSkillType *> > mapFogOfWarUnitList;
public: public:
World(); World();
~World(); ~World();
@ -152,6 +157,9 @@ public:
void end(); //to die before selection does void end(); //to die before selection does
void endScenario(); //to die before selection does void endScenario(); //to die before selection does
void addFogOfWarSkillType(const Unit *unit,const FogOfWarSkillType *fowst);
void removeFogOfWarSkillType(const Unit *unit);
//get //get
inline int getMaxPlayers() const {return map.getMaxPlayers();} inline int getMaxPlayers() const {return map.getMaxPlayers();}
inline int getThisFactionIndex() const {return thisFactionIndex;} inline int getThisFactionIndex() const {return thisFactionIndex;}
@ -290,7 +298,7 @@ public:
bool canTickWorld() const; bool canTickWorld() const;
void exploreCells(const Vec2i &newPos, int sightRange, int teamIndex); void exploreCells(const Vec2i &newPos, int sightRange, int teamIndex);
bool showWorldForPlayer(int factionIndex) const; bool showWorldForPlayer(int factionIndex, bool excludeFogOfWarCheck=false) const;
inline UnitUpdater * getUnitUpdater() { return &unitUpdater; } inline UnitUpdater * getUnitUpdater() { return &unitUpdater; }