t2 engine svn checkout

This commit is contained in:
loop 2024-01-07 04:36:33 +00:00
commit ff569bd2ae
988 changed files with 394180 additions and 0 deletions

View file

@ -0,0 +1 @@
(This file must be converted with BinHex 4.0) :!!"bFh*M8P0&4#!!N!F0Y'b-!*!%!3!!!!`1!!!,$J!!!DBS!5N"5S$@96#pSEj 9D`)!a%T%f"%q2!3!J(S"B")-4!abCA4bEbke,R*cFQ0bEA0dB@%aER4cG@ePF(P NCA)T!J"bFh*M8P0&4!%!rj!%!*!5TAi&A`#3"3)i[#"Zrr`6S#NJE[rm!5e3p9F "rm!S!J(d1J!e%D!U!8T&EH`e%U!MF!!d!f!Q5N4Q)M)"CK`e!bC3+%[Cr%X#!)! Y6#i#)"Z"R"'hlLi"CIDh@h-X!IqN,3(ra&`"!`J[Kia2!Me'rpl8![rc,@aH@`% Y9&m"(@cN%Ira%6!XG(KkRbF!!!%!!!IJ!!!-R!!!e!F!!`$4`!Brq@!)Irm`'2r rH"$rhkJMr[r%&rrch%ri'q*2XFrUMZr[mXrrr[12[rhjMcr'qCdqCrRr2q0rhEr "HhkIm,YqMr2qId#6pRricr`hf(rX(rrrf"[rrrJ2rrq`"Irri!2rqX!!qpm!!$h q!!!(i!!!2r`!!2rr!!(rri!(rrrJ$rrrm"rrrrJIrrri2rrrr(rrrrjrrrrqrj! `IrrrrRrrrrirrrrm(rrrq"rrrrJ2rrr`"rrri!(rri!!rrm!!$rm!*!%"d&38%` !N!8%!*!,pIG9KUUUUkU'@rIe!*!5pPYk-)#V@rH'9IQ!UUTEpJ#3$e@UUc#V9Ar i+P9996&9Ki#U93#3$2DUJ$&99P8a9999J)"EIrNU+hqVK[B!N!RfKS"EpP@'Ii# VXBHVXDZUIrG9J&9rK[B!N!IeUP@3"&c1L)K!3%!F3%"NL+U'A2C9UkVf!*!'KUT 99LZUUf3F(%!F(%!F3%"!C+Yr-BDUXB!!N!99IbY@@e9M3"a!3"a!N!6jqN!F3)L U9B"9UP8!!!$fUe[h+UU(3"a!(%"GAIRkA9hlA@3F3)HU+e99XIB!!&9EUe9rV%! F3"aGAI[mr+bXTV)cq8!F3)G9KSHU@`$eU[FUKV&N(%!FqPhl9LXVp[AfV)MjC"a !C+Vj+[QUp6'!@e@!Ud!F32PGJ9Eiq&eNC2Ifq[T!3"`Fr&5!-DVhIrJV-DTN($P GAB(jAB*!3%!FC$0M38!rJKaUT$&jX9@!UP99Ud"!A[TGq[YG3"a!("`FC$TFqrP G3%#V@e@!KSC999@V(&f"A9$lL%!F3%"!C'4GJB(jJN!F3+Z!99@VKP99-9e!qPe @+rYH(%!FAIb"q9C@qi(j3"a!Khp@@kUU9P9rKd$jAIIhr%"!(%!V+eeG9[HXL2T M3"baJ&9@X+ZUX+ZV3&eGpr@XC"a!3%"H3%$h!2R3L2P"(+ZUKUUUKS!VUSG!1IT G!2[G("a!3"a!q9Iep[Rm9iG!UkViKS"EUS#UUQ4!9ehfprkbC"a!3&f"AIAe9[R k1BLUKe@UA2HUKS#`Kd!jJ6)!pi,@V2hmqS')q9EkqPe!L,#NKUVhpBD!J+UV3%$ jJM,e!2Ah-[Vjq9hj9PeN(@5UUeZ!K[8!A+TFKXk(3$TFC'4Gq2FVqPe@9PeH3"a !Ul#!J+Vj!!$fUhpkKUU)4MVjAITA9PEjqS&H3%!F3)HUUeZ!U[B!!!"9KParUkU )3%"HC'4HC&dk3%!F(%#)X+YEJ+T9!*!&J+T@Il'UKf3F(%!F(%!F3"`FC+ZUUS# !USB!N!EfKUTFIkZ`UiGN3%!F3%"!C)HVKUZ!@kU(p3#3"rD'qB"rJ+UaUUZ(UiH (XDUVKB#'J)#'pJ#3#ICrKi#!J(qVKUUUXDU!UV"kKP@UJ2B!N!a9USD'J)"EJ*! %@i#VKS#U93#3$rC9USD!J&Z!J)DNKUUUA2B!N",e6eZ!UkUUUSC9-I8!N!`#!*! '$-99j9h!!*!*cGcHh&cG9G`!N!F-AXl0c-c-cYA!!*!&$&h-h-c-hGhFcHA!!*! %aGh-AGjHjHAFcFeF!*!%A-c0EZ-c)c[PAFcP`!!!"9cFAV)M)M)c1qh&9G!!!-h 0h,-M-M-ch6)qA0aF!!cYc&ib-MZpflkl)qA-aF!-hXhM)bZqlZl[h6)qaHA3"Fa 9XM,ElFc!cZfb1eh08-hFhM)p[Gc,ZmcG-b,Xh&cFc&XVZpfl-c+pXc5b0FeFeFc M1p[HXb-L+lhYXclFe9c-iVfmlM)c1l[Gfc)qh-jFc,2Eh1XM+qhGhYdb2Yh9AFh MfmcM-Mc,[FlYXbAFeH9Hil[!kb-cXc`0RY-Z999GaH1pX1SL-b2G$0lH2PaGeG9 E2Ec2qb-lf`$GfqAXAF9GAM[F$,rUlGlGhE2P99`&h9icfm!!c0hEhEXVAYe3$9e @ilfl[-cEhEXb2Ph9d!cYe9ilfphGhGXc)qAYeF!!aGhPicZlZlXc)MjHh9`!!!e Ge9kb)b)b-L[PAG93!!!-9GhPlV-b-c[ZAYeH!*!%aGhG99lZlPAPeGeF!*!%$0l GhH999G9GA&h!!*!&$&9GhC!%jGA!!*!(c&AGhG999G`!N!N-hH99A-!!N!K!!q! Hq$rmErjrrVrr[rfrrrIrrprlhrlqIrirr"ri"r!2m$rmIrjrr[q3%(rqIrirr!r `!!!"!*!&p[HVpk[jprB!N!EfUUZVIrL!IrQUUrB!!!$epS$fcUZaXD[hK[EfpJ! !KUTEUf4!3%$kC+ZUXDS!pU[hV%"GqrckqrP!USDap[AhX@6jq[[ip[IkC'6mqII i9DYHq[Z#3%"NBrZ#UhQaKP@VqPhl3&hmqI[j3+Z!UkZ`UrRhr%"!A[Ijq[QaUV# UUUVkp[kb3&hjp[ckUrLUpiD`32RhpIhmqIRkC,#NprDVcUTFqIVhqS&H3+Z`U[N !KUUaUQ4NC&e!C+Z`UUS!!2EfqE#aUkZ(XDZVJ2Ee!!!!pSHUKUZUXDU`UUVf!*! 'p[@!UkUNpIB!N!H!!!$GlHh0!!!!cHlFhHhX!!$0hZlZlGl!$GhV-cfqcG$1hM[ Zlp2XlGhVhHc1kllFh1[HXchH[Yh-lGillHdqhZlYcMc0lYlGhHh2mlh1lZh0kpc qlYfqh0lHhGhGXqlG$GlVZl1qlF!-cHlZkqlH!!$1hHhGlG`!!!$-hYc0!*!&4!I J'"JJ"(!1H"lm2rjrrj!%rRrm2hJHF!iJ""JB"q!(i"ri2rarrRrqrj!-IrjrrMr m(rJ(i!!(!!F!!!"%"q!I'$m-I`Cr![m"r`(r!B$rJ2q!rd$qB2i`r"Mi"q!(i"r i2rarrRrqrj!-IrjrrMrm(rJ(i!!(!!F!!!"%"q!Iq$rmArT2mSIKJm'"N!5$`BI K6r*IqMrm(rJ(i!IJ(rJrr(rqIrlrN!arrRrq2r`Iq!IJ!!F!"`!!!%3(i"Mi-2a JrN$qJ2q!ri$rr`(r!Im"I`*r"Mm-(aJ(i!IJ(rJrr(rqIrlrN!arrRrq2r`Iq!I J!!F!"`!!!!3!!3#!!!!!(J#!!*!)rj!%!43)3@*[GA3Z,Li!N!J9%%eeE(4T3RP dC80SBA*6CA4%9e*%!!!!G3"4)!!!!"@T-M!`-5"(BA*KCf9(B@ePFbjMEfeB9M% b)%9ZCfPZC5#T-M!`-5"(BA*KCf9(B@ePFbjMEfd08'pbG'P[ER-JU6)`-$%J8fP PFR*K)%pZE'PZC5`J5@jM,Je"E'`J8QPRD(4c)&*PFf9bGQ9N,J!!!"a(9M%b!!! !!8C548B!N!@!5801)`#3"B!!N!FK)&Ba-L"&EQGTEQ8JU6)`-$%J4f&bB@GP4f& YCA-ZBfpY!!!!!J#3"!%!!!!-$J!!#`i!!!'Q%mE*e!0H!!!!(!'#!!p*3diM!!! !JNC548B!!!#1GQ9bF`!!!*TTBf`i!!!!TQPME$3!!!#bD@0c)`!!!,jTBh-i!!! !bQPMFc3!!!$@689193!!!1*$99*6!!-!lNe#39)!!!%H9%e36!!!!5T#6N4-!!! "0Q0KFQ)!!!&#4eBa-J!!!8j03N06!!!"@J#!rrm!N!36aXGJ!)$rr`!!!336aXL X!!(rr`!!#NB6aXM!!)$rr`!!!3m6aXFB!)$rr`!!"4-6aXFF!)$rr`!!"aF6aXF 8!)$rr`!!"eX6aXF3!)$rr`!!#&m6aXFJ!)$rr`!!#JX6aXKB!-J!N!3*Za2'b+! !b3!%!!!)ia2'b*`!bJ!)!!!*+a2'b*J!b`!-!!!*Fa2'b*3!J2rr!!!+!a2'b)` !JJ!I!!!+,42'bB`!J2rr!!!+[a2'afJ!!2rr!!!+h`#3"a!!!!VM%mE(A!#!rrm !!!X)!*!%!f*L-30LBM)$BQ)c!f*L0!j2GfjPFL"bCA0[GA*MC3403N068G`:

View file

@ -0,0 +1,260 @@
//-----------------------------------------------------------------------------
// V12 Engine
//
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------
#include "PlatformMacCarb/platformMacCarb.h"
#include "console/console.h"
#include "PlatformMacCarb/platformAL.h"
#define TRY_REAL_OPENAL 0
#if TRY_REAL_OPENAL
#else
#define MILES_REENTRANT_CHECK
// Stub functions: ---------------------------------------------------------
// AL:
ALvoid stub_alEnable( ALenum ) {}
ALvoid stub_alDisable( ALenum ) {}
ALboolean stub_alIsEnabled( ALenum ) {return(AL_FALSE);}
ALvoid stub_alHint( ALenum , ALenum ) {}
ALboolean stub_alGetBoolean( ALenum ) {return(AL_FALSE);}
ALint stub_alGetInteger( ALenum ) {return(0);}
ALfloat stub_alGetFloat( ALenum ) {return(0.f);}
ALdouble stub_alGetDouble( ALenum ) {return(0.f);}
ALvoid stub_alGetBooleanv( ALenum, ALboolean* ) {}
ALvoid stub_alGetIntegerv( ALenum, ALint* ) {}
ALvoid stub_alGetFloatv( ALenum, ALfloat* ) {}
ALvoid stub_alGetDoublev( ALenum, ALdouble* ) {}
const ALubyte* stub_alGetString( ALenum pname )
{
switch(pname)
{
case AL_VENDOR: return (ALubyte*)"None";
case AL_VERSION: return (ALubyte*)"OpenAL 0.1";
case AL_RENDERER: return (ALubyte*)"None";
case AL_EXTENSIONS: return (ALubyte*)"";
}
return(0);
}
ALenum stub_alGetError( ALvoid ) {return(0);}
ALboolean stub_alIsExtensionPresent( const ALubyte* ) {return(AL_FALSE);}
ALvoid* stub_alGetProcAddress( const ALubyte* ) {return(0);}
ALenum stub_alGetEnumValue( const ALubyte* ) {return(0);}
ALvoid stub_alListenerf( ALenum, ALfloat ) {}
ALvoid stub_alListener3f( ALenum, ALfloat, ALfloat, ALfloat ) {}
ALvoid stub_alListenerfv( ALenum, ALfloat* ) {}
ALvoid stub_alGetListeneri( ALenum, ALint* ) {}
ALvoid stub_alGetListenerf( ALenum, ALfloat* ) {}
ALvoid stub_alGetListenerfv( ALenum, ALfloat* ) {}
ALvoid stub_alGenSources( ALsizei, ALuint* ) {}
ALvoid stub_alDeleteSources( ALsizei, ALuint* ) {}
ALboolean stub_alIsSource( ALuint ) {return(AL_FALSE);}
ALvoid stub_alSourcei( ALuint, ALenum, ALint ) {}
ALvoid stub_alSourcef( ALuint, ALenum, ALfloat ) {}
ALvoid stub_alSource3f( ALuint, ALenum, ALfloat, ALfloat, ALfloat ) {}
ALvoid stub_alSourcefv( ALuint, ALenum, ALfloat* ) {}
ALvoid stub_alGetSourcei( ALuint, ALenum, ALint* ) {}
ALvoid stub_alGetSourcef( ALuint, ALenum, ALfloat* ) {}
ALvoid stub_alGetSourcefv( ALuint, ALenum, ALfloat* ) {}
ALvoid stub_alSourcePlayv( ALuint, ALuint* ) {}
ALvoid stub_alSourceStopv( ALuint, ALuint* ) {}
ALvoid stub_alSourcePlay( ALuint ) {}
ALvoid stub_alSourcePause( ALuint ) {}
ALvoid stub_alSourceStop( ALuint ) {}
ALvoid stub_alGenBuffers( ALsizei, ALuint* ) {}
ALvoid stub_alDeleteBuffers( ALsizei, ALuint* ) {}
ALboolean stub_alIsBuffer( ALuint ) {return(AL_FALSE);}
ALvoid stub_alBufferData( ALuint, ALenum, ALvoid*, ALsizei, ALsizei ) {}
ALsizei stub_alBufferAppendData( ALuint, ALenum, ALvoid*, ALsizei, ALsizei ) {return(0);}
ALvoid stub_alGetBufferi( ALuint, ALenum, ALint* ) {}
ALvoid stub_alGetBufferf( ALuint, ALenum, ALfloat* ) {}
// ALC:
ALvoid* stub_alcCreateContext( ALint *) {return(0);}
ALCenum stub_alcMakeContextCurrent( ALvoid *) {return(ALC_INVALID);}
ALvoid* stub_alcUpdateContext( ALvoid * ) {return(0);}
ALCenum stub_alcDestroyContext( ALvoid * ) {return(ALC_INVALID);}
ALCenum stub_alcGetError( ALvoid ) {return(ALC_INVALID);}
const ALubyte* stub_alcGetErrorString( ALvoid ) {return(0);}
ALvoid* stub_alcGetCurrentContext( ALvoid ) {return(0);}
// ALUT:
void stub_alutInit( int *, char ** ) {}
void stub_alutExit( ALvoid ) {}
ALboolean stub_alutLoadWAV( const char *, ALvoid **, ALsizei *, ALsizei *, ALsizei *, ALsizei *) {return(AL_FALSE);}
// Extension: IASIG
ALvoid stub_alGenEnvironmentIASIG( ALsizei, ALuint* ) {}
ALvoid stub_alDeleteEnvironmentIASIG( ALsizei, ALuint*) {}
ALboolean stub_alIsEnvironmentIASIG( ALuint ) {return(AL_FALSE);}
ALvoid stub_alEnvironmentiIASIG( ALuint, ALenum, ALint ) {}
ALvoid stub_alEnvironmentfIASIG( ALuint, ALenum, ALfloat ) {}
ALvoid stub_alGetEnvironmentiIASIG_EXT( ALuint, ALenum, ALint * ) {}
ALvoid stub_alGetEnvironmentfIASIG_EXT( ALuint, ALenum, ALfloat * ) {}
// Extension: Dynamix
ALboolean stub_alBufferi_EXT( ALuint, ALenum, ALint ) { return(AL_FALSE); }
ALboolean stub_alBufferSyncData_EXT( ALuint, ALenum, ALvoid *, ALsizei, ALsizei ) {return(AL_FALSE); }
ALboolean stub_alBufferStreamFile_EXT( ALuint, const ALubyte * ) { return(AL_FALSE); }
ALboolean stub_alSourceCallback_EXT( ALuint, ALvoid * ) { return(AL_FALSE); }
ALvoid stub_alSourceResetEnvironment_EXT( ALuint ) {}
ALboolean stub_alContexti_EXT( ALenum, ALint) { return(AL_FALSE); }
ALboolean stub_alGetContexti_EXT( ALenum, ALint * ) { return(AL_FALSE); }
ALboolean stub_alGetContextstr_EXT( ALenum, ALuint, ALubyte ** ) { return(AL_FALSE); }
ALboolean stub_alCaptureInit_EXT( ALenum, ALuint, ALsizei ) { return(AL_FALSE); }
ALboolean stub_alCaptureDestroy_EXT( ALvoid ) { return(AL_FALSE); }
ALboolean stub_alCaptureStart_EXT( ALvoid ) { return(AL_FALSE); }
ALboolean stub_alCaptureStop_EXT( ALvoid ) { return(AL_FALSE); }
ALsizei stub_alCaptureGetData_EXT( ALvoid *, ALsizei, ALenum, ALuint ) { return(AL_FALSE); }
// declare OpenAL functions
#define AL_EXTENSION(ext_name) bool gDoesSupport_##ext_name = false;
#define AL_FUNCTION(fn_return,fn_name,fn_args) fn_return (*fn_name)fn_args = stub_##fn_name;
#define AL_EXT_FUNCTION(ext_name,fn_return,fn_name,fn_args) fn_return (*fn_name)fn_args = stub_##fn_name;
#include <openALFn.h>
// DLL's: ------------------------------------------------------------------
static bool findExtension( const char* name )
{
bool result = false;
if (alGetString != NULL)
{
result = dStrstr( (const char*)alGetString(AL_EXTENSIONS), name) != NULL;
}
return result;
}
static bool bindFunction( void *&fnAddress, const char *name )
{
fnAddress = NULL; //GetProcAddress( winState.hinstOpenAL, name );
if( !fnAddress )
Con::errorf(ConsoleLogEntry::General, " Missing OpenAL function '%s'", name);
return (fnAddress != NULL);
}
static void bindExtension( void *&fnAddress, const char *name, bool &supported )
{
if (supported)
{
bindFunction(fnAddress, name);
if (fnAddress == NULL)
supported = NULL;
}
else
fnAddress = NULL;
}
static bool bindDLLFunctions()
{
bool result = true;
#define AL_FUNCTION(fn_return,fn_name,fn_args) result &= bindFunction( *(void**)&fn_name, #fn_name);
#include <openALFn.h>
return result;
}
// Stub: -------------------------------------------------------------------
static void bindStubFunctions()
{
#define AL_EXTENSION(ext_name) gDoesSupport_##ext_name = false;
#define AL_FUNCTION(fn_return,fn_name,fn_parms) fn_name = stub_##fn_name;
#define AL_EXT_FUNCTION(ext_name,fn_return,fn_name,fn_args) fn_name = stub_##fn_name;
#include <openALFn.h>
}
// Miles: ------------------------------------------------------------------
#ifndef NO_MILES_OPENAL
#ifdef MILES_REENTRANT_CHECK
#define AL_FUNCTION(fn_return, fn_name, fn_args) extern fn_return miles_api_##fn_name fn_args;
#define AL_EXT_FUNCTION(ext_name, fn_return, fn_name, fn_args) extern fn_return miles_api_##fn_name fn_args;
#else
#define AL_FUNCTION(fn_return, fn_name, fn_args) extern fn_return miles_##fn_name fn_args;
#define AL_EXT_FUNCTION(ext_name, fn_return, fn_name, fn_args) extern fn_return miles_##fn_name fn_args;
#endif
#include <openALFn.h>
#endif
static void bindMilesFunctions()
{
#ifndef NO_MILES_OPENAL
#define AL_EXTENSION(ext_name) gDoesSupport_##ext_name = false;
#ifdef MILES_REENTRANT_CHECK
#define AL_FUNCTION(fn_return,fn_name,fn_parms) fn_name = miles_api_##fn_name;
#define AL_EXT_FUNCTION(ext_name, fn_return, fn_name, fn_args) fn_name = miles_api_##fn_name;
#else
#define AL_FUNCTION(fn_return,fn_name,fn_parms) fn_name = miles_##fn_name;
#define AL_EXT_FUNCTION(ext_name, fn_return, fn_name, fn_args) fn_name = miles_##fn_name;
#endif
#include <openALFn.h>
#endif
}
#endif // TRY REAL OPENAL
namespace Audio
{
static bool sStaticLibrary;
void libraryShutdown()
{
/*
if (winState.hinstOpenAL)
FreeLibrary(winState.hinstOpenAL);
winState.hinstOpenAL = NULL;
*/
bindStubFunctions();
sStaticLibrary = true;
}
bool libraryInit(const char *library)
{
libraryShutdown();
if(!library || !library[0])
return(false);
/*
// static drivers...
if(!dStricmp(library, "Miles"))
{
bindMilesFunctions();
return(true);
}
winState.hinstOpenAL = LoadLibrary( avar("%s.dll", library) );
if(winState.hinstOpenAL != NULL)
{
if(bindDLLFunctions())
{
sStaticLibrary = false;
return(true);
}
libraryShutdown();
}
*/
return(false);
}
void libraryInitExtensions()
{
// static library extensions are bound on libraryInit (need to be defined anyways...)
if(sStaticLibrary)
{
#define AL_EXTENSION(ext_name) gDoesSupport_##ext_name = findExtension( #ext_name );
#include <openALFn.h>
}
else
{
#define AL_EXTENSION(ext_name) gDoesSupport_##ext_name = findExtension( #ext_name );
#define AL_EXT_FUNCTION(ext_name, fn_return,fn_name,fn_args) bindExtension( *(void**)&fn_name, #fn_name, gDoesSupport_##ext_name );
#include <openALFn.h>
}
}
} // end namespace Audio

View file

@ -0,0 +1,79 @@
//-----------------------------------------------------------------------------
// V12 Engine
//
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------
#include "PlatformMacCarb/platformMacCarb.h"
#include "console/console.h"
#include "Core/stringTable.h"
#include <math.h>
#include <Gestalt.h>
// possibly useful gestalts:
//gestaltCarbonVersion
// gestaltNativeCPUtype = FOUR_CHAR_CODE('cput'), /* Native CPU type */
// gestaltNativeCPUfamily = FOUR_CHAR_CODE('cpuf'), /* Native CPU family */
// gestaltCPU601 = 0x0101, /* IBM 601 */
// gestaltCPU603 = 0x0103,
// gestaltCPU604 = 0x0104,
// gestaltCPU603e = 0x0106,
// gestaltCPU603ev = 0x0107,
// gestaltCPU750 = 0x0108, /* Also 740 - "G3" */
// gestaltCPU604e = 0x0109,
// gestaltCPU604ev = 0x010A /* Mach 5, 250Mhz and up */
// gestaltDisplayMgrVers = FOUR_CHAR_CODE('dplv') /* Display Manager version */
// gestaltDisplayMgrAttr = FOUR_CHAR_CODE('dply'), /* Display Manager attributes */
// gestaltLogicalRAMSize = FOUR_CHAR_CODE('lram') /* logical ram size -- can be lower than physram... */
// gestaltPhysicalRAMSize = FOUR_CHAR_CODE('ram ') /* physical RAM size */
// gestaltOSAttr = FOUR_CHAR_CODE('os '), /* o/s attributes */
// gestaltSysZoneGrowable = 0, /* system heap is growable */
// gestaltLaunchCanReturn = 1, /* can return from launch */
// gestaltLaunchFullFileSpec = 2, /* can launch from full file spec */
// gestaltLaunchControl = 3, /* launch control support available */
// gestaltTempMemSupport = 4, /* temp memory support */
// gestaltRealTempMemory = 5, /* temp memory handles are real */
// gestaltTempMemTracked = 6, /* temporary memory handles are tracked */
// gestaltIPCSupport = 7, /* IPC support is present */
// gestaltSysDebuggerSupport = 8 /* system debugger support is present */
// gestaltPowerMgrAttr = FOUR_CHAR_CODE('powr'), /* power manager attributes */
// gestaltPMgrExists = 0,
// gestaltPMgrCPUIdle = 1,
// gestaltPMgrSCC = 2,
// gestaltPMgrSound = 3,
// gestaltPMgrDispatchExists = 4,
// gestaltPMgrSupportsAVPowerStateAtSleepWake = 5
// gestaltPowerPCProcessorFeatures = FOUR_CHAR_CODE('ppcf'), /* Optional PowerPC processor features */
// gestaltPowerPCHasGraphicsInstructions = 0, /* has fres, frsqrte, and fsel instructions */
// gestaltPowerPCHasSTFIWXInstruction = 1, /* has stfiwx instruction */
// gestaltPowerPCHasSquareRootInstructions = 2, /* has fsqrt and fsqrts instructions */
// gestaltPowerPCHasDCBAInstruction = 3, /* has dcba instruction */
// gestaltPowerPCHasVectorInstructions = 4, /* has vector instructions */
// gestaltPowerPCHasDataStreams = 5 /* has dst, dstt, dstst, dss, and dssall instructions */
// should add multiprocessing check
// should add threadmgr check -- and we'll need optional code to do something diff.
Platform::SystemInfo_struct Platform::SystemInfo;
void Processor::init()
{
#pragma message("we need code to determine processor speed and specific processor class")
Platform::SystemInfo.processor.type = CPU_PowerPC_G3;
Platform::SystemInfo.processor.name = StringTable->insert("Unknown PowerPC");
Platform::SystemInfo.processor.mhz = 200; //!!!!!!!TBD - safe min value.
Platform::SystemInfo.processor.properties = CPU_PROP_PPCMIN;
Con::printf("Processor Init:");
Con::printf(" %s, %d Mhz", Platform::SystemInfo.processor.name, Platform::SystemInfo.processor.mhz);
if (Platform::SystemInfo.processor.properties & CPU_PROP_PPCMIN)
Con::printf(" FPU detected");
Con::printf(" ");
}

View file

@ -0,0 +1,322 @@
//-----------------------------------------------------------------------------
// V12 Engine
//
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------
#include "PlatformMacCarb/platformMacCarb.h"
#include "PlatformMacCarb/maccarbConsole.h"
#include "Platform/event.h"
#include "Platform/gameInterface.h"
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#if !__APPLE__
#include <SIOUX.h>
#endif
MacConsole *gConsole = NULL;
ConsoleFunction(enableWinConsole, void, 2, 2, "enableWinConsole(bool);")
{
argc;
gConsole->enable(dAtob(argv[1]));
}
void MacConsole::create()
{
gConsole = new MacConsole();
}
void MacConsole::destroy()
{
delete gConsole;
gConsole = NULL;
}
void MacConsole::enable(bool enabled)
{
consoleEnabled = enabled;
if(consoleEnabled)
{
// AllocConsole();
printf("Console Initialized.\n");
const char *title = Con::getVariable("Con::WindowTitle");
if (title && *title)
{
unsigned char t2[256];
str2p(title, t2);
#if !__APPLE__
SIOUXSetTitle(t2);
#endif
}
// stdOut = GetStdHandle(STD_OUTPUT_HANDLE);
// stdIn = GetStdHandle(STD_INPUT_HANDLE);
// stdErr = GetStdHandle(STD_ERROR_HANDLE);
//
printf("%s", Con::getVariable("Con::Prompt"));
}
}
bool MacConsole::isEnabled()
{
if ( gConsole )
return gConsole->consoleEnabled;
return false;
}
static void macConsoleConsumer(ConsoleLogEntry::Level, const char *line)
{
gConsole->processConsoleLine(line);
}
MacConsole::MacConsole()
{
for (S32 iIndex = 0; iIndex < MAX_CMDS; iIndex ++)
rgCmds[iIndex][0] = '\0';
iCmdIndex = 0;
consoleEnabled = false;
currMsg = NULL;
Con::addConsumer(macConsoleConsumer);
inpos = 0;
lineOutput = false;
// Con::addVariable("MacConsoleEnabled", consoleEnableCallback, "false");
#if !__APPLE__
// set up the SIOUX stuff here for now.
SIOUXSettings.standalone = false;
SIOUXSettings.setupmenus = false;
SIOUXSettings.initializeTB = false;
SIOUXSettings.asktosaveonclose = false;
SIOUXSettings.toppixel = 4 + GetMBarHeight();
SIOUXSettings.leftpixel = 4;
SIOUXSettings.columns = 120;
SIOUXSettings.rows = 40;
#endif
}
void MacConsole::printf(const char *s, ...)
{
// static char buffer[512];
int bytes;
va_list args;
va_start(args, s);
vprintf(s, args);
// vsprintf(buffer, s, args);
// WriteFile(stdOut, buffer, strlen(buffer), &bytes, NULL);
// FlushFileBuffers( stdOut );
}
void MacConsole::processConsoleLine(const char *consoleLine)
{
if(consoleEnabled)
{
inbuf[inpos] = 0;
if(lineOutput)
printf("%s\n", consoleLine);
else
printf("%c%s\n%s%s", '\r', consoleLine, Con::getVariable("Con::Prompt"), inbuf);
}
}
//--------------------------------------
bool MacConsole::handleEvent(const EventRecord *msg)
{
#if !__APPLE__
// if (MacConsole::isEnabled())
{
if (SIOUXHandleOneEvent((EventRecord*)msg))
{
currMsg = msg;
process();
currMsg = NULL;
return(true);
}
}
#endif
return(false);
}
//--------------------------------------
// on the mac, we call this after the console has consumed a keyboard event.
void MacConsole::process()
{
// for now, minimal processing.
if(consoleEnabled && currMsg)
{
/*
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(currMsg->what==keyDown || currMsg->what==autoKey)
{
U8 ascii = currMsg->message & charCodeMask;
U8 keycode = TranslateOSKeyCode( (currMsg->message & keyCodeMask) >> 8 );
switch (ascii)
{
// If no ASCII char, check if it's a handled virtual key
case 28:
case 29:
case 30:
case 31:
switch (keycode)
{
// UP ARROW
case KEY_UP:
{
// 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 KEY_DOWN:
{
// 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 KEY_LEFT:
break;
// RIGHT ARROW
case KEY_RIGHT:
break;
default :
break;
}
break;
// backspace???
case '\b':
if(inpos > 0)
{
outbuf[outpos++] = '\b';
outbuf[outpos++] = ' ';
outbuf[outpos++] = '\b';
inpos--;
}
break;
// some kind of CR/LF
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;
Game->postEvent(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++] = ascii;
outbuf[outpos++] = ascii;
break;
}
}
//}
//}
if(outpos)
{
outbuf[outpos] = 0;
printf("%s", outbuf);
}
//}
}
}

View file

@ -0,0 +1,56 @@
//-----------------------------------------------------------------------------
// V12 Engine
//
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------
#ifndef _MACCARBCONSOLE_H_
#define _MACCARBCONSOLE_H_
#define MAX_CMDS 10
#ifndef _CONSOLE_H_
#include "console/console.h"
#endif
#ifndef _EVENT_H_
#include "Platform/event.h"
#endif
#include <Events.h>
class MacConsole
{
bool consoleEnabled;
const EventRecord *currMsg;
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:
MacConsole();
void process();
void enable(bool);
void processConsoleLine(const char *consoleLine);
bool handleEvent(const EventRecord *msg);
static void create();
static void destroy();
static bool isEnabled();
};
extern MacConsole *gConsole;
#endif

View file

@ -0,0 +1,944 @@
//-----------------------------------------------------------------------------
// V12 Engine
//
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------
#include "platformMacCarb/platformMacCarb.h"
#include "core/fileio.h"
#include "core/tVector.h"
#include "core/stringTable.h"
#include "console/console.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <utime.h>
#pragma message("todo: file io needs some real work...")
// this is the main working dir path.
static StringTableEntry cwd = NULL;
static Boolean homeInPackage = FALSE;
//--------- Helper Functions ------------------------------
#define CAT_FOLDER_ATTRIB 0x10 // which bit stores file vs folder status.
#define CAT_IS_FOLDER(c) (((c).dirInfo.ioFlAttrib & CAT_FOLDER_ATTRIB) != 0)
// look for PC/unix delimiters
#define ISA_SLASH(c) ((c) == '\\' || (c) == '/')
// while mac paths are typically <255, I think HFS+ and UDF can have
// like 1024 or something. I'll cap to something larger, so we don't
// go running off into memory...
#define MAX_MAC_PATH_LONG 1200
// the str255 maxsize, allowing null termination and length byte.
#define MAX_MAC_PATH 254
//-----------------------------------------------------------------------------
static U32 makeMacPath(const char *src, char *dst)
{
U32 num = 0;
// don't need these aliases, but aids in debugging.
char *s = (char*)src, *d = dst;
// clear dest.
*d = '\0';
// if the first char is a slash, then it's a top-level folder
if (ISA_SLASH(*s))
{
// then no leading colon.
s++; // skip the slash now.
}
else // curr-dir-relative
{
// start new string with a colon.
*d++ = ':';
num++;
}
while(*s && num<MAX_MAC_PATH-1)
{
if (ISA_SLASH(*s))
*d++ = ':';
else
*d++ = *s;
s++;
num++;
}
// null terminate dest.
*d = 0;
return(num);
}
//-----------------------------------------------------------------------------
#ifdef __APPLE__
#include <CFBundle.h>
#define MACCARB_CONTENT_OUTSIDE_BUNDLE 1
#endif
void macGetHomeDirectory()
{
HGetVol(NULL, &platState.volRefNum, &platState.dirID);
// then, we need to check if we're in a package/bundle. if so, need to find what dir
// we are really in (potentially!!!!!tbd - we may WANT to do everything inside the
// bundle dir anyway, so...
#ifdef __APPLE__ // for now, only do this for OSX Project Builder compiles...
#if MACCARB_CONTENT_OUTSIDE_BUNDLE
CFBundleRef ref;
ref = CFBundleGetMainBundle();
if (ref)
{ // then we need to find the matching dirID.
CFURLRef url;
Boolean success = FALSE;
Boolean wantAbsolute = TRUE; // !!!!TBD for now, get the full path.
OSErr err;
CInfoPBRec catinfo;
Str255 dirname;
char wdbuf[2048];
U32 len = 0, totallen = 0;
url = CFBundleCopyBundleURL(ref);
success = CFURLGetFileSystemRepresentation(url, wantAbsolute, wdbuf, sizeof(wdbuf));
if (!success) return; // done.
// find the directory above the bundle's dir in the path.
// walk backward through the string to the next / or \ or :
len = dStrlen(wdbuf);
while(len)
{
len--;
if (wdbuf[len]=='/')
{ // stop here and null.
wdbuf[len]=0;
break;
}
}
if (len==0) return; // done.
// we now have the valid home path. save the workingdir refstring and copy into platState.
// offset the buffer by the length of the prefix "/Volumes" to strip it off...
dMemmove(platState.absAppPath, wdbuf+8, len-8);
// now, we need to decode what our parent dirID really is.
// convert into dirname as pstr.
totallen = makeMacPath(platState.absAppPath, &dirname[1]);
dirname[0] = totallen;
// clear the paramblock.
dMemset((void*)&catinfo, 0L, sizeof(catinfo));
catinfo.dirInfo.ioVRefNum = platState.volRefNum;
catinfo.dirInfo.ioDrParID = 0; // hoping the dirname suffices...
catinfo.dirInfo.ioDrDirID = 0; // hoping the dirname suffices...
catinfo.dirInfo.ioNamePtr = (StringPtr)&dirname;
// ask for info about the folder named in ioNamePtr by specifying zero as the dirindex.
catinfo.dirInfo.ioFDirIndex = 0;
err = PBGetCatInfoSync(&catinfo);
if (err!=noErr) return;
// now we have our REAL dirID.
platState.dirID = catinfo.dirInfo.ioDrDirID;
// can't do this here!
// cwd = StringTable->insert(wdbuf);
// Platform::getWorkingDirectory();
homeInPackage = TRUE;
}
else // we're not in a bundle
#endif
#endif
{ // run the normal working-dir-retrieve code.
// can't do this here!
// Platform::getWorkingDirectory();
}
}
//-----------------------------------------------------------------------------
bool dFileDelete(const char * name)
{
if(!name || (dStrlen(name) >= MAX_MAC_PATH))
return(false);
return(remove(name));
}
//-----------------------------------------------------------------------------
bool dFileTouch(const char *path)
{
if (!path || !*path)
return false;
OSErr err = noErr;
CInfoPBRec catinfo;
U8 macpath[MAX_MAC_PATH_LONG];
U32 size;
size = makeMacPath(path, (char*)(macpath+1));
if (size>MAX_MAC_PATH)
return false;
macpath[0] = size; // set PString length.
// clear the paramblock.
dMemset((void*)&catinfo, 0L, sizeof(catinfo));
// fill in paramblock.
catinfo.hFileInfo.ioVRefNum = macpath[1]==':'?platState.volRefNum:0;
catinfo.hFileInfo.ioDirID = macpath[1]==':'?platState.dirID:0;
catinfo.hFileInfo.ioNamePtr = macpath;
// need to clear the dir index.
catinfo.hFileInfo.ioFDirIndex = 0;
// get the current info on this file.
err = PBGetCatInfoSync(&catinfo);
if (err!=noErr)
return false; // !!!!TBD should log?
// get curr time and update the modified time field
unsigned long curtime;
GetDateTime(&curtime);
catinfo.hFileInfo.ioFlMdDat = curtime;
// reset the dirID, as it came back with the fileID.
catinfo.hFileInfo.ioDirID = macpath[1]==':'?platState.dirID:0;
// save it all back.
err = PBSetCatInfoSync(&catinfo);
if (err!=noErr)
return false; // !!!!TBD should log?
return true;
}
//-----------------------------------------------------------------------------
// 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];
char tmpFilename[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");
// if the string BEGINS with a slash, assume it's a full path reference
// otherwise, create a reference off the /Volumes dir + the working directory (since we stripped off /Volumes...)
#if __APPLE__
if (homeInPackage && filename[0]!='/')
{
dStrcpy(tmpFilename, "/Volumes");
dStrcat(tmpFilename, platState.absAppPath);
dStrcat(tmpFilename, "/");
dStrcat(tmpFilename, filename);
}
else
#endif
dStrcpy(tmpFilename, filename);
#if __APPLE__
dStrcpy(hostFilename, tmpFilename);
#else
// change from posix to Mac
makeMacPath(tmpFilename, hostFilename);
#endif
// 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!
}
}
#define HANDLE_CAST void *
#define INVALID_HANDLE_VALUE ((HANDLE_CAST)0L)
//-----------------------------------------------------------------------------
// Get the current position of the file pointer.
//-----------------------------------------------------------------------------
U32 File::getPosition() const
{
AssertFatal(Closed != currentStatus, "File::getPosition: file closed");
AssertFatal(INVALID_HANDLE_VALUE != (HANDLE_CAST)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));
}
//-----------------------------------------------------------------------------
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 = platState.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);
}
else
{
rInfo.pFullPath = StringTable->insert(basePath);
}
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;
}
//-----------------------------------------------------------------------------
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;
}
//-----------------------------------------------------------------------------
// either time param COULD be null.
//-----------------------------------------------------------------------------
bool Platform::getFileTimes(const char *path, FileTime *createTime, FileTime *modifyTime)
{
if (!path || !*path)
return false;
OSErr err = noErr;
CInfoPBRec catinfo;
U8 macpath[MAX_MAC_PATH_LONG];
U32 size;
size = makeMacPath(path, (char*)(macpath+1));
if (size>MAX_MAC_PATH)
return false;
macpath[0] = size; // set PString length.
// clear the paramblock.
dMemset((void*)&catinfo, 0L, sizeof(catinfo));
// fill in paramblock.
catinfo.hFileInfo.ioVRefNum = macpath[1]==':'?platState.volRefNum:0;
catinfo.hFileInfo.ioDirID = macpath[1]==':'?platState.dirID:0;
catinfo.hFileInfo.ioNamePtr = macpath;
err = PBGetCatInfoSync(&catinfo);
if (err!=noErr)
return false; // !!!!TBD should log?
if (createTime)
createTime->time = catinfo.hFileInfo.ioFlCrDat;
if (modifyTime)
modifyTime->time = catinfo.hFileInfo.ioFlMdDat;
return true;
}
//-----------------------------------------------------------------------------
bool Platform::createPath(const char *file)
{
char pathBuf[1024];
char dirBuf[256];
const char *dir;
U32 pathLen = 0;
S32 parentDirID = platState.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 = platState.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(platState.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::cdFileExists(const char *filePath, const char *volumeName, S32 serialNum)
{
return true; // !!!!!TBD
}
//-----------------------------------------------------------------------------
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 = platState.dirID;
if (in_pBasePath)
{
CInfoPBRec cinfo;
Str63 nameField;
OSErr result;
cinfo.hFileInfo.ioVRefNum = platState.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);
}
//-----------------------------------------------------------------------------
StringTableEntry Platform::getWorkingDirectory()
{
if (!cwd)
{
OSErr err;
CInfoPBRec catinfo;
Str255 dirname;
char cwd_buf[2048];
U32 len = 0, totallen = 0;
*cwd_buf = 0;
// clear the paramblock.
dMemset((void*)&catinfo, 0L, sizeof(catinfo));
catinfo.dirInfo.ioVRefNum = platState.volRefNum;
catinfo.dirInfo.ioDrParID = platState.dirID;
catinfo.dirInfo.ioNamePtr = (StringPtr)&dirname;
// ask for info about this directory.
catinfo.dirInfo.ioFDirIndex = -1;
do
{
dirname[0] = 0; // make sure to null the dirname!
// reset dir id each time through to the parent's id.
catinfo.dirInfo.ioDrDirID = catinfo.dirInfo.ioDrParID;
err = PBGetCatInfoSync(&catinfo);
if (err!=noErr) break;
// capture st255 len and null terminate it.
len = dirname[0]+1;
dirname[len] = 0;
// put a slash as the first char (eff converting it into a cstr...).
dirname[0] = '/';
// copy the current path forward in the buffer to allow us to prepend the new dir.
// MUST USE MEMMOVE, as we are copying in-place, and memmove allows moving within
// a given buffer. memcpy doesn't.
// and remember to allow for the null on the end...
if (totallen) dMemmove(cwd_buf + len, cwd_buf, totallen+1);
// copy the new path in, prepending the string. don't copy the null here...
dMemmove(cwd_buf, dirname, len);
// inc the total size.
totallen += len;
// make damn sure we're null terminated.
cwd_buf[totallen] = 0;
}
while (catinfo.dirInfo.ioDrDirID != fsRtDirID);
cwd = StringTable->insert(cwd_buf);
}
return cwd;
}
//-----------------------------------------------------------------------------
bool Platform::isFile(const char *path)
{
if (!path || !*path)
return false;
OSErr err = noErr;
CInfoPBRec catinfo;
U8 macpath[MAX_MAC_PATH_LONG];
U32 size;
size = makeMacPath(path, (char*)(macpath+1));
if (size>MAX_MAC_PATH)
return false;
macpath[0] = size; // set PString length.
// clear the paramblock.
dMemset((void*)&catinfo, 0L, sizeof(catinfo));
// fill in paramblock.
catinfo.dirInfo.ioVRefNum = macpath[1]==':'?platState.volRefNum:0;
catinfo.dirInfo.ioDrDirID = macpath[1]==':'?platState.dirID:0;
catinfo.dirInfo.ioNamePtr = macpath;
err = PBGetCatInfoSync(&catinfo);
if (err!=noErr)
return false; // !!!!TBD should log?
if (CAT_IS_FOLDER(catinfo))
return false;
return true;
}
//-----------------------------------------------------------------------------
bool Platform::isDirectory(const char *path)
{
if (!path || !*path)
return false;
OSErr err = noErr;
CInfoPBRec catinfo;
U8 macpath[MAX_MAC_PATH_LONG];
U32 size;
size = makeMacPath(path, (char*)(macpath+1));
if (size>MAX_MAC_PATH)
return false;
macpath[0] = size; // set PString length.
// clear the paramblock.
dMemset((void*)&catinfo, 0L, sizeof(catinfo));
// fill in paramblock.
catinfo.dirInfo.ioVRefNum = macpath[1]==':'?platState.volRefNum:0;
catinfo.dirInfo.ioDrDirID = macpath[1]==':'?platState.dirID:0;
catinfo.dirInfo.ioNamePtr = macpath;
err = PBGetCatInfoSync(&catinfo);
if (err!=noErr)
return false; // !!!!TBD should log?
if (CAT_IS_FOLDER(catinfo))
return true;
return false;
}
//-----------------------------------------------------------------------------
bool Platform::isSubDirectory(const char *pathParent, const char *pathSub)
{
char fullpath[MAX_MAC_PATH_LONG];
dStrcpyl(fullpath, sizeof(fullpath), pathParent, "/", pathSub, NULL);
return isDirectory((const char *)fullpath);
}

View file

@ -0,0 +1,14 @@
//-----------------------------------------------------------------------------
// V12 Engine
//
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------
#ifndef _MACCARBFILEIO_H_
#define _MACCARBFILEIO_H_
// only one exported func at the moment.
void macGetHomeDirectory(void);
#endif // _MACCARBFILEIO_H_

View file

@ -0,0 +1,182 @@
//-----------------------------------------------------------------------------
// V12 Engine
//
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------
#include "PlatformMacCarb/platformMacCarb.h"
#include "dgl/gFont.h"
#include "dgl/gBitmap.h"
#include "Math/mRect.h"
#include "console/console.h"
//#include <Fonts.h>
static GWorldPtr fontgw = NULL;
static Rect fontrect = {0,0,256,256};
static short fontdepth = 32;
static U8 rawmap[256*256];
void createFontInit(void);
void createFontShutdown(void);
S32 CopyCharToRaw(U8 *raw, PixMapHandle pm, const Rect &r);
// !!!!! TBD this should be returning error, or raising exception...
void createFontInit()
{
OSErr err = NewGWorld(&fontgw, fontdepth, &fontrect, NULL, NULL, keepLocal);
AssertWarn(err==noErr, "Font system failed to initialize GWorld.");
}
void createFontShutdown()
{
DisposeGWorld(fontgw);
fontgw = NULL;
}
U8 ColorAverage8(RGBColor &rgb)
{
return ((rgb.red>>8) + (rgb.green>>8) + (rgb.blue>>8)) / 3;
}
S32 CopyCharToRaw(U8 *raw, PixMapHandle pmh, const Rect &r)
{
// walk the pixmap, copying into raw buffer.
// we want bg black, fg white, which is opposite 'sign' from the pixmap (bg white, with black text)
// int off = GetPixRowBytes(pmh);
// U32 *c = (U32*)GetPixBaseAddr(pmh);
// U32 *p;
RGBColor rgb;
S32 i, j;
U8 val;
S32 lastRow = -1;
for (i = r.left; i <= r.right; i++)
{
for (j = r.top; j <= r.bottom; j++)
{
// p = (U32*)(((U8*)c) + (j*off)); // since rowbytes is bytes not pixels, need to convert to byte * before doing the math...
val = 0;
// if (((*p)&0x00FFFFFF)==0) // then black pixel in current port, so want white in new buffer.
GetCPixel(i, j, &rgb);
if ((ColorAverage8(rgb)>>2) < 2) // get's us some grays with a small slop factor.
{
val = 255;
lastRow = j; // track the last row in the rect that we actually saw an active pixel, finding descenders basically...
}
raw[i + (j<<8)] = val;
// p++;
}
}
return(lastRow);
}
GFont *createFont(const char *name, S32 size)
{
if(!name)
return NULL;
if(size < 1)
return NULL;
short fontid;
GetFNum(str2p(name), &fontid);
if (fontid == 0)
{
Con::errorf(ConsoleLogEntry::General,"Error creating font -- it doesn't exist: %s %d",name, size);
return(NULL);
}
Boolean aaWas;
S16 aaSize;
CGrafPtr savePort;
GDHandle saveGD;
GetGWorld(&savePort, &saveGD);
aaWas = IsAntiAliasedTextEnabled(&aaSize);
if (aaWas)
SetAntiAliasedTextEnabled(0, 0);
RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF};
RGBColor black = {0, 0, 0};
PixMapHandle pmh;
SetGWorld(fontgw, NULL);
PenNormal(); // reset pen attribs.
// shouldn't really need to do this, right?
RGBBackColor(&white);
RGBForeColor(&black);
// set proper font.
TextSize(size);
TextFont(fontid);
TextMode(srcCopy);
// get font info
int cx, cy, ry, my;
FontInfo fi;
GetFontInfo(&fi); // gets us basic glyphs.
cy = fi.ascent + fi.descent + fi.leading; // !!!! HACK. Not per-char-specific.
pmh = GetGWorldPixMap(fontgw);
GFont *retFont = new GFont;
Rect b = {0,0,0,0};
for(S32 i = 32; i < 256; i++)
{
// clear the port.
EraseRect(&fontrect);
// reset position to left edge, bottom of line for this font style.
MoveTo(0,cy);
// draw char & calc its pixel width.
DrawChar(i);
cx = CharWidth(i);
if (!LockPixels(pmh))
{
UpdateGWorld(&fontgw, fontdepth, &fontrect, NULL, NULL, keepLocal);
pmh = GetGWorldPixMap(fontgw);
// for now, assume we're good to go... TBD!!!!
LockPixels(pmh);
MoveTo(0,fi.ascent); // reset position to left edge, bottom of line for this font style.
DrawChar(i);
cx = CharWidth(i);
}
b.right = cx+1;
b.bottom = cy+2; // in case descenders drop too low, we want to catch the chars.
ry = CopyCharToRaw(rawmap, pmh, b);
UnlockPixels(pmh);
if (ry<0) // bitmap was blank.
{
Con::printf("Blank character %c", i);
if (cx)
retFont->insertBitmap(i, rawmap, 0, 0, 0, 0, 0, cx);
}
else
{
retFont->insertBitmap(i, rawmap, 256, cx+1, cy+2 /*ry*/, 0, fi.ascent+fi.descent, cx+1);
}
}
retFont->pack(cy, fi.ascent);
// if (actualChars==0)
// Con::errorf(ConsoleLogEntry::General,"Error creating font: %s %d",name, size);
//clean up local vars
if (aaWas)
SetAntiAliasedTextEnabled(aaWas, aaSize);
SetGWorld(savePort, saveGD);
return retFont;
}

Binary file not shown.

View file

@ -0,0 +1,265 @@
//-----------------------------------------------------------------------------
// V12 Engine
//
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------
#include "PlatformMacCarb/platformGL.h"
#include "PlatformMacCarb/platformMacCarb.h"
#include "console/console.h"
GLState gGLState;
bool gOpenGLDisablePT = false;
bool gOpenGLDisableCVA = false;
bool gOpenGLDisableTEC = false;
bool gOpenGLDisableARBMT = false;
bool gOpenGLDisableFC = true; //false;
bool gOpenGLDisableTCompress = false;
bool gOpenGLNoEnvColor = false;
float gOpenGLGammaCorrection = 0.5;
bool gOpenGLNoDrawArraysAlpha = false;
#if 1 // until we decide how to actually implement these...
GLboolean mglAvailVB() { return(false); }
GLint mglAllocVB(GLsizei size, GLint format, GLboolean preserve) { return(0); }
void* mglLockVB(GLint handle, GLsizei size) { return(NULL); }
void mglUnlockVB(GLint handle) {}
void mglSetVB(GLint handle) {}
void mglOffsetVB(GLint handle, GLuint offset) {}
void mglFillVB(GLint handle, GLint first, GLsizei count) {}
void mglFreeVB(GLint handle) {}
void mglFogCP(GLenum type, GLsizei stride, const GLvoid *pointer) {}
void mglColorTable(GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const GLvoid *table) {}
GLboolean glAvailableVertexBufferEXT() { return(false); }
GLint glAllocateVertexBufferEXT(GLsizei size, GLint format, GLboolean preserve) { return(0); }
void* glLockVertexBufferEXT(GLint handle, GLsizei size) { return(NULL); }
void glUnlockVertexBufferEXT(GLint handle) {}
void glSetVertexBufferEXT(GLint handle) {}
void glOffsetVertexBufferEXT(GLint handle, GLuint offset) {}
void glFillVertexBufferEXT(GLint handle, GLint first, GLsizei count) {}
void glFreeVertexBufferEXT(GLint handle) {}
void glFogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *pointer) {}
void glColorTableEXT(GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const GLvoid *table) {}
#endif
bool QGL_EXT_Init( )
{
// Load extensions...
//
const char* pExtString = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
// OpenGL Exists ========================================
if (glBegin == (void *)kUnresolvedCFragSymbolAddress)
{ // !!!!!!! TBD
Con::printf("OpenGL Init: Failed to find OpenGL system library.");
return(false);
}
// EXT_paletted_texture ========================================
// glColorTableEXT = NULL;
if (pExtString && dStrstr(pExtString, (const char*)"GL_EXT_paletted_texture") != NULL)
gGLState.suppPalettedTexture = true;
else
gGLState.suppPalettedTexture = false;
// EXT_compiled_vertex_array ========================================
/*
glLockArraysEXT = NULL;
glUnlockArraysEXT = NULL;
*/
#if FOR_ATI_TRUFORM_DEMO //!!!!!TBD!!!!!!!! HACK HACK HACK
if (pExtString && dStrstr(pExtString, (const char*)"GL_EXT_compiled_vertex_array") != NULL)
gGLState.suppLockedArrays = true;
else
#endif
gGLState.suppLockedArrays = false;
// ARB_multitexture ========================================
/*
glActiveTextureARB = NULL;
glClientActiveTextureARB = NULL;
glMultiTexCoord2fARB = NULL;
glMultiTexCoord2fvARB = NULL;
*/
if (pExtString && dStrstr(pExtString, (const char*)"GL_ARB_multitexture") != NULL)
gGLState.suppARBMultitexture = true;
else
gGLState.suppARBMultitexture = false;
// NV_vertex_array_range ========================================
/*
glVertexArrayRangeNV = dllVertexArrayRangeNV = NULL;
glFlushVertexArrayRangeNV = dllFlushVertexArrayRangeNV = NULL;
*/
/*
wglAllocateMemoryNV = NULL;
wglFreeMemoryNV = NULL;
*/
if (pExtString && dStrstr(pExtString, (const char*)"GL_NV_vertex_array_range") != NULL)
gGLState.suppVertexArrayRange = true;
else
gGLState.suppVertexArrayRange = false;
// EXT_fog_coord ========================================
/*
glFogCoordfEXT = NULL;
glFogCoordPointerEXT = NULL;
*/
if (pExtString && dStrstr(pExtString, (const char*)"GL_EXT_fog_coord") != NULL)
gGLState.suppFogCoord = true;
else
gGLState.suppFogCoord = false;
// ARB_texture_compression ========================================
/*
glCompressedTexImage3DARB = NULL;
glCompressedTexImage2DARB = NULL;
glCompressedTexImage1DARB = NULL;
glCompressedTexSubImage3DARB = NULL;
glCompressedTexSubImage2DARB = NULL;
glCompressedTexSubImage1DARB = NULL;
glGetCompressedTexImageARB = NULL;
*/
if (pExtString && dStrstr(pExtString, (const char*)"GL_ARB_texture_compression") != NULL)
gGLState.suppTextureCompression = true;
else
gGLState.suppTextureCompression = false;
// 3DFX_texture_compression_FXT1 ========================================
if (pExtString && dStrstr(pExtString, (const char*)"GL_3DFX_texture_compression_FXT1") != NULL)
gGLState.suppFXT1 = true;
else
gGLState.suppFXT1 = false;
// EXT_texture_compression_S3TC ========================================
if (pExtString && dStrstr(pExtString, (const char*)"GL_EXT_texture_compression_s3tc") != NULL)
gGLState.suppS3TC = true;
else
gGLState.suppS3TC = false;
// WGL_3DFX_gamma_control ========================================
/*
qwglGetDeviceGammaRamp3DFX = NULL;
qwglSetDeviceGammaRamp3DFX = NULL;
*/
if (pExtString && dStrstr(pExtString, (const char*)"WGL_3DFX_gamma_control" ) != NULL)
{
// qwglGetDeviceGammaRamp3DFX = (qwglGetDeviceGammaRamp3DFX_t) qwglGetProcAddress( "wglGetDeviceGammaRamp3DFX" );
// qwglSetDeviceGammaRamp3DFX = (qwglSetDeviceGammaRamp3DFX_t) qwglGetProcAddress( "wglSetDeviceGammaRamp3DFX" );
}
else
{
}
// EXT_vertex_buffer ========================================
/*
glAvailableVertexBufferEXT = NULL;
glAllocateVertexBufferEXT = NULL;
glLockVertexBufferEXT = NULL;
glUnlockVertexBufferEXT = NULL;
glSetVertexBufferEXT = NULL;
glOffsetVertexBufferEXT = NULL;
glFillVertexBufferEXT = NULL;
glFreeVertexBufferEXT = NULL;
*/
if (pExtString && dStrstr(pExtString, (const char*)"GL_EXT_vertex_buffer") != NULL)
{
gGLState.suppVertexBuffer = true;
AssertWarn(gGLState.suppVertexBuffer == false, "We're assuming no vertex bufffer support on Mac for now!");
}
else
gGLState.suppVertexBuffer = false;
// Binary states, i.e., no supporting functions ========================================
// EXT_packed_pixels
// EXT_texture_env_combine ...
gGLState.suppPackedPixels = pExtString? (dStrstr(pExtString, (const char*)"GL_EXT_packed_pixels") != NULL) : false;
gGLState.suppTextureEnvCombine = pExtString? (dStrstr(pExtString, (const char*)"GL_EXT_texture_env_combine") != NULL) : false;
gGLState.suppEdgeClamp = pExtString? (dStrstr(pExtString, (const char*)"GL_EXT_texture_edge_clamp") != NULL) : false;
gGLState.suppTexEnvAdd = pExtString? (dStrstr(pExtString, (const char*)"GL_ARB_texture_env_add") != NULL) : false;
gGLState.suppTexEnvAdd |= pExtString? (dStrstr(pExtString, (const char*)"GL_EXT_texture_env_add") != NULL) : false;
// Anisotropic filtering ========================================
gGLState.suppTexAnisotropic = pExtString? (dStrstr(pExtString, (const char*)"GL_EXT_texture_filter_anisotropic") != NULL) : false;
if (gGLState.suppTexAnisotropic)
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gGLState.maxAnisotropy);
// Texture combine units ========================================
if (gGLState.suppARBMultitexture)
glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gGLState.maxTextureUnits);
else
gGLState.maxTextureUnits = 1;
// Swap interval ========================================
/*
qwglSwapIntervalEXT = NULL;
*/
if (pExtString && dStrstr(pExtString, (const char*)"WGL_EXT_swap_control") != NULL)
gGLState.suppSwapInterval = true; //( qwglSwapIntervalEXT != NULL );
else
gGLState.suppSwapInterval = false;
// console out all the extensions...
Con::printf("OpenGL Init: Enabled Extensions");
if (gGLState.suppARBMultitexture) Con::printf(" ARB_multitexture (Max Texture Units: %d)", gGLState.maxTextureUnits);
if (gGLState.suppPalettedTexture) Con::printf(" EXT_paletted_texture");
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");
if (gGLState.suppTextureCompression) Con::printf(" ARB_texture_compression");
if (gGLState.suppS3TC) Con::printf(" EXT_texture_compression_s3tc");
if (gGLState.suppFXT1) Con::printf(" 3DFX_texture_compression_FXT1");
if (gGLState.suppTexEnvAdd) Con::printf(" (ARB|EXT)_texture_env_add");
if (gGLState.suppTexAnisotropic) Con::printf(" EXT_texture_filter_anisotropic (Max anisotropy: %f)", gGLState.maxAnisotropy);
if (gGLState.suppSwapInterval) Con::printf(" WGL_EXT_swap_control");
Con::warnf("OpenGL Init: Disabled Extensions");
if (!gGLState.suppARBMultitexture) Con::warnf(" ARB_multitexture");
if (!gGLState.suppPalettedTexture) Con::warnf(" EXT_paletted_texture");
if (!gGLState.suppLockedArrays) Con::warnf(" EXT_compiled_vertex_array");
if (!gGLState.suppVertexArrayRange) Con::warnf(" NV_vertex_array_range");
if (!gGLState.suppTextureEnvCombine) Con::warnf(" EXT_texture_env_combine");
if (!gGLState.suppPackedPixels) Con::warnf(" EXT_packed_pixels");
if (!gGLState.suppFogCoord) Con::warnf(" EXT_fog_coord");
if (!gGLState.suppTextureCompression) Con::warnf(" ARB_texture_compression");
if (!gGLState.suppS3TC) Con::warnf(" EXT_texture_compression_s3tc");
if (!gGLState.suppFXT1) Con::warnf(" 3DFX_texture_compression_FXT1");
if (!gGLState.suppTexEnvAdd) Con::warnf(" (ARB|EXT)_texture_env_add");
if (!gGLState.suppTexAnisotropic) Con::warnf(" EXT_texture_filter_anisotropic");
if (!gGLState.suppSwapInterval) Con::warnf(" WGL_EXT_swap_control");
Con::printf("");
// Set some console variables:
Con::setBoolVariable( "$FogCoordSupported", gGLState.suppFogCoord );
Con::setBoolVariable( "$TextureCompressionSupported", gGLState.suppTextureCompression );
Con::setBoolVariable( "$AnisotropySupported", gGLState.suppTexAnisotropic );
Con::setBoolVariable( "$PalettedTextureSupported", gGLState.suppPalettedTexture );
Con::setBoolVariable( "$SwapIntervalSupported", gGLState.suppSwapInterval );
if (!gGLState.suppPalettedTexture && Con::getBoolVariable("$pref::OpenGL::forcePalettedTexture",false))
{
Con::setBoolVariable("$pref::OpenGL::forcePalettedTexture", false);
Con::setBoolVariable("$pref::OpenGL::force16BitTexture", true);
}
return true;
}

View file

@ -0,0 +1,205 @@
// >>> MODIFIED CARBON.H FOR DIRECT INCLUSION IN V12 CODEBASE
// >>> INCLUDES MINIMUM-NECESSARY GENERAL-USE HEADERS.
#ifndef __MINCARBON__
#define __MINCARBON__
//#ifndef __CORESERVICES__
//#include <CoreServices.h>
//#endif
//#ifndef __APPLICATIONSERVICES__
//#include <ApplicationServices.h>
//#endif
#ifndef __EVENTS__
#include <Events.h>
#endif
#ifndef __PROCESSES__
#include <Processes.h>
#endif
#ifndef __NOTIFICATION__
#include <Notification.h>
#endif
//#ifndef __DRAG__
//#include <Drag.h>
//#endif
//#ifndef __ICONS__
//#include <Icons.h>
//#endif
#ifndef __CONTROLS__
#include <Controls.h>
#endif
#ifndef __APPEARANCE__
#include <Appearance.h>
#endif
#ifndef __MACWINDOWS__
#include <MacWindows.h>
#endif
#ifndef __TEXTEDIT__
#include <TextEdit.h>
#endif
#ifndef __MENUS__
#include <Menus.h>
#endif
#ifndef __DIALOGS__
#include <Dialogs.h>
#endif
//#ifndef __LISTS__
//#include <Lists.h>
//#endif
//#ifndef __CARBONEVENTS__
//#include <CarbonEvents.h>
//#endif
//#ifndef __TEXTSERVICES__
//#include <TextServices.h>
//#endif
#ifndef __SCRAP__
#include <Scrap.h>
#endif
//#ifndef __MACTEXTEDITOR__
//#include <MacTextEditor.h>
//#endif
//#ifndef __MACHELP__
//#include <MacHelp.h>
//#endif
#ifndef __CONTROLDEFINITIONS__
#include <ControlDefinitions.h>
#endif
//#ifndef __TSMTE__
//#include <TSMTE.h>
//#endif
//#ifndef __TRANSLATIONEXTENSIONS__
//#include <TranslationExtensions.h>
//#endif
//#ifndef __TRANSLATION__
//#include <Translation.h>
//#endif
//#ifndef __AEINTERACTION__
//#include <AEInteraction.h>
//#endif
//#ifndef __TYPESELECT__
//#include <TypeSelect.h>
//#endif
//#ifndef __INTERNETCONFIG__
//#include <InternetConfig.h>
//#endif
#ifndef __SOUND__
#include <Sound.h>
#endif
//#ifndef __OSA__
//#include <OSA.h>
//#endif
//#ifndef __OSACOMP__
//#include <OSAComp.h>
//#endif
//#ifndef __OSAGENERIC__
//#include <OSAGeneric.h>
//#endif
//#ifndef __APPLESCRIPT__
//#include <AppleScript.h>
//#endif
//#ifndef __ASDEBUGGING__
//#include <ASDebugging.h>
//#endif
//#ifndef __ASREGISTRY__
//#include <ASRegistry.h>
//#endif
//#ifndef __FINDERREGISTRY__
//#include <FinderRegistry.h>
//#endif
//#ifndef __PMAPPLICATION__
//#include <PMApplication.h>
//#endif
#ifndef __NAVIGATION__
#include <Navigation.h>
#endif
#ifndef __URLACCESS__
#include <URLAccess.h>
#endif
#ifndef __COLORPICKER__
#include <ColorPicker.h>
#endif
//#ifndef __CMCALIBRATOR__
//#include <CMCalibrator.h>
//#endif
//#ifndef __HTMLRENDERING__
//#include <HTMLRendering.h>
//#endif
//#ifndef __SPEECHRECOGNITION__
//#include <SpeechRecognition.h>
//#endif
//#ifndef __NSL__
//#include <NSL.h>
//#endif
//#ifndef __FINDBYCONTENT__
//#include <FindByContent.h>
//#endif
//#ifndef __KEYCHAINHI__
//#include <KeychainHI.h>
//#endif
//#ifndef __IBCARBONRUNTIME__
//#include <IBCarbonRuntime.h>
//#endif
//#ifndef __APPLEHELP__
//#include <AppleHelp.h>
//#endif
//#ifndef __ICAAPPLICATION__
//#include <ICAApplication.h>
//#endif
//#ifndef __ICADEVICE__
//#include <ICADevice.h>
//#endif
//#ifndef __ICACAMERA__
//#include <ICACamera.h>
//#endif
#endif /* __MINCARBON__ */

File diff suppressed because it is too large Load diff

View 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(" ");
}

View file

@ -0,0 +1,60 @@
//-----------------------------------------------------------------------------
// V12 Engine
//
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------
#include "PlatformMacCarb/platformMacCarb.h"
#include <stdlib.h>
#include <string.h>
//--------------------------------------
#ifdef new
#undef new
#endif
void* FN_CDECL operator new(dsize_t dt, void* ptr)
{
dMemset(ptr, 0xFF, dt);
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));
}

View file

@ -0,0 +1,55 @@
// macCarbNPatch.h
//
// mac specific implementation(s) of NPatch functionality
// since each platform might use slightly diff methods to control.
// current Mac NPatches is ATI TRUFORM implementation, accessed on OS9 via a
// back door method. OSX tests for the ATIX extension.
#if !__APPLE__
#define AGLSETINT_NPATCH_FLAG ((unsigned long)500)
#define AGLSETINT_NPATCH_LOD ((unsigned long)501)
#endif
// for the moment, this seems to be the best roundup of
// the npatch extensions on the PC.
#ifndef GL_ATIX_pn_triangles
#define GL_ATIX_pn_triangles 1
#define GL_PN_TRIANGLES_ATIX 0x6090
#define GL_MAX_PN_TRIANGLES_TESSELATION_LEVEL_ATIX 0x6091
#define GL_PN_TRIANGLES_POINT_MODE_ATIX 0x6092
#define GL_PN_TRIANGLES_NORMAL_MODE_ATIX 0x6093
#define GL_PN_TRIANGLES_TESSELATION_LEVEL_ATIX 0x6094
#define GL_PN_TRIANGLES_POINT_MODE_LINEAR_ATIX 0x6095
#define GL_PN_TRIANGLES_POINT_MODE_CUBIC_ATIX 0x6096
#define GL_PN_TRIANGLES_NORMAL_MODE_LINEAR_ATIX 0x6097
#define GL_PN_TRIANGLES_NORMAL_MODE_QUADRATIC_ATIX 0x6098
#if __APPLE__ // for the moment...
extern void glPNTrianglesiATIX(GLenum pname, GLint param);
extern void glPNTrianglesfATIX(GLenum pname, GLfloat param);
#endif
#endif
typedef void (*PFNGLPNTRIANGLESIATIPROC)(GLenum pname, GLint param);
//typedef void (APIENTRY *PFNGLPNTRIANGLESFATIPROC)(GLenum pname, GLfloat param);
#define GL_NPATCH_EXT_STRING "GL_ATIX_pn_triangles"
#define GL_NPATCH_SETINT_STRING "glPNTrianglesiATIX"
typedef PFNGLPNTRIANGLESIATIPROC PFNNPatchSetInt;
#define GETINT_NPATCH_MAX_LEVEL GL_MAX_PN_TRIANGLES_TESSELATION_LEVEL_ATIX
#define GL_NPATCH_FLAG GL_PN_TRIANGLES_ATIX
#define SETINT_NPATCH_LOD GL_PN_TRIANGLES_TESSELATION_LEVEL_ATIX
#define SETINT_NPATCH_POINTINTERP GL_PN_TRIANGLES_POINT_MODE_ATIX
#define SETINT_NPATCH_NORMALINTERP GL_PN_TRIANGLES_NORMAL_MODE_ATIX
#define NPATCH_POINTINTERP_MIN GL_PN_TRIANGLES_POINT_MODE_LINEAR_ATIX
#define NPATCH_POINTINTERP_MAX GL_PN_TRIANGLES_POINT_MODE_CUBIC_ATIX
#define NPATCH_NORMALINTERP_MIN GL_PN_TRIANGLES_NORMAL_MODE_LINEAR_ATIX
#define NPATCH_NORMALINTERP_MAX GL_PN_TRIANGLES_NORMAL_MODE_QUADRATIC_ATIX

View file

@ -0,0 +1,982 @@
//-----------------------------------------------------------------------------
// V12 Engine
//
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------
//!!!!!!!!! NOTE !!!!!!!!!
// Since the platform layers are currently separate, the Mac implementation takes
// extreme advantage of knowing that all values are already in 'network order', and
// that a byte array of an ip address is the same byte order as a U32 ip address.
// dc - need to inlucde OT stuff first, as V12 does some nasty stuff with redeclaring
// base new() implementation to take filename/linenum, and screws up the OT hdrs.
#include <OpenTransport.h>
#if __APPLE__
#include <OpenTransportProtocol.h>
#include <OpenTransportProviders.h>
#define IP_BROADCAST kIP_BROADCAST
#define IP_REUSEADDR kIP_REUSEADDR
#else
#include <OpenTptInternet.h>
#endif
#include "PlatformMacCarb/platformMacCarb.h"
#include "Platform/platform.h"
#include "Platform/event.h"
#include "console/console.h"
#include "Platform/gameInterface.h"
#include "Core/fileStream.h"
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;
}
};
// main control vars.
static Net::Error getLastError();
static S32 defaultPort = 28000;
static S32 netPort = 0;
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, };
// OpenTransport init controls.
static U32 OTReferenceCount = 0;
//======================================================================
// NEW MAC GLOBALS
//======================================================================
// structures we want/need to hang around.
static EndpointRef mainEndpoint = NULL;
static InetAddress mainPortAddr, destPortAddr;
static TBind tbRequest, tbBound;
static TUnitData tSend, tRecv;
static OTFlags tFlags = 0L;
// error holders.
static OSErr macErr = kOTNoError;
static const OSStatus kStatusFine = 0L;
static OSStatus macStatus = kStatusFine;
static OTResult macResult = kOTNoError;
#define HOSTFROMBYTES(a) (*((InetHost*)(a)))
static const InetHost broadcastIP = 0xFFFFFFFF;
static const InetHost loopbackIP = 0x7F000001; // 127.0.0.1
#if V12_DEBUG
static InetHost testloop = 0;
static U8 test2[4];
#endif
//======================================================================
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()
{
if ( OTReferenceCount == 0 )
if (InitOpenTransport() != kOTNoError)
return false;
#if V12_DEBUG // this just validates the byte ordering of host ips in a byte array.
OTInetStringToHost("127.0.2.1", &testloop);
OTInetStringToHost("127.0.2.1", (InetHost*)test2);
#endif
// successfully opened Open Transport, inncrement the reference count
OTReferenceCount++;
return true;
}
//======================================================================
void Net::shutdown()
{
while(connectionList)
Net::closeConnectTo(connectionList->tag);
// make sure that we shut down the main open port.
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, InetAddress *inAddr)
{
dMemset(inAddr, 0, sizeof(InetAddress));
inAddr->fAddressType = AF_INET;
inAddr->fHost = HOSTFROMBYTES(address->netNum);
inAddr->fPort = address->port;
}
//======================================================================
static void IPSocketToNetAddress(const InetAddress *inAddr, NetAddress *address)
{
address->type = NetAddress::IPAddress;
address->port = inAddr->fPort;
HOSTFROMBYTES(address->netNum) = inAddr->fHost;
}
//======================================================================
bool Net::openPort(S32 port)
{
// check if we have an endpoint already.
if (mainEndpoint != NULL) // just unbind it - no need to close & recreate...
OTUnbind(mainEndpoint);
else // need to create a new endpoint.
{
mainEndpoint = OTOpenEndpoint(OTCreateConfiguration(kUDPName), 0L, NULL, &macStatus);
if (mainEndpoint == NULL)
{
// !!!!!!TBD add error case.
// macStatus may need to be converted...
return false;
}
}
// then, bind the endpoint to the specified address.
// first, clear the bind value struct.
tbBound.qlen = 0;
tbBound.addr.maxlen = 0;
tbBound.addr.len = 0;
tbBound.addr.buf = NULL;
// then, setup the bind request struct to point to a port addr struct.
tbRequest.qlen = 4;
tbRequest.addr.maxlen = sizeof(InetAddress);
tbRequest.addr.len = sizeof(InetAddress);
tbRequest.addr.buf = (U8*)(&mainPortAddr);
// then, fill the port address structure for the given port.
// this will bind to whichever net device it first finds. !!!!!TBD????
OTInitInetAddress(&mainPortAddr, port, kOTAnyInetAddress);
// then do the bind. this is sync, obv.
macStatus = OTBind(mainEndpoint, &tbRequest, &tbBound);
if (macStatus != kStatusFine)
{
return false;
}
// now that we're bound, need to 'negotiate' for capabilities.
U8 omBuffer[kOTFourByteOptionSize];
TOptMgmt omRequest;
TOptMgmt omReply;
// alias the buffer for cleaner structure access.
TOption *omOpts = (TOption*)omBuffer;
// set up the request and reply structures.
omRequest.flags = T_NEGOTIATE;
omRequest.opt.len = kOTFourByteOptionSize;
omRequest.opt.buf = omBuffer;
omReply.opt.maxlen = kOTFourByteOptionSize;
omReply.opt.buf = omBuffer;
// main thing we need is BROADCAST cap.
omOpts->len = kOTFourByteOptionSize;
omOpts->status = 0;
omOpts->level = INET_IP; // we're dealing with IP protocols.
omOpts->name = IP_BROADCAST; // we want BROADCAST.
*(U32*)(omOpts->value) = TRUE; // we want broadcast to be ENABLED.
macStatus = OTOptionManagement(mainEndpoint, &omRequest, &omReply);
if(macStatus != kStatusFine)
{
// need to look deeper to see what really happened.
if(omOpts->status != T_SUCCESS)
{
// !!!!!TBD convert/handle the error!
}
return false;
}
// we also want REUSE_ADDR
omOpts->len = kOTFourByteOptionSize;
omOpts->status = 0;
omOpts->level = INET_IP; // we're dealing with IP protocols.
omOpts->name = IP_REUSEADDR; // we want REUSE_ADDR.
*(U32*)(omOpts->value) = TRUE; // we want broadcast to be ENABLED.
macStatus = OTOptionManagement(mainEndpoint, &omRequest, &omReply);
if(macStatus != kStatusFine)
{
// need to look deeper to see what really happened.
if(omOpts->status != T_SUCCESS)
{
// !!!!!TBD convert/handle the error!
}
return false;
}
// we're ready. hold onto assigned portnum in a global...
netPort = port;
return true;
}
//======================================================================
void Net::closePort()
{
// check if we have an endpoint.
if (mainEndpoint != NULL)
{
// for now, unbind it
OTUnbind(mainEndpoint);
netPort = 0;
// we'll try this for nicer cleanup...
OTCloseProvider(mainEndpoint);
mainEndpoint = NULL;
}
}
//======================================================================
Net::Error Net::sendto(const NetAddress *address, const U8 *buffer, S32 bufferSize)
{
if (!sendPackets)
return NoError;
if (mainEndpoint == NULL)
return NoError; // !!!!!TBD????
// clear any send struct fields that should be clean...
tSend.opt.len = 0;
// setup the send buffer.
tSend.udata.maxlen = bufferSize;
tSend.udata.len = bufferSize;
tSend.udata.buf = (U8*)buffer;
// setup the dest addr struct.
tSend.addr.maxlen = sizeof(InetAddress);
tSend.addr.len = sizeof(InetAddress);
tSend.addr.buf = (U8*)(&mainPortAddr);
// fill in the dest address.
netToIPSocketAddress(address, &mainPortAddr);
// then send it.
macResult = OTSndUData(mainEndpoint, &tSend);
if(macResult < 0)
{
//!!!!!!TBD handle error.
return UnknownError;
}
return NoError;
}
//======================================================================
static PacketReceiveEvent receiveEvent; // why create on stack each time...
//======================================================================
void Net::process()
{
S32 bytesRead;
if (mainEndpoint==NULL)
return;
macResult = kOTNoError;
while(1)
{
bytesRead = 0L;
// clear any send struct fields that should be clean...
tRecv.opt.len = 0;
// setup the recv buffer to point to the receive event packet..
tRecv.udata.maxlen = MaxPacketDataSize;
tRecv.udata.len = MaxPacketDataSize;
tRecv.udata.buf = receiveEvent.data;
// setup the dest addr struct.
tRecv.addr.maxlen = sizeof(InetAddress);
tRecv.addr.len = sizeof(InetAddress);
tRecv.addr.buf = (U8*)(&destPortAddr);
tFlags = 0L;
macResult = OTRcvUData(mainEndpoint, &tRecv, &tFlags);
if (macResult == kOTNoError)
bytesRead = tRecv.udata.len;
else
if (macResult < 0)
{
if (macResult == kOTNoDataErr)
break; // clean return.
else
{
// !!!!TBD error handling.
break;
}
}
// else // !!!!TBD????? what to do with positive error?
// {
// }
IPSocketToNetAddress(&destPortAddr, &receiveEvent.sourceAddress);
// check for loopback.
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;
// validate that we read something, else loop again.
if (bytesRead <= 0)
continue;
// post the received data.
receiveEvent.size = PacketReceiveEventHeaderSize + bytesRead;
Game->postEvent(receiveEvent);
}
// !!!!!!TBD
// may need to convert macResult into another variable
// for referencing error later on...
}
// THE NEXT SET OF METHODS ARE FOR HANDLING TCP-STREAM PORTS.
//======================================================================
//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;
}
//======================================================================
NetSocket 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;
}
//======================================================================
NetSocket Net::openConnectTo(const char *stringAddress)
{
nextConnectionId++;
if(!sendPackets)
return nextConnectionId;
Connection *conn = newConnection(nextConnectionId);
conn->listenConnection = false;
conn->prevState = ConnectedNotifyEvent::DNSResolved;
conn->state = ConnectedNotifyEvent::DNSResolved;
conn->socket = openSocket();
NetAddress netaddr;
connect(conn->socket, &netaddr);
setBlocking(conn->socket, false);
//threadHandle = CreateThread(NULL, 0, connectThreadFunction, (LPVOID) conn, 0, &threadId);
//CloseHandle(threadHandle);
conn->state = ConnectedNotifyEvent::Connected;
return conn->tag;
}
#if later
//======================================================================
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;
Game->postEvent(event);
}
walk = &con->nextConnection;
}
else
{
if(con->state != con->prevState)
{
ConnectedNotifyEvent event;
event.tag = con->tag;
event.state = con->state;
Game->postEvent(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;
Game->postEvent(event);
}
else if(err != WouldBlock)
{
// bad news... this disconnected
ConnectedNotifyEvent event;
event.tag = con->tag;
event.state = ConnectedNotifyEvent::Disconnected;
Game->postEvent(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;
}
}
}
#endif
//======================================================================
void Net::closeConnectTo(NetSocket sock)
{
if(Game->isJournalReading())
return;
Connection **walk;
for(walk = &connectionList; *walk != NULL; walk = &(*walk)->nextConnection)
{
Connection *con = *walk;
if(con->tag == sock)
{
*walk = con->nextConnection;
closeSocket(con->socket);
break;
}
}
for(walk = &connectionTable[sock & ConnectionTableMask]; *walk != NULL; walk = &(*walk)->nextInTable)
{
Connection *con = *walk;
if(con->tag == sock)
{
*walk = con->nextInTable;
delete con;
return;
}
}
}
//======================================================================
Net::Error Net::sendtoSocket(NetSocket socket, const U8 *buffer, int bufferSize)
{
if(Game->isJournalReading())
{
U32 e;
Game->journalRead(&e);
return (Net::Error) e;
}
Net::Error e = send(socket, buffer, bufferSize);
if(Game->isJournalWriting())
Game->journalWrite(U32(e));
return e;
}
//======================================================================
NetSocket Net::openSocket()
{
return InvalidSocket;
#if later
SOCKET retSocket;
retSocket = socket(AF_INET, SOCK_STREAM, 0);
if(retSocket == INVALID_SOCKET)
return InvalidSocket;
else
return retSocket;
#endif
}
//======================================================================
Net::Error Net::closeSocket(NetSocket socket)
{
if(socket != InvalidSocket)
{
#if later
if(!closesocket(socket))
return NoError;
else
#endif
return getLastError();
}
else
return NotASocket;
}
//======================================================================
Net::Error Net::connect(NetSocket socket, const NetAddress *address)
{
if(address->type != NetAddress::IPAddress)
return WrongProtocolType;
#if later
SOCKADDR_IN socketAddress;
netToIPSocketAddress(address, &socketAddress);
if(!::connect(socket, (PSOCKADDR) &socketAddress, sizeof(socketAddress)))
return NoError;
#endif
return getLastError();
}
Net::Error Net::listen(NetSocket socket, S32 backlog)
{
#if later
if(!::listen(socket, backlog))
return NoError;
#endif
return getLastError();
}
//======================================================================
NetSocket Net::accept(NetSocket acceptSocket, NetAddress *remoteAddress)
{
#if later
SOCKADDR_IN socketAddress;
S32 addrLen = sizeof(socketAddress);
SOCKET retVal = ::accept(acceptSocket, (PSOCKADDR) &socketAddress, &addrLen);
if(retVal != INVALID_SOCKET)
{
IPSocketToNetAddress(&socketAddress, remoteAddress);
return retVal;
}
#endif
return InvalidSocket;
}
//======================================================================
Net::Error Net::bind(NetSocket socket, U16 port)
{
#if later
S32 error;
SOCKADDR_IN socketAddress;
dMemset((char *)&socketAddress, 0, sizeof(socketAddress));
socketAddress.sin_family = AF_INET;
// It's entirely possible that there are two NIC cards.
// We let the user specify which one the server runs on.
// thanks to [TPG]P1aGu3 for the name
const char* serverIP = Con::getVariable( "Host::BindAddress" );
// serverIP is guaranteed to be non-0.
AssertFatal( serverIP, "serverIP is NULL!" );
if( serverIP[0] != '\0' ) {
// we're not empty
socketAddress.sin_addr.s_addr = inet_addr( serverIP );
if( socketAddress.sin_addr.s_addr != INADDR_NONE ) {
Con::printf( "Binding server port to %s", serverIP );
} else {
Con::warnf( ConsoleLogEntry::General,
"inet_addr() failed for %s while binding!",
serverIP );
socketAddress.sin_addr.s_addr = INADDR_ANY;
}
} else {
Con::printf( "Binding server port to default IP" );
socketAddress.sin_addr.s_addr = INADDR_ANY;
}
socketAddress.sin_port = htons(port);
error = ::bind(socket, (PSOCKADDR) &socketAddress, sizeof(socketAddress));
if(!error)
return NoError;
#endif
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, &notblock);
// if(!error)
// return NoError;
return getLastError();
}
//======================================================================
Net::Error Net::send(NetSocket socket, const U8 *buffer, S32 bufferSize)
{
Net::Error e;
// e = ::send(socket, (const char*)buffer, bufferSize, 0);
return getLastError();
// return e;
}
//======================================================================
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;
/* this was for IPX only. !!!!tbd
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)
{
char sRemote[256]; // temporary space so we can muck with the inString.
char *sPort;
// clear destination.
dMemset((void*)address, 0, sizeof(NetAddress));
// assume IP if it doesn't have ipx: at the front.
if (dStrnicmp(addressString, "ipx:", 4))
{
if (!dStrnicmp(addressString, "ip:", 3))
addressString += 3; // eat off the ip:
if (dStrlen(addressString) > 255) // waaay too long.
return false;
dStrcpy(sRemote, addressString);
sPort = dStrchr(sRemote, ':');
if (sPort) // if non-null...
*sPort++ = 0; // null the : and set ahead past the :
// first, look for broadcast.
if(!dStricmp(sRemote, "broadcast"))
{
*((InetHost*)address->netNum) = broadcastIP;
}
else
{
// try to do a simple string convert, in hopes it's a dotted-numeral address.
OTInetStringToHost(sRemote, ((InetHost*)(address->netNum)));
// if host numbers are all zero, safe bet that we need to do DNS lookup...
if(*((InetHost*)address->netNum) == 0)
{
/* THIS WAS OLD CODE... NEED TO VERIFY OR REWRITE!!!!TBD
U8 dnsBuffer[1024];
TLookupRequest dnsRequest;
TLookupReply dnsReply;
MapperRef dns;
// create a mapper for DNS lookup
dns = OTOpenMapper(OTCreateConfiguration(kDNRName), 0, &macStatus);
// set the mapper to be sync and blocking, so we don't need callbacks
// !!!!TBD change to async handling of this!
if (macStatus == kOTNoError)
oterr = OTSetSynchronous(dns);
if (macStatus == kOTNoError)
oterr = OTSetBlocking(dns);
// then, if we haven't yet hit an error, do the DNS lookup.
if (macStatus == kOTNoError)
{
dMemset((void*)&dnsRequest, 0, sizeof(TLookupRequest));
dnsRequest.maxcnt = 1; // just looking for a single IP
dnsRequest.timeout = 5000; // # ms before we timeout.
dnsRequest.name.buf = sRemote;
dnsRequest.name.len = dStrlen(sRemote);
dMemset((char *)&dnsReply, 0, sizeof(TLookupReply));
dnsReply.names.maxlen = 1024;
dnsReply.names.buf = dnsBuffer;
macStatus = OTLookupName(dns, &dnsRequest, &dnsReply);
if (macStatus == kOTNoError)
{
if (!dnsReply.rspcount)
{
// !!!!TBD handle error of not found. hopefully, macStatus was set already.
}
else // copy over the result.
{
// address->netNumIP = ((InetAddress*)(((TLookupBuffer*)dnsBuffer)->fAddressBuffer));
}
}
}
// HERE we handle ALL drop through error cases.
// this way, it's handled in one place, and cleanup
// is simpler as well...
if (macStatus != kOTNoError)
{
//!!!!TBD -- handle the error by setting global lookup val.
}
// close down dns if valid.
if (dns != kOTInvalidMapperRef)
{
macStatus = OTCloseProvider(dns);
if (macStatus != kOTNoError)
{
// !!!! NOT SURE. we don't want to necessarily blow away
// the failure above with this one.
//!!!!TBD -- handle the error by setting global lookup val.
}
}
*/
// if((hp = gethostbyname(remoteAddr)) == NULL)
return false;
}
}
if (sPort)
address->port = dAtoi(sPort);
else
address->port = defaultPort;
address->type = NetAddress::IPAddress;
return true;
}
return false;
}
//======================================================================
void Net::addressToString(const NetAddress *address, char addressString[256])
{
addressString[0] = 0; // clear string...
if(address->type == NetAddress::IPAddress)
{
if (HOSTFROMBYTES(address->netNum) == broadcastIP)
dSprintf(addressString, 256, "IP:Broadcast:%d", address->port);
else
dSprintf(addressString, 256, "IP:%d.%d.%d.%d:%d",
address->netNum[0], address->netNum[1], address->netNum[2], address->netNum[3],
address->port);
}
}
//======================================================================
Net::Error getLastError()
{
return Net::UnknownError;
// S32 err = WSAGetLastError();
// switch(err)
// {
// case WSAEWOULDBLOCK:
// return Net::WouldBlock;
// default:
// return Net::UnknownError;
// }
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,38 @@
//-----------------------------------------------------------------------------
// V12 Engine
//
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------
#ifndef _MACCARBOGLVIDEO_H_
#define _MACCARBOGLVIDEO_H_
#ifndef _PLATFORMVIDEO_H_
#include "Platform/platformVideo.h"
#endif
class OpenGLDevice : public DisplayDevice
{
bool mCanChangeGamma;
bool mRestoreGamma;
U16 mOriginalRamp[256*3];
public:
OpenGLDevice();
void initDevice();
bool activate( U32 width, U32 height, U32 bpp, bool fullScreen );
void shutdown();
void destroy();
bool setScreenMode( U32 width, U32 height, U32 bpp, bool fullScreen, bool forceIt = false, bool repaint = true );
void swapBuffers();
const char* getDriverInfo();
bool getGammaCorrection(F32 &g);
bool setGammaCorrection(F32 g);
bool setVerticalSync( bool on );
static DisplayDevice* create();
};
#endif // _MACCARBOGLVIDEO_H_

View file

@ -0,0 +1,25 @@
//-----------------------------------------------------------------------------
// V12 Engine
//
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------
#include "PlatformMacCarb/platformMacCarb.h"
void Platform::postQuitMessage(const U32 in_quitVal)
{
platState.quit = true;
}
void Platform::debugBreak()
{
#pragma message("Platform::debugBreak NYI")
//DebugBreak();
}
void Platform::forceShutdown(S32 returnValue)
{
#pragma message("Platform::forceShutdown NYI")
//exit(returnValue);
}

View file

@ -0,0 +1,370 @@
//-----------------------------------------------------------------------------
// V12 Engine
//
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------
#include "PlatformMacCarb/platformMacCarb.h"
#include "platform/platform.h"
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
char *dStrdup_r(const char *src, const char *file, U32 line)
{
char *buffer = (char *) dMalloc_r(dStrlen(src) + 1, file, line);
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);
}
// concatenates a list of src's onto the end of dst
// the list of src's MUST be terminated by a NULL parameter
// dStrcatl(dst, sizeof(dst), src1, src2, NULL);
char* dStrcatl(char *dst, U32 dstSize, ...)
{
const char* src;
char *p = dst;
AssertFatal(dstSize > 0, "dStrcatl: destination size is set zero");
dstSize--; // leave room for string termination
// find end of dst
while (dstSize && *p++)
dstSize--;
va_list args;
va_start(args, dstSize);
// concatenate each src to end of dst
while ( (src = va_arg(args, const char*)) != NULL )
while( dstSize && *src )
{
*p++ = *src++;
dstSize--;
}
va_end(args);
// make sure the string is terminated
*p = 0;
return dst;
}
// copy a list of src's into dst
// the list of src's MUST be terminated by a NULL parameter
// dStrccpyl(dst, sizeof(dst), src1, src2, NULL);
char* dStrcpyl(char *dst, U32 dstSize, ...)
{
const char* src;
char *p = dst;
AssertFatal(dstSize > 0, "dStrcpyl: destination size is set zero");
dstSize--; // leave room for string termination
va_list args;
va_start(args, dstSize);
// concatenate each src to end of dst
while ( (src = va_arg(args, const char*)) != NULL )
while( dstSize && *src )
{
*p++ = *src++;
dstSize--;
}
va_end(args);
// make sure the string is terminated
*p = 0;
return dst;
}
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(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);
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;
}

View file

@ -0,0 +1,64 @@
//-----------------------------------------------------------------------------
// V12 Engine
//
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------
#include "PlatformMacCarb/platformMacCarb.h"
#include <time.h>
#include <timer.h>
#pragma message("time code needs eval -- may not be accurate in all cases, and might cause performance hit.")
//--------------------------------------
void Platform::getLocalTime(LocalTime &lt)
{
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;
}
U32 Platform::getTime()
{
time_t long_time;
time( &long_time );
return long_time;
}
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 platState.currentTime;
}
void Platform::advanceTime(U32 delta)
{
platState.currentTime += delta;
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,20 @@
//maccarb_common_prefix.h
// for Project Builder, not sure what the heck it sets.
//#ifndef __POWERPC__
//#define __POWERPC__ 1
//#endif
#define TARG_MACCARB 0x0104 // the carbon version # we are targeting.
#define TARG_MACANY 1
// activate custom features.
#define TRUFORM 1
#define TERRAIN_NORMALS 1 // which will allow Truform on terrain.
// defines for the mac headers to activate proper Carbon codepaths.
#define TARGET_API_MAC_CARBON 1
#define OTCARBONAPPLICATION 1 // means we can use the old-style funcnames

View file

@ -0,0 +1,21 @@
//maccarb_debug_prefix.h
#include "maccarb_common_prefix.h"
// our defines
#define V12_DEBUG 1
#define BUILD_SUFFIX "_DEBUG"
// turn these off for now.
//#define DEBUG 1
//#define ENABLE_ASSERTS 1
#define ITFDUMP_NOASM 1
//#define USEASSEMBLYTERRBLEND 1
#define PNG_NO_READ_tIME 1
#define PNG_NO_WRITE_TIME 1
#define NO_MILES_OPENAL 1

View file

@ -0,0 +1,19 @@
//maccarb_release_prefix.h
#include "maccarb_common_prefix.h"
// our defines
#define V12_NO_ASSERTS 1
#define BUILD_SUFFIX ""
#define ITFDUMP_NOASM 1
//#define USEASSEMBLYTERRBLEND 1
#define PNG_NO_READ_tIME 1
#define PNG_NO_WRITE_TIME 1
#define NO_MILES_OPENAL 1

View file

@ -0,0 +1,148 @@
//-----------------------------------------------------------------------------
// V12 Engine
//
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------
#ifndef _PLATFORMAL_H_
#define _PLATFORMAL_H_
#ifndef _PLATFORM_H_
#include "Platform/platform.h"
#endif
#define AL_NO_PROTOTYPES
#include <al/al.h>
#include <al/alc.h>
#include <al/alut.h>
// extra enums for win32/miles implementation
enum {
// error values
AL_CONTEXT_ALREADY_INSTANTIATED = 0xbaadf00d,
AL_ENVIRONMENT_ALREADY_INSTANTIATED,
AL_UNSUPPORTED,
AL_INVALID_BUFFER,
AL_ERROR,
// context extention
ALC_PROVIDER,
ALC_PROVIDER_COUNT,
ALC_PROVIDER_NAME,
ALC_SPEAKER,
ALC_SPEAKER_COUNT,
ALC_SPEAKER_NAME,
ALC_BUFFER_DYNAMIC_MEMORY_SIZE,
ALC_BUFFER_DYNAMIC_MEMORY_USAGE,
ALC_BUFFER_DYNAMIC_COUNT,
ALC_BUFFER_MEMORY_USAGE,
ALC_BUFFER_COUNT,
ALC_BUFFER_LATENCY,
// misc 3d params
AL_MIN_DISTANCE,
AL_MAX_DISTANCE, // DEFINE IS IN NEWEST OPENAL
AL_CONE_OUTER_GAIN,
// relative with pos(0,0,0) won't work for ambient sounds with miles
AL_SOURCE_AMBIENT, // DEFINE IS IN NEWEST OPENAL
AL_PAN,
// other extensions
AL_BUFFER_KEEP_RESIDENT,
AL_FORMAT_WAVE_EXT,
// Environment extensions:
AL_ENV_EFFECT_VOLUME_EXT,
AL_ENV_FLAGS_EXT,
AL_ENV_DAMPING_EXT,
AL_ENV_ENVIRONMENT_SIZE_EXT,
AL_ENV_ROOM_VOLUME_EXT,
};
enum {
// sample level environment:
AL_ENV_SAMPLE_REVERB_MIX_EXT = 0,
AL_ENV_SAMPLE_DIRECT_EXT,
AL_ENV_SAMPLE_DIRECT_HF_EXT,
AL_ENV_SAMPLE_ROOM_EXT,
AL_ENV_SAMPLE_ROOM_HF_EXT,
AL_ENV_SAMPLE_OBSTRUCTION_EXT,
AL_ENV_SAMPLE_OBSTRUCTION_LF_RATIO_EXT,
AL_ENV_SAMPLE_OCCLUSION_EXT,
AL_ENV_SAMPLE_OCCLUSION_LF_RATIO_EXT,
AL_ENV_SAMPLE_OCCLUSION_ROOM_RATIO_EXT,
AL_ENV_SAMPLE_ROOM_ROLLOFF_EXT,
AL_ENV_SAMPLE_AIR_ABSORPTION_EXT,
AL_ENV_SAMPLE_OUTSIDE_VOLUME_HF_EXT,
AL_ENV_SAMPLE_FLAGS_EXT,
AL_ENV_SAMPLE_COUNT,
};
// room types: same as miles/eax
enum {
AL_ENVIRONMENT_GENERIC = 0,
AL_ENVIRONMENT_PADDEDCELL,
AL_ENVIRONMENT_ROOM,
AL_ENVIRONMENT_BATHROOM,
AL_ENVIRONMENT_LIVINGROOM,
AL_ENVIRONMENT_STONEROOM,
AL_ENVIRONMENT_AUDITORIUM,
AL_ENVIRONMENT_CONCERTHALL,
AL_ENVIRONMENT_CAVE,
AL_ENVIRONMENT_ARENA,
AL_ENVIRONMENT_HANGAR,
AL_ENVIRONMENT_CARPETEDHALLWAY,
AL_ENVIRONMENT_HALLWAY,
AL_ENVIRONMENT_STONECORRIDOR,
AL_ENVIRONMENT_ALLEY,
AL_ENVIRONMENT_FOREST,
AL_ENVIRONMENT_CITY,
AL_ENVIRONMENT_MOUNTAINS,
AL_ENVIRONMENT_QUARRY,
AL_ENVIRONMENT_PLAIN,
AL_ENVIRONMENT_PARKINGLOT,
AL_ENVIRONMENT_SEWERPIPE,
AL_ENVIRONMENT_UNDERWATER,
AL_ENVIRONMENT_DRUGGED,
AL_ENVIRONMENT_DIZZY,
AL_ENVIRONMENT_PSYCHOTIC,
AL_ENVIRONMENT_COUNT
};
// declare OpenAL functions
#define AL_EXTENSION(ext_name) extern bool gDoesSupport_##ext_name;
#define AL_FUNCTION(fn_return,fn_name,fn_args) extern fn_return (FN_CDECL *fn_name)fn_args;
#define AL_EXT_FUNCTION(ext_name,fn_return,fn_name,fn_args) extern fn_return (FN_CDECL *fn_name)fn_args;
#ifndef _OPENALFN_H_
#include <openALFn.h>
//#include "OpenAL/win32/openALFn.h"
#endif
namespace Audio
{
bool libraryInit(const char *library);
void libraryInitExtensions();
void libraryShutdown();
inline bool doesSupportIASIG()
{
return 0; //gDoesSupport_AL_EXT_IASIG;
}
inline bool doesSupportDynamix()
{
return 0; //gDoesSupport_AL_EXT_DYNAMIX;
}
// helpers
F32 DBToLinear(F32 value);
F32 linearToDB(F32 value);
} // end namespace Audio
#endif // _H_PLATFORMAL_

View file

@ -0,0 +1,191 @@
//-----------------------------------------------------------------------------
// V12 Engine
//
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------
#ifndef _PLATFORMGL_H_
#define _PLATFORMGL_H_
// ON MAC, WE ARE USING THE STD APPLE OPENGL HDRS.
#include <gl.h>
#include <glu.h>
#include <glext.h>
// FROM HERE ON IS >NOT< IN APPLE OPENGL 1.2 SDK
#if defined(GL_GLEXT_VERSION) && (GL_GLEXT_VERSION<=6) && defined(GL_VERSION_1_2)
#ifndef GL_EXT_vertex_buffer
#define GL_EXT_vertex_buffer 1
// these are the V12-custom extensions. really only useful in external 3d driver.
#define GL_V12MTVFMT_EXT 0x8702
#define GL_V12MTNVFMT_EXT 0x8703
#define GL_V12FTVFMT_EXT 0x8704
#define GL_V12FMTVFMT_EXT 0x8705
#ifdef GL_GLEXT_PROTOTYPES
extern GLboolean APIENTRY glAvailableVertexBufferEXT();
extern GLint APIENTRY glAllocateVertexBufferEXT(GLsizei size, GLint format, GLboolean preserve);
extern void* APIENTRY glLockVertexBufferEXT(GLint handle, GLsizei size);
extern void APIENTRY glUnlockVertexBufferEXT(GLint handle);
extern void APIENTRY glSetVertexBufferEXT(GLint handle);
extern void APIENTRY glOffsetVertexBufferEXT(GLint handle, GLuint offset);
extern void APIENTRY glFillVertexBufferEXT(GLint handle, GLint first, GLsizei count);
extern void APIENTRY glFreeVertexBufferEXT(GLint handle);
#endif /* GL_GLEXT_PROTOTYPES */
typedef GLboolean (APIENTRY * PFNGLAVAILABLEVERTEXBUFFEREXTPROC) ();
typedef GLint (APIENTRY * PFNGLALLOCATEVERTEXBUFFEREXTPROC) (GLsizei size, GLint format, GLboolean preserve);
typedef void* (APIENTRY * PFNGLLOCKVERTEXBUFFEREXTPROC) (GLint handle, GLsizei size);
typedef void (APIENTRY * PFNGLUNLOCKVERTEXBUFFEREXTPROC) (GLint handle);
typedef void (APIENTRY * PFNGLSETVERTEXBUFFEREXTPROC) (GLint handle);
typedef void (APIENTRY * PFNGLOFFSETVERTEXBUFFEREXTPROC) (GLint handle, GLuint offset);
typedef void (APIENTRY * PFNGLFILLVERTEXBUFFEREXTPROC) (GLint handle, GLint first, GLsizei count);
typedef void (APIENTRY * PFNGLFREEVERTEXBUFFEREXTPROC) (GLint handle);
#endif
/* A forgotten token. */
#define GL_CLAMP_TO_EDGE_EXT 0x812F
#define UNSIGNED_SHORT_5_6_5 0x8363
#define UNSIGNED_SHORT_5_6_5_REV 0x8364
#endif // glexts < v6, gl v1.2 stuff needed additionally.
/*
* GL state information.
*/
struct GLState
{
bool suppARBMultitexture;
bool suppPackedPixels;
bool suppTexEnvAdd;
bool suppLockedArrays;
bool suppTextureEnvCombine;
bool suppVertexArrayRange;
bool suppFogCoord;
bool suppEdgeClamp;
bool suppTextureCompression;
bool suppS3TC;
bool suppFXT1;
bool suppTexAnisotropic;
bool suppPalettedTexture;
bool suppVertexBuffer;
bool suppSwapInterval;
unsigned int triCount[4];
unsigned int primCount[4];
unsigned int primMode; // 0-3
GLfloat maxAnisotropy;
GLint maxTextureUnits;
};
extern GLState gGLState;
extern bool gOpenGLDisablePT;
extern bool gOpenGLDisableCVA;
extern bool gOpenGLDisableTEC;
extern bool gOpenGLDisableARBMT;
extern bool gOpenGLDisableFC;
extern bool gOpenGLDisableTCompress;
extern bool gOpenGLNoEnvColor;
extern float gOpenGLGammaCorrection;
extern bool gOpenGLNoDrawArraysAlpha;
/*
* Inline state helpers.
*/
inline void dglSetRenderPrimType(unsigned int type)
{
gGLState.primMode = type;
}
inline void dglClearPrimMetrics()
{
for(int i = 0; i < 4; i++)
gGLState.triCount[i] = gGLState.primCount[i] = 0;
}
inline bool dglDoesSupportPalettedTexture()
{
return gGLState.suppPalettedTexture && (gOpenGLDisablePT == false);
}
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;
}
inline bool dglDoesSupportTextureCompression()
{
return gGLState.suppTextureCompression && (gOpenGLDisableTCompress == false);
}
inline bool dglDoesSupportS3TC()
{
return gGLState.suppS3TC;
}
inline bool dglDoesSupportFXT1()
{
return gGLState.suppFXT1;
}
inline bool dglDoesSupportTexEnvAdd()
{
return gGLState.suppTexEnvAdd;
}
inline bool dglDoesSupportTexAnisotropy()
{
return gGLState.suppTexAnisotropic;
}
inline bool dglDoesSupportVertexBuffer()
{
return false;
}
inline GLfloat dglGetMaxAnisotropy()
{
return gGLState.maxAnisotropy;
}
inline GLint dglGetMaxTextureUnits()
{
if (dglDoesSupportARBMultitexture())
return gGLState.maxTextureUnits;
else
return 1;
}
#endif

View file

@ -0,0 +1,65 @@
//-----------------------------------------------------------------------------
// V12 Engine
//
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------
#ifndef _PLATFORMMACCARB_H_
#define _PLATFORMMACCARB_H_
#if __APPLE__
#include <Carbon/Carbon.h>
#else
#include "platformMacCarb/macCarbHeaders.h"
#endif
#include <agl.h>
#ifndef _PLATFORM_H_
#include "platform/platform.h"
#endif
class MacCarbPlatState
{
public:
GDHandle hDisplay;
WindowPtr appWindow;
AGLDrawable drawable;
char appWindowTitle[256];
bool quit;
AGLPixelFormat fmt;
AGLContext ctx;
short volRefNum; // application volume/drive reference number
long dirID; // application directory id
char absAppPath[2048]; // app path - make it big enough!
S32 desktopBitsPixel;
S32 desktopWidth;
S32 desktopHeight;
U32 currentTime;
MacCarbPlatState();
};
extern MacCarbPlatState platState;
extern bool QGL_EXT_Init();
extern WindowPtr CreateOpenGLWindow( U32 width, U32 height, bool fullScreen );
extern WindowPtr CreateCurtain( U32 width, U32 height );
U32 GetMilliseconds();
U8* str2p(const char *str);
U8* str2p(const char *str, U8 *dst_p);
char* p2str(U8 *p);
char* p2str(U8 *p, char *dst_str);
U8 TranslateOSKeyCode(U8 vcode);
#endif //_PLATFORMMACCARB_H_