- added a backtrace for gcc compiled binary when we get a runtime error.

- added more out of synch checks and better error handling
This commit is contained in:
Mark Vejvoda 2011-01-02 00:39:13 +00:00
parent 67be9b7b40
commit 896b1c308c
21 changed files with 940 additions and 648 deletions

View File

@ -32,7 +32,7 @@ IF(CMAKE_COMPILER_IS_GNUCXX OR MINGW)
# Default compiler flags
#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s") ## Strip binary
ADD_DEFINITIONS("-fno-strict-aliasing -frounding-math -fsignaling-nans -mfpmath=sse -msse")
ADD_DEFINITIONS("-fno-strict-aliasing -frounding-math -fsignaling-nans -mfpmath=sse -msse -rdynamic")
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
# Debug compiler flags

View File

@ -3,9 +3,9 @@
//
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
@ -62,14 +62,14 @@ AiInterface::AiInterface(Game &game, int factionIndex, int teamIndex, int useSta
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
// ==================== main ====================
// ==================== main ====================
void AiInterface::update() {
timer++;
ai.update();
}
// ==================== misc ====================
// ==================== misc ====================
void AiInterface::printLog(int logLevel, const string &s){
if(this->logLevel>=logLevel){
@ -82,7 +82,7 @@ void AiInterface::printLog(int logLevel, const string &s){
}
fprintf(f, "%s\n", logString.c_str());
fclose(f);
//redirect to console
if(redir) {
console->addLine(logString);
@ -90,7 +90,7 @@ void AiInterface::printLog(int logLevel, const string &s){
}
}
// ==================== interaction ====================
// ==================== interaction ====================
Faction *AiInterface::getMyFaction() {
return world->getFaction(factionIndex);
@ -224,7 +224,7 @@ CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *command
}
}
CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *commandType, const Vec2i &pos, const UnitType *ut){
CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *commandType, const Vec2i &pos, const UnitType *ut) {
assert(this->gameSettings != NULL);
const Unit *unit = getMyUnit(unitIndex);
@ -328,7 +328,7 @@ CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *command
}
}
// ==================== get data ====================
// ==================== get data ====================
int AiInterface::getMapMaxPlayers(){
return world->getMaxPlayers();
@ -360,10 +360,10 @@ int AiInterface::onSightUnitCount(){
for(int i=0; i<world->getFactionCount(); ++i){
for(int j=0; j<world->getFaction(i)->getUnitCount(); ++j){
SurfaceCell *sc= map->getSurfaceCell(Map::toSurfCoords(world->getFaction(i)->getUnit(j)->getPos()));
if(sc->isVisible(teamIndex)){
count++;
if(sc->isVisible(teamIndex)){
count++;
}
}
}
}
return count;
}
@ -383,7 +383,7 @@ const Unit *AiInterface::getMyUnit(int unitIndex){
}
const Unit *AiInterface::getOnSightUnit(int unitIndex){
int count=0;
Map *map= world->getMap();

View File

@ -3,9 +3,9 @@
//
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#include "ai_rule.h"
@ -26,7 +26,7 @@ namespace Glest{ namespace Game{
// class AiRule
// =====================================================
AiRule::AiRule(Ai *ai){
AiRule::AiRule(Ai *ai){
this->ai= ai;
}
@ -34,7 +34,7 @@ AiRule::AiRule(Ai *ai){
// class AiRuleWorkerHarvest
// =====================================================
AiRuleWorkerHarvest::AiRuleWorkerHarvest(Ai *ai):
AiRuleWorkerHarvest::AiRuleWorkerHarvest(Ai *ai):
AiRule(ai)
{
stoppedWorkerIndex= -1;
@ -52,7 +52,7 @@ void AiRuleWorkerHarvest::execute(){
// class AiRuleRefreshHarvester
// =====================================================
AiRuleRefreshHarvester::AiRuleRefreshHarvester(Ai *ai):
AiRuleRefreshHarvester::AiRuleRefreshHarvester(Ai *ai):
AiRule(ai)
{
workerIndex= -1;
@ -70,7 +70,7 @@ void AiRuleRefreshHarvester::execute(){
// class AiRuleScoutPatrol
// =====================================================
AiRuleScoutPatrol::AiRuleScoutPatrol(Ai *ai):
AiRuleScoutPatrol::AiRuleScoutPatrol(Ai *ai):
AiRule(ai)
{
}
@ -86,7 +86,7 @@ void AiRuleScoutPatrol::execute(){
// class AiRuleRepair
// =====================================================
AiRuleRepair::AiRuleRepair(Ai *ai):
AiRuleRepair::AiRuleRepair(Ai *ai):
AiRule(ai)
{
}
@ -108,7 +108,7 @@ bool AiRuleRepair::test(){
void AiRuleRepair::execute() {
AiInterface *aiInterface= ai->getAiInterface();
const Unit *damagedUnit= aiInterface->getMyUnit(damagedUnitIndex);
//find a repairer and issue command
/*
if(damagedUnit != NULL) {
@ -140,7 +140,7 @@ void AiRuleRepair::execute() {
if(rct->isRepairableUnitType(damagedUnit->getType())){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
aiInterface->giveCommand(i, rct, damagedUnit->getPos());
aiInterface->giveCommand(i, rct, damagedUnit->getPos());
aiInterface->printLog(3, "Repairing order issued");
return;
}
@ -152,7 +152,7 @@ void AiRuleRepair::execute() {
// class AiRuleReturnBase
// =====================================================
AiRuleReturnBase::AiRuleReturnBase(Ai *ai):
AiRuleReturnBase::AiRuleReturnBase(Ai *ai):
AiRule(ai)
{
stoppedUnitIndex= -1;
@ -170,13 +170,13 @@ void AiRuleReturnBase::execute(){
// class AiRuleMassiveAttack
// =====================================================
AiRuleMassiveAttack::AiRuleMassiveAttack(Ai *ai):
AiRuleMassiveAttack::AiRuleMassiveAttack(Ai *ai):
AiRule(ai)
{
}
bool AiRuleMassiveAttack::test(){
if(ai->isStableBase()){
ultraAttack= false;
return ai->beingAttacked(attackPos, field, INT_MAX);
@ -184,7 +184,7 @@ bool AiRuleMassiveAttack::test(){
else{
ultraAttack= true;
return ai->beingAttacked(attackPos, field, baseRadius);
}
}
}
void AiRuleMassiveAttack::execute(){
@ -228,14 +228,14 @@ void AiRuleAddTasks::execute(){
if(workerCount<10) ai->addTask(new ProduceTask(ucWorker));
if(workerRatio<0.20) ai->addTask(new ProduceTask(ucWorker));
if(workerRatio<0.30) ai->addTask(new ProduceTask(ucWorker));
//warriors
if(warriorCount<10) ai->addTask(new ProduceTask(ucWarrior));
if(warriorRatio<0.20) ai->addTask(new ProduceTask(ucWarrior));
if(warriorRatio<0.30) ai->addTask(new ProduceTask(ucWarrior));
if(workerCount>=10) ai->addTask(new ProduceTask(ucWarrior));
if(workerCount>=15) ai->addTask(new ProduceTask(ucWarrior));
if(warriorCount<ai->minWarriors+2)
if(workerCount>=15) ai->addTask(new ProduceTask(ucWarrior));
if(warriorCount<ai->minWarriors+2)
{
ai->addTask(new ProduceTask(ucWarrior));
if( buildingCount>9 )
@ -249,7 +249,7 @@ void AiRuleAddTasks::execute(){
ai->addTask(new ProduceTask(ucWarrior));
}
}
//buildings
if(buildingCount<6 || buildingRatio<0.20) ai->addTask(new BuildTask());
if(buildingCount<10 && workerCount>12) ai->addTask(new BuildTask());
@ -265,18 +265,18 @@ void AiRuleAddTasks::execute(){
//workers
if(workerCount<buildingCount+2) ai->addTask(new ProduceTask(ucWorker));
if(workerCount>5 && workerRatio<0.20) ai->addTask(new ProduceTask(ucWorker));
//warriors
if(warriorCount<10) ai->addTask(new ProduceTask(ucWarrior));
if(warriorRatio<0.20) ai->addTask(new ProduceTask(ucWarrior));
if(warriorRatio<0.30) ai->addTask(new ProduceTask(ucWarrior));
if(workerCount>=10) ai->addTask(new ProduceTask(ucWarrior));
if(workerCount>=15) ai->addTask(new ProduceTask(ucWarrior));
if(workerCount>=15) ai->addTask(new ProduceTask(ucWarrior));
//buildings
if(buildingCount<6 || buildingRatio<0.20) ai->addTask(new BuildTask());
if(buildingCount<10 && ai->isStableBase()) ai->addTask(new BuildTask());
//upgrades
if(upgradeCount==0 && workerCount>6) ai->addTask(new UpgradeTask());
if(upgradeCount==1 && workerCount>7) ai->addTask(new UpgradeTask());
@ -290,18 +290,18 @@ void AiRuleAddTasks::execute(){
if(workerCount<10) ai->addTask(new ProduceTask(ucWorker));
if(workerRatio<0.20) ai->addTask(new ProduceTask(ucWorker));
if(workerRatio<0.30) ai->addTask(new ProduceTask(ucWorker));
//warriors
if(warriorCount<10) ai->addTask(new ProduceTask(ucWarrior));
if(warriorRatio<0.20) ai->addTask(new ProduceTask(ucWarrior));
if(warriorRatio<0.30) ai->addTask(new ProduceTask(ucWarrior));
if(workerCount>=10) ai->addTask(new ProduceTask(ucWarrior));
if(workerCount>=15) ai->addTask(new ProduceTask(ucWarrior));
if(workerCount>=15) ai->addTask(new ProduceTask(ucWarrior));
//buildings
if(buildingCount<6 || buildingRatio<0.20) ai->addTask(new BuildTask());
if(buildingCount<10 && workerCount>12) ai->addTask(new BuildTask());
//upgrades
if(upgradeCount==0 && workerCount>5) ai->addTask(new UpgradeTask());
if(upgradeCount==1 && workerCount>10) ai->addTask(new UpgradeTask());
@ -326,13 +326,13 @@ bool AiRuleBuildOneFarm::test(){
//for all units
for(int i=0; i<aiInterface->getMyFactionType()->getUnitTypeCount(); ++i){
const UnitType *ut= aiInterface->getMyFactionType()->getUnitType(i);
//for all production commands
for(int j=0; j<ut->getCommandTypeCount(); ++j){
const CommandType *ct= ut->getCommandType(j);
if(ct->getClass()==ccProduce){
const UnitType *producedType= static_cast<const ProduceCommandType*>(ct)->getProducedUnit();
//for all resources
for(int k=0; k<producedType->getCostCount(); ++k){
const Resource *r= producedType->getCost(k);
@ -370,22 +370,22 @@ bool AiRuleProduceResourceProducer::test(){
//consumables first
for(int i=0; i<aiInterface->getTechTree()->getResourceTypeCount(); ++i){
rt= aiInterface->getTechTree()->getResourceType(i);
const Resource *r= aiInterface->getResource(rt);
const Resource *r= aiInterface->getResource(rt);
if(rt->getClass()==rcConsumable && r->getBalance()<0){
interval= longInterval;
return true;
}
}
//statics second
for(int i=0; i<aiInterface->getTechTree()->getResourceTypeCount(); ++i){
rt= aiInterface->getTechTree()->getResourceType(i);
const Resource *r= aiInterface->getResource(rt);
const Resource *r= aiInterface->getResource(rt);
if(rt->getClass()==rcStatic && r->getAmount()<minStaticResources){
interval= longInterval;
return true;
}
}
@ -421,7 +421,7 @@ bool AiRuleProduce::test(){
void AiRuleProduce::execute(){
if(produceTask!=NULL){
//generic produce task, produce random unit that has the skill or produces the resource
if(produceTask->getUnitType()==NULL){
produceGeneric(produceTask);
@ -438,21 +438,21 @@ void AiRuleProduce::execute(){
}
void AiRuleProduce::produceGeneric(const ProduceTask *pt){
typedef vector<const UnitType*> UnitTypes;
typedef vector<const UnitType*> UnitTypes;
UnitTypes ableUnits;
AiInterface *aiInterface= ai->getAiInterface();
//for each unit, produce it if possible
for(int i=0; i<aiInterface->getMyUnitCount(); ++i){
//for each command
const UnitType *ut= aiInterface->getMyUnit(i)->getType();
for(int j=0; j<ut->getCommandTypeCount(); ++j){
const CommandType *ct= ut->getCommandType(j);
//if the command is produce
if(ct->getClass()==ccProduce || ct->getClass()==ccMorph){
const UnitType *producedUnit= static_cast<const UnitType*>(ct->getProduced());
bool produceIt= false;
@ -502,12 +502,12 @@ void AiRuleProduce::produceGeneric(const ProduceTask *pt){
}
void AiRuleProduce::produceSpecific(const ProduceTask *pt){
AiInterface *aiInterface= ai->getAiInterface();
//if unit meets requirements
if(aiInterface->reqsOk(pt->getUnitType())){
//if unit doesnt meet resources retry
if(!aiInterface->checkCosts(pt->getUnitType())){
ai->retryTask(pt);
@ -523,16 +523,16 @@ void AiRuleProduce::produceSpecific(const ProduceTask *pt){
//for each unit
for(int i=0; i<aiInterface->getMyUnitCount(); ++i){
//for each command
const UnitType *ut= aiInterface->getMyUnit(i)->getType();
for(int j=0; j<ut->getCommandTypeCount(); ++j){
const CommandType *ct= ut->getCommandType(j);
//if the command is produce
if(ct->getClass()==ccProduce || ct->getClass()==ccMorph){
const UnitType *producedUnit= static_cast<const UnitType*>(ct->getProduced());
//if units match
if(producedUnit == pt->getUnitType()){
if(aiInterface->reqsOk(ct)){
@ -540,7 +540,7 @@ void AiRuleProduce::produceSpecific(const ProduceTask *pt){
producers.push_back(i);
producersDefaultCommandType[i].push_back(ct);
}
}
}
}
}
}
@ -563,7 +563,7 @@ void AiRuleProduce::produceSpecific(const ProduceTask *pt){
prIndex = (i - producers.size());
}
currentProducerIndex=producers[prIndex];
if(currentProducerIndex >= aiInterface->getMyUnitCount()) {
char szBuf[1024]="";
printf("In [%s::%s Line: %d] currentProducerIndex >= aiInterface->getMyUnitCount(), currentProducerIndex = %d, aiInterface->getMyUnitCount() = %d, i = %d,producers.size() = %lu\n",__FILE__,__FUNCTION__,__LINE__,currentProducerIndex,aiInterface->getMyUnitCount(),i,(unsigned long)producers.size());
@ -594,7 +594,7 @@ void AiRuleProduce::produceSpecific(const ProduceTask *pt){
{
// maybe we need another producer of this kind if possible!
if(aiInterface->reqsOk(aiInterface->getMyUnit(bestIndex)->getType()))
{
{
if(ai->getCountOfClass(ucBuilding)>5)
ai->addTask(new BuildTask(aiInterface->getMyUnit(bestIndex)->getType()));
}
@ -610,13 +610,13 @@ void AiRuleProduce::produceSpecific(const ProduceTask *pt){
//if the command is produce
if(ct->getClass()==ccProduce)
{
const UnitType *unitType= static_cast<const UnitType*>(ct->getProduced());
const UnitType *unitType= static_cast<const UnitType*>(ct->getProduced());
if(unitType->hasSkillClass(scAttack) && !unitType->hasCommandClass(ccHarvest) && aiInterface->reqsOk(ct))
{//this can produce a warrior
backupProducers.push_back(i);
}
}
}
}
}
}
if(!backupProducers.empty())
{
@ -626,7 +626,7 @@ void AiRuleProduce::produceSpecific(const ProduceTask *pt){
int bestIndex=-1;
int currentCommandCount=0;
for(unsigned int i=randomstart; i<backupProducers.size()+randomstart; i++)
{
{
int prIndex = i;
if(i >= backupProducers.size()) {
prIndex = (i - backupProducers.size());
@ -665,15 +665,15 @@ void AiRuleProduce::produceSpecific(const ProduceTask *pt){
const UnitType *ut=aiInterface->getMyUnit(bestIndex)->getType();
for(int j=0; j<ut->getCommandTypeCount(); ++j){
const CommandType *ct= ut->getCommandType(j);
//if the command is produce
if(ct->getClass()==ccProduce)
{
const UnitType *unitType= static_cast<const UnitType*>(ct->getProduced());
const UnitType *unitType= static_cast<const UnitType*>(ct->getProduced());
if(unitType->hasSkillClass(scAttack) && !unitType->hasCommandClass(ccHarvest) && aiInterface->reqsOk(ct))
{//this can produce a warrior
productionCommandIndexes.push_back(j);
}
}
}
}
int commandIndex=productionCommandIndexes[ai->getRandom()->randRange(0, productionCommandIndexes.size()-1)];
@ -696,7 +696,7 @@ void AiRuleProduce::produceSpecific(const ProduceTask *pt){
}
}
else
{
{
if(currentCommandCount==0)
{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -771,7 +771,7 @@ bool AiRuleBuild::test(){
void AiRuleBuild::execute(){
if(buildTask!=NULL){
//generic build task, build random building that can be built
@ -789,29 +789,29 @@ void AiRuleBuild::execute(){
}
void AiRuleBuild::buildGeneric(const BuildTask *bt){
//find buildings that can be built
AiInterface *aiInterface= ai->getAiInterface();
typedef vector<const UnitType*> UnitTypes;
typedef vector<const UnitType*> UnitTypes;
UnitTypes buildings;
//for each unit
for(int i=0; i<aiInterface->getMyUnitCount(); ++i){
//for each command
const UnitType *ut= aiInterface->getMyUnit(i)->getType();
for(int j=0; j<ut->getCommandTypeCount(); ++j){
const CommandType *ct= ut->getCommandType(j);
//if the command is build
if(ct->getClass()==ccBuild){
const BuildCommandType *bct= static_cast<const BuildCommandType*>(ct);
//for each building
for(int k=0; k<bct->getBuildingCount(); ++k){
const UnitType *building= bct->getBuilding(k);
const UnitType *building= bct->getBuilding(k);
if(aiInterface->reqsOk(bct) && aiInterface->reqsOk(building)){
//if any building, or produces resource
const ResourceType *rt= bt->getResourceType();
const Resource *cost= building->getCost(rt);
@ -829,13 +829,13 @@ void AiRuleBuild::buildGeneric(const BuildTask *bt){
}
void AiRuleBuild::buildBestBuilding(const vector<const UnitType*> &buildings){
if(!buildings.empty()){
//build the least built building
bool buildingFound= false;
for(int i=0; i<10 && !buildingFound; ++i){
if(i>0){
//Defensive buildings have priority
@ -882,13 +882,13 @@ void AiRuleBuild::buildBestBuilding(const vector<const UnitType*> &buildings){
}
}
void AiRuleBuild::buildSpecific(const BuildTask *bt){
void AiRuleBuild::buildSpecific(const BuildTask *bt) {
AiInterface *aiInterface= ai->getAiInterface();
//if reqs ok
if(aiInterface->reqsOk(bt->getUnitType())){
if(aiInterface->reqsOk(bt->getUnitType())) {
//retry if not enough resources
if(!aiInterface->checkCosts(bt->getUnitType())){
if(aiInterface->checkCosts(bt->getUnitType()) == false) {
ai->retryTask(bt);
return;
}
@ -898,30 +898,30 @@ void AiRuleBuild::buildSpecific(const BuildTask *bt){
// then a list of build commandtypes for each unit
map<int,vector<const BuildCommandType *> > buildersDefaultCommandType;
const BuildCommandType *defBct= NULL;
//for each unit
for(int i=0; i<aiInterface->getMyUnitCount(); ++i){
for(int i = 0; i < aiInterface->getMyUnitCount(); ++i) {
//if the unit is not going to build
const Unit *u= aiInterface->getMyUnit(i);
if(!u->anyCommand() || u->getCurrCommand()->getCommandType()->getClass()!=ccBuild){
const Unit *u = aiInterface->getMyUnit(i);
if(u->anyCommand() == false || u->getCurrCommand()->getCommandType()->getClass() != ccBuild) {
//for each command
const UnitType *ut= aiInterface->getMyUnit(i)->getType();
for(int j=0; j<ut->getCommandTypeCount(); ++j){
for(int j = 0; j < ut->getCommandTypeCount(); ++j) {
const CommandType *ct= ut->getCommandType(j);
//if the command is build
if(ct->getClass()==ccBuild){
if(ct->getClass() == ccBuild) {
const BuildCommandType *bct= static_cast<const BuildCommandType*>(ct);
//for each building
for(int k=0; k<bct->getBuildingCount(); ++k){
const UnitType *building= bct->getBuilding(k);
for(int k = 0; k < bct->getBuildingCount(); ++k) {
const UnitType *building= bct->getBuilding(k);
//if building match
if(bt->getUnitType()==building){
if(aiInterface->reqsOk(bct)){
if(bt->getUnitType() == building) {
if(aiInterface->reqsOk(bct)) {
builders.push_back(i);
buildersDefaultCommandType[i].push_back(bct);
defBct= bct;
@ -934,15 +934,14 @@ void AiRuleBuild::buildSpecific(const BuildTask *bt){
}
//use random builder to build
if(!builders.empty()){
if(builders.empty() == false) {
int bIndex = ai->getRandom()->randRange(0, builders.size()-1);
int builderIndex= builders[bIndex];
Vec2i pos;
Vec2i pos;
Vec2i searchPos= bt->getForcePos()? bt->getPos(): ai->getRandomHomePosition();
//if free pos give command, else retry
if(ai->findPosForBuilding(bt->getUnitType(), searchPos, pos)){
if(ai->findPosForBuilding(bt->getUnitType(), searchPos, pos)) {
defBct = NULL;
if(buildersDefaultCommandType.find(builderIndex) != buildersDefaultCommandType.end()) {
//defBct = buildersDefaultCommandType[builderIndex];
@ -952,13 +951,12 @@ void AiRuleBuild::buildSpecific(const BuildTask *bt){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] bestCommandTypeIndex = %d, bestCommandTypeCount = %d\n",__FILE__,__FUNCTION__,__LINE__,bestCommandTypeIndex,bestCommandTypeCount);
defBct = buildersDefaultCommandType[builderIndex][bestCommandTypeIndex];
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] builderIndex = %d, bIndex = %d, defBct = %p\n",__FILE__,__FUNCTION__,__LINE__,builderIndex,bIndex,defBct);
aiInterface->giveCommand(builderIndex, defBct, pos, bt->getUnitType());
}
else{
else {
ai->retryTask(bt);
return;
}
@ -1030,21 +1028,21 @@ void AiRuleUpgrade::execute(){
}
void AiRuleUpgrade::upgradeGeneric(const UpgradeTask *upgt){
typedef vector<const UpgradeType*> UpgradeTypes;
typedef vector<const UpgradeType*> UpgradeTypes;
AiInterface *aiInterface= ai->getAiInterface();
//find upgrades that can be upgraded
UpgradeTypes upgrades;
//for each upgrade, upgrade it if possible
for(int i=0; i<aiInterface->getMyUnitCount(); ++i){
//for each command
const UnitType *ut= aiInterface->getMyUnit(i)->getType();
for(int j=0; j<ut->getCommandTypeCount(); ++j){
const CommandType *ct= ut->getCommandType(j);
//if the command is upgrade
if(ct->getClass()==ccUpgrade){
const UpgradeCommandType *upgct= static_cast<const UpgradeCommandType*>(ct);
@ -1063,7 +1061,7 @@ void AiRuleUpgrade::upgradeGeneric(const UpgradeTask *upgt){
}
void AiRuleUpgrade::upgradeSpecific(const UpgradeTask *upgt){
AiInterface *aiInterface= ai->getAiInterface();
//if reqs ok
@ -1077,24 +1075,24 @@ void AiRuleUpgrade::upgradeSpecific(const UpgradeTask *upgt){
//for each unit
for(int i=0; i<aiInterface->getMyUnitCount(); ++i){
//for each command
const UnitType *ut= aiInterface->getMyUnit(i)->getType();
for(int j=0; j<ut->getCommandTypeCount(); ++j){
const CommandType *ct= ut->getCommandType(j);
//if the command is upgrade
if(ct->getClass()==ccUpgrade){
const UpgradeCommandType *uct= static_cast<const UpgradeCommandType*>(ct);
const UpgradeType *producedUpgrade= uct->getProducedUpgrade();
//if upgrades match
if(producedUpgrade == upgt->getUpgradeType()){
if(aiInterface->reqsOk(uct)){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
aiInterface->giveCommand(i, uct);
}
}
}
}
}
}
@ -1149,7 +1147,7 @@ bool AiRuleExpand::test() {
}
}
}
return false;
}
@ -1158,4 +1156,4 @@ void AiRuleExpand::execute(){
ai->addPriorityTask(new BuildTask(storeType, expandPos));
}
}}//end namespace
}}//end namespace

View File

@ -495,21 +495,38 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const {
throw runtime_error(szBuf);
}
ct= unit->getType()->findCommandTypeById(networkCommand->getCommandTypeId());
if(unit->getFaction()->getIndex() != networkCommand->getUnitFactionIndex()) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s::%s Line: %d]\nUnit / Faction mismatch for network command = [%s]\n%s\nfor unit = %d\n[%s]\n[%s]\nactual local factionIndex = %d.\nGame out of synch.",
__FILE__,__FUNCTION__,__LINE__,networkCommand->toString().c_str(),unit->getType()->getCommandTypeListDesc().c_str(),unit->getId(), unit->getFullName().c_str(),unit->getDesc().c_str(),unit->getFaction()->getIndex());
SystemFlags::OutputDebug(SystemFlags::debugError,"%s\n",szBuf);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",szBuf);
std::string worldLog = world->DumpWorldToLog();
//std::string sError = "worldLog = " + worldLog + " " + string(szBuf);
std::string sError = "Error [#1]: Game is out of sync, please check log files for details.";
std::string sError = "Error [#1]: Game is out of sync (Unit / Faction mismatch)\nplease check log files for details.";
throw runtime_error(sError);
}
else if(networkCommand->getUnitTypeId() >= 0 &&
unit->getType()->getId() != networkCommand->getUnitTypeId() &&
ct->getClass() != ccBuild) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s::%s Line: %d]\nUnit / Type mismatch for network command = [%s]\n%s\nfor unit = %d\n[%s]\n[%s]\nactual local factionIndex = %d.\nactual local unitTypeId = %d.\nGame out of synch.",
__FILE__,__FUNCTION__,__LINE__,networkCommand->toString().c_str(),unit->getType()->getCommandTypeListDesc().c_str(),unit->getId(), unit->getFullName().c_str(),unit->getDesc().c_str(),unit->getFaction()->getIndex(),unit->getType()->getId());
SystemFlags::OutputDebug(SystemFlags::debugError,"%s\n",szBuf);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",szBuf);
std::string worldLog = world->DumpWorldToLog();
//std::string sError = "worldLog = " + worldLog + " " + string(szBuf);
std::string sError = "Error [#2]: Game is out of sync (unit type mismatch)\nplease check log files for details.";
throw runtime_error(sError);
}
const UnitType* unitType= world->findUnitTypeById(unit->getFaction()->getType(), networkCommand->getUnitTypeId());
ct= unit->getType()->findCommandTypeById(networkCommand->getCommandTypeId());
// debug test!
//throw runtime_error("Test missing command type!");
@ -544,13 +561,13 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const {
//create command
Command *command= NULL;
if(unitType!=NULL){
if(unitType != NULL) {
command= new Command(ct, networkCommand->getPosition(), unitType, facing);
}
else if(target==NULL){
else if(target == NULL) {
command= new Command(ct, networkCommand->getPosition());
}
else{
else {
command= new Command(ct, target);
}

View File

@ -140,6 +140,8 @@ Game::~Game() {
Unit::setGame(NULL);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ==== END GAME ==== getCurrentPixelByteCount() = %llu\n",__FILE__,__FUNCTION__,__LINE__,(long long unsigned int)renderer.getCurrentPixelByteCount());
SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"==== END GAME ====\n");
//this->program->reInitGl();
//renderer.reinitAll();
}
@ -649,6 +651,7 @@ void Game::init(bool initForPreviewOnly)
SystemFlags::OutputDebug(SystemFlags::debugPathFinder,"PathFinderType: %s\n", (getGameSettings()->getPathFinderType() ? "RoutePlanner" : "PathFinder"));
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ==== START GAME ==== getCurrentPixelByteCount() = %llu\n",__FILE__,__FUNCTION__,__LINE__,(long long unsigned int)renderer.getCurrentPixelByteCount());
SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"==== START GAME ====\n");
}
// ==================== update ====================
@ -663,6 +666,16 @@ void Game::update() {
// a) Updates non dependent on speed
if(NetworkManager::getInstance().getGameNetworkInterface() != NULL &&
NetworkManager::getInstance().getGameNetworkInterface()->getQuit() &&
mainMessageBox.getEnabled() == false &&
errorMessageBox.getEnabled() == false) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//quitGame();
quitTriggeredIndicator = true;
return;
}
//misc
updateFps++;
mouse2d= (mouse2d+1) % Renderer::maxMouse2dAnim;
@ -783,7 +796,9 @@ void Game::update() {
if(networkManager.getGameNetworkInterface() != NULL) {
networkManager.getGameNetworkInterface()->quitGame(true);
}
ErrorDisplayMessage(ex.what(),true);
if(errorMessageBox.getEnabled() == false) {
ErrorDisplayMessage(ex.what(),true);
}
}
}
@ -1407,6 +1422,10 @@ void Game::keyPress(char c){
Stats Game::quitGame() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled == true) {
world.DumpWorldToLog();
}
//Stats stats = *(world.getStats());
Stats endStats;

View File

@ -35,6 +35,12 @@
#include "sound_renderer.h"
#include "font_gl.h"
#include "cache_manager.h"
// For gcc backtrace on crash!
#ifdef __GNUC__
#include <execinfo.h>
#include <cxxabi.h>
#endif
#ifdef WIN32
#if defined(__WIN32__) && !defined(__GNUC__)
@ -70,6 +76,7 @@ using namespace Shared::Graphics::Gl;
namespace Glest{ namespace Game{
bool gameInitialized = false;
static char *application_binary=NULL;
const char *GAME_ARGS[] = {
"--help",
@ -190,19 +197,223 @@ public:
message(msg.c_str());
}
#ifdef __GNUC__
static int getFileAndLine(void *address, char *file, size_t flen) {
int line=-1;
static char buf[256]="";
char *p=NULL;
// prepare command to be executed
// our program need to be passed after the -e parameter
//sprintf (buf, "/usr/bin/addr2line -C -e ./a.out -f -i %lx", addr);
sprintf (buf, "addr2line -C -e %s -f -i %p",application_binary,address);
FILE* f = popen (buf, "r");
if (f == NULL) {
perror (buf);
return 0;
}
// get function name
char *ret = fgets (buf, 256, f);
// get file and line
ret = fgets (buf, 256, f);
if (buf[0] != '?') {
int l;
char *p = buf;
// file name is until ':'
while (*p != ':')
{
p++;
}
*p++ = 0;
// after file name follows line number
strcpy (file , buf);
sscanf (p,"%d", &line);
}
else {
strcpy (file,"unkown");
line = 0;
}
pclose(f);
return line;
}
static void * getStackAddress(const unsigned int index) {
//printf("\nSTART index = %d\n",index);
void *lineAddress = NULL;
if(index == 0) {
lineAddress = __builtin_return_address(0);
}
if(index == 1) {
lineAddress = __builtin_return_address(1);
}
if(index == 2) {
lineAddress = __builtin_return_address(2);
}
if(index == 3) {
lineAddress = __builtin_return_address(3);
}
if(index == 4) {
lineAddress = __builtin_return_address(4);
}
if(index == 5) {
lineAddress = __builtin_return_address(5);
}
if(index == 6) {
lineAddress = __builtin_return_address(6);
}
if(index == 7) {
lineAddress = __builtin_return_address(7);
}
if(index == 8) {
lineAddress = __builtin_return_address(8);
}
if(index == 9) {
lineAddress = __builtin_return_address(9);
}
if(index == 10) {
lineAddress = __builtin_return_address(10);
}
if(index == 11) {
lineAddress = __builtin_return_address(11);
}
if(index == 12) {
lineAddress = __builtin_return_address(12);
}
if(index == 13) {
lineAddress = __builtin_return_address(13);
}
if(index == 14) {
lineAddress = __builtin_return_address(14);
}
if(index == 15) {
lineAddress = __builtin_return_address(15);
}
//printf("\nEND index = %d lineAddress [%p]\n",index,lineAddress);
return lineAddress;
}
#endif
static void handleRuntimeError(const char *msg) {
Program *program = Program::getInstance();
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] [%s] gameInitialized = %d, program = %p\n",__FILE__,__FUNCTION__,__LINE__,msg,gameInitialized,program);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] [%s] gameInitialized = %d, program = %p\n",__FILE__,__FUNCTION__,__LINE__,msg,gameInitialized,program);
string errMsg = (msg != NULL ? msg : "null");
#ifdef __GNUC__
errMsg += "\nStack Trace:\n";
//errMsg += "To find line #'s use:\n";
//errMsg += "readelf --debug-dump=decodedline %s | egrep 0xaddress-of-stack\n";
const size_t max_depth = 15;
void *stack_addrs[max_depth];
size_t stack_depth = backtrace(stack_addrs, max_depth);
char **stack_strings = backtrace_symbols(stack_addrs, stack_depth);
//for (size_t i = 1; i < stack_depth; i++) {
// errMsg += string(stack_strings[i]) + "\n";
//}
char szBuf[4096]="";
for(size_t i = 1; i < stack_depth; i++) {
const unsigned int stackIndex = i-1;
void *lineAddress = getStackAddress(stackIndex);
size_t sz = 1024; // just a guess, template names will go much wider
char *function = static_cast<char *>(malloc(sz));
char *begin = 0;
char *end = 0;
// find the parentheses and address offset surrounding the mangled name
for (char *j = stack_strings[i]; *j; ++j) {
if (*j == '(') {
begin = j;
}
else if (*j == '+') {
end = j;
}
}
if (begin && end) {
*begin++ = '\0';
*end = '\0';
// found our mangled name, now in [begin, end)
int status;
char *ret = abi::__cxa_demangle(begin, function, &sz, &status);
if (ret) {
// return value may be a realloc() of the input
function = ret;
}
else {
// demangling failed, just pretend it's a C function with no args
strncpy(function, begin, sz);
strncat(function, "()", sz);
function[sz-1] = '\0';
}
//fprintf(out, " %s:%s\n", stack.strings[i], function);
sprintf(szBuf,"%s:%s address [%p]",stack_strings[i],function,lineAddress);
}
else {
// didn't find the mangled name, just print the whole line
//fprintf(out, " %s\n", stack.strings[i]);
sprintf(szBuf,"%s address [%p]",stack_strings[i],lineAddress);
}
errMsg += string(szBuf);
char file[4096]="";
int line = getFileAndLine(lineAddress, file, 4096);
if(line >= 0) {
errMsg += " line: " + intToStr(line);
}
errMsg += "\n";
free(function);
}
free(stack_strings); // malloc()ed by backtrace_symbols
#endif
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] [%s]\n",__FILE__,__FUNCTION__,__LINE__,errMsg.c_str());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] [%s]\n",__FILE__,__FUNCTION__,__LINE__,errMsg.c_str());
if(program && gameInitialized == true) {
//SystemFlags::Close();
program->showMessage(msg);
//SystemFlags::Close();
printf("\nprogram->getState() [%p]\n",program->getState());
if(program->getState() != NULL) {
program->showMessage(errMsg.c_str());
for(;program->isMessageShowing();) {
//program->getState()->render();
Window::handleEvent();
program->loop();
}
}
else {
program->showMessage(errMsg.c_str());
for(;program->isMessageShowing();) {
//program->renderProgramMsgBox();
Window::handleEvent();
program->loop();
}
}
}
else {
string err = "#2 An error ocurred and " + string(GameConstants::application_name) + " will close.\nError msg = [" + (msg != NULL ? string(msg) : string("?")) + "]\n\nPlease report this bug to "+mailString;
string err = "#2 An error ocurred and " +
string(GameConstants::application_name) +
" will close.\nError msg = [" +
errMsg +
"]\n\nPlease report this bug to "+mailString;
#ifdef WIN32
err += string(", attaching the generated ") + getCrashDumpFileName() + string(" file.");
#endif
@ -213,10 +424,7 @@ public:
#ifdef WIN32
runtimeErrorMsg = "";
if(msg != NULL) {
runtimeErrorMsg = msg;
}
runtimeErrorMsg = errMsg;
throw runtimeErrorMsg;
#endif
//SystemFlags::Close();
@ -1277,7 +1485,7 @@ int glestMainWrapper(int argc, char** argv) {
#ifdef WIN32_STACK_TRACE
__try {
#endif
application_binary=argv[0];
return glestMain(argc, argv);
#ifdef WIN32_STACK_TRACE

View File

@ -601,6 +601,10 @@ void Program::restoreDisplaySettings(){
}
}
bool Program::isMessageShowing() {
return msgBox.getEnabled();
}
void Program::showMessage(const char *msg) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] msg [%s]\n",__FILE__,__FUNCTION__,__LINE__,msg);

View File

@ -144,7 +144,8 @@ public:
void loop();
void loopWorker();
void resize(SizeState sizeState);
void showMessage(const char *msg);
void showMessage(const char *msg);
bool isMessageShowing();
//misc
void setState(ProgramState *programState,bool cleanupOldState=true);
@ -164,7 +165,7 @@ public:
void reInitGl();
private:
void setDisplaySettings();
void restoreDisplaySettings();
};

View File

@ -88,8 +88,8 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
}
catch(const std::exception &ex) {
serverInitError = true;
char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
char szBuf[4096]="";
sprintf(szBuf,"In [%s::%s %d] Error detected:\n%s\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
//throw runtime_error(szBuf);!!!
@ -220,7 +220,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
listBoxTileset.init(xoffset+460, mapPos, 150);
listBoxTileset.setItems(results);
srand(time(NULL));
listBoxTileset.setSelectedItemIndex(rand() % listBoxTileset.getItemCount());
listBoxTileset.setSelectedItemIndex(rand() % listBoxTileset.getItemCount());
labelTileset.registerGraphicComponent(containerName,"labelTileset");
labelTileset.init(xoffset+460, mapHeadPos);
@ -444,7 +444,9 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
}
if(results.size() == 0) {
throw runtime_error("(1)There are no factions for the tech tree [" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "]");
//throw runtime_error("(1)There are no factions for the tech tree [" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "]");
showGeneralError=true;
generalErrorToShow = "[#1] There are no factions for the tech tree [" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "]";
}
for(int i=0; i<GameConstants::maxPlayers; ++i){
@ -595,327 +597,338 @@ void MenuStateCustomGame::returnToParentMenu(){
void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
CoreData &coreData= CoreData::getInstance();
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
int oldListBoxMapfilterIndex=listBoxMapFilter.getSelectedItemIndex();
try {
CoreData &coreData= CoreData::getInstance();
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
int oldListBoxMapfilterIndex=listBoxMapFilter.getSelectedItemIndex();
if(mainMessageBox.getEnabled()){
int button= 1;
if(mainMessageBox.mouseClick(x, y, button))
{
soundRenderer.playFx(coreData.getClickSoundA());
if(button==1)
{
mainMessageBox.setEnabled(false);
}
}
}
else if(buttonReturn.mouseClick(x,y) || serverInitError == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(mainMessageBox.getEnabled()){
int button= 1;
if(mainMessageBox.mouseClick(x, y, button))
{
soundRenderer.playFx(coreData.getClickSoundA());
if(button==1)
{
mainMessageBox.setEnabled(false);
}
}
}
else if(buttonReturn.mouseClick(x,y) || serverInitError == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
soundRenderer.playFx(coreData.getClickSoundA());
soundRenderer.playFx(coreData.getClickSoundA());
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
needToBroadcastServerSettings = false;
needToRepublishToMasterserver = false;
safeMutex.ReleaseLock();
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
needToBroadcastServerSettings = false;
needToRepublishToMasterserver = false;
safeMutex.ReleaseLock();
MutexSafeWrapper safeMutexPtr(&publishToMasterserverThreadPtrChangeAccessor);
publishToMasterserverThreadInDeletion = true;
//BaseThread::shutdownAndWait(publishToMasterserverThread);
if(publishToMasterserverThread != NULL &&
publishToMasterserverThread->shutdownAndWait() == true) {
delete publishToMasterserverThread;
publishToMasterserverThread = NULL;
}
MutexSafeWrapper safeMutexPtr(&publishToMasterserverThreadPtrChangeAccessor);
publishToMasterserverThreadInDeletion = true;
//BaseThread::shutdownAndWait(publishToMasterserverThread);
if(publishToMasterserverThread != NULL &&
publishToMasterserverThread->shutdownAndWait() == true) {
delete publishToMasterserverThread;
publishToMasterserverThread = NULL;
}
publishToMasterserverThreadInDeletion = false;
safeMutexPtr.ReleaseLock();
publishToMasterserverThreadInDeletion = false;
safeMutexPtr.ReleaseLock();
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__);
returnToParentMenu();
returnToParentMenu();
}
else if(buttonPlayNow.mouseClick(x,y) && buttonPlayNow.getEnabled()) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
PlayNow();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
else if(buttonRestoreLastSettings.mouseClick(x,y) && buttonRestoreLastSettings.getEnabled()) {
RestoreLastGameSettings();
}
else if(listBoxMap.mouseClick(x, y)){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n", getCurrentMapFile().c_str());
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
loadMapInfo(Map::getMapPath(getCurrentMapFile(),"",false), &mapInfo, true);
labelMapInfo.setText(mapInfo.desc);
updateControlers();
updateNetworkSlots();
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxFogOfWar.mouseClick(x, y)) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxAllowObservers.mouseClick(x, y)) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
reloadFactions(true);
if(hasNetworkGameSettings() == true) {
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxEnableObserverMode.mouseClick(x, y)) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxPathFinderType.mouseClick(x, y)) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if (listBoxAdvanced.mouseClick(x, y)) {
//TODO
}
/*
else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxEnableServerControlledAI.mouseClick(x, y) && listBoxEnableServerControlledAI.getEditable()) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
needToRepublishToMasterserver = true;
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
*/
else if(listBoxTileset.mouseClick(x, y)){
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if(listBoxMapFilter.mouseClick(x, y)){
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
switchToNextMapGroup(listBoxMapFilter.getSelectedItemIndex()-oldListBoxMapfilterIndex);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n", getCurrentMapFile().c_str());
loadMapInfo(Map::getMapPath(getCurrentMapFile()), &mapInfo, true);
labelMapInfo.setText(mapInfo.desc);
updateControlers();
updateNetworkSlots();
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if(listBoxTechTree.mouseClick(x, y)){
reloadFactions(false);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if(listBoxPublishServer.mouseClick(x, y) && listBoxPublishServer.getEditable()) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
needToRepublishToMasterserver = true;
soundRenderer.playFx(coreData.getClickSoundC());
}
/*
else if(listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxNetworkFramePeriod.mouseClick(x, y)){
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
needToRepublishToMasterserver = true;
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
soundRenderer.playFx(coreData.getClickSoundC());
}
*/
else if(listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxNetworkPauseGameForLaggedClients.mouseClick(x, y)){
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
soundRenderer.playFx(coreData.getClickSoundC());
}
else {
for(int i=0; i<mapInfo.players; ++i) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if (listBoxAdvanced.getSelectedItemIndex() == 1) {
// set multiplier
if(listBoxRMultiplier[i].mouseClick(x, y)) {
}
}
//ensure thet only 1 human player is present
if(listBoxControls[i].mouseClick(x, y)) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
//look for human players
int humanIndex1= -1;
int humanIndex2= -1;
for(int j=0; j<GameConstants::maxPlayers; ++j) {
ControlType ct= static_cast<ControlType>(listBoxControls[j].getSelectedItemIndex());
if(ct == ctHuman) {
if(humanIndex1 == -1) {
humanIndex1= j;
}
else {
humanIndex2= j;
}
}
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] humanIndex1 = %d, humanIndex2 = %d\n",__FILE__,__FUNCTION__,__LINE__,humanIndex1,humanIndex2);
//no human
if(humanIndex1 == -1 && humanIndex2 == -1) {
listBoxControls[i].setSelectedItemIndex(ctHuman);
//labelPlayerNames[i].setText("");
//labelPlayerNames[i].setText(getHumanPlayerName());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] i = %d, labelPlayerNames[i].getText() [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,labelPlayerNames[i].getText().c_str());
}
//2 humans
else if(humanIndex1 != -1 && humanIndex2 != -1) {
int closeSlotIndex = (humanIndex1 == i ? humanIndex2: humanIndex1);
int humanSlotIndex = (closeSlotIndex == humanIndex1 ? humanIndex2 : humanIndex1);
string origPlayName = labelPlayerNames[closeSlotIndex].getText();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] closeSlotIndex = %d, origPlayName [%s]\n",__FILE__,__FUNCTION__,__LINE__,closeSlotIndex,origPlayName.c_str());
listBoxControls[closeSlotIndex].setSelectedItemIndex(ctClosed);
//labelPlayerNames[closeSlotIndex].setText("");
labelPlayerNames[humanSlotIndex].setText((origPlayName != "" ? origPlayName : getHumanPlayerName()));
}
updateNetworkSlots();
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true) {
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
updateResourceMultiplier(i);
}
else if(listBoxFactions[i].mouseClick(x, y)) {
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if(listBoxTeams[i].mouseClick(x, y))
{
if(factionFiles[listBoxFactions[i].getSelectedItemIndex()] != formatString(GameConstants::OBSERVER_SLOTNAME)) {
//printf("i = %d factionFiles[listBoxFactions[i].getSelectedItemIndex()] [%s] listBoxTeams[i].getSelectedItemIndex() = %d, lastSelectedTeamIndex[i] = %d\n",i,factionFiles[listBoxFactions[i].getSelectedItemIndex()].c_str(),listBoxTeams[i].getSelectedItemIndex(),lastSelectedTeamIndex[i]);
if(listBoxTeams[i].getSelectedItemIndex() + 1 != (GameConstants::maxPlayers + fpt_Observer)) {
lastSelectedTeamIndex[i] = listBoxTeams[i].getSelectedItemIndex();
}
}
else {
lastSelectedTeamIndex[i] = -1;
}
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);;
}
}
else if(labelPlayerNames[i].mouseClick(x, y)) {
SetActivePlayerNameEditor();
}
}
}
}
else if(buttonPlayNow.mouseClick(x,y) && buttonPlayNow.getEnabled()) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
PlayNow();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
else if(buttonRestoreLastSettings.mouseClick(x,y) && buttonRestoreLastSettings.getEnabled()) {
RestoreLastGameSettings();
}
else if(listBoxMap.mouseClick(x, y)){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n", getCurrentMapFile().c_str());
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
loadMapInfo(Map::getMapPath(getCurrentMapFile(),"",false), &mapInfo, true);
labelMapInfo.setText(mapInfo.desc);
updateControlers();
updateNetworkSlots();
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxFogOfWar.mouseClick(x, y)) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxAllowObservers.mouseClick(x, y)) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
reloadFactions(true);
if(hasNetworkGameSettings() == true) {
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxEnableObserverMode.mouseClick(x, y)) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxPathFinderType.mouseClick(x, y)) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if (listBoxAdvanced.mouseClick(x, y)) {
//TODO
}
/*
else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxEnableServerControlledAI.mouseClick(x, y) && listBoxEnableServerControlledAI.getEditable()) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
needToRepublishToMasterserver = true;
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
*/
else if(listBoxTileset.mouseClick(x, y)){
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if(listBoxMapFilter.mouseClick(x, y)){
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
switchToNextMapGroup(listBoxMapFilter.getSelectedItemIndex()-oldListBoxMapfilterIndex);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n", getCurrentMapFile().c_str());
loadMapInfo(Map::getMapPath(getCurrentMapFile()), &mapInfo, true);
labelMapInfo.setText(mapInfo.desc);
updateControlers();
updateNetworkSlots();
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if(listBoxTechTree.mouseClick(x, y)){
reloadFactions(false);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if(listBoxPublishServer.mouseClick(x, y) && listBoxPublishServer.getEditable()) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
needToRepublishToMasterserver = true;
soundRenderer.playFx(coreData.getClickSoundC());
}
/*
else if(listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxNetworkFramePeriod.mouseClick(x, y)){
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
needToRepublishToMasterserver = true;
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
soundRenderer.playFx(coreData.getClickSoundC());
}
*/
else if(listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxNetworkPauseGameForLaggedClients.mouseClick(x, y)){
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
soundRenderer.playFx(coreData.getClickSoundC());
}
else {
for(int i=0; i<mapInfo.players; ++i) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if (listBoxAdvanced.getSelectedItemIndex() == 1) {
// set multiplier
if(listBoxRMultiplier[i].mouseClick(x, y)) {
}
}
//ensure thet only 1 human player is present
if(listBoxControls[i].mouseClick(x, y)) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
//look for human players
int humanIndex1= -1;
int humanIndex2= -1;
for(int j=0; j<GameConstants::maxPlayers; ++j) {
ControlType ct= static_cast<ControlType>(listBoxControls[j].getSelectedItemIndex());
if(ct == ctHuman) {
if(humanIndex1 == -1) {
humanIndex1= j;
}
else {
humanIndex2= j;
}
}
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] humanIndex1 = %d, humanIndex2 = %d\n",__FILE__,__FUNCTION__,__LINE__,humanIndex1,humanIndex2);
//no human
if(humanIndex1 == -1 && humanIndex2 == -1) {
listBoxControls[i].setSelectedItemIndex(ctHuman);
//labelPlayerNames[i].setText("");
//labelPlayerNames[i].setText(getHumanPlayerName());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] i = %d, labelPlayerNames[i].getText() [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,labelPlayerNames[i].getText().c_str());
}
//2 humans
else if(humanIndex1 != -1 && humanIndex2 != -1) {
int closeSlotIndex = (humanIndex1 == i ? humanIndex2: humanIndex1);
int humanSlotIndex = (closeSlotIndex == humanIndex1 ? humanIndex2 : humanIndex1);
string origPlayName = labelPlayerNames[closeSlotIndex].getText();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] closeSlotIndex = %d, origPlayName [%s]\n",__FILE__,__FUNCTION__,__LINE__,closeSlotIndex,origPlayName.c_str());
listBoxControls[closeSlotIndex].setSelectedItemIndex(ctClosed);
//labelPlayerNames[closeSlotIndex].setText("");
labelPlayerNames[humanSlotIndex].setText((origPlayName != "" ? origPlayName : getHumanPlayerName()));
}
updateNetworkSlots();
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true) {
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
updateResourceMultiplier(i);
}
else if(listBoxFactions[i].mouseClick(x, y)) {
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if(listBoxTeams[i].mouseClick(x, y))
{
if(factionFiles[listBoxFactions[i].getSelectedItemIndex()] != formatString(GameConstants::OBSERVER_SLOTNAME)) {
//printf("i = %d factionFiles[listBoxFactions[i].getSelectedItemIndex()] [%s] listBoxTeams[i].getSelectedItemIndex() = %d, lastSelectedTeamIndex[i] = %d\n",i,factionFiles[listBoxFactions[i].getSelectedItemIndex()].c_str(),listBoxTeams[i].getSelectedItemIndex(),lastSelectedTeamIndex[i]);
if(listBoxTeams[i].getSelectedItemIndex() + 1 != (GameConstants::maxPlayers + fpt_Observer)) {
lastSelectedTeamIndex[i] = listBoxTeams[i].getSelectedItemIndex();
}
}
else {
lastSelectedTeamIndex[i] = -1;
}
if(listBoxPublishServer.getSelectedItemIndex() == 0) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);;
}
}
else if(labelPlayerNames[i].mouseClick(x, y)) {
SetActivePlayerNameEditor();
}
}
catch(const std::exception &ex) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s::%s %d] Error detected:\n%s\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
//throw runtime_error(szBuf);
showGeneralError=true;
generalErrorToShow = szBuf;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -1356,8 +1369,8 @@ void MenuStateCustomGame::render() {
renderer.renderConsole(&console,showFullConsole,true);
}
catch(const std::exception &ex) {
char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
char szBuf[4096]="";
sprintf(szBuf,"In [%s::%s %d] Error detected:\n%s\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
throw runtime_error(szBuf);
}
}
@ -1770,8 +1783,8 @@ void MenuStateCustomGame::update() {
}
}
catch(const std::exception &ex) {
char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
char szBuf[4096]="";
sprintf(szBuf,"In [%s::%s %d] Error detected:\n%s\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
//throw runtime_error(szBuf);
@ -1841,120 +1854,131 @@ void MenuStateCustomGame::publishToMasterserver()
void MenuStateCustomGame::simpleTask() {
if(publishToMasterserverThreadInDeletion == true) {
return;
}
try {
if(publishToMasterserverThreadInDeletion == true) {
return;
}
if( publishToMasterserverThread == NULL ||
publishToMasterserverThread->getQuitStatus() == true) {
return;
}
if( publishToMasterserverThread == NULL ||
publishToMasterserverThread->getQuitStatus() == true) {
return;
}
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
bool republish = (needToRepublishToMasterserver == true && publishToServerInfo.size() != 0);
needToRepublishToMasterserver = false;
std::map<string,string> newPublishToServerInfo = publishToServerInfo;
publishToServerInfo.clear();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
bool republish = (needToRepublishToMasterserver == true && publishToServerInfo.size() != 0);
needToRepublishToMasterserver = false;
std::map<string,string> newPublishToServerInfo = publishToServerInfo;
publishToServerInfo.clear();
bool broadCastSettings = needToBroadcastServerSettings;
needToBroadcastServerSettings=false;
bool broadCastSettings = needToBroadcastServerSettings;
needToBroadcastServerSettings=false;
bool hasClientConnection = false;
if(broadCastSettings) {
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
hasClientConnection = serverInterface->hasClientConnection();
}
bool hasClientConnection = false;
if(broadCastSettings) {
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
hasClientConnection = serverInterface->hasClientConnection();
}
bool needPing = (difftime(time(NULL),lastNetworkPing) >= GameConstants::networkPingInterval);
safeMutex.ReleaseLock();
bool needPing = (difftime(time(NULL),lastNetworkPing) >= GameConstants::networkPingInterval);
safeMutex.ReleaseLock();
if( publishToMasterserverThread == NULL ||
publishToMasterserverThread->getQuitStatus() == true) {
return;
}
if( publishToMasterserverThread == NULL ||
publishToMasterserverThread->getQuitStatus() == true) {
return;
}
if(republish == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(republish == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
//string request = Config::getInstance().getString("Masterserver") + "addServerInfo.php?" + newPublishToServerInfo;
string request = Config::getInstance().getString("Masterserver") + "addServerInfo.php?";
//string request = Config::getInstance().getString("Masterserver") + "addServerInfo.php?" + newPublishToServerInfo;
string request = Config::getInstance().getString("Masterserver") + "addServerInfo.php?";
CURL *handle = SystemFlags::initHTTP();
for(std::map<string,string>::const_iterator iterMap = newPublishToServerInfo.begin();
iterMap != newPublishToServerInfo.end(); iterMap++) {
CURL *handle = SystemFlags::initHTTP();
for(std::map<string,string>::const_iterator iterMap = newPublishToServerInfo.begin();
iterMap != newPublishToServerInfo.end(); iterMap++) {
request += iterMap->first;
request += "=";
request += SystemFlags::escapeURL(iterMap->second,handle);
request += "&";
}
request += iterMap->first;
request += "=";
request += SystemFlags::escapeURL(iterMap->second,handle);
request += "&";
}
//printf("the request is:\n%s\n",request.c_str());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] the request is:\n%s\n",__FILE__,__FUNCTION__,__LINE__,request.c_str());
//printf("the request is:\n%s\n",request.c_str());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] the request is:\n%s\n",__FILE__,__FUNCTION__,__LINE__,request.c_str());
std::string serverInfo = SystemFlags::getHTTP(request,handle);
SystemFlags::cleanupHTTP(&handle);
std::string serverInfo = SystemFlags::getHTTP(request,handle);
SystemFlags::cleanupHTTP(&handle);
//printf("the result is:\n'%s'\n",serverInfo.c_str());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] the result is:\n'%s'\n",__FILE__,__FUNCTION__,__LINE__,serverInfo.c_str());
//printf("the result is:\n'%s'\n",serverInfo.c_str());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] the result is:\n'%s'\n",__FILE__,__FUNCTION__,__LINE__,serverInfo.c_str());
// uncomment to enable router setup check of this server
if(EndsWith(serverInfo, "OK") == false) {
showMasterserverError=true;
masterServererErrorToShow = (serverInfo != "" ? serverInfo : "No Reply");
}
}
// uncomment to enable router setup check of this server
if(EndsWith(serverInfo, "OK") == false) {
showMasterserverError=true;
masterServererErrorToShow = (serverInfo != "" ? serverInfo : "No Reply");
}
}
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__);
if( publishToMasterserverThread == NULL ||
publishToMasterserverThread->getQuitStatus() == true) {
return;
}
if( publishToMasterserverThread == NULL ||
publishToMasterserverThread->getQuitStatus() == true) {
return;
}
if(broadCastSettings) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(broadCastSettings) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
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__);
MutexSafeWrapper safeMutex2(&masterServerThreadAccessor);
GameSettings gameSettings;
loadGameSettings(&gameSettings);
MutexSafeWrapper safeMutex2(&masterServerThreadAccessor);
GameSettings gameSettings;
loadGameSettings(&gameSettings);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
serverInterface->setGameSettings(&gameSettings,false);
safeMutex2.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
serverInterface->setGameSettings(&gameSettings,false);
safeMutex2.ReleaseLock();
if(hasClientConnection == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(hasClientConnection == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutex3(&masterServerThreadAccessor);
MutexSafeWrapper safeMutex3(&masterServerThreadAccessor);
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__);
serverInterface->broadcastGameSetup(&gameSettings);
safeMutex3.ReleaseLock();
}
}
serverInterface->broadcastGameSetup(&gameSettings);
safeMutex3.ReleaseLock();
}
}
if( publishToMasterserverThread == NULL ||
publishToMasterserverThread->getQuitStatus() == true) {
return;
}
if( publishToMasterserverThread == NULL ||
publishToMasterserverThread->getQuitStatus() == true) {
return;
}
if(needPing == true) {
lastNetworkPing = time(NULL);
if(needPing == true) {
lastNetworkPing = time(NULL);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] Sending nmtPing to clients\n",__FILE__,__FUNCTION__,__LINE__);
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
NetworkMessagePing msg(GameConstants::networkPingInterval,time(NULL));
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] Sending nmtPing to clients\n",__FILE__,__FUNCTION__,__LINE__);
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
NetworkMessagePing msg(GameConstants::networkPingInterval,time(NULL));
MutexSafeWrapper safeMutex2(&masterServerThreadAccessor);
serverInterface->broadcastPing(&msg);
safeMutex2.ReleaseLock();
MutexSafeWrapper safeMutex2(&masterServerThreadAccessor);
serverInterface->broadcastPing(&msg);
safeMutex2.ReleaseLock();
}
}
catch(const std::exception &ex) {
char szBuf[4096]="";
sprintf(szBuf,"In [%s::%s %d] Error detected:\n%s\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
//throw runtime_error(szBuf);!!!
showGeneralError=true;
generalErrorToShow = ex.what();
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -2361,8 +2385,8 @@ bool MenuStateCustomGame::hasNetworkGameSettings() {
}
}
catch(const std::exception &ex) {
char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
char szBuf[4096]="";
sprintf(szBuf,"In [%s::%s %d] Error detected:\n%s\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
showGeneralError=true;
@ -2445,7 +2469,9 @@ void MenuStateCustomGame::reloadFactions(bool keepExistingSelectedItem) {
}
if(results.size() == 0) {
throw runtime_error("(2)There are no factions for the tech tree [" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "]");
//throw runtime_error("(2)There are no factions for the tech tree [" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "]");
showGeneralError=true;
generalErrorToShow = "[#2] There are no factions for the tech tree [" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "]";
}
results.push_back(formatString(GameConstants::RANDOMFACTION_SLOTNAME));
@ -2512,8 +2538,8 @@ void MenuStateCustomGame::updateControlers(){
}
}
catch(const std::exception &ex) {
char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
char szBuf[4096]="";
sprintf(szBuf,"In [%s::%s %d] Error detected:\n%s\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
throw runtime_error(szBuf);
}
@ -2533,8 +2559,8 @@ void MenuStateCustomGame::closeUnusedSlots(){
updateNetworkSlots();
}
catch(const std::exception &ex) {
char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
char szBuf[4096]="";
sprintf(szBuf,"In [%s::%s %d] Error detected:\n%s\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
throw runtime_error(szBuf);
}
@ -2562,8 +2588,8 @@ void MenuStateCustomGame::updateNetworkSlots() {
serverInterface->addSlot(i);
}
catch(const std::exception &ex) {
char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
char szBuf[4096]="";
sprintf(szBuf,"In [%s::%s %d] Error detected:\n%s\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
showGeneralError=true;
@ -2585,8 +2611,8 @@ void MenuStateCustomGame::updateNetworkSlots() {
}
}
catch(const std::exception &ex) {
char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
char szBuf[4096]="";
sprintf(szBuf,"In [%s::%s %d] Error detected:\n%s\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
//throw runtime_error(szBuf);!!!

View File

@ -535,9 +535,7 @@ void ClientInterface::updateKeyframe(int frameCount) {
NetworkMessageCommandList networkMessageCommandList;
while(receiveMessage(&networkMessageCommandList) == false &&
isConnected() == true &&
difftime(time(NULL),receiveTimeElapsed) <= (messageWaitTimeout / 1000)) {
//sleep(waitSleepTime);
//sleep(0);
difftime(time(NULL),receiveTimeElapsed) <= (messageWaitTimeout / 2000)) {
waitCount++;
}
@ -585,11 +583,9 @@ void ClientInterface::updateKeyframe(int frameCount) {
{
time_t receiveTimeElapsed = time(NULL);
NetworkMessageQuit networkMessageQuit;
//if(receiveMessage(&networkMessageQuit)) {
while(receiveMessage(&networkMessageQuit) == false &&
isConnected() == true &&
difftime(time(NULL),receiveTimeElapsed) <= (messageWaitTimeout / 1000)) {
//sleep(0);
difftime(time(NULL),receiveTimeElapsed) <= (messageWaitTimeout / 2000)) {
}
quit= true;
done= true;
@ -603,7 +599,6 @@ void ClientInterface::updateKeyframe(int frameCount) {
while(receiveMessage(&networkMessageText) == false &&
isConnected() == true &&
difftime(time(NULL),receiveTimeElapsed) <= (messageWaitTimeout / 1000)) {
//sleep(0);
}
ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getTeamIndex(),networkMessageText.getPlayerIndex());

View File

@ -344,8 +344,8 @@ void ConnectionSlot::update(bool checkForNewClients) {
lastReceiveCommandListTime = time(NULL);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] currentFrameCount = %d\n",__FILE__,__FUNCTION__,__LINE__,currentFrameCount);
for(int i= 0; i<networkMessageCommandList.getCommandCount(); ++i) {
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,intToStr(__LINE__));
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,intToStr(__LINE__));
for(int i = 0; i < networkMessageCommandList.getCommandCount(); ++i) {
vctPendingNetworkCommandList.push_back(*networkMessageCommandList.getCommand(i));
}
}

View File

@ -305,7 +305,7 @@ void NetworkMessageLaunch::send(Socket* socket) const{
// class NetworkMessageLaunch
// =====================================================
NetworkMessageCommandList::NetworkMessageCommandList(int32 frameCount){
NetworkMessageCommandList::NetworkMessageCommandList(int32 frameCount) {
data.header.messageType= nmtCommandList;
data.header.frameCount= frameCount;
data.header.commandCount= 0;
@ -317,24 +317,29 @@ bool NetworkMessageCommandList::addCommand(const NetworkCommand* networkCommand)
data.header.commandCount++;
return true;
}
else {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING / ERROR too many commands in commandlist data.header.commandCount = %d\n",__FILE__,__FUNCTION__,__LINE__,data.header.commandCount);
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] WARNING / ERROR too many commands in commandlist data.header.commandCount = %d\n",__FILE__,__FUNCTION__,__LINE__,data.header.commandCount);
}
return false;
}
bool NetworkMessageCommandList::receive(Socket* socket) {
// _peek_ type, commandCount & frame num first.
for(int peekAttempt = 1; peekAttempt < 1000; peekAttempt++) {
for(int peekAttempt = 1; peekAttempt < 2000; peekAttempt++) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] peekAttempt = %d\n",__FILE__,__FUNCTION__,__LINE__,peekAttempt);
if (NetworkMessage::peek(socket, &data, commandListHeaderSize) == true) {
break;
}
else {
sleep(1); // sleep 1 ms to wait for socket data
}
//else {
// sleep(1); // sleep 1 ms to wait for socket data
//}
}
if (NetworkMessage::peek(socket, &data, commandListHeaderSize) == false) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR / WARNING!!! NetworkMessage::peek failed!\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] ERROR / WARNING!!! NetworkMessage::peek failed!\n",__FILE__,__FUNCTION__,__LINE__);
return false;
}
@ -345,21 +350,24 @@ bool NetworkMessageCommandList::receive(Socket* socket) {
int totalMsgSize = commandListHeaderSize + (sizeof(NetworkCommand) * data.header.commandCount);
// _peek_ type, commandCount & frame num first.
for(int peekAttempt = 1; peekAttempt < 1000; peekAttempt++) {
for(int peekAttempt = 1; peekAttempt < 2000; peekAttempt++) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] peekAttempt = %d\n",__FILE__,__FUNCTION__,__LINE__,peekAttempt);
if (NetworkMessage::peek(socket, &data, totalMsgSize) == true) {
break;
}
else {
sleep(1); // sleep 1 ms to wait for socket data
}
//else {
// sleep(1); // sleep 1 ms to wait for socket data
//}
}
if (socket->getDataToRead() < totalMsgSize) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR / WARNING!!! Insufficient data to read entire command list [need %d bytes, only %d available].\n",
__FILE__,__FUNCTION__,__LINE__, totalMsgSize, socket->getDataToRead());
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] ERROR / WARNING!!! Insufficient data to read entire command list [need %d bytes, only %d available].\n",
__FILE__,__FUNCTION__,__LINE__, totalMsgSize, socket->getDataToRead());
return false;
}
bool result = NetworkMessage::receive(socket, &data, totalMsgSize);
@ -374,7 +382,7 @@ bool NetworkMessageCommandList::receive(Socket* socket) {
return result;
}
void NetworkMessageCommandList::send(Socket* socket) const{
void NetworkMessageCommandList::send(Socket* socket) const {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtCommandList, frameCount = %d, data.header.commandCount = %d, data.header.messageType = %d\n",__FILE__,__FUNCTION__,__LINE__,data.header.frameCount,data.header.commandCount,data.header.messageType);
assert(data.header.messageType==nmtCommandList);

View File

@ -242,15 +242,12 @@ public:
#pragma pack(push, 1)
class NetworkMessageCommandList: public NetworkMessage{
private:
//static const int maxCommandCount= 16*4;
//static const int maxCommandCount = (16 * 4) * 2;
static const int maxCommandCount = 2048; // can be as large as 65535
static const int maxCommandCount = 2496; // can be as large as 65535
private:
struct DataHeader {
int8 messageType;
uint16 commandCount;
//int8 commandCount;
int32 frameCount;
};

View File

@ -54,7 +54,7 @@ NetworkCommand::NetworkCommand(World *world, int networkCommandType, int unitId,
this->unitFactionIndex = unit->getFaction()->getIndex();
this->unitFactionUnitCount = unit->getFaction()->getUnitCount();
const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), this->unitTypeId);
//const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), this->unitTypeId);
const CommandType *ct = unit->getType()->findCommandTypeById(this->commandTypeId);
if(ct != NULL && ct->getClass() == ccBuild) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str());
@ -63,6 +63,8 @@ NetworkCommand::NetworkCommand(World *world, int networkCommandType, int unitId,
}
}
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Created NetworkCommand as follows:\n%s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str());
}
void NetworkCommand::preprocessNetworkCommand(World *world) {
@ -71,7 +73,7 @@ void NetworkCommand::preprocessNetworkCommand(World *world) {
//validate unit
if(unit != NULL) {
const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), unitTypeId);
//const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), unitTypeId);
const CommandType *ct = unit->getType()->findCommandTypeById(commandTypeId);
if(ct != NULL && ct->getClass() == ccBuild && targetId >= 0) {
CardinalDir::assertDirValid(targetId);
@ -94,16 +96,4 @@ string NetworkCommand::toString() const {
return result;
}
/*
NetworkCommand::NetworkCommand(int networkCommandType, NetworkCommandSubType ncstType, int unitId, int value1, int value2) {
this->networkCommandType= networkCommandType;
this->unitId= unitId;
this->commandTypeId= ncstType;
this->positionX= -1;
this->positionY= -1;
this->unitTypeId= value1;
this->targetId= value2;
}
*/
}}//end namespace

View File

@ -72,14 +72,14 @@ enum NetworkCommandType {
//};
#pragma pack(push, 1)
class NetworkCommand{
class NetworkCommand {
private:
int16 networkCommandType;
int32 unitId;
int16 unitTypeId;
int16 commandTypeId;
int16 positionX;
int16 positionY;
int16 unitTypeId;
int32 targetId;
int8 wantQueue;
int8 fromFactionIndex;
@ -91,12 +91,12 @@ private:
public:
NetworkCommand(){};
NetworkCommand(
World *world,
int networkCommandType,
int unitId,
int commandTypeId= -1,
const Vec2i &pos= Vec2i(0),
int unitTypeId= -1,
World *world,
int networkCommandType,
int unitId,
int commandTypeId= -1,
const Vec2i &pos= Vec2i(0),
int unitTypeId= -1,
int targetId= -1,
int facing= -1,
bool wantQueue = false,

View File

@ -791,7 +791,7 @@ void ServerInterface::update() {
}
}
void ServerInterface::updateKeyframe(int frameCount){
void ServerInterface::updateKeyframe(int frameCount) {
Chrono chrono;
chrono.start();
@ -801,7 +801,7 @@ void ServerInterface::updateKeyframe(int frameCount){
NetworkMessageCommandList networkMessageCommandList(frameCount);
//build command list, remove commands from requested and add to pending
while(!requestedCommands.empty()) {
while(requestedCommands.empty() == false) {
if(networkMessageCommandList.addCommand(&requestedCommands.back())) {
pendingCommands.push_back(requestedCommands.back());
requestedCommands.pop_back();
@ -814,9 +814,10 @@ void ServerInterface::updateKeyframe(int frameCount){
try {
// Possible cause of out of synch since we have more commands that need
// to be sent in this frame
if(!requestedCommands.empty()) {
if(requestedCommands.empty() == false) {
char szBuf[1024]="";
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING / ERROR, requestedCommands.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,requestedCommands.size());
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] WARNING / ERROR, requestedCommands.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,requestedCommands.size());
string sMsg = "may go out of synch: server requestedCommands.size() = " + intToStr(requestedCommands.size());
sendTextMessage(sMsg,-1, true);

View File

@ -31,7 +31,7 @@ const float SoundRenderer::audibleDist= 50.f;
// class SoundRenderer
// =====================================================
SoundRenderer::SoundRenderer(){
SoundRenderer::SoundRenderer() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
soundPlayer = NULL;
@ -49,7 +49,6 @@ bool SoundRenderer::init(Window *window) {
Config &config= Config::getInstance();
runThreadSafe = config.getBool("ThreadedSoundStream","false");
//if(soundPlayer == NULL) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
si.setFactory(fr.getSoundFactory(config.getString("FactorySound")));
@ -62,7 +61,6 @@ bool SoundRenderer::init(Window *window) {
soundPlayerParams.strBufferCount= config.getInt("SoundStreamingBuffers");
soundPlayer->init(&soundPlayerParams);
}
//}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -84,7 +82,7 @@ bool SoundRenderer::wasInitOk() const {
return result;
}
SoundRenderer::~SoundRenderer(){
SoundRenderer::~SoundRenderer() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
stopAllSounds();
@ -97,55 +95,63 @@ SoundRenderer::~SoundRenderer(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
SoundRenderer &SoundRenderer::getInstance(){
SoundRenderer &SoundRenderer::getInstance() {
static SoundRenderer soundRenderer;
return soundRenderer;
}
void SoundRenderer::update(){
void SoundRenderer::update() {
if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
MutexSafeWrapper safeMutex(NULL);
if(runThreadSafe == true) {
safeMutex.setMutex(&mutex);
}
soundPlayer->updateStreams();
if(runThreadSafe == true) mutex.v();
}
}
// ======================= Music ============================
void SoundRenderer::playMusic(StrSound *strSound){
void SoundRenderer::playMusic(StrSound *strSound) {
if(strSound != NULL) {
strSound->setVolume(musicVolume);
strSound->restart();
if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
MutexSafeWrapper safeMutex(NULL);
if(runThreadSafe == true) {
safeMutex.setMutex(&mutex);
}
soundPlayer->play(strSound);
if(runThreadSafe == true) mutex.v();
}
}
}
void SoundRenderer::setMusicVolume(StrSound *strSound){
void SoundRenderer::setMusicVolume(StrSound *strSound) {
if(strSound != NULL) {
strSound->setVolume(musicVolume);
}
}
void SoundRenderer::stopMusic(StrSound *strSound){
void SoundRenderer::stopMusic(StrSound *strSound) {
if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
MutexSafeWrapper safeMutex(NULL);
if(runThreadSafe == true) {
safeMutex.setMutex(&mutex);
}
soundPlayer->stop(strSound);
if(strSound != NULL) {
if(strSound->getNext() != NULL) {
soundPlayer->stop(strSound->getNext());
}
}
if(runThreadSafe == true) mutex.v();
}
}
// ======================= Fx ============================
void SoundRenderer::playFx(StaticSound *staticSound, Vec3f soundPos, Vec3f camPos){
void SoundRenderer::playFx(StaticSound *staticSound, Vec3f soundPos, Vec3f camPos) {
if(staticSound!=NULL){
float d= soundPos.dist(camPos);
@ -155,57 +161,72 @@ void SoundRenderer::playFx(StaticSound *staticSound, Vec3f soundPos, Vec3f camPo
staticSound->setVolume(correctedVol);
if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
MutexSafeWrapper safeMutex(NULL);
if(runThreadSafe == true) {
safeMutex.setMutex(&mutex);
}
soundPlayer->play(staticSound);
if(runThreadSafe == true) mutex.v();
}
}
}
}
void SoundRenderer::playFx(StaticSound *staticSound){
void SoundRenderer::playFx(StaticSound *staticSound) {
if(staticSound!=NULL){
staticSound->setVolume(fxVolume);
if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
MutexSafeWrapper safeMutex(NULL);
if(runThreadSafe == true) {
safeMutex.setMutex(&mutex);
}
soundPlayer->play(staticSound);
if(runThreadSafe == true) mutex.v();
}
}
}
// ======================= Ambient ============================
void SoundRenderer::playAmbient(StrSound *strSound){
void SoundRenderer::playAmbient(StrSound *strSound) {
if(strSound != NULL) {
strSound->setVolume(ambientVolume);
if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
MutexSafeWrapper safeMutex(NULL);
if(runThreadSafe == true) {
safeMutex.setMutex(&mutex);
}
soundPlayer->play(strSound, ambientFade);
if(runThreadSafe == true) mutex.v();
}
}
}
void SoundRenderer::stopAmbient(StrSound *strSound){
void SoundRenderer::stopAmbient(StrSound *strSound) {
if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
MutexSafeWrapper safeMutex(NULL);
if(runThreadSafe == true) {
safeMutex.setMutex(&mutex);
}
soundPlayer->stop(strSound, ambientFade);
if(runThreadSafe == true) mutex.v();
}
}
// ======================= Misc ============================
void SoundRenderer::stopAllSounds(){
void SoundRenderer::stopAllSounds() {
if(soundPlayer != NULL) {
mutex.p();
MutexSafeWrapper safeMutex(NULL);
if(runThreadSafe == true) {
safeMutex.setMutex(&mutex);
}
soundPlayer->stopAllSounds();
mutex.v();
}
}
void SoundRenderer::loadConfig(){
void SoundRenderer::loadConfig() {
Config &config= Config::getInstance();
fxVolume= config.getInt("SoundVolumeFx")/100.f;

View File

@ -3,9 +3,9 @@
//
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
@ -65,16 +65,15 @@ public:
void playMusic(StrSound *strSound);
void setMusicVolume(StrSound *strSound);
void stopMusic(StrSound *strSound);
//fx
void playFx(StaticSound *staticSound, Vec3f soundPos, Vec3f camPos);
void playFx(StaticSound *staticSound);
//ambient
//void playAmbient(StaticSound *staticSound);
void playAmbient(StrSound *strSound);
void stopAmbient(StrSound *strSound);
//misc
void stopAllSounds();
void loadConfig();

View File

@ -3,9 +3,9 @@
//
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
@ -28,16 +28,16 @@ namespace Glest{ namespace Game{
Command::Command(const CommandType *ct, const Vec2i &pos){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ct = [%p]\n",__FILE__,__FUNCTION__,__LINE__,ct);
this->commandType= ct;
this->commandType= ct;
this->pos= pos;
this->unitRef= NULL;
unitType= NULL;
stateType = cst_None;
stateValue = -1;
}
}
Command::Command(const CommandType *ct, Unit* unit){
this->commandType= ct;
Command::Command(const CommandType *ct, Unit* unit) {
this->commandType= ct;
this->pos= Vec2i(0);
this->unitRef= unit;
unitType= NULL;
@ -47,10 +47,10 @@ Command::Command(const CommandType *ct, Unit* unit){
}
stateType = cst_None;
stateValue = -1;
}
}
Command::Command(const CommandType *ct, const Vec2i &pos, const UnitType *unitType, CardinalDir facing){
this->commandType= ct;
Command::Command(const CommandType *ct, const Vec2i &pos, const UnitType *unitType, CardinalDir facing) {
this->commandType= ct;
this->pos= pos;
this->unitRef= NULL;
this->unitType= unitType;

View File

@ -1900,7 +1900,7 @@ std::string Unit::toString() const {
result += "id = " + intToStr(this->id);
if(this->type != NULL) {
result += " name [" + this->type->getName() + "]";
result += " name [" + this->type->getName() + "][" + intToStr(this->type->getId()) + "]";
}
if(this->faction != NULL) {

View File

@ -203,7 +203,7 @@ void StreamSoundSource::update()
if(fadeState == NoFading){
alSourcef(source, AL_GAIN, sound->getVolume());
}
ALint processed = 0;
alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
while(processed > 0) {
@ -481,15 +481,23 @@ void SoundPlayerOpenAL::updateStreams() {
source->update();
}
catch(std::exception& e) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
std::cerr << "Error while updating sound stream: "
<< e.what() << "\n";
std::cerr << "Error while updating sound stream: "<< e.what() << "\n";
}
}
alcProcessContext(context);
checkAlcError("Error while processing audio context: ");
} catch(...) {
}
catch(exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
printOpenALInfo();
throw runtime_error(ex.what());
}
catch(...) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] UNKNOWN Error\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] UNKNOWN Error\n",__FILE__,__FUNCTION__,__LINE__);
printOpenALInfo();
throw;