Code Restructuring to make mega-glest more standard

This commit is contained in:
Mark Vejvoda
2010-03-12 05:20:53 +00:00
parent 7cb4f99ec4
commit 43c3f2457e
399 changed files with 0 additions and 73357 deletions

View File

@@ -1,55 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
//
// 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_PLATFORM_FACTORYREPOSITORY_H_
#define _SHARED_PLATFORM_FACTORYREPOSITORY_H_
#include <string>
#include "graphics_factory.h"
#include "sound_factory.h"
#include "graphics_factory_gl.h"
#include "sound_factory_openal.h"
using std::string;
using Shared::Graphics::GraphicsFactory;
using Shared::Sound::SoundFactory;
using Shared::Graphics::Gl::GraphicsFactoryGl;
using Shared::Sound::OpenAL::SoundFactoryOpenAL;
namespace Shared{ namespace Platform{
// =====================================================
// class FactoryRepository
// =====================================================
class FactoryRepository{
private:
FactoryRepository(){};
FactoryRepository(const FactoryRepository& );
void operator=(const FactoryRepository& );
private:
GraphicsFactoryGl graphicsFactoryGl;
SoundFactoryOpenAL soundFactoryOpenAL;
public:
static FactoryRepository &getInstance();
GraphicsFactory *getGraphicsFactory(const string &name);
SoundFactory *getSoundFactory(const string &name);
};
}}//end namespace
#endif

View File

@@ -1,57 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
//
// 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_PLATFORM_GLWRAP_H_
#define _SHARED_PLATFORM_GLWRAP_H_
#include <SDL.h>
#define GL_GLEXT_PROTOTYPES
#include <SDL_opengl.h>
#include <string>
#include "font.h"
#include "types.h"
using std::string;
using Shared::Graphics::FontMetrics;
namespace Shared{ namespace Platform{
// =====================================================
// class PlatformContextGl
// =====================================================
class PlatformContextGl {
public:
virtual ~PlatformContextGl() {}
virtual void init(int colorBits, int depthBits, int stencilBits);
virtual void end();
virtual void makeCurrent();
virtual void swapBuffers();
DeviceContextHandle getHandle() const { return 0; }
};
// =====================================================
// Global Fcs
// =====================================================
void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, int charCount, FontMetrics &metrics);
void createGlFontOutlines(uint32 &base, const string &type, int width, float depth, int charCount, FontMetrics &metrics);
const char *getPlatformExtensions(const PlatformContextGl *pcgl);
void* getGlProcAddress(const char *procName);
}}//end namespace
#endif

View File

@@ -1,7 +0,0 @@
#ifndef _NOIMPL_H_
#define _NOIMPL_H_
#define NOIMPL std::cerr << __PRETTY_FUNCTION__ << " not implemented.\n";
#endif

View File

@@ -1,29 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2005 Matthias Braun
//
// 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_PLATFORM_MAIN_H_
#define _SHARED_PLATFORM_MAIN_H_
#include <SDL.h>
#include <iostream>
#define MAIN_FUNCTION(X) int main(int argc, char **argv) \
{ \
if(SDL_Init(SDL_INIT_EVERYTHING) < 0) { \
std::cerr << "Couldn't initialize SDL: " << SDL_GetError() << "\n"; \
return 1; \
} \
SDL_EnableUNICODE(1); \
int result = X(argc, argv); \
SDL_Quit(); \
return result; \
}
#endif

View File

@@ -1,115 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
//
// 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_PLATFORM_PLATFORMUTIL_H_
#define _SHARED_PLATFORM_PLATFORMUTIL_H_
#include <string>
#include <vector>
#include <stdexcept>
#include <SDL.h>
#include "types.h"
#include "checksum.h"
#include <utility>
using std::string;
using std::vector;
using std::exception;
using Shared::Platform::int64;
using Shared::Util::Checksum;
namespace Shared{ namespace Platform{
// =====================================================
// class PerformanceTimer
// =====================================================
class PerformanceTimer{
private:
Uint32 lastTicks;
Uint32 updateTicks;
int times; // number of consecutive times
int maxTimes; // maximum number consecutive times
public:
void init(float fps, int maxTimes= -1);
bool isTime();
void reset();
};
// =====================================================
// class Chrono
// =====================================================
class Chrono {
private:
Uint32 startCount;
Uint32 accumCount;
Uint32 freq;
bool stopped;
public:
Chrono();
void start();
void stop();
int64 getMicros() const;
int64 getMillis() const;
int64 getSeconds() const;
private:
int64 queryCounter(int multiplier) const;
};
// =====================================================
// class PlatformExceptionHandler
// =====================================================
class PlatformExceptionHandler {
public:
virtual ~PlatformExceptionHandler() {}
void install(string dumpFileName) {}
virtual void handle()=0;
};
// =====================================================
// Misc
// =====================================================
void findAll(const string &path, vector<string> &results, bool cutExtension=false, bool errorOnNotFound=true);
int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string &filterFileExt, Checksum *recursiveChecksum);
vector<std::pair<string,int32> > getFolderTreeContentsCheckSumListRecursively(const string &path, const string &filterFileExt, vector<std::pair<string,int32> > *recursiveMap);
void createDirectoryPaths(string Path);
string extractDirectoryPathFromFile(string filename);
bool changeVideoMode(int resH, int resW, int colorBits, int refreshFrequency);
void restoreVideoMode();
void message(string message);
bool ask(string message);
void exceptionMessage(const exception &excp);
int getScreenW();
int getScreenH();
void sleep(int millis);
void showCursor(bool b);
bool isKeyDown(int virtualKey);
string getCommandLine();
}}//end namespace
#endif

View File

@@ -1,26 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
//
// 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_PLATFORM_SDL_GLOBALS_H_
#define _SHARED_PLATFORM_SDL_GLOBALS_H_
// This header contains things that should not be used outside the platform/sdl
// directory
namespace Shared{ namespace Platform{ namespace Private{
extern bool shouldBeFullscreen;
extern int ScreenWidth;
extern int ScreenHeight;
}}}
#endif

View File

@@ -1,67 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
//
// 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_PLATFORM_THREAD_H_
#define _SHARED_PLATFORM_THREAD_H_
#include <SDL_thread.h>
#include <SDL_mutex.h>
// =====================================================
// class Thread
// =====================================================
namespace Shared{ namespace Platform{
class Thread{
public:
enum Priority {
pIdle = 0,
pLow = 1,
pNormal = 2,
pHigh = 3,
pRealTime = 4
};
private:
SDL_Thread* thread;
public:
virtual ~Thread() {}
void start();
virtual void execute()=0;
void setPriority(Thread::Priority threadPriority);
void suspend();
void resume();
private:
static int beginExecution(void *param);
};
// =====================================================
// class Mutex
// =====================================================
class Mutex{
private:
SDL_mutex* mutex;
public:
Mutex();
~Mutex();
void p();
void v();
};
}}//end namespace
#endif

View File

@@ -1,37 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
//
// 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_PLATFORM_TYPES_H_
#define _SHARED_PLATFORM_TYPES_H_
#include <SDL_types.h>
namespace Shared{ namespace Platform{
// These don't have a real meaning in the SDL port
typedef void* WindowHandle;
typedef void* DeviceContextHandle;
typedef void* GlContextHandle;
typedef float float32;
typedef double float64;
// don't use Sint8 here because that is defined as signed char
// and some parts of the code do std::string str = (int8*) var;
typedef char int8;
typedef Uint8 uint8;
typedef Sint16 int16;
typedef Uint16 uint16;
typedef Sint32 int32;
typedef Uint32 uint32;
typedef Sint64 int64;
}}//end namespace
#endif

View File

@@ -1,144 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
//
// 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_PLATFORM_WINDOW_H_
#define _SHARED_PLATFORM_WINDOW_H_
#include <map>
#include <string>
#include <SDL.h>
#include "types.h"
using std::map;
using std::string;
namespace Shared{ namespace Platform{
class Timer;
class PlatformContextGl;
enum MouseButton{
mbLeft,
mbRight,
mbCenter
};
enum SizeState{
ssMaximized,
ssMinimized,
ssRestored
};
// keycode constants (unfortunately designed after DirectInput and therefore not
// very specific)
// They also have to fit into a char. The positive numbers seem to be equal
// to ascii, for the rest we have to find sensefull mappings from SDL (which is
// alot more fine grained like left/right control instead of just control...)
const char vkAdd = -1;
const char vkSubtract = -2;
const char vkAlt = -3;
const char vkControl = -4;
const char vkShift = -5;
const char vkEscape = -6;
const char vkUp = -7;
const char vkLeft = -8;
const char vkRight = -9;
const char vkDown = -10;
const char vkReturn = -11;
const char vkBack = -12;
struct MouseState{
bool leftMouse;
bool rightMouse;
bool centerMouse;
};
enum WindowStyle{
wsFullscreen,
wsWindowedFixed,
wsWindowedResizable
};
// =====================================================
// class Window
// =====================================================
class Window {
private:
Uint32 lastMouseDown[3];
int lastMouseX[3];
int lastMouseY[3];
protected:
int w, h;
public:
static bool handleEvent();
Window();
virtual ~Window();
WindowHandle getHandle() {return 0;}
string getText();
int getX() { return 0; }
int getY() { return 0; }
int getW() { return w; }
int getH() { return h; }
//component state
int getClientW() { return getW(); }
int getClientH() { return getH(); }
float getAspect();
//object state
void setText(string text);
void setStyle(WindowStyle windowStyle);
void setSize(int w, int h);
void setPos(int x, int y);
void setEnabled(bool enabled);
void setVisible(bool visible);
//misc
void create();
void destroy();
void minimize();
protected:
virtual void eventCreate(){}
virtual void eventMouseDown(int x, int y, MouseButton mouseButton){}
virtual void eventMouseUp(int x, int y, MouseButton mouseButton){}
virtual void eventMouseMove(int x, int y, const MouseState* mouseState){}
virtual void eventMouseDoubleClick(int x, int y, MouseButton mouseButton){}
virtual void eventKeyDown(char key){}
virtual void eventKeyUp(char key){}
virtual void eventKeyPress(char c){}
virtual void eventResize(){};
virtual void eventPaint(){}
virtual void eventTimer(int timerId){}
virtual void eventActivate(bool activated){};
virtual void eventResize(SizeState sizeState){};
virtual void eventMenu(int menuId){}
virtual void eventClose(){};
virtual void eventDestroy(){};
private:
/// needed to detect double clicks
void handleMouseDown(SDL_Event event);
static MouseButton getMouseButton(int sdlButton);
static char getKey(SDL_keysym keysym);
static void toggleFullscreen();
};
}}//end namespace
#endif

View File

@@ -1,38 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
//
// 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_PLATFORM_WINDOWGL_H_
#define _SHARED_PLATFORM_WINDOWGL_H_
#include "context_gl.h"
#include "window.h"
using Shared::Graphics::Gl::ContextGl;
namespace Shared{ namespace Platform{
// =====================================================
// class WindowGl
// =====================================================
class WindowGl: public Window{
private:
ContextGl context;
public:
void initGl(int colorBits, int depthBits, int stencilBits);
void makeCurrentGl();
void swapBuffersGl();
};
}}//end namespace
#endif