- 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

@@ -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);