- Attempt to use libcurl in a thread safe manner

This commit is contained in:
Mark Vejvoda 2010-06-23 14:49:20 +00:00
parent e0b9089eeb
commit 87b4706940
14 changed files with 220 additions and 158 deletions

View File

@ -31,6 +31,8 @@ namespace Glest { namespace Game {
// ================== PUBLIC =====================
static std::map<std::string, Quad2i> cacheVisibleQuad;
const float GameCamera::startingVAng= -60.f;
const float GameCamera::startingHAng= 0.f;
const float GameCamera::vTransitionMult= 0.125f;
@ -40,11 +42,32 @@ const float GameCamera::centerOffsetZ= 8.0f;
// ================= Constructor =================
class quadCacheLookup {
public:
quadCacheLookup(float fov,float hAng,Vec3f pos) {
this->fov = fov;
this->hAng = hAng;
this->pos = pos;
}
std::string getString() const {
std::ostringstream streamOut;
streamOut << fov << "_" << hAng << "_" << pos.getString();
return streamOut.str();
}
float fov;
float hAng;
Vec3f pos;
};
GameCamera::GameCamera() : pos(0.f, defaultHeight, 0.f),
destPos(0.f, defaultHeight, 0.f), destAng(startingVAng, startingHAng) {
Config &config = Config::getInstance();
state= sGame;
cacheVisibleQuad.clear();
//config
speed= 15.f / GameConstants::cameraFps;
clampBounds= !Config::getInstance().getBool("PhotoMode");
@ -141,41 +164,19 @@ void GameCamera::update(){
}
}
Quad2i GameCamera::computeVisibleQuad() const{
/*
class cacheLookup {
public:
cacheLookup(float fov,float hAng,Vec3f pos) {
this->fov = fov;
this->hAng = hAng;
this->pos = pos;
}
std::string getString() const {
std::ostringstream streamOut;
streamOut << fov << "_" << hAng << "_" << pos.getString();
return streamOut.str();
}
float fov;
float hAng;
Vec3f pos;
};
cacheLookup lookup(fov, hAng,pos);
Quad2i GameCamera::computeVisibleQuad() const {
//
quadCacheLookup lookup(fov, hAng, pos);
string lookupKey = lookup.getString();
static std::map<string, Quad2i> cacheQuad;
if(cacheQuad.find(lookupKey) != cacheQuad.end()) {
return cacheQuad[lookupKey];
std::map<std::string, Quad2i>::const_iterator iterFind = cacheVisibleQuad.find(lookupKey);
if(iterFind != cacheVisibleQuad.end()) {
return iterFind->second;
}
//
*/
float nearDist = 20.f;
float dist = pos.y > 20.f ? pos.y * 1.2f : 20.f;
float farDist = 90.f * (pos.y > 20.f ? pos.y / 15.f : 1.f);
//float fov = Config::getInstance().getFloat("CameraFov","45");
#ifdef USE_STREFLOP
Vec2f v(streflop::sinf(degToRad(180 - hAng)), streflop::cosf(degToRad(180 - hAng)));
@ -207,10 +208,10 @@ Quad2i GameCamera::computeVisibleQuad() const{
return Quad2i(p2, p4, p1, p3);
}
// cacheQuad[lookupKey] = Quad2i(p4, p3, p2, p1);
// return cacheQuad[lookupKey];
return Quad2i(p4, p3, p2, p1);
//cacheVisibleQuad[lookupKey] = Quad2i(p4, p3, p2, p1);
cacheVisibleQuad.insert(std::make_pair(lookupKey,Quad2i(p4, p3, p2, p1)));
return cacheVisibleQuad[lookupKey];
// return Quad2i(p4, p3, p2, p1);
}
void GameCamera::switchState(){

View File

@ -14,6 +14,9 @@
#include "vec.h"
#include "math_util.h"
#include <map>
#include <string>
#include "leak_dumper.h"
namespace Shared { namespace Xml {
class XmlNode;

View File

@ -530,7 +530,7 @@ void Renderer::loadGameCameraMatrix(){
}
void Renderer::loadCameraMatrix(const Camera *camera){
Vec3f position= camera->getPosition();
const Vec3f &position= camera->getConstPosition();
Quaternion orientation= camera->getOrientation().conjugate();
glMatrixMode(GL_MODELVIEW);
@ -2072,7 +2072,7 @@ void Renderer::renderMenuBackground(const MenuBackground *menuBackground){
assertGl();
Vec3f cameraPosition= menuBackground->getCamera()->getPosition();
const Vec3f &cameraPosition= menuBackground->getCamera()->getConstPosition();
glPushAttrib(GL_LIGHTING_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT);

View File

@ -8,7 +8,6 @@
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#include "menu_state_custom_game.h"
#include "renderer.h"
@ -322,10 +321,8 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
MenuStateCustomGame::~MenuStateCustomGame() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
needToBroadcastServerSettings = false;
needToRepublishToMasterserver = false;
safeMutex.ReleaseLock();
//BaseThread::shutdownAndWait(publishToMasterserverThread);
delete publishToMasterserverThread;
@ -337,11 +334,9 @@ MenuStateCustomGame::~MenuStateCustomGame() {
void MenuStateCustomGame::returnToParentMenu(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
needToBroadcastServerSettings = false;
needToRepublishToMasterserver = false;
bool returnToMasterServerMenu = parentMenuIsMs;
safeMutex.ReleaseLock();
//BaseThread::shutdownAndWait(publishToMasterserverThread);
delete publishToMasterserverThread;
@ -440,9 +435,8 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
}
needToBroadcastServerSettings = false;
needToRepublishToMasterserver = false;
safeMutex.ReleaseLock();
//BaseThread::shutdownAndWait(publishToMasterserverThread);
delete publishToMasterserverThread;
publishToMasterserverThread = NULL;
@ -623,8 +617,6 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
}
void MenuStateCustomGame::mouseMove(int x, int y, const MouseState *ms){
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if (mainMessageBox.getEnabled()) {
mainMessageBox.mouseMove(x, y);
}
@ -649,12 +641,9 @@ void MenuStateCustomGame::mouseMove(int x, int y, const MouseState *ms){
}
void MenuStateCustomGame::render(){
try {
Renderer &renderer= Renderer::getInstance();
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if(mainMessageBox.getEnabled()){
renderer.renderMessageBox(&mainMessageBox);
}
@ -711,59 +700,67 @@ void MenuStateCustomGame::render(){
}
}
void MenuStateCustomGame::update()
{
void MenuStateCustomGame::update() {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
try {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(serverInitError == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(showGeneralError) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
showGeneralError=false;
mainMessageBoxState=1;
showMessageBox( generalErrorToShow, "Error", false);
safeMutex.ReleaseLock();
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
return;
}
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
Lang& lang= Lang::getInstance();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
bool haveAtLeastOneNetworkClientConnected = false;
bool hasOneNetworkSlotOpen = false;
int currentConnectionCount=0;
Config &config = Config::getInstance();
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
bool masterServerErr = showMasterserverError;
safeMutex.ReleaseLock(true);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(masterServerErr)
{
safeMutex.Lock();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(EndsWith(masterServererErrorToShow, "wrong router setup") == true)
{
masterServererErrorToShow=lang.get("wrong router setup");
}
showMasterserverError=false;
listBoxPublishServer.setSelectedItemIndex(1);
mainMessageBoxState=1;
showMessageBox( masterServererErrorToShow, lang.get("ErrorFromMasterserver"), false);
safeMutex.ReleaseLock(true);
listBoxPublishServer.setSelectedItemIndex(1);
}
else if(showGeneralError) {
safeMutex.Lock();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
showGeneralError=false;
mainMessageBoxState=1;
showMessageBox( generalErrorToShow, "Error", false);
safeMutex.ReleaseLock(true);
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
// handle setting changes from clients
SwitchSetupRequest** switchSetupRequests=serverInterface->getSwitchSetupRequests();
safeMutex.Lock();
for(int i= 0; i<mapInfo.players; ++i)
{
if(switchSetupRequests[i]!=NULL)
@ -813,11 +810,9 @@ void MenuStateCustomGame::update()
switchSetupRequests[i]=NULL;
}
}
safeMutex.ReleaseLock(true);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] mapInfo.players = %d\n",__FILE__,__FUNCTION__,__LINE__,mapInfo.players);
safeMutex.Lock();
for(int i= 0; i<mapInfo.players; ++i)
{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -919,16 +914,13 @@ void MenuStateCustomGame::update()
labelNetStatus[i].setText("");
}
}
safeMutex.ReleaseLock(true);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
safeMutex.Lock();
bool checkDataSynch = (serverInterface->getAllowGameDataSynchCheck() == true &&
//haveAtLeastOneNetworkClientConnected == true &&
needToSetChangedGameSettings == true &&
difftime(time(NULL),lastSetChangedGameSettings) >= 2);
safeMutex.ReleaseLock(true);
// Send the game settings to each client if we have at least one networked client
if(checkDataSynch == true)
@ -936,61 +928,44 @@ void MenuStateCustomGame::update()
GameSettings gameSettings;
loadGameSettings(&gameSettings);
serverInterface->setGameSettings(&gameSettings);
safeMutex.Lock();
needToSetChangedGameSettings = false;
safeMutex.ReleaseLock(true);
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(hasOneNetworkSlotOpen)
{
safeMutex.Lock();
//listBoxPublishServer.setSelectedItemIndex(0);
listBoxPublishServer.setEditable(true);
listBoxEnableServerControlledAI.setEditable(true);
safeMutex.ReleaseLock(true);
}
else
{
safeMutex.Lock();
listBoxPublishServer.setSelectedItemIndex(1);
listBoxPublishServer.setEditable(false);
listBoxEnableServerControlledAI.setEditable(false);
safeMutex.ReleaseLock(true);
}
safeMutex.Lock();
bool republishToMaster = (difftime(time(NULL),lastMasterserverPublishing) >= 5);
safeMutex.ReleaseLock(true);
if(republishToMaster == true) {
safeMutex.Lock();
needToRepublishToMasterserver = true;
lastMasterserverPublishing = time(NULL);
safeMutex.ReleaseLock(true);
}
safeMutex.Lock();
bool callPublishNow = (listBoxPublishServer.getEditable() &&
listBoxPublishServer.getSelectedItemIndex() == 0 &&
needToRepublishToMasterserver == true);
safeMutex.ReleaseLock(true);
if(callPublishNow == true) {
// give it to me baby, aha aha ...
publishToMasterserver();
}
safeMutex.Lock();
bool broadCastSettings = (difftime(time(NULL),lastSetChangedGameSettings) >= 2);
safeMutex.ReleaseLock(true);
if(broadCastSettings == true) {
safeMutex.Lock();
needToBroadcastServerSettings=true;
safeMutex.ReleaseLock(true);
}
//call the chat manager
@ -999,25 +974,19 @@ void MenuStateCustomGame::update()
//console
console.update();
safeMutex.Lock();
broadCastSettings = (difftime(time(NULL),lastSetChangedGameSettings) >= 2);
safeMutex.ReleaseLock(true);
if(broadCastSettings == true)
{// reset timer here on bottom becasue used for different things
safeMutex.Lock();
lastSetChangedGameSettings = time(NULL);
safeMutex.ReleaseLock(true);
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
safeMutex.Lock();
if(currentConnectionCount > soundConnectionCount){
soundConnectionCount = currentConnectionCount;
SoundRenderer::getInstance().playFx(CoreData::getInstance().getAttentionSound());
}
soundConnectionCount = currentConnectionCount;
safeMutex.ReleaseLock(true);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
@ -1034,15 +1003,19 @@ void MenuStateCustomGame::update()
void MenuStateCustomGame::publishToMasterserver()
{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
int slotCountUsed=0;
int slotCountHumans=0;
int slotCountConnectedPlayers=0;
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
GameSettings gameSettings;
loadGameSettings(&gameSettings);
string serverinfo="";
//string serverinfo="";
publishToServerInfo.clear();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
for(int i= 0; i < mapInfo.players; ++i) {
if(listBoxControls[i].getSelectedItemIndex() != ctClosed) {
slotCountUsed++;
@ -1063,74 +1036,71 @@ void MenuStateCustomGame::publishToMasterserver()
slotCountConnectedPlayers++;
}
}
//?status=waiting&system=linux&info=titus
serverinfo += "glestVersion=" + SystemFlags::escapeURL(glestVersionString) + "&";
serverinfo += "platform=" + SystemFlags::escapeURL(getPlatformNameString()) + "&";
serverinfo += "binaryCompileDate=" + SystemFlags::escapeURL(getCompileDateTime()) + "&";
publishToServerInfo["glestVersion"] = glestVersionString;
publishToServerInfo["platform"] = getPlatformNameString();
publishToServerInfo["binaryCompileDate"] = getCompileDateTime();
//game info:
serverinfo += "serverTitle=" + SystemFlags::escapeURL(Config::getInstance().getString("NetPlayerName") + "'s game") + "&";
publishToServerInfo["serverTitle"] = Config::getInstance().getString("NetPlayerName") + "'s game";
//ip is automatically set
//game setup info:
serverinfo += "tech=" + SystemFlags::escapeURL(listBoxTechTree.getSelectedItem()) + "&";
serverinfo += "map=" + SystemFlags::escapeURL(listBoxMap.getSelectedItem()) + "&";
serverinfo += "tileset=" + SystemFlags::escapeURL(listBoxTileset.getSelectedItem()) + "&";
serverinfo += "activeSlots=" + intToStr(slotCountUsed) + "&";
serverinfo += "networkSlots=" + intToStr(slotCountHumans) + "&";
serverinfo += "connectedClients=" + intToStr(slotCountConnectedPlayers);
publishToServerInfo["tech"] = listBoxTechTree.getSelectedItem();
publishToServerInfo["map"] = listBoxMap.getSelectedItem();
publishToServerInfo["tileset"] = listBoxTileset.getSelectedItem();
publishToServerInfo["activeSlots"] = intToStr(slotCountUsed);
publishToServerInfo["networkSlots"] = intToStr(slotCountHumans);
publishToServerInfo["connectedClients"] = intToStr(slotCountConnectedPlayers);
publishToServerInfo = serverinfo;
safeMutex.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
void MenuStateCustomGame::simpleTask() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
bool republish = (needToRepublishToMasterserver == true && publishToServerInfo != "");
if(publishToMasterserverThread == NULL || publishToMasterserverThread->getQuitStatus() == true || publishToMasterserverThread->getRunningStatus() == false) {
return;
}
bool republish = (needToRepublishToMasterserver == true && publishToServerInfo.size() != 0);
needToRepublishToMasterserver = false;
string newPublishToServerInfo = publishToServerInfo;
publishToServerInfo = "";
//safeMutex.ReleaseLock(true);
if(republish == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
string request = Config::getInstance().getString("Masterserver") + "addServerInfo.php?" + newPublishToServerInfo;
//string request = Config::getInstance().getString("Masterserver") + "addServerInfo.php?" + newPublishToServerInfo;
string request = Config::getInstance().getString("Masterserver") + "addServerInfo.php?";
CURL *handle = SystemFlags::initHTTP();
for(std::map<string,string>::const_iterator iterMap = publishToServerInfo.begin();
iterMap != publishToServerInfo.end(); iterMap++) {
request += iterMap->first;
request += "=";
request += SystemFlags::escapeURL(iterMap->second,handle);
request += "&";
}
publishToServerInfo.clear();
//printf("the request is:\n%s\n",request.c_str());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] the request is:\n%s\n",__FILE__,__FUNCTION__,__LINE__,request.c_str());
if(publishToMasterserverThread == NULL || publishToMasterserverThread->getQuitStatus() == true || publishToMasterserverThread->getRunningStatus() == false) {
return;
}
std::string serverInfo = SystemFlags::getHTTP(request,handle);
SystemFlags::cleanupHTTP(&handle);
std::string serverInfo = SystemFlags::getHTTP(request);
//printf("the result is:\n'%s'\n",serverInfo.c_str());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] the result is:\n'%s'\n",__FILE__,__FUNCTION__,__LINE__,serverInfo.c_str());
// uncomment to enable router setup check of this server
//if(serverInfo!="OK")
if(EndsWith(serverInfo, "OK") == false) {
//safeMutex.Lock();
showMasterserverError=true;
masterServererErrorToShow=serverInfo;
//safeMutex.ReleaseLock(true);
}
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
//safeMutex.Lock();
bool broadCastSettings = needToBroadcastServerSettings;
if(publishToMasterserverThread == NULL || publishToMasterserverThread->getQuitStatus() == true || publishToMasterserverThread->getRunningStatus() == false) {
return;
}
needToBroadcastServerSettings=false;
//safeMutex.ReleaseLock(true);
@ -1144,17 +1114,9 @@ void MenuStateCustomGame::simpleTask() {
if(serverInterface->hasClientConnection() == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(publishToMasterserverThread == NULL || publishToMasterserverThread->getQuitStatus() == true || publishToMasterserverThread->getRunningStatus() == false) {
return;
}
GameSettings gameSettings;
loadGameSettings(&gameSettings);
if(publishToMasterserverThread == NULL || publishToMasterserverThread->getQuitStatus() == true || publishToMasterserverThread->getRunningStatus() == false) {
return;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
serverInterface->setGameSettings(&gameSettings);
@ -1168,8 +1130,6 @@ void MenuStateCustomGame::simpleTask() {
void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
int factionCount= 0;
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
@ -1228,8 +1188,6 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getTech() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getTech().c_str());
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getMap() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getMap().c_str());
safeMutex.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
}
@ -1524,7 +1482,6 @@ void MenuStateCustomGame::updateControlers(){
void MenuStateCustomGame::closeUnusedSlots(){
try {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
for(int i= 0; i<mapInfo.players; ++i){
if(listBoxControls[i].getSelectedItemIndex()==ctNetwork){

View File

@ -71,7 +71,7 @@ private:
time_t lastMasterserverPublishing;
bool needToRepublishToMasterserver;
bool needToBroadcastServerSettings;
string publishToServerInfo;
std::map<string,string> publishToServerInfo;
SimpleTaskThread *publishToMasterserverThread;
Mutex masterServerThreadAccessor;

View File

@ -204,7 +204,7 @@ MenuStateMasterserver::~MenuStateMasterserver() {
clearServerLines();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] END\n",__FILE__,__FUNCTION__,__LINE__);
}
void MenuStateMasterserver::clearServerLines(){
@ -265,10 +265,10 @@ void MenuStateMasterserver::mouseClick(int x, int y, MouseButton mouseButton){
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
soundRenderer.playFx(coreData.getClickSoundB());
needUpdateFromServer = false;
safeMutex.ReleaseLock();
//BaseThread::shutdownAndWait(updateFromMasterserverThread);
delete updateFromMasterserverThread;
updateFromMasterserverThread = NULL;
safeMutex.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);

View File

@ -112,7 +112,7 @@ void ClientInterface::update()
}
int lastSendElapsed = difftime(time(NULL),lastNetworkCommandListSendTime);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] lastSendElapsed = %d\n",__FILE__,__FUNCTION__,__LINE__,lastSendElapsed);
if(lastNetworkCommandListSendTime > 0) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] lastSendElapsed = %d\n",__FILE__,__FUNCTION__,__LINE__,lastSendElapsed);
if(networkMessageCommandList.getCommandCount() > 0 ||
(lastNetworkCommandListSendTime > 0 && lastSendElapsed >= ClientInterface::maxNetworkCommandListSendTimeWait)) {

View File

@ -180,9 +180,14 @@ ConnectionSlot::~ConnectionSlot()
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
BaseThread::shutdownAndWait(slotThreadWorker);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
delete slotThreadWorker;
slotThreadWorker = NULL;
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
close();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__);

View File

@ -0,0 +1,51 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#ifndef _SHARED_GRAPHICS_CAMERA_H_
#define _SHARED_GRAPHICS_CAMERA_H_
#include "vec.h"
#include "quaternion.h"
namespace Shared{ namespace Graphics{
// =====================================================
// class Camera
// =====================================================
class Camera{
private:
Quaternion orientation;
Vec3f position;
public:
Camera();
Vec3f getPosition() const {return position;}
Quaternion getOrientation() const {return orientation;}
const Vec3f & getConstPosition() const {return position;}
const Quaternion & getConstOrientation() const {return orientation;}
void setPosition(const Vec3f &position) {this->position= position;}
void setOrientation(const Quaternion &orientation) {this->orientation= orientation;}
void moveLocalX(float amount);
void moveLocalY(float amount);
void moveLocalZ(float amount);
void addYaw(float amount);
void addPitch(float amount);
void addRoll(float amount);
};
}}//end namespace
#endif

View File

@ -116,8 +116,11 @@ public:
static void init();
static SystemFlagsType & getSystemSettingType(DebugType type) { return debugLogFileList[type]; }
static size_t httpWriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data);
static std::string getHTTP(std::string URL);
static std::string escapeURL(std::string URL);
static std::string getHTTP(std::string URL,CURL *handle=NULL);
static std::string escapeURL(std::string URL, CURL *handle=NULL);
static CURL *initHTTP();
static void cleanupHTTP(CURL **handle);
// Let the macro call into this when require.. NEVER call it automatically.
static void handleDebug(DebugType type, const char *fmt, ...);

View File

@ -33,7 +33,7 @@ BaseThread::BaseThread() : Thread() {
BaseThread::~BaseThread() {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
shutdownAndWait();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s] END\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
}
void BaseThread::signalQuit() {
@ -98,20 +98,20 @@ void BaseThread::shutdownAndWait(BaseThread *pThread) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
pThread->signalQuit();
sleep(0);
//sleep(0);
for( time_t elapsed = time(NULL); difftime(time(NULL),elapsed) <= 7; ) {
for( time_t elapsed = time(NULL); difftime(time(NULL),elapsed) <= 5; ) {
if(pThread->getRunningStatus() == false) {
break;
}
sleep(0);
sleep(1);
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
//sleep(0);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
}
//sleep(0);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s] END\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
}
void BaseThread::shutdownAndWait() {

View File

@ -145,7 +145,7 @@ void SimpleTaskThread::execute() {
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
setRunningStatus(false);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s] END\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
}
void SimpleTaskThread::setTaskSignalled(bool value) {

View File

@ -708,6 +708,7 @@ float Socket::getThreadedPingMS(std::string host) {
if(pingThread == NULL) {
lastThreadedPing = 0;
pingThread = new SimpleTaskThread(this,0,50);
pingThread->setUniqueID(__FILE__ + "_" + __FUNCTION);
pingThread->start();
}
@ -1216,6 +1217,7 @@ void ClientSocket::startBroadCastClientThread(DiscoveredServersInterface *cb) {
ClientSocket::stopBroadCastClientThread();
broadCastClientThread = new BroadCastClientSocketThread(cb);
broadCastClientThread->setUniqueID(string(__FILE__) + string("_") + string(__FUNCTION__));
broadCastClientThread->start();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -1495,6 +1497,7 @@ void ServerSocket::startBroadCastThread() {
stopBroadCastThread();
broadCastThread = new BroadCastSocketThread();
broadCastThread->setUniqueID(string(__FILE__) + string("_") + string(__FUNCTION__));
broadCastThread->start();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);

View File

@ -69,11 +69,13 @@ size_t SystemFlags::httpWriteMemoryCallback(void *ptr, size_t size, size_t nmemb
return realsize;
}
std::string SystemFlags::escapeURL(std::string URL)
{
std::string SystemFlags::escapeURL(std::string URL, CURL *handle) {
string result = URL;
char *escaped=curl_easy_escape(SystemFlags::curl_handle,URL.c_str(),0);
if(handle == NULL) {
handle = SystemFlags::curl_handle;
}
char *escaped=curl_easy_escape(handle,URL.c_str(),0);
if(escaped != NULL) {
result = escaped;
curl_free(escaped);
@ -81,33 +83,56 @@ std::string SystemFlags::escapeURL(std::string URL)
return result;
}
std::string SystemFlags::getHTTP(std::string URL) {
curl_easy_setopt(SystemFlags::curl_handle, CURLOPT_URL, URL.c_str());
std::string SystemFlags::getHTTP(std::string URL,CURL *handle) {
if(handle == NULL) {
handle = SystemFlags::curl_handle;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
curl_easy_setopt(handle, CURLOPT_URL, URL.c_str());
/* send all data to this function */
curl_easy_setopt(SystemFlags::curl_handle, CURLOPT_WRITEFUNCTION, SystemFlags::httpWriteMemoryCallback);
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, SystemFlags::httpWriteMemoryCallback);
struct SystemFlags::httpMemoryStruct chunk;
chunk.memory=NULL; /* we expect realloc(NULL, size) to work */
chunk.size = 0; /* no data at this point */
/* we pass our 'chunk' struct to the callback function */
curl_easy_setopt(SystemFlags::curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, (void *)&chunk);
/* some servers don't like requests that are made without a user-agent
field, so we provide one */
curl_easy_setopt(SystemFlags::curl_handle, CURLOPT_USERAGENT, "mega-glest-agent/1.0");
curl_easy_setopt(handle, CURLOPT_USERAGENT, "mega-glest-agent/1.0");
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] handle = %p\n",__FILE__,__FUNCTION__,__LINE__,handle);
//curl_easy_setopt(handle, CURLOPT_VERBOSE, 1);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
/* get contents from the URL */
curl_easy_perform(SystemFlags::curl_handle);
curl_easy_perform(handle);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
std::string serverResponse = (chunk.memory != NULL ? chunk.memory : "");
if(chunk.memory) {
free(chunk.memory);
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] serverResponse [%s]\n",__FILE__,__FUNCTION__,__LINE__,serverResponse.c_str());
return serverResponse;
}
CURL *SystemFlags::initHTTP() {
curl_global_init(CURL_GLOBAL_ALL);
CURL *handle = curl_easy_init();
return handle;
}
void SystemFlags::init() {
if(SystemFlags::debugLogFileList.size() == 0) {
SystemFlags::debugLogFileList[SystemFlags::debugSystem] = SystemFlags::SystemFlagsType(SystemFlags::debugSystem);
@ -117,9 +142,15 @@ void SystemFlags::init() {
SystemFlags::debugLogFileList[SystemFlags::debugUnitCommands] = SystemFlags::SystemFlagsType(SystemFlags::debugUnitCommands);
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(curl_handle == NULL) {
curl_global_init(CURL_GLOBAL_ALL);
curl_handle = curl_easy_init();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
curl_handle = SystemFlags::initHTTP();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] curl_handle = %p\n",__FILE__,__FUNCTION__,__LINE__,curl_handle);
}
}
@ -141,13 +172,21 @@ inline bool acquire_file_lock(int hnd)
SystemFlags::SystemFlags() {
}
void SystemFlags::cleanupHTTP(CURL **handle) {
if(handle != NULL && *handle != NULL) {
curl_easy_cleanup(*handle);
*handle = NULL;
curl_global_cleanup();
}
}
SystemFlags::~SystemFlags() {
SystemFlags::Close();
if(curl_handle != NULL) {
curl_easy_cleanup(curl_handle);
SystemFlags::cleanupHTTP(&curl_handle);
curl_handle = NULL;
curl_global_cleanup();
}
}