mirror of
https://github.com/tribes2/engine.git
synced 2026-02-23 08:33:45 +00:00
t2 engine svn checkout
This commit is contained in:
commit
ff569bd2ae
988 changed files with 394180 additions and 0 deletions
111
platform/3Dfx.h
Normal file
111
platform/3Dfx.h
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
** 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.
|
||||
**
|
||||
** $Revision: 1.1 $
|
||||
** $Date: 2001/05/17 02:18:56 $
|
||||
*/
|
||||
#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 stuff
|
||||
*/
|
||||
#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__ */
|
||||
373
platform/event.h
Normal file
373
platform/event.h
Normal file
|
|
@ -0,0 +1,373 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _EVENT_H_
|
||||
#define _EVENT_H_
|
||||
|
||||
// Library-wide input events - all external events are converted into system events
|
||||
|
||||
typedef int NetConnectionId;
|
||||
|
||||
struct NetAddress {
|
||||
int type;
|
||||
enum {
|
||||
IPXAddress, IPAddress
|
||||
};
|
||||
U8 netNum[4]; // ip sin_addr ipx sa_netnum
|
||||
U8 nodeNum[6]; // ipx sa_nodenum
|
||||
U16 port; // ip sin_port, ipx sa_socket
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
MaxPacketDataSize = 1500,
|
||||
MaxConsoleLineSize = 512
|
||||
|
||||
};
|
||||
|
||||
enum EventType
|
||||
{
|
||||
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); }
|
||||
};
|
||||
|
||||
// Time event advances simulation
|
||||
|
||||
struct TimeEvent : public Event
|
||||
{
|
||||
U32 elapsedTime;
|
||||
|
||||
TimeEvent() { type = TimeEventType; size = sizeof(TimeEvent); }
|
||||
};
|
||||
|
||||
struct ConnectedNotifyEvent : public Event
|
||||
{
|
||||
enum State {
|
||||
DNSResolved,
|
||||
DNSFailed,
|
||||
Connected,
|
||||
ConnectFailed,
|
||||
Disconnected
|
||||
};
|
||||
U32 state;
|
||||
U32 tag;
|
||||
ConnectedNotifyEvent() { type = ConnectedNotifyEventType; size = sizeof(ConnectedNotifyEvent); }
|
||||
};
|
||||
|
||||
struct ConnectedReceiveEvent : public Event
|
||||
{
|
||||
U32 tag;
|
||||
U8 data[MaxPacketDataSize];
|
||||
ConnectedReceiveEvent() { type = ConnectedReceiveEventType; }
|
||||
};
|
||||
|
||||
struct ConnectedAcceptEvent : public Event
|
||||
{
|
||||
U32 portTag;
|
||||
U32 connectionTag;
|
||||
NetAddress address;
|
||||
ConnectedAcceptEvent() { type = ConnectedAcceptEventType; size = sizeof(ConnectedAcceptEvent); }
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ConnectedReceiveEventHeaderSize = U32( &( (ConnectedReceiveEvent *)0)->data)
|
||||
};
|
||||
|
||||
// Packet receive event is incoming packet event - packetType is what type of packet it is
|
||||
|
||||
struct PacketReceiveEvent : public Event
|
||||
{
|
||||
NetAddress sourceAddress;
|
||||
U8 data[MaxPacketDataSize]; // placeholder for data
|
||||
PacketReceiveEvent() { type = PacketReceiveEventType; }
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
PacketReceiveEventHeaderSize = U32( &( (PacketReceiveEvent *)0)->data)
|
||||
};
|
||||
|
||||
// request for connection, connection lost, etc.
|
||||
|
||||
// event sent to the currently focused console
|
||||
|
||||
struct ConsoleEvent : public Event
|
||||
{
|
||||
char data[MaxConsoleLineSize];
|
||||
ConsoleEvent() { type = ConsoleEventType; }
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ConsoleEventHeaderSize = U32( &( (ConsoleEvent *)0)->data)
|
||||
};
|
||||
|
||||
// Input event structure - all input events generated in the platform come through here
|
||||
|
||||
struct MouseMoveEvent : public Event
|
||||
{
|
||||
S32 xPos, yPos;
|
||||
U8 modifier;
|
||||
|
||||
MouseMoveEvent() { type = MouseMoveEventType; size = sizeof(MouseMoveEvent); }
|
||||
};
|
||||
|
||||
struct InputEvent : public Event
|
||||
{
|
||||
U32 deviceInst; // device instance joystick0, joystick1 etc
|
||||
float fValue; // value -1.0 to 1.0
|
||||
U16 deviceType; // mouse, keyboard, joystick, device( ie unidentified)
|
||||
U16 objType; // SI_XAXIS, SI_BUTTON, SI_KEY ...
|
||||
U16 ascii; // ascii character code 'a', 'A', 'b', '*', etc (if device==keyboard) - possibly a uchar or something
|
||||
U16 objInst; // which type instance OR DIK_CODE
|
||||
U8 action; // MAKE/BREAK/MOVE
|
||||
U8 modifier; // SI_LSHIFT, etc
|
||||
|
||||
InputEvent() { type = InputEventType; size = sizeof(InputEvent); }
|
||||
};
|
||||
|
||||
// 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_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
|
||||
};
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
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
|
||||
|
||||
// Event SubTypes
|
||||
#define SI_ANY 0xff
|
||||
|
||||
// Modifier Keys
|
||||
#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)
|
||||
#define SI_LALT (1<<4)
|
||||
#define SI_RALT (1<<5)
|
||||
#define SI_ALT (SI_LALT|SI_RALT)
|
||||
|
||||
#endif
|
||||
239
platform/gameInterface.cc
Normal file
239
platform/gameInterface.cc
Normal file
|
|
@ -0,0 +1,239 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "platform/platform.h"
|
||||
#include "platform/event.h"
|
||||
#include "platform/gameInterface.h"
|
||||
#include "core/fileStream.h"
|
||||
#ifdef __linux
|
||||
#include "platform/platformMutex.h"
|
||||
|
||||
static void* mutex = 0;
|
||||
#endif
|
||||
#include "console/console.h"
|
||||
GameInterface *Game = NULL;
|
||||
|
||||
GameInterface::GameInterface()
|
||||
{
|
||||
AssertFatal(Game == NULL, "ERROR: Multiple games declared.");
|
||||
Game = this;
|
||||
mJournalMode = JournalOff;
|
||||
mRunning = true;
|
||||
#ifdef __linux
|
||||
mutex = Mutex::createMutex( );
|
||||
AssertFatal( mutex == 0, "ERROR: can't create mutex" );
|
||||
#endif
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
#ifdef __linux
|
||||
Mutex::lockMutex( mutex );
|
||||
#else
|
||||
if(PlatformAssert::processingAssert()) // ignore any events if an assert dialog is up.
|
||||
return;
|
||||
|
||||
#ifdef DEBUG
|
||||
sReentrantCount++;
|
||||
AssertFatal(sReentrantCount == 1, "Error! ProcessEvent is NOT reentrant.");
|
||||
#endif
|
||||
#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 __linux
|
||||
Mutex::unlockMutex( mutex );
|
||||
#else
|
||||
#ifdef DEBUG
|
||||
sReentrantCount--;
|
||||
#endif
|
||||
#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 == JournalLoad || mJournalMode == JournalPlay) && event.type != QuitEventType)
|
||||
return;
|
||||
if(mJournalMode == JournalSave) {
|
||||
gJournalStream.write(event.size, &event);
|
||||
gJournalStream.flush();
|
||||
}
|
||||
processEvent(&event);
|
||||
}
|
||||
|
||||
void GameInterface::journalProcess()
|
||||
{
|
||||
if(mJournalMode == JournalLoad || mJournalMode == JournalPlay)
|
||||
{
|
||||
ReadEvent journalReadEvent;
|
||||
if(gJournalStream.read(&journalReadEvent.type))
|
||||
{
|
||||
if(gJournalStream.read(&journalReadEvent.size))
|
||||
{
|
||||
if(gJournalStream.read(journalReadEvent.size - sizeof(Event), &journalReadEvent.data))
|
||||
{
|
||||
if(gJournalStream.getPosition() == gJournalStream.getStreamSize() && mJournalMode == JournalLoad && !Con::getBoolVariable("NoJournalBreak", false))
|
||||
Platform::debugBreak();
|
||||
processEvent(&journalReadEvent);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(mJournalMode == JournalLoad)
|
||||
mRunning = false;
|
||||
else
|
||||
mJournalMode = JournalOff;
|
||||
}
|
||||
}
|
||||
|
||||
void GameInterface::loadJournal(const char *fileName)
|
||||
{
|
||||
mJournalMode = JournalLoad;
|
||||
gJournalStream.open(fileName, FileStream::Read);
|
||||
}
|
||||
|
||||
void GameInterface::saveJournal(const char *fileName)
|
||||
{
|
||||
mJournalMode = JournalSave;
|
||||
gJournalStream.open(fileName, FileStream::Write);
|
||||
}
|
||||
|
||||
void GameInterface::playJournal(const char *fileName)
|
||||
{
|
||||
mJournalMode = JournalPlay;
|
||||
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);
|
||||
}
|
||||
|
||||
74
platform/gameInterface.h
Normal file
74
platform/gameInterface.h
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _GAMEINTERFACE_H_
|
||||
#define _GAMEINTERFACE_H_
|
||||
|
||||
class FileStream;
|
||||
|
||||
class GameInterface
|
||||
{
|
||||
public:
|
||||
enum JournalMode {
|
||||
JournalOff,
|
||||
JournalSave,
|
||||
JournalPlay,
|
||||
JournalLoad,
|
||||
};
|
||||
private:
|
||||
JournalMode mJournalMode;
|
||||
bool mRunning;
|
||||
public:
|
||||
GameInterface();
|
||||
|
||||
// calls from the platform into the game:
|
||||
virtual int main(int argc, const char **argv);
|
||||
virtual void textureKill();
|
||||
virtual void textureResurrect();
|
||||
virtual void refreshWindow();
|
||||
|
||||
virtual void postEvent(Event &event);
|
||||
|
||||
// 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);
|
||||
|
||||
void setRunning(bool running) { mRunning = running; }
|
||||
bool isRunning() { return mRunning; }
|
||||
|
||||
void journalProcess();
|
||||
void loadJournal(const char *fileName);
|
||||
void saveJournal(const char *fileName);
|
||||
void playJournal(const char *fileName);
|
||||
|
||||
JournalMode getJournalMode() { return mJournalMode; };
|
||||
|
||||
bool isJournalReading() { return mJournalMode == JournalLoad || mJournalMode == JournalPlay; }
|
||||
bool isJournalWriting() { return mJournalMode == JournalSave; }
|
||||
|
||||
void journalRead(U32 *val);
|
||||
void journalWrite(U32 val);
|
||||
void journalRead(U32 size, void *buffer);
|
||||
void journalWrite(U32 size, const void *buffer);
|
||||
|
||||
FileStream *getJournalStream();
|
||||
};
|
||||
|
||||
extern GameInterface *Game;
|
||||
|
||||
#endif
|
||||
495
platform/platform.h
Normal file
495
platform/platform.h
Normal file
|
|
@ -0,0 +1,495 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORM_H_
|
||||
#define _PLATFORM_H_
|
||||
|
||||
#ifndef _TYPES_H_
|
||||
#include "platform/types.h"
|
||||
#endif
|
||||
#ifndef _PLATFORMASSERT_H_
|
||||
#include "platform/platformAssert.h"
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Endian conversions
|
||||
#ifdef PLATFORM_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 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(S32(i)));
|
||||
}
|
||||
|
||||
|
||||
#elif defined(PLATFORM_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 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_Pentium,
|
||||
CPU_Intel_PentiumII,
|
||||
CPU_Intel_PentiumIII,
|
||||
CPU_AMD_K6,
|
||||
CPU_AMD_K6_2,
|
||||
CPU_AMD_K6_3,
|
||||
CPU_AMD_K7,
|
||||
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_G3
|
||||
};
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
enum PPCProperties
|
||||
{ // PowerPC properties
|
||||
};
|
||||
|
||||
struct Platform
|
||||
{
|
||||
static void init();
|
||||
static void shutdown();
|
||||
static void process();
|
||||
static bool doCDCheck();
|
||||
static void initWindow(const Point2I &initialSize, const char *name);
|
||||
static void enableKeyboardTranslation(void);
|
||||
static void disableKeyboardTranslation(void);
|
||||
static void setWindowLocked(bool locked);
|
||||
static void minimizeWindow();
|
||||
static bool excludeOtherInstances(const char *string);
|
||||
|
||||
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* pVirtPath;
|
||||
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(int returnValue);
|
||||
|
||||
static U32 getTime();
|
||||
static U32 getVirtualMilliseconds();
|
||||
static U32 getRealMilliseconds();
|
||||
static void advanceTime(U32 delta);
|
||||
|
||||
// Directory functions. Dump path returns false iff the directory cannot be
|
||||
// opened.
|
||||
public:
|
||||
static void getCurrentDirectory(char *out_pDirectory, const U32 in_bufferSize);
|
||||
static bool dumpPath(const char *in_pBasePath, Vector<FileInfo>& out_rFileVector);
|
||||
static bool getFileTimes(const char *filePath, FileTime *createTime, FileTime *modifyTime);
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
|
||||
struct Processor
|
||||
{
|
||||
static void init();
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// time manager generates a ServerTimeEvent / ClientTimeEvent, FrameEvent combo
|
||||
// every other time its process is called.
|
||||
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 int dStrcmp(const char *str1, const char *str2);
|
||||
extern int dStricmp(const char *str1, const char *str2);
|
||||
extern int dStrncmp(const char *str1, const char *str2, U32 len);
|
||||
extern int dStrnicmp(const char *str1, const char *str2, U32 len);
|
||||
extern char* dStrcpy(char *dst, const char *src);
|
||||
extern char* dStrncpy(char *dst, const char *src, U32 len);
|
||||
extern U32 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 U32 dStrspn(const char *str, const char *set);
|
||||
extern U32 dStrcspn(const char *str, const char *set);
|
||||
extern char* dStrstr(char *str1, char *str2);
|
||||
extern const 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, U32 bufferSize, const char *format, ...);
|
||||
extern int dVsprintf(char *buffer, U32 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);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// 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
|
||||
class ConsoleObject;
|
||||
const char* __dyncreate_getNameFromType(ConsoleObject *);
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Memory functions
|
||||
|
||||
namespace Memory {
|
||||
U32 getMemoryUsed();
|
||||
U32 getMemoryAllocated();
|
||||
} // 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 void destructInPlace(T* p)
|
||||
{
|
||||
p->~T();
|
||||
}
|
||||
|
||||
#ifndef NO_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 // #ifndef NO_MEMORY_MANAGER
|
||||
|
||||
#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*, U32);
|
||||
|
||||
extern void setBreakAlloc(U32);
|
||||
extern void setMinimumAllocUnit(U32);
|
||||
extern void* dMalloc_r(U32 in_size, const char*, const U32);
|
||||
extern void dFree(void* in_pFree);
|
||||
extern void* dRealloc(void* in_pResize, U32 in_size);
|
||||
extern void* dRealMalloc(dsize_t);
|
||||
extern void dRealFree(void*);
|
||||
|
||||
extern void* dMemcpy(void *dst, const void *src, unsigned size);
|
||||
extern void* dMemmove(void *dst, const void *src, unsigned size);
|
||||
extern void* dMemset(void *dst, int c, unsigned size);
|
||||
extern int dMemcmp(const void *ptr1, const void *ptr2, unsigned size);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Graphics functions
|
||||
|
||||
class GFont;
|
||||
extern GFont *createFont(const char *name, int size);
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// 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 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 int 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(int connectPort);
|
||||
static void closePort();
|
||||
static Error sendto(const NetAddress *address, const U8 *buffer, int 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 sendTo(NetSocket socket, const U8 *buffer, int 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, int maxConcurrentListens);
|
||||
static NetSocket accept(NetSocket acceptSocket, NetAddress *remoteAddress);
|
||||
|
||||
static Error bind(NetSocket socket, U16 port);
|
||||
static Error setBufferSize(NetSocket socket, int bufferSize);
|
||||
static Error setBroadcast(NetSocket socket, bool broadcastEnable);
|
||||
static Error setBlocking(NetSocket socket, bool blockingIO);
|
||||
|
||||
static Error send(NetSocket socket, const U8 *buffer, int bufferSize);
|
||||
static Error recv(NetSocket socket, U8 *buffer, int bufferSize, int *bytesRead);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
162
platform/platformAL.h
Normal file
162
platform/platformAL.h
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORMAL_H_
|
||||
#define _PLATFORMAL_H_
|
||||
|
||||
#ifndef _PLATFORM_H_
|
||||
#include "Platform/platform.h"
|
||||
#endif
|
||||
//#define AL_NO_PROTOTYPES
|
||||
//#define ALC_NO_PROTOTYPES
|
||||
//#define _LIB
|
||||
//#include <al/al.h>
|
||||
//#include <al/alc.h>
|
||||
//#include <al/alut.h>
|
||||
|
||||
#include <al/altypes.h>
|
||||
#include <al/alctypes.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>
|
||||
#undef AL_FUNCTION
|
||||
|
||||
|
||||
|
||||
/*
|
||||
// extra enums for win32/miles implementation
|
||||
enum {
|
||||
// error values
|
||||
AL_CONTEXT_ALREADY_INSTANTIATED = 0xbaadf00d,
|
||||
AL_ENVIRONMENT_ALREADY_INSTANTIATED,
|
||||
AL_UNSUPPORTED,
|
||||
AL_INVALID_BUFFER,
|
||||
AL_ERROR,
|
||||
|
||||
// context extention
|
||||
ALC_PROVIDER,
|
||||
ALC_PROVIDER_COUNT,
|
||||
ALC_PROVIDER_NAME,
|
||||
ALC_SPEAKER,
|
||||
ALC_SPEAKER_COUNT,
|
||||
ALC_SPEAKER_NAME,
|
||||
ALC_BUFFER_DYNAMIC_MEMORY_SIZE,
|
||||
ALC_BUFFER_DYNAMIC_MEMORY_USAGE,
|
||||
ALC_BUFFER_DYNAMIC_COUNT,
|
||||
ALC_BUFFER_MEMORY_USAGE,
|
||||
ALC_BUFFER_COUNT,
|
||||
ALC_BUFFER_LATENCY,
|
||||
|
||||
// misc 3d params
|
||||
AL_MIN_DISTANCE,
|
||||
AL_MAX_DISTANCE,
|
||||
AL_CONE_OUTER_GAIN,
|
||||
|
||||
// relative with pos(0,0,0) won't work for ambient sounds with miles
|
||||
AL_SOURCE_AMBIENT,
|
||||
AL_PAN,
|
||||
|
||||
// other extensions
|
||||
AL_BUFFER_KEEP_RESIDENT,
|
||||
AL_FORMAT_WAVE_EXT,
|
||||
|
||||
// Environment extensions:
|
||||
AL_ENV_EFFECT_VOLUME_EXT,
|
||||
AL_ENV_FLAGS_EXT,
|
||||
AL_ENV_DAMPING_EXT,
|
||||
AL_ENV_ENVIRONMENT_SIZE_EXT,
|
||||
AL_ENV_ROOM_VOLUME_EXT,
|
||||
};
|
||||
|
||||
enum {
|
||||
// sample level environment:
|
||||
AL_ENV_SAMPLE_REVERB_MIX_EXT = 0,
|
||||
AL_ENV_SAMPLE_DIRECT_EXT,
|
||||
AL_ENV_SAMPLE_DIRECT_HF_EXT,
|
||||
AL_ENV_SAMPLE_ROOM_EXT,
|
||||
AL_ENV_SAMPLE_ROOM_HF_EXT,
|
||||
AL_ENV_SAMPLE_OBSTRUCTION_EXT,
|
||||
AL_ENV_SAMPLE_OBSTRUCTION_LF_RATIO_EXT,
|
||||
AL_ENV_SAMPLE_OCCLUSION_EXT,
|
||||
AL_ENV_SAMPLE_OCCLUSION_LF_RATIO_EXT,
|
||||
AL_ENV_SAMPLE_OCCLUSION_ROOM_RATIO_EXT,
|
||||
AL_ENV_SAMPLE_ROOM_ROLLOFF_EXT,
|
||||
AL_ENV_SAMPLE_AIR_ABSORPTION_EXT,
|
||||
AL_ENV_SAMPLE_OUTSIDE_VOLUME_HF_EXT,
|
||||
AL_ENV_SAMPLE_FLAGS_EXT,
|
||||
|
||||
AL_ENV_SAMPLE_COUNT,
|
||||
};
|
||||
|
||||
// room types: same as miles/eax
|
||||
enum {
|
||||
AL_ENVIRONMENT_GENERIC = 0,
|
||||
AL_ENVIRONMENT_PADDEDCELL,
|
||||
AL_ENVIRONMENT_ROOM,
|
||||
AL_ENVIRONMENT_BATHROOM,
|
||||
AL_ENVIRONMENT_LIVINGROOM,
|
||||
AL_ENVIRONMENT_STONEROOM,
|
||||
AL_ENVIRONMENT_AUDITORIUM,
|
||||
AL_ENVIRONMENT_CONCERTHALL,
|
||||
AL_ENVIRONMENT_CAVE,
|
||||
AL_ENVIRONMENT_ARENA,
|
||||
AL_ENVIRONMENT_HANGAR,
|
||||
AL_ENVIRONMENT_CARPETEDHALLWAY,
|
||||
AL_ENVIRONMENT_HALLWAY,
|
||||
AL_ENVIRONMENT_STONECORRIDOR,
|
||||
AL_ENVIRONMENT_ALLEY,
|
||||
AL_ENVIRONMENT_FOREST,
|
||||
AL_ENVIRONMENT_CITY,
|
||||
AL_ENVIRONMENT_MOUNTAINS,
|
||||
AL_ENVIRONMENT_QUARRY,
|
||||
AL_ENVIRONMENT_PLAIN,
|
||||
AL_ENVIRONMENT_PARKINGLOT,
|
||||
AL_ENVIRONMENT_SEWERPIPE,
|
||||
AL_ENVIRONMENT_UNDERWATER,
|
||||
AL_ENVIRONMENT_DRUGGED,
|
||||
AL_ENVIRONMENT_DIZZY,
|
||||
AL_ENVIRONMENT_PSYCHOTIC,
|
||||
|
||||
AL_ENVIRONMENT_COUNT
|
||||
};
|
||||
*/
|
||||
|
||||
namespace Audio
|
||||
{
|
||||
|
||||
//bool libraryInit();
|
||||
//void libraryInitExtensions();
|
||||
//void libraryShutdown();
|
||||
|
||||
//inline bool doesSupportIASIG()
|
||||
//{
|
||||
// return gDoesSupport_AL_EXT_IASIG;
|
||||
//}
|
||||
|
||||
//inline bool doesSupportDynamix()
|
||||
//{
|
||||
// return gDoesSupport_AL_EXT_DYNAMIX;
|
||||
//}
|
||||
|
||||
|
||||
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_
|
||||
115
platform/platformAssert.cc
Normal file
115
platform/platformAssert.cc
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "Platform/platformAssert.h"
|
||||
#include "console/console.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
//-------------------------------------- STATIC Declaration
|
||||
PlatformAssert *PlatformAssert::platformAssert = NULL;
|
||||
|
||||
//--------------------------------------
|
||||
PlatformAssert::PlatformAssert()
|
||||
{
|
||||
processing = false;
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
void PlatformAssert::create()
|
||||
{
|
||||
if (!platformAssert)
|
||||
platformAssert = 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;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
void PlatformAssert::process(Type assertType,
|
||||
const char *filename,
|
||||
U32 lineNumber,
|
||||
const char *message)
|
||||
{
|
||||
processing = true;
|
||||
char *typeName[] = { "Unknown", "Fatal-ISV", "Fatal", "Warning" };
|
||||
|
||||
// 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 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;
|
||||
}
|
||||
|
||||
bool PlatformAssert::processingAssert()
|
||||
{
|
||||
return platformAssert ? platformAssert->processing : false;
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
void PlatformAssert::processAssert(Type assertType,
|
||||
const char *filename,
|
||||
U32 lineNumber,
|
||||
const char *message)
|
||||
{
|
||||
if (platformAssert)
|
||||
platformAssert->process(assertType, filename, lineNumber, message);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
const char* avar(const char *message, ...)
|
||||
{
|
||||
static char buffer[1024];
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
dVsprintf(buffer, sizeof(buffer), message, args);
|
||||
return( buffer );
|
||||
}
|
||||
77
platform/platformAssert.h
Normal file
77
platform/platformAssert.h
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, 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;
|
||||
|
||||
bool displayMessageBox(const char *title, const char *message, bool retry);
|
||||
void process(Type assertType,
|
||||
const char* filename,
|
||||
U32 lineNumber,
|
||||
const char* message);
|
||||
|
||||
PlatformAssert();
|
||||
|
||||
public:
|
||||
static void create();
|
||||
static void destroy();
|
||||
static void processAssert(Type assertType,
|
||||
const char* filename,
|
||||
U32 lineNumber,
|
||||
const char* message);
|
||||
static char* message(const char *message, ...);
|
||||
static bool processingAssert();
|
||||
};
|
||||
|
||||
|
||||
#ifdef ENABLE_ASSERTS
|
||||
#define AssertWarn(x, y) \
|
||||
{ if (!bool(x)) \
|
||||
PlatformAssert::processAssert(PlatformAssert::Warning, __FILE__, __LINE__, y); }
|
||||
|
||||
#define AssertFatal(x, y) \
|
||||
{ if (!bool(x)) \
|
||||
PlatformAssert::processAssert(PlatformAssert::Fatal, __FILE__, __LINE__, y); }
|
||||
|
||||
// #define AssertFatal(x, y) { }
|
||||
|
||||
#else
|
||||
#define AssertFatal(x, y) { }
|
||||
#define AssertWarn(x, y) { }
|
||||
#endif
|
||||
|
||||
|
||||
#define AssertISV(x, y) \
|
||||
{ if (!bool(x)) \
|
||||
PlatformAssert::processAssert(PlatformAssert::Fatal_ISV, __FILE__, __LINE__, y); }
|
||||
|
||||
|
||||
const char* avar(const char *in_msg, ...);
|
||||
|
||||
|
||||
|
||||
#endif // _PLATFORM_ASSERT_H_
|
||||
|
||||
171
platform/platformAudio.h
Normal file
171
platform/platformAudio.h
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORMAUDIO_H_
|
||||
#define _PLATFORMAUDIO_H_
|
||||
|
||||
#ifndef _PLATFORM_H_
|
||||
#include "Platform/platform.h"
|
||||
#endif
|
||||
#ifndef _PLATFORMAL_H_
|
||||
#include "PlatformWin32/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 AudioTypes {
|
||||
DefaultAudioType = 0,
|
||||
ChatAudioType,
|
||||
GuiAudioType,
|
||||
EffectAudioType,
|
||||
VoiceAudioType,
|
||||
MusicAudioType,
|
||||
|
||||
NumAudioTypes
|
||||
};
|
||||
|
||||
//--------------------------------------
|
||||
// sound property description
|
||||
struct Description
|
||||
{
|
||||
F32 mVolume; // 0-1 1=loudest volume
|
||||
bool mIsLooping;
|
||||
bool mIs3D;
|
||||
|
||||
F32 mMinDistance;
|
||||
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;
|
||||
};
|
||||
|
||||
struct DriverInfo
|
||||
{
|
||||
char *mName;
|
||||
char *mVender;
|
||||
char *mVersion;
|
||||
char *mRenderer;
|
||||
char *mExtensions;
|
||||
};
|
||||
|
||||
void init();
|
||||
void detect();
|
||||
void destroy();
|
||||
|
||||
bool setDriver(const char *name);
|
||||
const Vector<DriverInfo>* getDriverList();
|
||||
|
||||
const char* getDriverListString();
|
||||
const char* getCurrentDriverInfo();
|
||||
}
|
||||
|
||||
class AudioDescription;
|
||||
class AudioProfile;
|
||||
class AudioEnvironment;
|
||||
class AudioSampleEnvironment;
|
||||
|
||||
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);
|
||||
|
||||
AUDIOHANDLE alxPlay(AUDIOHANDLE handle);
|
||||
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);
|
||||
|
||||
inline void alxSourcePoint3F(AUDIOHANDLE handle, ALenum pname, const Point3F *value)
|
||||
{
|
||||
alxSource3f(handle, pname, value->x, value->y, value->z);
|
||||
}
|
||||
|
||||
inline void alxSourceGetPoint3F(AUDIOHANDLE handle, ALenum pname, Point3F * value)
|
||||
{
|
||||
alxGetSource3f(handle, pname, &value->x, &value->y, &value->z);
|
||||
}
|
||||
|
||||
// Listener
|
||||
void alxListenerf(ALenum pname, ALfloat value);
|
||||
void alxListenerfv(ALenum pname, ALfloat *values);
|
||||
void alxListener3f(ALenum pname, ALfloat value1, ALfloat value2, ALfloat value3);
|
||||
void alxListeneri(ALenum pname, ALint value);
|
||||
void alxListenerMatrixF(const MatrixF *transform);
|
||||
|
||||
void alxGetListenerf(ALenum pname, ALfloat *value);
|
||||
void alxGetListenerfv(ALenum pname, ALfloat *values);
|
||||
void alxGetListener3f(ALenum pname, ALfloat *value1, ALfloat *value2, ALfloat *value3);
|
||||
void alxGetListeneri(ALenum pname, ALint *value);
|
||||
|
||||
inline void alxListenerPoint3F(ALenum pname, const Point3F *value)
|
||||
{
|
||||
alxListener3f(pname, value->x, value->y, value->z);
|
||||
}
|
||||
|
||||
inline void alxListenerGetPoint3F(ALenum pname, Point3F * value)
|
||||
{
|
||||
alxGetListener3f(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();
|
||||
|
||||
// voice
|
||||
struct SimVoiceStreamEvent;
|
||||
struct SimVoiceEvent;
|
||||
|
||||
void alxReceiveVoiceStream(SimVoiceStreamEvent *event);
|
||||
void alxReceiveVoiceEvent(SimVoiceEvent *event);
|
||||
|
||||
// misc
|
||||
ALuint alxGetWaveLen(ALuint buffer);
|
||||
bool alxIsValidHandle(AUDIOHANDLE handle);
|
||||
bool alxIsPlaying(AUDIOHANDLE handle);
|
||||
void alxUpdate();
|
||||
|
||||
#endif // _H_PLATFORMAUDIO_
|
||||
192
platform/platformCPU.cc
Normal file
192
platform/platformCPU.cc
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// $Id: platformCPU.cc,v 1.1 2002/03/17 04:27:07 jmquigs Exp $
|
||||
|
||||
#include "platform/platform.h"
|
||||
#include "core/stringTable.h"
|
||||
|
||||
enum
|
||||
{
|
||||
BIT_FPU = (1<<0),
|
||||
BIT_RDTSC = (1<<4),
|
||||
BIT_MMX = (1<<23),
|
||||
BIT_SSE = (1<<25),
|
||||
BIT_3DNOW = (1<<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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
96
platform/platformCPUInfo.asm
Normal file
96
platform/platformCPUInfo.asm
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
;-----------------------------------------------------------------------------
|
||||
; V12 Engine
|
||||
;
|
||||
; Copyright (c) 2001 GarageGames.Com
|
||||
; Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
;-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
segment .text
|
||||
|
||||
; this is a nice macro Rick
|
||||
; 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
|
||||
|
||||
; so is this
|
||||
;%define arg(x) [esp+(x*4)]
|
||||
|
||||
; void isCPUIDSupported(char *vendor, U32 *properties, U32 *processor);
|
||||
export_fn isCPUIDSupported
|
||||
|
||||
; mov ebp, esp
|
||||
push ebp
|
||||
push ebx
|
||||
push edx
|
||||
push ecx
|
||||
; mov ecx, arg(1)
|
||||
; mov edx, arg(2)
|
||||
; mov eax, arg(3)
|
||||
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
|
||||
|
||||
; mov dword [vendor], ebx
|
||||
; mov dword [vendor+4], edx
|
||||
; mov dword [vendor+8], ecx
|
||||
mov dword [esp+8], ebx
|
||||
mov dword [esp+12], edx
|
||||
mov dword [esp+16], ecx
|
||||
popfd
|
||||
pop ecx
|
||||
pop edx
|
||||
pop ebx
|
||||
leave
|
||||
; pop ebp
|
||||
; mov esp, ebp
|
||||
ret
|
||||
;jz EXIT
|
||||
; get generic extended CPUID info
|
||||
mov eax, 1
|
||||
cpuid ; eax=1, so cpuid queries feature information
|
||||
|
||||
and eax, 0x0FF0
|
||||
mov [esp+20], eax ; just store the model bits
|
||||
mov [esp+16], edx
|
||||
|
||||
; 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
|
||||
and edx, 0x80000000 ; 3DNow if bit 31 set -> put bit in our properties
|
||||
or [esp+16], edx
|
||||
MAYBE_3DLATER:
|
||||
|
||||
|
||||
EXIT:
|
||||
popfd
|
||||
pop ecx
|
||||
pop edx
|
||||
pop ebx
|
||||
ret
|
||||
|
||||
111
platform/platformInput.h
Normal file
111
platform/platformInput.h
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, 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() = NULL;
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
inline const char* InputDevice::getDeviceName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
class InputManager : public SimGroup
|
||||
{
|
||||
protected:
|
||||
bool mEnabled;
|
||||
|
||||
public:
|
||||
bool isEnabled();
|
||||
|
||||
virtual bool enable() = NULL;
|
||||
virtual void disable() = NULL;
|
||||
|
||||
virtual void process() = NULL;
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
inline bool InputManager::isEnabled()
|
||||
{
|
||||
return mEnabled;
|
||||
}
|
||||
|
||||
enum KEY_STATE
|
||||
{
|
||||
STATE_LOWER,
|
||||
STATE_UPPER,
|
||||
STATE_GOOFY
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
class Input
|
||||
{
|
||||
protected:
|
||||
static InputManager* smManager;
|
||||
static bool smActive;
|
||||
|
||||
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 InputManager* getManager();
|
||||
|
||||
#ifdef LOG_INPUT
|
||||
static void log( const char* format, ... );
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // _H_PLATFORMINPUT_
|
||||
1146
platform/platformMemory.cc
Normal file
1146
platform/platformMemory.cc
Normal file
File diff suppressed because it is too large
Load diff
19
platform/platformMutex.h
Normal file
19
platform/platformMutex.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORMMUTEX_H_
|
||||
#define _PLATFORMMUTEX_H_
|
||||
|
||||
struct Mutex
|
||||
{
|
||||
static void* createMutex( void );
|
||||
static void destroyMutex( void* );
|
||||
static void lockMutex( void* );
|
||||
static void unlockMutex( void* );
|
||||
};
|
||||
|
||||
#endif
|
||||
267
platform/platformRedBook.cc
Normal file
267
platform/platformRedBook.cc
Normal file
|
|
@ -0,0 +1,267 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, 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()
|
||||
{
|
||||
installConsoleCommands();
|
||||
}
|
||||
|
||||
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
|
||||
//------------------------------------------------------------------------------
|
||||
static bool cOpen(SimObject *, S32 argc, const char ** argv)
|
||||
{
|
||||
if(argc == 1)
|
||||
return(RedBook::open(RedBook::getDeviceName(0)));
|
||||
else
|
||||
return(RedBook::open(argv[1]));
|
||||
}
|
||||
|
||||
static bool cClose(SimObject *, S32, const char **)
|
||||
{
|
||||
return(RedBook::close());
|
||||
}
|
||||
|
||||
static bool cPlay(SimObject *, S32, const char ** argv)
|
||||
{
|
||||
return(RedBook::play(dAtoi(argv[1])));
|
||||
}
|
||||
|
||||
static bool cStop(SimObject *, S32, const char **)
|
||||
{
|
||||
return(RedBook::stop());
|
||||
}
|
||||
|
||||
static S32 cGetTrackCount(SimObject *, S32, const char **)
|
||||
{
|
||||
U32 trackCount;
|
||||
if(!RedBook::getTrackCount(&trackCount))
|
||||
return(0);
|
||||
return(trackCount);
|
||||
}
|
||||
|
||||
static F32 cGetVolume(SimObject *, S32, const char **)
|
||||
{
|
||||
F32 vol;
|
||||
if(!RedBook::getVolume(&vol))
|
||||
return(0.f);
|
||||
else
|
||||
return(vol);
|
||||
}
|
||||
|
||||
static bool cSetVolume(SimObject *, S32, const char ** argv)
|
||||
{
|
||||
return(RedBook::setVolume(dAtof(argv[1])));
|
||||
}
|
||||
|
||||
static S32 cGetDeviceCount(SimObject *, S32, const char **)
|
||||
{
|
||||
return(RedBook::getDeviceCount());
|
||||
}
|
||||
|
||||
static const char * cGetDeviceName(SimObject *, S32, const char ** argv)
|
||||
{
|
||||
return(RedBook::getDeviceName(dAtoi(argv[1])));
|
||||
}
|
||||
|
||||
static const char * cGetLastError(SimObject *, S32, const char **)
|
||||
{
|
||||
return(RedBook::getLastError());
|
||||
}
|
||||
|
||||
void RedBook::installConsoleCommands()
|
||||
{
|
||||
Con::addCommand("redbookOpen", cOpen, "redbookOpen(<device>)", 1, 2);
|
||||
Con::addCommand("redbookClose", cClose, "redbookClose()", 1, 1);
|
||||
Con::addCommand("redbookPlay", cPlay, "redbookPlay(track)", 2, 2);
|
||||
Con::addCommand("redbookStop", cStop, "redbookStop()", 1, 1);
|
||||
Con::addCommand("redbookGetTrackCount", cGetTrackCount, "redbookGetTrackCount()", 1, 1);
|
||||
Con::addCommand("redbookGetVolume", cGetVolume, "redbookGetVolume", 1, 1);
|
||||
Con::addCommand("redbookSetVolume", cSetVolume, "redbookSetVolume", 2, 2);
|
||||
|
||||
Con::addCommand("redbookGetDeviceCount", cGetDeviceCount, "redbookGetDeviceCount()", 1, 1);
|
||||
Con::addCommand("redbookGetDeviceName", cGetDeviceName, "redbookGetDeviceName(idx)", 2, 2);
|
||||
Con::addCommand("redbookGetLastError", cGetLastError, "redbookGetLastError()", 1, 1);
|
||||
}
|
||||
74
platform/platformRedBook.h
Normal file
74
platform/platformRedBook.h
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, 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[];
|
||||
|
||||
static void installConsoleCommands();
|
||||
|
||||
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
|
||||
26
platform/platformSemaphore.h
Normal file
26
platform/platformSemaphore.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORMSEMAPHORE_H_
|
||||
#define _PLATFORMSEMAPHORE_H_
|
||||
|
||||
#ifndef _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
|
||||
34
platform/platformThread.h
Normal file
34
platform/platformThread.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORMTHREAD_H_
|
||||
#define _PLATFORMTHREAD_H_
|
||||
|
||||
#ifndef _TYPES_H_
|
||||
#include "Platform/types.h"
|
||||
#endif
|
||||
|
||||
typedef void (*ThreadRunFunction)(S32);
|
||||
|
||||
class Thread
|
||||
{
|
||||
protected:
|
||||
void * mData;
|
||||
void start();
|
||||
|
||||
public:
|
||||
Thread(ThreadRunFunction func = 0, S32 arg = 0, bool start_thread = true);
|
||||
virtual ~Thread();
|
||||
|
||||
bool join();
|
||||
|
||||
virtual void run(S32 arg = 0);
|
||||
|
||||
bool isAlive();
|
||||
};
|
||||
|
||||
#endif
|
||||
659
platform/platformVideo.cc
Normal file
659
platform/platformVideo.cc
Normal file
|
|
@ -0,0 +1,659 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "Platform/platformVideo.h"
|
||||
#include "GUI/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;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
static bool cSetDisplayDevice( SimObject*, S32 argc, const char** argv )
|
||||
{
|
||||
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 ) );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
static bool cSetScreenMode( SimObject*, S32, const char** argv )
|
||||
{
|
||||
return( Video::setScreenMode( dAtoi( argv[1] ), dAtoi( argv[2] ), dAtoi( argv[3] ), dAtob( argv[4] ) ) );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static bool cFullScreenToggle( SimObject*, S32, const char** )
|
||||
{
|
||||
return( Video::toggleFullScreen() );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static bool cIsFullScreen( SimObject*, S32, const char** )
|
||||
{
|
||||
return( Video::isFullScreen() );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
static bool cSwitchBitDepth( SimObject*, S32, const char** )
|
||||
{
|
||||
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 ) ) );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
static bool cPrevRes( SimObject*, S32, const char** )
|
||||
{
|
||||
return( Video::prevRes() );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
static bool cNextRes( SimObject*, S32, const char** )
|
||||
{
|
||||
return( Video::nextRes() );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
static const char* cGetResolution( SimObject*, S32, const char** )
|
||||
{
|
||||
static char resBuf[16];
|
||||
Resolution res = Video::getResolution();
|
||||
dSprintf( resBuf, sizeof(resBuf), "%d %d %d", res.w, res.h, res.bpp );
|
||||
return( resBuf );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
static bool cSetResolution( SimObject*, S32 argc, const char** argv )
|
||||
{
|
||||
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 ) );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static const char* cVideoGetDeviceList( SimObject*, S32, const char** )
|
||||
{
|
||||
return( Video::getDeviceList() );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static const char* cVideoGetResList( SimObject*, S32, const char** argv )
|
||||
{
|
||||
DisplayDevice* device = Video::getDevice( argv[1] );
|
||||
if ( !device )
|
||||
{
|
||||
Con::warnf( ConsoleLogEntry::General, "\"%s\" display device not found!", argv[1] );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
return( device->getResolutionList() );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static const char* cVideoGetDriverInfo( SimObject*, S32, const char** )
|
||||
{
|
||||
return( Video::getDriverInfo() );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static bool cIsDeviceFullScreenOnly( SimObject*, S32, const char** argv )
|
||||
{
|
||||
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();
|
||||
|
||||
// Add console commands:
|
||||
Con::addCommand( "setDisplayDevice", cSetDisplayDevice, "setDisplayDevice( deviceName{, width{, height{, bpp{, fullScreen}}}}} );", 2, 6 );
|
||||
Con::addCommand( "setScreenMode", cSetScreenMode, "setScreenMode( width, height, bpp, fullScreen );", 5, 5 );
|
||||
Con::addCommand( "toggleFullScreen", cFullScreenToggle, "toggleFullScreen();", 1, 1 );
|
||||
Con::addCommand( "isFullScreen", cIsFullScreen, "isFullScreen();", 1, 1 );
|
||||
Con::addCommand( "switchBitDepth", cSwitchBitDepth, "switchBitDepth();", 1, 1 );
|
||||
Con::addCommand( "prevResolution", cPrevRes, "prevResolution();", 1, 1 );
|
||||
Con::addCommand( "nextResolution", cNextRes, "nextResolution();", 1, 1 );
|
||||
Con::addCommand( "getResolution", cGetResolution, "getResolution();", 1, 1 );
|
||||
Con::addCommand( "setResolution", cSetResolution, "setResolution( width, height, bpp );", 3, 4 );
|
||||
Con::addCommand( "setRes", cSetResolution, "setRes( width, height, bpp );", 3, 4 );
|
||||
Con::addCommand( "getDisplayDeviceList", cVideoGetDeviceList, "getDisplayDeviceList();", 1, 1 );
|
||||
Con::addCommand( "getResolutionList", cVideoGetResList, "getResolutionList( deviceName );", 2, 2 );
|
||||
Con::addCommand( "getVideoDriverInfo", cVideoGetDriverInfo, "getVideoDriverInfo();", 1, 1 );
|
||||
Con::addCommand( "isDeviceFullScreenOnly", cIsDeviceFullScreenOnly, "isDeviceFullScreenOnly( deviceName );", 2, 2 );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
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();
|
||||
}
|
||||
|
||||
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();");
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// 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> )" )
|
||||
{
|
||||
argc;
|
||||
return( Video::setVerticalSync( dAtob( argv[1] ) ) );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
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;
|
||||
}
|
||||
159
platform/platformVideo.h
Normal file
159
platform/platformVideo.h
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORMVIDEO_H_
|
||||
#define _PLATFORMVIDEO_H_
|
||||
|
||||
#ifndef _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 GFXSurface *getSurface(); // get a renderable surface (can return NULL if the window is minimized)
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
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() = NULL;
|
||||
virtual bool activate( U32 width, U32 height, U32 bpp, bool fullScreen ) = NULL;
|
||||
virtual void shutdown() = NULL;
|
||||
|
||||
virtual bool setScreenMode( U32 width, U32 height, U32 bpp, bool fullScreen, bool forceIt = false, bool repaint = true ) = NULL;
|
||||
virtual bool setResolution( U32 width, U32 height, U32 bpp );
|
||||
virtual bool toggleFullScreen();
|
||||
virtual void swapBuffers() = NULL;
|
||||
virtual const char* getDriverInfo() = NULL;
|
||||
virtual bool getGammaCorrection(F32 &g) = NULL;
|
||||
virtual bool setGammaCorrection(F32 g) = NULL;
|
||||
virtual bool setVerticalSync( bool on ) = NULL;
|
||||
|
||||
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
|
||||
538
platform/profiler.cc
Normal file
538
platform/profiler.cc
Normal file
|
|
@ -0,0 +1,538 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "platform/platform.h"
|
||||
#include "platform/profiler.h"
|
||||
#include "core/stringTable.h"
|
||||
#include <stdlib.h> // gotta use malloc and free directly
|
||||
#include "console/console.h"
|
||||
#include "core/tVector.h"
|
||||
#include "core/fileStream.h"
|
||||
|
||||
#ifdef ENABLE_PROFILER
|
||||
ProfilerRootData *ProfilerRootData::sRootList = NULL;
|
||||
Profiler *gProfiler = NULL;
|
||||
|
||||
#ifdef _WIN32
|
||||
// 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;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void startHighResolutionTimer(U32 time[2])
|
||||
{
|
||||
}
|
||||
|
||||
U32 endHighResolutionTimer(U32 time[2])
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Profiler::Profiler()
|
||||
{
|
||||
mMaxStackDepth = MaxStackDepth;
|
||||
mCurrentHash = 0;
|
||||
|
||||
mCurrentProfilerData = (ProfilerData *) malloc(sizeof(ProfilerData));
|
||||
mCurrentProfilerData->mRoot = NULL;
|
||||
mCurrentProfilerData->mNextForRoot = NULL;
|
||||
mCurrentProfilerData->mNextProfilerData = NULL;
|
||||
mCurrentProfilerData->mNextHash = NULL;
|
||||
mCurrentProfilerData->mParent = NULL;
|
||||
mCurrentProfilerData->mNextSibling = NULL;
|
||||
mCurrentProfilerData->mFirstChild = NULL;
|
||||
mCurrentProfilerData->mLastSeenProfiler = NULL;
|
||||
mCurrentProfilerData->mHash = 0;
|
||||
mCurrentProfilerData->mSubDepth = 0;
|
||||
mCurrentProfilerData->mInvokeCount = 0;
|
||||
mCurrentProfilerData->mTotalTime = 0;
|
||||
mCurrentProfilerData->mSubTime = 0;
|
||||
mRootProfilerData = mCurrentProfilerData;
|
||||
|
||||
for(U32 i = 0; i < ProfilerData::HashTableSize; i++)
|
||||
mCurrentProfilerData->mChildHash[i] = 0;
|
||||
|
||||
mProfileList = NULL;
|
||||
|
||||
mEnabled = false;
|
||||
mStackDepth = 0;
|
||||
mNextEnable = false;
|
||||
gProfiler = this;
|
||||
mDumpToConsole = false;
|
||||
mDumpToFile = false;
|
||||
mDumpFileName[0] = '\0';
|
||||
}
|
||||
|
||||
Profiler::~Profiler()
|
||||
{
|
||||
reset();
|
||||
free(mRootProfilerData);
|
||||
gProfiler = NULL;
|
||||
}
|
||||
|
||||
void Profiler::reset()
|
||||
{
|
||||
mEnabled = false; // in case we're in a profiler call.
|
||||
while(mProfileList)
|
||||
{
|
||||
ProfilerData *next = mProfileList->mNextProfilerData;
|
||||
free(mProfileList);
|
||||
mProfileList = NULL;
|
||||
}
|
||||
for(ProfilerRootData *walk = ProfilerRootData::sRootList; walk; walk = walk->mNextRoot)
|
||||
{
|
||||
walk->mFirstProfilerData = 0;
|
||||
walk->mTotalTime = 0;
|
||||
walk->mSubTime = 0;
|
||||
walk->mTotalInvokeCount = 0;
|
||||
}
|
||||
mCurrentProfilerData = mRootProfilerData;
|
||||
mCurrentProfilerData->mNextForRoot = 0;
|
||||
mCurrentProfilerData->mFirstChild = 0;
|
||||
for(U32 i = 0; i < ProfilerData::HashTableSize; i++)
|
||||
mCurrentProfilerData->mChildHash[i] = 0;
|
||||
mCurrentProfilerData->mInvokeCount = 0;
|
||||
mCurrentProfilerData->mTotalTime = 0;
|
||||
mCurrentProfilerData->mSubTime = 0;
|
||||
mCurrentProfilerData->mSubDepth = 0;
|
||||
mCurrentProfilerData->mLastSeenProfiler = 0;
|
||||
}
|
||||
|
||||
static Profiler aProfiler; // allocate the global profiler
|
||||
|
||||
ProfilerRootData::ProfilerRootData(const char *name)
|
||||
{
|
||||
for(ProfilerRootData *walk = sRootList; walk; walk = walk->mNextRoot)
|
||||
if(!dStrcmp(walk->mName, name))
|
||||
Platform::debugBreak();
|
||||
|
||||
mName = name;
|
||||
mNameHash = _StringTable::hashString(name);
|
||||
mNextRoot = sRootList;
|
||||
sRootList = this;
|
||||
mTotalTime = 0;
|
||||
mTotalInvokeCount = 0;
|
||||
mFirstProfilerData = NULL;
|
||||
mEnabled = true;
|
||||
}
|
||||
|
||||
void Profiler::validate()
|
||||
{
|
||||
for(ProfilerRootData *walk = ProfilerRootData::sRootList; walk; walk = walk->mNextRoot)
|
||||
{
|
||||
for(ProfilerData *dp = walk->mFirstProfilerData; dp; dp = dp->mNextForRoot)
|
||||
{
|
||||
if(dp->mRoot != walk)
|
||||
Platform::debugBreak();
|
||||
// check if it's in the parent's list...
|
||||
ProfilerData *wk;
|
||||
for(wk = dp->mParent->mFirstChild; wk; wk = wk->mNextSibling)
|
||||
if(wk == dp)
|
||||
break;
|
||||
if(!wk)
|
||||
Platform::debugBreak();
|
||||
for(wk = dp->mParent->mChildHash[walk->mNameHash & (ProfilerData::HashTableSize - 1)] ;
|
||||
wk; wk = wk->mNextHash)
|
||||
if(wk == dp)
|
||||
break;
|
||||
if(!wk)
|
||||
Platform::debugBreak();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Profiler::hashPush(ProfilerRootData *root)
|
||||
{
|
||||
mStackDepth++;
|
||||
AssertFatal(mStackDepth <= mMaxStackDepth,
|
||||
"Stack overflow in profiler. You may have mismatched PROFILE_START and PROFILE_ENDs");
|
||||
if(!mEnabled)
|
||||
return;
|
||||
|
||||
ProfilerData *nextProfiler = NULL;
|
||||
if(!root->mEnabled || mCurrentProfilerData->mRoot == root)
|
||||
{
|
||||
mCurrentProfilerData->mSubDepth++;
|
||||
return;
|
||||
}
|
||||
|
||||
if(mCurrentProfilerData->mLastSeenProfiler &&
|
||||
mCurrentProfilerData->mLastSeenProfiler->mRoot == root)
|
||||
nextProfiler = mCurrentProfilerData->mLastSeenProfiler;
|
||||
|
||||
if(!nextProfiler)
|
||||
{
|
||||
// first see if it's in the hash table...
|
||||
U32 index = root->mNameHash & (ProfilerData::HashTableSize - 1);
|
||||
nextProfiler = mCurrentProfilerData->mChildHash[index];
|
||||
while(nextProfiler)
|
||||
{
|
||||
if(nextProfiler->mRoot == root)
|
||||
break;
|
||||
nextProfiler = nextProfiler->mNextHash;
|
||||
}
|
||||
if(!nextProfiler)
|
||||
{
|
||||
nextProfiler = (ProfilerData *) malloc(sizeof(ProfilerData));
|
||||
for(U32 i = 0; i < ProfilerData::HashTableSize; i++)
|
||||
nextProfiler->mChildHash[i] = 0;
|
||||
|
||||
nextProfiler->mRoot = root;
|
||||
nextProfiler->mNextForRoot = root->mFirstProfilerData;
|
||||
root->mFirstProfilerData = nextProfiler;
|
||||
|
||||
nextProfiler->mNextProfilerData = mProfileList;
|
||||
mProfileList = nextProfiler;
|
||||
|
||||
nextProfiler->mNextHash = mCurrentProfilerData->mChildHash[index];
|
||||
mCurrentProfilerData->mChildHash[index] = nextProfiler;
|
||||
|
||||
nextProfiler->mParent = mCurrentProfilerData;
|
||||
nextProfiler->mNextSibling = mCurrentProfilerData->mFirstChild;
|
||||
mCurrentProfilerData->mFirstChild = nextProfiler;
|
||||
nextProfiler->mFirstChild = NULL;
|
||||
nextProfiler->mLastSeenProfiler = NULL;
|
||||
nextProfiler->mHash = root->mNameHash;
|
||||
nextProfiler->mInvokeCount = 0;
|
||||
nextProfiler->mTotalTime = 0;
|
||||
nextProfiler->mSubTime = 0;
|
||||
nextProfiler->mSubDepth = 0;
|
||||
}
|
||||
}
|
||||
root->mTotalInvokeCount++;
|
||||
nextProfiler->mInvokeCount++;
|
||||
startHighResolutionTimer(nextProfiler->mStartTime);
|
||||
mCurrentProfilerData->mLastSeenProfiler = nextProfiler;
|
||||
mCurrentProfilerData = nextProfiler;
|
||||
}
|
||||
|
||||
void Profiler::enable(bool enabled)
|
||||
{
|
||||
mNextEnable = enabled;
|
||||
}
|
||||
|
||||
void Profiler::dumpToConsole()
|
||||
{
|
||||
mDumpToConsole = true;
|
||||
mDumpToFile = false;
|
||||
mDumpFileName[0] = '\0';
|
||||
}
|
||||
|
||||
void Profiler::dumpToFile(const char* fileName)
|
||||
{
|
||||
AssertFatal(dStrlen(fileName) < DumpFileNameLength, "Error, dump filename too long");
|
||||
mDumpToFile = true;
|
||||
mDumpToConsole = false;
|
||||
dStrcpy(mDumpFileName, fileName);
|
||||
}
|
||||
|
||||
void Profiler::hashPop()
|
||||
{
|
||||
mStackDepth--;
|
||||
AssertFatal(mStackDepth >= 0, "Stack underflow in profiler. You may have mismatched PROFILE_START and PROFILE_ENDs");
|
||||
if(mEnabled)
|
||||
{
|
||||
if(mCurrentProfilerData->mSubDepth)
|
||||
{
|
||||
mCurrentProfilerData->mSubDepth--;
|
||||
return;
|
||||
}
|
||||
F64 fElapsed = endHighResolutionTimer(mCurrentProfilerData->mStartTime);
|
||||
mCurrentProfilerData->mTotalTime += fElapsed;
|
||||
mCurrentProfilerData->mParent->mSubTime += fElapsed; // mark it in the parent as well...
|
||||
mCurrentProfilerData->mRoot->mTotalTime += fElapsed;
|
||||
if(mCurrentProfilerData->mParent->mRoot)
|
||||
mCurrentProfilerData->mParent->mRoot->mSubTime += fElapsed; // mark it in the parent as well...
|
||||
mCurrentProfilerData = mCurrentProfilerData->mParent;
|
||||
}
|
||||
if(mStackDepth == 0)
|
||||
{
|
||||
// apply the next enable...
|
||||
if(mDumpToConsole || mDumpToFile)
|
||||
{
|
||||
dump();
|
||||
startHighResolutionTimer(mCurrentProfilerData->mStartTime);
|
||||
}
|
||||
if(!mEnabled && mNextEnable)
|
||||
startHighResolutionTimer(mCurrentProfilerData->mStartTime);
|
||||
mEnabled = mNextEnable;
|
||||
}
|
||||
}
|
||||
|
||||
static S32 QSORT_CALLBACK rootDataCompare(const void *s1, const void *s2)
|
||||
{
|
||||
const ProfilerRootData *r1 = *((ProfilerRootData **) s1);
|
||||
const ProfilerRootData *r2 = *((ProfilerRootData **) s2);
|
||||
return (r2->mTotalTime - r2->mSubTime) - (r1->mTotalTime - r1->mSubTime);
|
||||
}
|
||||
|
||||
static void profilerDataDumpRecurse(ProfilerData *data, char *buffer, U32 bufferLen, F64 totalTime)
|
||||
{
|
||||
// dump out this one:
|
||||
Con::printf("%7.3f %7.3f %8d %s%s",
|
||||
100 * data->mTotalTime / totalTime,
|
||||
100 * (data->mTotalTime - data->mSubTime) / totalTime,
|
||||
data->mInvokeCount,
|
||||
buffer,
|
||||
data->mRoot ? data->mRoot->mName : "ROOT" );
|
||||
data->mTotalTime = 0;
|
||||
data->mSubTime = 0;
|
||||
data->mInvokeCount = 0;
|
||||
|
||||
buffer[bufferLen] = ' ';
|
||||
buffer[bufferLen+1] = ' ';
|
||||
buffer[bufferLen+2] = 0;
|
||||
// sort data's children...
|
||||
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;
|
||||
}
|
||||
data->mFirstChild = list;
|
||||
while(list)
|
||||
{
|
||||
if(list->mInvokeCount)
|
||||
profilerDataDumpRecurse(list, buffer, bufferLen + 2, totalTime);
|
||||
list = list->mNextSibling;
|
||||
}
|
||||
buffer[bufferLen] = 0;
|
||||
}
|
||||
|
||||
static void profilerDataDumpRecurseFile(ProfilerData *data, char *buffer, U32 bufferLen, F64 totalTime, FileStream& fws)
|
||||
{
|
||||
char pbuffer[256];
|
||||
dSprintf(pbuffer, 255, "%7.3f %7.3f %8d %s%s\n",
|
||||
100 * data->mTotalTime / totalTime,
|
||||
100 * (data->mTotalTime - data->mSubTime) / totalTime,
|
||||
data->mInvokeCount,
|
||||
buffer,
|
||||
data->mRoot ? data->mRoot->mName : "ROOT" );
|
||||
fws.write(dStrlen(pbuffer), pbuffer);
|
||||
data->mTotalTime = 0;
|
||||
data->mSubTime = 0;
|
||||
data->mInvokeCount = 0;
|
||||
|
||||
buffer[bufferLen] = ' ';
|
||||
buffer[bufferLen+1] = ' ';
|
||||
buffer[bufferLen+2] = 0;
|
||||
// sort data's children...
|
||||
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;
|
||||
}
|
||||
data->mFirstChild = list;
|
||||
while(list)
|
||||
{
|
||||
if(list->mInvokeCount)
|
||||
profilerDataDumpRecurseFile(list, buffer, bufferLen + 2, totalTime, fws);
|
||||
list = list->mNextSibling;
|
||||
}
|
||||
buffer[bufferLen] = 0;
|
||||
}
|
||||
|
||||
void Profiler::dump()
|
||||
{
|
||||
bool enableSave = mEnabled;
|
||||
mEnabled = false;
|
||||
mStackDepth++;
|
||||
// may have some profiled calls... gotta turn em off.
|
||||
|
||||
Vector<ProfilerRootData *> rootVector;
|
||||
F64 totalTime = 0;
|
||||
for(ProfilerRootData *walk = ProfilerRootData::sRootList; walk; walk = walk->mNextRoot)
|
||||
{
|
||||
totalTime += walk->mTotalTime - walk->mSubTime;
|
||||
rootVector.push_back(walk);
|
||||
}
|
||||
dQsort((void *) &rootVector[0], rootVector.size(), sizeof(ProfilerRootData *), rootDataCompare);
|
||||
|
||||
|
||||
if (mDumpToConsole == true)
|
||||
{
|
||||
Con::printf("Profiler Data Dump:");
|
||||
Con::printf("Ordered by non-sub total time -");
|
||||
Con::printf("%%NSTime %% Time Invoke # Name");
|
||||
for(U32 i = 0; i < rootVector.size(); i++)
|
||||
{
|
||||
Con::printf("%7.3f %7.3f %8d %s",
|
||||
100 * (rootVector[i]->mTotalTime - rootVector[i]->mSubTime) / totalTime,
|
||||
100 * rootVector[i]->mTotalTime / totalTime,
|
||||
rootVector[i]->mTotalInvokeCount,
|
||||
rootVector[i]->mName);
|
||||
rootVector[i]->mTotalInvokeCount = 0;
|
||||
rootVector[i]->mTotalTime = 0;
|
||||
rootVector[i]->mSubTime = 0;
|
||||
}
|
||||
Con::printf("");
|
||||
Con::printf("Ordered by stack trace total time -");
|
||||
Con::printf("%% Time %% NSTime Invoke # Name");
|
||||
|
||||
U32 depth = 0;
|
||||
mCurrentProfilerData->mTotalTime = endHighResolutionTimer(mCurrentProfilerData->mStartTime);
|
||||
|
||||
char depthBuffer[MaxStackDepth * 2 + 1];
|
||||
depthBuffer[0] = 0;
|
||||
profilerDataDumpRecurse(mCurrentProfilerData, depthBuffer, 0, totalTime);
|
||||
mEnabled = enableSave;
|
||||
mStackDepth--;
|
||||
}
|
||||
else if (mDumpToFile == true && mDumpFileName[0] != '\0')
|
||||
{
|
||||
FileStream fws;
|
||||
bool success = fws.open(mDumpFileName, FileStream::Write);
|
||||
AssertFatal(success, "Oh, fuck.");
|
||||
char buffer[1024];
|
||||
|
||||
dStrcpy(buffer, "Profiler Data Dump:\n");
|
||||
fws.write(dStrlen(buffer), buffer);
|
||||
dStrcpy(buffer, "Ordered by non-sub total time -\n");
|
||||
fws.write(dStrlen(buffer), buffer);
|
||||
dStrcpy(buffer, "%%NSTime %% Time Invoke # Name\n");
|
||||
fws.write(dStrlen(buffer), buffer);
|
||||
|
||||
for(U32 i = 0; i < rootVector.size(); i++)
|
||||
{
|
||||
dSprintf(buffer, 1023, "%7.3f %7.3f %8d %s\n",
|
||||
100 * (rootVector[i]->mTotalTime - rootVector[i]->mSubTime) / totalTime,
|
||||
100 * rootVector[i]->mTotalTime / totalTime,
|
||||
rootVector[i]->mTotalInvokeCount,
|
||||
rootVector[i]->mName);
|
||||
fws.write(dStrlen(buffer), buffer);
|
||||
|
||||
rootVector[i]->mTotalInvokeCount = 0;
|
||||
rootVector[i]->mTotalTime = 0;
|
||||
rootVector[i]->mSubTime = 0;
|
||||
}
|
||||
dStrcpy(buffer, "\nOrdered by non-sub total time -\n");
|
||||
fws.write(dStrlen(buffer), buffer);
|
||||
dStrcpy(buffer, "%%NSTime %% Time Invoke # Name\n");
|
||||
fws.write(dStrlen(buffer), buffer);
|
||||
|
||||
U32 depth = 0;
|
||||
mCurrentProfilerData->mTotalTime = endHighResolutionTimer(mCurrentProfilerData->mStartTime);
|
||||
|
||||
char depthBuffer[MaxStackDepth * 2 + 1];
|
||||
depthBuffer[0] = 0;
|
||||
profilerDataDumpRecurseFile(mCurrentProfilerData, depthBuffer, 0, totalTime, fws);
|
||||
mEnabled = enableSave;
|
||||
mStackDepth--;
|
||||
|
||||
fws.close();
|
||||
}
|
||||
|
||||
mDumpToConsole = false;
|
||||
mDumpToFile = false;
|
||||
mDumpFileName[0] = '\0';
|
||||
}
|
||||
|
||||
void Profiler::enableMarker(const char *marker, bool enable)
|
||||
{
|
||||
reset();
|
||||
U32 markerLen = dStrlen(marker);
|
||||
if(markerLen == 0)
|
||||
return;
|
||||
bool sn = marker[markerLen - 1] == '*';
|
||||
for(ProfilerRootData *data = ProfilerRootData::sRootList; data; data = data->mNextRoot)
|
||||
{
|
||||
if(sn)
|
||||
{
|
||||
if(!dStrncmp(marker, data->mName, markerLen - 1))
|
||||
data->mEnabled = enable;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!dStrcmp(marker, data->mName))
|
||||
data->mEnabled = enable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConsoleFunction(profilerMarkerEnable, void, 3, 3, "profilerEnable(markerName, true/false);")
|
||||
{
|
||||
argc;
|
||||
if(gProfiler)
|
||||
gProfiler->enableMarker(argv[1], dAtob(argv[2]));
|
||||
}
|
||||
|
||||
ConsoleFunction(profilerEnable, void, 2, 2, "profilerEnable(true/false);")
|
||||
{
|
||||
argc;
|
||||
if(gProfiler)
|
||||
gProfiler->enable(dAtob(argv[1]));
|
||||
}
|
||||
|
||||
ConsoleFunction(profilerDump, void, 1, 1, "profilerDump();")
|
||||
{
|
||||
argc; argv;
|
||||
if(gProfiler)
|
||||
gProfiler->dumpToConsole();
|
||||
}
|
||||
|
||||
ConsoleFunction(profilerDumpToFile, void, 2, 2, "profilerDumpToFile(filename);")
|
||||
{
|
||||
argc; argv;
|
||||
if(gProfiler)
|
||||
gProfiler->dumpToFile(argv[1]);
|
||||
}
|
||||
|
||||
#endif
|
||||
103
platform/profiler.h
Normal file
103
platform/profiler.h
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PROFILER_H_
|
||||
#define _PROFILER_H_
|
||||
|
||||
#ifdef ENABLE_PROFILER
|
||||
|
||||
struct ProfilerData;
|
||||
struct ProfilerRootData;
|
||||
|
||||
class Profiler
|
||||
{
|
||||
enum {
|
||||
MaxStackDepth = 256,
|
||||
DumpFileNameLength = 256
|
||||
};
|
||||
U32 mCurrentHash;
|
||||
|
||||
ProfilerData *mCurrentProfilerData;
|
||||
ProfilerData *mProfileList;
|
||||
ProfilerData *mRootProfilerData;
|
||||
|
||||
bool mEnabled;
|
||||
S32 mStackDepth;
|
||||
bool mNextEnable;
|
||||
U32 mMaxStackDepth;
|
||||
bool mDumpToConsole;
|
||||
bool mDumpToFile;
|
||||
char mDumpFileName[DumpFileNameLength];
|
||||
void dump();
|
||||
void validate();
|
||||
public:
|
||||
Profiler();
|
||||
~Profiler();
|
||||
|
||||
void reset();
|
||||
void dumpToConsole();
|
||||
void dumpToFile(const char*);
|
||||
void enable(bool enabled);
|
||||
void hashPush(ProfilerRootData *data);
|
||||
void hashPop();
|
||||
void enableMarker(const char *marker, bool enabled);
|
||||
};
|
||||
|
||||
extern Profiler *gProfiler;
|
||||
|
||||
struct ProfilerRootData
|
||||
{
|
||||
const char *mName;
|
||||
U32 mNameHash;
|
||||
ProfilerData *mFirstProfilerData;
|
||||
ProfilerRootData *mNextRoot;
|
||||
F64 mTotalTime;
|
||||
F64 mSubTime;
|
||||
U32 mTotalInvokeCount;
|
||||
bool mEnabled;
|
||||
|
||||
static ProfilerRootData *sRootList;
|
||||
|
||||
ProfilerRootData(const char *name);
|
||||
};
|
||||
|
||||
struct ProfilerData
|
||||
{
|
||||
ProfilerRootData *mRoot; // link to root node.
|
||||
ProfilerData *mNextForRoot; // links together all ProfilerData's for a particular root
|
||||
ProfilerData *mNextProfilerData; // links all the profilerDatas
|
||||
ProfilerData *mNextHash;
|
||||
ProfilerData *mParent;
|
||||
ProfilerData *mNextSibling;
|
||||
ProfilerData *mFirstChild;
|
||||
enum {
|
||||
HashTableSize = 32,
|
||||
};
|
||||
ProfilerData *mChildHash[HashTableSize];
|
||||
ProfilerData *mLastSeenProfiler;
|
||||
|
||||
U32 mHash;
|
||||
U32 mSubDepth;
|
||||
U32 mInvokeCount;
|
||||
U32 mStartTime[2];
|
||||
F64 mTotalTime;
|
||||
F64 mSubTime;
|
||||
};
|
||||
|
||||
|
||||
#define PROFILE_START(name) \
|
||||
static ProfilerRootData pdata##name##obj (#name); \
|
||||
if(gProfiler) gProfiler->hashPush(& pdata##name##obj )
|
||||
|
||||
#define PROFILE_END() if(gProfiler) gProfiler->hashPop()
|
||||
|
||||
#else
|
||||
#define PROFILE_START(x)
|
||||
#define PROFILE_END()
|
||||
#endif
|
||||
|
||||
#endif
|
||||
153
platform/types.h
Normal file
153
platform/types.h
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _TYPES_H_
|
||||
#define _TYPES_H_
|
||||
|
||||
|
||||
|
||||
#ifdef __POWERPC__
|
||||
#ifndef _TYPESPPC_H_
|
||||
#include "Platform/typesPPC.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) || defined(WIN32)
|
||||
#ifndef _TYPESWIN32_H_
|
||||
#include "Platform/typesWin32.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __linux
|
||||
#ifndef _TYPESLINUX_H_
|
||||
#include "Platform/typesLinux.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
//-------------------------------------- A couple of all-around useful inlines and
|
||||
// globals
|
||||
//
|
||||
U32 getNextPow2(U32 io_num);
|
||||
U32 getBinLog2(U32 io_num);
|
||||
|
||||
inline bool isPow2(const U32 in_num)
|
||||
{
|
||||
return (in_num == getNextPow2(in_num));
|
||||
}
|
||||
|
||||
inline U16 endianSwap(const U16 in_swap)
|
||||
{
|
||||
return U16(((in_swap >> 8) & 0x00ff) |
|
||||
((in_swap << 8) & 0xff00));
|
||||
}
|
||||
|
||||
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---
|
||||
|
||||
inline U32 getMin(U32 a, U32 b)
|
||||
{
|
||||
return a>b ? b : a;
|
||||
}
|
||||
|
||||
inline U16 getMin(U16 a, U16 b)
|
||||
{
|
||||
return a>b ? b : a;
|
||||
}
|
||||
|
||||
inline U8 getMin(U8 a, U8 b)
|
||||
{
|
||||
return a>b ? b : a;
|
||||
}
|
||||
|
||||
inline S32 getMin(S32 a, S32 b)
|
||||
{
|
||||
return a>b ? b : a;
|
||||
}
|
||||
|
||||
inline S16 getMin(S16 a, S16 b)
|
||||
{
|
||||
return a>b ? b : a;
|
||||
}
|
||||
|
||||
inline S8 getMin(S8 a, S8 b)
|
||||
{
|
||||
return a>b ? b : a;
|
||||
}
|
||||
|
||||
inline float getMin(float a, float b)
|
||||
{
|
||||
return a>b ? b : a;
|
||||
}
|
||||
|
||||
inline double getMin(double a, double b)
|
||||
{
|
||||
return a>b ? b : a;
|
||||
}
|
||||
|
||||
inline U32 getMax(U32 a, U32 b)
|
||||
{
|
||||
return a>b ? a : b;
|
||||
}
|
||||
|
||||
inline U16 getMax(U16 a, U16 b)
|
||||
{
|
||||
return a>b ? a : b;
|
||||
}
|
||||
|
||||
inline U8 getMax(U8 a, U8 b)
|
||||
{
|
||||
return a>b ? a : b;
|
||||
}
|
||||
|
||||
inline S32 getMax(S32 a, S32 b)
|
||||
{
|
||||
return a>b ? a : b;
|
||||
}
|
||||
|
||||
inline S16 getMax(S16 a, S16 b)
|
||||
{
|
||||
return a>b ? a : b;
|
||||
}
|
||||
|
||||
inline S8 getMax(S8 a, S8 b)
|
||||
{
|
||||
return a>b ? a : b;
|
||||
}
|
||||
|
||||
inline float getMax(float a, float b)
|
||||
{
|
||||
return a>b ? 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(U8(ch0)) << 0) | \
|
||||
(U32(U8(ch1)) << 8) | \
|
||||
(U32(U8(ch2)) << 16) | \
|
||||
(U32(U8(ch3)) << 24))
|
||||
|
||||
#define BIT(x) (1 << (x))
|
||||
|
||||
#endif //_NTYPES_H_
|
||||
63
platform/typesLinux.h
Normal file
63
platform/typesLinux.h
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _TYPESLINUX_H_
|
||||
#define _TYPESLINUX_H_
|
||||
|
||||
#include <time.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 time_t 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);
|
||||
|
||||
#endif
|
||||
81
platform/typesPPC.h
Normal file
81
platform/typesPPC.h
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _TYPESPPC_H_
|
||||
#define _TYPESPPC_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;
|
||||
|
||||
struct FileTime
|
||||
{
|
||||
U64 time; // The date and time, specified in seconds since midnight, January 1, 1904.
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//-------------------------------------- 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);
|
||||
|
||||
|
||||
#endif //_NTYPES_H_
|
||||
98
platform/typesWin32.h
Normal file
98
platform/typesWin32.h
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, 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
|
||||
|
||||
|
||||
#define FN_CDECL __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;
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
typedef signed __int64 S64;
|
||||
typedef unsigned __int64 U64;
|
||||
#elif defined(__MWERKS__) // This has to go b4 MSC_VER since CodeWarrior defines MSC_VER too
|
||||
typedef signed long long S64;
|
||||
typedef unsigned long long U64;
|
||||
#elif defined(_MSC_VER)
|
||||
typedef signed _int64 S64;
|
||||
typedef unsigned _int64 U64;
|
||||
#pragma warning(disable: 4291) // disable warning caused by memory layer...
|
||||
#else
|
||||
typedef signed long long S64;
|
||||
typedef unsigned long long U64;
|
||||
#endif
|
||||
|
||||
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 int dsize_t;
|
||||
|
||||
typedef const char* StringTableEntry;
|
||||
|
||||
struct FileTime
|
||||
{
|
||||
U32 v1;
|
||||
U32 v2;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//-------------------------------------- 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);
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define for if(true) for
|
||||
#endif
|
||||
|
||||
|
||||
#endif //_NTYPES_H_
|
||||
65
platform/typesX86UNIX.h
Normal file
65
platform/typesX86UNIX.h
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue