mirror of
https://github.com/tribes2/engine.git
synced 2026-03-07 06:20:30 +00:00
t2 engine svn checkout
This commit is contained in:
commit
ff569bd2ae
988 changed files with 394180 additions and 0 deletions
115
platformPPC/platformGL.h
Normal file
115
platformPPC/platformGL.h
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORMGL_H_
|
||||
#define _PLATFORMGL_H_
|
||||
|
||||
#include <gl.h>
|
||||
#include <glu.h>
|
||||
|
||||
|
||||
bool QGL_EXT_Init();
|
||||
|
||||
|
||||
struct GLState
|
||||
{
|
||||
bool suppARBMultitexture;
|
||||
bool suppPackedPixels;
|
||||
bool suppLockedArrays;
|
||||
bool suppTextureEnvCombine;
|
||||
bool suppVertexArrayRange;
|
||||
bool suppFogCoord;
|
||||
bool suppEdgeClamp;
|
||||
};
|
||||
|
||||
extern GLState gGLState;
|
||||
#define UNSIGNED_SHORT_5_6_5 0x8363
|
||||
#define UNSIGNED_SHORT_5_6_5_REV 0x8364
|
||||
|
||||
extern bool gOpenGLDisableCVA;
|
||||
extern bool gOpenGLDisableTEC;
|
||||
extern bool gOpenGLDisableARBMT;
|
||||
extern bool gOpenGLDisableFC;
|
||||
|
||||
inline bool dglDoesSupportCompiledVertexArray()
|
||||
{
|
||||
return gGLState.suppLockedArrays && (gOpenGLDisableCVA == false);
|
||||
}
|
||||
|
||||
inline bool dglDoesSupportTextureEnvCombine()
|
||||
{
|
||||
return gGLState.suppTextureEnvCombine && (gOpenGLDisableTEC == false);
|
||||
}
|
||||
|
||||
inline bool dglDoesSupportARBMultitexture()
|
||||
{
|
||||
return gGLState.suppARBMultitexture && (gOpenGLDisableARBMT == false);
|
||||
}
|
||||
|
||||
inline bool dglDoesSupportVertexArrayRange()
|
||||
{
|
||||
return gGLState.suppVertexArrayRange;
|
||||
}
|
||||
|
||||
inline bool dglDoesSupportFogCoord()
|
||||
{
|
||||
return gGLState.suppFogCoord && (gOpenGLDisableFC == false);
|
||||
}
|
||||
|
||||
inline bool dglDoesSupportEdgeClamp()
|
||||
{
|
||||
return gGLState.suppEdgeClamp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// until Apple exposes some extensions we'll need to stub them here
|
||||
//
|
||||
|
||||
/* EXT_combine */
|
||||
#define GL_COMBINE_EXT 0x8570
|
||||
#define GL_COMBINE_RGB_EXT 0x8571
|
||||
#define GL_COMBINE_ALPHA_EXT 0x8572
|
||||
#define GL_SOURCE0_RGB_EXT 0x8580
|
||||
#define GL_SOURCE1_RGB_EXT 0x8581
|
||||
#define GL_SOURCE2_RGB_EXT 0x8582
|
||||
#define GL_SOURCE0_ALPHA_EXT 0x8588
|
||||
#define GL_SOURCE1_ALPHA_EXT 0x8589
|
||||
#define GL_SOURCE2_ALPHA_EXT 0x858A
|
||||
#define GL_OPERAND0_RGB_EXT 0x8590
|
||||
#define GL_OPERAND1_RGB_EXT 0x8591
|
||||
#define GL_OPERAND2_RGB_EXT 0x8592
|
||||
#define GL_OPERAND0_ALPHA_EXT 0x8598
|
||||
#define GL_OPERAND1_ALPHA_EXT 0x8599
|
||||
#define GL_OPERAND2_ALPHA_EXT 0x859A
|
||||
#define GL_RGB_SCALE_EXT 0x8573
|
||||
#define GL_ADD_SIGNED_EXT 0x8574
|
||||
#define GL_INTERPOLATE_EXT 0x8575
|
||||
#define GL_CONSTANT_EXT 0x8576
|
||||
#define GL_PRIMARY_COLOR_EXT 0x8577
|
||||
#define GL_PREVIOUS_EXT 0x8578
|
||||
|
||||
/* EXT_fog_coord */
|
||||
#define GL_FOG_COORDINATE_SOURCE_EXT -1
|
||||
#define GL_FOG_COORDINATE_EXT -1
|
||||
#define GL_FRAGMENT_DEPTH_EXT -1
|
||||
#define GL_FOG_COORDINATE_ARRAY_EXT -1
|
||||
|
||||
/* EXT_texture_edge_clamp */
|
||||
#define GL_CLAMP_TO_EDGE_EXT 0x812F
|
||||
|
||||
// stubbed unsupported extensions
|
||||
inline void glFogCoordfEXT(GLfloat ) {}
|
||||
inline void glFogCoordPointerEXT(GLenum, GLsizei, void *) {}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // _PLATFORMGL_H_
|
||||
69
platformPPC/platformPPC.h
Normal file
69
platformPPC/platformPPC.h
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PLATFORMPPC_H_
|
||||
#define _PLATFORMPPC_H_
|
||||
|
||||
|
||||
//#if defined(__MWERKS__)
|
||||
//# include <ansi_prefix.win32.h>
|
||||
//#else
|
||||
//# include <stdio.h>
|
||||
//# include <string.h>
|
||||
//#endif
|
||||
|
||||
#include <macwindows.h>
|
||||
#include <Files.h>
|
||||
#include <agl.h>
|
||||
#ifndef _PLATFORM_H_
|
||||
#include "Platform/platform.h"
|
||||
#endif
|
||||
#ifndef _PPCUTILS_H_
|
||||
#include "PlatformPPC/ppcUtils.h"
|
||||
#endif
|
||||
|
||||
struct PPCPlatState
|
||||
{
|
||||
GDHandle hDisplay;
|
||||
WindowPtr appWindow;
|
||||
char appWindowTitle[255];
|
||||
bool quit;
|
||||
|
||||
AGLPixelFormat fmt;
|
||||
AGLContext ctx;
|
||||
|
||||
S32 volRefNum; // current working volume/drive reference number
|
||||
S32 dirID; // current working directory id
|
||||
|
||||
// FILE *log_fp;
|
||||
// HINSTANCE hinstOpenGL;
|
||||
// HINSTANCE hinstGLU;
|
||||
// HWND appWindow;
|
||||
// HDC appDC;
|
||||
// HINSTANCE appInstance;
|
||||
// HGLRC hGLRC;
|
||||
|
||||
S32 desktopBitsPixel;
|
||||
S32 desktopWidth;
|
||||
S32 desktopHeight;
|
||||
U32 currentTime;
|
||||
|
||||
PPCPlatState();
|
||||
};
|
||||
|
||||
U32 GetMilliseconds();
|
||||
|
||||
extern PPCPlatState ppcState;
|
||||
|
||||
U8* str2p(const char *str);
|
||||
U8* str2p(const char *str, U8 *dst_p);
|
||||
|
||||
char* p2str(U8 *p);
|
||||
char* p2str(U8 *p, char *dst_str);
|
||||
|
||||
|
||||
#endif //_PLATFORMPPC_H_
|
||||
28
platformPPC/ppcAudio.cc
Normal file
28
platformPPC/ppcAudio.cc
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "Platform/platformAudio.h"
|
||||
//#include "winAudioDSound3.h"
|
||||
//#include "winAudioDSound7.h"
|
||||
|
||||
namespace Audio
|
||||
{
|
||||
|
||||
//void installPlaybackDevice( PlaybackDevice *dev );
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
void detect()
|
||||
{
|
||||
// install devices in order of increasing audio quality
|
||||
//installPlaybackDevice( DSound3SSDevice::create() );
|
||||
//installPlaybackDevice( DSound7HHDevice::create() );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
} // End namespace Audio
|
||||
34
platformPPC/ppcCPUInfo.cc
Normal file
34
platformPPC/ppcCPUInfo.cc
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "PlatformPPC/platformPPC.h"
|
||||
#include "console/console.h"
|
||||
#include "Core/stringTable.h"
|
||||
#include <math.h>
|
||||
|
||||
Platform::SystemInfo_struct Platform::SystemInfo;
|
||||
|
||||
|
||||
void Processor::init()
|
||||
{
|
||||
// Reference:
|
||||
// www.cyrix.com
|
||||
// www.amd.com
|
||||
// www.intel.com
|
||||
// http://developer.intel.com/design/PentiumII/manuals/24512701.pdf
|
||||
Platform::SystemInfo.processor.type = CPU_PowerPC_G3;
|
||||
Platform::SystemInfo.processor.name = StringTable->insert("Unknown PPC Compatible");
|
||||
Platform::SystemInfo.processor.mhz = 0;
|
||||
Platform::SystemInfo.processor.properties = CPU_PROP_C;
|
||||
|
||||
|
||||
Con::printf("Processor Init:");
|
||||
Con::printf(" %s, %d Mhz", Platform::SystemInfo.processor.name, Platform::SystemInfo.processor.mhz);
|
||||
if (Platform::SystemInfo.processor.properties & CPU_PROP_FPU)
|
||||
Con::printf(" FPU detected");
|
||||
Con::printf(" ");
|
||||
}
|
||||
231
platformPPC/ppcConsole.cc
Normal file
231
platformPPC/ppcConsole.cc
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "PlatformPPC/platformPPC.h"
|
||||
#include "PlatformPPC/ppcConsole.h"
|
||||
#include "Platform/event.h"
|
||||
|
||||
WinConsole *WindowsConsole = NULL;
|
||||
|
||||
static void consoleEnableCallback(const char *, const char *enabled)
|
||||
{
|
||||
WindowsConsole->enable(dAtob(enabled));
|
||||
}
|
||||
|
||||
void WinConsole::create()
|
||||
{
|
||||
WindowsConsole = new WinConsole();
|
||||
}
|
||||
|
||||
void WinConsole::destroy()
|
||||
{
|
||||
delete WindowsConsole;
|
||||
WindowsConsole = NULL;
|
||||
}
|
||||
|
||||
void WinConsole::enable(bool enabled)
|
||||
{
|
||||
winConsoleEnabled = enabled;
|
||||
// if(winConsoleEnabled)
|
||||
// {
|
||||
// AllocConsole();
|
||||
// const char *title = Con::getVariable("Con::WindowTitle");
|
||||
// if (title && *title)
|
||||
// SetConsoleTitle(title);
|
||||
// stdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
// stdIn = GetStdHandle(STD_INPUT_HANDLE);
|
||||
// stdErr = GetStdHandle(STD_ERROR_HANDLE);
|
||||
//
|
||||
// printf("%s", Con::getVariable("Con::Prompt"));
|
||||
// }
|
||||
}
|
||||
|
||||
WinConsole::WinConsole()
|
||||
{
|
||||
// for (S32 iIndex = 0; iIndex < MAX_CMDS; iIndex ++)
|
||||
// rgCmds[iIndex][0] = '\0';
|
||||
//
|
||||
// iCmdIndex = 0;
|
||||
// winConsoleEnabled = false;
|
||||
// Con::addConsumer(this);
|
||||
// inpos = 0;
|
||||
// lineOutput = false;
|
||||
// Con::addVariable("WinConsoleEnabled", consoleEnableCallback, "false");
|
||||
}
|
||||
|
||||
void WinConsole::printf(const char *s, ...)
|
||||
{
|
||||
s;
|
||||
// static char buffer[512];
|
||||
// DWORD bytes;
|
||||
// va_list args;
|
||||
// va_start(args, s);
|
||||
// vsprintf(buffer, s, args);
|
||||
// WriteFile(stdOut, buffer, strlen(buffer), &bytes, NULL);
|
||||
// FlushFileBuffers( stdOut );
|
||||
}
|
||||
|
||||
void WinConsole::processConsoleLine(const char *consoleLine)
|
||||
{
|
||||
consoleLine;
|
||||
// if(winConsoleEnabled)
|
||||
// {
|
||||
// inbuf[inpos] = 0;
|
||||
// if(lineOutput)
|
||||
// printf("%s\n", consoleLine);
|
||||
// else
|
||||
// printf("%c%s\n%s%s", '\r', consoleLine, Con::getVariable("Con::Prompt"), inbuf);
|
||||
// }
|
||||
}
|
||||
|
||||
void WinConsole::process()
|
||||
{
|
||||
// if(winConsoleEnabled)
|
||||
// {
|
||||
// DWORD numEvents;
|
||||
// GetNumberOfConsoleInputEvents(stdIn, &numEvents);
|
||||
// if(numEvents)
|
||||
// {
|
||||
// INPUT_RECORD rec[20];
|
||||
// char outbuf[256];
|
||||
// S32 outpos = 0;
|
||||
//
|
||||
// ReadConsoleInput(stdIn, rec, 20, &numEvents);
|
||||
// DWORD i;
|
||||
// for(i = 0; i < numEvents; i++)
|
||||
// {
|
||||
// if(rec[i].EventType == KEY_EVENT)
|
||||
// {
|
||||
// KEY_EVENT_RECORD *ke = &(rec[i].Event.KeyEvent);
|
||||
// if(ke->bKeyDown)
|
||||
// {
|
||||
// switch (ke->uChar.AsciiChar)
|
||||
// {
|
||||
// // If no ASCII char, check if it's a handled virtual key
|
||||
// case 0:
|
||||
// switch (ke->wVirtualKeyCode)
|
||||
// {
|
||||
// // UP ARROW
|
||||
// case 0x26 :
|
||||
// // Go to the previous command in the cyclic array
|
||||
// if ((-- iCmdIndex) < 0)
|
||||
// iCmdIndex = MAX_CMDS - 1;
|
||||
//
|
||||
// // If this command isn't empty ...
|
||||
// if (rgCmds[iCmdIndex][0] != '\0')
|
||||
// {
|
||||
// // Obliterate current displayed text
|
||||
// for (S32 i = outpos = 0; i < inpos; i ++)
|
||||
// {
|
||||
// outbuf[outpos ++] = '\b';
|
||||
// outbuf[outpos ++] = ' ';
|
||||
// outbuf[outpos ++] = '\b';
|
||||
// }
|
||||
//
|
||||
// // Copy command into command and display buffers
|
||||
// for (inpos = 0; inpos < (S32)strlen(rgCmds[iCmdIndex]); inpos ++, outpos ++)
|
||||
// {
|
||||
// outbuf[outpos] = rgCmds[iCmdIndex][inpos];
|
||||
// inbuf [inpos ] = rgCmds[iCmdIndex][inpos];
|
||||
// }
|
||||
// }
|
||||
// // If previous is empty, stay on current command
|
||||
// else if ((++ iCmdIndex) >= MAX_CMDS)
|
||||
// {
|
||||
// iCmdIndex = 0;
|
||||
// }
|
||||
//
|
||||
// break;
|
||||
//
|
||||
// // DOWN ARROW
|
||||
// case 0x28 : {
|
||||
// // Go to the next command in the command array, if
|
||||
// // it isn't empty
|
||||
// if (rgCmds[iCmdIndex][0] != '\0' && (++ iCmdIndex) >= MAX_CMDS)
|
||||
// iCmdIndex = 0;
|
||||
//
|
||||
// // Obliterate current displayed text
|
||||
// for (S32 i = outpos = 0; i < inpos; i ++)
|
||||
// {
|
||||
// outbuf[outpos ++] = '\b';
|
||||
// outbuf[outpos ++] = ' ';
|
||||
// outbuf[outpos ++] = '\b';
|
||||
// }
|
||||
//
|
||||
// // Copy command into command and display buffers
|
||||
// for (inpos = 0; inpos < (S32)strlen(rgCmds[iCmdIndex]); inpos ++, outpos ++)
|
||||
// {
|
||||
// outbuf[outpos] = rgCmds[iCmdIndex][inpos];
|
||||
// inbuf [inpos ] = rgCmds[iCmdIndex][inpos];
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// // LEFT ARROW
|
||||
// case 0x25 :
|
||||
// break;
|
||||
//
|
||||
// // RIGHT ARROW
|
||||
// case 0x27 :
|
||||
// break;
|
||||
//
|
||||
// default :
|
||||
// break;
|
||||
// }
|
||||
// break;
|
||||
// case '\b':
|
||||
// if(inpos > 0)
|
||||
// {
|
||||
// outbuf[outpos++] = '\b';
|
||||
// outbuf[outpos++] = ' ';
|
||||
// outbuf[outpos++] = '\b';
|
||||
// inpos--;
|
||||
// }
|
||||
// break;
|
||||
// case '\n':
|
||||
// case '\r':
|
||||
// outbuf[outpos++] = '\r';
|
||||
// outbuf[outpos++] = '\n';
|
||||
//
|
||||
// inbuf[inpos] = 0;
|
||||
// outbuf[outpos] = 0;
|
||||
// printf("%s", outbuf);
|
||||
//
|
||||
// S32 eventSize;
|
||||
// eventSize = ConsoleEventHeaderSize;
|
||||
//
|
||||
// dStrcpy(postEvent.data, inbuf);
|
||||
// postEvent.size = eventSize + dStrlen(inbuf) + 1;
|
||||
// GamePostEvent(postEvent);
|
||||
//
|
||||
// // If we've gone off the end of our array, wrap
|
||||
// // back to the beginning
|
||||
// if (iCmdIndex >= MAX_CMDS)
|
||||
// iCmdIndex %= MAX_CMDS;
|
||||
//
|
||||
// // Put the new command into the array
|
||||
// strcpy(rgCmds[iCmdIndex ++], inbuf);
|
||||
//
|
||||
// printf("%s", Con::getVariable("Con::Prompt"));
|
||||
// inpos = outpos = 0;
|
||||
// break;
|
||||
// default:
|
||||
// inbuf[inpos++] = ke->uChar.AsciiChar;
|
||||
// outbuf[outpos++] = ke->uChar.AsciiChar;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if(outpos)
|
||||
// {
|
||||
// outbuf[outpos] = 0;
|
||||
// printf("%s", outbuf);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
48
platformPPC/ppcConsole.h
Normal file
48
platformPPC/ppcConsole.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PCCCONSOLE_H_
|
||||
#define _PCCCONSOLE_H_
|
||||
|
||||
#define MAX_CMDS 10
|
||||
#ifndef _CONSOLE_H_
|
||||
#include "console/console.h"
|
||||
#endif
|
||||
#ifndef _EVENT_H_
|
||||
#include "Platform/event.h"
|
||||
#endif
|
||||
|
||||
class WinConsole
|
||||
{
|
||||
bool winConsoleEnabled;
|
||||
|
||||
// HANDLE stdOut;
|
||||
// HANDLE stdIn;
|
||||
// HANDLE stdErr;
|
||||
ConsoleEvent postEvent;
|
||||
char inbuf[512];
|
||||
S32 inpos;
|
||||
bool lineOutput;
|
||||
char curTabComplete[512];
|
||||
S32 tabCompleteStart;
|
||||
char rgCmds[MAX_CMDS][512];
|
||||
S32 iCmdIndex;
|
||||
|
||||
void printf(const char *s, ...);
|
||||
|
||||
public:
|
||||
WinConsole();
|
||||
void process();
|
||||
void enable(bool);
|
||||
void processConsoleLine(const char *consoleLine);
|
||||
static void create();
|
||||
static void destroy();
|
||||
};
|
||||
|
||||
extern WinConsole *WindowsConsole;
|
||||
|
||||
#endif
|
||||
636
platformPPC/ppcFileio.cc
Normal file
636
platformPPC/ppcFileio.cc
Normal file
|
|
@ -0,0 +1,636 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "PlatformPPC/platformPPC.h"
|
||||
#include "Core/fileio.h"
|
||||
#include "Core/tVector.h"
|
||||
#include "Core/stringTable.h"
|
||||
#include "console/console.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
//-------------------------------------- Helper Functions
|
||||
static void forwardslash(char *str)
|
||||
{
|
||||
while(*str)
|
||||
{
|
||||
if(*str == '\\')
|
||||
*str = ':';
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
static void toHostFilename(const char *str, char *dst)
|
||||
{
|
||||
*dst++ = ':';
|
||||
while(*str)
|
||||
{
|
||||
if(*str == '\\' || *str == '/')
|
||||
*dst++ = ':';
|
||||
else
|
||||
*dst++ = *str;
|
||||
str++;
|
||||
}
|
||||
*dst = 0;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructors & Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// After construction, the currentStatus will be Closed and the capabilities
|
||||
// will be 0.
|
||||
//-----------------------------------------------------------------------------
|
||||
File::File()
|
||||
: currentStatus(Closed), capability(0)
|
||||
{
|
||||
handle = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// insert a copy constructor here... (currently disabled)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
File::~File()
|
||||
{
|
||||
close();
|
||||
handle = NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Open a file in the mode specified by openMode (Read, Write, or ReadWrite).
|
||||
// Truncate the file if the mode is either Write or ReadWrite and truncate is
|
||||
// true.
|
||||
//
|
||||
// Sets capability appropriate to the openMode.
|
||||
// Returns the currentStatus of the file.
|
||||
//-----------------------------------------------------------------------------
|
||||
File::Status File::open(const char *filename, const AccessMode openMode)
|
||||
{
|
||||
char hostFilename[256];
|
||||
|
||||
AssertFatal(dStrlen(filename) <= 255, "File::open: Max Mac file length exceeded. MAX=255");
|
||||
AssertFatal(NULL != filename, "File::open: NULL filename");
|
||||
AssertWarn(NULL == handle, "File::open: handle already valid");
|
||||
|
||||
toHostFilename(filename, hostFilename);
|
||||
|
||||
// Close the file if it was already open...
|
||||
if (Closed != currentStatus)
|
||||
close();
|
||||
|
||||
// create the appropriate type of file...
|
||||
switch (openMode)
|
||||
{
|
||||
case Read:
|
||||
handle = (void *)fopen(hostFilename, "rb");
|
||||
break;
|
||||
case Write:
|
||||
handle = (void *)fopen(hostFilename, "wb");
|
||||
break;
|
||||
case ReadWrite:
|
||||
handle = (void *)fopen(hostFilename, "ab+");
|
||||
break;
|
||||
default:
|
||||
AssertFatal(false, "File::open: bad access mode"); // impossible
|
||||
}
|
||||
|
||||
if (handle == NULL) // handle not created successfully
|
||||
return setStatus();
|
||||
else
|
||||
{
|
||||
// successfully created file, so set the file capabilities...
|
||||
switch (openMode)
|
||||
{
|
||||
case Read:
|
||||
capability = U32(FileRead);
|
||||
break;
|
||||
case Write:
|
||||
capability = U32(FileWrite);
|
||||
break;
|
||||
case ReadWrite:
|
||||
capability = U32(FileRead) | U32(FileWrite);
|
||||
break;
|
||||
default:
|
||||
AssertFatal(false, "File::open: bad access mode");
|
||||
}
|
||||
|
||||
if (openMode == ReadWrite)
|
||||
setPosition(0);
|
||||
|
||||
return currentStatus = Ok; // success!
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Get the current position of the file pointer.
|
||||
//-----------------------------------------------------------------------------
|
||||
U32 File::getPosition() const
|
||||
{
|
||||
AssertFatal(Closed != currentStatus, "File::getPosition: file closed");
|
||||
AssertFatal(INVALID_HANDLE_VALUE != (HANDLE)handle, "File::getPosition: invalid file handle");
|
||||
|
||||
return ftell((FILE*)handle);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Set the position of the file pointer.
|
||||
// Absolute and relative positioning is supported via the absolutePos
|
||||
// parameter.
|
||||
//
|
||||
// If positioning absolutely, position MUST be positive - an IOError results if
|
||||
// position is negative.
|
||||
// Position can be negative if positioning relatively, however positioning
|
||||
// before the start of the file is an IOError.
|
||||
//
|
||||
// Returns the currentStatus of the file.
|
||||
//-----------------------------------------------------------------------------
|
||||
File::Status File::setPosition(S32 position, bool absolutePos)
|
||||
{
|
||||
AssertFatal(Closed != currentStatus, "File::setPosition: file closed");
|
||||
AssertFatal(handle != NULL, "File::setPosition: invalid file handle");
|
||||
|
||||
if (Ok != currentStatus && EOS != currentStatus)
|
||||
return currentStatus;
|
||||
|
||||
U32 finalPos;
|
||||
switch (absolutePos)
|
||||
{
|
||||
case true: // absolute position
|
||||
AssertFatal(0 <= position, "File::setPosition: negative absolute position");
|
||||
// position beyond EOS is OK
|
||||
fseek((FILE*)handle, position, SEEK_SET);
|
||||
finalPos = ftell((FILE*)handle);
|
||||
break;
|
||||
case false: // relative position
|
||||
AssertFatal((getPosition() >= (U32)abs(position) && 0 > position) || 0 <= position, "File::setPosition: negative relative position");
|
||||
// position beyond EOS is OK
|
||||
fseek((FILE*)handle, position, SEEK_CUR);
|
||||
finalPos = ftell((FILE*)handle);
|
||||
}
|
||||
|
||||
if (0xffffffff == finalPos)
|
||||
return setStatus(); // unsuccessful
|
||||
else if (finalPos >= getSize())
|
||||
return currentStatus = EOS; // success, at end of file
|
||||
else
|
||||
return currentStatus = Ok; // success!
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Get the size of the file in bytes.
|
||||
// It is an error to query the file size for a Closed file, or for one with an
|
||||
// error status.
|
||||
//-----------------------------------------------------------------------------
|
||||
U32 File::getSize() const
|
||||
{
|
||||
AssertWarn(Closed != currentStatus, "File::getSize: file closed");
|
||||
AssertFatal(handle != NULL, "File::getSize: invalid file handle");
|
||||
|
||||
if (Ok == currentStatus || EOS == currentStatus)
|
||||
{
|
||||
// this is not a very good way to do this
|
||||
U32 pos = ftell((FILE*)handle);
|
||||
fseek((FILE*)handle, 0, SEEK_END);
|
||||
U32 size = ftell((FILE*)handle);
|
||||
fseek((FILE*)handle, pos, SEEK_SET);
|
||||
return size;
|
||||
}
|
||||
else
|
||||
return 0; // unsuccessful
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Flush the file.
|
||||
// It is an error to flush a read-only file.
|
||||
// Returns the currentStatus of the file.
|
||||
//-----------------------------------------------------------------------------
|
||||
File::Status File::flush()
|
||||
{
|
||||
AssertFatal(Closed != currentStatus, "File::flush: file closed");
|
||||
AssertFatal(handle != NULL, "File::flush: invalid file handle");
|
||||
AssertFatal(true == hasCapability(FileWrite), "File::flush: cannot flush a read-only file");
|
||||
|
||||
if (fflush((FILE*)handle) == EOF)
|
||||
return setStatus(); // unsuccessful
|
||||
else
|
||||
return currentStatus = Ok; // success!
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Close the File.
|
||||
//
|
||||
// Returns the currentStatus
|
||||
//-----------------------------------------------------------------------------
|
||||
File::Status File::close()
|
||||
{
|
||||
// check if it's already closed...
|
||||
if (Closed == currentStatus)
|
||||
return currentStatus;
|
||||
|
||||
// it's not, so close it...
|
||||
if (handle != NULL)
|
||||
{
|
||||
if (fclose((FILE*)handle) == EOF)
|
||||
return setStatus(); // unsuccessful
|
||||
}
|
||||
handle = NULL;
|
||||
return currentStatus = Closed;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Self-explanatory.
|
||||
//-----------------------------------------------------------------------------
|
||||
File::Status File::getStatus() const
|
||||
{
|
||||
return currentStatus;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets and returns the currentStatus when an error has been encountered.
|
||||
//-----------------------------------------------------------------------------
|
||||
File::Status File::setStatus()
|
||||
{
|
||||
#pragma message("todo: File::setStatus")
|
||||
|
||||
switch (errno)
|
||||
{
|
||||
/*
|
||||
case EACCESS: // permission denied
|
||||
return currentStatus = IOError;
|
||||
case EBADF: // Bad File Pointer
|
||||
errno++;
|
||||
case EINVAL: // Invalid argument
|
||||
errno++;
|
||||
case ENOENT: // file not found
|
||||
errno++;
|
||||
*/
|
||||
default:
|
||||
return currentStatus = UnknownError;
|
||||
}
|
||||
|
||||
return currentStatus = UnknownError;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets and returns the currentStatus to status.
|
||||
//-----------------------------------------------------------------------------
|
||||
File::Status File::setStatus(File::Status status)
|
||||
{
|
||||
return currentStatus = status;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Read from a file.
|
||||
// The number of bytes to read is passed in size, the data is returned in src.
|
||||
// The number of bytes read is available in bytesRead if a non-Null pointer is
|
||||
// provided.
|
||||
//-----------------------------------------------------------------------------
|
||||
File::Status File::read(U32 size, char *dst, U32 *bytesRead)
|
||||
{
|
||||
AssertFatal(Closed != currentStatus, "File::read: file closed");
|
||||
AssertFatal(handle != NULL, "File::read: invalid file handle");
|
||||
AssertFatal(NULL != dst, "File::read: NULL destination pointer");
|
||||
AssertFatal(true == hasCapability(FileRead), "File::read: file lacks capability");
|
||||
AssertWarn(0 != size, "File::read: size of zero");
|
||||
|
||||
if (Ok != currentStatus || 0 == size)
|
||||
return currentStatus;
|
||||
else
|
||||
{
|
||||
U32 lastBytes;
|
||||
U32 *bytes = (NULL == bytesRead) ? &lastBytes : bytesRead;
|
||||
if (fread(dst, size, 1, (FILE*)handle) != 1)
|
||||
{ // fread onlu reports the number of chunks read not bytes
|
||||
// so we don't know exactly how much was read
|
||||
*bytes = getPosition();
|
||||
return currentStatus = EOS; // end of stream
|
||||
}
|
||||
else
|
||||
{
|
||||
*bytes = size;
|
||||
return currentStatus = Ok; // unsuccessful
|
||||
}
|
||||
}
|
||||
return currentStatus = Ok; // successfully read size bytes
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Write to a file.
|
||||
// The number of bytes to write is passed in size, the data is passed in src.
|
||||
// The number of bytes written is available in bytesWritten if a non-Null
|
||||
// pointer is provided.
|
||||
//-----------------------------------------------------------------------------
|
||||
File::Status File::write(U32 size, const char *src, U32 *bytesWritten)
|
||||
{
|
||||
AssertFatal(Closed != currentStatus, "File::write: file closed");
|
||||
AssertFatal(handle != NULL, "File::write: invalid file handle");
|
||||
AssertFatal(NULL != src, "File::write: NULL source pointer");
|
||||
AssertFatal(true == hasCapability(FileWrite), "File::write: file lacks capability");
|
||||
AssertWarn(0 != size, "File::write: size of zero");
|
||||
|
||||
if ((Ok != currentStatus && EOS != currentStatus) || 0 == size)
|
||||
return currentStatus;
|
||||
else
|
||||
{
|
||||
U32 lastBytes;
|
||||
U32 *bytes = (NULL == bytesWritten) ? &lastBytes : bytesWritten;
|
||||
if (fwrite(src, size, 1, (FILE*)handle) != 1)
|
||||
{ // fwrite onlu reports the number of chunks written not bytes
|
||||
// so we don't know exactly how much was written
|
||||
*bytes = getPosition();
|
||||
return setStatus();
|
||||
}
|
||||
else
|
||||
{
|
||||
*bytes = size;
|
||||
return currentStatus = Ok; // success!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Self-explanatory.
|
||||
//-----------------------------------------------------------------------------
|
||||
bool File::hasCapability(Capability cap) const
|
||||
{
|
||||
return (0 != (U32(cap) & capability));
|
||||
}
|
||||
|
||||
S32 Platform::compareFileTimes(const FileTime &a, const FileTime &b)
|
||||
{
|
||||
if(a.time > b.time)
|
||||
return 1;
|
||||
if(a.time < b.time)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static bool _recurseDumpPath(const char* in_pBasePath, const char* in_pCurPath, S32 dirID, Vector<Platform::FileInfo>& out_rFileVector)
|
||||
{
|
||||
char curPath[1024];
|
||||
char basePath[1024];
|
||||
char scratchBuf[1024];
|
||||
|
||||
if(in_pCurPath)
|
||||
dStrcpy(curPath, in_pCurPath);
|
||||
else
|
||||
curPath[0] = 0;
|
||||
|
||||
dStrcpy(basePath, in_pBasePath);
|
||||
in_pBasePath = basePath;
|
||||
|
||||
CInfoPBRec cinfo;
|
||||
Str63 nameField;
|
||||
OSErr result;
|
||||
S32 index = 1;
|
||||
|
||||
do
|
||||
{ // setup a catalog information request structure
|
||||
cinfo.hFileInfo.ioVRefNum = ppcState.volRefNum; // volume ID to search in
|
||||
cinfo.hFileInfo.ioDirID = dirID; // directory ID to search in
|
||||
cinfo.hFileInfo.ioFDirIndex = index++; // specify which entry you are interested in
|
||||
cinfo.hFileInfo.ioNamePtr = nameField; // supply a buffer to store the name
|
||||
|
||||
result = PBGetCatInfoSync(&cinfo);
|
||||
if (result == noErr)
|
||||
{
|
||||
if (cinfo.dirInfo.ioFlAttrib & ioDirMask)
|
||||
{ // it's a directory
|
||||
char *dirname = p2str(cinfo.hFileInfo.ioNamePtr);
|
||||
scratchBuf[0] = '\0';
|
||||
if (curPath[0] != '\0') {
|
||||
dStrcpy(scratchBuf, curPath);
|
||||
dStrcat(scratchBuf, "/");
|
||||
}
|
||||
dStrcat(scratchBuf, dirname);
|
||||
|
||||
_recurseDumpPath(basePath, scratchBuf, cinfo.hFileInfo.ioDirID, out_rFileVector);
|
||||
}
|
||||
else
|
||||
{ // it's a file
|
||||
char *filename = p2str(cinfo.hFileInfo.ioNamePtr);
|
||||
|
||||
out_rFileVector.increment();
|
||||
Platform::FileInfo& rInfo = out_rFileVector.last();
|
||||
|
||||
if (curPath[0] != '\0') {
|
||||
dSprintf(scratchBuf, sizeof(scratchBuf), "%s/%s", basePath, curPath);
|
||||
rInfo.pFullPath = StringTable->insert(scratchBuf);
|
||||
rInfo.pVirtPath = StringTable->insert(curPath);
|
||||
} else {
|
||||
rInfo.pFullPath = StringTable->insert(basePath);
|
||||
rInfo.pVirtPath = NULL;
|
||||
}
|
||||
|
||||
rInfo.pFileName = StringTable->insert(filename);
|
||||
rInfo.fileSize = cinfo.hFileInfo.ioFlLgLen;
|
||||
//rInfo.createTime.time = cinfo.hFileInfo.ioFlCrDat;
|
||||
//rInfo.modifyTime.time = cinfo.hFileInfo.ioFlMdDat;
|
||||
}
|
||||
}
|
||||
}while (result == noErr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
bool Platform::getFileTimes(const char *filePath, FileTime *createTime, FileTime *modifyTime)
|
||||
{
|
||||
return false;
|
||||
/*
|
||||
WIN32_FIND_DATA findData;
|
||||
HANDLE h = FindFirstFile(filePath, &findData);
|
||||
if(h == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
|
||||
if(createTime)
|
||||
{
|
||||
createTime->v1 = findData.ftCreationTime.dwLowDateTime;
|
||||
createTime->v2 = findData.ftCreationTime.dwHighDateTime;
|
||||
}
|
||||
if(modifyTime)
|
||||
{
|
||||
modifyTime->v1 = findData.ftLastWriteTime.dwLowDateTime;
|
||||
modifyTime->v2 = findData.ftLastWriteTime.dwHighDateTime;
|
||||
}
|
||||
FindClose(h);
|
||||
return true;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
bool Platform::createPath(const char *file)
|
||||
{
|
||||
char pathBuf[1024];
|
||||
char dirBuf[256];
|
||||
const char *dir;
|
||||
U32 pathLen = 0;
|
||||
S32 parentDirID = ppcState.dirID;
|
||||
|
||||
pathBuf[0] = 0;
|
||||
while((dir = dStrchr(file, '/')) != NULL)
|
||||
{
|
||||
U32 len = dir-file;
|
||||
dStrncpy(dirBuf, file, len);
|
||||
dirBuf[len] = 0;
|
||||
|
||||
dStrncpy(pathBuf + pathLen, file, dir - file);
|
||||
pathBuf[pathLen + dir-file] = 0;
|
||||
|
||||
// does directory/name already exist?
|
||||
CInfoPBRec cinfo;
|
||||
Str63 nameField;
|
||||
|
||||
cinfo.hFileInfo.ioVRefNum = ppcState.volRefNum; // volume ID to search in
|
||||
cinfo.hFileInfo.ioDirID = parentDirID; // directory ID to search in
|
||||
cinfo.hFileInfo.ioFDirIndex = 0; // get info on ioNamePtr
|
||||
cinfo.hFileInfo.ioNamePtr = nameField; // supply a buffer with name
|
||||
str2p(dirBuf, nameField);
|
||||
OSErr err = PBGetCatInfoSync(&cinfo);
|
||||
switch(err)
|
||||
{
|
||||
case noErr:
|
||||
if (cinfo.dirInfo.ioFlAttrib & ioDirMask)
|
||||
{ // it's a directory
|
||||
parentDirID = cinfo.hFileInfo.ioDirID;
|
||||
}
|
||||
else
|
||||
{ // the name existed and it was NOT a directory
|
||||
Con::printf("CreateDirectory(%s) - failed", pathBuf);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case fnfErr:
|
||||
{ // the name did not exist so create the directory
|
||||
long newId;
|
||||
OSErr err = DirCreate(ppcState.volRefNum, parentDirID, str2p(dirBuf), &newId);
|
||||
if (err != noErr)
|
||||
{
|
||||
Con::printf("CreateDirectory(%s) - failed", pathBuf);
|
||||
return false;
|
||||
}
|
||||
parentDirID = newId;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
file = dir + 1;
|
||||
pathLen += len;
|
||||
pathBuf[pathLen++] = '/';
|
||||
pathBuf[pathLen] = 0;
|
||||
Con::printf("CreateDirectory(%s) - Succeeded", pathBuf);
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
bool Platform::dumpPath(const char *in_pBasePath, Vector<Platform::FileInfo>& out_rFileVector)
|
||||
{
|
||||
// for now we can only search directories in the apps current workinng directory
|
||||
// specifying another drive, path or sub path (base/art) will not work.
|
||||
S32 dirID = ppcState.dirID;
|
||||
|
||||
if (in_pBasePath)
|
||||
{
|
||||
CInfoPBRec cinfo;
|
||||
Str63 nameField;
|
||||
OSErr result;
|
||||
|
||||
cinfo.hFileInfo.ioVRefNum = ppcState.volRefNum; // volume ID to search in
|
||||
cinfo.hFileInfo.ioDirID = dirID; // directory ID to search in
|
||||
cinfo.hFileInfo.ioFDirIndex = 0; // get info on ioNamePtr
|
||||
cinfo.hFileInfo.ioNamePtr = nameField; // supply a buffer with name
|
||||
str2p(in_pBasePath, nameField);
|
||||
result = PBGetCatInfoSync(&cinfo);
|
||||
if (result == noErr)
|
||||
{
|
||||
if (cinfo.dirInfo.ioFlAttrib & ioDirMask)
|
||||
{ // it's a directory
|
||||
char *dirname = p2str(cinfo.hFileInfo.ioNamePtr);
|
||||
return _recurseDumpPath(in_pBasePath, NULL, cinfo.hFileInfo.ioDirID, out_rFileVector);
|
||||
}
|
||||
return false; // not a directory
|
||||
}
|
||||
}
|
||||
return _recurseDumpPath(in_pBasePath, NULL, dirID, out_rFileVector);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
void Platform::getCurrentDirectory(char *dirBuf, const U32 in_bufferSize)
|
||||
{
|
||||
dirBuf, in_bufferSize;
|
||||
#pragma message("todo: Platform::getCurrentDirectory")
|
||||
// GetCurrentDirectory(in_bufferSize - 1, dirBuf);
|
||||
// forwardslash(dirBuf);
|
||||
|
||||
*dirBuf = '\0';
|
||||
|
||||
/*
|
||||
FUNCTION GetFullPath (DirID: LongInt; vRefnum: Integer): Str255;
|
||||
VAR
|
||||
myPB: CInfoPBRec; {parameter block for PBGetCatInfo}
|
||||
dirName: Str255; {a directory name}
|
||||
fullPath: Str255; {full pathname being constructed}
|
||||
myErr: OSErr;
|
||||
BEGIN
|
||||
fullPath := ''; {initialize full pathname}
|
||||
myPB.ioNamePtr := @dirName;
|
||||
myPB.ioVRefNum := vRefNum; {indicate target volume}
|
||||
myPB.ioDrParID := DirId; {initialize parent directory ID}
|
||||
myPB.ioFDirIndex := -1; {get info about a directory}
|
||||
{Get name of each parent directory, up to root directory.}
|
||||
REPEAT
|
||||
myPB.ioDrDirID := myPB.ioDrParID;
|
||||
myErr := PBGetCatInfo(@myPB, FALSE);
|
||||
IF gHaveAUX THEN
|
||||
|
||||
BEGIN
|
||||
IF dirName[1] <> '/' THEN
|
||||
dirName := concat(dirName, '/');
|
||||
END
|
||||
ELSE
|
||||
dirName := concat(dirName, ':');
|
||||
fullPath := concat(dirName, fullPath);
|
||||
UNTIL myPB.ioDrDirID = fsRtDirID;
|
||||
GetFullPath := fullPath; {return full pathname}
|
||||
END;
|
||||
|
||||
Note that GetFullPath uses either a slash (/) or a colon (:) to separate names in the
|
||||
full path, depending on whether A/UX is running or not. The GetFullPath function reads
|
||||
the value of the global variable gHaveAUX to determine whether A/UX is running; your
|
||||
application must initialize this variable (preferably by calling the Gestalt function)
|
||||
before it calls GetFullPath.
|
||||
The GetFullPath function defined in Listing 2-5 returns a result of type Str255, which
|
||||
limits the full pathname to 255 characters. An actual full pathname, however, might
|
||||
exceed 255 characters. A volume name can be up to 27 characters, and each directory name
|
||||
can be up to 31 characters. If the average volume and directory name is about 20
|
||||
characters long, GetFullPath can handle files located only about 12 levels deep. If the
|
||||
length of the average directory name is closer to the maximum, GetFullPath provides a
|
||||
full pathname for files located only about 8 levels deep. If necessary, you can overcome
|
||||
this limitation by rewriting GetFullPath to return a handle to the full pathname; the
|
||||
algorithm for ascending the directory hierarchy using PBGetCatInfo will still work, however.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
144
platformPPC/ppcFont.cc
Normal file
144
platformPPC/ppcFont.cc
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "PlatformPPC/platformPPC.h"
|
||||
#include "dgl/gFont.h"
|
||||
#include "dgl/gBitmap.h"
|
||||
#include "Math/mRect.h"
|
||||
|
||||
// static HDC fontHDC = NULL;
|
||||
// static HBITMAP fontBMP = NULL;
|
||||
|
||||
// void createFontInit(void);
|
||||
// void createFontShutdown(void);
|
||||
// void CopyCharToBitmap(GBitmap *pDstBMP, HDC hSrcHDC, const RectI &r);
|
||||
//
|
||||
void createFontInit()
|
||||
{
|
||||
// fontHDC = CreateCompatibleDC(NULL);
|
||||
// fontBMP = CreateCompatibleBitmap(fontHDC, 256, 256);
|
||||
}
|
||||
//
|
||||
void createFontShutdown()
|
||||
{
|
||||
// DeleteObject(fontBMP);
|
||||
// DeleteObject(fontHDC);
|
||||
}
|
||||
//
|
||||
// void CopyCharToBitmap(GBitmap *pDstBMP, HDC hSrcHDC, const RectI &r)
|
||||
// {
|
||||
// for (S32 i = r.point.y; i < r.point.y + r.extent.y; i++)
|
||||
// {
|
||||
// for (S32 j = r.point.x; j < r.point.x + r.extent.x; j++)
|
||||
// {
|
||||
// COLORREF color = GetPixel(hSrcHDC, j, i);
|
||||
// if (color)
|
||||
// *pDstBMP->getAddress(j, i) = 255;
|
||||
// else
|
||||
// *pDstBMP->getAddress(j, i) = 0;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
GFont *createFont(const char *name, S32 size)
|
||||
{
|
||||
return(NULL);
|
||||
|
||||
// if(!name)
|
||||
// return NULL;
|
||||
// if(size < 1)
|
||||
// return NULL;
|
||||
//
|
||||
//
|
||||
// HFONT hNewFont = CreateFont(size,0,0,0,0,0,0,0,0,0,0,0,0,name);
|
||||
// if(!hNewFont)
|
||||
// return NULL;
|
||||
//
|
||||
// GFont *retFont = new GFont;
|
||||
// GBitmap scratchPad(256, 256);
|
||||
//
|
||||
// TEXTMETRIC textMetric;
|
||||
// COLORREF backgroundColorRef = RGB( 0, 0, 0);
|
||||
// COLORREF foregroundColorRef = RGB(255, 255, 255);
|
||||
//
|
||||
// SelectObject(fontHDC, fontBMP);
|
||||
// SelectObject(fontHDC, hNewFont);
|
||||
// SetBkColor(fontHDC, backgroundColorRef);
|
||||
// SetTextColor(fontHDC, foregroundColorRef);
|
||||
// GetTextMetrics(fontHDC, &textMetric);
|
||||
//
|
||||
// RectI clip;
|
||||
// for(S32 i = 32; i < 256; i++)
|
||||
// {
|
||||
// SIZE size;
|
||||
// char buf[4];
|
||||
// buf[0] = ' ';
|
||||
// buf[1] = (char)i;
|
||||
// buf[2] = ' ';
|
||||
// buf[3] = '\0';
|
||||
//
|
||||
// TextOut(fontHDC, 0, 0, buf, 3);
|
||||
// GetTextExtentPoint32(fontHDC, buf, 3, &size);
|
||||
// RectI r(0, 0, size.cx + 1, size.cy + 1);
|
||||
// CopyCharToBitmap(&scratchPad, fontHDC, r);
|
||||
//
|
||||
// // now clip the raw bitmap so we don't waste any space
|
||||
// clip.point.x = 256;
|
||||
// clip.point.y = 256;
|
||||
// clip.extent.x = -257;
|
||||
// clip.extent.y = -257;
|
||||
//
|
||||
// S32 row, col;
|
||||
// bool found = FALSE;
|
||||
// Point2I upperL(256, 256);
|
||||
// Point2I lowerR(-1, -1);
|
||||
//
|
||||
// for (row = 0; row < size.cy; row++)
|
||||
// for (col = 0; col < size.cx; col++)
|
||||
// {
|
||||
// if (*scratchPad.getAddress(col, row) == 255)
|
||||
// {
|
||||
// found = TRUE;
|
||||
// if (upperL.x > col)
|
||||
// upperL.x = col;
|
||||
// if (upperL.y > row)
|
||||
// upperL.y = row;
|
||||
// if (lowerR.x < col)
|
||||
// lowerR.x = col;
|
||||
// if (lowerR.y < row)
|
||||
// lowerR.y = row;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (!found)
|
||||
// {
|
||||
// // bitmap is blank, probably a space, leave the width alone
|
||||
// // but truncate height to one line
|
||||
// clip.point.x = 0;
|
||||
// clip.point.y = 0x7fffffff;
|
||||
// clip.extent.x = size.cx / 3 + 1;
|
||||
// clip.extent.y = 0;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// clip.point = upperL;
|
||||
// clip.point.x -= 1;
|
||||
// if (clip.point.x < 0)
|
||||
// clip.point.x = 0;
|
||||
// clip.point.y -= 1;
|
||||
// if (clip.point.y < 0)
|
||||
// clip.point.y = 0;
|
||||
// clip.extent.set(lowerR.x - upperL.x + 2, lowerR.y - upperL.y + 2);
|
||||
// }
|
||||
// retFont->insertBitmap(i, &scratchPad, &clip);
|
||||
// }
|
||||
// retFont->pack(textMetric.tmHeight, textMetric.tmAscent);
|
||||
// //clean up local vars
|
||||
// DeleteObject(hNewFont);
|
||||
//
|
||||
// return retFont;
|
||||
}
|
||||
116
platformPPC/ppcGL.cc
Normal file
116
platformPPC/ppcGL.cc
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "PlatformWin32/platformGL.h"
|
||||
#include "PlatformPPC/platformPPC.h"
|
||||
#include <time.h>
|
||||
#include "console/console.h"
|
||||
|
||||
GLState gGLState;
|
||||
|
||||
bool gOpenGLDisableCVA = false;
|
||||
bool gOpenGLDisableTEC = false;
|
||||
bool gOpenGLDisableARBMT = false;
|
||||
bool gOpenGLDisableFC = true;
|
||||
|
||||
|
||||
// #define GL_EXT_abgr 1
|
||||
// #define GL_EXT_blend_color 1
|
||||
// #define GL_EXT_blend_minmax 1
|
||||
// #define GL_EXT_blend_subtract 1
|
||||
// #define GL_EXT_compiled_vertex_array 1
|
||||
// #define GL_ARB_multitexture 1
|
||||
// #define GL_APPLE_specular_vector 1
|
||||
// #define GL_APPLE_transform_hint 1
|
||||
|
||||
|
||||
|
||||
|
||||
bool QGL_EXT_Init( )
|
||||
{
|
||||
// Load extensions...
|
||||
//
|
||||
const char* pExtString = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
|
||||
|
||||
// EXT_compiled_vertex_array
|
||||
if (GL_EXT_compiled_vertex_array) //pExtString && dStrstr(pExtString, (const char*)"GL_EXT_compiled_vertex_array") != NULL)
|
||||
{
|
||||
//glLockArraysEXT = dllLockArraysEXT = (glLockArrays_t) qwglGetProcAddress("glLockArraysEXT");
|
||||
//glUnlockArraysEXT = dllUnlockArraysEXT = (glUnlockArrays_t) qwglGetProcAddress("glUnlockArraysEXT");
|
||||
gGLState.suppLockedArrays = true;
|
||||
} else {
|
||||
//glLockArraysEXT = dllLockArraysEXT = NULL;
|
||||
//glUnlockArraysEXT = dllUnlockArraysEXT = NULL;
|
||||
gGLState.suppLockedArrays = false;
|
||||
}
|
||||
|
||||
// ARB_multitexture
|
||||
if (GL_ARB_multitexture) //pExtString && dStrstr(pExtString, (const char*)"GL_ARB_multitexture") != NULL)
|
||||
{
|
||||
//glActiveTextureARB = dllActiveTextureARB = (glActiveTextureARB_t) qwglGetProcAddress("glActiveTextureARB");
|
||||
//glClientActiveTextureARB = dllClientActiveTextureARB = (glClientActiveTextureARB_t) qwglGetProcAddress("glClientActiveTextureARB");
|
||||
//glMultiTexCoord2fARB = dllMultiTexCoord2fARB = (glMultiTexCoord2fARB_t) qwglGetProcAddress("glMultiTexCoord2fARB");
|
||||
//glMultiTexCoord2fvARB = dllMultiTexCoord2fvARB = (glMultiTexCoord2fvARB_t) qwglGetProcAddress("glMultiTexCoord2fvARB");
|
||||
gGLState.suppARBMultitexture = true;
|
||||
} else {
|
||||
//glActiveTextureARB = dllActiveTextureARB = NULL;
|
||||
//glClientActiveTextureARB = dllClientActiveTextureARB = NULL;
|
||||
//glMultiTexCoord2fARB = dllMultiTexCoord2fARB = NULL;
|
||||
//glMultiTexCoord2fvARB = dllMultiTexCoord2fvARB = NULL;
|
||||
gGLState.suppARBMultitexture = false;
|
||||
}
|
||||
|
||||
// NV_vertex_array_range
|
||||
if (false) //pExtString && dStrstr(pExtString, (const char*)"GL_NV_vertex_array_range") != NULL)
|
||||
{
|
||||
//glVertexArrayRangeNV = dllVertexArrayRangeNV = (glVertexArrayRange_t) qwglGetProcAddress("glVertexArrayRangeNV");
|
||||
//glFlushVertexArrayRangeNV = dllFlushVertexArrayRangeNV = (glFlushVertexArrayRange_t) qwglGetProcAddress("glFlushVertexArrayRangeNV");
|
||||
gGLState.suppVertexArrayRange = true;
|
||||
} else {
|
||||
//glVertexArrayRangeNV = dllVertexArrayRangeNV = NULL;
|
||||
//glFlushVertexArrayRangeNV = dllFlushVertexArrayRangeNV = NULL;
|
||||
gGLState.suppVertexArrayRange = false;
|
||||
}
|
||||
|
||||
// EXT_fog_coord
|
||||
if (false) //pExtString && dStrstr(pExtString, (const char*)"GL_EXT_fog_coord") != NULL)
|
||||
{
|
||||
//glFogCoordfEXT = dllFogCoordfEXT = (glFogCoordf_t) qwglGetProcAddress("glFogCoordfEXT");
|
||||
//glFogCoordPointerEXT = dllFogCoordPointerEXT = (glFogCoordPointer_t) qwglGetProcAddress("glFogCoordPointerEXT");
|
||||
gGLState.suppFogCoord = true;
|
||||
} else {
|
||||
//glFogCoordfEXT = dllFogCoordfEXT = NULL;
|
||||
//glFogCoordPointerEXT = dllFogCoordPointerEXT = NULL;
|
||||
gGLState.suppFogCoord = false;
|
||||
}
|
||||
|
||||
// Binary states, i.e., no supporting functions
|
||||
// EXT_packed_pixels
|
||||
// EXT_texture_env_combine
|
||||
//
|
||||
gGLState.suppPackedPixels = false; //pExtString? (dStrstr(pExtString, (const char*)"GL_EXT_packed_pixels") != NULL) : false;
|
||||
gGLState.suppTextureEnvCombine = false; //pExtString? (dStrstr(pExtString, (const char*)"GL_EXT_texture_env_combine") != NULL) : false;
|
||||
|
||||
Con::printf("OpenGL Init: Enabled Extensions");
|
||||
if (gGLState.suppARBMultitexture) Con::printf(" ARB_multitexture");
|
||||
if (gGLState.suppLockedArrays) Con::printf(" EXT_compiled_vertex_array");
|
||||
if (gGLState.suppVertexArrayRange) Con::printf(" NV_vertex_array_range");
|
||||
if (gGLState.suppTextureEnvCombine) Con::printf(" EXT_texture_env_combine");
|
||||
if (gGLState.suppPackedPixels) Con::printf(" EXT_packed_pixels");
|
||||
if (gGLState.suppFogCoord) Con::printf(" EXT_fog_coord");
|
||||
|
||||
Con::warnf(ConsoleLogEntry::General, "OpenGL Init: Disabled Extensions");
|
||||
if (!gGLState.suppARBMultitexture) Con::warnf(ConsoleLogEntry::General, " ARB_multitexture");
|
||||
if (!gGLState.suppLockedArrays) Con::warnf(ConsoleLogEntry::General, " EXT_compiled_vertex_array");
|
||||
if (!gGLState.suppVertexArrayRange) Con::warnf(ConsoleLogEntry::General, " NV_vertex_array_range");
|
||||
if (!gGLState.suppTextureEnvCombine) Con::warnf(ConsoleLogEntry::General, " EXT_texture_env_combine");
|
||||
if (!gGLState.suppPackedPixels) Con::warnf(ConsoleLogEntry::General, " EXT_packed_pixels");
|
||||
if (!gGLState.suppFogCoord) Con::warnf(ConsoleLogEntry::General, " EXT_fog_coord");
|
||||
Con::printf("");
|
||||
|
||||
return true;
|
||||
}
|
||||
305
platformPPC/ppcInput.cc
Normal file
305
platformPPC/ppcInput.cc
Normal file
|
|
@ -0,0 +1,305 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "PlatformPPC/platformPPC.h"
|
||||
#include "Platform/platformInput.h"
|
||||
#include "ppcInput.h"
|
||||
#include "Platform/event.h"
|
||||
#include "console/console.h"
|
||||
|
||||
|
||||
// Static class variables:
|
||||
InputManager* Input::smManager;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
void Input::init()
|
||||
{
|
||||
Con::printf( "Input Init:" );
|
||||
smManager = NULL;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
static U8 VcodeRemap[256] =
|
||||
{
|
||||
KEY_A, // 0x00
|
||||
KEY_A, // 0x01
|
||||
KEY_D, // 0x02
|
||||
KEY_F, // 0x03
|
||||
KEY_H, // 0x04
|
||||
KEY_G, // 0x05
|
||||
KEY_Z, // 0x06
|
||||
KEY_X, // 0x07
|
||||
KEY_C, // 0x08
|
||||
KEY_V, // 0x09
|
||||
KEY_Y, // 0x0A
|
||||
KEY_B, // 0x0B
|
||||
KEY_Q, // 0x0C
|
||||
KEY_W, // 0x0D
|
||||
KEY_E, // 0x0E
|
||||
KEY_R, // 0x0F
|
||||
KEY_Y, // 0x10
|
||||
KEY_T, // 0x11
|
||||
KEY_1, // 0x12
|
||||
KEY_2, // 0x13
|
||||
KEY_3, // 0x14
|
||||
KEY_4, // 0x15
|
||||
KEY_6, // 0x16
|
||||
KEY_5, // 0x17
|
||||
0, // 0x18
|
||||
KEY_9, // 0x19
|
||||
KEY_7, // 0x1A
|
||||
0, // 0x1B
|
||||
KEY_8, // 0x1C
|
||||
KEY_0, // 0x1D
|
||||
0, // 0x1E
|
||||
KEY_O, // 0x1F
|
||||
KEY_U, // 0x20
|
||||
0, // 0x21
|
||||
KEY_I, // 0x22
|
||||
KEY_P, // 0x23
|
||||
KEY_RETURN, // 0x24
|
||||
KEY_L, // 0x25
|
||||
KEY_J, // 0x26
|
||||
0, // 0x27
|
||||
KEY_K, // 0x28
|
||||
0, // 0x29
|
||||
0, // 0x2A
|
||||
0, // 0x2B
|
||||
0, // 0x2C
|
||||
KEY_N, // 0x2D
|
||||
KEY_M, // 0x2E
|
||||
0, // 0x2F
|
||||
|
||||
KEY_TAB, // 0x30
|
||||
0, // 0x31
|
||||
0, // 0x32
|
||||
KEY_BACKSPACE, // 0x33
|
||||
0, // 0x34
|
||||
KEY_ESCAPE, // 0x35
|
||||
0, // 0x36
|
||||
KEY_ALT, // 0x37
|
||||
KEY_LSHIFT, // 0x38
|
||||
KEY_CAPSLOCK, // 0x39
|
||||
0, // 0x3A
|
||||
KEY_CONTROL, // 0x3B
|
||||
KEY_RSHIFT, // 0x3C
|
||||
0, // 0x3D
|
||||
0, // 0x3E
|
||||
0, // 0x3F
|
||||
0, // 0x40
|
||||
|
||||
KEY_MULTIPLY, // 0x41
|
||||
0, // 0x42
|
||||
0, // 0x43
|
||||
0, // 0x44
|
||||
KEY_ADD, // 0x45
|
||||
0, // 0x46
|
||||
KEY_NUMLOCK, // 0x47
|
||||
0, // 0x48
|
||||
0, // 0x49
|
||||
0, // 0x4A
|
||||
0, // 0x4B
|
||||
KEY_RETURN, // 0x4C
|
||||
KEY_DIVIDE, // 0x4D
|
||||
KEY_SUBTRACT, // 0x4E
|
||||
0, // 0x4F
|
||||
0, // 0x50
|
||||
0, // 0x51
|
||||
KEY_NUMPAD0, // 0x52
|
||||
KEY_NUMPAD1, // 0x53
|
||||
KEY_NUMPAD2, // 0x54
|
||||
KEY_NUMPAD3, // 0x55
|
||||
KEY_NUMPAD4, // 0x56
|
||||
KEY_NUMPAD5, // 0x57
|
||||
KEY_NUMPAD6, // 0x58
|
||||
KEY_NUMPAD7, // 0x59
|
||||
0, // 0x5A
|
||||
|
||||
|
||||
KEY_NUMPAD8, // 0x5B
|
||||
KEY_NUMPAD9, // 0x5C
|
||||
0, // 0x5D
|
||||
0, // 0x5E
|
||||
0, // 0x5F
|
||||
|
||||
KEY_F5, // 0x60
|
||||
KEY_F6, // 0x61
|
||||
KEY_F7, // 0x62
|
||||
KEY_F3, // 0x63
|
||||
KEY_F8, // 0x64
|
||||
KEY_F9, // 0x65
|
||||
0, // 0x66
|
||||
KEY_F11, // 0x67
|
||||
0, // 0x68
|
||||
KEY_PRINT, // 0x69
|
||||
0, // 0x6A
|
||||
KEY_SCROLLLOCK, // 0x6B
|
||||
0, // 0x6C
|
||||
KEY_F10, // 0x6D
|
||||
0, // 0x6E
|
||||
KEY_F12, // 0x6F
|
||||
0, // 0x70
|
||||
0, // 0x71
|
||||
KEY_INSERT, // 0x72
|
||||
KEY_HOME, // 0x73
|
||||
KEY_PAGE_UP, // 0x74
|
||||
KEY_DELETE, // 0x75
|
||||
KEY_F4, // 0x76
|
||||
KEY_END, // 0x77
|
||||
KEY_F2, // 0x78
|
||||
KEY_PAGE_DOWN, // 0x79
|
||||
KEY_F1, // 0x7A
|
||||
KEY_LEFT, // 0x7B
|
||||
KEY_RIGHT, // 0x7C
|
||||
KEY_DOWN, // 0x7D
|
||||
KEY_UP, // 0x7E
|
||||
0, // 0x7F
|
||||
0, // 0x80
|
||||
0, // 0x81
|
||||
0, // 0x82
|
||||
0, // 0x83
|
||||
0, // 0x84
|
||||
0, // 0x85
|
||||
0, // 0x86
|
||||
0, // 0x87
|
||||
0, // 0x88
|
||||
0, // 0x89
|
||||
0, // 0x8A
|
||||
0, // 0x8B
|
||||
0, // 0x8C
|
||||
0, // 0x8D
|
||||
0, // 0x8E
|
||||
0, // 0x8F
|
||||
|
||||
0, // 0x90
|
||||
0, // 0x91
|
||||
0, // 0x92
|
||||
0, // 0x93
|
||||
0, // 0x94
|
||||
0, // 0x95
|
||||
0, // 0x96
|
||||
0, // 0x97
|
||||
0, // 0x98
|
||||
0, // 0x99
|
||||
0, // 0x9A
|
||||
0, // 0x9B
|
||||
0, // 0x9C
|
||||
0, // 0x9D
|
||||
0, // 0x9E
|
||||
0, // 0x9F
|
||||
|
||||
0, // 0xA0
|
||||
0, // 0xA1
|
||||
0, // 0xA2
|
||||
0, // 0xA3
|
||||
0, // 0xA4
|
||||
0, // 0xA5
|
||||
0, // 0xA6
|
||||
0, // 0xA7
|
||||
0, // 0xA8
|
||||
0, // 0xA9
|
||||
0, // 0xAA
|
||||
0, // 0xAB
|
||||
0, // 0xAC
|
||||
0, // 0xAD
|
||||
0, // 0xAE
|
||||
0, // 0xAF
|
||||
0, // 0xB0
|
||||
0, // 0xB1
|
||||
0, // 0xB2
|
||||
0, // 0xB3
|
||||
0, // 0xB4
|
||||
0, // 0xB5
|
||||
0, // 0xB6
|
||||
0, // 0xB7
|
||||
0, // 0xB8
|
||||
0, // 0xB9
|
||||
0, // 0xBA
|
||||
0, // 0xBB
|
||||
0, // 0xBC
|
||||
0, // 0xBD
|
||||
0, // 0xBE
|
||||
0, // 0xBF
|
||||
0, // 0xC0
|
||||
0, // 0xC1
|
||||
0, // 0xC2
|
||||
0, // 0xC3
|
||||
0, // 0xC4
|
||||
0, // 0xC5
|
||||
0, // 0xC6
|
||||
0, // 0xC7
|
||||
0, // 0xC8
|
||||
0, // 0xC9
|
||||
0, // 0xCA
|
||||
0, // 0xCB
|
||||
0, // 0xCC
|
||||
0, // 0xCD
|
||||
0, // 0xCE
|
||||
0, // 0xCF
|
||||
0, // 0xD0
|
||||
0, // 0xD1
|
||||
0, // 0xD2
|
||||
0, // 0xD3
|
||||
0, // 0xD4
|
||||
0, // 0xD5
|
||||
0, // 0xD6
|
||||
0, // 0xD7
|
||||
0, // 0xD8
|
||||
0, // 0xD9
|
||||
0, // 0xDA
|
||||
0, // 0xDB
|
||||
0, // 0xDC
|
||||
0, // 0xDD
|
||||
0, // 0xDE
|
||||
0, // 0xDF
|
||||
0, // 0xE0
|
||||
0, // 0xE1
|
||||
0, // 0xE2
|
||||
0, // 0xE3
|
||||
0, // 0xE4
|
||||
|
||||
0, // 0xE5
|
||||
|
||||
0, // 0xE6
|
||||
0, // 0xE7
|
||||
0, // 0xE8
|
||||
0, // 0xE9
|
||||
0, // 0xEA
|
||||
0, // 0xEB
|
||||
0, // 0xEC
|
||||
0, // 0xED
|
||||
0, // 0xEE
|
||||
0, // 0xEF
|
||||
|
||||
0, // 0xF0
|
||||
0, // 0xF1
|
||||
0, // 0xF2
|
||||
0, // 0xF3
|
||||
0, // 0xF4
|
||||
0, // 0xF5
|
||||
|
||||
0, // 0xF6
|
||||
0, // 0xF7
|
||||
0, // 0xF8
|
||||
0, // 0xF9
|
||||
0, // 0xFA
|
||||
0, // 0xFB
|
||||
0, // 0xFC
|
||||
0, // 0xFD
|
||||
0, // 0xFE
|
||||
0 // 0xFF
|
||||
};
|
||||
|
||||
|
||||
U8 TranslateOSKeyCode(U8 vcode)
|
||||
{
|
||||
return VcodeRemap[vcode];
|
||||
}
|
||||
|
||||
|
||||
73
platformPPC/ppcMath.cc
Normal file
73
platformPPC/ppcMath.cc
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "Platform/platform.h"
|
||||
#include "console/console.h"
|
||||
#include "Math/mMath.h"
|
||||
|
||||
|
||||
extern void mInstallLibrary_C();
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
static void cMathInit(SimObject *obj, S32 argc, const char **argv)
|
||||
{
|
||||
obj;
|
||||
argc;
|
||||
argv;
|
||||
U32 properties = CPU_PROP_C; // C entensions are always used
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
Math::init(0);
|
||||
return;
|
||||
}
|
||||
for (argc--, argv++; argc; argc--, argv++)
|
||||
{
|
||||
if (dStricmp(*argv, "DETECT") == 0) {
|
||||
Math::init(0);
|
||||
return;
|
||||
}
|
||||
if (dStricmp(*argv, "C") == 0) {
|
||||
properties |= CPU_PROP_C;
|
||||
continue;
|
||||
}
|
||||
if (dStricmp(*argv, "FPU") == 0) {
|
||||
properties |= CPU_PROP_FPU;
|
||||
continue;
|
||||
}
|
||||
Con::printf("Error: MathInit(): ignoring unknown math extension '%s'", *argv);
|
||||
}
|
||||
Math::init(properties);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void Math::init(U32 properties)
|
||||
{
|
||||
Con::addCommand( "MathInit", cMathInit, "MathInit(detect|C|FPU|MMX|3DNOW|SSE|...)", 1, 10);
|
||||
|
||||
if (!properties)
|
||||
// detect what's available
|
||||
properties = Platform::SystemInfo.processor.properties;
|
||||
else
|
||||
// Make sure we're not asking for anything that's not supported
|
||||
properties &= Platform::SystemInfo.processor.properties;
|
||||
|
||||
Con::printf("Math Init:");
|
||||
Con::printf(" Installing Standard C extensions");
|
||||
mInstallLibrary_C();
|
||||
|
||||
if (properties & CPU_PROP_FPU)
|
||||
{
|
||||
Con::printf(" Installing FPU extensions");
|
||||
}
|
||||
Con::printf(" ");
|
||||
}
|
||||
|
||||
|
||||
59
platformPPC/ppcMemory.cc
Normal file
59
platformPPC/ppcMemory.cc
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "PlatformPPC/platformPPC.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
//--------------------------------------
|
||||
#ifdef new
|
||||
#undef new
|
||||
#endif
|
||||
|
||||
void* FN_CDECL operator new(dsize_t, void* ptr)
|
||||
{
|
||||
return (ptr);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
void* dRealMalloc(dsize_t in_size)
|
||||
{
|
||||
return malloc(in_size);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
void dRealFree(void* in_pFree)
|
||||
{
|
||||
free(in_pFree);
|
||||
}
|
||||
|
||||
|
||||
void* dMemcpy(void *dst, const void *src, unsigned size)
|
||||
{
|
||||
return memcpy(dst,src,size);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
void* dMemmove(void *dst, const void *src, unsigned size)
|
||||
{
|
||||
return memmove(dst,src,size);
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
void* dMemset(void *dst, S32 c, unsigned size)
|
||||
{
|
||||
return memset(dst,c,size);
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
S32 dMemcmp(const void *ptr1, const void *ptr2, unsigned len)
|
||||
{
|
||||
return(memcmp(ptr1, ptr2, len));
|
||||
}
|
||||
787
platformPPC/ppcNet.cc
Normal file
787
platformPPC/ppcNet.cc
Normal file
|
|
@ -0,0 +1,787 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <OpenTransport.h>
|
||||
#include <OpenTptInternet.h>
|
||||
|
||||
#include "PlatformPPC/platformPPC.h"
|
||||
#include "Platform/platform.h"
|
||||
#include "Platform/event.h"
|
||||
//#include <winsock.h>
|
||||
//#include <wsipx.h>
|
||||
#include "console/console.h"
|
||||
|
||||
|
||||
// stubbed stuff to get this to compile
|
||||
typedef void* HANDLE;
|
||||
typedef void* SOCKET;
|
||||
#define INVALID_SOCKET NULL
|
||||
typedef InetAddress SOCKADDR_IN;
|
||||
typedef InetAddress SOCKADDR_IPX;
|
||||
|
||||
|
||||
struct Connection
|
||||
{
|
||||
NetSocket socket;
|
||||
S32 state;
|
||||
S32 prevState;
|
||||
bool listenConnection;
|
||||
Connection *nextConnection;
|
||||
Connection *nextInTable;
|
||||
HANDLE connectThreadHandle;
|
||||
U32 tag;
|
||||
};
|
||||
|
||||
struct Status
|
||||
{
|
||||
bool mSignal;
|
||||
OSErr mErr;
|
||||
void *mData;
|
||||
Status()
|
||||
{
|
||||
mSignal = false;
|
||||
mErr = kOTNoError;
|
||||
mData = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static Net::Error getLastError();
|
||||
static S32 defaultPort = 28000;
|
||||
static S32 netPort = 0;
|
||||
//static SOCKET ipxSocket = INVALID_SOCKET;
|
||||
//static SOCKET udpSocket = INVALID_SOCKET;
|
||||
static bool sendPackets = true;
|
||||
static U32 nextConnectionId = 1;
|
||||
static U32 nextAcceptId = 1000000000;
|
||||
static Connection *connectionList = NULL;
|
||||
enum {
|
||||
ConnectionTableSize = 256,
|
||||
ConnectionTableMask = 0xFF
|
||||
};
|
||||
static Connection *connectionTable[ConnectionTableSize] = { 0, };
|
||||
|
||||
|
||||
// kOTAnyInetAddress
|
||||
static U32 OTReferenceCount = 0;
|
||||
static TEndpoint *EndPoint = NULL;
|
||||
static OSErr err = kOTNoError;
|
||||
|
||||
|
||||
static pascal void EventProc( void *_pSession, OTEventCode event, OTResult result, void *cookie )
|
||||
{
|
||||
Status *status = (Status *) _pSession;
|
||||
|
||||
switch ( event )
|
||||
{
|
||||
case T_DATA:
|
||||
//pSess->m_dataToRead = 1;
|
||||
break;
|
||||
|
||||
case T_BINDCOMPLETE:
|
||||
status->mErr = (OSErr) result;
|
||||
status->mSignal = true;
|
||||
break;
|
||||
|
||||
case T_OPENCOMPLETE:
|
||||
status->mErr = (OSErr) result;
|
||||
status->mData = cookie; // the EndPoint
|
||||
status->mSignal = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Net::setJournaling(bool jrn)
|
||||
{
|
||||
sendPackets = !jrn;
|
||||
}
|
||||
|
||||
bool Net::init()
|
||||
{
|
||||
// WSADATA stWSAData;
|
||||
// return !WSAStartup(0x0101, &stWSAData);
|
||||
if ( OTReferenceCount == 0 )
|
||||
if (InitOpenTransport() != kOTNoError)
|
||||
return false;
|
||||
|
||||
// successfully opened Open Transport, inncrement the reference count
|
||||
OTReferenceCount++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Net::shutdown()
|
||||
{
|
||||
// while(connectionList)
|
||||
// Net::closeConnectTo(connectionList->tag);
|
||||
//
|
||||
// closePort();
|
||||
// WSACleanup();
|
||||
|
||||
while(connectionList)
|
||||
Net::closeConnectTo(connectionList->tag);
|
||||
|
||||
closePort();
|
||||
if ( OTReferenceCount <= 0 )
|
||||
return;
|
||||
|
||||
// close Open Transport if there are no more references to it
|
||||
OTReferenceCount--;
|
||||
if ( OTReferenceCount == 0 )
|
||||
CloseOpenTransport();
|
||||
}
|
||||
|
||||
static void netToIPSocketAddress(const NetAddress *address, SOCKADDR_IN *sockAddr)
|
||||
{
|
||||
address;
|
||||
dMemset(sockAddr, 0, sizeof(SOCKADDR_IN));
|
||||
// sockAddr->sin_family = AF_INET;
|
||||
// sockAddr->sin_port = htons(address->port);
|
||||
// sockAddr->sin_addr.s_net = address->netNum[0];
|
||||
// sockAddr->sin_addr.s_host = address->netNum[1];
|
||||
// sockAddr->sin_addr.s_lh = address->netNum[2];
|
||||
// sockAddr->sin_addr.s_impno = address->netNum[3];
|
||||
}
|
||||
|
||||
static void IPSocketToNetAddress(const SOCKADDR_IN *sockAddr, NetAddress *address)
|
||||
{
|
||||
sockAddr, address;
|
||||
// address->type = NetAddress::IPAddress;
|
||||
// address->port = htons(sockAddr->sin_port);
|
||||
// address->netNum[0] = sockAddr->sin_addr.s_net;
|
||||
// address->netNum[1] = sockAddr->sin_addr.s_host;
|
||||
// address->netNum[2] = sockAddr->sin_addr.s_lh;
|
||||
// address->netNum[3] = sockAddr->sin_addr.s_impno;
|
||||
}
|
||||
|
||||
static void netToIPXSocketAddress(const NetAddress *address, SOCKADDR_IPX *sockAddr)
|
||||
{
|
||||
sockAddr, address;
|
||||
// dMemset(sockAddr, 0, sizeof(SOCKADDR_IPX));
|
||||
// sockAddr->sa_family = AF_INET;
|
||||
// sockAddr->sa_socket = htons(address->port);
|
||||
// sockAddr->sa_netnum[0] = address->netNum[0];
|
||||
// sockAddr->sa_netnum[1] = address->netNum[1];
|
||||
// sockAddr->sa_netnum[2] = address->netNum[2];
|
||||
// sockAddr->sa_netnum[3] = address->netNum[3];
|
||||
// sockAddr->sa_nodenum[0] = address->nodeNum[0];
|
||||
// sockAddr->sa_nodenum[1] = address->nodeNum[1];
|
||||
// sockAddr->sa_nodenum[2] = address->nodeNum[2];
|
||||
// sockAddr->sa_nodenum[3] = address->nodeNum[3];
|
||||
// sockAddr->sa_nodenum[4] = address->nodeNum[4];
|
||||
// sockAddr->sa_nodenum[5] = address->nodeNum[5];
|
||||
}
|
||||
|
||||
static void IPXSocketToNetAddress(const SOCKADDR_IPX *sockAddr, NetAddress *address)
|
||||
{
|
||||
sockAddr, address;
|
||||
// address->type = NetAddress::IPXAddress;
|
||||
// address->port = htons(sockAddr->sa_socket);
|
||||
// address->netNum[0] = sockAddr->sa_netnum[0] ;
|
||||
// address->netNum[1] = sockAddr->sa_netnum[1] ;
|
||||
// address->netNum[2] = sockAddr->sa_netnum[2] ;
|
||||
// address->netNum[3] = sockAddr->sa_netnum[3] ;
|
||||
// address->nodeNum[0] = sockAddr->sa_nodenum[0];
|
||||
// address->nodeNum[1] = sockAddr->sa_nodenum[1];
|
||||
// address->nodeNum[2] = sockAddr->sa_nodenum[2];
|
||||
// address->nodeNum[3] = sockAddr->sa_nodenum[3];
|
||||
// address->nodeNum[4] = sockAddr->sa_nodenum[4];
|
||||
// address->nodeNum[5] = sockAddr->sa_nodenum[5];
|
||||
}
|
||||
|
||||
//DWORD WINAPI connectThreadFunction(LPVOID param)
|
||||
//{
|
||||
// Connection *con = (Connection *) param;
|
||||
// con;
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
static Connection *newConnection(U32 id)
|
||||
{
|
||||
Connection *conn = new Connection;
|
||||
conn->nextConnection = connectionList;
|
||||
conn->tag = id;
|
||||
connectionList = conn;
|
||||
conn->nextInTable = connectionTable[conn->tag & ConnectionTableMask];
|
||||
connectionTable[conn->tag & ConnectionTableMask] = conn;
|
||||
return conn;
|
||||
}
|
||||
|
||||
U32 Net::openListenPort(U16 port)
|
||||
{
|
||||
nextConnectionId++;
|
||||
if(!sendPackets)
|
||||
return nextConnectionId;
|
||||
|
||||
Connection *conn = newConnection(nextConnectionId);
|
||||
|
||||
conn->listenConnection = true;
|
||||
|
||||
conn->socket = openSocket();
|
||||
bind(conn->socket, port);
|
||||
listen(conn->socket, 4);
|
||||
setBlocking(conn->socket, false);
|
||||
return conn->tag;
|
||||
}
|
||||
|
||||
U32 Net::openConnectTo(U16 port, const NetAddress *address)
|
||||
{
|
||||
port;
|
||||
|
||||
nextConnectionId++;
|
||||
if(!sendPackets)
|
||||
return nextConnectionId;
|
||||
|
||||
Connection *conn = newConnection(nextConnectionId);
|
||||
|
||||
conn->listenConnection = false;
|
||||
conn->prevState = ConnectedNotifyEvent::DNSResolve;
|
||||
conn->state = ConnectedNotifyEvent::DNSResolve;
|
||||
|
||||
conn->socket = openSocket();
|
||||
connect(conn->socket, address);
|
||||
setBlocking(conn->socket, false);
|
||||
|
||||
//threadHandle = CreateThread(NULL, 0, connectThreadFunction, (LPVOID) conn, 0, &threadId);
|
||||
|
||||
|
||||
//CloseHandle(threadHandle);
|
||||
conn->state = ConnectedNotifyEvent::Connected;
|
||||
return conn->tag;
|
||||
}
|
||||
|
||||
void Net::processConnected()
|
||||
{
|
||||
Connection **walk = &connectionList;
|
||||
Connection *con;
|
||||
while((con = *walk) != NULL)
|
||||
{
|
||||
bool del = false;
|
||||
if(con->listenConnection)
|
||||
{
|
||||
NetSocket newSocket;
|
||||
ConnectedAcceptEvent event;
|
||||
newSocket = accept(con->socket, &event.address);
|
||||
|
||||
if(newSocket != InvalidSocket)
|
||||
{
|
||||
Connection *nc = newConnection(nextAcceptId++);
|
||||
nc->listenConnection = false;
|
||||
nc->prevState = ConnectedNotifyEvent::Connected;
|
||||
nc->state = ConnectedNotifyEvent::Connected;
|
||||
nc->socket = newSocket;
|
||||
setBlocking(nc->socket, false);
|
||||
|
||||
event.portTag = con->tag;
|
||||
event.connectionTag = nc->tag;
|
||||
GamePostEvent(event);
|
||||
}
|
||||
walk = &con->nextConnection;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(con->state != con->prevState)
|
||||
{
|
||||
ConnectedNotifyEvent event;
|
||||
event.tag = con->tag;
|
||||
event.state = con->state;
|
||||
GamePostEvent(event);
|
||||
con->prevState = con->state;
|
||||
}
|
||||
if(con->state == ConnectedNotifyEvent::Connected)
|
||||
{
|
||||
ConnectedReceiveEvent event;
|
||||
Net::Error err;
|
||||
S32 bytesRead;
|
||||
event.tag = con->tag;
|
||||
|
||||
do {
|
||||
// err = recv(con->socket, event.data, MaxPacketDataSize, &bytesRead);
|
||||
if(err == NoError && bytesRead != 0)
|
||||
{
|
||||
event.size = ConnectedReceiveEventHeaderSize + bytesRead;
|
||||
GamePostEvent(event);
|
||||
}
|
||||
else if(err != WouldBlock)
|
||||
{
|
||||
// bad news... this disconnected
|
||||
ConnectedNotifyEvent event;
|
||||
event.tag = con->tag;
|
||||
event.state = ConnectedNotifyEvent::Disconnected;
|
||||
GamePostEvent(event);
|
||||
del = true;
|
||||
}
|
||||
}
|
||||
while(err == NoError && bytesRead != 0);
|
||||
}
|
||||
if(del)
|
||||
{
|
||||
*walk = con->nextConnection;
|
||||
closeSocket(con->socket);
|
||||
for(Connection **tbWalk = &connectionTable[con->tag & ConnectionTableMask]; *tbWalk != NULL; tbWalk = &(*tbWalk)->nextInTable)
|
||||
{
|
||||
Connection *dc = *tbWalk;
|
||||
if(dc->tag == con->tag)
|
||||
{
|
||||
*tbWalk = dc->nextInTable;
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete con;
|
||||
}
|
||||
else
|
||||
walk = &con->nextConnection;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Net::sendTo(U32 tag, const U8 *buffer, S32 bufferSize)
|
||||
{
|
||||
Connection *walk;
|
||||
for(walk = connectionTable[tag & ConnectionTableMask]; walk != NULL; walk = walk->nextConnection)
|
||||
if(walk->tag == tag)
|
||||
break;
|
||||
if(walk)
|
||||
send(walk->socket, buffer, bufferSize);
|
||||
}
|
||||
|
||||
void Net::closeConnectTo(U32 tag)
|
||||
{
|
||||
Connection **walk;
|
||||
for(walk = &connectionList; *walk != NULL; walk = &(*walk)->nextConnection)
|
||||
{
|
||||
Connection *con = *walk;
|
||||
if(con->tag == tag)
|
||||
{
|
||||
*walk = con->nextConnection;
|
||||
closeSocket(con->socket);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for(walk = &connectionTable[tag & ConnectionTableMask]; *walk != NULL; walk = &(*walk)->nextInTable)
|
||||
{
|
||||
Connection *con = *walk;
|
||||
if(con->tag == tag)
|
||||
{
|
||||
*walk = con->nextInTable;
|
||||
delete con;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Net::openPort(S32 port)
|
||||
{
|
||||
// if(udpSocket != INVALID_SOCKET)
|
||||
// closesocket(udpSocket);
|
||||
// if(ipxSocket != INVALID_SOCKET)
|
||||
// closesocket(ipxSocket);
|
||||
//
|
||||
// udpSocket = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
// ipxSocket = socket(AF_IPX, SOCK_DGRAM, NSPROTO_IPX);
|
||||
//
|
||||
// if(udpSocket != INVALID_SOCKET)
|
||||
// {
|
||||
// Net::Error error;
|
||||
// error = bind(udpSocket, port);
|
||||
// if(error == NoError)
|
||||
// error = setBufferSize(udpSocket, 32768);
|
||||
// if(error == NoError)
|
||||
// error = setBroadcast(udpSocket, true);
|
||||
// if(error == NoError)
|
||||
// error = setBlocking(udpSocket, false);
|
||||
// if(error == NoError)
|
||||
// Con::printf("UDP initialized on port %d", port);
|
||||
// else
|
||||
// {
|
||||
// closesocket(udpSocket);
|
||||
// udpSocket = INVALID_SOCKET;
|
||||
// Con::printf("Unable to initialize UDP - error %d", error);
|
||||
// }
|
||||
// }
|
||||
// if(ipxSocket != INVALID_SOCKET)
|
||||
// {
|
||||
// Net::Error error = NoError;
|
||||
// SOCKADDR_IPX ipxAddress;
|
||||
// memset((char *)&ipxAddress, 0, sizeof(ipxAddress));
|
||||
// ipxAddress.sa_family = AF_IPX;
|
||||
// ipxAddress.sa_socket = htons(port);
|
||||
// S32 err = ::bind(ipxSocket, (PSOCKADDR) &ipxAddress, sizeof(ipxAddress));
|
||||
// if(err)
|
||||
// error = getLastError();
|
||||
// if(error == NoError)
|
||||
// error = setBufferSize(ipxSocket, 32768);
|
||||
// if(error == NoError)
|
||||
// error = setBroadcast(ipxSocket, true);
|
||||
// if(error == NoError)
|
||||
// error = setBlocking(ipxSocket, false);
|
||||
// if(error == NoError)
|
||||
// Con::printf("IPX initialized on port %d", port);
|
||||
// else
|
||||
// {
|
||||
// closesocket(ipxSocket);
|
||||
// ipxSocket = INVALID_SOCKET;
|
||||
// Con::printf("Unable to initialize IPX - error %d", error);
|
||||
// }
|
||||
// }
|
||||
netPort = port;
|
||||
// return ipxSocket != INVALID_SOCKET || udpSocket != INVALID_SOCKET;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Net::closePort()
|
||||
{
|
||||
// if(ipxSocket != INVALID_SOCKET)
|
||||
// closesocket(ipxSocket);
|
||||
// if(udpSocket != INVALID_SOCKET)
|
||||
// closesocket(udpSocket);
|
||||
}
|
||||
|
||||
Net::Error Net::sendto(const NetAddress *address, const U8 *buffer, S32 bufferSize)
|
||||
{
|
||||
address, buffer, bufferSize;
|
||||
return NoError;
|
||||
// if(!sendPackets)
|
||||
// return NoError;
|
||||
// if(address->type == NetAddress::IPXAddress)
|
||||
// {
|
||||
// SOCKADDR_IPX ipxAddr;
|
||||
// netToIPXSocketAddress(address, &ipxAddr);
|
||||
// if(::sendto(ipxSocket, (const char*)buffer, bufferSize, 0,
|
||||
// (PSOCKADDR) &ipxAddr, sizeof(SOCKADDR_IPX)) == SOCKET_ERROR)
|
||||
// return getLastError();
|
||||
// else
|
||||
// return NoError;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// SOCKADDR_IN ipAddr;
|
||||
// netToIPSocketAddress(address, &ipAddr);
|
||||
// if(::sendto(udpSocket, (const char*)buffer, bufferSize, 0,
|
||||
// (PSOCKADDR) &ipAddr, sizeof(SOCKADDR_IN)) == SOCKET_ERROR)
|
||||
// return getLastError();
|
||||
// else
|
||||
// return NoError;
|
||||
// }
|
||||
}
|
||||
|
||||
void Net::process()
|
||||
{
|
||||
// SOCKADDR sa;
|
||||
//
|
||||
// PacketReceiveEvent receiveEvent;
|
||||
// for(;;)
|
||||
// {
|
||||
// S32 addrLen = sizeof(sa);
|
||||
// S32 bytesRead = SOCKET_ERROR;
|
||||
// if(udpSocket != INVALID_SOCKET)
|
||||
// bytesRead = recvfrom(udpSocket, (char *) receiveEvent.data, MaxPacketDataSize, 0, &sa, &addrLen);
|
||||
// if(bytesRead == SOCKET_ERROR && ipxSocket != INVALID_SOCKET)
|
||||
// {
|
||||
// addrLen = sizeof(sa);
|
||||
// bytesRead = recvfrom(ipxSocket, (char *) receiveEvent.data, MaxPacketDataSize, 0, &sa, &addrLen);
|
||||
// }
|
||||
//
|
||||
// if(bytesRead == SOCKET_ERROR)
|
||||
// break;
|
||||
//
|
||||
// if(sa.sa_family == AF_INET)
|
||||
// IPSocketToNetAddress((SOCKADDR_IN *) &sa, &receiveEvent.sourceAddress);
|
||||
// else if(sa.sa_family == AF_IPX)
|
||||
// IPXSocketToNetAddress((SOCKADDR_IPX *) &sa, &receiveEvent.sourceAddress);
|
||||
// else
|
||||
// continue;
|
||||
//
|
||||
// NetAddress &na = receiveEvent.sourceAddress;
|
||||
// if(na.type == NetAddress::IPAddress &&
|
||||
// na.netNum[0] == 127 &&
|
||||
// na.netNum[1] == 0 &&
|
||||
// na.netNum[2] == 0 &&
|
||||
// na.netNum[3] == 1 &&
|
||||
// na.port == netPort)
|
||||
// continue;
|
||||
// if(bytesRead <= 0)
|
||||
// continue;
|
||||
// receiveEvent.size = PacketReceiveEventHeaderSize + bytesRead;
|
||||
// GamePostEvent(receiveEvent);
|
||||
// }
|
||||
}
|
||||
|
||||
NetSocket Net::openSocket()
|
||||
{
|
||||
return InvalidSocket;
|
||||
// SOCKET retSocket;
|
||||
// retSocket = socket(AF_INET, SOCK_STREAM, 0);
|
||||
//
|
||||
// if(retSocket == INVALID_SOCKET)
|
||||
// return InvalidSocket;
|
||||
// else
|
||||
// return retSocket;
|
||||
}
|
||||
|
||||
Net::Error Net::closeSocket(NetSocket socket)
|
||||
{
|
||||
if(socket != InvalidSocket)
|
||||
{
|
||||
// if(!closesocket(socket))
|
||||
// return NoError;
|
||||
// else
|
||||
return getLastError();
|
||||
}
|
||||
else
|
||||
return NotASocket;
|
||||
}
|
||||
|
||||
Net::Error Net::connect(NetSocket socket, const NetAddress *address)
|
||||
{
|
||||
socket;
|
||||
if(address->type != NetAddress::IPAddress)
|
||||
return WrongProtocolType;
|
||||
// SOCKADDR_IN socketAddress;
|
||||
// netToIPSocketAddress(address, &socketAddress);
|
||||
// if(!::connect(socket, (PSOCKADDR) &socketAddress, sizeof(socketAddress)))
|
||||
// return NoError;
|
||||
return getLastError();
|
||||
}
|
||||
|
||||
Net::Error Net::listen(NetSocket socket, S32 backlog)
|
||||
{
|
||||
socket, backlog;
|
||||
// if(!::listen(socket, backlog))
|
||||
// return NoError;
|
||||
return getLastError();
|
||||
}
|
||||
|
||||
NetSocket Net::accept(NetSocket acceptSocket, NetAddress *remoteAddress)
|
||||
{
|
||||
acceptSocket, remoteAddress;
|
||||
// SOCKADDR_IN socketAddress;
|
||||
// S32 addrLen = sizeof(socketAddress);
|
||||
//
|
||||
// SOCKET retVal = ::accept(acceptSocket, (PSOCKADDR) &socketAddress, &addrLen);
|
||||
// if(retVal != INVALID_SOCKET)
|
||||
// {
|
||||
// IPSocketToNetAddress(&socketAddress, remoteAddress);
|
||||
// return retVal;
|
||||
// }
|
||||
return InvalidSocket;
|
||||
}
|
||||
|
||||
Net::Error Net::bind(NetSocket socket, U16 port)
|
||||
{
|
||||
socket, port;
|
||||
// S32 error;
|
||||
//
|
||||
// SOCKADDR_IN socketAddress;
|
||||
// dMemset((char *)&socketAddress, 0, sizeof(socketAddress));
|
||||
// socketAddress.sin_family = AF_INET;
|
||||
// socketAddress.sin_addr.s_addr = INADDR_ANY;
|
||||
// socketAddress.sin_port = htons(port);
|
||||
// error = ::bind(socket, (PSOCKADDR) &socketAddress, sizeof(socketAddress));
|
||||
//
|
||||
// if(!error)
|
||||
// return NoError;
|
||||
return getLastError();
|
||||
}
|
||||
|
||||
Net::Error Net::setBufferSize(NetSocket socket, S32 bufferSize)
|
||||
{
|
||||
socket, bufferSize;
|
||||
// S32 error;
|
||||
// error = setsockopt(socket, SOL_SOCKET, SO_RCVBUF, (char *) &bufferSize, sizeof(bufferSize));
|
||||
// if(!error)
|
||||
// error = setsockopt(socket, SOL_SOCKET, SO_SNDBUF, (char *) &bufferSize, sizeof(bufferSize));
|
||||
// if(!error)
|
||||
// return NoError;
|
||||
return getLastError();
|
||||
}
|
||||
|
||||
Net::Error Net::setBroadcast(NetSocket socket, bool broadcast)
|
||||
{
|
||||
socket, broadcast;
|
||||
// S32 bc = broadcast;
|
||||
// S32 error = setsockopt(socket, SOL_SOCKET, SO_BROADCAST, (char*)&bc, sizeof(bc));
|
||||
// if(!error)
|
||||
// return NoError;
|
||||
return getLastError();
|
||||
}
|
||||
|
||||
Net::Error Net::setBlocking(NetSocket socket, bool blockingIO)
|
||||
{
|
||||
socket, blockingIO;
|
||||
// DWORD notblock = !blockingIO;
|
||||
// S32 error = ioctlsocket(socket, FIONBIO, ¬block);
|
||||
// if(!error)
|
||||
// return NoError;
|
||||
return getLastError();
|
||||
}
|
||||
|
||||
Net::Error Net::send(NetSocket socket, const U8 *buffer, S32 bufferSize)
|
||||
{
|
||||
socket, buffer, bufferSize;
|
||||
// S32 error = ::send(socket, (const char*)buffer, bufferSize, 0);
|
||||
// if(!error)
|
||||
// return NoError;
|
||||
return getLastError();
|
||||
}
|
||||
|
||||
Net::Error Net::recv(NetSocket socket, U8 *buffer, S32 bufferSize, S32 *bytesRead)
|
||||
{
|
||||
socket, buffer, bufferSize, bytesRead;
|
||||
// *bytesRead = ::recv(socket, (char*)buffer, bufferSize, 0);
|
||||
// if(*bytesRead == SOCKET_ERROR)
|
||||
// return getLastError();
|
||||
return NoError;
|
||||
}
|
||||
|
||||
bool Net::compareAddresses(const NetAddress *a1, const NetAddress *a2)
|
||||
{
|
||||
if(a1->type != a2->type)
|
||||
return false;
|
||||
if(*((U32 *)a1->netNum) != *((U32 *)a2->netNum))
|
||||
return false;
|
||||
if(a1->type == NetAddress::IPAddress)
|
||||
return true;
|
||||
for(S32 i = 0; i < 6; i++)
|
||||
if(a1->nodeNum[i] != a2->nodeNum[i])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Net::stringToAddress(const char *addressString, NetAddress *address)
|
||||
{
|
||||
addressString, address;
|
||||
/*
|
||||
if(dStrnicmp(addressString, "ipx:", 4))
|
||||
{
|
||||
// assume IP if it doesn't have ipx: at the front.
|
||||
|
||||
if(!dStrnicmp(addressString, "ip:", 3))
|
||||
addressString += 3; // eat off the ip:
|
||||
|
||||
SOCKADDR_IN ipAddr;
|
||||
char remoteAddr[256];
|
||||
if(strlen(addressString) > 255)
|
||||
return false;
|
||||
|
||||
dStrcpy(remoteAddr, addressString);
|
||||
|
||||
char *portString = dStrchr(remoteAddr, ':');
|
||||
if(portString)
|
||||
*portString++ = 0;
|
||||
|
||||
struct hostent *hp;
|
||||
|
||||
if(!dStricmp(remoteAddr, "broadcast"))
|
||||
ipAddr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
|
||||
else
|
||||
{
|
||||
ipAddr.sin_addr.s_addr = inet_addr(remoteAddr);
|
||||
if(ipAddr.sin_addr.s_addr == INADDR_NONE)
|
||||
{
|
||||
if((hp = gethostbyname(remoteAddr)) == NULL)
|
||||
return false;
|
||||
else
|
||||
memcpy(&ipAddr.sin_addr.s_addr, hp->h_addr, sizeof(IN_ADDR));
|
||||
}
|
||||
}
|
||||
if(portString)
|
||||
ipAddr.sin_port = htons(dAtoi(portString));
|
||||
else
|
||||
ipAddr.sin_port = htons(defaultPort);
|
||||
ipAddr.sin_family = AF_INET;
|
||||
IPSocketToNetAddress(&ipAddr, address);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
S32 i;
|
||||
S32 port;
|
||||
|
||||
address->type = NetAddress::IPXAddress;
|
||||
for(i = 0; i < 6; i++)
|
||||
address->nodeNum[i] = 0xFF;
|
||||
|
||||
// it's an IPX string
|
||||
addressString += 4;
|
||||
if(!dStricmp(addressString, "broadcast"))
|
||||
{
|
||||
address->port = defaultPort;
|
||||
return true;
|
||||
}
|
||||
else if(sscanf(addressString, "broadcast:%d", &port) == 1)
|
||||
{
|
||||
address->port = port;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
S32 nodeNum[6];
|
||||
S32 netNum[4];
|
||||
S32 count = dSscanf(addressString, "%2x%2x%2x%2x:%2x%2x%2x%2x%2x%2x:%d",
|
||||
&netNum[0], &netNum[1], &netNum[2], &netNum[3],
|
||||
&nodeNum[0], &nodeNum[1], &nodeNum[2], &nodeNum[3], &nodeNum[4], &nodeNum[5],
|
||||
&port);
|
||||
|
||||
if(count == 10)
|
||||
{
|
||||
port = defaultPort;
|
||||
count++;
|
||||
}
|
||||
if(count != 11)
|
||||
return false;
|
||||
|
||||
for(i = 0; i < 6; i++)
|
||||
address->nodeNum[i] = nodeNum[i];
|
||||
for(i = 0; i < 4; i++)
|
||||
address->netNum[i] = netNum[i];
|
||||
address->port = port;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
void Net::addressToString(const NetAddress *address, char addressString[256])
|
||||
{
|
||||
address, addressString;
|
||||
/*
|
||||
if(address->type == NetAddress::IPAddress)
|
||||
{
|
||||
SOCKADDR_IN ipAddr;
|
||||
netToIPSocketAddress(address, &ipAddr);
|
||||
|
||||
if(ipAddr.sin_addr.s_addr == htonl(INADDR_BROADCAST))
|
||||
dSprintf(addressString, 256, "IP:Broadcast:%d", ntohs(ipAddr.sin_port));
|
||||
else
|
||||
dSprintf(addressString, 256, "IP:%d.%d.%d.%d:%d", ipAddr.sin_addr.s_net,
|
||||
ipAddr.sin_addr.s_host, ipAddr.sin_addr.s_lh,
|
||||
ipAddr.sin_addr.s_impno, ntohs(ipAddr.sin_port));
|
||||
}
|
||||
else
|
||||
{
|
||||
dSprintf(addressString, 256, "IPX:%.2X%.2X%.2X%.2X:%.2X%.2X%.2X%.2X%.2X%.2X:%d",
|
||||
address->netNum[0], address->netNum[1], address->netNum[2], address->netNum[3],
|
||||
address->nodeNum[0], address->nodeNum[1], address->nodeNum[2], address->nodeNum[3], address->nodeNum[4], address->nodeNum[5],
|
||||
address->port);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
Net::Error getLastError()
|
||||
{
|
||||
return Net::UnknownError;
|
||||
// S32 err = WSAGetLastError();
|
||||
// switch(err)
|
||||
// {
|
||||
// case WSAEWOULDBLOCK:
|
||||
// return Net::WouldBlock;
|
||||
// default:
|
||||
// return Net::UnknownError;
|
||||
// }
|
||||
}
|
||||
422
platformPPC/ppcOGLVideo.cc
Normal file
422
platformPPC/ppcOGLVideo.cc
Normal file
|
|
@ -0,0 +1,422 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "PlatformWin32/platformGL.h"
|
||||
#include "PlatformPPC/platformPPC.h"
|
||||
#include "PlatformPPC/ppcOGLVideo.h"
|
||||
#include "console/console.h"
|
||||
#include <math.h>
|
||||
|
||||
//extern Win32PlatState winState;
|
||||
extern PPCPlatState ppcState;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
OpenGLDevice::OpenGLDevice()
|
||||
{
|
||||
initDevice();
|
||||
}
|
||||
|
||||
|
||||
OpenGLDevice::~OpenGLDevice()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void OpenGLDevice::initDevice()
|
||||
{
|
||||
#pragma message("todo: enumerate available display modes");
|
||||
// Set the device name:
|
||||
mDeviceName = "OpenGL";
|
||||
|
||||
// Set some initial conditions:
|
||||
mResolutionList.clear();
|
||||
|
||||
Resolution newRes( 640, 480, 32 );
|
||||
mResolutionList.push_back( newRes );
|
||||
return;
|
||||
|
||||
/*
|
||||
// Enumerate all available resolutions:
|
||||
DEVMODE devMode;
|
||||
U32 modeNum = 0;
|
||||
U32 stillGoing = true;
|
||||
while ( stillGoing )
|
||||
{
|
||||
dMemset( &devMode, 0, sizeof( devMode ) );
|
||||
devMode.dmSize = sizeof( devMode );
|
||||
|
||||
stillGoing = EnumDisplaySettings( NULL, modeNum++, &devMode );
|
||||
if ( devMode.dmPelsWidth >= 640 && devMode.dmPelsHeight >= 480
|
||||
&& ( devMode.dmBitsPerPel == 16 || devMode.dmBitsPerPel == 32 ) )
|
||||
{
|
||||
// Only add this resolution if it is not already in the list:
|
||||
bool alreadyInList = false;
|
||||
for ( U32 i = 0; i < mResolutionList.size(); i++ )
|
||||
{
|
||||
if ( devMode.dmPelsWidth == mResolutionList[i].w
|
||||
&& devMode.dmPelsHeight == mResolutionList[i].h
|
||||
&& devMode.dmBitsPerPel == mResolutionList[i].bpp )
|
||||
{
|
||||
alreadyInList = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !alreadyInList )
|
||||
{
|
||||
Resolution newRes( devMode.dmPelsWidth, devMode.dmPelsHeight, devMode.dmBitsPerPel );
|
||||
mResolutionList.push_back( newRes );
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool OpenGLDevice::activate()
|
||||
{
|
||||
// If the rendering context exists, delete it:
|
||||
if (ppcState.ctx)
|
||||
{
|
||||
Con::printf( "Making the rendering context not current..." );
|
||||
aglSetCurrentContext(NULL);
|
||||
aglSetDrawable(ppcState.ctx, NULL);
|
||||
Con::printf( "Deleting the rendering context..." );
|
||||
aglDestroyContext(ppcState.ctx);
|
||||
ppcState.ctx = NULL;
|
||||
}
|
||||
|
||||
//if ( winState.hGLRC )
|
||||
//{
|
||||
// qwglMakeCurrent( NULL, NULL );
|
||||
// qwglDeleteContext( winState.hGLRC );
|
||||
// winState.hGLRC = NULL;
|
||||
//}
|
||||
|
||||
// If OpenGL library already loaded, shut it down:
|
||||
//if ( winState.hinstOpenGL )
|
||||
// QGL_Shutdown();
|
||||
|
||||
//if ( 0 /* TODO -- figure out when we will need to get a new window */ )
|
||||
//{
|
||||
// // Release the device context and kill the window:
|
||||
// ReleaseDC( winState.appWindow, winState.appDC );
|
||||
// winState.appDC = NULL;
|
||||
// DestroyWindow( winState.appWindow );
|
||||
//}
|
||||
|
||||
// If the app window does not exist, create it:
|
||||
/*
|
||||
if ( ppcState.appWindow == NULL )
|
||||
{
|
||||
// Create the new window:
|
||||
ppcState.appWindow = CreateOpenGLWindow( smIsFullScreen );
|
||||
if ( ppcState.appWindow == NULL )
|
||||
{
|
||||
Platform::AlertOK( "OpenGLDevice::activate", "Failed to create a window!" );
|
||||
return false;
|
||||
}
|
||||
|
||||
setResolution( smCurrentRes, true );
|
||||
|
||||
// Set the new window to the foreground:
|
||||
ShowWindow( ppcState.appWindow );
|
||||
|
||||
//ShowWindow( winState.appWindow, SW_SHOW );
|
||||
//SetForegroundWindow( winState.appWindow );
|
||||
//SetFocus( winState.appWindow );
|
||||
|
||||
}
|
||||
*/
|
||||
GLint attrib[] = { AGL_RGBA, AGL_DOUBLEBUFFER, AGL_DEPTH_SIZE, 16, AGL_NONE };
|
||||
|
||||
// Never unload a code module
|
||||
aglConfigure(AGL_RETAIN_RENDERERS, GL_TRUE);
|
||||
|
||||
ppcState.fmt = aglChoosePixelFormat(NULL, 0, attrib);
|
||||
if(ppcState.fmt == NULL)
|
||||
{
|
||||
Platform::AlertOK( "OpenGLDevice::activate", "Failed to set the pixel format of the device context!" );
|
||||
return false;
|
||||
}
|
||||
// Con::printf( ??? ); // Spit out pixel format details?
|
||||
|
||||
//QGL_Init( "opengl32", "glu32" );
|
||||
|
||||
//PIXELFORMATDESCRIPTOR pfd;
|
||||
//CreatePixelFormat( &pfd, smCurrentRes.bpp, 24, 8, false );
|
||||
|
||||
//S32 pixelFormat = ChooseBestPixelFormat( winState.appDC, &pfd );
|
||||
//qwglDescribePixelFormat( winState.appDC, pixelFormat, sizeof( pfd ), &pfd );
|
||||
//if ( !SetPixelFormat( winState.appDC, pixelFormat, &pfd ) )
|
||||
//{
|
||||
// Platform::AlertOK( "OpenGLDevice::activate", "Failed to set the pixel format of the device context!" );
|
||||
// return false;
|
||||
//}
|
||||
|
||||
// Create an AGL context
|
||||
Con::printf( "Creating a new rendering context..." );
|
||||
ppcState.ctx = aglCreateContext(ppcState.fmt, NULL);
|
||||
if(ppcState.ctx == NULL)
|
||||
{
|
||||
Platform::AlertOK( "OpenGLDevice::activate", "Failed to create a GL rendering context!" );
|
||||
return false;
|
||||
}
|
||||
|
||||
//winState.hGLRC = qwglCreateContext( winState.appDC );
|
||||
//if ( winState.hGLRC == NULL )
|
||||
//{
|
||||
// Platform::AlertOK( "OpenGLDevice::activate", "Failed to create a GL rendering context!" );
|
||||
// return false;
|
||||
//}
|
||||
|
||||
// Attach the context to the window
|
||||
Con::printf( "Attaching the rendering context to the window..." );
|
||||
if( !aglSetDrawable(ppcState.ctx, (CGrafPtr) ppcState.appWindow) )
|
||||
{
|
||||
Platform::AlertOK( "OpenGLDevice::activate", "Failed to make the rendering context current!" );
|
||||
return false;
|
||||
}
|
||||
// Make this context current
|
||||
aglSetCurrentContext(ppcState.ctx);
|
||||
|
||||
//if ( !qwglMakeCurrent( winState.appDC, winState.hGLRC ) )
|
||||
//{
|
||||
// Platform::AlertOK( "OpenGLDevice::activate", "Failed to make the rendering context current!" );
|
||||
// return false;
|
||||
//}
|
||||
|
||||
// Output some driver info to the console?
|
||||
|
||||
QGL_EXT_Init();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void OpenGLDevice::shutdown()
|
||||
{
|
||||
/*if (ppcState.ctx)
|
||||
{
|
||||
aglSetCurrentContext(NULL);
|
||||
aglSetDrawable(ppcState.ctx, NULL);
|
||||
aglDestroyContext(ppcState.ctx);
|
||||
ppcState.ctx = NULL;
|
||||
}*/
|
||||
|
||||
// if ( smIsFullScreen )
|
||||
// ChangeDisplaySettings( NULL, 0 );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool OpenGLDevice::setResolution( Resolution &res, bool forceIt )
|
||||
{
|
||||
if ( !smIsFullScreen && ( res.w >= ppcState.desktopWidth || res.h >= ppcState.desktopHeight ) )
|
||||
{
|
||||
Con::printf( "OpenGLDevice::setResolution -- can't switch to resolution larger than desktop in windowed mode!" );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( res.w < 640 || res.h < 480 )
|
||||
{
|
||||
Con::printf( "OpenGLDevice::setResolution -- can't go smaller than 640x480!" );
|
||||
return false;
|
||||
}
|
||||
|
||||
// If full-screen, make the new resolution match one of the ones in the list:
|
||||
if ( smIsFullScreen )
|
||||
{
|
||||
U32 resIndex = 0;
|
||||
U32 bestScore = 0, thisScore = 0;
|
||||
for ( int i = 0; i < mResolutionList.size(); i++ )
|
||||
{
|
||||
if ( res == mResolutionList[i] )
|
||||
{
|
||||
resIndex = i;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
thisScore = (int) res.h - (int) mResolutionList[i].h;
|
||||
if (thisScore < 0) thisScore = -thisScore;
|
||||
thisScore = (int) res.w - (int) mResolutionList[i].w + thisScore;
|
||||
if (thisScore < 0) thisScore = -thisScore;
|
||||
//thisScore = abs( (int) res.w - (int) mResolutionList[i].w ) + abs( (int) res.h - (int) mResolutionList[i].h );
|
||||
if ( ( !bestScore || thisScore < bestScore ) && res.bpp == mResolutionList[i].bpp )
|
||||
{
|
||||
bestScore = thisScore;
|
||||
resIndex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res = mResolutionList[resIndex];
|
||||
}
|
||||
|
||||
// Return if already at this resolution:
|
||||
if ( !forceIt && res == smCurrentRes )
|
||||
return true;
|
||||
|
||||
Con::printf( "Changing resolution to %dx%dx%d", res.w, res.h, res.bpp );
|
||||
U32 test;
|
||||
if ( smIsFullScreen )
|
||||
{
|
||||
// aglSetFullScreen( neds to know monitor freq...
|
||||
#if 0
|
||||
// Change the display settings:
|
||||
DEVMODE devMode;
|
||||
dMemset( &devMode, 0, sizeof( devMode ) );
|
||||
devMode.dmSize = sizeof( devMode );
|
||||
devMode.dmPelsWidth = res.w;
|
||||
devMode.dmPelsHeight = res.h;
|
||||
// TODO: whatever it takes to make bit depth switching work.
|
||||
//devMode.dmBitsPerPel = res.bpp
|
||||
devMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT/* | DM_BITSPERPEL*/;
|
||||
|
||||
if ( ChangeDisplaySettings( &devMode, CDS_FULLSCREEN ) != DISP_CHANGE_SUCCESSFUL )
|
||||
{
|
||||
ChangeDisplaySettings( NULL, 0 );
|
||||
Con::printf( "OpenGLDevice::setResolution -- ChangeDisplaySettings to %dx%dx%d failed.", res.w, res.h, res.bpp );
|
||||
return;
|
||||
}
|
||||
|
||||
test = SetWindowPos( ppcState.appWindow, 0, 0, 0, res.w, res.h, SWP_NOZORDER );
|
||||
if ( !test )
|
||||
{
|
||||
Con::printf( "OpenGLDevice::setResolution -- SetWindowPos moving to ( 0, 0 ) and sizing to %dx%d failed.", res.w, res.h );
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
//SizeWindow(ppcState.appWindow, res.w, res.h, true); // change the window size
|
||||
#pragma message("todo: center window on resize");
|
||||
|
||||
U32 xPos = 0;
|
||||
U32 yPos = 0;
|
||||
if (!aglSetDrawable(ppcState.ctx, (CGrafPtr) ppcState.appWindow))
|
||||
{
|
||||
Con::printf( "OpenGLDevice::setResolution: SizeWindow moving to ( %d, %d ) and sizing to %dx%d failed.", xPos, yPos, res.w, res.h );
|
||||
return false;
|
||||
}
|
||||
if (!aglUpdateContext(ppcState.ctx)) // tell OpenGL the window changed
|
||||
{
|
||||
Con::printf("OpenGLDevice::setResolution: Unable to resize render buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
// // Adjust the window rect to compensate for the window style:
|
||||
//
|
||||
// RECT windowRect;
|
||||
// windowRect.left = windowRect.top = 0;
|
||||
// windowRect.right = res.w;
|
||||
// windowRect.bottom = res.h;
|
||||
//
|
||||
// AdjustWindowRect( &windowRect, GetWindowLong( ppcState.appWindow, GWL_STYLE ), false );
|
||||
// U32 adjWidth = windowRect.right - windowRect.left;
|
||||
// U32 adjHeight = windowRect.bottom - windowRect.top;
|
||||
//
|
||||
// // Center the window again:
|
||||
// U32 xPos = ( ppcState.desktopWidth - adjWidth ) / 2;
|
||||
// U32 yPos = ( ppcState.desktopHeight - adjHeight ) / 2;
|
||||
// test = SetWindowPos( ppcState.appWindow, 0, xPos, yPos, adjWidth, adjHeight, SWP_NOZORDER );
|
||||
// if ( !test )
|
||||
// {
|
||||
// Con::printf( "OpenGLDevice::setResolution -- SetWindowPos moving to ( %d, %d ) and sizing to %dx%d failed.", xPos, yPos, res.w, res.h );
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
|
||||
smCurrentRes = res;
|
||||
Platform::setWindowSize( res.w, res.h );
|
||||
char tempBuf[15];
|
||||
dSprintf( tempBuf, sizeof( tempBuf ), "%dx%dx%d", smCurrentRes.w, smCurrentRes.h, smCurrentRes.bpp );
|
||||
Con::setVariable( "$pref::Video::resolution", tempBuf );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool OpenGLDevice::toggleFullScreen()
|
||||
{
|
||||
// Change the window style:
|
||||
// U32 style = WS_VISIBLE;
|
||||
// if ( smIsFullScreen )
|
||||
// style |= ( WS_OVERLAPPED | WS_BORDER | WS_CAPTION );
|
||||
// else
|
||||
// style |= ( WS_POPUP | WS_MAXIMIZE );
|
||||
// SetWindowLong( ppcState.appWindow, GWL_STYLE, style );
|
||||
//
|
||||
// U32 test = SetWindowPos( ppcState.appWindow, 0, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED );
|
||||
// if ( !test )
|
||||
// {
|
||||
// Con::printf( "OpenGLDevice::toggleFullScreen -- SetWindowPos changing window style failed." );
|
||||
// return false;
|
||||
// }
|
||||
|
||||
smIsFullScreen = !smIsFullScreen;
|
||||
Con::setVariable( "$pref::Video::fullScreen", ( smIsFullScreen ? "true" : "false" ) );
|
||||
|
||||
if ( !smIsFullScreen )
|
||||
{
|
||||
// Change to windowed mode:
|
||||
// ChangeDisplaySettings( NULL, 0 );
|
||||
|
||||
// Make sure the window size is not too big for the desktop:
|
||||
if ( smCurrentRes.w >= ppcState.desktopWidth || smCurrentRes.h >= ppcState.desktopHeight )
|
||||
{
|
||||
S32 resIndex;
|
||||
for ( resIndex = 0; resIndex < mResolutionList.size(); resIndex++ )
|
||||
{
|
||||
if ( smCurrentRes == mResolutionList[resIndex] )
|
||||
break;
|
||||
}
|
||||
|
||||
if ( resIndex < mResolutionList.size() )
|
||||
{
|
||||
// Walk back in the list until we get to a res smaller than the desktop:
|
||||
while ( resIndex >= 0 && ( mResolutionList[resIndex].w >= ppcState.desktopWidth || mResolutionList[resIndex].h >= ppcState.desktopHeight ) )
|
||||
resIndex--;
|
||||
|
||||
if ( resIndex >= 0 )
|
||||
{
|
||||
setResolution( mResolutionList[resIndex], true );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Something is really screwy if you ever get to here, but let it fall through anyways.
|
||||
Con::printf( "OpenGLDevice::toggleFullScreen -- a suitable resolution could not be found!" );
|
||||
}
|
||||
}
|
||||
|
||||
// Force the resolution change:
|
||||
if (setResolution( smCurrentRes, true ))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void OpenGLDevice::swapBuffers()
|
||||
{
|
||||
aglSwapBuffers(aglGetCurrentContext());
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
DisplayDevice* OpenGLDevice::create()
|
||||
{
|
||||
return new OpenGLDevice();
|
||||
}
|
||||
31
platformPPC/ppcOGLVideo.h
Normal file
31
platformPPC/ppcOGLVideo.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PCCOGLVIDEO_H_
|
||||
#define _PCCOGLVIDEO_H_
|
||||
|
||||
#ifndef _PLATFORMVIDEO_H_
|
||||
#include "Platform/platformVideo.h"
|
||||
#endif
|
||||
|
||||
class OpenGLDevice : public DisplayDevice
|
||||
{
|
||||
public:
|
||||
OpenGLDevice();
|
||||
~OpenGLDevice();
|
||||
|
||||
void initDevice();
|
||||
bool activate();
|
||||
void shutdown();
|
||||
bool setResolution( Resolution &res, bool forceIt = false );
|
||||
bool toggleFullScreen();
|
||||
void swapBuffers();
|
||||
|
||||
static DisplayDevice* create();
|
||||
};
|
||||
|
||||
#endif // _H_WINOGLVIDEO
|
||||
23
platformPPC/ppcProcessControl.cc
Normal file
23
platformPPC/ppcProcessControl.cc
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "PlatformPPC/platformPPC.h"
|
||||
|
||||
void Platform::postQuitMessage(const U32 in_quitVal)
|
||||
{
|
||||
ppcState.quit = true;
|
||||
}
|
||||
|
||||
void Platform::debugBreak()
|
||||
{
|
||||
//DebugBreak();
|
||||
}
|
||||
|
||||
void Platform::forceShutdown(S32 returnValue)
|
||||
{
|
||||
//exit(returnValue);
|
||||
}
|
||||
306
platformPPC/ppcStrings.cc
Normal file
306
platformPPC/ppcStrings.cc
Normal file
|
|
@ -0,0 +1,306 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "PlatformPPC/platformPPC.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
char *dStrdup(const char *src)
|
||||
{
|
||||
char *buffer = new char[dStrlen(src) + 1];
|
||||
dStrcpy(buffer, src);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
char *dStrnew(const char *src)
|
||||
{
|
||||
char *buffer = new char[dStrlen(src) + 1];
|
||||
dStrcpy(buffer, src);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
char* dStrcat(char *dst, const char *src)
|
||||
{
|
||||
return strcat(dst,src);
|
||||
}
|
||||
|
||||
|
||||
S32 dStrcmp(const char *str1, const char *str2)
|
||||
{
|
||||
return strcmp(str1, str2);
|
||||
}
|
||||
|
||||
|
||||
S32 dStricmp(const char *str1, const char *str2)
|
||||
{
|
||||
char c1, c2;
|
||||
while (1)
|
||||
{
|
||||
c1 = tolower(*str1++);
|
||||
c2 = tolower(*str2++);
|
||||
if (c1 < c2) return -1;
|
||||
if (c1 > c2) return 1;
|
||||
if (c1 == 0) return 0;
|
||||
}
|
||||
}
|
||||
|
||||
S32 dStrncmp(const char *str1, const char *str2, U32 len)
|
||||
{
|
||||
return strncmp(str1, str2, len);
|
||||
}
|
||||
|
||||
S32 dStrnicmp(const char *str1, const char *str2, U32 len)
|
||||
{
|
||||
S32 i;
|
||||
char c1, c2;
|
||||
for (i=0; i<len; i++)
|
||||
{
|
||||
c1 = tolower(*str1++);
|
||||
c2 = tolower(*str2++);
|
||||
if (c1 < c2) return -1;
|
||||
if (c1 > c2) return 1;
|
||||
if (!c1) return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
char* dStrcpy(char *dst, const char *src)
|
||||
{
|
||||
return strcpy(dst,src);
|
||||
}
|
||||
|
||||
|
||||
char* dStrncpy(char *dst, const char *src, U32 len)
|
||||
{
|
||||
return strncpy(dst,src,len);
|
||||
}
|
||||
|
||||
|
||||
U32 dStrlen(const char *str)
|
||||
{
|
||||
return strlen(str);
|
||||
}
|
||||
|
||||
|
||||
char* dStrupr(char *str)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
*str = toupper(*str);
|
||||
str++;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
char* dStrlwr(char *str)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
*str = tolower(*str);
|
||||
str++;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
char* dStrchr(char *str, S32 c)
|
||||
{
|
||||
return strchr(str,c);
|
||||
}
|
||||
|
||||
|
||||
const char* dStrchr(const char *str, S32 c)
|
||||
{
|
||||
return strchr(str,c);
|
||||
}
|
||||
|
||||
const char* dStrrchr(const char *str, S32 c)
|
||||
{
|
||||
return strrchr(str,c);
|
||||
}
|
||||
|
||||
|
||||
char* dStrrchr(char *str, S32 c)
|
||||
{
|
||||
return strrchr(str,c);
|
||||
}
|
||||
|
||||
U32 dStrspn(const char *str, const char *set)
|
||||
{
|
||||
return(strspn(str, set));
|
||||
}
|
||||
|
||||
U32 dStrcspn(const char *str, const char *set)
|
||||
{
|
||||
return strcspn(str, set);
|
||||
}
|
||||
|
||||
|
||||
char* dStrstr(char *str1, char *str2)
|
||||
{
|
||||
return strstr(str1,str2);
|
||||
}
|
||||
|
||||
|
||||
const char* dStrstr(const char *str1, const char *str2)
|
||||
{
|
||||
return strstr(str1,str2);
|
||||
}
|
||||
|
||||
char* dStrtok(char *str, const char *sep)
|
||||
{
|
||||
return strtok(str, sep);
|
||||
}
|
||||
|
||||
|
||||
S32 dAtoi(const char *str)
|
||||
{
|
||||
return atoi(str);
|
||||
}
|
||||
|
||||
|
||||
F32 dAtof(const char *str)
|
||||
{
|
||||
return atof(str);
|
||||
}
|
||||
|
||||
bool dAtob(const char *str)
|
||||
{
|
||||
return !dStricmp(str, "true") || dAtof(str);
|
||||
}
|
||||
|
||||
bool dIsalnum(const char c)
|
||||
{
|
||||
return isalnum(c);
|
||||
}
|
||||
|
||||
bool dIsalpha(const char c)
|
||||
{
|
||||
return(isalpha(c));
|
||||
}
|
||||
|
||||
bool dIsspace(const char c)
|
||||
{
|
||||
return(isspace(c));
|
||||
}
|
||||
|
||||
bool dIsdigit(const char c)
|
||||
{
|
||||
return(isdigit(c));
|
||||
}
|
||||
|
||||
void dPrintf(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vprintf(format, args);
|
||||
}
|
||||
|
||||
S32 dVprintf(const char *format, void *arglist)
|
||||
{
|
||||
S32 len = vprintf(format, (char*)arglist);
|
||||
|
||||
// to-do
|
||||
// The intended behavior is to zero-terminate and not allow the overflow
|
||||
return (len);
|
||||
}
|
||||
|
||||
S32 dSprintf(char *buffer, U32 /*bufferSize*/, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
S32 len = vsprintf(buffer, format, args);
|
||||
|
||||
// to-do
|
||||
// The intended behavior is to zero-terminate and not allow the overflow
|
||||
return (len);
|
||||
}
|
||||
|
||||
|
||||
S32 dVsprintf(char *buffer, U32 /*bufferSize*/, const char *format, void *arglist)
|
||||
{
|
||||
S32 len = vsprintf(buffer, format, (char*)arglist);
|
||||
|
||||
// to-do
|
||||
// The intended behavior is to zero-terminate and not allow the overflow
|
||||
return (len);
|
||||
}
|
||||
|
||||
|
||||
S32 dSscanf(const char *buffer, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
return __vsscanf(buffer, format, args);
|
||||
}
|
||||
|
||||
S32 dFflushStdout()
|
||||
{
|
||||
return fflush(stdout);
|
||||
}
|
||||
|
||||
S32 dFflushStderr()
|
||||
{
|
||||
return fflush(stderr);
|
||||
}
|
||||
|
||||
void dQsort(void *base, U32 nelem, U32 width, S32 (QSORT_CALLBACK *fcmp)(const void *, const void *))
|
||||
{
|
||||
qsort(base, nelem, width, fcmp);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Mac Strinng conversion routines
|
||||
U8* str2p(const char *str)
|
||||
{
|
||||
static U8 buffer[256];
|
||||
str2p(str, buffer);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
U8* str2p(const char *str, U8 *p)
|
||||
{
|
||||
AssertFatal(dStrlen(str) <= 255, "str2p:: Max Pascal String length exceeded (max=255).");
|
||||
U8 *dst = p+1;
|
||||
U8 *src = (U8*)str;
|
||||
*p = 0;
|
||||
while(*src != '\0')
|
||||
{
|
||||
*dst++ = *src++;
|
||||
(*p) += 1;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
char* p2str(U8 *p)
|
||||
{
|
||||
static char buffer[256];
|
||||
p2str(p, buffer);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
char* p2str(U8 *p, char *dst_str)
|
||||
{
|
||||
U8 len = *p++;
|
||||
char *src = (char*)p;
|
||||
char *dst = dst_str;
|
||||
while (len--)
|
||||
{
|
||||
*dst++ = *src++;
|
||||
}
|
||||
*dst = '\0';
|
||||
return dst_str;
|
||||
}
|
||||
|
||||
67
platformPPC/ppcTime.cc
Normal file
67
platformPPC/ppcTime.cc
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "PlatformPPC/platformPPC.h"
|
||||
#include <time.h>
|
||||
#include <timer.h>
|
||||
|
||||
//--------------------------------------
|
||||
void Platform::getLocalTime(LocalTime <)
|
||||
{
|
||||
#pragma message("todo: Platform::getLocalTime")
|
||||
// struct tm *systime;
|
||||
// time_t long_time;
|
||||
//
|
||||
// time( &long_time ); // Get time as long integer.
|
||||
// systime = localtime( &long_time ); // Convert to local time.
|
||||
//
|
||||
// lt.sec = systime->tm_sec;
|
||||
// lt.min = systime->tm_min;
|
||||
// lt.hour = systime->tm_hour;
|
||||
// lt.month = systime->tm_mon;
|
||||
// lt.monthday = systime->tm_mday;
|
||||
// lt.weekday = systime->tm_wday;
|
||||
// lt.year = systime->tm_year;
|
||||
// lt.yearday = systime->tm_yday;
|
||||
// lt.isdst = systime->tm_isdst;
|
||||
|
||||
lt.sec = 0;
|
||||
lt.min = 0;
|
||||
lt.hour = 0;
|
||||
lt.month = 1;
|
||||
lt.monthday = 1;
|
||||
lt.weekday = 0;
|
||||
lt.year = 1999;
|
||||
lt.yearday = 1;
|
||||
lt.isdst = 0;
|
||||
}
|
||||
|
||||
|
||||
U32 GetMilliseconds()
|
||||
{
|
||||
UnsignedWide time;
|
||||
Microseconds(&time);
|
||||
return (time.hi*5000000) + (time.lo/1000);
|
||||
}
|
||||
|
||||
U32 Platform::getRealMilliseconds()
|
||||
{
|
||||
UnsignedWide time;
|
||||
Microseconds(&time);
|
||||
return (time.hi*5000000) + (time.lo/1000);
|
||||
}
|
||||
|
||||
U32 Platform::getVirtualMilliseconds()
|
||||
{
|
||||
return ppcState.currentTime;
|
||||
}
|
||||
|
||||
void Platform::advanceTime(U32 delta)
|
||||
{
|
||||
ppcState.currentTime += delta;
|
||||
}
|
||||
|
||||
22
platformPPC/ppcUtils.cc
Normal file
22
platformPPC/ppcUtils.cc
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "PlatformPPC/platformPPC.h"
|
||||
#include "PlatformPPC/ppcUtils.h"
|
||||
|
||||
void ppcGetWorkingDirectory()
|
||||
{
|
||||
WDPBRec rec;
|
||||
rec.ioCompletion = NULL;
|
||||
rec.ioNamePtr = NULL;
|
||||
|
||||
// get the current vRefNum and dirID
|
||||
PBHGetVolSync( &rec );
|
||||
|
||||
ppcState.volRefNum = rec.ioWDVRefNum;
|
||||
ppcState.dirID = rec.ioWDDirID;
|
||||
}
|
||||
15
platformPPC/ppcUtils.h
Normal file
15
platformPPC/ppcUtils.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _PPCUTILLS_H_
|
||||
#define _PPCUTILLS_H_
|
||||
|
||||
|
||||
void ppcGetWorkingDirectory();
|
||||
|
||||
|
||||
#endif // _H_PPCUTILS_
|
||||
1046
platformPPC/ppcWindow.cc
Normal file
1046
platformPPC/ppcWindow.cc
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue