1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-10-18 04:19:31 +00:00

Major include refactor; changes to pretty much everything

This untangles some of the gigantic kitchen sink headers
in an attempt to split things into smaller files.
Also don't include gl.h, glext.h, windows.h,
and other such nonsense *everywhere*.

Lots of cleanups on the way too. More dead/unused code removal.

Remove incrFlag(), decrFlag() Lua functions.
This commit is contained in:
fgenesis 2016-07-09 04:18:40 +02:00
commit 8472718fb7
141 changed files with 2993 additions and 3708 deletions

View file

@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "ActionInput.h"
#include "ActionMapper.h"
#include "SDL.h"
#ifndef BBGE_BUILD_SDL2
#error Needs fixes for SDL 1.2, doesnt support scancodes

View file

@ -26,6 +26,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
class Event;
class ActionMapper;
#include <map>
#include <list>
#include "ActionSet.h"
#include "Joystick.h"

View file

@ -19,6 +19,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "AfterEffect.h"
#include "RenderBase.h"
#include <assert.h>
@ -94,8 +95,7 @@ void AfterEffectManager::deleteEffects()
}
effects.clear();
numEffects=0;
while (!openSpots.empty())
openSpots.pop();
openSpots.clear();
}
void AfterEffectManager::deleteShaders()
@ -170,7 +170,7 @@ void AfterEffectManager::destroyEffect(int id)
{
delete effects[id];
effects[id] = 0;
openSpots.push(id);
openSpots.push_back(id);
}
void AfterEffectManager::render()
@ -420,11 +420,10 @@ void AfterEffectManager::reloadDevice()
void AfterEffectManager::addEffect(Effect *e)
{
if (!openSpots.empty())
{
int i = openSpots.front();
openSpots.pop();
int i = openSpots.back();
openSpots.pop_back();
effects[i] = e;
}
else
@ -435,13 +434,8 @@ void AfterEffectManager::addEffect(Effect *e)
Vector base(0,0,0);
e->position.x /= screenWidth;
e->position.y /= screenHeight;
}
@ -450,22 +444,12 @@ void ShockEffect::update(float dt, Vector ** drawGrid, int xDivs, int yDivs)
dt *= timeMultiplier;
Effect::update(dt, drawGrid, xDivs, yDivs);
centerPoint = position;
centerPoint -= ((core->screenCenter-originalCenter)*core->globalScale.x)/core->width;
float xDist,yDist,tDist;
amplitude-=dt*rate;
currentDistance+=dt*frequency;
float distFromCamp = 4;
float adjWaveLength = waveLength/distFromCamp;
float adjAmplitude = amplitude/distFromCamp;
@ -476,21 +460,13 @@ void ShockEffect::update(float dt, Vector ** drawGrid, int xDivs, int yDivs)
{
for (int j = 1; j < (yDivs-1); j++)
{
float xDist = (centerPoint.x - drawGrid[i][j].x)/.75;
float yDist = centerPoint.y - drawGrid[i][j].y;
xDist = (centerPoint.x - drawGrid[i][j].x)/.75;
yDist = centerPoint.y - drawGrid[i][j].y;
tDist = sqrtf(xDist*xDist+yDist*yDist);
float tDist = sqrtf(xDist*xDist+yDist*yDist);
if (tDist < currentDistance*adjWaveLength)
{
drawGrid[i][j].x += adjAmplitude*sinf(-tDist/adjWaveLength+currentDistance)*.75f;
drawGrid[i][j].y += adjAmplitude*cosf(-tDist/adjWaveLength+currentDistance);
}

View file

@ -98,7 +98,7 @@ public:
void reloadDevice();
std::vector<Effect*> effects;
std::queue<int> openSpots;
std::vector<int> openSpots;
bool active;

View file

@ -20,28 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "Base.h"
#include "Core.h"
#include <algorithm>
#ifdef BBGE_BUILD_WINDOWS
#include <shellapi.h>
#endif
#ifdef _MSC_VER
# include <intrin.h>
#endif
#if defined(BBGE_BUILD_UNIX)
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#include <errno.h>
#endif
#if defined(BBGE_BUILD_MACOSX)
#include <Carbon/Carbon.h>
#endif
#include <assert.h>
#include "OSFunctions.h"
#ifdef BBGE_BUILD_VFS
# include "ttvfs.h"
@ -51,79 +31,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
ttvfs::Root vfs; // extern
#endif
Vector getDirVector(Direction dir)
{
switch(dir)
{
case DIR_DOWN:
return Vector(0, 1);
break;
case DIR_UP:
return Vector(0, -1);
break;
case DIR_LEFT:
return Vector(-1, 0);
break;
case DIR_RIGHT:
return Vector(1, 0);
break;
}
return Vector(0,0);
}
#include "ttvfs_stdio.h"
Direction getOppositeDir(Direction dir)
{
switch(dir)
{
case DIR_DOWN:
return DIR_UP;
break;
case DIR_UP:
return DIR_DOWN;
break;
case DIR_LEFT:
return DIR_RIGHT;
break;
case DIR_RIGHT:
return DIR_LEFT;
break;
}
return DIR_NONE;
}
Direction getNextDirClockwise(Direction dir)
{
switch(dir)
{
case DIR_DOWN:
return DIR_LEFT;
break;
case DIR_UP:
return DIR_RIGHT;
break;
case DIR_LEFT:
return DIR_UP;
break;
case DIR_RIGHT:
return DIR_DOWN;
break;
}
return DIR_NONE;
}
void sizePowerOf2Texture(int &v)
{
int p = 8, use=0;
do
{
use = 1 << p;
p++;
}
while(v > use);
v = use;
}
int randAngle360()
{
@ -165,7 +75,7 @@ unsigned hash(const std::string &string)
static unsigned char lowerToUpperTable[256];
static unsigned char upperToLowerTable[256];
void initCharTranslationTables(const std::map<unsigned char, unsigned char>& tab)
void initCharTranslationTables(const CharTranslationTable *ptab)
{
for (unsigned int i = 0; i < 256; ++i)
{
@ -177,20 +87,23 @@ void initCharTranslationTables(const std::map<unsigned char, unsigned char>& tab
lowerToUpperTable[i] = i - 'a' + 'A';
upperToLowerTable[i - 'a' + 'A'] = i;
}
for (std::map<unsigned char, unsigned char>::const_iterator it = tab.begin(); it != tab.end(); ++it)
{
lowerToUpperTable[it->first] = it->second;
upperToLowerTable[it->second] = it->first;
}
if(ptab)
for (unsigned int i = 0; i < 256; ++i)
{
int to = (*ptab)[i];
if(to > 0)
{
lowerToUpperTable[i] = to;
upperToLowerTable[to] = i;
}
}
}
struct TransatableStaticInit
{
TransatableStaticInit()
{
std::map<unsigned char, unsigned char> dummy;
initCharTranslationTables(dummy);
initCharTranslationTables(NULL);
}
};
static TransatableStaticInit _transtable_static_init;
@ -259,11 +172,6 @@ std::string numToZeroString(int num, int zeroes)
return os.str();
}
bool isVectorInRect(const Vector &vec, const Vector &coord1, const Vector &coord2)
{
return (vec.x > coord1.x && vec.x < coord2.x && vec.y > coord1.y && vec.y < coord2.y);
}
void stringToUpper(std::string &s)
{
for (int i = 0; i < s.size(); i++)
@ -331,7 +239,7 @@ bool exists(const std::string &f, bool makeFatal, bool skipVFS)
#endif
if (!e)
{
std::string tmp = core->adjustFilenameCase(f);
std::string tmp = adjustFilenameCase(f);
FILE *file = fopen(tmp.c_str(), "rb");
if (file)
{
@ -348,43 +256,14 @@ bool exists(const std::string &f, bool makeFatal, bool skipVFS)
return e;
}
void drawCircle(float radius, int stepSize)
{
glBegin(GL_POLYGON);
{
for(int i=0;i < 360; i+=stepSize) {
const float degInRad = i*PI/180.0f;
glVertex3f(cosf(degInRad)*radius, sinf(degInRad)*radius,0.0);
}
}
glEnd();
}
void exit_error(const std::string &message)
{
errorLog(message);
exit(1);
}
std::string parseCommand(const std::string &line, const std::string &command)
{
int stringPos = line.find(command);
if (stringPos != std::string::npos)
{
return line.substr((command.length()), line.length());
}
return "";
}
void glColor3_256(int r, int g, int b)
{
glColor4f(float(r)/256.0f, float(g)/256.0f, float(b)/256.0f, 1.0f);
}
bool chance(int perc)
{
if (perc == 100) return true;
@ -392,15 +271,6 @@ bool chance(int perc)
return ((rand()%100) <= perc);
}
bool chancef(float p)
{
if (p >= 1) return true;
if (p <= 0) return false;
return ((rand()%100) <= p*100);
}
void errorLog(const std::string &s)
{
if (core)
@ -472,54 +342,6 @@ char *readFile(const std::string& path, unsigned long *size_ret)
return buffer;
}
tinyxml2::XMLError readXML(const std::string& fn, tinyxml2::XMLDocument& doc)
{
unsigned long sz = 0;
char *buf = readFile(fn, &sz);
tinyxml2::XMLError err = doc.Parse(buf, sz);
delete [] buf;
return err;
}
tinyxml2::XMLDocument *readXML(const std::string& fn, tinyxml2::XMLError *perr /* = 0 */, bool keepEmpty /* = false */)
{
tinyxml2::XMLDocument *doc = new tinyxml2::XMLDocument();
tinyxml2::XMLError err = readXML(fn, *doc);
if(perr)
*perr = err;
if(err != tinyxml2::XML_SUCCESS && !keepEmpty)
{
delete doc;
doc = NULL;
}
return doc;
}
void doSingleFile(const std::string &path, const std::string &type, std::string filename, void callback(const std::string &filename, int param), int param)
{
if (filename.size()>4)
{
std::string search = filename;
stringToLower(search);
std::string filetype = filename.substr(search.size()-4, search.size());
debugLog("checking:" + search + " for type:" + type);
if (search.find(type)!=std::string::npos)
{
debugLog("callback");
callback(path+filename, param);
}
else
{
debugLog("not the same");
}
}
}
std::string stripEndlineForUnix(const std::string &in)
{
std::string out;
@ -533,257 +355,6 @@ std::string stripEndlineForUnix(const std::string &in)
return out;
}
#ifdef BBGE_BUILD_VFS
struct vfscallback_s
{
std::string *path;
const char *ext;
intptr_t param;
void (*callback)(const std::string &filename, intptr_t param);
};
void forEachFile_vfscallback(VFILE *vf, void *user)
{
vfscallback_s *d = (vfscallback_s*)user;
if(d->ext)
{
const char *e = strrchr(vf->name(), '.');
if(e && nocasecmp(d->ext, e))
return;
}
d->callback(*(d->path) + vf->name(), d->param);
}
#endif
void forEachFile(std::string path, std::string type, void callback(const std::string &filename, intptr_t param), intptr_t param)
{
if (path.empty()) return;
#ifdef BBGE_BUILD_VFS
ttvfs::DirView view;
if(!vfs.FillDirView(path.c_str(), view))
{
debugLog("Path '" + path + "' does not exist");
return;
}
vfscallback_s dat;
dat.path = &path;
dat.ext = type.length() ? type.c_str() : NULL;
dat.param = param;
dat.callback = callback;
view.forEachFile(forEachFile_vfscallback, &dat, true);
return;
// -------------------------------------
#endif
stringToLower(type);
path = core->adjustFilenameCase(path);
debugLog("forEachFile - path: " + path + " type: " + type);
#if defined(BBGE_BUILD_UNIX)
DIR *dir=0;
dir = opendir(path.c_str());
if (dir)
{
dirent *file=0;
while ( (file=readdir(dir)) != NULL )
{
if (file->d_name && strlen(file->d_name) > 4)
{
debugLog(file->d_name);
char *extension=strrchr(file->d_name,'.');
if (extension)
{
debugLog(extension);
if (extension!=NULL)
{
if (strcasecmp(extension,type.c_str())==0)
{
callback(path + std::string(file->d_name), param);
}
}
}
}
}
closedir(dir);
}
else
{
debugLog("FAILED TO OPEN DIR");
}
#endif
#ifdef BBGE_BUILD_WINDOWS
BOOL fFinished;
HANDLE hList;
TCHAR szDir[MAX_PATH+1];
WIN32_FIND_DATA FileData;
int end = path.size()-1;
if (path[end] != '/')
path[end] += '/';
// Get the proper directory path
// \\ %s\\*
if (type.find('.')==std::string::npos)
{
type = "." + type;
}
sprintf(szDir, "%s\\*", path.c_str());
stringToUpper(type);
// Get the first file
hList = FindFirstFile(szDir, &FileData);
if (hList == INVALID_HANDLE_VALUE)
{
debugLog("No files of type " + type + " found in path " + path);
}
else
{
// Traverse through the directory structure
fFinished = FALSE;
while (!fFinished)
{
// Check the object is a directory or not
//printf("%*s%s\n", indent, "", FileData.cFileName);
std::string filename = FileData.cFileName;
if (filename.size()>4)
{
std::string filetype = filename.substr(filename.size()-4, filename.size());
stringToUpper(filetype);
if (filetype==type)
{
callback(path+filename, param);
}
}
if (!FindNextFile(hList, &FileData))
{
fFinished = TRUE;
}
}
}
FindClose(hList);
#endif
}
std::vector<std::string> getFileList(std::string path, std::string type, int param)
{
std::vector<std::string> list;
#ifdef BBGE_BUILD_WINDOWS
BOOL fFinished;
HANDLE hList;
TCHAR szDir[MAX_PATH+1];
WIN32_FIND_DATA FileData;
// Get the proper directory path
sprintf(szDir, "%s\\*", path.c_str());
// Get the first file
hList = FindFirstFile(szDir, &FileData);
if (hList == INVALID_HANDLE_VALUE)
{
printf("No files found\n\n");
}
else
{
// Traverse through the directory structure
fFinished = FALSE;
while (!fFinished)
{
// Check the object is a directory or not
//printf("%*s%s\n", indent, "", FileData.cFileName);
std::string filename = FileData.cFileName;
if (filename.size()>4 && filename.substr(filename.size()-4, filename.size())==type)
{
list.push_back (filename);
}
if (!FindNextFile(hList, &FileData))
{
fFinished = TRUE;
}
}
}
FindClose(hList);
#endif
return list;
}
#if defined(BBGE_BUILD_MACOSX) && !SDL_VERSION_ATLEAST(2,0,0)
void cocoaMessageBox(const std::string &title, const std::string &msg);
#endif
void messageBox(const std::string& title, const std::string &msg)
{
#ifdef BBGE_BUILD_WINDOWS
MessageBox (0,msg.c_str(),title.c_str(),MB_OK);
#elif SDL_VERSION_ATLEAST(2,0,0)
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, title.c_str(),
msg.c_str(), NULL);
#elif defined(BBGE_BUILD_MACOSX)
cocoaMessageBox(title, msg);
#elif defined(BBGE_BUILD_UNIX)
// !!! FIXME: probably don't want the whole GTK+ dependency in here...
fprintf(stderr, "%s: %s\n", title.c_str(), msg.c_str());
#else
#error Please define your platform.
#endif
}
Vector getNearestPointOnLine(Vector a, Vector b, Vector c)
{
Vector nearest;
/// Local Variables ///////////////////////////////////////////////////////////
long dot_ta,dot_tb;
///////////////////////////////////////////////////////////////////////////////
// SEE IF a IS THE NEAREST POINT - ANGLE IS OBTUSE
dot_ta = (c.x - a.x)*(b.x - a.x) + (c.y - a.y)*(b.y - a.y);
if (dot_ta <= 0) // IT IS OFF THE a VERTEX
{
nearest.x = a.x;
nearest.y = a.y;
return nearest;
}
dot_tb = (c.x - b.x)*(a.x - b.x) + (c.y - b.y)*(a.y - b.y);
// SEE IF b IS THE NEAREST POINT - ANGLE IS OBTUSE
if (dot_tb <= 0)
{
nearest.x = b.x;
nearest.y = b.y;
return nearest;
}
// FIND THE REAL NEAREST POINT ON THE LINE SEGMENT - BASED ON RATIO
nearest.x = a.x + ((b.x - a.x) * dot_ta)/(dot_ta + dot_tb);
nearest.y = a.y + ((b.y - a.y) * dot_ta)/(dot_ta + dot_tb);
return nearest;
}
bool isTouchingLine(Vector lineStart, Vector lineEnd, Vector point, int radius, Vector *closestP)
{
@ -807,30 +378,6 @@ bool isTouchingLine(Vector lineStart, Vector lineEnd, Vector point, int radius,
return distsqr <= radius*radius;
}
GLuint generateEmptyTexture(int quality) // Create An Empty Texture
{
GLuint txtnumber=0; // Texture ID
unsigned char *data; // Stored Data
// Create Storage Space For Texture Data (128x128x4)
int size = (quality * quality) * 4;
data = new unsigned char[size];
memset(data, 0, size); // Clear Storage Memory
glGenTextures(1, &txtnumber); // Create 1 Texture
glBindTexture(GL_TEXTURE_2D, txtnumber); // Bind The Texture
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, quality, quality, 0,
GL_RGBA, GL_UNSIGNED_BYTE, data); // Build Texture Using Information In data
delete [] data; // Release data
return txtnumber; // Return The Texture ID
}
Vector randVector(float mag)
{
float angle = (rand() / (float)RAND_MAX) * 2.0f * PI;
@ -861,197 +408,6 @@ float lerp(const float &v1, const float &v2, float dt, int lerpType)
return (v2-v1)*dt+v1;
}
#if 0
#include <zlib.h>
#include <assert.h>
#define CHUNK 16384
/* Compress from file source to file dest until EOF on source.
def() returns Z_OK on success, Z_MEM_ERROR if memory could not be
allocated for processing, Z_STREAM_ERROR if an invalid compression
level is supplied, Z_VERSION_ERROR if the version of zlib.h and the
version of the library linked do not match, or Z_ERRNO if there is
an error reading or writing the files. */
int packFile(const std::string &sourcef, const std::string &destf, int level)
{
FILE *source = fopen(core->adjustFilenameCase(sourcef).c_str(), "rb");
FILE *dest = fopen(core->adjustFilenameCase(destf).c_str(), "wb");
if (!source || !dest)
return 0;
int ret, flush;
unsigned have;
z_stream strm;
unsigned char in[CHUNK];
unsigned char out[CHUNK];
/* allocate deflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
ret = deflateInit(&strm, level);
if (ret != Z_OK)
return ret;
/* compress until end of file */
do {
strm.avail_in = fread(in, 1, CHUNK, source);
if (ferror(source)) {
(void)deflateEnd(&strm);
return Z_ERRNO;
}
flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
strm.next_in = in;
/* run deflate() on input until output buffer not full, finish
compression if all of source has been read in */
do {
strm.avail_out = CHUNK;
strm.next_out = out;
ret = deflate(&strm, flush); /* no bad return value */
assert(ret != Z_STREAM_ERROR); /* state not clobbered */
have = CHUNK - strm.avail_out;
if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
(void)deflateEnd(&strm);
return Z_ERRNO;
}
} while (strm.avail_out == 0);
assert(strm.avail_in == 0); /* all input will be used */
/* done when last data in file processed */
} while (flush != Z_FINISH);
assert(ret == Z_STREAM_END); /* stream will be complete */
/* clean up and return */
(void)deflateEnd(&strm);
fclose(source);
fclose(dest);
return Z_OK;
}
/* Decompress from file source to file dest until stream ends or EOF.
inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be
allocated for processing, Z_DATA_ERROR if the deflate data is
invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
the version of the library linked do not match, or Z_ERRNO if there
is an error reading or writing the files. */
int unpackFile(const std::string &sourcef, const std::string &destf)
{
FILE *source = fopen(core->adjustFilenameCase(sourcef).c_str(), "rb");
FILE *dest = fopen(core->adjustFilenameCase(destf).c_str(), "wb");
if (!source || !dest)
return 0;
int ret;
unsigned have;
z_stream strm;
unsigned char in[CHUNK];
unsigned char out[CHUNK];
/* allocate inflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = 0;
strm.next_in = Z_NULL;
ret = inflateInit(&strm);
if (ret != Z_OK)
return ret;
/* decompress until deflate stream ends or end of file */
do {
strm.avail_in = fread(in, 1, CHUNK, source);
if (ferror(source)) {
(void)inflateEnd(&strm);
return Z_ERRNO;
}
if (strm.avail_in == 0)
break;
strm.next_in = in;
/* run inflate() on input until output buffer not full */
do {
strm.avail_out = CHUNK;
strm.next_out = out;
ret = inflate(&strm, Z_NO_FLUSH);
assert(ret != Z_STREAM_ERROR); /* state not clobbered */
switch (ret) {
case Z_NEED_DICT:
ret = Z_DATA_ERROR; /* and fall through */
case Z_DATA_ERROR:
case Z_MEM_ERROR:
(void)inflateEnd(&strm);
return ret;
}
have = CHUNK - strm.avail_out;
if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
(void)inflateEnd(&strm);
return Z_ERRNO;
}
} while (strm.avail_out == 0);
/* done when inflate() says it's done */
} while (ret != Z_STREAM_END);
/* clean up and return */
(void)inflateEnd(&strm);
fclose(source);
fclose(dest);
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
}
#endif
void openURL(const std::string &url)
{
#ifdef BBGE_BUILD_WINDOWS
ShellExecute(NULL, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
#endif
#if defined(BBGE_BUILD_MACOSX)
CFStringRef str = CFStringCreateWithCString (0, url.c_str(), 0);
CFURLRef ref = CFURLCreateWithString(kCFAllocatorDefault, str, NULL);
LSOpenCFURLRef(ref, 0);
CFRelease(ref);
CFRelease(str);
#elif BBGE_BUILD_UNIX
std::string cmd("PATH=$PATH:. xdg-open '");
cmd += url;
cmd += "'";
if (system(cmd.c_str()) != 0)
debugLog("system(xdg_open '" + url + "') failed");
#endif
}
void clamp256Col(int *r)
{
if (*r > 255) *r = 255;
if (*r < 0) *r = 0;
}
Vector colorRGB(int r, int g, int b)
{
Vector c;
clamp256Col(&r);
clamp256Col(&g);
clamp256Col(&b);
c.x = float(r)/255.0f;
c.y = float(g)/255.0f;
c.z = float(b)/255.0f;
return c;
}
std::string underscoresToSpaces(const std::string &str)
{
std::string s = str;
@ -1068,48 +424,7 @@ std::string spacesToUnderscores(const std::string &str)
return s;
}
void triggerBreakpoint()
{
#ifdef _MSC_VER
__debugbreak();
#elif defined(__GNUC__) && ((__i386__) || (__x86_64__))
__asm__ __volatile__ ( "int $3\n\t" );
#else
raise(SIGTRAP);
#endif
}
bool createDir(const std::string& d)
{
bool success = false;
int err = 0;
#if defined(BBGE_BUILD_UNIX)
if (!mkdir(d.c_str(), S_IRWXU))
success = true;
else
{
err = errno;
if (err == EEXIST)
success = true;
}
#elif defined(BBGE_BUILD_WINDOWS)
if (CreateDirectoryA(d.c_str(), NULL))
success = true;
else
{
err = GetLastError();
if(err == ERROR_ALREADY_EXISTS)
success = true;
}
#endif
if (!success)
{
std::ostringstream os;
os << "Failed to create directory: [" << d << "], error code: " << err;
debugLog(os.str());
}
return success;
}
#include "DeflateCompressor.h"

View file

@ -22,13 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define BBGE_BASE_H
#ifdef BBGE_BUILD_WINDOWS
#define WIN32_LEAN_AND_MEAN
#define WIN32_NOMINMAX
#include <windows.h>
#undef min
#undef max
#define WIN32_NOMINMAX
#ifdef _MSC_VER
#define strtof (float)strtod
#define snprintf _snprintf
@ -37,28 +31,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "BBGECompileConfig.h"
#ifdef BBGE_BUILD_WINDOWS
#define BBGE_PROF(x)
#define BBGE_PROF(x)
#else
#define BBGE_PROF(x)
#endif
#include "SDL.h"
#define GL_GLEXT_LEGACY 1
#include "gl.h"
#include "glext.h"
#define compile_assert(pred) switch(0){case 0:case (pred):;}
#ifdef _MSC_VER
@ -82,36 +57,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#pragma warning(disable:4189) // UqqqqSEFUL: local variable is initialized but not referenced
#endif
#undef GetCharWidth
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <stack>
#include "Rect.h"
#include "math.h"
#include "ttvfs_stdio.h"
#include "tinyxml2.h"
#include "Refcounted.h"
#ifdef BBGE_BUILD_LINUX
# include <sys/types.h>
# include <stdint.h>
#endif
// dumb win32 includes/defines cleanup
#undef GetCharWidth
#include "Vector.h"
#include "OSFunctions.h"
// --- Defined in RenderBase.cpp -- Declared here to avoid pulling in gl.h via RenderBase.h --
void drawCircle(float radius, int stepSize);
unsigned generateEmptyTexture(int res);
void sizePowerOf2Texture(int &v);
// ----------------------
enum Align { ALIGN_CENTER=0, ALIGN_LEFT };
@ -129,11 +88,6 @@ enum Direction
DIR_MAX = 8
};
#include "Event.h"
#include "Vector.h"
const float SQRT2 = 1.41421356;
const float PI = 3.14159265;
@ -143,34 +97,26 @@ const float PI_HALF = 1.57079633;
#define HUGE_VALF ((float)1e38)
#endif
struct IntPair
{
IntPair(unsigned short int x, unsigned short int y) : x(x), y(y) {}
unsigned short int x, y;
};
typedef int CharTranslationTable[256]; // -1 entries are skipped
#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
std::string numToZeroString(int num, int zeroes);
bool chance(int perc);
bool chancef(float p);
void initCharTranslationTables(const std::map<unsigned char, unsigned char>& tab);
void initCharTranslationTables(const CharTranslationTable *ptab);
void stringToUpper(std::string &s);
void stringToLower(std::string &s);
void stringToLowerUserData(std::string &s);
void glColor3_256(int r, int g, int b);
float sqr(float x);
bool exists(const std::string &f, bool makeFatal = false, bool skipVFS = false);
void errorLog(const std::string &s);
void debugLog(const std::string &s);
char *readFile(const std::string& path, unsigned long *size_ret = 0);
tinyxml2::XMLDocument *readXML(const std::string& fn, tinyxml2::XMLError *perr = 0, bool keepEmpty = false);
tinyxml2::XMLError readXML(const std::string& fn, tinyxml2::XMLDocument& doc);
char *readCompressedFile(std::string path, unsigned long *size_ret = 0);
void forEachFile(std::string path, std::string type, void callback(const std::string &filename, intptr_t param), intptr_t param);
std::string stripEndlineForUnix(const std::string &in);
std::vector<std::string> getFileList(std::string path, std::string type, int param);
#ifdef HAVE_STRCASECMP
static inline int nocasecmp(const std::string &s1, const std::string &s2)
{ return strcasecmp(s1.c_str(), s2.c_str()); }
@ -183,24 +129,11 @@ static inline int nocasecmp(const char *s1, const char *s2)
#else
int nocasecmp(const std::string &s1, const std::string &s2);
#endif
Vector getNearestPointOnLine(Vector start, Vector end, Vector point);
bool isTouchingLine(Vector lineStart, Vector lineEnd, Vector point, int radius=1, Vector* closest=0);
void sizePowerOf2Texture(int &v);
Vector getDirVector(Direction dir);
Direction getOppositeDir(Direction dir);
Direction getNextDirClockwise(Direction dir);
Vector colorRGB(int r, int g, int b);
GLuint generateEmptyTexture(int res);
void drawCircle(float radius, int steps=1);
bool isVectorInRect(const Vector &vec, const Vector &coord1, const Vector &coord2);
std::string parseCommand(const std::string &line, const std::string &command);
void messageBox(const std::string &title, const std::string& msg);
void exit_error(const std::string &message);

View file

@ -19,12 +19,15 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "BitmapFont.h"
#include "RenderBase.h"
#include "Core.h"
#include "../ExternalLibs/glfont2/glfont2.h"
using namespace glfont;
BmpFont::BmpFont()
: font(new GLFont)
{
scale = 1;
loaded = false;
@ -35,6 +38,7 @@ BmpFont::BmpFont()
BmpFont::~BmpFont()
{
delete font;
destroy();
}
@ -42,7 +46,7 @@ void BmpFont::destroy()
{
if (loaded)
{
font.Destroy();
font->Destroy();
loaded = false;
}
@ -52,14 +56,14 @@ void BmpFont::destroy()
void BmpFont::load(const std::string &file, float scale, bool loadTexture)
{
if (loaded)
font.Destroy();
font->Destroy();
this->scale = scale;
GLuint id=0;
glGenTextures(1, &id);
if (!font.Create(file.c_str(), id, loadTexture))
if (!font->Create(file.c_str(), id, loadTexture))
return;
@ -92,23 +96,6 @@ void BitmapText::autoKern()
{
}
void BitmapText::loadSpacingMap(const std::string &file)
{
spacingMap.clear();
InStream inFile(file.c_str());
std::string line;
while (std::getline(inFile, line))
{
if (!line.empty())
{
char c = line[0];
line = line.substr(2, line.length());
std::istringstream is(line);
is >> spacingMap[c];
}
}
}
int BitmapText::getWidthOnScreen()
{
return text.size()*(fontDrawSize/2);
@ -142,13 +129,13 @@ float BitmapText::getSetWidth()
float BitmapText::getHeight()
{
float sz = bmpFont->font.GetCharHeight('A') * bmpFont->scale;
float sz = bmpFont->font->GetCharHeight('A') * bmpFont->scale;
return lines.size()*sz;
}
float BitmapText::getLineHeight()
{
return bmpFont->font.GetCharHeight('A') * bmpFont->scale;
return bmpFont->font->GetCharHeight('A') * bmpFont->scale;
}
void BitmapText::formatText()
@ -164,7 +151,7 @@ void BitmapText::formatText()
for (int i = 0; i < text.size(); i++)
{
float sz = bmpFont->font.GetCharWidth(text[i])*bmpFont->scale;
float sz = bmpFont->font->GetCharWidth(text[i])*bmpFont->scale;
currentWidth += sz;
if (currentWidth+sz >= textWidth || text[i] == '\n')
@ -301,7 +288,7 @@ void BitmapText::onRender()
bmpFont->font.Begin();
bmpFont->font->Begin();
if (fontTextureTest) fontTextureTest->apply();
@ -310,7 +297,7 @@ void BitmapText::onRender()
float y=0;
float x=0;
float adj = bmpFont->font.GetCharHeight('A') * bmpFont->scale;
float adj = bmpFont->font->GetCharHeight('A') * bmpFont->scale;
if (scrolling)
{
@ -324,13 +311,13 @@ void BitmapText::onRender()
if (align == ALIGN_CENTER)
{
std::pair<int, int> sz;
bmpFont->font.GetStringSize(lines[i], &sz);
bmpFont->font->GetStringSize(lines[i], &sz);
x = -sz.first*0.5f*bmpFont->scale;
}
float la = 1.0f-(scrollDelay/scrollSpeed);
bmpFont->font.DrawString(theLine, bmpFont->scale, x, y, top_color, bottom_color, alpha.x, la);
bmpFont->font->DrawString(theLine, bmpFont->scale, x, y, top_color, bottom_color, alpha.x, la);
y += adj;
}
}
@ -342,10 +329,10 @@ void BitmapText::onRender()
if (align == ALIGN_CENTER)
{
std::pair<int, int> sz;
bmpFont->font.GetStringSize(lines[i], &sz);
bmpFont->font->GetStringSize(lines[i], &sz);
x = -sz.first*0.5f*bmpFont->scale;
}
bmpFont->font.DrawString(lines[i], bmpFont->scale, x, y, top_color, bottom_color, alpha.x, 1);
bmpFont->font->DrawString(lines[i], bmpFont->scale, x, y, top_color, bottom_color, alpha.x, 1);
y += adj;
}
}
@ -410,7 +397,7 @@ float BitmapText::getStringWidth(const std::string& text)
if(text[i] == '\n')
{
std::pair<int, int> dim;
bmpFont->font.GetStringSize(tmp, &dim);
bmpFont->font->GetStringSize(tmp, &dim);
maxsize = std::max(maxsize, dim.first);
tmp.resize(0);
}
@ -418,7 +405,7 @@ float BitmapText::getStringWidth(const std::string& text)
tmp += text[i];
}
std::pair<int, int> dim;
bmpFont->font.GetStringSize(tmp, &dim);
bmpFont->font->GetStringSize(tmp, &dim);
maxsize = std::max(maxsize, dim.first);
return maxsize * bmpFont->scale;

View file

@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "RenderObject.h"
#include "BaseText.h"
#include "../ExternalLibs/glfont2/glfont2.h"
namespace glfont { class GLFont; }
enum BitmapFontEffect
{
@ -41,7 +41,7 @@ struct BmpFont
void load(const std::string &file, float scale=1, bool loadTexture=true);
void destroy();
glfont::GLFont font;
glfont::GLFont * const font;
float scale;
bool loaded;
@ -66,7 +66,6 @@ public:
virtual void setAlign(Align align);
std::string getText();
int getWidthOnScreen();
void loadSpacingMap(const std::string &file);
Vector getColorIndex(int i, int j);
void updateWordColoring();
void autoKern();
@ -92,8 +91,6 @@ protected:
int currentScrollChar;
Align align;
float alignWidth;
typedef std::map<char, float> SpacingMap;
SpacingMap spacingMap;
void formatText();
float fontDrawSize;
void onRender();

View file

@ -22,9 +22,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Texture.h"
#include "AfterEffect.h"
#include "Particles.h"
#include "GLLoad.h"
#include "RenderBase.h"
#include <time.h>
#include <iostream>
#include <fstream>
#ifdef BBGE_BUILD_UNIX
#include <limits.h>
@ -40,7 +43,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#endif
#if BBGE_BUILD_WINDOWS
#include <shlobj.h>
#include <direct.h>
#endif
@ -61,6 +63,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Core *core = 0;
static std::ofstream _logOut;
#ifdef BBGE_BUILD_WINDOWS
HICON icon_windows = 0;
#endif
@ -489,91 +493,6 @@ std::string Core::getUserDataFolder()
return userDataFolder;
}
#if BBGE_BUILD_UNIX
#include <sys/types.h>
#include <pwd.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
// based on code I wrote for PhysicsFS: http://icculus.org/physfs/
// the zlib license on physfs allows this cut-and-pasting.
static int locateOneElement(char *buf)
{
char *ptr;
DIR *dirp;
if (access(buf, F_OK) == 0)
return(1); // quick rejection: exists in current case.
ptr = strrchr(buf, '/'); // find entry at end of path.
if (ptr == NULL)
{
dirp = opendir(".");
ptr = buf;
}
else
{
*ptr = '\0';
dirp = opendir(buf);
*ptr = '/';
ptr++; // point past dirsep to entry itself.
}
struct dirent *dent;
while ((dent = readdir(dirp)) != NULL)
{
if (strcasecmp(dent->d_name, ptr) == 0)
{
strcpy(ptr, dent->d_name); // found a match. Overwrite with this case.
closedir(dirp);
return(1);
}
}
// no match at all...
closedir(dirp);
return(0);
}
#endif
std::string Core::adjustFilenameCase(const char *_buf)
{
#ifdef BBGE_BUILD_UNIX // any case is fine if not Linux.
int rc = 1;
char *buf = (char *) alloca(strlen(_buf) + 1);
strcpy(buf, _buf);
char *ptr = buf;
while ((ptr = strchr(ptr + 1, '/')) != 0)
{
*ptr = '\0'; // block this path section off
rc = locateOneElement(buf);
*ptr = '/'; // restore path separator
if (!rc)
break; // missing element in path.
}
// check final element...
if (rc)
rc = locateOneElement(buf);
#if 0
if (strcmp(_buf, buf) != 0)
{
fprintf(stderr, "Corrected filename case: '%s' => '%s (%s)'\n",
_buf, buf, rc ? "found" : "not found");
}
#endif
return std::string(buf);
#else
return std::string(_buf);
#endif
}
Core::~Core()
{
if (particleManager)
@ -812,52 +731,6 @@ void Core::setSDLGLAttributes()
}
#ifdef GLAPIENTRY
#undef GLAPIENTRY
#endif
#ifdef BBGE_BUILD_WINDOWS
#define GLAPIENTRY APIENTRY
#else
#define GLAPIENTRY
#endif
unsigned int Core::dbg_numRenderCalls = 0;
#ifdef BBGE_BUILD_OPENGL_DYNAMIC
#define GL_FUNC(ret,fn,params,call,rt) \
extern "C" { \
static ret (GLAPIENTRY *p##fn) params = NULL; \
ret GLAPIENTRY fn params { ++Core::dbg_numRenderCalls; rt p##fn call; } \
}
#include "OpenGLStubs.h"
#undef GL_FUNC
static bool lookup_glsym(const char *funcname, void **func)
{
*func = SDL_GL_GetProcAddress(funcname);
if (*func == NULL)
{
std::ostringstream os;
os << "Failed to find OpenGL symbol \"" << funcname << "\"\n";
errorLog(os.str());
return false;
}
return true;
}
static bool lookup_all_glsyms(void)
{
bool retval = true;
#define GL_FUNC(ret,fn,params,call,rt) \
if (!lookup_glsym(#fn, (void **) &p##fn)) retval = false;
#include "OpenGLStubs.h"
#undef GL_FUNC
return retval;
}
#endif
bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, int vsync, int bpp, bool recreate)
{
static bool didOnce = false;
@ -1104,14 +977,8 @@ void Core::shutdownGraphicsLibrary(bool killVideo)
FrameBuffer::resetOpenGL();
gScreen = 0;
#if BBGE_BUILD_OPENGL_DYNAMIC
// reset all the entry points to NULL, so we know exactly what happened
// if we call a GL function after shutdown.
#define GL_FUNC(ret,fn,params,call,rt) \
p##fn = NULL;
#include "OpenGLStubs.h"
#undef GL_FUNC
unload_all_glsyms();
#endif
}
@ -1435,7 +1302,7 @@ void Core::onBackgroundUpdate()
SDL_Delay(200);
}
void Core::main(float runTime)
void Core::run(float runTime)
{
// cannot nest loops when the game is over
if (loopDone) return;
@ -1596,7 +1463,7 @@ void Core::main(float runTime)
updateCullData();
dbg_numRenderCalls = 0;
g_dbg_numRenderCalls = 0;
if (settings.renderOn)
{
@ -3077,8 +2944,11 @@ int Core::zgaSave( const char *filename,
}
#ifdef BBGE_BUILD_VFS
#include "ttvfs_zip/VFSZipArchiveLoader.h"
#include "ttvfs.h"
#include "ttvfs_stdio.h"
#endif
void Core::setupFileAccess()
{
@ -3118,13 +2988,15 @@ void Core::initLocalization()
}
std::string low, up;
std::map<unsigned char, unsigned char> trans;
CharTranslationTable trans;
memset(&trans[0], -1, sizeof(trans));
while(in)
{
in >> low >> up;
trans[low[0]] = up[0];
}
initCharTranslationTables(trans);
initCharTranslationTables(&trans);
}
void Core::onJoystickAdded(int deviceID)

View file

@ -192,7 +192,7 @@ protected:
bool isList; // True if this is a GL display list
union {
RenderObject *robj;
GLuint listID;
unsigned listID;
} u;
};
std::vector<DisplayListElement> displayList;
@ -239,14 +239,11 @@ public:
std::string getPreferencesFolder();
std::string getUserDataFolder();
std::string adjustFilenameCase(const char *buf);
std::string adjustFilenameCase(const std::string &str) { return adjustFilenameCase(str.c_str()); };
void resetCamera();
virtual void shutdown();
void main(float runTime = -1); // can use main
void run(float runTime = -1); // can use main
@ -472,7 +469,6 @@ public:
int zgaSave(const char *filename, short int width, short int height, unsigned char pixelDepth, unsigned char *imageData);
volatile int dbg_numThreadDecoders;
static unsigned int dbg_numRenderCalls;
virtual void onBackgroundUpdate();
@ -545,8 +541,6 @@ protected:
int nestedMains;
std::string baseTextureDirectory;
std::ofstream _logOut;
int nowTicks, thenTicks;
int _vsync, _bpp;

View file

@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "DarkLayer.h"
#include "Core.h"
#include "RenderBase.h"
DarkLayer::DarkLayer()
{

View file

@ -47,10 +47,8 @@ protected:
int quality;
bool active;
int layer, renderLayer;
GLuint texture;
GLuint format;
unsigned texture;
unsigned format;
};
#endif

View file

@ -19,6 +19,8 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "DebugFont.h"
#include "RenderBase.h"
#include "Core.h"
DebugFont::DebugFont(int initSz, const std::string &initText)
{

View file

@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef DEBUGFONT_H
#define DEBUGFONT_H
#include "Core.h"
#include "BaseText.h"
#include "Event.h"
class DebugFont : public BaseText
{

View file

@ -18,10 +18,12 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <assert.h>
#include "Effects.h"
#include "RenderBase.h"
#include "Core.h"
#include <assert.h>
PostProcessingFX::PostProcessingFX()
{

View file

@ -19,6 +19,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "Particles.h"
#include "RenderBase.h"
Emitter::Emitter(ParticleEffect *pe) : Quad(), pe(pe)
{

View file

@ -31,8 +31,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <signal.h>
#endif
#include "SDL.h"
#include "Base.h"
#include "Core.h"
#include "ttvfs_stdio.h"
#include "FmodOpenALBridge.h"
@ -44,10 +47,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "MT.h"
#ifndef _DEBUG
//#define _DEBUG 1
#endif
#undef min
#undef max
@ -1416,7 +1415,7 @@ FMOD_RESULT OpenALSystem::createSound(const char *name_or_data, const FMOD_MODE
strcat(fname, ".ogg");
// just in case...
VFILE *io = vfopen(core->adjustFilenameCase(fname).c_str(), "rb");
VFILE *io = vfopen(adjustFilenameCase(fname).c_str(), "rb");
if (io == NULL)
return FMOD_ERR_INTERNAL;
size_t filesize = 0;

View file

@ -20,6 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "FrameBuffer.h"
#include "Core.h"
#include "RenderBase.h"
#include "glext.h"
//WARNING: FrameBuffer objects have to have reloadDevice/unloadDevice called manually!
@ -76,7 +78,7 @@ float FrameBuffer::getHeightP()
return py;
}
bool FrameBuffer::init(int width, int height, bool fitToScreen, GLint filter)
bool FrameBuffer::init(int width, int height, bool fitToScreen)
{
// !!! FIXME: check for common GMA GL_RENDERER strings on Linux, too.
#ifdef BBGE_BUILD_MACOSX
@ -201,8 +203,8 @@ bool FrameBuffer::init(int width, int height, bool fitToScreen, GLint filter)
glBindTexture( GL_TEXTURE_2D, g_dynamicTextureID );
// GL_LINEAR
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB,
width, height,

View file

@ -29,7 +29,7 @@ class FrameBuffer
public:
FrameBuffer();
~FrameBuffer();
bool init(int width, int height, bool fitToScreen=false, GLint filter=GL_LINEAR);
bool init(int width, int height, bool fitToScreen=false);
bool isInited() { return inited; }
bool isEnabled() { return enabled; }
void setEnabled(bool e);
@ -49,9 +49,9 @@ public:
protected:
int _w, _h;
bool _fitToScreen;
GLuint g_frameBuffer;
GLuint g_depthRenderBuffer;
GLuint g_dynamicTextureID;
unsigned g_frameBuffer;
unsigned g_depthRenderBuffer;
unsigned g_dynamicTextureID;
int w,h;
bool enabled, inited;
};

69
BBGE/GLLoad.cpp Normal file
View file

@ -0,0 +1,69 @@
#include "Base.h"
#if BBGE_BUILD_OPENGL_DYNAMIC
#include "RenderBase.h"
#include "GLLoad.h"
#include <sstream>
#ifdef GLAPIENTRY
#undef GLAPIENTRY
#endif
#ifdef BBGE_BUILD_WINDOWS
#define GLAPIENTRY __stdcall
#else
#define GLAPIENTRY
#endif
unsigned g_dbg_numRenderCalls = 0; // extern
#ifdef BBGE_BUILD_OPENGL_DYNAMIC
#define GL_FUNC(ret,fn,params,call,rt) \
extern "C" { \
static ret (GLAPIENTRY *p##fn) params = NULL; \
ret GLAPIENTRY fn params { ++g_dbg_numRenderCalls; rt p##fn call; } \
}
#include "OpenGLStubs.h"
#undef GL_FUNC
static bool lookup_glsym(const char *funcname, void **func)
{
*func = SDL_GL_GetProcAddress(funcname);
if (*func == NULL)
{
std::ostringstream os;
os << "Failed to find OpenGL symbol \"" << funcname << "\"\n";
errorLog(os.str());
return false;
}
return true;
}
bool lookup_all_glsyms()
{
bool retval = true;
#define GL_FUNC(ret,fn,params,call,rt) \
if (!lookup_glsym(#fn, (void **) &p##fn)) retval = false;
#include "OpenGLStubs.h"
#undef GL_FUNC
return retval;
}
#endif
void unload_all_glsyms()
{
#if BBGE_BUILD_OPENGL_DYNAMIC
// reset all the entry points to NULL, so we know exactly what happened
// if we call a GL function after shutdown.
#define GL_FUNC(ret,fn,params,call,rt) \
p##fn = NULL;
#include "OpenGLStubs.h"
#undef GL_FUNC
#endif
}
#endif

9
BBGE/GLLoad.h Normal file
View file

@ -0,0 +1,9 @@
#ifndef BBGE_GLLOAD_H
#define BBGE_GLLOAD_H
bool lookup_all_glsyms();
void unload_all_glsyms();
extern unsigned g_dbg_numRenderCalls;
#endif

View file

@ -1,6 +1,8 @@
#ifndef BBGE_GAME_KEYS_H
#define BBGE_GAME_KEYS_H
#include "BBGECompileConfig.h"
#ifdef BBGE_BUILD_SDL2
#include <SDL_scancode.h>

View file

@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "Gradient.h"
#include "Core.h"
#include "RenderBase.h"
Gradient::Gradient() : RenderObject()
{

View file

@ -1,24 +1,5 @@
#include "Localization.h"
#ifdef BBGE_BUILD_UNIX
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
#ifdef BBGE_BUILD_MACOSX
#include <CoreFoundation/CFLocale.h>
#include <CoreFoundation/CFString.h>
// veeery clunky.
static std::string _CFToStdString(CFStringRef cs)
{
char buf[1024];
CFStringGetCString(cs, &buf[0], 1024, kCFStringEncodingUTF8);
return &buf[0];
}
#endif
static std::string s_locale;
static std::string s_modpath;
@ -84,57 +65,4 @@ std::string localisePath(const std::string &path, const std::string& modpath /*
return path;
}
std::string getSystemLocale()
{
std::string localeStr;
#ifdef BBGE_BUILD_WINDOWS
LCID lcid = GetThreadLocale();
char buf[100];
char ctry[100];
if (GetLocaleInfo(lcid, LOCALE_SISO639LANGNAME, buf, sizeof buf) != 0)
{
localeStr = buf;
if (GetLocaleInfo(lcid, LOCALE_SISO3166CTRYNAME, ctry, sizeof ctry) != 0)
{
localeStr += "_";
localeStr += ctry;
}
}
#elif BBGE_BUILD_MACOSX
CFLocaleRef locale = CFLocaleCopyCurrent();
CFStringRef buf;
if ((buf = (CFStringRef)CFLocaleGetValue(locale, kCFLocaleLanguageCode)) != NULL)
{
localeStr = _CFToStdString(buf);
if ((buf = (CFStringRef)CFLocaleGetValue(locale, kCFLocaleCountryCode)) != NULL)
{
localeStr += "_";
localeStr += _CFToStdString(buf);
}
}
CFRelease(locale);
#else
const char *lang = (const char *)getenv("LANG");
if (lang && *lang)
{
localeStr = lang;
size_t found = localeStr.find('.');
if (found != std::string::npos)
localeStr.resize(found);
}
#endif
return localeStr;
}

View file

@ -1,5 +1,5 @@
#include "MT.h"
#include "Base.h"
#include "SDL.h"
// --------- Lockable ----------

View file

@ -1,23 +0,0 @@
/*
Copyright (C) 2007, 2010 - Bit-Blot
This file is part of Aquaria.
Aquaria is free software; you can redistribute it 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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "MathFunctions.h"

View file

@ -123,7 +123,8 @@ void SmallBlockAllocator::_FreeBlock(Block *blk)
free(blk);
// keeps the vector sorted
_allblocks.erase(std::remove(_allblocks.begin(), _allblocks.end(), blk), _allblocks.end());
std::vector<Block*>::iterator where = std::remove(_allblocks.begin(), _allblocks.end(), blk);
_allblocks.erase(where, _allblocks.end());
}

430
BBGE/OSFunctions.cpp Normal file
View file

@ -0,0 +1,430 @@
#include "OSFunctions.h"
#include "Base.h"
#include <sstream>
#include "ttvfs_stdio.h"
#ifdef BBGE_BUILD_WINDOWS
# define WIN32_LEAN_AND_MEAN
# define WIN32_NOMINMAX
# include <windows.h>
# undef min
# undef max
#include <shellapi.h>
#elif BBGE_BUILD_LINUX
# include <sys/types.h>
# include <stdint.h>
#endif
#ifdef _MSC_VER
# include <intrin.h>
#endif
#if defined(BBGE_BUILD_UNIX)
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#include <errno.h>
#include <pwd.h>
#include <fcntl.h>
#include <unistd.h>
#endif
#if defined(BBGE_BUILD_MACOSX)
#include <Carbon/Carbon.h>
#include <CoreFoundation/CFLocale.h>
#include <CoreFoundation/CFString.h>
// veeery clunky.
static std::string _CFToStdString(CFStringRef cs)
{
char buf[1024];
CFStringGetCString(cs, &buf[0], 1024, kCFStringEncodingUTF8);
return &buf[0];
}
#endif
#ifdef BBGE_BUILD_VFS
#include "ttvfs.h"
#endif
#include "SDL.h"
void openURL(const std::string &url)
{
#ifdef BBGE_BUILD_WINDOWS
ShellExecute(NULL, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
#endif
#if defined(BBGE_BUILD_MACOSX)
CFStringRef str = CFStringCreateWithCString (0, url.c_str(), 0);
CFURLRef ref = CFURLCreateWithString(kCFAllocatorDefault, str, NULL);
LSOpenCFURLRef(ref, 0);
CFRelease(ref);
CFRelease(str);
#elif BBGE_BUILD_UNIX
std::string cmd("PATH=$PATH:. xdg-open '");
cmd += url;
cmd += "'";
if (system(cmd.c_str()) != 0)
debugLog("system(xdg_open '" + url + "') failed");
#endif
}
void triggerBreakpoint()
{
#ifdef _MSC_VER
__debugbreak();
#elif defined(__GNUC__) && ((__i386__) || (__x86_64__))
__asm__ __volatile__ ( "int $3\n\t" );
#else
raise(SIGTRAP);
#endif
}
bool createDir(const std::string& d)
{
bool success = false;
int err = 0;
#if defined(BBGE_BUILD_UNIX)
if (!mkdir(d.c_str(), S_IRWXU))
success = true;
else
{
err = errno;
if (err == EEXIST)
success = true;
}
#elif defined(BBGE_BUILD_WINDOWS)
if (CreateDirectoryA(d.c_str(), NULL))
success = true;
else
{
err = GetLastError();
if(err == ERROR_ALREADY_EXISTS)
success = true;
}
#endif
if (!success)
{
std::ostringstream os;
os << "Failed to create directory: [" << d << "], error code: " << err;
debugLog(os.str());
}
return success;
}
#if defined(BBGE_BUILD_MACOSX) && !SDL_VERSION_ATLEAST(2,0,0)
void cocoaMessageBox(const std::string &title, const std::string &msg);
#endif
void messageBox(const std::string& title, const std::string &msg)
{
#ifdef BBGE_BUILD_WINDOWS
MessageBox (0,msg.c_str(),title.c_str(),MB_OK);
#elif SDL_VERSION_ATLEAST(2,0,0)
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, title.c_str(),
msg.c_str(), NULL);
#elif defined(BBGE_BUILD_MACOSX)
cocoaMessageBox(title, msg);
#elif defined(BBGE_BUILD_UNIX)
// !!! FIXME: probably don't want the whole GTK+ dependency in here...
fprintf(stderr, "%s: %s\n", title.c_str(), msg.c_str());
#else
#error Please define your platform.
#endif
}
#ifdef BBGE_BUILD_VFS
struct vfscallback_s
{
const std::string *path;
const char *ext;
intptr_t param;
void (*callback)(const std::string &filename, intptr_t param);
};
void forEachFile_vfscallback(VFILE *vf, void *user)
{
vfscallback_s *d = (vfscallback_s*)user;
if(d->ext)
{
const char *e = strrchr(vf->name(), '.');
if(e && nocasecmp(d->ext, e))
return;
}
d->callback(*(d->path) + vf->name(), d->param);
}
#endif
void forEachFile(const std::string& inpath, std::string type, void callback(const std::string &filename, intptr_t param), intptr_t param)
{
if (inpath.empty()) return;
#ifdef BBGE_BUILD_VFS
ttvfs::DirView view;
if(!vfs.FillDirView(inpath.c_str(), view))
{
debugLog("Path '" + inpath + "' does not exist");
return;
}
vfscallback_s dat;
dat.path = &inpath;
dat.ext = type.length() ? type.c_str() : NULL;
dat.param = param;
dat.callback = callback;
view.forEachFile(forEachFile_vfscallback, &dat, true);
return;
// -------------------------------------
#endif
stringToLower(type);
std::string path = adjustFilenameCase(inpath.c_str());
debugLog("forEachFile - path: " + path + " type: " + type);
#if defined(BBGE_BUILD_UNIX)
DIR *dir=0;
dir = opendir(path.c_str());
if (dir)
{
dirent *file=0;
while ( (file=readdir(dir)) != NULL )
{
if (file->d_name && strlen(file->d_name) > 4)
{
debugLog(file->d_name);
char *extension=strrchr(file->d_name,'.');
if (extension)
{
debugLog(extension);
if (extension!=NULL)
{
if (strcasecmp(extension,type.c_str())==0)
{
callback(path + std::string(file->d_name), param);
}
}
}
}
}
closedir(dir);
}
else
{
debugLog("FAILED TO OPEN DIR");
}
#endif
#ifdef BBGE_BUILD_WINDOWS
BOOL fFinished;
HANDLE hList;
TCHAR szDir[MAX_PATH+1];
WIN32_FIND_DATA FileData;
int end = path.size()-1;
if (path[end] != '/')
path[end] += '/';
// Get the proper directory path
// \\ %s\\*
if (type.find('.')==std::string::npos)
{
type = "." + type;
}
sprintf(szDir, "%s\\*", path.c_str());
stringToUpper(type);
// Get the first file
hList = FindFirstFile(szDir, &FileData);
if (hList == INVALID_HANDLE_VALUE)
{
debugLog("No files of type " + type + " found in path " + path);
}
else
{
// Traverse through the directory structure
fFinished = FALSE;
while (!fFinished)
{
// Check the object is a directory or not
//printf("%*s%s\n", indent, "", FileData.cFileName);
std::string filename = FileData.cFileName;
if (filename.size()>4)
{
std::string filetype = filename.substr(filename.size()-4, filename.size());
stringToUpper(filetype);
if (filetype==type)
{
callback(path+filename, param);
}
}
if (!FindNextFile(hList, &FileData))
{
fFinished = TRUE;
}
}
}
FindClose(hList);
#endif
}
#if BBGE_BUILD_UNIX
// based on code I wrote for PhysicsFS: http://icculus.org/physfs/
// the zlib license on physfs allows this cut-and-pasting.
static int locateOneElement(char *buf)
{
char *ptr;
DIR *dirp;
if (access(buf, F_OK) == 0)
return(1); // quick rejection: exists in current case.
ptr = strrchr(buf, '/'); // find entry at end of path.
if (ptr == NULL)
{
dirp = opendir(".");
ptr = buf;
}
else
{
*ptr = '\0';
dirp = opendir(buf);
*ptr = '/';
ptr++; // point past dirsep to entry itself.
}
struct dirent *dent;
while ((dent = readdir(dirp)) != NULL)
{
if (strcasecmp(dent->d_name, ptr) == 0)
{
strcpy(ptr, dent->d_name); // found a match. Overwrite with this case.
closedir(dirp);
return(1);
}
}
// no match at all...
closedir(dirp);
return(0);
}
#endif
std::string adjustFilenameCase(const std::string& s)
{
return adjustFilenameCase(s.c_str());
}
std::string adjustFilenameCase(const char *_buf)
{
#ifdef BBGE_BUILD_UNIX // any case is fine if not Linux.
int rc = 1;
char *buf = (char *) alloca(strlen(_buf) + 1);
strcpy(buf, _buf);
char *ptr = buf;
while ((ptr = strchr(ptr + 1, '/')) != 0)
{
*ptr = '\0'; // block this path section off
rc = locateOneElement(buf);
*ptr = '/'; // restore path separator
if (!rc)
break; // missing element in path.
}
// check final element...
if (rc)
rc = locateOneElement(buf);
#if 0
if (strcmp(_buf, buf) != 0)
{
fprintf(stderr, "Corrected filename case: '%s' => '%s (%s)'\n",
_buf, buf, rc ? "found" : "not found");
}
#endif
return std::string(buf);
#else
return std::string(_buf);
#endif
}
std::string getSystemLocale()
{
std::string localeStr;
#ifdef BBGE_BUILD_WINDOWS
LCID lcid = GetThreadLocale();
char buf[100];
char ctry[100];
if (GetLocaleInfo(lcid, LOCALE_SISO639LANGNAME, buf, sizeof buf) != 0)
{
localeStr = buf;
if (GetLocaleInfo(lcid, LOCALE_SISO3166CTRYNAME, ctry, sizeof ctry) != 0)
{
localeStr += "_";
localeStr += ctry;
}
}
#elif BBGE_BUILD_MACOSX
CFLocaleRef locale = CFLocaleCopyCurrent();
CFStringRef buf;
if ((buf = (CFStringRef)CFLocaleGetValue(locale, kCFLocaleLanguageCode)) != NULL)
{
localeStr = _CFToStdString(buf);
if ((buf = (CFStringRef)CFLocaleGetValue(locale, kCFLocaleCountryCode)) != NULL)
{
localeStr += "_";
localeStr += _CFToStdString(buf);
}
}
CFRelease(locale);
#else
const char *lang = (const char *)getenv("LANG");
if (lang && *lang)
{
localeStr = lang;
size_t found = localeStr.find('.');
if (found != std::string::npos)
localeStr.resize(found);
}
#endif
return localeStr;
}

15
BBGE/OSFunctions.h Normal file
View file

@ -0,0 +1,15 @@
#ifndef BBGE_OSFUNCTIONS_H
#define BBGE_OSFUNCTIONS_H
#include <string>
void messageBox(const std::string &title, const std::string& msg);
void forEachFile(const std::string& inpath, std::string type, void callback(const std::string &filename, intptr_t param), intptr_t param);
std::string adjustFilenameCase(const char *_buf);
std::string adjustFilenameCase(const std::string&);
bool createDir(const std::string& d);
void triggerBreakpoint();
void openURL(const std::string &url);
std::string getSystemLocale();
#endif

View file

@ -19,11 +19,6 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// !!! FIXME: whoa, we should fix this warning, not mask it!
//#ifdef _MSC_VER
//#pragma warning( disable : 4003 ) // "not enough actual parameters for macro 'GL_FUNC'"
//#endif
GL_FUNC(void,glBindTexture,(GLenum target,GLuint name),(target,name),)
GL_FUNC(void,glBitmap,(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap),(width,height,xorig,yorig,xmove,ymove,bitmap),)
GL_FUNC(void,glBlendFunc,(GLenum f,GLenum x),(f,x),)
@ -31,15 +26,14 @@ GL_FUNC(void,glClear,(GLbitfield a),(a),)
GL_FUNC(void,glClearColor,(GLclampf r,GLclampf g,GLclampf b,GLclampf a),(r,g,b,a),)
GL_FUNC(void,glColor4f,(GLfloat r,GLfloat g,GLfloat b,GLfloat a),(r,g,b,a),)
GL_FUNC(void,glColor4ub,(GLubyte r,GLubyte g,GLubyte b,GLubyte a),(r,g,b,a),)
GL_FUNC(void,glColorPointer,(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer),(size,type,stride,pointer),)
GL_FUNC(void,glCopyPixels,(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type),(x,y,width,height,type),)
GL_FUNC(void,glCopyTexImage2D,(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border),(target, level, internalFormat, x, y, width, height, border),)
GL_FUNC(void,glCopyTexSubImage2D,(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height),(target, level, xoffset, yoffset, x, y, width, height),)
GL_FUNC(void,glDeleteTextures,(GLsizei n, const GLuint *textures),(n,textures),)
GL_FUNC(void,glDisable,(GLenum cap),(cap),)
GL_FUNC(void,glDisableClientState,(GLenum array),(array),)
GL_FUNC(void,glDrawArrays,(GLenum mode, GLint first, GLsizei count),(mode,first,count),)
GL_FUNC(void,glDrawElements,(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices),(mode,count,type,indices),)
//GL_FUNC(void,glDrawArrays,(GLenum mode, GLint first, GLsizei count),(mode,first,count),)
//GL_FUNC(void,glDrawElements,(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices),(mode,count,type,indices),)
GL_FUNC(void,glEnable,(GLenum cap),(cap),)
GL_FUNC(void,glEnableClientState,(GLenum array),(array),)
GL_FUNC(void,glFinish,(void),(),)
@ -47,9 +41,7 @@ GL_FUNC(void,glFlush,(void),(),)
GL_FUNC(void,glGenTextures,(GLsizei n, GLuint *textures),(n,textures),)
GL_FUNC(GLenum,glGetError,(void),(),return)
GL_FUNC(void,glGetFloatv,(GLenum pname, GLfloat *params),(pname,params),)
GL_FUNC(void,glGetTexParameterfv,(GLenum target, GLenum pname, GLfloat *params),(target,pname,params),)
GL_FUNC(void,glHint,(GLenum target, GLenum mode),(target,mode),)
GL_FUNC(void,glLightfv,(GLenum light, GLenum pname, const GLfloat *params),(light,pname,params),)
GL_FUNC(void,glLineWidth,(GLfloat width),(width),)
GL_FUNC(void,glLoadIdentity,(void),(),)
GL_FUNC(void,glMatrixMode,(GLenum mode),(mode),)
@ -64,7 +56,6 @@ GL_FUNC(void,glReadPixels,(GLint x, GLint y, GLsizei width, GLsizei height, GLen
GL_FUNC(void,glRotatef,(GLfloat angle, GLfloat x, GLfloat y, GLfloat z),(angle,x,y,z),)
GL_FUNC(void,glScalef,(GLfloat x, GLfloat y, GLfloat z),(x,y,z),)
GL_FUNC(void,glTexCoordPointer,(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer),(size,type,stride,pointer),)
GL_FUNC(void,glGetTexLevelParameterfv,(GLenum target, GLint level, GLenum pname, GLfloat *params),(target,level,pname,params),)
GL_FUNC(void,glTexParameterf,(GLenum target, GLenum pname, GLfloat param),(target,pname,param),)
GL_FUNC(void,glTexParameteri,(GLenum target, GLenum pname, GLint param),(target,pname,param),)
GL_FUNC(void,glTexSubImage2D,(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels),(target,level,xoffset,yoffset,width,height,format,type,pixels),)

View file

@ -86,7 +86,7 @@ void ParticleEffect::bankLoad(const std::string &file, const std::string &path)
clearEmitters();
usef = core->adjustFilenameCase(usef);
usef = adjustFilenameCase(usef);
debugLog(usef);
char *buffer = readFile(usef);
if (!buffer)

View file

@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Precacher.h"
#include "Quad.h"
#include "Core.h"
#include "ttvfs_stdio.h"
Precacher::Precacher()
{

View file

@ -21,7 +21,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef PRECACHER_H
#define PRECACHER_H
#include "Quad.h"
#include <vector>
#include <string>
class RenderObject;
class Precacher
{

View file

@ -1,64 +0,0 @@
/*
Copyright (C) 2007, 2010 - Bit-Blot
This file is part of Aquaria.
Aquaria is free software; you can redistribute it 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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "ProfRender.h"
void prof_print(float x, float y, char *str)
{
core->print(x, y-1.5f*4, str, 6);
//Prof_set_report_mode(Prof_HIERARCHICAL_TIME);
/*
Prof_SELF_TIME: flat times sorted by self time
Prof_HIERARCHICAL_TIME: flat times sorted by hierarchical time
Prof_CALL_GRAPH: call graph parent/children information
*/
}
float prof_width(char *str)
{
int c = 0;
float x = 0;
while (str[c] != '\0')
{
c++;
x += 1.2f;
}
x *= 6;
return x;
}
ProfRender::ProfRender() : RenderObject()
{
followCamera = 1;
cull = false;
alpha = 0.5;
}
void ProfRender::onRender()
{
#ifdef BBGE_BUILD_WINDOWS
#endif
}

View file

@ -1,31 +0,0 @@
/*
Copyright (C) 2007, 2010 - Bit-Blot
This file is part of Aquaria.
Aquaria is free software; you can redistribute it 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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "Core.h"
class ProfRender : public RenderObject
{
public:
ProfRender();
protected:
void onRender();
};

View file

@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "Quad.h"
#include "Core.h"
#include "RenderBase.h"
#include <assert.h>
Vector Quad::renderBorderColor = Vector(1,1,1);

View file

@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "QuadTrail.h"
#include <assert.h>
#include "RenderBase.h"
QuadTrail::QuadTrail(int maxPoints, float pointDist)
: RenderObject(), maxPoints(maxPoints), pointDist(pointDist), numPoints(0)

25
BBGE/ReadXML.cpp Normal file
View file

@ -0,0 +1,25 @@
#include "ReadXML.h"
#include "Base.h"
tinyxml2::XMLError readXML(const std::string& fn, tinyxml2::XMLDocument& doc)
{
unsigned long sz = 0;
char *buf = readFile(fn, &sz);
tinyxml2::XMLError err = doc.Parse(buf, sz);
delete [] buf;
return err;
}
tinyxml2::XMLDocument *readXML(const std::string& fn, tinyxml2::XMLError *perr /* = 0 */, bool keepEmpty /* = false */)
{
tinyxml2::XMLDocument *doc = new tinyxml2::XMLDocument();
tinyxml2::XMLError err = readXML(fn, *doc);
if(perr)
*perr = err;
if(err != tinyxml2::XML_SUCCESS && !keepEmpty)
{
delete doc;
doc = NULL;
}
return doc;
}

10
BBGE/ReadXML.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef BBGE_READ_XML_H
#define BBGE_READ_XML_H
#include "tinyxml2.h"
#include <string>
tinyxml2::XMLDocument *readXML(const std::string& fn, tinyxml2::XMLError *perr = 0, bool keepEmpty = false);
tinyxml2::XMLError readXML(const std::string& fn, tinyxml2::XMLDocument& doc);
#endif

51
BBGE/RenderBase.cpp Normal file
View file

@ -0,0 +1,51 @@
#include "RenderBase.h"
#include "Base.h"
void drawCircle(float radius, int stepSize)
{
glBegin(GL_POLYGON);
for(int i=0;i < 360; i+=stepSize)
{
const float degInRad = i*(PI/180.0f);
glVertex3f(cosf(degInRad)*radius, sinf(degInRad)*radius,0.0);
}
glEnd();
}
void sizePowerOf2Texture(int &v)
{
int p = 8, use=0;
do
{
use = 1 << p;
p++;
}
while(v > use);
v = use;
}
unsigned generateEmptyTexture(int quality) // Create An Empty Texture
{
GLuint txtnumber=0; // Texture ID
unsigned char *data; // Stored Data
// Create Storage Space For Texture Data (128x128x4)
int size = (quality * quality) * 4;
data = new unsigned char[size];
memset(data, 0, size); // Clear Storage Memory
glGenTextures(1, &txtnumber); // Create 1 Texture
glBindTexture(GL_TEXTURE_2D, txtnumber); // Bind The Texture
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, quality, quality, 0,
GL_RGBA, GL_UNSIGNED_BYTE, data); // Build Texture Using Information In data
delete [] data; // Release data
return txtnumber; // Return The Texture ID
}

22
BBGE/RenderBase.h Normal file
View file

@ -0,0 +1,22 @@
#ifndef BBGE_RENDERBASE_H
#define BBGE_RENDERBASE_H
#include "SDL.h"
#define GL_GLEXT_LEGACY 1
#include "gl.h"
#ifdef _WINDOWS_
#error windows.h was included! euuugh!
#endif
#ifdef APIENTRY
#undef APIENTRY
#endif
#ifdef WINGDIAPI
#undef WINGDIAPI
#endif
#endif

View file

@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "RenderObject.h"
#include "Core.h"
#include "MathFunctions.h"
#include "RenderBase.h"
#include <assert.h>
#include <algorithm>

View file

@ -24,9 +24,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Base.h"
#include "Texture.h"
#include "ScriptObject.h"
#include <list>
class Core;
class StateData;
class Texture;
enum RenderObjectFlags
{

View file

@ -19,6 +19,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "Core.h"
#include "RenderBase.h"
#define BASE_ARRAY_SIZE 100 // Size of an object array in a new layer

View file

@ -19,7 +19,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "Quad.h"
#include "RenderBase.h"
OutlineRect::OutlineRect() : RenderObject()
{

View file

@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "RoundedRect.h"
#include "Core.h"
#include "TTFFont.h"
#include "RenderBase.h"
#include <assert.h>

View file

@ -18,8 +18,10 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "ScreenTransition.h"
#include "Core.h"
#include "RenderBase.h"
ScreenTransition::ScreenTransition() : RenderObject()
{

View file

@ -42,7 +42,7 @@ protected:
float width, height;
GLuint screen_texture;
unsigned screen_texture;
};
#endif

View file

@ -21,6 +21,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Shader.h"
#include "algorithmx.h"
#include "RenderBase.h"
#include "glext.h"
#include <sstream>
#ifdef BBGE_BUILD_SHADERS
// GL_ARB_shader_objects

View file

@ -45,7 +45,7 @@ public:
protected:
std::string vertFile, fragFile;
std::string vertSrc, fragSrc;
GLuint g_programObj;
unsigned g_programObj;
int numUniforms;
private:

View file

@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Particles.h"
#include "MathFunctions.h"
#include "SimpleIStringStream.h"
#include "ReadXML.h"
#include "tinyxml2.h"
using namespace tinyxml2;
@ -82,6 +83,10 @@ Bone::Bone() : Quad()
originalRenderPass = 0;
}
ParticleEffect *Bone::getEmitter(unsigned slot) const
{
return slot < emitters.size() ? emitters[slot] : NULL;
}
void Bone::destroy()
{
@ -345,7 +350,7 @@ void BoneCommand::run()
break;
case AC_PRT_LOAD:
{
ParticleEffect *e = b->emitters[slot];
ParticleEffect *e = b->getEmitter(slot);
if (e)
{
e->load(file);
@ -354,14 +359,14 @@ void BoneCommand::run()
break;
case AC_PRT_START:
{
ParticleEffect *e = b->emitters[slot];
ParticleEffect *e = b->getEmitter(slot);
if (e)
e->start();
}
break;
case AC_PRT_STOP:
{
ParticleEffect *e = b->emitters[slot];
ParticleEffect *e = b->getEmitter(slot);
if (e)
e->stop();
}
@ -1131,7 +1136,7 @@ void SkeletalSprite::loadSkin(const std::string &fn)
file = animationPath + skinPath + fn + ".xml";
}
file = core->adjustFilenameCase(file);
file = adjustFilenameCase(file);
if (!exists(file))
{
@ -1254,7 +1259,7 @@ void SkeletalSprite::loadSkeletal(const std::string &fn)
return;
}
file = core->adjustFilenameCase(file);
file = adjustFilenameCase(file);
XMLDocument *xml = _retrieveSkeletalXML(file, false);
if(!xml)
@ -1308,17 +1313,20 @@ void SkeletalSprite::loadSkeletal(const std::string &fn)
newb->prt = bone->Attribute("prt");
SimpleIStringStream is(newb->prt);
int slot;
std::string pfile;
while (is >> slot)
{
std::string pfile;
is >> pfile;
// add particle system + load
newb->emitters[slot] = new ParticleEffect;
ParticleEffect *e = newb->emitters[slot];
newb->addChild(e, PM_POINTER);
e->load(pfile);
// hack for now:
//e->start();
if(slot > 0)
{
is >> pfile;
// add particle system + load
ParticleEffect *e = new ParticleEffect;
if(newb->emitters.size() < (size_t)slot)
newb->emitters.resize(slot+4);
newb->emitters[slot] = e;
newb->addChild(e, PM_POINTER);
e->load(pfile);
}
}
}
XMLElement *fr=0;

View file

@ -43,6 +43,7 @@ class SkeletalSprite;
class Bone : public Quad
{
friend class SkeletalSprite;
public:
Bone();
void setAnimated(int a);
@ -60,7 +61,7 @@ public:
std::string gfx;
std::string name;
int boneIdx, pidx, rbp;
std::map<int, ParticleEffect*> emitters;
std::string prt;
std::vector<Vector> changeStrip;
@ -69,6 +70,7 @@ public:
Vector originalScale;
void addSegment(Bone *b);
ParticleEffect *getEmitter(unsigned slot) const;
int segmentChain;
@ -86,6 +88,7 @@ public:
int originalRenderPass; // stores the render pass originally set in the XML file. For AC_RESET_PASS.
protected:
std::vector<ParticleEffect*> emitters;
int minDist, maxDist, reverse;
std::vector<Bone*> segments;
};

View file

@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Core.h"
#include "SoundManager.h"
#include "Base.h"
#include "ttvfs_stdio.h"
#ifdef BBGE_BUILD_FMOD_OPENAL_BRIDGE
#include "FmodOpenALBridge.h"
@ -510,35 +511,22 @@ void SoundManager::stopAll()
void SoundManager::onVoiceEnded()
{
event_stopVoice.call();
if (dspReverb)
dspReverb->remove();
if (!voxQueue.empty())
{
std::string vox = voxQueue.front();
if (!voxQueue.empty())
voxQueue.pop();
voxQueue.pop_front();
playVoice(vox, SVT_INTERRUPT);
}
else
{
setMusicFader(1, 1);
sfxFader = 1;
}
}
@ -821,7 +809,7 @@ bool SoundManager::playVoice(const std::string &name, SoundVoiceType svt, float
{
fn = voicePath2 + name + fileType;
fn = localisePathInternalModpath(fn);
fn = core->adjustFilenameCase(fn);
fn = adjustFilenameCase(fn);
if (exists(fn)) checkOther = false;
}
@ -829,7 +817,7 @@ bool SoundManager::playVoice(const std::string &name, SoundVoiceType svt, float
{
fn = voicePath + name + fileType;
fn = localisePath(fn);
fn = core->adjustFilenameCase(fn);
fn = adjustFilenameCase(fn);
if (!exists(fn))
{
debugLog("Could not find voice file [" + fn + "]");
@ -847,7 +835,7 @@ bool SoundManager::playVoice(const std::string &name, SoundVoiceType svt, float
if (isPlayingVoice())
{
if (voxQueue.empty() || voxQueue.front() != n)
voxQueue.push(n);
voxQueue.push_back(n);
}
else
{
@ -1142,7 +1130,7 @@ bool SoundManager::playMusic(const std::string &name, SoundLoopType slt, SoundFa
}
}
fn = core->adjustFilenameCase(fn);
fn = adjustFilenameCase(fn);
lastMusic = name;
stringToLower(lastMusic);
@ -1322,7 +1310,7 @@ void SoundManager::stopVoice()
void SoundManager::stopAllVoice()
{
while (!voxQueue.empty()) voxQueue.pop();
voxQueue.clear();
stopVoice();
}
@ -1370,19 +1358,19 @@ Buffer SoundManager::loadSoundIntoBank(const std::string &filename, const std::s
{
f = audioPath2 + filename + format;
f = localisePathInternalModpath(f);
f = core->adjustFilenameCase(f);
f = adjustFilenameCase(f);
if (!exists(f))
{
f = path + filename + format;
f = localisePath(f);
f = core->adjustFilenameCase(f);
f = adjustFilenameCase(f);
}
}
else
{
f = path + filename + format;
f = localisePath(f);
f = core->adjustFilenameCase(f);
f = adjustFilenameCase(f);
}
int loc = f.find_last_of('/');
@ -1589,7 +1577,7 @@ SoundHolder::~SoundHolder()
void SoundHolder::updateSoundPosition(float x, float y)
{
if (activeSounds.size())
for(std::set<void*>::iterator it = activeSounds.begin(); it != activeSounds.end(); ++it)
for(std::vector<void*>::iterator it = activeSounds.begin(); it != activeSounds.end(); ++it)
sound->setSoundPos(*it, x, y);
}
@ -1605,7 +1593,8 @@ void SoundHolder::unlinkSound(void *channel)
FMOD::Channel *pChannel = (FMOD::Channel*)channel;
pChannel->setUserData(NULL);
pChannel->setCallback(NULL);
activeSounds.erase(channel);
std::vector<void*>::iterator where = std::remove(activeSounds.begin(), activeSounds.end(), channel);
activeSounds.erase(where, activeSounds.end());
}
void SoundHolder::linkSound(void *channel)
@ -1615,7 +1604,7 @@ void SoundHolder::linkSound(void *channel)
FMOD::Channel *pChannel = (FMOD::Channel*)channel;
pChannel->setUserData(this);
pChannel->setCallback(s_soundHolderCallback);
activeSounds.insert(channel);
activeSounds.push_back(channel);
}
void SoundHolder::unlinkAllSounds()

View file

@ -24,9 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <stdlib.h>
#include <string>
#include <list>
#include <queue>
#include <set>
#include "Vector.h"
#include "Event.h"
#define BBGE_AUDIO_NOCHANNEL NULL
@ -199,7 +198,7 @@ public:
std::string lastVoice, lastMusic;
typedef std::list<std::string> LocalSounds;
typedef std::vector<std::string> LocalSounds;
LocalSounds localSounds;
void setOverrideVoiceFader(float v);
@ -219,7 +218,7 @@ private:
float sfxVol;
float voiceFader, sfxFader;
std::queue<std::string> voxQueue;
std::list<std::string> voxQueue;
void (*loadProgressCallback)();
};
@ -238,7 +237,7 @@ protected:
virtual ~SoundHolder();
private:
std::set<void*> activeSounds;
std::vector<void*> activeSounds;
};

View file

@ -22,10 +22,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define __state_data__
#include "Base.h"
#include "RenderObject.h"
#include "ActionMapper.h"
#include "Event.h"
class StateManager;
class RenderObject;
class StateObject;

View file

@ -18,8 +18,22 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "TTFFont.h"
#ifdef AQUARIA_INTERNAL_FTGL
#include <ft2build.h>
#include FT_FREETYPE_H
#include "FTGL.h"
#include "FTGLTextureFont.h"
#else
#include <FTGL/ftgl.h>
#endif
#undef min
#undef max
#undef GetCharWidth
TTFFont::TTFFont()
{

View file

@ -21,18 +21,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef BBGE_TTFFONT_H
#define BBGE_TTFFONT_H
#include "Base.h"
#include "BaseText.h"
#ifdef AQUARIA_INTERNAL_FTGL
#include <ft2build.h>
#include FT_FREETYPE_H
#include "FTGL.h"
#include "FTGLTextureFont.h"
#else
#include <FTGL/ftgl.h>
#endif
class FTGLTextureFont;
struct TTFFont
{

View file

@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Core.h"
#include "../ExternalLibs/glpng.h"
#include "ByteBuffer.h"
#include "RenderBase.h"
#include <assert.h>
#if defined(BBGE_BUILD_UNIX)
@ -30,15 +30,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#endif
GLint Texture::filter = GL_LINEAR;
GLint Texture::format = 0;
bool Texture::useMipMaps = true;
Texture::Texture()
{
textures[0] = 0;
@ -223,7 +214,7 @@ bool Texture::load(std::string file)
}
stringToLowerUserData(file);
file = core->adjustFilenameCase(file);
file = adjustFilenameCase(file);
loadName = file;
repeating = false;
@ -255,7 +246,7 @@ bool Texture::load(std::string file)
if (found)
{
file = localisePathInternalModpath(file);
file = core->adjustFilenameCase(file);
file = adjustFilenameCase(file);
std::string post = file.substr(file.size()-3, 3);
@ -320,31 +311,14 @@ bool Texture::loadPNG(const std::string &file)
if (file.empty()) return false;
bool good = false;
pngInfo info;
int pngType = PNG_ALPHA;
if (format != 0)
{
if (format == GL_LUMINANCE_ALPHA)
pngType = PNG_LUMINANCEALPHA;
}
unsigned long memsize = 0;
const char *memptr = readFile(file, &memsize);
if(!memptr || !memsize)
goto fail;
if (filter == GL_NEAREST)
{
textures[0] = pngBindMem(memptr, memsize, PNG_NOMIPMAPS, pngType, &info, GL_CLAMP_TO_EDGE, filter, filter);
}
else
{
textures[0] = pngBindMem(memptr, memsize, PNG_BUILDMIPMAPS, pngType, &info, GL_CLAMP_TO_EDGE, GL_LINEAR_MIPMAP_LINEAR, filter);
}
textures[0] = pngBindMem(memptr, memsize, PNG_BUILDMIPMAPS, PNG_ALPHA, &info, GL_CLAMP_TO_EDGE, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
if (textures[0] != 0)
{
@ -392,8 +366,8 @@ bool Texture::loadTGA(ImageTGA *imageTGA)
glGenTextures(1, &textures[0]);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,filter); // Linear Filtering
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,filter); // Linear Filtering
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
if (imageTGA->channels==3)
glTexImage2D(GL_TEXTURE_2D, 0, 3, imageTGA->sizeX, imageTGA->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, imageTGA->data);
@ -449,7 +423,7 @@ ImageTGA *Texture::TGAloadMem(void *mem, int size)
ByteBuffer bb(mem, size, ByteBuffer::REUSE);
ImageTGA *pImageData = NULL; // This stores our important image data
WORD width = 0, height = 0; // The dimensions of the image
unsigned short width = 0, height = 0;// The dimensions of the image
byte length = 0; // The length in bytes to the pixels
byte imageType = 0; // The image type (RLE, RGB, Alpha...)
byte bits = 0; // The bits per pixel for the image (16, 24, 32)

View file

@ -21,7 +21,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef __texture__
#define __texture__
#include "Base.h"
#include <string>
#include "Refcounted.h"
enum TextureLoadResult
@ -60,12 +61,9 @@ public:
static ImageTGA *TGAload(const char* filename);
static ImageTGA *TGAloadMem(void *mem, int size);
static bool useMipMaps;
bool repeat, repeating;
static GLint filter;
static GLint format;
GLuint textures[1];
unsigned textures[1];
void reload();

View file

@ -39,6 +39,7 @@ void Vector::rotate2DRad(float rad)
Vector getRotatedVector(const Vector &vec, float rot)
{
/*
glPushMatrix();
glLoadIdentity();
@ -58,6 +59,10 @@ Vector getRotatedVector(const Vector &vec, float rot)
glPopMatrix();
return Vector(x,y,z);
*/
float s = sinf(rot);
float c = cosf(rot);
return c*vec.x - s*vec.y, s*vec.x + c*vec.y;
}
// note update this from float lerp

View file

@ -24,7 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <cmath>
#include <float.h>
#include <vector>
#include "Event.h"
typedef float scalar_t;
@ -392,8 +391,9 @@ protected:
std::vector <VectorPathNode> pathNodes;
};
class InterpolatedVector;
// This struct is used to keep all of the interpolation-specific data out
// of the global InterpolatedVector class, so that we don't waste memory on
// non-interpolated vectors.
struct InterpolatedVectorData
{
InterpolatedVectorData()
@ -430,10 +430,6 @@ struct InterpolatedVectorData
bool followingPath;
};
// This struct is used to keep all of the interpolation-specific data out
// of the global InterpolatedVector class, so that we don't waste memory on
// non-interpolated vectors.
class InterpolatedVector : public Vector
{
public:
@ -510,13 +506,6 @@ public:
return data && data->followingPath;
}
// for faking a single value
inline float getValue() const
{
return x;
}
// We never allocate this if the vector isn't used for
// interpolation, which saves a _lot_ of memory.
InterpolatedVectorData *data;