- added many new things and fixed a number of bugs (too tried to mention them all)

This commit is contained in:
Mark Vejvoda
2010-06-24 01:23:18 +00:00
parent a842909e7d
commit 1d4f47718c
23 changed files with 444 additions and 47 deletions

View File

@@ -41,7 +41,7 @@ Game *thisGamePtr = NULL;
// ===================== PUBLIC ========================
Game::Game(Program *program, const GameSettings *gameSettings):
ProgramState(program), lastMousePos(0)
ProgramState(program), lastMousePos(0), isFirstRender(true)
{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@@ -328,6 +328,7 @@ void Game::init()
chatManager.init(&console, world.getThisTeamIndex());
console.clearStoredLines();
const Vec2i &v= map->getStartLocation(world.getThisFaction()->getStartLocationIndex());
gameCamera.init(map->getW(), map->getH());
gameCamera.setPos(Vec2f(v.x, v.y));
@@ -544,6 +545,15 @@ void Game::updateCamera(){
void Game::render() {
//SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps);
// Ensure the camera starts in the right position
if(isFirstRender == true) {
isFirstRender = false;
Map *map= world.getMap();
const Vec2i &v= map->getStartLocation(world.getThisFaction()->getStartLocationIndex());
gameCamera.init(map->getW(), map->getH());
gameCamera.setPos(Vec2f(v.x, v.y));
}
renderFps++;
renderWorker();
//SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps);
@@ -1017,7 +1027,12 @@ void Game::keyPress(char c){
void Game::quitGame(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
program->setState(new BattleEnd(program, world.getStats()));
Stats stats = *(world.getStats());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
program->setState(new BattleEnd(program, &stats));
}
// ==================== PRIVATE ====================

View File

@@ -83,6 +83,7 @@ private:
Vec2i lastMousePos;
time_t lastRenderLog2d;
DisplayMessageFunction originalDisplayMsgCallback;
bool isFirstRender;
public:
Game(Program *program, const GameSettings *gameSettings);

View File

@@ -22,6 +22,7 @@ PlayerStats::PlayerStats(){
deaths= 0;
unitsProduced= 0;
resourcesHarvested= 0;
playerName = "";
}
// =====================================================

View File

@@ -16,8 +16,10 @@
#include "game_constants.h"
#include "faction.h"
#include "vec.h"
using std::string;
using namespace Shared::Graphics;
namespace Glest{ namespace Game{
@@ -32,6 +34,8 @@ struct PlayerStats{
int deaths;
int unitsProduced;
int resourcesHarvested;
string playerName;
Vec3f playerColor;
};
// =====================================================
@@ -63,6 +67,8 @@ public:
int getDeaths(int factionIndex) const {return playerStats[factionIndex].deaths;}
int getUnitsProduced(int factionIndex) const {return playerStats[factionIndex].unitsProduced;}
int getResourcesHarvested(int factionIndex) const {return playerStats[factionIndex].resourcesHarvested;}
string getPlayerName(int factionIndex) const {return playerStats[factionIndex].playerName;}
Vec3f getPlayerColor(int factionIndex) const { return playerStats[factionIndex].playerColor;}
void setDescription(const string& description) {this->description = description;}
void setFactionTypeName(int playerIndex, const string& factionTypeName) {playerStats[playerIndex].factionTypeName= factionTypeName;}
@@ -73,6 +79,8 @@ public:
void die(int diedFactionIndex);
void produce(int producerFactionIndex);
void harvest(int harvesterFactionIndex, int amount);
void setPlayerName(int playerIndex, string value) {playerStats[playerIndex].playerName = value; }
void setPlayerColor(int playerIndex, Vec3f value) {playerStats[playerIndex].playerColor = value; }
};
}}//end namespace

View File

@@ -163,7 +163,9 @@ Renderer::Renderer(){
FactoryRepository &fr= FactoryRepository::getInstance();
Config &config= Config::getInstance();
maxConsoleLines= Config::getInstance().getInt("ConsoleMaxLines");
no2DMouseRendering = config.getBool("No2DMouseRendering","false");
maxConsoleLines= config.getInt("ConsoleMaxLines");
gi.setFactory(fr.getGraphicsFactory(config.getString("FactoryGraphics")));
GraphicsFactory *graphicsFactory= GraphicsInterface::getInstance().getFactory();
@@ -549,6 +551,9 @@ void Renderer::computeVisibleQuad(){
// =======================================
void Renderer::renderMouse2d(int x, int y, int anim, float fade){
if(no2DMouseRendering == true) {
return;
}
float color1, color2;
float fadeFactor= fade+1.f;

View File

@@ -261,6 +261,8 @@ private:
bool allowRenderUnitTitles;
std::vector<std::pair<Unit *,Vec3f> > renderUnitTitleList;
bool no2DMouseRendering;
private:
Renderer();
~Renderer();
@@ -270,7 +272,6 @@ public:
void reinitAll();
//init
void init();
void initGame(const Game *game);
@@ -385,6 +386,9 @@ public:
void setPhotoMode(bool value) { photoMode = value; }
bool getNo2DMouseRendering() const { return no2DMouseRendering; }
void setNo2DMouseRendering(bool value) { no2DMouseRendering = value; }
private:
//private misc
float computeSunAngle(float time);

View File

@@ -34,10 +34,11 @@ namespace Glest{ namespace Game{
// class BattleEnd
// =====================================================
BattleEnd::BattleEnd(Program *program, const Stats *stats):
ProgramState(program) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
this->stats= *stats;
BattleEnd::BattleEnd(Program *program, const Stats *stats): ProgramState(program) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] stats = %p\n",__FILE__,__FUNCTION__,__LINE__,stats);
if(stats != NULL) {
this->stats= *stats;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
@@ -102,7 +103,14 @@ void BattleEnd::render(){
assert(false);
};
textRenderer->render((lang.get("Player")+" "+intToStr(i+1)).c_str(), textX, bm+400);
Vec3f color = stats.getPlayerColor(i);
if(stats.getPlayerName(i) != "") {
textRenderer->render(stats.getPlayerName(i).c_str(), textX, bm+400, false, color);
}
else {
textRenderer->render((lang.get("Player")+" "+intToStr(i+1)).c_str(), textX, bm+400,false, color);
}
textRenderer->render(stats.getVictory(i)? lang.get("Victory").c_str(): lang.get("Defeat").c_str(), textX, bm+360);
textRenderer->render(controlString, textX, bm+320);
textRenderer->render(stats.getFactionTypeName(i), textX, bm+280);
@@ -146,13 +154,11 @@ void BattleEnd::render(){
void BattleEnd::keyDown(char key){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
program->setState(new MainMenu(program));
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
void BattleEnd::mouseDownLeft(int x, int y){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
program->setState(new MainMenu(program));
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
}}//end namespace

View File

@@ -373,7 +373,9 @@ int glestMain(int argc, char** argv){
std::pair<string,string>("glestkeys.ini","glestuserkeys.ini"),
std::pair<bool,bool>(true,false));
showCursor(false);
if(config.getBool("No2DMouseRendering","false") == false) {
showCursor(false);
}
if(config.getBool("noTeamColors","false") == true) {
MeshCallbackTeamColor::noTeamColors = true;
@@ -391,6 +393,8 @@ int glestMain(int argc, char** argv){
mainWindow= new MainWindow(program);
mainWindow->setUseDefaultCursorOnly(config.getBool("No2DMouseRendering","false"));
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//parse command line

View File

@@ -296,7 +296,10 @@ void Program::setState(ProgramState *programState, bool cleanupOldState)
updateCameraTimer.reset();
fpsTimer.reset();
showCursor(false);
Config &config = Config::getInstance();
if(config.getBool("No2DMouseRendering","false") == false) {
showCursor(false);
}
sleep(0);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@@ -484,7 +487,10 @@ void Program::showMessage(const char *msg) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
showCursor(false);
Config &config = Config::getInstance();
if(config.getBool("No2DMouseRendering","false") == false) {
showCursor(false);
}
//MainWindow *mainWindow= new MainWindow(this);
init(this->window,false);

View File

@@ -200,7 +200,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
listBoxEnableServerControlledAI.init(700, networkPos, 80);
listBoxEnableServerControlledAI.pushBackItem(lang.get("Yes"));
listBoxEnableServerControlledAI.pushBackItem(lang.get("No"));
listBoxEnableServerControlledAI.setSelectedItemIndex(1);
listBoxEnableServerControlledAI.setSelectedItemIndex(0);
@@ -741,7 +741,7 @@ void MenuStateCustomGame::update() {
if(EndsWith(masterServererErrorToShow, "wrong router setup") == true)
{
masterServererErrorToShow=lang.get("wrong router setup");
masterServererErrorToShow=lang.get("WrongRouterSetup");
}
showMasterserverError=false;
mainMessageBoxState=1;
@@ -1508,7 +1508,24 @@ void MenuStateCustomGame::updateNetworkSlots()
{
if(serverInterface->getSlot(i) == NULL && listBoxControls[i].getSelectedItemIndex() == ctNetwork)
{
serverInterface->addSlot(i);
try {
serverInterface->addSlot(i);
}
catch(const std::exception &ex) {
char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
showGeneralError=true;
if(serverInterface->isPortBound() == false) {
generalErrorToShow = Lang::getInstance().get("ErrorBindingPort") + " : " + intToStr(serverInterface->getBindPort());
}
else {
generalErrorToShow = ex.what();
}
// Revert network to CPU
listBoxControls[i].setSelectedItemIndex(2);
}
}
if(serverInterface->getSlot(i) != NULL && listBoxControls[i].getSelectedItemIndex() != ctNetwork)
{

View File

@@ -169,7 +169,7 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
listBoxAutoRefresh.pushBackItem("10 s");
listBoxAutoRefresh.pushBackItem("20 s");
listBoxAutoRefresh.pushBackItem("30 s");
listBoxAutoRefresh.setSelectedItemIndex(0);
listBoxAutoRefresh.setSelectedItemIndex(1);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);

View File

@@ -1,7 +1,7 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Marti<EFBFBD>o Figueroa
// 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
@@ -10,8 +10,11 @@
// ==============================================================
#include "network_manager.h"
#include "util.h"
#include "leak_dumper.h"
using namespace Shared::Util;
namespace Glest{ namespace Game{
// =====================================================
@@ -23,13 +26,18 @@ NetworkManager &NetworkManager::getInstance(){
return networkManager;
}
NetworkManager::NetworkManager(){
NetworkManager::NetworkManager() {
SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d this->networkRole = %d\n",__FILE__,__FUNCTION__,__LINE__,this->networkRole);
gameNetworkInterface= NULL;
networkRole= nrIdle;
SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d this->networkRole = %d\n",__FILE__,__FUNCTION__,__LINE__,this->networkRole);
}
void NetworkManager::init(NetworkRole networkRole)
{
void NetworkManager::init(NetworkRole networkRole) {
SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d this->networkRole = %d\n",__FILE__,__FUNCTION__,__LINE__,this->networkRole);
assert(gameNetworkInterface==NULL);
this->networkRole = networkRole;
@@ -37,16 +45,21 @@ void NetworkManager::init(NetworkRole networkRole)
if(networkRole==nrServer){
gameNetworkInterface = new ServerInterface();
}
else
{
else {
gameNetworkInterface = new ClientInterface();
}
SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d this->networkRole = %d\n",__FILE__,__FUNCTION__,__LINE__,this->networkRole);
}
void NetworkManager::end(){
void NetworkManager::end() {
SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d this->networkRole = %d\n",__FILE__,__FUNCTION__,__LINE__,this->networkRole);
delete gameNetworkInterface;
gameNetworkInterface= NULL;
networkRole= nrIdle;
SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d this->networkRole = %d\n",__FILE__,__FUNCTION__,__LINE__,this->networkRole);
}
void NetworkManager::update(){

View File

@@ -61,7 +61,8 @@ ServerInterface::ServerInterface(){
switchSetupRequests[i]= NULL;
}
serverSocket.setBlock(false);
serverSocket.bind(Config::getInstance().getInt("ServerPort",intToStr(GameConstants::serverPort).c_str()));
//serverSocket.bind(Config::getInstance().getInt("ServerPort",intToStr(GameConstants::serverPort).c_str()));
serverSocket.setBindPort(Config::getInstance().getInt("ServerPort",intToStr(GameConstants::serverPort).c_str()));
}
ServerInterface::~ServerInterface(){
@@ -85,6 +86,10 @@ void ServerInterface::addSlot(int playerIndex){
assert(playerIndex>=0 && playerIndex<GameConstants::maxPlayers);
if(serverSocket.isPortBound() == false) {
serverSocket.bind(serverSocket.getBindPort());
}
delete slots[playerIndex];
slots[playerIndex]= new ConnectionSlot(this, playerIndex);
updateListen();
@@ -681,11 +686,10 @@ void ServerInterface::quitGame(bool userManuallyQuit)
{
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
if(userManuallyQuit == true)
{
string sQuitText = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " has chosen to leave the game!";
NetworkMessageText networkMessageText(sQuitText,getHostName(),-1);
broadcastMessage(&networkMessageText, -1);
if(userManuallyQuit == true) {
//string sQuitText = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " has chosen to leave the game!";
//NetworkMessageText networkMessageText(sQuitText,getHostName(),-1);
//broadcastMessage(&networkMessageText, -1);
}
NetworkMessageQuit networkMessageQuit;

View File

@@ -88,6 +88,9 @@ public:
ConnectionSlotEvent &event);
void updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> &socketTriggeredList);
bool isPortBound() const { return serverSocket.isPortBound(); }
int getBindPort() const { return serverSocket.getBindPort(); }
public:
Mutex * getServerSynchAccessor() { return &serverSynchAccessor; }

View File

@@ -651,6 +651,8 @@ void World::initFactionTypes(GameSettings *gs){
stats.setTeam(i, gs->getTeam(i));
stats.setFactionTypeName(i, formatString(gs->getFactionTypeName(i)));
stats.setControl(i, gs->getFactionControl(i));
stats.setPlayerName(i,gs->getNetworkPlayerName(i));
stats.setPlayerColor(i,getFaction(i)->getTexture()->getPixmap()->getPixel3f(0, 0));
}
thisTeamIndex= getFaction(thisFactionIndex)->getTeam();

View File

@@ -0,0 +1,58 @@
// ==============================================================
// 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_GL_TEXTRENDERERGL_H_
#define _SHARED_GRAPHICS_GL_TEXTRENDERERGL_H_
#include "text_renderer.h"
namespace Shared{ namespace Graphics{ namespace Gl{
class Font2DGl;
class Font3DGl;
// =====================================================
// class TextRenderer2DGl
// =====================================================
class TextRenderer2DGl: public TextRenderer2D{
private:
const Font2DGl *font;
bool rendering;
public:
TextRenderer2DGl();
virtual void begin(const Font2D *font);
virtual void render(const string &text, int x, int y, bool centered, Vec3f color);
virtual void end();
};
// =====================================================
// class TextRenderer3DGl
// =====================================================
class TextRenderer3DGl: public TextRenderer3D{
private:
const Font3DGl *font;
bool rendering;
public:
TextRenderer3DGl();
virtual void begin(const Font3D *font);
virtual void render(const string &text, float x, float y, float size, bool centered);
virtual void end();
};
}}}//end namespace
#endif

View File

@@ -0,0 +1,52 @@
// ==============================================================
// 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_TEXTRENDERER_H_
#define _SHARED_GRAPHICS_TEXTRENDERER_H_
#include <string>
#include "vec.h"
#include "font.h"
using std::string;
namespace Shared{ namespace Graphics{
// =====================================================
// class TextRenderer2D
// =====================================================
class TextRenderer2D{
public:
virtual ~TextRenderer2D(){};
virtual void begin(const Font2D *font)= 0;
virtual void render(const string &text, int x, int y, bool centered= false,Vec3f color=Vec3f(-1.0))= 0;
virtual void end()= 0;
};
// =====================================================
// class TextRenderer3D
// =====================================================
class TextRenderer3D{
public:
virtual ~TextRenderer3D(){};
virtual void begin(const Font3D *font)= 0;
virtual void render(const string &text, float x, float y, float size, bool centered= false)= 0;
virtual void end()= 0;
};
}}//end namespace
#endif

View File

@@ -113,7 +113,7 @@ public:
static bool hasDataToRead(std::map<PLATFORM_SOCKET,bool> &socketTriggeredList);
static bool hasDataToRead(PLATFORM_SOCKET socket);
bool hasDataToRead();
void disconnectSocket();
virtual void disconnectSocket();
PLATFORM_SOCKET getSocketId() const { return sock; }
@@ -194,8 +194,15 @@ public:
Socket *accept();
void stopBroadCastThread();
void setBindPort(int port) { boundPort = port; }
int getBindPort() const { return boundPort; }
bool isPortBound() const { return portBound; }
virtual void disconnectSocket();
protected:
bool portBound;
int boundPort;
BroadCastSocketThread *broadCastThread;
void startBroadCastThread();

View File

@@ -132,6 +132,7 @@ private:
protected:
int w, h;
static bool isActive;
static bool no2DMouseRendering;
public:
static bool handleEvent();
@@ -170,6 +171,9 @@ public:
void destroy();
void minimize();
static void setUseDefaultCursorOnly(bool value) { no2DMouseRendering = value; }
static bool getUseDefaultCursorOnly() { return no2DMouseRendering; }
protected:
virtual void eventCreate(){}
virtual void eventMouseDown(int x, int y, MouseButton mouseButton){}

View File

@@ -0,0 +1,150 @@
// ==============================================================
// 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
// ==============================================================
#include "text_renderer_gl.h"
#include "opengl.h"
#include "font_gl.h"
#include "leak_dumper.h"
namespace Shared{ namespace Graphics{ namespace Gl{
// =====================================================
// class TextRenderer2DGl
// =====================================================
TextRenderer2DGl::TextRenderer2DGl(){
rendering= false;
}
void TextRenderer2DGl::begin(const Font2D *font){
assert(!rendering);
rendering= true;
this->font= static_cast<const Font2DGl*>(font);
}
void TextRenderer2DGl::render(const string &text, int x, int y, bool centered, Vec3f color) {
assert(rendering);
assertGl();
if(color.x >= 0) {
glPushAttrib(GL_CURRENT_BIT);
glColor3fv(color.ptr());
}
int line=0;
int size= font->getSize();
const unsigned char *utext= reinterpret_cast<const unsigned char*>(text.c_str());
Vec2f rasterPos;
const FontMetrics *metrics= font->getMetrics();
if(centered){
rasterPos.x= x-metrics->getTextWidth(text)/2.f;
rasterPos.y= y+metrics->getHeight()/2.f;
}
else{
rasterPos= Vec2f(static_cast<float>(x), static_cast<float>(y));
}
glRasterPos2f(rasterPos.x, rasterPos.y);
for (int i=0; utext[i]!='\0'; ++i) {
switch(utext[i]){
case '\t':
rasterPos= Vec2f((rasterPos.x/size+3.f)*size, y-(size+1.f)*line);
glRasterPos2f(rasterPos.x, rasterPos.y);
break;
case '\n':
line++;
rasterPos= Vec2f(static_cast<float>(x), y-(metrics->getHeight()*2.f)*line);
glRasterPos2f(rasterPos.x, rasterPos.y);
break;
default:
glCallList(font->getHandle()+utext[i]);
}
}
if(color.x >= 0) {
glPopAttrib();
}
assertGl();
}
void TextRenderer2DGl::end(){
assert(rendering);
rendering= false;
}
// =====================================================
// class TextRenderer3DGl
// =====================================================
TextRenderer3DGl::TextRenderer3DGl(){
rendering= false;
}
void TextRenderer3DGl::begin(const Font3D *font){
assert(!rendering);
rendering= true;
this->font= static_cast<const Font3DGl*>(font);
assertGl();
//load color
glPushAttrib(GL_TRANSFORM_BIT);
assertGl();
}
void TextRenderer3DGl::render(const string &text, float x, float y, float size, bool centered){
assert(rendering);
assertGl();
const unsigned char *utext= reinterpret_cast<const unsigned char*>(text.c_str());
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glPushAttrib(GL_POLYGON_BIT);
float scale= size/10.f;
if(centered){
const FontMetrics *metrics= font->getMetrics();
glTranslatef(x-scale*metrics->getTextWidth(text)/2.f, y-scale*metrics->getHeight()/2.f, 0);
}
else{
glTranslatef(x-scale, y-scale, 0);
}
glScalef(scale, scale, scale);
for (int i=0; utext[i]!='\0'; ++i) {
glCallList(font->getHandle()+utext[i]);
}
glPopMatrix();
glPopAttrib();
assertGl();
}
void TextRenderer3DGl::end(){
assert(rendering);
rendering= false;
assertGl();
glPopAttrib();
assertGl();
}
}}}//end namespace

View File

@@ -784,7 +784,7 @@ void showCursor(bool b) {
}
SDL_ShowCursor(b ? SDL_ENABLE : SDL_DISABLE);
if(b) {
SDL_WM_GrabInput(SDL_GRAB_OFF);
//SDL_WM_GrabInput(SDL_GRAB_OFF);
//SDL_WarpMouse(x,y);
}
}

View File

@@ -1465,6 +1465,7 @@ void BroadCastClientSocketThread::execute() {
ServerSocket::ServerSocket() : Socket() {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
portBound = false;
broadCastThread = NULL;
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@@ -1513,9 +1514,19 @@ bool ServerSocket::isBroadCastThreadRunning() {
return isThreadRunning;
}
void ServerSocket::bind(int port)
{
void ServerSocket::bind(int port) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d port = %d, portBound = %d START\n",__FILE__,__FUNCTION__,__LINE__,port,portBound);
boundPort = port;
if(isSocketValid() == false) {
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(isSocketValid() == false) {
throwException("Error creating socket");
}
setBlock(false);
}
//sockaddr structure
sockaddr_in addr;
addr.sin_family= AF_INET;
@@ -1540,6 +1551,14 @@ void ServerSocket::bind(int port)
sprintf(szBuf, "Error binding socket sock = %d, err = %d, error = %s\n",sock,err,getLastSocketErrorFormattedText().c_str());
throw runtime_error(szBuf);
}
portBound = true;
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d port = %d, portBound = %d END\n",__FILE__,__FUNCTION__,__LINE__,port,portBound);
}
void ServerSocket::disconnectSocket() {
Socket::disconnectSocket();
portBound = false;
}
void ServerSocket::listen(int connectionQueueSize) {
@@ -1554,6 +1573,9 @@ void ServerSocket::listen(int connectionQueueSize) {
throwException("Error creating socket");
}
setBlock(false);
}
if(portBound == false) {
bind(boundPort);
}
@@ -1579,8 +1601,12 @@ void ServerSocket::listen(int connectionQueueSize) {
}
}
Socket *ServerSocket::accept()
{
Socket *ServerSocket::accept() {
if(isSocketValid() == false) {
throwException("socket is invalid!");
}
struct sockaddr_in cli_addr;
socklen_t clilen = sizeof(cli_addr);
char client_host[100]="";

View File

@@ -49,6 +49,7 @@ bool Window::isFullScreen = false;
SDL_keysym Window::keystate;
bool Window::isActive = false;
bool Window::no2DMouseRendering = false;
// ========== PUBLIC ==========
@@ -176,8 +177,10 @@ bool Window::handleEvent() {
Window::isActive = true;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Window::isActive = %d\n",__FILE__,__FUNCTION__,__LINE__,Window::isActive);
showCursor(!Window::isActive);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Window::isActive = %d\n",__FILE__,__FUNCTION__,__LINE__,Window::isActive);
if(Window::isActive && Window::getUseDefaultCursorOnly() == false) {
showCursor(!Window::isActive);
}
}
// Check if the program has lost window focus
else if (event.active.state == SDL_APPACTIVE) {
@@ -188,8 +191,10 @@ bool Window::handleEvent() {
Window::isActive = true;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Window::isActive = %d\n",__FILE__,__FUNCTION__,__LINE__,Window::isActive);
showCursor(!Window::isActive);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Window::isActive = %d\n",__FILE__,__FUNCTION__,__LINE__,Window::isActive);
if(Window::isActive && Window::getUseDefaultCursorOnly() == false) {
showCursor(!Window::isActive);
}
}
// Check if the program has lost window focus
else if (event.active.state == SDL_APPMOUSEFOCUS) {
@@ -200,8 +205,10 @@ bool Window::handleEvent() {
Window::isActive = true;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Window::isActive = %d\n",__FILE__,__FUNCTION__,__LINE__,Window::isActive);
showCursor(!Window::isActive);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Window::isActive = %d\n",__FILE__,__FUNCTION__,__LINE__,Window::isActive);
if(Window::isActive && Window::getUseDefaultCursorOnly() == false) {
showCursor(!Window::isActive);
}
}
else {
if (event.active.gain == 0) {
@@ -211,8 +218,10 @@ bool Window::handleEvent() {
Window::isActive = true;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Window::isActive = %d, event.active.state = %d\n",__FILE__,__FUNCTION__,__LINE__,Window::isActive,event.active.state);
showCursor(!Window::isActive);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Window::isActive = %d, event.active.state = %d\n",__FILE__,__FUNCTION__,__LINE__,Window::isActive,event.active.state);
if(Window::isActive && Window::getUseDefaultCursorOnly() == false) {
showCursor(!Window::isActive);
}
}
}
@@ -413,8 +422,10 @@ void Window::toggleFullscreen() {
if(Window::isFullScreen == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] Window::isFullScreen == true [%d]\n",__FILE__,__FUNCTION__,__LINE__,handle);
ShowWindow(handle, SW_MAXIMIZE);
showCursor(false);
ShowWindow(handle, SW_MAXIMIZE);
if(Window::isActive && Window::getUseDefaultCursorOnly() == false) {
showCursor(false);
}
}
else {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] Window::isFullScreen == false [%d]\n",__FILE__,__FUNCTION__,__LINE__,handle);