added everything
This commit is contained in:
109
engine/platform/3Dfx.h
Executable file
109
engine/platform/3Dfx.h
Executable file
@ -0,0 +1,109 @@
|
||||
/*
|
||||
** Copyright (c) 1995, 3Dfx Interactive, Inc.
|
||||
** All Rights Reserved.
|
||||
**
|
||||
** This is UNPUBLISHED PROPRIETARY SOURCE CODE of 3Dfx Interactive, Inc.;
|
||||
** the contents of this file may not be disclosed to third parties, copied or
|
||||
** duplicated in any form, in whole or in part, without the prior written
|
||||
** permission of 3Dfx Interactive, Inc.
|
||||
**
|
||||
** RESTRICTED RIGHTS LEGEND:
|
||||
** Use, duplication or disclosure by the Government is subject to restrictions
|
||||
** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
|
||||
** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
|
||||
** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
|
||||
** rights reserved under the Copyright Laws of the United States.
|
||||
**
|
||||
*/
|
||||
#ifndef _3DFX_H_
|
||||
#define _3DFX_H_
|
||||
|
||||
/*
|
||||
** basic data types
|
||||
*/
|
||||
typedef unsigned char FxU8;
|
||||
typedef signed char FxI8;
|
||||
typedef unsigned short FxU16;
|
||||
typedef signed short FxI16;
|
||||
typedef signed long FxI32;
|
||||
typedef unsigned long FxU32;
|
||||
typedef int FxBool;
|
||||
typedef float FxFloat;
|
||||
typedef double FxDouble;
|
||||
|
||||
/*
|
||||
** color types
|
||||
*/
|
||||
typedef unsigned long FxColor_t;
|
||||
typedef struct { float r, g, b, a; } FxColor4;
|
||||
|
||||
/*
|
||||
** fundamental types
|
||||
*/
|
||||
#define FXTRUE 1
|
||||
#define FXFALSE 0
|
||||
|
||||
/*
|
||||
** helper macros
|
||||
*/
|
||||
#define FXUNUSED( a ) ( (a) = (a) )
|
||||
#define FXBIT( i ) ( 1L << (i) )
|
||||
|
||||
/*
|
||||
** export macros
|
||||
*/
|
||||
|
||||
#if defined(__MSC__) || defined(_MSC_VER) || (defined(__MWERKS__) && defined(WIN32))
|
||||
#if defined (MSVC16)
|
||||
#define FX_ENTRY
|
||||
#define FX_CALL
|
||||
#else
|
||||
#define FX_ENTRY extern
|
||||
#define FX_CALL __stdcall
|
||||
#endif
|
||||
#elif defined(__WATCOMC__) || defined(__BORLANDC__)
|
||||
#define FX_ENTRY extern
|
||||
#define FX_CALL __stdcall
|
||||
#elif defined (__IBMC__) || defined (__IBMCPP__)
|
||||
/* IBM Visual Age C/C++: */
|
||||
#define FX_ENTRY extern
|
||||
#define FX_CALL __stdcall
|
||||
#elif defined(__DJGPP__)
|
||||
#define FX_ENTRY extern
|
||||
#define FX_CALL
|
||||
#elif defined(__unix__)
|
||||
#define FX_ENTRY extern
|
||||
#define FX_CALL
|
||||
#else
|
||||
#warning define FX_ENTRY & FX_CALL for your compiler
|
||||
#define FX_ENTRY extern
|
||||
#define FX_CALL
|
||||
#endif
|
||||
|
||||
/*
|
||||
** x86 compiler specific definitions
|
||||
*/
|
||||
#if defined(__BORLANDC_)
|
||||
# define REALMODE
|
||||
|
||||
# define REGW( a, b ) ((a).x.b)
|
||||
# define REGB( a, b ) ((a).h.b)
|
||||
# define INT86( a, b, c ) int86(a,b,c)
|
||||
# define INT86X( a, b, c, d ) int86x(a,b,c,d)
|
||||
|
||||
# define RM_SEG( a ) FP_SEG( a )
|
||||
# define RM_OFF( a ) FP_OFF( a )
|
||||
#elif defined(__WATCOMC__)
|
||||
# undef FP_SEG
|
||||
# undef FP_OFF
|
||||
|
||||
# define REGW( a, b ) ((a).w.b)
|
||||
# define REGB( a, b ) ((a).h.b)
|
||||
# define INT86( a, b, c ) int386(a,b,c)
|
||||
# define INT86X( a, b, c, d ) int386x(a,b,c,d)
|
||||
|
||||
# define RM_SEG( a ) ( ( ( ( FxU32 ) (a) ) & 0x000F0000 ) >> 4 )
|
||||
# define RM_OFF( a ) ( ( FxU16 ) (a) )
|
||||
#endif
|
||||
|
||||
#endif /* !__3DFX_H__ */
|
405
engine/platform/GLCoreFunc.h
Executable file
405
engine/platform/GLCoreFunc.h
Executable file
@ -0,0 +1,405 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
GL_FUNCTION(void, glAccum, (GLenum op, GLfloat value), return; )
|
||||
GL_FUNCTION(void, glAlphaFunc, (GLenum func, GLclampf ref), return; )
|
||||
GL_FUNCTION(GLboolean, glAreTexturesResident, (GLsizei n, const GLuint *textures, GLboolean *residences), return false; )
|
||||
GL_FUNCTION(void, glArrayElement, (GLint i), return; )
|
||||
GL_FUNCTION(void, glBegin, (GLenum mode), return; )
|
||||
GL_FUNCTION(void, glBindTexture, (GLenum target, GLuint texture), return; )
|
||||
GL_FUNCTION(void, glBitmap, (GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap), return; )
|
||||
GL_FUNCTION(void, glBlendFunc, (GLenum sfactor, GLenum dfactor), return; )
|
||||
GL_FUNCTION(void, glCallList, (GLuint list), return; )
|
||||
GL_FUNCTION(void, glCallLists, (GLsizei n, GLenum type, const GLvoid *lists), return; )
|
||||
GL_FUNCTION(void, glClear, (GLbitfield mask), return; )
|
||||
GL_FUNCTION(void, glClearAccum, (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha), return; )
|
||||
GL_FUNCTION(void, glClearColor, (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha), return; )
|
||||
GL_FUNCTION(void, glClearDepth, (GLclampd depth), return; )
|
||||
GL_FUNCTION(void, glClearIndex, (GLfloat c), return; )
|
||||
GL_FUNCTION(void, glClearStencil, (GLint s), return; )
|
||||
GL_FUNCTION(void, glClipPlane, (GLenum plane, const GLdouble *equation), return; )
|
||||
|
||||
GL_FUNCTION(void, glColor3b, (GLbyte red, GLbyte green, GLbyte blue), return; )
|
||||
GL_FUNCTION(void, glColor3bv, (const GLbyte *v), return; )
|
||||
GL_FUNCTION(void, glColor3d, (GLdouble red, GLdouble green, GLdouble blue), return; )
|
||||
GL_FUNCTION(void, glColor3dv, (const GLdouble *v), return; )
|
||||
GL_FUNCTION(void, glColor3f, (GLfloat red, GLfloat green, GLfloat blue), return; )
|
||||
GL_FUNCTION(void, glColor3fv, (const GLfloat *v), return; )
|
||||
GL_FUNCTION(void, glColor3i, (GLint red, GLint green, GLint blue), return; )
|
||||
GL_FUNCTION(void, glColor3iv, (const GLint *v), return; )
|
||||
GL_FUNCTION(void, glColor3s, (GLshort red, GLshort green, GLshort blue), return; )
|
||||
GL_FUNCTION(void, glColor3sv, (const GLshort *v), return; )
|
||||
GL_FUNCTION(void, glColor3ub, (GLubyte red, GLubyte green, GLubyte blue), return; )
|
||||
GL_FUNCTION(void, glColor3ubv, (const GLubyte *v), return; )
|
||||
GL_FUNCTION(void, glColor3ui, (GLuint red, GLuint green, GLuint blue), return; )
|
||||
GL_FUNCTION(void, glColor3uiv, (const GLuint *v), return; )
|
||||
GL_FUNCTION(void, glColor3us, (GLushort red, GLushort green, GLushort blue), return; )
|
||||
GL_FUNCTION(void, glColor3usv, (const GLushort *v), return; )
|
||||
GL_FUNCTION(void, glColor4b, (GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha), return; )
|
||||
GL_FUNCTION(void, glColor4bv, (const GLbyte *v), return; )
|
||||
GL_FUNCTION(void, glColor4d, (GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha), return; )
|
||||
GL_FUNCTION(void, glColor4dv, (const GLdouble *v), return; )
|
||||
GL_FUNCTION(void, glColor4f, (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha), return; )
|
||||
GL_FUNCTION(void, glColor4fv, (const GLfloat *v), return; )
|
||||
GL_FUNCTION(void, glColor4i, (GLint red, GLint green, GLint blue, GLint alpha), return; )
|
||||
GL_FUNCTION(void, glColor4iv, (const GLint *v), return; )
|
||||
GL_FUNCTION(void, glColor4s, (GLshort red, GLshort green, GLshort blue, GLshort alpha), return; )
|
||||
GL_FUNCTION(void, glColor4sv, (const GLshort *v), return; )
|
||||
GL_FUNCTION(void, glColor4ub, (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha), return; )
|
||||
GL_FUNCTION(void, glColor4ubv, (const GLubyte *v), return; )
|
||||
GL_FUNCTION(void, glColor4ui, (GLuint red, GLuint green, GLuint blue, GLuint alpha), return; )
|
||||
GL_FUNCTION(void, glColor4uiv, (const GLuint *v), return; )
|
||||
GL_FUNCTION(void, glColor4us, (GLushort red, GLushort green, GLushort blue, GLushort alpha), return; )
|
||||
GL_FUNCTION(void, glColor4usv, (const GLushort *v), return; )
|
||||
|
||||
GL_FUNCTION(void, glColorMask, (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha), return; )
|
||||
GL_FUNCTION(void, glColorMaterial, (GLenum face, GLenum mode), return; )
|
||||
GL_FUNCTION(void, glCopyPixels, (GLint x, GLint y, GLsizei width, GLsizei height, GLenum type), return; )
|
||||
GL_FUNCTION(void, glCopyTexImage1D, (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border), return; )
|
||||
GL_FUNCTION(void, glCopyTexImage2D, (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border), return; )
|
||||
GL_FUNCTION(void, glCopyTexSubImage1D, (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width), return; )
|
||||
GL_FUNCTION(void, glCopyTexSubImage2D, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height), return; )
|
||||
//GL_FUNCTION(void, glCopyTexSubImage3D, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height), return; )
|
||||
GL_FUNCTION(void, glCullFace, (GLenum mode), return; )
|
||||
GL_FUNCTION(void, glDeleteLists, (GLuint list, GLsizei range), return; )
|
||||
GL_FUNCTION(void, glDeleteTextures, (GLsizei n, const GLuint *textures), return; )
|
||||
GL_FUNCTION(void, glDepthFunc, (GLenum func), return; )
|
||||
GL_FUNCTION(void, glDepthMask, (GLboolean flag), return; )
|
||||
GL_FUNCTION(void, glDepthRange, (GLclampd zNear, GLclampd zFar), return; )
|
||||
GL_FUNCTION(void, glDisable, (GLenum cap), return; )
|
||||
GL_FUNCTION(void, glDisableClientState, (GLenum array), return; )
|
||||
GL_FUNCTION(void, glDrawArrays, (GLenum mode, GLint first, GLsizei count), return; )
|
||||
GL_FUNCTION(void, glDrawBuffer, (GLenum mode), return; )
|
||||
GL_FUNCTION(void, glDrawElements, (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices), return; )
|
||||
GL_FUNCTION(void, glDrawPixels, (GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels), return; )
|
||||
//GL_FUNCTION(void, glDrawRangeElements, (GLenum mode, GLuint start, GLuint end, GLsizei cound, GLenum type, const GLvoid *indices), return; )
|
||||
GL_FUNCTION(void, glEdgeFlag, (GLboolean flag), return; )
|
||||
GL_FUNCTION(void, glEdgeFlagv, (const GLboolean *flag), return; )
|
||||
GL_FUNCTION(void, glEdgeFlagPointer, (GLsizei stride, const GLvoid *pointer), return; )
|
||||
GL_FUNCTION(void, glEnable, (GLenum cap), return; )
|
||||
GL_FUNCTION(void, glEndList, (void), return; )
|
||||
GL_FUNCTION(void, glEnableClientState, (GLenum array), return; )
|
||||
GL_FUNCTION(void, glEnd, (void), return; )
|
||||
GL_FUNCTION(void, glEvalCoord1d, (GLdouble u), return;)
|
||||
GL_FUNCTION(void, glEvalCoord1f, (GLfloat u), return;)
|
||||
GL_FUNCTION(void, glEvalCoord2d, (GLdouble u, GLdouble v), return;)
|
||||
GL_FUNCTION(void, glEvalCoord2f, (GLfloat u, GLfloat v), return;)
|
||||
GL_FUNCTION(void, glEvalCoord1dv, (const GLdouble *u), return;)
|
||||
GL_FUNCTION(void, glEvalCoord1fv, (const GLfloat *u), return;)
|
||||
GL_FUNCTION(void, glEvalCoord2dv, (const GLdouble *u), return;)
|
||||
GL_FUNCTION(void, glEvalCoord2fv, (const GLfloat *u), return;)
|
||||
GL_FUNCTION(void, glEvalMesh1, (GLenum mode, GLint i1, GLint i2), return; )
|
||||
GL_FUNCTION(void, glEvalMesh2, (GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2), return; )
|
||||
GL_FUNCTION(void, glEvalPoint1, (GLint i), return; )
|
||||
GL_FUNCTION(void, glEvalPoint2, (GLint i, GLint j), return; )
|
||||
GL_FUNCTION(void, glFeedbackBuffer, (GLsizei size, GLenum type, GLfloat *buffer), return; )
|
||||
GL_FUNCTION(void, glFinish, (void), return; )
|
||||
GL_FUNCTION(void, glFlush, (void), return; )
|
||||
GL_FUNCTION(void, glFogf, (GLenum pname, GLfloat param), return; )
|
||||
GL_FUNCTION(void, glFogfv, (GLenum pname, const GLfloat *params), return; )
|
||||
GL_FUNCTION(void, glFogi, (GLenum pname, GLint param), return; )
|
||||
GL_FUNCTION(void, glFogiv, (GLenum pname, const GLint *params), return; )
|
||||
GL_FUNCTION(void, glFrontFace, (GLenum mode), return; )
|
||||
GL_FUNCTION(void, glFrustum, (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar), return; )
|
||||
|
||||
GL_FUNCTION(GLuint, glGenLists, (GLsizei range), return 0; )
|
||||
GL_FUNCTION(void, glGenTextures, (GLsizei n, GLuint *textures), return; )
|
||||
GL_FUNCTION(void, glGetBooleanv, (GLenum pname, GLboolean *params), return; )
|
||||
GL_FUNCTION(void, glGetClipPlane, (GLenum plane, GLdouble *equation), return; )
|
||||
GL_FUNCTION(void, glColorPointer, (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer), return; )
|
||||
GL_FUNCTION(void, glGetDoublev, (GLenum pname, GLdouble *params), return; )
|
||||
GL_FUNCTION(void, glGetFloatv, (GLenum pname, GLfloat *params), return; )
|
||||
GL_FUNCTION(GLuint, glGetError, (void), return 0; )
|
||||
GL_FUNCTION(void, glGetIntegerv, (GLenum pname, GLint *params), return; )
|
||||
GL_FUNCTION(void, glGetLightfv, (GLenum light, GLenum pname, GLfloat *params), return; )
|
||||
GL_FUNCTION(void, glGetLightiv, (GLenum light, GLenum pname, GLint *params), return; )
|
||||
GL_FUNCTION(void, glGetMapdv, (GLenum target, GLenum query, GLdouble *v), return; )
|
||||
GL_FUNCTION(void, glGetMapfv, (GLenum target, GLenum query, GLfloat *v), return; )
|
||||
GL_FUNCTION(void, glGetMapiv, (GLenum target, GLenum query, GLint *v), return; )
|
||||
GL_FUNCTION(void, glGetMaterialfv, (GLenum face, GLenum pname, GLfloat *params), return; )
|
||||
GL_FUNCTION(void, glGetMaterialiv, (GLenum face, GLenum pname, GLint *params), return; )
|
||||
GL_FUNCTION(void, glGetPixelMapfv, (GLenum map, GLfloat *values), return; )
|
||||
GL_FUNCTION(void, glGetPixelMapuiv, (GLenum map, GLuint *values), return; )
|
||||
GL_FUNCTION(void, glGetPixelMapusv, (GLenum map, GLushort *values), return; )
|
||||
GL_FUNCTION(void, glGetPointerv, (GLenum pname, GLvoid* *params), return; )
|
||||
GL_FUNCTION(void, glGetPolygonStipple, (GLubyte *mask), return; )
|
||||
GL_FUNCTION(const GLubyte*, glGetString, (GLenum name), return NULL; )
|
||||
GL_FUNCTION(void, glGetTexEnvfv, (GLenum target, GLenum pname, GLfloat *params), return; )
|
||||
GL_FUNCTION(void, glGetTexEnviv, (GLenum target, GLenum pname, GLint *params), return; )
|
||||
GL_FUNCTION(void, glGetTexGendv, (GLenum coord, GLenum pname, GLdouble *params), return; )
|
||||
GL_FUNCTION(void, glGetTexGenfv, (GLenum coord, GLenum pname, GLfloat *params), return; )
|
||||
GL_FUNCTION(void, glGetTexGeniv, (GLenum coord, GLenum pname, GLint *params), return; )
|
||||
GL_FUNCTION(void, glGetTexImage, (GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels), return; )
|
||||
GL_FUNCTION(void, glGetTexLevelParameterfv, (GLenum target, GLint level, GLenum pname, GLfloat *params), return; )
|
||||
GL_FUNCTION(void, glGetTexLevelParameteriv, (GLenum target, GLint level, GLenum pname, GLint *params), return; )
|
||||
GL_FUNCTION(void, glGetTexParameterfv, (GLenum target, GLenum pname, GLfloat *params), return; )
|
||||
GL_FUNCTION(void, glGetTexParameteriv, (GLenum target, GLenum pname, GLint *params), return; )
|
||||
|
||||
GL_FUNCTION(void, glHint, (GLenum target, GLenum mode), return; )
|
||||
GL_FUNCTION(void, glIndexd, (GLdouble c), return; )
|
||||
GL_FUNCTION(void, glIndexf, (GLfloat c), return; )
|
||||
GL_FUNCTION(void, glIndexi, (GLint c), return; )
|
||||
GL_FUNCTION(void, glIndexs, (GLshort c), return; )
|
||||
GL_FUNCTION(void, glIndexub, (GLubyte c), return; )
|
||||
GL_FUNCTION(void, glIndexdv, (const GLdouble *c), return; )
|
||||
GL_FUNCTION(void, glIndexfv, (const GLfloat *c), return; )
|
||||
GL_FUNCTION(void, glIndexiv, (const GLint *c), return; )
|
||||
GL_FUNCTION(void, glIndexsv, (const GLshort *c), return; )
|
||||
GL_FUNCTION(void, glIndexubv, (const GLubyte *c), return; )
|
||||
GL_FUNCTION(void, glIndexMask, (GLuint mask), return; )
|
||||
GL_FUNCTION(void, glIndexPointer, (GLenum type, GLsizei stride, const GLvoid *pointer), return; )
|
||||
GL_FUNCTION(void, glInitNames, (void), return; );
|
||||
GL_FUNCTION(void, glInterleavedArrays, (GLenum format, GLsizei stride, const GLvoid *pointer), return; )
|
||||
GL_FUNCTION(GLboolean, glIsEnabled, (GLenum cap), return false; )
|
||||
GL_FUNCTION(GLboolean, glIsList, (GLuint list), return false; )
|
||||
GL_FUNCTION(GLboolean, glIsTexture, (GLuint texture), return false; )
|
||||
GL_FUNCTION(void, glLightf, (GLenum light, GLenum pname, GLfloat param), return; )
|
||||
GL_FUNCTION(void, glLightfv, (GLenum light, GLenum pname, const GLfloat *params), return; )
|
||||
GL_FUNCTION(void, glLighti, (GLenum light, GLenum pname, GLint param), return; )
|
||||
GL_FUNCTION(void, glLightiv, (GLenum light, GLenum pname, const GLint *params), return; )
|
||||
GL_FUNCTION(void, glLightModelf, (GLenum pname, GLfloat param), return; )
|
||||
GL_FUNCTION(void, glLightModelfv, (GLenum pname, const GLfloat *params), return; )
|
||||
GL_FUNCTION(void, glLightModeli, (GLenum pname, GLint param), return; )
|
||||
GL_FUNCTION(void, glLightModeliv, (GLenum pname, const GLint *params), return; )
|
||||
GL_FUNCTION(void, glLineStipple, (GLint factor, GLushort pattern), return; )
|
||||
GL_FUNCTION(void, glLineWidth, (GLfloat width), return; )
|
||||
GL_FUNCTION(void, glListBase, (GLuint base), return; )
|
||||
GL_FUNCTION(void, glLoadIdentity, (void), return; )
|
||||
GL_FUNCTION(void, glLoadMatrixd, (const GLdouble *m), return; )
|
||||
GL_FUNCTION(void, glLoadMatrixf, (const GLfloat *m), return; )
|
||||
GL_FUNCTION(void, glLoadName, (GLuint name), return; )
|
||||
GL_FUNCTION(void, glLogicOp, (GLenum opcode), return; )
|
||||
GL_FUNCTION(void, glMap1d, (GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points), return; )
|
||||
GL_FUNCTION(void, glMap1f, (GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points), return; )
|
||||
GL_FUNCTION(void, glMap2d, (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points), return; )
|
||||
GL_FUNCTION(void, glMap2f, (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points), return; )
|
||||
GL_FUNCTION(void, glMapGrid1d, (GLint un, GLdouble u1, GLdouble u2), return; )
|
||||
GL_FUNCTION(void, glMapGrid1f, (GLint un, GLfloat u1, GLfloat u2), return; )
|
||||
GL_FUNCTION(void, glMapGrid2d, (GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2), return; )
|
||||
GL_FUNCTION(void, glMapGrid2f, (GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2), return; )
|
||||
GL_FUNCTION(void, glMaterialf, (GLenum face, GLenum pname, GLfloat param), return; )
|
||||
GL_FUNCTION(void, glMaterialfv, (GLenum face, GLenum pname, const GLfloat* params), return; )
|
||||
GL_FUNCTION(void, glMateriali, (GLenum face, GLenum pname, GLint param), return; )
|
||||
GL_FUNCTION(void, glMaterialiv, (GLenum face, GLenum pname, const GLint* params), return; )
|
||||
GL_FUNCTION(void, glMatrixMode, (GLenum mode), return; )
|
||||
GL_FUNCTION(void, glMultMatrixd, (const GLdouble *m), return; )
|
||||
GL_FUNCTION(void, glMultMatrixf, (const GLfloat *m), return; )
|
||||
GL_FUNCTION(void, glNewList, (GLuint list, GLenum mode), return; )
|
||||
|
||||
GL_FUNCTION(void, glNormal3b, (GLbyte nx, GLbyte ny, GLbyte nz), return; );
|
||||
GL_FUNCTION(void, glNormal3bv, (const GLbyte *v), return; );
|
||||
GL_FUNCTION(void, glNormal3d, (GLdouble nx, GLdouble ny, GLdouble nz), return; );
|
||||
GL_FUNCTION(void, glNormal3dv, (const GLdouble *v), return; );
|
||||
GL_FUNCTION(void, glNormal3f, (GLfloat nx, GLfloat ny, GLfloat nz), return; );
|
||||
GL_FUNCTION(void, glNormal3fv, (const GLfloat *v), return; );
|
||||
GL_FUNCTION(void, glNormal3i, (GLint nx, GLint ny, GLint nz), return; );
|
||||
GL_FUNCTION(void, glNormal3iv, (const GLint *v), return; );
|
||||
GL_FUNCTION(void, glNormal3s, (GLshort nx, GLshort ny, GLshort nz), return; );
|
||||
GL_FUNCTION(void, glNormal3sv, (const GLshort *v), return; );
|
||||
|
||||
GL_FUNCTION(void, glNormalPointer, (GLenum type, GLsizei stride, const GLvoid *pointer), return; )
|
||||
GL_FUNCTION(void, glOrtho, (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar), return; )
|
||||
GL_FUNCTION(void, glPassThrough, (GLfloat token), return; )
|
||||
GL_FUNCTION(void, glPixelMapfv, (GLenum map, GLint mapSize, const GLfloat *values), return; )
|
||||
GL_FUNCTION(void, glPixelMapuiv, (GLenum map, GLint mapSize, const GLuint *values), return; )
|
||||
GL_FUNCTION(void, glPixelMapusv, (GLenum map, GLint mapSize, const GLushort *values), return; )
|
||||
GL_FUNCTION(void, glPixelStoref, (GLenum pname, GLfloat param), return; )
|
||||
GL_FUNCTION(void, glPixelStorei, (GLenum pname, GLint param), return; )
|
||||
GL_FUNCTION(void, glPixelTransferf, (GLenum pname, GLfloat param), return; )
|
||||
GL_FUNCTION(void, glPixelTransferi, (GLenum pname, GLint param), return; )
|
||||
GL_FUNCTION(void, glPixelZoom, (GLfloat xfactor, GLfloat yfactor), return; )
|
||||
GL_FUNCTION(void, glPointSize, (GLfloat size), return; )
|
||||
GL_FUNCTION(void, glPolygonMode, (GLenum face, GLenum mode), return; )
|
||||
GL_FUNCTION(void, glPolygonOffset, (GLfloat factor, GLfloat units), return; )
|
||||
GL_FUNCTION(void, glPolygonStipple, (const GLubyte *mask), return; )
|
||||
GL_FUNCTION(void, glPopAttrib, (void), return; )
|
||||
GL_FUNCTION(void, glPopClientAttrib, (void), return; )
|
||||
GL_FUNCTION(void, glPopMatrix, (void), return; )
|
||||
GL_FUNCTION(void, glPopName, (void), return; )
|
||||
GL_FUNCTION(void, glPrioritizeTextures, (GLsizei n, const GLuint *textures, const GLclampf *priorities), return; )
|
||||
GL_FUNCTION(void, glPushAttrib, (GLbitfield mask), return; )
|
||||
GL_FUNCTION(void, glPushClientAttrib, (GLbitfield mask), return; )
|
||||
GL_FUNCTION(void, glPushMatrix, (void), return; )
|
||||
GL_FUNCTION(void, glPushName, (GLuint name), return; )
|
||||
|
||||
GL_FUNCTION(void, glRasterPos2d, (GLdouble x, GLdouble y), return; )
|
||||
GL_FUNCTION(void, glRasterPos2dv, (const GLdouble *v), return; )
|
||||
GL_FUNCTION(void, glRasterPos2f, (GLfloat x, GLfloat y), return; )
|
||||
GL_FUNCTION(void, glRasterPos2fv, (const GLfloat *v), return; )
|
||||
GL_FUNCTION(void, glRasterPos2i, (GLint x, GLint y), return; )
|
||||
GL_FUNCTION(void, glRasterPos2iv, (const GLint *v), return; )
|
||||
GL_FUNCTION(void, glRasterPos2s, (GLshort x, GLshort y), return; )
|
||||
GL_FUNCTION(void, glRasterPos2sv, (const GLshort *v), return; )
|
||||
GL_FUNCTION(void, glRasterPos3d, (GLdouble x, GLdouble y, GLdouble z), return; )
|
||||
GL_FUNCTION(void, glRasterPos3dv, (const GLdouble *v), return; )
|
||||
GL_FUNCTION(void, glRasterPos3f, (GLfloat x, GLfloat y, GLfloat z), return; )
|
||||
GL_FUNCTION(void, glRasterPos3fv, (const GLfloat *v), return; )
|
||||
GL_FUNCTION(void, glRasterPos3i, (GLint x, GLint y, GLint z), return; )
|
||||
GL_FUNCTION(void, glRasterPos3iv, (const GLint *v), return; )
|
||||
GL_FUNCTION(void, glRasterPos3s, (GLshort x, GLshort y, GLshort z), return; )
|
||||
GL_FUNCTION(void, glRasterPos3sv, (const GLshort *v), return; )
|
||||
GL_FUNCTION(void, glRasterPos4d, (GLdouble x, GLdouble y, GLdouble z, GLdouble w), return; )
|
||||
GL_FUNCTION(void, glRasterPos4dv, (const GLdouble *v), return; )
|
||||
GL_FUNCTION(void, glRasterPos4f, (GLfloat x, GLfloat y, GLfloat z, GLfloat w), return; )
|
||||
GL_FUNCTION(void, glRasterPos4fv, (const GLfloat *v), return; )
|
||||
GL_FUNCTION(void, glRasterPos4i, (GLint x, GLint y, GLint z, GLint w), return; )
|
||||
GL_FUNCTION(void, glRasterPos4iv, (const GLint *v), return; )
|
||||
GL_FUNCTION(void, glRasterPos4s, (GLshort x, GLshort y, GLshort z, GLshort w), return; )
|
||||
GL_FUNCTION(void, glRasterPos4sv, (const GLshort *v), return; )
|
||||
|
||||
GL_FUNCTION(void, glReadBuffer, (GLenum mode), return; )
|
||||
GL_FUNCTION(void, glReadPixels, (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels), return; )
|
||||
GL_FUNCTION(void, glRectd, (GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2), return; )
|
||||
GL_FUNCTION(void, glRectdv, (const GLdouble *v1, const GLdouble *v2), return; )
|
||||
GL_FUNCTION(void, glRectf, (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2), return; )
|
||||
GL_FUNCTION(void, glRectfv, (const GLfloat *v1, const GLfloat *v2), return; )
|
||||
GL_FUNCTION(void, glRecti, (GLint x1, GLint y1, GLint x2, GLint y2), return; )
|
||||
GL_FUNCTION(void, glRectiv, (const GLint *v1, const GLint *v2), return; )
|
||||
GL_FUNCTION(void, glRects, (GLshort x1, GLshort y1, GLshort x2, GLshort y2), return; )
|
||||
GL_FUNCTION(void, glRectsv, (const GLshort *v1, const GLshort *v2), return; )
|
||||
GL_FUNCTION(GLint, glRenderMode, (GLenum mode), return 0; )
|
||||
GL_FUNCTION(void, glRotated, (GLdouble angle, GLdouble x, GLdouble y, GLdouble z), return; )
|
||||
GL_FUNCTION(void, glRotatef, (GLfloat angle, GLfloat x, GLfloat y, GLfloat z), return; )
|
||||
GL_FUNCTION(void, glScaled, (GLdouble x, GLdouble y, GLdouble z), return; )
|
||||
GL_FUNCTION(void, glScalef, (GLfloat x, GLfloat y, GLfloat z), return; )
|
||||
GL_FUNCTION(void, glScissor, (GLint x, GLint y, GLsizei width, GLsizei height), return; )
|
||||
GL_FUNCTION(void, glSelectBuffer, (GLsizei size, GLuint *buffer), return; )
|
||||
GL_FUNCTION(void, glShadeModel, (GLenum mode), return; )
|
||||
GL_FUNCTION(void, glStencilFunc, (GLenum func, GLint ref, GLuint mask), return; )
|
||||
GL_FUNCTION(void, glStencilMask, (GLuint mask), return; )
|
||||
GL_FUNCTION(void, glStencilOp, (GLenum fail, GLenum zfail, GLenum zpass), return; )
|
||||
|
||||
GL_FUNCTION(void, glTexCoord1d, (GLdouble s), return; )
|
||||
GL_FUNCTION(void, glTexCoord1dv, (const GLdouble *v), return; )
|
||||
GL_FUNCTION(void, glTexCoord1f, (GLfloat s), return; )
|
||||
GL_FUNCTION(void, glTexCoord1fv, (const GLfloat *v), return; )
|
||||
GL_FUNCTION(void, glTexCoord1i, (GLint s), return; )
|
||||
GL_FUNCTION(void, glTexCoord1iv, (const GLint *v), return; )
|
||||
GL_FUNCTION(void, glTexCoord1s, (GLshort s), return; )
|
||||
GL_FUNCTION(void, glTexCoord1sv, (const GLshort *v), return; )
|
||||
GL_FUNCTION(void, glTexCoord2d, (GLdouble s, GLdouble t), return; )
|
||||
GL_FUNCTION(void, glTexCoord2dv, (const GLdouble *v), return; )
|
||||
GL_FUNCTION(void, glTexCoord2f, (GLfloat s, GLfloat t), return; )
|
||||
GL_FUNCTION(void, glTexCoord2fv, (const GLfloat *v), return; )
|
||||
GL_FUNCTION(void, glTexCoord2i, (GLint s, GLint t), return; )
|
||||
GL_FUNCTION(void, glTexCoord2iv, (const GLint *v), return; )
|
||||
GL_FUNCTION(void, glTexCoord2s, (GLshort s, GLshort t), return; )
|
||||
GL_FUNCTION(void, glTexCoord2sv, (const GLshort *v), return; )
|
||||
GL_FUNCTION(void, glTexCoord3d, (GLdouble s, GLdouble t, GLdouble r), return; )
|
||||
GL_FUNCTION(void, glTexCoord3dv, (const GLdouble *v), return; )
|
||||
GL_FUNCTION(void, glTexCoord3f, (GLfloat s, GLfloat t, GLfloat r), return; )
|
||||
GL_FUNCTION(void, glTexCoord3fv, (const GLfloat *v), return; )
|
||||
GL_FUNCTION(void, glTexCoord3i, (GLint s, GLint t, GLint r), return; )
|
||||
GL_FUNCTION(void, glTexCoord3iv, (const GLint *v), return; )
|
||||
GL_FUNCTION(void, glTexCoord3s, (GLshort s, GLshort t, GLshort r), return; )
|
||||
GL_FUNCTION(void, glTexCoord3sv, (const GLshort *v), return; )
|
||||
GL_FUNCTION(void, glTexCoord4d, (GLdouble s, GLdouble t, GLdouble r, GLdouble q), return; )
|
||||
GL_FUNCTION(void, glTexCoord4dv, (const GLdouble *v), return; )
|
||||
GL_FUNCTION(void, glTexCoord4f, (GLfloat s, GLfloat t, GLfloat r, GLfloat q), return; )
|
||||
GL_FUNCTION(void, glTexCoord4fv, (const GLfloat *v), return; )
|
||||
GL_FUNCTION(void, glTexCoord4i, (GLint s, GLint t, GLint r, GLint q), return; )
|
||||
GL_FUNCTION(void, glTexCoord4iv, (const GLint *v), return; )
|
||||
GL_FUNCTION(void, glTexCoord4s, (GLshort s, GLshort t, GLshort r, GLshort q), return; )
|
||||
GL_FUNCTION(void, glTexCoord4sv, (const GLshort *v), return; )
|
||||
|
||||
GL_FUNCTION(void, glTexCoordPointer, (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer), return; )
|
||||
GL_FUNCTION(void, glTexEnvf, (GLenum target, GLenum pname, GLfloat param), return; )
|
||||
GL_FUNCTION(void, glTexEnvfv, (GLenum target, GLenum pname, const GLfloat *params), return; )
|
||||
GL_FUNCTION(void, glTexEnvi, (GLenum target, GLenum pname, GLint param), return; )
|
||||
GL_FUNCTION(void, glTexEnviv, (GLenum target, GLenum pname, const GLint *params), return; )
|
||||
GL_FUNCTION(void, glTexGend, (GLenum coord, GLenum pname, GLdouble param), return; )
|
||||
GL_FUNCTION(void, glTexGendv, (GLenum coord, GLenum pname, const GLdouble *param), return; )
|
||||
GL_FUNCTION(void, glTexGenf, (GLenum coord, GLenum pname, GLfloat param), return; )
|
||||
GL_FUNCTION(void, glTexGenfv, (GLenum coord, GLenum pname, const GLfloat *param), return; )
|
||||
GL_FUNCTION(void, glTexGeni, (GLenum coord, GLenum pname, GLint param), return; )
|
||||
GL_FUNCTION(void, glTexGeniv, (GLenum coord, GLenum pname, const GLint *param), return; )
|
||||
GL_FUNCTION(void, glTexImage1D, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels), return; )
|
||||
GL_FUNCTION(void, glTexImage2D, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels), return; )
|
||||
//GL_FUNCTION(void, glTexImage3D, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels), return; )
|
||||
GL_FUNCTION(void, glTexParameterfv, (GLenum target, GLenum pname, const GLfloat *params), return; )
|
||||
GL_FUNCTION(void, glTexParameterf, (GLenum target, GLenum pname, GLfloat param), return; )
|
||||
GL_FUNCTION(void, glTexParameteriv, (GLenum target, GLenum pname, const GLint *params), return; )
|
||||
GL_FUNCTION(void, glTexParameteri, (GLenum target, GLenum pname, GLint param), return; )
|
||||
GL_FUNCTION(void, glTexSubImage1D, (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels), return; )
|
||||
GL_FUNCTION(void, glTexSubImage2D, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels), return; )
|
||||
//GL_FUNCTION(void, glTexSubImage3D, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels), return; )
|
||||
GL_FUNCTION(void, glTranslated, (GLdouble x, GLdouble y, GLdouble z), return; )
|
||||
GL_FUNCTION(void, glTranslatef, (GLfloat x, GLfloat y, GLfloat z), return; )
|
||||
|
||||
GL_FUNCTION(void, glVertex2d, (GLdouble x, GLdouble y), return; )
|
||||
GL_FUNCTION(void, glVertex2dv, (const GLdouble *v), return; )
|
||||
GL_FUNCTION(void, glVertex2f, (GLfloat x, GLfloat y), return; )
|
||||
GL_FUNCTION(void, glVertex2fv, (const GLfloat *v), return; )
|
||||
GL_FUNCTION(void, glVertex2i, (GLint x, GLint y), return; )
|
||||
GL_FUNCTION(void, glVertex2iv, (const GLint *v), return; )
|
||||
GL_FUNCTION(void, glVertex2s, (GLshort x, GLshort y), return; )
|
||||
GL_FUNCTION(void, glVertex2sv, (const GLshort *v), return; )
|
||||
GL_FUNCTION(void, glVertex3d, (GLdouble x, GLdouble y, GLdouble z), return; )
|
||||
GL_FUNCTION(void, glVertex3dv, (const GLdouble *v), return; )
|
||||
GL_FUNCTION(void, glVertex3f, (GLfloat x, GLfloat y, GLfloat z), return; )
|
||||
GL_FUNCTION(void, glVertex3fv, (const GLfloat *v), return; )
|
||||
GL_FUNCTION(void, glVertex3i, (GLint x, GLint y, GLint z), return; )
|
||||
GL_FUNCTION(void, glVertex3iv, (const GLint *v), return; )
|
||||
GL_FUNCTION(void, glVertex3s, (GLshort x, GLshort y, GLshort z), return; )
|
||||
GL_FUNCTION(void, glVertex3sv, (const GLshort *v), return; )
|
||||
GL_FUNCTION(void, glVertex4d, (GLdouble x, GLdouble y, GLdouble z, GLdouble w), return; )
|
||||
GL_FUNCTION(void, glVertex4dv, (const GLdouble *v), return; )
|
||||
GL_FUNCTION(void, glVertex4f, (GLfloat x, GLfloat y, GLfloat z, GLfloat w), return; )
|
||||
GL_FUNCTION(void, glVertex4fv, (const GLfloat *v), return; )
|
||||
GL_FUNCTION(void, glVertex4i, (GLint x, GLint y, GLint z, GLint w), return; )
|
||||
GL_FUNCTION(void, glVertex4iv, (const GLint *v), return; )
|
||||
GL_FUNCTION(void, glVertex4s, (GLshort x, GLshort y, GLshort z, GLshort w), return; )
|
||||
GL_FUNCTION(void, glVertex4sv, (const GLshort *v), return; )
|
||||
|
||||
GL_FUNCTION(void, glVertexPointer, (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer), return; )
|
||||
GL_FUNCTION(void, glViewport, (GLint x, GLint y, GLsizei width, GLsizei height), return; )
|
||||
|
||||
//torque vertex buffer extension
|
||||
GL_FUNCTION(GLboolean, glAvailableVertexBufferEXT, (void), return GL_FALSE; )
|
||||
GL_FUNCTION(GLint, glAllocateVertexBufferEXT, (GLsizei size, GLint format, GLboolean preserve), return 0; )
|
||||
GL_FUNCTION(void*, glLockVertexBufferEXT, (GLint handle, GLsizei size), return NULL; )
|
||||
GL_FUNCTION(void, glUnlockVertexBufferEXT, (GLint handle), return; )
|
||||
GL_FUNCTION(void, glSetVertexBufferEXT, (GLint handle), return; )
|
||||
GL_FUNCTION(void, glOffsetVertexBufferEXT, (GLint handle, GLuint offset), return; )
|
||||
GL_FUNCTION(void, glFillVertexBufferEXT, (GLint handle, GLint first, GLsizei count), return; )
|
||||
GL_FUNCTION(void, glFreeVertexBufferEXT, (GLint handle), return; )
|
||||
|
||||
//GL_ARB_imaging
|
||||
#ifdef DEFINE_IMAGING
|
||||
GL_FUNCTION(void, glBlendColor, (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha), return; )
|
||||
GL_FUNCTION(void, glBlendEquation, (GLenum mode), return; )
|
||||
GL_FUNCTION(void, glColorSubTable, (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data), return; )
|
||||
GL_FUNCTION(void, glColorTable, (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const GLvoid* data), return; )
|
||||
GL_FUNCTION(void, glColorTableParameterfv, (GLenum target, GLenum pname, const GLfloat *params), return; )
|
||||
GL_FUNCTION(void, glColorTableParameterfi, (GLenum target, GLenum pname, const GLint *params), return; )
|
||||
GL_FUNCTION(void, glConvolutionFilter1D, (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image), return; )
|
||||
GL_FUNCTION(void, glConvolutionFilter2D, (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image), return; )
|
||||
GL_FUNCTION(void, glConvolutionParameterf, (GLenum target, GLenum pname, GLfloat params), return; )
|
||||
GL_FUNCTION(void, glConvolutionParameteri, (GLenum target, GLenum pname, GLint params), return; )
|
||||
GL_FUNCTION(void, glCopyColorSubTable, (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width), return; )
|
||||
GL_FUNCTION(void, glCopyColorTable, (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width), return; )
|
||||
GL_FUNCTION(void, glCopyConvolutionFilter1D, (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width), return; )
|
||||
GL_FUNCTION(void, glCopyConvolutionFilter2D, (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height), return; )
|
||||
GL_FUNCTION(void, glGetColorTable, (GLenum target, GLenum format, GLenum type, GLvoid *table), return; )
|
||||
GL_FUNCTION(void, glGetColorTableParameterfv, (GLenum target, GLenum pname, GLfloat *params), return; )
|
||||
GL_FUNCTION(void, glGetColorTableParameteriv, (GLenum target, GLenum pname, GLint *params), return; )
|
||||
GL_FUNCTION(void, glGetConvolutionFilter, (GLenum target, GLenum format, GLenum type, GLvoid *image), return; )
|
||||
GL_FUNCTION(void, glGetConvolutionParamterfv, (GLenum target, GLenum pname, GLfloat *params), return; )
|
||||
GL_FUNCTION(void, glGetConvolutionParamteriv, (GLenum target, GLenum pname, GLint *params), return; )
|
||||
GL_FUNCTION(void, glGetHistogram, (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values), return; )
|
||||
GL_FUNCTION(void, glGetHistogramParameterfv, (GLenum target, GLenum pname, GLfloat *params), return; )
|
||||
GL_FUNCTION(void, glGetHistogramParameteriv, (GLenum target, GLenum pname, GLint *params), return; )
|
||||
GL_FUNCTION(void, glGetMinmax, (GLenum target, GLboolean reset, GLenum format, GLvoid *values), return; )
|
||||
GL_FUNCTION(void, glGetMinmaxParameterfv, (GLenum target, GLenum pname, GLfloat *params), return; )
|
||||
GL_FUNCTION(void, glGetMinmaxParameteriv, (GLenum target, GLenum pname, GLint *params), return; )
|
||||
GL_FUNCTION(void, glGetSeparableFilter, (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span), return; )
|
||||
GL_FUNCTION(void, glHistogram, (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink), return; )
|
||||
GL_FUNCTION(void, glMinmax, (GLenum target, GLenum internalformat, GLboolean sink), return; )
|
||||
GL_FUNCTION(void, glResetHistogram, (GLenum target), return; )
|
||||
GL_FUNCTION(void, glResetMinmax, (GLenum target), return; )
|
||||
GL_FUNCTION(void, glSeparableFilter2D, (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column), return; )
|
||||
#endif
|
||||
|
125
engine/platform/GLExtFunc.h
Executable file
125
engine/platform/GLExtFunc.h
Executable file
@ -0,0 +1,125 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifndef GL_GROUP_BEGIN
|
||||
#define GL_GROUP_BEGIN( flag )
|
||||
#define UNDEF_BEGIN
|
||||
#endif
|
||||
|
||||
#ifndef GL_GROUP_END
|
||||
#define GL_GROUP_END()
|
||||
#define UNDEF_END
|
||||
#endif
|
||||
|
||||
//ARB_multitexture
|
||||
GL_GROUP_BEGIN(ARB_multitexture)
|
||||
GL_FUNCTION(void, glActiveTextureARB, (GLenum target), return; )
|
||||
GL_FUNCTION(void, glClientActiveTextureARB, (GLenum target), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord1dARB, (GLenum target, GLdouble s), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord1dvARB, (GLenum target, const GLdouble *v), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord1fARB, (GLenum target, GLfloat s), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord1fvARB, (GLenum target, const GLfloat *v), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord1iARB, (GLenum target, GLint s), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord1ivARB, (GLenum target, const GLint *v), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord1sARB, (GLenum target, GLshort s), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord1svARB, (GLenum target, const GLshort *v), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord2dARB, (GLenum target, GLdouble s, GLdouble t), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord2dvARB, (GLenum target, const GLdouble *v), return; )
|
||||
GL_FUNCTION(void, glMultiTexCoord2fARB, (GLenum target, GLfloat s, GLfloat t), return; )
|
||||
GL_FUNCTION(void, glMultiTexCoord2fvARB, (GLenum target, const GLfloat *v), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord2iARB, (GLenum target, GLint s, GLint t), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord2ivARB, (GLenum target, const GLint *v), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord2sARB, (GLenum target, GLshort s, GLshort t), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord2svARB, (GLenum target, const GLshort *v), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord3dARB, (GLenum target, GLdouble s, GLdouble t, GLdouble r), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord3dvARB, (GLenum target, const GLdouble *v), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord3fARB, (GLenum target, GLfloat s, GLfloat t, GLfloat r), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord3fvARB, (GLenum target, const GLfloat *v), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord3iARB, (GLenum target, GLint s, GLint t, GLint r), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord3ivARB, (GLenum target, const GLint *v), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord3sARB, (GLenum target, GLshort s, GLshort t, GLshort r), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord3svARB, (GLenum target, const GLshort *v), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord4dARB, (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord4dvARB, (GLenum target, const GLdouble *v), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord4fARB, (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord4fvARB, (GLenum target, const GLfloat *v), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord4iARB, (GLenum target, GLint s, GLint t, GLint r, GLint q), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord4ivARB, (GLenum target, const GLint *v), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord4sARB, (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q), return; )
|
||||
//GL_FUNCTION(void, glMultiTexCoord4svARB, (GLenum target, const GLshort *v), return; )
|
||||
GL_GROUP_END()
|
||||
|
||||
//ARB_texture_compression
|
||||
GL_GROUP_BEGIN(ARB_texture_compression)
|
||||
GL_FUNCTION(void, glCompressedTexImage3DARB, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void*), return; )
|
||||
GL_FUNCTION(void, glCompressedTexImage2DARB, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void*), return; )
|
||||
GL_FUNCTION(void, glCompressedTexImage1DARB, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLsizei imageSize, const void*), return; )
|
||||
GL_FUNCTION(void, glCompressedTexSubImage3DARB, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void*), return; )
|
||||
GL_FUNCTION(void, glCompressedTexSubImage2DARB, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void*), return; )
|
||||
GL_FUNCTION(void, glCompressedTexSubImage1DARB, (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void*), return; )
|
||||
GL_FUNCTION(void, glGetCompressedTexImageARB, (GLenum target, GLint lod, void* img), return; )
|
||||
GL_GROUP_END()
|
||||
|
||||
//EXT_compiled_vertex_array
|
||||
GL_GROUP_BEGIN(EXT_compiled_vertex_array)
|
||||
GL_FUNCTION(void, glLockArraysEXT, (GLint first, GLsizei count), return; )
|
||||
GL_FUNCTION(void, glUnlockArraysEXT, (void), return; )
|
||||
GL_GROUP_END()
|
||||
|
||||
//EXT_fog_coord
|
||||
GL_GROUP_BEGIN(EXT_fog_coord)
|
||||
GL_FUNCTION(void, glFogCoordfEXT, (GLfloat), return; )
|
||||
GL_FUNCTION(void , glFogCoordPointerEXT, (GLenum, GLsizei, void*), return; )
|
||||
GL_GROUP_END()
|
||||
|
||||
//EXT_paletted_texture
|
||||
GL_GROUP_BEGIN(EXT_paletted_texture)
|
||||
GL_FUNCTION(void, glColorTableEXT, (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const void* data), return; )
|
||||
GL_GROUP_END()
|
||||
|
||||
|
||||
// EXT_blend_color
|
||||
// http://www.msi.unilim.fr/~porquet/glexts/GL_EXT_blend_color.txt.html
|
||||
#define GL_CONSTANT_COLOR_EXT 0x8001
|
||||
#define GL_ONE_MINUS_CONSTANT_COLOR_EXT 0x8002
|
||||
#define GL_CONSTANT_ALPHA_EXT 0x8003
|
||||
#define GL_ONE_MINUS_CONSTANT_ALPHA_EXT 0x8004
|
||||
#define GL_BLEND_COLOR_EXT 0x8005
|
||||
|
||||
GL_GROUP_BEGIN(EXT_blend_color)
|
||||
GL_FUNCTION(void, glBlendColorEXT, (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha), return; )
|
||||
GL_GROUP_END()
|
||||
|
||||
// EXT_blend_minmax
|
||||
// http://www.msi.unilim.fr/~porquet/glexts/GL_EXT_blend_minmax.txt.html
|
||||
#define GL_FUNC_ADD_EXT 0x8006
|
||||
#define GL_MIN_EXT 0x8007
|
||||
#define GL_MAX_EXT 0x8008
|
||||
#define GL_BLEND_EQUATION_EXT 0x8009
|
||||
|
||||
GL_GROUP_BEGIN(EXT_blend_minmax)
|
||||
GL_FUNCTION(void, glBlendEquationEXT, (GLenum mode), return; )
|
||||
GL_GROUP_END()
|
||||
|
||||
//NV_vertex_array_range
|
||||
#ifdef TORQUE_OS_WIN32
|
||||
GL_GROUP_BEGIN(NV_vertex_array_range)
|
||||
GL_FUNCTION(void, glVertexArrayRangeNV, (GLsizei length, void* pointer), return; )
|
||||
GL_FUNCTION(void, glFlushVertexArrayRangeNV, (), return; )
|
||||
GL_FUNCTION(void*, wglAllocateMemoryNV, (GLsizei, GLfloat, GLfloat, GLfloat), return NULL; )
|
||||
GL_FUNCTION(void, wglFreeMemoryNV, (void*), return; )
|
||||
GL_GROUP_END()
|
||||
#endif
|
||||
|
||||
#ifdef UNDEF_BEGIN
|
||||
#undef GL_GROUP_BEGIN
|
||||
#undef UNDEF_BEGIN
|
||||
#endif
|
||||
|
||||
#ifdef UNDEF_END
|
||||
#undef GL_GROUP_END
|
||||
#undef UNDEF_END
|
||||
#endif
|
14
engine/platform/GLUFunc.h
Executable file
14
engine/platform/GLUFunc.h
Executable file
@ -0,0 +1,14 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
GL_FUNCTION(void, gluOrtho2D, (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top), return; )
|
||||
GL_FUNCTION(void, gluPerspective, (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar), return; )
|
||||
GL_FUNCTION(void, gluPickMatrix, (GLdouble x, GLdouble y, GLdouble width, GLdouble height, GLint viewport[4]), return; )
|
||||
GL_FUNCTION(void, gluLookAt, (GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz), return; )
|
||||
GL_FUNCTION(int, gluProject, (GLdouble objx, GLdouble objy, GLdouble objz, const GLdouble modelMatrix[16], const GLdouble projMatrix[16], const GLint viewport[4], GLdouble *winx, GLdouble *winy, GLdouble *winz), return 0; )
|
||||
GL_FUNCTION(int, gluUnProject, (GLdouble winx, GLdouble winy, GLdouble winz, const GLdouble modelMatrix[16], const GLdouble projMatrix[16], const GLint viewport[4], GLdouble *objx, GLdouble *objy, GLdouble *objz), return 0; )
|
||||
GL_FUNCTION(int, gluScaleImage, (GLenum format, GLint widthin, GLint heightin, GLenum typein, const void *datain, GLint widthout, GLint heightout, GLenum typeout, void *dataout), return 0; )
|
||||
GL_FUNCTION(int, gluBuild1DMipmaps, (GLenum target, GLint components, GLint width, GLenum format, GLenum type, const void *data), return 0; )
|
||||
GL_FUNCTION(int, gluBuild2DMipmaps, (GLenum target, GLint components, GLint width, GLint height, GLenum format, GLenum type, const void *data), return 0; )
|
399
engine/platform/event.h
Executable file
399
engine/platform/event.h
Executable file
@ -0,0 +1,399 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
/// @file
|
||||
/// Library-wide input events
|
||||
///
|
||||
/// All external events are converted into system events, which are defined
|
||||
/// in this file.
|
||||
#ifndef _EVENT_H_
|
||||
#define _EVENT_H_
|
||||
|
||||
#include "platform/types.h"
|
||||
|
||||
typedef int NetConnectionId;
|
||||
|
||||
/// Generic network address
|
||||
///
|
||||
/// This is used to represent IP addresses.
|
||||
struct NetAddress {
|
||||
int type; ///< Type of address (IPAddress currently)
|
||||
|
||||
/// Acceptable NetAddress types.
|
||||
enum {
|
||||
IPAddress,
|
||||
IPXAddress
|
||||
};
|
||||
|
||||
U8 netNum[4]; ///< For IP: sin_addr<br>
|
||||
/// For IPX: sa_netnum
|
||||
|
||||
U8 nodeNum[6]; ///< For IP: Not used.<br>
|
||||
/// For IPX: sa_nodenum (not used by IP)
|
||||
|
||||
U16 port; ///< For IP: sin_port<br>
|
||||
/// For IPX: sa_socket
|
||||
};
|
||||
|
||||
enum EventConstants
|
||||
{
|
||||
MaxPacketDataSize = 1500, ///< Maximum allowed size of a packet.
|
||||
MaxConsoleLineSize = 512 ///< Maximum allowed size of a console line.
|
||||
};
|
||||
|
||||
/// Available event types.
|
||||
enum EventTypes
|
||||
{
|
||||
InputEventType,
|
||||
MouseMoveEventType,
|
||||
PacketReceiveEventType,
|
||||
TimeEventType,
|
||||
QuitEventType,
|
||||
ConsoleEventType,
|
||||
ConnectedReceiveEventType,
|
||||
ConnectedAcceptEventType,
|
||||
ConnectedNotifyEventType
|
||||
};
|
||||
|
||||
/// Base event structure (also used for FrameEvent and QuitEvent)
|
||||
struct Event
|
||||
{
|
||||
U16 type, size;
|
||||
Event() { size = sizeof(Event); }
|
||||
};
|
||||
|
||||
/// The time event causes the simulation to advance.
|
||||
struct TimeEvent : public Event
|
||||
{
|
||||
U32 elapsedTime; ///< Indicates elapsed time in simulation.
|
||||
|
||||
TimeEvent() { type = TimeEventType; size = sizeof(TimeEvent); }
|
||||
};
|
||||
|
||||
/// Notify simulation of state of a connection.
|
||||
struct ConnectedNotifyEvent : public Event
|
||||
{
|
||||
/// Valid connection states
|
||||
enum State {
|
||||
DNSResolved,
|
||||
DNSFailed,
|
||||
Connected,
|
||||
ConnectFailed,
|
||||
Disconnected
|
||||
};
|
||||
|
||||
U32 state; ///< Indicates current connection state.
|
||||
U32 tag; ///< Identifies connection.
|
||||
ConnectedNotifyEvent() { type = ConnectedNotifyEventType; size = sizeof(ConnectedNotifyEvent); }
|
||||
};
|
||||
|
||||
/// Triggered when we receive data from a connected entity.
|
||||
struct ConnectedReceiveEvent : public Event
|
||||
{
|
||||
U32 tag; ///< Identifies connection
|
||||
U8 data[MaxPacketDataSize]; /// Payload
|
||||
ConnectedReceiveEvent() { type = ConnectedReceiveEventType; }
|
||||
};
|
||||
|
||||
/// Triggered when we accept a new connection.
|
||||
struct ConnectedAcceptEvent : public Event
|
||||
{
|
||||
U32 portTag; ///< Identifies port we received this connection on.
|
||||
U32 connectionTag; ///< Identifies the connection.
|
||||
NetAddress address; ///< Originating address of connection.
|
||||
ConnectedAcceptEvent() { type = ConnectedAcceptEventType; size = sizeof(ConnectedAcceptEvent); }
|
||||
};
|
||||
|
||||
|
||||
/// Triggered on incoming (UDP) packet
|
||||
///
|
||||
/// packetType is what type of packet it is.
|
||||
struct PacketReceiveEvent : public Event
|
||||
{
|
||||
NetAddress sourceAddress; ///< Originating address.
|
||||
U8 data[MaxPacketDataSize]; ///< Payload
|
||||
PacketReceiveEvent() { type = PacketReceiveEventType; }
|
||||
};
|
||||
|
||||
/// Represents a line of console input.
|
||||
struct ConsoleEvent : public Event
|
||||
{
|
||||
char data[MaxConsoleLineSize]; ///< Payload
|
||||
ConsoleEvent() { type = ConsoleEventType; }
|
||||
};
|
||||
|
||||
/// Header sizes for events defined later on.
|
||||
/// Byte offset to payload of a PacketReceiveEvent
|
||||
const U32 PacketReceiveEventHeaderSize = Offset(data,PacketReceiveEvent);
|
||||
/// Byte offset to payload of a ConnectedReceiveEvent
|
||||
const U32 ConnectedReceiveEventHeaderSize = Offset(data,ConnectedReceiveEvent);
|
||||
/// Byte offset to payload of a ConsoleEvent
|
||||
const U32 ConsoleEventHeaderSize = Offset(data,ConsoleEvent);
|
||||
|
||||
|
||||
/// Mouse input event.
|
||||
struct MouseMoveEvent : public Event
|
||||
{
|
||||
S32 xPos, yPos;
|
||||
U8 modifier;
|
||||
|
||||
MouseMoveEvent() { type = MouseMoveEventType; size = sizeof(MouseMoveEvent); }
|
||||
};
|
||||
|
||||
/// Generic input event.
|
||||
struct InputEvent : public Event
|
||||
{
|
||||
U32 deviceInst; ///< Device instance: joystick0, joystick1, etc
|
||||
float fValue; ///< Value ranges from -1.0 to 1.0
|
||||
U16 deviceType; ///< One of mouse, keyboard, joystick, unknown
|
||||
U16 objType; ///< One of SI_XAXIS, SI_BUTTON, SI_KEY ...
|
||||
U16 ascii; ///< ASCII character code if this is a keyboard event.
|
||||
U16 objInst; ///< Which type instance or a KeyCode
|
||||
U8 action; ///< What was the action? (MAKE/BREAK/MOVE)
|
||||
U8 modifier; ///< Modifier to action: SI_LSHIFT, SI_LCTRL, etc.
|
||||
|
||||
InputEvent() { type = InputEventType; size = sizeof(InputEvent); }
|
||||
};
|
||||
|
||||
/// @defgroup input_constants Input system constants
|
||||
/// @{
|
||||
|
||||
/// Input event constants:
|
||||
enum KeyCodes {
|
||||
KEY_NULL = 0x000, ///< Invalid KeyCode
|
||||
KEY_BACKSPACE = 0x001,
|
||||
KEY_TAB = 0x002,
|
||||
KEY_RETURN = 0x003,
|
||||
KEY_CONTROL = 0x004,
|
||||
KEY_ALT = 0x005,
|
||||
KEY_SHIFT = 0x006,
|
||||
KEY_PAUSE = 0x007,
|
||||
KEY_CAPSLOCK = 0x008,
|
||||
KEY_ESCAPE = 0x009,
|
||||
KEY_SPACE = 0x00a,
|
||||
KEY_PAGE_DOWN = 0x00b,
|
||||
KEY_PAGE_UP = 0x00c,
|
||||
KEY_END = 0x00d,
|
||||
KEY_HOME = 0x00e,
|
||||
KEY_LEFT = 0x00f,
|
||||
KEY_UP = 0x010,
|
||||
KEY_RIGHT = 0x011,
|
||||
KEY_DOWN = 0x012,
|
||||
KEY_PRINT = 0x013,
|
||||
KEY_INSERT = 0x014,
|
||||
KEY_DELETE = 0x015,
|
||||
KEY_HELP = 0x016,
|
||||
|
||||
KEY_0 = 0x017,
|
||||
KEY_1 = 0x018,
|
||||
KEY_2 = 0x019,
|
||||
KEY_3 = 0x01a,
|
||||
KEY_4 = 0x01b,
|
||||
KEY_5 = 0x01c,
|
||||
KEY_6 = 0x01d,
|
||||
KEY_7 = 0x01e,
|
||||
KEY_8 = 0x01f,
|
||||
KEY_9 = 0x020,
|
||||
|
||||
KEY_A = 0x021,
|
||||
KEY_B = 0x022,
|
||||
KEY_C = 0x023,
|
||||
KEY_D = 0x024,
|
||||
KEY_E = 0x025,
|
||||
KEY_F = 0x026,
|
||||
KEY_G = 0x027,
|
||||
KEY_H = 0x028,
|
||||
KEY_I = 0x029,
|
||||
KEY_J = 0x02a,
|
||||
KEY_K = 0x02b,
|
||||
KEY_L = 0x02c,
|
||||
KEY_M = 0x02d,
|
||||
KEY_N = 0x02e,
|
||||
KEY_O = 0x02f,
|
||||
KEY_P = 0x030,
|
||||
KEY_Q = 0x031,
|
||||
KEY_R = 0x032,
|
||||
KEY_S = 0x033,
|
||||
KEY_T = 0x034,
|
||||
KEY_U = 0x035,
|
||||
KEY_V = 0x036,
|
||||
KEY_W = 0x037,
|
||||
KEY_X = 0x038,
|
||||
KEY_Y = 0x039,
|
||||
KEY_Z = 0x03a,
|
||||
|
||||
KEY_TILDE = 0x03b,
|
||||
KEY_MINUS = 0x03c,
|
||||
KEY_EQUALS = 0x03d,
|
||||
KEY_LBRACKET = 0x03e,
|
||||
KEY_RBRACKET = 0x03f,
|
||||
KEY_BACKSLASH = 0x040,
|
||||
KEY_SEMICOLON = 0x041,
|
||||
KEY_APOSTROPHE = 0x042,
|
||||
KEY_COMMA = 0x043,
|
||||
KEY_PERIOD = 0x044,
|
||||
KEY_SLASH = 0x045,
|
||||
KEY_NUMPAD0 = 0x046,
|
||||
KEY_NUMPAD1 = 0x047,
|
||||
KEY_NUMPAD2 = 0x048,
|
||||
KEY_NUMPAD3 = 0x049,
|
||||
KEY_NUMPAD4 = 0x04a,
|
||||
KEY_NUMPAD5 = 0x04b,
|
||||
KEY_NUMPAD6 = 0x04c,
|
||||
KEY_NUMPAD7 = 0x04d,
|
||||
KEY_NUMPAD8 = 0x04e,
|
||||
KEY_NUMPAD9 = 0x04f,
|
||||
KEY_MULTIPLY = 0x050,
|
||||
KEY_ADD = 0x051,
|
||||
KEY_SEPARATOR = 0x052,
|
||||
KEY_SUBTRACT = 0x053,
|
||||
KEY_DECIMAL = 0x054,
|
||||
KEY_DIVIDE = 0x055,
|
||||
KEY_NUMPADENTER = 0x056,
|
||||
|
||||
KEY_F1 = 0x057,
|
||||
KEY_F2 = 0x058,
|
||||
KEY_F3 = 0x059,
|
||||
KEY_F4 = 0x05a,
|
||||
KEY_F5 = 0x05b,
|
||||
KEY_F6 = 0x05c,
|
||||
KEY_F7 = 0x05d,
|
||||
KEY_F8 = 0x05e,
|
||||
KEY_F9 = 0x05f,
|
||||
KEY_F10 = 0x060,
|
||||
KEY_F11 = 0x061,
|
||||
KEY_F12 = 0x062,
|
||||
KEY_F13 = 0x063,
|
||||
KEY_F14 = 0x064,
|
||||
KEY_F15 = 0x065,
|
||||
KEY_F16 = 0x066,
|
||||
KEY_F17 = 0x067,
|
||||
KEY_F18 = 0x068,
|
||||
KEY_F19 = 0x069,
|
||||
KEY_F20 = 0x06a,
|
||||
KEY_F21 = 0x06b,
|
||||
KEY_F22 = 0x06c,
|
||||
KEY_F23 = 0x06d,
|
||||
KEY_F24 = 0x06e,
|
||||
|
||||
KEY_NUMLOCK = 0x06f,
|
||||
KEY_SCROLLLOCK = 0x070,
|
||||
KEY_LCONTROL = 0x071,
|
||||
KEY_RCONTROL = 0x072,
|
||||
KEY_LALT = 0x073,
|
||||
KEY_RALT = 0x074,
|
||||
KEY_LSHIFT = 0x075,
|
||||
KEY_RSHIFT = 0x076,
|
||||
KEY_WIN_LWINDOW = 0x077,
|
||||
KEY_WIN_RWINDOW = 0x078,
|
||||
KEY_WIN_APPS = 0x079,
|
||||
KEY_OEM_102 = 0x080,
|
||||
|
||||
KEY_MAC_OPT = 0x090,
|
||||
KEY_MAC_LOPT = 0x091,
|
||||
KEY_MAC_ROPT = 0x092,
|
||||
|
||||
KEY_BUTTON0 = 0x0100,
|
||||
KEY_BUTTON1 = 0x0101,
|
||||
KEY_BUTTON2 = 0x0102,
|
||||
KEY_BUTTON3 = 0x0103,
|
||||
KEY_BUTTON4 = 0x0104,
|
||||
KEY_BUTTON5 = 0x0105,
|
||||
KEY_BUTTON6 = 0x0106,
|
||||
KEY_BUTTON7 = 0x0107,
|
||||
KEY_BUTTON8 = 0x0108,
|
||||
KEY_BUTTON9 = 0x0109,
|
||||
KEY_BUTTON10 = 0x010A,
|
||||
KEY_BUTTON11 = 0x010B,
|
||||
KEY_BUTTON12 = 0x010C,
|
||||
KEY_BUTTON13 = 0x010D,
|
||||
KEY_BUTTON14 = 0x010E,
|
||||
KEY_BUTTON15 = 0x010F,
|
||||
KEY_BUTTON16 = 0x0110,
|
||||
KEY_BUTTON17 = 0x0111,
|
||||
KEY_BUTTON18 = 0x0112,
|
||||
KEY_BUTTON19 = 0x0113,
|
||||
KEY_BUTTON20 = 0x0114,
|
||||
KEY_BUTTON21 = 0x0115,
|
||||
KEY_BUTTON22 = 0x0116,
|
||||
KEY_BUTTON23 = 0x0117,
|
||||
KEY_BUTTON24 = 0x0118,
|
||||
KEY_BUTTON25 = 0x0119,
|
||||
KEY_BUTTON26 = 0x011A,
|
||||
KEY_BUTTON27 = 0x011B,
|
||||
KEY_BUTTON28 = 0x011C,
|
||||
KEY_BUTTON29 = 0x011D,
|
||||
KEY_BUTTON30 = 0x011E,
|
||||
KEY_BUTTON31 = 0x011F,
|
||||
KEY_ANYKEY = 0xfffe
|
||||
};
|
||||
|
||||
/// Joystick event codes.
|
||||
enum JoystickCodes {
|
||||
SI_XPOV = 0x204,
|
||||
SI_YPOV = 0x205,
|
||||
SI_UPOV = 0x206,
|
||||
SI_DPOV = 0x207,
|
||||
SI_LPOV = 0x208,
|
||||
SI_RPOV = 0x209,
|
||||
SI_XAXIS = 0x20B,
|
||||
SI_YAXIS = 0x20C,
|
||||
SI_ZAXIS = 0x20D,
|
||||
SI_RXAXIS = 0x20E,
|
||||
SI_RYAXIS = 0x20F,
|
||||
SI_RZAXIS = 0x210,
|
||||
SI_SLIDER = 0x211,
|
||||
SI_XPOV2 = 0x212,
|
||||
SI_YPOV2 = 0x213,
|
||||
SI_UPOV2 = 0x214,
|
||||
SI_DPOV2 = 0x215,
|
||||
SI_LPOV2 = 0x216,
|
||||
SI_RPOV2 = 0x217
|
||||
};
|
||||
|
||||
/// Input device types
|
||||
enum InputDeviceTypes
|
||||
{
|
||||
UnknownDeviceType,
|
||||
MouseDeviceType,
|
||||
KeyboardDeviceType,
|
||||
JoystickDeviceType
|
||||
};
|
||||
|
||||
/// Device Event Action Types
|
||||
#define SI_MAKE 0x01
|
||||
#define SI_BREAK 0x02
|
||||
#define SI_MOVE 0x03
|
||||
#define SI_REPEAT 0x04
|
||||
|
||||
///Device Event Types
|
||||
#define SI_UNKNOWN 0x01
|
||||
#define SI_BUTTON 0x02
|
||||
#define SI_POV 0x03
|
||||
#define SI_KEY 0x0A
|
||||
#define SI_TEXT 0x10
|
||||
|
||||
/// Event SubTypes
|
||||
#define SI_ANY 0xff
|
||||
|
||||
// Modifier Keys
|
||||
/// shift and ctrl are the same between platforms.
|
||||
#define SI_LSHIFT (1<<0)
|
||||
#define SI_RSHIFT (1<<1)
|
||||
#define SI_SHIFT (SI_LSHIFT|SI_RSHIFT)
|
||||
#define SI_LCTRL (1<<2)
|
||||
#define SI_RCTRL (1<<3)
|
||||
#define SI_CTRL (SI_LCTRL|SI_RCTRL)
|
||||
/// win altkey, mapped to mac cmdkey.
|
||||
#define SI_LALT (1<<4)
|
||||
#define SI_RALT (1<<5)
|
||||
#define SI_ALT (SI_LALT|SI_RALT)
|
||||
/// mac optionkey
|
||||
#define SI_MAC_LOPT (1<<6)
|
||||
#define SI_MAC_ROPT (1<<7)
|
||||
#define SI_MAC_OPT (SI_MAC_LOPT|SI_MAC_ROPT)
|
||||
|
||||
/// @}
|
||||
|
||||
#endif
|
263
engine/platform/gameInterface.cc
Executable file
263
engine/platform/gameInterface.cc
Executable file
@ -0,0 +1,263 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "platform/platform.h"
|
||||
#include "platform/event.h"
|
||||
#include "platform/gameInterface.h"
|
||||
#include "core/fileStream.h"
|
||||
#include "console/console.h"
|
||||
#include "platform/platformMutex.h"
|
||||
|
||||
GameInterface *Game = NULL;
|
||||
void *gGameEventQueueMutex;
|
||||
|
||||
GameInterface::GameInterface()
|
||||
{
|
||||
AssertFatal(Game == NULL, "ERROR: Multiple games declared.");
|
||||
Game = this;
|
||||
mJournalMode = JournalOff;
|
||||
mRunning = true;
|
||||
mRequiresRestart = false;
|
||||
if(!gGameEventQueueMutex)
|
||||
gGameEventQueueMutex = Mutex::createMutex();
|
||||
eventQueue = &eventQueue1;
|
||||
}
|
||||
|
||||
int GameInterface::main(int, const char**)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
void GameInterface::textureKill()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GameInterface::textureResurrect()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GameInterface::refreshWindow()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static U32 sReentrantCount = 0;
|
||||
|
||||
void GameInterface::processEvent(Event *event)
|
||||
{
|
||||
if(!mRunning)
|
||||
return;
|
||||
|
||||
if(PlatformAssert::processingAssert()) // ignore any events if an assert dialog is up.
|
||||
return;
|
||||
|
||||
#ifdef TORQUE_DEBUG
|
||||
sReentrantCount++;
|
||||
AssertFatal(sReentrantCount == 1, "Error! ProcessEvent is NOT reentrant.");
|
||||
#endif
|
||||
|
||||
switch(event->type)
|
||||
{
|
||||
case PacketReceiveEventType:
|
||||
processPacketReceiveEvent((PacketReceiveEvent *) event);
|
||||
break;
|
||||
case MouseMoveEventType:
|
||||
processMouseMoveEvent((MouseMoveEvent *) event);
|
||||
break;
|
||||
case InputEventType:
|
||||
processInputEvent((InputEvent *) event);
|
||||
break;
|
||||
case QuitEventType:
|
||||
processQuitEvent();
|
||||
break;
|
||||
case TimeEventType:
|
||||
processTimeEvent((TimeEvent *) event);
|
||||
break;
|
||||
case ConsoleEventType:
|
||||
processConsoleEvent((ConsoleEvent *) event);
|
||||
break;
|
||||
case ConnectedAcceptEventType:
|
||||
processConnectedAcceptEvent( (ConnectedAcceptEvent *) event );
|
||||
break;
|
||||
case ConnectedReceiveEventType:
|
||||
processConnectedReceiveEvent( (ConnectedReceiveEvent *) event );
|
||||
break;
|
||||
case ConnectedNotifyEventType:
|
||||
processConnectedNotifyEvent( (ConnectedNotifyEvent *) event );
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef TORQUE_DEBUG
|
||||
sReentrantCount--;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GameInterface::processPacketReceiveEvent(PacketReceiveEvent*)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GameInterface::processMouseMoveEvent(MouseMoveEvent*)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GameInterface::processInputEvent(InputEvent*)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GameInterface::processQuitEvent()
|
||||
{
|
||||
}
|
||||
|
||||
void GameInterface::processTimeEvent(TimeEvent*)
|
||||
{
|
||||
}
|
||||
|
||||
void GameInterface::processConsoleEvent(ConsoleEvent*)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GameInterface::processConnectedAcceptEvent(ConnectedAcceptEvent*)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GameInterface::processConnectedReceiveEvent(ConnectedReceiveEvent*)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GameInterface::processConnectedNotifyEvent(ConnectedNotifyEvent*)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
struct ReadEvent : public Event
|
||||
{
|
||||
U8 data[3072];
|
||||
};
|
||||
|
||||
FileStream gJournalStream;
|
||||
|
||||
void GameInterface::postEvent(Event &event)
|
||||
{
|
||||
if(mJournalMode == JournalPlay && event.type != QuitEventType)
|
||||
return;
|
||||
|
||||
// Only one thread can post at a time.
|
||||
Mutex::lockMutex(gGameEventQueueMutex);
|
||||
|
||||
if(mJournalMode == JournalSave)
|
||||
{
|
||||
gJournalStream.write(event.size, &event);
|
||||
gJournalStream.flush();
|
||||
}
|
||||
|
||||
// Create a deep copy of event, and save a pointer to the copy in a vector.
|
||||
Event* copy = (Event*)dMalloc(event.size);
|
||||
dMemcpy(copy, &event, event.size);
|
||||
eventQueue->push_back(copy);
|
||||
|
||||
Mutex::unlockMutex(gGameEventQueueMutex);
|
||||
}
|
||||
|
||||
void GameInterface::processEvents()
|
||||
{
|
||||
// We want to lock the queue when processing as well - don't need
|
||||
// anyone putting new events in the middle of this.
|
||||
// We double-buffer the event queues so we'll block the other thread(s) for
|
||||
// a minimum amount of time.
|
||||
Mutex::lockMutex(gGameEventQueueMutex);
|
||||
// swap event queue pointers
|
||||
Vector<Event*> &fullEventQueue = *eventQueue;
|
||||
if(eventQueue == &eventQueue1)
|
||||
eventQueue = &eventQueue2;
|
||||
else
|
||||
eventQueue = &eventQueue1;
|
||||
Mutex::unlockMutex(gGameEventQueueMutex);
|
||||
|
||||
// Walk the event queue in fifo order, processing the events, then clear the queue.
|
||||
for(int i=0; i < fullEventQueue.size(); i++)
|
||||
{
|
||||
Game->processEvent(fullEventQueue[i]);
|
||||
dFree(fullEventQueue[i]);
|
||||
}
|
||||
fullEventQueue.clear();
|
||||
|
||||
}
|
||||
|
||||
void GameInterface::journalProcess()
|
||||
{
|
||||
if(mJournalMode == JournalPlay)
|
||||
{
|
||||
ReadEvent journalReadEvent;
|
||||
// used to be:
|
||||
// if(gJournalStream.read(&journalReadEvent.type))
|
||||
// if(gJournalStream.read(&journalReadEvent.size))
|
||||
// for proper non-endian stream handling, the read-ins should match the write-out by using bytestreams read:
|
||||
if(gJournalStream.read(sizeof(Event), &journalReadEvent))
|
||||
{
|
||||
if(gJournalStream.read(journalReadEvent.size - sizeof(Event), &journalReadEvent.data))
|
||||
{
|
||||
if(gJournalStream.getPosition() == gJournalStream.getStreamSize() && mJournalBreak)
|
||||
Platform::debugBreak();
|
||||
processEvent(&journalReadEvent);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// JournalBreak is used for debugging, so halt all game
|
||||
// events if we get this far.
|
||||
if(mJournalBreak)
|
||||
mRunning = false;
|
||||
else
|
||||
mJournalMode = JournalOff;
|
||||
}
|
||||
}
|
||||
|
||||
void GameInterface::saveJournal(const char *fileName)
|
||||
{
|
||||
mJournalMode = JournalSave;
|
||||
gJournalStream.open(fileName, FileStream::Write);
|
||||
}
|
||||
|
||||
void GameInterface::playJournal(const char *fileName,bool journalBreak)
|
||||
{
|
||||
mJournalMode = JournalPlay;
|
||||
mJournalBreak = journalBreak;
|
||||
gJournalStream.open(fileName, FileStream::Read);
|
||||
}
|
||||
|
||||
FileStream *GameInterface::getJournalStream()
|
||||
{
|
||||
return &gJournalStream;
|
||||
}
|
||||
|
||||
void GameInterface::journalRead(U32 *val)
|
||||
{
|
||||
gJournalStream.read(val);
|
||||
}
|
||||
|
||||
void GameInterface::journalWrite(U32 val)
|
||||
{
|
||||
gJournalStream.write(val);
|
||||
}
|
||||
|
||||
void GameInterface::journalRead(U32 size, void *buffer)
|
||||
{
|
||||
gJournalStream.read(size, buffer);
|
||||
}
|
||||
|
||||
void GameInterface::journalWrite(U32 size, const void *buffer)
|
||||
{
|
||||
gJournalStream.write(size, buffer);
|
||||
}
|
||||
|
132
engine/platform/gameInterface.h
Executable file
132
engine/platform/gameInterface.h
Executable file
@ -0,0 +1,132 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _GAMEINTERFACE_H_
|
||||
#define _GAMEINTERFACE_H_
|
||||
|
||||
#include "platform/event.h"
|
||||
#include "core/tVector.h"
|
||||
|
||||
class FileStream;
|
||||
|
||||
class GameInterface
|
||||
{
|
||||
enum JournalMode {
|
||||
JournalOff,
|
||||
JournalSave,
|
||||
JournalPlay,
|
||||
};
|
||||
JournalMode mJournalMode;
|
||||
bool mRunning;
|
||||
bool mJournalBreak;
|
||||
bool mRequiresRestart;
|
||||
|
||||
/// Events are stored here by any thread, for processing by the main thread.
|
||||
Vector<Event*> eventQueue1, eventQueue2, *eventQueue;
|
||||
|
||||
public:
|
||||
GameInterface();
|
||||
|
||||
/// @name Platform Interface
|
||||
/// The platform calls these functions to control execution of the game.
|
||||
/// @{
|
||||
virtual int main(int argc, const char **argv);
|
||||
virtual void textureKill();
|
||||
virtual void textureResurrect();
|
||||
virtual void refreshWindow();
|
||||
|
||||
/// Place an event in Game's event queue.
|
||||
virtual void postEvent(Event &event);
|
||||
/// Process all the events in Game's event queue. Only the main thread should call this.
|
||||
virtual void processEvents();
|
||||
/// @}
|
||||
|
||||
/// @name Event Handlers
|
||||
/// default event behavior with journaling support
|
||||
/// default handler forwards events to appropriate routines
|
||||
/// @{
|
||||
virtual void processEvent(Event *event);
|
||||
|
||||
virtual void processPacketReceiveEvent(PacketReceiveEvent *event);
|
||||
virtual void processMouseMoveEvent(MouseMoveEvent *event);
|
||||
virtual void processInputEvent(InputEvent *event);
|
||||
virtual void processQuitEvent();
|
||||
virtual void processTimeEvent(TimeEvent *event);
|
||||
virtual void processConsoleEvent(ConsoleEvent *event);
|
||||
virtual void processConnectedAcceptEvent(ConnectedAcceptEvent *event);
|
||||
virtual void processConnectedReceiveEvent(ConnectedReceiveEvent *event);
|
||||
virtual void processConnectedNotifyEvent(ConnectedNotifyEvent *event);
|
||||
/// @}
|
||||
|
||||
/// @name Running
|
||||
/// @{
|
||||
void setRunning(bool running) { mRunning = running; }
|
||||
bool isRunning() { return mRunning; }
|
||||
void setRestart( bool restart ) { mRequiresRestart = restart; }
|
||||
bool requiresRestart() { return mRequiresRestart; }
|
||||
/// @}
|
||||
|
||||
/// @name Journaling
|
||||
///
|
||||
/// Journaling is used in order to make a "demo" of the actual game. It logs
|
||||
/// all processes that happen throughout code execution (NOT script). This is
|
||||
/// very handy for debugging. Say an end user finds a crash in the program.
|
||||
/// The user can start up the engine with journal recording enabled, reproduce
|
||||
/// the crash, then send in the journal file to the development team. The
|
||||
/// development team can then play back the journal file and see exactly what
|
||||
/// happened to cause the crash. This will result in the ability to run the
|
||||
/// program through the debugger to easily track what went wrong and easily
|
||||
/// create a stack trace.
|
||||
///
|
||||
/// Actually enabling journaling may be different in different distributions
|
||||
/// if the developers decided to change how it works. However, by default,
|
||||
/// run the program with the "-jSave filename" command argument. The filename
|
||||
/// does not need an extension, and only requires write access. If the file
|
||||
/// does not exist, it will be created. In order to play back a journal,
|
||||
/// use the "-jPlay filename" command argument, and just watch the magic happen.
|
||||
/// Examples:
|
||||
/// @code
|
||||
/// torqueDemo_DEBUG.exe -jSave crash
|
||||
/// torqueDemo_DEBUG.exe -jPlay crash
|
||||
/// @endcode
|
||||
/// @{
|
||||
|
||||
/// If we're doing a journal playback, this function is responsible for reading
|
||||
/// events from the journal file and dispatching them.
|
||||
void journalProcess();
|
||||
|
||||
/// Start loading journal data from the specified file.
|
||||
void loadJournal(const char *fileName);
|
||||
|
||||
/// Start saving journal data to the specified file (must be able to write it).
|
||||
void saveJournal(const char *fileName);
|
||||
|
||||
/// Play back the specified journal.
|
||||
///
|
||||
/// @param fileName Journal file to play back.
|
||||
/// @param journalBreak Should we break execution after we're done?
|
||||
void playJournal(const char *fileName, bool journalBreak = false);
|
||||
|
||||
JournalMode getJournalMode() { return mJournalMode; };
|
||||
|
||||
/// Are we reading back from the journal?
|
||||
bool isJournalReading() { return mJournalMode == JournalPlay; }
|
||||
|
||||
/// Are we writing to the journal?
|
||||
bool isJournalWriting() { return mJournalMode == JournalSave; }
|
||||
|
||||
void journalRead(U32 *val); ///< Read a U32 from the journal.
|
||||
void journalWrite(U32 val); ///< Write a U32 to the journal.
|
||||
void journalRead(U32 size, void *buffer); ///< Read a block of data from the journal.
|
||||
void journalWrite(U32 size, const void *buffer);///< Write a block of data to the journal.
|
||||
|
||||
FileStream *getJournalStream();
|
||||
/// @}
|
||||
};
|
||||
|
||||
/// Global game instance.
|
||||
extern GameInterface *Game;
|
||||
|
||||
#endif
|
18
engine/platform/platform.cc
Executable file
18
engine/platform/platform.cc
Executable file
@ -0,0 +1,18 @@
|
||||
#include "platform/platform.h"
|
||||
#include "console/console.h"
|
||||
#include "console/consoleTypes.h"
|
||||
#include "platform/platformMutex.h"
|
||||
|
||||
S32 sgBackgroundSleepTime = 3000;
|
||||
S32 sgTimeManagerProcessInterval = 0;
|
||||
|
||||
void Platform::initConsole()
|
||||
{
|
||||
Con::addVariable("pref::backgroundSleepTime", TypeS32, &sgBackgroundSleepTime);
|
||||
Con::addVariable("pref::timeManagerProcessInterval", TypeS32, &sgTimeManagerProcessInterval);
|
||||
}
|
||||
|
||||
S32 Platform::getBackgroundSleepTime()
|
||||
{
|
||||
return sgBackgroundSleepTime;
|
||||
}
|
733
engine/platform/platform.h
Executable file
733
engine/platform/platform.h
Executable file
@ -0,0 +1,733 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORM_H_
|
||||
#define _PLATFORM_H_
|
||||
|
||||
#ifndef _TORQUECONFIG_H_
|
||||
# include "core/torqueConfig.h"
|
||||
#endif
|
||||
|
||||
#ifndef _TORQUE_TYPES_H_
|
||||
# include "platform/types.h"
|
||||
#endif
|
||||
|
||||
#ifndef _PLATFORMASSERT_H_
|
||||
# include "platform/platformAssert.h"
|
||||
#endif
|
||||
|
||||
//#define TORQUE_DISABLE_MEMORY_MANAGER
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Endian conversions
|
||||
#ifdef TORQUE_LITTLE_ENDIAN
|
||||
|
||||
inline U16 convertHostToLEndian(U16 i) { return i; }
|
||||
inline U16 convertLEndianToHost(U16 i) { return i; }
|
||||
inline U32 convertHostToLEndian(U32 i) { return i; }
|
||||
inline U32 convertLEndianToHost(U32 i) { return i; }
|
||||
inline S16 convertHostToLEndian(S16 i) { return i; }
|
||||
inline S16 convertLEndianToHost(S16 i) { return i; }
|
||||
inline S32 convertHostToLEndian(S32 i) { return i; }
|
||||
inline S32 convertLEndianToHost(S32 i) { return i; }
|
||||
|
||||
inline F32 convertHostToLEndian(F32 i) { return i; }
|
||||
inline F32 convertLEndianToHost(F32 i) { return i; }
|
||||
|
||||
inline F64 convertHostToLEndian(F64 i) { return i; }
|
||||
inline F64 convertLEndianToHost(F64 i) { return i; }
|
||||
|
||||
inline U16 convertHostToBEndian(U16 i)
|
||||
{
|
||||
return U16((i << 8) | (i >> 8));
|
||||
}
|
||||
|
||||
inline U16 convertBEndianToHost(U16 i)
|
||||
{
|
||||
return U16((i << 8) | (i >> 8));
|
||||
}
|
||||
|
||||
inline S16 convertHostToBEndian(S16 i)
|
||||
{
|
||||
return S16(convertHostToBEndian(U16(i)));
|
||||
}
|
||||
|
||||
inline S16 convertBEndianToHost(S16 i)
|
||||
{
|
||||
return S16(convertBEndianToHost(S16(i)));
|
||||
}
|
||||
|
||||
inline U32 convertHostToBEndian(U32 i)
|
||||
{
|
||||
return ((i << 24) & 0xff000000) |
|
||||
((i << 8) & 0x00ff0000) |
|
||||
((i >> 8) & 0x0000ff00) |
|
||||
((i >> 24) & 0x000000ff);
|
||||
}
|
||||
|
||||
inline U32 convertBEndianToHost(U32 i)
|
||||
{
|
||||
return ((i << 24) & 0xff000000) |
|
||||
((i << 8) & 0x00ff0000) |
|
||||
((i >> 8) & 0x0000ff00) |
|
||||
((i >> 24) & 0x000000ff);
|
||||
}
|
||||
|
||||
inline S32 convertHostToBEndian(S32 i)
|
||||
{
|
||||
return S32(convertHostToBEndian(U32(i)));
|
||||
}
|
||||
|
||||
inline S32 convertBEndianToHost(S32 i)
|
||||
{
|
||||
return S32(convertBEndianToHost(U32(i)));
|
||||
}
|
||||
|
||||
inline U64 convertBEndianToHost(U64 i)
|
||||
{
|
||||
U32 *inp = (U32 *) &i;
|
||||
U64 ret;
|
||||
U32 *outp = (U32 *) &ret;
|
||||
outp[0] = convertBEndianToHost(inp[1]);
|
||||
outp[1] = convertBEndianToHost(inp[0]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline U64 convertHostToBEndian(U64 i)
|
||||
{
|
||||
U32 *inp = (U32 *) &i;
|
||||
U64 ret;
|
||||
U32 *outp = (U32 *) &ret;
|
||||
outp[0] = convertHostToBEndian(inp[1]);
|
||||
outp[1] = convertHostToBEndian(inp[0]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline F64 convertBEndianToHost(F64 in_swap)
|
||||
{
|
||||
U64 result = convertBEndianToHost(* ((U64 *) &in_swap) );
|
||||
return * ((F64 *) &result);
|
||||
}
|
||||
|
||||
inline F64 convertHostToBEndian(F64 in_swap)
|
||||
{
|
||||
U64 result = convertHostToBEndian(* ((U64 *) &in_swap) );
|
||||
return * ((F64 *) &result);
|
||||
}
|
||||
|
||||
#elif defined(TORQUE_BIG_ENDIAN)
|
||||
|
||||
inline U16 convertHostToBEndian(U16 i) { return i; }
|
||||
inline U16 convertBEndianToHost(U16 i) { return i; }
|
||||
inline U32 convertHostToBEndian(U32 i) { return i; }
|
||||
inline U32 convertBEndianToHost(U32 i) { return i; }
|
||||
inline S16 convertHostToBEndian(S16 i) { return i; }
|
||||
inline S16 convertBEndianToHost(S16 i) { return i; }
|
||||
inline S32 convertHostToBEndian(S32 i) { return i; }
|
||||
inline S32 convertBEndianToHost(S32 i) { return i; }
|
||||
|
||||
inline U16 convertHostToLEndian(U16 i)
|
||||
{
|
||||
return (i << 8) | (i >> 8);
|
||||
}
|
||||
inline U16 convertLEndianToHost(U16 i)
|
||||
{
|
||||
return (i << 8) | (i >> 8);
|
||||
}
|
||||
inline U32 convertHostToLEndian(U32 i)
|
||||
{
|
||||
return ((i << 24) & 0xff000000) |
|
||||
((i << 8) & 0x00ff0000) |
|
||||
((i >> 8) & 0x0000ff00) |
|
||||
((i >> 24) & 0x000000ff);
|
||||
}
|
||||
inline U32 convertLEndianToHost(U32 i)
|
||||
{
|
||||
return ((i << 24) & 0xff000000) |
|
||||
((i << 8) & 0x00ff0000) |
|
||||
((i >> 8) & 0x0000ff00) |
|
||||
((i >> 24) & 0x000000ff);
|
||||
}
|
||||
|
||||
inline U64 convertLEndianToHost(U64 i)
|
||||
{
|
||||
U32 *inp = (U32 *) &i;
|
||||
U64 ret;
|
||||
U32 *outp = (U32 *) &ret;
|
||||
outp[0] = convertLEndianToHost(inp[1]);
|
||||
outp[1] = convertLEndianToHost(inp[0]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline U64 convertHostToLEndian(U64 i)
|
||||
{
|
||||
U32 *inp = (U32 *) &i;
|
||||
U64 ret;
|
||||
U32 *outp = (U32 *) &ret;
|
||||
outp[0] = convertHostToLEndian(inp[1]);
|
||||
outp[1] = convertHostToLEndian(inp[0]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline F64 convertLEndianToHost(F64 in_swap)
|
||||
{
|
||||
U64 result = convertLEndianToHost(* ((U64 *) &in_swap) );
|
||||
return * ((F64 *) &result);
|
||||
}
|
||||
|
||||
inline F64 convertHostToLEndian(F64 in_swap)
|
||||
{
|
||||
U64 result = convertHostToLEndian(* ((U64 *) &in_swap) );
|
||||
return * ((F64 *) &result);
|
||||
}
|
||||
|
||||
inline F32 convertHostToLEndian(F32 i)
|
||||
{
|
||||
U32 result = convertHostToLEndian( *reinterpret_cast<U32*>(&i) );
|
||||
return *reinterpret_cast<F32*>(&result);
|
||||
}
|
||||
|
||||
inline F32 convertLEndianToHost(F32 i)
|
||||
{
|
||||
U32 result = convertLEndianToHost( *reinterpret_cast<U32*>(&i) );
|
||||
return *reinterpret_cast<F32*>(&result);
|
||||
}
|
||||
|
||||
inline S16 convertHostToLEndian(S16 i) { return S16(convertHostToLEndian(U16(i))); }
|
||||
inline S16 convertLEndianToHost(S16 i) { return S16(convertLEndianToHost(U16(i))); }
|
||||
inline S32 convertHostToLEndian(S32 i) { return S32(convertHostToLEndian(U32(i))); }
|
||||
inline S32 convertLEndianToHost(S32 i) { return S32(convertLEndianToHost(U32(i))); }
|
||||
|
||||
#else
|
||||
#error "Endian define not set"
|
||||
#endif
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Input structures and functions - all input is pushed into the input event queue
|
||||
template <class T> class Vector;
|
||||
class Point2I;
|
||||
|
||||
|
||||
// Theese emuns must be globally scoped so that they work
|
||||
// with the inline assembly
|
||||
enum ProcessorType
|
||||
{
|
||||
// x86
|
||||
CPU_X86Compatible,
|
||||
CPU_Intel_Unknown,
|
||||
CPU_Intel_486,
|
||||
CPU_Intel_Pentium,
|
||||
CPU_Intel_PentiumMMX,
|
||||
CPU_Intel_PentiumPro,
|
||||
CPU_Intel_PentiumII,
|
||||
CPU_Intel_PentiumCeleron,
|
||||
CPU_Intel_PentiumIII,
|
||||
CPU_Intel_Pentium4,
|
||||
CPU_AMD_K6,
|
||||
CPU_AMD_K6_2,
|
||||
CPU_AMD_K6_3,
|
||||
CPU_AMD_Athlon,
|
||||
CPU_AMD_Unknown,
|
||||
CPU_Cyrix_6x86,
|
||||
CPU_Cyrix_MediaGX,
|
||||
CPU_Cyrix_6x86MX,
|
||||
CPU_Cyrix_GXm, // Media GX w/ MMX
|
||||
CPU_Cyrix_Unknown,
|
||||
// PowerPC
|
||||
CPU_PowerPC_Unknown,
|
||||
CPU_PowerPC_601,
|
||||
CPU_PowerPC_603,
|
||||
CPU_PowerPC_603e,
|
||||
CPU_PowerPC_603ev,
|
||||
CPU_PowerPC_604,
|
||||
CPU_PowerPC_604e,
|
||||
CPU_PowerPC_604ev,
|
||||
CPU_PowerPC_G3,
|
||||
CPU_PowerPC_G4,
|
||||
CPU_PowerPC_G4_7450,
|
||||
CPU_PowerPC_G4_7455,
|
||||
CPU_PowerPC_G4_7447,
|
||||
CPU_PowerPC_G5
|
||||
};
|
||||
|
||||
enum x86Properties
|
||||
{ // x86 properties
|
||||
CPU_PROP_C = (1<<0),
|
||||
CPU_PROP_FPU = (1<<1),
|
||||
CPU_PROP_MMX = (1<<2), // Integer-SIMD
|
||||
CPU_PROP_3DNOW = (1<<3), // AMD Float-SIMD
|
||||
CPU_PROP_SSE = (1<<4), // PentiumIII SIMD
|
||||
CPU_PROP_RDTSC = (1<<5) // Read Time Stamp Counter
|
||||
// CPU_PROP_SSE2 = (1<<6), // Pentium4 SIMD
|
||||
// CPU_PROP_MP = (1<<7) // Multi-processor system
|
||||
};
|
||||
|
||||
enum PPCProperties
|
||||
{ // PowerPC properties
|
||||
CPU_PROP_PPCMIN = (1<<0),
|
||||
CPU_PROP_ALTIVEC = (1<<1), // Float-SIMD
|
||||
CPU_PROP_PPCMP = (1<<7) // Multi-processor system
|
||||
};
|
||||
|
||||
enum DriveType
|
||||
{
|
||||
DRIVETYPE_FIXED = 0,
|
||||
DRIVETYPE_REMOVABLE = 1,
|
||||
DRIVETYPE_REMOTE = 2,
|
||||
DRIVETYPE_CDROM = 3,
|
||||
DRIVETYPE_RAMDISK = 4,
|
||||
DRIVETYPE_UNKNOWN = 5
|
||||
};
|
||||
|
||||
struct Platform
|
||||
{
|
||||
static void sleep(U32 ms);
|
||||
static void init();
|
||||
static void initConsole();
|
||||
static void shutdown();
|
||||
static void process();
|
||||
static bool doCDCheck();
|
||||
static void initWindow(const Point2I &initialSize, const char *name);
|
||||
static void setWindowTitle( const char* title );
|
||||
static void enableKeyboardTranslation(void);
|
||||
static void disableKeyboardTranslation(void);
|
||||
static void setWindowLocked(bool locked);
|
||||
static void minimizeWindow();
|
||||
static bool excludeOtherInstances(const char *string);
|
||||
static bool checkOtherInstances(const char *string);
|
||||
static void restartInstance();
|
||||
|
||||
static const Point2I &getWindowSize();
|
||||
static void setWindowSize( U32 newWidth, U32 newHeight );
|
||||
static float getRandom();
|
||||
static void AlertOK(const char *windowTitle, const char *message);
|
||||
static bool AlertOKCancel(const char *windowTitle, const char *message);
|
||||
static bool AlertRetry(const char *windowTitle, const char *message);
|
||||
|
||||
struct LocalTime
|
||||
{
|
||||
U8 sec; // seconds after minute (0-59)
|
||||
U8 min; // Minutes after hour (0-59)
|
||||
U8 hour; // Hours after midnight (0-23)
|
||||
U8 month; // Month (0-11; 0=january)
|
||||
U8 monthday; // Day of the month (1-31)
|
||||
U8 weekday; // Day of the week (0-6, 6=sunday)
|
||||
U16 year; // current year minus 1900
|
||||
U16 yearday; // Day of year (0-365)
|
||||
bool isdst; // true if daylight savings time is active
|
||||
};
|
||||
|
||||
static void getLocalTime(LocalTime &);
|
||||
|
||||
struct FileInfo
|
||||
{
|
||||
const char* pFullPath;
|
||||
const char* pFileName;
|
||||
U32 fileSize;
|
||||
};
|
||||
static bool cdFileExists(const char *filePath, const char *volumeName, S32 serialNum);
|
||||
static void fileToLocalTime(const FileTime &ft, LocalTime *lt);
|
||||
// compare file times returns < 0 if a is earlier than b, >0 if b is earlier than a
|
||||
static S32 compareFileTimes(const FileTime &a, const FileTime &b);
|
||||
// Process control
|
||||
public:
|
||||
static void postQuitMessage(const U32 in_quitVal);
|
||||
static void debugBreak();
|
||||
static void forceShutdown(S32 returnValue);
|
||||
|
||||
static U32 getTime();
|
||||
static U32 getVirtualMilliseconds();
|
||||
static U32 getRealMilliseconds();
|
||||
static void advanceTime(U32 delta);
|
||||
|
||||
static S32 getBackgroundSleepTime();
|
||||
|
||||
// Directory functions. Dump path returns false iff the directory cannot be
|
||||
// opened.
|
||||
public:
|
||||
static StringTableEntry getWorkingDirectory();
|
||||
static StringTableEntry getExecutableName();
|
||||
static bool dumpPath(const char *in_pBasePath, Vector<FileInfo>& out_rFileVector, S32 recurseDepth = -1);
|
||||
static bool dumpDirectories( const char *path, Vector<StringTableEntry> &directoryVector, S32 depth = 0, bool noBasePath = false );
|
||||
static bool hasSubDirectory( const char *pPath );
|
||||
static bool getFileTimes(const char *filePath, FileTime *createTime, FileTime *modifyTime);
|
||||
static bool isFile(const char *pFilePath);
|
||||
static S32 getFileSize(const char *pFilePath);
|
||||
static bool isDirectory(const char *pDirPath);
|
||||
static bool isSubDirectory(const char *pParent, const char *pDir);
|
||||
|
||||
static void addExcludedDirectory(const char *pDir);
|
||||
static void clearExcludedDirectories();
|
||||
static bool isExcludedDirectory(const char *pDir);
|
||||
|
||||
struct VolumeInformation
|
||||
{
|
||||
StringTableEntry RootPath;
|
||||
StringTableEntry Name;
|
||||
StringTableEntry FileSystem;
|
||||
U32 SerialNumber;
|
||||
U32 Type;
|
||||
bool ReadOnly;
|
||||
}*PVolumeInformation;
|
||||
|
||||
// Volume functions.
|
||||
static void getVolumeNamesList( Vector<const char*>& out_rNameVector, bool bOnlyFixedDrives = false );
|
||||
static void getVolumeInformationList( Vector<VolumeInformation>& out_rVolumeInfoVector, bool bOnlyFixedDrives = false );
|
||||
|
||||
static bool createPath(const char *path); // create a directory path
|
||||
static struct SystemInfo_struct
|
||||
{
|
||||
struct Processor
|
||||
{
|
||||
ProcessorType type;
|
||||
const char *name;
|
||||
U32 mhz;
|
||||
U32 properties; // CPU type specific enum
|
||||
} processor;
|
||||
} SystemInfo;
|
||||
|
||||
// Web page launch function:
|
||||
static bool openWebBrowser( const char* webAddress );
|
||||
|
||||
static const char* getLoginPassword();
|
||||
static bool setLoginPassword( const char* password );
|
||||
|
||||
static const char* getClipboard();
|
||||
static bool setClipboard(const char *text);
|
||||
|
||||
static bool stringToFileTime(const char * string, FileTime * time);
|
||||
static bool fileTimeToString(FileTime * time, char * string, U32 strLen);
|
||||
};
|
||||
|
||||
|
||||
struct Processor
|
||||
{
|
||||
static void init();
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// time manager generates a ServerTimeEvent / ClientTimeEvent, FrameEvent combo
|
||||
// every other time its process is called.
|
||||
extern S32 sgTimeManagerProcessInterval;
|
||||
struct TimeManager
|
||||
{
|
||||
static void process();
|
||||
};
|
||||
|
||||
// the entry point of the app is in the platform code...
|
||||
// it calls out into game code at GameMain
|
||||
|
||||
// all input goes through the game input event queue
|
||||
// whether or not it is used (replaying a journal, etc)
|
||||
// is up to the game code. The game must copy the event data out.
|
||||
|
||||
struct Event;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// String functions
|
||||
|
||||
extern char* dStrcat(char *dst, const char *src);
|
||||
extern UTF8* dStrcat(UTF8 *dst, const UTF8 *src);
|
||||
|
||||
extern char* dStrncat(char* dst, const char* src, dsize_t len);
|
||||
extern char* dStrcatl(char *dst, dsize_t dstSize, ...);
|
||||
|
||||
extern int dStrcmp(const char *str1, const char *str2);
|
||||
extern int dStrcmp(const UTF16 *str1, const UTF16 *str2);
|
||||
extern int dStrcmp(const UTF8 *str1, const UTF8 *str2);
|
||||
|
||||
extern int dStricmp(const char *str1, const char *str2);
|
||||
extern int dStrncmp(const char *str1, const char *str2, dsize_t len);
|
||||
extern int dStrnicmp(const char *str1, const char *str2, dsize_t len);
|
||||
extern char* dStrcpy(char *dst, const char *src);
|
||||
|
||||
extern char* dStrcpyl(char *dst, dsize_t dstSize, ...);
|
||||
extern char* dStrncpy(char *dst, const char *src, dsize_t len);
|
||||
extern char* dStrncpy(UTF8 *dst, const UTF8 *src, dsize_t len);
|
||||
|
||||
extern dsize_t dStrlen(const char *str);
|
||||
|
||||
extern char* dStrupr(char *str);
|
||||
extern char* dStrlwr(char *str);
|
||||
extern char* dStrchr(char *str, int c);
|
||||
extern const char* dStrchr(const char *str, int c);
|
||||
extern char* dStrrchr(char *str, int c);
|
||||
extern const char* dStrrchr(const char *str, int c);
|
||||
extern dsize_t dStrspn(const char *str, const char *set);
|
||||
extern dsize_t dStrcspn(const char *str, const char *set);
|
||||
|
||||
extern char* dStrstr(char *str1, char *str2);
|
||||
extern char* dStrstr(const char *str1, const char *str2);
|
||||
|
||||
extern char* dStrtok(char *str, const char *sep);
|
||||
|
||||
extern int dAtoi(const char *str);
|
||||
extern float dAtof(const char *str);
|
||||
extern bool dAtob(const char *str);
|
||||
|
||||
extern void dPrintf(const char *format, ...);
|
||||
extern int dVprintf(const char *format, void *arglist);
|
||||
extern int dSprintf(char *buffer, dsize_t bufferSize, const char *format, ...);
|
||||
extern int dVsprintf(char *buffer, dsize_t bufferSize, const char *format, void *arglist);
|
||||
extern int dSscanf(const char *buffer, const char *format, ...);
|
||||
extern int dFflushStdout();
|
||||
extern int dFflushStderr();
|
||||
|
||||
inline char dToupper(const char c) { if (c >= char('a') && c <= char('z')) return char(c + 'A' - 'a'); else return c; }
|
||||
inline char dTolower(const char c) { if (c >= char('A') && c <= char('Z')) return char(c - 'A' + 'a'); else return c; }
|
||||
|
||||
extern bool dIsalnum(const char c);
|
||||
extern bool dIsalpha(const char c);
|
||||
extern bool dIsdigit(const char c);
|
||||
extern bool dIsspace(const char c);
|
||||
//------------------------------------------------------------------------------
|
||||
// Unicode string conversions
|
||||
|
||||
//extern UTF8 * convertUTF16toUTF8(const UTF16 *string, UTF8 *buffer, U32 bufsize);
|
||||
//extern UTF16 * convertUTF8toUTF16(const UTF8 *string, UTF16 *buffer, U32 bufsize);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// \brief Get the first character of a UTF-8 string as a UTF-16 character
|
||||
///
|
||||
/// \param string UTF-8 string
|
||||
/// \return First character of string as a UTF-16 character
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//extern UTF16 getFirstUTF8Char(const UTF8 *string);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// \brief Obtain a pointer to the start of the next UTF-8 character in the string
|
||||
///
|
||||
/// As UTF-8 characters can span multiple bytes, you can't scan the string
|
||||
/// in the same way you would an ANSI string. getNextUTF8Char() is intended
|
||||
///
|
||||
/// This still works if ptr points to the middle of a character.
|
||||
///
|
||||
/// \param ptr Pointer to last character or start of string
|
||||
/// \return Pointer to next UTF-8 character in the string or NULL for end of string.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//extern const UTF8 *getNextUTF8Char(const UTF8 *ptr);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// \brief Obtain a pointer to the start of the Nth UTF-8 character in the string
|
||||
///
|
||||
/// As UTF-8 characters can span multiple bytes, you can't scan the string
|
||||
/// in the same way you would an ANSI string. This allows you to quickly
|
||||
/// skip to the appropriate place in the string.
|
||||
///
|
||||
/// This still works if ptr points to the middle of a character.
|
||||
///
|
||||
/// \param ptr Pointer to last character or start of string
|
||||
/// \return Pointer to Nth UTF-8 character in the string or NULL for end of string.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//extern const UTF8 *getNextUTF8Char(const UTF8 *ptr, const U32 n);
|
||||
|
||||
// UNICODE is a windows platform API switching flag. Don't define it on other platforms.
|
||||
#ifdef UNICODE
|
||||
#define dT(s) L##s
|
||||
#else
|
||||
#define dT(s) s
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Misc StdLib functions
|
||||
|
||||
|
||||
#define QSORT_CALLBACK FN_CDECL
|
||||
void dQsort(void *base, U32 nelem, U32 width, int (QSORT_CALLBACK *fcmp)(const void *, const void *));
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// ConsoleObject GetClassNameFn
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Memory functions
|
||||
namespace Memory
|
||||
{
|
||||
dsize_t getMemoryUsed();
|
||||
dsize_t getMemoryAllocated();
|
||||
void validate();
|
||||
} // namespace Memory
|
||||
|
||||
extern void* FN_CDECL operator new(dsize_t size, void* ptr);
|
||||
|
||||
template <class T>
|
||||
inline T* constructInPlace(T* p)
|
||||
{
|
||||
return new(p) T;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T* constructInPlace(T* p, const T* copy)
|
||||
{
|
||||
return new(p) T(*copy);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void destructInPlace(T* p)
|
||||
{
|
||||
p->~T();
|
||||
}
|
||||
|
||||
#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
|
||||
extern void* FN_CDECL operator new(dsize_t size, const char*, const U32);
|
||||
extern void* FN_CDECL operator new[](dsize_t size, const char*, const U32);
|
||||
extern void FN_CDECL operator delete(void* ptr);
|
||||
extern void FN_CDECL operator delete[](void* ptr);
|
||||
#define new new(__FILE__, __LINE__)
|
||||
#endif
|
||||
|
||||
#define placenew(x) new(x)
|
||||
#define dMalloc(x) dMalloc_r(x, __FILE__, __LINE__)
|
||||
#define dStrdup(x) dStrdup_r(x, __FILE__, __LINE__)
|
||||
|
||||
extern char* dStrdup_r(const char *src, const char*, dsize_t);
|
||||
|
||||
extern void setBreakAlloc(dsize_t);
|
||||
extern void setMinimumAllocUnit(U32);
|
||||
extern void* dMalloc_r(dsize_t in_size, const char*, const dsize_t);
|
||||
extern void dFree(void* in_pFree);
|
||||
extern void* dRealloc(void* in_pResize, dsize_t in_size);
|
||||
extern void* dRealMalloc(dsize_t);
|
||||
extern void dRealFree(void*);
|
||||
|
||||
extern void* dMemcpy(void *dst, const void *src, dsize_t size);
|
||||
extern void* dMemmove(void *dst, const void *src, dsize_t size);
|
||||
extern void* dMemset(void *dst, int c, dsize_t size);
|
||||
extern int dMemcmp(const void *ptr1, const void *ptr2, dsize_t size);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Graphics functions
|
||||
|
||||
// Charsets for fonts
|
||||
|
||||
// [tom, 7/27/2005] These are intended to map to their Win32 equivalents. This
|
||||
// enumeration may require changes to accommodate other platforms.
|
||||
enum FontCharset
|
||||
{
|
||||
TGE_ANSI_CHARSET = 0,
|
||||
TGE_SYMBOL_CHARSET,
|
||||
TGE_SHIFTJIS_CHARSET,
|
||||
TGE_HANGEUL_CHARSET,
|
||||
TGE_HANGUL_CHARSET,
|
||||
TGE_GB2312_CHARSET,
|
||||
TGE_CHINESEBIG5_CHARSET,
|
||||
TGE_OEM_CHARSET,
|
||||
TGE_JOHAB_CHARSET,
|
||||
TGE_HEBREW_CHARSET,
|
||||
TGE_ARABIC_CHARSET,
|
||||
TGE_GREEK_CHARSET,
|
||||
TGE_TURKISH_CHARSET,
|
||||
TGE_VIETNAMESE_CHARSET,
|
||||
TGE_THAI_CHARSET,
|
||||
TGE_EASTEUROPE_CHARSET,
|
||||
TGE_RUSSIAN_CHARSET,
|
||||
TGE_MAC_CHARSET,
|
||||
TGE_BALTIC_CHARSET
|
||||
};
|
||||
|
||||
class GOldFont;
|
||||
extern GOldFont *createFont(const char *name, dsize_t size, U32 charset = TGE_ANSI_CHARSET);
|
||||
const char *getCharSetName(const U32 charSet);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// FileIO functions
|
||||
typedef void* FILE_HANDLE;
|
||||
enum DFILE_STATUS
|
||||
{
|
||||
DFILE_OK = 1
|
||||
};
|
||||
|
||||
extern bool dFileDelete(const char *name);
|
||||
extern bool dFileTouch(const char *name);
|
||||
extern bool dPathCopy(const char *fromName, const char *toName, bool nooverwrite = true);
|
||||
|
||||
extern FILE_HANDLE dOpenFileRead(const char *name, DFILE_STATUS &error);
|
||||
extern FILE_HANDLE dOpenFileReadWrite(const char *name, bool append, DFILE_STATUS &error);
|
||||
extern int dFileRead(FILE_HANDLE handle, U32 bytes, char *dst, DFILE_STATUS &error);
|
||||
extern int dFileWrite(FILE_HANDLE handle, U32 bytes, const char *dst, DFILE_STATUS &error);
|
||||
extern void dFileClose(FILE_HANDLE handle);
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Math
|
||||
struct Math
|
||||
{
|
||||
static void init(U32 properties = 0); // 0 == detect available hardware
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Networking
|
||||
struct NetAddress;
|
||||
|
||||
typedef S32 NetSocket;
|
||||
const NetSocket InvalidSocket = -1;
|
||||
|
||||
struct Net
|
||||
{
|
||||
enum Error
|
||||
{
|
||||
NoError,
|
||||
WrongProtocolType,
|
||||
InvalidPacketProtocol,
|
||||
WouldBlock,
|
||||
NotASocket,
|
||||
UnknownError
|
||||
};
|
||||
|
||||
enum Protocol
|
||||
{
|
||||
UDPProtocol,
|
||||
IPXProtocol,
|
||||
TCPProtocol
|
||||
};
|
||||
|
||||
static bool init();
|
||||
static void shutdown();
|
||||
|
||||
// Unreliable net functions (UDP)
|
||||
// sendto is for sending data
|
||||
// all incoming data comes in on packetReceiveEventType
|
||||
// App can only open one unreliable port... who needs more? ;)
|
||||
static bool openPort(S32 connectPort);
|
||||
static void closePort();
|
||||
static Error sendto(const NetAddress *address, const U8 *buffer, S32 bufferSize);
|
||||
|
||||
// Reliable net functions (TCP)
|
||||
// all incoming messages come in on the Connected* events
|
||||
static NetSocket openListenPort(U16 port);
|
||||
static NetSocket openConnectTo(const char *stringAddress); // does the DNS resolve etc.
|
||||
static void closeConnectTo(NetSocket socket);
|
||||
static Error sendtoSocket(NetSocket socket, const U8 *buffer, S32 bufferSize);
|
||||
|
||||
static void process();
|
||||
|
||||
static bool compareAddresses(const NetAddress *a1, const NetAddress *a2);
|
||||
static bool stringToAddress(const char *addressString, NetAddress *address);
|
||||
static void addressToString(const NetAddress *address, char addressString[256]);
|
||||
|
||||
// lower level socked based network functions
|
||||
static NetSocket openSocket();
|
||||
static Error closeSocket(NetSocket socket);
|
||||
|
||||
static Error connect(NetSocket socket, const NetAddress *address);
|
||||
static Error listen(NetSocket socket, S32 maxConcurrentListens);
|
||||
static NetSocket accept(NetSocket acceptSocket, NetAddress *remoteAddress);
|
||||
|
||||
static Error bind(NetSocket socket, U16 port);
|
||||
static Error setBufferSize(NetSocket socket, S32 bufferSize);
|
||||
static Error setBroadcast(NetSocket socket, bool broadcastEnable);
|
||||
static Error setBlocking(NetSocket socket, bool blockingIO);
|
||||
|
||||
static Error send(NetSocket socket, const U8 *buffer, S32 bufferSize);
|
||||
static Error recv(NetSocket socket, U8 *buffer, S32 bufferSize, S32 *bytesRead);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
50
engine/platform/platformAL.h
Executable file
50
engine/platform/platformAL.h
Executable file
@ -0,0 +1,50 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORMAL_H_
|
||||
#define _PLATFORMAL_H_
|
||||
|
||||
#ifndef _PLATFORM_H_
|
||||
#include "platform/platform.h"
|
||||
#endif
|
||||
|
||||
#if defined(TORQUE_OS_MAC)
|
||||
#include "OpenAL/al.h"
|
||||
#include "OpenAL/alc.h"
|
||||
#include "OpenAL/altypes.h"
|
||||
#include "OpenAL/alctypes.h"
|
||||
#include "OpenAL/eaxtypes.h"
|
||||
#else
|
||||
// declare externs of the AL fns here.
|
||||
#include "al/altypes.h"
|
||||
#include "al/alctypes.h"
|
||||
#include "al/eaxtypes.h"
|
||||
#define AL_FUNCTION(fn_return,fn_name,fn_args, fn_value) extern fn_return (FN_CDECL *fn_name)fn_args;
|
||||
#include "al/al_func.h"
|
||||
#include "al/alc_func.h"
|
||||
#include "al/eax_func.h"
|
||||
#undef AL_FUNCTION
|
||||
#endif
|
||||
|
||||
namespace Audio
|
||||
{
|
||||
|
||||
bool OpenALInit();
|
||||
void OpenALShutdown();
|
||||
|
||||
bool OpenALDLLInit();
|
||||
void OpenALDLLShutdown();
|
||||
|
||||
// special alx flags
|
||||
#define AL_GAIN_LINEAR 0xFF01
|
||||
|
||||
// helpers
|
||||
F32 DBToLinear(F32 value);
|
||||
F32 linearToDB(F32 value);
|
||||
|
||||
} // end namespace Audio
|
||||
|
||||
|
||||
#endif // _H_PLATFORMAL_
|
133
engine/platform/platformAssert.cc
Executable file
133
engine/platform/platformAssert.cc
Executable file
@ -0,0 +1,133 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "platform/platformAssert.h"
|
||||
#include "console/console.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
//-------------------------------------- STATIC Declaration
|
||||
PlatformAssert *PlatformAssert::platformAssert = NULL;
|
||||
|
||||
//--------------------------------------
|
||||
PlatformAssert::PlatformAssert()
|
||||
{
|
||||
processing = false;
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
PlatformAssert::~PlatformAssert()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
void PlatformAssert::create( PlatformAssert* newAssertClass )
|
||||
{
|
||||
if (!platformAssert)
|
||||
platformAssert = newAssertClass ? newAssertClass : new PlatformAssert;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
void PlatformAssert::destroy()
|
||||
{
|
||||
if (platformAssert)
|
||||
delete platformAssert;
|
||||
platformAssert = NULL;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
bool PlatformAssert::displayMessageBox(const char *title, const char *message, bool retry)
|
||||
{
|
||||
if (retry)
|
||||
return Platform::AlertRetry(title, message);
|
||||
|
||||
Platform::AlertOK(title, message);
|
||||
return false;
|
||||
}
|
||||
|
||||
static char *typeName[] = { "Unknown", "Fatal-ISV", "Fatal", "Warning" };
|
||||
|
||||
//--------------------------------------
|
||||
|
||||
bool PlatformAssert::process(Type assertType,
|
||||
const char *filename,
|
||||
U32 lineNumber,
|
||||
const char *message)
|
||||
{
|
||||
// If we're somehow recursing, just die.
|
||||
if(processing)
|
||||
Platform::debugBreak();
|
||||
|
||||
processing = true;
|
||||
|
||||
// always dump to the Assert to the Console
|
||||
if (Con::isActive())
|
||||
{
|
||||
if (assertType == Warning)
|
||||
Con::warnf(ConsoleLogEntry::Assert, "%s: (%s @ %ld) %s", typeName[assertType], filename, lineNumber, message);
|
||||
else
|
||||
Con::errorf(ConsoleLogEntry::Assert, "%s: (%s @ %ld) %s", typeName[assertType], filename, lineNumber, message);
|
||||
}
|
||||
|
||||
// if not a WARNING pop-up a dialog box
|
||||
if (assertType != Warning)
|
||||
{
|
||||
// used for processing navGraphs (an assert won't botch the whole build)
|
||||
if(Con::getBoolVariable("$FP::DisableAsserts", false) == true)
|
||||
Platform::forceShutdown(1);
|
||||
|
||||
char buffer[2048];
|
||||
dSprintf(buffer, 2048, "%s: (%s @ %ld)", typeName[assertType], filename, lineNumber);
|
||||
|
||||
#ifdef TORQUE_DEBUG
|
||||
// In debug versions, allow a retry even for ISVs...
|
||||
bool retry = displayMessageBox(buffer, message, true);
|
||||
#else
|
||||
bool retry = displayMessageBox(buffer, message, ((assertType == Fatal) ? true : false) );
|
||||
#endif
|
||||
if (retry)
|
||||
Platform::debugBreak();
|
||||
else
|
||||
Platform::forceShutdown(1);
|
||||
}
|
||||
processing = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PlatformAssert::processingAssert()
|
||||
{
|
||||
return platformAssert ? platformAssert->processing : false;
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
bool PlatformAssert::processAssert(Type assertType,
|
||||
const char *filename,
|
||||
U32 lineNumber,
|
||||
const char *message)
|
||||
{
|
||||
if (platformAssert)
|
||||
return platformAssert->process(assertType, filename, lineNumber, message);
|
||||
else // when platAssert NULL (during _start/_exit) try direct output...
|
||||
dPrintf("\n%s: (%s @ %ld) %s\n", typeName[assertType], filename, lineNumber, message);
|
||||
|
||||
// this could also be platform-specific: OutputDebugString on PC, DebugStr on Mac.
|
||||
// Will raw printfs do the job? In the worst case, it's a break-pointable line of code.
|
||||
// would have preferred Con but due to race conditions, it might not be around...
|
||||
// Con::errorf(ConsoleLogEntry::Assert, "%s: (%s @ %ld) %s", typeName[assertType], filename, lineNumber, message);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
const char* avar(const char *message, ...)
|
||||
{
|
||||
static char buffer[4096];
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
dVsprintf(buffer, sizeof(buffer), message, args);
|
||||
return( buffer );
|
||||
}
|
124
engine/platform/platformAssert.h
Executable file
124
engine/platform/platformAssert.h
Executable file
@ -0,0 +1,124 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORMASSERT_H_
|
||||
#define _PLATFORMASSERT_H_
|
||||
|
||||
#ifndef _PLATFORM_H_
|
||||
#include "platform/platform.h"
|
||||
#endif
|
||||
|
||||
class PlatformAssert
|
||||
{
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
Warning = 3,
|
||||
Fatal = 2,
|
||||
Fatal_ISV = 1
|
||||
};
|
||||
|
||||
private:
|
||||
static PlatformAssert *platformAssert;
|
||||
bool processing;
|
||||
|
||||
virtual bool displayMessageBox(const char *title, const char *message, bool retry);
|
||||
virtual bool process(Type assertType,
|
||||
const char* filename,
|
||||
U32 lineNumber,
|
||||
const char* message);
|
||||
|
||||
PlatformAssert();
|
||||
virtual ~PlatformAssert();
|
||||
|
||||
public:
|
||||
static void create( PlatformAssert* newAssertClass = NULL );
|
||||
static void destroy();
|
||||
static bool processAssert(Type assertType,
|
||||
const char* filename,
|
||||
U32 lineNumber,
|
||||
const char* message);
|
||||
static char *message(const char *message, ...);
|
||||
static bool processingAssert();
|
||||
};
|
||||
|
||||
|
||||
#ifdef TORQUE_ENABLE_ASSERTS
|
||||
/*!
|
||||
Assert that the statement x is true, and continue processing.
|
||||
|
||||
If the statment x is true, continue processing.
|
||||
|
||||
If the statement x is false, log the file and line where the assert occured,
|
||||
the message y and continue processing.
|
||||
|
||||
These asserts are only present in DEBUG builds.
|
||||
*/
|
||||
#define AssertWarn(x, y) \
|
||||
{ if ((x)==0) \
|
||||
PlatformAssert::processAssert(PlatformAssert::Warning, __FILE__, __LINE__, y); }
|
||||
|
||||
/*!
|
||||
Assert that the statement x is true, otherwise halt.
|
||||
|
||||
If the statement x is true, continue processing.
|
||||
|
||||
If the statement x is false, log the file and line where the assert occured,
|
||||
the message y and displaying a dialog containing the message y. The user then
|
||||
has the option to halt or continue causing the debugger to break.
|
||||
|
||||
These asserts are only present in DEBUG builds.
|
||||
|
||||
This assert is very useful for verifying data as well as function entry and
|
||||
exit conditions.
|
||||
*/
|
||||
#define AssertFatal(x, y) \
|
||||
{ if (((bool)(x))==(bool)0) \
|
||||
{ if ( PlatformAssert::processAssert(PlatformAssert::Fatal, __FILE__, __LINE__, y) ) { Platform::debugBreak(); } } }
|
||||
|
||||
#else
|
||||
#define AssertFatal(x, y) { }
|
||||
#define AssertWarn(x, y) { }
|
||||
#endif
|
||||
|
||||
/*!
|
||||
Assert (In Shipping Version) that the statement x is true, otherwise halt.
|
||||
|
||||
If the statement x is true, continue processing.
|
||||
|
||||
If the statement x is false, log the file and line where the assert occurred,
|
||||
the message y and exit the program displaying a dialog containing the message y.
|
||||
These asserts are present in both OPTIMIZED and DEBUG builds.
|
||||
|
||||
This assert should only be used for rare conditions where the application cannot continue
|
||||
execution without seg-faulting and you want to display a nice exit message.
|
||||
*/
|
||||
#define AssertISV(x, y) \
|
||||
{ if ((x)==0) \
|
||||
{ if ( PlatformAssert::processAssert(PlatformAssert::Fatal_ISV, __FILE__, __LINE__, y) ) { Platform::debugBreak(); } } }
|
||||
|
||||
|
||||
/*!
|
||||
Sprintf style string formating into a fixed temporary buffer.
|
||||
@param in_msg sprintf style format string
|
||||
@returns pointer to fixed buffer containing formatted string
|
||||
|
||||
\b Example:
|
||||
\code
|
||||
U8 a = 5;
|
||||
S16 b = -10;
|
||||
char *output = avar("hello %s! a=%u, b=%d", "world");
|
||||
ouput = "hello world! a=5, b=-10"
|
||||
\endcode
|
||||
|
||||
@warning avar uses a static fixed buffer. Treat the buffer as volatile data
|
||||
and use it immediately. Other functions my use avar too and clobber the buffer.
|
||||
*/
|
||||
const char* avar(const char *in_msg, ...);
|
||||
|
||||
|
||||
|
||||
#endif // _PLATFORM_ASSERT_H_
|
||||
|
159
engine/platform/platformAudio.h
Executable file
159
engine/platform/platformAudio.h
Executable file
@ -0,0 +1,159 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORMAUDIO_H_
|
||||
#define _PLATFORMAUDIO_H_
|
||||
|
||||
#ifndef _PLATFORM_H_
|
||||
#include "platform/platform.h"
|
||||
#endif
|
||||
|
||||
#ifndef NO_AUDIO_SUPPORT
|
||||
|
||||
#ifndef _PLATFORMAL_H_
|
||||
#include "platform/platformAL.h"
|
||||
#endif
|
||||
|
||||
#ifndef _MMATH_H_
|
||||
#include "math/mMath.h"
|
||||
#endif
|
||||
|
||||
#ifndef _BITSET_H_
|
||||
#include "core/bitSet.h"
|
||||
#endif
|
||||
|
||||
typedef U32 AUDIOHANDLE;
|
||||
#define NULL_AUDIOHANDLE 0
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
namespace Audio
|
||||
{
|
||||
enum Constants {
|
||||
|
||||
NumAudioTypes = 32
|
||||
};
|
||||
|
||||
//--------------------------------------
|
||||
// sound property description
|
||||
struct Description
|
||||
{
|
||||
F32 mVolume; // 0-1 1=loudest volume
|
||||
bool mIsLooping;
|
||||
bool mIsStreaming;
|
||||
bool mIs3D;
|
||||
|
||||
F32 mReferenceDistance;
|
||||
F32 mMaxDistance;
|
||||
U32 mConeInsideAngle;
|
||||
U32 mConeOutsideAngle;
|
||||
F32 mConeOutsideVolume;
|
||||
Point3F mConeVector;
|
||||
|
||||
// environment info
|
||||
F32 mEnvironmentLevel;
|
||||
|
||||
// used by 'AudioEmitter' class
|
||||
S32 mLoopCount;
|
||||
S32 mMinLoopGap;
|
||||
S32 mMaxLoopGap;
|
||||
|
||||
// each 'type' can have its own volume
|
||||
S32 mType;
|
||||
};
|
||||
|
||||
void initOpenAL();
|
||||
void shutdownOpenAL();
|
||||
void destroy();
|
||||
}
|
||||
|
||||
class AudioDescription;
|
||||
class AudioProfile;
|
||||
class AudioEnvironment;
|
||||
class AudioSampleEnvironment;
|
||||
class AudioStreamSource;
|
||||
|
||||
AUDIOHANDLE alxCreateSource(const Audio::Description *desc, const char *filename, const MatrixF *transform=NULL, AudioSampleEnvironment * sampleEnvironment = 0);
|
||||
AUDIOHANDLE alxCreateSource(AudioDescription *descObject, const char *filename, const MatrixF *transform=NULL, AudioSampleEnvironment * sampleEnvironment = 0);
|
||||
AUDIOHANDLE alxCreateSource(const AudioProfile *profile, const MatrixF *transform=NULL);
|
||||
AudioStreamSource* alxFindAudioStreamSource(AUDIOHANDLE handle);
|
||||
|
||||
AUDIOHANDLE alxPlay(AUDIOHANDLE handle);
|
||||
void alxPause(AUDIOHANDLE handle);
|
||||
void alxPauseAll();
|
||||
void alxUnPause(AUDIOHANDLE handle);
|
||||
void alxUnPauseAll();
|
||||
void alxStop(AUDIOHANDLE handle);
|
||||
void alxStopAll();
|
||||
|
||||
// one-shot helper alxPlay functions, create and play in one call
|
||||
AUDIOHANDLE alxPlay(const AudioProfile *profile, const MatrixF *transform=NULL, const Point3F *velocity=NULL);
|
||||
|
||||
// Source
|
||||
void alxSourcef(AUDIOHANDLE handle, ALenum pname, ALfloat value);
|
||||
void alxSourcefv(AUDIOHANDLE handle, ALenum pname, ALfloat *values);
|
||||
void alxSource3f(AUDIOHANDLE handle, ALenum pname, ALfloat value1, ALfloat value2, ALfloat value3);
|
||||
void alxSourcei(AUDIOHANDLE handle, ALenum pname, ALint value);
|
||||
void alxSourceMatrixF(AUDIOHANDLE handle, const MatrixF *transform);
|
||||
|
||||
void alxGetSourcef(AUDIOHANDLE handle, ALenum pname, ALfloat *value);
|
||||
void alxGetSourcefv(AUDIOHANDLE handle, ALenum pname, ALfloat *values);
|
||||
void alxGetSource3f(AUDIOHANDLE handle, ALenum pname, ALfloat *value1, ALfloat *value2, ALfloat *value3);
|
||||
void alxGetSourcei(AUDIOHANDLE handle, ALenum pname, ALint *value);
|
||||
|
||||
/** alSource3f access extension for use with Point3F's
|
||||
*/
|
||||
inline void alxSourcePoint3F(AUDIOHANDLE handle, ALenum pname, const Point3F *value)
|
||||
{
|
||||
alxSource3f(handle, pname, value->x, value->y, value->z);
|
||||
}
|
||||
|
||||
/** alGetSource3f access extension for use with Point3F's
|
||||
*/
|
||||
inline void alxSourceGetPoint3F(AUDIOHANDLE handle, ALenum pname, Point3F * value)
|
||||
{
|
||||
alxGetSource3f(handle, pname, &value->x, &value->y, &value->z);
|
||||
}
|
||||
|
||||
// Listener
|
||||
void alxListenerMatrixF(const MatrixF *transform);
|
||||
void alxListenerf(ALenum param, ALfloat value);
|
||||
void alxGetListenerf(ALenum param, ALfloat *value);
|
||||
|
||||
|
||||
/** alListener3f access extension for use with Point3F's
|
||||
*/
|
||||
inline void alxListenerPoint3F(ALenum pname, const Point3F *value)
|
||||
{
|
||||
alListener3f(pname, value->x, value->y, value->z);
|
||||
}
|
||||
|
||||
/** alGetListener3f access extension for use with Point3F's
|
||||
*/
|
||||
inline void alxGetListenerPoint3F(ALenum pname, Point3F *value)
|
||||
{
|
||||
alGetListener3f(pname, &value->x, &value->y, &value->z);
|
||||
}
|
||||
|
||||
// Environment
|
||||
void alxEnvironmenti(ALenum pname, ALint value);
|
||||
void alxEnvironmentf(ALenum pname, ALfloat value);
|
||||
void alxGetEnvironmenti(ALenum pname, ALint * value);
|
||||
void alxGetEnvironmentf(ALenum pname, ALfloat * value);
|
||||
|
||||
void alxSetEnvironment(const AudioEnvironment * environment);
|
||||
const AudioEnvironment * alxGetEnvironment();
|
||||
|
||||
// misc
|
||||
void alxUpdateTypeGain(U32 type);
|
||||
bool alxIsValidHandle(AUDIOHANDLE handle);
|
||||
bool alxIsPlaying(AUDIOHANDLE handle);
|
||||
void alxUpdate();
|
||||
F32 alxGetStreamPosition( AUDIOHANDLE handle );
|
||||
F32 alxGetStreamDuration( AUDIOHANDLE handle );
|
||||
|
||||
#endif // NO_AUDIO_SUPPORT
|
||||
|
||||
#endif // _H_PLATFORMAUDIO_
|
191
engine/platform/platformCPU.cc
Executable file
191
engine/platform/platformCPU.cc
Executable file
@ -0,0 +1,191 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include "platform/platform.h"
|
||||
#include "core/stringTable.h"
|
||||
|
||||
enum CPUFlags
|
||||
{
|
||||
BIT_FPU = BIT(0),
|
||||
BIT_RDTSC = BIT(4),
|
||||
BIT_MMX = BIT(23),
|
||||
BIT_SSE = BIT(25),
|
||||
BIT_3DNOW = BIT(31),
|
||||
};
|
||||
|
||||
// fill the specified structure with information obtained from asm code
|
||||
void SetProcessorInfo(Platform::SystemInfo_struct::Processor& pInfo,
|
||||
char* vendor, U32 processor, U32 properties)
|
||||
{
|
||||
Platform::SystemInfo.processor.properties |= (properties & BIT_FPU) ? CPU_PROP_FPU : 0;
|
||||
Platform::SystemInfo.processor.properties |= (properties & BIT_RDTSC) ? CPU_PROP_RDTSC : 0;
|
||||
Platform::SystemInfo.processor.properties |= (properties & BIT_MMX) ? CPU_PROP_MMX : 0;
|
||||
|
||||
if (dStricmp(vendor, "GenuineIntel") == 0)
|
||||
{
|
||||
pInfo.properties |= (properties & BIT_SSE) ? CPU_PROP_SSE : 0;
|
||||
pInfo.type = CPU_Intel_Unknown;
|
||||
// switch on processor family code
|
||||
switch ((processor >> 8) & 0x0f)
|
||||
{
|
||||
case 4:
|
||||
pInfo.type = CPU_Intel_486;
|
||||
pInfo.name = StringTable->insert("Intel 486 class");
|
||||
break;
|
||||
|
||||
// Pentium Family
|
||||
case 5:
|
||||
// switch on processor model code
|
||||
switch ((processor >> 4) & 0xf)
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
pInfo.type = CPU_Intel_Pentium;
|
||||
pInfo.name = StringTable->insert("Intel Pentium");
|
||||
break;
|
||||
case 4:
|
||||
pInfo.type = CPU_Intel_PentiumMMX;
|
||||
pInfo.name = StringTable->insert("Intel Pentium MMX");
|
||||
break;
|
||||
default:
|
||||
pInfo.type = CPU_Intel_Pentium;
|
||||
pInfo.name = StringTable->insert( "Intel (unknown, Pentium family)" );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
// Pentium Pro/II/II family
|
||||
case 6:
|
||||
// switch on processor model code
|
||||
switch ((processor >> 4) & 0xf)
|
||||
{
|
||||
case 1:
|
||||
pInfo.type = CPU_Intel_PentiumPro;
|
||||
pInfo.name = StringTable->insert("Intel Pentium Pro");
|
||||
break;
|
||||
case 3:
|
||||
case 5:
|
||||
pInfo.type = CPU_Intel_PentiumII;
|
||||
pInfo.name = StringTable->insert("Intel Pentium II");
|
||||
break;
|
||||
case 6:
|
||||
pInfo.type = CPU_Intel_PentiumCeleron;
|
||||
pInfo.name = StringTable->insert("Intel Pentium Celeron");
|
||||
break;
|
||||
case 7:
|
||||
case 8:
|
||||
case 10:
|
||||
case 11:
|
||||
pInfo.type = CPU_Intel_PentiumIII;
|
||||
pInfo.name = StringTable->insert("Intel Pentium III");
|
||||
break;
|
||||
default:
|
||||
pInfo.type = CPU_Intel_PentiumPro;
|
||||
pInfo.name = StringTable->insert( "Intel (unknown, Pentium Pro/II/III family)" );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
// Pentium4 Family
|
||||
case 0xf:
|
||||
pInfo.type = CPU_Intel_Pentium4;
|
||||
pInfo.name = StringTable->insert( "Intel Pentium 4" );
|
||||
break;
|
||||
|
||||
default:
|
||||
pInfo.type = CPU_Intel_Unknown;
|
||||
pInfo.name = StringTable->insert( "Intel (unknown)" );
|
||||
break;
|
||||
}
|
||||
}
|
||||
//--------------------------------------
|
||||
else
|
||||
if (dStricmp(vendor, "AuthenticAMD") == 0)
|
||||
{
|
||||
// AthlonXP processors support SSE
|
||||
pInfo.properties |= (properties & BIT_SSE) ? CPU_PROP_SSE : 0;
|
||||
pInfo.properties |= (properties & BIT_3DNOW) ? CPU_PROP_3DNOW : 0;
|
||||
// switch on processor family code
|
||||
switch ((processor >> 8) & 0xf)
|
||||
{
|
||||
// K6 Family
|
||||
case 5:
|
||||
// switch on processor model code
|
||||
switch ((processor >> 4) & 0xf)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
pInfo.type = CPU_AMD_K6_3;
|
||||
pInfo.name = StringTable->insert("AMD K5");
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
pInfo.type = CPU_AMD_K6;
|
||||
pInfo.name = StringTable->insert("AMD K6");
|
||||
break;
|
||||
case 8:
|
||||
pInfo.type = CPU_AMD_K6_2;
|
||||
pInfo.name = StringTable->insert("AMD K6-2");
|
||||
break;
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
pInfo.type = CPU_AMD_K6_3;
|
||||
pInfo.name = StringTable->insert("AMD K6-3");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
// Athlon Family
|
||||
case 6:
|
||||
pInfo.type = CPU_AMD_Athlon;
|
||||
pInfo.name = StringTable->insert("AMD Athlon");
|
||||
break;
|
||||
|
||||
default:
|
||||
pInfo.type = CPU_AMD_Unknown;
|
||||
pInfo.name = StringTable->insert("AMD (unknown)");
|
||||
break;
|
||||
}
|
||||
}
|
||||
//--------------------------------------
|
||||
else
|
||||
if (dStricmp(vendor, "CyrixInstead") == 0)
|
||||
{
|
||||
switch (processor)
|
||||
{
|
||||
case 0x520:
|
||||
pInfo.type = CPU_Cyrix_6x86;
|
||||
pInfo.name = StringTable->insert("Cyrix 6x86");
|
||||
break;
|
||||
case 0x440:
|
||||
pInfo.type = CPU_Cyrix_MediaGX;
|
||||
pInfo.name = StringTable->insert("Cyrix Media GX");
|
||||
break;
|
||||
case 0x600:
|
||||
pInfo.type = CPU_Cyrix_6x86MX;
|
||||
pInfo.name = StringTable->insert("Cyrix 6x86mx/MII");
|
||||
break;
|
||||
case 0x540:
|
||||
pInfo.type = CPU_Cyrix_GXm;
|
||||
pInfo.name = StringTable->insert("Cyrix GXm");
|
||||
break;
|
||||
default:
|
||||
pInfo.type = CPU_Cyrix_Unknown;
|
||||
pInfo.name = StringTable->insert("Cyrix (unknown)");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
111
engine/platform/platformCPUInfo.asm
Executable file
111
engine/platform/platformCPUInfo.asm
Executable file
@ -0,0 +1,111 @@
|
||||
;-----------------------------------------------------------------------------
|
||||
; Torque Game Engine
|
||||
; Copyright (C) GarageGames.com, Inc.
|
||||
;-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
segment .text
|
||||
|
||||
; syntax: export_fn <function name>
|
||||
%macro export_fn 1
|
||||
%ifdef LINUX
|
||||
; No underscore needed for ELF object files
|
||||
global %1
|
||||
%1:
|
||||
%else
|
||||
global _%1
|
||||
_%1:
|
||||
%endif
|
||||
%endmacro
|
||||
|
||||
; push registers
|
||||
%macro pushreg 0
|
||||
; pushad
|
||||
push ebx
|
||||
push ebp
|
||||
push esi
|
||||
push edi
|
||||
%endmacro
|
||||
|
||||
; pop registers
|
||||
%macro popreg 0
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebp
|
||||
pop ebx
|
||||
; popad
|
||||
%endmacro
|
||||
|
||||
; void detectX86CPUInfo(char *vendor, U32 *processor, U32 *properties);
|
||||
export_fn detectX86CPUInfo
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
|
||||
pushreg
|
||||
|
||||
push edx
|
||||
push ecx
|
||||
pushfd
|
||||
pushfd ; save EFLAGS to stack
|
||||
pop eax ; move EFLAGS into EAX
|
||||
mov ebx, eax
|
||||
xor eax, 0x200000 ; flip bit 21
|
||||
push eax
|
||||
popfd ; restore EFLAGS
|
||||
pushfd
|
||||
pop eax
|
||||
cmp eax, ebx
|
||||
jz EXIT ; doesn't support CPUID instruction
|
||||
|
||||
;
|
||||
; get vendor information using CPUID eax == 0
|
||||
xor eax, eax
|
||||
cpuid
|
||||
|
||||
; store the vendor tag (12 bytes in ebx, edx, ecx) in the first parameter,
|
||||
; which should be a char[13]
|
||||
push eax ; save eax
|
||||
mov eax, [ebp+8] ; store the char* address in eax
|
||||
mov [eax], ebx ; move ebx into the first 4 bytes
|
||||
add eax, 4 ; advance the char* 4 bytes
|
||||
mov [eax], edx ; move edx into the next 4 bytes
|
||||
add eax, 4 ; advance the char* 4 bytes
|
||||
mov [eax], ecx ; move ecx into the last 4 bytes
|
||||
pop eax ; restore eax
|
||||
|
||||
; get generic extended CPUID info
|
||||
mov eax, 1
|
||||
cpuid ; eax=1, so cpuid queries feature information
|
||||
|
||||
and eax, 0x0FF0
|
||||
push ecx
|
||||
mov ecx, [ebp+12]
|
||||
mov [ecx], eax ; just store the model bits in processor param
|
||||
mov ecx, [ebp+16]
|
||||
mov [ecx], edx ; set properties param
|
||||
pop ecx
|
||||
|
||||
; want to check for 3DNow(tm).
|
||||
; need to see if extended cpuid functions present.
|
||||
mov eax, 0x80000000
|
||||
cpuid
|
||||
cmp eax, 0x80000000
|
||||
jbe MAYBE_3DLATER
|
||||
mov eax, 0x80000001
|
||||
cpuid
|
||||
; 3DNow if bit 31 set -> put bit in our properties
|
||||
and edx, 0x80000000
|
||||
push eax
|
||||
mov eax, [ebp+16]
|
||||
or [eax], edx
|
||||
pop eax
|
||||
MAYBE_3DLATER:
|
||||
EXIT:
|
||||
popfd
|
||||
pop ecx
|
||||
pop edx
|
||||
|
||||
popreg
|
||||
|
||||
pop ebp
|
||||
ret
|
33
engine/platform/platformFileIO.cc
Executable file
33
engine/platform/platformFileIO.cc
Executable file
@ -0,0 +1,33 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "platform/platform.h"
|
||||
#include "core/tVector.h"
|
||||
|
||||
typedef Vector<char*> CharVector;
|
||||
static CharVector gPlatformDirectoryExcludeList;
|
||||
|
||||
void Platform::addExcludedDirectory(const char *pDir)
|
||||
{
|
||||
gPlatformDirectoryExcludeList.push_back(dStrdup(pDir));
|
||||
}
|
||||
|
||||
void Platform::clearExcludedDirectories()
|
||||
{
|
||||
while(gPlatformDirectoryExcludeList.size())
|
||||
{
|
||||
dFree(gPlatformDirectoryExcludeList.last());
|
||||
gPlatformDirectoryExcludeList.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
bool Platform::isExcludedDirectory(const char *pDir)
|
||||
{
|
||||
for(CharVector::iterator i=gPlatformDirectoryExcludeList.begin(); i!=gPlatformDirectoryExcludeList.end(); i++)
|
||||
if(!dStrcmp(pDir, *i))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
45
engine/platform/platformFont.h
Executable file
45
engine/platform/platformFont.h
Executable file
@ -0,0 +1,45 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORM_H_
|
||||
#include "platform/platform.h"
|
||||
#endif
|
||||
|
||||
#ifndef _PLATFORMFONT_H_
|
||||
#define _PLATFORMFONT_H_
|
||||
|
||||
class PlatformFont
|
||||
{
|
||||
public:
|
||||
struct CharInfo
|
||||
{
|
||||
S16 bitmapIndex; // Note: -1 indicates character is NOT to be
|
||||
// rendered, i.e., \n, \r, etc.
|
||||
U32 xOffset; // x offset into bitmap sheet
|
||||
U32 yOffset; // y offset into bitmap sheet
|
||||
U32 width; // width of character (pixels)
|
||||
U32 height; // height of character (pixels)
|
||||
S32 xOrigin;
|
||||
S32 yOrigin;
|
||||
S32 xIncrement;
|
||||
U8 *bitmapData; // temp storage for bitmap data
|
||||
};
|
||||
|
||||
virtual bool isValidChar(const UTF16 ch) const = 0;
|
||||
virtual bool isValidChar(const UTF8 *str) const = 0;
|
||||
|
||||
virtual U32 getFontHeight() const = 0;
|
||||
virtual U32 getFontBaseLine() const = 0;
|
||||
|
||||
virtual PlatformFont::CharInfo &getCharInfo(const UTF16 ch) const = 0;
|
||||
virtual PlatformFont::CharInfo &getCharInfo(const UTF8 *str) const = 0;
|
||||
|
||||
virtual bool create(const char *name, U32 size, U32 charset = TGE_ANSI_CHARSET) = 0;
|
||||
};
|
||||
|
||||
extern PlatformFont *createPlatformFont(const char *name, U32 size, U32 charset = TGE_ANSI_CHARSET);
|
||||
|
||||
|
||||
#endif // _PLATFORMFONT_H_
|
15
engine/platform/platformGL.h
Executable file
15
engine/platform/platformGL.h
Executable file
@ -0,0 +1,15 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORMGL_H_
|
||||
// redirect to appropriate platform file
|
||||
#if defined(TORQUE_OS_MAC)
|
||||
#include "platformMacCarb/platformGL.h"
|
||||
#elif defined(TORQUE_OS_WIN32)
|
||||
#include "platformWin32/platformGL.h"
|
||||
#elif defined(TORQUE_OS_LINUX) || defined(TORQUE_OS_OPENBSD) || defined(TORQUE_OS_FREEBSD)
|
||||
#include "platformX86UNIX/platformGL.h"
|
||||
#endif
|
||||
#endif
|
113
engine/platform/platformInput.h
Executable file
113
engine/platform/platformInput.h
Executable file
@ -0,0 +1,113 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORMINPUT_H_
|
||||
#define _PLATFORMINPUT_H_
|
||||
|
||||
#ifndef _SIMBASE_H_
|
||||
#include "console/simBase.h"
|
||||
#endif
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
U8 TranslateOSKeyCode( U8 vcode );
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
class InputDevice : public SimObject
|
||||
{
|
||||
public:
|
||||
struct ObjInfo
|
||||
{
|
||||
U16 mType;
|
||||
U16 mInst;
|
||||
S32 mMin, mMax;
|
||||
};
|
||||
|
||||
protected:
|
||||
char mName[30];
|
||||
|
||||
public:
|
||||
const char* getDeviceName();
|
||||
virtual bool process() = 0;
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
inline const char* InputDevice::getDeviceName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
class InputManager : public SimGroup
|
||||
{
|
||||
protected:
|
||||
bool mEnabled;
|
||||
|
||||
public:
|
||||
bool isEnabled();
|
||||
|
||||
virtual bool enable() = 0;
|
||||
virtual void disable() = 0;
|
||||
|
||||
virtual void process() = 0;
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
inline bool InputManager::isEnabled()
|
||||
{
|
||||
return mEnabled;
|
||||
}
|
||||
|
||||
enum KEY_STATE
|
||||
{
|
||||
STATE_LOWER,
|
||||
STATE_UPPER,
|
||||
STATE_GOOFY
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
class Input
|
||||
{
|
||||
protected:
|
||||
static InputManager* smManager;
|
||||
static bool smActive;
|
||||
static bool smLastKeyboardActivated;
|
||||
static bool smLastMouseActivated;
|
||||
static bool smLastJoystickActivated;
|
||||
|
||||
public:
|
||||
static void init();
|
||||
static void destroy();
|
||||
|
||||
static bool enable();
|
||||
static void disable();
|
||||
|
||||
static void activate();
|
||||
static void deactivate();
|
||||
static void reactivate();
|
||||
|
||||
static U16 getAscii( U16 keyCode, KEY_STATE keyState );
|
||||
static U16 getKeyCode( U16 asciiCode );
|
||||
|
||||
static bool isEnabled();
|
||||
static bool isActive();
|
||||
|
||||
static void process();
|
||||
static void setCursorPos(S32 x, S32 y);
|
||||
|
||||
static InputManager* getManager();
|
||||
|
||||
#ifdef LOG_INPUT
|
||||
static void log( const char* format, ... );
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // _H_PLATFORMINPUT_
|
1304
engine/platform/platformMemory.cc
Executable file
1304
engine/platform/platformMemory.cc
Executable file
File diff suppressed because it is too large
Load Diff
80
engine/platform/platformMutex.h
Executable file
80
engine/platform/platformMutex.h
Executable file
@ -0,0 +1,80 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORMMUTEX_H_
|
||||
#define _PLATFORMMUTEX_H_
|
||||
|
||||
#include "platform/platformAssert.h"
|
||||
|
||||
// TODO: change this to a proper class.
|
||||
|
||||
struct Mutex
|
||||
{
|
||||
static void* createMutex( void );
|
||||
static void destroyMutex( void* );
|
||||
static bool lockMutex( void *mutex, bool block = true);
|
||||
static void unlockMutex( void* );
|
||||
};
|
||||
|
||||
/// Helper for simplifying mutex locking code.
|
||||
///
|
||||
/// This class will automatically unlock a mutex that you've
|
||||
/// locked through it, saving you from managing a lot of complex
|
||||
/// exit cases. For instance:
|
||||
///
|
||||
/// @code
|
||||
/// MutexHandle handle;
|
||||
/// handle.lock(myMutex);
|
||||
///
|
||||
/// if(error1)
|
||||
/// return; // Auto-unlocked by handle if we leave here - normally would
|
||||
/// // leave the mutex locked, causing much pain later.
|
||||
///
|
||||
/// handle.unlock();
|
||||
/// @endcode
|
||||
class MutexHandle
|
||||
{
|
||||
private:
|
||||
void *mMutexPtr;
|
||||
|
||||
public:
|
||||
MutexHandle()
|
||||
: mMutexPtr(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
~MutexHandle()
|
||||
{
|
||||
if(mMutexPtr)
|
||||
unlock();
|
||||
}
|
||||
|
||||
bool lock(void *mutex, bool blocking=true)
|
||||
{
|
||||
AssertFatal(!mMutexPtr, "MutexHandle::lock - shouldn't be locking things twice!");
|
||||
|
||||
bool ret = Mutex::lockMutex(mutex, blocking);
|
||||
|
||||
if(ret)
|
||||
{
|
||||
// We succeeded, do book-keeping.
|
||||
mMutexPtr = mutex;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
if(mMutexPtr)
|
||||
{
|
||||
Mutex::unlockMutex(mMutexPtr);
|
||||
mMutexPtr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
209
engine/platform/platformNetAsync.cc
Executable file
209
engine/platform/platformNetAsync.cc
Executable file
@ -0,0 +1,209 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "platform/platform.h"
|
||||
|
||||
// NetAsync is used by Posix compliant platforms. Since Windows is not Posix
|
||||
// compliant, NetAsync is not compatible with win32 Torque. Since it sometimes
|
||||
// gets included by automated build stuff, we're manually snipping it out here.
|
||||
#if !defined(TORQUE_OS_WIN32)
|
||||
|
||||
#include "platform/platformMutex.h"
|
||||
#include "platform/platformThread.h"
|
||||
#include "platform/platformNetAsync.h"
|
||||
#include "console/console.h"
|
||||
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
NetAsync gNetAsync;
|
||||
|
||||
void* gNetAsyncMutex = NULL;
|
||||
|
||||
static void lockNetAsyncMutex()
|
||||
{
|
||||
if(!gNetAsyncMutex)
|
||||
gNetAsyncMutex = Mutex::createMutex();
|
||||
|
||||
AssertFatal(gNetAsyncMutex, "Could not create gNetAsyncMutex!");
|
||||
|
||||
Mutex::lockMutex(gNetAsyncMutex);
|
||||
}
|
||||
|
||||
static void unlockNetAsyncMutex()
|
||||
{
|
||||
if(!gNetAsyncMutex)
|
||||
gNetAsyncMutex = Mutex::createMutex();
|
||||
|
||||
AssertFatal(gNetAsyncMutex, "Could not create gNetAsyncMutex!");
|
||||
|
||||
Mutex::unlockMutex(gNetAsyncMutex);
|
||||
}
|
||||
|
||||
// internal structure for storing information about a name lookup request
|
||||
struct NameLookupRequest
|
||||
{
|
||||
NetSocket sock;
|
||||
char remoteAddr[4096];
|
||||
char out_h_addr[4096];
|
||||
int out_h_length;
|
||||
bool complete;
|
||||
|
||||
NameLookupRequest()
|
||||
{
|
||||
sock = InvalidSocket;
|
||||
remoteAddr[0] = 0;
|
||||
out_h_addr[0] = 0;
|
||||
out_h_length = -1;
|
||||
complete = false;
|
||||
}
|
||||
};
|
||||
|
||||
void NetAsync::queueLookup(const char* remoteAddr, NetSocket socket)
|
||||
{
|
||||
lockNetAsyncMutex();
|
||||
// do we have it already?
|
||||
unsigned int i = 0;
|
||||
for (i = 0; i < mLookupRequests.size(); ++i)
|
||||
{
|
||||
if (mLookupRequests[i]->sock == socket)
|
||||
// found it. ignore more than one lookup at a time for a socket.
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == mLookupRequests.size())
|
||||
{
|
||||
// not found, so add it
|
||||
NameLookupRequest* lookupRequest = new NameLookupRequest();
|
||||
lookupRequest->sock = socket;
|
||||
dStrncpy(lookupRequest->remoteAddr, remoteAddr,
|
||||
sizeof(lookupRequest->remoteAddr));
|
||||
mLookupRequests.push_back(lookupRequest);
|
||||
}
|
||||
unlockNetAsyncMutex();
|
||||
}
|
||||
|
||||
void NetAsync::run()
|
||||
{
|
||||
if (isRunning())
|
||||
return;
|
||||
|
||||
mRunning = true;
|
||||
NameLookupRequest* lookupRequest = NULL;
|
||||
|
||||
while (isRunning())
|
||||
{
|
||||
lookupRequest = NULL;
|
||||
|
||||
// lock
|
||||
lockNetAsyncMutex();
|
||||
// if there is a request...
|
||||
if (mLookupRequests.size() > 0)
|
||||
{
|
||||
// assign the first incomplete request
|
||||
for (unsigned int i = 0; i < mLookupRequests.size(); ++i)
|
||||
if (!mLookupRequests[i]->complete)
|
||||
lookupRequest = mLookupRequests[i];
|
||||
}
|
||||
|
||||
// unlock so that more requests can be added
|
||||
unlockNetAsyncMutex();
|
||||
|
||||
// if we have a lookup request
|
||||
if (lookupRequest != NULL)
|
||||
{
|
||||
// do it
|
||||
struct hostent* hostent = gethostbyname(lookupRequest->remoteAddr);
|
||||
if (hostent == NULL)
|
||||
{
|
||||
// oh well! leave the lookup data unmodified (h_length) should
|
||||
// still be -1 from initialization
|
||||
lookupRequest->complete = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// copy the stuff we need from the hostent
|
||||
dMemset(lookupRequest->out_h_addr, 0,
|
||||
sizeof(lookupRequest->out_h_addr));
|
||||
dMemcpy(lookupRequest->out_h_addr, hostent->h_addr, hostent->h_length);
|
||||
|
||||
lookupRequest->out_h_length = hostent->h_length;
|
||||
lookupRequest->complete = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// no lookup request. sleep for a bit
|
||||
Platform::sleep(500);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
bool NetAsync::checkLookup(NetSocket socket, char* out_h_addr,
|
||||
int* out_h_length, int out_h_addr_size)
|
||||
{
|
||||
lockNetAsyncMutex();
|
||||
unsigned int i = 0;
|
||||
bool found = false;
|
||||
// search for the socket
|
||||
Vector<NameLookupRequest*>::iterator iter;
|
||||
for (iter = mLookupRequests.begin();
|
||||
iter != mLookupRequests.end();
|
||||
++iter)
|
||||
// if we found it and it is complete...
|
||||
if (socket == (*iter)->sock && (*iter)->complete)
|
||||
{
|
||||
// copy the lookup data to the callers parameters
|
||||
dMemcpy(out_h_addr, (*iter)->out_h_addr, out_h_addr_size);
|
||||
*out_h_length = (*iter)->out_h_length;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// we found the socket, so we are done with it. erase.
|
||||
if (found)
|
||||
{
|
||||
delete *iter;
|
||||
mLookupRequests.erase(iter);
|
||||
}
|
||||
unlockNetAsyncMutex();
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
// this is called by the pthread module to start the thread
|
||||
static void StartThreadFunc(S32 nothing)
|
||||
{
|
||||
nothing;
|
||||
|
||||
if (gNetAsync.isRunning())
|
||||
return;
|
||||
|
||||
gNetAsync.run();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void NetAsync::startAsync()
|
||||
{
|
||||
if (gNetAsync.isRunning())
|
||||
return;
|
||||
|
||||
// create the thread...
|
||||
Thread *zThread = new Thread((ThreadRunFunction)StartThreadFunc, 0, true);
|
||||
|
||||
if (!zThread)
|
||||
Con::errorf("Error starting net async thread.");
|
||||
}
|
||||
|
||||
void NetAsync::stopAsync()
|
||||
{
|
||||
if (gNetAsync.isRunning())
|
||||
gNetAsync.stop();
|
||||
}
|
||||
|
||||
#endif
|
56
engine/platform/platformNetAsync.h
Executable file
56
engine/platform/platformNetAsync.h
Executable file
@ -0,0 +1,56 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef PLATFORM_NET_ASYNC_H
|
||||
#define PLATFORM_NET_ASYNC_H
|
||||
|
||||
#include "platform/platform.h"
|
||||
#include "core/tVector.h"
|
||||
|
||||
struct NameLookupRequest;
|
||||
|
||||
// class for doing asynchronous network operations on unix (linux and
|
||||
// hopefully osx) platforms. right now it only implements dns lookups
|
||||
class NetAsync
|
||||
{
|
||||
private:
|
||||
Vector<NameLookupRequest*> mLookupRequests;
|
||||
bool mRunning;
|
||||
|
||||
public:
|
||||
NetAsync()
|
||||
{
|
||||
mRunning = false;
|
||||
}
|
||||
|
||||
// queue a DNS lookup. only one dns lookup can be queued per socket at
|
||||
// a time. subsequent queue request for the socket are ignored. use
|
||||
// checkLookup() to check the status of a request.
|
||||
void queueLookup(const char* remoteAddr, NetSocket socket);
|
||||
|
||||
// check on the status of a dns lookup for a socket. if the lookup is
|
||||
// not yet complete, the function will return false. if it is
|
||||
// complete, the function will return true, and out_h_addr and
|
||||
// out_h_length will be set appropriately. if out_h_length is -1, then
|
||||
// name could not be resolved. otherwise, it provides the number of
|
||||
// address bytes copied into out_h_addr.
|
||||
bool checkLookup(NetSocket socket, char* out_h_addr, int* out_h_length, int out_h_addr_size);
|
||||
|
||||
// returns true if the async thread is running, false otherwise
|
||||
bool isRunning() { return mRunning; };
|
||||
|
||||
// these functions are used by the static start/stop functions
|
||||
void run();
|
||||
void stop() { mRunning = false; };
|
||||
|
||||
// used to start and stop the thread
|
||||
static void startAsync();
|
||||
static void stopAsync();
|
||||
};
|
||||
|
||||
// the global net async object
|
||||
extern NetAsync gNetAsync;
|
||||
|
||||
#endif
|
253
engine/platform/platformRedBook.cc
Executable file
253
engine/platform/platformRedBook.cc
Executable file
@ -0,0 +1,253 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "console/console.h"
|
||||
#include "platform/platformRedBook.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Class: RedBookDevice
|
||||
//------------------------------------------------------------------------------
|
||||
RedBookDevice::RedBookDevice()
|
||||
{
|
||||
mAcquired = false;
|
||||
mDeviceName = 0;
|
||||
}
|
||||
|
||||
RedBookDevice::~RedBookDevice()
|
||||
{
|
||||
delete [] mDeviceName;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Class: RedBook
|
||||
//------------------------------------------------------------------------------
|
||||
Vector<RedBookDevice *> RedBook::smDeviceList(__FILE__, __LINE__);
|
||||
RedBookDevice * RedBook::smCurrentDevice;
|
||||
char RedBook::smLastError[1024];
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RedBook::init()
|
||||
{
|
||||
}
|
||||
|
||||
void RedBook::destroy()
|
||||
{
|
||||
close();
|
||||
|
||||
for( Vector<RedBookDevice*>::iterator i = smDeviceList.begin( ); i != smDeviceList.end( ); i++ ) {
|
||||
delete *i;
|
||||
}
|
||||
|
||||
smDeviceList.clear( );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void RedBook::installDevice(RedBookDevice * device)
|
||||
{
|
||||
smDeviceList.push_back(device);
|
||||
}
|
||||
|
||||
RedBookDevice * RedBook::getCurrentDevice()
|
||||
{
|
||||
return(smCurrentDevice);
|
||||
}
|
||||
|
||||
U32 RedBook::getDeviceCount()
|
||||
{
|
||||
return(smDeviceList.size());
|
||||
}
|
||||
|
||||
const char * RedBook::getDeviceName(U32 idx)
|
||||
{
|
||||
if(idx >= getDeviceCount())
|
||||
{
|
||||
setLastError("Invalid device index");
|
||||
return("");
|
||||
}
|
||||
return(smDeviceList[idx]->mDeviceName);
|
||||
}
|
||||
|
||||
void RedBook::setLastError(const char * error)
|
||||
{
|
||||
if(!error || dStrlen(error) >= sizeof(smLastError))
|
||||
setLastError("Invalid error string passed");
|
||||
else
|
||||
dStrcpy(smLastError, error);
|
||||
}
|
||||
|
||||
const char * RedBook::getLastError()
|
||||
{
|
||||
return(smLastError);
|
||||
}
|
||||
|
||||
void RedBook::handleCallback(U32 type)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case PlayFinished:
|
||||
Con::executef(2, "RedBookCallback", "PlayFinished");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool RedBook::open(const char * deviceName)
|
||||
{
|
||||
if(!deviceName)
|
||||
{
|
||||
setLastError("Invalid device name");
|
||||
return(false);
|
||||
}
|
||||
|
||||
for(U32 i = 0; i < smDeviceList.size(); i++)
|
||||
if(!dStricmp(deviceName, smDeviceList[i]->mDeviceName))
|
||||
return(open(smDeviceList[i]));
|
||||
|
||||
setLastError("Failed to find device");
|
||||
return(false);
|
||||
}
|
||||
|
||||
bool RedBook::open(RedBookDevice * device)
|
||||
{
|
||||
if(!device)
|
||||
{
|
||||
setLastError("Invalid device passed");
|
||||
return(false);
|
||||
}
|
||||
|
||||
close();
|
||||
smCurrentDevice = device;
|
||||
return(smCurrentDevice->open());
|
||||
}
|
||||
|
||||
bool RedBook::close()
|
||||
{
|
||||
if(smCurrentDevice)
|
||||
{
|
||||
bool ret = smCurrentDevice->close();
|
||||
smCurrentDevice = 0;
|
||||
return(ret);
|
||||
}
|
||||
|
||||
setLastError("No device is currently open");
|
||||
return(false);
|
||||
}
|
||||
|
||||
bool RedBook::play(U32 track)
|
||||
{
|
||||
if(!smCurrentDevice)
|
||||
{
|
||||
setLastError("No device is currently open");
|
||||
return(false);
|
||||
}
|
||||
return(smCurrentDevice->play(track));
|
||||
}
|
||||
|
||||
bool RedBook::stop()
|
||||
{
|
||||
if(!smCurrentDevice)
|
||||
{
|
||||
setLastError("No device is currently open");
|
||||
return(false);
|
||||
}
|
||||
return(smCurrentDevice->stop());
|
||||
}
|
||||
|
||||
bool RedBook::getTrackCount(U32 * trackCount)
|
||||
{
|
||||
if(!smCurrentDevice)
|
||||
{
|
||||
setLastError("No device is currently open");
|
||||
return(false);
|
||||
}
|
||||
return(smCurrentDevice->getTrackCount(trackCount));
|
||||
}
|
||||
|
||||
bool RedBook::getVolume(F32 * volume)
|
||||
{
|
||||
if(!smCurrentDevice)
|
||||
{
|
||||
setLastError("No device is currently open");
|
||||
return(false);
|
||||
}
|
||||
return(smCurrentDevice->getVolume(volume));
|
||||
}
|
||||
|
||||
bool RedBook::setVolume(F32 volume)
|
||||
{
|
||||
if(!smCurrentDevice)
|
||||
{
|
||||
setLastError("No device is currently open");
|
||||
return(false);
|
||||
}
|
||||
return(smCurrentDevice->setVolume(volume));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// console methods
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ConsoleFunctionGroupBegin( Redbook, "Control functions for Redbook audio (ie, CD audio).")
|
||||
|
||||
ConsoleFunction(redbookOpen, bool, 1, 2, "(string device=NULL)")
|
||||
{
|
||||
if(argc == 1)
|
||||
return(RedBook::open(RedBook::getDeviceName(0)));
|
||||
else
|
||||
return(RedBook::open(argv[1]));
|
||||
}
|
||||
|
||||
ConsoleFunction(redbookClose, bool, 1, 1, "Close the current Redbook device.")
|
||||
{
|
||||
return(RedBook::close());
|
||||
}
|
||||
|
||||
ConsoleFunction( redbookPlay, bool, 2, 2, "(int track) Play the selected track.")
|
||||
{
|
||||
return(RedBook::play(dAtoi(argv[1])));
|
||||
}
|
||||
|
||||
ConsoleFunction( redbookStop, bool, 1, 1, "Stop playing.")
|
||||
{
|
||||
return(RedBook::stop());
|
||||
}
|
||||
ConsoleFunction(redbookGetTrackCount, S32, 1, 1, "Return the number of tracks.")
|
||||
{
|
||||
U32 trackCount;
|
||||
if(!RedBook::getTrackCount(&trackCount))
|
||||
return(0);
|
||||
return(trackCount);
|
||||
}
|
||||
|
||||
ConsoleFunction(redbookGetVolume, F32, 1, 1, "Get the volume.")
|
||||
{
|
||||
F32 vol;
|
||||
if(!RedBook::getVolume(&vol))
|
||||
return(0.f);
|
||||
else
|
||||
return(vol);
|
||||
}
|
||||
|
||||
ConsoleFunction(redbookSetVolume, bool, 2, 2, "(float volume) Set playback volume.")
|
||||
{
|
||||
return(RedBook::setVolume(dAtof(argv[1])));
|
||||
}
|
||||
|
||||
ConsoleFunction( redbookGetDeviceCount, S32, 1, 1, "get the number of redbook devices.")
|
||||
{
|
||||
return(RedBook::getDeviceCount());
|
||||
}
|
||||
|
||||
ConsoleFunction( redbookGetDeviceName, const char *, 2, 2, "(int index) Get name of specified Redbook device.")
|
||||
{
|
||||
return(RedBook::getDeviceName(dAtoi(argv[1])));
|
||||
}
|
||||
|
||||
ConsoleFunction( redbookGetLastError, const char*, 1, 1, "Get a string explaining the last redbook error.")
|
||||
{
|
||||
return(RedBook::getLastError());
|
||||
}
|
||||
|
||||
ConsoleFunctionGroupEnd( Redbook );
|
70
engine/platform/platformRedBook.h
Executable file
70
engine/platform/platformRedBook.h
Executable file
@ -0,0 +1,70 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORMREDBOOK_H_
|
||||
#define _PLATFORMREDBOOK_H_
|
||||
|
||||
#ifndef _PLATFORM_H_
|
||||
#include "platform/platform.h"
|
||||
#endif
|
||||
#ifndef _TVECTOR_H_
|
||||
#include "core/tVector.h"
|
||||
#endif
|
||||
|
||||
class RedBookDevice
|
||||
{
|
||||
public:
|
||||
RedBookDevice();
|
||||
virtual ~RedBookDevice();
|
||||
|
||||
bool mAcquired;
|
||||
char * mDeviceName;
|
||||
|
||||
virtual bool open() = 0;
|
||||
virtual bool close() = 0;
|
||||
virtual bool play(U32) = 0;
|
||||
virtual bool stop() = 0;
|
||||
virtual bool getTrackCount(U32 *) = 0;
|
||||
virtual bool getVolume(F32 *) = 0;
|
||||
virtual bool setVolume(F32) = 0;
|
||||
};
|
||||
|
||||
class RedBook
|
||||
{
|
||||
private:
|
||||
static Vector<RedBookDevice *> smDeviceList;
|
||||
static RedBookDevice * smCurrentDevice;
|
||||
static char smLastError[];
|
||||
|
||||
public:
|
||||
enum {
|
||||
PlayFinished = 0,
|
||||
};
|
||||
static void handleCallback(U32);
|
||||
|
||||
static void init();
|
||||
static void destroy();
|
||||
|
||||
static void installDevice(RedBookDevice *);
|
||||
static U32 getDeviceCount();
|
||||
static const char * getDeviceName(U32);
|
||||
static RedBookDevice * getCurrentDevice();
|
||||
|
||||
static void setLastError(const char *);
|
||||
static const char * getLastError();
|
||||
|
||||
static bool open(const char *);
|
||||
static bool open(RedBookDevice *);
|
||||
static bool close();
|
||||
static bool play(U32);
|
||||
static bool stop();
|
||||
static bool getTrackCount(U32 *);
|
||||
static bool getVolume(F32 *);
|
||||
static bool setVolume(F32);
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#endif
|
24
engine/platform/platformSemaphore.h
Executable file
24
engine/platform/platformSemaphore.h
Executable file
@ -0,0 +1,24 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORMSEMAPHORE_H_
|
||||
#define _PLATFORMSEMAPHORE_H_
|
||||
|
||||
#ifndef _TORQUE_TYPES_H_
|
||||
#include "platform/types.h"
|
||||
#endif
|
||||
|
||||
struct Semaphore
|
||||
{
|
||||
static void * createSemaphore(U32 initialCount = 1);
|
||||
static void destroySemaphore(void * semaphore);
|
||||
static bool acquireSemaphore(void * semaphore, bool block = true);
|
||||
static void releaseSemaphore(void * semaphore);
|
||||
|
||||
inline static bool P(void * semaphore, bool block = true) {return(acquireSemaphore(semaphore, block));}
|
||||
inline static void V(void * semaphore) {releaseSemaphore(semaphore);}
|
||||
};
|
||||
|
||||
#endif
|
109
engine/platform/platformString.cc
Executable file
109
engine/platform/platformString.cc
Executable file
@ -0,0 +1,109 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "platform/platform.h"
|
||||
#include "platform/profiler.h"
|
||||
|
||||
// An explanation of the following bit twiddling:
|
||||
//----------------------------------------------------------------
|
||||
// UTF8 encodes characters with a varying # of bytes.
|
||||
// first byte of a UTF8 char is either or
|
||||
// 0x(xxxxxx)
|
||||
// 11(xxxxxx)
|
||||
//
|
||||
// 0xxx xxxx & 0xC0 = 0000 0000 or 0100 0000 = 0x00 or 0x40
|
||||
// 11xx xxxx & 0xC0 = 1100 0000 = 0xC0
|
||||
//
|
||||
// all middle bytes of UTF8 chars start with
|
||||
// 10(xxxxxx)
|
||||
//
|
||||
// 10xx xxxx & 0xC0 = 1000 0000 = 0x80
|
||||
//
|
||||
// so, a bitwise and against 0xC0 will detect whether we are in the middle of a UTF8 char or not.
|
||||
//
|
||||
// see: http://en.wikipedia.org/wiki/UTF8 for a good clear explanation of UTF8
|
||||
/*
|
||||
UTF16 getFirstUTF8Char(const UTF8 *string)
|
||||
{
|
||||
if(string == NULL || *string == 0)
|
||||
return 0;
|
||||
|
||||
PROFILE_START(getFirstUTF8Char);
|
||||
|
||||
if(*string & 0xc0 == 0x80)
|
||||
{
|
||||
// We're in the middle of a character, find the next one
|
||||
string = getNextUTF8Char(string);
|
||||
}
|
||||
|
||||
UTF8 s[5];
|
||||
const UTF8 *ptr;
|
||||
|
||||
// Get first UTF-8 char
|
||||
for(ptr = string+1;(*ptr & 0xc0) == 0x80 && *ptr;ptr++)
|
||||
{
|
||||
}
|
||||
|
||||
dStrncpy((char *)s, (const char *)string, ptr - string);
|
||||
s[ptr - string] = 0;
|
||||
|
||||
UTF16 buf[3];
|
||||
convertUTF8toUTF16(s, buf, sizeof(buf));
|
||||
|
||||
PROFILE_END();
|
||||
|
||||
return buf[0];
|
||||
}
|
||||
|
||||
const UTF8 *getNextUTF8Char(const UTF8 *ptr)
|
||||
{
|
||||
while(*ptr)
|
||||
{
|
||||
ptr++;
|
||||
if((*ptr & 0xc0) != 0x80)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const UTF8 *getNextUTF8Char(const UTF8 *ptr, const U32 n)
|
||||
{
|
||||
for(U32 i=0; i<n && ptr; i++)
|
||||
ptr = getNextUTF8Char(ptr);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
*/
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
const char *getCharSetName(const U32 charSet)
|
||||
{
|
||||
switch(charSet)
|
||||
{
|
||||
case TGE_ANSI_CHARSET: return "ansi";
|
||||
case TGE_SYMBOL_CHARSET: return "symbol";
|
||||
case TGE_SHIFTJIS_CHARSET: return "shiftjis";
|
||||
case TGE_HANGEUL_CHARSET: return "hangeul";
|
||||
case TGE_HANGUL_CHARSET: return "hangul";
|
||||
case TGE_GB2312_CHARSET: return "gb2312";
|
||||
case TGE_CHINESEBIG5_CHARSET: return "chinesebig5";
|
||||
case TGE_OEM_CHARSET: return "oem";
|
||||
case TGE_JOHAB_CHARSET: return "johab";
|
||||
case TGE_HEBREW_CHARSET: return "hebrew";
|
||||
case TGE_ARABIC_CHARSET: return "arabic";
|
||||
case TGE_GREEK_CHARSET: return "greek";
|
||||
case TGE_TURKISH_CHARSET: return "turkish";
|
||||
case TGE_VIETNAMESE_CHARSET: return "vietnamese";
|
||||
case TGE_THAI_CHARSET: return "thai";
|
||||
case TGE_EASTEUROPE_CHARSET: return "easteurope";
|
||||
case TGE_RUSSIAN_CHARSET: return "russian";
|
||||
case TGE_MAC_CHARSET: return "mac";
|
||||
case TGE_BALTIC_CHARSET: return "baltic";
|
||||
}
|
||||
|
||||
AssertISV(false, "getCharSetName - unknown charset! Update table in platformString.cc!");
|
||||
return "";
|
||||
}
|
67
engine/platform/platformThread.h
Executable file
67
engine/platform/platformThread.h
Executable file
@ -0,0 +1,67 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORMTHREAD_H_
|
||||
#define _PLATFORMTHREAD_H_
|
||||
|
||||
#ifndef _TORQUE_TYPES_H_
|
||||
#include "platform/types.h"
|
||||
#endif
|
||||
|
||||
typedef void (*ThreadRunFunction)(S32);
|
||||
|
||||
class Thread
|
||||
{
|
||||
private:
|
||||
static U32 gMainThread;
|
||||
|
||||
protected:
|
||||
void * mData;
|
||||
|
||||
public:
|
||||
Thread(ThreadRunFunction func = 0, S32 arg = 0, bool start_thread = true);
|
||||
virtual ~Thread();
|
||||
|
||||
void start();
|
||||
bool join();
|
||||
|
||||
virtual void run(S32 arg = 0);
|
||||
|
||||
bool isAlive();
|
||||
|
||||
static U32 getCurrentThreadId();
|
||||
static bool compareThreads(U32 thread1, U32 thread2);
|
||||
|
||||
static U32 getMainThread();
|
||||
static void setMainThread();
|
||||
static bool isMainThread();
|
||||
};
|
||||
|
||||
class PlatformThreadStorage;
|
||||
|
||||
/// Platform independent per-thread storage class.
|
||||
class ThreadStorage
|
||||
{
|
||||
enum
|
||||
{
|
||||
PlatformThreadStorageStorageSize = 32,
|
||||
};
|
||||
|
||||
PlatformThreadStorage *mThreadStorage;
|
||||
U8 mStorage[PlatformThreadStorageStorageSize];
|
||||
public:
|
||||
/// ThreadStorage constructor.
|
||||
ThreadStorage();
|
||||
/// ThreadStorage destructor.
|
||||
~ThreadStorage();
|
||||
|
||||
/// returns the per-thread stored void pointer for this ThreadStorage. The default value is NULL.
|
||||
void *get();
|
||||
/// sets the per-thread stored void pointer for this ThreadStorage object.
|
||||
void set(void *data);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
672
engine/platform/platformVideo.cc
Executable file
672
engine/platform/platformVideo.cc
Executable file
@ -0,0 +1,672 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "platform/platformVideo.h"
|
||||
#include "gui/core/guiCanvas.h"
|
||||
#include "console/console.h"
|
||||
#include "platform/gameInterface.h"
|
||||
|
||||
extern void GameDeactivate( bool noRender );
|
||||
extern void GameReactivate();
|
||||
|
||||
// Static class data:
|
||||
Vector<DisplayDevice*> Video::smDeviceList;
|
||||
DisplayDevice* Video::smCurrentDevice;
|
||||
bool Video::smCritical = false;
|
||||
bool Video::smNeedResurrect = false;
|
||||
|
||||
Resolution DisplayDevice::smCurrentRes;
|
||||
bool DisplayDevice::smIsFullScreen;
|
||||
|
||||
|
||||
ConsoleFunctionGroupBegin(Video, "Video control functions.");
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
ConsoleFunction( setDisplayDevice, bool, 2, 6, "( string deviceName, int width, int height=NULL, int bpp=NULL, bool fullScreen=NULL )"
|
||||
"Attempt to set the screen mode using as much information as is provided.")
|
||||
{
|
||||
Resolution currentRes = Video::getResolution();
|
||||
|
||||
U32 width = ( argc > 2 ) ? dAtoi( argv[2] ) : currentRes.w;
|
||||
U32 height = ( argc > 3 ) ? dAtoi( argv[3] ) : currentRes.h;
|
||||
U32 bpp = ( argc > 4 ) ? dAtoi( argv[4] ) : currentRes.bpp;
|
||||
bool fullScreen = ( argc > 5 ) ? dAtob( argv[5] ) : Video::isFullScreen();
|
||||
|
||||
return( Video::setDevice( argv[1], width, height, bpp, fullScreen ) );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
ConsoleFunction( setScreenMode, bool, 5, 5, "( int width, int height, int bpp, bool fullScreen )" )
|
||||
{
|
||||
return( Video::setScreenMode( dAtoi( argv[1] ), dAtoi( argv[2] ), dAtoi( argv[3] ), dAtob( argv[4] ) ) );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
ConsoleFunction( toggleFullScreen, bool, 1, 1, "")
|
||||
{
|
||||
return( Video::toggleFullScreen() );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
ConsoleFunction( isFullScreen, bool, 1, 1, "Is the game running full-screen?")
|
||||
{
|
||||
return( Video::isFullScreen() );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
ConsoleFunction( switchBitDepth, bool, 1, 1, "Switch between 16 or 32 bits. Only works in full screen.")
|
||||
{
|
||||
if ( !Video::isFullScreen() )
|
||||
{
|
||||
Con::warnf( ConsoleLogEntry::General, "Can only switch bit depth in full-screen mode!" );
|
||||
return( false );
|
||||
}
|
||||
|
||||
Resolution res = Video::getResolution();
|
||||
return( Video::setResolution( res.w, res.h, ( res.bpp == 16 ? 32 : 16 ) ) );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
ConsoleFunction( prevResolution, bool, 1, 1, "Switch to previous resolution.")
|
||||
{
|
||||
return( Video::prevRes() );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
ConsoleFunction( nextResolution, bool, 1, 1, "Switch to next resolution.")
|
||||
{
|
||||
return( Video::nextRes() );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
ConsoleFunction( getRes, const char*, 1, 1, "Get the width, height, and bitdepth of the screen.")
|
||||
{
|
||||
static char resBuf[16];
|
||||
Resolution res = Video::getResolution();
|
||||
dSprintf( resBuf, sizeof(resBuf), "%d %d %d", res.w, res.h, res.bpp );
|
||||
return( resBuf );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
ConsoleFunction( setRes, bool, 3, 4, "( int width, int height, int bpp=NULL )")
|
||||
{
|
||||
U32 width = dAtoi( argv[1] );
|
||||
U32 height = dAtoi( argv[2] );
|
||||
U32 bpp = 0;
|
||||
if ( argc == 4 )
|
||||
{
|
||||
bpp = dAtoi( argv[3] );
|
||||
if ( bpp != 16 && bpp != 32 )
|
||||
bpp = 0;
|
||||
}
|
||||
|
||||
return( Video::setResolution( width, height, bpp ) );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
ConsoleFunction( getDesktopResolution, const char*, 1, 1, "Get the width, height, and bitdepth of the screen.")
|
||||
{
|
||||
static char resBuf[32];
|
||||
Resolution res = Video::getDesktopResolution();
|
||||
dSprintf( resBuf, sizeof(resBuf), "%d %d %d", res.w, res.h, res.bpp );
|
||||
return( resBuf );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
ConsoleFunction( getDisplayDeviceList, const char*, 1, 1, "")
|
||||
{
|
||||
return( Video::getDeviceList() );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
ConsoleFunction( getResolutionList, const char*, 2, 2, "")
|
||||
{
|
||||
DisplayDevice* device = Video::getDevice( argv[1] );
|
||||
if ( !device )
|
||||
{
|
||||
Con::warnf( ConsoleLogEntry::General, "\"%s\" display device not found!", argv[1] );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
return( device->getResolutionList() );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
ConsoleFunction( getVideoDriverInfo, const char*, 1, 1, "")
|
||||
{
|
||||
return( Video::getDriverInfo() );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
ConsoleFunction( isDeviceFullScreenOnly, bool, 2, 2, "( string deviceName )")
|
||||
{
|
||||
DisplayDevice* device = Video::getDevice( argv[1] );
|
||||
if ( !device )
|
||||
{
|
||||
Con::warnf( ConsoleLogEntry::General, "\"%s\" display device not found!", argv[1] );
|
||||
return( false );
|
||||
}
|
||||
|
||||
return( device->isFullScreenOnly() );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static F32 sgOriginalGamma = -1.0;
|
||||
static F32 sgGammaCorrection = 0.0;
|
||||
|
||||
ConsoleFunction(videoSetGammaCorrection, void, 2, 2, "setGammaCorrection(gamma);")
|
||||
{
|
||||
argc;
|
||||
F32 g = mClampF(dAtof(argv[1]),0.0,1.0);
|
||||
F32 d = -(g - 0.5);
|
||||
|
||||
if (d != sgGammaCorrection &&
|
||||
(sgOriginalGamma != -1.0 || Video::getGammaCorrection(sgOriginalGamma)))
|
||||
Video::setGammaCorrection(sgOriginalGamma+d);
|
||||
sgGammaCorrection = d;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void Video::init()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void Video::destroy()
|
||||
{
|
||||
if ( smCurrentDevice )
|
||||
{
|
||||
smCritical = true;
|
||||
smCurrentDevice->shutdown();
|
||||
smCritical = false;
|
||||
}
|
||||
|
||||
smCurrentDevice = NULL;
|
||||
|
||||
for ( U32 i = 0; i < smDeviceList.size(); i++ )
|
||||
delete smDeviceList[i];
|
||||
|
||||
smDeviceList.clear();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool Video::installDevice( DisplayDevice *dev )
|
||||
{
|
||||
if ( dev )
|
||||
{
|
||||
smDeviceList.push_back( dev );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool Video::setDevice( const char *renderName, U32 width, U32 height, U32 bpp, bool fullScreen )
|
||||
{
|
||||
S32 deviceIndex = NO_DEVICE;
|
||||
S32 iOpenGL = -1;
|
||||
S32 iD3D = -1;
|
||||
|
||||
for ( S32 i = 0; i < smDeviceList.size(); i++ )
|
||||
{
|
||||
if ( dStrcmp( smDeviceList[i]->mDeviceName, renderName ) == 0 )
|
||||
deviceIndex = i;
|
||||
|
||||
if ( dStrcmp( smDeviceList[i]->mDeviceName, "OpenGL" ) == 0 )
|
||||
iOpenGL = i;
|
||||
if ( dStrcmp( smDeviceList[i]->mDeviceName, "D3D" ) == 0 )
|
||||
iD3D = i;
|
||||
}
|
||||
|
||||
if ( deviceIndex == NO_DEVICE )
|
||||
{
|
||||
Con::warnf( ConsoleLogEntry::General, "\"%s\" display device not found!", renderName );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Change the display device:
|
||||
if ( smDeviceList[deviceIndex] != NULL )
|
||||
{
|
||||
if (smCurrentDevice && smCurrentDevice != smDeviceList[deviceIndex])
|
||||
{
|
||||
Con::printf( "Deactivating the previous display device..." );
|
||||
Game->textureKill();
|
||||
smNeedResurrect = true;
|
||||
smCurrentDevice->shutdown();
|
||||
}
|
||||
|
||||
if (iOpenGL != -1 && !Con::getBoolVariable("$pref::Video::allowOpenGL"))
|
||||
{
|
||||
// change to D3D, delete OpenGL in the recursive call
|
||||
if (dStrcmp(renderName,"OpenGL") == 0)
|
||||
{
|
||||
U32 w, h, d;
|
||||
|
||||
dSscanf(Con::getVariable("$pref::Video::resolution"), "%d %d %d", &w, &h, &d);
|
||||
|
||||
return setDevice("D3D",w,h,d,Con::getBoolVariable("$pref::Video::fullScreen",true));
|
||||
}
|
||||
else
|
||||
{
|
||||
delete smDeviceList[iOpenGL];
|
||||
smDeviceList.erase(iOpenGL);
|
||||
}
|
||||
}
|
||||
else if (iD3D != -1 && !Con::getBoolVariable("$pref::Video::allowD3D"))
|
||||
{
|
||||
// change to OpenGL, delete D3D in the recursive call
|
||||
if (dStrcmp(renderName,"D3D") == 0)
|
||||
{
|
||||
U32 w, h, d;
|
||||
|
||||
dSscanf(Con::getVariable("$pref::Video::resolution"), "%d %d %d", &w, &h, &d);
|
||||
|
||||
return setDevice("OpenGL",w,h,d,Con::getBoolVariable("$pref::Video::fullScreen",true));
|
||||
}
|
||||
else
|
||||
{
|
||||
delete smDeviceList[iD3D];
|
||||
smDeviceList.erase(iD3D);
|
||||
}
|
||||
}
|
||||
else if (iD3D != -1 &&
|
||||
dStrcmp(renderName,"OpenGL") == 0 &&
|
||||
!Con::getBoolVariable("$pref::Video::preferOpenGL") &&
|
||||
!Con::getBoolVariable("$pref::Video::appliedPref"))
|
||||
{
|
||||
U32 w, h, d;
|
||||
|
||||
dSscanf(Con::getVariable("$pref::Video::resolution"), "%d %d %d", &w, &h, &d);
|
||||
Con::setBoolVariable("$pref::Video::appliedPref", true);
|
||||
|
||||
return setDevice("D3D",w,h,d,Con::getBoolVariable("$pref::Video::fullScreen",true));
|
||||
}
|
||||
else
|
||||
Con::setBoolVariable("$pref::Video::appliedPref", true);
|
||||
|
||||
Con::printf( "Activating the %s display device...", renderName );
|
||||
smCurrentDevice = smDeviceList[deviceIndex];
|
||||
|
||||
smCritical = true;
|
||||
bool result = smCurrentDevice->activate( width, height, bpp, fullScreen );
|
||||
smCritical = false;
|
||||
|
||||
if ( result )
|
||||
{
|
||||
if (smNeedResurrect)
|
||||
{
|
||||
Game->textureResurrect();
|
||||
smNeedResurrect = false;
|
||||
}
|
||||
if (sgOriginalGamma != -1.0 || Video::getGammaCorrection(sgOriginalGamma))
|
||||
Video::setGammaCorrection(sgOriginalGamma + sgGammaCorrection);
|
||||
Con::evaluate("resetCanvas();");
|
||||
}
|
||||
|
||||
// The video mode activate may have failed above, return that status
|
||||
return( result );
|
||||
}
|
||||
|
||||
return( false );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool Video::setScreenMode( U32 width, U32 height, U32 bpp, bool fullScreen )
|
||||
{
|
||||
if ( smCurrentDevice )
|
||||
{
|
||||
smCritical = true;
|
||||
bool result = smCurrentDevice->setScreenMode( width, height, bpp, fullScreen );
|
||||
smCritical = false;
|
||||
|
||||
return( result );
|
||||
}
|
||||
|
||||
return( false );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void Video::deactivate()
|
||||
{
|
||||
if ( smCritical ) return;
|
||||
|
||||
GameDeactivate( DisplayDevice::isFullScreen() );
|
||||
if ( smCurrentDevice && DisplayDevice::isFullScreen() )
|
||||
{
|
||||
smCritical = true;
|
||||
|
||||
Game->textureKill();
|
||||
smCurrentDevice->shutdown();
|
||||
|
||||
Platform::minimizeWindow();
|
||||
smCritical = false;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void Video::reactivate()
|
||||
{
|
||||
if ( smCritical ) return;
|
||||
|
||||
if ( smCurrentDevice && DisplayDevice::isFullScreen() )
|
||||
{
|
||||
Resolution res = DisplayDevice::getResolution();
|
||||
|
||||
smCritical = true;
|
||||
smCurrentDevice->activate(res.w,res.h,res.bpp,DisplayDevice::isFullScreen());
|
||||
Game->textureResurrect();
|
||||
|
||||
smCritical = false;
|
||||
if (sgOriginalGamma != -1.0)
|
||||
Video::setGammaCorrection(sgOriginalGamma + sgGammaCorrection);
|
||||
}
|
||||
GameReactivate();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool Video::setResolution( U32 width, U32 height, U32 bpp )
|
||||
{
|
||||
if ( smCurrentDevice )
|
||||
{
|
||||
if ( bpp == 0 )
|
||||
bpp = DisplayDevice::getResolution().bpp;
|
||||
|
||||
smCritical = true;
|
||||
bool result = smCurrentDevice->setResolution( width, height, bpp );
|
||||
smCritical = false;
|
||||
|
||||
return( result );
|
||||
}
|
||||
return( false );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool Video::toggleFullScreen()
|
||||
{
|
||||
if ( smCurrentDevice )
|
||||
{
|
||||
smCritical = true;
|
||||
bool result = smCurrentDevice->toggleFullScreen();
|
||||
smCritical = false;
|
||||
|
||||
return( result );
|
||||
}
|
||||
return( false );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
DisplayDevice* Video::getDevice( const char* renderName )
|
||||
{
|
||||
for ( S32 i = 0; i < smDeviceList.size(); i++ )
|
||||
{
|
||||
if ( dStrcmp( smDeviceList[i]->mDeviceName, renderName ) == 0 )
|
||||
return( smDeviceList[i] );
|
||||
}
|
||||
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool Video::prevRes()
|
||||
{
|
||||
if ( smCurrentDevice )
|
||||
{
|
||||
smCritical = true;
|
||||
bool result = smCurrentDevice->prevRes();
|
||||
smCritical = false;
|
||||
|
||||
return( result );
|
||||
}
|
||||
return( false );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool Video::nextRes()
|
||||
{
|
||||
if ( smCurrentDevice )
|
||||
{
|
||||
smCritical = true;
|
||||
bool result = smCurrentDevice->nextRes();
|
||||
smCritical = false;
|
||||
|
||||
return( result );
|
||||
}
|
||||
return( false );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Resolution Video::getResolution()
|
||||
{
|
||||
return DisplayDevice::getResolution();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
const char* Video::getDeviceList()
|
||||
{
|
||||
U32 deviceCount = smDeviceList.size();
|
||||
if ( deviceCount > 0 ) // It better be...
|
||||
{
|
||||
U32 strLen = 0, i;
|
||||
for ( i = 0; i < deviceCount; i++ )
|
||||
strLen += ( dStrlen( smDeviceList[i]->mDeviceName ) + 1 );
|
||||
|
||||
char* returnString = Con::getReturnBuffer( strLen );
|
||||
dStrcpy( returnString, smDeviceList[0]->mDeviceName );
|
||||
for ( i = 1; i < deviceCount; i++ )
|
||||
{
|
||||
dStrcat( returnString, "\t" );
|
||||
dStrcat( returnString, smDeviceList[i]->mDeviceName );
|
||||
}
|
||||
|
||||
return( returnString );
|
||||
}
|
||||
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
const char* Video::getResolutionList()
|
||||
{
|
||||
if ( smCurrentDevice )
|
||||
return smCurrentDevice->getResolutionList();
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
const char* Video::getDriverInfo()
|
||||
{
|
||||
if ( smCurrentDevice )
|
||||
return smCurrentDevice->getDriverInfo();
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool Video::isFullScreen()
|
||||
{
|
||||
return DisplayDevice::isFullScreen();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void Video::swapBuffers()
|
||||
{
|
||||
if ( smCurrentDevice )
|
||||
smCurrentDevice->swapBuffers();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool Video::getGammaCorrection(F32 &g)
|
||||
{
|
||||
if (smCurrentDevice)
|
||||
return smCurrentDevice->getGammaCorrection(g);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool Video::setGammaCorrection(F32 g)
|
||||
{
|
||||
if (smCurrentDevice)
|
||||
return smCurrentDevice->setGammaCorrection(g);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool Video::setVerticalSync( bool on )
|
||||
{
|
||||
if ( smCurrentDevice )
|
||||
return( smCurrentDevice->setVerticalSync( on ) );
|
||||
|
||||
return( false );
|
||||
}
|
||||
|
||||
ConsoleFunction( setVerticalSync, bool, 2, 2, "setVerticalSync( bool f )" )
|
||||
{
|
||||
argc;
|
||||
return( Video::setVerticalSync( dAtob( argv[1] ) ) );
|
||||
}
|
||||
|
||||
ConsoleFunction( minimizeWindow, void, 1, 1, "minimizeWindow() - Minimize the game window" )
|
||||
{
|
||||
Platform::minimizeWindow();
|
||||
}
|
||||
|
||||
ConsoleFunctionGroupEnd(Video);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
DisplayDevice::DisplayDevice()
|
||||
{
|
||||
mDeviceName = NULL;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void DisplayDevice::init()
|
||||
{
|
||||
smCurrentRes = Resolution( 0, 0, 0 );
|
||||
smIsFullScreen = false;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool DisplayDevice::prevRes()
|
||||
{
|
||||
U32 resIndex;
|
||||
for ( resIndex = mResolutionList.size() - 1; resIndex > 0; resIndex-- )
|
||||
{
|
||||
if ( mResolutionList[resIndex].bpp == smCurrentRes.bpp
|
||||
&& mResolutionList[resIndex].w <= smCurrentRes.w
|
||||
&& mResolutionList[resIndex].h != smCurrentRes.h )
|
||||
break;
|
||||
}
|
||||
|
||||
if ( mResolutionList[resIndex].bpp == smCurrentRes.bpp )
|
||||
return( Video::setResolution( mResolutionList[resIndex].w, mResolutionList[resIndex].h, mResolutionList[resIndex].bpp ) );
|
||||
|
||||
return( false );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool DisplayDevice::nextRes()
|
||||
{
|
||||
U32 resIndex;
|
||||
for ( resIndex = 0; resIndex < mResolutionList.size() - 1; resIndex++ )
|
||||
{
|
||||
if ( mResolutionList[resIndex].bpp == smCurrentRes.bpp
|
||||
&& mResolutionList[resIndex].w >= smCurrentRes.w
|
||||
&& mResolutionList[resIndex].h != smCurrentRes.h )
|
||||
break;
|
||||
}
|
||||
|
||||
if ( mResolutionList[resIndex].bpp == smCurrentRes.bpp )
|
||||
return( Video::setResolution( mResolutionList[resIndex].w, mResolutionList[resIndex].h, mResolutionList[resIndex].bpp ) );
|
||||
|
||||
return( false );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// This function returns a string containing all of the available resolutions for this device
|
||||
// in the format "<bit depth> <width> <height>", separated by tabs.
|
||||
//
|
||||
const char* DisplayDevice::getResolutionList()
|
||||
{
|
||||
if (Con::getBoolVariable("$pref::Video::clipHigh", false))
|
||||
for (S32 i = mResolutionList.size()-1; i >= 0; --i)
|
||||
if (mResolutionList[i].w > 1152 || mResolutionList[i].h > 864)
|
||||
mResolutionList.erase(i);
|
||||
|
||||
if (Con::getBoolVariable("$pref::Video::only16", false))
|
||||
for (S32 i = mResolutionList.size()-1; i >= 0; --i)
|
||||
if (mResolutionList[i].bpp == 32)
|
||||
mResolutionList.erase(i);
|
||||
|
||||
U32 resCount = mResolutionList.size();
|
||||
if ( resCount > 0 )
|
||||
{
|
||||
char* tempBuffer = new char[resCount * 15];
|
||||
tempBuffer[0] = 0;
|
||||
for ( U32 i = 0; i < resCount; i++ )
|
||||
{
|
||||
char newString[15];
|
||||
dSprintf( newString, sizeof( newString ), "%d %d %d\t", mResolutionList[i].w, mResolutionList[i].h, mResolutionList[i].bpp );
|
||||
dStrcat( tempBuffer, newString );
|
||||
}
|
||||
tempBuffer[dStrlen( tempBuffer ) - 1] = 0;
|
||||
|
||||
char* returnString = Con::getReturnBuffer( dStrlen( tempBuffer ) + 1 );
|
||||
dStrcpy( returnString, tempBuffer );
|
||||
delete [] tempBuffer;
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define checkstr(a) a = a ? a : "unknown"
|
||||
|
||||
void Video::setVideo(const char * gapi, const char * vendor, const char * renderer, const char * platform, const char * os, const char * arch)
|
||||
{
|
||||
checkstr(gapi);
|
||||
checkstr(vendor);
|
||||
checkstr(renderer);
|
||||
checkstr(platform);
|
||||
checkstr(os);
|
||||
checkstr(arch);
|
||||
|
||||
Con::executef(7, "setVideo",gapi,vendor,renderer,platform,os,arch);
|
||||
}
|
158
engine/platform/platformVideo.h
Executable file
158
engine/platform/platformVideo.h
Executable file
@ -0,0 +1,158 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORMVIDEO_H_
|
||||
#define _PLATFORMVIDEO_H_
|
||||
|
||||
#ifndef _TORQUE_TYPES_H_
|
||||
#include "platform/types.h"
|
||||
#endif
|
||||
#ifndef _TVECTOR_H_
|
||||
#include "core/tVector.h"
|
||||
#endif
|
||||
#ifndef _PLATFORMASSERT_H_
|
||||
#include "platform/platformAssert.h"
|
||||
#endif
|
||||
|
||||
enum devices
|
||||
{
|
||||
NO_DEVICE = -1,
|
||||
OPENGL_DEVICE,
|
||||
VOODOO2_DEVICE,
|
||||
N_DEVICES
|
||||
};
|
||||
|
||||
struct Resolution;
|
||||
class DisplayDevice;
|
||||
|
||||
|
||||
class Video
|
||||
{
|
||||
private:
|
||||
static Vector<DisplayDevice *> smDeviceList;
|
||||
static DisplayDevice* smCurrentDevice;
|
||||
static bool smCritical;
|
||||
|
||||
public:
|
||||
static bool smNeedResurrect;
|
||||
|
||||
static void init(); // enumerate all the devices
|
||||
static void destroy(); // clean up and shut down
|
||||
static bool installDevice( DisplayDevice *dev );
|
||||
static bool setDevice( const char *renderName, U32 width, U32 height, U32 bpp, bool fullScreen ); // set the current display device
|
||||
static bool setScreenMode( U32 width, U32 height, U32 bpp, bool fullScreen );
|
||||
static void deactivate(); // deactivate current display device
|
||||
static void reactivate(); // reactivate current display device
|
||||
static bool setResolution( U32 width, U32 height, U32 bpp ); // set the current resolution
|
||||
static bool toggleFullScreen(); // toggle full screen mode
|
||||
static DisplayDevice* getDevice( const char* renderName );
|
||||
static const char* getDeviceList(); // get a tab-separated list of all the installed display devices
|
||||
static const char* getResolutionList(); // get a tab-separated list of all the available resolutions for the current device
|
||||
static const char* getDriverInfo(); // get info about the current display device driver
|
||||
static bool prevRes(); // switch to the next smaller available resolution with the same bit depth
|
||||
static bool nextRes(); // switch to the next larger available resolution with the same bit depth
|
||||
static Resolution getResolution(); // get the current resolution
|
||||
static Resolution getDesktopResolution(); // get the current desktop resolution
|
||||
static bool isFullScreen(); // return the current screen state
|
||||
static void swapBuffers(); // page flip
|
||||
static bool getGammaCorrection(F32 &g); // get gamma correction
|
||||
static bool setGammaCorrection(F32 g); // set gamma correction
|
||||
static bool setVerticalSync( bool on ); // enable/disable vertical sync
|
||||
static void setVideo(const char * gapi, const char * vendor, const char * renderer, const char * platform, const char * os, const char * arch);
|
||||
};
|
||||
|
||||
|
||||
struct Resolution
|
||||
{
|
||||
U32 w, h, bpp;
|
||||
|
||||
Resolution( U32 _w = 0, U32 _h = 0, U32 _bpp = 0 )
|
||||
{
|
||||
w = _w;
|
||||
h = _h;
|
||||
bpp = _bpp;
|
||||
}
|
||||
|
||||
bool operator==( const Resolution& otherRes ) const
|
||||
{
|
||||
return ( ( w == otherRes.w ) && ( h == otherRes.h ) && ( bpp == otherRes.bpp ) );
|
||||
}
|
||||
|
||||
void operator=( const Resolution& otherRes )
|
||||
{
|
||||
w = otherRes.w;
|
||||
h = otherRes.h;
|
||||
bpp = otherRes.bpp;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class DisplayDevice
|
||||
{
|
||||
public:
|
||||
const char* mDeviceName;
|
||||
|
||||
protected:
|
||||
static Resolution smCurrentRes;
|
||||
static bool smIsFullScreen;
|
||||
|
||||
Vector<Resolution> mResolutionList;
|
||||
bool mFullScreenOnly;
|
||||
|
||||
public:
|
||||
DisplayDevice();
|
||||
|
||||
virtual void initDevice() = 0;
|
||||
virtual bool activate( U32 width, U32 height, U32 bpp, bool fullScreen ) = 0;
|
||||
virtual void shutdown() = 0;
|
||||
|
||||
virtual bool setScreenMode( U32 width, U32 height, U32 bpp, bool fullScreen, bool forceIt = false, bool repaint = true ) = 0;
|
||||
virtual bool setResolution( U32 width, U32 height, U32 bpp );
|
||||
virtual bool toggleFullScreen();
|
||||
virtual void swapBuffers() = 0;
|
||||
virtual const char* getDriverInfo() = 0;
|
||||
virtual bool getGammaCorrection(F32 &g) = 0;
|
||||
virtual bool setGammaCorrection(F32 g) = 0;
|
||||
virtual bool setVerticalSync( bool on ) = 0;
|
||||
|
||||
bool prevRes();
|
||||
bool nextRes();
|
||||
const char* getResolutionList();
|
||||
bool isFullScreenOnly() { return( mFullScreenOnly ); }
|
||||
|
||||
static void init();
|
||||
static Resolution getResolution();
|
||||
static bool isFullScreen();
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
inline bool DisplayDevice::setResolution( U32 width, U32 height, U32 bpp )
|
||||
{
|
||||
return setScreenMode( width, height, bpp, smIsFullScreen );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
inline bool DisplayDevice::toggleFullScreen()
|
||||
{
|
||||
return setScreenMode( smCurrentRes.w, smCurrentRes.h, smCurrentRes.bpp, !smIsFullScreen );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
inline Resolution DisplayDevice::getResolution()
|
||||
{
|
||||
return smCurrentRes;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
inline bool DisplayDevice::isFullScreen()
|
||||
{
|
||||
return smIsFullScreen;
|
||||
}
|
||||
|
||||
#endif // _H_PLATFORMVIDEO
|
833
engine/platform/profiler.cc
Executable file
833
engine/platform/profiler.cc
Executable file
@ -0,0 +1,833 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Note that we do all our memory managament directly against the OS
|
||||
// facilities. This simplifies things, as it means the profiler is
|
||||
// not re-entrant during pushes/pops.
|
||||
//
|
||||
// (This requirement might not be necessary? Let's question this
|
||||
// assumption later... -- BJG)
|
||||
|
||||
#if defined(__MACOSX__)
|
||||
#include <Carbon/Carbon.h>
|
||||
#endif
|
||||
#include "platform/profiler.h"
|
||||
#include "platform/platformMutex.h"
|
||||
#include "util/safeDelete.h"
|
||||
#include <stdlib.h> // gotta use malloc and free directly
|
||||
|
||||
#ifdef TORQUE_ENABLE_PROFILER
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ThreadStorage gProfilerReentrancyGuard;
|
||||
volatile bool gGlobalProfilerReentrancyGuard = false;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if defined(TORQUE_SUPPORTS_VC_INLINE_X86_ASM)
|
||||
// platform specific get hires times...
|
||||
void startHighResolutionTimer(U32 time[2])
|
||||
{
|
||||
//time[0] = Platform::getRealMilliseconds();
|
||||
|
||||
__asm
|
||||
{
|
||||
push eax
|
||||
push edx
|
||||
push ecx
|
||||
rdtsc
|
||||
mov ecx, time
|
||||
mov DWORD PTR [ecx], eax
|
||||
mov DWORD PTR [ecx + 4], edx
|
||||
pop ecx
|
||||
pop edx
|
||||
pop eax
|
||||
}
|
||||
}
|
||||
|
||||
U32 endHighResolutionTimer(U32 time[2])
|
||||
{
|
||||
U32 ticks;
|
||||
//ticks = Platform::getRealMilliseconds() - time[0];
|
||||
//return ticks;
|
||||
|
||||
__asm
|
||||
{
|
||||
push eax
|
||||
push edx
|
||||
push ecx
|
||||
//db 0fh, 31h
|
||||
rdtsc
|
||||
mov ecx, time
|
||||
sub edx, DWORD PTR [ecx+4]
|
||||
sbb eax, DWORD PTR [ecx]
|
||||
mov DWORD PTR ticks, eax
|
||||
pop ecx
|
||||
pop edx
|
||||
pop eax
|
||||
}
|
||||
return ticks;
|
||||
}
|
||||
|
||||
#elif defined(TORQUE_SUPPORTS_GCC_INLINE_X86_ASM)
|
||||
|
||||
// platform specific get hires times...
|
||||
void startHighResolutionTimer(U32 time[2])
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
"rdtsc\n"
|
||||
: "=a" (time[0]), "=d" (time[1])
|
||||
);
|
||||
}
|
||||
|
||||
U32 endHighResolutionTimer(U32 time[2])
|
||||
{
|
||||
U32 ticks;
|
||||
__asm__ __volatile__(
|
||||
"rdtsc\n"
|
||||
"sub 0x4(%%ecx), %%edx\n"
|
||||
"sbb (%%ecx), %%eax\n"
|
||||
: "=a" (ticks) : "c" (time)
|
||||
);
|
||||
return ticks;
|
||||
}
|
||||
|
||||
#elif defined(TORQUE_OS_MAC)
|
||||
|
||||
void startHighResolutionTimer(U32 time[2]) {
|
||||
UnsignedWide t;
|
||||
Microseconds(&t);
|
||||
time[0] = t.lo;
|
||||
time[1] = t.hi;
|
||||
}
|
||||
|
||||
U32 endHighResolutionTimer(U32 time[2]) {
|
||||
UnsignedWide t;
|
||||
Microseconds(&t);
|
||||
return t.lo - time[0];
|
||||
// given that we're returning a 32 bit integer, and this is unsigned subtraction...
|
||||
// it will just wrap around, we don't need the upper word of the time.
|
||||
// NOTE: the code assumes that more than 3 hrs will not go by between calls to startHighResolutionTimer() and endHighResolutionTimer().
|
||||
// I mean... that damn well better not happen anyway.
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void startHighResolutionTimer(U32 time[2])
|
||||
{
|
||||
}
|
||||
|
||||
U32 endHighResolutionTimer(U32 time[2])
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ProfilerRoot *ProfilerRoot::smRootList = NULL;
|
||||
U32 ProfilerRoot::smRootCount = 0;
|
||||
|
||||
ProfilerRoot::ProfilerRoot(const char *name)
|
||||
{
|
||||
for(ProfilerRoot *walk = smRootList; walk; walk = walk->mNextRoot)
|
||||
{
|
||||
if(!dStrcmp(walk->mName, name))
|
||||
{
|
||||
AssertISV(false, avar("ProfilerRoot::ProfilerRoot - encountered "
|
||||
"duplicate profiler block name '%s'. All block "
|
||||
"names must be unique!", name));
|
||||
}
|
||||
}
|
||||
|
||||
// Note down our data.
|
||||
mName = name;
|
||||
mNameHash = _StringTable::hashString(name);
|
||||
mID = smRootCount++;
|
||||
|
||||
// Link us onto the master list.
|
||||
mNextRoot = smRootList;
|
||||
smRootList = this;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ProfilerRootData::ProfilerRootData()
|
||||
{
|
||||
mFirstProfilerData = NULL;
|
||||
mEnabled = true;
|
||||
reset();
|
||||
}
|
||||
|
||||
ProfilerRootData::~ProfilerRootData()
|
||||
{
|
||||
}
|
||||
|
||||
void ProfilerRootData::reset()
|
||||
{
|
||||
mTotalTime = 0;
|
||||
mSubTime = 0;
|
||||
mTotalInvokeCount = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ProfilerData::ProfilerData()
|
||||
{
|
||||
dMemset(this, 0, sizeof(ProfilerData));
|
||||
}
|
||||
|
||||
ProfilerData::~ProfilerData()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ProfilerInstance::ProfilerInstance()
|
||||
{
|
||||
// Don't set thread ID here as we might be being allocated
|
||||
// anywhere...
|
||||
mThreadID = 0;
|
||||
|
||||
// But mutex is OK to allocate now.
|
||||
mMutex = Mutex::createMutex();
|
||||
|
||||
// Set up the root ProfilerData.
|
||||
mProfileList = mRootProfilerData = mCurrentProfilerData = (ProfilerData*)malloc(sizeof(ProfilerData));
|
||||
constructInPlace(mProfileList);
|
||||
|
||||
// Allocate our ProfilerRootData table.
|
||||
mRootTable = NULL;
|
||||
mRootCount = 0;
|
||||
growRoots(ProfilerRoot::smRootCount);
|
||||
|
||||
// Set up general misc state
|
||||
mEnabled = false;
|
||||
mStackDepth = 0;
|
||||
mNextEnable = false;
|
||||
mMaxStackDepth = MaxStackDepth;
|
||||
mDumpToConsole = false;
|
||||
mDumpToFile = false;
|
||||
dMemset(mDumpFileName, 0, sizeof(mDumpFileName));
|
||||
|
||||
mRootCount = ProfilerRoot::smRootCount;
|
||||
}
|
||||
|
||||
ProfilerInstance::~ProfilerInstance()
|
||||
{
|
||||
MutexHandle m;
|
||||
m.lock(mMutex);
|
||||
|
||||
free(mRootTable);
|
||||
|
||||
// Walk the profilelist and free things on it.
|
||||
ProfilerData *walk = mProfileList, *tmp;
|
||||
while(walk)
|
||||
{
|
||||
tmp = walk;
|
||||
walk = walk->mNextProfilerData;
|
||||
|
||||
destructInPlace(tmp);
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
m.unlock();
|
||||
Mutex::destroyMutex(mMutex);
|
||||
}
|
||||
|
||||
void ProfilerInstance::hashPush(ProfilerRoot *pr)
|
||||
{
|
||||
// We need the stack depth tracked at all times so we won't get fscked
|
||||
// when the profiler gets turned on in the midst of things... It's also
|
||||
// a nice way to validate we aren't in any weird situations vis a vis
|
||||
// our profile block boundary setups.
|
||||
|
||||
mStackDepth++;
|
||||
AssertFatal(mStackDepth <= mMaxStackDepth,
|
||||
"Stack overflow in profiler. You may have mismatched PROFILE_START and PROFILE_ENDs");
|
||||
|
||||
if(!mEnabled)
|
||||
return;
|
||||
|
||||
// Make sure we've got our roots.
|
||||
growRoots(ProfilerRoot::smRootCount);
|
||||
|
||||
// Convert from our ProfilerRoot to our ProfilerRootData.
|
||||
ProfilerRootData *root = lookup(pr);
|
||||
|
||||
ProfilerData *nextProfiler = NULL;
|
||||
|
||||
// Fast check for cases when we hit a profile block from itself.
|
||||
if(!root->mEnabled || mCurrentProfilerData->mOwningRoot == root)
|
||||
{
|
||||
mCurrentProfilerData->mSubDepth++;
|
||||
return;
|
||||
}
|
||||
|
||||
// Check to see if we're seeing the same profiler block we saw before,
|
||||
// and put in the cache.
|
||||
//
|
||||
// This gives big wins in cases like:
|
||||
// for(S32 i=0; i<1000; i++)
|
||||
// {
|
||||
// PROFILE_START(foo); doSomething(); PROFILE_END();
|
||||
// }
|
||||
if(mCurrentProfilerData->mLastSeenProfiler &&
|
||||
mCurrentProfilerData->mLastSeenProfiler->mOwningRoot == root)
|
||||
nextProfiler = mCurrentProfilerData->mLastSeenProfiler;
|
||||
|
||||
// Did we get a hit on the cache?
|
||||
if(!nextProfiler)
|
||||
{
|
||||
// Didn't, so let's search for it.
|
||||
|
||||
// first see if it's in the hash table...
|
||||
U32 index = pr->mNameHash & (ProfilerData::HashTableSize - 1);
|
||||
nextProfiler = mCurrentProfilerData->mChildHash[index];
|
||||
while(nextProfiler)
|
||||
{
|
||||
if(nextProfiler->mOwningRoot == root)
|
||||
break;
|
||||
nextProfiler = nextProfiler->mNextHash;
|
||||
}
|
||||
|
||||
// It wasn't, so let's create a new one.
|
||||
if(!nextProfiler)
|
||||
{
|
||||
// Allocate...
|
||||
nextProfiler = (ProfilerData *) malloc(sizeof(ProfilerData));
|
||||
constructInPlace(nextProfiler);
|
||||
|
||||
// Link it to its ProfilerRootData
|
||||
nextProfiler->mOwningRoot = root;
|
||||
nextProfiler->mNextForRoot = root->mFirstProfilerData;
|
||||
root->mFirstProfilerData = nextProfiler;
|
||||
|
||||
// Put it on our ProfilerData list.
|
||||
nextProfiler->mNextProfilerData = mProfileList;
|
||||
mProfileList = nextProfiler;
|
||||
|
||||
// Hash it, too.
|
||||
nextProfiler->mNextHash = mCurrentProfilerData->mChildHash[index];
|
||||
mCurrentProfilerData->mChildHash[index] = nextProfiler;
|
||||
|
||||
// Fill in parent/child relationships.
|
||||
nextProfiler->mParent = mCurrentProfilerData;
|
||||
nextProfiler->mNextSibling = mCurrentProfilerData->mFirstChild;
|
||||
mCurrentProfilerData->mFirstChild = nextProfiler;
|
||||
}
|
||||
}
|
||||
|
||||
// Note invocations.
|
||||
root->mTotalInvokeCount++;
|
||||
nextProfiler->mInvokeCount++;
|
||||
|
||||
// Note our current position, and cache what we last saw.
|
||||
mCurrentProfilerData->mLastSeenProfiler = nextProfiler;
|
||||
mCurrentProfilerData = nextProfiler;
|
||||
|
||||
// Start the timer.
|
||||
startHighResolutionTimer(nextProfiler->mStartTime);
|
||||
}
|
||||
|
||||
void ProfilerInstance::hashPop()
|
||||
{
|
||||
// Update the stack depth.
|
||||
mStackDepth--;
|
||||
AssertFatal(mStackDepth >= 0, "Stack underflow in profiler. You may have mismatched PROFILE_START and PROFILE_ENDs");
|
||||
|
||||
if(mEnabled)
|
||||
{
|
||||
// If we're in a subdepth situation, then just dec it.
|
||||
if(mCurrentProfilerData->mSubDepth)
|
||||
{
|
||||
mCurrentProfilerData->mSubDepth--;
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, let's end the timer!
|
||||
F64 fElapsed = endHighResolutionTimer(mCurrentProfilerData->mStartTime);
|
||||
|
||||
// Update our total time, both for this instance and the root.
|
||||
mCurrentProfilerData->mTotalTime += fElapsed;
|
||||
mCurrentProfilerData->mOwningRoot->mTotalTime += fElapsed;
|
||||
|
||||
// Update our parent's subtime as well.
|
||||
mCurrentProfilerData->mParent->mSubTime += fElapsed;
|
||||
|
||||
// Parent might be root node, so make sure we don't go into
|
||||
// never-never land.
|
||||
if(mCurrentProfilerData->mParent->mOwningRoot)
|
||||
mCurrentProfilerData->mParent->mOwningRoot->mSubTime += fElapsed;
|
||||
|
||||
// And indicate we're back to our parent.
|
||||
mCurrentProfilerData = mCurrentProfilerData->mParent;
|
||||
}
|
||||
|
||||
// If we've bottomed out, we're at a frame boundary and can do dumps,
|
||||
// and other frame boundary actions with impunity.
|
||||
if(mStackDepth == 0)
|
||||
{
|
||||
MutexHandle m;
|
||||
m.lock(mMutex);
|
||||
|
||||
gProfilerReentrancyGuard.set((void*)1);
|
||||
|
||||
// Grab a lock on our mutex so we don't have people changing this
|
||||
// stuff when we aren't ready.
|
||||
|
||||
// Do dumps...
|
||||
bool doStart = false;
|
||||
|
||||
if(mDumpToConsole || mDumpToFile)
|
||||
{
|
||||
dump();
|
||||
doStart = true;
|
||||
}
|
||||
|
||||
// apply the next enable...
|
||||
if(!mEnabled && mNextEnable)
|
||||
doStart = true;
|
||||
|
||||
mEnabled = mNextEnable;
|
||||
|
||||
gProfilerReentrancyGuard.set((void*)0);
|
||||
|
||||
// Finally, kick off the timer if appropriate.
|
||||
if(doStart)
|
||||
startHighResolutionTimer(mCurrentProfilerData->mStartTime);
|
||||
}
|
||||
}
|
||||
|
||||
void ProfilerInstance::validate()
|
||||
{
|
||||
mEnabled = false;
|
||||
|
||||
// We may be running this in situations where the roots don't match yet,
|
||||
// so let's silence this check -- BJG
|
||||
//AssertISV(mRootCount == ProfilerRoot::smRootCount, "ProfilerInstance::validate - mismatched root count!");
|
||||
|
||||
// Check by walking the global roots, fetching our instance root, and
|
||||
// making sure its children are all properly set up/linked.
|
||||
for(ProfilerRoot *prWalk = ProfilerRoot::smRootList; prWalk; prWalk = prWalk->mNextRoot)
|
||||
{
|
||||
ProfilerRootData *walk = lookup(prWalk);
|
||||
for(ProfilerData *dp = walk->mFirstProfilerData; dp; dp = dp->mNextForRoot)
|
||||
{
|
||||
AssertISV(dp->mOwningRoot == walk,
|
||||
"ProfilerInstance::validate - encountered a ProfilerData under the wrong root!");
|
||||
|
||||
// check if it's in the parent's list...
|
||||
ProfilerData *wk;
|
||||
for(wk = dp->mParent->mFirstChild; wk; wk = wk->mNextSibling)
|
||||
if(wk == dp)
|
||||
break;
|
||||
|
||||
AssertISV(wk,
|
||||
"ProfilerInstance::validate - could not find a ProfilerData under its parent's child list!");
|
||||
|
||||
// Check that it's in the right hash.
|
||||
for(wk = dp->mParent->mChildHash[prWalk->mNameHash & (ProfilerData::HashTableSize - 1)] ;
|
||||
wk; wk = wk->mNextHash)
|
||||
if(wk == dp)
|
||||
break;
|
||||
|
||||
AssertISV(wk, "ProfilerInstance::validate - could not find a ProfilerDataa in its parent's hash table!");
|
||||
}
|
||||
}
|
||||
|
||||
mEnabled = true;
|
||||
}
|
||||
|
||||
static S32 QSORT_CALLBACK rootDataCompare(const void *s1, const void *s2)
|
||||
{
|
||||
const ProfilerRootData *r1 = *((ProfilerRootData **) s1);
|
||||
const ProfilerRootData *r2 = *((ProfilerRootData **) s2);
|
||||
|
||||
// Because of overflow issues, we have to compare the F64s rather than
|
||||
// subtract and return the delta; doing this can result in breakage
|
||||
// with numbers in excess of the S32 range. (Note how you commonly
|
||||
// experienced weird NS time sorting in the profiler prior to this fix.)
|
||||
const F64 time1 = (r1->mTotalTime - r1->mSubTime);
|
||||
const F64 time2 = (r2->mTotalTime - r2->mSubTime);
|
||||
|
||||
// Compare and return the right value, goofy. :)
|
||||
if(time1 > time2)
|
||||
return -1;
|
||||
else if(time1 < time2)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ProfilerInstance::printFunc(char *fmt, ...)
|
||||
{
|
||||
U8 buffer[512];
|
||||
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr, fmt);
|
||||
dVsprintf((char*)buffer, 512, fmt, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
if(gProfiler->mCurrentDumpIsConsole)
|
||||
Con::printf("%s", buffer);
|
||||
|
||||
if(gProfiler->mCurrentDumpIsFile)
|
||||
gProfiler->mCurrentDumpStream->writeLine(&buffer[0]);
|
||||
}
|
||||
|
||||
void ProfilerInstance::printSortedRootData(Vector<ProfilerRootData*> &rootVector, F64 totalTime)
|
||||
{
|
||||
printFunc("Profiled blocks ordered by non-sub total time:");
|
||||
printFunc("");
|
||||
printFunc("%%NSTime %% Time Invoke # Name");
|
||||
for(U32 i = 0; i < rootVector.size(); i++)
|
||||
{
|
||||
printFunc("%7.3f %7.3f %8d %s",
|
||||
F32(100 * (rootVector[i]->mTotalTime - rootVector[i]->mSubTime) / totalTime),
|
||||
F32(100 * rootVector[i]->mTotalTime / totalTime),
|
||||
rootVector[i]->mTotalInvokeCount,
|
||||
rootVector[i]->mRoot->mName);
|
||||
rootVector[i]->mTotalInvokeCount = 0;
|
||||
rootVector[i]->mTotalTime = 0;
|
||||
rootVector[i]->mSubTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ProfilerInstance::profilerDataDumpRecurse(ProfilerData *data, char *buffer, U32 bufferLen, F64 totalTime)
|
||||
{
|
||||
if(!data->mOwningRoot)
|
||||
{
|
||||
printFunc( "------------- ROOT ----------------");
|
||||
}
|
||||
else
|
||||
{
|
||||
printFunc("%7.3f %7.3f %8d %s%s",
|
||||
100 * data->mTotalTime / totalTime,
|
||||
100 * (data->mTotalTime - data->mSubTime) / totalTime,
|
||||
data->mInvokeCount,
|
||||
buffer,
|
||||
data->mOwningRoot->mRoot->mName );
|
||||
}
|
||||
|
||||
// Reset as part of printing (Good idea? -- BJG)
|
||||
data->mTotalTime = 0;
|
||||
data->mSubTime = 0;
|
||||
data->mInvokeCount = 0;
|
||||
|
||||
buffer[bufferLen] = ' ';
|
||||
buffer[bufferLen+1] = ' ';
|
||||
buffer[bufferLen+2] = 0;
|
||||
|
||||
// Sort our children by total time.
|
||||
ProfilerData *list = NULL;
|
||||
while(data->mFirstChild)
|
||||
{
|
||||
ProfilerData *ins = data->mFirstChild;
|
||||
data->mFirstChild = ins->mNextSibling;
|
||||
ProfilerData **walk = &list;
|
||||
while(*walk && (*walk)->mTotalTime > ins->mTotalTime)
|
||||
walk = &(*walk)->mNextSibling;
|
||||
ins->mNextSibling = *walk;
|
||||
*walk = ins;
|
||||
}
|
||||
|
||||
// And recurse
|
||||
data->mFirstChild = list;
|
||||
while(list)
|
||||
{
|
||||
if(list->mInvokeCount)
|
||||
profilerDataDumpRecurse(list, buffer, bufferLen + 2, totalTime);
|
||||
list = list->mNextSibling;
|
||||
}
|
||||
buffer[bufferLen] = 0;
|
||||
}
|
||||
|
||||
void ProfilerInstance::dump()
|
||||
{
|
||||
// We assume that we've locked our ProfilerInstance mutex by this point.
|
||||
|
||||
// But we have to get the dump mutex, too, no sense having multiple
|
||||
// dumps going at once.
|
||||
MutexHandle m;
|
||||
m.lock(gProfiler->mDumpMutex);
|
||||
|
||||
// May have some profiled calls... gotta turn em off.
|
||||
bool enableSave = mEnabled;
|
||||
mEnabled = false;
|
||||
mStackDepth++;
|
||||
|
||||
// First, do our search/sort book-keeping.
|
||||
|
||||
// Build a list of all our roots, sorted by non-sub time.
|
||||
Vector<ProfilerRootData *> rootVector(ProfilerRoot::smRootCount);
|
||||
F64 totalTime = 0;
|
||||
for(U32 i=0; i<ProfilerRoot::smRootCount; i++)
|
||||
{
|
||||
rootVector.push_back(mRootTable + i);
|
||||
ProfilerRootData &prd = mRootTable[i];
|
||||
totalTime += prd.mTotalTime - prd.mSubTime;
|
||||
}
|
||||
dQsort((void *)rootVector.address(), rootVector.size(), sizeof(ProfilerRootData *), rootDataCompare);
|
||||
|
||||
// Set up our console status.
|
||||
gProfiler->mCurrentDumpIsConsole = mDumpToConsole;
|
||||
|
||||
// Open our stream, if we need it.
|
||||
FileStream fws;
|
||||
|
||||
if(mDumpToFile)
|
||||
{
|
||||
bool success = fws.open(mDumpFileName, FileStream::Write);
|
||||
|
||||
if(success)
|
||||
{
|
||||
gProfiler->mCurrentDumpIsFile = true;
|
||||
gProfiler->mCurrentDumpStream = &fws;
|
||||
}
|
||||
else
|
||||
{
|
||||
gProfiler->mCurrentDumpIsFile = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gProfiler->mCurrentDumpIsFile = false;
|
||||
}
|
||||
|
||||
|
||||
// Now, generate our info and blast it out to the appropriate place
|
||||
// (ie, console or file.)
|
||||
printFunc("Profiler Data Dump:");
|
||||
printSortedRootData(rootVector, totalTime);
|
||||
|
||||
printFunc("");
|
||||
printFunc("Profiler Data Dump:");
|
||||
|
||||
// Allocate a buffer for indentation use...
|
||||
char depthBuffer[MaxStackDepth * 2 + 1];
|
||||
depthBuffer[0] = 0;
|
||||
|
||||
// Make the recursive call.
|
||||
U32 depth = 0;
|
||||
profilerDataDumpRecurse(mCurrentProfilerData, depthBuffer, 0, totalTime);
|
||||
|
||||
// Clean up the stream. (Check against the actual write-to-file flag in
|
||||
// the profiler, as this won't get set if we failed to open the stream.)
|
||||
if(gProfiler->mCurrentDumpIsFile)
|
||||
fws.close();
|
||||
|
||||
// Clear our flags.
|
||||
mDumpToConsole = false;
|
||||
mDumpToFile = false;
|
||||
mDumpFileName[0] = '\0';
|
||||
|
||||
// Restore our state.
|
||||
mEnabled = enableSave;
|
||||
mStackDepth--;
|
||||
}
|
||||
|
||||
void ProfilerInstance::enable(bool enable)
|
||||
{
|
||||
MutexHandle m;
|
||||
m.lock(mMutex);
|
||||
|
||||
mNextEnable = enable;
|
||||
|
||||
// Implicit unlock.
|
||||
}
|
||||
|
||||
void ProfilerInstance::dumpToConsole()
|
||||
{
|
||||
MutexHandle m;
|
||||
m.lock(mMutex);
|
||||
|
||||
mDumpToConsole = true;
|
||||
|
||||
// If it's a dead thread, then pop never gets called. So we have a quick
|
||||
// check here to take care of this take. The pop functionality is under
|
||||
// mutex, so we can safely do it here.
|
||||
if(mStackDepth == 0)
|
||||
{
|
||||
mEnabled = false;
|
||||
mNextEnable = true;
|
||||
|
||||
// This will dump and reset the flag for us.
|
||||
dump();
|
||||
}
|
||||
|
||||
// Implicit unlock.
|
||||
}
|
||||
|
||||
void ProfilerInstance::growRoots(U32 newCount)
|
||||
{
|
||||
// If it's the same size or smaller as we've got now, early out.
|
||||
if(newCount <= mRootCount)
|
||||
return;
|
||||
|
||||
// Otherwise, we have to allocate some new space and update all our
|
||||
// pointers. W00t!
|
||||
|
||||
// Get new memory...
|
||||
ProfilerRootData *newRoots = (ProfilerRootData*)malloc(sizeof(ProfilerRootData) * newCount);
|
||||
|
||||
// ... then copy our extant data into it...
|
||||
if(mRootTable)
|
||||
dMemcpy(newRoots, mRootTable, sizeof(ProfilerRootData) * mRootCount);
|
||||
|
||||
// ... and finally initialize the uninitialized entries.
|
||||
for(U32 i=mRootCount; i<newCount; i++)
|
||||
constructInPlace(&newRoots[i]);
|
||||
|
||||
// Now walk our ProfilerDatas and update their pointers.
|
||||
for(ProfilerData *pdWalk = mProfileList; pdWalk; pdWalk = pdWalk->mNextProfilerData)
|
||||
{
|
||||
// This is silly pointer math, double check it -- BJG.
|
||||
if(pdWalk->mOwningRoot)
|
||||
pdWalk->mOwningRoot = (pdWalk->mOwningRoot - mRootTable) + newRoots;
|
||||
}
|
||||
|
||||
mRootTable = newRoots;
|
||||
mRootCount = newCount;
|
||||
|
||||
// Walk the ProfilerRoots and make sure we're pointing to them.
|
||||
for(ProfilerRoot *prWalk = ProfilerRoot::smRootList; prWalk; prWalk = prWalk->mNextRoot)
|
||||
lookup(prWalk)->mRoot = prWalk;
|
||||
|
||||
// And we're done. Double check. :)
|
||||
validate();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/// Pointer to the global profiler.
|
||||
Profiler *gProfiler = NULL;
|
||||
|
||||
static Profiler aProfiler;
|
||||
|
||||
Profiler::Profiler()
|
||||
{
|
||||
mInstanceListHead = NULL;
|
||||
mDumpMutex = Mutex::createMutex();
|
||||
|
||||
// Singleton magic:
|
||||
AssertISV(gProfiler==NULL, "Profiler - a Profiler is already present!");
|
||||
gProfiler = this;
|
||||
|
||||
}
|
||||
|
||||
Profiler::~Profiler()
|
||||
{
|
||||
// Make it so we don't do anything while we're in the destructor.
|
||||
gGlobalProfilerReentrancyGuard = true;
|
||||
Mutex::destroyMutex(mDumpMutex);
|
||||
|
||||
// Clean up the instance list.
|
||||
ProfilerInstance *walk = mInstanceListHead, *tmp;
|
||||
while(walk)
|
||||
{
|
||||
tmp = walk;
|
||||
walk = walk->mNextInstance;
|
||||
|
||||
destructInPlace(tmp);
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
// Singleton magic:
|
||||
AssertISV(gProfiler==this, "Profiler - a Profiler other than me is present!");
|
||||
gProfiler = NULL;
|
||||
|
||||
gGlobalProfilerReentrancyGuard = false;
|
||||
}
|
||||
|
||||
ProfilerInstance *Profiler::getCurrentInstance()
|
||||
{
|
||||
if(gGlobalProfilerReentrancyGuard || gProfilerReentrancyGuard.get())
|
||||
return NULL;
|
||||
|
||||
// Get the instance for this thread, if any.
|
||||
ProfilerInstance *pi = (ProfilerInstance*)mCurrentInstance.get();
|
||||
|
||||
// If not, allocate a new one and link it into the
|
||||
// list.
|
||||
if(!pi)
|
||||
{
|
||||
gProfilerReentrancyGuard.set((void*)1);
|
||||
|
||||
pi = (ProfilerInstance*)malloc(sizeof(ProfilerInstance));
|
||||
constructInPlace(pi);
|
||||
|
||||
pi->mThreadID = Thread::getCurrentThreadId();
|
||||
|
||||
pi->mNextInstance = mInstanceListHead;
|
||||
mInstanceListHead = pi;
|
||||
|
||||
mCurrentInstance.set(pi);
|
||||
|
||||
gProfilerReentrancyGuard.set(0);
|
||||
}
|
||||
|
||||
return pi;
|
||||
}
|
||||
|
||||
void Profiler::hashPush(ProfilerRoot *root)
|
||||
{
|
||||
ProfilerInstance *pi = getCurrentInstance();
|
||||
if(pi)
|
||||
pi->hashPush(root);
|
||||
}
|
||||
|
||||
void Profiler::hashPop()
|
||||
{
|
||||
ProfilerInstance *pi = getCurrentInstance();
|
||||
if(pi)
|
||||
pi->hashPop();
|
||||
}
|
||||
|
||||
ProfilerInstance *Profiler::getInstanceByID(U32 id)
|
||||
{
|
||||
// Walk the list and get the matching thing.
|
||||
ProfilerInstance *walk = mInstanceListHead;
|
||||
|
||||
while(walk)
|
||||
{
|
||||
if(walk->mThreadID == id)
|
||||
return walk;
|
||||
|
||||
walk = walk->mNextInstance;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void Profiler::enable(bool enable)
|
||||
{
|
||||
for(ProfilerInstance *walk = mInstanceListHead; walk; walk = walk->mNextInstance)
|
||||
walk->enable(enable);
|
||||
}
|
||||
|
||||
void Profiler::dumpToConsole()
|
||||
{
|
||||
for(ProfilerInstance *walk = mInstanceListHead; walk; walk = walk->mNextInstance)
|
||||
walk->dumpToConsole();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleFunction(profilerEnable, void, 2, 2, "(bool enable) - Turn the profiler on and off.")
|
||||
{
|
||||
if(gProfiler) gProfiler->enable(dAtob(argv[1]));
|
||||
}
|
||||
|
||||
ConsoleFunction(profilerDump, void, 1, 1, "() - Dump all profiled threads' information.")
|
||||
{
|
||||
if(gProfiler) gProfiler->dumpToConsole();
|
||||
}
|
||||
|
||||
#endif
|
557
engine/platform/profiler.h
Executable file
557
engine/platform/profiler.h
Executable file
@ -0,0 +1,557 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PROFILER_H_
|
||||
#define _PROFILER_H_
|
||||
|
||||
#include "core/torqueConfig.h"
|
||||
|
||||
#ifdef TORQUE_ENABLE_PROFILER
|
||||
|
||||
// First, define our macros; that way if we use the profiler in any
|
||||
// of the includes we depend on, we'll have them available.
|
||||
#define PROFILE_START(name) \
|
||||
static ProfilerRoot pdata##name##obj (#name); \
|
||||
if(gProfiler) gProfiler->hashPush(& pdata##name##obj )
|
||||
|
||||
#define PROFILE_END() if(gProfiler) gProfiler->hashPop()
|
||||
|
||||
#else
|
||||
|
||||
// If profiler is disabled then just stub the blocks out.
|
||||
#define PROFILE_START(x)
|
||||
#define PROFILE_END()
|
||||
|
||||
#endif
|
||||
|
||||
// Then include our includes and the real profiler code that needs them.
|
||||
#ifdef TORQUE_ENABLE_PROFILER
|
||||
|
||||
#include "platform/platform.h"
|
||||
#include "core/stringTable.h"
|
||||
#include "console/console.h"
|
||||
#include "core/tVector.h"
|
||||
#include "core/fileStream.h"
|
||||
#include "platform/platformThread.h"
|
||||
|
||||
struct ProfilerData;
|
||||
struct ProfilerRoot;
|
||||
struct ProfilerRootData;
|
||||
struct ProfilerInstance;
|
||||
|
||||
/// Torque includes a full-featured code profiler, which can be used to
|
||||
/// measure the performance of game code.
|
||||
///
|
||||
/// The profiler tracks performance information about a number of blocks in
|
||||
/// the code base defined by matched sets of PROFILE_START() and
|
||||
/// PROFILER_END() blocks. Basically, you can use it to see how much time
|
||||
/// a chunk of code is taking out of your overall execution time.
|
||||
///
|
||||
/// The information tracked includes:
|
||||
/// * Percent of time spent in just this block.
|
||||
/// * Percent of time spent in this block as well as any other blocks
|
||||
/// encountered inside of it.
|
||||
/// * Number of invocations, ie, how many times this block was run.
|
||||
///
|
||||
/// The profiler tracks both global statistics for each block, as well as
|
||||
/// providing hierarchical data about performance (ie, what blocks are
|
||||
/// called from inside what other blocks, and what time is spent where).
|
||||
///
|
||||
/// While this information is not as fine grained as that provided by
|
||||
/// serious, low-level profiling tools (ie, gprof, VTune, Shark), the
|
||||
/// overhead is lower. The profiler can be enabled in beta or debug builds
|
||||
/// of your application, and used to easily dump information about low
|
||||
/// performance situations. Because it is Torque-aware, it also gives more
|
||||
/// useful information in some cases than lower level profilers can provide.
|
||||
///
|
||||
/// For instance, it can easily show when and how frequently you are
|
||||
/// allocating/freeing memory, or what the relative breakdown in time is
|
||||
/// between player update code and physics for other items. It can give
|
||||
/// useful information for trying to decide if your game is CPU or GPU
|
||||
/// bound, or if code is being erroneously run too much. (Seeing a helper
|
||||
/// function is getting run several dozen thousand times more than its
|
||||
/// parent can be one tip-off. ;)
|
||||
///
|
||||
/// <b>How To Use The Profiler</b>
|
||||
///
|
||||
/// First, you must #define TORQUE_ENABLE_PROFILER in torqueConfig.h in
|
||||
/// order to active the profiler. Then you can use it from script. Examples
|
||||
/// of script use:
|
||||
///
|
||||
/// @code
|
||||
/// // profilerEnable enables or disables profiling. Data is only gathered
|
||||
/// // when the profiler is enabled.
|
||||
/// profilerEnable(bool enable);
|
||||
/// profilerReset(); //resets the data gathered by the profiler
|
||||
/// profilerDump(); //dumps all profiler data to the console
|
||||
/// profilerDumpToFile(string filename); //dumps all profiler data to a given file
|
||||
/// @endcode
|
||||
///
|
||||
/// The C++ code side of the profiler uses pairs of PROFILE_START() and
|
||||
/// PROFILE_END().
|
||||
///
|
||||
/// When using these macros, make sure there is a PROFILE_END() for every
|
||||
/// PROFILE_START and a PROFILE_START() for every PROFILE_END(). It is fine
|
||||
/// to nest these macros, however, you must make sure that no matter what
|
||||
/// execution path the code takes, the PROFILE macros will be balanced. (This
|
||||
/// usually means having a PROFILE_END() before every return statement in a
|
||||
/// function, for instance.)
|
||||
///
|
||||
/// The profiler can be used to locate areas of code that are slow or should
|
||||
/// be considered for optimization. Since it tracks the relative time of
|
||||
/// execution of that code to the execution of the main loop, it is possible
|
||||
/// to benchmark any given code to see if changes made will actually
|
||||
/// improve performance.
|
||||
///
|
||||
/// Here are some examples:
|
||||
/// @code
|
||||
/// PROFILE_START(TerrainRender);
|
||||
/// //some code here
|
||||
/// PROFILE_START(TerrainRenderGridSquare);
|
||||
/// //some code here
|
||||
/// PROFILE_END();
|
||||
/// //possibly some code here
|
||||
/// PROFILE_END();
|
||||
///
|
||||
/// void foo()
|
||||
/// {
|
||||
/// PROFILE_START(foo_do);
|
||||
/// if(doThing())
|
||||
/// {
|
||||
/// PROFILE_END();
|
||||
/// return true;
|
||||
/// }
|
||||
/// PROFILE_END();
|
||||
/// return false;
|
||||
/// }
|
||||
/// @endcode
|
||||
///
|
||||
/// <b>What Data the Profiler Gathers</b>
|
||||
///
|
||||
/// The profiler gathers two general representations of the profiling data.
|
||||
///
|
||||
/// First, it gathers per block data. This is data that relates to every
|
||||
/// single execution of a given block - for instance, foo_do in the
|
||||
/// above example code has its invocation count and total and non-sub time
|
||||
/// tracked regardless of where it is called from. This is used to generate
|
||||
/// the first half of the profiler data dump, the sorted list of what blocks
|
||||
/// are, overall, taking up the most non-sub time.
|
||||
///
|
||||
/// Second, data is gathered per instance of a block. This is the data used
|
||||
/// to display the nice formatted tree that makes up the second half of a
|
||||
/// profiler data dump. A single block may have many instances as it is
|
||||
/// called from different parts of the codebase. For instance, foo_do might
|
||||
/// get called from the main loop, as well as from the console, making it
|
||||
/// show up in several places on the hierarchical view:
|
||||
///
|
||||
/// @code
|
||||
/// MainLoop
|
||||
/// foo_do
|
||||
/// ConsoleCode
|
||||
/// foo_do
|
||||
/// @endcode
|
||||
///
|
||||
/// There are three values gathered per block:
|
||||
/// - Total time. Shown as a percentage of the time period that was profiled,
|
||||
/// this is the time spent in both this block and all its children.
|
||||
/// - Non-sub time. This is the amount of time spent ONLY in this block,
|
||||
/// and not any of its children.
|
||||
/// - Invocations. The number of times this block was executed.
|
||||
///
|
||||
/// <b>How the Profiler Works</b>
|
||||
///
|
||||
/// Internally, all profiler state is managed by ProfilerInstance. The
|
||||
/// gProfiler is just a wrapper around this, responsible for dispatching
|
||||
/// profiler events (ie, PROFILER_START and PROFILE_END macros, which
|
||||
/// correspond to calls to Profiler::hashPush and Profiler::hashPop
|
||||
/// respectively) to the appropriate ProfilerInstance. There is one
|
||||
/// ProfilerInstance per thread, representing the entire profiler state
|
||||
/// for that thread.
|
||||
///
|
||||
/// ProfilerRoots are allocated statically in each PROFILER_START macro, and
|
||||
/// are used as "anchors" for a table of ProfilerRootDatas contained in each
|
||||
/// ProfilerInstance. Each ProfilerRoot is assigned an ID which is used for
|
||||
/// fast lookups in the ProfilerInstance's ProfilerRootData table. There are
|
||||
/// potentially many ProfilerRootDatas for a given ProfilerRoot, but only one
|
||||
/// and exactly one PRD for a PR in a given ProfilerInstance.
|
||||
///
|
||||
/// Together, a PR and a PRD represent a "block", i.e., a specific chunk
|
||||
/// of code begun with a PROFILE_START() and ended with one or more
|
||||
/// PROFILE_END()s. This is all that is needed to gather the per-block
|
||||
/// data mentioned in the previous section.
|
||||
///
|
||||
/// However, context is often important in analysis, so we also gather
|
||||
/// hierarchical data, tracking what blocks are called from which other
|
||||
/// blocks. This allows us to know that, for instance, we only allocate
|
||||
/// memory once out of every hundred frames in the terrain inner loops,
|
||||
/// while executing a single console function can involve several frees
|
||||
/// and allocs. (That is to say, TerrainRender is invoked hundreds of times,
|
||||
/// while MemoryAlloc and MemoryFree only show up under it once or twice,
|
||||
/// and ConsoleExec shows up once or twice with MemoryAlloc and MemoryFree
|
||||
/// being invoked a dozen times each.)
|
||||
///
|
||||
/// To acheive this, we make use of the ProfilerData structure. For each
|
||||
/// "instance" of a block we encounter, we allocate a ProfilerData and place
|
||||
/// it in a tree structure. A given ProfilerRootData in a ProfilerInstance
|
||||
/// might have many ProfilerDatas, representing different situations under
|
||||
/// which it is executed, ie, different blocks that call it.
|
||||
///
|
||||
/// So we build a list, and grow a tree from it. By tracking our position
|
||||
/// in the tree, we can easily build up a consistent view of how our code
|
||||
/// blocks are called, and how we spend our time in different calling
|
||||
/// hierarchies.
|
||||
class Profiler
|
||||
{
|
||||
friend class ProfilerInstance;
|
||||
|
||||
ProfilerInstance *mInstanceListHead;
|
||||
ThreadStorage mCurrentInstance;
|
||||
|
||||
/// Get the current ProfilerInstance for the executing thread, or
|
||||
/// allocate it if it is unavailable.
|
||||
ProfilerInstance *getCurrentInstance();
|
||||
|
||||
/// We only want one thing to dump at a time - imagine the madness
|
||||
/// of interleaved output - so we stick a mutex here to manage that, and
|
||||
/// some other state information, as it's easy to get to from wherever
|
||||
/// we've got the lock.
|
||||
void *mDumpMutex;
|
||||
|
||||
bool mCurrentDumpIsConsole;
|
||||
bool mCurrentDumpIsFile;
|
||||
Stream *mCurrentDumpStream;
|
||||
|
||||
public:
|
||||
Profiler();
|
||||
~Profiler();
|
||||
|
||||
/// Get a list of the IDs of all the threads we're profiling. Pass these
|
||||
/// IDs into the function variants that require an id parameter in order
|
||||
/// to control a specific thread's profiling activity.
|
||||
void getThreadList(Vector<U32> &ids);
|
||||
|
||||
ProfilerInstance *getInstanceByID(const U32 id);
|
||||
|
||||
void enable(bool enable);
|
||||
void dumpToConsole();
|
||||
void dumpToFile(const char *fileName);
|
||||
void enableMarker(const char *marker, bool enable);
|
||||
void reset();
|
||||
|
||||
void hashPush(ProfilerRoot *pr);
|
||||
void hashPop();
|
||||
};
|
||||
|
||||
extern Profiler *gProfiler;
|
||||
|
||||
/// Helper structure used to store general information about a profiler
|
||||
/// block.
|
||||
///
|
||||
/// Everything that follows are implementation details.
|
||||
///
|
||||
/// @see Profiler for information on how to use the profiler.
|
||||
///
|
||||
/// We use a slightly indirected scheme to manage the complexities of
|
||||
/// profiling threads. Basically, the ProfilerRoot structures store the
|
||||
/// name and other constant, global information about a given profiler
|
||||
/// block. We walk the list at startup to generate a list at startup
|
||||
/// which is then used to lookup into a thread-specific table of
|
||||
/// ProfilerRootDatas. This way we can easily track profile information
|
||||
/// for each thread without duplication of information or trying to make
|
||||
/// the core profiling data structures thread-safe via synchronization
|
||||
/// primitives, which can be horribly slow.
|
||||
///
|
||||
/// Profilers must be fast and deterministic, so that they don't impact
|
||||
/// what they measure. :)
|
||||
struct ProfilerRoot
|
||||
{
|
||||
/// Name of this profile block.
|
||||
const char *mName;
|
||||
|
||||
/// Hash of the profile block name, for fast lookups.
|
||||
U32 mNameHash;
|
||||
|
||||
/// Next block in the master list.
|
||||
ProfilerRoot *mNextRoot;
|
||||
|
||||
/// Assigned sequentially to map to the thread table.
|
||||
/// This allows us to quickly lookup into it. (A hash
|
||||
/// would be slow.)
|
||||
U32 mID;
|
||||
|
||||
// This structure is exactly 16 bytes. (4 words at 4 bytes each)
|
||||
// Following are non-data members:
|
||||
|
||||
/// Head of master list of all profiler blocks.
|
||||
static ProfilerRoot *smRootList;
|
||||
|
||||
/// Global count of roots.
|
||||
static U32 smRootCount;
|
||||
|
||||
/// Constructor - called by the PROFILE_START macro.
|
||||
ProfilerRoot(const char *name);
|
||||
};
|
||||
|
||||
/// Profiler thread table data element. One of these is created for every
|
||||
/// ProfilerRoot, to store thread specific data. They are indexed by
|
||||
/// ProfilerRoot::mID.
|
||||
///
|
||||
/// @see Profiler for information on how to use the profiler.
|
||||
struct ProfilerRootData
|
||||
{
|
||||
ProfilerRootData();
|
||||
~ProfilerRootData();
|
||||
|
||||
/// We keep a pointer back to the original root structure so we can do
|
||||
/// name lookups and the like.
|
||||
ProfilerRoot *mRoot;
|
||||
|
||||
/// Head of linked list of actual ProfilerDatas for this
|
||||
/// block.
|
||||
ProfilerData *mFirstProfilerData;
|
||||
|
||||
/// Should profile information for this block be gathered?
|
||||
bool mEnabled;
|
||||
|
||||
/// @name Data Accumulators
|
||||
///
|
||||
///
|
||||
/// @{
|
||||
|
||||
/// Total time spent in all instances of this block.
|
||||
F64 mTotalTime;
|
||||
|
||||
/// Total time spent in all child instances of this block, excluding
|
||||
/// this block.
|
||||
F64 mSubTime;
|
||||
|
||||
/// Total number of times all instances of this block have been invoked.
|
||||
U32 mTotalInvokeCount;
|
||||
|
||||
/// @}
|
||||
|
||||
/// Reset all the data accumulators.
|
||||
void reset();
|
||||
};
|
||||
|
||||
/// Runtime information on a given instance of a profiler block.
|
||||
///
|
||||
/// @see Profiler for information on how to use the profiler.
|
||||
///
|
||||
/// Generated on the fly as we build our profiler tree, this represents
|
||||
/// profiled instances of a block. This enables us to accurately track
|
||||
/// recursive situations and the like.
|
||||
///
|
||||
/// It is organized in the following lists:
|
||||
/// - Root list. Each root has a list of all its instances associated
|
||||
/// with it.
|
||||
/// - ProfilerData list. Each thread keeps a master list of all the
|
||||
/// ProfilerDatas associated with it.
|
||||
/// - Hash list. Children of a ProfilerData are kept in a hash indexed
|
||||
/// by name. Thus a bin list is maintained for each bin of the hash.
|
||||
/// - Child list. The children of a ProfilerData are all kept in a
|
||||
/// list for easy traversal.
|
||||
///
|
||||
struct ProfilerData
|
||||
{
|
||||
ProfilerData();
|
||||
~ProfilerData();
|
||||
|
||||
/// What ProfilerRootData do we belong to?
|
||||
ProfilerRootData *mOwningRoot;
|
||||
|
||||
/// Next ProfilerData for this root.
|
||||
ProfilerData *mNextForRoot;
|
||||
|
||||
/// Master list for the profiled thread.
|
||||
ProfilerData *mNextProfilerData;
|
||||
|
||||
/// Next ProfilerData in the hash bin.
|
||||
ProfilerData *mNextHash;
|
||||
|
||||
/// Who is our parent?
|
||||
ProfilerData *mParent;
|
||||
|
||||
/// Next sibling of our parent.
|
||||
ProfilerData *mNextSibling;
|
||||
|
||||
/// Our first child.
|
||||
ProfilerData *mFirstChild;
|
||||
|
||||
enum {
|
||||
HashTableSize = 32,
|
||||
};
|
||||
ProfilerData *mChildHash[HashTableSize];
|
||||
|
||||
/// For fast lookups, we cache the last seen child. If we see the same
|
||||
/// profiler block many times in a row this can save us a lot of
|
||||
/// traversal in Profiler::hashPush.
|
||||
ProfilerData *mLastSeenProfiler;
|
||||
|
||||
/// The hash of this block's names, kept here for fast lookups.
|
||||
U32 mHash;
|
||||
|
||||
/// Number of times we have recursed into this block from itself.
|
||||
U32 mSubDepth;
|
||||
|
||||
/// Number of times this block instance has been run.
|
||||
U32 mInvokeCount;
|
||||
|
||||
/// The high performance timer needs some memory to store its start time.
|
||||
U32 mStartTime[2];
|
||||
|
||||
/// Total time we've spent in this block instance.
|
||||
F64 mTotalTime;
|
||||
|
||||
/// Total time we've spent in this block instance's children, excluding
|
||||
/// this instance itself.
|
||||
F64 mSubTime;
|
||||
};
|
||||
|
||||
/// Manages thread-local profiler state.
|
||||
///
|
||||
/// @see Profiler for information on how to use the profiler.
|
||||
///
|
||||
/// This is the meat of the profiler; there are one of these for each
|
||||
/// profiler and they are responsible for tracking all of the state for a
|
||||
/// thread's profile information.
|
||||
class ProfilerInstance
|
||||
{
|
||||
friend class Profiler;
|
||||
|
||||
/// @name Dump Code
|
||||
///
|
||||
/// Miscellaneous helper functions for dumping the profiler state to
|
||||
/// disk or console. We have a unified interface to avoid duplicating
|
||||
/// a bunch of complex output code for file/console output.
|
||||
///
|
||||
/// If you have a burning need to know what these guys do, just read the
|
||||
/// code. It's really pretty straightforward.
|
||||
///
|
||||
/// @{
|
||||
|
||||
/// Print data to the appropriate place(s). (Console, stream, or both.)
|
||||
static void printFunc(char *fmt, ...);
|
||||
|
||||
/// Print a sorted vector of profiler block data in a nice way.
|
||||
static void printSortedRootData(Vector<ProfilerRootData*> &rootVector, F64 totalTime);
|
||||
|
||||
/// Recursively dump part of the profiler data tree.
|
||||
static void profilerDataDumpRecurse(ProfilerData *data, char *buffer, U32 bufferLen, F64 totalTime);
|
||||
|
||||
/// @}
|
||||
|
||||
/// We tend to encounter new blocks part-way through execution. This is
|
||||
/// due to the nature of static variables (which our global roots are).
|
||||
/// They only initialize when they come into scope! So, we have to be able
|
||||
/// to grow our local root data table. This ensures it has at least
|
||||
/// newCount slows in it, and makes sure everything points to the right
|
||||
/// roots.
|
||||
void growRoots(U32 newCount);
|
||||
|
||||
enum
|
||||
{
|
||||
MaxStackDepth = 256,
|
||||
DumpFileNameLength = 256
|
||||
};
|
||||
|
||||
/// ID of the thread we have profiled data for.
|
||||
U32 mThreadID;
|
||||
|
||||
/// Mutex to manage some nasty conditions - we lock on deconstruction,
|
||||
/// and also when we're dumping so we don't try to dump from two places
|
||||
/// at the same time.
|
||||
///
|
||||
/// @note This isn't bullet proof yet on the deconstruct case, but we
|
||||
/// don't actually kill off profiler data so we're ok. :)
|
||||
void *mMutex;
|
||||
|
||||
/// Thread-local table of all the ProfilerRootDatas.
|
||||
///
|
||||
/// Since we have to keep track of per-block data specific to each
|
||||
/// thread (it's a pain to update, nevermind interpret data global to
|
||||
/// all threads), we keep a local copy of everything here so we're
|
||||
/// essentially independent of the ProfilerRoots scattered throughout
|
||||
/// the codebase.
|
||||
ProfilerRootData *mRootTable;
|
||||
|
||||
/// Number of roots we have current allocated. Since not all roots are
|
||||
/// known (they get initialized as they're visited...), we have to be
|
||||
/// able to reallocate our thread-local root table. This isn't much fun
|
||||
/// but enables us to be much more robust.
|
||||
///
|
||||
/// @see growRoots
|
||||
U32 mRootCount;
|
||||
|
||||
/// Our current ProfilerData. This indicates where in the profiler tree
|
||||
/// we are at the moment, and is updated on (almost) every push or pop.
|
||||
ProfilerData *mCurrentProfilerData;
|
||||
|
||||
/// List of all allocated ProfilerDatas. Important for book-keeping
|
||||
/// and update operations.
|
||||
ProfilerData *mProfileList;
|
||||
|
||||
/// This is the root ProfilerData in our local tree of profiler data.
|
||||
ProfilerData *mRootProfilerData;
|
||||
|
||||
/// Currently enabled?
|
||||
bool mEnabled;
|
||||
|
||||
/// Current depth of profiler stack.
|
||||
S32 mStackDepth;
|
||||
|
||||
/// Maximum allowed profiler stack depth.
|
||||
U32 mMaxStackDepth;
|
||||
|
||||
/// Enable state for next frame.
|
||||
bool mNextEnable;
|
||||
|
||||
/// Should we dump to console at next frame?
|
||||
bool mDumpToConsole;
|
||||
|
||||
/// Should we dump to file at next frame?
|
||||
bool mDumpToFile;
|
||||
|
||||
/// If so, where?
|
||||
char mDumpFileName[DumpFileNameLength];
|
||||
|
||||
/// Next allocated ProfilerInstance.
|
||||
ProfilerInstance *mNextInstance;
|
||||
|
||||
/// Do a bunch of extra checking to make sure our data structures
|
||||
/// are clean.
|
||||
///
|
||||
/// @note This is mostly kept around for debug situations, and is not
|
||||
/// normally called.
|
||||
void validate();
|
||||
|
||||
/// Look up the ProfilerRootData that corresponds to a given
|
||||
/// ProfilerRoot.(
|
||||
inline ProfilerRootData *lookup(ProfilerRoot *pr)
|
||||
{
|
||||
return mRootTable + pr->mID;
|
||||
}
|
||||
|
||||
/// Helper function to do the actual dumping. You should have the
|
||||
/// instance's mutex before you call this.
|
||||
void dump();
|
||||
|
||||
public:
|
||||
ProfilerInstance();
|
||||
~ProfilerInstance();
|
||||
|
||||
void hashPush(ProfilerRoot *pr);
|
||||
void hashPop();
|
||||
|
||||
void enable(bool enable);
|
||||
void enableMarker(const char *name, bool enable);
|
||||
void reset();
|
||||
void dumpToConsole();
|
||||
void dumpToFile(const char *fileName);
|
||||
};
|
||||
|
||||
#endif /* TORQUE_ENABLE_PROFILER */
|
||||
|
||||
#endif /* _PROFILER_H_ */
|
79
engine/platform/types.codewarrior.h
Executable file
79
engine/platform/types.codewarrior.h
Executable file
@ -0,0 +1,79 @@
|
||||
|
||||
#ifndef INCLUDED_TYPES_CODEWARRIOR_H
|
||||
#define INCLUDED_TYPES_CODEWARRIOR_H
|
||||
|
||||
#pragma once
|
||||
|
||||
// If using the IDE detect if DEBUG build was requested
|
||||
#if __ide_target("Torque-W32-Debug")
|
||||
#define TORQUE_DEBUG
|
||||
#elif __ide_target("Torque-MacCarb-Debug")
|
||||
#define TORQUE_DEBUG
|
||||
#elif __ide_target("Torque-MacX-Debug")
|
||||
#define TORQUE_DEBUG
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
// Types
|
||||
typedef signed long long S64; ///< Compiler independent Signed 64-bit integer
|
||||
typedef unsigned long long U64; ///< Compiler independent Unsigned 64-bit integer
|
||||
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
// Compiler Version
|
||||
#define TORQUE_COMPILER_CODEWARRIOR __MWERKS__
|
||||
|
||||
#define TORQUE_COMPILER_STRING "CODEWARRIOR"
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
// Identify the Operating System
|
||||
#if defined(_WIN32)
|
||||
# define TORQUE_OS_STRING "Win32"
|
||||
# define TORQUE_OS_WIN32
|
||||
# include "platform/types.win32.h"
|
||||
|
||||
#elif defined(macintosh) || defined(__APPLE__)
|
||||
# define TORQUE_OS_STRING "Mac"
|
||||
# define TORQUE_OS_MAC
|
||||
# if defined(__MACH__)
|
||||
# define TORQUE_OS_MAC_OSX
|
||||
# endif
|
||||
# include "platform/types.ppc.h"
|
||||
// for the moment:
|
||||
# include "platformMacCarb/macCarb_common_prefix.h"
|
||||
#else
|
||||
# error "CW: Unsupported Operating System"
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
// Identify the CPU
|
||||
#if defined(_M_IX86)
|
||||
# define TORQUE_CPU_STRING "x86"
|
||||
# define TORQUE_CPU_X86
|
||||
# define TORQUE_LITTLE_ENDIAN
|
||||
# define TORQUE_SUPPORTS_NASM
|
||||
# define TORQUE_SUPPORTS_VC_INLINE_X86_ASM
|
||||
|
||||
// Compiling with the CW IDE we cannot use NASM :(
|
||||
# if __ide_target("Torque-W32-Debug")
|
||||
# undef TORQUE_SUPPORTS_NASM
|
||||
# elif __ide_target("Torque-W32-Release")
|
||||
# undef TORQUE_SUPPORTS_NASM
|
||||
# endif
|
||||
|
||||
#elif defined(__POWERPC__)
|
||||
# define TORQUE_CPU_STRING "PowerPC"
|
||||
# define TORQUE_CPU_PPC
|
||||
# define TORQUE_BIG_ENDIAN
|
||||
|
||||
#else
|
||||
# error "CW: Unsupported Target CPU"
|
||||
#endif
|
||||
|
||||
|
||||
#endif // INCLUDED_TYPES_CODEWARRIOR_H
|
||||
|
97
engine/platform/types.gcc.h
Executable file
97
engine/platform/types.gcc.h
Executable file
@ -0,0 +1,97 @@
|
||||
|
||||
#ifndef INCLUDED_TYPES_GCC_H
|
||||
#define INCLUDED_TYPES_GCC_H
|
||||
|
||||
|
||||
// For additional information on GCC predefined macros
|
||||
// http://gcc.gnu.org/onlinedocs/gcc-3.0.2/cpp.html
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
// Types
|
||||
typedef signed long long S64;
|
||||
typedef unsigned long long U64;
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
// Compiler Version
|
||||
#define TORQUE_COMPILER_GCC (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
// Identify the compiler string
|
||||
|
||||
#if defined(__MINGW32__)
|
||||
# define TORQUE_COMPILER_STRING "GCC (MinGW)"
|
||||
# define TORQUE_COMPILER_MINGW
|
||||
#elif defined(__CYGWIN__)
|
||||
# define TORQUE_COMPILER_STRING "GCC (Cygwin)"
|
||||
# define TORQUE_COMPILER_MINGW
|
||||
#else
|
||||
# define TORQUE_COMPILER_STRING "GCC "
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
// Identify the Operating System
|
||||
#if defined(__WIN32__) || defined(_WIN32)
|
||||
# define TORQUE_OS_STRING "Win32"
|
||||
# define TORQUE_OS_WIN32
|
||||
# define TORQUE_SUPPORTS_NASM
|
||||
# define TORQUE_SUPPORTS_GCC_INLINE_X86_ASM
|
||||
# include "platform/types.win32.h"
|
||||
|
||||
#elif defined(linux)
|
||||
# define TORQUE_OS_STRING "Linux"
|
||||
# define TORQUE_OS_LINUX
|
||||
# define TORQUE_SUPPORTS_NASM
|
||||
# define TORQUE_SUPPORTS_GCC_INLINE_X86_ASM
|
||||
# include "platform/types.posix.h"
|
||||
|
||||
#elif defined(__OpenBSD__)
|
||||
# define TORQUE_OS_STRING "OpenBSD"
|
||||
# define TORQUE_OS_OPENBSD
|
||||
# define TORQUE_SUPPORTS_NASM
|
||||
# define TORQUE_SUPPORTS_GCC_INLINE_X86_ASM
|
||||
# include "platform/types.posix.h"
|
||||
|
||||
#elif defined(__FreeBSD__)
|
||||
# define TORQUE_OS_STRING "FreeBSD"
|
||||
# define TORQUE_OS_FREEBSD
|
||||
# define TORQUE_SUPPORTS_NASM
|
||||
# define TORQUE_SUPPORTS_GCC_INLINE_X86_ASM
|
||||
# include "platform/types.posix.h"
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
# define TORQUE_OS_MAC
|
||||
# define TORQUE_OS_MAC_OSX
|
||||
#if defined(i386)
|
||||
# define TORQUE_SUPPORTS_NASM
|
||||
#endif
|
||||
# include "platform/types.ppc.h"
|
||||
// for the moment:
|
||||
# include "platformMacCarb/macCarb_common_prefix.h"
|
||||
#else
|
||||
# error "GCC: Unsupported Operating System"
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
// Identify the CPU
|
||||
#if defined(i386)
|
||||
# define TORQUE_CPU_STRING "Intel x86"
|
||||
# define TORQUE_CPU_X86
|
||||
# define TORQUE_LITTLE_ENDIAN
|
||||
|
||||
#elif defined(__ppc__)
|
||||
# define TORQUE_CPU_STRING "PowerPC"
|
||||
# define TORQUE_CPU_PPC
|
||||
# define TORQUE_BIG_ENDIAN
|
||||
|
||||
#else
|
||||
# error "GCC: Unsupported Target CPU"
|
||||
#endif
|
||||
|
||||
|
||||
#endif // INCLUDED_TYPES_GCC_H
|
||||
|
275
engine/platform/types.h
Executable file
275
engine/platform/types.h
Executable file
@ -0,0 +1,275 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _TORQUE_TYPES_H_
|
||||
#define _TORQUE_TYPES_H_
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//-------------------------------------- Basic Types...
|
||||
|
||||
typedef signed char S8; ///< Compiler independent Signed Char
|
||||
typedef unsigned char U8; ///< Compiler independent Unsigned Char
|
||||
|
||||
typedef signed short S16; ///< Compiler independent Signed 16-bit short
|
||||
typedef unsigned short U16; ///< Compiler independent Unsigned 16-bit short
|
||||
|
||||
typedef signed int S32; ///< Compiler independent Signed 32-bit integer
|
||||
typedef unsigned int U32; ///< Compiler independent Unsigned 32-bit integer
|
||||
|
||||
typedef float F32; ///< Compiler independent 32-bit float
|
||||
typedef double F64; ///< Compiler independent 64-bit float
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------- String Types
|
||||
|
||||
typedef char UTF8; ///< Compiler independent 8 bit Unicode encoded character
|
||||
typedef unsigned short UTF16; ///< Compiler independent 16 bit Unicode encoded character
|
||||
typedef unsigned int UTF32; ///< Compiler independent 32 bit Unicode encoded character
|
||||
|
||||
typedef const char* StringTableEntry;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//-------------------------------------- Type constants...
|
||||
#define __EQUAL_CONST_F F32(0.000001) ///< Constant float epsilon used for F32 comparisons
|
||||
|
||||
static const F32 Float_One = F32(1.0); ///< Constant float 1.0
|
||||
static const F32 Float_Half = F32(0.5); ///< Constant float 0.5
|
||||
static const F32 Float_Zero = F32(0.0); ///< Constant float 0.0
|
||||
static const F32 Float_Pi = F32(3.14159265358979323846); ///< Constant float PI
|
||||
static const F32 Float_2Pi = F32(2.0 * 3.14159265358979323846); ///< Constant float 2*PI
|
||||
|
||||
static const S8 S8_MIN = S8(-128); ///< Constant Min Limit S8
|
||||
static const S8 S8_MAX = S8(127); ///< Constant Max Limit S8
|
||||
static const U8 U8_MAX = U8(255); ///< Constant Max Limit U8
|
||||
|
||||
static const S16 S16_MIN = S16(-32768); ///< Constant Min Limit S16
|
||||
static const S16 S16_MAX = S16(32767); ///< Constant Max Limit S16
|
||||
static const U16 U16_MAX = U16(65535); ///< Constant Max Limit U16
|
||||
|
||||
static const S32 S32_MIN = S32(-2147483647 - 1); ///< Constant Min Limit S32
|
||||
static const S32 S32_MAX = S32(2147483647); ///< Constant Max Limit S32
|
||||
static const U32 U32_MAX = U32(0xffffffff); ///< Constant Max Limit U32
|
||||
|
||||
static const F32 F32_MIN = F32(1.175494351e-38F); ///< Constant Min Limit F32
|
||||
static const F32 F32_MAX = F32(3.402823466e+38F); ///< Constant Max Limit F32
|
||||
|
||||
//--------------------------------------
|
||||
// Identify the compiler being used
|
||||
|
||||
// Metrowerks CodeWarrior
|
||||
#if defined(__MWERKS__)
|
||||
# include "platform/types.codewarrior.h"
|
||||
// Microsoft Visual C++/Visual.NET
|
||||
#elif defined(_MSC_VER)
|
||||
# include "platform/types.visualc.h"
|
||||
// GNU GCC
|
||||
#elif defined(__GNUC__)
|
||||
# include "platform/types.gcc.h"
|
||||
#else
|
||||
# error "Unknown Compiler"
|
||||
#endif
|
||||
|
||||
//--------------------------------------
|
||||
// Enable Asserts in all debug builds -- AFTER compiler types include.
|
||||
#if defined(TORQUE_DEBUG)
|
||||
#define TORQUE_ENABLE_ASSERTS
|
||||
#endif
|
||||
|
||||
|
||||
//-------------------------------------- A couple of all-around useful inlines and
|
||||
// globals
|
||||
//
|
||||
U32 getNextPow2(U32 io_num);
|
||||
U32 getBinLog2(U32 io_num);
|
||||
|
||||
/**
|
||||
Determines if the given U32 is some 2^n
|
||||
@param in_num Any U32
|
||||
@returns true if in_num is a power of two, otherwise false
|
||||
*/
|
||||
inline bool isPow2(const U32 in_num)
|
||||
{
|
||||
return (in_num == getNextPow2(in_num));
|
||||
}
|
||||
|
||||
/**
|
||||
Convert the byte ordering on the U16 to and from big/little endian format.
|
||||
@param in_swap Any U16
|
||||
@returns swaped U16.
|
||||
*/
|
||||
inline U16 endianSwap(const U16 in_swap)
|
||||
{
|
||||
return U16(((in_swap >> 8) & 0x00ff) |
|
||||
((in_swap << 8) & 0xff00));
|
||||
}
|
||||
|
||||
/**
|
||||
Convert the byte ordering on the U32 to and from big/little endian format.
|
||||
@param in_swap Any U32
|
||||
@returns swaped U32.
|
||||
*/
|
||||
inline U32 endianSwap(const U32 in_swap)
|
||||
{
|
||||
return U32(((in_swap >> 24) & 0x000000ff) |
|
||||
((in_swap >> 8) & 0x0000ff00) |
|
||||
((in_swap << 8) & 0x00ff0000) |
|
||||
((in_swap << 24) & 0xff000000));
|
||||
}
|
||||
|
||||
//----------------Many versions of min and max-------------
|
||||
//---not using template functions because MS VC++ chokes---
|
||||
|
||||
/// Returns the lesser of the two parameters: a & b.
|
||||
inline U32 getMin(U32 a, U32 b)
|
||||
{
|
||||
return a>b ? b : a;
|
||||
}
|
||||
|
||||
/// Returns the lesser of the two parameters: a & b.
|
||||
inline U16 getMin(U16 a, U16 b)
|
||||
{
|
||||
return a>b ? b : a;
|
||||
}
|
||||
|
||||
/// Returns the lesser of the two parameters: a & b.
|
||||
inline U8 getMin(U8 a, U8 b)
|
||||
{
|
||||
return a>b ? b : a;
|
||||
}
|
||||
|
||||
/// Returns the lesser of the two parameters: a & b.
|
||||
inline S32 getMin(S32 a, S32 b)
|
||||
{
|
||||
return a>b ? b : a;
|
||||
}
|
||||
|
||||
/// Returns the lesser of the two parameters: a & b.
|
||||
inline S16 getMin(S16 a, S16 b)
|
||||
{
|
||||
return a>b ? b : a;
|
||||
}
|
||||
|
||||
/// Returns the lesser of the two parameters: a & b.
|
||||
inline S8 getMin(S8 a, S8 b)
|
||||
{
|
||||
return a>b ? b : a;
|
||||
}
|
||||
|
||||
/// Returns the lesser of the two parameters: a & b.
|
||||
inline float getMin(float a, float b)
|
||||
{
|
||||
return a>b ? b : a;
|
||||
}
|
||||
|
||||
/// Returns the lesser of the two parameters: a & b.
|
||||
inline double getMin(double a, double b)
|
||||
{
|
||||
return a>b ? b : a;
|
||||
}
|
||||
|
||||
/// Returns the greater of the two parameters: a & b.
|
||||
inline U32 getMax(U32 a, U32 b)
|
||||
{
|
||||
return a>b ? a : b;
|
||||
}
|
||||
|
||||
/// Returns the greater of the two parameters: a & b.
|
||||
inline U16 getMax(U16 a, U16 b)
|
||||
{
|
||||
return a>b ? a : b;
|
||||
}
|
||||
|
||||
/// Returns the greater of the two parameters: a & b.
|
||||
inline U8 getMax(U8 a, U8 b)
|
||||
{
|
||||
return a>b ? a : b;
|
||||
}
|
||||
|
||||
/// Returns the greater of the two parameters: a & b.
|
||||
inline S32 getMax(S32 a, S32 b)
|
||||
{
|
||||
return a>b ? a : b;
|
||||
}
|
||||
|
||||
/// Returns the greater of the two parameters: a & b.
|
||||
inline S16 getMax(S16 a, S16 b)
|
||||
{
|
||||
return a>b ? a : b;
|
||||
}
|
||||
|
||||
/// Returns the greater of the two parameters: a & b.
|
||||
inline S8 getMax(S8 a, S8 b)
|
||||
{
|
||||
return a>b ? a : b;
|
||||
}
|
||||
|
||||
/// Returns the greater of the two parameters: a & b.
|
||||
inline float getMax(float a, float b)
|
||||
{
|
||||
return a>b ? a : b;
|
||||
}
|
||||
|
||||
/// Returns the greater of the two parameters: a & b.
|
||||
inline double getMax(double a, double b)
|
||||
{
|
||||
return a>b ? a : b;
|
||||
}
|
||||
|
||||
//-------------------------------------- Use this instead of Win32 FOURCC()
|
||||
// macro...
|
||||
//
|
||||
#define makeFourCCTag(ch0, ch1, ch2, ch3) \
|
||||
(((U32(ch0) & 0xFF) << 0) | \
|
||||
((U32(ch1) & 0xFF) << 8) | \
|
||||
((U32(ch2) & 0xFF) << 16) | \
|
||||
((U32(ch3) & 0xFF) << 24) )
|
||||
|
||||
#define makeFourCCString(ch0, ch1, ch2, ch3) { ch0, ch1, ch2, ch3 }
|
||||
|
||||
#define BIT(x) (1 << (x)) ///< Returns value with bit x set (2^x)
|
||||
|
||||
#ifndef Offset
|
||||
/// Offset macro:
|
||||
/// Calculates the location in memory of a given member x of class cls from the
|
||||
/// start of the class. Need several definitions to account for various
|
||||
/// flavors of GCC.
|
||||
|
||||
// define all the variants of Offset that we might use
|
||||
#define _Offset_Normal(x, cls) ((dsize_t)((const char *)&(((cls *)0)->x)-(const char *)0))
|
||||
#define _Offset_Variant_1(x, cls) ((int)(&((cls *)1)->x) - 1)
|
||||
#define _Offset_Variant_2(x, cls) offsetof(cls, x) // also requires #include <stddef.h>
|
||||
|
||||
// now, for each compiler type, define the Offset macros that should be used.
|
||||
// The Engine code usually uses the Offset macro, but OffsetNonConst is needed
|
||||
// when a variable is used in the indexing of the member field (see
|
||||
// TSShapeConstructor::initPersistFields for an example)
|
||||
|
||||
// compiler is non-GCC, or gcc < 3
|
||||
#if !defined(TORQUE_COMPILER_GCC) || (__GNUC__ < 3)
|
||||
#define Offset(x, cls) _Offset_Normal(x, cls)
|
||||
#define OffsetNonConst(x, cls) _Offset_Normal(x, cls)
|
||||
|
||||
// compiler is GCC 3 with minor version less than 4
|
||||
#elif defined(TORQUE_COMPILER_GCC) && (__GNUC__ == 3) && (__GNUC_MINOR__ < 4)
|
||||
#define Offset(x, cls) _Offset_Variant_1(x, cls)
|
||||
#define OffsetNonConst(x, cls) _Offset_Variant_1(x, cls)
|
||||
|
||||
// compiler is GCC 3 with minor version greater than 4
|
||||
#elif defined(TORQUE_COMPILER_GCC) && (__GNUC__ == 3) && (__GNUC_MINOR__ >= 4)
|
||||
#include <stddef.h>
|
||||
#define Offset(x, cls) _Offset_Variant_2(x, cls)
|
||||
#define OffsetNonConst(x, cls) _Offset_Variant_1(x, cls)
|
||||
|
||||
// compiler is GCC 4
|
||||
#elif defined(TORQUE_COMPILER_GCC) && (__GNUC__ == 4)
|
||||
#include <stddef.h>
|
||||
#define Offset(x, cls) _Offset_Variant_2(x, cls)
|
||||
#define OffsetNonConst(x, cls) _Offset_Variant_1(x, cls)
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif //_TORQUE_TYPES_H_
|
29
engine/platform/types.posix.h
Executable file
29
engine/platform/types.posix.h
Executable file
@ -0,0 +1,29 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _TYPESPOSIX_H_
|
||||
#define _TYPESPOSIX_H_
|
||||
|
||||
|
||||
#define FN_CDECL ///< Calling convention
|
||||
|
||||
// size_t is needed to overload new
|
||||
// size_t tends to be OS and compiler specific and may need to
|
||||
// be if/def'ed in the future
|
||||
typedef unsigned int dsize_t;
|
||||
|
||||
|
||||
/** Platform dependent file date-time structure. The defination of this structure
|
||||
* will likely be different for each OS platform.
|
||||
*/
|
||||
typedef S32 FileTime;
|
||||
|
||||
|
||||
#ifndef NULL
|
||||
# define NULL (0)
|
||||
#endif
|
||||
|
||||
|
||||
#endif //_TYPESPOSIX_H_
|
33
engine/platform/types.ppc.h
Executable file
33
engine/platform/types.ppc.h
Executable file
@ -0,0 +1,33 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _TYPESPPC_H_
|
||||
#define _TYPESPPC_H_
|
||||
|
||||
///< Calling convention
|
||||
#define FN_CDECL
|
||||
|
||||
// size_t is needed to overload new
|
||||
// size_t tends to be OS and compiler specific and may need to
|
||||
// be if/def'ed in the future
|
||||
typedef unsigned long dsize_t;
|
||||
|
||||
|
||||
/** Platform dependent file date-time structure. The defination of this structure
|
||||
* will likely be different for each OS platform.
|
||||
* On the PPC is a 64-bit structure for storing the date/time for a file
|
||||
*/
|
||||
|
||||
// 64-bit structure for storing the date/time for a file
|
||||
// The date and time, specified in seconds since the unix epoch.
|
||||
// NOTE: currently, this is only 32-bits in value, so the upper 32 are all zeroes.
|
||||
typedef U64 FileTime;
|
||||
|
||||
#ifndef NULL
|
||||
# define NULL (0)
|
||||
#endif
|
||||
|
||||
|
||||
#endif //_TYPESPPC_H_
|
63
engine/platform/types.visualc.h
Executable file
63
engine/platform/types.visualc.h
Executable file
@ -0,0 +1,63 @@
|
||||
|
||||
#ifndef INCLUDED_TYPES_VISUALC_H
|
||||
#define INCLUDED_TYPES_VISUALC_H
|
||||
|
||||
|
||||
// For more information on VisualC++ predefined macros
|
||||
// http://support.microsoft.com/default.aspx?scid=kb;EN-US;q65472
|
||||
|
||||
//--------------------------------------
|
||||
// Types
|
||||
typedef signed _int64 S64;
|
||||
typedef unsigned _int64 U64;
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
// Compiler Version
|
||||
#define TORQUE_COMPILER_VISUALC _MSC_VER
|
||||
|
||||
//--------------------------------------
|
||||
// Identify the compiler string
|
||||
#if _MSC_VER < 1200
|
||||
// No support for old compilers
|
||||
# error "VC: Minimum VisualC++ 6.0 or newer required"
|
||||
#else _MSC_VER >= 1200
|
||||
# define TORQUE_COMPILER_STRING "VisualC++"
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
// Identify the Operating System
|
||||
#if defined(_WIN32)
|
||||
# define TORQUE_OS_STRING "Win32"
|
||||
# define TORQUE_OS_WIN32
|
||||
# include "platform/types.win32.h"
|
||||
#else
|
||||
# error "VC: Unsupported Operating System"
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
// Identify the CPU
|
||||
#if defined(_M_IX86)
|
||||
# define TORQUE_CPU_STRING "x86"
|
||||
# define TORQUE_CPU_X86
|
||||
# define TORQUE_LITTLE_ENDIAN
|
||||
# define TORQUE_SUPPORTS_NASM
|
||||
# define TORQUE_SUPPORTS_VC_INLINE_X86_ASM
|
||||
#else
|
||||
# error "VC: Unsupported Target CPU"
|
||||
#endif
|
||||
|
||||
|
||||
#define FN_CDECL __cdecl ///< Calling convention
|
||||
|
||||
#define for if(false) {} else for ///< Hack to work around Microsoft VC's non-C++ compliance on variable scoping
|
||||
|
||||
// disable warning caused by memory layer
|
||||
// see msdn.microsoft.com "Compiler Warning (level 1) C4291" for more details
|
||||
#pragma warning(disable: 4291)
|
||||
|
||||
|
||||
#endif // INCLUDED_TYPES_VISUALC_H
|
||||
|
33
engine/platform/types.win32.h
Executable file
33
engine/platform/types.win32.h
Executable file
@ -0,0 +1,33 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _TYPESWIN32_H_
|
||||
#define _TYPESWIN32_H_
|
||||
|
||||
|
||||
#define FN_CDECL __cdecl ///< Calling convention
|
||||
|
||||
// size_t is needed to overload new
|
||||
// size_t tends to be OS and compiler specific and may need to
|
||||
// be if/def'ed in the future
|
||||
typedef unsigned int dsize_t;
|
||||
|
||||
|
||||
/** Platform dependent file date-time structure. The defination of this structure
|
||||
* will likely be different for each OS platform.
|
||||
*/
|
||||
struct FileTime
|
||||
{
|
||||
U32 v1;
|
||||
U32 v2;
|
||||
};
|
||||
|
||||
|
||||
#ifndef NULL
|
||||
# define NULL 0
|
||||
#endif
|
||||
|
||||
|
||||
#endif //_TYPESWIN32_H_
|
63
engine/platform/typesLinux.h
Executable file
63
engine/platform/typesLinux.h
Executable file
@ -0,0 +1,63 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _TYPESLINUX_H_
|
||||
#define _TYPESLINUX_H_
|
||||
|
||||
/* eek. */
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
#define PLATFORM_LITTLE_ENDIAN
|
||||
|
||||
#define FN_CDECL
|
||||
|
||||
typedef signed char S8;
|
||||
typedef unsigned char U8;
|
||||
|
||||
typedef signed short S16;
|
||||
typedef unsigned short U16;
|
||||
|
||||
typedef signed int S32;
|
||||
typedef unsigned int U32;
|
||||
|
||||
typedef signed long long S64;
|
||||
typedef unsigned long long U64;
|
||||
|
||||
typedef float F32;
|
||||
typedef double F64;
|
||||
|
||||
typedef unsigned int dsize_t;
|
||||
|
||||
typedef const char* StringTableEntry;
|
||||
|
||||
typedef S32 FileTime;
|
||||
|
||||
#define __EQUAL_CONST_F F32(0.000001)
|
||||
|
||||
static const F32 Float_One = F32(1.0);
|
||||
static const F32 Float_Half = F32(0.5);
|
||||
static const F32 Float_Zero = F32(0.0);
|
||||
static const F32 Float_Pi = F32(3.14159265358979323846);
|
||||
static const F32 Float_2Pi = F32(2.0 * 3.14159265358979323846);
|
||||
|
||||
static const S8 S8_MIN = S8(-128);
|
||||
static const S8 S8_MAX = S8(127);
|
||||
static const U8 U8_MAX = U8(255);
|
||||
|
||||
static const S16 S16_MIN = S16(-32768);
|
||||
static const S16 S16_MAX = S16(32767);
|
||||
static const U16 U16_MAX = U16(65535);
|
||||
|
||||
static const S32 S32_MIN = S32(-2147483647 - 1);
|
||||
static const S32 S32_MAX = S32(2147483647);
|
||||
static const U32 U32_MAX = U32(0xffffffff);
|
||||
|
||||
static const F32 F32_MAX = F32(3.402823466e+38F);
|
||||
static const F32 F32_MIN = F32(1.175494351e-38F);
|
||||
|
||||
|
||||
#endif
|
82
engine/platform/typesPPC.h
Executable file
82
engine/platform/typesPPC.h
Executable file
@ -0,0 +1,82 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _TYPES_PPC_H_
|
||||
#define _TYPES_PPC_H_
|
||||
|
||||
// We have to check this. Since every file will eventually wind up including
|
||||
// this header, but not every header includes a windows or system header...
|
||||
//
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
// Let's just have this in a nice central location. Again, since every file
|
||||
// will wind up including this file, we can affect compilation most effectively
|
||||
// from this location.
|
||||
//
|
||||
#define PLATFORM_BIG_ENDIAN
|
||||
|
||||
#define FN_CDECL
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//-------------------------------------- Basic Types...
|
||||
|
||||
typedef signed char S8;
|
||||
typedef unsigned char U8;
|
||||
|
||||
typedef signed short S16;
|
||||
typedef unsigned short U16;
|
||||
|
||||
typedef signed int S32;
|
||||
typedef unsigned int U32;
|
||||
|
||||
typedef signed long long S64;
|
||||
typedef unsigned long long U64;
|
||||
|
||||
typedef float F32;
|
||||
typedef double F64;
|
||||
|
||||
// size_t is needed to overload new
|
||||
// size_t tends to be OS and compiler specific and may need to
|
||||
// be if/def'ed in the future
|
||||
typedef unsigned long dsize_t;
|
||||
|
||||
typedef const char* StringTableEntry;
|
||||
|
||||
// 64-bit structure for storing the date/time for a file
|
||||
// The date and time, specified in seconds since the unix epoch.
|
||||
// NOTE: currently, this is only 32-bits in value, so the upper 32 are all zeroes.
|
||||
typedef U64 FileTime;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//-------------------------------------- Type constants...
|
||||
#define __EQUAL_CONST_F F32(0.000001)
|
||||
|
||||
static const F32 Float_One = F32(1.0);
|
||||
static const F32 Float_Half = F32(0.5);
|
||||
static const F32 Float_Zero = F32(0.0);
|
||||
static const F32 Float_Pi = F32(3.14159265358979323846);
|
||||
static const F32 Float_2Pi = F32(2.0 * 3.14159265358979323846);
|
||||
|
||||
static const S8 S8_MIN = S8(-128);
|
||||
static const S8 S8_MAX = S8(127);
|
||||
static const U8 U8_MAX = U8(255);
|
||||
|
||||
static const S16 S16_MIN = S16(-32768);
|
||||
static const S16 S16_MAX = S16(32767);
|
||||
static const U16 U16_MAX = U16(65535);
|
||||
|
||||
static const S32 S32_MIN = S32(-2147483647 - 1);
|
||||
static const S32 S32_MAX = S32(2147483647);
|
||||
static const U32 U32_MAX = U32(0xffffffff);
|
||||
|
||||
static const F32 F32_MAX = F32(3.402823466e+38F);
|
||||
static const F32 F32_MIN = F32(1.175494351e-38F);
|
||||
|
||||
|
||||
#endif //_TYPES_PPC_H_
|
105
engine/platform/typesWin32.h
Executable file
105
engine/platform/typesWin32.h
Executable file
@ -0,0 +1,105 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _TYPESWIN32_H_
|
||||
#define _TYPESWIN32_H_
|
||||
|
||||
// We have to check this. Since every file will eventually wind up including
|
||||
// this header, but not every header includes a windows or system header...
|
||||
//
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
// Let's just have this in a nice central location. Again, since every file
|
||||
// will wind up including this file, we can affect compilation most effectively
|
||||
// from this location.
|
||||
//
|
||||
#define PLATFORM_LITTLE_ENDIAN ///< Signals this platfrom is Little Endian
|
||||
|
||||
|
||||
#define FN_CDECL __cdecl ///< Calling convention
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//-------------------------------------- Basic Types...
|
||||
|
||||
typedef signed char S8; ///< Compiler independent Signed Char
|
||||
typedef unsigned char U8; ///< Compiler independent Unsigned Char
|
||||
|
||||
typedef signed short S16; ///< Compiler independent Signed 16-bit short
|
||||
typedef unsigned short U16; ///< Compiler independent Unsigned 16-bit short
|
||||
|
||||
typedef signed int S32; ///< Compiler independent Signed 32-bit integer
|
||||
typedef unsigned int U32; ///< Compiler independent Unsigned 32-bit integer
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
typedef signed __int64 S64; ///< Compiler independent Signed 64-bit integer
|
||||
typedef unsigned __int64 U64; ///< Compiler independent Unsigned 64-bit integer
|
||||
|
||||
#elif defined(__MWERKS__) // This has to go before MSC_VER since CodeWarrior defines MSC_VER too
|
||||
typedef signed long long S64; ///< Compiler independent Signed 64-bit integer
|
||||
typedef unsigned long long U64; ///< Compiler independent Unsigned 64-bit integer
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
typedef signed _int64 S64; ///< Compiler independent Signed 64-bit integer
|
||||
typedef unsigned _int64 U64; ///< Compiler independent Unsigned 64-bit integer
|
||||
#pragma warning(disable: 4291) // disable warning caused by memory layer...
|
||||
|
||||
#else
|
||||
typedef signed long long S64; ///< Compiler independent Signed 64-bit integer
|
||||
typedef unsigned long long U64; ///< Compiler independent Unsigned 64-bit integer
|
||||
#endif
|
||||
|
||||
typedef float F32; ///< Compiler independent 32-bit float
|
||||
typedef double F64; ///< Compiler independent 64-bit float
|
||||
|
||||
// size_t is needed to overload new
|
||||
// size_t tends to be OS and compiler specific and may need to
|
||||
// be if/def'ed in the future
|
||||
typedef unsigned int dsize_t;
|
||||
|
||||
typedef const char* StringTableEntry;
|
||||
|
||||
/* Platform dependent file date-time structure. The defination of this structure
|
||||
* will likely be different for each OS platform.
|
||||
*/
|
||||
struct FileTime
|
||||
{
|
||||
U32 v1;
|
||||
U32 v2;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//-------------------------------------- Type constants...
|
||||
#define __EQUAL_CONST_F F32(0.000001) ///< Constant float epsilon used for F32 comparisons
|
||||
|
||||
static const F32 Float_One = F32(1.0); ///< Constant float 1.0
|
||||
static const F32 Float_Half = F32(0.5); ///< Constant float 0.5
|
||||
static const F32 Float_Zero = F32(0.0); ///< Constant float 0.0
|
||||
static const F32 Float_Pi = F32(3.14159265358979323846); ///< Constant float PI
|
||||
static const F32 Float_2Pi = F32(2.0 * 3.14159265358979323846); ///< Constant float 2*PI
|
||||
|
||||
static const S8 S8_MIN = S8(-128); ///< Constant Min Limit S8
|
||||
static const S8 S8_MAX = S8(127); ///< Constant Max Limit S8
|
||||
static const U8 U8_MAX = U8(255); ///< Constant Max Limit U8
|
||||
|
||||
static const S16 S16_MIN = S16(-32768); ///< Constant Min Limit S16
|
||||
static const S16 S16_MAX = S16(32767); ///< Constant Max Limit S16
|
||||
static const U16 U16_MAX = U16(65535); ///< Constant Max Limit U16
|
||||
|
||||
static const S32 S32_MIN = S32(-2147483647 - 1); ///< Constant Min Limit S32
|
||||
static const S32 S32_MAX = S32(2147483647); ///< Constant Max Limit S32
|
||||
static const U32 U32_MAX = U32(0xffffffff); ///< Constant Max Limit U32
|
||||
|
||||
static const F32 F32_MIN = F32(1.175494351e-38F); ///< Constant Min Limit F32
|
||||
static const F32 F32_MAX = F32(3.402823466e+38F); ///< Constant Max Limit F32
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define for if(false) {} else for ///< Hack to work around Microsoft VC's non-C++ compliance on variable scoping
|
||||
#endif
|
||||
|
||||
|
||||
#endif //_NTYPES_H_
|
63
engine/platform/typesX86UNIX.h
Executable file
63
engine/platform/typesX86UNIX.h
Executable file
@ -0,0 +1,63 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _TYPESX86UNIX_H_
|
||||
#define _TYPESX86UNIX_H_
|
||||
|
||||
/* eek. */
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
#define PLATFORM_LITTLE_ENDIAN
|
||||
|
||||
#define FN_CDECL
|
||||
|
||||
typedef signed char S8;
|
||||
typedef unsigned char U8;
|
||||
|
||||
typedef signed short S16;
|
||||
typedef unsigned short U16;
|
||||
|
||||
typedef signed int S32;
|
||||
typedef unsigned int U32;
|
||||
|
||||
typedef signed long long S64;
|
||||
typedef unsigned long long U64;
|
||||
|
||||
typedef float F32;
|
||||
typedef double F64;
|
||||
|
||||
typedef unsigned int dsize_t;
|
||||
|
||||
typedef const char* StringTableEntry;
|
||||
|
||||
typedef S32 FileTime;
|
||||
|
||||
#define __EQUAL_CONST_F F32(0.000001)
|
||||
|
||||
static const F32 Float_One = F32(1.0);
|
||||
static const F32 Float_Half = F32(0.5);
|
||||
static const F32 Float_Zero = F32(0.0);
|
||||
static const F32 Float_Pi = F32(3.14159265358979323846);
|
||||
static const F32 Float_2Pi = F32(2.0 * 3.14159265358979323846);
|
||||
|
||||
static const S8 S8_MIN = S8(-128);
|
||||
static const S8 S8_MAX = S8(127);
|
||||
static const U8 U8_MAX = U8(255);
|
||||
|
||||
static const S16 S16_MIN = S16(-32768);
|
||||
static const S16 S16_MAX = S16(32767);
|
||||
static const U16 U16_MAX = U16(65535);
|
||||
|
||||
static const S32 S32_MIN = S32(-2147483647 - 1);
|
||||
static const S32 S32_MAX = S32(2147483647);
|
||||
static const U32 U32_MAX = U32(0xffffffff);
|
||||
|
||||
static const F32 F32_MAX = F32(3.402823466e+38F);
|
||||
static const F32 F32_MIN = F32(1.175494351e-38F);
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user