- bugfixes related to cppcheck report
- bugfixes found using valgrind (memory leaks)
This commit is contained in:
parent
4885f3f3a6
commit
d33e1174a5
|
@ -476,7 +476,7 @@ bool PathFinder::addToOpenSet(Unit *unit, Node *node,const Vec2i finalPos, Vec2i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
direction PathFinder::directionOfMove(Vec2i to, Vec2i from) {
|
direction PathFinder::directionOfMove(Vec2i to, Vec2i from) const {
|
||||||
if (from.x == to.x) {
|
if (from.x == to.x) {
|
||||||
if (from.y == to.y)
|
if (from.y == to.y)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -545,16 +545,16 @@ Vec2i PathFinder::adjustInDirection(Vec2i c, int dir) {
|
||||||
return Vec2i( -1, -1 );
|
return Vec2i( -1, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PathFinder::directionIsDiagonal(direction dir) {
|
bool PathFinder::directionIsDiagonal(direction dir) const {
|
||||||
return (dir % 2) != 0;
|
return (dir % 2) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// logical implication operator
|
// logical implication operator
|
||||||
bool PathFinder::implies (bool a, bool b) {
|
bool PathFinder::implies(bool a, bool b) const {
|
||||||
return a ? b : true;
|
return a ? b : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
directionset PathFinder::addDirectionToSet (directionset dirs, direction dir) {
|
directionset PathFinder::addDirectionToSet(directionset dirs, direction dir) const {
|
||||||
return dirs | 1 << dir;
|
return dirs | 1 << dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -595,7 +595,7 @@ directionset PathFinder::naturalNeighbours(direction dir) {
|
||||||
|
|
||||||
// return and remove a direction from the set
|
// return and remove a direction from the set
|
||||||
// returns NO_DIRECTION if the set was empty
|
// returns NO_DIRECTION if the set was empty
|
||||||
direction PathFinder::nextDirectionInSet (directionset *dirs) {
|
direction PathFinder::nextDirectionInSet(directionset *dirs) const {
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
char bit = 1 << i;
|
char bit = 1 << i;
|
||||||
if (*dirs & bit) {
|
if (*dirs & bit) {
|
||||||
|
|
|
@ -133,16 +133,16 @@ private:
|
||||||
|
|
||||||
|
|
||||||
bool contained(Vec2i c);
|
bool contained(Vec2i c);
|
||||||
direction directionOfMove(Vec2i to, Vec2i from);
|
direction directionOfMove(Vec2i to, Vec2i from) const;
|
||||||
direction directionWeCameFrom(Vec2i node, Vec2i nodeFrom);
|
direction directionWeCameFrom(Vec2i node, Vec2i nodeFrom);
|
||||||
bool isEnterable(Vec2i coord);
|
bool isEnterable(Vec2i coord);
|
||||||
Vec2i adjustInDirection(Vec2i c, int dir);
|
Vec2i adjustInDirection(Vec2i c, int dir);
|
||||||
bool directionIsDiagonal(direction dir);
|
bool directionIsDiagonal(direction dir) const;
|
||||||
directionset forcedNeighbours(Vec2i coord,direction dir);
|
directionset forcedNeighbours(Vec2i coord,direction dir);
|
||||||
bool implies (bool a, bool b);
|
bool implies(bool a, bool b) const;
|
||||||
directionset addDirectionToSet (directionset dirs, direction dir);
|
directionset addDirectionToSet(directionset dirs, direction dir) const;
|
||||||
directionset naturalNeighbours(direction dir);
|
directionset naturalNeighbours(direction dir);
|
||||||
direction nextDirectionInSet (directionset *dirs);
|
direction nextDirectionInSet(directionset *dirs) const;
|
||||||
Vec2i jump(Vec2i dest, direction dir, Vec2i start,std::vector<Vec2i> &path,int pathLength);
|
Vec2i jump(Vec2i dest, direction dir, Vec2i start,std::vector<Vec2i> &path,int pathLength);
|
||||||
bool addToOpenSet(Unit *unit, Node *node,const Vec2i finalPos, Vec2i sucPos, bool &nodeLimitReached,int maxNodeCount,Node **newNodeAdded,bool bypassChecks);
|
bool addToOpenSet(Unit *unit, Node *node,const Vec2i finalPos, Vec2i sucPos, bool &nodeLimitReached,int maxNodeCount,Node **newNodeAdded,bool bypassChecks);
|
||||||
};
|
};
|
||||||
|
|
|
@ -335,6 +335,12 @@ bool GraphicButton::mouseMove(int x, int y){
|
||||||
const int GraphicListBox::defH= 22;
|
const int GraphicListBox::defH= 22;
|
||||||
const int GraphicListBox::defW= 140;
|
const int GraphicListBox::defW= 140;
|
||||||
|
|
||||||
|
GraphicListBox::GraphicListBox(std::string containerName, std::string objName)
|
||||||
|
: GraphicComponent(containerName, objName) {
|
||||||
|
selectedItemIndex = 0;
|
||||||
|
lighted = false;
|
||||||
|
}
|
||||||
|
|
||||||
void GraphicListBox::init(int x, int y, int w, int h, Vec3f textColor){
|
void GraphicListBox::init(int x, int y, int w, int h, Vec3f textColor){
|
||||||
GraphicComponent::init(x, y, w, h);
|
GraphicComponent::init(x, y, w, h);
|
||||||
|
|
||||||
|
@ -450,6 +456,13 @@ bool GraphicListBox::mouseClick(int x, int y){
|
||||||
const int GraphicMessageBox::defH= 240;
|
const int GraphicMessageBox::defH= 240;
|
||||||
const int GraphicMessageBox::defW= 350;
|
const int GraphicMessageBox::defW= 350;
|
||||||
|
|
||||||
|
GraphicMessageBox::GraphicMessageBox(std::string containerName, std::string objName)
|
||||||
|
: GraphicComponent(containerName, objName) {
|
||||||
|
buttonCount = 0;
|
||||||
|
header = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void GraphicMessageBox::init(const string &button1Str, const string &button2Str, int newWidth,int newHeight) {
|
void GraphicMessageBox::init(const string &button1Str, const string &button2Str, int newWidth,int newHeight) {
|
||||||
init(button1Str,newWidth,newHeight);
|
init(button1Str,newWidth,newHeight);
|
||||||
|
|
||||||
|
@ -546,6 +559,11 @@ bool GraphicMessageBox::mouseClick(int x, int y, int &clickedButton){
|
||||||
const int GraphicLine::defH= 5;
|
const int GraphicLine::defH= 5;
|
||||||
const int GraphicLine::defW= 1000;
|
const int GraphicLine::defW= 1000;
|
||||||
|
|
||||||
|
GraphicLine::GraphicLine(std::string containerName, std::string objName)
|
||||||
|
: GraphicComponent(containerName, objName) {
|
||||||
|
horizontal = false;
|
||||||
|
}
|
||||||
|
|
||||||
void GraphicLine::init(int x, int y, int w, int h){
|
void GraphicLine::init(int x, int y, int w, int h){
|
||||||
GraphicComponent::init(x, y, w, h);
|
GraphicComponent::init(x, y, w, h);
|
||||||
horizontal=true;
|
horizontal=true;
|
||||||
|
@ -558,6 +576,12 @@ void GraphicLine::init(int x, int y, int w, int h){
|
||||||
const int GraphicCheckBox::defH= 22;
|
const int GraphicCheckBox::defH= 22;
|
||||||
const int GraphicCheckBox::defW= 22;
|
const int GraphicCheckBox::defW= 22;
|
||||||
|
|
||||||
|
GraphicCheckBox::GraphicCheckBox(std::string containerName, std::string objName)
|
||||||
|
: GraphicComponent(containerName, objName) {
|
||||||
|
value = false;
|
||||||
|
lighted = false;
|
||||||
|
}
|
||||||
|
|
||||||
void GraphicCheckBox::init(int x, int y, int w, int h){
|
void GraphicCheckBox::init(int x, int y, int w, int h){
|
||||||
GraphicComponent::init(x, y, w, h);
|
GraphicComponent::init(x, y, w, h);
|
||||||
value=true;
|
value=true;
|
||||||
|
@ -591,6 +615,19 @@ bool GraphicCheckBox::mouseClick(int x, int y){
|
||||||
const int GraphicScrollBar::defThickness=20;
|
const int GraphicScrollBar::defThickness=20;
|
||||||
const int GraphicScrollBar::defLength= 200;
|
const int GraphicScrollBar::defLength= 200;
|
||||||
|
|
||||||
|
GraphicScrollBar::GraphicScrollBar(std::string containerName, std::string objName)
|
||||||
|
: GraphicComponent(containerName, objName) {
|
||||||
|
lighted = false;
|
||||||
|
horizontal = false;
|
||||||
|
elementCount = 0;
|
||||||
|
visibleSize = 0;
|
||||||
|
visibleStart = 0;
|
||||||
|
|
||||||
|
// position on component for renderer
|
||||||
|
visibleCompPosStart = 0;
|
||||||
|
visibleCompPosEnd = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void GraphicScrollBar::init(int x, int y, bool horizontal,int length, int thickness){
|
void GraphicScrollBar::init(int x, int y, bool horizontal,int length, int thickness){
|
||||||
GraphicComponent::init(x, y, horizontal?length:thickness,horizontal?thickness:length );
|
GraphicComponent::init(x, y, horizontal?length:thickness,horizontal?thickness:length );
|
||||||
this->horizontal=horizontal;
|
this->horizontal=horizontal;
|
||||||
|
|
|
@ -199,7 +199,8 @@ private:
|
||||||
bool lighted;
|
bool lighted;
|
||||||
Vec3f textColor;
|
Vec3f textColor;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
GraphicListBox(std::string containerName="", std::string objName="");
|
||||||
void init(int x, int y, int w=defW, int h=defH, Vec3f textColor=Vec3f(1.f, 1.f, 1.f));
|
void init(int x, int y, int w=defW, int h=defH, Vec3f textColor=Vec3f(1.f, 1.f, 1.f));
|
||||||
|
|
||||||
int getItemCount() const {return items.size();}
|
int getItemCount() const {return items.size();}
|
||||||
|
@ -243,6 +244,7 @@ private:
|
||||||
string header;
|
string header;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
GraphicMessageBox(std::string containerName="", std::string objName="");
|
||||||
void init(const string &button1Str, const string &button2Str, int newWidth=-1,int newHeight=-1);
|
void init(const string &button1Str, const string &button2Str, int newWidth=-1,int newHeight=-1);
|
||||||
void init(const string &button1Str, int newWidth=-1,int newHeight=-1);
|
void init(const string &button1Str, int newWidth=-1,int newHeight=-1);
|
||||||
|
|
||||||
|
@ -274,6 +276,7 @@ private:
|
||||||
bool horizontal;
|
bool horizontal;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
GraphicLine(std::string containerName="", std::string objName="");
|
||||||
void init(int x, int y, int w=defW, int h=defH);
|
void init(int x, int y, int w=defW, int h=defH);
|
||||||
bool getHorizontal() const {return horizontal;}
|
bool getHorizontal() const {return horizontal;}
|
||||||
void setHorizontal(bool horizontal) {this->horizontal= horizontal;}
|
void setHorizontal(bool horizontal) {this->horizontal= horizontal;}
|
||||||
|
@ -293,6 +296,7 @@ private:
|
||||||
bool lighted;
|
bool lighted;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
GraphicCheckBox(std::string containerName="", std::string objName="");
|
||||||
void init(int x, int y, int w=defW, int h=defH);
|
void init(int x, int y, int w=defW, int h=defH);
|
||||||
bool getValue() const {return value;}
|
bool getValue() const {return value;}
|
||||||
void setValue(bool value) {this->value= value;}
|
void setValue(bool value) {this->value= value;}
|
||||||
|
@ -323,6 +327,7 @@ private:
|
||||||
int visibleCompPosEnd;
|
int visibleCompPosEnd;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
GraphicScrollBar(std::string containerName="", std::string objName="");
|
||||||
void init(int x, int y, bool horizontal,int length=defLength, int thickness=defThickness);
|
void init(int x, int y, bool horizontal,int length=defLength, int thickness=defThickness);
|
||||||
virtual bool mouseDown(int x, int y);
|
virtual bool mouseDown(int x, int y);
|
||||||
virtual bool mouseMove(int x, int y);
|
virtual bool mouseMove(int x, int y);
|
||||||
|
|
|
@ -200,7 +200,7 @@ void ChatManager::keyDown(SDL_KeyboardEvent key) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(matchedIndexes.size() > 0) {
|
if(matchedIndexes.empty() == false) {
|
||||||
int newMatchedIndex = -1;
|
int newMatchedIndex = -1;
|
||||||
for(unsigned int index = 0; index < matchedIndexes.size(); ++index) {
|
for(unsigned int index = 0; index < matchedIndexes.size(); ++index) {
|
||||||
int possibleMatchIndex = matchedIndexes[index];
|
int possibleMatchIndex = matchedIndexes[index];
|
||||||
|
@ -248,7 +248,7 @@ void ChatManager::keyDown(SDL_KeyboardEvent key) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(matchedIndexes.size() > 0) {
|
if(matchedIndexes.empty() == false) {
|
||||||
int newMatchedIndex = -1;
|
int newMatchedIndex = -1;
|
||||||
for(unsigned int index = 0; index < matchedIndexes.size(); ++index) {
|
for(unsigned int index = 0; index < matchedIndexes.size(); ++index) {
|
||||||
int possibleMatchIndex = matchedIndexes[index];
|
int possibleMatchIndex = matchedIndexes[index];
|
||||||
|
@ -333,7 +333,7 @@ void ChatManager::switchOnEdit() {
|
||||||
void ChatManager::deleteText(int deleteCount,bool addToAutoCompleteBuffer) {
|
void ChatManager::deleteText(int deleteCount,bool addToAutoCompleteBuffer) {
|
||||||
if(text.empty() == false) {
|
if(text.empty() == false) {
|
||||||
for(unsigned int i = 0; i < deleteCount; ++i) {
|
for(unsigned int i = 0; i < deleteCount; ++i) {
|
||||||
if(textCharLength.size() > 0) {
|
if(textCharLength.empty() == false) {
|
||||||
//printf("BEFORE DEL textCharLength.size() = %d textCharLength[textCharLength.size()-1] = %d text.length() = %d\n",textCharLength.size(),textCharLength[textCharLength.size()-1],text.length());
|
//printf("BEFORE DEL textCharLength.size() = %d textCharLength[textCharLength.size()-1] = %d text.length() = %d\n",textCharLength.size(),textCharLength[textCharLength.size()-1],text.length());
|
||||||
|
|
||||||
if(textCharLength[textCharLength.size()-1] > text.length()) {
|
if(textCharLength[textCharLength.size()-1] > text.length()) {
|
||||||
|
|
|
@ -941,7 +941,7 @@ void Game::init(bool initForPreviewOnly) {
|
||||||
//init renderer state
|
//init renderer state
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Initializing renderer\n",__FILE__,__FUNCTION__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Initializing renderer\n",__FILE__,__FUNCTION__);
|
||||||
logger.add(Lang::getInstance().get("LogScreenGameLoadingInitRenderer","",true), true);
|
logger.add(Lang::getInstance().get("LogScreenGameLoadingInitRenderer","",true), true);
|
||||||
renderer.initGame(this);
|
renderer.initGame(this,this->getGameCameraPtr());
|
||||||
|
|
||||||
for(int i=0; i < world.getFactionCount(); ++i) {
|
for(int i=0; i < world.getFactionCount(); ++i) {
|
||||||
Faction *faction= world.getFaction(i);
|
Faction *faction= world.getFaction(i);
|
||||||
|
@ -1307,7 +1307,7 @@ void Game::update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
scriptManager.init(&world, &gameCamera);
|
scriptManager.init(&world, &gameCamera);
|
||||||
renderer.initGame(this);
|
renderer.initGame(this,this->getGameCameraPtr());
|
||||||
|
|
||||||
//sounds
|
//sounds
|
||||||
//soundRenderer.stopAllSounds(fadeMusicMilliseconds);
|
//soundRenderer.stopAllSounds(fadeMusicMilliseconds);
|
||||||
|
@ -1349,7 +1349,7 @@ void Game::update() {
|
||||||
catch(const exception &ex) {
|
catch(const exception &ex) {
|
||||||
gameStarted = true;
|
gameStarted = true;
|
||||||
|
|
||||||
throw ex;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1457,7 +1457,7 @@ void Game::render() {
|
||||||
renderFps++;
|
renderFps++;
|
||||||
totalRenderFps++;
|
totalRenderFps++;
|
||||||
|
|
||||||
NetworkManager &networkManager= NetworkManager::getInstance();
|
//NetworkManager &networkManager= NetworkManager::getInstance();
|
||||||
if(this->masterserverMode == false) {
|
if(this->masterserverMode == false) {
|
||||||
renderWorker();
|
renderWorker();
|
||||||
}
|
}
|
||||||
|
@ -1470,8 +1470,7 @@ void Game::render() {
|
||||||
int connectedClients=0;
|
int connectedClients=0;
|
||||||
for(int i = 0; i < world.getFactionCount(); ++i) {
|
for(int i = 0; i < world.getFactionCount(); ++i) {
|
||||||
Faction *faction = world.getFaction(i);
|
Faction *faction = world.getFaction(i);
|
||||||
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
if(server->isClientConnected(faction->getStartLocationIndex()) == true) {
|
||||||
if(slot != NULL && slot->isConnected() == true) {
|
|
||||||
connectedClients++;
|
connectedClients++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2572,7 +2571,7 @@ Stats Game::quitGame() {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
endStats = *(world.getStats());
|
endStats = *(world.getStats());
|
||||||
NetworkManager &networkManager= NetworkManager::getInstance();
|
//NetworkManager &networkManager= NetworkManager::getInstance();
|
||||||
if(this->masterserverMode == true) {
|
if(this->masterserverMode == true) {
|
||||||
endStats.setIsMasterserverMode(true);
|
endStats.setIsMasterserverMode(true);
|
||||||
}
|
}
|
||||||
|
@ -2813,6 +2812,11 @@ void Game::render2d(){
|
||||||
str+= "Log buffer count: " + intToStr(SystemFlags::getLogEntryBufferCount())+"\n";
|
str+= "Log buffer count: " + intToStr(SystemFlags::getLogEntryBufferCount())+"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
str+= "UnitRangeCellsLookupItemCache: " + world.getUnitUpdater()->getUnitRangeCellsLookupItemCacheStats()+"\n";
|
||||||
|
str+= "ExploredCellsLookupItemCache: " + world.getExploredCellsLookupItemCacheStats()+"\n";
|
||||||
|
str+= "FowAlphaCellsLookupItemCache: " + world.getFowAlphaCellsLookupItemCacheStats()+"\n";
|
||||||
|
//str+= "AllFactionsCacheStats: " + world.getAllFactionsCacheStats()+"\n";
|
||||||
|
|
||||||
//str+= "AttackWarningCount: " + intToStr(world.getUnitUpdater()->getAttackWarningCount()) + "\n";
|
//str+= "AttackWarningCount: " + intToStr(world.getUnitUpdater()->getAttackWarningCount()) + "\n";
|
||||||
|
|
||||||
str+= "Map: " + gameSettings.getMap() +"\n";
|
str+= "Map: " + gameSettings.getMap() +"\n";
|
||||||
|
@ -2831,15 +2835,15 @@ void Game::render2d(){
|
||||||
for(int i= 0; i<4; ++i){
|
for(int i= 0; i<4; ++i){
|
||||||
str+= "(" + intToStr(visibleQuad.p[i].x) + "," +intToStr(visibleQuad.p[i].y) + ") ";
|
str+= "(" + intToStr(visibleQuad.p[i].x) + "," +intToStr(visibleQuad.p[i].y) + ") ";
|
||||||
}
|
}
|
||||||
str+= "\n";
|
// str+= "\n";
|
||||||
str+= "Visible quad camera: ";
|
// str+= "Visible quad camera: ";
|
||||||
for(int i= 0; i<4; ++i){
|
// for(int i= 0; i<4; ++i){
|
||||||
str+= "(" + intToStr(visibleQuadCamera.p[i].x) + "," +intToStr(visibleQuadCamera.p[i].y) + ") ";
|
// str+= "(" + intToStr(visibleQuadCamera.p[i].x) + "," +intToStr(visibleQuadCamera.p[i].y) + ") ";
|
||||||
}
|
// }
|
||||||
str+= "\n";
|
str+= "\n";
|
||||||
|
|
||||||
str+= "Visible quad area: " + floatToStr(visibleQuad.area()) +"\n";
|
str+= "Visible quad area: " + floatToStr(visibleQuad.area()) +"\n";
|
||||||
str+= "Visible quad camera area: " + floatToStr(visibleQuadCamera.area()) +"\n";
|
// str+= "Visible quad camera area: " + floatToStr(visibleQuadCamera.area()) +"\n";
|
||||||
|
|
||||||
// Rect2i boundingRect= visibleQuad.computeBoundingRect();
|
// Rect2i boundingRect= visibleQuad.computeBoundingRect();
|
||||||
// Rect2i scaledRect= boundingRect/Map::cellScale;
|
// Rect2i scaledRect= boundingRect/Map::cellScale;
|
||||||
|
@ -2898,7 +2902,7 @@ void Game::render2d(){
|
||||||
if(renderer.getShowDebugUI() == true) {
|
if(renderer.getShowDebugUI() == true) {
|
||||||
const Metrics &metrics= Metrics::getInstance();
|
const Metrics &metrics= Metrics::getInstance();
|
||||||
//int mx= metrics.getMinimapX();
|
//int mx= metrics.getMinimapX();
|
||||||
int my= metrics.getMinimapY();
|
//int my= metrics.getMinimapY();
|
||||||
//int mw= metrics.getMinimapW();
|
//int mw= metrics.getMinimapW();
|
||||||
int mh= metrics.getMinimapH();
|
int mh= metrics.getMinimapH();
|
||||||
const Vec4f fontColor=getGui()->getDisplay()->getColor();
|
const Vec4f fontColor=getGui()->getDisplay()->getColor();
|
||||||
|
|
|
@ -154,13 +154,14 @@ public:
|
||||||
Game(Program *program, const GameSettings *gameSettings, bool masterserverMode);
|
Game(Program *program, const GameSettings *gameSettings, bool masterserverMode);
|
||||||
~Game();
|
~Game();
|
||||||
|
|
||||||
|
bool isMasterserverMode() const { return masterserverMode; }
|
||||||
//get
|
//get
|
||||||
GameSettings *getGameSettings() {return &gameSettings;}
|
GameSettings *getGameSettings() {return &gameSettings;}
|
||||||
void setGameSettings(GameSettings *settings) { gameSettings = *settings;}
|
void setGameSettings(GameSettings *settings) { gameSettings = *settings;}
|
||||||
const GameSettings *getReadOnlyGameSettings() const {return &gameSettings;}
|
const GameSettings *getReadOnlyGameSettings() const {return &gameSettings;}
|
||||||
|
|
||||||
const GameCamera *getGameCamera() const {return &gameCamera;}
|
const GameCamera *getGameCamera() const {return &gameCamera;}
|
||||||
GameCamera *getGameCamera() {return &gameCamera;}
|
GameCamera *getGameCameraPtr() {return &gameCamera;}
|
||||||
const Commander *getCommander() const {return &commander;}
|
const Commander *getCommander() const {return &commander;}
|
||||||
Gui *getGui() {return &gui;}
|
Gui *getGui() {return &gui;}
|
||||||
const Gui *getGui() const {return &gui;}
|
const Gui *getGui() const {return &gui;}
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace Glest { namespace Game {
|
||||||
// class GameCamera
|
// class GameCamera
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
static std::map<float, std::map<float, std::map<Vec3f, Quad2i> > > cacheVisibleQuad;
|
//static std::map<float, std::map<float, std::map<Vec3f, Quad2i> > > cacheVisibleQuad;
|
||||||
|
|
||||||
// ================== PUBLIC =====================
|
// ================== PUBLIC =====================
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ void GameCamera::update(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Quad2i GameCamera::computeVisibleQuad() const {
|
Quad2i GameCamera::computeVisibleQuad() {
|
||||||
//printf("\n@@@ hAng [%f] vAng [%f] fov [%f]\n",hAng,vAng,fov);
|
//printf("\n@@@ hAng [%f] vAng [%f] fov [%f]\n",hAng,vAng,fov);
|
||||||
|
|
||||||
if(MaxVisibleQuadItemCache != 0) {
|
if(MaxVisibleQuadItemCache != 0) {
|
||||||
|
|
|
@ -85,6 +85,7 @@ private:
|
||||||
|
|
||||||
float calculatedDefault;
|
float calculatedDefault;
|
||||||
|
|
||||||
|
std::map<float, std::map<float, std::map<Vec3f, Quad2i> > > cacheVisibleQuad;
|
||||||
int MaxVisibleQuadItemCache;
|
int MaxVisibleQuadItemCache;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -117,7 +118,7 @@ public:
|
||||||
|
|
||||||
//other
|
//other
|
||||||
void update();
|
void update();
|
||||||
Quad2i computeVisibleQuad() const;
|
Quad2i computeVisibleQuad();
|
||||||
void switchState();
|
void switchState();
|
||||||
void resetPosition();
|
void resetPosition();
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,20 @@ const int ScriptManager::messageWrapCount= 30;
|
||||||
const int ScriptManager::displayTextWrapCount= 64;
|
const int ScriptManager::displayTextWrapCount= 64;
|
||||||
|
|
||||||
ScriptManager::ScriptManager() {
|
ScriptManager::ScriptManager() {
|
||||||
|
world = NULL;
|
||||||
|
gameCamera = NULL;
|
||||||
|
lastCreatedUnitId = -1;
|
||||||
|
lastDeadUnitId = 0;
|
||||||
|
lastDeadUnitCauseOfDeath = 0;
|
||||||
|
lastDeadUnitKillerId = 0;
|
||||||
|
lastAttackedUnitId = 0;
|
||||||
|
lastAttackingUnitId = 0;
|
||||||
|
gameOver = false;
|
||||||
|
gameWon = false;
|
||||||
|
currentTimerTriggeredEventId = 0;
|
||||||
|
currentCellTriggeredEventId = 0;
|
||||||
|
currentEventId = 0;
|
||||||
|
inCellTriggerEvent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptManager::~ScriptManager() {
|
ScriptManager::~ScriptManager() {
|
||||||
|
|
|
@ -78,6 +78,10 @@ CoreData::CoreData() {
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreData::~CoreData() {
|
CoreData::~CoreData() {
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreData::cleanup() {
|
||||||
deleteValues(waterSounds.getSoundsPtr()->begin(), waterSounds.getSoundsPtr()->end());
|
deleteValues(waterSounds.getSoundsPtr()->begin(), waterSounds.getSoundsPtr()->end());
|
||||||
waterSounds.getSoundsPtr()->clear();
|
waterSounds.getSoundsPtr()->clear();
|
||||||
}
|
}
|
||||||
|
@ -167,7 +171,7 @@ void CoreData::load() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(logoTextureList.size() == 0) {
|
if(logoTextureList.empty() == true) {
|
||||||
logosPath= data_path + "data/core/menu/textures/logo*.*";
|
logosPath= data_path + "data/core/menu/textures/logo*.*";
|
||||||
vector<string> logoFilenames;
|
vector<string> logoFilenames;
|
||||||
findAll(logosPath, logoFilenames, false, false);
|
findAll(logosPath, logoFilenames, false, false);
|
||||||
|
@ -200,7 +204,7 @@ void CoreData::load() {
|
||||||
}
|
}
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
if(miscTextureList.size() == 0) {
|
if(miscTextureList.empty() == true) {
|
||||||
introPath= data_path + "data/core/menu/textures/intro*.*";
|
introPath= data_path + "data/core/menu/textures/intro*.*";
|
||||||
vector<string> introFilenames;
|
vector<string> introFilenames;
|
||||||
findAll(introPath, introFilenames, false, false);
|
findAll(introPath, introFilenames, false, false);
|
||||||
|
|
|
@ -88,6 +88,7 @@ public:
|
||||||
static CoreData &getInstance();
|
static CoreData &getInstance();
|
||||||
|
|
||||||
void load();
|
void load();
|
||||||
|
void cleanup();
|
||||||
void loadFonts();
|
void loadFonts();
|
||||||
|
|
||||||
Texture2D *getBackgroundTexture() const {return backgroundTexture;}
|
Texture2D *getBackgroundTexture() const {return backgroundTexture;}
|
||||||
|
|
|
@ -300,6 +300,12 @@ void ParticleSystemType::setValues(AttackParticleSystem *ats){
|
||||||
// class ParticleSystemTypeProjectile
|
// class ParticleSystemTypeProjectile
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
|
||||||
|
ParticleSystemTypeProjectile::ParticleSystemTypeProjectile() : ParticleSystemType() {
|
||||||
|
trajectorySpeed = 0.0f;
|
||||||
|
trajectoryScale = 0.0f;
|
||||||
|
trajectoryFrequency = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
void ParticleSystemTypeProjectile::load(const XmlNode* particleFileNode, const string &dir, const string &path,
|
void ParticleSystemTypeProjectile::load(const XmlNode* particleFileNode, const string &dir, const string &path,
|
||||||
RendererInterface *renderer, std::map<string,vector<pair<string, string> > > &loadedFileList,
|
RendererInterface *renderer, std::map<string,vector<pair<string, string> > > &loadedFileList,
|
||||||
string parentLoader, string techtreePath) {
|
string parentLoader, string techtreePath) {
|
||||||
|
@ -373,6 +379,14 @@ ProjectileParticleSystem *ParticleSystemTypeProjectile::create() {
|
||||||
// class ParticleSystemTypeSplash
|
// class ParticleSystemTypeSplash
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
|
||||||
|
ParticleSystemTypeSplash::ParticleSystemTypeSplash() {
|
||||||
|
emissionRateFade = 0.0f;
|
||||||
|
verticalSpreadA = 0.0f;
|
||||||
|
verticalSpreadB = 0.0f;
|
||||||
|
horizontalSpreadA = 0.0f;
|
||||||
|
horizontalSpreadB = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
void ParticleSystemTypeSplash::load(const XmlNode* particleFileNode, const string &dir, const string &path,
|
void ParticleSystemTypeSplash::load(const XmlNode* particleFileNode, const string &dir, const string &path,
|
||||||
RendererInterface *renderer, std::map<string,vector<pair<string, string> > > &loadedFileList,
|
RendererInterface *renderer, std::map<string,vector<pair<string, string> > > &loadedFileList,
|
||||||
string parentLoader, string techtreePath) {
|
string parentLoader, string techtreePath) {
|
||||||
|
|
|
@ -121,6 +121,7 @@ private:
|
||||||
float trajectoryFrequency;
|
float trajectoryFrequency;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
ParticleSystemTypeProjectile();
|
||||||
void load(const XmlNode *particleFileNode, const string &dir, const string &path,
|
void load(const XmlNode *particleFileNode, const string &dir, const string &path,
|
||||||
RendererInterface *renderer, std::map<string,vector<pair<string, string> > > &loadedFileList,
|
RendererInterface *renderer, std::map<string,vector<pair<string, string> > > &loadedFileList,
|
||||||
string parentLoader, string techtreePath);
|
string parentLoader, string techtreePath);
|
||||||
|
@ -134,6 +135,8 @@ public:
|
||||||
|
|
||||||
class ParticleSystemTypeSplash: public ParticleSystemType {
|
class ParticleSystemTypeSplash: public ParticleSystemType {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
ParticleSystemTypeSplash();
|
||||||
void load(const XmlNode *particleFileNode, const string &dir, const string &path,
|
void load(const XmlNode *particleFileNode, const string &dir, const string &path,
|
||||||
RendererInterface *renderer, std::map<string,vector<pair<string, string> > > &loadedFileList,
|
RendererInterface *renderer, std::map<string,vector<pair<string, string> > > &loadedFileList,
|
||||||
string parentLoader, string techtreePath);
|
string parentLoader, string techtreePath);
|
||||||
|
|
|
@ -162,6 +162,7 @@ Renderer::Renderer(bool masterserverMode) : BaseRenderer() {
|
||||||
this->allowRenderUnitTitles = false;
|
this->allowRenderUnitTitles = false;
|
||||||
this->menu = NULL;
|
this->menu = NULL;
|
||||||
this->game = NULL;
|
this->game = NULL;
|
||||||
|
this->gameCamera = NULL;
|
||||||
showDebugUI = false;
|
showDebugUI = false;
|
||||||
showDebugUILevel = debugui_fps;
|
showDebugUILevel = debugui_fps;
|
||||||
modelRenderer = NULL;
|
modelRenderer = NULL;
|
||||||
|
@ -173,6 +174,9 @@ Renderer::Renderer(bool masterserverMode) : BaseRenderer() {
|
||||||
visibleFrameUnitList.clear();
|
visibleFrameUnitList.clear();
|
||||||
visibleFrameUnitListCameraKey = "";
|
visibleFrameUnitListCameraKey = "";
|
||||||
|
|
||||||
|
quadCache = VisibleQuadContainerCache();
|
||||||
|
quadCache.clearFrustrumData();
|
||||||
|
|
||||||
lastRenderFps=MIN_FPS_NORMAL_RENDERING;
|
lastRenderFps=MIN_FPS_NORMAL_RENDERING;
|
||||||
shadowsOffDueToMinRender=false;
|
shadowsOffDueToMinRender=false;
|
||||||
shadowMapHandle=0;
|
shadowMapHandle=0;
|
||||||
|
@ -282,8 +286,12 @@ Renderer::~Renderer() {
|
||||||
cleanupScreenshotThread();
|
cleanupScreenshotThread();
|
||||||
|
|
||||||
mapSurfaceData.clear();
|
mapSurfaceData.clear();
|
||||||
|
quadCache = VisibleQuadContainerCache();
|
||||||
|
quadCache.clearFrustrumData();
|
||||||
|
|
||||||
this->menu = NULL;
|
this->menu = NULL;
|
||||||
this->game = NULL;
|
this->game = NULL;
|
||||||
|
this->gameCamera = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::simpleTask(BaseThread *callingThread) {
|
void Renderer::simpleTask(BaseThread *callingThread) {
|
||||||
|
@ -368,9 +376,10 @@ void Renderer::init() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::initGame(const Game *game){
|
void Renderer::initGame(const Game *game, GameCamera *gameCamera) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
this->gameCamera = gameCamera;
|
||||||
VisibleQuadContainerCache::enableFrustumCalcs = Config::getInstance().getBool("EnableFrustrumCalcs","true");
|
VisibleQuadContainerCache::enableFrustumCalcs = Config::getInstance().getBool("EnableFrustrumCalcs","true");
|
||||||
quadCache = VisibleQuadContainerCache();
|
quadCache = VisibleQuadContainerCache();
|
||||||
quadCache.clearFrustrumData();
|
quadCache.clearFrustrumData();
|
||||||
|
@ -501,6 +510,9 @@ void Renderer::reset3dMenu() {
|
||||||
// ==================== end ====================
|
// ==================== end ====================
|
||||||
|
|
||||||
void Renderer::end() {
|
void Renderer::end() {
|
||||||
|
quadCache = VisibleQuadContainerCache();
|
||||||
|
quadCache.clearFrustrumData();
|
||||||
|
|
||||||
if(Renderer::rendererEnded == true) {
|
if(Renderer::rendererEnded == true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -536,7 +548,10 @@ void Renderer::end() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::endScenario() {
|
void Renderer::endScenario() {
|
||||||
game= NULL;
|
this->game= NULL;
|
||||||
|
this->gameCamera = NULL;
|
||||||
|
quadCache = VisibleQuadContainerCache();
|
||||||
|
quadCache.clearFrustrumData();
|
||||||
|
|
||||||
if(this->masterserverMode == true) {
|
if(this->masterserverMode == true) {
|
||||||
return;
|
return;
|
||||||
|
@ -565,7 +580,8 @@ void Renderer::endScenario() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::endGame(bool isFinalEnd) {
|
void Renderer::endGame(bool isFinalEnd) {
|
||||||
game= NULL;
|
this->game= NULL;
|
||||||
|
this->gameCamera = NULL;
|
||||||
|
|
||||||
quadCache = VisibleQuadContainerCache();
|
quadCache = VisibleQuadContainerCache();
|
||||||
quadCache.clearFrustrumData();
|
quadCache.clearFrustrumData();
|
||||||
|
@ -1287,8 +1303,7 @@ bool Renderer::CubeInFrustum(vector<vector<float> > &frustum, float x, float y,
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::computeVisibleQuad() {
|
void Renderer::computeVisibleQuad() {
|
||||||
const GameCamera *gameCamera = game->getGameCamera();
|
visibleQuad = this->gameCamera->computeVisibleQuad();
|
||||||
visibleQuad = gameCamera->computeVisibleQuad();
|
|
||||||
|
|
||||||
//Matrix4 LookAt( gameCamera->getPos(), gameCamera->getPos(), Vector3 up );
|
//Matrix4 LookAt( gameCamera->getPos(), gameCamera->getPos(), Vector3 up );
|
||||||
//gluLookAt
|
//gluLookAt
|
||||||
|
@ -1391,7 +1406,7 @@ void Renderer::computeVisibleQuad() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if((tl.y > bl.y) || (tr.y > br.y)) {
|
if((tl.y > bl.y) || (tr.y > br.y)) {
|
||||||
visibleQuad = game->getGameCamera()->computeVisibleQuad();
|
visibleQuad = this->gameCamera->computeVisibleQuad();
|
||||||
|
|
||||||
if(debug) printf("Swap Y???\n");
|
if(debug) printf("Swap Y???\n");
|
||||||
|
|
||||||
|
@ -1446,7 +1461,7 @@ void Renderer::computeVisibleQuad() {
|
||||||
catch(PROJECTION_TO_INFINITY e) {
|
catch(PROJECTION_TO_INFINITY e) {
|
||||||
if(debug) printf("hmm staring at the horizon %d\n",(int)e);
|
if(debug) printf("hmm staring at the horizon %d\n",(int)e);
|
||||||
// use historic code solution
|
// use historic code solution
|
||||||
visibleQuad = game->getGameCamera()->computeVisibleQuad();
|
visibleQuad = this->gameCamera->computeVisibleQuad();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5411,7 +5426,7 @@ void Renderer::renderMenuBackground(Camera *camera, float fade, Model *mainModel
|
||||||
}
|
}
|
||||||
|
|
||||||
//characters
|
//characters
|
||||||
if(characterModels.size() > 0) {
|
if(characterModels.empty() == false) {
|
||||||
float dist= characterPosition.dist(cameraPosition);
|
float dist= characterPosition.dist(cameraPosition);
|
||||||
float minDist= 3.f;
|
float minDist= 3.f;
|
||||||
if(dist < minDist) {
|
if(dist < minDist) {
|
||||||
|
|
|
@ -55,6 +55,7 @@ using namespace Shared::PlatformCommon;
|
||||||
//non shared classes
|
//non shared classes
|
||||||
class Config;
|
class Config;
|
||||||
class Game;
|
class Game;
|
||||||
|
class GameCamera;
|
||||||
class MainMenu;
|
class MainMenu;
|
||||||
class Console;
|
class Console;
|
||||||
class MenuBackground;
|
class MenuBackground;
|
||||||
|
@ -67,11 +68,14 @@ class SurfaceCell;
|
||||||
// class MeshCallbackTeamColor
|
// class MeshCallbackTeamColor
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class MeshCallbackTeamColor: public MeshCallback{
|
class MeshCallbackTeamColor: public MeshCallback {
|
||||||
private:
|
private:
|
||||||
const Texture *teamTexture;
|
const Texture *teamTexture;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
MeshCallbackTeamColor() : MeshCallback() {
|
||||||
|
teamTexture = NULL;
|
||||||
|
}
|
||||||
void setTeamTexture(const Texture *teamTexture) {this->teamTexture= teamTexture;}
|
void setTeamTexture(const Texture *teamTexture) {this->teamTexture= teamTexture;}
|
||||||
virtual void execute(const Mesh *mesh);
|
virtual void execute(const Mesh *mesh);
|
||||||
|
|
||||||
|
@ -97,6 +101,7 @@ protected:
|
||||||
frustumData = obj.frustumData;
|
frustumData = obj.frustumData;
|
||||||
proj = obj.proj;
|
proj = obj.proj;
|
||||||
modl = obj.modl;
|
modl = obj.modl;
|
||||||
|
frustumDataCache = obj.frustumDataCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -234,6 +239,7 @@ private:
|
||||||
|
|
||||||
//game
|
//game
|
||||||
const Game *game;
|
const Game *game;
|
||||||
|
GameCamera *gameCamera;
|
||||||
const MainMenu *menu;
|
const MainMenu *menu;
|
||||||
|
|
||||||
//misc
|
//misc
|
||||||
|
@ -379,7 +385,7 @@ public:
|
||||||
|
|
||||||
//init
|
//init
|
||||||
void init();
|
void init();
|
||||||
void initGame(const Game *game);
|
void initGame(const Game *game, GameCamera *gameCamera);
|
||||||
void initMenu(const MainMenu *mm);
|
void initMenu(const MainMenu *mm);
|
||||||
void reset3d();
|
void reset3d();
|
||||||
void reset2d();
|
void reset2d();
|
||||||
|
|
|
@ -124,7 +124,7 @@ Gui::Gui(){
|
||||||
|
|
||||||
void Gui::init(Game *game){
|
void Gui::init(Game *game){
|
||||||
this->commander= game->getCommander();
|
this->commander= game->getCommander();
|
||||||
this->gameCamera= game->getGameCamera();
|
this->gameCamera= game->getGameCameraPtr();
|
||||||
this->console= game->getConsole();
|
this->console= game->getConsole();
|
||||||
this->world= game->getWorld();
|
this->world= game->getWorld();
|
||||||
this->game=game;
|
this->game=game;
|
||||||
|
|
|
@ -28,7 +28,7 @@ class Gui;
|
||||||
/// List of selected units and groups
|
/// List of selected units and groups
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class Selection: public UnitObserver{
|
class Selection: public UnitObserver {
|
||||||
public:
|
public:
|
||||||
typedef vector<Unit*> UnitContainer;
|
typedef vector<Unit*> UnitContainer;
|
||||||
typedef UnitContainer::const_iterator UnitIterator;
|
typedef UnitContainer::const_iterator UnitIterator;
|
||||||
|
@ -45,6 +45,11 @@ private:
|
||||||
Gui *gui;
|
Gui *gui;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Selection() : UnitObserver() {
|
||||||
|
factionIndex = 0;
|
||||||
|
teamIndex = 0;
|
||||||
|
gui = NULL;
|
||||||
|
}
|
||||||
void init(Gui *gui, int factionIndex, int teamIndex);
|
void init(Gui *gui, int factionIndex, int teamIndex);
|
||||||
virtual ~Selection();
|
virtual ~Selection();
|
||||||
|
|
||||||
|
|
|
@ -297,12 +297,18 @@ Intro::Intro(Program *program):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int textureWidth = logoTexture->getTextureWidth();
|
int textureWidth = 256;
|
||||||
|
if(logoTexture != NULL) {
|
||||||
|
textureWidth = logoTexture->getTextureWidth();
|
||||||
|
}
|
||||||
if(lang.hasString(introTagTextureWidthName,"",true) == true) {
|
if(lang.hasString(introTagTextureWidthName,"",true) == true) {
|
||||||
textureWidth = strToInt(lang.get(introTagTextureWidthName,"",true));
|
textureWidth = strToInt(lang.get(introTagTextureWidthName,"",true));
|
||||||
}
|
}
|
||||||
|
|
||||||
int textureHeight = logoTexture->getTextureHeight();
|
int textureHeight = 128;
|
||||||
|
if(logoTexture != NULL) {
|
||||||
|
textureHeight = logoTexture->getTextureHeight();
|
||||||
|
}
|
||||||
if(lang.hasString(introTagTextureHeightName,"",true) == true) {
|
if(lang.hasString(introTagTextureHeightName,"",true) == true) {
|
||||||
textureHeight = strToInt(lang.get(introTagTextureHeightName,"",true));
|
textureHeight = strToInt(lang.get(introTagTextureHeightName,"",true));
|
||||||
}
|
}
|
||||||
|
@ -559,7 +565,7 @@ void Intro::renderModelBackground() {
|
||||||
// Black background
|
// Black background
|
||||||
glClearColor(0, 0, 0, 1);
|
glClearColor(0, 0, 0, 1);
|
||||||
|
|
||||||
if(models.size() > 0) {
|
if(models.empty() == false) {
|
||||||
int difTime= 1000 * timer / GameConstants::updateFps - modelShowTime;
|
int difTime= 1000 * timer / GameConstants::updateFps - modelShowTime;
|
||||||
int totalModelShowTime = Intro::introTime - modelShowTime;
|
int totalModelShowTime = Intro::introTime - modelShowTime;
|
||||||
int individualModelShowTime = totalModelShowTime / models.size();
|
int individualModelShowTime = totalModelShowTime / models.size();
|
||||||
|
@ -569,7 +575,7 @@ void Intro::renderModelBackground() {
|
||||||
//int difTime= 1;
|
//int difTime= 1;
|
||||||
if(difTime > 0) {
|
if(difTime > 0) {
|
||||||
if(difTime > ((modelIndex+1) * individualModelShowTime)) {
|
if(difTime > ((modelIndex+1) * individualModelShowTime)) {
|
||||||
int oldmodelIndex = modelIndex;
|
//int oldmodelIndex = modelIndex;
|
||||||
if(modelIndex+1 < models.size()) {
|
if(modelIndex+1 < models.size()) {
|
||||||
modelIndex++;
|
modelIndex++;
|
||||||
|
|
||||||
|
@ -750,8 +756,8 @@ void Intro::render() {
|
||||||
|
|
||||||
if(Renderer::renderText3DEnabled) {
|
if(Renderer::renderText3DEnabled) {
|
||||||
const Metrics &metrics= Metrics::getInstance();
|
const Metrics &metrics= Metrics::getInstance();
|
||||||
int w= metrics.getVirtualW();
|
//int w= metrics.getVirtualW();
|
||||||
int h= metrics.getVirtualH();
|
//int h= metrics.getVirtualH();
|
||||||
|
|
||||||
renderer.renderText3D(
|
renderer.renderText3D(
|
||||||
timingText, coreData.getMenuFontVeryBig3D(), 1,
|
timingText, coreData.getMenuFontVeryBig3D(), 1,
|
||||||
|
@ -759,8 +765,8 @@ void Intro::render() {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const Metrics &metrics= Metrics::getInstance();
|
const Metrics &metrics= Metrics::getInstance();
|
||||||
int w= metrics.getVirtualW();
|
//int w= metrics.getVirtualW();
|
||||||
int h= metrics.getVirtualH();
|
//int h= metrics.getVirtualH();
|
||||||
|
|
||||||
renderer.renderText(
|
renderer.renderText(
|
||||||
timingText, coreData.getMenuFontVeryBig(), 1,
|
timingText, coreData.getMenuFontVeryBig(), 1,
|
||||||
|
|
|
@ -151,7 +151,11 @@ static void cleanupProcessObjects() {
|
||||||
//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(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(Renderer::isEnded() == false) Renderer::getInstance().end();
|
if(Renderer::isEnded() == false) {
|
||||||
|
Renderer::getInstance().end();
|
||||||
|
CoreData &coreData= CoreData::getInstance();
|
||||||
|
coreData.cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
@ -663,6 +667,7 @@ MainWindow::MainWindow(Program *program) : WindowGl() {
|
||||||
this->popupMenu.setVisible(false);
|
this->popupMenu.setVisible(false);
|
||||||
this->triggerLanguageToggle = false;
|
this->triggerLanguageToggle = false;
|
||||||
this->triggerLanguage = "";
|
this->triggerLanguage = "";
|
||||||
|
this->cancelLanguageSelection = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow(){
|
MainWindow::~MainWindow(){
|
||||||
|
@ -2850,7 +2855,7 @@ int glestMain(int argc, char** argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE])) == true) {
|
if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE])) == true) {
|
||||||
Renderer &renderer= Renderer::getInstance(true);
|
Renderer::getInstance(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_USE_PORTS]) == true) {
|
if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_USE_PORTS]) == true) {
|
||||||
|
@ -3212,7 +3217,7 @@ int glestMain(int argc, char** argv) {
|
||||||
string autoloadMapName = paramPartTokens[1];
|
string autoloadMapName = paramPartTokens[1];
|
||||||
|
|
||||||
GameSettings *gameSettings = &startupGameSettings;
|
GameSettings *gameSettings = &startupGameSettings;
|
||||||
int factionCount= 0;
|
//int factionCount= 0;
|
||||||
gameSettings->setMap(autoloadMapName);
|
gameSettings->setMap(autoloadMapName);
|
||||||
gameSettings->setTileset("forest");
|
gameSettings->setTileset("forest");
|
||||||
gameSettings->setTech("megapack");
|
gameSettings->setTech("megapack");
|
||||||
|
|
|
@ -82,7 +82,7 @@ bool ProgramState::canRender(bool sleepIfCannotRender) {
|
||||||
if(lastFps > maxFPSCap) {
|
if(lastFps > maxFPSCap) {
|
||||||
if(sleepIfCannotRender == true) {
|
if(sleepIfCannotRender == true) {
|
||||||
sleep(sleepMillis);
|
sleep(sleepMillis);
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] sleeping because lastFps = %d, maxFPSCap = %d sleepMillis = %d\n",__FILE__,__FUNCTION__,__LINE__,lastFps,maxFPSCap,sleepMillis);
|
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] sleeping because lastFps = %d, maxFPSCap = %d sleepMillis = %d\n",__FILE__,__FUNCTION__,__LINE__,lastFps,maxFPSCap,sleepMillis);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -246,6 +246,8 @@ Program::~Program(){
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
Renderer::getInstance().end();
|
Renderer::getInstance().end();
|
||||||
|
CoreData &coreData= CoreData::getInstance();
|
||||||
|
coreData.cleanup();
|
||||||
|
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
|
||||||
int aHeadPos=240;
|
int aHeadPos=240;
|
||||||
int aPos=aHeadPos-labelOffset;
|
int aPos=aHeadPos-labelOffset;
|
||||||
int networkHeadPos=700;
|
int networkHeadPos=700;
|
||||||
int networkPos=networkHeadPos-labelOffset;
|
//int networkPos=networkHeadPos-labelOffset;
|
||||||
int xoffset=0;
|
int xoffset=0;
|
||||||
|
|
||||||
//state
|
//state
|
||||||
|
@ -1100,8 +1100,8 @@ void MenuStateConnectedGame::updateResourceMultiplier(const int index) {
|
||||||
void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButton) {
|
void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButton) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CoreData &coreData= CoreData::getInstance();
|
//CoreData &coreData= CoreData::getInstance();
|
||||||
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
//SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
||||||
//int oldListBoxMapfilterIndex=listBoxMapFilter.getSelectedItemIndex();
|
//int oldListBoxMapfilterIndex=listBoxMapFilter.getSelectedItemIndex();
|
||||||
|
|
||||||
if(buttonPlayNow.mouseClick(x,y) && buttonPlayNow.getEnabled()) {
|
if(buttonPlayNow.mouseClick(x,y) && buttonPlayNow.getEnabled()) {
|
||||||
|
@ -1316,7 +1316,7 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//ensure thet only 1 human player is present
|
//ensure thet only 1 human player is present
|
||||||
int oldSelectedIndex = listBoxControls[i].getSelectedItemIndex();
|
//int oldSelectedIndex = listBoxControls[i].getSelectedItemIndex();
|
||||||
if(clientInterface != NULL && clientInterface->getGameSettings() != NULL &&
|
if(clientInterface != NULL && clientInterface->getGameSettings() != NULL &&
|
||||||
clientInterface->getGameSettings()->getStartLocationIndex(clientInterface->getGameSettings()->getThisFactionIndex()) != i &&
|
clientInterface->getGameSettings()->getStartLocationIndex(clientInterface->getGameSettings()->getThisFactionIndex()) != i &&
|
||||||
listBoxControls[i].mouseClick(x, y)) {
|
listBoxControls[i].mouseClick(x, y)) {
|
||||||
|
@ -3708,7 +3708,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName,
|
||||||
// Reload tilesets for the UI
|
// Reload tilesets for the UI
|
||||||
findDirs(Config::getInstance().getPathListForType(ptTechs), techTreeFiles);
|
findDirs(Config::getInstance().getPathListForType(ptTechs), techTreeFiles);
|
||||||
|
|
||||||
int initialTechSelection=0;
|
//int initialTechSelection=0;
|
||||||
std::vector<string> techsFormatted = techTreeFiles;
|
std::vector<string> techsFormatted = techTreeFiles;
|
||||||
for(int i= 0; i < techsFormatted.size(); i++){
|
for(int i= 0; i < techsFormatted.size(); i++){
|
||||||
techsFormatted.at(i)= formatString(techsFormatted.at(i));
|
techsFormatted.at(i)= formatString(techsFormatted.at(i));
|
||||||
|
|
|
@ -1682,7 +1682,7 @@ void MenuStateCustomGame::render() {
|
||||||
// START - this code ensure player title and player names don't overlap
|
// START - this code ensure player title and player names don't overlap
|
||||||
int offsetPosition=0;
|
int offsetPosition=0;
|
||||||
for(int i=0; i < GameConstants::maxPlayers; ++i) {
|
for(int i=0; i < GameConstants::maxPlayers; ++i) {
|
||||||
const Metrics &metrics= Metrics::getInstance();
|
//const Metrics &metrics= Metrics::getInstance();
|
||||||
FontMetrics *fontMetrics= NULL;
|
FontMetrics *fontMetrics= NULL;
|
||||||
if(Renderer::renderText3DEnabled == false) {
|
if(Renderer::renderText3DEnabled == false) {
|
||||||
fontMetrics = labelPlayers[i].getFont()->getMetrics();
|
fontMetrics = labelPlayers[i].getFont()->getMetrics();
|
||||||
|
|
|
@ -134,7 +134,7 @@ void MenuStateGraphicInfo::mouseMove(int x, int y, const MouseState *ms){
|
||||||
void MenuStateGraphicInfo::render(){
|
void MenuStateGraphicInfo::render(){
|
||||||
|
|
||||||
Renderer &renderer= Renderer::getInstance();
|
Renderer &renderer= Renderer::getInstance();
|
||||||
Lang &lang= Lang::getInstance();
|
//Lang &lang= Lang::getInstance();
|
||||||
|
|
||||||
renderer.renderButton(&buttonReturn);
|
renderer.renderButton(&buttonReturn);
|
||||||
renderer.renderLabel(&labelInfo);
|
renderer.renderLabel(&labelInfo);
|
||||||
|
|
|
@ -957,7 +957,7 @@ string MenuStateMods::refreshMapModInfo(string mapInfo) {
|
||||||
std::vector<std::string> mapInfoList;
|
std::vector<std::string> mapInfoList;
|
||||||
Tokenize(mapInfo,mapInfoList,"|");
|
Tokenize(mapInfo,mapInfoList,"|");
|
||||||
if(mapInfoList.size() >= 5) {
|
if(mapInfoList.size() >= 5) {
|
||||||
Config &config = Config::getInstance();
|
//Config &config = Config::getInstance();
|
||||||
ModInfo modinfo;
|
ModInfo modinfo;
|
||||||
modinfo.name = mapInfoList[0];
|
modinfo.name = mapInfoList[0];
|
||||||
modinfo.count = mapInfoList[1];
|
modinfo.count = mapInfoList[1];
|
||||||
|
@ -977,7 +977,7 @@ string MenuStateMods::getMapCRC(string mapName) {
|
||||||
Config &config = Config::getInstance();
|
Config &config = Config::getInstance();
|
||||||
vector<string> mappaths=config.getPathListForType(ptMaps,"");
|
vector<string> mappaths=config.getPathListForType(ptMaps,"");
|
||||||
string result="";
|
string result="";
|
||||||
if(mappaths.size()>0 ){
|
if(mappaths.empty() == false) {
|
||||||
Checksum checksum;
|
Checksum checksum;
|
||||||
string itemPath = mappaths[1] + "/" + mapName;
|
string itemPath = mappaths[1] + "/" + mapName;
|
||||||
if (fileExists(itemPath)){
|
if (fileExists(itemPath)){
|
||||||
|
|
|
@ -33,6 +33,7 @@ namespace Glest{ namespace Game{
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
ConnectionSlotThread::ConnectionSlotThread(int slotIndex) : BaseThread() {
|
ConnectionSlotThread::ConnectionSlotThread(int slotIndex) : BaseThread() {
|
||||||
|
this->triggerIdMutex = new Mutex();
|
||||||
this->slotIndex = slotIndex;
|
this->slotIndex = slotIndex;
|
||||||
this->slotInterface = NULL;
|
this->slotInterface = NULL;
|
||||||
//this->event = NULL;
|
//this->event = NULL;
|
||||||
|
@ -41,12 +42,18 @@ ConnectionSlotThread::ConnectionSlotThread(int slotIndex) : BaseThread() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionSlotThread::ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface,int slotIndex) : BaseThread() {
|
ConnectionSlotThread::ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface,int slotIndex) : BaseThread() {
|
||||||
|
this->triggerIdMutex = new Mutex();
|
||||||
this->slotIndex = slotIndex;
|
this->slotIndex = slotIndex;
|
||||||
this->slotInterface = slotInterface;
|
this->slotInterface = slotInterface;
|
||||||
//this->event = NULL;
|
//this->event = NULL;
|
||||||
eventList.clear();
|
eventList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConnectionSlotThread::~ConnectionSlotThread() {
|
||||||
|
delete triggerIdMutex;
|
||||||
|
triggerIdMutex = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void ConnectionSlotThread::setQuitStatus(bool value) {
|
void ConnectionSlotThread::setQuitStatus(bool value) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d value = %d\n",__FILE__,__FUNCTION__,__LINE__,value);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d value = %d\n",__FILE__,__FUNCTION__,__LINE__,value);
|
||||||
|
|
||||||
|
@ -60,7 +67,7 @@ void ConnectionSlotThread::setQuitStatus(bool value) {
|
||||||
|
|
||||||
void ConnectionSlotThread::signalUpdate(ConnectionSlotEvent *event) {
|
void ConnectionSlotThread::signalUpdate(ConnectionSlotEvent *event) {
|
||||||
if(event != NULL) {
|
if(event != NULL) {
|
||||||
MutexSafeWrapper safeMutex(&triggerIdMutex,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(triggerIdMutex,CODE_AT_LINE);
|
||||||
eventList.push_back(*event);
|
eventList.push_back(*event);
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
}
|
}
|
||||||
|
@ -69,7 +76,7 @@ void ConnectionSlotThread::signalUpdate(ConnectionSlotEvent *event) {
|
||||||
|
|
||||||
void ConnectionSlotThread::setTaskCompleted(int eventId) {
|
void ConnectionSlotThread::setTaskCompleted(int eventId) {
|
||||||
if(eventId > 0) {
|
if(eventId > 0) {
|
||||||
MutexSafeWrapper safeMutex(&triggerIdMutex,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(triggerIdMutex,CODE_AT_LINE);
|
||||||
//event->eventCompleted = true;
|
//event->eventCompleted = true;
|
||||||
for(int i = 0; i < eventList.size(); ++i) {
|
for(int i = 0; i < eventList.size(); ++i) {
|
||||||
ConnectionSlotEvent &slotEvent = eventList[i];
|
ConnectionSlotEvent &slotEvent = eventList[i];
|
||||||
|
@ -84,13 +91,13 @@ void ConnectionSlotThread::setTaskCompleted(int eventId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionSlotThread::purgeAllEvents() {
|
void ConnectionSlotThread::purgeAllEvents() {
|
||||||
MutexSafeWrapper safeMutex(&triggerIdMutex,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(triggerIdMutex,CODE_AT_LINE);
|
||||||
eventList.clear();
|
eventList.clear();
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionSlotThread::setAllEventsCompleted() {
|
void ConnectionSlotThread::setAllEventsCompleted() {
|
||||||
MutexSafeWrapper safeMutex(&triggerIdMutex,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(triggerIdMutex,CODE_AT_LINE);
|
||||||
for(int i = 0; i < eventList.size(); ++i) {
|
for(int i = 0; i < eventList.size(); ++i) {
|
||||||
ConnectionSlotEvent &slotEvent = eventList[i];
|
ConnectionSlotEvent &slotEvent = eventList[i];
|
||||||
if(slotEvent.eventCompleted == false) {
|
if(slotEvent.eventCompleted == false) {
|
||||||
|
@ -101,7 +108,7 @@ void ConnectionSlotThread::setAllEventsCompleted() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionSlotThread::purgeCompletedEvents() {
|
void ConnectionSlotThread::purgeCompletedEvents() {
|
||||||
MutexSafeWrapper safeMutex(&triggerIdMutex,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(triggerIdMutex,CODE_AT_LINE);
|
||||||
//event->eventCompleted = true;
|
//event->eventCompleted = true;
|
||||||
for(int i = eventList.size() - 1; i >= 0; i--) {
|
for(int i = eventList.size() - 1; i >= 0; i--) {
|
||||||
ConnectionSlotEvent &slotEvent = eventList[i];
|
ConnectionSlotEvent &slotEvent = eventList[i];
|
||||||
|
@ -123,7 +130,7 @@ bool ConnectionSlotThread::canShutdown(bool deleteSelfIfShutdownDelayed) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConnectionSlotThread::isSignalCompleted(ConnectionSlotEvent *event) {
|
bool ConnectionSlotThread::isSignalCompleted(ConnectionSlotEvent *event) {
|
||||||
MutexSafeWrapper safeMutex(&triggerIdMutex,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(triggerIdMutex,CODE_AT_LINE);
|
||||||
bool result = false;
|
bool result = false;
|
||||||
if(event != NULL) {
|
if(event != NULL) {
|
||||||
for(int i = 0; i < eventList.size(); ++i) {
|
for(int i = 0; i < eventList.size(); ++i) {
|
||||||
|
@ -177,7 +184,7 @@ void ConnectionSlotThread::execute() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(&triggerIdMutex,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(triggerIdMutex,CODE_AT_LINE);
|
||||||
int eventCount = eventList.size();
|
int eventCount = eventList.size();
|
||||||
if(eventCount > 0) {
|
if(eventCount > 0) {
|
||||||
ConnectionSlotEvent eventCopy;
|
ConnectionSlotEvent eventCopy;
|
||||||
|
@ -233,9 +240,12 @@ void ConnectionSlotThread::execute() {
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex) {
|
ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex) {
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
this->mutexSocket = new Mutex();
|
||||||
|
this->mutexCloseConnection = new Mutex();
|
||||||
|
this->mutexPendingNetworkCommandList = new Mutex();
|
||||||
|
this->socketSynchAccessor = new Mutex();
|
||||||
this->connectedRemoteIPAddress = 0;
|
this->connectedRemoteIPAddress = 0;
|
||||||
this->sessionKey = 0;
|
this->sessionKey = 0;
|
||||||
this->serverInterface = serverInterface;
|
this->serverInterface = serverInterface;
|
||||||
|
@ -283,6 +293,18 @@ ConnectionSlot::~ConnectionSlot() {
|
||||||
}
|
}
|
||||||
slotThreadWorker = NULL;
|
slotThreadWorker = NULL;
|
||||||
|
|
||||||
|
delete socketSynchAccessor;
|
||||||
|
socketSynchAccessor = NULL;
|
||||||
|
|
||||||
|
delete mutexPendingNetworkCommandList;
|
||||||
|
mutexPendingNetworkCommandList = NULL;
|
||||||
|
|
||||||
|
delete mutexCloseConnection;
|
||||||
|
mutexCloseConnection = NULL;
|
||||||
|
|
||||||
|
delete mutexSocket;
|
||||||
|
mutexSocket = NULL;
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,7 +394,7 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
|
||||||
|
|
||||||
//printf("Got new connection for slot = %d\n",playerIndex);
|
//printf("Got new connection for slot = %d\n",playerIndex);
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(&mutexCloseConnection,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(mutexCloseConnection,CODE_AT_LINE);
|
||||||
this->setSocket(newSocket);
|
this->setSocket(newSocket);
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
|
@ -390,7 +412,7 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
|
||||||
|
|
||||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
|
|
||||||
MutexSafeWrapper safeMutexSlot1(&mutexPendingNetworkCommandList,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot1(mutexPendingNetworkCommandList,CODE_AT_LINE);
|
||||||
this->vctPendingNetworkCommandList.clear();
|
this->vctPendingNetworkCommandList.clear();
|
||||||
safeMutexSlot1.ReleaseLock();
|
safeMutexSlot1.ReleaseLock();
|
||||||
|
|
||||||
|
@ -545,7 +567,7 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
|
||||||
lastReceiveCommandListTime = time(NULL);
|
lastReceiveCommandListTime = time(NULL);
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] currentFrameCount = %d\n",__FILE__,__FUNCTION__,__LINE__,currentFrameCount);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] currentFrameCount = %d\n",__FILE__,__FUNCTION__,__LINE__,currentFrameCount);
|
||||||
|
|
||||||
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(mutexPendingNetworkCommandList,CODE_AT_LINE);
|
||||||
for(int i = 0; i < networkMessageCommandList.getCommandCount(); ++i) {
|
for(int i = 0; i < networkMessageCommandList.getCommandCount(); ++i) {
|
||||||
vctPendingNetworkCommandList.push_back(*networkMessageCommandList.getCommand(i));
|
vctPendingNetworkCommandList.push_back(*networkMessageCommandList.getCommand(i));
|
||||||
}
|
}
|
||||||
|
@ -1026,7 +1048,7 @@ void ConnectionSlot::close() {
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(&mutexCloseConnection,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(mutexCloseConnection,CODE_AT_LINE);
|
||||||
|
|
||||||
bool updateServerListener = (this->getSocket() != NULL);
|
bool updateServerListener = (this->getSocket() != NULL);
|
||||||
this->deleteSocket();
|
this->deleteSocket();
|
||||||
|
@ -1066,7 +1088,7 @@ bool ConnectionSlot::updateCompleted(ConnectionSlotEvent *event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionSlot::sendMessage(const NetworkMessage* networkMessage) {
|
void ConnectionSlot::sendMessage(const NetworkMessage* networkMessage) {
|
||||||
MutexSafeWrapper safeMutex(&socketSynchAccessor,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(socketSynchAccessor,CODE_AT_LINE);
|
||||||
|
|
||||||
// Skip text messages not intended for the players preferred language
|
// Skip text messages not intended for the players preferred language
|
||||||
const NetworkMessageText *textMsg = dynamic_cast<const NetworkMessageText *>(networkMessage);
|
const NetworkMessageText *textMsg = dynamic_cast<const NetworkMessageText *>(networkMessage);
|
||||||
|
@ -1088,7 +1110,7 @@ string ConnectionSlot::getHumanPlayerName(int index) {
|
||||||
|
|
||||||
vector<NetworkCommand> ConnectionSlot::getPendingNetworkCommandList(bool clearList) {
|
vector<NetworkCommand> ConnectionSlot::getPendingNetworkCommandList(bool clearList) {
|
||||||
vector<NetworkCommand> ret;
|
vector<NetworkCommand> ret;
|
||||||
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(mutexPendingNetworkCommandList,CODE_AT_LINE);
|
||||||
if(vctPendingNetworkCommandList.empty() == false) {
|
if(vctPendingNetworkCommandList.empty() == false) {
|
||||||
ret = vctPendingNetworkCommandList;
|
ret = vctPendingNetworkCommandList;
|
||||||
if(clearList == true) {
|
if(clearList == true) {
|
||||||
|
@ -1101,7 +1123,7 @@ vector<NetworkCommand> ConnectionSlot::getPendingNetworkCommandList(bool clearLi
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionSlot::clearPendingNetworkCommandList() {
|
void ConnectionSlot::clearPendingNetworkCommandList() {
|
||||||
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(mutexPendingNetworkCommandList,CODE_AT_LINE);
|
||||||
if(vctPendingNetworkCommandList.empty() == false) {
|
if(vctPendingNetworkCommandList.empty() == false) {
|
||||||
vctPendingNetworkCommandList.clear();
|
vctPendingNetworkCommandList.clear();
|
||||||
}
|
}
|
||||||
|
@ -1112,7 +1134,7 @@ bool ConnectionSlot::hasValidSocketId() {
|
||||||
//bool result = (this->getSocket() != NULL && this->getSocket()->getSocketId() > 0);
|
//bool result = (this->getSocket() != NULL && this->getSocket()->getSocketId() > 0);
|
||||||
//return result;
|
//return result;
|
||||||
bool result = false;
|
bool result = false;
|
||||||
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(mutexSocket,CODE_AT_LINE);
|
||||||
if(socket != NULL && socket->getSocketId() > 0) {
|
if(socket != NULL && socket->getSocketId() > 0) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
@ -1122,7 +1144,7 @@ bool ConnectionSlot::hasValidSocketId() {
|
||||||
|
|
||||||
bool ConnectionSlot::isConnected() {
|
bool ConnectionSlot::isConnected() {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(mutexSocket,CODE_AT_LINE);
|
||||||
if(socket != NULL && socket->isConnected() == true) {
|
if(socket != NULL && socket->isConnected() == true) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
@ -1131,7 +1153,7 @@ bool ConnectionSlot::isConnected() {
|
||||||
|
|
||||||
PLATFORM_SOCKET ConnectionSlot::getSocketId() {
|
PLATFORM_SOCKET ConnectionSlot::getSocketId() {
|
||||||
PLATFORM_SOCKET result = 0;
|
PLATFORM_SOCKET result = 0;
|
||||||
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(mutexSocket,CODE_AT_LINE);
|
||||||
if(socket != NULL) {
|
if(socket != NULL) {
|
||||||
result = socket->getSocketId();
|
result = socket->getSocketId();
|
||||||
}
|
}
|
||||||
|
@ -1140,7 +1162,7 @@ PLATFORM_SOCKET ConnectionSlot::getSocketId() {
|
||||||
|
|
||||||
pair<bool,Socket*> ConnectionSlot::getSocketInfo() {
|
pair<bool,Socket*> ConnectionSlot::getSocketInfo() {
|
||||||
pair<bool,Socket*> result;
|
pair<bool,Socket*> result;
|
||||||
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(mutexSocket,CODE_AT_LINE);
|
||||||
result.first = (socket != NULL && socket->isConnected());
|
result.first = (socket != NULL && socket->isConnected());
|
||||||
result.second = socket;
|
result.second = socket;
|
||||||
|
|
||||||
|
@ -1151,25 +1173,25 @@ pair<bool,Socket*> ConnectionSlot::getSocketInfo() {
|
||||||
Socket* ConnectionSlot::getSocket(bool mutexLock) {
|
Socket* ConnectionSlot::getSocket(bool mutexLock) {
|
||||||
MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE);
|
||||||
if(mutexLock == true) {
|
if(mutexLock == true) {
|
||||||
safeMutexSlot.setMutex(&mutexSocket,CODE_AT_LINE);
|
safeMutexSlot.setMutex(mutexSocket,CODE_AT_LINE);
|
||||||
}
|
}
|
||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionSlot::setSocket(Socket *newSocket) {
|
void ConnectionSlot::setSocket(Socket *newSocket) {
|
||||||
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(mutexSocket,CODE_AT_LINE);
|
||||||
socket = newSocket;
|
socket = newSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionSlot::deleteSocket() {
|
void ConnectionSlot::deleteSocket() {
|
||||||
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(mutexSocket,CODE_AT_LINE);
|
||||||
delete socket;
|
delete socket;
|
||||||
socket = NULL;
|
socket = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConnectionSlot::hasDataToRead() {
|
bool ConnectionSlot::hasDataToRead() {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(mutexSocket,CODE_AT_LINE);
|
||||||
|
|
||||||
if(socket != NULL && socket->hasDataToRead() == true) {
|
if(socket != NULL && socket->hasDataToRead() == true) {
|
||||||
result = true;
|
result = true;
|
||||||
|
|
|
@ -75,7 +75,7 @@ protected:
|
||||||
|
|
||||||
ConnectionSlotCallbackInterface *slotInterface;
|
ConnectionSlotCallbackInterface *slotInterface;
|
||||||
Semaphore semTaskSignalled;
|
Semaphore semTaskSignalled;
|
||||||
Mutex triggerIdMutex;
|
Mutex *triggerIdMutex;
|
||||||
vector<ConnectionSlotEvent> eventList;
|
vector<ConnectionSlotEvent> eventList;
|
||||||
int slotIndex;
|
int slotIndex;
|
||||||
|
|
||||||
|
@ -88,6 +88,8 @@ protected:
|
||||||
public:
|
public:
|
||||||
ConnectionSlotThread(int slotIndex);
|
ConnectionSlotThread(int slotIndex);
|
||||||
ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface,int slotIndex);
|
ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface,int slotIndex);
|
||||||
|
virtual ~ConnectionSlotThread();
|
||||||
|
|
||||||
virtual void execute();
|
virtual void execute();
|
||||||
void signalUpdate(ConnectionSlotEvent *event);
|
void signalUpdate(ConnectionSlotEvent *event);
|
||||||
bool isSignalCompleted(ConnectionSlotEvent *event);
|
bool isSignalCompleted(ConnectionSlotEvent *event);
|
||||||
|
@ -106,7 +108,7 @@ class ConnectionSlot: public NetworkInterface {
|
||||||
private:
|
private:
|
||||||
ServerInterface* serverInterface;
|
ServerInterface* serverInterface;
|
||||||
|
|
||||||
Mutex mutexSocket;
|
Mutex *mutexSocket;
|
||||||
Socket* socket;
|
Socket* socket;
|
||||||
int playerIndex;
|
int playerIndex;
|
||||||
string name;
|
string name;
|
||||||
|
@ -116,9 +118,9 @@ private:
|
||||||
time_t connectedTime;
|
time_t connectedTime;
|
||||||
bool gotIntro;
|
bool gotIntro;
|
||||||
|
|
||||||
Mutex mutexCloseConnection;
|
Mutex *mutexCloseConnection;
|
||||||
|
|
||||||
Mutex mutexPendingNetworkCommandList;
|
Mutex *mutexPendingNetworkCommandList;
|
||||||
vector<NetworkCommand> vctPendingNetworkCommandList;
|
vector<NetworkCommand> vctPendingNetworkCommandList;
|
||||||
ConnectionSlotThread* slotThreadWorker;
|
ConnectionSlotThread* slotThreadWorker;
|
||||||
int currentFrameCount;
|
int currentFrameCount;
|
||||||
|
@ -199,7 +201,7 @@ protected:
|
||||||
|
|
||||||
Mutex * getServerSynchAccessor();
|
Mutex * getServerSynchAccessor();
|
||||||
std::vector<std::string> threadErrorList;
|
std::vector<std::string> threadErrorList;
|
||||||
Mutex socketSynchAccessor;
|
Mutex *socketSynchAccessor;
|
||||||
|
|
||||||
void setSocket(Socket *newSocket);
|
void setSocket(Socket *newSocket);
|
||||||
void deleteSocket();
|
void deleteSocket();
|
||||||
|
|
|
@ -402,7 +402,7 @@ void NetworkMessageCommandList::send(Socket* socket) const {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) 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);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) 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);
|
assert(data.header.messageType==nmtCommandList);
|
||||||
int totalMsgSize = commandListHeaderSize + (sizeof(NetworkCommand) * data.header.commandCount);
|
//int totalMsgSize = commandListHeaderSize + (sizeof(NetworkCommand) * data.header.commandCount);
|
||||||
//NetworkMessage::send(socket, &data, totalMsgSize);
|
//NetworkMessage::send(socket, &data, totalMsgSize);
|
||||||
NetworkMessage::send(socket, &data.header, commandListHeaderSize);
|
NetworkMessage::send(socket, &data.header, commandListHeaderSize);
|
||||||
if(data.header.commandCount > 0) {
|
if(data.header.commandCount > 0) {
|
||||||
|
|
|
@ -47,6 +47,15 @@ const int MASTERSERVER_HEARTBEAT_GAME_STATUS_SECONDS = 30;
|
||||||
ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() {
|
ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
serverSynchAccessor = new Mutex();
|
||||||
|
for(int i= 0; i < GameConstants::maxPlayers; ++i) {
|
||||||
|
slotAccessorMutexes[i] = new Mutex();
|
||||||
|
}
|
||||||
|
masterServerThreadAccessor = new Mutex();
|
||||||
|
textMessageQueueThreadAccessor = new Mutex();
|
||||||
|
broadcastMessageQueueThreadAccessor = new Mutex();
|
||||||
|
inBroadcastMessageThreadAccessor = new Mutex();
|
||||||
|
|
||||||
nextEventId = 1;
|
nextEventId = 1;
|
||||||
gameHasBeenInitiated = false;
|
gameHasBeenInitiated = false;
|
||||||
exitServer = false;
|
exitServer = false;
|
||||||
|
@ -169,7 +178,7 @@ ServerInterface::~ServerInterface() {
|
||||||
exitServer = true;
|
exitServer = true;
|
||||||
for(int i= 0; i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; i < GameConstants::maxPlayers; ++i) {
|
||||||
if(slots[i] != NULL) {
|
if(slots[i] != NULL) {
|
||||||
MutexSafeWrapper safeMutex(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutex(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
delete slots[i];
|
delete slots[i];
|
||||||
slots[i]=NULL;
|
slots[i]=NULL;
|
||||||
}
|
}
|
||||||
|
@ -187,7 +196,7 @@ ServerInterface::~ServerInterface() {
|
||||||
delete ftpServer;
|
delete ftpServer;
|
||||||
ftpServer = NULL;
|
ftpServer = NULL;
|
||||||
}
|
}
|
||||||
MutexSafeWrapper safeMutex(&masterServerThreadAccessor,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(masterServerThreadAccessor,CODE_AT_LINE);
|
||||||
delete publishToMasterserverThread;
|
delete publishToMasterserverThread;
|
||||||
publishToMasterserverThread = NULL;
|
publishToMasterserverThread = NULL;
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
|
@ -196,6 +205,27 @@ ServerInterface::~ServerInterface() {
|
||||||
if(needToRepublishToMasterserver == true) {
|
if(needToRepublishToMasterserver == true) {
|
||||||
simpleTask(NULL);
|
simpleTask(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(int i= 0; i < GameConstants::maxPlayers; ++i) {
|
||||||
|
delete slotAccessorMutexes[i];
|
||||||
|
slotAccessorMutexes[i] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete textMessageQueueThreadAccessor;
|
||||||
|
textMessageQueueThreadAccessor = NULL;
|
||||||
|
|
||||||
|
delete broadcastMessageQueueThreadAccessor;
|
||||||
|
broadcastMessageQueueThreadAccessor = NULL;
|
||||||
|
|
||||||
|
delete inBroadcastMessageThreadAccessor;
|
||||||
|
inBroadcastMessageThreadAccessor = NULL;
|
||||||
|
|
||||||
|
delete serverSynchAccessor;
|
||||||
|
serverSynchAccessor = NULL;
|
||||||
|
|
||||||
|
delete masterServerThreadAccessor;
|
||||||
|
masterServerThreadAccessor = NULL;
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +233,7 @@ int ServerInterface::isValidClientType(uint32 clientIp) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
if(slots[i] != NULL) {
|
if(slots[i] != NULL) {
|
||||||
MutexSafeWrapper safeMutex(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutex(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
|
|
||||||
Socket *socket = slots[i]->getSocket();
|
Socket *socket = slots[i]->getSocket();
|
||||||
if(socket != NULL) {
|
if(socket != NULL) {
|
||||||
|
@ -275,14 +305,14 @@ void ServerInterface::addClientToServerIPAddress(uint32 clientIp, uint32 ServerI
|
||||||
void ServerInterface::addSlot(int playerIndex) {
|
void ServerInterface::addSlot(int playerIndex) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
assert(playerIndex >= 0 && playerIndex < GameConstants::maxPlayers);
|
assert(playerIndex >= 0 && playerIndex < GameConstants::maxPlayers);
|
||||||
MutexSafeWrapper safeMutex(&serverSynchAccessor,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(serverSynchAccessor,CODE_AT_LINE);
|
||||||
if(serverSocket.isPortBound() == false) {
|
if(serverSocket.isPortBound() == false) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
serverSocket.bind(serverSocket.getBindPort());
|
serverSocket.bind(serverSocket.getBindPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(playerIndex));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(playerIndex));
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
ConnectionSlot *slot = slots[playerIndex];
|
ConnectionSlot *slot = slots[playerIndex];
|
||||||
if(slot != NULL) {
|
if(slot != NULL) {
|
||||||
|
@ -308,9 +338,9 @@ bool ServerInterface::switchSlot(int fromPlayerIndex, int toPlayerIndex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(&serverSynchAccessor,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(serverSynchAccessor,CODE_AT_LINE);
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[fromPlayerIndex],CODE_AT_LINE_X(fromPlayerIndex));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[fromPlayerIndex],CODE_AT_LINE_X(fromPlayerIndex));
|
||||||
MutexSafeWrapper safeMutexSlot2(&slotAccessorMutexes[toPlayerIndex],CODE_AT_LINE_X(toPlayerIndex));
|
MutexSafeWrapper safeMutexSlot2(slotAccessorMutexes[toPlayerIndex],CODE_AT_LINE_X(toPlayerIndex));
|
||||||
if(slots[toPlayerIndex] != NULL && slots[toPlayerIndex] != NULL &&
|
if(slots[toPlayerIndex] != NULL && slots[toPlayerIndex] != NULL &&
|
||||||
slots[toPlayerIndex]->isConnected() == false) {
|
slots[toPlayerIndex]->isConnected() == false) {
|
||||||
slots[fromPlayerIndex]->setPlayerIndex(toPlayerIndex);
|
slots[fromPlayerIndex]->setPlayerIndex(toPlayerIndex);
|
||||||
|
@ -338,11 +368,11 @@ bool ServerInterface::switchSlot(int fromPlayerIndex, int toPlayerIndex) {
|
||||||
void ServerInterface::removeSlot(int playerIndex, int lockedSlotIndex) {
|
void ServerInterface::removeSlot(int playerIndex, int lockedSlotIndex) {
|
||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex);
|
||||||
MutexSafeWrapper safeMutex(&serverSynchAccessor,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(serverSynchAccessor,CODE_AT_LINE);
|
||||||
MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE_X(playerIndex));
|
MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE_X(playerIndex));
|
||||||
if(playerIndex != lockedSlotIndex) {
|
if(playerIndex != lockedSlotIndex) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex);
|
||||||
safeMutexSlot.setMutex(&slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(playerIndex));
|
safeMutexSlot.setMutex(slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(playerIndex));
|
||||||
}
|
}
|
||||||
ConnectionSlot *slot = slots[playerIndex];
|
ConnectionSlot *slot = slots[playerIndex];
|
||||||
bool notifyDisconnect = false;
|
bool notifyDisconnect = false;
|
||||||
|
@ -398,14 +428,14 @@ void ServerInterface::removeSlot(int playerIndex, int lockedSlotIndex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionSlot *ServerInterface::getSlot(int playerIndex) {
|
ConnectionSlot *ServerInterface::getSlot(int playerIndex) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(i));
|
||||||
ConnectionSlot *result = slots[playerIndex];
|
ConnectionSlot *result = slots[playerIndex];
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerInterface::isClientConnected(int index) {
|
bool ServerInterface::isClientConnected(int index) {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[index],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[index],CODE_AT_LINE_X(i));
|
||||||
if(slots[index] != NULL && slots[index]->isConnected() == true) {
|
if(slots[index] != NULL && slots[index]->isConnected() == true) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
@ -426,7 +456,7 @@ bool ServerInterface::hasClientConnection() {
|
||||||
int ServerInterface::getConnectedSlotCount() {
|
int ServerInterface::getConnectedSlotCount() {
|
||||||
int connectedSlotCount = 0;
|
int connectedSlotCount = 0;
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
if(slots[i] != NULL) {
|
if(slots[i] != NULL) {
|
||||||
++connectedSlotCount;
|
++connectedSlotCount;
|
||||||
}
|
}
|
||||||
|
@ -476,7 +506,7 @@ void ServerInterface::slotUpdateTask(ConnectionSlotEvent *event) {
|
||||||
//
|
//
|
||||||
// //printf("===> START slot %d [%d][%p] - About to updateSlot\n",event->triggerId,event->eventId,slots[event->triggerId]);
|
// //printf("===> START slot %d [%d][%p] - About to updateSlot\n",event->triggerId,event->eventId,slots[event->triggerId]);
|
||||||
//
|
//
|
||||||
// safeMutexSlot.setMutex(&slotAccessorMutexes[event->triggerId],CODE_AT_LINE_X(event->triggerId));
|
// safeMutexSlot.setMutex(slotAccessorMutexes[event->triggerId],CODE_AT_LINE_X(event->triggerId));
|
||||||
// connectionSlot = slots[event->triggerId];
|
// connectionSlot = slots[event->triggerId];
|
||||||
// }
|
// }
|
||||||
// else {
|
// else {
|
||||||
|
@ -708,7 +738,7 @@ bool ServerInterface::signalClientReceiveCommands(ConnectionSlot *connectionSlot
|
||||||
|
|
||||||
void ServerInterface::updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> & socketTriggeredList) {
|
void ServerInterface::updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> & socketTriggeredList) {
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ConnectionSlot* connectionSlot= slots[i];
|
ConnectionSlot* connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL) {
|
if(connectionSlot != NULL) {
|
||||||
PLATFORM_SOCKET clientSocket = connectionSlot->getSocketId();
|
PLATFORM_SOCKET clientSocket = connectionSlot->getSocketId();
|
||||||
|
@ -721,7 +751,7 @@ void ServerInterface::updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> &
|
||||||
|
|
||||||
void ServerInterface::validateConnectedClients() {
|
void ServerInterface::validateConnectedClients() {
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ConnectionSlot* connectionSlot = slots[i];
|
ConnectionSlot* connectionSlot = slots[i];
|
||||||
if(connectionSlot != NULL) {
|
if(connectionSlot != NULL) {
|
||||||
connectionSlot->validateConnection();
|
connectionSlot->validateConnection();
|
||||||
|
@ -734,7 +764,7 @@ void ServerInterface::signalClientsToRecieveData(std::map<PLATFORM_SOCKET,bool>
|
||||||
std::map<int,bool> & mapSlotSignalledList) {
|
std::map<int,bool> & mapSlotSignalledList) {
|
||||||
//bool checkForNewClients = true;
|
//bool checkForNewClients = true;
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ConnectionSlot* connectionSlot = slots[i];
|
ConnectionSlot* connectionSlot = slots[i];
|
||||||
|
|
||||||
bool socketTriggered = false;
|
bool socketTriggered = false;
|
||||||
|
@ -764,7 +794,7 @@ void ServerInterface::checkForCompletedClients(std::map<int,bool> & mapSlotSigna
|
||||||
|
|
||||||
//printf("===> START slot %d [%p] - About to checkForCompletedClients\n",i,slots[i]);
|
//printf("===> START slot %d [%p] - About to checkForCompletedClients\n",i,slots[i]);
|
||||||
|
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
|
|
||||||
//printf("===> IN slot %d - About to checkForCompletedClients\n",i);
|
//printf("===> IN slot %d - About to checkForCompletedClients\n",i);
|
||||||
|
|
||||||
|
@ -824,7 +854,7 @@ void ServerInterface::checkForLaggingClients(std::map<int,bool> &mapSlotSignalle
|
||||||
threadsDone = true;
|
threadsDone = true;
|
||||||
// Examine all threads for completion of delegation
|
// Examine all threads for completion of delegation
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ConnectionSlot* connectionSlot = slots[i];
|
ConnectionSlot* connectionSlot = slots[i];
|
||||||
if(connectionSlot != NULL && mapSlotSignalledList[i] == true &&
|
if(connectionSlot != NULL && mapSlotSignalledList[i] == true &&
|
||||||
slotsCompleted.find(i) == slotsCompleted.end()) {
|
slotsCompleted.find(i) == slotsCompleted.end()) {
|
||||||
|
@ -937,7 +967,7 @@ void ServerInterface::checkForLaggingClients(std::map<int,bool> &mapSlotSignalle
|
||||||
void ServerInterface::executeNetworkCommandsFromClients() {
|
void ServerInterface::executeNetworkCommandsFromClients() {
|
||||||
if(gameHasBeenInitiated == true) {
|
if(gameHasBeenInitiated == true) {
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ConnectionSlot* connectionSlot= slots[i];
|
ConnectionSlot* connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
||||||
vector<NetworkCommand> pendingList = connectionSlot->getPendingNetworkCommandList(true);
|
vector<NetworkCommand> pendingList = connectionSlot->getPendingNetworkCommandList(true);
|
||||||
|
@ -954,7 +984,7 @@ void ServerInterface::executeNetworkCommandsFromClients() {
|
||||||
|
|
||||||
void ServerInterface::dispatchPendingChatMessages(std::vector <string> &errorMsgList) {
|
void ServerInterface::dispatchPendingChatMessages(std::vector <string> &errorMsgList) {
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ConnectionSlot* connectionSlot= slots[i];
|
ConnectionSlot* connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL &&
|
if(connectionSlot != NULL &&
|
||||||
connectionSlot->getChatTextList(false).empty() == false) {
|
connectionSlot->getChatTextList(false).empty() == false) {
|
||||||
|
@ -1284,7 +1314,7 @@ void ServerInterface::waitUntilReady(Checksum *checksum) {
|
||||||
vector<string> waitingForHosts;
|
vector<string> waitingForHosts;
|
||||||
allReady= true;
|
allReady= true;
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ConnectionSlot* connectionSlot= slots[i];
|
ConnectionSlot* connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
||||||
if(connectionSlot->isReady() == false) {
|
if(connectionSlot->isReady() == false) {
|
||||||
|
@ -1363,7 +1393,7 @@ void ServerInterface::waitUntilReady(Checksum *checksum) {
|
||||||
uint32 loadingStatus = nmls_NONE;
|
uint32 loadingStatus = nmls_NONE;
|
||||||
//send ready message after, so clients start delayed
|
//send ready message after, so clients start delayed
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ConnectionSlot* connectionSlot= slots[i];
|
ConnectionSlot* connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
||||||
switch(i) {
|
switch(i) {
|
||||||
|
@ -1421,7 +1451,7 @@ void ServerInterface::waitUntilReady(Checksum *checksum) {
|
||||||
|
|
||||||
// send loading status message
|
// send loading status message
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ConnectionSlot* connectionSlot= slots[i];
|
ConnectionSlot* connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
||||||
NetworkMessageLoadingStatus networkMessageLoadingStatus(loadingStatus);
|
NetworkMessageLoadingStatus networkMessageLoadingStatus(loadingStatus);
|
||||||
|
@ -1457,7 +1487,7 @@ void ServerInterface::waitUntilReady(Checksum *checksum) {
|
||||||
try {
|
try {
|
||||||
//send ready message after, so clients start delayed
|
//send ready message after, so clients start delayed
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ConnectionSlot* connectionSlot= slots[i];
|
ConnectionSlot* connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
||||||
NetworkMessageReady networkMessageReady(checksum->getSum());
|
NetworkMessageReady networkMessageReady(checksum->getSum());
|
||||||
|
@ -1476,7 +1506,7 @@ void ServerInterface::waitUntilReady(Checksum *checksum) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerInterface::processBroadCastMessageQueue() {
|
void ServerInterface::processBroadCastMessageQueue() {
|
||||||
MutexSafeWrapper safeMutexSlot(&broadcastMessageQueueThreadAccessor,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(broadcastMessageQueueThreadAccessor,CODE_AT_LINE);
|
||||||
if(broadcastMessageQueue.empty() == false) {
|
if(broadcastMessageQueue.empty() == false) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] broadcastMessageQueue.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,broadcastMessageQueue.size());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] broadcastMessageQueue.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,broadcastMessageQueue.size());
|
||||||
for(int i = 0; i < broadcastMessageQueue.size(); ++i) {
|
for(int i = 0; i < broadcastMessageQueue.size(); ++i) {
|
||||||
|
@ -1492,7 +1522,7 @@ void ServerInterface::processBroadCastMessageQueue() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerInterface::queueBroadcastMessage(const NetworkMessage *networkMessage, int excludeSlot) {
|
void ServerInterface::queueBroadcastMessage(const NetworkMessage *networkMessage, int excludeSlot) {
|
||||||
MutexSafeWrapper safeMutexSlot(&broadcastMessageQueueThreadAccessor,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(broadcastMessageQueueThreadAccessor,CODE_AT_LINE);
|
||||||
pair<const NetworkMessage*,int> item;
|
pair<const NetworkMessage*,int> item;
|
||||||
item.first = networkMessage;
|
item.first = networkMessage;
|
||||||
item.second = excludeSlot;
|
item.second = excludeSlot;
|
||||||
|
@ -1500,7 +1530,7 @@ void ServerInterface::queueBroadcastMessage(const NetworkMessage *networkMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerInterface::processTextMessageQueue() {
|
void ServerInterface::processTextMessageQueue() {
|
||||||
MutexSafeWrapper safeMutexSlot(&textMessageQueueThreadAccessor,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(textMessageQueueThreadAccessor,CODE_AT_LINE);
|
||||||
if(textMessageQueue.empty() == false) {
|
if(textMessageQueue.empty() == false) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] textMessageQueue.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,textMessageQueue.size());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] textMessageQueue.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,textMessageQueue.size());
|
||||||
for(int i = 0; i < textMessageQueue.size(); ++i) {
|
for(int i = 0; i < textMessageQueue.size(); ++i) {
|
||||||
|
@ -1516,7 +1546,7 @@ void ServerInterface::queueTextMessage(const string & text, int teamIndex,
|
||||||
|
|
||||||
//printf("Line: %d text [%s]\n",__LINE__,text.c_str());
|
//printf("Line: %d text [%s]\n",__LINE__,text.c_str());
|
||||||
|
|
||||||
MutexSafeWrapper safeMutexSlot(&textMessageQueueThreadAccessor,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(textMessageQueueThreadAccessor,CODE_AT_LINE);
|
||||||
TextMessageQueue item;
|
TextMessageQueue item;
|
||||||
item.text = text;
|
item.text = text;
|
||||||
item.teamIndex = teamIndex;
|
item.teamIndex = teamIndex;
|
||||||
|
@ -1559,7 +1589,7 @@ string ServerInterface::getNetworkStatus() {
|
||||||
Lang &lang = Lang::getInstance();
|
Lang &lang = Lang::getInstance();
|
||||||
string str="";
|
string str="";
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ConnectionSlot* connectionSlot= slots[i];
|
ConnectionSlot* connectionSlot= slots[i];
|
||||||
|
|
||||||
str+= intToStr(i)+ ": ";
|
str+= intToStr(i)+ ": ";
|
||||||
|
@ -1588,7 +1618,7 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
|
||||||
bool bOkToStart = true;
|
bool bOkToStart = true;
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ConnectionSlot *connectionSlot= slots[i];
|
ConnectionSlot *connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL &&
|
if(connectionSlot != NULL &&
|
||||||
(connectionSlot->getAllowDownloadDataSynch() == true || connectionSlot->getAllowGameDataSynchCheck() == true) &&
|
(connectionSlot->getAllowDownloadDataSynch() == true || connectionSlot->getAllowGameDataSynchCheck() == true) &&
|
||||||
|
@ -1608,7 +1638,7 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
|
||||||
if(useInGameBlockingClientSockets == true) {
|
if(useInGameBlockingClientSockets == true) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
for(int i= 0; i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; i < GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ConnectionSlot *connectionSlot= slots[i];
|
ConnectionSlot *connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
||||||
connectionSlot->getSocket()->setBlock(true);
|
connectionSlot->getSocket()->setBlock(true);
|
||||||
|
@ -1627,7 +1657,7 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",__FILE__,__FUNCTION__,__LINE__,needToRepublishToMasterserver);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",__FILE__,__FUNCTION__,__LINE__,needToRepublishToMasterserver);
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(&masterServerThreadAccessor,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(masterServerThreadAccessor,CODE_AT_LINE);
|
||||||
delete publishToMasterserverThread;
|
delete publishToMasterserverThread;
|
||||||
publishToMasterserverThread = NULL;
|
publishToMasterserverThread = NULL;
|
||||||
lastMasterserverHeartbeatTime = 0;
|
lastMasterserverHeartbeatTime = 0;
|
||||||
|
@ -1662,7 +1692,7 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
|
||||||
|
|
||||||
void ServerInterface::broadcastGameSetup(const GameSettings *gameSettings) {
|
void ServerInterface::broadcastGameSetup(const GameSettings *gameSettings) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
MutexSafeWrapper safeMutex(&serverSynchAccessor,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(serverSynchAccessor,CODE_AT_LINE);
|
||||||
NetworkMessageLaunch networkMessageLaunch(gameSettings, nmtBroadCastSetup);
|
NetworkMessageLaunch networkMessageLaunch(gameSettings, nmtBroadCastSetup);
|
||||||
broadcastMessage(&networkMessageLaunch);
|
broadcastMessage(&networkMessageLaunch);
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
@ -1672,7 +1702,7 @@ void ServerInterface::broadcastMessage(const NetworkMessage *networkMessage, int
|
||||||
try {
|
try {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
MutexSafeWrapper safeMutexSlotBroadCastAccessor(&inBroadcastMessageThreadAccessor,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlotBroadCastAccessor(inBroadcastMessageThreadAccessor,CODE_AT_LINE);
|
||||||
if(inBroadcastMessage == true && dynamic_cast<const NetworkMessageText *>(networkMessage) != NULL) {
|
if(inBroadcastMessage == true && dynamic_cast<const NetworkMessageText *>(networkMessage) != NULL) {
|
||||||
safeMutexSlotBroadCastAccessor.ReleaseLock();
|
safeMutexSlotBroadCastAccessor.ReleaseLock();
|
||||||
const NetworkMessageText *txtMsg = dynamic_cast<const NetworkMessageText *>(networkMessage);
|
const NetworkMessageText *txtMsg = dynamic_cast<const NetworkMessageText *>(networkMessage);
|
||||||
|
@ -1689,7 +1719,7 @@ void ServerInterface::broadcastMessage(const NetworkMessage *networkMessage, int
|
||||||
MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE_X(i));
|
||||||
if(i != lockedSlotIndex) {
|
if(i != lockedSlotIndex) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] i = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,i,lockedSlotIndex);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] i = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,i,lockedSlotIndex);
|
||||||
safeMutexSlot.setMutex(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
safeMutexSlot.setMutex(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionSlot* connectionSlot= slots[i];
|
ConnectionSlot* connectionSlot= slots[i];
|
||||||
|
@ -1724,7 +1754,7 @@ void ServerInterface::broadcastMessage(const NetworkMessage *networkMessage, int
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugError,"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());
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||||
|
|
||||||
MutexSafeWrapper safeMutexSlotBroadCastAccessor(&inBroadcastMessageThreadAccessor,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlotBroadCastAccessor(inBroadcastMessageThreadAccessor,CODE_AT_LINE);
|
||||||
inBroadcastMessage = false;
|
inBroadcastMessage = false;
|
||||||
safeMutexSlotBroadCastAccessor.ReleaseLock();
|
safeMutexSlotBroadCastAccessor.ReleaseLock();
|
||||||
|
|
||||||
|
@ -1737,7 +1767,7 @@ void ServerInterface::broadcastMessageToConnectedClients(const NetworkMessage *n
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
try {
|
try {
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ConnectionSlot *connectionSlot= slots[i];
|
ConnectionSlot *connectionSlot= slots[i];
|
||||||
|
|
||||||
if(i != excludeSlot && connectionSlot != NULL) {
|
if(i != excludeSlot && connectionSlot != NULL) {
|
||||||
|
@ -1761,7 +1791,7 @@ void ServerInterface::updateListen() {
|
||||||
}
|
}
|
||||||
int openSlotCount = 0;
|
int openSlotCount = 0;
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i));
|
//MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i));
|
||||||
bool isSlotOpen = (slots[i] != NULL && slots[i]->isConnected() == false);
|
bool isSlotOpen = (slots[i] != NULL && slots[i]->isConnected() == false);
|
||||||
|
|
||||||
if(isSlotOpen == true) {
|
if(isSlotOpen == true) {
|
||||||
|
@ -1774,7 +1804,7 @@ void ServerInterface::updateListen() {
|
||||||
int ServerInterface::getOpenSlotCount() {
|
int ServerInterface::getOpenSlotCount() {
|
||||||
int openSlotCount = 0;
|
int openSlotCount = 0;
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i));
|
//MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i));
|
||||||
bool isSlotOpen = (slots[i] != NULL && slots[i]->isConnected() == false);
|
bool isSlotOpen = (slots[i] != NULL && slots[i]->isConnected() == false);
|
||||||
|
|
||||||
if(isSlotOpen == true) {
|
if(isSlotOpen == true) {
|
||||||
|
@ -1786,7 +1816,7 @@ int ServerInterface::getOpenSlotCount() {
|
||||||
|
|
||||||
int ServerInterface::getGameSettingsUpdateCount() {
|
int ServerInterface::getGameSettingsUpdateCount() {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START gameSettingsUpdateCount = %d\n",__FILE__,__FUNCTION__,gameSettingsUpdateCount);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START gameSettingsUpdateCount = %d\n",__FILE__,__FUNCTION__,gameSettingsUpdateCount);
|
||||||
MutexSafeWrapper safeMutex(&serverSynchAccessor,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(serverSynchAccessor,CODE_AT_LINE);
|
||||||
|
|
||||||
int result = gameSettingsUpdateCount;
|
int result = gameSettingsUpdateCount;
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
|
@ -1795,7 +1825,7 @@ int ServerInterface::getGameSettingsUpdateCount() {
|
||||||
|
|
||||||
void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool waitForClientAck) {
|
void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool waitForClientAck) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START gameSettingsUpdateCount = %d, waitForClientAck = %d\n",__FILE__,__FUNCTION__,gameSettingsUpdateCount,waitForClientAck);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START gameSettingsUpdateCount = %d, waitForClientAck = %d\n",__FILE__,__FUNCTION__,gameSettingsUpdateCount,waitForClientAck);
|
||||||
MutexSafeWrapper safeMutex(&serverSynchAccessor,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(serverSynchAccessor,CODE_AT_LINE);
|
||||||
|
|
||||||
string mapFile = serverGameSettings->getMap();
|
string mapFile = serverGameSettings->getMap();
|
||||||
if(find(mapFiles.begin(),mapFiles.end(),mapFile) == mapFiles.end()) {
|
if(find(mapFiles.begin(),mapFiles.end(),mapFile) == mapFiles.end()) {
|
||||||
|
@ -1834,7 +1864,7 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//printf("===> START slot %d - About to setGameSettings #1\n",i);
|
//printf("===> START slot %d - About to setGameSettings #1\n",i);
|
||||||
|
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ConnectionSlot *connectionSlot = slots[i];
|
ConnectionSlot *connectionSlot = slots[i];
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
||||||
if(connectionSlot->getReceivedNetworkGameStatus() == false) {
|
if(connectionSlot->getReceivedNetworkGameStatus() == false) {
|
||||||
|
@ -1850,7 +1880,7 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ConnectionSlot *connectionSlot = slots[i];
|
ConnectionSlot *connectionSlot = slots[i];
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
||||||
connectionSlot->setReceivedNetworkGameStatus(false);
|
connectionSlot->setReceivedNetworkGameStatus(false);
|
||||||
|
@ -1870,7 +1900,7 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//printf("===> START slot %d - About to setGameSettings 2\n",i);
|
//printf("===> START slot %d - About to setGameSettings 2\n",i);
|
||||||
|
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ConnectionSlot *connectionSlot = slots[i];
|
ConnectionSlot *connectionSlot = slots[i];
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
||||||
if(connectionSlot->getReceivedNetworkGameStatus() == false) {
|
if(connectionSlot->getReceivedNetworkGameStatus() == false) {
|
||||||
|
@ -1921,7 +1951,7 @@ std::map<string,string> ServerInterface::publishToMasterserver() {
|
||||||
std::map < string, string > publishToServerInfo;
|
std::map < string, string > publishToServerInfo;
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
if(slots[i] != NULL) {
|
if(slots[i] != NULL) {
|
||||||
slotCountUsed++;
|
slotCountUsed++;
|
||||||
slotCountHumans++;
|
slotCountHumans++;
|
||||||
|
@ -1955,7 +1985,7 @@ std::map<string,string> ServerInterface::publishToMasterserver() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerInterface::simpleTask(BaseThread *callingThread) {
|
void ServerInterface::simpleTask(BaseThread *callingThread) {
|
||||||
MutexSafeWrapper safeMutex(&masterServerThreadAccessor,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(masterServerThreadAccessor,CODE_AT_LINE);
|
||||||
if(difftime(time(NULL),lastMasterserverHeartbeatTime) >= MASTERSERVER_HEARTBEAT_GAME_STATUS_SECONDS) {
|
if(difftime(time(NULL),lastMasterserverHeartbeatTime) >= MASTERSERVER_HEARTBEAT_GAME_STATUS_SECONDS) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
|
|
@ -48,13 +48,13 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ConnectionSlot* slots[GameConstants::maxPlayers];
|
ConnectionSlot* slots[GameConstants::maxPlayers];
|
||||||
Mutex slotAccessorMutexes[GameConstants::maxPlayers];
|
Mutex *slotAccessorMutexes[GameConstants::maxPlayers];
|
||||||
|
|
||||||
ServerSocket serverSocket;
|
ServerSocket serverSocket;
|
||||||
bool gameHasBeenInitiated;
|
bool gameHasBeenInitiated;
|
||||||
int gameSettingsUpdateCount;
|
int gameSettingsUpdateCount;
|
||||||
SwitchSetupRequest* switchSetupRequests[GameConstants::maxPlayers];
|
SwitchSetupRequest* switchSetupRequests[GameConstants::maxPlayers];
|
||||||
Mutex serverSynchAccessor;
|
Mutex *serverSynchAccessor;
|
||||||
int currentFrameCount;
|
int currentFrameCount;
|
||||||
|
|
||||||
time_t gameStartTime;
|
time_t gameStartTime;
|
||||||
|
@ -62,7 +62,7 @@ private:
|
||||||
time_t lastGlobalLagCheckTime;
|
time_t lastGlobalLagCheckTime;
|
||||||
|
|
||||||
SimpleTaskThread *publishToMasterserverThread;
|
SimpleTaskThread *publishToMasterserverThread;
|
||||||
Mutex masterServerThreadAccessor;
|
Mutex *masterServerThreadAccessor;
|
||||||
time_t lastMasterserverHeartbeatTime;
|
time_t lastMasterserverHeartbeatTime;
|
||||||
bool needToRepublishToMasterserver;
|
bool needToRepublishToMasterserver;
|
||||||
|
|
||||||
|
@ -70,13 +70,13 @@ private:
|
||||||
bool exitServer;
|
bool exitServer;
|
||||||
int64 nextEventId;
|
int64 nextEventId;
|
||||||
|
|
||||||
Mutex textMessageQueueThreadAccessor;
|
Mutex *textMessageQueueThreadAccessor;
|
||||||
vector<TextMessageQueue> textMessageQueue;
|
vector<TextMessageQueue> textMessageQueue;
|
||||||
|
|
||||||
Mutex broadcastMessageQueueThreadAccessor;
|
Mutex *broadcastMessageQueueThreadAccessor;
|
||||||
vector<pair<const NetworkMessage *,int> > broadcastMessageQueue;
|
vector<pair<const NetworkMessage *,int> > broadcastMessageQueue;
|
||||||
|
|
||||||
Mutex inBroadcastMessageThreadAccessor;
|
Mutex *inBroadcastMessageThreadAccessor;
|
||||||
bool inBroadcastMessage;
|
bool inBroadcastMessage;
|
||||||
|
|
||||||
bool masterserverAdminRequestLaunch;
|
bool masterserverAdminRequestLaunch;
|
||||||
|
@ -184,7 +184,7 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Mutex *getServerSynchAccessor() {
|
Mutex *getServerSynchAccessor() {
|
||||||
return &serverSynchAccessor;
|
return serverSynchAccessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void simpleTask(BaseThread *callingThread);
|
virtual void simpleTask(BaseThread *callingThread);
|
||||||
|
|
|
@ -213,9 +213,15 @@ void Faction::sortUnitsByCommandGroups() {
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
FactionThread::FactionThread(Faction *faction) : BaseThread() {
|
FactionThread::FactionThread(Faction *faction) : BaseThread() {
|
||||||
|
this->triggerIdMutex = new Mutex();
|
||||||
this->faction = faction;
|
this->faction = faction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FactionThread::~FactionThread() {
|
||||||
|
delete triggerIdMutex;
|
||||||
|
triggerIdMutex = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void FactionThread::setQuitStatus(bool value) {
|
void FactionThread::setQuitStatus(bool value) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d value = %d\n",__FILE__,__FUNCTION__,__LINE__,value);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d value = %d\n",__FILE__,__FUNCTION__,__LINE__,value);
|
||||||
|
|
||||||
|
@ -230,7 +236,7 @@ void FactionThread::setQuitStatus(bool value) {
|
||||||
void FactionThread::signalPathfinder(int frameIndex) {
|
void FactionThread::signalPathfinder(int frameIndex) {
|
||||||
if(frameIndex >= 0) {
|
if(frameIndex >= 0) {
|
||||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||||
MutexSafeWrapper safeMutex(&triggerIdMutex,mutexOwnerId);
|
MutexSafeWrapper safeMutex(triggerIdMutex,mutexOwnerId);
|
||||||
this->frameIndex.first = frameIndex;
|
this->frameIndex.first = frameIndex;
|
||||||
this->frameIndex.second = false;
|
this->frameIndex.second = false;
|
||||||
|
|
||||||
|
@ -242,7 +248,7 @@ void FactionThread::signalPathfinder(int frameIndex) {
|
||||||
void FactionThread::setTaskCompleted(int frameIndex) {
|
void FactionThread::setTaskCompleted(int frameIndex) {
|
||||||
if(frameIndex >= 0) {
|
if(frameIndex >= 0) {
|
||||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||||
MutexSafeWrapper safeMutex(&triggerIdMutex,mutexOwnerId);
|
MutexSafeWrapper safeMutex(triggerIdMutex,mutexOwnerId);
|
||||||
if(this->frameIndex.first == frameIndex) {
|
if(this->frameIndex.first == frameIndex) {
|
||||||
this->frameIndex.second = true;
|
this->frameIndex.second = true;
|
||||||
}
|
}
|
||||||
|
@ -265,7 +271,7 @@ bool FactionThread::isSignalPathfinderCompleted(int frameIndex) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||||
MutexSafeWrapper safeMutex(&triggerIdMutex,mutexOwnerId);
|
MutexSafeWrapper safeMutex(triggerIdMutex,mutexOwnerId);
|
||||||
//bool result = (event != NULL ? event->eventCompleted : true);
|
//bool result = (event != NULL ? event->eventCompleted : true);
|
||||||
bool result = (this->frameIndex.first == frameIndex && this->frameIndex.second == true);
|
bool result = (this->frameIndex.first == frameIndex && this->frameIndex.second == true);
|
||||||
|
|
||||||
|
@ -297,7 +303,7 @@ void FactionThread::execute() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||||
MutexSafeWrapper safeMutex(&triggerIdMutex,mutexOwnerId);
|
MutexSafeWrapper safeMutex(triggerIdMutex,mutexOwnerId);
|
||||||
bool executeTask = (frameIndex.first >= 0);
|
bool executeTask = (frameIndex.first >= 0);
|
||||||
|
|
||||||
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] frameIndex = %d this = %p executeTask = %d\n",__FILE__,__FUNCTION__,__LINE__,frameIndex.first, this, executeTask);
|
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] frameIndex = %d this = %p executeTask = %d\n",__FILE__,__FUNCTION__,__LINE__,frameIndex.first, this, executeTask);
|
||||||
|
@ -309,7 +315,7 @@ void FactionThread::execute() {
|
||||||
|
|
||||||
World *world = faction->getWorld();
|
World *world = faction->getWorld();
|
||||||
|
|
||||||
Config &config= Config::getInstance();
|
//Config &config= Config::getInstance();
|
||||||
//bool sortedUnitsAllowed = config.getBool("AllowGroupedUnitCommands","true");
|
//bool sortedUnitsAllowed = config.getBool("AllowGroupedUnitCommands","true");
|
||||||
bool sortedUnitsAllowed = false;
|
bool sortedUnitsAllowed = false;
|
||||||
if(sortedUnitsAllowed) {
|
if(sortedUnitsAllowed) {
|
||||||
|
@ -375,6 +381,7 @@ Faction::Faction() {
|
||||||
teamIndex=0;
|
teamIndex=0;
|
||||||
startLocationIndex=0;
|
startLocationIndex=0;
|
||||||
thisFaction=false;
|
thisFaction=false;
|
||||||
|
currentSwitchTeamVoteFactionIndex = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Faction::~Faction() {
|
Faction::~Faction() {
|
||||||
|
@ -1574,7 +1581,7 @@ int Faction::getFrameCount() {
|
||||||
|
|
||||||
const SwitchTeamVote * Faction::getFirstSwitchTeamVote() const {
|
const SwitchTeamVote * Faction::getFirstSwitchTeamVote() const {
|
||||||
const SwitchTeamVote *vote = NULL;
|
const SwitchTeamVote *vote = NULL;
|
||||||
if(switchTeamVotes.size() > 0) {
|
if(switchTeamVotes.empty() == false) {
|
||||||
for(std::map<int,SwitchTeamVote>::const_iterator iterMap = switchTeamVotes.begin();
|
for(std::map<int,SwitchTeamVote>::const_iterator iterMap = switchTeamVotes.begin();
|
||||||
iterMap != switchTeamVotes.end(); ++iterMap) {
|
iterMap != switchTeamVotes.end(); ++iterMap) {
|
||||||
const SwitchTeamVote &curVote = iterMap->second;
|
const SwitchTeamVote &curVote = iterMap->second;
|
||||||
|
@ -1657,6 +1664,64 @@ bool Faction::canCreateUnit(const UnitType *ut, bool checkBuild, bool checkProdu
|
||||||
return foundUnit;
|
return foundUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64 Faction::getCacheKBytes(uint64 *cache1Size, uint64 *cache2Size) {
|
||||||
|
uint64 cache1Count = 0;
|
||||||
|
uint64 cache2Count = 0;
|
||||||
|
|
||||||
|
//std::map<Vec2i,int> cacheResourceTargetList;
|
||||||
|
for(std::map<Vec2i,int>::iterator iterMap1 = cacheResourceTargetList.begin();
|
||||||
|
iterMap1 != cacheResourceTargetList.end(); ++iterMap1) {
|
||||||
|
cache1Count++;
|
||||||
|
}
|
||||||
|
//std::map<Vec2i,bool> cachedCloseResourceTargetLookupList;
|
||||||
|
for(std::map<Vec2i,bool>::iterator iterMap1 = cachedCloseResourceTargetLookupList.begin();
|
||||||
|
iterMap1 != cachedCloseResourceTargetLookupList.end(); ++iterMap1) {
|
||||||
|
cache2Count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cache1Size) {
|
||||||
|
*cache1Size = cache1Count;
|
||||||
|
}
|
||||||
|
if(cache2Size) {
|
||||||
|
*cache2Size = cache2Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64 totalBytes = cache1Count * sizeof(int);
|
||||||
|
totalBytes += cache2Count * sizeof(bool);
|
||||||
|
|
||||||
|
totalBytes /= 1000;
|
||||||
|
|
||||||
|
return totalBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
string Faction::getCacheStats() {
|
||||||
|
string result = "";
|
||||||
|
|
||||||
|
int cache1Count = 0;
|
||||||
|
int cache2Count = 0;
|
||||||
|
|
||||||
|
//std::map<Vec2i,int> cacheResourceTargetList;
|
||||||
|
for(std::map<Vec2i,int>::iterator iterMap1 = cacheResourceTargetList.begin();
|
||||||
|
iterMap1 != cacheResourceTargetList.end(); ++iterMap1) {
|
||||||
|
cache1Count++;
|
||||||
|
}
|
||||||
|
//std::map<Vec2i,bool> cachedCloseResourceTargetLookupList;
|
||||||
|
for(std::map<Vec2i,bool>::iterator iterMap1 = cachedCloseResourceTargetLookupList.begin();
|
||||||
|
iterMap1 != cachedCloseResourceTargetLookupList.end(); ++iterMap1) {
|
||||||
|
cache2Count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64 totalBytes = cache1Count * sizeof(int);
|
||||||
|
totalBytes += cache2Count * sizeof(bool);
|
||||||
|
|
||||||
|
totalBytes /= 1000;
|
||||||
|
|
||||||
|
char szBuf[1024]="";
|
||||||
|
sprintf(szBuf,"cache1Count [%d] cache2Count [%d] total KB: %s",cache1Count,cache2Count,formatNumber(totalBytes).c_str());
|
||||||
|
result = szBuf;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
std::string Faction::toString() const {
|
std::string Faction::toString() const {
|
||||||
std::string result = "";
|
std::string result = "";
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ protected:
|
||||||
|
|
||||||
Faction *faction;
|
Faction *faction;
|
||||||
Semaphore semTaskSignalled;
|
Semaphore semTaskSignalled;
|
||||||
Mutex triggerIdMutex;
|
Mutex *triggerIdMutex;
|
||||||
std::pair<int,bool> frameIndex;
|
std::pair<int,bool> frameIndex;
|
||||||
|
|
||||||
virtual void setQuitStatus(bool value);
|
virtual void setQuitStatus(bool value);
|
||||||
|
@ -75,6 +75,7 @@ protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FactionThread(Faction *faction);
|
FactionThread(Faction *faction);
|
||||||
|
virtual ~FactionThread();
|
||||||
virtual void execute();
|
virtual void execute();
|
||||||
void signalPathfinder(int frameIndex);
|
void signalPathfinder(int frameIndex);
|
||||||
bool isSignalPathfinderCompleted(int frameIndex);
|
bool isSignalPathfinderCompleted(int frameIndex);
|
||||||
|
@ -250,6 +251,9 @@ public:
|
||||||
|
|
||||||
bool canCreateUnit(const UnitType *ut, bool checkBuild, bool checkProduce, bool checkMorph) const;
|
bool canCreateUnit(const UnitType *ut, bool checkBuild, bool checkProduce, bool checkMorph) const;
|
||||||
|
|
||||||
|
string getCacheStats();
|
||||||
|
uint64 getCacheKBytes(uint64 *cache1Size, uint64 *cache2Size);
|
||||||
|
|
||||||
std::string toString() const;
|
std::string toString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -131,7 +131,10 @@ void UnitPathBasic::addToLastPathCache(const Vec2i &path) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lastPathCacheQueue.push_back(path);
|
const bool tryLastPathCache = Config::getInstance().getBool("EnablePathfinderCache","false");
|
||||||
|
if(tryLastPathCache == true) {
|
||||||
|
lastPathCacheQueue.push_back(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2i UnitPathBasic::pop(bool removeFrontPos) {
|
Vec2i UnitPathBasic::pop(bool removeFrontPos) {
|
||||||
|
@ -286,6 +289,7 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos, const UnitType
|
||||||
Unit::mapMemoryList[this]=true;
|
Unit::mapMemoryList[this]=true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
mutexCommands = new Mutex();
|
||||||
changedActiveCommand = false;
|
changedActiveCommand = false;
|
||||||
lastSynchDataString="";
|
lastSynchDataString="";
|
||||||
modelFacing = CardinalDir::NORTH;
|
modelFacing = CardinalDir::NORTH;
|
||||||
|
@ -339,6 +343,10 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos, const UnitType
|
||||||
showUnitParticles = config.getBool("UnitParticles","true");
|
showUnitParticles = config.getBool("UnitParticles","true");
|
||||||
maxQueuedCommandDisplayCount = config.getInt("MaxQueuedCommandDisplayCount","15");
|
maxQueuedCommandDisplayCount = config.getInt("MaxQueuedCommandDisplayCount","15");
|
||||||
|
|
||||||
|
if(Renderer::getInstance().isMasterserverMode() == true) {
|
||||||
|
showUnitParticles = false;
|
||||||
|
}
|
||||||
|
|
||||||
lastPos= pos;
|
lastPos= pos;
|
||||||
progress= 0;
|
progress= 0;
|
||||||
lastAnimProgress= 0;
|
lastAnimProgress= 0;
|
||||||
|
@ -405,7 +413,7 @@ Unit::~Unit() {
|
||||||
|
|
||||||
//remove commands
|
//remove commands
|
||||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||||
MutexSafeWrapper safeMutex(&mutexCommands,mutexOwnerId);
|
MutexSafeWrapper safeMutex(mutexCommands,mutexOwnerId);
|
||||||
|
|
||||||
changedActiveCommand = false;
|
changedActiveCommand = false;
|
||||||
while(commands.empty() == false) {
|
while(commands.empty() == false) {
|
||||||
|
@ -459,6 +467,9 @@ Unit::~Unit() {
|
||||||
//MutexSafeWrapper safeMutex1(&mutexDeletedUnits,string(__FILE__) + "_" + intToStr(__LINE__));
|
//MutexSafeWrapper safeMutex1(&mutexDeletedUnits,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
//deletedUnits[this]=true;
|
//deletedUnits[this]=true;
|
||||||
|
|
||||||
|
delete mutexCommands;
|
||||||
|
mutexCommands=NULL;
|
||||||
|
|
||||||
#ifdef LEAK_CHECK_UNITS
|
#ifdef LEAK_CHECK_UNITS
|
||||||
Unit::mapMemoryList.erase(this);
|
Unit::mapMemoryList.erase(this);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1100,7 +1111,7 @@ bool Unit::anyCommand(bool validateCommandtype) const {
|
||||||
//return current command, assert that there is always one command
|
//return current command, assert that there is always one command
|
||||||
Command *Unit::getCurrrentCommandThreadSafe() {
|
Command *Unit::getCurrrentCommandThreadSafe() {
|
||||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||||
MutexSafeWrapper safeMutex(&mutexCommands,mutexOwnerId);
|
MutexSafeWrapper safeMutex(mutexCommands,mutexOwnerId);
|
||||||
|
|
||||||
if(commands.empty() == false) {
|
if(commands.empty() == false) {
|
||||||
return commands.front();
|
return commands.front();
|
||||||
|
@ -1119,7 +1130,7 @@ Command *Unit::getCurrCommand() const {
|
||||||
|
|
||||||
void Unit::replaceCurrCommand(Command *cmd) {
|
void Unit::replaceCurrCommand(Command *cmd) {
|
||||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||||
MutexSafeWrapper safeMutex(&mutexCommands,mutexOwnerId);
|
MutexSafeWrapper safeMutex(mutexCommands,mutexOwnerId);
|
||||||
|
|
||||||
assert(commands.empty() == false);
|
assert(commands.empty() == false);
|
||||||
commands.front() = cmd;
|
commands.front() = cmd;
|
||||||
|
@ -1191,7 +1202,7 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] Deleting lower priority command [%s]\n",__FILE__,__FUNCTION__,__LINE__,(*i)->toString().c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] Deleting lower priority command [%s]\n",__FILE__,__FUNCTION__,__LINE__,(*i)->toString().c_str());
|
||||||
|
|
||||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||||
MutexSafeWrapper safeMutex(&mutexCommands,mutexOwnerId);
|
MutexSafeWrapper safeMutex(mutexCommands,mutexOwnerId);
|
||||||
|
|
||||||
deleteQueuedCommand(*i);
|
deleteQueuedCommand(*i);
|
||||||
i= commands.erase(i);
|
i= commands.erase(i);
|
||||||
|
@ -1226,7 +1237,7 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue) {
|
||||||
// clearCommands();
|
// clearCommands();
|
||||||
// changedActiveCommand = willChangedActiveCommand;
|
// changedActiveCommand = willChangedActiveCommand;
|
||||||
|
|
||||||
bool willChangedActiveCommand= (commands.size() > 0);
|
bool willChangedActiveCommand= (commands.empty() == false);
|
||||||
if(willChangedActiveCommand){
|
if(willChangedActiveCommand){
|
||||||
CommandClass currCommandClass=getCurrCommand()->getCommandType()->getClass();
|
CommandClass currCommandClass=getCurrCommand()->getCommandType()->getClass();
|
||||||
CommandClass commandClass=command->getCommandType()->getClass();
|
CommandClass commandClass=command->getCommandType()->getClass();
|
||||||
|
@ -1271,7 +1282,7 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue) {
|
||||||
//push back command
|
//push back command
|
||||||
if(result == crSuccess) {
|
if(result == crSuccess) {
|
||||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||||
MutexSafeWrapper safeMutex(&mutexCommands,mutexOwnerId);
|
MutexSafeWrapper safeMutex(mutexCommands,mutexOwnerId);
|
||||||
|
|
||||||
commands.push_back(command);
|
commands.push_back(command);
|
||||||
|
|
||||||
|
@ -1300,7 +1311,7 @@ CommandResult Unit::finishCommand() {
|
||||||
|
|
||||||
//pop front
|
//pop front
|
||||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||||
MutexSafeWrapper safeMutex(&mutexCommands,mutexOwnerId);
|
MutexSafeWrapper safeMutex(mutexCommands,mutexOwnerId);
|
||||||
|
|
||||||
delete commands.front();
|
delete commands.front();
|
||||||
commands.erase(commands.begin());
|
commands.erase(commands.begin());
|
||||||
|
@ -1341,7 +1352,7 @@ CommandResult Unit::cancelCommand() {
|
||||||
|
|
||||||
//delete ans pop command
|
//delete ans pop command
|
||||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||||
MutexSafeWrapper safeMutex(&mutexCommands,mutexOwnerId);
|
MutexSafeWrapper safeMutex(mutexCommands,mutexOwnerId);
|
||||||
|
|
||||||
delete commands.back();
|
delete commands.back();
|
||||||
commands.pop_back();
|
commands.pop_back();
|
||||||
|
@ -2590,7 +2601,7 @@ void Unit::clearCommands() {
|
||||||
undoCommand(commands.back());
|
undoCommand(commands.back());
|
||||||
|
|
||||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||||
MutexSafeWrapper safeMutex(&mutexCommands,mutexOwnerId);
|
MutexSafeWrapper safeMutex(mutexCommands,mutexOwnerId);
|
||||||
|
|
||||||
delete commands.back();
|
delete commands.back();
|
||||||
commands.pop_back();
|
commands.pop_back();
|
||||||
|
|
|
@ -404,7 +404,7 @@ private:
|
||||||
|
|
||||||
std::vector<UnitAttackBoostEffect *> currentAttackBoostEffects;
|
std::vector<UnitAttackBoostEffect *> currentAttackBoostEffects;
|
||||||
|
|
||||||
Mutex mutexCommands;
|
Mutex *mutexCommands;
|
||||||
|
|
||||||
//static Mutex mutexDeletedUnits;
|
//static Mutex mutexDeletedUnits;
|
||||||
//static std::map<void *,bool> deletedUnits;
|
//static std::map<void *,bool> deletedUnits;
|
||||||
|
|
|
@ -851,7 +851,7 @@ void SwitchTeamCommandType::load(int id, const XmlNode *n, const string &dir,
|
||||||
|
|
||||||
string SwitchTeamCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
|
string SwitchTeamCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
|
||||||
string str= name+"\n";
|
string str= name+"\n";
|
||||||
Lang &lang= Lang::getInstance();
|
//Lang &lang= Lang::getInstance();
|
||||||
|
|
||||||
//prod speed
|
//prod speed
|
||||||
//str+= lang.get("MorphSpeed")+": "+ intToStr(morphSkillType->getSpeed())+"\n";
|
//str+= lang.get("MorphSpeed")+": "+ intToStr(morphSkillType->getSpeed())+"\n";
|
||||||
|
|
|
@ -29,6 +29,9 @@ private:
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
AttackType() {
|
||||||
|
id = -1;
|
||||||
|
}
|
||||||
int getId() const {return id;}
|
int getId() const {return id;}
|
||||||
const string &getName() const {return name;}
|
const string &getName() const {return name;}
|
||||||
|
|
||||||
|
@ -40,12 +43,15 @@ public:
|
||||||
// class ArmorType
|
// class ArmorType
|
||||||
// ===============================
|
// ===============================
|
||||||
|
|
||||||
class ArmorType{
|
class ArmorType {
|
||||||
private:
|
private:
|
||||||
string name;
|
string name;
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
ArmorType() {
|
||||||
|
id = -1;
|
||||||
|
}
|
||||||
int getId() const {return id;}
|
int getId() const {return id;}
|
||||||
const string &getName() const {return name;}
|
const string &getName() const {return name;}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ using Shared::Graphics::Vec3f;
|
||||||
typedef vector<ObjectParticleSystemType*> ObjectParticleSystemTypes;
|
typedef vector<ObjectParticleSystemType*> ObjectParticleSystemTypes;
|
||||||
typedef vector<ObjectParticleSystemTypes> ObjectParticleVector;
|
typedef vector<ObjectParticleSystemTypes> ObjectParticleVector;
|
||||||
|
|
||||||
class ObjectType{
|
class ObjectType {
|
||||||
private:
|
private:
|
||||||
typedef vector<TilesetModelType*> ModelTypes;
|
typedef vector<TilesetModelType*> ModelTypes;
|
||||||
private:
|
private:
|
||||||
|
@ -51,6 +51,11 @@ private:
|
||||||
int height;
|
int height;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
ObjectType() {
|
||||||
|
objectClass = -1;
|
||||||
|
walkable = false;
|
||||||
|
height = 0;
|
||||||
|
}
|
||||||
~ObjectType();
|
~ObjectType();
|
||||||
void init(int modelCount, int objectClass, bool walkable, int height);
|
void init(int modelCount, int objectClass, bool walkable, int height);
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ using Shared::Graphics::Vec3f;
|
||||||
|
|
||||||
typedef vector<ObjectParticleSystemType*> ModelParticleSystemTypes;
|
typedef vector<ObjectParticleSystemType*> ModelParticleSystemTypes;
|
||||||
|
|
||||||
class TilesetModelType{
|
class TilesetModelType {
|
||||||
private:
|
private:
|
||||||
Model *model;
|
Model *model;
|
||||||
ModelParticleSystemTypes particleTypes;
|
ModelParticleSystemTypes particleTypes;
|
||||||
|
@ -41,6 +41,11 @@ private:
|
||||||
bool rotationAllowed;
|
bool rotationAllowed;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
TilesetModelType() {
|
||||||
|
model = NULL;
|
||||||
|
height = 0;
|
||||||
|
rotationAllowed = false;
|
||||||
|
}
|
||||||
~TilesetModelType();
|
~TilesetModelType();
|
||||||
|
|
||||||
void addParticleSystem(ObjectParticleSystemType *particleSystem);
|
void addParticleSystem(ObjectParticleSystemType *particleSystem);
|
||||||
|
|
|
@ -131,7 +131,7 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree,
|
||||||
this->id= id;
|
this->id= id;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Lang &lang= Lang::getInstance();
|
//Lang &lang= Lang::getInstance();
|
||||||
|
|
||||||
char szBuf[1024]="";
|
char szBuf[1024]="";
|
||||||
sprintf(szBuf,Lang::getInstance().get("LogScreenGameLoadingUnitType","",true).c_str(),formatString(name).c_str());
|
sprintf(szBuf,Lang::getInstance().get("LogScreenGameLoadingUnitType","",true).c_str(),formatString(name).c_str());
|
||||||
|
|
|
@ -46,6 +46,9 @@ private:
|
||||||
int kills;
|
int kills;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Level() {
|
||||||
|
kills = 0;
|
||||||
|
}
|
||||||
void init(string name, int kills);
|
void init(string name, int kills);
|
||||||
|
|
||||||
const string &getName() const {return name;}
|
const string &getName() const {return name;}
|
||||||
|
|
|
@ -72,6 +72,17 @@ private:
|
||||||
StaticSound nightStart;
|
StaticSound nightStart;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
AmbientSounds() {
|
||||||
|
enabledDay = false;
|
||||||
|
enabledNight = false;
|
||||||
|
enabledRain = false;
|
||||||
|
enabledSnow = false;
|
||||||
|
enabledDayStart = false;
|
||||||
|
enabledNightStart = false;
|
||||||
|
alwaysPlayDay = false;
|
||||||
|
alwaysPlayNight = false;
|
||||||
|
}
|
||||||
|
|
||||||
bool isEnabledDay() const {return enabledDay;}
|
bool isEnabledDay() const {return enabledDay;}
|
||||||
bool isEnabledNight() const {return enabledNight;}
|
bool isEnabledNight() const {return enabledNight;}
|
||||||
bool isEnabledRain() const {return enabledRain;}
|
bool isEnabledRain() const {return enabledRain;}
|
||||||
|
@ -131,6 +142,13 @@ private:
|
||||||
Checksum checksumValue;
|
Checksum checksumValue;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Tileset() {
|
||||||
|
waterTex = NULL;
|
||||||
|
waterEffects = false;
|
||||||
|
fog = false;
|
||||||
|
fogMode = 0;
|
||||||
|
fogDensity = 0.0f;
|
||||||
|
}
|
||||||
~Tileset();
|
~Tileset();
|
||||||
Checksum loadTileset(const vector<string> pathList, const string &tilesetName,
|
Checksum loadTileset(const vector<string> pathList, const string &tilesetName,
|
||||||
Checksum* checksum, std::map<string,vector<pair<string, string> > > &loadedFileList);
|
Checksum* checksum, std::map<string,vector<pair<string, string> > > &loadedFileList);
|
||||||
|
|
|
@ -29,7 +29,7 @@ using Shared::Sound::StaticSound;
|
||||||
/// Raises time related events (day/night cycle)
|
/// Raises time related events (day/night cycle)
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class TimeFlow{
|
class TimeFlow {
|
||||||
public:
|
public:
|
||||||
static const float dusk;
|
static const float dusk;
|
||||||
static const float dawn;
|
static const float dawn;
|
||||||
|
@ -42,6 +42,13 @@ private:
|
||||||
float timeInc;
|
float timeInc;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
TimeFlow() {
|
||||||
|
firstTime = false;
|
||||||
|
tileset = NULL;
|
||||||
|
time = 0.0f;
|
||||||
|
lastTime = 0.0f;
|
||||||
|
timeInc = 0.0f;
|
||||||
|
}
|
||||||
void init(Tileset *tileset);
|
void init(Tileset *tileset);
|
||||||
|
|
||||||
float getTime() const {return time;}
|
float getTime() const {return time;}
|
||||||
|
|
|
@ -1277,7 +1277,7 @@ void UnitUpdater::updateHarvest(Unit *unit, int frameIndex) {
|
||||||
if (r->decAmount(1)) {
|
if (r->decAmount(1)) {
|
||||||
const ResourceType *rt = r->getType();
|
const ResourceType *rt = r->getType();
|
||||||
sc->deleteResource();
|
sc->deleteResource();
|
||||||
unit->getFaction()->removeResourceTargetFromCache(unitTargetPos);
|
world->removeResourceTargetFromCache(unitTargetPos);
|
||||||
|
|
||||||
switch(this->game->getGameSettings()->getPathFinderType()) {
|
switch(this->game->getGameSettings()->getPathFinderType()) {
|
||||||
case pfBasic:
|
case pfBasic:
|
||||||
|
@ -2178,26 +2178,28 @@ bool UnitUpdater::findCachedCellsEnemies(Vec2i center, int range, int size, vect
|
||||||
bool result = false;
|
bool result = false;
|
||||||
//return result;
|
//return result;
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(&mutexUnitRangeCellsLookupItemCache,string(__FILE__) + "_" + intToStr(__LINE__));
|
if(game->isMasterserverMode() == false) {
|
||||||
std::map<Vec2i, std::map<int, std::map<int, UnitRangeCellsLookupItem > > >::iterator iterFind = UnitRangeCellsLookupItemCache.find(center);
|
MutexSafeWrapper safeMutex(&mutexUnitRangeCellsLookupItemCache,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
|
std::map<Vec2i, std::map<int, std::map<int, UnitRangeCellsLookupItem > > >::iterator iterFind = UnitRangeCellsLookupItemCache.find(center);
|
||||||
|
|
||||||
if(iterFind != UnitRangeCellsLookupItemCache.end()) {
|
if(iterFind != UnitRangeCellsLookupItemCache.end()) {
|
||||||
std::map<int, std::map<int, UnitRangeCellsLookupItem > >::iterator iterFind3 = iterFind->second.find(size);
|
std::map<int, std::map<int, UnitRangeCellsLookupItem > >::iterator iterFind3 = iterFind->second.find(size);
|
||||||
if(iterFind3 != iterFind->second.end()) {
|
if(iterFind3 != iterFind->second.end()) {
|
||||||
std::map<int, UnitRangeCellsLookupItem>::iterator iterFind4 = iterFind3->second.find(range);
|
std::map<int, UnitRangeCellsLookupItem>::iterator iterFind4 = iterFind3->second.find(range);
|
||||||
if(iterFind4 != iterFind3->second.end()) {
|
if(iterFind4 != iterFind3->second.end()) {
|
||||||
result = true;
|
result = true;
|
||||||
|
|
||||||
std::vector<Cell *> &cellList = iterFind4->second.rangeCellList;
|
std::vector<Cell *> &cellList = iterFind4->second.rangeCellList;
|
||||||
for(int idx = 0; idx < cellList.size(); ++idx) {
|
for(int idx = 0; idx < cellList.size(); ++idx) {
|
||||||
Cell *cell = cellList[idx];
|
Cell *cell = cellList[idx];
|
||||||
|
|
||||||
findEnemiesForCell(ast,cell,unit,commandTarget,enemies);
|
findEnemiesForCell(ast,cell,unit,commandTarget,enemies);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
}
|
}
|
||||||
safeMutex.ReleaseLock();
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -2299,7 +2301,7 @@ bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ok update our caches with the latest info
|
// Ok update our caches with the latest info
|
||||||
if(cacheItem.rangeCellList.size() > 0) {
|
if(cacheItem.rangeCellList.empty() == false) {
|
||||||
MutexSafeWrapper safeMutex(&mutexUnitRangeCellsLookupItemCache,string(__FILE__) + "_" + intToStr(__LINE__));
|
MutexSafeWrapper safeMutex(&mutexUnitRangeCellsLookupItemCache,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
|
|
||||||
//cacheItem.UnitRangeCellsLookupItemCacheTimerCountIndex = UnitRangeCellsLookupItemCacheTimerCount++;
|
//cacheItem.UnitRangeCellsLookupItemCacheTimerCountIndex = UnitRangeCellsLookupItemCacheTimerCount++;
|
||||||
|
@ -2483,7 +2485,7 @@ vector<Unit*> UnitUpdater::enemyUnitsOnRange(const Unit *unit,const AttackSkillT
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ok update our caches with the latest info
|
// Ok update our caches with the latest info
|
||||||
if(cacheItem.rangeCellList.size() > 0) {
|
if(cacheItem.rangeCellList.empty() == false) {
|
||||||
MutexSafeWrapper safeMutex(&mutexUnitRangeCellsLookupItemCache,string(__FILE__) + "_" + intToStr(__LINE__));
|
MutexSafeWrapper safeMutex(&mutexUnitRangeCellsLookupItemCache,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
|
|
||||||
//cacheItem.UnitRangeCellsLookupItemCacheTimerCountIndex = UnitRangeCellsLookupItemCacheTimerCount++;
|
//cacheItem.UnitRangeCellsLookupItemCacheTimerCountIndex = UnitRangeCellsLookupItemCacheTimerCount++;
|
||||||
|
@ -2537,6 +2539,41 @@ vector<Unit*> UnitUpdater::findUnitsInRange(const Unit *unit, int radius) {
|
||||||
return units;
|
return units;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string UnitUpdater::getUnitRangeCellsLookupItemCacheStats() {
|
||||||
|
string result = "";
|
||||||
|
|
||||||
|
int posCount = 0;
|
||||||
|
int sizeCount = 0;
|
||||||
|
int rangeCount = 0;
|
||||||
|
int rangeCountCellCount = 0;
|
||||||
|
|
||||||
|
Mutex mutexUnitRangeCellsLookupItemCache;
|
||||||
|
//std::map<Vec2i, std::map<int, std::map<int, UnitRangeCellsLookupItem > > > UnitRangeCellsLookupItemCache;
|
||||||
|
for(std::map<Vec2i, std::map<int, std::map<int, UnitRangeCellsLookupItem > > >::iterator iterMap1 = UnitRangeCellsLookupItemCache.begin();
|
||||||
|
iterMap1 != UnitRangeCellsLookupItemCache.end(); ++iterMap1) {
|
||||||
|
posCount++;
|
||||||
|
|
||||||
|
for(std::map<int, std::map<int, UnitRangeCellsLookupItem > >::iterator iterMap2 = iterMap1->second.begin();
|
||||||
|
iterMap2 != iterMap1->second.end(); ++iterMap2) {
|
||||||
|
sizeCount++;
|
||||||
|
|
||||||
|
for(std::map<int, UnitRangeCellsLookupItem>::iterator iterMap3 = iterMap2->second.begin();
|
||||||
|
iterMap3 != iterMap2->second.end(); ++iterMap3) {
|
||||||
|
rangeCount++;
|
||||||
|
|
||||||
|
rangeCountCellCount += iterMap3->second.rangeCellList.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64 totalBytes = rangeCountCellCount * sizeof(Cell *);
|
||||||
|
totalBytes /= 1000;
|
||||||
|
|
||||||
|
char szBuf[1024]="";
|
||||||
|
sprintf(szBuf,"pos [%d] size [%d] range [%d][%d] total KB: %s",posCount,sizeCount,rangeCount,rangeCountCellCount,formatNumber(totalBytes).c_str());
|
||||||
|
result = szBuf;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class ParticleDamager
|
// class ParticleDamager
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
|
@ -126,6 +126,8 @@ public:
|
||||||
void findUnitsForCell(Cell *cell, const Unit *unit,vector<Unit*> &units);
|
void findUnitsForCell(Cell *cell, const Unit *unit,vector<Unit*> &units);
|
||||||
vector<Unit*> findUnitsInRange(const Unit *unit, int radius);
|
vector<Unit*> findUnitsInRange(const Unit *unit, int radius);
|
||||||
|
|
||||||
|
string getUnitRangeCellsLookupItemCacheStats();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//attack
|
//attack
|
||||||
void hit(Unit *attacker);
|
void hit(Unit *attacker);
|
||||||
|
|
|
@ -325,7 +325,7 @@ Checksum World::loadScenario(const string &path, Checksum *checksum, bool resetC
|
||||||
|
|
||||||
if(resetCurrentScenario == true) {
|
if(resetCurrentScenario == true) {
|
||||||
scenario = Scenario();
|
scenario = Scenario();
|
||||||
scriptManager->init(this, this->getGame()->getGameCamera());
|
scriptManager->init(this, this->getGame()->getGameCameraPtr());
|
||||||
}
|
}
|
||||||
|
|
||||||
scenarioChecksum = scenario.load(path);
|
scenarioChecksum = scenario.load(path);
|
||||||
|
@ -1436,7 +1436,8 @@ void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex) {
|
||||||
//bool cacheLookupSightResult = false;
|
//bool cacheLookupSightResult = false;
|
||||||
|
|
||||||
// cache lookup of previously calculated cells + sight range
|
// cache lookup of previously calculated cells + sight range
|
||||||
if(MaxExploredCellsLookupItemCache > 0) {
|
if(MaxExploredCellsLookupItemCache > 0 && game->isMasterserverMode() == false) {
|
||||||
|
//if(MaxExploredCellsLookupItemCache > 0) {
|
||||||
if(difftime(time(NULL),ExploredCellsLookupItem::lastDebug) >= 10) {
|
if(difftime(time(NULL),ExploredCellsLookupItem::lastDebug) >= 10) {
|
||||||
ExploredCellsLookupItem::lastDebug = time(NULL);
|
ExploredCellsLookupItem::lastDebug = time(NULL);
|
||||||
//printf("In [%s::%s Line: %d] ExploredCellsLookupItemCache.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,ExploredCellsLookupItemCache.size());
|
//printf("In [%s::%s Line: %d] ExploredCellsLookupItemCache.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,ExploredCellsLookupItemCache.size());
|
||||||
|
@ -1540,7 +1541,7 @@ void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex) {
|
||||||
|
|
||||||
// Ok update our caches with the latest info for this position, sight and team
|
// Ok update our caches with the latest info for this position, sight and team
|
||||||
if(MaxExploredCellsLookupItemCache > 0) {
|
if(MaxExploredCellsLookupItemCache > 0) {
|
||||||
if(item.exploredCellList.size() > 0 || item.visibleCellList.size() > 0) {
|
if(item.exploredCellList.empty() == false || item.visibleCellList.empty() == false) {
|
||||||
//ExploredCellsLookupItemCache.push_back(item);
|
//ExploredCellsLookupItemCache.push_back(item);
|
||||||
item.ExploredCellsLookupItemCacheTimerCountIndex = ExploredCellsLookupItemCacheTimerCount++;
|
item.ExploredCellsLookupItemCacheTimerCountIndex = ExploredCellsLookupItemCacheTimerCount++;
|
||||||
ExploredCellsLookupItemCache[newPos][sightRange] = item;
|
ExploredCellsLookupItemCache[newPos][sightRange] = item;
|
||||||
|
@ -1701,7 +1702,9 @@ void World::computeFow(int factionIdxToTick) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//compute texture
|
//compute texture
|
||||||
if(fogOfWar) {
|
//printf("Masterserver = %d\n",game->isMasterserverMode());
|
||||||
|
|
||||||
|
if(fogOfWar == true && game->isMasterserverMode() == false) {
|
||||||
for(int i=0; i<getFactionCount(); ++i) {
|
for(int i=0; i<getFactionCount(); ++i) {
|
||||||
Faction *faction= getFaction(i);
|
Faction *faction= getFaction(i);
|
||||||
if(faction->getTeam() == thisTeamIndex) {
|
if(faction->getTeam() == thisTeamIndex) {
|
||||||
|
@ -1758,7 +1761,7 @@ void World::computeFow(int factionIdxToTick) {
|
||||||
itemCache.alphaList.push_back(alpha);
|
itemCache.alphaList.push_back(alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(itemCache.surfPosList.size() > 0) {
|
if(itemCache.surfPosList.empty() == false) {
|
||||||
FowAlphaCellsLookupItemCache[unit->getPos()][sightRange] = itemCache;
|
FowAlphaCellsLookupItemCache[unit->getPos()][sightRange] = itemCache;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1796,6 +1799,98 @@ int World::getNextCommandGroupId() {
|
||||||
return ++nextCommandGroupId;
|
return ++nextCommandGroupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void World::removeResourceTargetFromCache(const Vec2i &pos) {
|
||||||
|
for(int i= 0; i < factions.size(); ++i) {
|
||||||
|
factions[i]->removeResourceTargetFromCache(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string World::getExploredCellsLookupItemCacheStats() {
|
||||||
|
string result = "";
|
||||||
|
|
||||||
|
int posCount = 0;
|
||||||
|
int sightCount = 0;
|
||||||
|
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++;
|
||||||
|
|
||||||
|
for(std::map<int, ExploredCellsLookupItem >::iterator iterMap2 = iterMap1->second.begin();
|
||||||
|
iterMap2 != iterMap1->second.end(); ++iterMap2) {
|
||||||
|
sightCount++;
|
||||||
|
|
||||||
|
exploredCellCount += iterMap2->second.exploredCellList.size();
|
||||||
|
visibleCellCount += iterMap2->second.visibleCellList.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64 totalBytes = exploredCellCount * sizeof(SurfaceCell *);
|
||||||
|
totalBytes += visibleCellCount * sizeof(SurfaceCell *);
|
||||||
|
|
||||||
|
totalBytes /= 1000;
|
||||||
|
|
||||||
|
char szBuf[1024]="";
|
||||||
|
sprintf(szBuf,"pos [%d] sight [%d] [%d][%d] total KB: %s",posCount,sightCount,exploredCellCount,visibleCellCount,formatNumber(totalBytes).c_str());
|
||||||
|
result = szBuf;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
string World::getFowAlphaCellsLookupItemCacheStats() {
|
||||||
|
string result = "";
|
||||||
|
|
||||||
|
int posCount = 0;
|
||||||
|
int sightCount = 0;
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64 totalBytes = surfPosCount * sizeof(Vec2i);
|
||||||
|
totalBytes += alphaListCount * sizeof(float);
|
||||||
|
|
||||||
|
totalBytes /= 1000;
|
||||||
|
|
||||||
|
char szBuf[1024]="";
|
||||||
|
sprintf(szBuf,"pos [%d] sight [%d] [%d][%d] total KB: %s",posCount,sightCount,surfPosCount,alphaListCount,formatNumber(totalBytes).c_str());
|
||||||
|
result = szBuf;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
string World::getAllFactionsCacheStats() {
|
||||||
|
string result = "";
|
||||||
|
|
||||||
|
uint64 totalBytes = 0;
|
||||||
|
uint64 totalCache1Size = 0;
|
||||||
|
uint64 totalCache2Size = 0;
|
||||||
|
for(int i = 0; i < getFactionCount(); ++i) {
|
||||||
|
uint64 cache1Size = 0;
|
||||||
|
uint64 cache2Size = 0;
|
||||||
|
totalBytes += getFaction(i)->getCacheKBytes(&cache1Size, &cache2Size);
|
||||||
|
totalCache1Size += cache1Size;
|
||||||
|
totalCache2Size += cache2Size;
|
||||||
|
}
|
||||||
|
|
||||||
|
char szBuf[1024]="";
|
||||||
|
sprintf(szBuf,"totalCache1Size [%lu] totalCache1Size [%lu] total KB: %s",totalCache1Size,totalCache2Size,formatNumber(totalBytes).c_str());
|
||||||
|
result = szBuf;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
std::string World::DumpWorldToLog(bool consoleBasicInfoOnly) const {
|
std::string World::DumpWorldToLog(bool consoleBasicInfoOnly) const {
|
||||||
|
|
||||||
string debugWorldLogFile = Config::getInstance().getString("DebugWorldLogFile","debugWorld.log");
|
string debugWorldLogFile = Config::getInstance().getString("DebugWorldLogFile","debugWorld.log");
|
||||||
|
|
|
@ -82,7 +82,7 @@ public:
|
||||||
static time_t lastDebug;
|
static time_t lastDebug;
|
||||||
};
|
};
|
||||||
|
|
||||||
class World{
|
class World {
|
||||||
private:
|
private:
|
||||||
typedef vector<Faction *> Factions;
|
typedef vector<Faction *> Factions;
|
||||||
|
|
||||||
|
@ -258,6 +258,12 @@ public:
|
||||||
|
|
||||||
UnitUpdater * getUnitUpdater() { return &unitUpdater; }
|
UnitUpdater * getUnitUpdater() { return &unitUpdater; }
|
||||||
|
|
||||||
|
void removeResourceTargetFromCache(const Vec2i &pos);
|
||||||
|
|
||||||
|
string getExploredCellsLookupItemCacheStats();
|
||||||
|
string getFowAlphaCellsLookupItemCacheStats();
|
||||||
|
string getAllFactionsCacheStats();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void initCells(bool fogOfWar);
|
void initCells(bool fogOfWar);
|
||||||
|
|
|
@ -120,10 +120,10 @@ protected:
|
||||||
time_t lastThreadedPing;
|
time_t lastThreadedPing;
|
||||||
//Mutex pingThreadAccessor;
|
//Mutex pingThreadAccessor;
|
||||||
|
|
||||||
Mutex dataSynchAccessorRead;
|
Mutex *dataSynchAccessorRead;
|
||||||
Mutex dataSynchAccessorWrite;
|
Mutex *dataSynchAccessorWrite;
|
||||||
|
|
||||||
Mutex inSocketDestructorSynchAccessor;
|
Mutex *inSocketDestructorSynchAccessor;
|
||||||
bool inSocketDestructor;
|
bool inSocketDestructor;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -214,7 +214,7 @@ protected:
|
||||||
class BroadCastSocketThread : public BaseThread
|
class BroadCastSocketThread : public BaseThread
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Mutex mutexPauseBroadcast;
|
Mutex *mutexPauseBroadcast;
|
||||||
bool pauseBroadcast;
|
bool pauseBroadcast;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -38,6 +38,8 @@ string doubleToStr(double f,int precsion=2);
|
||||||
|
|
||||||
bool IsNumeric(const char *p, bool allowNegative=true);
|
bool IsNumeric(const char *p, bool allowNegative=true);
|
||||||
|
|
||||||
|
string formatNumber(uint64 f);
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -119,13 +119,14 @@ int ftpCreateAccount(const char* name, const char* passw, const char* root, int
|
||||||
*/
|
*/
|
||||||
int ftpFindAccount(const char* name)
|
int ftpFindAccount(const char* name)
|
||||||
{
|
{
|
||||||
int n;
|
if(name[0] != '\0') {
|
||||||
|
int n;
|
||||||
if(name[0] != '\0')
|
for(n = 0; n < MAX_USERS; n++) {
|
||||||
for(n = 0; n < MAX_USERS; n++)
|
if(!strncmp(ftpUsers[n].name, name, MAXLEN_USERNAME)) {
|
||||||
if(!strncmp(ftpUsers[n].name, name, MAXLEN_USERNAME))
|
|
||||||
return n + 1;
|
return n + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -276,7 +276,6 @@ LOCAL int ftpCmdAbor(int sessionId, const char* args, int len)
|
||||||
#define MLSD 8
|
#define MLSD 8
|
||||||
LOCAL int sendListing(socket_t dataSocket, int sessionId, const char* path, int format)
|
LOCAL int sendListing(socket_t dataSocket, int sessionId, const char* path, int format)
|
||||||
{
|
{
|
||||||
int haveAnySuccessfulFiles = 0;
|
|
||||||
void *dir;
|
void *dir;
|
||||||
const char monName[12][4] = {
|
const char monName[12][4] = {
|
||||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||||
|
@ -286,11 +285,12 @@ LOCAL int sendListing(socket_t dataSocket, int sessionId, const char* path, int
|
||||||
dir = ftpOpenDir(path);
|
dir = ftpOpenDir(path);
|
||||||
if(dir)
|
if(dir)
|
||||||
{
|
{
|
||||||
const char* dirEntry;
|
const char* dirEntry = NULL;
|
||||||
int len;
|
int len = 0;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
ftpTime_S currTime = {0};
|
ftpTime_S currTime = {0};
|
||||||
ftpPathInfo_S fileInfo;
|
ftpPathInfo_S fileInfo;
|
||||||
|
int haveAnySuccessfulFiles = 0;
|
||||||
|
|
||||||
ftpGetLocalTime(&currTime);
|
ftpGetLocalTime(&currTime);
|
||||||
ftpSendMsg(MSG_NORMAL, sessionId, 150, ftpMsg010);
|
ftpSendMsg(MSG_NORMAL, sessionId, 150, ftpMsg010);
|
||||||
|
@ -1023,7 +1023,6 @@ void ftpParseCmd(int sessionId)
|
||||||
{
|
{
|
||||||
ftpSession_S *pSession;
|
ftpSession_S *pSession;
|
||||||
int len;
|
int len;
|
||||||
int c;
|
|
||||||
socket_t ctrlSocket;
|
socket_t ctrlSocket;
|
||||||
|
|
||||||
pSession = ftpGetSession(sessionId);
|
pSession = ftpGetSession(sessionId);
|
||||||
|
@ -1033,6 +1032,7 @@ void ftpParseCmd(int sessionId)
|
||||||
if((pSession->rxBuf[len - 1] == '\n') &&
|
if((pSession->rxBuf[len - 1] == '\n') &&
|
||||||
(pSession->rxBuf[len - 2] == '\r') ) // command correctly terminated?
|
(pSession->rxBuf[len - 2] == '\r') ) // command correctly terminated?
|
||||||
{
|
{
|
||||||
|
int c = 0;
|
||||||
pSession->rxBuf[len - 2] = '\0';
|
pSession->rxBuf[len - 2] = '\0';
|
||||||
pSession->rxBufWriteIdx = 0;
|
pSession->rxBufWriteIdx = 0;
|
||||||
|
|
||||||
|
|
|
@ -548,8 +548,8 @@ int getLastSocketError() {
|
||||||
|
|
||||||
const char * getLastSocketErrorText(int *errNumber) {
|
const char * getLastSocketErrorText(int *errNumber) {
|
||||||
int errId = (errNumber != NULL ? *errNumber : getLastSocketError());
|
int errId = (errNumber != NULL ? *errNumber : getLastSocketError());
|
||||||
//return WSAGetLastErrorMessage("",errId);
|
return WSAGetLastErrorMessage("",errId);
|
||||||
return "?";
|
//return "?";
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -68,7 +68,8 @@ void TextFreetypeGL::init(string fontName, int fontSize) {
|
||||||
this->font = texture_font_new( atlas, fontFile, (float)fontFaceSize );
|
this->font = texture_font_new( atlas, fontFile, (float)fontFaceSize );
|
||||||
//font = texture_font_new( atlas, font_manager_match_description( 0, "Verdana", minsize, bold, italic ), minsize );
|
//font = texture_font_new( atlas, font_manager_match_description( 0, "Verdana", minsize, bold, italic ), minsize );
|
||||||
|
|
||||||
int missed = texture_font_cache_glyphs( font, cache );
|
//int missed = texture_font_cache_glyphs( font, cache );
|
||||||
|
texture_font_cache_glyphs( font, cache );
|
||||||
|
|
||||||
free((void*)this->fontFile);
|
free((void*)this->fontFile);
|
||||||
this->fontFile = NULL;
|
this->fontFile = NULL;
|
||||||
|
@ -113,7 +114,7 @@ void TextFreetypeGL::Render(const char* str, const int len) {
|
||||||
for(int i = 0; (len < 0 && *ustr) || (len >= 0 && i < len); i++) {
|
for(int i = 0; (len < 0 && *ustr) || (len >= 0 && i < len); i++) {
|
||||||
unsigned int prevChar = (i > 0 ? *ustr-1 : 0);
|
unsigned int prevChar = (i > 0 ? *ustr-1 : 0);
|
||||||
unsigned int thisChar = *ustr++;
|
unsigned int thisChar = *ustr++;
|
||||||
unsigned int nextChar = *ustr;
|
//unsigned int nextChar = *ustr;
|
||||||
|
|
||||||
// Get glyph (build it if needed
|
// Get glyph (build it if needed
|
||||||
TextureGlyph *glyph = texture_font_get_glyph( this->font, thisChar );
|
TextureGlyph *glyph = texture_font_get_glyph( this->font, thisChar );
|
||||||
|
|
|
@ -1037,7 +1037,7 @@ Md5Model::Md5Model (const string &filename)
|
||||||
while (!ifs.eof ())
|
while (!ifs.eof ())
|
||||||
{
|
{
|
||||||
string token, buffer;
|
string token, buffer;
|
||||||
int version;
|
int version = 0;
|
||||||
|
|
||||||
// Read next token
|
// Read next token
|
||||||
ifs >> token;
|
ifs >> token;
|
||||||
|
@ -1377,8 +1377,8 @@ Md5Animation::Md5Animation (const string &filename)
|
||||||
while (!ifs.eof ())
|
while (!ifs.eof ())
|
||||||
{
|
{
|
||||||
string token, buffer;
|
string token, buffer;
|
||||||
int version;
|
int version = 0;;
|
||||||
int i;
|
int i = 0;
|
||||||
|
|
||||||
// Read next token
|
// Read next token
|
||||||
ifs >> token;
|
ifs >> token;
|
||||||
|
|
|
@ -717,7 +717,7 @@ void MapPreview::loadFromFile(const string &path) {
|
||||||
#else
|
#else
|
||||||
FILE *f1 = fopen(path.c_str(), "rb");
|
FILE *f1 = fopen(path.c_str(), "rb");
|
||||||
#endif
|
#endif
|
||||||
int fileErrno = errno;
|
//int fileErrno = errno;
|
||||||
if (f1 != NULL) {
|
if (f1 != NULL) {
|
||||||
|
|
||||||
//read header
|
//read header
|
||||||
|
|
|
@ -202,12 +202,12 @@ void FileCRCPreCacheThread::execute() {
|
||||||
string &techPath = techDataPaths[idx];
|
string &techPath = techDataPaths[idx];
|
||||||
endPathWithSlash(techPath);
|
endPathWithSlash(techPath);
|
||||||
findAll(techPath + techName + "/factions/*.", results, false, false);
|
findAll(techPath + techName + "/factions/*.", results, false, false);
|
||||||
if(results.size() > 0) {
|
if(results.empty() == false) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(results.size() == 0) {
|
if(results.empty() == true) {
|
||||||
for(unsigned int factionIdx = 0; factionIdx < results.size(); ++factionIdx) {
|
for(unsigned int factionIdx = 0; factionIdx < results.size(); ++factionIdx) {
|
||||||
string factionName = results[factionIdx];
|
string factionName = results[factionIdx];
|
||||||
int32 factionCRC = 0;
|
int32 factionCRC = 0;
|
||||||
|
|
|
@ -76,6 +76,7 @@ getHTTPResponse(int s, int * size)
|
||||||
int chunksize_buf_index;
|
int chunksize_buf_index;
|
||||||
|
|
||||||
header_buf = malloc(header_buf_len);
|
header_buf = malloc(header_buf_len);
|
||||||
|
header_buf[0] = '\0';
|
||||||
content_buf = malloc(content_buf_len);
|
content_buf = malloc(content_buf_len);
|
||||||
chunksize_buf[0] = '\0';
|
chunksize_buf[0] = '\0';
|
||||||
chunksize_buf_index = 0;
|
chunksize_buf_index = 0;
|
||||||
|
|
|
@ -785,15 +785,19 @@ bool Socket::isSocketValid(const PLATFORM_SOCKET *validateSocket) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket::Socket(PLATFORM_SOCKET sock) {
|
Socket::Socket(PLATFORM_SOCKET sock) {
|
||||||
MutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,CODE_AT_LINE);
|
dataSynchAccessorRead = new Mutex();
|
||||||
inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
dataSynchAccessorWrite = new Mutex();
|
||||||
|
inSocketDestructorSynchAccessor = new Mutex();
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutexSocketDestructorFlag(inSocketDestructorSynchAccessor,CODE_AT_LINE);
|
||||||
|
inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE);
|
||||||
this->inSocketDestructor = false;
|
this->inSocketDestructor = false;
|
||||||
//safeMutexSocketDestructorFlag.ReleaseLock();
|
//safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
//this->pingThread = NULL;
|
//this->pingThread = NULL;
|
||||||
//pingThreadAccessor.setOwnerId(CODE_AT_LINE);
|
//pingThreadAccessor.setOwnerId(CODE_AT_LINE);
|
||||||
dataSynchAccessorRead.setOwnerId(CODE_AT_LINE);
|
dataSynchAccessorRead->setOwnerId(CODE_AT_LINE);
|
||||||
dataSynchAccessorWrite.setOwnerId(CODE_AT_LINE);
|
dataSynchAccessorWrite->setOwnerId(CODE_AT_LINE);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -802,8 +806,12 @@ Socket::Socket(PLATFORM_SOCKET sock) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket::Socket() {
|
Socket::Socket() {
|
||||||
MutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,CODE_AT_LINE);
|
dataSynchAccessorRead = new Mutex();
|
||||||
inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
dataSynchAccessorWrite = new Mutex();
|
||||||
|
inSocketDestructorSynchAccessor = new Mutex();
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutexSocketDestructorFlag(inSocketDestructorSynchAccessor,CODE_AT_LINE);
|
||||||
|
inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE);
|
||||||
this->inSocketDestructor = false;
|
this->inSocketDestructor = false;
|
||||||
//safeMutexSocketDestructorFlag.ReleaseLock();
|
//safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
|
@ -906,12 +914,12 @@ void Socket::simpleTask(BaseThread *callingThread) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Socket::~Socket() {
|
Socket::~Socket() {
|
||||||
MutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSocketDestructorFlag(inSocketDestructorSynchAccessor,CODE_AT_LINE);
|
||||||
if(this->inSocketDestructor == true) {
|
if(this->inSocketDestructor == true) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE);
|
||||||
this->inSocketDestructor = true;
|
this->inSocketDestructor = true;
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START closing socket = %d...\n",__FILE__,__FUNCTION__,sock);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START closing socket = %d...\n",__FILE__,__FUNCTION__,sock);
|
||||||
|
@ -922,9 +930,10 @@ Socket::~Socket() {
|
||||||
|
|
||||||
// Allow other callers with a lock on the mutexes to let them go
|
// Allow other callers with a lock on the mutexes to let them go
|
||||||
for(time_t elapsed = time(NULL);
|
for(time_t elapsed = time(NULL);
|
||||||
(dataSynchAccessorRead.getRefCount() > 0 ||
|
(dataSynchAccessorRead->getRefCount() > 0 ||
|
||||||
dataSynchAccessorWrite.getRefCount() > 0) &&
|
dataSynchAccessorWrite->getRefCount() > 0) &&
|
||||||
difftime(time(NULL),elapsed) <= 5;) {
|
difftime(time(NULL),elapsed) <= 2;) {
|
||||||
|
printf("Waiting in socket destructor\n");
|
||||||
//sleep(0);
|
//sleep(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -933,6 +942,13 @@ Socket::~Socket() {
|
||||||
//delete pingThread;
|
//delete pingThread;
|
||||||
//pingThread = NULL;
|
//pingThread = NULL;
|
||||||
safeMutexSocketDestructorFlag.ReleaseLock();
|
safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
|
delete dataSynchAccessorRead;
|
||||||
|
dataSynchAccessorRead = NULL;
|
||||||
|
delete dataSynchAccessorWrite;
|
||||||
|
dataSynchAccessorWrite = NULL;
|
||||||
|
delete inSocketDestructorSynchAccessor;
|
||||||
|
inSocketDestructorSynchAccessor = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::disconnectSocket() {
|
void Socket::disconnectSocket() {
|
||||||
|
@ -941,8 +957,8 @@ void Socket::disconnectSocket() {
|
||||||
if(isSocketValid() == true) {
|
if(isSocketValid() == true) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] calling shutdown and close for socket = %d...\n",__FILE__,__FUNCTION__,sock);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] calling shutdown and close for socket = %d...\n",__FILE__,__FUNCTION__,sock);
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(dataSynchAccessorRead,CODE_AT_LINE);
|
||||||
MutexSafeWrapper safeMutex1(&dataSynchAccessorWrite,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex1(dataSynchAccessorWrite,CODE_AT_LINE);
|
||||||
::shutdown(sock,2);
|
::shutdown(sock,2);
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
::close(sock);
|
::close(sock);
|
||||||
|
@ -1180,10 +1196,10 @@ int Socket::send(const void *data, int dataSize) {
|
||||||
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
// return -1;
|
// return -1;
|
||||||
// }
|
// }
|
||||||
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
// inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE);
|
||||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(dataSynchAccessorWrite,CODE_AT_LINE);
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
bytesSent = ::send(sock, (const char *)data, dataSize, SO_NOSIGPIPE);
|
bytesSent = ::send(sock, (const char *)data, dataSize, SO_NOSIGPIPE);
|
||||||
|
@ -1218,10 +1234,10 @@ int Socket::send(const void *data, int dataSize) {
|
||||||
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
// return -1;
|
// return -1;
|
||||||
// }
|
// }
|
||||||
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
// inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE);
|
||||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(dataSynchAccessorWrite,CODE_AT_LINE);
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
bytesSent = ::send(sock, (const char *)data, dataSize, SO_NOSIGPIPE);
|
bytesSent = ::send(sock, (const char *)data, dataSize, SO_NOSIGPIPE);
|
||||||
#else
|
#else
|
||||||
|
@ -1267,10 +1283,10 @@ int Socket::send(const void *data, int dataSize) {
|
||||||
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
// return -1;
|
// return -1;
|
||||||
// }
|
// }
|
||||||
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
// inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE);
|
||||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(dataSynchAccessorWrite,CODE_AT_LINE);
|
||||||
const char *sendBuf = (const char *)data;
|
const char *sendBuf = (const char *)data;
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
bytesSent = ::send(sock, &sendBuf[totalBytesSent], dataSize - totalBytesSent, SO_NOSIGPIPE);
|
bytesSent = ::send(sock, &sendBuf[totalBytesSent], dataSize - totalBytesSent, SO_NOSIGPIPE);
|
||||||
|
@ -1332,10 +1348,10 @@ int Socket::receive(void *data, int dataSize, bool tryReceiveUntilDataSizeMet) {
|
||||||
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
// return -1;
|
// return -1;
|
||||||
// }
|
// }
|
||||||
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
// inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE);
|
||||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(dataSynchAccessorRead,CODE_AT_LINE);
|
||||||
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
|
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
}
|
}
|
||||||
|
@ -1361,10 +1377,10 @@ int Socket::receive(void *data, int dataSize, bool tryReceiveUntilDataSizeMet) {
|
||||||
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
// return -1;
|
// return -1;
|
||||||
// }
|
// }
|
||||||
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
// inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE);
|
||||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(dataSynchAccessorRead,CODE_AT_LINE);
|
||||||
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
|
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
|
@ -1410,7 +1426,7 @@ int Socket::peek(void *data, int dataSize,bool mustGetData) {
|
||||||
|
|
||||||
const int MAX_PEEK_WAIT_SECONDS = 3;
|
const int MAX_PEEK_WAIT_SECONDS = 3;
|
||||||
|
|
||||||
ssize_t err = 0;
|
int err = 0;
|
||||||
if(isSocketValid() == true) {
|
if(isSocketValid() == true) {
|
||||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
|
|
||||||
|
@ -1419,17 +1435,19 @@ int Socket::peek(void *data, int dataSize,bool mustGetData) {
|
||||||
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
// return -1;
|
// return -1;
|
||||||
// }
|
// }
|
||||||
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
// inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE);
|
||||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
//MutexSafeWrapper safeMutex(&dataSynchAccessor,CODE_AT_LINE + "_" + intToStr(sock) + "_" + intToStr(dataSize));
|
//MutexSafeWrapper safeMutex(&dataSynchAccessor,CODE_AT_LINE + "_" + intToStr(sock) + "_" + intToStr(dataSize));
|
||||||
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(dataSynchAccessorRead,CODE_AT_LINE);
|
||||||
|
|
||||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
|
|
||||||
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
|
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
|
//printf("Peek #1 err = %d\n",err);
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) if(chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) if(chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
}
|
}
|
||||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
|
@ -1441,6 +1459,8 @@ int Socket::peek(void *data, int dataSize,bool mustGetData) {
|
||||||
else if(err < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN && mustGetData == true) {
|
else if(err < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN && mustGetData == true) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 ERROR EAGAIN during peek, trying again...\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 ERROR EAGAIN during peek, trying again...\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
//printf("Peek #2 err = %d\n",err);
|
||||||
|
|
||||||
time_t tStartTimer = time(NULL);
|
time_t tStartTimer = time(NULL);
|
||||||
while((err < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) &&
|
while((err < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) &&
|
||||||
(difftime(time(NULL),tStartTimer) <= MAX_PEEK_WAIT_SECONDS)) {
|
(difftime(time(NULL),tStartTimer) <= MAX_PEEK_WAIT_SECONDS)) {
|
||||||
|
@ -1458,11 +1478,11 @@ int Socket::peek(void *data, int dataSize,bool mustGetData) {
|
||||||
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
// return -1;
|
// return -1;
|
||||||
// }
|
// }
|
||||||
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
// inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE);
|
||||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
//MutexSafeWrapper safeMutex(&dataSynchAccessor,CODE_AT_LINE + "_" + intToStr(sock) + "_" + intToStr(dataSize));
|
//MutexSafeWrapper safeMutex(&dataSynchAccessor,CODE_AT_LINE + "_" + intToStr(sock) + "_" + intToStr(dataSize));
|
||||||
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(dataSynchAccessorRead,CODE_AT_LINE);
|
||||||
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
|
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
|
@ -1477,6 +1497,7 @@ int Socket::peek(void *data, int dataSize,bool mustGetData) {
|
||||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
|
|
||||||
if(err <= 0) {
|
if(err <= 0) {
|
||||||
|
//printf("Peek #3 err = %d\n",err);
|
||||||
if(mustGetData == true || getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) {
|
if(mustGetData == true || getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) {
|
||||||
int iErr = getLastSocketError();
|
int iErr = getLastSocketError();
|
||||||
disconnectSocket();
|
disconnectSocket();
|
||||||
|
@ -1537,7 +1558,7 @@ bool Socket::isReadable() {
|
||||||
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
// return false;
|
// return false;
|
||||||
//}
|
//}
|
||||||
//inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
//inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE);
|
||||||
//safeMutexSocketDestructorFlag.ReleaseLock();
|
//safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||||
|
@ -1574,7 +1595,7 @@ bool Socket::isWritable() {
|
||||||
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
// return false;
|
// return false;
|
||||||
//}
|
//}
|
||||||
//inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
//inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE);
|
||||||
//safeMutexSocketDestructorFlag.ReleaseLock();
|
//safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
|
//MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
|
||||||
|
@ -1607,7 +1628,7 @@ bool Socket::isConnected() {
|
||||||
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
// inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE);
|
||||||
|
|
||||||
//if the socket is not writable then it is not conencted
|
//if the socket is not writable then it is not conencted
|
||||||
if(isWritable() == false) {
|
if(isWritable() == false) {
|
||||||
|
@ -1618,9 +1639,10 @@ bool Socket::isConnected() {
|
||||||
if(isReadable()) {
|
if(isReadable()) {
|
||||||
char tmp=0;
|
char tmp=0;
|
||||||
int err = peek(&tmp, 1, false);
|
int err = peek(&tmp, 1, false);
|
||||||
if(err <= 0 && err != PLATFORM_SOCKET_TRY_AGAIN) {
|
//if(err <= 0 && err != PLATFORM_SOCKET_TRY_AGAIN) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] ERROR Peek failed, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,err,getLastSocketErrorFormattedText().c_str());
|
if(err <= 0) {
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) SystemFlags::OutputDebug(SystemFlags::debugError,"SOCKET DISCONNECTED In [%s::%s Line: %d] ERROR Peek failed, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,err,getLastSocketErrorFormattedText().c_str());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] ERROR Peek failed, err = %d for socket: %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,err,sock,getLastSocketErrorFormattedText().c_str());
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) SystemFlags::OutputDebug(SystemFlags::debugError,"SOCKET DISCONNECTED In [%s::%s Line: %d] ERROR Peek failed, err = %d for socket: %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,err,sock,getLastSocketErrorFormattedText().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1757,7 +1779,7 @@ void ClientSocket::connect(const Ip &ip, int port)
|
||||||
FD_SET(sock, &myset);
|
FD_SET(sock, &myset);
|
||||||
|
|
||||||
{
|
{
|
||||||
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(dataSynchAccessorRead,CODE_AT_LINE);
|
||||||
err = select((int)sock + 1, NULL, &myset, NULL, &tv);
|
err = select((int)sock + 1, NULL, &myset, NULL, &tv);
|
||||||
//safeMutex.ReleaseLock();
|
//safeMutex.ReleaseLock();
|
||||||
}
|
}
|
||||||
|
@ -2175,7 +2197,7 @@ Socket *ServerSocket::accept() {
|
||||||
struct sockaddr_in cli_addr;
|
struct sockaddr_in cli_addr;
|
||||||
socklen_t clilen = sizeof(cli_addr);
|
socklen_t clilen = sizeof(cli_addr);
|
||||||
char client_host[100]="";
|
char client_host[100]="";
|
||||||
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(dataSynchAccessorRead,CODE_AT_LINE);
|
||||||
PLATFORM_SOCKET newSock= ::accept(sock, (struct sockaddr *) &cli_addr, &clilen);
|
PLATFORM_SOCKET newSock= ::accept(sock, (struct sockaddr *) &cli_addr, &clilen);
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
|
@ -2549,23 +2571,27 @@ void UPNP_Tools::NETremRedirects(int ext_port) {
|
||||||
//
|
//
|
||||||
BroadCastSocketThread::BroadCastSocketThread() : BaseThread() {
|
BroadCastSocketThread::BroadCastSocketThread() : BaseThread() {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
mutexPauseBroadcast = new Mutex();
|
||||||
setPauseBroadcast(false);
|
setPauseBroadcast(false);
|
||||||
//printf("new broadcast thread [%p]\n",this);
|
//printf("new broadcast thread [%p]\n",this);
|
||||||
}
|
}
|
||||||
|
|
||||||
BroadCastSocketThread::~BroadCastSocketThread() {
|
BroadCastSocketThread::~BroadCastSocketThread() {
|
||||||
//printf("delete broadcast thread [%p]\n",this);
|
//printf("delete broadcast thread [%p]\n",this);
|
||||||
|
|
||||||
|
delete mutexPauseBroadcast;
|
||||||
|
mutexPauseBroadcast = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BroadCastSocketThread::getPauseBroadcast() {
|
bool BroadCastSocketThread::getPauseBroadcast() {
|
||||||
MutexSafeWrapper safeMutexSocketDestructorFlag(&mutexPauseBroadcast,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSocketDestructorFlag(mutexPauseBroadcast,CODE_AT_LINE);
|
||||||
mutexPauseBroadcast.setOwnerId(CODE_AT_LINE);
|
mutexPauseBroadcast->setOwnerId(CODE_AT_LINE);
|
||||||
return pauseBroadcast;
|
return pauseBroadcast;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BroadCastSocketThread::setPauseBroadcast(bool value) {
|
void BroadCastSocketThread::setPauseBroadcast(bool value) {
|
||||||
MutexSafeWrapper safeMutexSocketDestructorFlag(&mutexPauseBroadcast,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSocketDestructorFlag(mutexPauseBroadcast,CODE_AT_LINE);
|
||||||
mutexPauseBroadcast.setOwnerId(CODE_AT_LINE);
|
mutexPauseBroadcast->setOwnerId(CODE_AT_LINE);
|
||||||
pauseBroadcast = value;
|
pauseBroadcast = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2592,7 +2618,7 @@ void BroadCastSocketThread::execute() {
|
||||||
short port=0; // The port for the broadcast.
|
short port=0; // The port for the broadcast.
|
||||||
struct sockaddr_in bcLocal[MAX_NIC_COUNT]; // local socket address for the broadcast.
|
struct sockaddr_in bcLocal[MAX_NIC_COUNT]; // local socket address for the broadcast.
|
||||||
PLATFORM_SOCKET bcfd[MAX_NIC_COUNT]; // The socket used for the broadcast.
|
PLATFORM_SOCKET bcfd[MAX_NIC_COUNT]; // The socket used for the broadcast.
|
||||||
bool one = true; // Parameter for "setscokopt".
|
int one = 1; // Parameter for "setscokopt".
|
||||||
int pn=0; // The number of the packet broadcasted.
|
int pn=0; // The number of the packet broadcasted.
|
||||||
const int buffMaxSize=1024;
|
const int buffMaxSize=1024;
|
||||||
char buff[buffMaxSize]=""; // Buffers the data to be broadcasted.
|
char buff[buffMaxSize]=""; // Buffers the data to be broadcasted.
|
||||||
|
|
|
@ -94,29 +94,38 @@ void Thread::resume() {
|
||||||
|
|
||||||
class SDLMutexSafeWrapper {
|
class SDLMutexSafeWrapper {
|
||||||
protected:
|
protected:
|
||||||
SDL_mutex *mutex;
|
SDL_mutex **mutex;
|
||||||
|
bool destroyMutexInDestructor;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SDLMutexSafeWrapper(SDL_mutex *mutex) {
|
SDLMutexSafeWrapper(SDL_mutex **mutex, bool destroyMutexInDestructor=false) {
|
||||||
this->mutex = mutex;
|
this->mutex = mutex;
|
||||||
|
this->destroyMutexInDestructor = destroyMutexInDestructor;
|
||||||
Lock();
|
Lock();
|
||||||
}
|
}
|
||||||
~SDLMutexSafeWrapper() {
|
~SDLMutexSafeWrapper() {
|
||||||
ReleaseLock();
|
bool keepMutex = (this->destroyMutexInDestructor == true && mutex != NULL && *mutex != NULL);
|
||||||
|
ReleaseLock(keepMutex);
|
||||||
|
|
||||||
|
if(this->destroyMutexInDestructor == true && mutex != NULL && *mutex != NULL) {
|
||||||
|
SDL_DestroyMutex(*mutex);
|
||||||
|
*mutex = NULL;
|
||||||
|
mutex = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lock() {
|
void Lock() {
|
||||||
if(this->mutex != NULL) {
|
if(mutex != NULL && *mutex != NULL) {
|
||||||
SDL_mutexP(this->mutex);
|
SDL_mutexP(*mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ReleaseLock(bool keepMutex=false) {
|
void ReleaseLock(bool keepMutex=false) {
|
||||||
if(this->mutex != NULL) {
|
if(mutex != NULL && *mutex != NULL) {
|
||||||
SDL_mutexV(this->mutex);
|
SDL_mutexV(*mutex);
|
||||||
|
|
||||||
if(keepMutex == false) {
|
if(keepMutex == false) {
|
||||||
this->mutex = NULL;
|
mutex = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,7 +133,7 @@ public:
|
||||||
|
|
||||||
Mutex::Mutex(string ownerId) {
|
Mutex::Mutex(string ownerId) {
|
||||||
mutexAccessor = SDL_CreateMutex();
|
mutexAccessor = SDL_CreateMutex();
|
||||||
SDLMutexSafeWrapper safeMutex(mutexAccessor);
|
SDLMutexSafeWrapper safeMutex(&mutexAccessor);
|
||||||
refCount=0;
|
refCount=0;
|
||||||
this->ownerId = ownerId;
|
this->ownerId = ownerId;
|
||||||
mutex = SDL_CreateMutex();
|
mutex = SDL_CreateMutex();
|
||||||
|
@ -138,7 +147,7 @@ Mutex::Mutex(string ownerId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Mutex::~Mutex() {
|
Mutex::~Mutex() {
|
||||||
SDLMutexSafeWrapper safeMutex(mutexAccessor);
|
SDLMutexSafeWrapper safeMutex(&mutexAccessor,true);
|
||||||
if(mutex == NULL) {
|
if(mutex == NULL) {
|
||||||
char szBuf[1024]="";
|
char szBuf[1024]="";
|
||||||
snprintf(szBuf,1023,"In [%s::%s Line: %d] mutex == NULL refCount = %d owner [%s] deleteownerId [%s]",__FILE__,__FUNCTION__,__LINE__,refCount,ownerId.c_str(),deleteownerId.c_str());
|
snprintf(szBuf,1023,"In [%s::%s Line: %d] mutex == NULL refCount = %d owner [%s] deleteownerId [%s]",__FILE__,__FUNCTION__,__LINE__,refCount,ownerId.c_str(),deleteownerId.c_str());
|
||||||
|
|
|
@ -15,6 +15,9 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include "platform_common.h"
|
#include "platform_common.h"
|
||||||
|
#include <sstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <locale>
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -145,4 +148,21 @@ bool IsNumeric(const char *p, bool allowNegative) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Comma: public numpunct<char>// own facet class
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
char do_thousands_sep() const { return ','; }// use the comma
|
||||||
|
string do_grouping() const { return "\3"; }//group 3 digits
|
||||||
|
};
|
||||||
|
string formatNumber(uint64 f) {
|
||||||
|
|
||||||
|
locale myloc( locale(), // C++ default locale
|
||||||
|
new Comma);// Own numeric facet
|
||||||
|
|
||||||
|
ostringstream out;
|
||||||
|
out.imbue(myloc);
|
||||||
|
out << f;
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
Loading…
Reference in New Issue