Source release of Wolfenstein 3D Classic Platinum for iOS, 1.1

This commit is contained in:
Travis Bradshaw
2012-01-31 16:55:36 -06:00
parent e20e553baf
commit a82aba6b94
421 changed files with 68803 additions and 0 deletions

172
wolf3d/code/env/angle.c vendored Normal file
View File

@@ -0,0 +1,172 @@
/*
Copyright (C) 2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* angle.h: Angle math routines.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* Portion of this code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#include "../wolfiphone.h"
/*
-----------------------------------------------------------------------------
Function: angle_diff -Finds the difference between two angles.
Parameters: angle1, angle2 -[in] Angles in Radians.
Returns:
Returns the absolute difference between two angles, this will always
be between 0 and 180 degrees.
Notes:
-----------------------------------------------------------------------------
*/
INLINECALL float angle_diff( float angle1, float angle2 )
{
float d;
if( angle1 > angle2 )
{
d = angle1 - angle2;
}
else
{
d = angle2 - angle1;
}
if( d > M_PI )
{
return 2 * M_PI - d;
}
else
{
return d;
}
}
/*
-----------------------------------------------------------------------------
Function: angle_wise -Clockwise distance between two angles.
Parameters: angle1, angle2 -[in] Angles in Radians.
Returns:
Returns the clockwise distance from angle2 to angle1, this may be
greater than 180 degrees.
Notes:
-----------------------------------------------------------------------------
*/
INLINECALL float angle_wise( float angle1, float angle2 )
{
if( angle1 > angle2 )
{
return angle1 - angle2;
}
else
{
return angle1 + 2 * M_PI - angle2;
}
}
/*
-----------------------------------------------------------------------------
Function: interpolate_angle -Linear interpolate between angle A and B by
fraction 'f'.
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
INLINECALL float interpolate_angle( float from, float to, float fraction )
{
float diff = angle_diff( from, to ) * fraction;
if( angle_wise( to, from ) >= M_PI )
{
return from - diff;
}
else
{
return from + diff;
}
}
/*
-----------------------------------------------------------------------------
Function: normalize_angle -
Parameters:
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
INLINECALL float normalize_angle( float angle )
{
while( angle < 0 )
{
angle += (2 * M_PI);
}
while( angle >= (2 * M_PI) )
{
angle -= (2 * M_PI);
}
return angle;
}
/*
-----------------------------------------------------------------------------
Function: LerpAngle -Linear interpolate allowing for the Modulo 360 problem.
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
INLINECALL float LerpAngle( float from, float to, float frac )
{
if( to - from > 180 )
{
to -= 360;
}
if( to - from < -180 )
{
to += 360;
}
return from + frac * (to - from);
}

53
wolf3d/code/env/angle.h vendored Normal file
View File

@@ -0,0 +1,53 @@
/*
Copyright (C) 2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* angle.h: Angle math routines.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* Portion of this code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#ifndef __ANGLE_H__
#define __ANGLE_H__
#define DEG2RAD( a ) ( (a) * 0.01745329251994329576f ) // a * M_PI / 180.0f
#define RAD2DEG( a ) ( (int)((a) / 0.01745329251994329576f) ) // a * 180.0f / M_PI
#define ANGLE2SHORT( x ) ( (int)((x) * 65536 / 360) & 65535 )
#define SHORT2ANGLE( x ) ( (x) * (360.0 / 65536) )
extern float angle_diff( float angle1, float angle2 );
extern float angle_wise( float angle1, float angle2 );
extern float interpolate_angle( float from, float to, float fraction );
extern float normalize_angle( float angle );
extern float LerpAngle( float from, float to, float frac );
#endif /* __ANGLE_H__ */

50
wolf3d/code/env/app_def.h vendored Normal file
View File

@@ -0,0 +1,50 @@
/*
Copyright (C) 2004-2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* app_def.h: Engine interface to game layer.
*
*/
#ifndef __APP_DEF__
#define __APP_DEF__
#define WOLFENSTEIN3D 1
#if WOLFENSTEIN3D
#define APP_VERSION "0.01i"
#define RELEASENAME "Nebka"
#define BASEDIRNAME "base"
#define GAME_NAME "Wolfenstein 3-D Redux"
#endif /* WOLFENSTEIN3D */
#endif /* __APP_DEF__ */

60
wolf3d/code/env/arch.c vendored Normal file
View File

@@ -0,0 +1,60 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* arch.c: Portable byte swapping.
*
* Author: Id Software, Inc.
* Date: 1997-2001
*
*/
#include "../wolfiphone.h"
/*
-----------------------------------------------------------------------------
Function: FloatSwap -Endian byte swapping on Float value.
Parameters: f -[in] Float value to byte swap.
Returns: Byte swapped float value.
Notes:
-----------------------------------------------------------------------------
*/
INLINECALL float FloatSwap( float f )
{
union
{
float f;
W8 b[ 4 ];
} dat1, dat2;
dat1.f = f;
dat2.b[ 0 ] = dat1.b[ 3 ];
dat2.b[ 1 ] = dat1.b[ 2 ];
dat2.b[ 2 ] = dat1.b[ 1 ];
dat2.b[ 3 ] = dat1.b[ 0 ];
return dat2.f;
}

273
wolf3d/code/env/arch.h vendored Normal file
View File

@@ -0,0 +1,273 @@
/*
Copyright (C) 2004 Michael Liebscher <johnnycanuck@users.sourceforge.net>
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* arch.h: System dependant #defines and macros.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* Portion of this code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#ifndef __ARCH_H__
#define __ARCH_H__
// Define BUILDSTRING and CPUSTRING based on platform
#ifdef _WIN32
#ifdef _DEBUG
#define BUILDSTRING "Win32 DEBUG"
#else
#define BUILDSTRING "Win32 RELEASE"
#endif
#ifdef _M_IX86
#define CPUSTRING "x86"
#elif defined _M_ALPHA
#define CPUSTRING "AXP"
#else
#define CPUSTRING "Unknown CPU"
#endif
#elif defined __linux__
#define BUILDSTRING "Linux"
#ifdef __i386__
#define CPUSTRING "i386"
#elif defined __alpha__
#define CPUSTRING "AXP"
#else
#define CPUSTRING "Unknown CPU"
#endif
#elif defined __FreeBSD__
#define BUILDSTRING "FreeBSD"
#ifdef __i386__
#define CPUSTRING "i386"
#else
#define CPUSTRING "Unknown CPU"
#endif
#elif defined __sun__
#define BUILDSTRING "Solaris"
#ifdef __i386__
#define CPUSTRING "i386"
#else
#define CPUSTRING "sparc"
#endif
#elif defined MACOS
#define BUILDSTRING "MAC"
#ifdef __powerpc__
#define CPUSTRING "PowerPC"
#else
#define CPUSTRING "Unknown CPU"
#endif
#else
#define BUILDSTRING "Unknown OS"
#define CPUSTRING "Unknown CPU"
#endif /* if WIN32 else __linux__ else __FreeBSD__ else __sun__ else MACOS */
/*
correct numeric types: W8, SW8, W16, SW16, W32, SW32, W64, SW64
correct misc types: void, float, _boolean
s -signed
XX -Number of bits
*/
#if( __GNUC__ || __WATCOMC__ || _MSC_VER )
typedef unsigned char W8, *PW8;
typedef signed char SW8, *PSW8;
typedef unsigned short W16, *PW16;
typedef signed short SW16, *PSW16;
typedef unsigned long W32, *PW32;
typedef signed long SW32, *PSW32;
#if( __GNUC__ )
typedef unsigned long long W64, *PW64;
typedef long long SW64, *PSW64;
#elif( _MSC_VER || __WATCOMC__ )
typedef unsigned __int64 W64, *PW64;
typedef __int64 SW64, *PSW64;
#else
#error "please define W64"
#endif
#else
#error "Unknown compiler, please define basic types"
#endif
/* Define NULL pointer value */
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif /* NULL */
/* Define INLINECALL keyword */
#ifndef INLINECALL
#if defined(__cplusplus) || defined(__GNUC__)
#define INLINECALL inline
#elif defined(_WIN32) && !defined(__WATCOMC__)
#define INLINECALL __inline
#else
#define INLINECALL /* Not supported */
#endif
#endif /* INLINECALL */
typedef W8 colour3_t[ 3 ]; // RGB
typedef W8 colour4_t[ 4 ]; // RGBA
typedef W32 COLOURVAL, *PCOLOURVAL; // Represents a 32-bit colour value.
#ifdef _WIN32
#define vsnprintf _vsnprintf
#endif
typedef W8 _boolean;
#define false 0
#define true 1
//enum { false = 0,
// true = 1 };
#define ShortSwap( x ) ( ( (((W16) (x)) & 0x00FF) << 8 ) | ( (((W16) (x))& 0xFF00) >> 8) )
#define LongSwap( x ) ( ( ((W32) (x)) & 0xFF000000) >> 24 ) | ( ((( (W32) (x) ) & 0xFF0000) >> 8) ) | ( ((( (W32) (x) ) & 0xFF00) << 8 ) ) | ( (( (W32) (x) ) & 0xFF) << 24 )
#if defined( IPHONE) || defined(__i386__) || defined(_M_IX86) // Little endian
#define BigShort( x ) ShortSwap( x )
#define LittleShort( x ) ( x )
#define BigLong( x ) LongSwap( x )
#define LittleLong( x ) ( x )
#define BigFloat( x ) FloatSwap( x )
#define LittleFloat( x ) ( x )
#else // Big endian
#define BigShort( x ) ( x )
#define LittleShort( x ) ShortSwap( x )
#define BigLong( x ) ( x )
#define LittleLong( x ) LongSwap( x )
#define BigFloat( x ) ( x )
#define LittleFloat( x ) FloatSwap( x )
#endif
#endif /* __ARCH_H__ */

1195
wolf3d/code/env/cmd.c vendored Normal file

File diff suppressed because it is too large Load Diff

150
wolf3d/code/env/cmd.h vendored Normal file
View File

@@ -0,0 +1,150 @@
/*
Copyright (C) 2004 Michael Liebscher <johnnycanuck@users.sourceforge.net>
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* cmd.h: Command text buffering and command execution.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
/*
Notes:
Any number of commands can be added in a frame, from several different sources.
Most commands come from either keybindings or console line input, but remote
servers can also send across commands and entire text files can be execed.
The + command line options are also added to the command buffer.
The game starts with a Cbuf_AddText( "exec DEFAULT.CFG\n" ); Cbuf_Execute();
*/
#ifndef __CMD_H__
#define __CMD_H__
#include "arch.h"
typedef enum {
EXEC_NOW, // don't return until completed
EXEC_INSERT, // insert at current position, but don't run yet
EXEC_APPEND // add to end of the command buffer
} execwhen_t;
extern void Cbuf_AddText( const char *text );
// as new commands are generated from the console or keybindings,
// the text is added to the end of the command buffer.
extern void Cbuf_InsertText( char *text );
// when a command wants to issue other commands immediately, the text is
// inserted at the beginning of the buffer, before any remaining unexecuted
// commands.
extern void Cbuf_ExecuteText( execwhen_t exec_when, char *text );
// this can be used in place of either Cbuf_AddText or Cbuf_InsertText
extern void Cbuf_AddEarlyCommands( _boolean clear );
// adds all the +set commands from the command line
extern _boolean Cbuf_AddLateCommands( void );
// adds all the remaining + commands from the command line
// Returns true if any late commands were added, which
// will keep the demoloop from immediately starting
extern void Cbuf_Execute( void );
// Pulls off \n terminated lines of text from the command buffer and sends
// them through Cmd_ExecuteString. Stops when the buffer is empty.
// Normally called once per frame, but may be explicitly invoked.
// Do not call inside a command function!
extern void Cbuf_CopyToDefer( void );
extern void Cbuf_InsertFromDefer( void );
// These two functions are used to defer any pending commands while a map
// is being loaded
//===========================================================================
#define MAX_STRING_CHARS 1024 // max length of a string passed to Cmd_TokenizeString
#define MAX_STRING_TOKENS 80 // max tokens resulting from Cmd_TokenizeString
#define MAX_TOKEN_CHARS 128 // max length of an individual token
/*
Command execution takes a NUL-terminated string, breaks it into tokens,
then searches for a command or variable that matches the first token.
*/
typedef void (*xcommand_t) (void);
extern void Cmd_Init( void );
extern void Cmd_AddCommand( char *cmd_name, xcommand_t function );
// called by the init functions of other parts of the program to
// register commands and functions to call for them.
// The cmd_name is referenced later, so it should not be in temp memory
// if function is NULL, the command will be forwarded to the server
// as a clc_stringcmd instead of executed locally
extern void Cmd_RemoveCommand( char *cmd_name );
extern _boolean Cmd_Exists( char *cmd_name );
// used by the cvar code to check for cvar / command name overlap
extern char *Cmd_CompleteCommand( char *partial );
// attempts to match a partial command for automatic command line completion
// returns NULL if nothing fits
extern int Cmd_Argc( void );
extern char *Cmd_Argv( int arg );
extern char *Cmd_Args( void );
// The functions that execute commands get their parameters with these
// functions. Cmd_Argv () will return an empty string, not a NULL
// if arg > argc, so string operations are always safe.
extern void Cmd_TokenizeString( char *text, _boolean macroExpand );
// Takes a NUL-terminated string. Does not need to be /n terminated.
// breaks the string up into arg tokens.
extern void Cmd_ExecuteString( char *text );
// Parses a single line of text into arguments and tries to execute it
// as if it was typed at the console
//extern void Cmd_ForwardToServer( void );
// adds the current command line as a clc_stringcmd to the client message.
// things like godmode, noclip, etc, are commands directed to the server,
// so when they are typed in at the console, they will need to be forwarded.
#endif /* __CMD_H__ */

518
wolf3d/code/env/com_string.c vendored Normal file
View File

@@ -0,0 +1,518 @@
/*
Copyright (C) 2004-2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
Copyright (C) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* com_string.c: Common string functions done in a portable manner.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* Portion of this code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
* Portion of this code was derived from code that was originally
* written by Todd C. Miller.
*
*/
#include "../wolfiphone.h"
/*
-----------------------------------------------------------------------------
Function: my_strlcpy -Copies a specified number of characters from a
source string into a buffer.
Parameters: dest -[in/out] Pointer to a buffer into which the function
copies characters
source -[in] Pointer to a NUL-terminated string from which
the function copies characters.
nMaxLength -[in] Specifies the number of bytes to be copied
from the string pointed to by source into the
buffer pointed to by dest.
Returns: Returns strlen( source ); if retval >= nMaxLength, truncation
occurred.
Notes:
At most nMaxLength-1 characters will be copied. Always NUL-
terminates (unless nMaxLength == 0).
-----------------------------------------------------------------------------
*/
PUBLIC size_t my_strlcpy( char *dest, const char *source, size_t nMaxLength )
{
char *d = dest;
const char *s = source;
size_t n = nMaxLength;
/* Copy as many bytes as will fit */
if( n != 0 && --n != 0 )
{
do
{
if( (*d++ = *s++) == 0 )
{
break;
}
} while( --n != 0 );
}
/* Not enough room in dest, add NUL and traverse rest of source */
if( n == 0 )
{
if( nMaxLength != 0 )
{
*d = '\0'; /* NUL-terminate dest */
}
while( *s++ )
{
;
}
}
return( s - source - 1 ); /* count does not include NUL */
}
/*
-----------------------------------------------------------------------------
Function: my_strlcat -Appends one string to another.
Parameters: dest -[in/out] Pointer to a NUL-terminated string. The buffer
must be large enough to contain both strings or else
truncation will occur.
source -[in] Pointer to a NUL-terminated string from which
the function copies characters.
nMaxLength -[in] full size of dest, not space left.
Returns: Returns strlen( source ) + MIN( nMaxLength, strlen( initial dest ) ).
If retval >= nMaxLength, truncation occurred.
Notes:
At most nMaxLength-1 characters will be copied. Always NUL-
terminates (unless nMaxLength <= strlen( dest ) ).
-----------------------------------------------------------------------------
*/
PUBLIC size_t my_strlcat( char *dest, const char *source, size_t nMaxLength )
{
char *d = dest;
const char *s = source;
size_t n = nMaxLength;
size_t dlen;
/* Find the end of dest and adjust bytes left but don't go past end */
while( n-- != 0 && *d != '\0' )
{
d++;
}
dlen = d - dest;
n = nMaxLength - dlen;
/* No room left to append string */
if( n == 0 )
{
return( dlen + strlen( s ) );
}
while( *s != '\0' )
{
if( n != 1 )
{
*d++ = *s;
n--;
}
s++;
}
*d = '\0'; /* NUL-terminate string */
return( dlen + (s - source) ); /* count does not include NUL */
}
/*
-----------------------------------------------------------------------------
Function: my_strnicmp -Compare characters of two strings without regard to case.
Parameters: string1, string2 -[in] NUL-terminated strings to compare.
count -[in] Number of characters to compare.
Returns: 0 string1 identical to string2, -1 otherwise.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC int my_strnicmp( const char *string1, const char *string2, size_t count )
{
char c1, c2;
if( ! string1 || ! *string1 ||
! string2 || ! *string2 )
{
return -1;
}
do
{
c1 = *string1++;
c2 = *string2++;
if( ! count-- )
{
return 0; /* strings are equal until end point */
}
if( c1 != c2 )
{
if( TOUPPER( c1 ) != TOUPPER( c2 ) ) /* Uppercase compare */
{
return -1; /* strings are not equal */
}
}
} while( c1 );
return 0; /* strings are equal */
}
/*
-----------------------------------------------------------------------------
Function: my_stricmp -Perform an uppercase comparison of strings.
Parameters: string1, string2 -[in] NUL-terminated strings to compare.
Returns: 0 string1 identical to string2, -1 otherwise.
Notes:
Calls my_strnicmp, where count is 99999
-----------------------------------------------------------------------------
*/
PUBLIC int my_stricmp( const char *string1, const char *string2 )
{
return my_strnicmp( string1, string2, 99999 );
}
/*
-----------------------------------------------------------------------------
Function: my_snprintf -Write formatted data to a string.
Parameters: dest -[out] Storage location for output.
size -[in] Maximum number of characters to store.
format -[in] Format-control string.
... -[in] Optional arguments.
Returns: Nothing.
Notes: If the format string is longer than 32768 truncation will occur.
Also, if format is longer than dest truncation will occur.
-----------------------------------------------------------------------------
*/
PUBLIC void my_snprintf( char *dest, size_t size, const char *format, ... )
{
va_list argptr;
char bigbuffer[ 0x8000 ];
va_start( argptr, format );
(void)vsnprintf( bigbuffer, sizeof( bigbuffer ), format, argptr );
va_end( argptr );
bigbuffer[ sizeof( bigbuffer ) - 1 ] = '\0';
my_strlcpy( dest, bigbuffer, size );
}
/*
-----------------------------------------------------------------------------
Function: my_CopyString -Allocate a duplicate copy of a string, and return
duplicate.
Parameters: in -[in] String to duplicate.
Returns:
Pointer to duplicate string. Caller is responsible for freeing
memory with Z_Free.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *my_CopyString( const char *in )
{
char *out;
out = Z_Malloc( strlen( in ) + 1 );
my_strlcpy( out, in, strlen( in ) + 1 );
return out;
}
/*
-----------------------------------------------------------------------------
Function: my_strhash -Create a hash id from string.
Parameters: string -[in] NUL-terminated string.
Returns: Hash id.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC W32 my_strhash( const char *string )
{
W32 hash = *string;
if( hash )
{
for( string += 1; *string != '\0'; ++string )
{
hash = (hash << 5) - hash + *string;
}
}
return hash;
}
/*
-----------------------------------------------------------------------------
Function: my_strupr -Convert a string to uppercase.
Parameters: string -[in/out] NUL-terminated string to capitalize.
Returns:
This functions returns a pointer to the converted string. Because
the modification is done in place, the pointer returned is the same
as the pointer passed as the input argument. No return value is
reserved to indicate an error.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *my_strupr( char *string )
{
char *ptr;
if( ! string || ! *string )
{
return string;
}
ptr = string;
do
{
*ptr = TOUPPER( *ptr );
} while( *ptr++ );
return string;
}
/*
-----------------------------------------------------------------------------
Function: my_strlwr -Convert a string to lowercase.
Parameters: string -[in/out] NUL-terminated string to convert to lowercase.
Returns:
This functions returns a pointer to the converted string. Because
the modification is done in place, the pointer returned is the same
as the pointer passed as the input argument. No return value is
reserved to indicate an error.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *my_strlwr( char *string )
{
char *ptr;
if( ! string || ! *string )
{
return string;
}
ptr = string;
do
{
*ptr = TOLOWER( *ptr );
} while( *ptr++ );
return string;
}
/*
-----------------------------------------------------------------------------
Function: StringToInteger -Convert string to integer.
Parameters: string -[in] NUL-terminated string to be converted.
error -[out] Error code. See header.
Returns: An integer value.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC SW32 StringToInteger( const char *string, W32 *error )
{
const char *ptr = string;
SW32 temp;
SW32 number = 0;
W32 errortag = 0;
_boolean bNegative = false;
if( ! string || ! *string )
{
*error = SCE_NULL_VALUE;
return 0;
}
if( *ptr == '-' )
{
bNegative = true;
ptr++;
}
while( *ptr && ISNUMERIC( *ptr ) )
{
temp = number;
number = (number * 10) + *ptr - '0';
if( number < temp )
{
errortag &= SCE_BUFFER_OVERFLOW;
}
ptr++;
}
if( *ptr )
{
errortag &= SCE_NON_NUMERIC;
}
if( bNegative )
{
number = -number;
}
*error = errortag;
return number;
}
/*
-----------------------------------------------------------------------------
Function: StringToFloat -Convert string to float.
Parameters: string -[in] NUL-terminated string to be converted.
error -[out] Error code. See header.
Returns: A float value.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC double StringToFloat( const char *string, W32 *error )
{
const char *ptr = string;
double number = 0;
SW32 exponent = 0;
W32 expError;
_boolean bNegative = false;
*error = 0;
if( ! string || ! *string )
{
*error &= SCE_NULL_VALUE;
return 0;
}
if( *ptr == '-' )
{
bNegative = true;
ptr++;
}
else if( *ptr == '+' )
{
ptr++;
}
while( *ptr && ISNUMERIC( *ptr ) )
{
number = (number * 10) + (double)(*ptr - '0');
ptr++;
}
if( *ptr == '.' )
{
ptr++;
while( *ptr && ISNUMERIC( *ptr ) )
{
number = (number * 10) + (double)(*ptr - '0');
exponent--;
ptr++;
}
}
if( TOLOWER( *ptr ) == 'e' )
{
ptr++;
exponent += StringToInteger( ptr, &expError );
}
if( bNegative )
{
number = -number;
}
if( expError )
{
*error |= expError;
}
return (number * pow( 10, exponent ));
}

87
wolf3d/code/env/com_string.h vendored Normal file
View File

@@ -0,0 +1,87 @@
/*
Copyright (C) 2004 Michael Liebscher <johnnycanuck@users.sourceforge.net>
Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* com_string.h: Common string functions done in a portable manner.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* Portion of this code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
* Portion of this code was derived from code that was originally
* written by Todd C. Miller.
*
*/
/*
Notes:
This module is implemented by com_string.c.
*/
#ifndef __COM_STRING_H__
#define __COM_STRING_H__
#define ISSPACE( c ) ( ( c ) == ' ' || ( c ) == '\f' || ( c ) == '\n' || ( c ) == '\r' || ( c ) == '\t' || ( c ) == '\v' )
#define ISUPPER( c ) ( ( c ) >= 'A' && ( c ) <= 'Z' )
#define ISLOWER( c ) ( ( c ) >= 'a' && ( c ) <= 'z' )
#define ISALPHA( c ) ( ISUPPER( c ) || ISLOWER( c ) )
#define TOUPPER( c ) ( ISLOWER( c ) ? (c) - 'a' + 'A' : ( c ) )
#define TOLOWER( c ) ( ISUPPER( c ) ? (c) - 'A' + 'a' : ( c ) )
#define ISNUMERIC( c ) ( ( c ) >= '0' && ( c ) <= '9' )
#define ISALPHANUMERIC( c ) ( ISALPHA( c ) || ISNUMERIC( c ) )
extern size_t my_strlcpy( char *dest, const char *source, size_t nMaxLength );
extern size_t my_strlcat( char *dest, const char *source, size_t nMaxLength );
extern int my_stricmp( const char *string1, const char *string2 );
extern int my_strnicmp( const char *string1, const char *string2, size_t count );
extern void my_snprintf( char *dest, size_t size, const char *format, ... );
extern char *my_CopyString( const char *in );
extern W32 my_strhash( const char *string );
extern char *my_strupr( char *string );
extern char *my_strlwr( char *string );
/* String conversion error */
#define SCE_NON_NUMERIC (1 << 0) /* Non-numeric value was encountered */
#define SCE_BUFFER_OVERFLOW (1 << 1) /* Numberic overflowed */
#define SCE_NULL_VALUE (1 << 2) /* NULL string was passed into function */
extern SW32 StringToInteger( const char *string, W32 *error );
extern double StringToFloat( const char *string, W32 *error );
#endif /* __COM_STRING_H__ */

593
wolf3d/code/env/common.c vendored Normal file
View File

@@ -0,0 +1,593 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* common.c: Misc functions used in client and server.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#include "../wolfiphone.h"
#define MAXPRINTMSG 4096
#define MAX_NUM_ARGVS 50
colour3_t colourBlack = { 0, 0, 0 };
colour3_t colourRed = { 255, 0, 0 };
colour3_t colourGreen = { 0, 255, 0 };
colour3_t colourBlue = { 0, 0, 255 };
colour3_t colourWhite = { 255, 255, 255 };
int com_argc;
char *com_argv[ MAX_NUM_ARGVS + 1 ];
jmp_buf abortframe; // an ERR_DROP occured, exit the entire frame
FILE *log_stats_file;
cvar_t *log_stats;
cvar_t *developer;
cvar_t *logfile_active; // 1 = buffer log, 2 = flush after each print
FILE *logfile;
/*
============================================================================
CLIENT / SERVER interactions
============================================================================
*/
static int rd_target;
static char *rd_buffer;
static int rd_buffersize;
static void (*rd_flush)( int target, char *buffer );
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Com_BeginRedirect( int target, char *buffer, int buffersize, void (*flush) )
{
if( ! target || ! buffer || ! buffersize || ! flush )
{
return;
}
rd_target = target;
rd_buffer = buffer;
rd_buffersize = buffersize;
rd_flush = flush;
*rd_buffer = 0;
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Com_EndRedirect( void )
{
rd_flush( rd_target, rd_buffer );
rd_target = 0;
rd_buffer = NULL;
rd_buffersize = 0;
rd_flush = NULL;
}
/*
-----------------------------------------------------------------------------
Function: Com_Printf -print out message.
Parameters:
Returns: Nothing.
Notes:
Both client and server can use this, and it will output
to the apropriate place.
-----------------------------------------------------------------------------
*/
PUBLIC void Com_Printf( const char *fmt, ... )
{
va_list argptr;
static char msg[ MAXPRINTMSG ];
va_start( argptr, fmt );
(void)vsnprintf( msg, sizeof( msg ), fmt, argptr );
va_end( argptr );
msg[ sizeof( msg ) - 1 ] = '\0';
if( rd_target )
{
if( (strlen( msg ) + strlen( rd_buffer ) ) > (rd_buffersize - 1) )
{
rd_flush( rd_target, rd_buffer );
*rd_buffer = '\0';
}
my_strlcat( rd_buffer, msg, rd_buffersize );
return;
}
Con_Print( msg );
#ifdef _WIN32
OutputDebugString( msg );
#endif
// also echo to debugging console
// Sys_ConsoleOutput( msg );
// logfile
if( logfile_active && logfile_active->value )
{
char name[ MAX_GAMEPATH ];
if( ! logfile )
{
my_snprintf( name, sizeof( name ), "%s/console.log", FS_Gamedir() );
if( logfile_active->value > 2 )
{
logfile = fopen( name, "a" );
}
else
{
logfile = fopen( name, "w" );
}
}
if( logfile )
{
fprintf( logfile, "%s", msg );
}
if( logfile_active->value > 1 )
{
fflush( logfile ); // force it to save every time
}
}
}
/*
-----------------------------------------------------------------------------
Function: Com_DPrintf -A Com_Printf that only shows up if the "developer"
cvar is set
Parameters:
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Com_DPrintf( const char *fmt, ... )
{
va_list argptr;
static char msg[ MAXPRINTMSG ];
if( ! developer || ! developer->value )
{
return; // don't confuse non-developers with techie stuff...
}
va_start( argptr, fmt );
(void)vsnprintf( msg, sizeof( msg ), fmt, argptr );
va_end( argptr );
msg[ sizeof( msg ) - 1 ] = '\0';
Com_Printf( "%s", msg );
}
/*
-----------------------------------------------------------------------------
Function: Com_Error
Parameters:
Returns:
Notes:
Both client and server can use this, and it will
do the apropriate things.
-----------------------------------------------------------------------------
*/
PUBLIC void Com_Error( int code, const char *fmt, ... )
{
va_list argptr;
static char msg[ MAXPRINTMSG ];
static _boolean recursive;
if( recursive )
{
Sys_Error( "recursive error after: %s", msg );
}
recursive = true;
va_start (argptr,fmt);
(void)vsnprintf( msg, sizeof( msg ), fmt, argptr );
va_end (argptr);
msg[ sizeof( msg ) - 1 ] = '\0';
if( code == ERR_DISCONNECT )
{
recursive = false;
longjmp (abortframe, -1);
}
else if( code == ERR_DROP )
{
Com_Printf( "********************\nERROR: %s\n********************\n", msg );
recursive = false;
longjmp( abortframe, -1 );
}
else
{
}
if( logfile )
{
fclose( logfile );
logfile = NULL;
}
Sys_Error( "%s", msg );
}
//===========================================================================
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void SZ_Init( sizebuf_t *buf, PW8 data, int length )
{
memset( buf, 0, sizeof( *buf ) );
buf->data = data;
buf->maxsize = length;
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void SZ_Clear( sizebuf_t *buf )
{
buf->cursize = 0;
buf->overflowed = false;
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void *SZ_GetSpace( sizebuf_t *buf, int length )
{
void *data;
if( buf->cursize + length > buf->maxsize )
{
if( ! buf->allowoverflow )
{
Com_Error( ERR_FATAL, "SZ_GetSpace: overflow without allowoverflow set" );
}
if( length > buf->maxsize )
{
Com_Error( ERR_FATAL, "SZ_GetSpace: %i is > full buffer size", length );
}
Com_Printf( "SZ_GetSpace: overflow\n" );
SZ_Clear( buf );
buf->overflowed = true;
}
data = buf->data + buf->cursize;
buf->cursize += length;
return data;
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void SZ_Write( sizebuf_t *buf, void *data, int length )
{
memcpy( SZ_GetSpace( buf, length ), data, length );
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void SZ_Print( sizebuf_t *buf, W8 *data )
{
int len;
len = strlen( (char *)data ) + 1;
if (buf->cursize)
{
if( buf->data[ buf->cursize - 1 ] )
{
memcpy( (PW8)SZ_GetSpace( buf, len ), data, len ); // no trailing 0
}
else
{
memcpy( (PW8)SZ_GetSpace( buf, len - 1 ) - 1, data, len ); // write over trailing 0
}
}
else
{
memcpy( (PW8)SZ_GetSpace( buf, len ),data,len );
}
}
//============================================================================
/*
-----------------------------------------------------------------------------
Function: COM_CheckParm
Parameters:
Returns:
The position (1 to argc-1) in the program's argument list
where the given parameter apears, or 0 if not present
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC int COM_CheckParm( char *parm )
{
int i;
for( i = 1 ; i < com_argc ; ++i )
{
if( ! strcmp( parm, com_argv[ i ] ) )
{
return i;
}
}
return 0;
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC int COM_Argc (void)
{
return com_argc;
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *COM_Argv (int arg)
{
if (arg < 0 || arg >= com_argc || !com_argv[arg])
return "";
return com_argv[arg];
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void COM_ClearArgv( int arg )
{
if (arg < 0 || arg >= com_argc || !com_argv[arg])
{
return;
}
com_argv[ arg ] = "";
}
/*
-----------------------------------------------------------------------------
Function: COM_InitArgv -Set global argv values with commadline argv values.
Parameters:
argc -[in] An integer specifying how many arguments are in argv[].
argv -[in] An array of null-terminated strings. The last pointer
(argv[argc]) is NULL.
Returns: Nothing.
Notes: Sets global variables com_argc and com_argv.
-----------------------------------------------------------------------------
*/
PUBLIC void COM_InitArgv( int argc, char *argv[] )
{
int i;
if( argc > MAX_NUM_ARGVS )
{
argc = MAX_NUM_ARGVS;
Com_DPrintf( "argc > MAX_NUM_ARGVS\n" );
}
com_argc = argc;
for( i = 0; i < argc; ++i )
{
if( ! argv[ i ] || strlen( argv[ i ] ) >= MAX_TOKEN_CHARS )
{
com_argv[ i ] = "";
}
else
{
com_argv[ i ] = argv[ i ];
}
}
}
/*
-----------------------------------------------------------------------------
Function: COM_AddParm -Adds the given string at the end of the current
argument list
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void COM_AddParm( char *parm )
{
if( com_argc == MAX_NUM_ARGVS )
{
Com_Error( ERR_FATAL, "COM_AddParm: MAX_NUM_ARGS" );
}
com_argv[ com_argc++ ] = parm;
}
/*
-----------------------------------------------------------------------------
Function: Com_Error_f -Just throw a fatal error to test error shutdown
procedures.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void Com_Error_f (void)
{
Com_Error( ERR_FATAL, "%s", Cmd_Argv( 1 ) );
}

207
wolf3d/code/env/common.h vendored Normal file
View File

@@ -0,0 +1,207 @@
/*
Copyright (C) 2004 Michael Liebscher <johnnycanuck@users.sourceforge.net>
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* common.h: Common definitions between client and server.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
/*
Notes:
This module is implemented by common.c.
*/
#ifndef __COMMON_H__
#define __COMMON_H__
//============================================================================
typedef struct sizebuf_s
{
_boolean allowoverflow; // if false, do a Com_Error
_boolean overflowed; // set to true if the buffer size failed
W8 *data;
int maxsize;
int cursize;
int readcount;
} sizebuf_t;
extern void SZ_Init( sizebuf_t *buf, PW8 data, int length );
extern void SZ_Clear( sizebuf_t *buf );
extern void *SZ_GetSpace( sizebuf_t *buf, int length );
extern void SZ_Write( sizebuf_t *buf, void *data, int length );
extern void SZ_Print( sizebuf_t *buf, W8 *data ); // memcpy onto the sizebuf
//============================================================================
extern int COM_Argc( void );
extern char *COM_Argv( int arg ); // range and null checked
extern void COM_ClearArgv( int arg );
extern int COM_CheckParm( char *parm );
extern void COM_AddParm( char *parm );
extern void COM_Init( void );
extern void COM_InitArgv( int argc, char *argv[] );
extern char *COM_Parse( char **data_p );
// data is an in/out parm, returns a parsed out token
//============================================================================
/////////////////////////////////////////////////////////////////////
//
// Colour
//
/////////////////////////////////////////////////////////////////////
extern colour3_t colourBlack;
extern colour3_t colourRed;
extern colour3_t colourBlue;
extern colour3_t colourGreen;
extern colour3_t colourWhite;
/////////////////////////////////////////////////////////////////////
// End Colour
/////////////////////////////////////////////////////////////////////
/*
==============================================================
MISC
==============================================================
*/
#define ERR_FATAL 0 // exit the entire game with a popup window
#define ERR_DROP 1 // print to console and disconnect from game
#define ERR_QUIT 2 // not an error, just a normal exit
#define ERR_DISCONNECT 4 // don't kill server
#define EXEC_NOW 0 // don't return until completed
#define EXEC_INSERT 1 // insert at current position, but don't run yet
#define EXEC_APPEND 2 // add to end of the command buffer
#define PRINT_ALL 0
#define PRINT_DEVELOPER 1 // only print when "developer 1"
extern void Com_BeginRedirect( int target, char *buffer, int buffersize, void (*flush) );
extern void Com_EndRedirect( void );
extern void Com_Printf( const char *fmt, ... );
extern void Com_DPrintf( const char *fmt, ... );
extern void Com_Error( int code, const char *fmt, ... );
extern char *va( char *format, ... );
extern cvar_t *developer;
extern cvar_t *log_stats;
extern cvar_t *logfile_active;
extern FILE *log_stats_file;
extern void common_Init( int argc, char *argv[] );
extern void common_Frame( int msec );
/*
==============================================================
NON-PORTABLE SYSTEM SERVICES
==============================================================
*/
extern char *Sys_ConsoleInput( void );
extern void Sys_ConsoleOutput( const char *string );
extern void Sys_SendKeyEvents( void );
extern void Sys_Error( const char *format, ... );
extern void Sys_Quit( void );
extern char *Sys_GetClipboardData( void );
extern void Sys_CopyProtect( void );
/*
==============================================================
CLIENT / SERVER SYSTEMS
==============================================================
*/
extern void Client_Init( void );
//
// button bits
//
#define BUTTON_ATTACK 1
#define BUTTON_USE 2
#define BUTTON_CHANGE_WEAPON 4
#define BUTTON_ANY 128 // any key whatsoever
// usercmd_t is sent to the server each client frame
typedef struct usercmd_s
{
W8 msec;
W8 buttons;
short angles[ 3 ];
short forwardmove, sidemove, upmove;
W8 impulse; // remove?
W8 lightlevel; // light level the player is standing on
} usercmd_t;
#endif /* __COMMON_H__ */

62
wolf3d/code/env/common_utils.h vendored Normal file
View File

@@ -0,0 +1,62 @@
/*
Copyright (C) 2004 Michael Liebscher <johnnycanuck@users.sourceforge.net>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* common_utils.h: General Purpose Macros.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
*/
#ifndef __COMMON_UTILS_H__
#define __COMMON_UTILS_H__
/*
Make sure the following macros are defined.
*/
#ifndef __FILE__
#define __FILE__ ""
#endif
#ifndef __LINE__
#define __LINE__ 0L
#endif
/*
These function prefixes are used for figuring out which
functions are exported and which are not.
*/
#define PUBLIC /* Accessible outside this module */
#define PRIVATE static /* Accessible only within this module */
#endif /* __COMMON_UTILS_H__ */

811
wolf3d/code/env/console.c vendored Normal file
View File

@@ -0,0 +1,811 @@
/*
Copyright (C) 2004-2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* console.c: Console drawing and management.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#include "../wolfiphone.h"
extern viddef_t viddef;
extern int consoleActive;
console_t con;
float scr_conlines;
float scr_con_current;
cvar_t *con_notifytime;
cvar_t *scr_conspeed;
#define MAXCMDLINE 256
char key_lines[ 32 ][ MAXCMDLINE ];
int edit_line;
int key_linepos;
colour3_t colourconLGray = { 220, 220, 220 };
colour3_t colourconLLGray = { 192, 192, 192 };
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void DrawString( int x, int y, char *s )
{
Font_put_line( FONT0, x, y, s );
}
/*
-----------------------------------------------------------------------------
Function: Key_ClearTyping -Clear any keys that where typed.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
void Key_ClearTyping( void )
{
key_lines[ edit_line ][ 1 ] = 0; // clear any typing
key_linepos = 1;
}
/*
-----------------------------------------------------------------------------
Function: Con_ToggleConsole_f -Get ready to enter console.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Con_ToggleConsole_f( void )
{
Key_ClearTyping();
Con_ClearNotify();
}
/*
-----------------------------------------------------------------------------
Function: Con_Clear_f -Clear console text buffer.
Parameters: Nothing.
Returns: Nothing.
Notes:
Zero sets con.text memory block.
-----------------------------------------------------------------------------
*/
PRIVATE void Con_Clear_f( void )
{
memset( con.text, ' ', CON_TEXTSIZE );
}
/*
-----------------------------------------------------------------------------
Function: Con_Dump_f -Save the console contents out to a file.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void Con_Dump_f( void )
{
int length, x;
char *line;
FILE *f;
char buffer[1024];
char name[MAX_OSPATH];
if( Cmd_Argc() != 2 )
{
Com_Printf( "usage: conDump <filename>\n" );
return;
}
my_snprintf( name, sizeof( name ), "%s/%s.txt", FS_Gamedir(), Cmd_Argv( 1 ) );
Com_Printf( "Dumped console text to %s.\n", name );
FS_CreatePath( name );
f = fopen( name, "w" );
if( ! f )
{
Com_Printf( "ERROR: couldn't open.\n" );
return;
}
// skip empty lines
for( length = con.current - con.totallines + 1; length <= con.current; ++length )
{
line = con.text + (length % con.totallines) * con.linewidth;
for( x = 0; x < con.linewidth; ++x )
{
if( line[ x ] != ' ' )
{
break;
}
}
if( x != con.linewidth )
{
break;
}
}
// write the remaining lines
buffer[ con.linewidth ] = '\0';
for( ; length <= con.current ; ++length )
{
line = con.text + (length % con.totallines) * con.linewidth;
my_strlcpy( buffer, line, con.linewidth );
for( x = con.linewidth - 1; x >= 0; --x )
{
if( buffer[ x ] == ' ' )
{
buffer[ x ] = '\0'; // NUL-terminate string
}
else
{
break;
}
}
for( x = 0; buffer[ x ]; ++x )
{
buffer[ x ] &= 0x7f;
}
fprintf( f, "%s\n", buffer );
}
fclose( f );
}
/*
-----------------------------------------------------------------------------
Function: Con_ClearNotify -Clear console con.times.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Con_ClearNotify( void )
{
int i;
for( i = 0; i < NUM_CON_TIMES; ++i )
{
con.times[ i ] = 0;
}
}
/*
-----------------------------------------------------------------------------
Function: Con_CheckResize -If the line width has changed, reformat the buffer.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Con_CheckResize( void )
{
int i, j, width, oldwidth, oldtotallines, numlines, numchars;
char tbuf[ CON_TEXTSIZE ];
width = (viddef.width >> 3) - 2;
if( width == con.linewidth )
{
return;
}
if( width < 1 ) // video hasn't been initialized yet
{
width = 38;
con.linewidth = width;
con.totallines = CON_TEXTSIZE / con.linewidth;
memset( con.text, ' ', CON_TEXTSIZE );
}
else
{
oldwidth = con.linewidth;
con.linewidth = width;
oldtotallines = con.totallines;
con.totallines = CON_TEXTSIZE / con.linewidth;
numlines = oldtotallines;
if( con.totallines < numlines )
{
numlines = con.totallines;
}
numchars = oldwidth;
if( con.linewidth < numchars )
{
numchars = con.linewidth;
}
memcpy( tbuf, con.text, CON_TEXTSIZE );
memset( con.text, ' ', CON_TEXTSIZE );
for( i = 0; i < numlines; ++i )
{
for( j = 0; j < numchars; ++j )
{
con.text[(con.totallines - 1 - i) * con.linewidth + j] =
tbuf[((con.current - i + oldtotallines) %
oldtotallines) * oldwidth + j];
}
}
Con_ClearNotify();
}
con.current = con.totallines - 1;
con.display = con.current;
}
/*
-----------------------------------------------------------------------------
Function:
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Con_Init( void )
{
con.linewidth = -1;
Con_CheckResize();
Com_Printf( "Console Initialized\n" );
//
// register our commands
//
con_notifytime = Cvar_Get( "con_notifytime", "90", CVAR_INIT );
scr_conspeed = Cvar_Get( "scr_conspeed", "90", CVAR_INIT );
Cmd_AddCommand( "toggleconsole", Con_ToggleConsole_f );
Cmd_AddCommand( "clear", Con_Clear_f );
Cmd_AddCommand( "conDump", Con_Dump_f );
con.initialized = true;
}
/*
-----------------------------------------------------------------------------
Function: Con_Linefeed -Fill rest of line with spaces.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void Con_Linefeed( void )
{
con.x = 0;
if( con.display == con.current )
{
con.display++;
}
con.current++;
memset( &con.text[ (con.current % con.totallines) * con.linewidth ]
, ' ', con.linewidth );
}
/*
-----------------------------------------------------------------------------
Function: Con_Print -Print formatted message to the console.
Parameters: txt -[in] Text message to print
Returns: Nothing.
Notes:
Handles cursor positioning, line wrapping, etc
All console printing must go through this in order to be logged to disk
If no console is visible, the text will appear at the top of the game window
-----------------------------------------------------------------------------
*/
PUBLIC void Con_Print( char *txt )
{
int y;
int c, wordlength;
static int cr;
int mask;
#ifdef IPHONE
printf( "%s", txt );
#endif
if( ! con.initialized )
{
return;
}
if( txt[ 0 ] == 1 || txt[ 0 ] == 2 )
{
mask = 128; // go to colored text
txt++;
}
else
{
mask = 0;
}
while( (c = *txt) )
{
// count word length
for( wordlength = 0 ; wordlength < con.linewidth ; ++wordlength )
{
if( txt[ wordlength ] <= ' ')
{
break;
}
}
// word wrap
if( wordlength != con.linewidth && (con.x + wordlength > con.linewidth) )
{
con.x = 0;
}
txt++;
if( cr )
{
con.current--;
cr = false;
}
if( ! con.x )
{
Con_Linefeed();
// mark time for transparent overlay
if( con.current >= 0 )
{
con.times[ con.current % NUM_CON_TIMES ] = iphoneFrameNum;
}
}
switch( c )
{
case '\n':
con.x = 0;
break;
case '\r':
con.x = 0;
cr = 1;
break;
default: // display character and advance
y = con.current % con.totallines;
con.text[ y * con.linewidth + con.x] = c | mask | con.ormask;
con.x++;
if( con.x >= con.linewidth )
{
con.x = 0;
}
break;
}
}
}
/*
-----------------------------------------------------------------------------
Function: Con_CenteredPrint -Print message that is centered on screen.
Parameters: text -[in] Message string.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Con_CenteredPrint( const char *text )
{
int length;
char buffer[ 1024 ];
length = strlen( text );
length = ( con.linewidth - length ) >> 1;
if( length < 0 )
{
length = 0;
}
memset( buffer, ' ', length );
my_strlcpy( buffer + length, text, sizeof( buffer ) - length );
my_strlcat( buffer, "\n", sizeof( buffer ) );
Con_Print( buffer );
}
/*
==============================================================================
DRAWING
==============================================================================
*/
/*
-----------------------------------------------------------------------------
Function: Con_DrawInput -The input line scrolls horizontally if typing
goes beyond the right edge.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void Con_DrawInput( void )
{
int y;
int i;
char *text;
char buf[256];
W16 heightfont, charwidth;
static char ccursor[ 2 ] = { ' ', '_' };
heightfont = Font_GetSize( FONT0 ) + 4;
#ifdef IPHONE
{
if ( consoleActive == 0 ) {
return;
}
strcpy( buf, SysIPhoneGetConsoleTextField() );
key_linepos = strlen( buf );
buf[key_linepos+1] = 0;
text = buf;
}
#else
if( ClientStatic.key_dest != key_console )
{
return; // don't draw anything (always draw if not active)
}
text = key_lines[ edit_line ];
#endif
// add the cursor frame
text[ key_linepos ] = ccursor[ 0 + ((int)( iphoneFrameNum >> 3 ) & 1 ) ];
// fill out remainder with spaces
for( i = key_linepos + 1 ; i < con.linewidth ; ++i )
{
text[ i ] = ' ';
}
// prestep if horizontally scrolling
if( key_linepos >= con.linewidth )
{
text += 1 + key_linepos - con.linewidth;
}
// draw it
y = con.vislines - heightfont;
charwidth = 8;
for( i = 0 ; i < con.linewidth ; ++i )
{
charwidth += Font_put_character( FONT0, charwidth, con.vislines - 22, text[ i ] );
}
// remove cursor
key_lines[ edit_line ][ key_linepos ] = 0;
}
/*
-----------------------------------------------------------------------------
Function: Con_DrawNotify -Draws the last few lines of output transparently
over the game top.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Con_DrawNotify( void )
{
int x, v;
int charwidth;
char *text;
int i;
int time;
// char *s;
// int skip;
W16 size;
Font_SetSize( FONT1, 1 );
size = Font_GetSize( FONT1 );
Font_SetColour( FONT1, colourWhite );
v = 0;
for( i = con.current - NUM_CON_TIMES+1 ; i <= con.current ; ++i )
{
if( i < 0 )
{
continue;
}
time = FloatToInt( con.times[ i % NUM_CON_TIMES ] );
if( time == 0 )
{
continue;
}
time = iphoneFrameNum- time;
if( time > con_notifytime->value )
{
continue;
}
text = con.text + (i % con.totallines) * con.linewidth;
charwidth = 0;
for( x = 0 ; x < con.linewidth ; ++x )
{
charwidth += Font_put_character( FONT1, charwidth, v, text[ x ] );
}
v += size;
}
Font_SetSize( FONT1, 2 );
}
/*
-----------------------------------------------------------------------------
Function: Con_DrawConsole -Draws the console.
Parameters: frac -[in] Fraction of the screen the console will take up.
Range is 0.0 to 1.0
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Con_DrawConsole( float frac )
{
int i, x, y;
int rows;
char *text;
int row;
W32 lines;
// int w, h;
int heightfont, charwidth;
lines = FloatToInt( viddef.height * frac );
if( lines < 1 )
{
return;
}
Font_SetSize( FONT0, 1 );
Font_SetColour( FONT0, colourconLLGray );
heightfont = Font_GetSize( FONT0 );
if( lines > viddef.height )
{
lines = viddef.height;
}
//
// Draw the background
//
R_Draw_Fill( 0, -viddef.height + lines, viddef.width, viddef.height, colourBlack );
R_Draw_Fill( 0, lines-2, viddef.width, 2, colourconLGray );
Font_SetColour( FONT0, colourconLLGray );
//
// Draw the text
//
con.vislines = lines;
#if 0
rows = (lines - 8) >> 3; // rows of text to draw
y = lines - 24;
#else
rows = (lines - 22) >> 3; // rows of text to draw
y = lines - 30;
#endif
// draw from the bottom up
if( con.display != con.current )
{
// draw arrows to show the buffer is backscrolled
for( x = 0; x < con.linewidth; x += 4 )
{
Font_put_character( FONT0, (x+1) << 3, y, '^' );
}
y -= heightfont;
rows--;
}
row = con.display;
for( i = 0 ; i < rows ; ++i, y -= heightfont, --row )
{
if( row < 0 )
{
break;
}
if( con.current - row >= con.totallines )
{
break; // past scrollback wrap point
}
text = con.text + (row % con.totallines) * con.linewidth;
charwidth = 0;
for( x = 0; x < con.linewidth; ++x )
{
charwidth += Font_put_character( FONT0, charwidth, y, text[ x ] );
}
}
// draw the input prompt, user text, and cursor if desired
Con_DrawInput();
Font_SetSize( FONT0, 2 );
}
/*
-----------------------------------------------------------------------------
Function: Client_Screen_RunConsole -Figure out how the console should be
drawn.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Client_Screen_RunConsole( void )
{
if( scr_conlines < scr_con_current )
{
scr_con_current -= scr_conspeed->value * iphoneFrameNum;
if( scr_conlines > scr_con_current )
{
scr_con_current = scr_conlines;
}
}
else if( scr_conlines > scr_con_current )
{
scr_con_current += scr_conspeed->value * iphoneFrameNum;
if( scr_conlines < scr_con_current )
{
scr_con_current = scr_conlines;
}
}
}
/*
-----------------------------------------------------------------------------
Function: Client_Screen_DrawConsole -Draw the console on the screen.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Client_Screen_DrawConsole( void )
{
Con_CheckResize();
if( scr_con_current )
{
Con_DrawConsole( scr_con_current );
}
else
{
Con_DrawNotify();
}
}

86
wolf3d/code/env/console.h vendored Normal file
View File

@@ -0,0 +1,86 @@
/*
Copyright (C) 2004 Michael Liebscher <johnnycanuck@users.sourceforge.net>
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* console.h: Console drawing and management..
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
/*
Notes:
This module is implemented by console.c.
*/
#ifndef __CONSOLE_H__
#define __CONSOLE_H__
#define NUM_CON_TIMES 4
#define CON_TEXTSIZE 32768
typedef struct
{
_boolean initialized;
char text[CON_TEXTSIZE];
int current; // line where next message will be printed
int x; // offset in current line for next print
int display; // bottom of console displays this line
int ormask; // high bit mask for colored characters
int linewidth; // characters across screen
int totallines; // total lines in console scrollback
float cursorspeed;
int vislines;
float times[NUM_CON_TIMES]; // cls.realtime time the line was generated
// for transparent notify lines
} console_t;
extern console_t con;
extern void Con_DrawCharacter( int cx, int line, int num );
extern void Con_CheckResize( void );
extern void Con_Init( void );
extern void Con_DrawConsole( float frac );
extern void Con_Print( char *txt );
extern void Con_CenteredPrint( const char *text );
extern void Con_DrawNotify( void );
extern void Con_ClearNotify( void );
extern void Con_ToggleConsole_f( void );
extern void Client_Screen_RunConsole( void );
extern void Client_Screen_DrawConsole( void );
#endif /* __CONSOLE_H__ */

765
wolf3d/code/env/cvar.c vendored Normal file
View File

@@ -0,0 +1,765 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* cvar.c: Dynamic variable tracking.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#include "../wolfiphone.h"
cvar_t *cvar_vars;
/*
-----------------------------------------------------------------------------
Function: Cvar_InfoValidate -String can not have / " ;
Parameters: string -[in] String to validate.
Returns: 1 if string is valid, otherwise 0;
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE _boolean Cvar_InfoValidate( const char *string )
{
if( strstr( string, "\\" ) )
{
return false;
}
if( strstr( string, "\"" ) )
{
return false;
}
if( strstr( string, ";" ) )
{
return false;
}
return true;
}
/*
-----------------------------------------------------------------------------
Function: Cvar_FindVar -Return cvar;
Parameters: var_name -[in] Name of cvar to lookup.
Returns: NULL if cvar not found, otherwise returns the cvar.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE cvar_t *Cvar_FindVar( const char *var_name )
{
cvar_t *var;
W32 hashid;
hashid = my_strhash( var_name );
for( var = cvar_vars ; var ; var = var->next )
{
if( hashid == var->id )
{
return var;
}
}
return NULL;
}
/*
-----------------------------------------------------------------------------
Function: Cvar_VariableValue -Get value of cvar.
Parameters: var_name -[in] Name of cvar to get value.
Returns: 0 if not found, other the value of the cvar.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC float Cvar_VariableValue( const char *var_name )
{
cvar_t *var;
var = Cvar_FindVar( var_name );
if( ! var )
{
return 0;
}
return (float)atof( var->string );
}
/*
-----------------------------------------------------------------------------
Function: Cvar_VariableString -Get cvar variable as string.
Parameters: var_name -[in] Name of cvar to get value.
Returns: Blank string on error, otherwise value string.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *Cvar_VariableString( const char *var_name )
{
cvar_t *var;
var = Cvar_FindVar( var_name );
if( ! var )
{
return "";
}
return var->string;
}
/*
-----------------------------------------------------------------------------
Function: Cvar_CompleteVariable -Complete cvar string name.
Parameters: partial -[in] Partial name of string to look up.
Returns: NULL if partial string not found, otherwise the complete
string name.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *Cvar_CompleteVariable( const char *partial )
{
cvar_t *cvar;
size_t len;
W32 hashid;
len = strlen( partial );
if( ! len )
{
return NULL;
}
//
// Check exact match.
//
hashid = my_strhash( partial );
for( cvar = cvar_vars ; cvar ; cvar = cvar->next )
{
if( hashid == cvar->id )
{
return cvar->name;
}
}
//
// Check partial match.
//
for( cvar = cvar_vars ; cvar ; cvar = cvar->next )
{
if( ! strncmp( partial, cvar->name, len ) )
{
return cvar->name;
}
}
return NULL;
}
/*
-----------------------------------------------------------------------------
Function: Cvar_Get -Get cvar structure.
Parameters:
var_name -[in] the name of the cvar variable.
var_value -[in] string value of the cvar variable.
flags -[in] see CVARFlags for more information.
Returns: NULL on error, otherwise valid pointer to cvar_t structure.
Notes:
If the variable already exists, the value will not be set and
the flags will be or'ed.
-----------------------------------------------------------------------------
*/
PUBLIC cvar_t *Cvar_Get( const char *var_name, const char *var_value, CVARFlags flags )
{
cvar_t *var;
if( flags & (CVAR_USERINFO | CVAR_SERVERINFO) )
{
if( ! Cvar_InfoValidate( var_name ) )
{
Com_Printf( "invalid info cvar name\n" );
return NULL;
}
}
var = Cvar_FindVar( var_name );
if( var )
{
var->flags |= flags;
return var;
}
if( ! var_value )
{
return NULL;
}
if( flags & (CVAR_USERINFO | CVAR_SERVERINFO) )
{
if( ! Cvar_InfoValidate( var_value ) )
{
Com_Printf( "invalid info cvar value\n" );
return NULL;
}
}
var = Z_Malloc( sizeof( *var ) );
var->name = my_CopyString( var_name );
var->string = my_CopyString( var_value );
var->id = my_strhash( var_name );
var->modified = true;
var->value = (float)atof( var->string );
// link the variable in
var->next = cvar_vars;
cvar_vars = var;
var->flags = flags;
return var;
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE cvar_t *Cvar_Set2( const char *var_name, const char *value, _boolean force )
{
cvar_t *var;
var = Cvar_FindVar( var_name );
if( ! var )
{ // create it
return Cvar_Get( var_name, value, CVAR_INIT );
}
if( var->flags & (CVAR_USERINFO | CVAR_SERVERINFO) )
{
if( ! Cvar_InfoValidate( value ) )
{
Com_Printf( "invalid info cvar value\n" );
return var;
}
}
if( ! force )
{
if( var->flags & CVAR_NOSET )
{
Com_Printf( "%s is write protected.\n", var_name );
return var;
}
if( var->flags & CVAR_LATCH )
{
if( var->latched_string )
{
if( strcmp( value, var->latched_string ) == 0 )
{
return var;
}
Z_Free( var->latched_string );
}
else
{
if( strcmp( value, var->string ) == 0 )
{
return var;
}
}
return var;
}
}
else
{
if( var->latched_string )
{
Z_Free( var->latched_string );
var->latched_string = NULL;
}
}
if( ! strcmp( value, var->string ) )
{
return var; // not changed
}
var->modified = true;
if( var->flags & CVAR_USERINFO )
{
userinfo_modified = true; // transmit at next oportunity
}
Z_Free( var->string ); // free the old value string
var->string = my_CopyString( value );
var->value = (float)atof( var->string );
return var;
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC cvar_t *Cvar_ForceSet( const char *var_name, const char *value )
{
return Cvar_Set2( var_name, value, true );
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC cvar_t *Cvar_Set( const char *var_name, const char *value )
{
return Cvar_Set2( var_name, value, false );
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC cvar_t *Cvar_FullSet( const char *var_name, const char *value, CVARFlags flags )
{
cvar_t *var;
var = Cvar_FindVar( var_name );
if( ! var )
{ // create it
return Cvar_Get( var_name, value, flags );
}
var->modified = true;
if( var->flags & CVAR_USERINFO )
{
userinfo_modified = true; // transmit at next oportunity
}
Z_Free( var->string ); // free the old value string
var->string = my_CopyString( value );
var->value = (float)atof( var->string );
var->flags = flags;
return var;
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Cvar_SetValue( const char *var_name, float value )
{
char val[ 32 ];
if( value == (int)value )
{
my_snprintf( val, sizeof( val ), "%i", (int)value );
}
else
{
my_snprintf( val, sizeof( val ), "%f", value );
}
Cvar_Set( var_name, val );
}
/*
-----------------------------------------------------------------------------
Function: Cvar_GetLatchedVars -Any variables with latched values will now
be updated
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Cvar_GetLatchedVars( void )
{
cvar_t *var;
for( var = cvar_vars ; var ; var = var->next )
{
if( ! var->latched_string )
{
continue;
}
Z_Free( var->string );
var->string = var->latched_string;
var->latched_string = NULL;
var->value = (float)atof(var->string);
}
}
/*
-----------------------------------------------------------------------------
Function: Cvar_Command -Handles variable inspection and changing from
the console.
Parameters: Nothing.
Returns: false if variable not found, otherwise true.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC _boolean Cvar_Command( void )
{
cvar_t *v;
// check variables
v = Cvar_FindVar( Cmd_Argv( 0 ) );
if( ! v )
{
return false;
}
// perform a variable print or set
if( Cmd_Argc() == 1 )
{
Com_Printf( "\"%s\" is \"%s\"\n", v->name, v->string );
return true;
}
Cvar_Set( v->name, Cmd_Argv( 1 ) );
return true;
}
/*
-----------------------------------------------------------------------------
Function: Cvar_Set_f -Allows setting and defining of arbitrary cvars from console.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void Cvar_Set_f( void )
{
int c;
int flags;
c = Cmd_Argc();
if( c != 3 && c != 4 )
{
Com_Printf( "usage: set <variable> <value> [u / s]\n" );
return;
}
if( c == 4 )
{
if( ! strcmp( Cmd_Argv( 3 ), "u" ) )
{
flags = CVAR_USERINFO;
}
else if( ! strcmp( Cmd_Argv( 3 ), "s" ) )
{
flags = CVAR_SERVERINFO;
}
else
{
Com_Printf( "flags can only be 'u' or 's'\n" );
return;
}
Cvar_FullSet( Cmd_Argv( 1 ), Cmd_Argv( 2 ), flags );
}
else
{
Cvar_Set( Cmd_Argv( 1 ), Cmd_Argv( 2 ) );
}
}
/*
-----------------------------------------------------------------------------
Function: Cvar_WriteVariables -Appends lines containing "set variable value"
for all variables with the archive flag set
to true.
Parameters:
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Cvar_WriteVariables( const char *path )
{
cvar_t *var;
char buffer[1024];
FILE *f;
f = fopen( path, "a" );
for( var = cvar_vars ; var ; var = var->next )
{
if( var->flags & CVAR_ARCHIVE )
{
my_snprintf( buffer, sizeof( buffer ), "set %s \"%s\"\n", var->name, var->string );
fprintf( f, "%s", buffer );
}
}
fclose( f );
}
/*
-----------------------------------------------------------------------------
Function: Cvar_List_f -Print all cvars to the console.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void Cvar_List_f( void )
{
cvar_t *var;
int i;
i = 0;
for( var = cvar_vars ; var ; var = var->next, ++i )
{
if( var->flags & CVAR_ARCHIVE )
{
Com_Printf ("*");
}
else
{
Com_Printf (" ");
}
if( var->flags & CVAR_USERINFO )
{
Com_Printf ("U");
}
else
{
Com_Printf (" ");
}
if (var->flags & CVAR_SERVERINFO)
{
Com_Printf ("S");
}
else
{
Com_Printf (" ");
}
if( var->flags & CVAR_NOSET )
{
Com_Printf ("-");
}
else if (var->flags & CVAR_LATCH)
{
Com_Printf ("L");
}
else
{
Com_Printf (" ");
}
Com_Printf (" %s \"%s\"\n", var->name, var->string);
}
Com_Printf ("%i cvars\n", i);
}
PUBLIC _boolean userinfo_modified;
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE char *Cvar_BitInfo( int bit )
{
return NULL;
/* static char info[ MAX_INFO_STRING ];
cvar_t *var;
info[0] = 0;
for (var = cvar_vars ; var ; var = var->next)
{
if (var->flags & bit)
Info_SetValueForKey (info, var->name, var->string);
}
return info;
*/
}
/*
-----------------------------------------------------------------------------
Function: Cvar_Userinfo -Get CVAR_USERINFO cvars in a string.
Parameters: Nothing.
Returns: An info string containing all the CVAR_USERINFO cvars.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *Cvar_Userinfo( void )
{
return Cvar_BitInfo( CVAR_USERINFO );
}
/*
-----------------------------------------------------------------------------
Function: Cvar_Serverinfo -Get CVAR_SERVERINFO cvars in a string.
Parameters: Nothing.
Returns: An info string containing all the CVAR_SERVERINFO cvars.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *Cvar_Serverinfo( void )
{
return Cvar_BitInfo( CVAR_SERVERINFO );
}
/*
-----------------------------------------------------------------------------
Function: Cvar_Init -Initialize cvar console functions.
Parameters: Nothing.
Returns: Nothing.
Notes:
This is done so that we can read in archived cvars from cfg files.
Also to list all the cvar variables.
-----------------------------------------------------------------------------
*/
PUBLIC void Cvar_Init( void )
{
Cmd_AddCommand( "set", Cvar_Set_f );
Cmd_AddCommand( "listCvars", Cvar_List_f );
}

162
wolf3d/code/env/cvar.h vendored Normal file
View File

@@ -0,0 +1,162 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* cvar.h: Dynamic variable tracking.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
/*
Notes:
Dynamic variable tracking.
cvar_t variables are used to hold scalar or string variables
that can be changed or displayed at the console or prog code
as well as accessed directly in C code.
The user can access cvars from the console in three ways:
r_draworder -prints the current value
r_draworder 0 -sets the current value to 0
set r_draworder 0 -as above, but creates the cvar if not present
Cvars are restricted from having the same names as commands to keep this
module from being ambiguous.
This module is implemented by cvar.c
*/
#ifndef __CVAR_H__
#define __CVAR_H__
#include "arch.h"
#if 0
typedef enum _CVARType
{
CVAR_DEFAULT = BIT( 0 ), // Just create it with no flag value.
CVAR_BOOL = BIT( 0 ), // Set to cause it to be saved to vars.rc
CVAR_INT = BIT( 0 ), // Added to userinfo when changed.
CVAR_FLOAT = BIT( 0 ), // Added to serverinfo when changed.
CVAR_STRING = BIT( 0 ), // Don't allow change from console at all,
// but can be set from the command line.
CVAR_LATCH = BIT( 0 ), // Save changes until server restart.
} CVARType;
#endif
typedef enum _CVARFlags
{
CVAR_INIT = 0x0, // Just create it with no flag value.
CVAR_ARCHIVE = 0x1, // Set to cause it to be saved to vars.rc
CVAR_USERINFO = 0x2, // Added to userinfo when changed.
CVAR_SERVERINFO = 0x4, // Added to serverinfo when changed.
CVAR_NOSET = 0x8, // Don't allow change from console at all,
// but can be set from the command line.
CVAR_LATCH = 0x10, // Save changes until server restart.
} CVARFlags;
// nothing outside the Cvar_*() functions should modify these fields!
typedef struct cvar_s
{
char *name;
char *string;
W32 id;
char *latched_string; // for CVAR_LATCH vars
int flags;
_boolean modified; // set each time the cvar is changed
float value;
struct cvar_s *next;
} cvar_t;
extern cvar_t *cvar_vars;
extern cvar_t *Cvar_Get( const char *var_name, const char *value, CVARFlags flags );
// creates the variable if it doesn't exist, or returns the existing one
// if it exists, the value will not be changed, but flags will be ORed in
// that allows variables to be unarchived without needing bitflags
extern cvar_t *Cvar_Set( const char *var_name, const char *value );
// will create the variable if it doesn't exist
extern cvar_t *Cvar_ForceSet( const char *var_name, const char *value );
// will set the variable even if NOSET or LATCH
extern cvar_t *Cvar_FullSet( const char *var_name, const char *value, CVARFlags flags );
extern void Cvar_SetValue( const char *var_name, float value );
// expands value to a string and calls Cvar_Set
extern float Cvar_VariableValue( const char *var_name );
// returns 0 if not defined or non numeric
extern char *Cvar_VariableString( const char *var_name );
// returns an empty string if not defined
extern char *Cvar_CompleteVariable( const char *partial );
// attempts to match a partial variable name for command line completion
// returns NULL if nothing fits
extern void Cvar_GetLatchedVars( void );
// any CVAR_LATCHED variables that have been set will now take effect
extern _boolean Cvar_Command( void );
// called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
// command. Returns true if the command was a variable reference that
// was handled. (print or change)
extern void Cvar_WriteVariables( const char *path );
// appends lines containing "set variable value" for all variables
// with the archive flag set to true.
extern void Cvar_Init( void );
extern char *Cvar_Userinfo( void );
// returns an info string containing all the CVAR_USERINFO cvars
extern char *Cvar_Serverinfo( void );
// returns an info string containing all the CVAR_SERVERINFO cvars
extern _boolean userinfo_modified;
// this is set each time a CVAR_USERINFO variable is changed
// so that the client knows to send it to the server
#endif /* __CVAR_H__ */

302
wolf3d/code/env/fileio.c vendored Normal file
View File

@@ -0,0 +1,302 @@
/*
Copyright (C) 2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../wolfiphone.h"
// if true, use mmap instead of alloc and read
//#define USE_MMAP
/*
-----------------------------------------------------------------------------
Function: FS_GetLoadedFilePointer() -Get file pointer.
Parameters:
filestream -[in] Target file handle.
origin -[in] Pointer position
SEEK_SET -Beginning of file.
SEEK_CUR -Current position of file pointer.
SEEK_END -End of file.
Returns: File pointer on success, otherwise NULL.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void *FS_GetLoadedFilePointer( filehandle_t *fhandle, W32 origin )
{
switch( origin )
{
case SEEK_SET:
return( (void *)fhandle->ptrStart );
case SEEK_END:
return( (void *)fhandle->ptrEnd );
case SEEK_CUR:
return( (void *)fhandle->ptrCurrent );
}
return NULL;
}
/*
-----------------------------------------------------------------------------
Function: FS_GetFileSize() -Get the length of a file.
Parameters: filestream -[in] Target file handle.
Returns: The file length in bytes.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC SW32 FS_GetFileSize( filehandle_t *fhandle )
{
return fhandle->filesize;
}
/*
-----------------------------------------------------------------------------
Function: FS_FileSeek() -Moves the file pointer to a specified location.
Parameters:
fhandle -[in] Pointer to filehandle_t structure.
offset -[in] Number of bytes from origin
origin -[in] Initial position
SEEK_SET -Beginning of file.
SEEK_CUR -Current position of file pointer.
SEEK_END -End of file.
Returns: If successful zero, otherwise a nonzero value.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC W32 FS_FileSeek( filehandle_t *fhandle, SW32 offset, W32 origin )
{
switch( origin )
{
case SEEK_SET:
if( offset < 0 ||
offset > fhandle->filesize )
{
return 1;
}
fhandle->ptrCurrent = fhandle->ptrStart + offset;
break;
case SEEK_END:
if( offset > 0 )
{
return 1;
}
// offset is negative
if( (fhandle->filesize + offset) < 0 )
{
return 1;
}
// offset is negative
fhandle->ptrCurrent = fhandle->ptrEnd + offset;
break;
case SEEK_CUR:
if( offset < 0 )
{
// offset is negative
if( ((fhandle->ptrCurrent - fhandle->ptrStart) + offset) < 0 )
{
return 1;
}
}
if( offset > 0 )
{
if( offset > (fhandle->ptrEnd - fhandle->ptrCurrent) )
{
return 1;
}
}
fhandle->ptrCurrent += offset;
break;
default:
return 1;
}
return 0;
}
/*
-----------------------------------------------------------------------------
Function: FS_FileTell() -Gets the current position of a file pointer.
Parameters: fhandle -[in] Pointer to filehandle_t structure.
Returns: If successful current file position, otherwise -1.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC SW32 FS_FileTell( filehandle_t *fhandle )
{
return( fhandle->ptrCurrent - fhandle->ptrStart );
}
/*
-----------------------------------------------------------------------------
Function: FS_CloseFile -Close file handle.
Parameters: filestream -[in] Pointer to valid FILE structure.
Returns: Nothing.
Notes: Closes a file stream that was returned by FS_FOpenFile.
-----------------------------------------------------------------------------
*/
PUBLIC void FS_CloseFile( filehandle_t *fhandle )
{
if( fhandle->filedata )
{
#ifdef USE_MMAP
if ( munmap( fhandle->filedata, fhandle->filesize ) != 0 ) {
assert( 0 );
}
#else
free( fhandle->filedata );
#endif
fhandle->filedata = NULL;
}
Z_Free( fhandle );
}
/*
-----------------------------------------------------------------------------
Function: FS_OpenFile -Open file from the file system.
-----------------------------------------------------------------------------
*/
PUBLIC filehandle_t *FS_OpenFile( const char *filename, W32 FlagsAndAttributes )
{
char netpath[ MAX_OSPATH ];
filehandle_t *hFile;
const char *pathBase;
struct stat s;
int fd;
//
// Check for the file in the directory tree
//
if ( FlagsAndAttributes & FA_FILE_IPHONE_DOC_DIR ) {
extern char iphoneDocDirectory[1024];
pathBase = iphoneDocDirectory;
my_snprintf( netpath, sizeof( netpath ), "%s/%s", pathBase, filename );
} else {
// extern char iphoneAppDirectory[1024];
// pathBase = iphoneAppDirectory;
pathBase = FS_Gamedir();
my_snprintf( netpath, sizeof( netpath ), "%s/%s", pathBase, filename );
}
// high performance file mapping path, avoiding stdio
fd = open( netpath, O_RDONLY );
if ( fd == -1 ) {
return NULL;
}
fstat( fd, &s );
hFile = Z_Malloc( sizeof( filehandle_t ) );
memset( hFile, 0, sizeof( filehandle_t ) );
hFile->filesize = s.st_size;
#ifdef USE_MMAP
hFile->filedata = mmap( NULL, hFile->filesize, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0 );
if ( (int)hFile->filedata == -1 ) {
Com_Printf( "mmap failed: %s\n", strerror( errno ) );
assert( 0 );
}
#else
hFile->filedata = malloc( hFile->filesize );
read( fd, hFile->filedata, hFile->filesize );
#endif
hFile->ptrStart = hFile->ptrCurrent = (PW8)hFile->filedata;
hFile->ptrEnd = (PW8)hFile->filedata + hFile->filesize;
hFile->bLoaded = true;
// mmap doesn't require the file to stay open
close( fd );
return hFile;
}
/*
-----------------------------------------------------------------------------
Function: FS_ReadFile -Reads data from a stream.
Parameters: buffer -[in/out] Storage location for data.
size -[in] Item size in bytes.
count -[in] Maximum number of items to be read.
fhandle -[in] Pointer to valid filehandle_t structure.
Returns: On success number of full items actually read, otherwise -1.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC SW32 FS_ReadFile( void *buffer, W32 size, W32 count, filehandle_t *fhandle )
{
W8 *buf = (PW8)buffer;
W32 i;
if( (size * count) > (fhandle->ptrEnd - fhandle->ptrCurrent) )
{
SW32 read;
read = (fhandle->ptrEnd - fhandle->ptrCurrent);
for( i = 0 ; i < (fhandle->ptrEnd - fhandle->ptrCurrent) ; ++i )
{
buf[ i ] = fhandle->ptrCurrent[ i ];
}
fhandle->ptrCurrent = fhandle->ptrEnd;
return( read );
}
else
{
for( i = 0 ; i < (size * count) ; ++i, fhandle->ptrCurrent++ )
{
buf[ i ] = *fhandle->ptrCurrent;
}
return( (size * count) / size );
}
/* should never get here */
return -1;
}

162
wolf3d/code/env/files.c vendored Normal file
View File

@@ -0,0 +1,162 @@
/*
Copyright (C) 2004 Michael Liebscher <johnnycanuck@users.sourceforge.net>
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* files.c: Interface to file i/o layer.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
/*
Notes:
This module accesses data through a hierarchal file system, but the
contents of the file system can be transparently merged from several
sources.
The "base directory" is the path to the directory holding the
executable and all game directories. The sys_* files pass this to
host_init in quakeparms_t->basedir. This can be overridden with the
"-basedir" command line parm to allow code debugging in a different
directory. The base directory is only used during file system
initialization.
The "game directory" is the first tree on the search path and directory
that all generated files (save games, screen shots, demos, config
files) will be saved to. This can be overridden with the "-game"
command line parameter. The game directory can never be changed while
the application is executing. This is a precaution against having a
malicious server instruct clients to write files over areas they
shouldn't.
*/
#include "../wolfiphone.h"
PRIVATE char fs_gamedir[ MAX_OSPATH ];
/*
-----------------------------------------------------------------------------
Function: FS_Gamedir -Get root directory.
Parameters: Nothing.
Returns: String with the name of the root directory.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *FS_Gamedir( void )
{
return fs_gamedir;
}
/*
-----------------------------------------------------------------------------
Function: FS_ListFiles -List files.
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE char **FS_ListFiles( char *findname, int *numfiles, unsigned musthave, unsigned canthave )
{
char *s;
int nfiles = 0;
char **list = 0;
s = FS_FindFirst( findname, musthave, canthave );
while ( s )
{
if ( s[strlen(s)-1] != '.' )
nfiles++;
s = FS_FindNext( musthave, canthave );
}
FS_FindClose ();
if ( !nfiles )
return NULL;
nfiles++; // add space for a guard
*numfiles = nfiles;
list = MM_MALLOC( sizeof( char * ) * nfiles );
if( list == NULL )
{
MM_OUTOFMEM( "list" );
}
memset( list, 0, sizeof( char * ) * nfiles );
s = FS_FindFirst( findname, musthave, canthave );
nfiles = 0;
while( s )
{
if( s[ strlen( s ) - 1 ] != '.' )
{
list[ nfiles ] = strdup( s );
(void)my_strlwr( list[ nfiles ] );
nfiles++;
}
s = FS_FindNext( musthave, canthave );
}
FS_FindClose();
return list;
}
/*
-----------------------------------------------------------------------------
Function: FS_InitFilesystem -Initialize file system.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void FS_InitFilesystem( void )
{
char *p;
p = getenv("CWD");
sprintf( fs_gamedir, "%s/base", p );
}

161
wolf3d/code/env/filestring.c vendored Normal file
View File

@@ -0,0 +1,161 @@
/*
Copyright (C) 2004-2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* filestring.c: Portable file path/name manipulation methods.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#include "../wolfiphone.h"
/*
-----------------------------------------------------------------------------
Function: FS_CreatePath -Creates given path.
Parameters: path -[in] Pointer to NULL terminated string that contains directory
path.
Returns: Nothing.
Notes: Creates any directories needed to store the given filename.
-----------------------------------------------------------------------------
*/
PUBLIC void FS_CreatePath( char *path )
{
char *ofs;
for( ofs = path + 1; *ofs; ofs++ )
{
if( *ofs == '/' )
{ // create the directory
*ofs = '\0';
FS_CreateDirectory( path );
*ofs = '/';
}
}
}
PUBLIC void FS_FilePath( char *in, char *out )
{
char *s;
s = in + strlen( in ) - 1;
while( s != in && *s != '/' )
{
s--;
}
strncpy( out, in, s-in );
out[ s - in ] = '\0'; // NUL-terminate string.
}
PUBLIC char *FS_SkipPath( char *pathname )
{
char *last;
last = pathname;
while( *pathname )
{
if( *pathname == '/' )
{
last = pathname + 1;
}
pathname++;
}
return last;
}
PUBLIC void FS_StripExtension( char *in, char *out )
{
while( *in && *in != '.' )
{
*out++ = *in++;
}
*out = '\0'; // NUL-terminate string.
}
PUBLIC char *FS_FileExtension( char *in )
{
static char exten[ 8 ];
int i;
while( *in && *in != '.' )
{
in++;
}
if( ! *in )
{
return "";
}
in++;
for( i = 0 ; i < 7 && *in ; i++, in++ )
{
exten[ i ] = *in;
}
exten[ i ] = '\0'; // NUL-terminate string.
return exten;
}
PUBLIC void FS_FileBase( char *in, char *out )
{
char *s, *s2;
s = in + strlen( in ) - 1;
while( s != in && *s != '.' )
{
s--;
}
for( s2 = s ; s2 != in && *s2 != '/' ; s2-- )
{
;
}
if( s - s2 < 2 )
{
out[ 0 ] = '\0'; // NUL-terminate string.
}
else
{
s--;
strncpy( out, s2 + 1, s - s2 );
out[ s - s2 ] = '\0'; // NUL-terminate string.
}
}

55
wolf3d/code/env/filestring.h vendored Normal file
View File

@@ -0,0 +1,55 @@
/*
Copyright (C) 2004-2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* filesystem.h: Interface to filesystem layer.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
/*
Notes:
This module is implemented by filestring.c.
*/
#ifndef __FILESTRING_H__
#define __FILESTRING_H__
extern void FS_CreatePath( char *path );
extern void FS_FilePath( char *in, char *out );
extern char *FS_SkipPath( char *pathname );
extern void FS_StripExtension( char *in, char *out );
extern char *FS_FileExtension( char *in );
extern void FS_FileBase( char *in, char *out );
#endif /* __FILESTRING_H__ */

134
wolf3d/code/env/filesystem.h vendored Normal file
View File

@@ -0,0 +1,134 @@
/*
Copyright (C) 2004-2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* filesystem.h: Interface to filesystem layer.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
/*
Notes:
This module is implemented by files.c.
*/
#ifndef __FILESYSTEM_H__
#define __FILESYSTEM_H__
#define MAX_GAMEPATH 256 // max length of a game pathname
#define MAX_OSPATH 256 // max length of a filesystem pathname
extern void FS_InitFilesystem(void);
extern char *FS_Gamedir(void);
/////////////////////////////////////////////////////////////////////
//
// PORTABLE FILE SYSTEM SERVICES
//
/////////////////////////////////////////////////////////////////////
typedef struct
{
FILE *hFile;
/* Following is used when the file is loaded into memory */
_boolean bLoaded; /* Was file loaded into memory? */
W32 filesize; /* Size of file data in bytes */
W8 *ptrStart; /* pointer to start of file data block */
W8 *ptrCurrent; /* pointer to current position in file data block */
W8 *ptrEnd; /* pointer to end of file data block */
void *filedata; /* file data loaded into memory */
} filehandle_t;
/* Desired Access Flags */
#define DA_GENERIC_READ 0x01
#define DA_GENERIC_WRITE 0x02
/* Flags and Attributes */
#define FA_FILE_FLAG_LOAD 0x01
#define FA_FILE_FLAG_CACHE 0x02
#define FA_FILE_IPHONE_DOC_DIR 0x04
extern filehandle_t *FS_OpenFile( const char *filename, W32 FlagsAndAttributes );
extern void FS_CloseFile( filehandle_t *fhandle );
// note: this can't be called from another DLL, due to MS libc issues
extern SW32 FS_ReadFile( void *buffer, W32 size, W32 count, filehandle_t *fhandle );
extern SW32 FS_FileTell( filehandle_t *fhandle );
extern W32 FS_FileSeek( filehandle_t *fhandle, SW32 offset, W32 origin );
extern SW32 FS_GetFileSize( filehandle_t *fhandle );
extern void *FS_GetLoadedFilePointer( filehandle_t *fhandle, W32 origin );
extern void FS_CreatePath( char *path );
extern void FS_FilePath( char *in, char *out );
extern char *FS_SkipPath( char *pathname );
/////////////////////////////////////////////////////////////////////
//
// NON-PORTABLE FILE SYSTEM SERVICES
//
/////////////////////////////////////////////////////////////////////
extern W8 FS_CreateDirectory( const char *dirname );
extern W8 FS_ChangeCurrentDirectory( const char *path );
extern _boolean FS_DeleteFile( const char *filename );
extern _boolean FS_RemoveDirectory( const char *pathname );
// directory/file attributes
#define FA_ARCH 0x01
#define FA_HIDDEN 0x02
#define FA_RDONLY 0x04
#define FA_DIR 0x08
#define FA_SYSTEM 0x10
// pass in an attribute mask of things you wish to REJECT
extern char *FS_FindFirst( const char *path, W32 musthave, W32 canthave );
extern char *FS_FindNext( W32 musthave, W32 canthave );
extern void FS_FindClose( void );
#endif /* __FILESYSTEM_H__ */

492
wolf3d/code/env/font_manager.c vendored Normal file
View File

@@ -0,0 +1,492 @@
/*
Copyright (C) 2004-2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* font_manager.c: Font management.
*
*/
#include "../wolfiphone.h"
/*
! " # $ % & ' ( ) * + , - . /
0 1 2 3 4 5 6 7 8 9 : ; ( = ) ?
@ A B C D E F G H I J K L M N O
P Q R S T U V W X Y Z [ / ] ^ -
` a b c d e f g h i j k l m n o
p q r s t u v w x y z { | } ~
*/
#define MAX_FONTS 4
font_t *myfonts[ MAX_FONTS ];
PRIVATE W32 num_fonts = 0;
typedef struct
{
char *start, *end;
} string_seg_t;
font_t *createFont( const char *filename )
{
font_t *temp_font;
char *datname;
filehandle_t *fp;
W32 size;
W32 i;
if( num_fonts == (MAX_FONTS - 1) )
{
Com_Printf( "[createFont]: No more font slots open\n" );
return NULL;
}
temp_font = Z_Malloc( sizeof( font_t ) );
temp_font->texfont = TM_FindTexture( filename, TT_Pic );
if( NULL == temp_font->texfont )
{
Com_Printf( "[createFont]: unable to open file (%s)\n", filename );
Z_Free( temp_font );
return NULL;
}
memset( temp_font->nCharWidth, 0, sizeof( temp_font->nCharWidth ) );
datname = MM_MALLOC( strlen( filename ) + 1 );
FS_StripExtension( (char *)filename, datname );
my_strlcat( datname, ".dat", strlen( filename ) + 1 );
fp = FS_OpenFile( datname, 0 );
if( NULL == fp )
{
Com_Printf( "[createFont]: unable to open file (%s)\n", datname );
MM_FREE( datname );
Z_Free( temp_font );
return NULL;
}
size = FS_GetFileSize( fp );
// check header size
if( size < 10 )
{
Com_Printf( "[createFont]: File (%s) has incorrect file length\n", datname );
MM_FREE( datname );
Z_Free( temp_font );
FS_CloseFile( fp );
return NULL;
}
// Check sig of font dat file
FS_ReadFile( &size, 1, 4, fp );
FS_ReadFile( &temp_font->nMaxWidth, 1, 1, fp );
FS_ReadFile( &temp_font->nMaxHeight, 1, 1, fp );
FS_ReadFile( &size, 1, 4, fp );
size = LittleLong( size );
if( size > 127 )
{
Com_Printf( "[createFont]: File (%s) has incorrect Character Width array\n", datname );
MM_FREE( datname );
Z_Free( temp_font );
FS_CloseFile( fp );
return NULL;
}
FS_ReadFile( &temp_font->nCharWidth, 1, size, fp );
FS_CloseFile( fp );
temp_font->nSize = 2;
temp_font->colour[ 3 ] = 255;
temp_font->hFrac = (float)(temp_font->nMaxHeight / (float)temp_font->texfont->height);
temp_font->wFrac = (float)(temp_font->nMaxWidth / (float)temp_font->texfont->width);
for( i = 0 ; i < MAX_FONTS ; ++i )
{
if( ! myfonts[ i ] )
{
break;
}
}
if( i == (MAX_FONTS - 1) )
{
Com_Printf( "[createFont]: No more font slots open\n" );
MM_FREE( datname );
Z_Free( temp_font );
return NULL;
}
myfonts[ i ] = temp_font;
MM_FREE( datname );
return temp_font;
}
void Font_Init( void )
{
W32 i;
for( i = 0 ; i < MAX_FONTS ; ++i )
{
myfonts[ i ] = NULL;
}
(void)createFont( "iphone/font1.tga" );
// (void)createFont( "iphone/font2.tga" );
}
void Font_Shutdown( void )
{
}
void Font_GetMsgDimensions( FONTSELECT fs, const char *string, int *w, int *h )
{
int width = 0;
int mx = 0;
W16 scale;
int height;
if( ! myfonts[ fs ] )
{
*w = *h = 0;
return;
}
scale = myfonts[ fs ]->nMaxHeight * myfonts[ fs ]->nSize;
height = scale;
while( *string )
{
if( *string == '\n' )
{
if( mx > width )
{
width = mx;
}
mx = 0;
height += scale;
++string;
continue;
}
mx += myfonts[ fs ]->nCharWidth[ (*string)-32 ] * myfonts[ fs ]->nSize;
++string;
}
if( mx > width )
{
width = mx;
}
*w = width;
*h = height;
}
void Font_SetSize( FONTSELECT fs, W16 size )
{
if( myfonts[ fs ] )
{
myfonts[ fs ]->nSize = size;
}
}
W16 Font_GetSize( FONTSELECT fs )
{
if( myfonts[ fs ] )
{
return( myfonts[ fs ]->nMaxHeight * myfonts[ fs ]->nSize );
}
return 0;
}
void Font_SetColour( FONTSELECT fs, colour3_t c )
{
if( myfonts[ fs ] )
{
myfonts[ fs ]->colour[ 0 ] = c[ 0 ];
myfonts[ fs ]->colour[ 1 ] = c[ 1 ];
myfonts[ fs ]->colour[ 2 ] = c[ 2 ];
}
}
extern void R_Draw_Character( int x, int y, int num, font_t *myfont );
void Font_put_line( FONTSELECT fs, int x, int y, const char *string )
{
int mx = x;
W16 scale;
if( ! myfonts[ fs ] )
{
return;
}
scale = myfonts[ fs ]->nSize;
while( *string )
{
if( *string == '\n' )
{
mx = x;
y += myfonts[ fs ]->nMaxHeight * scale;
++string;
continue;
}
R_Draw_Character( mx, y, *string, myfonts[ fs ] );
mx += myfonts[ fs ]->nCharWidth[ (*string)-32 ] * scale;
++string;
}
}
void Font_put_lineR2L( FONTSELECT fs, int x, int y, const char *string )
{
int mx = x;
unsigned int charindex;
unsigned int i;
if( ! myfonts[ fs ] )
{
return;
}
for ( i = 0; i < strlen( string ); ++i )
{
charindex = strlen( string ) - i - 1;
mx -= myfonts[ fs ]->nCharWidth[ string[ charindex ]-32 ] * myfonts[ fs ]->nSize;
R_Draw_Character( mx, y, string[ charindex ], myfonts[ fs ] );
}
}
W16 Font_put_character( FONTSELECT fs, int x, int y, W16 num )
{
if( ! myfonts[ fs ] || num > 126 )
{
return 0;
}
R_Draw_Character( x, y, num, myfonts[ fs ] );
return( myfonts[ fs ]->nCharWidth[ num - 32 ] * myfonts[ fs ]->nSize );
}
void Font_put_line_size( FONTSELECT fs, int x, int y, const char *start, const char *end )
{
int mx = x;
W16 scale;
if( ! myfonts[ fs ] )
{
return;
}
scale = myfonts[ fs ]->nSize;
while( start != end )
{
R_Draw_Character( mx, y, *start, myfonts[ fs ] );
mx += myfonts[ fs ]->nCharWidth[ (*start)-32 ] * scale;
++start;
}
}
W8 Font_get_line( FONTSELECT fs, int line_width, string_seg_t *sst )
{
int x = 0, last_word_width = 0, last_word_spaces = 0;
int in_a_word = 0;
int t_words = 0;
int t_spaces = 0;
int chars_width = 0;
W16 scale;
const char *word_start = sst->start;
if( ! myfonts[ fs ] )
{
return false;
}
scale = myfonts[ fs ]->nSize;
if( line_width < 0 )
{
line_width = 1000000;
}
while( *sst->end != '\0' && *sst->end != '\n' )
{
char c = *sst->end;
int c_width = myfonts[ fs ]->nCharWidth[ c - 32 ] * scale; // FIX ME
// we exceeded the space available for this line
if( x + c_width > line_width )
{
if( in_a_word )
{
chars_width = last_word_width;
sst->end = (char *)word_start;
t_spaces = last_word_spaces;
}
return t_words ? true : false;
}
x += c_width;
if( c != ' ' )
{
if( ! in_a_word )
{
last_word_width = chars_width;
word_start = sst->end;
}
in_a_word = 1;
chars_width += c_width;
}
else
{
if( in_a_word )
{
in_a_word = 0;
t_words++;
last_word_spaces = t_spaces;
}
t_spaces++;
}
++sst->end;
}
if( in_a_word )
{
t_words++;
}
if( *sst->end != '\0' && *sst->end == '\n' )
{
++sst->end;
}
return t_words ? true : false;
}
void Font_put_paragraph( FONTSELECT fs, short x, short y,
const char *string,
int space_between_lines,
int line_width_in_pixel )
{
string_seg_t sst;
sst.start = sst.end = (char *)string;
if( ! myfonts[ fs ] )
{
return;
}
while( Font_get_line( fs, line_width_in_pixel, &sst ) )
{
Font_put_line_size( fs, x, y, sst.start, sst.end );
if( *sst.end != '\0' && *sst.end == ' ' )
{
sst.start = sst.end;
++sst.start;
sst.end = sst.start;
}
else if( *sst.end != '\0' && *sst.end == '\n' )
{
while( *sst.end == '\n' )
{
++sst.end;
y += Font_GetSize( fs ) + space_between_lines;
}
sst.start = sst.end;
}
else
{
sst.start = sst.end;
}
y += Font_GetSize( fs ) + space_between_lines;
}
}

78
wolf3d/code/env/font_manager.h vendored Normal file
View File

@@ -0,0 +1,78 @@
/*
Copyright (C) 2004 Michael Liebscher
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* font_manager.h: Font management.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
*/
/*
Notes:
This module is implemented by font_manager.c.
*/
#ifndef __FONT_MANAGER_H__
#define __FONT_MANAGER_H__
typedef enum { FONT0 = 0, FONT1, FONT2, FONT3 } FONTSELECT;
typedef struct
{
W8 nCharWidth[ 128 ]; /* width of each character */
W8 nMaxWidth; /* box width */
W8 nMaxHeight; /* box height */
SW32 spacing; /* space between characters */
W32 nSize;
float wFrac;
float hFrac;
colour4_t colour; /* Font colour */
texture_t *texfont;
} font_t;
extern void Font_Init( void );
extern void Font_Shutdown( void );
extern void Font_SetSize( FONTSELECT fs, W16 size );
extern W16 Font_GetSize( FONTSELECT fs );
extern void Font_SetColour( FONTSELECT fs, colour3_t c );
extern void Font_put_line( FONTSELECT fs, int x, int y, const char *string );
extern void Font_put_lineR2L( FONTSELECT fs, int x, int y, const char *string );
extern W16 Font_put_character( FONTSELECT fs, int x, int y, W16 num );
extern void Font_put_paragraph( FONTSELECT fs, short x, short y,
const char *string,
int space_between_lines,
int line_width_in_pixel );
extern void Font_GetMsgDimensions( FONTSELECT fs, const char *string, int *w, int *h );
#endif /* __FONT_MANAGER_H__ */

207
wolf3d/code/env/glob.c vendored Normal file
View File

@@ -0,0 +1,207 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../wolfiphone.h"
/* Like glob_match, but match PATTERN against any final segment of TEXT. */
static int glob_match_after_star( char *pattern, char *text )
{
register char *p = pattern, *t = text;
register char c, c1;
while( (c = *p++) == '?' || c == '*' )
{
if( c == '?' && *t++ == '\0' )
{
return 0;
}
}
if( c == '\0' )
{
return 1;
}
if( c == '\\' )
{
c1 = *p;
}
else
{
c1 = c;
}
while( 1 )
{
if( (c == '[' || *t == c1) && glob_match( p - 1, t ) )
{
return 1;
}
if( *t++ == '\0' )
{
return 0;
}
}
}
/* Return nonzero if PATTERN has any special globbing chars in it. */
static int glob_pattern_p( char *pattern )
{
register char *p = pattern;
register char c;
int open = 0;
while( (c = *p++) != '\0' )
{
switch( c )
{
case '?':
case '*':
return 1;
case '[': /* Only accept an open brace if there is a close */
open++; /* brace to match it. Bracket expressions must be */
continue; /* complete, according to Posix.2 */
case ']':
if( open )
{
return 1;
}
continue;
case '\\':
if( *p++ == '\0' )
{
return 0;
}
}
}
return 0;
}
/* Match the pattern PATTERN against the string TEXT;
return 1 if it matches, 0 otherwise.
A match means the entire string TEXT is used up in matching.
In the pattern string, `*' matches any sequence of characters,
`?' matches any character, [SET] matches any character in the specified set,
[!SET] matches any character not in the specified set.
A set is composed of characters or ranges; a range looks like
character hyphen character (as in 0-9 or A-Z).
[0-9a-zA-Z_] is the set of characters allowed in C identifiers.
Any other character in the pattern must be matched exactly.
To suppress the special syntactic significance of any of `[]*?!-\',
and match the character exactly, precede it with a `\'.
*/
int glob_match(char *pattern, char *text)
{
register char *p = pattern, *t = text;
register char c;
while ((c = *p++) != '\0')
switch (c) {
case '?':
if (*t == '\0')
return 0;
else
++t;
break;
case '\\':
if (*p++ != *t++)
return 0;
break;
case '*':
return glob_match_after_star(p, t);
case '[':
{
register char c1 = *t++;
int invert;
if (!c1)
return (0);
invert = ((*p == '!') || (*p == '^'));
if (invert)
p++;
c = *p++;
while (1) {
register char cstart = c, cend = c;
if (c == '\\') {
cstart = *p++;
cend = cstart;
}
if (c == '\0')
return 0;
c = *p++;
if (c == '-' && *p != ']') {
cend = *p++;
if (cend == '\\')
cend = *p++;
if (cend == '\0')
return 0;
c = *p++;
}
if (c1 >= cstart && c1 <= cend)
goto match;
if (c == ']')
break;
}
if (!invert)
return 0;
break;
match:
/* Skip the rest of the [...] construct that already matched. */
while (c != ']') {
if (c == '\0')
return 0;
c = *p++;
if (c == '\0')
return 0;
else if (c == '\\')
++p;
}
if (invert)
return 0;
break;
}
default:
if (c != *t++)
return 0;
}
return *t == '\0';
}

22
wolf3d/code/env/glob.h vendored Normal file
View File

@@ -0,0 +1,22 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
extern int glob_match( char *pattern, char *text );

224
wolf3d/code/env/math.c vendored Normal file
View File

@@ -0,0 +1,224 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* math.c: Math routines.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#include "../wolfiphone.h"
////////////////////////////
//
// Square Root
//
////////////////////////////
/*
-----------------------------------------------------------------------------
Function: _sqrtf -Calculates the square root.
Parameters: x -[in] Nonnegative floating-point value
Returns: The square-root of x.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC float _sqrtf( float x )
{
return (float)sqrt( x );
}
/*
-----------------------------------------------------------------------------
Function: _3DNow_Sqrt -Calculates the square root.
Parameters: x -[in] Nonnegative floating-point value
Returns: The square-root of x.
Notes: 15-Bit Precision
-----------------------------------------------------------------------------
*/
#if __i386__
PUBLIC float _3DNow_Sqrt( float x )
{
float root = 0.f;
#if( _MSC_VER || __WATCOMC__ )
__asm
{
femms
movd mm0, x
pfrsqrt mm1, mm0
punpckldq mm0, mm0
pfmul mm0, mm1
movd root, mm0
femms
}
#endif
return root;
}
/*
-----------------------------------------------------------------------------
Function: _SSE_Sqrt -Calculates the square root.
Parameters: x -[in] Nonnegative floating-point value
Returns: The square-root of x.
Notes:
-----------------------------------------------------------------------------
*/
float _SSE_Sqrt( float x )
{
float root = 0.f;
#if( _MSC_VER || __WATCOMC__ )
__asm
{
sqrtss xmm0, x
movss root, xmm0
}
#endif
return root;
}
#endif /* __i386__ */
////////////////////////////
//
// End Square Root
//
////////////////////////////
float (*pfSqrt)( float x ) = _sqrtf;
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC int my_log2( int val )
{
int answer = 0;
while( ( val >>= 1 ) != 0 )
{
answer++;
}
return answer;
}
/*
-----------------------------------------------------------------------------
Function: CalcFov -Calculate the field of view.
Parameters:fov_x -[in] Must be within 1 and 179 degrees.
width -[in] Width of viewing area.
height -[in] Height of viewing area.
Returns: The field of view in degrees.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC float CalcFov( float fov_x, float width, float height )
{
if( fov_x < 1 || fov_x > 179 )
{
Com_Error( ERR_DROP, "Bad fov: %f", fov_x );
}
return (float)RAD2DEG( atan( height / ( width / tan( fov_x / 360 * M_PI ) ) ) ) * 2;
}
/*
-----------------------------------------------------------------------------
Function: MathLib_Init -Initialize optimized math routines.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void MathLib_Init( void )
{
Com_Printf( "Initializing Math Module\n" );
#if 0//__i386__
if( main_cpu_s.b3DNow )
{
// pfSqrt = _3DNow_Sqrt;
Com_Printf( "...using 3DNow!\n" );
}
if( main_cpu_s.bSSE )
{
// pfSqrt = _SSE_Sqrt;
Com_Printf( "...using SSE\n" );
}
#endif
}

158
wolf3d/code/env/matrix.c vendored Normal file
View File

@@ -0,0 +1,158 @@
/*
Copyright (C) 2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* matrix.c: Matrix math routines.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
*/
#include "../wolfiphone.h"
/*
-----------------------------------------------------------------------------
Function: Matrix3x3Multiply -Computes the product of two 3x3 matrices.
Parameters: in1, in2 -[in] 3x3 matrices.
out -[out] result.
Returns: Nothing
Notes:
Product of two 3x3 matrices
( a b c ) ( r u x ) ( ar + bs + ct au + bv + cw ax + by + cz )
( d e f ) ( s v y ) = ( dr + es + ft du + ev + fw dx + ey + fz )
( h i j ) ( t w z ) ( hr + hs + ht iu + iv + iw jx + jy + jz )
-----------------------------------------------------------------------------
*/
PUBLIC void Matrix3x3Multiply( mat3_t in1, mat3_t in2, mat3_t out )
{
out[0] = in1[0] * in2[0] + in1[1] * in2[3] + in1[2] * in2[6];
out[1] = in1[0] * in2[1] + in1[1] * in2[4] + in1[2] * in2[7];
out[2] = in1[0] * in2[2] + in1[1] * in2[5] + in1[2] * in2[8];
out[3] = in1[3] * in2[0] + in1[4] * in2[3] + in1[5] * in2[6];
out[4] = in1[3] * in2[1] + in1[4] * in2[4] + in1[5] * in2[7];
out[5] = in1[3] * in2[2] + in1[4] * in2[5] + in1[5] * in2[8];
out[6] = in1[6] * in2[0] + in1[7] * in2[3] + in1[8] * in2[6];
out[7] = in1[6] * in2[1] + in1[7] * in2[4] + in1[8] * in2[7];
out[8] = in1[6] * in2[2] + in1[7] * in2[5] + in1[8] * in2[8];
}
/*
-----------------------------------------------------------------------------
Function: MatrixIdentity -Set matrix to the identity matrix (unit matrix).
Parameters: matrix -[in/out] 4x4 matrix.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void MatrixIdentity( mat4_t matrix )
{
matrix[ 0] = 1.0; matrix[ 1] = 0.0; matrix[ 2] = 0.0; matrix[ 3] = 0.0;
matrix[ 4] = 0.0; matrix[ 5] = 1.0; matrix[ 6] = 0.0; matrix[ 7] = 0.0;
matrix[ 8] = 0.0; matrix[ 9] = 0.0; matrix[10] = 1.0; matrix[11] = 0.0;
matrix[12] = 0.0; matrix[13] = 0.0; matrix[14] = 0.0; matrix[15] = 1.0;
}
/*
-----------------------------------------------------------------------------
Function: MatrixInvert -Invert a matrix.
Parameters:
in -[in] Input matrix
out -[out] Output matrix.
Returns: Nothing.
Notes: Matrix MUST be orthonormal
-----------------------------------------------------------------------------
*/
PUBLIC void MatrixInvert( mat4_t in, mat4_t out )
{
// Transpose rotation
out[ 0] = in[ 0]; out[ 1] = in[ 4]; out[ 2] = in[ 8];
out[ 4] = in[ 1]; out[ 5] = in[ 5]; out[ 6] = in[ 9];
out[ 8] = in[ 2]; out[ 9] = in[ 6]; out[10] = in[10];
// Clear shearing terms
out[3] = 0.0f; out[7] = 0.0f; out[11] = 0.0f; out[15] = 1.0f;
// Translation is minus the dot of translation and rotations
out[12] = -(in[12] * in[ 0]) - (in[13] * in[ 1]) - (in[14] * in[ 2]);
out[13] = -(in[12] * in[ 4]) - (in[13] * in[ 5]) - (in[14] * in[ 6]);
out[14] = -(in[12] * in[ 8]) - (in[13] * in[ 9]) - (in[14] * in[10]);
}
/*
-----------------------------------------------------------------------------
Function: VectorMatrixMultiply -Multiply a vector by a matrix.
Parameters:
vecIn -[in] Input vector.
m -[in] Input matrix.
vecOut -[out] Output vector.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void VectorMatrixMultiply( vec3_t vecIn, mat4_t m, vec3_t vecOut )
{
vecOut[0] = (vecIn[0] * m[ 0]) + (vecIn[1] * m[ 4]) + (vecIn[2] * m[ 8]) + m[12];
vecOut[1] = (vecIn[0] * m[ 1]) + (vecIn[1] * m[ 5]) + (vecIn[2] * m[ 9]) + m[13];
vecOut[2] = (vecIn[0] * m[ 2]) + (vecIn[1] * m[ 6]) + (vecIn[2] * m[10]) + m[14];
}
/*
-----------------------------------------------------------------------------
Function: VectorMatrix3x3Multiply -Multiply a vector by just the 3x3 portion
of a matrix.
Parameters:
in -[in] Input vector.
m -[in] Input matrix.
out -[out] Output vector.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void VectorMatrix3x3Multiply( vec3_t in, mat4_t m, vec3_t out )
{
out[0] = (in[0] * m[ 0]) + (in[1] * m[ 4]) + (in[2] * m[ 8]);
out[1] = (in[0] * m[ 1]) + (in[1] * m[ 5]) + (in[2] * m[ 9]);
out[2] = (in[0] * m[ 2]) + (in[1] * m[ 6]) + (in[2] * m[10]);
}

43
wolf3d/code/env/matrix.h vendored Normal file
View File

@@ -0,0 +1,43 @@
/*
Copyright (C) 2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* matrix.h: Matrix math routines.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
*/
#ifndef __MATRIX_H__
#define __MATRIX_H__
#include "vector.h"
typedef float mat3_t[ 9 ]; // 3x3 matrix
typedef float mat4_t[ 16 ]; // 4x4 matrix
extern void Matrix3x3Multiply( mat3_t in1, mat3_t in2, mat3_t out ) ;
extern void MatrixIdentity( mat4_t matrix );
extern void MatrixInvert( mat4_t in, mat4_t out );
extern void VectorMatrixMultiply( vec3_t vecIn, mat4_t m, vec3_t vecOut );
extern void VectorMatrix3x3Multiply( vec3_t vecIn, mat4_t m, vec3_t vecOut );
#endif /* __MATRIX_H__ */

193
wolf3d/code/env/memory.c vendored Normal file
View File

@@ -0,0 +1,193 @@
/*
Copyright (C) 2004-2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* memory.c: Memory allocation module.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
*/
#include "../wolfiphone.h"
#ifndef DEBUG_MEMORY
#define DEBUG_MEMORY 0
#endif
/*
-----------------------------------------------------------------------------
Function: Memory_malloc -Allocates memory blocks.
Parameters: size -[in] Bytes to allocate.
Returns:
Void pointer to the allocated space on success, or NULL if
there is insufficient memory available.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void *Memory_malloc( size_t size )
{
void *ptr;
ptr = malloc( size );
if( ptr != NULL )
{
#if DEBUG_MEMORY
Com_DPrintf( "[Memory_malloc]: %p size:%ld\n", ptr, size );
#endif
return ptr;
}
Com_DPrintf( "[Memory_malloc]: Could not allocate %d bytes\n", size );
return NULL;
}
/*
-----------------------------------------------------------------------------
Function: Memory_calloc -Allocates an array in memory with elements
initialized to 0.
Parameters:
num -[in] Number of elements.
size -[in] Bytes to allocate.
Returns:
Void pointer to the allocated space on success, or NULL if
there is insufficient memory available.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void *Memory_calloc( size_t num, size_t size )
{
void *ptr;
ptr = calloc( num, size );
if( ptr != NULL )
{
#if DEBUG_MEMORY
Com_DPrintf( "[Memory_calloc]: %p size:%ld num:%ld\n", ptr, size, num );
#endif
return ptr;
}
Com_DPrintf( "[Memory_calloc]: Could not allocate %d objects of size %d\n", num, size );
return NULL;
}
/*
-----------------------------------------------------------------------------
Function: Memory_realloc -Reallocate memory blocks.
Parameters:
memblock -[in] Pointer to previously allocated memory block.
size -[in] Bytes to allocate.
Returns:
A void pointer to the reallocated (and possibly moved) memory
block. The return value is NULL if the size is zero and the
buffer argument is not NULL, or if there is not enough
available memory to expand the block to the given size.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void *Memory_realloc( void *memblock, size_t size )
{
void *ptr;
ptr = realloc( memblock, size );
if( ptr != NULL )
{
#if DEBUG_MEMORY
Com_DPrintf( "[Memory_realloc]: %p size:%ld\n", ptr, size );
#endif
return ptr;
}
Com_DPrintf( "[Memory_realloc]: Could not reallocate %d bytes\n", size );
return NULL;
}
/*
-----------------------------------------------------------------------------
Function: Memory_free -Deallocates or frees a memory block.
Parameters:
memblock -[in] Previously allocated memory block to be freed.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Memory_free( void *memblock )
{
if( memblock )
{
#if DEBUG_MEMORY
Com_DPrintf( "[Memory_free]: %p\n", memblock );
#endif
free( memblock );
}
}
PUBLIC void Memory_outofmem( const char *name, const char *file, W32 line )
{
Com_Error( ERR_FATAL, "%s:%ld failed allocation for \"%s\"\n",
file, line, name );
}

57
wolf3d/code/env/memory.h vendored Normal file
View File

@@ -0,0 +1,57 @@
/*
Copyright (C) 2004-2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* memory.h: Memory allocation manager.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
*/
/*
Notes:
This module is implemented by memory.c.
*/
#ifndef __MEMORY_H__
#define __MEMORY_H__
// Use the macros
extern void *Memory_malloc( size_t size );
extern void *Memory_calloc( size_t num, size_t size );
extern void *Memory_realloc( void *memblock, size_t size );
extern void Memory_free( void *memblock );
extern void Memory_outofmem( const char *name, const char *file, W32 line );
#define MM_MALLOC( size ) Memory_malloc( (size) )
#define MM_CALLOC( num, size ) Memory_calloc( (num), (size) )
#define MM_REALLOC( memblock, size ) Memory_realloc( (memblock), (size) )
#define MM_FREE( memblock ) { Memory_free( (memblock) ); ((memblock)) = NULL; }
#define MM_OUTOFMEM( name ) Memory_outofmem( (name), __FILE__, __LINE__ )
#endif /* __MEMORY_H__ */

95
wolf3d/code/env/mymath.h vendored Normal file
View File

@@ -0,0 +1,95 @@
/*
Copyright (C) 2004-2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* mymath.h: Math routines.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* Portion of this code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#ifndef __MYMATH_H__
#define __MYMATH_H__
typedef int fixed4_t;
typedef int fixed8_t;
typedef int fixed16_t;
#define PITCH 0 /* up / down */
#define YAW 1 /* left / right */
#define ROLL 2 /* fall over */
#ifndef M_PI
#define M_PI 3.14159265358979323846f // matches value in gcc v2 math.h
#endif
#ifndef ABS
#define ABS( x ) ( (x) < 0 ? -(x) : (x) )
#endif
#define nanmask ( 255 << 23 )
#define IS_NAN( x ) ( ( (*(int *) &x ) & nanmask ) == nanmask )
/* Use RINT() instead of rint() */
#ifdef __GNUC__
#define RINT( x ) rint( x )
#else
#define RINT( x ) floor( (x) + 0.5 )
#endif
extern void MathLib_Init( void );
extern int my_log2( int val );
extern float (*pfSqrt)( float x );
extern float CalcFov( float fov_x, float width, float height );
#endif /* __MYMATH_H__ */

872
wolf3d/code/env/myopengl.h vendored Normal file
View File

@@ -0,0 +1,872 @@
/*
Copyright (C) 2005 Michael Liebscher
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* MyOpenGL.h: OpenGL Interface
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
*/
/*
Notes:
This module is implemented by opengl_win.c.
*/
#ifndef __MYOPENGL_H__
#define __MYOPENGL_H__
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#endif
#ifdef IPHONE
#include <OpenGLES/ES1/gl.h>
#include <OpenGLES/ES1/glext.h>
#else
#include <GL/gl.h>
#endif
#ifdef __unix__
#include <GL/glx.h>
#endif
extern int OpenGL_Init( const char *dllname );
extern void OpenGL_Shutdown( void );
#ifndef APIENTRY
#define APIENTRY
#endif
#ifndef APIENTRYP
#define APIENTRYP APIENTRY *
#endif
typedef GLvoid ( APIENTRYP GLACCUM )(GLenum op, GLfloat value);
typedef GLvoid ( APIENTRYP GLALPHAFUNC )(GLenum func, GLclampf ref);
typedef GLboolean ( APIENTRYP GLARETEXTURESRESIDENT )(GLsizei n, const GLuint *textures, GLboolean *residences);
typedef GLvoid ( APIENTRYP GLARRAYELEMENT )(GLint i);
typedef GLvoid ( APIENTRYP GLBEGIN )(GLenum mode);
typedef GLvoid ( APIENTRYP GLBINDTEXTURE )(GLenum target, GLuint texture);
typedef GLvoid ( APIENTRYP GLBITMAP )(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap);
typedef GLvoid ( APIENTRYP GLBLENDFUNC )(GLenum sfactor, GLenum dfactor);
typedef GLvoid ( APIENTRYP GLCALLLIST )(GLuint list);
typedef GLvoid ( APIENTRYP GLCALLLISTS )(GLsizei n, GLenum type, const GLvoid *lists);
typedef GLvoid ( APIENTRYP GLCLEAR )(GLbitfield mask);
typedef GLvoid ( APIENTRYP GLCLEARACCUM )(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
typedef GLvoid ( APIENTRYP GLCLEARCOLOR )(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
typedef GLvoid ( APIENTRYP GLCLEARDEPTH )(GLclampd depth);
typedef GLvoid ( APIENTRYP GLCLEARINDEX )(GLfloat c);
typedef GLvoid ( APIENTRYP GLCLEARSTENCIL )(GLint s);
typedef GLvoid ( APIENTRYP GLCLIPPLANE )(GLenum plane, const GLdouble *equation);
typedef GLvoid ( APIENTRYP GLCOLOR3B )(GLbyte red, GLbyte green, GLbyte blue);
typedef GLvoid ( APIENTRYP GLCOLOR3BV )(const GLbyte *v);
typedef GLvoid ( APIENTRYP GLCOLOR3D )(GLdouble red, GLdouble green, GLdouble blue);
typedef GLvoid ( APIENTRYP GLCOLOR3DV )(const GLdouble *v);
typedef GLvoid ( APIENTRYP GLCOLOR3F )(GLfloat red, GLfloat green, GLfloat blue);
typedef GLvoid ( APIENTRYP GLCOLOR3FV )(const GLfloat *v);
typedef GLvoid ( APIENTRYP GLCOLOR3I )(GLint red, GLint green, GLint blue);
typedef GLvoid ( APIENTRYP GLCOLOR3IV )(const GLint *v);
typedef GLvoid ( APIENTRYP GLCOLOR3S )(GLshort red, GLshort green, GLshort blue);
typedef GLvoid ( APIENTRYP GLCOLOR3SV )(const GLshort *v);
typedef GLvoid ( APIENTRYP GLCOLOR3UB )(GLubyte red, GLubyte green, GLubyte blue);
typedef GLvoid ( APIENTRYP GLCOLOR3UBV )(const GLubyte *v);
typedef GLvoid ( APIENTRYP GLCOLOR3UI )(GLuint red, GLuint green, GLuint blue);
typedef GLvoid ( APIENTRYP GLCOLOR3UIV )(const GLuint *v);
typedef GLvoid ( APIENTRYP GLCOLOR3US )(GLushort red, GLushort green, GLushort blue);
typedef GLvoid ( APIENTRYP GLCOLOR3USV )(const GLushort *v);
typedef GLvoid ( APIENTRYP GLCOLOR4B )(GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha);
typedef GLvoid ( APIENTRYP GLCOLOR4BV )(const GLbyte *v);
typedef GLvoid ( APIENTRYP GLCOLOR4D )(GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha);
typedef GLvoid ( APIENTRYP GLCOLOR4DV )(const GLdouble *v);
typedef GLvoid ( APIENTRYP GLCOLOR4F )(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
typedef GLvoid ( APIENTRYP GLCOLOR4FV )(const GLfloat *v);
typedef GLvoid ( APIENTRYP GLCOLOR4I )(GLint red, GLint green, GLint blue, GLint alpha);
typedef GLvoid ( APIENTRYP GLCOLOR4IV )(const GLint *v);
typedef GLvoid ( APIENTRYP GLCOLOR4S )(GLshort red, GLshort green, GLshort blue, GLshort alpha);
typedef GLvoid ( APIENTRYP GLCOLOR4SV )(const GLshort *v);
typedef GLvoid ( APIENTRYP GLCOLOR4UB )(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
typedef GLvoid ( APIENTRYP GLCOLOR4UBV )(const GLubyte *v);
typedef GLvoid ( APIENTRYP GLCOLOR4UI )(GLuint red, GLuint green, GLuint blue, GLuint alpha);
typedef GLvoid ( APIENTRYP GLCOLOR4UIV )(const GLuint *v);
typedef GLvoid ( APIENTRYP GLCOLOR4US )(GLushort red, GLushort green, GLushort blue, GLushort alpha);
typedef GLvoid ( APIENTRYP GLCOLOR4USV )(const GLushort *v);
typedef GLvoid ( APIENTRYP GLCOLORMASK )(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
typedef GLvoid ( APIENTRYP GLCOLORMATERIAL )(GLenum face, GLenum mode);
typedef GLvoid ( APIENTRYP GLCOLORPOINTER )(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
typedef GLvoid ( APIENTRYP GLCOPYPIXELS )(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type);
typedef GLvoid ( APIENTRYP GLCOPYTEXIMAGE1D )(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border);
typedef GLvoid ( APIENTRYP GLCOPYTEXIMAGE2D )(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
typedef GLvoid ( APIENTRYP GLCOPYTEXSUBIMAGE1D )(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
typedef GLvoid ( APIENTRYP GLCOPYTEXSUBIMAGE2D )(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
typedef GLvoid ( APIENTRYP GLCULLFACE )(GLenum mode);
typedef GLvoid ( APIENTRYP GLDELETELISTS )(GLuint list, GLsizei range);
typedef GLvoid ( APIENTRYP GLDELETETEXTURES )(GLsizei n, const GLuint *textures);
typedef GLvoid ( APIENTRYP GLDEPTHFUNC )(GLenum func);
typedef GLvoid ( APIENTRYP GLDEPTHMASK )(GLboolean flag);
typedef GLvoid ( APIENTRYP GLDEPTHRANGE )(GLclampd zNear, GLclampd zFar);
typedef GLvoid ( APIENTRYP GLDISABLE )(GLenum cap);
typedef GLvoid ( APIENTRYP GLDISABLECLIENTSTATE )(GLenum array);
typedef GLvoid ( APIENTRYP GLDRAWARRAYS )(GLenum mode, GLint first, GLsizei count);
typedef GLvoid ( APIENTRYP GLDRAWBUFFER )(GLenum mode);
typedef GLvoid ( APIENTRYP GLDRAWELEMENTS )(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
typedef GLvoid ( APIENTRYP GLDRAWPIXELS )(GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
typedef GLvoid ( APIENTRYP GLEDGEFLAG )(GLboolean flag);
typedef GLvoid ( APIENTRYP GLEDGEFLAGPOINTER )(GLsizei stride, const GLvoid *pointer);
typedef GLvoid ( APIENTRYP GLEDGEFLAGV )(const GLboolean *flag);
typedef GLvoid ( APIENTRYP GLENABLE )(GLenum cap);
typedef GLvoid ( APIENTRYP GLENABLECLIENTSTATE )(GLenum array);
typedef GLvoid ( APIENTRYP GLEND )(void);
typedef GLvoid ( APIENTRYP GLENDLIST )(void);
typedef GLvoid ( APIENTRYP GLEVALCOORD1D )(GLdouble u);
typedef GLvoid ( APIENTRYP GLEVALCOORD1DV )(const GLdouble *u);
typedef GLvoid ( APIENTRYP GLEVALCOORD1F )(GLfloat u);
typedef GLvoid ( APIENTRYP GLEVALCOORD1FV )(const GLfloat *u);
typedef GLvoid ( APIENTRYP GLEVALCOORD2D )(GLdouble u, GLdouble v);
typedef GLvoid ( APIENTRYP GLEVALCOORD2DV )(const GLdouble *u);
typedef GLvoid ( APIENTRYP GLEVALCOORD2F )(GLfloat u, GLfloat v);
typedef GLvoid ( APIENTRYP GLEVALCOORD2FV )(const GLfloat *u);
typedef GLvoid ( APIENTRYP GLEVALMESH1 )(GLenum mode, GLint i1, GLint i2);
typedef GLvoid ( APIENTRYP GLEVALMESH2 )(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2);
typedef GLvoid ( APIENTRYP GLEVALPOINT1 )(GLint i);
typedef GLvoid ( APIENTRYP GLEVALPOINT2 )(GLint i, GLint j);
typedef GLvoid ( APIENTRYP GLFEEDBACKBUFFER )(GLsizei size, GLenum type, GLfloat *buffer);
typedef GLvoid ( APIENTRYP GLFINISH )(void);
typedef GLvoid ( APIENTRYP GLFLUSH )(void);
typedef GLvoid ( APIENTRYP GLFOGF )(GLenum pname, GLfloat param);
typedef GLvoid ( APIENTRYP GLFOGFV )(GLenum pname, const GLfloat *params);
typedef GLvoid ( APIENTRYP GLFOGI )(GLenum pname, GLint param);
typedef GLvoid ( APIENTRYP GLFOGIV )(GLenum pname, const GLint *params);
typedef GLvoid ( APIENTRYP GLFRONTFACE )(GLenum mode);
typedef GLvoid ( APIENTRYP GLFRUSTUM )(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
typedef GLuint ( APIENTRYP GLGENLISTS )(GLsizei range);
typedef GLvoid ( APIENTRYP GLGENTEXTURES )(GLsizei n, GLuint *textures);
typedef GLvoid ( APIENTRYP GLGETBOOLEANV )(GLenum pname, GLboolean *params);
typedef GLvoid ( APIENTRYP GLGETCLIPPLANE )(GLenum plane, GLdouble *equation);
typedef GLvoid ( APIENTRYP GLGETDOUBLEV )(GLenum pname, GLdouble *params);
typedef GLenum ( APIENTRYP GLGETERROR )(void);
typedef GLvoid ( APIENTRYP GLGETFLOATV )(GLenum pname, GLfloat *params);
typedef GLvoid ( APIENTRYP GLGETINTEGERV )(GLenum pname, GLint *params);
typedef GLvoid ( APIENTRYP GLGETLIGHTFV )(GLenum light, GLenum pname, GLfloat *params);
typedef GLvoid ( APIENTRYP GLGETLIGHTIV )(GLenum light, GLenum pname, GLint *params);
typedef GLvoid ( APIENTRYP GLGETMAPDV )(GLenum target, GLenum query, GLdouble *v);
typedef GLvoid ( APIENTRYP GLGETMAPFV )(GLenum target, GLenum query, GLfloat *v);
typedef GLvoid ( APIENTRYP GLGETMAPIV )(GLenum target, GLenum query, GLint *v);
typedef GLvoid ( APIENTRYP GLGETMATERIALFV )(GLenum face, GLenum pname, GLfloat *params);
typedef GLvoid ( APIENTRYP GLGETMATERIALIV )(GLenum face, GLenum pname, GLint *params);
typedef GLvoid ( APIENTRYP GLGETPIXELMAPFV )(GLenum map, GLfloat *values);
typedef GLvoid ( APIENTRYP GLGETPIXELMAPUIV )(GLenum map, GLuint *values);
typedef GLvoid ( APIENTRYP GLGETPIXELMAPUSV )(GLenum map, GLushort *values);
typedef GLvoid ( APIENTRYP GLGETPOINTERV )(GLenum pname, GLvoid* *params);
typedef GLvoid ( APIENTRYP GLGETPOLYGONSTIPPLE )(GLubyte *mask);
typedef const GLubyte * ( APIENTRYP GLGETSTRING )(GLenum name);
typedef GLvoid ( APIENTRYP GLGETTEXENVFV )(GLenum target, GLenum pname, GLfloat *params);
typedef GLvoid ( APIENTRYP GLGETTEXENVIV )(GLenum target, GLenum pname, GLint *params);
typedef GLvoid ( APIENTRYP GLGETTEXGENDV )(GLenum coord, GLenum pname, GLdouble *params);
typedef GLvoid ( APIENTRYP GLGETTEXGENFV )(GLenum coord, GLenum pname, GLfloat *params);
typedef GLvoid ( APIENTRYP GLGETTEXGENIV )(GLenum coord, GLenum pname, GLint *params);
typedef GLvoid ( APIENTRYP GLGETTEXIMAGE )(GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels);
typedef GLvoid ( APIENTRYP GLGETTEXPARAMETERFV )(GLenum target, GLenum pname, GLfloat *params);
typedef GLvoid ( APIENTRYP GLGETTEXPARAMETERIV )(GLenum target, GLenum pname, GLint *params);
typedef GLvoid ( APIENTRYP GLHINT )(GLenum target, GLenum mode);
typedef GLvoid ( APIENTRYP GLINDEXMASK )(GLuint mask);
typedef GLvoid ( APIENTRYP GLINDEXPOINTER )(GLenum type, GLsizei stride, const GLvoid *pointer);
typedef GLvoid ( APIENTRYP GLINDEXD )(GLdouble c);
typedef GLvoid ( APIENTRYP GLINDEXDV )(const GLdouble *c);
typedef GLvoid ( APIENTRYP GLINDEXF )(GLfloat c);
typedef GLvoid ( APIENTRYP GLINDEXFV )(const GLfloat *c);
typedef GLvoid ( APIENTRYP GLINDEXI )(GLint c);
typedef GLvoid ( APIENTRYP GLINDEXIV )(const GLint *c);
typedef GLvoid ( APIENTRYP GLINDEXS )(GLshort c);
typedef GLvoid ( APIENTRYP GLINDEXSV )(const GLshort *c);
typedef GLvoid ( APIENTRYP GLINDEXUB )(GLubyte c);
typedef GLvoid ( APIENTRYP GLINDEXUBV )(const GLubyte *c);
typedef GLvoid ( APIENTRYP GLINITNAMES )(void);
typedef GLvoid ( APIENTRYP GLINTERLEAVEDARRAYS )(GLenum format, GLsizei stride, const GLvoid *pointer);
typedef GLboolean ( APIENTRYP GLISENABLED )(GLenum cap);
typedef GLboolean ( APIENTRYP GLISLIST )(GLuint list);
typedef GLboolean ( APIENTRYP GLISTEXTURE )(GLuint texture);
typedef GLvoid ( APIENTRYP GLLIGHTMODELF )(GLenum pname, GLfloat param);
typedef GLvoid ( APIENTRYP GLLIGHTMODELFV )(GLenum pname, const GLfloat *params);
typedef GLvoid ( APIENTRYP GLLIGHTMODELI )(GLenum pname, GLint param);
typedef GLvoid ( APIENTRYP GLLIGHTMODELIV )(GLenum pname, const GLint *params);
typedef GLvoid ( APIENTRYP GLLIGHTF )(GLenum light, GLenum pname, GLfloat param);
typedef GLvoid ( APIENTRYP GLLIGHTFV )(GLenum light, GLenum pname, const GLfloat *params);
typedef GLvoid ( APIENTRYP GLLIGHTI )(GLenum light, GLenum pname, GLint param);
typedef GLvoid ( APIENTRYP GLLIGHTIV )(GLenum light, GLenum pname, const GLint *params);
typedef GLvoid ( APIENTRYP GLLINESTIPPLE )(GLint factor, GLushort pattern);
typedef GLvoid ( APIENTRYP GLLINEWIDTH )(GLfloat width);
typedef GLvoid ( APIENTRYP GLLISTBASE )(GLuint base);
typedef GLvoid ( APIENTRYP GLLOADIDENTITY )(void);
typedef GLvoid ( APIENTRYP GLLOADMATRIXD )(const GLdouble *m);
typedef GLvoid ( APIENTRYP GLLOADMATRIXF )(const GLfloat *m);
typedef GLvoid ( APIENTRYP GLLOADNAME )(GLuint name);
typedef GLvoid ( APIENTRYP GLLOGICOP )(GLenum opcode);
typedef GLvoid ( APIENTRYP GLMAP1D )(GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points);
typedef GLvoid ( APIENTRYP GLMAP1F )(GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points);
typedef GLvoid ( APIENTRYP GLMAP2D )(GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points);
typedef GLvoid ( APIENTRYP GLMAP2F )(GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points);
typedef GLvoid ( APIENTRYP GLMAPGRID1D )(GLint un, GLdouble u1, GLdouble u2);
typedef GLvoid ( APIENTRYP GLMAPGRID1F )(GLint un, GLfloat u1, GLfloat u2);
typedef GLvoid ( APIENTRYP GLMAPGRID2D )(GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2);
typedef GLvoid ( APIENTRYP GLMAPGRID2F )(GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2);
typedef GLvoid ( APIENTRYP GLMATERIALF )(GLenum face, GLenum pname, GLfloat param);
typedef GLvoid ( APIENTRYP GLMATERIALFV )(GLenum face, GLenum pname, const GLfloat *params);
typedef GLvoid ( APIENTRYP GLMATERIALI )(GLenum face, GLenum pname, GLint param);
typedef GLvoid ( APIENTRYP GLMATERIALIV )(GLenum face, GLenum pname, const GLint *params);
typedef GLvoid ( APIENTRYP GLMATRIXMODE )(GLenum mode);
typedef GLvoid ( APIENTRYP GLMULTMATRIXD )(const GLdouble *m);
typedef GLvoid ( APIENTRYP GLMULTMATRIXF )(const GLfloat *m);
typedef GLvoid ( APIENTRYP GLNEWLIST )(GLuint list, GLenum mode);
typedef GLvoid ( APIENTRYP GLNORMAL3B )(GLbyte nx, GLbyte ny, GLbyte nz);
typedef GLvoid ( APIENTRYP GLNORMAL3BV )(const GLbyte *v);
typedef GLvoid ( APIENTRYP GLNORMAL3D )(GLdouble nx, GLdouble ny, GLdouble nz);
typedef GLvoid ( APIENTRYP GLNORMAL3DV )(const GLdouble *v);
typedef GLvoid ( APIENTRYP GLNORMAL3F )(GLfloat nx, GLfloat ny, GLfloat nz);
typedef GLvoid ( APIENTRYP GLNORMAL3FV )(const GLfloat *v);
typedef GLvoid ( APIENTRYP GLNORMAL3I )(GLint nx, GLint ny, GLint nz);
typedef GLvoid ( APIENTRYP GLNORMAL3IV )(const GLint *v);
typedef GLvoid ( APIENTRYP GLNORMAL3S )(GLshort nx, GLshort ny, GLshort nz);
typedef GLvoid ( APIENTRYP GLNORMAL3SV )(const GLshort *v);
typedef GLvoid ( APIENTRYP GLNORMALPOINTER )(GLenum type, GLsizei stride, const GLvoid *pointer);
typedef GLvoid ( APIENTRYP GLORTHO )(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
typedef GLvoid ( APIENTRYP GLPASSTHROUGH )(GLfloat token);
typedef GLvoid ( APIENTRYP GLPIXELMAPFV )(GLenum map, GLsizei mapsize, const GLfloat *values);
typedef GLvoid ( APIENTRYP GLPIXELMAPUIV )(GLenum map, GLsizei mapsize, const GLuint *values);
typedef GLvoid ( APIENTRYP GLPIXELMAPUSV )(GLenum map, GLsizei mapsize, const GLushort *values);
typedef GLvoid ( APIENTRYP GLPIXELSTOREF )(GLenum pname, GLfloat param);
typedef GLvoid ( APIENTRYP GLPIXELSTOREI )(GLenum pname, GLint param);
typedef GLvoid ( APIENTRYP GLPIXELTRANSFERF )(GLenum pname, GLfloat param);
typedef GLvoid ( APIENTRYP GLPIXELTRANSFERI )(GLenum pname, GLint param);
typedef GLvoid ( APIENTRYP GLPIXELZOOM )(GLfloat xfactor, GLfloat yfactor);
typedef GLvoid ( APIENTRYP GLPOINTSIZE )(GLfloat size);
typedef GLvoid ( APIENTRYP GLPOLYGONMODE )(GLenum face, GLenum mode);
typedef GLvoid ( APIENTRYP GLPOLYGONOFFSET )(GLfloat factor, GLfloat units);
typedef GLvoid ( APIENTRYP GLPOLYGONSTIPPLE )(const GLubyte *mask);
typedef GLvoid ( APIENTRYP GLPOPATTRIB )(void);
typedef GLvoid ( APIENTRYP GLPOPCLIENTATTRIB )(void);
typedef GLvoid ( APIENTRYP GLPOPMATRIX )(void);
typedef GLvoid ( APIENTRYP GLPOPNAME )(void);
typedef GLvoid ( APIENTRYP GLPRIORITIZETEXTURES )(GLsizei n, const GLuint *textures, const GLclampf *priorities);
typedef GLvoid ( APIENTRYP GLPUSHATTRIB )(GLbitfield mask);
typedef GLvoid ( APIENTRYP GLPUSHCLIENTATTRIB )(GLbitfield mask);
typedef GLvoid ( APIENTRYP GLPUSHMATRIX )(void);
typedef GLvoid ( APIENTRYP GLPUSHNAME )(GLuint name);
typedef GLvoid ( APIENTRYP GLRASTERPOS2D )(GLdouble x, GLdouble y);
typedef GLvoid ( APIENTRYP GLRASTERPOS2DV )(const GLdouble *v);
typedef GLvoid ( APIENTRYP GLRASTERPOS2F )(GLfloat x, GLfloat y);
typedef GLvoid ( APIENTRYP GLRASTERPOS2FV )(const GLfloat *v);
typedef GLvoid ( APIENTRYP GLRASTERPOS2I )(GLint x, GLint y);
typedef GLvoid ( APIENTRYP GLRASTERPOS2IV )(const GLint *v);
typedef GLvoid ( APIENTRYP GLRASTERPOS2S )(GLshort x, GLshort y);
typedef GLvoid ( APIENTRYP GLRASTERPOS2SV )(const GLshort *v);
typedef GLvoid ( APIENTRYP GLRASTERPOS3D )(GLdouble x, GLdouble y, GLdouble z);
typedef GLvoid ( APIENTRYP GLRASTERPOS3DV )(const GLdouble *v);
typedef GLvoid ( APIENTRYP GLRASTERPOS3F )(GLfloat x, GLfloat y, GLfloat z);
typedef GLvoid ( APIENTRYP GLRASTERPOS3FV )(const GLfloat *v);
typedef GLvoid ( APIENTRYP GLRASTERPOS3I )(GLint x, GLint y, GLint z);
typedef GLvoid ( APIENTRYP GLRASTERPOS3IV )(const GLint *v);
typedef GLvoid ( APIENTRYP GLRASTERPOS3S )(GLshort x, GLshort y, GLshort z);
typedef GLvoid ( APIENTRYP GLRASTERPOS3SV )(const GLshort *v);
typedef GLvoid ( APIENTRYP GLRASTERPOS4D )(GLdouble x, GLdouble y, GLdouble z, GLdouble w);
typedef GLvoid ( APIENTRYP GLRASTERPOS4DV )(const GLdouble *v);
typedef GLvoid ( APIENTRYP GLRASTERPOS4F )(GLfloat x, GLfloat y, GLfloat z, GLfloat w);
typedef GLvoid ( APIENTRYP GLRASTERPOS4FV )(const GLfloat *v);
typedef GLvoid ( APIENTRYP GLRASTERPOS4I )(GLint x, GLint y, GLint z, GLint w);
typedef GLvoid ( APIENTRYP GLRASTERPOS4IV )(const GLint *v);
typedef GLvoid ( APIENTRYP GLRASTERPOS4S )(GLshort x, GLshort y, GLshort z, GLshort w);
typedef GLvoid ( APIENTRYP GLRASTERPOS4SV )(const GLshort *v);
typedef GLvoid ( APIENTRYP GLREADBUFFER )(GLenum mode);
typedef GLvoid ( APIENTRYP GLREADPIXELS )(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
typedef GLvoid ( APIENTRYP GLRECTD )(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2);
typedef GLvoid ( APIENTRYP GLRECTDV )(const GLdouble *v1, const GLdouble *v2);
typedef GLvoid ( APIENTRYP GLRECTF )(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2);
typedef GLvoid ( APIENTRYP GLRECTFV )(const GLfloat *v1, const GLfloat *v2);
typedef GLvoid ( APIENTRYP GLRECTI )(GLint x1, GLint y1, GLint x2, GLint y2);
typedef GLvoid ( APIENTRYP GLRECTIV )(const GLint *v1, const GLint *v2);
typedef GLvoid ( APIENTRYP GLRECTS )(GLshort x1, GLshort y1, GLshort x2, GLshort y2);
typedef GLvoid ( APIENTRYP GLRECTSV )(const GLshort *v1, const GLshort *v2);
typedef GLint ( APIENTRYP GLRENDERMODE )(GLenum mode);
typedef GLvoid ( APIENTRYP GLROTATED )(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
typedef GLvoid ( APIENTRYP GLROTATEF )(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
typedef GLvoid ( APIENTRYP GLSCALED )(GLdouble x, GLdouble y, GLdouble z);
typedef GLvoid ( APIENTRYP GLSCALEF )(GLfloat x, GLfloat y, GLfloat z);
typedef GLvoid ( APIENTRYP GLSCISSOR )(GLint x, GLint y, GLsizei width, GLsizei height);
typedef GLvoid ( APIENTRYP GLSELECTBUFFER )(GLsizei size, GLuint *buffer);
typedef GLvoid ( APIENTRYP GLSHADEMODEL )(GLenum mode);
typedef GLvoid ( APIENTRYP GLSTENCILFUNC )(GLenum func, GLint ref, GLuint mask);
typedef GLvoid ( APIENTRYP GLSTENCILMASK )(GLuint mask);
typedef GLvoid ( APIENTRYP GLSTENCILOP )(GLenum fail, GLenum zfail, GLenum zpass);
typedef GLvoid ( APIENTRYP GLTEXCOORD1D )(GLdouble s);
typedef GLvoid ( APIENTRYP GLTEXCOORD1DV )(const GLdouble *v);
typedef GLvoid ( APIENTRYP GLTEXCOORD1F )(GLfloat s);
typedef GLvoid ( APIENTRYP GLTEXCOORD1FV )(const GLfloat *v);
typedef GLvoid ( APIENTRYP GLTEXCOORD1I )(GLint s);
typedef GLvoid ( APIENTRYP GLTEXCOORD1IV )(const GLint *v);
typedef GLvoid ( APIENTRYP GLTEXCOORD1S )(GLshort s);
typedef GLvoid ( APIENTRYP GLTEXCOORD1SV )(const GLshort *v);
typedef GLvoid ( APIENTRYP GLTEXCOORD2D )(GLdouble s, GLdouble t);
typedef GLvoid ( APIENTRYP GLTEXCOORD2DV )(const GLdouble *v);
typedef GLvoid ( APIENTRYP GLTEXCOORD2F )(GLfloat s, GLfloat t);
typedef GLvoid ( APIENTRYP GLTEXCOORD2FV )(const GLfloat *v);
typedef GLvoid ( APIENTRYP GLTEXCOORD2I )(GLint s, GLint t);
typedef GLvoid ( APIENTRYP GLTEXCOORD2IV )(const GLint *v);
typedef GLvoid ( APIENTRYP GLTEXCOORD2S )(GLshort s, GLshort t);
typedef GLvoid ( APIENTRYP GLTEXCOORD2SV )(const GLshort *v);
typedef GLvoid ( APIENTRYP GLTEXCOORD3D )(GLdouble s, GLdouble t, GLdouble r);
typedef GLvoid ( APIENTRYP GLTEXCOORD3DV )(const GLdouble *v);
typedef GLvoid ( APIENTRYP GLTEXCOORD3F )(GLfloat s, GLfloat t, GLfloat r);
typedef GLvoid ( APIENTRYP GLTEXCOORD3FV )(const GLfloat *v);
typedef GLvoid ( APIENTRYP GLTEXCOORD3I )(GLint s, GLint t, GLint r);
typedef GLvoid ( APIENTRYP GLTEXCOORD3IV )(const GLint *v);
typedef GLvoid ( APIENTRYP GLTEXCOORD3S )(GLshort s, GLshort t, GLshort r);
typedef GLvoid ( APIENTRYP GLTEXCOORD3SV )(const GLshort *v);
typedef GLvoid ( APIENTRYP GLTEXCOORD4D )(GLdouble s, GLdouble t, GLdouble r, GLdouble q);
typedef GLvoid ( APIENTRYP GLTEXCOORD4DV )(const GLdouble *v);
typedef GLvoid ( APIENTRYP GLTEXCOORD4F )(GLfloat s, GLfloat t, GLfloat r, GLfloat q);
typedef GLvoid ( APIENTRYP GLTEXCOORD4FV )(const GLfloat *v);
typedef GLvoid ( APIENTRYP GLTEXCOORD4I )(GLint s, GLint t, GLint r, GLint q);
typedef GLvoid ( APIENTRYP GLTEXCOORD4IV )(const GLint *v);
typedef GLvoid ( APIENTRYP GLTEXCOORD4S )(GLshort s, GLshort t, GLshort r, GLshort q);
typedef GLvoid ( APIENTRYP GLTEXCOORD4SV )(const GLshort *v);
typedef GLvoid ( APIENTRYP GLTEXCOORDPOINTER )(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
typedef GLvoid ( APIENTRYP GLTEXENVF )(GLenum target, GLenum pname, GLfloat param);
typedef GLvoid ( APIENTRYP GLTEXENVFV )(GLenum target, GLenum pname, const GLfloat *params);
typedef GLvoid ( APIENTRYP GLTEXENVI )(GLenum target, GLenum pname, GLint param);
typedef GLvoid ( APIENTRYP GLTEXENVIV )(GLenum target, GLenum pname, const GLint *params);
typedef GLvoid ( APIENTRYP GLTEXGEND )(GLenum coord, GLenum pname, GLdouble param);
typedef GLvoid ( APIENTRYP GLTEXGENDV )(GLenum coord, GLenum pname, const GLdouble *params);
typedef GLvoid ( APIENTRYP GLTEXGENF )(GLenum coord, GLenum pname, GLfloat param);
typedef GLvoid ( APIENTRYP GLTEXGENFV )(GLenum coord, GLenum pname, const GLfloat *params);
typedef GLvoid ( APIENTRYP GLTEXGENI )(GLenum coord, GLenum pname, GLint param);
typedef GLvoid ( APIENTRYP GLTEXGENIV )(GLenum coord, GLenum pname, const GLint *params);
typedef GLvoid ( APIENTRYP GLTEXIMAGE1D )(GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
typedef GLvoid ( APIENTRYP GLTEXIMAGE2D )(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
typedef GLvoid ( APIENTRYP GLTEXPARAMETERF )(GLenum target, GLenum pname, GLfloat param);
typedef GLvoid ( APIENTRYP GLTEXPARAMETERFV )(GLenum target, GLenum pname, const GLfloat *params);
typedef GLvoid ( APIENTRYP GLTEXPARAMETERI )(GLenum target, GLenum pname, GLint param);
typedef GLvoid ( APIENTRYP GLTEXPARAMETERIV )(GLenum target, GLenum pname, const GLint *params);
typedef GLvoid ( APIENTRYP GLTEXSUBIMAGE1D )(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels);
typedef GLvoid ( APIENTRYP GLTEXSUBIMAGE2D )(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
typedef GLvoid ( APIENTRYP GLTRANSLATED )(GLdouble x, GLdouble y, GLdouble z);
typedef GLvoid ( APIENTRYP GLTRANSLATEF )(GLfloat x, GLfloat y, GLfloat z);
typedef GLvoid ( APIENTRYP GLVERTEX2D )(GLdouble x, GLdouble y);
typedef GLvoid ( APIENTRYP GLVERTEX2DV )(const GLdouble *v);
typedef GLvoid ( APIENTRYP GLVERTEX2F )(GLfloat x, GLfloat y);
typedef GLvoid ( APIENTRYP GLVERTEX2FV )(const GLfloat *v);
typedef GLvoid ( APIENTRYP GLVERTEX2I )(GLint x, GLint y);
typedef GLvoid ( APIENTRYP GLVERTEX2IV )(const GLint *v);
typedef GLvoid ( APIENTRYP GLVERTEX2S )(GLshort x, GLshort y);
typedef GLvoid ( APIENTRYP GLVERTEX2SV )(const GLshort *v);
typedef GLvoid ( APIENTRYP GLVERTEX3D )(GLdouble x, GLdouble y, GLdouble z);
typedef GLvoid ( APIENTRYP GLVERTEX3DV )(const GLdouble *v);
typedef GLvoid ( APIENTRYP GLVERTEX3F )(GLfloat x, GLfloat y, GLfloat z);
typedef GLvoid ( APIENTRYP GLVERTEX3FV )(const GLfloat *v);
typedef GLvoid ( APIENTRYP GLVERTEX3I )(GLint x, GLint y, GLint z);
typedef GLvoid ( APIENTRYP GLVERTEX3IV )(const GLint *v);
typedef GLvoid ( APIENTRYP GLVERTEX3S )(GLshort x, GLshort y, GLshort z);
typedef GLvoid ( APIENTRYP GLVERTEX3SV )(const GLshort *v);
typedef GLvoid ( APIENTRYP GLVERTEX4D )(GLdouble x, GLdouble y, GLdouble z, GLdouble w);
typedef GLvoid ( APIENTRYP GLVERTEX4DV )(const GLdouble *v);
typedef GLvoid ( APIENTRYP GLVERTEX4F )(GLfloat x, GLfloat y, GLfloat z, GLfloat w);
typedef GLvoid ( APIENTRYP GLVERTEX4FV )(const GLfloat *v);
typedef GLvoid ( APIENTRYP GLVERTEX4I )(GLint x, GLint y, GLint z, GLint w);
typedef GLvoid ( APIENTRYP GLVERTEX4IV )(const GLint *v);
typedef GLvoid ( APIENTRYP GLVERTEX4S )(GLshort x, GLshort y, GLshort z, GLshort w);
typedef GLvoid ( APIENTRYP GLVERTEX4SV )(const GLshort *v);
typedef GLvoid ( APIENTRYP GLVERTEXPOINTER )(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
typedef GLvoid ( APIENTRYP GLVIEWPORT )(GLint x, GLint y, GLsizei width, GLsizei height);
//GLACCUM pfglAccum;
GLALPHAFUNC pfglAlphaFunc;
GLARETEXTURESRESIDENT pfglAreTexturesResident;
//GLARRAYELEMENT pfglArrayElement;
GLBEGIN pfglBegin;
GLBINDTEXTURE pfglBindTexture;
//GLBITMAP pfglBitmap;
GLBLENDFUNC pfglBlendFunc;
GLCALLLIST pfglCallList;
GLCALLLISTS pfglCallLists;
GLCLEAR pfglClear;
//GLCLEARACCUM pfglClearAccum;
GLCLEARCOLOR pfglClearColor;
GLCLEARDEPTH pfglClearDepth;
//GLCLEARINDEX pfglClearIndex;
//GLCLEARSTENCIL pfglClearStencil;
//GLCLIPPLANE pfglClipPlane;
GLCOLOR3B pfglColor3b;
GLCOLOR3BV pfglColor3bv;
GLCOLOR3D pfglColor3d;
GLCOLOR3DV pfglColor3dv;
GLCOLOR3F pfglColor3f;
GLCOLOR3FV pfglColor3fv;
GLCOLOR3I pfglColor3i;
GLCOLOR3IV pfglColor3iv;
GLCOLOR3S pfglColor3s;
GLCOLOR3SV pfglColor3sv;
GLCOLOR3UB pfglColor3ub;
GLCOLOR3UBV pfglColor3ubv;
GLCOLOR3UI pfglColor3ui;
GLCOLOR3UIV pfglColor3uiv;
GLCOLOR3US pfglColor3us;
GLCOLOR3USV pfglColor3usv;
GLCOLOR4B pfglColor4b;
GLCOLOR4BV pfglColor4bv;
GLCOLOR4D pfglColor4d;
GLCOLOR4DV pfglColor4dv;
GLCOLOR4F pfglColor4f;
GLCOLOR4FV pfglColor4fv;
GLCOLOR4I pfglColor4i;
GLCOLOR4IV pfglColor4iv;
GLCOLOR4S pfglColor4s;
GLCOLOR4SV pfglColor4sv;
GLCOLOR4UB pfglColor4ub;
GLCOLOR4UBV pfglColor4ubv;
GLCOLOR4UI pfglColor4ui;
GLCOLOR4UIV pfglColor4uiv;
GLCOLOR4US pfglColor4us;
GLCOLOR4USV pfglColor4usv;
GLCOLORMASK pfglColorMask;
GLCOLORMATERIAL pfglColorMaterial;
GLCOLORPOINTER pfglColorPointer;
GLCOPYPIXELS pfglCopyPixels;
GLCOPYTEXIMAGE1D pfglCopyTexImage1D;
GLCOPYTEXIMAGE2D pfglCopyTexImage2D;
GLCOPYTEXSUBIMAGE1D pfglCopyTexSubImage1D;
GLCOPYTEXSUBIMAGE2D pfglCopyTexSubImage2D;
GLCULLFACE pfglCullFace;
GLDELETELISTS pfglDeleteLists;
GLDELETETEXTURES pfglDeleteTextures;
GLDEPTHFUNC pfglDepthFunc;
GLDEPTHMASK pfglDepthMask;
GLDEPTHRANGE pfglDepthRange;
GLDISABLE pfglDisable;
GLDISABLECLIENTSTATE pfglDisableClientState;
GLDRAWARRAYS pfglDrawArrays;
GLDRAWBUFFER pfglDrawBuffer;
GLDRAWELEMENTS pfglDrawElements;
GLDRAWPIXELS pfglDrawPixels;
GLEDGEFLAG pfglEdgeFlag;
GLEDGEFLAGPOINTER pfglEdgeFlagPointer;
GLEDGEFLAGV pfglEdgeFlagv;
GLENABLE pfglEnable;
GLENABLECLIENTSTATE pfglEnableClientState;
GLEND pfglEnd;
GLENDLIST pfglEndList;
GLEVALCOORD1D pfglEvalCoord1d;
GLEVALCOORD1DV pfglEvalCoord1dv;
GLEVALCOORD1F pfglEvalCoord1f;
GLEVALCOORD1FV pfglEvalCoord1fv;
GLEVALCOORD2D pfglEvalCoord2d;
GLEVALCOORD2DV pfglEvalCoord2dv;
GLEVALCOORD2F pfglEvalCoord2f;
GLEVALCOORD2FV pfglEvalCoord2fv;
GLEVALMESH1 pfglEvalMesh1;
GLEVALMESH2 pfglEvalMesh2;
GLEVALPOINT1 pfglEvalPoint1;
GLEVALPOINT2 pfglEvalPoint2;
GLFEEDBACKBUFFER pfglFeedbackBuffer;
GLFINISH pfglFinish;
GLFLUSH pfglFlush;
GLFOGF pfglFogf;
GLFOGFV pfglFogfv;
GLFOGI pfglFogi;
GLFOGIV pfglFogiv;
GLFRONTFACE pfglFrontFace;
GLFRUSTUM pfglFrustum;
GLGENLISTS pfglGenLists;
GLGENTEXTURES pfglGenTextures;
GLGETBOOLEANV pfglGetBooleanv;
GLGETCLIPPLANE pfglGetClipPlane;
GLGETDOUBLEV pfglGetDoublev;
GLGETERROR pfglGetError;
GLGETFLOATV pfglGetFloatv;
GLGETINTEGERV pfglGetIntegerv;
GLGETLIGHTFV pfglGetLightfv;
GLGETLIGHTIV pfglGetLightiv;
GLGETMAPDV pfglGetMapdv;
GLGETMAPFV pfglGetMapfv;
GLGETMAPIV pfglGetMapiv;
GLGETMATERIALFV pfglGetMaterialfv;
GLGETMATERIALIV pfglGetMaterialiv;
GLGETPIXELMAPFV pfglGetPixelMapfv;
GLGETPIXELMAPUIV pfglGetPixelMapuiv;
GLGETPIXELMAPUSV pfglGetPixelMapusv;
GLGETPOINTERV pfglGetPointerv;
GLGETPOLYGONSTIPPLE pfglGetPolygonStipple;
GLGETSTRING pfglGetString;
GLGETTEXENVFV pfglGetTexEnvfv;
GLGETTEXENVIV pfglGetTexEnviv;
GLGETTEXGENDV pfglGetTexGendv;
GLGETTEXGENFV pfglGetTexGenfv;
GLGETTEXGENIV pfglGetTexGeniv;
GLGETTEXIMAGE pfglGetTexImage;
GLGETTEXPARAMETERFV pfglGetTexParameterfv;
GLGETTEXPARAMETERIV pfglGetTexParameteriv;
GLHINT pfglHint;
GLINDEXMASK pfglIndexMask;
GLINDEXPOINTER pfglIndexPointer;
GLINDEXD pfglIndexd;
GLINDEXDV pfglIndexdv;
GLINDEXF pfglIndexf;
GLINDEXFV pfglIndexfv;
GLINDEXI pfglIndexi;
GLINDEXIV pfglIndexiv;
GLINDEXS pfglIndexs;
GLINDEXSV pfglIndexsv;
GLINDEXUB pfglIndexub;
GLINDEXUBV pfglIndexubv;
GLINITNAMES pfglInitNames;
GLINTERLEAVEDARRAYS pfglInterleavedArrays;
GLISENABLED pfglIsEnabled;
GLISLIST pfglIsList;
GLISTEXTURE pfglIsTexture;
GLLIGHTMODELF pfglLightModelf;
GLLIGHTMODELFV pfglLightModelfv;
GLLIGHTMODELI pfglLightModeli;
GLLIGHTMODELIV pfglLightModeliv;
GLLIGHTF pfglLightf;
GLLIGHTFV pfglLightfv;
GLLIGHTI pfglLighti;
GLLIGHTIV pfglLightiv;
GLLINESTIPPLE pfglLineStipple;
GLLINEWIDTH pfglLineWidth;
GLLISTBASE pfglListBase;
GLLOADIDENTITY pfglLoadIdentity;
GLLOADMATRIXD pfglLoadMatrixd;
GLLOADMATRIXF pfglLoadMatrixf;
GLLOADNAME pfglLoadName;
GLLOGICOP pfglLogicOp;
GLMAP1D pfglMap1d;
GLMAP1F pfglMap1f;
GLMAP2D pfglMap2d;
GLMAP2F pfglMap2f;
GLMAPGRID1D pfglMapGrid1d;
GLMAPGRID1F pfglMapGrid1f;
GLMAPGRID2D pfglMapGrid2d;
GLMAPGRID2F pfglMapGrid2f;
GLMATERIALF pfglMaterialf;
GLMATERIALFV pfglMaterialfv;
GLMATERIALI pfglMateriali;
GLMATERIALIV pfglMaterialiv;
GLMATRIXMODE pfglMatrixMode;
GLMULTMATRIXD pfglMultMatrixd;
GLMULTMATRIXF pfglMultMatrixf;
GLNEWLIST pfglNewList;
GLNORMAL3B pfglNormal3b;
GLNORMAL3BV pfglNormal3bv;
GLNORMAL3D pfglNormal3d;
GLNORMAL3DV pfglNormal3dv;
GLNORMAL3F pfglNormal3f;
GLNORMAL3FV pfglNormal3fv;
GLNORMAL3I pfglNormal3i;
GLNORMAL3IV pfglNormal3iv;
GLNORMAL3S pfglNormal3s;
GLNORMAL3SV pfglNormal3sv;
GLNORMALPOINTER pfglNormalPointer;
GLORTHO pfglOrtho;
GLPASSTHROUGH pfglPassThrough;
GLPIXELMAPFV pfglPixelMapfv;
GLPIXELMAPUIV pfglPixelMapuiv;
GLPIXELMAPUSV pfglPixelMapusv;
GLPIXELSTOREF pfglPixelStoref;
GLPIXELSTOREI pfglPixelStorei;
GLPIXELTRANSFERF pfglPixelTransferf;
GLPIXELTRANSFERI pfglPixelTransferi;
GLPIXELZOOM pfglPixelZoom;
GLPOINTSIZE pfglPointSize;
GLPOLYGONMODE pfglPolygonMode;
GLPOLYGONOFFSET pfglPolygonOffset;
GLPOLYGONSTIPPLE pfglPolygonStipple;
GLPOPATTRIB pfglPopAttrib;
GLPOPCLIENTATTRIB pfglPopClientAttrib;
GLPOPMATRIX pfglPopMatrix;
GLPOPNAME pfglPopName;
GLPRIORITIZETEXTURES pfglPrioritizeTextures;
GLPUSHATTRIB pfglPushAttrib;
GLPUSHCLIENTATTRIB pfglPushClientAttrib;
GLPUSHMATRIX pfglPushMatrix;
GLPUSHNAME pfglPushName;
GLRASTERPOS2D pfglRasterPos2d;
GLRASTERPOS2DV pfglRasterPos2dv;
GLRASTERPOS2F pfglRasterPos2f;
GLRASTERPOS2FV pfglRasterPos2fv;
GLRASTERPOS2I pfglRasterPos2i;
GLRASTERPOS2IV pfglRasterPos2iv;
GLRASTERPOS2S pfglRasterPos2s;
GLRASTERPOS2SV pfglRasterPos2sv;
GLRASTERPOS3D pfglRasterPos3d;
GLRASTERPOS3DV pfglRasterPos3dv;
GLRASTERPOS3F pfglRasterPos3f;
GLRASTERPOS3FV pfglRasterPos3fv;
GLRASTERPOS3I pfglRasterPos3i;
GLRASTERPOS3IV pfglRasterPos3iv;
GLRASTERPOS3S pfglRasterPos3s;
GLRASTERPOS3SV pfglRasterPos3sv;
GLRASTERPOS4D pfglRasterPos4d;
GLRASTERPOS4DV pfglRasterPos4dv;
GLRASTERPOS4F pfglRasterPos4f;
GLRASTERPOS4FV pfglRasterPos4fv;
GLRASTERPOS4I pfglRasterPos4i;
GLRASTERPOS4IV pfglRasterPos4iv;
GLRASTERPOS4S pfglRasterPos4s;
GLRASTERPOS4SV pfglRasterPos4sv;
GLREADBUFFER pfglReadBuffer;
GLREADPIXELS pfglReadPixels;
GLRECTD pfglRectd;
GLRECTDV pfglRectdv;
GLRECTF pfglRectf;
GLRECTFV pfglRectfv;
GLRECTI pfglRecti;
GLRECTIV pfglRectiv;
GLRECTS pfglRects;
GLRECTSV pfglRectsv;
GLRENDERMODE pfglRenderMode;
GLROTATED pfglRotated;
GLROTATEF pfglRotatef;
GLSCALED pfglScaled;
GLSCALEF pfglScalef;
GLSCISSOR pfglScissor;
GLSELECTBUFFER pfglSelectBuffer;
GLSHADEMODEL pfglShadeModel;
GLSTENCILFUNC pfglStencilFunc;
GLSTENCILMASK pfglStencilMask;
GLSTENCILOP pfglStencilOp;
GLTEXCOORD1D pfglTexCoord1d;
GLTEXCOORD1DV pfglTexCoord1dv;
GLTEXCOORD1F pfglTexCoord1f;
GLTEXCOORD1FV pfglTexCoord1fv;
GLTEXCOORD1I pfglTexCoord1i;
GLTEXCOORD1IV pfglTexCoord1iv;
GLTEXCOORD1S pfglTexCoord1s;
GLTEXCOORD1SV pfglTexCoord1sv;
GLTEXCOORD2D pfglTexCoord2d;
GLTEXCOORD2DV pfglTexCoord2dv;
GLTEXCOORD2F pfglTexCoord2f;
GLTEXCOORD2FV pfglTexCoord2fv;
GLTEXCOORD2I pfglTexCoord2i;
GLTEXCOORD2IV pfglTexCoord2iv;
GLTEXCOORD2S pfglTexCoord2s;
GLTEXCOORD2SV pfglTexCoord2sv;
GLTEXCOORD3D pfglTexCoord3d;
GLTEXCOORD3DV pfglTexCoord3dv;
GLTEXCOORD3F pfglTexCoord3f;
GLTEXCOORD3FV pfglTexCoord3fv;
GLTEXCOORD3I pfglTexCoord3i;
GLTEXCOORD3IV pfglTexCoord3iv;
GLTEXCOORD3S pfglTexCoord3s;
GLTEXCOORD3SV pfglTexCoord3sv;
GLTEXCOORD4D pfglTexCoord4d;
GLTEXCOORD4DV pfglTexCoord4dv;
GLTEXCOORD4F pfglTexCoord4f;
GLTEXCOORD4FV pfglTexCoord4fv;
GLTEXCOORD4I pfglTexCoord4i;
GLTEXCOORD4IV pfglTexCoord4iv;
GLTEXCOORD4S pfglTexCoord4s;
GLTEXCOORD4SV pfglTexCoord4sv;
GLTEXCOORDPOINTER pfglTexCoordPointer;
GLTEXENVF pfglTexEnvf;
GLTEXENVFV pfglTexEnvfv;
GLTEXENVI pfglTexEnvi;
GLTEXENVIV pfglTexEnviv;
GLTEXGEND pfglTexGend;
GLTEXGENDV pfglTexGendv;
GLTEXGENF pfglTexGenf;
GLTEXGENFV pfglTexGenfv;
GLTEXGENI pfglTexGeni;
GLTEXGENIV pfglTexGeniv;
GLTEXIMAGE1D pfglTexImage1D;
GLTEXIMAGE2D pfglTexImage2D;
GLTEXPARAMETERF pfglTexParameterf;
GLTEXPARAMETERFV pfglTexParameterfv;
GLTEXPARAMETERI pfglTexParameteri;
GLTEXPARAMETERIV pfglTexParameteriv;
GLTEXSUBIMAGE1D pfglTexSubImage1D;
GLTEXSUBIMAGE2D pfglTexSubImage2D;
GLTRANSLATED pfglTranslated;
GLTRANSLATEF pfglTranslatef;
GLVERTEX2D pfglVertex2d;
GLVERTEX2DV pfglVertex2dv;
GLVERTEX2F pfglVertex2f;
GLVERTEX2FV pfglVertex2fv;
GLVERTEX2I pfglVertex2i;
GLVERTEX2IV pfglVertex2iv;
GLVERTEX2S pfglVertex2s;
GLVERTEX2SV pfglVertex2sv;
GLVERTEX3D pfglVertex3d;
GLVERTEX3DV pfglVertex3dv;
GLVERTEX3F pfglVertex3f;
GLVERTEX3FV pfglVertex3fv;
GLVERTEX3I pfglVertex3i;
GLVERTEX3IV pfglVertex3iv;
GLVERTEX3S pfglVertex3s;
GLVERTEX3SV pfglVertex3sv;
GLVERTEX4D pfglVertex4d;
GLVERTEX4DV pfglVertex4dv;
GLVERTEX4F pfglVertex4f;
GLVERTEX4FV pfglVertex4fv;
GLVERTEX4I pfglVertex4i;
GLVERTEX4IV pfglVertex4iv;
GLVERTEX4S pfglVertex4s;
GLVERTEX4SV pfglVertex4sv;
GLVERTEXPOINTER pfglVertexPointer;
GLVIEWPORT pfglViewport;
#ifdef _WIN32
typedef BOOL (WINAPI *WGLCOPYCONTEXT)(HGLRC, HGLRC, UINT);
typedef HGLRC (WINAPI *WGLCREATECONTEXT)(HDC);
typedef HGLRC (WINAPI *WGLCREATELAYERCONTEXT)(HDC, int);
typedef BOOL (WINAPI *WGLDELETECONTEXT)(HGLRC);
typedef BOOL (WINAPI *WGLDESCRIBELAYERPLANE)(HDC, int, int, UINT, LPLAYERPLANEDESCRIPTOR);
typedef HGLRC (WINAPI *WGLGETCURRENTCONTEXT)(VOID);
typedef HDC (WINAPI *WGLGETCURRENTDC)(VOID);
typedef int (WINAPI *WGLGETLAYERPALETTEENTRIES)(HDC, int, int, int, COLORREF *);
typedef PROC (WINAPI *WGLGETPROCADDRESS)(LPCSTR);
typedef BOOL (WINAPI *WGLMAKECURRENT)(HDC, HGLRC);
typedef BOOL (WINAPI *WGLREALIZELAYERPALETTE)(HDC, int, BOOL);
typedef int (WINAPI *WGLSETLAYERPALETTEENTRIES)(HDC, int, int, int, CONST COLORREF *);
typedef BOOL (WINAPI *WGLSHARELISTS)(HGLRC, HGLRC);
typedef BOOL (WINAPI *WGLSWAPLAYERBUFFERS)(HDC, UINT);
typedef BOOL (WINAPI *WGLUSEFONTBITMAPS)(HDC, DWORD, DWORD, DWORD);
typedef BOOL (WINAPI *WGLUSEFONTOUTLINES)(HDC, DWORD, DWORD, DWORD, FLOAT, FLOAT, int, LPGLYPHMETRICSFLOAT);
WGLCOPYCONTEXT pfwglCopyContext;
WGLCREATECONTEXT pfwglCreateContext;
WGLCREATELAYERCONTEXT pfwglCreateLayerContext;
WGLDELETECONTEXT pfwglDeleteContext;
WGLDESCRIBELAYERPLANE pfwglDescribeLayerPlane;
WGLGETCURRENTCONTEXT pfwglGetCurrentContext;
WGLGETCURRENTDC pfwglGetCurrentDC;
WGLGETLAYERPALETTEENTRIES pfwglGetLayerPaletteEntries;
WGLGETPROCADDRESS pfwglGetProcAddress;
WGLMAKECURRENT pfwglMakeCurrent;
WGLREALIZELAYERPALETTE pfwglRealizeLayerPalette;
WGLSETLAYERPALETTEENTRIES pfwglSetLayerPaletteEntries;
WGLSHARELISTS pfwglShareLists;
WGLSWAPLAYERBUFFERS pfwglSwapLayerBuffers;
WGLUSEFONTBITMAPS pfwglUseFontBitmaps;
WGLUSEFONTOUTLINES pfwglUseFontOutlines;
typedef int ( WINAPI *WGLCHOOSEPIXELFORMAT )(HDC, CONST PIXELFORMATDESCRIPTOR *);
typedef int ( WINAPI *WGLDESCRIBEPIXELFORMAT) (HDC, int, UINT, LPPIXELFORMATDESCRIPTOR);
typedef int ( WINAPI *WGLGETPIXELFORMAT)(HDC);
typedef BOOL ( WINAPI *WGLSETPIXELFORMAT)(HDC, int, CONST PIXELFORMATDESCRIPTOR *);
typedef BOOL ( WINAPI *WGLSWAPBUFFERS)(HDC);
WGLCHOOSEPIXELFORMAT pfwglChoosePixelFormat;
WGLDESCRIBEPIXELFORMAT pfwglDescribePixelFormat;
WGLGETPIXELFORMAT pfwglGetPixelFormat;
WGLSETPIXELFORMAT pfwglSetPixelFormat;
WGLSWAPBUFFERS pfwglSwapBuffers;
typedef BOOL (WINAPI *WGLSWAPINTERVALEXT)( int );
typedef int (WINAPI *WGLGETSWAPINTERVALEXT)( void );
WGLSWAPINTERVALEXT pfwglSwapIntervalEXT;
WGLGETSWAPINTERVALEXT pfwglGetSwapIntervalEXT;
void *(WINAPI *pfwglAllocateMemoryNV)( GLsizei size, GLfloat readFrequency, GLfloat writeFrequency, GLfloat priority );
void *(WINAPI *pfwglFreeMemoryNV)( void *pointer );
#ifndef HPBUFFERARB
DECLARE_HANDLE( HPBUFFERARB );
#endif
HPBUFFERARB (WINAPI *pfwglCreatePbufferARB)( HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList );
HDC (WINAPI *pfwglGetPbufferDCARB)( HPBUFFERARB hPbuffer );
int (WINAPI *pfwglReleasePbufferDCARB)( HPBUFFERARB hPbuffer, HDC hDC );
BOOL (WINAPI *pfwglDestroyPbufferARB)(HPBUFFERARB hPbuffer);
BOOL (WINAPI *pfwglQueryPbufferARB)( HPBUFFERARB hPbuffer, int iAttribute, int *piValue );
BOOL (WINAPI *pfwglGetPixelFormatAttribivARB)( HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
BOOL (WINAPI *pfwglGetPixelFormatAttribfvARB)( HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues);
BOOL (WINAPI *pfwglChoosePixelFormatARB)( HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
#endif /* _WIN32 */
#ifdef __unix__
// Local function in dll
extern void *pfwglGetProcAddress( const char *symbol );
void *(*pfwglAllocateMemoryNV)( GLsizei size, GLfloat readFrequency, GLfloat writeFrequency, GLfloat priority );
void *(*pfwglFreeMemoryNV)( void *pointer );
// GLX Functions
XVisualInfo * (*pfglXChooseVisual)( Display *dpy, int screen, int *attribList );
void (*pfglXCopyContext)( Display *dpy, GLXContext src, GLXContext dst, GLuint mask );
GLXContext (*pfglXCreateContext)( Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct );
GLXPixmap (*pfglXCreateGLXPixmap)( Display *dpy, XVisualInfo *vis, Pixmap pixmap );
void (*pfglXDestroyContext)( Display *dpy, GLXContext ctx );
void (*pfglXDestroyGLXPixmap)( Display *dpy, GLXPixmap pix );
int (*pfglXGetConfig)( Display *dpy, XVisualInfo *vis, int attrib, int *value );
GLXContext (*pfglXGetCurrentContext)( void );
GLXDrawable (*pfglXGetCurrentDrawable)( void );
Bool (*pfglXIsDirect)( Display *dpy, GLXContext ctx );
Bool (*pfglXMakeCurrent)( Display *dpy, GLXDrawable drawable, GLXContext ctx);
Bool (*pfglXQueryExtension)( Display *dpy, int *errorBase, int *eventBase );
Bool (*pfglXQueryVersion)( Display *dpy, int *major, int *minor );
void (*pfglXSwapBuffers)( Display *dpy, GLXDrawable drawable );
void (*pfglXUseXFont)( Font font, int first, int count, int listBase );
void (*pfglXWaitGL)( void );
void (*pfglXWaitX)( void );
#endif /* __unix__ */
#endif /* __MYOPENGL_H__ */

716
wolf3d/code/env/myopengl_extension.h vendored Normal file
View File

@@ -0,0 +1,716 @@
/*
Copyright (C) 2004 Michael Liebscher
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* myopengl_extension.h: Interface to OpenGL extensions.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
*/
/*
Notes:
This module is implemented by opengl_extenstion.c
*/
#ifndef __MYOPENGL_EXTENSION_H__
#define __MYOPENGL_EXTENSION_H__
#ifdef IPHONE
#include <OpenGLES/ES1/gl.h>
#include <OpenGLES/ES1/glext.h>
#else
#include <GL/gl.h>
#include "GL/glext.h"
#endif
#ifndef APIENTRY
#define APIENTRY
#endif
#ifndef APIENTRYP
#define APIENTRYP APIENTRY *
#endif
///////////////////////////////////////////////////////////////////////////////
//
// OpenGL Extensions
//
///////////////////////////////////////////////////////////////////////////////
#define GL_POINT_SIZE_MIN_EXT 0x8126
#define GL_POINT_SIZE_MAX_EXT 0x8127
#define GL_POINT_FADE_THRESHOLD_SIZE_EXT 0x8128
#define GL_DISTANCE_ATTENUATION_EXT 0x8129
#ifdef __sgi
#define GL_SHARED_TEXTURE_PALETTE_EXT GL_TEXTURE_COLOR_TABLE_SGI
#else
#define GL_SHARED_TEXTURE_PALETTE_EXT 0x81FB
#endif
#define GL_TEXTURE0_ARB 0x84C0
#define GL_TEXTURE1_ARB 0x84C1
#define GL_TEXTURE2_ARB 0x84C2
#define GL_TEXTURE3_ARB 0x84C3
#ifndef WGL_ARB_pixel_format
#define WGL_ARB_pixel_format 1
#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
#define WGL_DRAW_TO_WINDOW_ARB 0x2001
#define WGL_DRAW_TO_BITMAP_ARB 0x2002
#define WGL_ACCELERATION_ARB 0x2003
#define WGL_NEED_PALETTE_ARB 0x2004
#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005
#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006
#define WGL_SWAP_METHOD_ARB 0x2007
#define WGL_NUMBER_OVERLAYS_ARB 0x2008
#define WGL_NUMBER_UNDERLAYS_ARB 0x2009
#define WGL_TRANSPARENT_ARB 0x200A
#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037
#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038
#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039
#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A
#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B
#define WGL_SHARE_DEPTH_ARB 0x200C
#define WGL_SHARE_STENCIL_ARB 0x200D
#define WGL_SHARE_ACCUM_ARB 0x200E
#define WGL_SUPPORT_GDI_ARB 0x200F
#define WGL_SUPPORT_OPENGL_ARB 0x2010
#define WGL_DOUBLE_BUFFER_ARB 0x2011
#define WGL_STEREO_ARB 0x2012
#define WGL_PIXEL_TYPE_ARB 0x2013
#define WGL_COLOR_BITS_ARB 0x2014
#define WGL_RED_BITS_ARB 0x2015
#define WGL_RED_SHIFT_ARB 0x2016
#define WGL_GREEN_BITS_ARB 0x2017
#define WGL_GREEN_SHIFT_ARB 0x2018
#define WGL_BLUE_BITS_ARB 0x2019
#define WGL_BLUE_SHIFT_ARB 0x201A
#define WGL_ALPHA_BITS_ARB 0x201B
#define WGL_ALPHA_SHIFT_ARB 0x201C
#define WGL_ACCUM_BITS_ARB 0x201D
#define WGL_ACCUM_RED_BITS_ARB 0x201E
#define WGL_ACCUM_GREEN_BITS_ARB 0x201F
#define WGL_ACCUM_BLUE_BITS_ARB 0x2020
#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
#define WGL_DEPTH_BITS_ARB 0x2022
#define WGL_STENCIL_BITS_ARB 0x2023
#define WGL_AUX_BUFFERS_ARB 0x2024
#define WGL_NO_ACCELERATION_ARB 0x2025
#define WGL_GENERIC_ACCELERATION_ARB 0x2026
#define WGL_FULL_ACCELERATION_ARB 0x2027
#define WGL_SWAP_EXCHANGE_ARB 0x2028
#define WGL_SWAP_COPY_ARB 0x2029
#define WGL_SWAP_UNDEFINED_ARB 0x202A
#define WGL_TYPE_RGBA_ARB 0x202B
#define WGL_TYPE_COLORINDEX_ARB 0x202C
#endif /* WGL_ARB_pixel_format */
#ifndef WGL_ARB_pbuffer
#define WGL_ARB_pbuffer 1
#define WGL_DRAW_TO_PBUFFER_ARB 0x202D
#define WGL_MAX_PBUFFER_PIXELS_ARB 0x202E
#define WGL_MAX_PBUFFER_WIDTH_ARB 0x202F
#define WGL_MAX_PBUFFER_HEIGHT_ARB 0x2030
#define WGL_PBUFFER_LARGEST_ARB 0x2033
#define WGL_PBUFFER_WIDTH_ARB 0x2034
#define WGL_PBUFFER_HEIGHT_ARB 0x2035
#define WGL_PBUFFER_LOST_ARB 0x2036
#endif
/*
-----------------------
ARB_MultiTexture
-----------------------
*/
void (APIENTRYP pfglActiveTextureARB) (GLenum);
void (APIENTRYP pfglClientActiveTextureARB) (GLenum);
void (APIENTRYP pfglMultiTexCoord1dARB) (GLenum, GLdouble);
void (APIENTRYP pfglMultiTexCoord1dvARB) (GLenum, const GLdouble *);
void (APIENTRYP pfglMultiTexCoord1fARB) (GLenum, GLfloat);
void (APIENTRYP pfglMultiTexCoord1fvARB) (GLenum, const GLfloat *);
void (APIENTRYP pfglMultiTexCoord1iARB) (GLenum, GLint);
void (APIENTRYP pfglMultiTexCoord1ivARB) (GLenum, const GLint *);
void (APIENTRYP pfglMultiTexCoord1sARB) (GLenum, GLshort);
void (APIENTRYP pfglMultiTexCoord1svARB) (GLenum, const GLshort *);
void (APIENTRYP pfglMultiTexCoord2dARB) (GLenum, GLdouble, GLdouble);
void (APIENTRYP pfglMultiTexCoord2dvARB) (GLenum, const GLdouble *);
void (APIENTRYP pfglMultiTexCoord2fARB) (GLenum, GLfloat, GLfloat);
void (APIENTRYP pfglMultiTexCoord2fvARB) (GLenum, const GLfloat *);
void (APIENTRYP pfglMultiTexCoord2iARB) (GLenum, GLint, GLint);
void (APIENTRYP pfglMultiTexCoord2ivARB) (GLenum, const GLint *);
void (APIENTRYP pfglMultiTexCoord2sARB) (GLenum, GLshort, GLshort);
void (APIENTRYP pfglMultiTexCoord2svARB) (GLenum, const GLshort *);
void (APIENTRYP pfglMultiTexCoord3dARB) (GLenum, GLdouble, GLdouble, GLdouble);
void (APIENTRYP pfglMultiTexCoord3dvARB) (GLenum, const GLdouble *);
void (APIENTRYP pfglMultiTexCoord3fARB) (GLenum, GLfloat, GLfloat, GLfloat);
void (APIENTRYP pfglMultiTexCoord3fvARB) (GLenum, const GLfloat *);
void (APIENTRYP pfglMultiTexCoord3iARB) (GLenum, GLint, GLint, GLint);
void (APIENTRYP pfglMultiTexCoord3ivARB) (GLenum, const GLint *);
void (APIENTRYP pfglMultiTexCoord3sARB) (GLenum, GLshort, GLshort, GLshort);
void (APIENTRYP pfglMultiTexCoord3svARB) (GLenum, const GLshort *);
void (APIENTRYP pfglMultiTexCoord4dARB) (GLenum, GLdouble, GLdouble, GLdouble, GLdouble);
void (APIENTRYP pfglMultiTexCoord4dvARB) (GLenum, const GLdouble *);
void (APIENTRYP pfglMultiTexCoord4fARB) (GLenum, GLfloat, GLfloat, GLfloat, GLfloat);
void (APIENTRYP pfglMultiTexCoord4fvARB) (GLenum, const GLfloat *);
void (APIENTRYP pfglMultiTexCoord4iARB) (GLenum, GLint, GLint, GLint, GLint);
void (APIENTRYP pfglMultiTexCoord4ivARB) (GLenum, const GLint *);
void (APIENTRYP pfglMultiTexCoord4sARB) (GLenum, GLshort, GLshort, GLshort, GLshort);
void (APIENTRYP pfglMultiTexCoord4svARB) (GLenum, const GLshort *);
/*
-----------------------
ARB_TransposeMatrix
-----------------------
*/
void (APIENTRYP pfglLoadTransposeMatrixfARB) (const GLfloat *);
void (APIENTRYP pfglLoadTransposeMatrixdARB) (const GLdouble *);
void (APIENTRYP pfglMultTransposeMatrixfARB) (const GLfloat *);
void (APIENTRYP pfglMultTransposeMatrixdARB) (const GLdouble *);
/*
-----------------------
ARB_MultiSample
-----------------------
*/
void (APIENTRYP pfglSampleCoverageARB) (GLclampf, GLboolean);
/*
-----------------------
ARB_TextureCompression
-----------------------
*/
void (APIENTRYP pfglCompressedTexImage3DARB) (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *);
void (APIENTRYP pfglCompressedTexImage2DARB) (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *);
void (APIENTRYP pfglCompressedTexImage1DARB) (GLenum, GLint, GLenum, GLsizei, GLint, GLsizei, const GLvoid *);
void (APIENTRYP pfglCompressedTexSubImage3DARB) (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *);
void (APIENTRYP pfglCompressedTexSubImage2DARB) (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *);
void (APIENTRYP pfglCompressedTexSubImage1DARB) (GLenum, GLint, GLint, GLsizei, GLenum, GLsizei, const GLvoid *);
void (APIENTRYP pfglGetCompressedTexImageARB) (GLenum, GLint, GLvoid *);
/*
-----------------------
ARB_PointParameters
-----------------------
*/
void (APIENTRYP pfglPointParameterfARB) (GLenum, GLfloat);
void (APIENTRYP pfglPointParameterfvARB) (GLenum, const GLfloat *);
/*
-----------------------
ARB_VertexBlend
-----------------------
*/
void (APIENTRYP pfglWeightbvARB) (GLint, const GLbyte *);
void (APIENTRYP pfglWeightsvARB) (GLint, const GLshort *);
void (APIENTRYP pfglWeightivARB) (GLint, const GLint *);
void (APIENTRYP pfglWeightfvARB) (GLint, const GLfloat *);
void (APIENTRYP pfglWeightdvARB) (GLint, const GLdouble *);
void (APIENTRYP pfglWeightubvARB) (GLint, const GLubyte *);
void (APIENTRYP pfglWeightusvARB) (GLint, const GLushort *);
void (APIENTRYP pfglWeightuivARB) (GLint, const GLuint *);
void (APIENTRYP pfglWeightPointerARB) (GLint, GLenum, GLsizei, const GLvoid *);
void (APIENTRYP pfglVertexBlendARB) (GLint);
/*
-----------------------
ARB_MatrixPalette
-----------------------
*/
void (APIENTRYP pfglCurrentPaletteMatrixARB) (GLint);
void (APIENTRYP pfglMatrixIndexubvARB) (GLint, const GLubyte *);
void (APIENTRYP pfglMatrixIndexusvARB) (GLint, const GLushort *);
void (APIENTRYP pfglMatrixIndexuivARB) (GLint, const GLuint *);
void (APIENTRYP pfglMatrixIndexPointerARB) (GLint, GLenum, GLsizei, const GLvoid *);
/*
------------------------------
ARB_VertexProgram
------------------------------
*/
void (APIENTRYP pfglVertexAttrib1dARB) (GLuint, GLdouble);
void (APIENTRYP pfglVertexAttrib1dvARB) (GLuint, const GLdouble *);
void (APIENTRYP pfglVertexAttrib1fARB) (GLuint, GLfloat);
void (APIENTRYP pfglVertexAttrib1fvARB) (GLuint, const GLfloat *);
void (APIENTRYP pfglVertexAttrib1sARB) (GLuint, GLshort);
void (APIENTRYP pfglVertexAttrib1svARB) (GLuint, const GLshort *);
void (APIENTRYP pfglVertexAttrib2dARB) (GLuint, GLdouble, GLdouble);
void (APIENTRYP pfglVertexAttrib2dvARB) (GLuint, const GLdouble *);
void (APIENTRYP pfglVertexAttrib2fARB) (GLuint, GLfloat, GLfloat);
void (APIENTRYP pfglVertexAttrib2fvARB) (GLuint, const GLfloat *);
void (APIENTRYP pfglVertexAttrib2sARB) (GLuint, GLshort, GLshort);
void (APIENTRYP pfglVertexAttrib2svARB) (GLuint, const GLshort *);
void (APIENTRYP pfglVertexAttrib3dARB) (GLuint, GLdouble, GLdouble, GLdouble);
void (APIENTRYP pfglVertexAttrib3dvARB) (GLuint, const GLdouble *);
void (APIENTRYP pfglVertexAttrib3fARB) (GLuint, GLfloat, GLfloat, GLfloat);
void (APIENTRYP pfglVertexAttrib3fvARB) (GLuint, const GLfloat *);
void (APIENTRYP pfglVertexAttrib3sARB) (GLuint, GLshort, GLshort, GLshort);
void (APIENTRYP pfglVertexAttrib3svARB) (GLuint, const GLshort *);
void (APIENTRYP pfglVertexAttrib4NbvARB) (GLuint, const GLbyte *);
void (APIENTRYP pfglVertexAttrib4NivARB) (GLuint, const GLint *);
void (APIENTRYP pfglVertexAttrib4NsvARB) (GLuint, const GLshort *);
void (APIENTRYP pfglVertexAttrib4NubARB) (GLuint, GLubyte, GLubyte, GLubyte, GLubyte);
void (APIENTRYP pfglVertexAttrib4NubvARB) (GLuint, const GLubyte *);
void (APIENTRYP pfglVertexAttrib4NuivARB) (GLuint, const GLuint *);
void (APIENTRYP pfglVertexAttrib4NusvARB) (GLuint, const GLushort *);
void (APIENTRYP pfglVertexAttrib4bvARB) (GLuint, const GLbyte *);
void (APIENTRYP pfglVertexAttrib4dARB) (GLuint, GLdouble, GLdouble, GLdouble, GLdouble);
void (APIENTRYP pfglVertexAttrib4dvARB) (GLuint, const GLdouble *);
void (APIENTRYP pfglVertexAttrib4fARB) (GLuint, GLfloat, GLfloat, GLfloat, GLfloat);
void (APIENTRYP pfglVertexAttrib4fvARB) (GLuint, const GLfloat *);
void (APIENTRYP pfglVertexAttrib4ivARB) (GLuint, const GLint *);
void (APIENTRYP pfglVertexAttrib4sARB) (GLuint, GLshort, GLshort, GLshort, GLshort);
void (APIENTRYP pfglVertexAttrib4svARB) (GLuint, const GLshort *);
void (APIENTRYP pfglVertexAttrib4ubvARB) (GLuint, const GLubyte *);
void (APIENTRYP pfglVertexAttrib4uivARB) (GLuint, const GLuint *);
void (APIENTRYP pfglVertexAttrib4usvARB) (GLuint, const GLushort *);
void (APIENTRYP pfglVertexAttribPointerARB) (GLuint, GLint, GLenum, GLboolean, GLsizei, const GLvoid *);
void (APIENTRYP pfglEnableVertexAttribArrayARB) (GLuint);
void (APIENTRYP pfglDisableVertexAttribArrayARB) (GLuint);
void (APIENTRYP pfglProgramStringARB) (GLenum, GLenum, GLsizei, const GLvoid *);
void (APIENTRYP pfglBindProgramARB) (GLenum, GLuint);
void (APIENTRYP pfglDeleteProgramsARB) (GLsizei, const GLuint *);
void (APIENTRYP pfglGenProgramsARB) (GLsizei, GLuint *);
void (APIENTRYP pfglProgramEnvParameter4dARB) (GLenum, GLuint, GLdouble, GLdouble, GLdouble, GLdouble);
void (APIENTRYP pfglProgramEnvParameter4dvARB) (GLenum, GLuint, const GLdouble *);
void (APIENTRYP pfglProgramEnvParameter4fARB) (GLenum, GLuint, GLfloat, GLfloat, GLfloat, GLfloat);
void (APIENTRYP pfglProgramEnvParameter4fvARB) (GLenum, GLuint, const GLfloat *);
void (APIENTRYP pfglProgramLocalParameter4dARB) (GLenum, GLuint, GLdouble, GLdouble, GLdouble, GLdouble);
void (APIENTRYP pfglProgramLocalParameter4dvARB) (GLenum, GLuint, const GLdouble *);
void (APIENTRYP pfglProgramLocalParameter4fARB) (GLenum, GLuint, GLfloat, GLfloat, GLfloat, GLfloat);
void (APIENTRYP pfglProgramLocalParameter4fvARB) (GLenum, GLuint, const GLfloat *);
void (APIENTRYP pfglGetProgramEnvParameterdvARB) (GLenum, GLuint, GLdouble *);
void (APIENTRYP pfglGetProgramEnvParameterfvARB) (GLenum, GLuint, GLfloat *);
void (APIENTRYP pfglGetProgramLocalParameterdvARB) (GLenum, GLuint, GLdouble *);
void (APIENTRYP pfglGetProgramLocalParameterfvARB) (GLenum, GLuint, GLfloat *);
void (APIENTRYP pfglGetProgramivARB) (GLenum, GLenum, GLint *);
void (APIENTRYP pfglGetProgramStringARB) (GLenum, GLenum, GLvoid *);
void (APIENTRYP pfglGetVertexAttribdvARB) (GLuint, GLenum, GLdouble *);
void (APIENTRYP pfglGetVertexAttribfvARB) (GLuint, GLenum, GLfloat *);
void (APIENTRYP pfglGetVertexAttribivARB) (GLuint, GLenum, GLint *);
void (APIENTRYP pfglGetVertexAttribPointervARB) (GLuint, GLenum, GLvoid* *);
GLboolean (APIENTRYP pfglIsProgramARB) (GLuint);
/* All ARB_fragment_program entry points are shared with ARB_vertex_program. */
/*
------------------------------
ARB_VertexBufferObject
------------------------------
*/
void (APIENTRYP pfglBindBufferARB) (GLenum, GLuint);
void (APIENTRYP pfglDeleteBuffersARB) (GLsizei, const GLuint *);
void (APIENTRYP pfglGenBuffersARB) (GLsizei, GLuint *);
GLboolean (APIENTRYP pfglIsBufferARB) (GLuint);
void (APIENTRYP pfglBufferDataARB) (GLenum, GLsizeiptrARB, const GLvoid *, GLenum);
void (APIENTRYP pfglBufferSubDataARB) (GLenum, GLintptrARB, GLsizeiptrARB, const GLvoid *);
void (APIENTRYP pfglGetBufferSubDataARB) (GLenum, GLintptrARB, GLsizeiptrARB, GLvoid *);
GLvoid* (APIENTRYP pfglMapBufferARB) (GLenum, GLenum);
GLboolean (APIENTRYP pfglUnmapBufferARB) (GLenum);
void (APIENTRYP pfglGetBufferParameterivARB) (GLenum, GLenum, GLint *);
void (APIENTRYP pfglGetBufferPointervARB) (GLenum, GLenum, GLvoid* *);
/*
------------------------------
ARB_OcclusionQuery
------------------------------
*/
void (APIENTRYP pfglGenQueriesARB) (GLsizei, GLuint *);
void (APIENTRYP pfglDeleteQueriesARB) (GLsizei, const GLuint *);
GLboolean (APIENTRYP pfglIsQueryARB) (GLuint);
void (APIENTRYP pfglBeginQueryARB) (GLenum, GLuint);
void (APIENTRYP pfglEndQueryARB) (GLenum);
void (APIENTRYP pfglGetQueryivARB) (GLenum, GLenum, GLint *);
void (APIENTRYP pfglGetQueryObjectivARB) (GLuint, GLenum, GLint *);
void (APIENTRYP pfglGetQueryObjectuivARB) (GLuint, GLenum, GLuint *);
/*
------------------------------
ARB_ShaderObjects
------------------------------
*/
void (APIENTRYP pfglDeleteObjectARB) (GLhandleARB);
GLhandleARB (APIENTRYP pfglGetHandleARB) (GLenum);
void (APIENTRYP pfglDetachObjectARB) (GLhandleARB, GLhandleARB);
GLhandleARB (APIENTRYP pfglCreateShaderObjectARB) (GLenum);
void (APIENTRYP pfglShaderSourceARB) (GLhandleARB, GLsizei, const GLcharARB* *, const GLint *);
void (APIENTRYP pfglCompileShaderARB) (GLhandleARB);
GLhandleARB (APIENTRYP pfglCreateProgramObjectARB) (void);
void (APIENTRYP pfglAttachObjectARB) (GLhandleARB, GLhandleARB);
void (APIENTRYP pfglLinkProgramARB) (GLhandleARB);
void (APIENTRYP pfglUseProgramObjectARB) (GLhandleARB);
void (APIENTRYP pfglValidateProgramARB) (GLhandleARB);
void (APIENTRYP pfglUniform1fARB) (GLint, GLfloat);
void (APIENTRYP pfglUniform2fARB) (GLint, GLfloat, GLfloat);
void (APIENTRYP pfglUniform3fARB) (GLint, GLfloat, GLfloat, GLfloat);
void (APIENTRYP pfglUniform4fARB) (GLint, GLfloat, GLfloat, GLfloat, GLfloat);
void (APIENTRYP pfglUniform1iARB) (GLint, GLint);
void (APIENTRYP pfglUniform2iARB) (GLint, GLint, GLint);
void (APIENTRYP pfglUniform3iARB) (GLint, GLint, GLint, GLint);
void (APIENTRYP pfglUniform4iARB) (GLint, GLint, GLint, GLint, GLint);
void (APIENTRYP pfglUniform1fvARB) (GLint, GLsizei, const GLfloat *);
void (APIENTRYP pfglUniform2fvARB) (GLint, GLsizei, const GLfloat *);
void (APIENTRYP pfglUniform3fvARB) (GLint, GLsizei, const GLfloat *);
void (APIENTRYP pfglUniform4fvARB) (GLint, GLsizei, const GLfloat *);
void (APIENTRYP pfglUniform1ivARB) (GLint, GLsizei, const GLint *);
void (APIENTRYP pfglUniform2ivARB) (GLint, GLsizei, const GLint *);
void (APIENTRYP pfglUniform3ivARB) (GLint, GLsizei, const GLint *);
void (APIENTRYP pfglUniform4ivARB) (GLint, GLsizei, const GLint *);
void (APIENTRYP pfglUniformMatrix2fvARB) (GLint, GLsizei, GLboolean, const GLfloat *);
void (APIENTRYP pfglUniformMatrix3fvARB) (GLint, GLsizei, GLboolean, const GLfloat *);
void (APIENTRYP pfglUniformMatrix4fvARB) (GLint, GLsizei, GLboolean, const GLfloat *);
void (APIENTRYP pfglGetObjectParameterfvARB) (GLhandleARB, GLenum, GLfloat *);
void (APIENTRYP pfglGetObjectParameterivARB) (GLhandleARB, GLenum, GLint *);
void (APIENTRYP pfglGetInfoLogARB) (GLhandleARB, GLsizei, GLsizei *, GLcharARB *);
void (APIENTRYP pfglGetAttachedObjectsARB) (GLhandleARB, GLsizei, GLsizei *, GLhandleARB *);
GLint (APIENTRYP pfglGetUniformLocationARB) (GLhandleARB, const GLcharARB *);
void (APIENTRYP pfglGetActiveUniformARB) (GLhandleARB, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLcharARB *);
void (APIENTRYP pfglGetUniformfvARB) (GLhandleARB, GLint, GLfloat *);
void (APIENTRYP pfglGetUniformivARB) (GLhandleARB, GLint, GLint *);
void (APIENTRYP pfglGetShaderSourceARB) (GLhandleARB, GLsizei, GLsizei *, GLcharARB *);
/*
------------------------------
ARB_VertexShader
------------------------------
*/
void (APIENTRYP pfglBindAttribLocationARB) (GLhandleARB, GLuint, const GLcharARB *);
void (APIENTRYP pfglGetActiveAttribARB) (GLhandleARB, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLcharARB *);
GLint (APIENTRYP pfglGetAttribLocationARB) (GLhandleARB, const GLcharARB *);
/*
-----------------------
EXT_BlendColor
-----------------------
*/
void (APIENTRYP pfglBlendColorEXT) (GLclampf, GLclampf, GLclampf, GLclampf);
/*
-------------------------
EXT_CompiledVertexArray
-------------------------
*/
void ( APIENTRYP pfglLockArraysEXT) ( GLint, GLsizei );
void ( APIENTRYP pfglUnlockArraysEXT) ( void );
/*
-----------------------
EXT_SecondaryColor
-----------------------
*/
void (APIENTRYP pfglSecondaryColor3bEXT) (GLbyte, GLbyte, GLbyte);
void (APIENTRYP pfglSecondaryColor3bvEXT) (const GLbyte *);
void (APIENTRYP pfglSecondaryColor3dEXT) (GLdouble, GLdouble, GLdouble);
void (APIENTRYP pfglSecondaryColor3dvEXT) (const GLdouble *);
void (APIENTRYP pfglSecondaryColor3fEXT) (GLfloat, GLfloat, GLfloat);
void (APIENTRYP pfglSecondaryColor3fvEXT) (const GLfloat *);
void (APIENTRYP pfglSecondaryColor3iEXT) (GLint, GLint, GLint);
void (APIENTRYP pfglSecondaryColor3ivEXT) (const GLint *);
void (APIENTRYP pfglSecondaryColor3sEXT) (GLshort, GLshort, GLshort);
void (APIENTRYP pfglSecondaryColor3svEXT) (const GLshort *);
void (APIENTRYP pfglSecondaryColor3ubEXT) (GLubyte, GLubyte, GLubyte);
void (APIENTRYP pfglSecondaryColor3ubvEXT) (const GLubyte *);
void (APIENTRYP pfglSecondaryColor3uiEXT) (GLuint, GLuint, GLuint);
void (APIENTRYP pfglSecondaryColor3uivEXT) (const GLuint *);
void (APIENTRYP pfglSecondaryColor3usEXT) (GLushort, GLushort, GLushort);
void (APIENTRYP pfglSecondaryColor3usvEXT) (const GLushort *);
void (APIENTRYP pfglSecondaryColorPointerEXT) (GLint, GLenum, GLsizei, const GLvoid *);
/*
-----------------------
EXT_VertexShader
-----------------------
*/
void (APIENTRYP pfglBeginVertexShaderEXT) (void);
void (APIENTRYP pfglEndVertexShaderEXT) (void);
void (APIENTRYP pfglBindVertexShaderEXT) (GLuint);
GLuint (APIENTRYP pfglGenVertexShadersEXT) (GLuint);
void (APIENTRYP pfglDeleteVertexShaderEXT) (GLuint);
void (APIENTRYP pfglShaderOp1EXT) (GLenum, GLuint, GLuint);
void (APIENTRYP pfglShaderOp2EXT) (GLenum, GLuint, GLuint, GLuint);
void (APIENTRYP pfglShaderOp3EXT) (GLenum, GLuint, GLuint, GLuint, GLuint);
void (APIENTRYP pfglSwizzleEXT) (GLuint, GLuint, GLenum, GLenum, GLenum, GLenum);
void (APIENTRYP pfglWriteMaskEXT) (GLuint, GLuint, GLenum, GLenum, GLenum, GLenum);
void (APIENTRYP pfglInsertComponentEXT) (GLuint, GLuint, GLuint);
void (APIENTRYP pfglExtractComponentEXT) (GLuint, GLuint, GLuint);
GLuint (APIENTRYP pfglGenSymbolsEXT) (GLenum, GLenum, GLenum, GLuint);
void (APIENTRYP pfglSetInvariantEXT) (GLuint, GLenum, const GLvoid *);
void (APIENTRYP pfglSetLocalConstantEXT) (GLuint, GLenum, const GLvoid *);
void (APIENTRYP pfglVariantbvEXT) (GLuint, const GLbyte *);
void (APIENTRYP pfglVariantsvEXT) (GLuint, const GLshort *);
void (APIENTRYP pfglVariantivEXT) (GLuint, const GLint *);
void (APIENTRYP pfglVariantfvEXT) (GLuint, const GLfloat *);
void (APIENTRYP pfglVariantdvEXT) (GLuint, const GLdouble *);
void (APIENTRYP pfglVariantubvEXT) (GLuint, const GLubyte *);
void (APIENTRYP pfglVariantusvEXT) (GLuint, const GLushort *);
void (APIENTRYP pfglVariantuivEXT) (GLuint, const GLuint *);
void (APIENTRYP pfglVariantPointerEXT) (GLuint, GLenum, GLuint, const GLvoid *);
void (APIENTRYP pfglEnableVariantClientStateEXT) (GLuint);
void (APIENTRYP pfglDisableVariantClientStateEXT) (GLuint);
GLuint (APIENTRYP pfglBindLightParameterEXT) (GLenum, GLenum);
GLuint (APIENTRYP pfglBindMaterialParameterEXT) (GLenum, GLenum);
GLuint (APIENTRYP pfglBindTexGenParameterEXT) (GLenum, GLenum, GLenum);
GLuint (APIENTRYP pfglBindTextureUnitParameterEXT) (GLenum, GLenum);
GLuint (APIENTRYP pfglBindParameterEXT) (GLenum);
GLboolean (APIENTRYP pfglIsVariantEnabledEXT) (GLuint, GLenum);
void (APIENTRYP pfglGetVariantBooleanvEXT) (GLuint, GLenum, GLboolean *);
void (APIENTRYP pfglGetVariantIntegervEXT) (GLuint, GLenum, GLint *);
void (APIENTRYP pfglGetVariantFloatvEXT) (GLuint, GLenum, GLfloat *);
void (APIENTRYP pfglGetVariantPointervEXT) (GLuint, GLenum, GLvoid* *);
void (APIENTRYP pfglGetInvariantBooleanvEXT) (GLuint, GLenum, GLboolean *);
void (APIENTRYP pfglGetInvariantIntegervEXT) (GLuint, GLenum, GLint *);
void (APIENTRYP pfglGetInvariantFloatvEXT) (GLuint, GLenum, GLfloat *);
void (APIENTRYP pfglGetLocalConstantBooleanvEXT) (GLuint, GLenum, GLboolean *);
void (APIENTRYP pfglGetLocalConstantIntegervEXT) (GLuint, GLenum, GLint *);
void (APIENTRYP pfglGetLocalConstantFloatvEXT) (GLuint, GLenum, GLfloat *);
/*
-----------------------
EXT_VertexWeighting
-----------------------
*/
void (APIENTRYP pfglVertexWeightfEXT) (GLfloat);
void (APIENTRYP pfglVertexWeightfvEXT) (const GLfloat *);
void (APIENTRYP pfglVertexWeightPointerEXT) (GLsizei, GLenum, GLsizei, const GLvoid *);
//////////////////////////////////
//
// nVidia Extensions
//
//////////////////////////////////
/*
-----------------------
NV_Fence
-----------------------
*/
void (APIENTRYP pfglDeleteFencesNV) (GLsizei, const GLuint *);
void (APIENTRYP pfglGenFencesNV) (GLsizei, GLuint *);
GLboolean (APIENTRYP pfglIsFenceNV) (GLuint);
GLboolean (APIENTRYP pfglTestFenceNV) (GLuint);
void (APIENTRYP pfglGetFenceivNV) (GLuint, GLenum, GLint *);
void (APIENTRYP pfglFinishFenceNV) (GLuint);
void (APIENTRYP pfglSetFenceNV) (GLuint, GLenum);
/*
-----------------------
NV_VertexArrayRange
-----------------------
*/
void (APIENTRYP pfglFlushVertexArrayRangeNV) (void);
void (APIENTRYP pfglVertexArrayRangeNV) (GLsizei, const GLvoid *);
/*
-----------------------
NV_VertexProgram
-----------------------
*/
GLboolean (APIENTRYP pfglAreProgramsResidentNV) (GLsizei, const GLuint *, GLboolean *);
void (APIENTRYP pfglBindProgramNV) (GLenum, GLuint);
void (APIENTRYP pfglDeleteProgramsNV) (GLsizei, const GLuint *);
void (APIENTRYP pfglExecuteProgramNV) (GLenum, GLuint, const GLfloat *);
void (APIENTRYP pfglGenProgramsNV) (GLsizei, GLuint *);
void (APIENTRYP pfglGetProgramParameterdvNV) (GLenum, GLuint, GLenum, GLdouble *);
void (APIENTRYP pfglGetProgramParameterfvNV) (GLenum, GLuint, GLenum, GLfloat *);
void (APIENTRYP pfglGetProgramivNV) (GLuint, GLenum, GLint *);
void (APIENTRYP pfglGetProgramStringNV) (GLuint, GLenum, GLubyte *);
void (APIENTRYP pfglGetTrackMatrixivNV) (GLenum, GLuint, GLenum, GLint *);
void (APIENTRYP pfglGetVertexAttribdvNV) (GLuint, GLenum, GLdouble *);
void (APIENTRYP pfglGetVertexAttribfvNV) (GLuint, GLenum, GLfloat *);
void (APIENTRYP pfglGetVertexAttribivNV) (GLuint, GLenum, GLint *);
void (APIENTRYP pfglGetVertexAttribPointervNV) (GLuint, GLenum, GLvoid* *);
GLboolean (APIENTRYP pfglIsProgramNV) (GLuint);
void (APIENTRYP pfglLoadProgramNV) (GLenum, GLuint, GLsizei, const GLubyte *);
void (APIENTRYP pfglProgramParameter4dNV) (GLenum, GLuint, GLdouble, GLdouble, GLdouble, GLdouble);
void (APIENTRYP pfglProgramParameter4dvNV) (GLenum, GLuint, const GLdouble *);
void (APIENTRYP pfglProgramParameter4fNV) (GLenum, GLuint, GLfloat, GLfloat, GLfloat, GLfloat);
void (APIENTRYP pfglProgramParameter4fvNV) (GLenum, GLuint, const GLfloat *);
void (APIENTRYP pfglProgramParameters4dvNV) (GLenum, GLuint, GLuint, const GLdouble *);
void (APIENTRYP pfglProgramParameters4fvNV) (GLenum, GLuint, GLuint, const GLfloat *);
void (APIENTRYP pfglRequestResidentProgramsNV) (GLsizei, const GLuint *);
void (APIENTRYP pfglTrackMatrixNV) (GLenum, GLuint, GLenum, GLenum);
void (APIENTRYP pfglVertexAttribPointerNV) (GLuint, GLint, GLenum, GLsizei, const GLvoid *);
void (APIENTRYP pfglVertexAttrib1dNV) (GLuint, GLdouble);
void (APIENTRYP pfglVertexAttrib1dvNV) (GLuint, const GLdouble *);
void (APIENTRYP pfglVertexAttrib1fNV) (GLuint, GLfloat);
void (APIENTRYP pfglVertexAttrib1fvNV) (GLuint, const GLfloat *);
void (APIENTRYP pfglVertexAttrib1sNV) (GLuint, GLshort);
void (APIENTRYP pfglVertexAttrib1svNV) (GLuint, const GLshort *);
void (APIENTRYP pfglVertexAttrib2dNV) (GLuint, GLdouble, GLdouble);
void (APIENTRYP pfglVertexAttrib2dvNV) (GLuint, const GLdouble *);
void (APIENTRYP pfglVertexAttrib2fNV) (GLuint, GLfloat, GLfloat);
void (APIENTRYP pfglVertexAttrib2fvNV) (GLuint, const GLfloat *);
void (APIENTRYP pfglVertexAttrib2sNV) (GLuint, GLshort, GLshort);
void (APIENTRYP pfglVertexAttrib2svNV) (GLuint, const GLshort *);
void (APIENTRYP pfglVertexAttrib3dNV) (GLuint, GLdouble, GLdouble, GLdouble);
void (APIENTRYP pfglVertexAttrib3dvNV) (GLuint, const GLdouble *);
void (APIENTRYP pfglVertexAttrib3fNV) (GLuint, GLfloat, GLfloat, GLfloat);
void (APIENTRYP pfglVertexAttrib3fvNV) (GLuint, const GLfloat *);
void (APIENTRYP pfglVertexAttrib3sNV) (GLuint, GLshort, GLshort, GLshort);
void (APIENTRYP pfglVertexAttrib3svNV) (GLuint, const GLshort *);
void (APIENTRYP pfglVertexAttrib4dNV) (GLuint, GLdouble, GLdouble, GLdouble, GLdouble);
void (APIENTRYP pfglVertexAttrib4dvNV) (GLuint, const GLdouble *);
void (APIENTRYP pfglVertexAttrib4fNV) (GLuint, GLfloat, GLfloat, GLfloat, GLfloat);
void (APIENTRYP pfglVertexAttrib4fvNV) (GLuint, const GLfloat *);
void (APIENTRYP pfglVertexAttrib4sNV) (GLuint, GLshort, GLshort, GLshort, GLshort);
void (APIENTRYP pfglVertexAttrib4svNV) (GLuint, const GLshort *);
void (APIENTRYP pfglVertexAttrib4ubNV) (GLuint, GLubyte, GLubyte, GLubyte, GLubyte);
void (APIENTRYP pfglVertexAttrib4ubvNV) (GLuint, const GLubyte *);
void (APIENTRYP pfglVertexAttribs1dvNV) (GLuint, GLsizei, const GLdouble *);
void (APIENTRYP pfglVertexAttribs1fvNV) (GLuint, GLsizei, const GLfloat *);
void (APIENTRYP pfglVertexAttribs1svNV) (GLuint, GLsizei, const GLshort *);
void (APIENTRYP pfglVertexAttribs2dvNV) (GLuint, GLsizei, const GLdouble *);
void (APIENTRYP pfglVertexAttribs2fvNV) (GLuint, GLsizei, const GLfloat *);
void (APIENTRYP pfglVertexAttribs2svNV) (GLuint, GLsizei, const GLshort *);
void (APIENTRYP pfglVertexAttribs3dvNV) (GLuint, GLsizei, const GLdouble *);
void (APIENTRYP pfglVertexAttribs3fvNV) (GLuint, GLsizei, const GLfloat *);
void (APIENTRYP pfglVertexAttribs3svNV) (GLuint, GLsizei, const GLshort *);
void (APIENTRYP pfglVertexAttribs4dvNV) (GLuint, GLsizei, const GLdouble *);
void (APIENTRYP pfglVertexAttribs4fvNV) (GLuint, GLsizei, const GLfloat *);
void (APIENTRYP pfglVertexAttribs4svNV) (GLuint, GLsizei, const GLshort *);
void (APIENTRYP pfglVertexAttribs4ubvNV) (GLuint, GLsizei, const GLubyte *);
//////////////////////////////////
//
// ATI Extensions
//
//////////////////////////////////
/*
------------------------------
ATI_EnvmapBumpmap
------------------------------
*/
void (APIENTRYP pfglTexBumpParameterivATI) (GLenum, const GLint *);
void (APIENTRYP pfglTexBumpParameterfvATI) (GLenum, const GLfloat *);
void (APIENTRYP pfglGetTexBumpParameterivATI) (GLenum, GLint *);
void (APIENTRYP pfglGetTexBumpParameterfvATI) (GLenum, GLfloat *);
/*
------------------------------
ATI_FragmentShader
------------------------------
*/
GLuint (APIENTRYP pfglGenFragmentShadersATI) (GLuint);
void (APIENTRYP pfglBindFragmentShaderATI) (GLuint);
void (APIENTRYP pfglDeleteFragmentShaderATI) (GLuint);
void (APIENTRYP pfglBeginFragmentShaderATI) (void);
void (APIENTRYP pfglEndFragmentShaderATI) (void);
void (APIENTRYP pfglPassTexCoordATI) (GLuint, GLuint, GLenum);
void (APIENTRYP pfglSampleMapATI) (GLuint, GLuint, GLenum);
void (APIENTRYP pfglColorFragmentOp1ATI) (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint);
void (APIENTRYP pfglColorFragmentOp2ATI) (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint);
void (APIENTRYP pfglColorFragmentOp3ATI) (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint);
void (APIENTRYP pfglAlphaFragmentOp1ATI) (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint);
void (APIENTRYP pfglAlphaFragmentOp2ATI) (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint);
void (APIENTRYP pfglAlphaFragmentOp3ATI) (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint);
void (APIENTRYP pfglSetFragmentShaderConstantATI) (GLuint, const GLfloat *);
/*
------------------------------
ATI_VertexArrayObject
------------------------------
*/
GLuint (APIENTRYP pfglNewObjectBufferATI) (GLsizei, const GLvoid *, GLenum);
GLboolean (APIENTRYP pfglIsObjectBufferATI) (GLuint);
void (APIENTRYP pfglUpdateObjectBufferATI) (GLuint, GLuint, GLsizei, const GLvoid *, GLenum);
void (APIENTRYP pfglGetObjectBufferfvATI) (GLuint, GLenum, GLfloat *);
void (APIENTRYP pfglGetObjectBufferivATI) (GLuint, GLenum, GLint *);
void (APIENTRYP pfglFreeObjectBufferATI) (GLuint);
void (APIENTRYP pfglArrayObjectATI) (GLenum, GLint, GLenum, GLsizei, GLuint, GLuint);
void (APIENTRYP pfglGetArrayObjectfvATI) (GLenum, GLenum, GLfloat *);
void (APIENTRYP pfglGetArrayObjectivATI) (GLenum, GLenum, GLint *);
void (APIENTRYP pfglVariantArrayObjectATI) (GLuint, GLenum, GLsizei, GLuint, GLuint);
void (APIENTRYP pfglGetVariantArrayObjectfvATI) (GLuint, GLenum, GLfloat *);
void (APIENTRYP pfglGetVariantArrayObjectivATI) (GLuint, GLenum, GLint *);
/*
------------------------------
ATI_MapObjectBuffer
------------------------------
*/
GLvoid* (APIENTRYP pfglMapObjectBufferATI) (GLuint);
void (APIENTRYP pfglUnmapObjectBufferATI) (GLuint);
#endif /* __MYOPENGL_EXTENSION_H__ */

48
wolf3d/code/env/num_type.h vendored Normal file
View File

@@ -0,0 +1,48 @@
/*
Copyright (C) 2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
num_type.h: System dependant float/double to integer conversions.
*/
#ifndef __NUM_TYPE_H__
#define __NUM_TYPE_H__
#include "arch.h"
#define BIT( x ) ( 1 << (x) )
#define FloatToInt( a ) (SW32)(a)
#define DoubleToInt( a ) (SW32)(a)
#endif /* __NUM_TYPE_H__ */

154
wolf3d/code/env/oggfile.c vendored Normal file
View File

@@ -0,0 +1,154 @@
/*
Copyright (C) 2009 Id Software, Inc.
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../wolfiphone.h"
filehandle_t *fh;
PRIVATE size_t ovc_read( void *ptr, size_t size, size_t nmemb, void *dataSource )
{
if( ! size || ! nmemb )
{
return 0;
}
return FS_ReadFile( ptr, size, nmemb, fh );
}
PRIVATE int ovc_seek( void *dataSource, ogg_int64_t offset, int whence )
{
return FS_FileSeek( fh, offset, whence );
}
PRIVATE int ovc_close( void *dataSource )
{
return 0;
}
PRIVATE long ovc_tell( void *dataSource )
{
return FS_FileTell( fh );
}
/*
-----------------------------------------------------------------------------
Function: LoadOggInfo -Load ogg file.
Parameters: filename -[in] Name of wav file to load.
wav -[out] wav data.
info -[out] wav sound info.
Returns: True if file loaded, otherwise false.
Notes: Caller is responsible for freeing wav data by calling Z_Free.
-----------------------------------------------------------------------------
*/
PUBLIC _boolean LoadOggInfo( const char *filename, W8 **wav, soundInfo_t *info )
{
W8 *data;
int size;
int dummy;
char *newFilename;
int len;
OggVorbis_File vorbisFile;
vorbis_info vorbisInfo;
ov_callbacks vorbisCallbacks = {ovc_read, ovc_seek, ovc_close, ovc_tell};
int ret;
newFilename = strdup( filename );
len = strlen( newFilename );
if ( len < 5 || strcmp( newFilename + len - 4, ".wav" ) ) {
free( newFilename );
return false;
}
newFilename[ len - 3 ] = 'o';
newFilename[ len - 2 ] = 'g';
newFilename[ len - 1 ] = 'g';
fh = FS_OpenFile( newFilename, 0 );
if( ! fh )
{
free( newFilename );
return false;
}
if( (ret = ov_open_callbacks( fh, &vorbisFile, NULL, 0, vorbisCallbacks )) < 0 ) {
free( newFilename );
return false;
}
vorbisInfo = *ov_info( &vorbisFile, -1 );
if( vorbisInfo.channels != 1 && vorbisInfo.channels != 2 )
{
Com_Printf( "Only mono and stereo OGG files supported (%s)\n", newFilename );
free( newFilename );
return false;
}
info->channels = vorbisInfo.channels;
info->sample_rate = vorbisInfo.rate;
info->sample_size = 2;
#define BUFFER_SIZE ( 128 * 1024 )
data = (W8 *)malloc( BUFFER_SIZE );
size = 0;
while( size < BUFFER_SIZE )
{
int read = 0;
read = ov_read( &vorbisFile, (char *)data + size, BUFFER_SIZE - size, &dummy );
if( read == 0 )
{
break;
}
if( read <= 0 )
{
Com_Printf( "Only mono and stereo OGG files supported (%s)\n", newFilename );
free( newFilename );
return false;
}
size += read;
}
info->samples = size / ( info->channels * info->sample_size );
// Com_Printf("Loaded %s: channels=%d, sample_rate=%d, sample_size=%d, samples=%d. \n", newFilename, info->channels, info->sample_rate, info->sample_size, info->samples );
free( newFilename );
*wav = (W8 *)Z_Malloc( size );
memcpy(*wav, data, size );
free( data );
FS_CloseFile( fh );
return true;
}

29
wolf3d/code/env/oggfile.h vendored Normal file
View File

@@ -0,0 +1,29 @@
/*
Copyright (C) 2009 Id Software, Inc.
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __LOADERS_OGGFILE_H__
#define __LOADERS_OGGFILE_H__
extern _boolean LoadOggInfo( const char *filename, W8 **wav, soundInfo_t *info );
#endif /* __LOADERS_OGGFILE_H__ */

335
wolf3d/code/env/openal_binding.c vendored Normal file
View File

@@ -0,0 +1,335 @@
/*
Copyright (C) 2004 Michael Liebscher
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* openal_binding.c: Interface to OpenAL library.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
*/
#include "../wolfiphone.h"
#ifdef _WIN32
HINSTANCE hinstOpenAL;
#elif __unix__
void *OpenALLib;
#elif IPHONE
void *OpenALLib;
// from here on in this file, behave like unix
#define __unix__ 1
#else
#error "Please define interface to OpenAL library!"
#endif
/*
-----------------------------------------------------------------------------
Function: OpenAL_Shutdown -Shutdown interface to OpenAL.
Parameters: Nothing.
Returns: Nothing.
Notes:
Unloads the specified Dynamic Link Library then NULLs out all the
proc pointers.
-----------------------------------------------------------------------------
*/
PUBLIC void OpenAL_Shutdown( void )
{
#ifdef _WIN32
if( hinstOpenAL )
{
FreeLibrary( hinstOpenAL );
hinstOpenAL = NULL;
}
hinstOpenAL = NULL;
#elif __unix__
if( OpenALLib )
{
dlclose( OpenALLib );
OpenALLib = NULL;
}
OpenALLib = NULL;
#else
#error "Please define interface to OpenAL library!"
#endif
pfalcCloseDevice = NULL;
pfalcCreateContext = NULL;
pfalcDestroyContext = NULL;
pfalcGetContextsDevice = NULL;
pfalcGetCurrentContext = NULL;
pfalcGetEnumValue = NULL;
pfalcGetError = NULL;
pfalcGetIntegerv = NULL;
pfalcGetProcAddress = NULL;
pfalcGetString = NULL;
pfalcIsExtensionPresent = NULL;
pfalcMakeContextCurrent = NULL;
pfalcOpenDevice = NULL;
pfalcProcessContext = NULL;
pfalcSuspendContext = NULL;
pfalGenBuffers = NULL;
pfalDeleteBuffers = NULL;
pfalIsBuffer = NULL;
pfalBufferData = NULL;
pfalGetBufferf = NULL;
pfalGetBufferi = NULL;
pfalEnable = NULL;
pfalDisable = NULL;
pfalDopplerFactor = NULL;
pfalDopplerVelocity = NULL;
pfalDistanceModel = NULL;
pfalGetBoolean = NULL;
pfalGetBooleanv = NULL;
pfalGetDouble = NULL;
pfalGetDoublev = NULL;
pfalGetFloat = NULL;
pfalGetFloatv = NULL;
pfalGetInteger = NULL;
pfalGetIntegerv = NULL;
pfalGetEnumValue = NULL;
pfalGetError = NULL;
pfalGetProcAddress = NULL;
pfalGetString = NULL;
pfalIsExtensionPresent = NULL;
pfalIsEnabled = NULL;
pfalListenerf = NULL;
pfalListener3f = NULL;
pfalListenerfv = NULL;
pfalListeneri = NULL;
pfalGetListenerf = NULL;
pfalGetListener3f = NULL;
pfalGetListenerfv = NULL;
pfalGetListeneri = NULL;
pfalGenSources = NULL;
pfalDeleteSources = NULL;
pfalIsSource = NULL;
pfalSourcef = NULL;
pfalSourcefv = NULL;
pfalSource3f = NULL;
pfalSourcei = NULL;
pfalGetSourcef = NULL;
pfalGetSource3f = NULL;
pfalGetSourcefv = NULL;
pfalGetSourcei = NULL;
pfalSourcePlay = NULL;
pfalSourcePlayv = NULL;
pfalSourcePause = NULL;
pfalSourcePausev = NULL;
pfalSourceStop = NULL;
pfalSourceStopv = NULL;
pfalSourceRewind = NULL;
pfalSourceRewindv = NULL;
pfalSourceQueueBuffers = NULL;
pfalSourceUnqueueBuffers = NULL;
}
#ifdef _WIN32
#define GPA( a ) GetProcAddress( hinstOpenAL, a )
#elif __unix__
#define GPA( a ) dlsym( OpenALLib, a )
#else
#error "Please define interface to OpenAL library!"
#endif
/*
-----------------------------------------------------------------------------
Function: OpenAL_Init -Setup interface to OpenAL.
Parameters: dllname -[in] Name of the OpenAL dynamic link library.
Returns: true on success, otherwise false.
Notes:
This is responsible for binding our al function pointers to
the appropriate OpenAL stuff. In Windows this means doing a
LoadLibrary and a bunch of calls to GetProcAddress. On other
operating systems we need to do the right thing, whatever that
might be.
-----------------------------------------------------------------------------
*/
PUBLIC _boolean OpenAL_Init( const char *dllname )
{
#ifdef _WIN32
char buffer[ 1024 ], *ptr;
SearchPath( NULL, dllname, NULL, sizeof( buffer ) - 1, buffer, &ptr );
Com_Printf( "...calling LoadLibrary( %s ): ", buffer );
if( ( hinstOpenAL = LoadLibrary( dllname ) ) == 0 )
{
char *buf = NULL;
Com_Printf( "failed\n" );
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(),
MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
(LPTSTR) &buf, 0, NULL );
Com_Printf( "%s\n", buf );
return false;
}
#elif __unix__
Com_Printf( "...calling dlopen( %s ): ", dllname );
if( ( OpenALLib = dlopen( dllname, RTLD_LAZY | RTLD_GLOBAL ) ) == 0 )
{
Com_Printf( "failed\n" );
Com_Printf( "%s\n", dlerror() );
return false;
}
#else
#error "Please define interface to OpenAL library!"
#endif
Com_Printf( "succeeded\n" );
if( ! (pfalcCloseDevice = (ALCCLOSEDEVICE)GPA( "alcCloseDevice" )) ) return false;
if( ! (pfalcCreateContext = (ALCCREATECONTEXT)GPA( "alcCreateContext" )) ) return false;
if( ! (pfalcDestroyContext = (ALCDESTROYCONTEXT)GPA( "alcDestroyContext" )) ) return false;
if( ! (pfalcGetContextsDevice = (ALCGETCONTEXTSDEVICE)GPA( "alcGetContextsDevice" )) ) return false;
if( ! (pfalcGetCurrentContext = (ALCGETCURRENTCONTEXT)GPA( "alcGetCurrentContext" )) ) return false;
if( ! (pfalcGetEnumValue = (ALCGETENUMVALUE)GPA( "alcGetEnumValue" )) ) return false;
if( ! (pfalcGetError = (ALCGETERROR)GPA( "alcGetError" )) ) return false;
if( ! (pfalcGetIntegerv = (ALCGETINTEGERV)GPA( "alcGetIntegerv" )) ) return false;
if( ! (pfalcGetProcAddress = (ALCGETPROCADDRESS)GPA( "alcGetProcAddress" )) ) return false;
if( ! (pfalcGetString = (ALCGETSTRING)GPA( "alcGetString" )) ) return false;
if( ! (pfalcIsExtensionPresent = (ALCISEXTENSIONPRESENT)GPA( "alcIsExtensionPresent" )) ) return false;
if( ! (pfalcMakeContextCurrent = (ALCMAKECONTEXTCURRENT)GPA( "alcMakeContextCurrent" )) ) return false;
if( ! (pfalcOpenDevice = (ALCOPENDEVICE)GPA( "alcOpenDevice" )) ) return false;
if( ! (pfalcProcessContext = (ALCPROCESSCONTEXT)GPA( "alcProcessContext" )) ) return false;
if( ! (pfalcSuspendContext = (ALCSUSPENDCONTEXT)GPA( "alcSuspendContext" )) ) return false;
if( ! (pfalGenBuffers = (ALGENBUFFERS)GPA("alGenBuffers")) ) return false;
if( ! (pfalDeleteBuffers = (ALDELETEBUFFERS)GPA("alDeleteBuffers")) ) return false;
if( ! (pfalIsBuffer = (ALISBUFFER)GPA("alIsBuffer")) ) return false;
if( ! (pfalBufferData = (ALBUFFERDATA)GPA("alBufferData")) ) return false;
if( ! (pfalGetBufferf = (ALGETBUFFERF)GPA("alGetBufferf")) ) return false;
if( ! (pfalGetBufferi = (ALGETBUFFERI)GPA("alGetBufferi")) ) return false;
if( ! (pfalEnable = (ALENABLE)GPA("alEnable")) ) return false;
if( ! (pfalDisable = (ALDISABLE)GPA("alDisable")) ) return false;
if( ! (pfalDopplerFactor = (ALDOPPLERFACTOR)GPA("alDopplerFactor")) ) return false;
if( ! (pfalDopplerVelocity = (ALDOPPLERVELOCITY)GPA("alDopplerVelocity")) ) return false;
if( ! (pfalDistanceModel = (ALDISTANCEMODEL)GPA("alDistanceModel")) ) return false;
if( ! (pfalGetBoolean = (ALGETBOOLEAN)GPA("alGetBoolean")) ) return false;
if( ! (pfalGetBooleanv = (ALGETBOOLEANV)GPA("alGetBooleanv")) ) return false;
if( ! (pfalGetDouble = (ALGETDOUBLE)GPA("alGetDouble")) ) return false;
if( ! (pfalGetDoublev = (ALGETDOUBLEV)GPA("alGetDoublev")) ) return false;
if( ! (pfalGetFloat = (ALGETFLOAT)GPA("alGetFloat")) ) return false;
if( ! (pfalGetFloatv = (ALGETFLOATV)GPA("alGetFloatv")) ) return false;
if( ! (pfalGetInteger = (ALGETINTEGER)GPA("alGetInteger")) ) return false;
if( ! (pfalGetIntegerv = (ALGETINTEGERV)GPA("alGetIntegerv")) ) return false;
if( ! (pfalGetEnumValue = (ALGETENUMVALUE)GPA("alGetEnumValue")) ) return false;
if( ! (pfalGetError = (ALGETERROR)GPA("alGetError")) ) return false;
if( ! (pfalGetProcAddress = (ALGETPROCADDRESS)GPA("alGetProcAddress")) ) return false;
if( ! (pfalGetString = (ALGETSTRING)GPA("alGetString")) ) return false;
if( ! (pfalIsExtensionPresent = (ALISEXTENSIONPRESENT)GPA("alIsExtensionPresent")) ) return false;
if( ! (pfalIsEnabled = (ALISENABLED)GPA("alIsEnabled")) ) return false;
if( ! (pfalListenerf = (ALLISTENERF)GPA("alListenerf")) ) return false;
if( ! (pfalListener3f = (ALLISTENER3F)GPA("alListener3f")) ) return false;
if( ! (pfalListenerfv = (ALLISTENERFV)GPA("alListenerfv")) ) return false;
if( ! (pfalListeneri = (ALLISTENERI)GPA("alListeneri")) ) return false;
if( ! (pfalGetListenerf = (ALGETLISTENERF)GPA("alGetListenerf")) ) return false;
if( ! (pfalGetListener3f = (ALGETLISTENER3F)GPA("alGetListener3f")) ) return false;
if( ! (pfalGetListenerfv = (ALGETLISTENERFV)GPA("alGetListenerfv")) ) return false;
if( ! (pfalGetListeneri = (ALGETLISTENERI)GPA("alGetListeneri")) ) return false;
if( ! (pfalGenSources = (ALGENSOURCES)GPA("alGenSources")) ) return false;
if( ! (pfalDeleteSources = (ALDELETESOURCES)GPA("alDeleteSources")) ) return false;
if( ! (pfalIsSource = (ALISSOURCE)GPA("alIsSource")) ) return false;
if( ! (pfalSourcef = (ALSOURCEF)GPA("alSourcef")) ) return false;
if( ! (pfalSourcefv = (ALSOURCEFV)GPA("alSourcefv")) ) return false;
if( ! (pfalSource3f = (ALSOURCE3F)GPA("alSource3f")) ) return false;
if( ! (pfalSourcei = (ALSOURCEI)GPA("alSourcei")) ) return false;
if( ! (pfalGetSourcef = (ALGETSOURCEF)GPA("alGetSourcef")) ) return false;
if( ! (pfalGetSource3f = (ALGETSOURCE3F)GPA("alGetSource3f")) ) return false;
if( ! (pfalGetSourcefv = (ALGETSOURCEFV)GPA("alGetSourcefv")) ) return false;
if( ! (pfalGetSourcei = (ALGETSOURCEI)GPA("alGetSourcei")) ) return false;
if( ! (pfalSourcePlay = (ALSOURCEPLAY)GPA("alSourcePlay")) ) return false;
if( ! (pfalSourcePlayv = (ALSOURCEPLAYV)GPA("alSourcePlayv")) ) return false;
if( ! (pfalSourcePause = (ALSOURCEPAUSE)GPA("alSourcePause")) ) return false;
if( ! (pfalSourcePausev = (ALSOURCEPAUSEV)GPA("alSourcePausev")) ) return false;
if( ! (pfalSourceStop = (ALSOURCESTOP)GPA("alSourceStop")) ) return false;
if( ! (pfalSourceStopv = (ALSOURCESTOPV)GPA("alSourceStopv")) ) return false;
if( ! (pfalSourceRewind = (ALSOURCEREWIND)GPA("alSourceRewind")) ) return false;
if( ! (pfalSourceRewindv = (ALSOURCEREWINDV)GPA("alSourceRewindv")) ) return false;
if( ! (pfalSourceQueueBuffers = (ALSOURCEQUEUEBUFFERS)GPA("alSourceQueueBuffers")) ) return false;
if( ! (pfalSourceUnqueueBuffers = (ALSOURCEUNQUEUEBUFFERS)GPA("alSourceUnqueueBuffers")) ) return false;
return true;
}

186
wolf3d/code/env/openal_binding.h vendored Normal file
View File

@@ -0,0 +1,186 @@
/*
Copyright (C) 2004 Michael Liebscher
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* openal_binding.h: Interface to OpenAL library.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
*/
#ifndef __OPENAL_BINDING_H__
#define __OPENAL_BINDING_H__
extern _boolean OpenAL_Init( const char *dllname );
extern void OpenAL_Shutdown( void );
typedef ALCAPI ALCvoid ( * ALCCLOSEDEVICE)(ALCdevice *pDevice);
typedef ALCAPI ALCcontext*( * ALCCREATECONTEXT)(ALCdevice *device, const ALCint *attrList);
typedef ALCAPI ALCvoid ( * ALCDESTROYCONTEXT)(ALCcontext *context);
typedef ALCAPI ALCdevice* ( * ALCGETCONTEXTSDEVICE)(ALCcontext *pContext);
typedef ALCAPI ALCcontext * ( * ALCGETCURRENTCONTEXT)(ALCvoid);
typedef ALCAPI ALCenum ( * ALCGETENUMVALUE)(ALCdevice *device, const ALCubyte *enumName);
typedef ALCAPI ALCenum ( * ALCGETERROR)(ALCdevice *device);
typedef ALCAPI ALCvoid ( * ALCGETINTEGERV)(ALCdevice *device,ALCenum param,ALsizei size,ALCint *data);
typedef ALCAPI ALCvoid * ( * ALCGETPROCADDRESS)(ALCdevice *device, const ALCubyte *funcName);
typedef ALCAPI const ALCubyte* ( * ALCGETSTRING)(ALCdevice *device,ALCenum param);
typedef ALCAPI ALCboolean ( * ALCISEXTENSIONPRESENT)(ALCdevice *device, const ALCubyte *extName);
typedef ALCAPI ALCboolean ( * ALCMAKECONTEXTCURRENT)(ALCcontext *context);
typedef ALCAPI ALCdevice* ( * ALCOPENDEVICE)(const ALCubyte *deviceName);
typedef ALCAPI ALCvoid ( * ALCPROCESSCONTEXT)(ALCcontext *pContext);
typedef ALCAPI ALCvoid ( * ALCSUSPENDCONTEXT)(ALCcontext *pContext);
typedef ALCAPI ALvoid ( * ALGENBUFFERS)(ALsizei n, ALuint* bufferNames);
typedef ALCAPI ALvoid ( * ALDELETEBUFFERS)(ALsizei n, const ALuint* bufferNames);
typedef ALCAPI ALboolean ( * ALISBUFFER)(ALuint bufferName);
typedef ALCAPI ALvoid ( * ALBUFFERDATA)(ALuint bufferName, ALenum format, const ALvoid* data, ALsizei size, ALsizei freq);
typedef ALCAPI ALvoid ( * ALGETBUFFERF)(ALuint bufferName, ALenum param, ALfloat* value);
typedef ALCAPI ALvoid ( * ALGETBUFFERI)(ALuint bufferName, ALenum param, ALint* value);
typedef ALCAPI ALvoid ( * ALENABLE)(ALenum capability);
typedef ALCAPI ALvoid ( * ALDISABLE)(ALenum capability);
typedef ALCAPI ALvoid ( * ALDOPPLERFACTOR)(ALfloat value);
typedef ALCAPI ALvoid ( * ALDOPPLERVELOCITY)(ALfloat value);
typedef ALCAPI ALvoid ( * ALDISTANCEMODEL)(ALenum value);
typedef ALCAPI ALboolean ( * ALGETBOOLEAN)(ALenum param);
typedef ALCAPI ALvoid ( * ALGETBOOLEANV)(ALenum param, ALboolean* data);
typedef ALCAPI ALdouble ( * ALGETDOUBLE)(ALenum param);
typedef ALCAPI ALvoid ( * ALGETDOUBLEV)(ALenum param, ALdouble* data);
typedef ALCAPI ALfloat ( * ALGETFLOAT)(ALenum param);
typedef ALCAPI ALvoid ( * ALGETFLOATV)(ALenum param, ALfloat* data);
typedef ALCAPI ALint ( * ALGETINTEGER)(ALenum param);
typedef ALCAPI ALvoid ( * ALGETINTEGERV)(ALenum param, ALint* data);
typedef ALCAPI ALenum ( * ALGETENUMVALUE)(const ALubyte* ename);
typedef ALCAPI ALenum ( * ALGETERROR)(ALvoid);
typedef ALCAPI ALvoid* ( * ALGETPROCADDRESS)(const ALubyte* fname);
typedef ALCAPI const ALubyte* ( * ALGETSTRING)(ALenum param);
typedef ALCAPI ALboolean ( * ALISEXTENSIONPRESENT)(const ALubyte* ename);
typedef ALCAPI ALboolean ( * ALISENABLED)(ALenum capability);
typedef ALCAPI ALvoid ( * ALLISTENERF)(ALenum param, ALfloat value);
typedef ALCAPI ALvoid ( * ALLISTENER3F)(ALenum param, ALfloat v1, ALfloat v2, ALfloat v3);
typedef ALCAPI ALvoid ( * ALLISTENERFV)(ALenum param, const ALfloat* values);
typedef ALCAPI ALvoid ( * ALLISTENERI)(ALenum param, ALint value);
typedef ALCAPI ALvoid ( * ALGETLISTENERF)(ALenum param, ALfloat* value);
typedef ALCAPI ALvoid ( * ALGETLISTENER3F)(ALenum param, ALfloat* v1, ALfloat* v2, ALfloat* v3);
typedef ALCAPI ALvoid ( * ALGETLISTENERFV)(ALenum param, ALfloat* values);
typedef ALCAPI ALvoid ( * ALGETLISTENERI)(ALenum param, ALint* value);
typedef ALCAPI ALvoid ( * ALGENSOURCES)(ALsizei n, ALuint* sourceNames);
typedef ALCAPI ALvoid ( * ALDELETESOURCES)(ALsizei n, const ALuint* sourceNames);
typedef ALCAPI ALboolean ( * ALISSOURCE)(ALuint sourceName);
typedef ALCAPI ALvoid ( * ALSOURCEF)(ALuint sourceName, ALenum param, ALfloat value);
typedef ALCAPI ALvoid ( * ALSOURCEFV)(ALuint sourceName, ALenum param, const ALfloat* values);
typedef ALCAPI ALvoid ( * ALSOURCE3F)(ALuint sourceName, ALenum param, ALfloat v1, ALfloat v2, ALfloat v3);
typedef ALCAPI ALvoid ( * ALSOURCEI)(ALuint sourceName, ALenum param, ALint value);
typedef ALCAPI ALvoid ( * ALGETSOURCEF)(ALuint sourceName, ALenum param, ALfloat* value);
typedef ALCAPI ALvoid ( * ALGETSOURCE3F)(ALuint sourceName, ALenum param, ALfloat* v1, ALfloat* v2, ALfloat* v3);
typedef ALCAPI ALvoid ( * ALGETSOURCEFV)(ALuint sourceName, ALenum param, ALfloat* values);
typedef ALCAPI ALvoid ( * ALGETSOURCEI)(ALuint sourceName, ALenum param, ALint* value);
typedef ALCAPI ALvoid ( * ALSOURCEPLAY)(ALuint sourceName);
typedef ALCAPI ALvoid ( * ALSOURCEPLAYV)(ALsizei n, const ALuint* sourceNames);
typedef ALCAPI ALvoid ( * ALSOURCEPAUSE)(ALuint sourceName);
typedef ALCAPI ALvoid ( * ALSOURCEPAUSEV)(ALsizei n, const ALuint* sourceNames);
typedef ALCAPI ALvoid ( * ALSOURCESTOP)(ALuint sourceName);
typedef ALCAPI ALvoid ( * ALSOURCESTOPV)(ALsizei n, const ALuint* sourceNames);
typedef ALCAPI ALvoid ( * ALSOURCEREWIND)(ALuint sourceName);
typedef ALCAPI ALvoid ( * ALSOURCEREWINDV)(ALsizei n, const ALuint* sourceNames);
typedef ALCAPI ALvoid ( * ALSOURCEQUEUEBUFFERS)(ALuint sourceName, ALsizei n, const ALuint* buffers);
typedef ALCAPI ALvoid ( * ALSOURCEUNQUEUEBUFFERS)(ALuint sourceName, ALsizei n, ALuint* buffers);
ALCCLOSEDEVICE pfalcCloseDevice;
ALCCREATECONTEXT pfalcCreateContext;
ALCDESTROYCONTEXT pfalcDestroyContext;
ALCGETCONTEXTSDEVICE pfalcGetContextsDevice;
ALCGETCURRENTCONTEXT pfalcGetCurrentContext;
ALCGETENUMVALUE pfalcGetEnumValue;
ALCGETERROR pfalcGetError;
ALCGETINTEGERV pfalcGetIntegerv;
ALCGETPROCADDRESS pfalcGetProcAddress;
ALCGETSTRING pfalcGetString;
ALCISEXTENSIONPRESENT pfalcIsExtensionPresent;
ALCMAKECONTEXTCURRENT pfalcMakeContextCurrent;
ALCOPENDEVICE pfalcOpenDevice;
ALCPROCESSCONTEXT pfalcProcessContext;
ALCSUSPENDCONTEXT pfalcSuspendContext;
ALGENBUFFERS pfalGenBuffers;
ALDELETEBUFFERS pfalDeleteBuffers;
ALISBUFFER pfalIsBuffer;
ALBUFFERDATA pfalBufferData;
ALGETBUFFERF pfalGetBufferf;
ALGETBUFFERI pfalGetBufferi;
ALENABLE pfalEnable;
ALDISABLE pfalDisable;
ALDOPPLERFACTOR pfalDopplerFactor;
ALDOPPLERVELOCITY pfalDopplerVelocity;
ALDISTANCEMODEL pfalDistanceModel;
ALGETBOOLEAN pfalGetBoolean;
ALGETBOOLEANV pfalGetBooleanv;
ALGETDOUBLE pfalGetDouble;
ALGETDOUBLEV pfalGetDoublev;
ALGETFLOAT pfalGetFloat;
ALGETFLOATV pfalGetFloatv;
ALGETINTEGER pfalGetInteger;
ALGETINTEGERV pfalGetIntegerv;
ALGETENUMVALUE pfalGetEnumValue;
ALGETERROR pfalGetError;
ALGETPROCADDRESS pfalGetProcAddress;
ALGETSTRING pfalGetString;
ALISEXTENSIONPRESENT pfalIsExtensionPresent;
ALISENABLED pfalIsEnabled;
ALLISTENERF pfalListenerf;
ALLISTENER3F pfalListener3f;
ALLISTENERFV pfalListenerfv;
ALLISTENERI pfalListeneri;
ALGETLISTENERF pfalGetListenerf;
ALGETLISTENER3F pfalGetListener3f;
ALGETLISTENERFV pfalGetListenerfv;
ALGETLISTENERI pfalGetListeneri;
ALGENSOURCES pfalGenSources;
ALDELETESOURCES pfalDeleteSources;
ALISSOURCE pfalIsSource;
ALSOURCEF pfalSourcef;
ALSOURCEFV pfalSourcefv;
ALSOURCE3F pfalSource3f;
ALSOURCEI pfalSourcei;
ALGETSOURCEF pfalGetSourcef;
ALGETSOURCE3F pfalGetSource3f;
ALGETSOURCEFV pfalGetSourcefv;
ALGETSOURCEI pfalGetSourcei;
ALSOURCEPLAY pfalSourcePlay;
ALSOURCEPLAYV pfalSourcePlayv;
ALSOURCEPAUSE pfalSourcePause;
ALSOURCEPAUSEV pfalSourcePausev;
ALSOURCESTOP pfalSourceStop;
ALSOURCESTOPV pfalSourceStopv;
ALSOURCEREWIND pfalSourceRewind;
ALSOURCEREWINDV pfalSourceRewindv;
ALSOURCEQUEUEBUFFERS pfalSourceQueueBuffers;
ALSOURCEUNQUEUEBUFFERS pfalSourceUnqueueBuffers;
#endif /* __OPENAL_BINDING_H__ */

247
wolf3d/code/env/openal_main.c vendored Normal file
View File

@@ -0,0 +1,247 @@
/*
Copyright (C) 2004 Michael Liebscher
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* openal_main.c: Interface to Sound Device.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
*/
#include "../wolfiphone.h"
#ifdef _WIN32
#define OPENAL_DLL_NAME "openal32.dll"
#elif __unix__
#define OPENAL_DLL_NAME "libopenal.so"
#elif IPHONE
#define OPENAL_DLL_NAME "/System/Library/Frameworks/OpenAL.framework/OpenAL"
#else
#error "Please define OPENAL_DLL_NAME"
#endif
PRIVATE ALCcontext *Context;
PRIVATE ALCdevice *Device;
cvar_t *s_driver;
cvar_t *s_device;
char *deviceList;
char *sound_devices[ 12 ];
W16 numSoundDevices, numDefaultSoundDevice;
/*
-----------------------------------------------------------------------------
Function: Sound_Device_getDeviceList -Get OpenAL device list.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void Sound_Device_getDeviceList( void )
{
char deviceName[ 256 ];
my_strlcpy( deviceName, s_device->string, sizeof( deviceName ) );
if( pfalcIsExtensionPresent( NULL, (ALubyte*)"ALC_ENUMERATION_EXT") == AL_TRUE )
{
// try out enumeration extension
deviceList = (char *)pfalcGetString( NULL, ALC_DEVICE_SPECIFIER );
for( numSoundDevices = 0 ; numSoundDevices < 12 ; ++numSoundDevices )
{
sound_devices[ numSoundDevices ] = NULL;
}
for( numSoundDevices = 0 ; numSoundDevices < 12 ; ++numSoundDevices )
{
sound_devices[ numSoundDevices ] = deviceList;
if( strcmp( sound_devices[ numSoundDevices ], deviceName ) == 0 )
{
numDefaultSoundDevice = numSoundDevices;
}
deviceList += strlen( deviceList );
if( deviceList[ 0 ] == 0 )
{
if( deviceList[ 1 ] == 0 )
{
break;
}
else
{
deviceList += 1;
}
}
} // End for numSoundDevices = 0 ; numSoundDevices < 12 ; ++numSoundDevices
}
}
/*
-----------------------------------------------------------------------------
Function: Sound_Device_Register -Register OpenAL cvars.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void Sound_Device_Register( void )
{
s_driver = Cvar_Get( "s_driver", OPENAL_DLL_NAME, CVAR_ARCHIVE );
s_device = Cvar_Get( "s_device", "", CVAR_LATCH | CVAR_ARCHIVE );
}
/*
-----------------------------------------------------------------------------
Function: Sound_Device_Setup -Setup OpenAL sound device.
Parameters: Nothing.
Returns: true on success, otherwise false.
Notes: Call Sound_Device_Shutdown() when you are done.
-----------------------------------------------------------------------------
*/
PUBLIC _boolean Sound_Device_Setup( void )
{
Com_Printf( "...Initializing AudioSession\n" );
SysIPhoneInitAudioSession();
Com_Printf( "...Initializing OpenAL subsystem\n" );
Sound_Device_Register();
// Initialize our OpenAL dynamic bindings
if( ! OpenAL_Init( s_driver->string ) )
{
Com_Printf( "[%s]: Dynamic binding of (%s) failed\n", "openal_main.c", s_driver->string );
goto failed;
}
Sound_Device_getDeviceList();
Device = pfalcOpenDevice( (ALCubyte *)( (s_device->string[ 0 ]) ? s_device->string : NULL ) );
if( Device == NULL )
{
Com_Printf( "Failed to Initialize OpenAL\n" );
goto failed;
}
// Create context(s)
Context = pfalcCreateContext( Device, NULL );
if( Context == NULL )
{
Com_Printf( "Failed to initialize OpenAL\n" );
goto failed;
}
// Set active context
pfalcGetError( Device );
pfalcMakeContextCurrent( Context );
if( pfalcGetError( Device ) != ALC_NO_ERROR )
{
Com_Printf( "Failed to Make Context Current\n" );
goto failed;
}
return true;
failed:
if( Context )
{
pfalcDestroyContext( Context );
Context = NULL;
}
if( Device )
{
pfalcCloseDevice( Device );
Device = NULL;
}
OpenAL_Shutdown();
return false;
}
/*
-----------------------------------------------------------------------------
Function: Sound_Device_Shutdown -Shutdown OpenAL sound device.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Sound_Device_Shutdown( void )
{
if( Context )
{
pfalcMakeContextCurrent( NULL );
pfalcDestroyContext( Context );
Context = NULL;
}
if( Device )
{
pfalcCloseDevice( Device );
Device = NULL;
}
OpenAL_Shutdown();
}

256
wolf3d/code/env/opengl_draw.c vendored Normal file
View File

@@ -0,0 +1,256 @@
/*
Copyright (C) 2004-2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* opengl_draw.c: OpenGL drawing routines.
*
* Author: Michael Liebscher
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#include "../wolfiphone.h"
texture_t *draw_chars;
//extern _boolean scrap_dirty;
//void Scrap_Upload (void);
/*
-----------------------------------------------------------------------------
Function: R_Draw_Char -Draw ASCII character to the screen.
Parameters: x -[in] x-coordinate.
y -[in] y-coordinate.
num -[in] ASCII character value.
myfont -[in] Valid pointer to font_t structure.
Returns: Nothing.
Notes:
It can be clipped to the top of the screen to allow the console to be
smoothly scrolled off.
-----------------------------------------------------------------------------
*/
PUBLIC void R_Draw_Character( int x, int y, int num, font_t *myfont )
{
int row, col;
int scale, sh; // scaled width, height
float frow, fcol;
num &= 255;
if( (num & 127) == 32 )
{
return; // space
}
if( y <= -myfont->nMaxHeight )
{
return; // totally off screen
}
scale = myfont->nSize;
sh = myfont->nMaxHeight;
row = (num >> 4) - 2;
col = num & 15;
frow = row * myfont->hFrac;
fcol = col * myfont->wFrac;
pfglColor4ubv( myfont->colour );
pfglEnable( GL_BLEND );
R_Bind( myfont->texfont->texnum );
pfglBegin( GL_QUADS );
pfglTexCoord2f( fcol, frow );
pfglVertex2i( x, y );
pfglTexCoord2f( fcol+myfont->wFrac, frow );
pfglVertex2i( x+myfont->nMaxWidth*scale, y );
pfglTexCoord2f( fcol+myfont->wFrac, frow+myfont->hFrac );
pfglVertex2i( x+myfont->nMaxWidth*scale, (y+sh*scale) );
pfglTexCoord2f( fcol, frow+myfont->hFrac );
pfglVertex2i( x, (y+sh*scale) );
pfglEnd();
pfglDisable( GL_BLEND );
pfglColor3f( 1, 1, 1 );
}
/*
-----------------------------------------------------------------------------
Function: R_Draw_StretchPic -Draw stretched image to the screen.
Parameters: x -[in] x-coordinate.
y -[in] y-coordinate.
w -[in] width of region.
h -[in] height of region.
pic -[in] Image filename to stretch.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void R_Draw_StretchPic( int x, int y, int w, int h, const char *pic )
{
texture_t *gl;
gl = TM_FindTexture( pic, TT_Pic );
if( ! gl )
{
Com_Printf( "Can't find pic: %s\n", pic );
return;
}
R_Bind( gl->texnum );
pfglBegin( GL_QUADS );
pfglTexCoord2f( 0.0f, 0.0f ); pfglVertex2i( x, y );
pfglTexCoord2f( 1.0f, 0.0f ); pfglVertex2i( x+w, y );
pfglTexCoord2f( 1.0f, 1.0f ); pfglVertex2i( x+w, y+h );
pfglTexCoord2f( 0.0f, 1.0f ); pfglVertex2i( x, y+h );
pfglEnd();
}
/*
-----------------------------------------------------------------------------
Function: R_Draw_Fill -Fills a box of pixels with a single color.
Parameters: x -[in] x-coordinate.
y -[in] y-coordinate.
w -[in] width of region.
h -[in] height of region.
c -[in] Colour to fill region.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void R_Draw_Fill( int x, int y, int w, int h, colour3_t c )
{
#if 1
// as of 2.2 OS, doing a clear with a small scissor rect is MUCH slower
// than drawing geometry, so they must not be optimizing that case...
colour4_t c4;
c4[0] = c[0];
c4[1] = c[1];
c4[2] = c[2];
c4[3] = 255;
R_Draw_Blend( x, y, w, h, c4 );
#else
if ( revLand->value ) {
qglScissor( x, y, w, h );
} else {
qglScissor( x, 320-(y+h), w, h );
}
qglEnable( GL_SCISSOR_TEST );
qglClearColor( c[0] / 255.0f, c[1] / 255.0f, c[2] / 255.0f, 1.0f );
qglClear( GL_COLOR_BUFFER_BIT );
qglDisable( GL_SCISSOR_TEST );
#endif
}
PUBLIC void R_Draw_Blend( int x, int y, int w, int h, colour4_t c )
{
pfglDisable( GL_TEXTURE_2D );
pfglColor4ubv( c );
pfglBegin( GL_QUADS );
pfglVertex2i( x, y );
pfglVertex2i( x+w, y );
pfglVertex2i( x+w, y+h );
pfglVertex2i( x, y+h );
pfglEnd();
pfglColor3f( 1, 1, 1 );
pfglEnable( GL_TEXTURE_2D );
}
/*
-----------------------------------------------------------------------------
Function: R_Draw_Line -Draw a line on the screen.
Parameters: nXStart -[in] x-coordinate of starting point.
nYStart -[in] y-coordinate of starting point.
nXEnd -[in] x-coordinate of ending point.
nYEnd -[in] y-coordinate of ending point.
c -[in] Colour value.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void R_Draw_Line( int nXStart, int nYStart, int nXEnd, int nYEnd, int width, colour3_t c )
{
pfglDisable( GL_TEXTURE_2D );
pfglColor3ubv( c );
pfglLineWidth( (float)width );
pfglBegin( GL_LINES );
pfglVertex2i( nXStart, nYStart );
pfglVertex2i( nXEnd, nYEnd );
pfglEnd();
pfglColor3f( 1, 1, 1 );
pfglEnable( GL_TEXTURE_2D );
}

1024
wolf3d/code/env/opengl_extension.c vendored Normal file

File diff suppressed because it is too large Load Diff

254
wolf3d/code/env/opengl_local.h vendored Normal file
View File

@@ -0,0 +1,254 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __OPENGL_LOCAL_H__
#define __OPENGL_LOCAL_H__
extern int glMaxTexSize; // maximum texture size
//===================================================================
extern void GL_SetDefaultState( void );
extern float gldepthmin, gldepthmax;
//====================================================
extern int gl_filter_min, gl_filter_max;
//
// view origin
//
extern vec3_t vup;
extern vec3_t vpn;
extern vec3_t vright;
extern vec3_t r_origin;
//
// screen size info
//
//extern refdef_t r_newrefdef;
extern int r_viewcluster, r_viewcluster2, r_oldviewcluster, r_oldviewcluster2;
extern cvar_t *r_norefresh;
extern cvar_t *r_lefthand;
extern cvar_t *r_speeds;
extern cvar_t *r_novis;
extern cvar_t *r_nocull;
extern cvar_t *gl_vertex_arrays;
extern cvar_t *gl_ext_swapinterval;
extern cvar_t *gl_ext_palettedtexture;
extern cvar_t *gl_ext_multitexture;
extern cvar_t *gl_ext_pointparameters;
extern cvar_t *gl_ext_compiled_vertex_array;
extern cvar_t *gl_nosubimage;
extern cvar_t *gl_bitdepth;
extern cvar_t *gl_mode;
extern cvar_t *gl_lightmap;
extern cvar_t *gl_shadows;
extern cvar_t *gl_dynamic;
extern cvar_t *gl_nobind;
extern cvar_t *gl_round_down;
extern cvar_t *gl_picmip;
extern cvar_t *gl_skymip;
extern cvar_t *gl_showtris;
extern cvar_t *gl_finish;
extern cvar_t *gl_ztrick;
extern cvar_t *gl_clear;
extern cvar_t *gl_cull;
extern cvar_t *gl_poly;
extern cvar_t *gl_texsort;
extern cvar_t *gl_polyblend;
extern cvar_t *gl_flashblend;
extern cvar_t *gl_lightmaptype;
extern cvar_t *gl_modulate;
extern cvar_t *gl_playermip;
extern cvar_t *gl_drawbuffer;
extern cvar_t *gl_driver;
extern cvar_t *gl_swapinterval;
extern cvar_t *gl_texturemode;
extern cvar_t *gl_saturatelighting;
extern cvar_t *r_fullscreen;
extern cvar_t *vid_gamma;
extern cvar_t *intensity;
extern int gl_lightmap_format;
extern int gl_solid_format;
extern int gl_alpha_format;
extern int gl_tex_alpha_format;
extern void R_Bind( int texnum );
extern void R_MBind( GLenum target, int texnum );
extern void R_TexEnv( GLenum value );
extern void R_EnableMultitexture( _boolean enable );
extern void R_SelectTexture( GLenum );
//====================================================================
extern int registration_sequence;
typedef struct
{
const char *renderer_string;
const char *vendor_string;
const char *version_string;
const char *extensions_string;
_boolean Version_1_2;
} glconfig_t;
typedef struct
{
float inverse_intensity;
_boolean fullscreen;
int prev_mode;
int lightmap_textures;
int currenttextures[2];
int currenttmu;
} glstate_t;
extern glconfig_t gl_config;
extern glstate_t gl_state;
//////////////////////////////////////////////////////
typedef struct
{
_boolean ARBMultiTexture;
int nTextureStages; // Number of texture stages supported
_boolean EXTTextureEnvCombine;
_boolean EXTTextureFilterAnisotropic;
float nMaxAnisotropy;
// NB: Fence extension is not here, because NVVertexArrayRange is false if GL_NV_fence is not here.
_boolean NVVertexArrayRange;
int NVVertexArrayRangeMaxVertex;
_boolean EXTTextureCompressionS3TC;
_boolean EXTVertexWeighting;
_boolean EXTSeparateSpecularColor;
_boolean NVTextureEnvCombine4;
_boolean ARBTextureCubeMap;
_boolean NVVertexProgram;
_boolean EXTVertexShader;
_boolean NVTextureShader;
// true if NVVertexProgram and if we know that VP is emulated
_boolean NVVertexProgramEmulated;
_boolean EXTSecondaryColor;
_boolean EXTBlendColor;
// NVVertexArrayRange2.
_boolean NVVertexArrayRange2;
// equal to GL_VERTEX_ARRAY_RANGE_WITHOUT_FLUSH_NV if possible, or GL_VERTEX_ARRAY_RANGE_NV
int NVStateVARWithoutFlush;
/* WGL ARB Extensions */
_boolean WGLARBPBuffer;
_boolean WGLARBPixelFormat;
_boolean WGLEXTSwapControl;
/* ATI Extensions */
_boolean ATIVertexArrayObject;
_boolean ATIMapObjectBuffer;
_boolean ATITextureEnvCombine3;
_boolean ATIEnvMapBumpMap;
_boolean ATIFragmentShader;
_boolean ATIXTextureEnvRoute;
/* ARB Extensions */
_boolean ARBTextureCompression;
_boolean ARBFragmentProgram;
_boolean ARBVertexBufferObject;
_boolean ARBVertexProgram;
/* Disable Hardware feature */
_boolean DisableHardwareVertexProgram;
_boolean DisableHardwareTextureShader;
} GL_Extensions;
extern GL_Extensions gl_ext;
extern void GL_ConfigExtensions( const char *glext );
extern void MYgluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar );
extern void PrintGLError( W32 err, const char *from );
/*
====================================================================
IMPLEMENTATION SPECIFIC FUNCTIONS
====================================================================
*/
#ifdef __cplusplus
extern "C" {
#endif
void GLimp_BeginFrame();
_boolean GLimp_Init( void *hinstance, void *hWnd );
void GLimp_Shutdown( void );
int GLimp_SetMode( int *pwidth, int *pheight, int mode, _boolean fullscreen );
void GLimp_AppActivate( _boolean active );
#ifdef __cplusplus
}
#endif
#endif /* __OPENGL_LOCAL_H__ */

400
wolf3d/code/env/opengl_main.c vendored Normal file
View File

@@ -0,0 +1,400 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../wolfiphone.h"
viddef_t viddef;
float gldepthmin, gldepthmax;
glconfig_t gl_config;
glstate_t gl_state;
//
// view origin
//
vec3_t vup;
vec3_t vpn;
vec3_t vright;
vec3_t r_origin;
cvar_t *r_norefresh;
cvar_t *r_speeds;
cvar_t *r_novis;
cvar_t *r_nocull;
cvar_t *r_lefthand;
cvar_t *gl_nosubimage;
cvar_t *gl_vertex_arrays;
cvar_t *gl_ext_swapinterval;
cvar_t *gl_ext_palettedtexture;
cvar_t *gl_ext_multitexture;
cvar_t *gl_ext_pointparameters;
cvar_t *gl_ext_compiled_vertex_array;
//cvar_t *gl_ext_TextureCompressionS3TC;
cvar_t *gl_bitdepth;
cvar_t *gl_drawbuffer;
cvar_t *gl_driver;
cvar_t *gl_lightmap;
cvar_t *gl_shadows;
cvar_t *gl_mode;
cvar_t *gl_dynamic;
cvar_t *gl_modulate;
cvar_t *gl_nobind;
cvar_t *gl_round_down;
cvar_t *gl_picmip;
cvar_t *gl_skymip;
cvar_t *gl_showtris;
cvar_t *gl_ztrick;
cvar_t *gl_finish;
cvar_t *gl_clear;
cvar_t *gl_cull;
cvar_t *gl_polyblend;
cvar_t *gl_flashblend;
cvar_t *gl_playermip;
cvar_t *gl_saturatelighting;
cvar_t *gl_swapinterval;
cvar_t *gl_texturemode;
cvar_t *r_fullscreen;
cvar_t *vid_gamma;
cvar_t *r_ref;
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void MYgluPerspective( GLdouble fovy, GLdouble aspect,
GLdouble zNear, GLdouble zFar )
{
GLdouble xmin, xmax, ymin, ymax;
ymax = zNear * tan( fovy * M_PI / 360.0 );
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
xmin += -( 2 * 0 ) / zNear;
xmax += -( 2 * 0 ) / zNear;
pfglFrustum( xmin, xmax, ymin, ymax, zNear, zFar );
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void R_ScreenShot_f( void )
{
W8 *buffer;
char picname[ 80 ];
char checkname[ MAX_OSPATH ];
int i;
FILE *f;
// create the scrnshots directory if it doesn't exist
my_snprintf( checkname, sizeof( checkname ), "%s/scrnshot", FS_Gamedir() );
FS_CreateDirectory( checkname );
//
// find a file name to save it to
//
my_strlcpy( picname, "scrn00.tga", sizeof( picname ) );
for( i = 0 ; i <= 99 ; ++i )
{
picname[ 4 ] = i / 10 + '0';
picname[ 5 ] = i % 10 + '0';
my_snprintf( checkname, sizeof( checkname ), "%s/scrnshot/%s", FS_Gamedir(), picname );
f = fopen( checkname, "rb" );
if( ! f )
{
break; // file doesn't exist
}
fclose( f );
}
if( i == 100 )
{
Com_Printf( "R_ScreenShot_f: Couldn't create a file\n" );
return;
}
buffer = MM_MALLOC( viddef.width * viddef.height * 3 );
pfglReadPixels( 0, 0, viddef.width, viddef.height, GL_RGB, GL_UNSIGNED_BYTE, buffer );
WriteTGA( checkname, 24, viddef.width, viddef.height, buffer, 1, 1 );
MM_FREE( buffer );
Com_Printf( "Wrote %s\n", picname );
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void R_Strings_f( void )
{
Com_Printf( "GL_VENDOR: %s\n", gl_config.vendor_string );
Com_Printf( "GL_RENDERER: %s\n", gl_config.renderer_string );
Com_Printf( "GL_VERSION: %s\n", gl_config.version_string );
Com_Printf( "GL_EXTENSIONS: %s\n", gl_config.extensions_string );
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void R_Register( void )
{
gl_round_down = Cvar_Get ("gl_round_down", "1", CVAR_INIT);
r_lefthand = Cvar_Get( "hand", "0", CVAR_USERINFO | CVAR_ARCHIVE );
r_norefresh = Cvar_Get ("r_norefresh", "0", CVAR_INIT);
r_novis = Cvar_Get ("r_novis", "0", CVAR_INIT);
r_nocull = Cvar_Get ("r_nocull", "0", CVAR_INIT);
r_speeds = Cvar_Get ("r_speeds", "0", CVAR_INIT);
gl_nosubimage = Cvar_Get( "gl_nosubimage", "0", CVAR_INIT );
gl_modulate = Cvar_Get ("gl_modulate", "1", CVAR_ARCHIVE );
gl_bitdepth = Cvar_Get( "gl_bitdepth", "0", CVAR_INIT );
gl_mode = Cvar_Get( "gl_mode", "0", CVAR_ARCHIVE );
gl_lightmap = Cvar_Get ("gl_lightmap", "0", CVAR_INIT);
gl_dynamic = Cvar_Get ("gl_dynamic", "1", CVAR_INIT);
gl_nobind = Cvar_Get ("gl_nobind", "0", CVAR_INIT);
gl_picmip = Cvar_Get ("gl_picmip", "0", CVAR_INIT);
gl_skymip = Cvar_Get ("gl_skymip", "0", CVAR_INIT);
gl_showtris = Cvar_Get( "gl_showtris", "0", CVAR_INIT );
gl_ztrick = Cvar_Get( "gl_ztrick", "0", CVAR_INIT );
gl_finish = Cvar_Get( "gl_finish", "0", CVAR_ARCHIVE );
gl_clear = Cvar_Get( "gl_clear", "0", CVAR_INIT );
gl_cull = Cvar_Get( "gl_cull", "1", CVAR_INIT );
gl_polyblend = Cvar_Get( "gl_polyblend", "1", CVAR_INIT );
gl_flashblend = Cvar_Get( "gl_flashblend", "0", CVAR_INIT );
gl_playermip = Cvar_Get( "gl_playermip", "0", CVAR_INIT );
gl_driver = Cvar_Get( "gl_driver", OPENGL_DLL_NAME, CVAR_ARCHIVE );
gl_vertex_arrays = Cvar_Get( "gl_vertex_arrays", "0", CVAR_ARCHIVE );
gl_ext_swapinterval = Cvar_Get( "gl_ext_swapinterval", "1", CVAR_ARCHIVE );
gl_ext_palettedtexture = Cvar_Get( "gl_ext_palettedtexture", "1", CVAR_ARCHIVE );
gl_ext_multitexture = Cvar_Get( "gl_ext_multitexture", "1", CVAR_ARCHIVE );
gl_ext_pointparameters = Cvar_Get( "gl_ext_pointparameters", "1", CVAR_ARCHIVE );
gl_ext_compiled_vertex_array = Cvar_Get( "gl_ext_compiled_vertex_array", "1", CVAR_ARCHIVE );
gl_drawbuffer = Cvar_Get( "gl_drawbuffer", "GL_BACK", CVAR_INIT );
gl_swapinterval = Cvar_Get( "gl_swapinterval", "1", CVAR_ARCHIVE );
// gl_saturatelighting = Cvar_Get( "gl_saturatelighting", "0", CVAR_INIT );
r_fullscreen = Cvar_Get( "r_fullscreen", "0", CVAR_ARCHIVE );
vid_gamma = Cvar_Get( "vid_gamma", "1.0", CVAR_ARCHIVE );
r_ref = Cvar_Get( "r_ref", "gl", CVAR_ARCHIVE );
Cmd_AddCommand( "screenshot", R_ScreenShot_f );
Cmd_AddCommand( "r_strings", R_Strings_f );
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void R_Init()
{
char renderer_buffer[ 1000 ];
char vendor_buffer[ 1000 ];
int err;
int a, b;
Com_Printf( "\n------ Display Initialization ------\n" );
Com_Printf( "Initializing OpenGL Subsystem\n" );
R_Register();
// set our "safe" modes
gl_state.prev_mode = 0;
viddef.width = 480;
viddef.height = 320;
// get various GL strings
gl_config.vendor_string = (char *)pfglGetString( GL_VENDOR );
Com_Printf( "GL_VENDOR: %s\n", gl_config.vendor_string );
gl_config.renderer_string = (char *)pfglGetString( GL_RENDERER );
Com_Printf( "GL_RENDERER: %s\n", gl_config.renderer_string );
gl_config.version_string = (char *)pfglGetString( GL_VERSION );
Com_Printf( "GL_VERSION: %s\n", gl_config.version_string );
gl_config.extensions_string = (char *)pfglGetString( GL_EXTENSIONS );
Com_Printf( "GL_EXTENSIONS: %s\n", gl_config.extensions_string );
my_strlcpy( renderer_buffer, gl_config.renderer_string, sizeof( renderer_buffer ) );
(void)my_strlwr( renderer_buffer );
my_strlcpy( vendor_buffer, gl_config.vendor_string, sizeof( vendor_buffer ) );
(void)my_strlwr( vendor_buffer );
sscanf( gl_config.version_string, "%d.%d", &a, &b );
if( a >= 1 && b >= 2 )
{
gl_config.Version_1_2 = true;
}
pfglGetIntegerv( GL_MAX_TEXTURE_SIZE, &glMaxTexSize );
Com_Printf( "GL_MAX_TEXTURE_SIZE: %d\n", glMaxTexSize);
GL_SetDefaultState();
TM_Init();
Font_Init();
err = pfglGetError();
if( err != GL_NO_ERROR )
{
Com_Printf( "glGetError() = 0x%x\n", err );
}
}
/*
-----------------------------------------------------------------------------
Function: PrintGLError -Print OpenGL error message.
Parameters: err -[in] Error code.
from -[in] function name that produced the error.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void PrintGLError( W32 err, const char *from )
{
if( err == GL_NO_ERROR )
{
return;
}
if( from != "" )
{
Com_Printf( "\n\n\nGL Error: %s\n", from );
}
switch( err )
{
case GL_NO_ERROR:
Com_Printf( "GL_NO_ERROR:\nNo error has been recorded. The value of this symbolic constant is guaranteed to be zero.\n" );
break;
case GL_INVALID_ENUM:
Com_Printf( "GL_INVALID_ENUM:\nAn unacceptable value is specified for an enumerated argument. The offending function is ignored, having no side effect other than to set the error flag.\n" );
break;
case GL_INVALID_VALUE:
Com_Printf( "GL_INVALID_VALUE:\nA numeric argument is out of range. The offending function is ignored, having no side effect other than to set the error flag.\n" );
break;
case GL_INVALID_OPERATION:
Com_Printf( "GL_INVALID_OPERATION:\nThe specified operation is not allowed in the current state. The offending function is ignored, having no side effect other than to set the error flag.\n" );
break;
case GL_STACK_OVERFLOW:
Com_Printf( "GL_STACK_OVERFLOW:\nThis function would cause a stack overflow. The offending function is ignored, having no side effect other than to set the error flag.\n" );
break;
case GL_STACK_UNDERFLOW:
Com_Printf( "GL_STACK_UNDERFLOW:\nThis function would cause a stack underflow. The offending function is ignored, having no side effect other than to set the error flag.\n" );
break;
case GL_OUT_OF_MEMORY:
Com_Printf( "GL_OUT_OF_MEMORY:\nThere is not enough memory left to execute the function. The state of OpenGL is undefined, except for the state of the error flags, after this error is recorded.\n" );
break;
default:
Com_Printf( "Unknown GL error flag 0x%x\n", err );
}
}

253
wolf3d/code/env/opengl_texture.c vendored Normal file
View File

@@ -0,0 +1,253 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* opengl_texture.c: OpenGL Texture Manager.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* Portion of this code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#include "../wolfiphone.h"
int currentTextures[ 4 ];
int currenttmu;
int glMaxTexSize;
// ***************************************************************************
// ***************************************************************************
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void R_DeleteTexture( unsigned int texnum )
{
pfglDeleteTextures( 1, &texnum );
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void R_TexEnv( GLenum mode )
{
static int lastmodes[ 4 ] = { -1, -1, -1, -1 };
if ( mode != lastmodes[ currenttmu ] )
{
pfglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode );
lastmodes[ currenttmu ] = mode;
}
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void R_SelectTexture( GLenum texture )
{
int tmu;
#ifndef IPHONE
if( ! pfglActiveTextureARB )
{
return;
}
#endif
if( texture == GL_TEXTURE0 )
{
tmu = 0;
}
else if( texture == GL_TEXTURE1 )
{
tmu = 1;
}
else if( texture == GL_TEXTURE2 )
{
tmu = 2;
}
else
{
tmu = 3;
}
if( tmu == currenttmu )
{
return;
}
currenttmu = tmu;
pfglActiveTextureARB( texture );
pfglClientActiveTextureARB( texture );
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void R_Bind( int texnum )
{
// Is this texture already bound
if( currentTextures[ currenttmu ] == texnum )
{
return;
}
currentTextures[ currenttmu ] = texnum;
pfglBindTexture( GL_TEXTURE_2D, texnum );
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void R_MBind( GLenum target, int texnum )
{
R_SelectTexture( target );
if( target == GL_TEXTURE0 )
{
if ( currentTextures[ 0 ] == texnum )
{
return;
}
}
else if( target == GL_TEXTURE1 )
{
if( currentTextures[ 1 ] == texnum )
{
return;
}
}
else if( target == GL_TEXTURE2 )
{
if( currentTextures[ 2 ] == texnum )
{
return;
}
}
else
{
if( currentTextures[ 3 ] == texnum )
{
return;
}
}
R_Bind( texnum );
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void R_EnableMultitexture( _boolean enable )
{
#ifndef IPHONE
if( ! pfglActiveTextureARB )
{
return;
}
#endif
if( enable )
{
R_SelectTexture( GL_TEXTURE1 );
pfglEnable( GL_TEXTURE_2D );
R_TexEnv( GL_REPLACE );
}
else
{
R_SelectTexture( GL_TEXTURE1 );
pfglDisable( GL_TEXTURE_2D );
R_TexEnv( GL_REPLACE );
}
R_SelectTexture( GL_TEXTURE0 );
R_TexEnv( GL_REPLACE );
}

107
wolf3d/code/env/random_number.c vendored Normal file
View File

@@ -0,0 +1,107 @@
/*
Copyright (C) 2004 Michael Liebscher
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* random_number.c: Wolfenstein3-D random number generator.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Wolfenstein3-D, and was originally
* written by Id Software, Inc.
*
*/
#include "../wolfiphone.h"
/* This is just John Carmack's table driven pseudo-random number generator */
W32 rndtable[] = {
0, 8, 109, 220, 222, 241, 149, 107, 75, 248, 254, 140, 16, 66,
74, 21, 211, 47, 80, 242, 154, 27, 205, 128, 161, 89, 77, 36,
95, 110, 85, 48, 212, 140, 211, 249, 22, 79, 200, 50, 28, 188,
52, 140, 202, 120, 68, 145, 62, 70, 184, 190, 91, 197, 152, 224,
149, 104, 25, 178, 252, 182, 202, 182, 141, 197, 4, 81, 181, 242,
145, 42, 39, 227, 156, 198, 225, 193, 219, 93, 122, 175, 249, 0,
175, 143, 70, 239, 46, 246, 163, 53, 163, 109, 168, 135, 2, 235,
25, 92, 20, 145, 138, 77, 69, 166, 78, 176, 173, 212, 166, 113,
94, 161, 41, 50, 239, 49, 111, 164, 70, 60, 2, 37, 171, 75,
136, 156, 11, 56, 42, 146, 138, 229, 73, 146, 77, 61, 98, 196,
135, 106, 63, 197, 195, 86, 96, 203, 113, 101, 170, 247, 181, 113,
80, 250, 108, 7, 255, 237, 129, 226, 79, 107, 112, 166, 103, 241,
24, 223, 239, 120, 198, 58, 60, 82, 128, 3, 184, 66, 143, 224,
145, 224, 81, 206, 163, 45, 63, 90, 168, 114, 59, 33, 159, 95,
28, 139, 123, 98, 125, 196, 15, 70, 194, 253, 54, 14, 109, 226,
71, 17, 161, 93, 186, 87, 244, 138, 20, 52, 123, 251, 26, 36,
17, 46, 52, 231, 232, 76, 31, 221, 84, 37, 216, 165, 212, 106,
197, 242, 98, 43, 39, 175, 254, 145, 190, 84, 118, 222, 187, 136,
120, 163, 236, 249
};
W32 rndindex = 0;
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void US_InitRndT( int randomize )
{
if( randomize )
{
rndindex = time( NULL ) & 0xFF;
}
else
{
rndindex = 0;
}
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC int US_RndT( void )
{
rndindex++;
rndindex &= 0xFF;
return rndtable[ rndindex ];
}

48
wolf3d/code/env/random_number.h vendored Normal file
View File

@@ -0,0 +1,48 @@
/*
Copyright (C) 2004 Michael Liebscher
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* mymath.h: Math routines.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Wolfenstein3-D, and was originally
* written by Id Software, Inc.
*
*/
#ifndef __RANDOM_NUMBER_H__
#define __RANDOM_NUMBER_H__
#define random() ( (rand() & 0x7fff) / ((float)0x7fff) )
#define crandom() ( 2.0 * (random() - 0.5) )
extern void US_InitRndT( int randomize );
extern int US_RndT( void );
#endif /* __RANDOM_NUMBER_H__ */

100
wolf3d/code/env/renderer.h vendored Normal file
View File

@@ -0,0 +1,100 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* renderer.h: Interface to graphics API.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
/*
Notes:
This module communicates with the graphics API. The API can be any graphics
API, e.g OpenGL, DirectX, SDL, GDI, etc; as long as the functions listed in
this header are implemented.
*/
#ifndef __RENDERER_H__
#define __RENDERER_H__
#ifdef _WIN32
#define OPENGL_DLL_NAME "opengl32.dll"
#elif __unix__
#define OPENGL_DLL_NAME "libGL.so.1"
#elif IPHONE
#define OPENGL_DLL_NAME "not applicable"
#else
#error "Define OPENGL_DLL_NAME"
#endif
typedef enum
{
rserr_ok,
rserr_invalid_fullscreen,
rserr_invalid_mode,
rserr_unknown
} rserr_t;
extern int registration_sequence;
extern void R_Init( void );
extern void R_BeginRegistration( const char *model );
extern void R_BeginFrame( void );
extern void R_SwapBuffers( int );
extern void R_SetPalette( const unsigned char *palette);
extern void R_DeleteTexture( unsigned int texnum );
extern void R_Draw_StretchPic( int x, int y, int w, int h, const char *name );
extern void R_Draw_Character( int x, int y, int num, font_t *myfont );
extern void R_Draw_Fill( int x, int y, int w, int h, colour3_t c );
extern void R_Draw_Line( int nXStart, int nYStart, int nXEnd, int nYEnd, int width, colour3_t c );
#endif /* __RENDERER_H__ */

189
wolf3d/code/env/share.c vendored Normal file
View File

@@ -0,0 +1,189 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../wolfiphone.h"
char com_token[128];
/*
============================================================================
BYTE ORDER FUNCTIONS
============================================================================
*/
/*
-----------------------------------------------------------------------------
Function: va() -Does a varargs printf into a temp buffer, so I don't need to
have varargs versions of all text functions.
Parameters: format -[in] Format-control string.
... -[in] Optional arguments.
Returns: Formatted string.
Notes:
If format string is longer than 1024 it will be truncated.
-----------------------------------------------------------------------------
*/
PUBLIC char *va( char *format, ... )
{
va_list argptr;
static char string[ 1024 ];
va_start( argptr, format );
(void)vsnprintf( string, sizeof( string ), format, argptr );
va_end( argptr );
string[ sizeof( string ) - 1 ] = '\0';
return string;
}
/*
-----------------------------------------------------------------------------
Function: COM_Parse() -Parse a token out of a string.
Parameters: data_p -[in] String to parse.
Returns: On success it will return the token string, otherwise it will
return "".
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *COM_Parse( char **data_p )
{
int c;
int len;
char *data;
data = *data_p;
len = 0;
com_token[ 0 ] = 0;
if( ! data )
{
*data_p = NULL;
return "";
}
// skip whitespace
skipwhite:
while( (c = *data) <= ' ')
{
if( c == 0 )
{
*data_p = NULL;
return "";
}
data++;
}
// skip // comments
if( c == '/' && data[ 1 ] == '/' )
{
while( *data && *data != '\n' )
{
data++;
}
goto skipwhite;
}
// handle quoted strings specially
if( c == '\"' )
{
data++;
while( 1 )
{
c = *data++;
if( c == '\"' || ! c )
{
com_token[ len ] = 0;
*data_p = data;
return com_token;
}
if( len < MAX_TOKEN_CHARS )
{
com_token[ len ] = c;
len++;
}
}
}
// parse a regular word
do
{
if( len < MAX_TOKEN_CHARS )
{
com_token[ len ] = c;
len++;
}
data++;
c = *data;
} while( c > 32 );
if( len == MAX_TOKEN_CHARS )
{
// Com_Printf ("Token exceeded %i chars, discarded.\n", MAX_TOKEN_CHARS);
len = 0;
}
com_token[ len ] = 0;
*data_p = data;
return com_token;
}
/*
-----------------------------------------------------------------------------
Function: Com_PageInMemory()
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
int paged_total;
PUBLIC void Com_PageInMemory( PW8 buffer, int size )
{
int i;
for( i = size - 1 ; i > 0 ; i -= 4096 )
{
paged_total += buffer[ i ];
}
}

730
wolf3d/code/env/sound.c vendored Normal file
View File

@@ -0,0 +1,730 @@
/*
Copyright (C) 2004-2005 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* sound.c:
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
* Acknowledgement:
* Portion of this code was derived from Quake II Evolved.
*
*/
#include "../wolfiphone.h"
#define MAX_PLAYSOUNDS 128
#define MAX_CHANNELS 64
PRIVATE playSound_t s_playSounds[ MAX_PLAYSOUNDS ];
PRIVATE playSound_t s_freePlaySounds;
PRIVATE playSound_t s_pendingPlaySounds;
PRIVATE channel_t s_channels[ MAX_CHANNELS ];
PRIVATE int s_numChannels;
PRIVATE listener_t s_listener;
PRIVATE int s_frameCount;
PRIVATE _boolean s_activeApp;
_boolean sound_initialized = false;
cvar_t *s_initSound;
cvar_t *s_masterVolume;
cvar_t *s_sfxVolume;
cvar_t *s_musicVolume;
cvar_t *s_minDistance;
cvar_t *s_maxDistance;
cvar_t *s_rolloffFactor;
cvar_t *s_dopplerFactor;
cvar_t *s_dopplerVelocity;
/////////////////////////////////////////////////////////////////////
//
// Sound Channels
//
/////////////////////////////////////////////////////////////////////
/*
-----------------------------------------------------------------------------
Function: Sound_AllocChannels -Allocate sound channels.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void Sound_AllocChannels( void )
{
channel_t *ch;
int i;
for( i = 0, ch = s_channels ; i < MAX_CHANNELS ; ++i, ++ch )
{
pfalGenSources( 1, &ch->sourceName );
if( pfalGetError() != AL_NO_ERROR )
{
break;
}
s_numChannels++;
}
}
/*
-----------------------------------------------------------------------------
Function: Sound_ChannelState -Free sound channels.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE int Sound_ChannelState( channel_t *ch )
{
int state;
pfalGetSourcei( ch->sourceName, AL_SOURCE_STATE, &state );
return state;
}
PRIVATE void Sound_PlayChannel( channel_t *ch, sfx_t *sfx )
{
ch->sfx = sfx;
pfalSourcei( ch->sourceName, AL_BUFFER, sfx->bufferNum );
pfalSourcei( ch->sourceName, AL_LOOPING, ch->loopSound );
pfalSourcei( ch->sourceName, AL_SOURCE_RELATIVE, AL_FALSE );
pfalSourcePlay( ch->sourceName );
}
PRIVATE void Sound_StopChannel( channel_t *ch )
{
ch->sfx = NULL;
// as of 2.2.1, OpenAL on the iphone doesn't seem to stop sounds properly.
// Only deleting the entire source seems to work.
pfalSourceStop( ch->sourceName );
// pfalSourceStopv( 1, &ch->sourceName );
// pfalSourcei( ch->sourceName, AL_BUFFER, 0 );
// pfalSourceRewind( ch->sourceName );
#if 1
pfalDeleteSources( 1, &ch->sourceName );
pfalGenSources( 1, &ch->sourceName );
#endif
}
PRIVATE void Sound_SpatializeChannel( channel_t *ch )
{
// vec3_t position, velocity;
// Update position and velocity
if( ch->entNum == 0 || ! ch->distanceMult )
{
pfalSourcefv( ch->sourceName, AL_POSITION, s_listener.position );
pfalSourcefv( ch->sourceName, AL_VELOCITY, s_listener.velocity );
}
else
{
if( ch->fixedPosition )
{
pfalSource3f( ch->sourceName, AL_POSITION, ch->position[1], ch->position[2], -ch->position[0] );
pfalSource3f( ch->sourceName, AL_VELOCITY, 0, 0, 0 );
}
/* else
{
if( ch->loopSound )
{
Client_GetEntitySoundSpatialization( ch->loopNum, position, velocity );
}
else
{
Client_GetEntitySoundSpatialization( ch->entNum, position, velocity );
}
pfalSource3f( ch->sourceName, AL_POSITION, position[1], position[2], -position[0] );
pfalSource3f( ch->sourceName, AL_VELOCITY, velocity[1], velocity[2], -velocity[0] );
}
*/
}
// Update min/max distance
if( ch->distanceMult )
{
pfalSourcef( ch->sourceName, AL_REFERENCE_DISTANCE, s_minDistance->value * ch->distanceMult );
}
else
{
pfalSourcef( ch->sourceName, AL_REFERENCE_DISTANCE, s_maxDistance->value );
}
pfalSourcef( ch->sourceName, AL_MAX_DISTANCE, s_maxDistance->value );
// Update volume and rolloff factor
pfalSourcef( ch->sourceName, AL_GAIN, s_sfxVolume->value * ch->volume );
pfalSourcef( ch->sourceName, AL_ROLLOFF_FACTOR, s_rolloffFactor->value );
}
/*
-----------------------------------------------------------------------------
Function: Sound_PickChannel -
Parameters:
Returns:
Notes:
Tries to find a free channel, or tries to replace an active channel.
-----------------------------------------------------------------------------
*/
PUBLIC channel_t *Sound_PickChannel( W32 entNum, W32 entChannel )
{
channel_t *ch;
int i;
int firstToDie = -1;
int oldestTime = iphoneFrameNum;
for( i = 0, ch = s_channels ; i < s_numChannels ; ++i, ++ch )
{
// Don't let game sounds override streaming sounds
if( ch->streaming )
{
continue;
}
// Check if this channel is active
if( ! ch->sfx )
{
// Free channel
firstToDie = i;
break;
}
// Channel 0 never overrides
if( entChannel != 0 && (ch->entNum == entNum && ch->entChannel == entChannel ) )
{
// Always override sound from same entity
firstToDie = i;
break;
}
// Replace the oldest sound
if( ch->startTime < oldestTime )
{
oldestTime = ch->startTime;
firstToDie = i;
}
}
if( firstToDie == -1 )
{
return NULL;
}
ch = &s_channels[ firstToDie ];
ch->entNum = entNum;
ch->entChannel = entChannel;
ch->startTime = iphoneFrameNum;
// Make sure this channel is stopped
Sound_StopChannel( ch );
return ch;
}
/////////////////////////////////////////////////////////////////////
// End of Sound Channels
/////////////////////////////////////////////////////////////////////
/*
-----------------------------------------------------------------------------
Function: Sound_AddLoopingSounds -
Parameters: Nothing.
Returns: Nothing.
Notes:
Entities with a a->sound field will generate looping sounds that are
automatically started and stopped as the entities are sent to the
client.
-----------------------------------------------------------------------------
*/
PRIVATE void Sound_AddLoopingSounds( void )
{
}
PRIVATE playSound_t *Sound_AllocPlaySound( void )
{
playSound_t *ps;
ps = s_freePlaySounds.next;
if( ps == &s_freePlaySounds )
{
return NULL; // No free playSounds
}
ps->prev->next = ps->next;
ps->next->prev = ps->prev;
return ps;
}
PRIVATE void Sound_FreePlaySound( playSound_t *ps )
{
ps->prev->next = ps->next;
ps->next->prev = ps->prev;
// Add to free list
ps->next = s_freePlaySounds.next;
s_freePlaySounds.next->prev = ps;
ps->prev = &s_freePlaySounds;
s_freePlaySounds.next = ps;
}
/*
-----------------------------------------------------------------------------
Function: Sound_IssuePlaySounds -
Parameters:
Returns: Nothing.
Notes:
Take the next playsound and begin it on the channel.
This is never called directly by Sound_StartSound*, but only by the update loop.
-----------------------------------------------------------------------------
*/
PRIVATE void Sound_IssuePlaySounds( void )
{
playSound_t *ps;
channel_t *ch;
while( 1 )
{
ps = s_pendingPlaySounds.next;
if( ps == &s_pendingPlaySounds )
{
break; // No more pending playSounds
}
if( ps->beginTime > iphoneFrameNum )
{
break; // No more pending playSounds this frame
}
// Pick a channel and start the sound effect
ch = Sound_PickChannel( ps->entNum, ps->entChannel );
if( ! ch )
{
if( ps->sfx->name[ 0 ] == '#' )
Com_DPrintf( "Dropped sound %s\n", &ps->sfx->name[1]);
else
Com_DPrintf( "Dropped sound sound/%s\n", ps->sfx->name);
Sound_FreePlaySound( ps );
continue;
}
ch->loopSound = false;
ch->fixedPosition = ps->fixedPosition;
vectorCopy( ps->position, ch->position );
ch->volume = ps->volume;
if( ps->attenuation != ATTN_NONE )
{
ch->distanceMult = 1.0f / ps->attenuation;
}
else
{
ch->distanceMult = 0.0;
}
Sound_SpatializeChannel( ch );
Sound_PlayChannel( ch, ps->sfx );
// Free the playSound
Sound_FreePlaySound( ps );
}
}
/*
-----------------------------------------------------------------------------
Function: Sound_StartSound -
Parameters:
Returns: Nothing.
Notes:
Validates the parms and queues the sound up.
If origin is NULL, the sound will be dynamically sourced from the
entity.
entChannel 0 will never override a playing sound.
-----------------------------------------------------------------------------
*/
PUBLIC void Sound_StartSound( const vec3_t position, int entNum, int entChannel, sfx_t *sfx, float volume, float attenuation, int timeOfs )
{
playSound_t *ps, *sort;
if( ! sound_initialized )
{
return;
}
if( ! sfx )
{
return;
}
// Make sure the sound is loaded
if( ! Sound_LoadSound( sfx ) )
{
return;
}
// Allocate a playSound
ps = Sound_AllocPlaySound();
if( ! ps )
{
if( sfx->name[0] == '#' )
Com_DPrintf( "Dropped sound %s\n", &sfx->name[1] );
else
Com_DPrintf( "Dropped sound sound/%s\n", sfx->name);
return;
}
ps->sfx = sfx;
ps->entNum = entNum;
ps->entChannel = entChannel;
if( position )
{
ps->fixedPosition = true;
vectorCopy( position, ps->position );
}
else
{
ps->fixedPosition = false;
}
ps->volume = volume;
ps->attenuation = attenuation;
ps->beginTime = iphoneFrameNum;
// Sort into the pending playSounds list
for( sort = s_pendingPlaySounds.next ; sort != &s_pendingPlaySounds && sort->beginTime < ps->beginTime ; sort = sort->next )
{
;
}
ps->next = sort;
ps->prev = sort->prev;
ps->next->prev = ps;
ps->prev->next = ps;
}
PUBLIC void Sound_StartLocalSound( const char *filename )
{
sfx_t *sfx;
if( ! sound_initialized )
{
return;
}
sfx = Sound_RegisterSound( filename );
if( ! sfx )
{
Com_Printf( "Sound_StartLocalSound: could not cache (%s)\n", filename );
return;
}
Sound_StartSound( NULL, 0, 0, sfx, 1, ATTN_NONE, 0 );
}
PUBLIC void Sound_StopAllSounds( void )
{
channel_t *ch;
int i;
if( ! sound_initialized )
{
return;
}
// Clear all the playSounds
memset( s_playSounds, 0, sizeof( s_playSounds ) );
s_freePlaySounds.next = s_freePlaySounds.prev = &s_freePlaySounds;
s_pendingPlaySounds.next = s_pendingPlaySounds.prev = &s_pendingPlaySounds;
for( i = 0 ; i < MAX_PLAYSOUNDS ; ++i )
{
s_playSounds[ i ].prev = &s_freePlaySounds;
s_playSounds[ i ].next = s_freePlaySounds.next;
s_playSounds[ i ].prev->next = &s_playSounds[ i ];
s_playSounds[ i ].next->prev = &s_playSounds[ i ];
}
// Stop all the channels
for( i = 0, ch = s_channels ; i < s_numChannels ; ++i, ++ch )
{
if( ! ch->sfx )
{
continue;
}
Sound_StopChannel( ch );
}
// Reset frame count
s_frameCount = 0;
}
/*
-----------------------------------------------------------------------------
Function: Sound_Update -
Parameters: Nothing.
Returns: Nothing.
Notes:
Called once each time through the main loop.
-----------------------------------------------------------------------------
*/
PUBLIC void Sound_Update( const vec3_t position, const vec3_t velocity, const vec3_t at, const vec3_t up)
{
channel_t *ch;
int i, total = 0;
if( ! sound_initialized )
{
return;
}
// Bump frame count
s_frameCount++;
// Set up listener
vectorSet( s_listener.position, position[1], position[2], -position[0] );
vectorSet( s_listener.velocity, velocity[1], velocity[2], -velocity[0] );
vectorSet( &s_listener.orientation[0], at[1], -at[2], -at[0] );
vectorSet( &s_listener.orientation[3], up[1], -up[2], -up[0] );
pfalListenerfv( AL_POSITION, s_listener.position );
pfalListenerfv( AL_VELOCITY, s_listener.velocity );
pfalListenerfv( AL_ORIENTATION, s_listener.orientation );
pfalListenerf( AL_GAIN, (s_activeApp) ? s_masterVolume->value : 0.0);
// Set state
pfalDistanceModel( AL_INVERSE_DISTANCE_CLAMPED );
pfalDopplerFactor( s_dopplerFactor->value );
pfalDopplerVelocity( s_dopplerVelocity->value );
// Stream background track
Sound_StreamBGTrack();
// Add looping sounds
Sound_AddLoopingSounds();
// Issue playSounds
Sound_IssuePlaySounds();
// Update spatialization for all sounds
for( i = 0, ch = s_channels ; i < s_numChannels ; ++i, ++ch )
{
if( ! ch->sfx )
{
continue; // Not active
}
// Check for stop
if( ch->loopSound )
{
if( ch->loopFrame != s_frameCount )
{
Sound_StopChannel( ch );
continue;
}
}
else
{
if( Sound_ChannelState(ch) == AL_STOPPED )
{
Sound_StopChannel( ch );
continue;
}
}
// Respatialize channel
Sound_SpatializeChannel( ch );
total++;
}
}
PUBLIC void Sound_Activate( _boolean active )
{
s_activeApp = active;
if( ! sound_initialized )
{
return;
}
pfalListenerf( AL_GAIN, ( active ) ? s_masterVolume->value : 0.0 );
}
/////////////////////////////////////////////////////////////////////
//
// Console Commands
//
/////////////////////////////////////////////////////////////////////
PRIVATE void Sound_Play_f( void )
{
int i = 1;
char name[ MAX_GAMEPATH ];
if( Cmd_Argc() == 1 )
{
Com_Printf( "Usage: play <soundfile>\n" );
return;
}
while( i < Cmd_Argc() )
{
my_strlcpy( name, Cmd_Argv( i ), sizeof( name ) );
Sound_StartLocalSound( name );
i++;
}
}
PRIVATE void Sound_StopSound_f( void )
{
Sound_StopAllSounds();
}
/////////////////////////////////////////////////////////////////////
// End of Console Commands
/////////////////////////////////////////////////////////////////////
extern void Sound_SoundList_f( void );
PRIVATE void Sound_Register( void )
{
s_initSound = Cvar_Get( "s_initSound", "1", CVAR_INIT );
s_masterVolume = Cvar_Get( "s_masterVolume", "1.0", CVAR_ARCHIVE );
s_sfxVolume = Cvar_Get( "s_sfxVolume", "1.0", CVAR_ARCHIVE );
s_musicVolume = Cvar_Get( "s_musicVolume", "1.0", CVAR_ARCHIVE );
s_minDistance = Cvar_Get( "s_minDistance", "0.0", CVAR_ARCHIVE );
s_maxDistance = Cvar_Get( "s_maxDistance", "1.0", CVAR_ARCHIVE );
s_rolloffFactor = Cvar_Get( "s_rolloffFactor", "1.0", CVAR_ARCHIVE );
s_dopplerFactor = Cvar_Get( "s_dopplerFactor", "1.0", CVAR_ARCHIVE );
s_dopplerVelocity = Cvar_Get( "s_dopplerVelocity", "0.0", CVAR_ARCHIVE );
Cmd_AddCommand( "play", Sound_Play_f );
Cmd_AddCommand( "stopsound", Sound_StopSound_f );
Cmd_AddCommand( "listSounds", Sound_SoundList_f );
}
PUBLIC void Sound_Init( void )
{
Com_Printf( "\n------- Sound Initialization -------\n" );
Sound_Register();
if( ! Sound_Device_Setup() )
{
Com_Printf( "------------------------------------\n" );
return;
}
sound_initialized = true;
Sound_AllocChannels();
Sound_StopAllSounds();
Com_Printf( "------------------------------------\n" );
}

93
wolf3d/code/env/sound.h vendored Normal file
View File

@@ -0,0 +1,93 @@
/*
Copyright (C) 2004-2005 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* sound.h:
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
* Acknowledgement:
* Portion of this code was derived from Quake II Evolved.
*
*/
#ifndef __SOUND_H__
#define __SOUND_H__
// Sound channels
// Channel 0 never willingly overrides
// Other channels (1-7) always override a playing sound on that channel
#define CHAN_AUTO 0
#define CHAN_WEAPON 1
#define CHAN_VOICE 2
#define CHAN_ITEM 3
#define CHAN_BODY 4
// Modifier flags
#define CHAN_NO_PHS_ADD 8 // Send to all clients, not just ones in PHS (ATTN 0 will also do this)
#define CHAN_RELIABLE 16 // Send by reliable message, not datagram
// Sound attenuation values
#define ATTN_NONE 0 // Full volume the entire level
#define ATTN_NORM 1
#define ATTN_IDLE 2
#define ATTN_STATIC 3 // Diminish very rapidly with distance
extern cvar_t *s_device;
extern cvar_t *s_masterVolume;
extern cvar_t *s_sfxVolume;
extern cvar_t *s_musicVolume;
extern char *sound_devices[ 12 ];
extern W16 numSoundDevices;
extern W16 numDefaultSoundDevice;
extern W8 sound_initialized;
extern void Sound_Init( void );
extern void Sound_Update( const vec3_t position, const vec3_t velocity, const vec3_t at, const vec3_t up);
extern void Sound_Activate( _boolean active );
extern channel_t *Sound_PickChannel( W32 entNum, W32 entChannel );
extern sfx_t *Sound_RegisterSound( const char *name );
extern void Sound_StartLocalSound( const char *filename );
extern void Sound_StreamBGTrack( void );
extern void Sound_StartStreaming( void );
extern void Sound_StopStreaming( void );
extern void Sound_StartBGTrack( const char *introTrack, const char *loopTrack );
extern void Sound_StopBGTrack( void );
extern void Sound_StartSound( const vec3_t position, int entNum, int entChannel, sfx_t *sfx, float volume, float attenuation, int timeOfs );
extern void Sound_StopAllSounds( void );
#endif /* __SOUND_H__ */

111
wolf3d/code/env/sound_local.h vendored Normal file
View File

@@ -0,0 +1,111 @@
/*
Copyright (C) 2004-2005 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* sound_local.h:
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
* Acknowledgement:
* Portion of this code was derived from Quake II Evolved.
*
*/
#ifndef __SOUND_LOCAL_H__
#define __SOUND_LOCAL_H__
typedef struct sfx_s
{
char name[ MAX_GAMEPATH ];
_boolean defaulted;
_boolean loaded;
int samples;
int rate;
unsigned format; /* Sound samples: format specifier */
unsigned bufferNum;
struct sfx_s *nextHash;
} sfx_t;
// A playSound will be generated by each call to S_StartSound.
// When the mixer reaches playSound->beginTime, the playSound will be
// assigned to a channel.
typedef struct playSound_s
{
struct playSound_s *prev, *next;
sfx_t *sfx;
int entNum;
int entChannel;
_boolean fixedPosition; // Use position instead of fetching entity's origin
vec3_t position; // Only use if fixedPosition is set
float volume;
float attenuation;
int beginTime; // Begin at this time
} playSound_t;
typedef struct
{
_boolean streaming;
sfx_t *sfx; // NULL if unused
int entNum; // To allow overriding a specific sound
int entChannel;
int startTime; // For overriding oldest sounds
_boolean loopSound; // Looping sound
int loopNum; // Looping entity number
int loopFrame; // For stopping looping sounds
_boolean fixedPosition; // Use position instead of fetching entity's origin
vec3_t position; // Only use if fixedPosition is set
float volume;
float distanceMult;
unsigned sourceName; // OpenAL sourceName
} channel_t;
typedef struct
{
vec3_t position;
vec3_t velocity;
float orientation[ 6 ];
} listener_t;
// extern void Sound_SoundList_f( void );
extern _boolean Sound_LoadSound( sfx_t *sfx );
extern sfx_t *Sound_FindSound( const char *name );
extern _boolean Sound_Device_Setup( void );
extern void Sound_Device_Shutdown( void );
#endif /* __SOUND_LOCAL_H__ */

287
wolf3d/code/env/sound_sfx_id.c vendored Normal file
View File

@@ -0,0 +1,287 @@
/*
Copyright (C) 2004-2005 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* sound_sfx_id.c:
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
* Acknowledgement:
* Portion of this code was derived from Quake II Evolved.
*
*/
#include "../wolfiphone.h"
#define SFX_HASHSIZE 256
#define MAX_SFX 1024
PRIVATE sfx_t *s_sfxHash[ SFX_HASHSIZE ];
PRIVATE sfx_t *s_sfx[ MAX_SFX ];
PRIVATE int s_numSfx;
PRIVATE _boolean s_registering = false;
PRIVATE W32 s_registration_sequence = 0;
void Sound_SoundList_f( void )
{
}
/*
-----------------------------------------------------------------------------
Function: Sound_UploadSound -Upload sound data to buffer.
Parameters: data -[in] Sound data.
sample_size -[in] Sound sample size.
channels -[in] Number of sound channels.
sfx -[in] valid pointer to sfx_t structure.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void Sound_UploadSound( W8 *data, int sample_size, int channels, sfx_t *sfx )
{
int size;
// Calculate buffer size
size = sfx->samples * sample_size * channels;
// Set buffer format
if( sample_size == 2 )
{
if( channels == 2 )
{
sfx->format = AL_FORMAT_STEREO16;
}
else
{
sfx->format = AL_FORMAT_MONO16;
}
// Upload the sound
pfalGenBuffers( 1, &sfx->bufferNum );
pfalBufferData( sfx->bufferNum, sfx->format, data, size, sfx->rate );
}
else
{
/*
We upsample the sound to 16 bit here because the iphone
pops at the beginning and end of buffers with 8 bit. -Cass
(Brian Harris wants to be acknowledeged for helping find
this workaround.)
*/
short *d = (short *)malloc( size * 2 );
for ( int i = 0; i < size; i++ ) {
d[i] = ((short)data[i] - 128) * 256;
}
if( channels == 2 )
{
sfx->format = AL_FORMAT_STEREO16;
}
else
{
sfx->format = AL_FORMAT_MONO16;
}
// Upload the sound
pfalGenBuffers( 1, &sfx->bufferNum );
pfalBufferData( sfx->bufferNum, sfx->format, d, size * 2, sfx->rate );
free( d );
}
}
/*
-----------------------------------------------------------------------------
Function: Sound_LoadSound -Load sound data.
Parameters: sfx -[in] Pointer to valid sfx_t structure.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC _boolean Sound_LoadSound( sfx_t *sfx )
{
char name[ MAX_GAMEPATH ];
W8 *data;
soundInfo_t info;
if( sfx->name[ 0 ] == '*' )
{
return false;
}
// See if still in memory
if( sfx->loaded )
{
return true;
}
my_strlcpy( name, sfx->name, sizeof( name ) );
if( ! LoadWavInfo( name, &data, &info ) )
{
if ( ! LoadOggInfo( name, &data, &info ) ) {
sfx->defaulted = true;
Com_Printf( "Could not find sound (%s)\n", name );
return false;
}
}
sfx->loaded = true;
sfx->samples = info.samples;
sfx->rate = info.sample_rate;
Sound_UploadSound( data, info.sample_size, info.channels, sfx );
Z_Free( data );
return true;
}
/*
-----------------------------------------------------------------------------
Function: Sound_FindSound -Load sound data.
Parameters: sfx -[in] Pointer to valid sfx_t structure.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC sfx_t *Sound_FindSound( const char *name )
{
sfx_t *sfx;
unsigned hashKey;
if( ! name || ! name[ 0 ] )
{
Com_Printf( "Sound_FindSound: NULL sound name\n" );
return NULL;
}
if( strlen( name ) >= MAX_GAMEPATH )
{
Com_Printf( "Sound_FindSound: sound name exceeds MAX_GAMEPATH\n");
return NULL;
}
// See if already loaded
hashKey = (my_strhash( name ) % SFX_HASHSIZE);
for( sfx = s_sfxHash[ hashKey ] ; sfx ; sfx = sfx->nextHash )
{
if( ! my_stricmp( sfx->name, name ) )
{
return sfx;
}
}
// Create a new sfx_t
if( s_numSfx == MAX_SFX )
{
Com_Printf( "Sound_FindSound: MAX_SFX hit\n" );
return NULL;
}
s_sfx[ s_numSfx++ ] = sfx = Z_Malloc( sizeof( sfx_t ) );
my_strlcpy( sfx->name, name, sizeof( sfx->name ) );
// Add to hash table
sfx->nextHash = s_sfxHash[ hashKey ];
s_sfxHash[ hashKey ] = sfx;
return sfx;
}
PUBLIC void Sound_BeginRegistration( void )
{
s_registration_sequence++;
s_registering = true;
}
PUBLIC sfx_t *Sound_RegisterSound( const char *name )
{
sfx_t *sfx;
if( ! sound_initialized )
{
return NULL;
}
if( g_version->value == 1 )
{
char tempname[ 256 ];
my_snprintf( tempname, sizeof( tempname ), "sod%s", name );
sfx = Sound_FindSound( tempname );
}
else
{
sfx = Sound_FindSound( name );
}
if( ! s_registering )
{
Sound_LoadSound( sfx );
}
return sfx;
}
PUBLIC void Sound_EndRegistration( void )
{
s_registering = false;
}

516
wolf3d/code/env/sound_stream.c vendored Normal file
View File

@@ -0,0 +1,516 @@
/*
Copyright (C) 2005 Michael Liebscher
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* sound_stream.c: Sound Stream manager.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* Portion of this code was derived from Quake II Evolved.
*
*/
#include "../wolfiphone.h"
typedef struct
{
char introName[ MAX_GAMEPATH ];
char loopName[ MAX_GAMEPATH ];
_boolean looping;
filehandle_t *hFile;
int start;
int rate;
unsigned format;
void *vorbisFile;
} musicTrack_t;
// anything greater than 1<<13 caused crashes on iphone OS 2.1 (on a 3G iphone)
#define BUFFER_SIZE (1<<11)
PRIVATE musicTrack_t bgTrack;
PRIVATE channel_t *s_streamingChannel;
extern void Sound_StopBGTrack( void );
/*
-----------------------------------------------------------------------------
Function: ovc_read -OGG read Callback. Reads data from a stream.
Parameters:
ptr -[in] Storage location for data.
size -[in] Item size in bytes.
nmemb -[in] Maximum number of items to be read.
datasource -[in] music track data structure.
Returns: Nothing
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE size_t ovc_read( void *ptr, size_t size, size_t nmemb, void *datasource )
{
musicTrack_t *track = (musicTrack_t *)datasource;
if( ! size || ! nmemb )
{
return 0;
}
return FS_ReadFile( ptr, size, nmemb, track->hFile );
}
/*
-----------------------------------------------------------------------------
Function: ovc_read -OGG seek Callback. Moves the file pointer to a specified
location.
Parameters:
datasource -[in] music track data structure.
offset -[in] Number of bytes from whence.
whence -[in] Initial position.
Returns:
If successful, fseek returns 0. Otherwise, it returns a nonzero
value.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE int ovc_seek( void *datasource, ogg_int64_t offset, int whence )
{
musicTrack_t *track = (musicTrack_t *)datasource;
return FS_FileSeek( track->hFile, offset, whence );
}
/*
-----------------------------------------------------------------------------
Function: ovc_close -OGG close Callback. Closes a stream.
Parameters: datasource -[in] music track data structure.
Returns: 0 if the stream is successfully closed, otherwise nonzero.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE int ovc_close( void *datasource )
{
return 0;
}
/*
-----------------------------------------------------------------------------
Function: ovc_tell -OGG tell Callback. Gets the current position of a file
pointer.
Parameters: datasource -[in] music track data structure.
Returns: The current file position.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE long ovc_tell( void *datasource )
{
musicTrack_t *track = (musicTrack_t *)datasource;
return FS_FileTell( track->hFile );
}
/*
-----------------------------------------------------------------------------
Function: Sound_OpenBGTrack -OGG read Callback.
Parameters:
name -[in] File name to open.
track -[in/out] Music track data structure.
Returns: False on error, otherwise true.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE _boolean Sound_OpenBGTrack( const char *name, musicTrack_t *track )
{
OggVorbis_File *vorbisFile;
vorbis_info *vorbisInfo;
ov_callbacks vorbisCallbacks = {ovc_read, ovc_seek, ovc_close, ovc_tell};
int ret;
extern cvar_t *music;
if ( music->value == 0 || SysIPhoneOtherAudioIsPlaying() ) {
return 0;
}
track->hFile = FS_OpenFile( name, 0 );
if( ! track->hFile )
{
return false;
}
track->vorbisFile = vorbisFile = Z_Malloc( sizeof( OggVorbis_File ) );
if( (ret = ov_open_callbacks( track, vorbisFile, NULL, 0, vorbisCallbacks )) < 0 )
{
switch( ret )
{
case OV_EREAD:
Com_DPrintf( "A read from media returned an error.(%s)\n", name );
break;
case OV_ENOTVORBIS:
Com_DPrintf( "Bitstream is not Vorbis data.(%s)\n", name );
break;
case OV_EVERSION:
Com_DPrintf( "Vorbis version mismatch.(%s)\n", name );
break;
case OV_EBADHEADER:
Com_DPrintf( "Invalid Vorbis bitstream header.(%s)\n", name );
break;
case OV_EFAULT:
Com_DPrintf( "Internal logic fault; indicates a bug or heap/stack corruption.(%s)\n", name );
break;
}
Com_DPrintf( "Could not open OGG stream (%s)\n", name );
return false;
}
vorbisInfo = ov_info( vorbisFile, -1 );
if( vorbisInfo->channels != 1 && vorbisInfo->channels != 2 )
{
Com_DPrintf( "Only mono and stereo OGG files supported (%s)\n", name );
return false;
}
track->start = ov_raw_tell( vorbisFile );
track->rate = vorbisInfo->rate;
track->format = (vorbisInfo->channels == 2) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16;
return true;
}
/*
-----------------------------------------------------------------------------
Function: Sound_CloseBGTrack -Close out background music track.
Parameters: track -[in] Music track to close.
Returns: Nothing
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void Sound_CloseBGTrack( musicTrack_t *track )
{
if( track->vorbisFile )
{
ov_clear( track->vorbisFile );
Z_Free( track->vorbisFile );
track->vorbisFile = NULL;
}
if( track->hFile )
{
FS_CloseFile( track->hFile );
}
}
/*
-----------------------------------------------------------------------------
Function: Sound_StreamBGTrack -Called each frame to update streaming music
track.
Parameters: Nothing
Returns: Nothing
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Sound_StreamBGTrack( void )
{
W8 data[BUFFER_SIZE];
int processed, queued, state;
int size, read, dummy;
unsigned buffer;
if( ! s_musicVolume->value )
{
return;
}
if( ! s_streamingChannel )
{
return;
}
// Unqueue and delete any processed buffers
pfalGetSourcei( s_streamingChannel->sourceName, AL_BUFFERS_PROCESSED, &processed );
if( processed > 0 )
{
while (processed--)
{
pfalSourceUnqueueBuffers( s_streamingChannel->sourceName, 1, &buffer );
pfalDeleteBuffers( 1, &buffer );
}
}
// Make sure we always have at least 4 buffers in the queue
pfalGetSourcei( s_streamingChannel->sourceName, AL_BUFFERS_QUEUED, &queued );
while( queued < 4 )
{
size = 0;
// Stream from disk
while( size < BUFFER_SIZE )
{
read = ov_read( bgTrack.vorbisFile, (char *)data + size, BUFFER_SIZE - size, &dummy );
if( read == 0 )
{
// End of file
if( ! bgTrack.looping)
{
// Close the intro track
Sound_CloseBGTrack( &bgTrack );
// Open the loop track
if( ! Sound_OpenBGTrack( bgTrack.loopName, &bgTrack ) )
{
Sound_StopBGTrack();
return;
}
bgTrack.looping = true;
}
// Restart the track, skipping over the header
ov_raw_seek( bgTrack.vorbisFile, (ogg_int64_t)bgTrack.start );
// Try streaming again
read = ov_read( bgTrack.vorbisFile, (char *)data + size, BUFFER_SIZE - size, &dummy );
}
if( read <= 0 )
{
// An error occurred
Sound_StopBGTrack();
return;
}
size += read;
}
// Upload and queue the new buffer
pfalGenBuffers( 1, &buffer );
pfalBufferData( buffer, bgTrack.format, data, size, bgTrack.rate );
pfalSourceQueueBuffers( s_streamingChannel->sourceName, 1, &buffer );
queued++;
}
// Update volume
pfalSourcef( s_streamingChannel->sourceName, AL_GAIN, s_musicVolume->value );
// If not playing, then do so
pfalGetSourcei( s_streamingChannel->sourceName, AL_SOURCE_STATE, &state );
if( state != AL_PLAYING )
{
pfalSourcePlay(s_streamingChannel->sourceName);
}
}
/*
-----------------------------------------------------------------------------
Function: Sound_StartStreaming -Start streaming background music track.
Parameters: Nothing
Returns: Nothing
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Sound_StartStreaming( void )
{
if( ! sound_initialized )
{
return;
}
if( s_streamingChannel )
{
return;
}
s_streamingChannel = Sound_PickChannel( 0, 0 );
if( ! s_streamingChannel )
{
return;
}
s_streamingChannel->streaming = true;
// hmmm...
pfalDeleteSources( 1, &s_streamingChannel->sourceName );
pfalGenSources( 1, &s_streamingChannel->sourceName );
// Set up the source
pfalSourcei( s_streamingChannel->sourceName, AL_BUFFER, 0 );
pfalSourcei( s_streamingChannel->sourceName, AL_LOOPING, AL_FALSE );
pfalSourcei( s_streamingChannel->sourceName, AL_SOURCE_RELATIVE, AL_TRUE );
pfalSourcefv( s_streamingChannel->sourceName, AL_POSITION, vec3_origin );
pfalSourcefv( s_streamingChannel->sourceName, AL_VELOCITY, vec3_origin );
pfalSourcef( s_streamingChannel->sourceName, AL_REFERENCE_DISTANCE, 1.0 );
pfalSourcef( s_streamingChannel->sourceName, AL_MAX_DISTANCE, 1.0 );
pfalSourcef( s_streamingChannel->sourceName, AL_ROLLOFF_FACTOR, 0.0 );
}
/*
-----------------------------------------------------------------------------
Function: Sound_StopStreaming -Stop playing streaming music track.
Parameters: Nothing
Returns: Nothing
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Sound_StopStreaming( void )
{
int processed;
unsigned buffer;
if( ! sound_initialized )
{
return;
}
if( ! s_streamingChannel )
{
return;
}
s_streamingChannel->streaming = false;
pfalSourceStop( s_streamingChannel->sourceName );
pfalGetSourcei( s_streamingChannel->sourceName, AL_BUFFERS_PROCESSED, &processed );
if( processed > 0 )
{
while( processed-- )
{
pfalSourceUnqueueBuffers( s_streamingChannel->sourceName, 1, &buffer );
pfalDeleteBuffers( 1, &buffer );
}
}
pfalSourcei( s_streamingChannel->sourceName, AL_BUFFER, 0 );
// hmmm...
pfalDeleteSources( 1, &s_streamingChannel->sourceName );
pfalGenSources( 1, &s_streamingChannel->sourceName );
s_streamingChannel = NULL;
}
/*
-----------------------------------------------------------------------------
Function: Sound_StartBGTrack -Play background music track.
Parameters:
introTrack -[in] File name of intro track.
loopTrack -[in] File name of loop track.
Returns: Nothing
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Sound_StartBGTrack( const char *introTrack, const char *loopTrack )
{
if( ! sound_initialized )
{
return;
}
Sound_StopBGTrack();
my_strlcpy( bgTrack.introName, introTrack, sizeof( bgTrack.introName ) );
my_strlcpy( bgTrack.loopName, loopTrack, sizeof( bgTrack.loopName) );
Sound_StartStreaming();
if( ! Sound_OpenBGTrack( bgTrack.introName, &bgTrack ) )
{
Sound_StopBGTrack();
return;
}
Sound_StreamBGTrack();
}
/*
-----------------------------------------------------------------------------
Function: Sound_StopBGTrack -Stop playing background track.
Parameters: Nothing
Returns: Nothing
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Sound_StopBGTrack( void )
{
if( ! sound_initialized )
{
return;
}
Sound_StopStreaming();
Sound_CloseBGTrack( &bgTrack );
memset( &bgTrack, 0, sizeof( musicTrack_t ) );
}

1430
wolf3d/code/env/texture_manager.c vendored Normal file

File diff suppressed because it is too large Load Diff

192
wolf3d/code/env/texture_manager.h vendored Normal file
View File

@@ -0,0 +1,192 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
Copyright (C) 1995 Spencer Kimball and Peter Mattis.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* texture_manager.c: Texture manager.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* Portion of this code was derived from
* The GIMP (an image manipulation program) and was originally
* written by Spencer Kimball and Peter Mattis.
*
* Portion of this code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#ifndef __TEXTURE_MANAGER_H__
#define __TEXTURE_MANAGER_H__
#define MAX_TEXTURES 1024
typedef enum
{
TT_Sprite,
TT_Wall,
TT_Pic,
TextureTypeCount
} texturetype_t;
typedef enum
{
Repeat = 0,
Clamp,
WrapModeCount // Number of Wrap modes
} TWrapMode;
typedef enum
{
Auto = 0,
RGBA8888,
RGBA4444,
RGBA5551,
RGB888,
RGB565,
DXTC1,
DXTC1Alpha,
DXTC3,
DXTC5,
Luminance,
Alpha,
AlphaLuminance,
DsDt,
UpImageFormatCount // Number of Upload formats
} TTexFormat;
typedef enum
{
Nearest = 0,
Linear,
MagFilterCount // Number of Magnification filters
} TMagFilter;
typedef enum
{
NearestMipMapOff = 0,
NearestMipMapNearest,
NearestMipMapLinear,
LinearMipMapOff,
LinearMipMapNearest,
LinearMipMapLinear,
MinFilterCount // Number of Min filters
} TMinFilter;
typedef enum {
PF_565,
PF_5551,
PF_4444,
PF_PVR4,
PF_PVR4A,
PF_PVR2,
PF_PVR2A
} picFormat_t;
#define PF_NO_MIPS 256
// this is the header from the pre-digested binary files with sprite bounds
typedef struct {
int picFormat;
int srcWidth;
int srcHeight;
int uploadWidth;
int uploadHeight;
int numBounds;
int bounds[2][2][2];
} picHeader_t;
typedef struct texture_s
{
_boolean MipMap;
_boolean isTextureCube;
TTexFormat UploadFormat;
TWrapMode WrapS;
TWrapMode WrapT;
TWrapMode WrapR;
TMinFilter MinFilter;
TMagFilter MagFilter;
W32 registration_sequence; // 0 = free
W16 width, height;
W16 upload_width, upload_height;
W16 bytes;
texturetype_t type;
char name[ MAX_GAMEPATH ]; // game path, including extension
unsigned int texnum;
picHeader_t header;
float maxS, maxT; // header.srcWidth / header.uploadWidth for nonPOT textures
} texture_t;
typedef enum
{
INTERPOLATION_NONE, /* None (Fastest) */
INTERPOLATION_LINEAR, /* Linear */
INTERPOLATION_CUBIC /* Cubic (Best) */
} InterpolationType;
extern W32 texture_registration_sequence;
extern void TM_Init( void );
extern void TM_Shutdown( void );
extern _boolean TM_MipMap( PW8 in, W16 *width, W16 *height, W16 bytes );
extern texture_t *wallTextures[1000];
extern texture_t *spriteTextures[1000];
extern texture_t *TM_FindTexture( const char *name, texturetype_t type );
extern texture_t *TM_AllocateTexture( const char *name );
extern void TM_GetTextureSize( SW32 *width, SW32 *height, const char *name );
extern void TM_ResampleTexture( PW8 in, int inwidth, int inheight, PW8 out, int outwidth, int outheight, W8 bytes, InterpolationType interpolation );
extern void TM_FreeUnusedTextures( void );
#endif /* __TEXTURE_MANAGER_H__ */

783
wolf3d/code/env/tga.c vendored Normal file
View File

@@ -0,0 +1,783 @@
/*
Copyright (C) 2004-2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
Copyright (C) 1995 Spencer Kimball and Peter Mattis
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* tga.h: Handle Targa file format.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* Portion of this code was derived from The GIMP -- an image manipulation
* program, and was originally written by Spencer Kimball and Peter Mattis.
*
*/
/*
Notes:
*/
#include "../wolfiphone.h"
#define TGA_HEADER_SIZE 18
#ifndef IPHONE
PRIVATE W8 *p_buf; // current pointer to tga data block
#endif
/* TRUEVISION-XFILE magic signature string */
static W8 magic[ 18 ] =
{
0x54, 0x52, 0x55, 0x45, 0x56, 0x49, 0x53, 0x49, 0x4f,
0x4e, 0x2d, 0x58, 0x46, 0x49, 0x4c, 0x45, 0x2e, 0x0
};
typedef struct _TargaHeader
{
W8 idLength;
W8 colorMapType;
W8 imageType;
/* Known image types. */
#define TGA_TYPE_MAPPED 1
#define TGA_TYPE_COLOR 2
#define TGA_TYPE_GRAY 3
W8 imageCompression;
/* Only known compression is RLE */
#define TGA_COMP_NONE 0
#define TGA_COMP_RLE 1
/* Color Map Specification. */
W16 colorMapIndex;
W16 colorMapLength;
W8 colorMapSize;
/* Image Specification. */
W16 xOrigin;
W16 yOrigin;
W16 width;
W16 height;
W8 bpp;
W8 bytes;
W8 alphaBits;
W8 flipHoriz;
W8 flipVert;
} TargaHeader;
PRIVATE void flip_line( W8 *buffer, TargaHeader *info )
{
W8 temp;
W8 *alt;
SW32 x, s;
alt = buffer + (info->bytes * (info->width - 1));
for( x = 0; x * 2 <= info->width; ++x )
{
for( s = 0; s < info->bytes; ++s )
{
temp = buffer[ s ];
buffer[ s ] = alt[ s ];
alt[ s ] = temp;
}
buffer += info->bytes;
alt -= info->bytes;
}
}
PRIVATE void upsample( W8 *dest, W8 *src,
W32 width, W32 bytes, W8 alphaBits )
{
W32 x;
for( x = 0 ; x < width ; ++x )
{
dest[0] = ((src[1] << 1) & 0xf8);
dest[0] += (dest[0] >> 5);
dest[1] = ((src[0] & 0xe0) >> 2) + ((src[1] & 0x03) << 6);
dest[1] += (dest[1] >> 5);
dest[2] = ((src[0] << 3) & 0xf8);
dest[2] += (dest[2] >> 5);
switch( alphaBits )
{
case 1:
dest[ 3 ] = (src[ 1 ] & 0x80) ? 0 : 255;
dest += 4;
break;
default:
dest += 3;
}
src += bytes;
}
}
PRIVATE void bgr2rgb( W8 *dest, W8 *src,
W32 width, W32 bytes, W32 alpha )
{
W32 x;
if( alpha )
{
for( x = 0 ; x < width ; ++x )
{
*(dest++) = src[2];
*(dest++) = src[1];
*(dest++) = src[0];
*(dest++) = src[3];
src += bytes;
}
}
else
{
for( x = 0 ; x < width ; ++x )
{
*(dest++) = src[2];
*(dest++) = src[1];
*(dest++) = src[0];
src += bytes;
}
}
}
PRIVATE SW32 rle_read( filehandle_t *fp, W8 *buffer,
TargaHeader *info )
{
static SW32 repeat = 0;
static SW32 direct = 0;
static W8 sample[ 4 ];
SW32 head;
W8 temphead;
SW32 x, k;
for( x = 0; x < info->width; ++x )
{
if( repeat == 0 && direct == 0 )
{
FS_ReadFile( &temphead, 1, 1, fp );
head = temphead;
if( head >= 128 )
{
repeat = head - 127;
if( FS_ReadFile( sample, info->bytes, 1, fp ) < 1 )
{
return EOF;
}
}
else
{
direct = head + 1;
}
}
if( repeat > 0 )
{
for( k = 0 ; k < info->bytes ; ++k )
{
buffer[ k ] = sample[ k ];
}
repeat--;
}
else /* direct > 0 */
{
if( FS_ReadFile( buffer, info->bytes, 1, fp ) < 1 )
{
return EOF;
}
direct--;
}
buffer += info->bytes;
}
return 0;
}
PRIVATE void read_line( filehandle_t *fp,
W8 *row,
W8 *buffer,
TargaHeader *info )
{
if( info->imageCompression == TGA_COMP_RLE )
{
if( rle_read( fp, buffer, info ) == EOF )
{
return;
}
}
else
{
FS_ReadFile( buffer, info->bytes, info->width, fp );
}
if( info->flipHoriz )
{
flip_line( buffer, info );
}
if( info->imageType == TGA_TYPE_COLOR )
{
if( info->bpp == 16 || info->bpp == 15 )
{
upsample( row, buffer, info->width, info->bytes, info->alphaBits );
}
else
{
bgr2rgb( row, buffer, info->width, info->bytes, info->bytes == 4 ? 1 : 0 );
}
}
else
{
memcpy( row, buffer, info->width * info->bpp );
}
}
PUBLIC void LoadTGA( const char *filename, W8 **pic, W16 *width, W16 *height, W16 *bytes )
{
TargaHeader targa_header;
W8 header[ 18 ];
W8 footer[ 26 ];
W8 extension[ 495 ];
W32 cmap_bytes;
SW32 offset;
W8 tga_cmap[4 * 256], gimp_cmap[3 * 256];
W8 *buffer, *data, *row;
int i;
SW32 datalength;
filehandle_t *hFile;
*pic = NULL;
//
// Load the file
//
hFile = FS_OpenFile( filename, 0 );
if( ! hFile )
{
Com_DPrintf( "Could not open (%s) for reading\n", filename );
goto TGALOADFAILED;
}
datalength = FS_GetFileSize( hFile );
if( ! FS_FileSeek( hFile, -26L, SEEK_END ) )
{
/* Is file big enough for a footer? */
if( FS_ReadFile( footer, sizeof( footer ), 1, hFile ) != 1 )
{
Com_DPrintf( "Cannot read footer from (%s)\n" , filename );
goto TGALOADFAILED;
}
else if( memcmp( footer + 8, magic, sizeof( magic ) ) == 0 )
{
/* Check the signature. */
offset = footer[ 0 ] + (footer[ 1 ] * 256) + (footer[ 2 ] * 65536)
+ (footer[ 3 ] * 16777216);
if( offset != 0 )
{
if( FS_FileSeek( hFile, offset, SEEK_SET ) ||
FS_ReadFile( extension, sizeof( extension ), 1, hFile ) != 1 )
{
Com_DPrintf( "Cannot read extension from '%s'\n", filename );
goto TGALOADFAILED;
}
/* Eventually actually handle version 2 TGA here */
}
}
}
//
// Get header information.
//
if( datalength < TGA_HEADER_SIZE )
{
Com_Printf( "Could not read header from (%s)\n", filename );
goto TGALOADFAILED;
}
if( FS_FileSeek( hFile, 0, SEEK_SET ) ||
FS_ReadFile( header, sizeof( header ), 1, hFile ) != 1 )
{
Com_Printf( "Cannot read header from (%s)\n", filename );
goto TGALOADFAILED;
}
targa_header.idLength = header[ 0 ];
targa_header.colorMapType = header[ 1 ];
switch( header[ 2 ] )
{
case 1:
targa_header.imageType = TGA_TYPE_MAPPED;
targa_header.imageCompression = TGA_COMP_NONE;
break;
case 2:
targa_header.imageType = TGA_TYPE_COLOR;
targa_header.imageCompression = TGA_COMP_NONE;
break;
case 3:
targa_header.imageType = TGA_TYPE_GRAY;
targa_header.imageCompression = TGA_COMP_NONE;
break;
case 9:
targa_header.imageType = TGA_TYPE_MAPPED;
targa_header.imageCompression = TGA_COMP_RLE;
break;
case 10:
targa_header.imageType = TGA_TYPE_COLOR;
targa_header.imageCompression = TGA_COMP_RLE;
break;
case 11:
targa_header.imageType = TGA_TYPE_GRAY;
targa_header.imageCompression = TGA_COMP_RLE;
break;
default:
targa_header.imageType = 0;
}
targa_header.colorMapIndex = header[ 3 ] + header[ 4 ] * 256;
targa_header.colorMapLength = header[ 5 ] + header[ 6 ] * 256;
targa_header.colorMapSize = header[ 7 ];
targa_header.xOrigin = header[ 8 ] + header[ 9 ] * 256;
targa_header.yOrigin = header[ 10 ] + header[ 11 ] * 256;
targa_header.width = header[ 12 ] + header[ 13 ] * 256;
targa_header.height = header[ 14 ] + header[ 15 ] * 256;
targa_header.bpp = header[ 16 ];
targa_header.bytes = (targa_header.bpp + 7) / 8;
targa_header.alphaBits = header[ 17 ] & 0x0f; /* Just the low 4 bits */
targa_header.flipHoriz = (header[ 17 ] & 0x10) ? 1 : 0;
targa_header.flipVert = (header[ 17 ] & 0x20) ? 0 : 1;
//
// Analyze header information.
//
switch( targa_header.imageType )
{
case TGA_TYPE_MAPPED:
if( targa_header.bpp != 8 )
{
Com_DPrintf( "Unhandled sub-format in (%s)\n", filename );
goto TGALOADFAILED;
}
goto TGALOADFAILED;
break;
case TGA_TYPE_COLOR:
if( targa_header.bpp != 15 && targa_header.bpp != 16 && targa_header.bpp != 24
&& targa_header.bpp != 32 )
{
Com_DPrintf( "Unhandled sub-format in (%s)\n", filename );
goto TGALOADFAILED;
}
break;
case TGA_TYPE_GRAY:
if( targa_header.bpp != 8 && (targa_header.alphaBits != 8 || (targa_header.bpp != 16 && targa_header.bpp != 15 )))
{
Com_DPrintf( "Unhandled sub-format in (%s)\n", filename );
goto TGALOADFAILED;
}
goto TGALOADFAILED;
break;
default:
Com_DPrintf( "Unknown image type for (%s)\n", filename );
goto TGALOADFAILED;
} /* end of switch targa_header.imageType */
/* Plausible but unhandled formats */
if( targa_header.bytes * 8 != targa_header.bpp && ! (targa_header.bytes == 2 && targa_header.bpp == 15) )
{
Com_DPrintf( "No support yet for TGA with these parameters\n" );
goto TGALOADFAILED;
}
/* Check that we have a color map only when we need it. */
if( targa_header.imageType == TGA_TYPE_MAPPED && targa_header.colorMapType != 1 )
{
Com_DPrintf( "Indexed image has invalid color map type %d\n",
targa_header.colorMapType );
goto TGALOADFAILED;
}
else if( targa_header.imageType != TGA_TYPE_MAPPED && targa_header.colorMapType != 0 )
{
Com_DPrintf( "Non-indexed image has invalid color map type %d\n",
targa_header.colorMapType );
goto TGALOADFAILED;
}
/* Skip the image ID field. */
if( targa_header.idLength && FS_FileSeek( hFile, targa_header.idLength, SEEK_CUR ) )
{
Com_DPrintf( "File (%s) is truncated or corrupted\n", filename );
goto TGALOADFAILED;
}
/* Handle colormap */
if( targa_header.colorMapType == 1 )
{
cmap_bytes = (targa_header.colorMapSize + 7 ) / 8;
if( cmap_bytes <= 4 &&
FS_ReadFile( tga_cmap, targa_header.colorMapLength * cmap_bytes, 1, hFile ) == 1 )
{
if( targa_header.colorMapSize == 32 )
{
bgr2rgb( gimp_cmap, tga_cmap, targa_header.colorMapLength, cmap_bytes, 1);
}
else if( targa_header.colorMapSize == 24 )
{
bgr2rgb( gimp_cmap, tga_cmap, targa_header.colorMapLength, cmap_bytes, 0);
}
else if( targa_header.colorMapSize == 16 || targa_header.colorMapSize == 15 )
{
upsample( gimp_cmap, tga_cmap, targa_header.colorMapLength, cmap_bytes, targa_header.alphaBits);
}
}
else
{
Com_DPrintf( "File (%s) is truncated or corrupted\n", filename );
goto TGALOADFAILED;
}
}
/* Allocate the data. */
data = MM_MALLOC( targa_header.width * targa_header.height * targa_header.bytes );
if( data == NULL )
{
MM_OUTOFMEM( "data" );
}
buffer = (PW8) MM_MALLOC( targa_header.width * targa_header.bytes );
if( buffer == NULL )
{
MM_FREE( data );
MM_OUTOFMEM( "buffer" );
}
if( targa_header.flipVert )
{
for( i = targa_header.height-1 ; i >= 0 ; --i )
{
row = data + (targa_header.width * targa_header.bytes * i);
read_line( hFile, row, buffer, &targa_header );
}
}
else
{
for( i = 0 ; i < targa_header.height ; ++i )
{
row = data + (targa_header.width * targa_header.bytes * i);
read_line( hFile, row, buffer, &targa_header );
}
}
MM_FREE( buffer );
FS_CloseFile( hFile );
*pic = data;
*width = targa_header.width;
*height = targa_header.height;
*bytes = targa_header.bytes;
return;
TGALOADFAILED:
*pic = NULL;
*width = 0;
*height = 0;
*bytes = 0;
if( hFile )
{
FS_CloseFile( hFile );
}
}
/*
-----------------------------------------------------------------------------
Function: rle_write -Run length encode scanline.
Parameters: fp -[in] Pointer to valid FILE structure.
buffer -[in] Scanline data.
width -[in] Image scanline width.
bytes -[in] Bytes per pixel.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE void rle_write( FILE *fp,
W8 *buffer,
W32 width,
W32 bytes )
{
SW32 repeat = 0;
SW32 direct = 0;
W8 *from = buffer;
W32 x;
for( x = 1 ; x < width ; ++x )
{
if( memcmp( buffer, buffer + bytes, bytes ) )
{
/* next pixel is different */
if( repeat )
{
putc( 128 + repeat, fp );
fwrite( from, bytes, 1, fp );
from = buffer + bytes; /* point to first different pixel */
repeat = 0;
direct = 0;
}
else
{
direct += 1;
}
}
else
{
/* next pixel is the same */
if( direct )
{
putc( direct - 1, fp );
fwrite( from, bytes, direct, fp );
from = buffer; /* point to first identical pixel */
direct = 0;
repeat = 1;
}
else
{
repeat += 1;
}
}
if( repeat == 128 )
{
putc( 255, fp );
fwrite( from, bytes, 1, fp );
from = buffer + bytes;
direct = 0;
repeat = 0;
}
else if( direct == 128 )
{
putc( 127, fp );
fwrite( from, bytes, direct, fp );
from = buffer + bytes;
direct = 0;
repeat = 0;
}
buffer += bytes;
}
if( repeat > 0 )
{
putc( 128 + repeat, fp );
fwrite( from, bytes, 1, fp );
}
else
{
putc( direct, fp );
fwrite( from, bytes, direct + 1, fp );
}
}
/*
-----------------------------------------------------------------------------
Function: WriteTGA -Write targa image file.
Parameters: filename -[in] Name of TGA file to save as.
bpp -[in] Bits per pixel. (16, 24 or 32).
width -[in] Width of image.
height -[in] Height of image.
Data -[in] Raw image data.
upsideDown -[in] Is the data upside down? 1 yes, 0 no.
rle -[in] Run Length encode? 1 yes, 0 no.
Returns: 0 on error, otherwise 1.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC W8 WriteTGA( const char *filename, W16 bpp, W16 width, W16 height,
void *Data, W8 upsideDown, W8 rle )
{
W16 i, x, y, BytesPerPixel;
W8 *scanline;
W8 header[ 18 ];
FILE *filestream;
W8 *ptr = (PW8) Data;
W8 temp;
BytesPerPixel = bpp >> 3;
filestream = fopen( filename, "wb" );
if( filestream == NULL )
{
Com_DPrintf( "Could not open file (%s) for write!\n", filename );
return 0;
}
memset( header, 0, 18 );
header[2] = rle ? 10 : 2;
header[12] = width & 255; // width low
header[13] = width >> 8; // width high
header[14] = height & 255; // height low
header[15] = height >> 8; // height high
header[16] = bpp & 255; // pixel size
if( upsideDown )
{
header[17] |= 1 << 5; // Image Descriptor
}
fwrite( header, sizeof( W8 ), sizeof( header ), filestream );
scanline = (PW8) MM_MALLOC( width * BytesPerPixel );
if( scanline == NULL )
{
fclose( filestream );
return 0;
}
for( y = 0; y < height; ++y )
{
W32 k = 0;
for( i = 0; i < (width * BytesPerPixel); ++i )
{
scanline[ k++ ] = ptr[ (height - y - 1) * width * BytesPerPixel + i ];
}
if( bpp == 24 || bpp == 32 )
{
// swap rgb to bgr
for( x = 0; x < (width * BytesPerPixel); x += BytesPerPixel )
{
temp = scanline[ x ];
scanline[ x ] = scanline[ x + 2 ];
scanline[ x + 2 ] = temp;
}
}
if( rle )
{
rle_write( filestream, scanline, width, BytesPerPixel );
}
else
{
fwrite( scanline, sizeof( W8 ), width * BytesPerPixel, filestream );
}
}
MM_FREE( scanline );
fclose( filestream );
return 1;
}

49
wolf3d/code/env/tga.h vendored Normal file
View File

@@ -0,0 +1,49 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
Copyright (C) 1995 Spencer Kimball and Peter Mattis
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* tga.h: Handle Targa file format.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* Portion of this code was derived from Quake II, and was
* originally written by id Software, Inc.
*
* Portion of this code was derived from The GIMP -- an image manipulation
* program, and was originally written by Spencer Kimball and Peter Mattis.
*/
#ifndef __TGA_H__
#define __TGA_H__
extern void LoadTGA( const char *filename, W8 **pic, W16 *width, W16 *height, W16 *bytes );
extern W8 WriteTGA( const char *filename, W16 bpp, W16 width, W16 height,
void *Data, W8 upsideDown, W8 rle );
#endif /* __TGA_H__ */

44
wolf3d/code/env/timer.h vendored Normal file
View File

@@ -0,0 +1,44 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* timer.h: Timer.
*
* Author: Id Software, Inc.
* Date: 1997-2001
*
*/
/*
Notes:
This module is implemented by win_timer.c or unix_timer.c.
*/
#ifndef __TIMER_H__
#define __TIMER_H__
extern W32 curtime; // time returned by last Sys_Milliseconds()
extern W32 Sys_Milliseconds( void );
#endif /* __TIMER_H__ */

286
wolf3d/code/env/unix_file.c vendored Normal file
View File

@@ -0,0 +1,286 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* unix_file.c: Handles non-portable file services.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* Portion of this code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#include "../wolfiphone.h"
PRIVATE char findbase[ MAX_OSPATH ];
PRIVATE char findpath[ MAX_OSPATH ];
PRIVATE char findpattern[ MAX_OSPATH ];
PRIVATE DIR *fdir;
/*
-----------------------------------------------------------------------------
Function: FS_CreateDirectory() -Creates a new directory.
Parameters: dirname -[in] Pointer to a NUL-terminated string that specifies
the path of the directory to be created.
Returns: On success nonzero, otherwise zero.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC W8 FS_CreateDirectory( const char *dirname )
{
int ret_val = mkdir( dirname, S_IRUSR | S_IWUSR | S_IXUSR );
if( ret_val == -1 && errno == EEXIST )
{
return 1;
}
return (W8)(! ret_val);
}
/*
-----------------------------------------------------------------------------
Function: FS_ChangeCurrentDirectory() -Changes the current directory
Parameters: path -[in] Pointer to a NUL-terminated string that specifies
the path to the new directory.
Returns: On success nonzero, otherwise zero.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC W8 FS_ChangeCurrentDirectory( const char *path )
{
return ! chdir( path );
}
/*
-----------------------------------------------------------------------------
Function: CompareAttributes() -Compare directory and file attributes.
Parameters: path -[in] Specifies the path to compare file attributes.
musthave -[in] File or directory must have these attributes.
canthave- [in] File or directory can not have these attributes.
Returns: On success true, otherwise false.
Notes:
-----------------------------------------------------------------------------
*/
PRIVATE _boolean CompareAttributes( const char *path, W32 musthave, W32 canthave )
{
struct stat st;
if( stat( path, &st ) == -1 )
{
return false;
}
if( ( st.st_mode & S_IFDIR ) && ( canthave & FA_DIR ) )
{
return false;
}
if( ( musthave & FA_DIR ) && !( st.st_mode & S_IFDIR ) )
{
return false;
}
return true;
}
/*
-----------------------------------------------------------------------------
Function: FS_FindFirstFile() -Searches a directory for a file.
Parameters: path -[in] Pointer to a NUL-terminated string that specifies
a valid directory or path and file name.
musthave -[in] File or directory must have these attributes.
canthave- [in] File or directory can not have these attributes.
Returns: On success string of file name or directory, otherwise NULL.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *FS_FindFirst( const char *path, W32 musthave, W32 canthave )
{
struct dirent *d;
char *p;
p;
if( fdir )
{
Com_Printf( "FS_FindFirst without close\n" );
return NULL;
}
FS_FilePath( (char *)path, findbase );
my_strlcpy( (char *)findpattern, FS_SkipPath( (char *)path ), sizeof( findpattern ) );
if( ! *findbase )
{
if( (fdir = opendir( "." )) == NULL )
{
return NULL;
}
}
else
{
if( (fdir = opendir( findbase )) == NULL )
{
return NULL;
}
}
while( (d = readdir( fdir )) != NULL )
{
if( ! *findpattern || glob_match( findpattern, d->d_name ) )
{
if( ! *findbase )
{
my_strlcpy( findpath, d->d_name, sizeof( findpath ) );
}
else
{
my_snprintf( findpath, sizeof( findpath ), "%s/%s", findbase, d->d_name );
}
if( CompareAttributes( findpath, musthave, canthave ) )
{
return findpath;
}
}
}
return NULL;
}
/*
-----------------------------------------------------------------------------
Function: FS_FindNext -Continues a file search from a previous call to
the FS_FindFirst function.
Parameters: musthave -[in] File or directory must have these attributes.
canthave- [in] File or directory can not have these attributes.
Returns: On success string of file name or directory, otherwise NULL.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC char *FS_FindNext( W32 musthave, W32 canthave )
{
struct dirent *d;
if( fdir == NULL )
{
return NULL;
}
while( (d = readdir( fdir ) ) != NULL)
{
if( ! *findpattern || glob_match( findpattern, d->d_name ) )
{
if( ! *findbase )
{
my_strlcpy( findpath, d->d_name, sizeof( findpath ) );
}
else
{
my_snprintf( findpath, sizeof( findpath ), "%s/%s", findbase, d->d_name );
}
if( CompareAttributes( findpath, musthave, canthave ) )
{
return findpath;
}
}
}
return NULL;
}
/*
-----------------------------------------------------------------------------
Function: FS_FindClose() -Closes the search handle.
Parameters: Nothing.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void FS_FindClose( void )
{
if( fdir )
{
closedir( fdir );
}
fdir = NULL;
}
/*
-----------------------------------------------------------------------------
Function: FS_DeleteFile() -Deletes an existing file.
Parameters: filename -[in] Pointer to a NUL-terminated string that
specifies the file to be deleted.
Returns: If successful the return value is nonzero, otherwise zero.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC _boolean FS_DeleteFile( const char *filename )
{
return( ! unlink( filename ) );
}
/*
-----------------------------------------------------------------------------
Function: FS_RemoveDirectory() -Deletes an existing empty directory.
Parameters: pathname -[in] Pointer to a NUL-terminated string that
specifies the directory to be deleted.
Returns: If successful the return value is nonzero, otherwise zero.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC _boolean FS_RemoveDirectory( const char *pathname )
{
return( ! rmdir( pathname ) );
}

67
wolf3d/code/env/unix_timer.c vendored Normal file
View File

@@ -0,0 +1,67 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* unix_timer.c: unix timer.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#include "../wolfiphone.h"
PUBLIC W32 curtime;
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC W32 Sys_Milliseconds( void )
{
struct timeval tp;
struct timezone tzp;
static int secbase;
gettimeofday( &tp, &tzp );
if( ! secbase )
{
secbase = tp.tv_sec;
return tp.tv_usec / 1000;
}
curtime = (tp.tv_sec - secbase) * 1000 + tp.tv_usec / 1000;
return curtime;
}

650
wolf3d/code/env/vector.c vendored Normal file
View File

@@ -0,0 +1,650 @@
/*
Copyright (C) 2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* vector.h: 2D and 3D vector math routines.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* Portion of this code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#include "../wolfiphone.h"
vec3_t vec3_origin = { 0, 0, 0 };
vec_t _VectorNormalize( vec3_t v );
vec_t (*pfVectorNormalize)( vec3_t v ) = _VectorNormalize;
/*
-----------------------------------------------------------------------------
Function: _VectorNormalize -Normalize a 3D vector.
Parameters: v -[in] 3D vector to normalize.
Returns: Unit vector value.
Notes:
For a given vector, the process of finding a unit vector which is
parallel to it. This is done by dividing the given vector by its
magnitude.
-----------------------------------------------------------------------------
*/
PUBLIC vec_t _VectorNormalize( vec3_t v )
{
float length, ilength;
length = (float)pfSqrt( v[ 0 ] * v[ 0 ] + v[ 1 ] * v[ 1 ] + v[ 2 ] * v[ 2 ] );
if( length )
{
ilength = 1 / length;
v[ 0 ] *= ilength;
v[ 1 ] *= ilength;
v[ 2 ] *= ilength;
}
return length;
}
/*
-----------------------------------------------------------------------------
Function: ProjectPointOnPlane -Project a point onto a plane.
Parameters: dst -[out] Destination Point on Plane.
p -[in] Point to project onto the plane.
normal -[in] A vector to specify the orientation of the plane.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal )
{
float d;
vec3_t n;
float inv_denom;
inv_denom = 1.0f / DotProduct( normal, normal );
d = DotProduct( normal, p ) * inv_denom;
n[ 0 ] = normal[ 0 ] * inv_denom;
n[ 1 ] = normal[ 1 ] * inv_denom;
n[ 2 ] = normal[ 2 ] * inv_denom;
dst[ 0 ] = p[ 0 ] - d * n[ 0 ];
dst[ 1 ] = p[ 1 ] - d * n[ 1 ];
dst[ 2 ] = p[ 2 ] - d * n[ 2 ];
}
/*
-----------------------------------------------------------------------------
Function: PerpendicularVector -
Parameters:dst -[out] Perpendicular Vector.
src -[in] Normalized vector.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void PerpendicularVector( vec3_t dst, const vec3_t src )
{
int pos;
int i;
float minelem = 1.0F;
vec3_t tempvec;
/* find the smallest magnitude axially aligned vector */
for( pos = 0, i = 0 ; i < 3 ; ++i )
{
if( fabs( src[ i ] ) < minelem )
{
pos = i;
minelem = (float)fabs( src[ i ] );
}
}
tempvec[ 0 ] = tempvec[ 1 ] = tempvec[ 2 ] = 0.0F;
tempvec[ pos ] = 1.0F;
/* project the point onto the plane defined by src */
ProjectPointOnPlane( dst, tempvec, src );
/* normalize the result */
pfVectorNormalize( dst );
}
/*
-----------------------------------------------------------------------------
Function: RotatePointAroundVector -Rotate a point around a vector.
Parameters: dst -[out] Point after rotation.
dir -[in] vector.
point -[in] Point.
degrees -[in] Degrees of rotation.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees )
{
mat3_t m;
mat3_t im;
mat3_t zrot;
mat3_t tmpmat;
mat3_t rot;
vec3_t vr, vup, vf;
float rad;
vf[0] = dir[0];
vf[1] = dir[1];
vf[2] = dir[2];
PerpendicularVector( vr, dir );
vectorCrossProduct( vr, vf, vup );
m[0] = vr[0];
m[3] = vr[1];
m[6] = vr[2];
m[1] = vup[0];
m[4] = vup[1];
m[7] = vup[2];
m[2] = vf[0];
m[5] = vf[1];
m[8] = vf[2];
memcpy( im, m, sizeof( im ) );
im[1] = m[3];
im[2] = m[6];
im[3] = m[1];
im[5] = m[7];
im[6] = m[2];
im[7] = m[5];
memset( zrot, 0, sizeof( zrot ) );
zrot[0] = zrot[4] = zrot[8] = 1.0F;
rad = DEG2RAD( degrees );
zrot[0] = (float)cos( rad );
zrot[1] = (float)sin( rad );
zrot[3] = (float)-sin( rad );
zrot[4] = (float)cos( rad );
Matrix3x3Multiply( m, zrot, tmpmat );
Matrix3x3Multiply( tmpmat, im, rot );
dst[0] = rot[0] * point[0] + rot[1] * point[1] + rot[2] * point[2];
dst[1] = rot[3] * point[0] + rot[4] * point[1] + rot[5] * point[2];
dst[2] = rot[6] * point[0] + rot[7] * point[1] + rot[8] * point[2];
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC float RadiusFromBounds( const vec3_t mins, const vec3_t maxs )
{
int i;
vec3_t corner;
float a, b;
for( i = 0; i < 3; ++i )
{
a = (float)fabs( mins[i] );
b = (float)fabs( maxs[i] );
corner[i] = a > b ? a : b;
}
return vectorLength( corner );
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void AddPointToBounds( vec3_t v, vec3_t mins, vec3_t maxs )
{
if ( v[0] < mins[0] )
{
mins[0] = v[0];
}
if ( v[0] > maxs[0])
{
maxs[0] = v[0];
}
if ( v[1] < mins[1] )
{
mins[1] = v[1];
}
if ( v[1] > maxs[1])
{
maxs[1] = v[1];
}
if ( v[2] < mins[2] )
{
mins[2] = v[2];
}
if ( v[2] > maxs[2])
{
maxs[2] = v[2];
}
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up )
{
float angle;
static float sr, sp, sy, cr, cp, cy;
// static to help MS compiler fp bugs
angle = angles[YAW] * ( M_PI*2 / 360 );
sy = (float)sin( angle );
cy = (float)cos( angle );
angle = angles[PITCH] * ( M_PI*2 / 360 );
sp = (float)sin( angle );
cp = (float)cos( angle );
angle = angles[ROLL] * ( M_PI*2 / 360 );
sr = (float)sin( angle );
cr = (float)cos( angle );
if( forward )
{
forward[0] = cp*cy;
forward[1] = cp*sy;
forward[2] = -sp;
}
if( right )
{
right[0] = (-1*sr*sp*cy+-1*cr*-sy);
right[1] = (-1*sr*sp*sy+-1*cr*cy);
right[2] = -1*sr*cp;
}
if( up )
{
up[0] = (cr*sp*cy+-sr*-sy);
up[1] = (cr*sp*sy+-sr*cy);
up[2] = cr*cp;
}
}
/*
-----------------------------------------------------------------------------
Function: vectorCompare -Compares two vectors for equality.
Parameters: v1, v2 -[in] 3d vectors to compare.
Returns: 1 if they are equal, otherwise 0.
Notes:
-----------------------------------------------------------------------------
*/
INLINECALL int vectorCompare( const vec3_t v1, const vec3_t v2 )
{
if( v1[ 0 ] != v2[ 0 ] ||
v1[ 1 ] != v2[ 1 ] ||
v1[ 2 ] != v2[ 2 ] )
{
return 0;
}
return 1;
}
/*
-----------------------------------------------------------------------------
Function: vectorLength -Get the length of a vector.
Parameters: v -[in] 3D vector to get the length of.
Returns: The length of the vector.
Notes:
Since the square of length is a sum of squares, and squares
(of real numbers) are always positive, length is always positive.
The only time the length of a 3D vector is zero is when the vector
is the zero vector.
-----------------------------------------------------------------------------
*/
INLINECALL vec_t vectorLength( const vec3_t v )
{
return (vec_t)pfSqrt( v[ 0 ] * v[ 0 ] + v[ 1 ] * v[ 1 ] + v[ 2 ] * v[ 2 ] );
}
/*
-----------------------------------------------------------------------------
Function: CrossProduct -Calulates the cross product of two vectors.
Parameters: v1, v2 -[in] 3D vectors.
cross -[out] The vector cross product.
Returns: Nothing
Notes:
The vector cross product takes two vector operands to produce a
vector result. The result, like all geometric vectors, has two
properties: length and orientation.
To find a vector perpendicular to a particular plane, compute the
cross product of two vectors in that plane. But there are two
directions perpendicular to the plane. Which one does the cross
product give you? That is determined by the right hand rule.
The cross product of two vectors is perpendicular to both; the right
hand rule picks the one out of two possible perpendicular directions.
Computing Cross Product from Column Matrices:
u × v = ( uj vk - uk vj , uk vi - ui vk , ui vj - uj vi )T
-----------------------------------------------------------------------------
*/
PUBLIC void vectorCrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross )
{
cross[ 0 ] = v1[ 1 ] * v2[ 2 ] - v1[ 2 ] * v2[ 1 ]; // X
cross[ 1 ] = v1[ 2 ] * v2[ 0 ] - v1[ 0 ] * v2[ 2 ]; // Y
cross[ 2 ] = v1[ 0 ] * v2[ 1 ] - v1[ 1 ] * v2[ 0 ]; // Z
}
#if defined(__i386__) && defined(_MSC_VER)
// Taken from an article written by Michael Abrash that originally appeared in
// Dr. Dobb's Journal.
PUBLIC void vectorCrossProduct_asm( const vec3_t v1, const vec3_t v2, vec3_t cross )
{
__asm
{
mov eax, cross
mov ecx, v2
mov edx, v1
;optimized cross product; 22 cycles
fld dword ptr [ecx+4] ;starts & ends on cycle 0
fmul dword ptr [edx+8] ;starts on cycle 1
fld dword ptr [ecx+8] ;starts & ends on cycle 2
fmul dword ptr [edx+0] ;starts on cycle 3
fld dword ptr [ecx+0] ;starts & ends on cycle 4
fmul dword ptr [edx+4] ;starts on cycle 5
fld dword ptr [ecx+8] ;starts & ends on cycle 6
fmul dword ptr [edx+4] ;starts on cycle 7
fld dword ptr [ecx+0] ;starts & ends on cycle 8
fmul dword ptr [edx+8] ;starts on cycle 9
fld dword ptr [ecx+4] ;starts & ends on cycle 10
fmul dword ptr [edx+0] ;starts on cycle 11
fxch st(2) ;no cost
fsubrp st(5),st(0) ;starts on cycle 12
fsubrp st(3),st(0) ;starts on cycle 13
fsubrp st(1),st(0) ;starts on cycle 14
fxch st(2) ;no cost, stalls for cycle 15
fstp dword ptr [eax+0] ;starts on cycle 16, ends on cycle 17
fstp dword ptr [eax+4] ;starts on cycle 18, ends on cycle 19
fstp dword ptr [eax+8] ;starts on cycle 20, ends on cycle 21
}
}
#endif /* __i386__ */
/*
-----------------------------------------------------------------------------
Function: _DotProduct -Calculates the dot product.
Parameters: v1, v2 -[in] 3D vectors to compute dot product.
Returns: the dot product
Notes:
Dot product, which takes two vectors as operands and produces a real
number as its output. Sometimes the dot product is called the inner
product or the scalar product.
The dot product is:
a · b = a1b1 + a2b2 + a3b3
-----------------------------------------------------------------------------
*/
PUBLIC vec_t _vectorDotProduct( const vec3_t v1, const vec3_t v2 )
{
return v1[ 0 ] * v2[ 0 ] + v1[ 1 ] * v2[ 1 ] + v1[ 2 ] * v2[ 2 ];
}
#if defined(__i386__) && defined(_MSC_VER)
// Taken from an article written by Michael Abrash that originally appeared in
// Dr. Dobb's Journal.
PUBLIC vec_t _vectorDotProduct_asm( const vec3_t v1, const vec3_t v2 )
{
float dotret;
__asm
{
mov eax, v2
mov ecx, v1
;optimized dot product; 15 cycles
fld dword ptr [eax+0] ;starts & ends on cycle 0
fmul dword ptr [ecx+0] ;starts on cycle 1
fld dword ptr [eax+4] ;starts & ends on cycle 2
fmul dword ptr [ecx+4] ;starts on cycle 3
fld dword ptr [eax+8] ;starts & ends on cycle 4
fmul dword ptr [ecx+8] ;starts on cycle 5
fxch st(1) ;no cost
faddp st(2),st(0) ;starts on cycle 6, stalls for cycles 7-8
faddp st(1),st(0) ;starts on cycle 9, stalls for cycles 10-12
fstp dword ptr [dotret] ;starts on cycle 13, ends on cycle 14
}
return dotret;
}
#endif /* __i386__ */
/*
-----------------------------------------------------------------------------
Function: _vectorSubtract -Vector Difference.
Parameters: veca, vecb -[in] 3D vectors.
out -[out] The vector difference of vectors A and B.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
INLINECALL void _vectorSubtract( const vec3_t veca, const vec3_t vecb, vec3_t out )
{
out[ 0 ] = veca[ 0 ] - vecb[ 0 ];
out[ 1 ] = veca[ 1 ] - vecb[ 1 ];
out[ 2 ] = veca[ 2 ] - vecb[ 2 ];
}
/*
-----------------------------------------------------------------------------
Function: _vectorAdd -Vector addition.
Parameters: veca, vecb -[in] 3D vectors.
out -[out] The vector sum of vectors A and B
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
INLINECALL void _vectorAdd( const vec3_t veca, const vec3_t vecb, vec3_t out )
{
out[ 0 ] = veca[ 0 ] + vecb[ 0 ];
out[ 1 ] = veca[ 1 ] + vecb[ 1 ];
out[ 2 ] = veca[ 2 ] + vecb[ 2 ];
}
/*
-----------------------------------------------------------------------------
Function: _vectorCopy -Copy a vector.
Parameters: in -[in] Source vector.
out -[out] Destination vector.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
INLINECALL void _vectorCopy( const vec3_t in, vec3_t out )
{
out[ 0 ] = in[ 0 ];
out[ 1 ] = in[ 1 ];
out[ 2 ] = in[ 2 ];
}
/*
-----------------------------------------------------------------------------
Function: _vectorScale -Scale a vector.
Parameters: in -[in] Source vector.
scale -[in] Scale vector.
out -[out] Destination vector.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
INLINECALL void _vectorScale( const vec3_t in, const vec_t scale, vec3_t out )
{
out[ 0 ] = in[ 0 ] * scale;
out[ 1 ] = in[ 1 ] * scale;
out[ 2 ] = in[ 2 ] * scale;
}
/*
-----------------------------------------------------------------------------
Function:
Parameters:
Returns:
Notes:
-----------------------------------------------------------------------------
*/
INLINECALL void _vectorMA( const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc )
{
vecc[ 0 ] = veca[ 0 ] + scale * vecb[ 0 ];
vecc[ 1 ] = veca[ 1 ] + scale * vecb[ 1 ];
vecc[ 2 ] = veca[ 2 ] + scale * vecb[ 2 ];
}
/////////////////////////////////////////////////////////////////////
//
// 2D Vector routines
//
/////////////////////////////////////////////////////////////////////
/*
-----------------------------------------------------------------------------
Function: vector2DCompare -Compares two vectors for equality.
Parameters: v1, v2 -[in] 2d vectors to compare.
Returns: 1 if they are equal, otherwise 0.
Notes:
-----------------------------------------------------------------------------
*/
INLINECALL W32 vector2DCompare( const vec2_t v1, const vec2_t v2 )
{
if( v1[ 0 ] != v2[ 0 ] || v1[ 1 ] != v2[ 1 ] )
{
return 0;
}
return 1;
}
/*
-----------------------------------------------------------------------------
Function: vector2DLength -Get the length of a vector.
Parameters: v -[in] 2D vector to get the length of.
Returns: The length of the vector.
Notes:
-----------------------------------------------------------------------------
*/
INLINECALL vec_t vector2DLength( const vec2_t v )
{
return (vec_t)pfSqrt( v[ 0 ] * v[ 0 ] + v[ 1 ] * v[ 1 ] );
}

125
wolf3d/code/env/vector.h vendored Normal file
View File

@@ -0,0 +1,125 @@
/*
Copyright (C) 2005 Michael Liebscher <johnnycanuck@users.sourceforge.net>
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* vector.h: 2D and 3D vector math routines.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* Portion of this code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#ifndef __VECTOR_H__
#define __VECTOR_H__
typedef float vec_t;
typedef vec_t vec2_t[ 2 ];
typedef vec_t vec3_t[ 3 ];
typedef vec_t vec4_t[ 4 ];
typedef vec_t vec5_t[ 5 ];
extern vec3_t vec3_origin;
/////////////////////////////////////////////////////////////////////
//
// 3D Vector routines
//
/////////////////////////////////////////////////////////////////////
#define vectorClear( a ) ( (a)[ 0 ] = (a)[ 1 ] = (a)[ 2 ] = 0 )
#define vectorNegate( a, b ) ( (b)[ 0 ] = (-a)[ 0 ], (b)[ 1 ] = (-a)[ 1 ], (b)[ 2 ] = (-a)[ 2 ] )
#define vectorSet( v, x, y, z ) ( (v)[ 0 ] = ( x ), (v)[ 1 ] = ( y ), (v)[ 2 ] = ( z ) )
#define vectorInverse( a ) ( (a)[ 0 ] = (-a)[ 0 ], (a)[ 1 ] = (-a)[ 1 ], (a)[ 2 ] = (-a)[ 2 ] )
#if 1
#define DotProduct( x, y ) ( (x)[ 0 ] * (y)[ 0 ] + (x)[ 1 ] * (y)[ 1 ] + (x)[ 2 ] * (y)[ 2 ] )
#define vectorSubtract( a, b, c ) ( (c)[ 0 ] = (a)[ 0 ] - (b)[ 0 ], (c)[ 1 ] = (a)[ 1 ] - (b)[ 1 ], (c)[ 2 ] = (a)[ 2 ] - (b)[ 2 ] )
#define vectorAdd( a, b, c ) ( (c)[ 0 ] = (a)[ 0 ] + (b)[ 0 ], (c)[ 1 ] = (a)[ 1 ] + (b)[ 1 ], (c)[ 2 ] = (a)[ 2 ] + (b)[ 2 ] )
#define vectorCopy( a, b ) ( (b)[ 0 ] = (a)[ 0 ], (b)[ 1 ] = (a)[ 1 ], (b)[ 2 ] = (a)[ 2 ] )
#define vectorScale( v, s, o ) ( (o)[ 0 ] = (v)[ 0 ] * (s),(o)[ 1 ] = (v)[ 1 ] * (s), (o)[ 2 ] = (v)[ 2 ] * (s) )
#define vectorMA( v, s, b, o ) ( (o)[ 0 ] = (v)[ 0 ] + (b)[ 0 ]*(s),(o)[ 1 ] = (v)[ 1 ] + (b)[ 1 ] * (s),(o)[ 2 ] = (v)[ 2 ] + (b)[ 2 ] * (s) )
#else
/* just in case you don't want to use the macros */
#define DotProduct( x, y ) _vectorDotProduct( x, y )
#define vectorSubtract( a, b, c ) _vectorSubtract( a, b, c )
#define vectorAdd( a, b, c ) _vectorAdd( a, b, c )
#define vectorCopy( a, b ) _vectorCopy( a, b )
#define vectorScale( v, s, o ) _vectorScale( v, s, o )
#define vectorMA( v, s, b, o ) _vectorMA( v, s, b, o )
#endif
extern void vectorCrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross );
extern int vectorCompare( const vec3_t v1, const vec3_t v2 );
extern vec_t vectorLength( const vec3_t v );
extern vec_t (*pfVectorNormalize)( vec3_t vec );
extern void angleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up );
extern void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees );
extern void PerpendicularVector( vec3_t dst, const vec3_t src );
extern void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal );
extern void AddPointToBounds( vec3_t v, vec3_t mins, vec3_t maxs );
extern float RadiusFromBounds( const vec3_t mins, const vec3_t maxs );
/////////////////////////////////////////////////////////////////////
//
// 2D Vector routines
//
/////////////////////////////////////////////////////////////////////
#define vector2DClear( a ) ( (a)[ 0 ] = (a)[ 1 ] = 0 )
#define vector2DNegate( a, b ) ( (b)[ 0 ] = (-a)[ 0 ], (b)[ 1 ] = (-a)[ 1 ] )
#define vector2DSet( v, x, y ) ( (v)[ 0 ] = ( x ), (v)[ 1 ] = ( y ) )
#define vector2DInverse( a ) ( (a)[ 0 ] = (-a)[ 0 ], (a)[ 1 ] = (-a)[ 1 ] )
#define vector2DPerpDot( a, b ) ( (a)[ 0 ] * (b)[ 1 ] - (a)[ 1 ] * (b)[ 0 ] )
#define vector2DDotProduct( x, y ) ( (x)[ 0 ] * (y)[ 0 ] + (x)[ 1 ] * (y)[ 1 ] )
#define vector2DSubtract( a, b, c ) ( (c)[ 0 ] = (a)[ 0 ] - (b)[ 0 ], (c)[ 1 ] = (a)[ 1 ] - (b)[ 1 ] )
#define vector2DAdd( a, b, c ) ( (c)[ 0 ] = (a)[ 0 ] + (b)[ 0 ], (c)[ 1 ] = (a)[ 1 ] + (b)[ 1 ] )
#define vector2DCopy( a, b ) ( (b)[ 0 ] = (a)[ 0 ], (b)[ 1 ] = (a)[ 1 ] )
#define vector2DScale( v, s, o ) ( (o)[ 0 ] = (v)[ 0 ] * (s), (o)[ 1 ] = (v)[ 1 ] * (s) )
#define vector2DMA( v, s, b, o ) ( (o)[ 0 ] = (v)[ 0 ] + (b)[ 0 ]*(s), (o)[ 1 ] = (v)[ 1 ] + (b)[ 1 ] * (s) )
extern W32 vector2DCompare( const vec2_t v1, const vec2_t v2 );
extern vec_t vector2DLength( const vec2_t v );
#endif /* __VECTOR_H__ */

68
wolf3d/code/env/video.h vendored Normal file
View File

@@ -0,0 +1,68 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* video.h -- video driver defs.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
/*
Notes:
This module is implemented by vid_sys.c.
*/
#ifndef __VIDEO_H__
#define __VIDEO_H__
typedef struct vrect_s
{
int x, y, width, height;
} vrect_t;
typedef struct
{
unsigned width, height; // coordinates from main game
} viddef_t;
extern viddef_t viddef; // global video state
// Video module initialisation etc
extern void Video_Init( void );
extern void Video_Shutdown( void );
extern void Video_CheckChanges( void );
extern void VID_NewWindow ( int width, int height );
extern _boolean VID_GetModeInfo( int *width, int *height, int mode );
#endif /* __VIDEO_H__ */

241
wolf3d/code/env/wavfile.c vendored Normal file
View File

@@ -0,0 +1,241 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* wav.c: Wav file loader.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#include "../wolfiphone.h"
PRIVATE W8 *iff_pdata;
PRIVATE W8 *iff_end;
PRIVATE W8 *iff_last_chunk;
PRIVATE W8 *iff_data;
PRIVATE int iff_chunk_len;
PRIVATE short Wav_GetLittleShort( void )
{
short val = 0;
val = *iff_pdata;
val += (*(iff_pdata + 1) << 8);
iff_pdata += 2;
return val;
}
PRIVATE int Wav_GetLittleLong( void )
{
int val = 0;
val = *iff_pdata;
val += (*(iff_pdata + 1) << 8);
val += (*(iff_pdata + 2) << 16);
val += (*(iff_pdata + 3) << 24);
iff_pdata += 4;
return val;
}
PRIVATE void Wav_FindNextChunk( const char *name )
{
while( 1 )
{
iff_pdata = iff_last_chunk;
if( iff_pdata >= iff_end )
{
// Didn't find the chunk
iff_pdata = NULL;
return;
}
iff_pdata += 4;
iff_chunk_len = Wav_GetLittleLong();
if( iff_chunk_len < 0 )
{
iff_pdata = NULL;
return;
}
iff_pdata -= 8;
iff_last_chunk = iff_pdata + 8 + ((iff_chunk_len + 1) & ~1);
if( ! my_strnicmp((const char *)iff_pdata, name, 4) )
{
return;
}
}
}
PRIVATE void Wav_FindChunk( const char *name )
{
iff_last_chunk = iff_data;
Wav_FindNextChunk( name );
}
PRIVATE void DumpChunks( void )
{
char str[ 5 ];
str[ 4 ] = 0;
iff_pdata = iff_data;
do
{
memcpy( str, iff_pdata, 4 );
iff_pdata += 4;
iff_chunk_len = Wav_GetLittleLong();
Com_Printf( "0x%x : %s (%d)\n", (int)(iff_pdata - 4), str, iff_chunk_len );
iff_pdata += (iff_chunk_len + 1) & ~1;
} while( iff_pdata < iff_end );
}
/*
-----------------------------------------------------------------------------
Function: LoadWavInfo -Load wav file.
Parameters: filename -[in] Name of wav file to load.
wav -[out] wav data.
info -[out] wav sound info.
Returns: True if file loaded, otherwise false.
Notes: Caller is responsible for freeing wav data by calling Z_Free.
-----------------------------------------------------------------------------
*/
PUBLIC _boolean LoadWavInfo( const char *filename, W8 **wav, soundInfo_t *info )
{
filehandle_t *hFile;
W8 *data;
W32 wavlength;
hFile = FS_OpenFile( filename, 0 );
if( ! hFile )
{
return false;
}
data = (PW8)FS_GetLoadedFilePointer( hFile, SEEK_SET );
wavlength = FS_GetFileSize( hFile );
iff_data = data;
iff_end = data + wavlength;
// look for RIFF signature
Wav_FindChunk( "RIFF" );
if( ! (iff_pdata && ! my_strnicmp( (const char *)iff_pdata + 8, "WAVE", 4 ) ) )
{
Com_DPrintf( "[LoadWavInfo]: Missing RIFF/WAVE chunks (%s)\n", filename );
FS_CloseFile( hFile );
return false;
}
// Get "fmt " chunk
iff_data = iff_pdata + 12;
Wav_FindChunk( "fmt " );
if( ! iff_pdata )
{
Com_DPrintf( "[LoadWavInfo]: Missing fmt chunk (%s)\n", filename );
FS_CloseFile( hFile );
return false;
}
iff_pdata += 8;
if( Wav_GetLittleShort() != 1 )
{
Com_DPrintf( "[LoadWavInfo]: Microsoft PCM format only (%s)\n", filename );
FS_CloseFile( hFile );
return false;
}
info->channels = Wav_GetLittleShort();
info->sample_rate = Wav_GetLittleLong();
iff_pdata += 4;
info->sample_size = Wav_GetLittleShort(); // Bytes Per Sample
if (info->sample_size != 1 && info->sample_size != 2)
{
Com_DPrintf( "[LoadWavInfo]: only 8 and 16 bit WAV files supported (%s)\n", filename );
FS_CloseFile( hFile );
return false;
}
iff_pdata += 2;
// Find data chunk
Wav_FindChunk( "data" );
if( ! iff_pdata )
{
Com_DPrintf( "[LoadWavInfo]: missing 'data' chunk (%s)\n", filename );
FS_CloseFile( hFile );
return false;
}
iff_pdata += 4;
info->samples = Wav_GetLittleLong() / info->sample_size;
if( info->samples <= 0 )
{
Com_DPrintf( "[LoadWavInfo]: file with 0 samples (%s)\n", filename );
FS_CloseFile( hFile );
return false;
}
// Load the data
*wav = Z_Malloc( info->samples * info->sample_size );
memcpy( *wav, data + (iff_pdata - data), info->samples * info->sample_size );
FS_CloseFile( hFile );
return true;
}

54
wolf3d/code/env/wavfile.h vendored Normal file
View File

@@ -0,0 +1,54 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* wav.h: Wav file loader.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
#ifndef __WAV_H__
#define __WAV_H__
// Structure used to describe a sound.
typedef struct
{
W32 sample_rate; // Sample rate in Hz
W32 channels; // Number of Channels (0x01 = Mono, 0x02 = Stereo)
W32 sample_size; // Bytes per sample
// 1 = 8 bit Mono
// 2 = 8 bit Stereo or 16 bit Mono
// 4 = 16 bit Stereo
W32 samples;
} soundInfo_t;
extern _boolean LoadWavInfo( const char *filename, W8 **wav, soundInfo_t *info );
#endif /* __WAV_H__ */

191
wolf3d/code/env/zmem.c vendored Normal file
View File

@@ -0,0 +1,191 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* zmem.c: Zone memory management.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
/*
Notes:
Add the following line in your initization function:
z_chain.next = z_chain.prev = &z_chain;
*/
#include "../wolfiphone.h"
// just cleared malloc with counters now...
#define Z_MAGIC 0x1d1d
PRIVATE int z_count, z_bytes;
zhead_t z_chain;
/*
-----------------------------------------------------------------------------
Function: Z_Free -Deallocates or frees a zone memory block.
Parameters: memblock -[in] Previously allocated zone memory block to be freed.
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Z_Free( void *memblock )
{
zhead_t *z;
z = ( (zhead_t *)memblock ) - 1;
if( z->magic != Z_MAGIC )
{
Com_Error( ERR_FATAL, "Z_Free: bad magic" );
}
z->prev->next = z->next;
z->next->prev = z->prev;
z_count--;
z_bytes -= z->size;
MM_FREE( z );
}
/*
-----------------------------------------------------------------------------
Function: Z_Stats_f -Console function to list zone memory usage.
Parameters: Nothing.
Returns: Nothing.
Notes: Lists number of bytes and blocks of zone memory allocated.
-----------------------------------------------------------------------------
*/
PUBLIC void Z_Stats_f( void )
{
Com_Printf( "%i bytes in %i blocks\n", z_bytes, z_count );
}
/*
-----------------------------------------------------------------------------
Function: Z_FreeTags -Free allocated zone memory blocks based on tag.
Parameters: tag -[in] Tag of zone memory blocks to free (see header for tag).
Returns: Nothing.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void Z_FreeTags( int tag )
{
zhead_t *z, *next;
for( z = z_chain.next; z != &z_chain; z = next )
{
next = z->next;
if( z->tag == tag )
{
Z_Free( (void *)(z+1) );
}
}
}
/*
-----------------------------------------------------------------------------
Function: Z_TagMalloc -Allocates zone memory blocks.
Parameters:
size -[in] Bytes to allocate.
tag -[in] Tag to associate with memory (see header for tag).
Returns:
A void pointer to the allocated space, or will shutdown application
if there is insufficient memory available.
Notes:
-----------------------------------------------------------------------------
*/
PUBLIC void *Z_TagMalloc( size_t size, int tag )
{
zhead_t *z;
// Allocate memory
size += sizeof( zhead_t );
z = MM_MALLOC( size );
if( ! z )
{
Com_Error( ERR_FATAL, "Z_Malloc: failed on allocation of %i bytes", size );
}
// Set memory block to zero and fill in header.
memset( z, 0, size );
z_count++;
z_bytes += size;
z->magic = Z_MAGIC;
z->tag = tag;
z->size = size;
// Add new memory block to chain.
z->next = z_chain.next;
z->prev = &z_chain;
z_chain.next->prev = z;
z_chain.next = z;
return (void *)(z+1);
}
/*
-----------------------------------------------------------------------------
Function: Z_Malloc -Allocates zone memory blocks.
Parameters: size -[in] Bytes to allocate.
Returns:
A void pointer to the allocated space, or will shutdown application
if there is insufficient memory available.
Notes: Calls Z_TagMalloc() with tag set to zero.
-----------------------------------------------------------------------------
*/
PUBLIC void *Z_Malloc( size_t size )
{
return Z_TagMalloc( size, 0 );
}

75
wolf3d/code/env/zmem.h vendored Normal file
View File

@@ -0,0 +1,75 @@
/*
Copyright (C) 2004 Michael Liebscher
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* zmem.h: Zone memory management.
*
* Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
* Date: 2004
*
* Acknowledgement:
* This code was derived from Quake II, and was originally
* written by Id Software, Inc.
*
*/
/*
Notes:
This module is implemented by zmem.c
*/
#ifndef __ZMEM_H__
#define __ZMEM_H__
#include <stdlib.h>
// memory tags to allow dynamic memory to be cleaned up
#define TAG_GAME 765 /* clear when unloading the dll */
#define TAG_LEVEL 766 /* clear when loading a new level */
#define TAG_LEVEL_SCP 767 /* clear when unloading level script */
typedef struct zhead_s
{
struct zhead_s *prev, *next;
short magic;
short tag; // for group free
int size;
} zhead_t;
extern zhead_t z_chain;
// Returns 0 filled memory block
extern void *Z_Malloc( size_t size );
extern void *Z_TagMalloc( size_t size, int tag );
extern void Z_Free( void *memblock );
extern void Z_FreeTags( int tag );
extern void Z_Stats_f( void );
#endif /* __ZMEM_H__ */