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

View File

@ -979,6 +979,17 @@ void Unit::setCurrSkill(const SkillType *currSkill) {
}
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 &&
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));
}
//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__);
}
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
// =====================================================

View File

@ -76,6 +76,9 @@ protected:
Clicks clicks;
int id;
std::map<string,bool> fogOfWarSkillAttachments;
const FogOfWarSkillType* fogOfWarSkillType;
public:
static const int invalidId= -1;
CommandClass commandTypeClass;
@ -85,6 +88,8 @@ public:
commandTypeClass = ccNull;
clicks = cOne;
id = -1;
fogOfWarSkillType = NULL;
fogOfWarSkillAttachments.clear();
}
virtual void update(UnitUpdater *unitUpdater, Unit *unit, int frameIndex) const= 0;
virtual void load(int id, const XmlNode *n, const string &dir,
@ -110,6 +115,10 @@ public:
CommandClass getClass() const;
Clicks getClicks() const {return clicks;}
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 scProduce: return "Produce";
case scUpgrade: return "Upgrade";
case scFogOfWar: return "Fog Of War";
default:
assert(false);
break;
@ -1116,6 +1117,44 @@ void DieSkillType::saveGame(XmlNode *rootNode) {
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
// =====================================================
@ -1132,6 +1171,7 @@ SkillTypeFactory::SkillTypeFactory(){
registerClass<UpgradeSkillType>("upgrade");
registerClass<MorphSkillType>("morph");
registerClass<DieSkillType>("die");
registerClass<FogOfWarSkillType>("fog_of_war");
}
SkillTypeFactory &SkillTypeFactory::getInstance(){

View File

@ -68,6 +68,7 @@ enum SkillClass{
scUpgrade,
scMorph,
scDie,
scFogOfWar,
scCount
};
@ -394,7 +395,7 @@ public:
// class DieSkillType
// ===============================
class DieSkillType: public SkillType{
class DieSkillType: public SkillType {
private:
bool fade;
@ -410,11 +411,35 @@ public:
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 SkillTypeFactory: public MultiFactory<SkillType>{
class SkillTypeFactory: public MultiFactory<SkillType> {
private:
SkillTypeFactory();
public:

View File

@ -34,7 +34,9 @@ const float Minimap::exploredAlpha= 0.5f;
Minimap::Minimap() {
fowPixmap0= NULL;
fowPixmap1= NULL;
fogOfWar= true;//Config::getInstance().getBool("FogOfWar");
fowPixmap0Copy = NULL;
fowPixmap1Copy = NULL;
fogOfWar= true;
gameSettings= NULL;
tex=NULL;
fowTex=NULL;
@ -58,8 +60,10 @@ void Minimap::init(int w, int h, const World *world, bool fogOfWar) {
float f= 0.f;
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) {
fowPixmap0= new Pixmap2D(potW, potH, 1);
fowPixmap1= new Pixmap2D(potW, potH, 1);
fowPixmap0 = new Pixmap2D(potW, potH, 1);
fowPixmap0Copy = 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__);
@ -112,22 +116,47 @@ Minimap::~Minimap() {
Logger::getInstance().add(Lang::getInstance().get("LogScreenGameUnLoadingMiniMap","",true), true);
delete fowPixmap0;
fowPixmap0=NULL;
delete fowPixmap0Copy;
fowPixmap0Copy = NULL;
delete fowPixmap1;
fowPixmap1=NULL;
delete fowPixmap1Copy;
fowPixmap1Copy=NULL;
}
// ==================== set ====================
void Minimap::incFowTextureAlphaSurface(const Vec2i &sPos, float alpha) {
void Minimap::incFowTextureAlphaSurface(const Vec2i &sPos, float alpha,
bool isIncrementalUpdate) {
if(fowPixmap1) {
assert(sPos.x<fowPixmap1->getW() && sPos.y<fowPixmap1->getH());
if(fowPixmap1->getPixelf(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() {
if(fowTex) {
Pixmap2D *tmpPixmap= fowPixmap0;
@ -224,8 +253,6 @@ void Minimap::saveGame(XmlNode *rootNode) {
std::map<string,string> mapTagReplacements;
XmlNode *minimapNode = rootNode->addChild("Minimap");
// Pixmap2D *fowPixmap0;
// Pixmap2D *fowPixmap1;
if(fowPixmap1 != NULL) {
for(unsigned int i = 0; i < fowPixmap1->getPixelByteCount(); ++i) {
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) {

View File

@ -50,6 +50,9 @@ class Minimap{
private:
Pixmap2D *fowPixmap0;
Pixmap2D *fowPixmap1;
Pixmap2D *fowPixmap0Copy;
Pixmap2D *fowPixmap1Copy;
Texture2D *tex;
Texture2D *fowTex; //Fog Of War Texture2D
bool fogOfWar;
@ -66,10 +69,13 @@ public:
const Texture2D *getFowTexture() const {return fowTex;}
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 updateFowTex(float t);
void setFogOfWar(bool value) { fogOfWar = value; resetFowTex(); }
void setFogOfWar(bool value);
void copyFowTex();
void restoreFowTex();
void saveGame(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());
}
// ==================== updateMove ====================
void UnitUpdater::updateMove(Unit *unit, int frameIndex) {
Chrono chrono;

View File

@ -54,19 +54,18 @@ World::World() {
ExploredCellsLookupItemCache.clear();
ExploredCellsLookupItemCacheTimer.clear();
ExploredCellsLookupItemCacheTimerCount = 0;
//FowAlphaCellsLookupItemCache.clear();
// Disable this cache as it takes too much RAM (not sure if its worth the performance gain)
enableFowAlphaCellsLookupItemCache = config.getBool("EnableFowCache","true");
nextCommandGroupId = 0;
techTree = NULL;
fogOfWarOverride = false;
fogOfWarSkillTypeValue = -1;
fogOfWarSmoothing= config.getBool("FogOfWarSmoothing");
fogOfWarSmoothingFrameSkip= config.getInt("FogOfWarSmoothingFrameSkip");
MaxExploredCellsLookupItemCache= config.getInt("MaxExploredCellsLookupItemCache",intToStr(MaxExploredCellsLookupItemCache).c_str());
//MaxExploredCellsLookupItemCache = 0;
frameCount= 0;
//nextUnitId= 0;
@ -77,6 +76,7 @@ World::World() {
thisFactionIndex=0;
thisTeamIndex=0;
fogOfWar=false;
originalGameFogOfWar = fogOfWar;
perfTimerEnabled=false;
queuedScenarioName="";
queuedScenarioKeepFactions=false;
@ -151,9 +151,10 @@ void World::endScenario() {
ExploredCellsLookupItemCache.clear();
ExploredCellsLookupItemCacheTimer.clear();
//FowAlphaCellsLookupItemCache.clear();
fogOfWarOverride = false;
originalGameFogOfWar = fogOfWar;
fogOfWarSkillTypeValue = -1;
map.end();
@ -167,7 +168,6 @@ void World::end(){
ExploredCellsLookupItemCache.clear();
ExploredCellsLookupItemCacheTimer.clear();
//FowAlphaCellsLookupItemCache.clear();
for(int i= 0; i<factions.size(); ++i){
factions[i]->end();
@ -186,6 +186,8 @@ void World::end(){
#endif
fogOfWarOverride = false;
originalGameFogOfWar = fogOfWar;
fogOfWarSkillTypeValue = -1;
map.end();
@ -195,18 +197,76 @@ void World::end(){
// ========================== init ===============================================
void World::setFogOfWar(bool value) {
fogOfWar = value;
fogOfWarOverride = true;
void World::addFogOfWarSkillType(const Unit *unit,const FogOfWarSkillType *fowst) {
std::pair<const Unit *,const FogOfWarSkillType *> fowData;
fowData.first = unit;
fowData.second = fowst;
if(game != NULL && game->getGameSettings() != NULL) {
game->getGameSettings()->setFogOfWar(fogOfWar);
initCells(fogOfWar); //must be done after knowing faction number and dimensions
//initMinimap();
minimap.setFogOfWar(fogOfWar);
computeFow();
mapFogOfWarUnitList[unit->getId()] = fowData;
if((fowst->getApplyToTeam() == true && unit->getTeam() == this->getThisTeamIndex()) ||
(fowst->getApplyToTeam() == false && unit->getFactionIndex() == this->getThisFactionIndex())) {
if((fowst->getFowEnable() == false && fogOfWarSkillTypeValue != 0) ||
(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() {
tileset = Tileset();
@ -218,7 +278,6 @@ void World::init(Game *game, bool createUnits, bool initFactions){
ExploredCellsLookupItemCache.clear();
ExploredCellsLookupItemCacheTimer.clear();
//FowAlphaCellsLookupItemCache.clear();
this->game = game;
scriptManager= game->getScriptManager();
@ -227,6 +286,7 @@ void World::init(Game *game, bool createUnits, bool initFactions){
if(fogOfWarOverride == false) {
fogOfWar = gs->getFogOfWar();
}
originalGameFogOfWar = fogOfWar;
if(loadWorldNode != NULL) {
timeFlow.loadGame(loadWorldNode);
@ -418,9 +478,6 @@ void World::updateAllFactionUnits() {
// Clear pathfinder list restrictions
for(int i = 0; i < factionCount; ++i) {
Faction *faction = getFaction(i);
//if(faction == NULL) {
// throw megaglest_runtime_error("faction == NULL");
//}
faction->clearUnitsPathfinding();
faction->clearAproxCanMoveSoonCached();
}
@ -439,13 +496,9 @@ void World::updateAllFactionUnits() {
// Signal the faction threads to do any pre-processing
for(int i = 0; i < factionCount; ++i) {
Faction *faction = getFaction(i);
//if(faction == NULL) {
// throw megaglest_runtime_error("faction == NULL");
//}
faction->signalWorkerThread(frameCount);
}
//sleep(0);
bool workThreadsFinished = false;
Chrono chrono;
chrono.start();
@ -455,18 +508,12 @@ void World::updateAllFactionUnits() {
workThreadsFinished = true;
for(int i = 0; i < factionCount; ++i) {
Faction *faction = getFaction(i);
//if(faction == NULL) {
// throw megaglest_runtime_error("faction == NULL");
//}
if(faction->isWorkerThreadSignalCompleted(frameCount) == false) {
workThreadsFinished = false;
break;
}
}
if(workThreadsFinished == false) {
//sleep(0);
}
else {
if(workThreadsFinished == true) {
break;
}
}
@ -477,9 +524,6 @@ void World::updateAllFactionUnits() {
//units
for(int i = 0; i < factionCount; ++i) {
Faction *faction = getFaction(i);
//if(faction == NULL) {
// throw megaglest_runtime_error("faction == NULL");
//}
faction->clearUnitsPathfinding();
int unitCount = faction->getUnitCount();
@ -512,9 +556,6 @@ void World::underTakeDeadFactionUnits() {
for(int i = 0; i< factionCount; ++i) {
if(factionIdxToTick == -1 || factionIdxToTick == i) {
Faction *faction = getFaction(i);
if(faction == NULL) {
throw megaglest_runtime_error("faction == NULL");
}
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);
@ -528,7 +569,6 @@ void World::underTakeDeadFactionUnits() {
if(unit->getToBeUndertaken() == true) {
unit->undertake();
delete unit;
//j--;
}
}
}
@ -582,14 +622,6 @@ void World::update() {
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
updateAllTilesetObjects();
@ -737,7 +769,6 @@ void World::tick() {
}
//increase hp
//int i = factionIdxToTick;
int factionCount = getFactionCount();
for(int i = 0; i < factionCount; ++i) {
if(factionIdxToTick == -1 || i == factionIdxToTick) {
@ -761,7 +792,6 @@ void World::tick() {
}
//compute resources balance
//int k = factionIdxToTick;
factionCount = getFactionCount();
for(int k = 0; k < factionCount; ++k) {
if(factionIdxToTick == -1 || k == factionIdxToTick) {
@ -870,7 +900,6 @@ void World::moveUnitCells(Unit *unit) {
Vec2i newPos= unit->getTargetPos();
//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
// 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));
}
unit->setTargetPos(pos);
//unit->setPos(pos,true);
this->moveUnitCells(unit);
}
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;
if(factionIndex >= 0) {
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) {
//Vec2i surfaceCellPos = map.toSurfCoords(pos);
//Vec2i surfaceCellPos = pos;
const Faction *faction = NULL;
if(factionIndex >= 0) {
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) {
//Vec2i surfaceCellPos = map.toSurfCoords(pos);
//Vec2i surfaceCellPos = pos;
const Faction *faction = NULL;
if(factionIndex >= 0) {
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;
if(factionIndex == thisFactionIndex && game != NULL) {
if(excludeFogOfWarCheck == false && fogOfWarSkillTypeValue == 0 && fogOfWarOverride == true) {
ret = true;
}
else if(factionIndex == thisFactionIndex && game != NULL) {
// Player is an Observer
if(thisTeamIndex == GameConstants::maxPlayers -1 + fpt_Observer) {
ret = true;
@ -2249,14 +2275,10 @@ void World::computeFow(int factionIdxToTick) {
}
//compute texture
//printf("Masterserver = %d\n",game->isMasterserverMode());
//if(fogOfWar == true && game->isMasterserverMode() == false) {
if(fogOfWar == true) {
for(int i=0; i<getFactionCount(); ++i) {
Faction *faction= getFaction(i);
if(faction->getTeam() == thisTeamIndex) {
//if(thisTeamIndex == GameConstants::maxPlayers + fpt_Observer) {
for(int j=0; j<faction->getUnitCount(); ++j){
const Unit *unit= faction->getUnit(j);
if(unit->isOperative()){
@ -2268,7 +2290,7 @@ void World::computeFow(int factionIdxToTick) {
const Vec2i &surfPos = cellList.surfPosList[k];
const float &alpha = cellList.alphaList[k];
minimap.incFowTextureAlphaSurface(surfPos, alpha);
minimap.incFowTextureAlphaSurface(surfPos, alpha, true);
}
}
else {
@ -2277,69 +2299,9 @@ void World::computeFow(int factionIdxToTick) {
const Vec2i &surfPos = cellList.surfPosList[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());
}
}
}
GameSettings * World::getGameSettingsPtr() {
@ -2416,7 +2377,6 @@ string World::getExploredCellsLookupItemCacheStats() {
int exploredCellCount = 0;
int visibleCellCount = 0;
//std::map<Vec2i, std::map<int, ExploredCellsLookupItem > > ExploredCellsLookupItemCache;
for(std::map<Vec2i, std::map<int, ExploredCellsLookupItem > >::iterator iterMap1 = ExploredCellsLookupItemCache.begin();
iterMap1 != ExploredCellsLookupItemCache.end(); ++iterMap1) {
posCount++;
@ -2449,19 +2409,6 @@ string World::getFowAlphaCellsLookupItemCacheStats() {
int surfPosCount = 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) {
Faction *faction= getFaction(i);
if(faction->getTeam() == thisTeamIndex) {

View File

@ -125,6 +125,8 @@ private:
bool fogOfWar;
int fogOfWarSmoothingFrameSkip;
bool fogOfWarSmoothing;
int fogOfWarSkillTypeValue;
Game *game;
Chrono chronoPerfTimer;
bool perfTimerEnabled;
@ -145,6 +147,9 @@ private:
MasterSlaveThreadController masterController;
bool originalGameFogOfWar;
std::map<int,std::pair<const Unit *,const FogOfWarSkillType *> > mapFogOfWarUnitList;
public:
World();
~World();
@ -152,6 +157,9 @@ public:
void end(); //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
inline int getMaxPlayers() const {return map.getMaxPlayers();}
inline int getThisFactionIndex() const {return thisFactionIndex;}
@ -290,7 +298,7 @@ public:
bool canTickWorld() const;
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; }