mirror of
https://github.com/glest/glest-source.git
synced 2025-09-29 08:59:01 +02:00
Moved most of the code from platform specific platform_util into a shared platform_common area
This commit is contained in:
@@ -29,7 +29,7 @@ using std::ifstream;
|
||||
using std::ios;
|
||||
using std::runtime_error;
|
||||
|
||||
using Shared::Platform::extractExtension;
|
||||
using Shared::PlatformCommon::extractExtension;
|
||||
|
||||
#define AS_STRING(...) #__VA_ARGS__
|
||||
|
||||
|
136
source/shared_lib/include/platform/common/platform_common.h
Normal file
136
source/shared_lib/include/platform/common/platform_common.h
Normal file
@@ -0,0 +1,136 @@
|
||||
// ==============================================================
|
||||
// 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_PLATFORMCOMMON_H_
|
||||
#define _SHARED_PLATFORM_PLATFORMCOMMON_H_
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
#include <list>
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#include "types.h"
|
||||
#include "checksum.h"
|
||||
#include <utility>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::list;
|
||||
using std::exception;
|
||||
|
||||
using Shared::Platform::int64;
|
||||
using Shared::Util::Checksum;
|
||||
|
||||
namespace Shared { namespace PlatformCommon {
|
||||
|
||||
// =====================================================
|
||||
// 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;
|
||||
|
||||
static int64 getCurTicks();
|
||||
static int64 getCurMillis();
|
||||
|
||||
private:
|
||||
int64 queryCounter(int multiplier) const;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ModeInfo
|
||||
// =====================================================
|
||||
class ModeInfo {
|
||||
public:
|
||||
int width;
|
||||
int height;
|
||||
int depth;
|
||||
|
||||
ModeInfo(int width, int height, int depth);
|
||||
|
||||
string getString() const;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// Misc
|
||||
// =====================================================
|
||||
void Tokenize(const string& str,vector<string>& tokens,const string& delimiters = " ");
|
||||
bool isdir(const char *path);
|
||||
void findDirs(const vector<string> &paths, vector<string> &results, bool errorOnNotFound=false);
|
||||
void findAll(const vector<string> &paths, const string &fileFilter, vector<string> &results, bool cutExtension=false, bool errorOnNotFound=true);
|
||||
void findAll(const string &path, vector<string> &results, bool cutExtension=false, bool errorOnNotFound=true);
|
||||
|
||||
int32 getFolderTreeContentsCheckSumRecursively(vector<string> paths, string pathSearchString, const string filterFileExt, Checksum *recursiveChecksum);
|
||||
int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string &filterFileExt, Checksum *recursiveChecksum);
|
||||
vector<std::pair<string,int32> > getFolderTreeContentsCheckSumListRecursively(vector<string> paths, string pathSearchString, const string filterFileExt, vector<std::pair<string,int32> > *recursiveMap);
|
||||
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);
|
||||
string extractExtension(const string& filename);
|
||||
|
||||
void getFullscreenVideoModes(list<ModeInfo> *modeinfos);
|
||||
void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight);
|
||||
bool changeVideoMode(int resH, int resW, int colorBits, int refreshFrequency);
|
||||
void restoreVideoMode(bool exitingApp=false);
|
||||
|
||||
bool EndsWith(const string &str, const string& key);
|
||||
|
||||
int getScreenW();
|
||||
int getScreenH();
|
||||
|
||||
void sleep(int millis);
|
||||
|
||||
void showCursor(bool b);
|
||||
bool isKeyDown(int virtualKey);
|
||||
string getCommandLine();
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -12,86 +12,14 @@
|
||||
#define _SHARED_PLATFORM_PLATFORMUTIL_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
#include <list>
|
||||
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#include "types.h"
|
||||
#include "checksum.h"
|
||||
#include <utility>
|
||||
#include "platform_common.h"
|
||||
|
||||
using namespace Shared::PlatformCommon;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::list;
|
||||
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;
|
||||
|
||||
static int64 getCurTicks();
|
||||
static int64 getCurMillis();
|
||||
|
||||
private:
|
||||
int64 queryCounter(int multiplier) const;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ModeInfo
|
||||
// =====================================================
|
||||
class ModeInfo {
|
||||
public:
|
||||
int width;
|
||||
int height;
|
||||
int depth;
|
||||
|
||||
ModeInfo(int width, int height, int depth);
|
||||
|
||||
string getString() const;
|
||||
};
|
||||
namespace Shared { namespace Platform {
|
||||
|
||||
// =====================================================
|
||||
// class PlatformExceptionHandler
|
||||
@@ -108,38 +36,10 @@ public:
|
||||
// Misc
|
||||
// =====================================================
|
||||
int MessageBox(int handle, const char *msg, const char *title, int buttons);
|
||||
void Tokenize(const string& str,vector<string>& tokens,const string& delimiters = " ");
|
||||
bool isdir(const char *path);
|
||||
void findDirs(const vector<string> &paths, vector<string> &results, bool errorOnNotFound=false);
|
||||
void findAll(const vector<string> &paths, const string &fileFilter, vector<string> &results, bool cutExtension=false, bool errorOnNotFound=true);
|
||||
void findAll(const string &path, vector<string> &results, bool cutExtension=false, bool errorOnNotFound=true);
|
||||
|
||||
int32 getFolderTreeContentsCheckSumRecursively(vector<string> paths, string pathSearchString, const string filterFileExt, Checksum *recursiveChecksum);
|
||||
int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string &filterFileExt, Checksum *recursiveChecksum);
|
||||
vector<std::pair<string,int32> > getFolderTreeContentsCheckSumListRecursively(vector<string> paths, string pathSearchString, const string filterFileExt, vector<std::pair<string,int32> > *recursiveMap);
|
||||
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);
|
||||
string extractExtension(const string& filename);
|
||||
|
||||
void getFullscreenVideoModes(list<ModeInfo> *modeinfos);
|
||||
void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight);
|
||||
bool changeVideoMode(int resH, int resW, int colorBits, int refreshFrequency);
|
||||
void restoreVideoMode(bool exitingApp=false);
|
||||
|
||||
bool EndsWith(const string &str, const string& key);
|
||||
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
|
||||
|
26
source/shared_lib/include/platform/sdl/sdl_private.h
Normal file
26
source/shared_lib/include/platform/sdl/sdl_private.h
Normal file
@@ -0,0 +1,26 @@
|
||||
// ==============================================================
|
||||
// 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 PlatformCommon { namespace Private {
|
||||
|
||||
extern bool shouldBeFullscreen;
|
||||
extern int ScreenWidth;
|
||||
extern int ScreenHeight;
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
|
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "sound_player.h"
|
||||
#include "platform_util.h"
|
||||
#include "platform_common.h"
|
||||
|
||||
#include <SDL.h>
|
||||
#include <AL/alc.h>
|
||||
@@ -18,6 +19,7 @@
|
||||
#include <vector>
|
||||
|
||||
using std::vector;
|
||||
using namespace Shared::PlatformCommon;
|
||||
|
||||
namespace Shared{ namespace Sound{ namespace OpenAL{
|
||||
|
||||
|
100
source/shared_lib/include/util/profiler.h
Normal file
100
source/shared_lib/include/util/profiler.h
Normal file
@@ -0,0 +1,100 @@
|
||||
// ==============================================================
|
||||
// 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_UTIL_PROFILER_H_
|
||||
#define _SHARED_UTIL_PROFILER_H_
|
||||
|
||||
//#define SL_PROFILE
|
||||
//SL_PROFILE controls if profile is enabled or not
|
||||
|
||||
#include "platform_util.h"
|
||||
#include "platform_common.h"
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
using std::list;
|
||||
using std::string;
|
||||
|
||||
using Shared::PlatformCommon::Chrono;
|
||||
|
||||
namespace Shared{ namespace Util{
|
||||
|
||||
#ifdef SL_PROFILE
|
||||
|
||||
// =====================================================
|
||||
// class Section
|
||||
// =====================================================
|
||||
|
||||
class Section{
|
||||
public:
|
||||
typedef list<Section*> SectionContainer;
|
||||
private:
|
||||
string name;
|
||||
Chrono chrono;
|
||||
int64 milisElapsed;
|
||||
Section *parent;
|
||||
SectionContainer children;
|
||||
|
||||
public:
|
||||
Section(const string &name);
|
||||
|
||||
Section *getParent() {return parent;}
|
||||
const string &getName() const {return name;}
|
||||
|
||||
void setParent(Section *parent) {this->parent= parent;}
|
||||
|
||||
void start() {chrono.start();}
|
||||
void stop() {milisElapsed+=chrono.getMillis();}
|
||||
|
||||
void addChild(Section *child) {children.push_back(child);}
|
||||
Section *getChild(const string &name);
|
||||
|
||||
void print(FILE *outSream, int tabLevel=0);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Profiler
|
||||
// =====================================================
|
||||
|
||||
class Profiler{
|
||||
private:
|
||||
Section *rootSection;
|
||||
Section *currSection;
|
||||
private:
|
||||
Profiler();
|
||||
public:
|
||||
~Profiler();
|
||||
static Profiler &getInstance();
|
||||
void sectionBegin(const string &name);
|
||||
void sectionEnd(const string &name);
|
||||
};
|
||||
|
||||
#endif //SL_PROFILE
|
||||
|
||||
// =====================================================
|
||||
// class funtions
|
||||
// =====================================================
|
||||
|
||||
inline void profileBegin(const string §ionName){
|
||||
#ifdef SL_PROFILE
|
||||
Profiler::getInstance().sectionBegin(sectionName);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void profileEnd(const string §ionName){
|
||||
#ifdef SL_PROFILE
|
||||
Profiler::getInstance().sectionEnd(sectionName);
|
||||
#endif
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user