Work started on the model loading code; Several other misc fixes and improvements.

- Sprinkled a few ‘const’s around in the original Quake code.
- Changed the Hunk_Alloc API to take an explicit state structure.
- Started work on the 3D model loading code.
This commit is contained in:
Guilherme Lampert 2015-10-30 18:45:37 -02:00
parent ce8cc0721c
commit ce0b363404
31 changed files with 984 additions and 401 deletions

View File

@ -24,6 +24,7 @@ SRC_FILES = \
ps2/vid_ps2.c \
ps2/ref_ps2.c \
ps2/tex_image.c \
ps2/model.c \
ps2/math_funcs.c \
ps2/net_ps2.c \
ps2/main_ps2.c \

View File

@ -64,7 +64,7 @@ int in_impulse;
void KeyDown(kbutton_t * b)
{
int k;
char * c;
const char * c;
c = Cmd_Argv(1);
if (c[0])
@ -100,7 +100,7 @@ void KeyDown(kbutton_t * b)
void KeyUp(kbutton_t * b)
{
int k;
char * c;
const char * c;
unsigned uptime;
c = Cmd_Argv(1);

View File

@ -278,7 +278,7 @@ so when they are typed in at the console, they will need to be forwarded.
*/
void Cmd_ForwardToServer(void)
{
char * cmd;
const char * cmd;
cmd = Cmd_Argv(0);
if (cls.state <= ca_connected || *cmd == '-' || *cmd == '+')
@ -508,7 +508,7 @@ CL_Connect_f
*/
void CL_Connect_f(void)
{
char * server;
const char * server;
if (Cmd_Argc() != 2)
{
@ -696,7 +696,8 @@ void CL_Packet_f(void)
{
char send[2048];
int i, l;
char *in, *out;
const char * in;
char * out;
netadr_t adr;
if (Cmd_Argc() != 3)
@ -898,8 +899,8 @@ Responses to broadcasts, etc
*/
void CL_ConnectionlessPacket(void)
{
char * s;
char * c;
const char * s;
const char * c;
MSG_BeginReading(&net_message);
MSG_ReadLong(&net_message); // skip the -1

View File

@ -165,7 +165,8 @@ keyname_t keynames[] =
void CompleteCommand(void)
{
char *cmd, *s;
const char * cmd;
const char * s;
s = key_lines[edit_line] + 1;
if (*s == '\\' || *s == '/')

View File

@ -23,26 +23,25 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "common/q_common.h"
#define REF_API_VERSION 3
#define REF_API_VERSION 3
#define ENTITY_FLAGS 68
#define POWERSUIT_SCALE 4.0f
#define MAX_DLIGHTS 32
#define MAX_ENTITIES 128
#define MAX_PARTICLES 4096
#define MAX_LIGHTSTYLES 256
#define MAX_DLIGHTS 32
#define MAX_ENTITIES 128
#define MAX_LIGHTSTYLES 256
#define MAX_PARTICLES 4096
#define ENTITY_FLAGS 68
#define POWERSUIT_SCALE 4.0f
#define SHELL_RED_COLOR 0xF2
#define SHELL_GREEN_COLOR 0xD0
#define SHELL_BLUE_COLOR 0xF3
#define SHELL_RG_COLOR 0xDC
#define SHELL_RB_COLOR 0x68
#define SHELL_BG_COLOR 0x78
#define SHELL_DOUBLE_COLOR 0xDF // 223
#define SHELL_HALF_DAM_COLOR 0x90
#define SHELL_CYAN_COLOR 0x72
#define SHELL_WHITE_COLOR 0xD7
#define SHELL_RED_COLOR 0xF2
#define SHELL_GREEN_COLOR 0xD0
#define SHELL_BLUE_COLOR 0xF3
#define SHELL_RG_COLOR 0xDC
#define SHELL_RB_COLOR 0x68
#define SHELL_BG_COLOR 0x78
#define SHELL_DOUBLE_COLOR 0xDF // 223
#define SHELL_HALF_DAM_COLOR 0x90
#define SHELL_CYAN_COLOR 0x72
#define SHELL_WHITE_COLOR 0xD7
//=============================================================================
//
@ -78,7 +77,6 @@ typedef struct entity_s
struct image_s * skin; // NULL for inline skin
int flags;
} entity_t;
typedef struct
@ -155,7 +153,7 @@ typedef struct
// are flood filled to eliminate mip map edge errors, and pics have
// an implicit "pics/" prepended to the name. (a pic name that starts with a
// slash will not use the "pics/" prefix or the ".pcx" postfix)
void (*BeginRegistration)(const char * map);
void (*BeginRegistration)(const char * map_name);
struct model_s * (*RegisterModel)(const char * name);
struct image_s * (*RegisterSkin)(const char * name);
struct image_s * (*RegisterPic)(const char * name);
@ -197,31 +195,32 @@ typedef struct
void (*Sys_Error)(int err_level, const char * str, ...);
void (*Con_Printf)(int print_level, const char * str, ...);
void (*Cmd_AddCommand)(char * name, void (*cmd)(void));
void (*Cmd_RemoveCommand)(char * name);
void (*Cmd_AddCommand)(const char * name, void (*cmd)(void));
void (*Cmd_RemoveCommand)(const char * name);
void (*Cmd_ExecuteText)(cmd_exec_when_t exec_when, const char * text);
int (*Cmd_Argc)(void);
char * (*Cmd_Argv)(int i);
void (*Cmd_ExecuteText)(int exec_when, char * text);
const char * (*Cmd_Argv)(int i);
// files will be memory mapped read only
// the returned buffer may be part of a larger pak file,
// or a discrete file from anywhere in the quake search path
// a -1 return means the file does not exist
// NULL can be passed for buf to just determine existance
int (*FS_LoadFile)(char * name, void ** buf);
int (*FS_LoadFile)(const char * name, void ** buf);
void (*FS_FreeFile)(void * buf);
// gamedir will be the current directory that generated
// files should be stored to, ie: "f:\quake\id1"
char * (*FS_Gamedir)(void);
cvar_t * (*Cvar_Get)(char * name, char * value, int flags);
cvar_t * (*Cvar_Set)(char * name, char * value);
void (*Cvar_SetValue)(char * name, float value);
cvar_t * (*Cvar_Get)(const char * name, const char * value, int flags);
cvar_t * (*Cvar_Set)(const char * name, const char * value);
void (*Cvar_SetValue)(const char * name, float value);
qboolean (*Vid_GetModeInfo)(int * width, int * height, int mode);
void (*Vid_MenuInit)(void);
void (*Vid_NewWindow)(int width, int height);
qboolean (*Vid_GetModeInfo)(int * width, int * height, int mode);
} refimport_t;

View File

@ -37,7 +37,7 @@ typedef struct
extern viddef_t viddef; // global video state
// Video module initialisation etc:
// Video module initialization etc:
void VID_Init(void);
void VID_Shutdown(void);
void VID_MenuInit(void);

View File

@ -18,14 +18,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
//
// LAMPERT 2015-10-29:
// Added 'static' to local data and 'const' to char* pointer parameters.
//
#include "common/q_common.h"
//
// Quake script command processing module
//
void Cmd_ForwardToServer(void);
enum
{
ALIAS_LOOP_COUNT = 16,
@ -39,9 +42,9 @@ typedef struct cmdalias_s
char * value;
} cmdalias_t;
cmdalias_t * cmd_alias;
qboolean cmd_wait;
int alias_count; // for detecting runaway loops
static cmdalias_t * cmd_alias;
static qboolean cmd_wait;
static int alias_count; // for detecting runaway loops
//=============================================================================
@ -62,14 +65,14 @@ void Cmd_Wait_f(void)
/*
=============================================================================
COMMAND BUFFER
COMMAND BUFFER
=============================================================================
*/
sizebuf_t cmd_text;
byte cmd_text_buf[8192];
byte defer_text_buf[8192];
static sizebuf_t cmd_text;
static byte cmd_text_buf[8192];
static byte defer_text_buf[8192];
/*
============
@ -88,10 +91,9 @@ Cbuf_AddText
Adds command text at the end of the buffer
============
*/
void Cbuf_AddText(char * text)
void Cbuf_AddText(const char * text)
{
int l;
l = strlen(text);
if (cmd_text.cursize + l >= cmd_text.maxsize)
@ -111,7 +113,7 @@ Adds a \n to the text
FIXME: actually change the command buffer to do less copying
============
*/
void Cbuf_InsertText(char * text)
void Cbuf_InsertText(const char * text)
{
char * temp;
int templen;
@ -168,19 +170,22 @@ void Cbuf_InsertFromDefer(void)
Cbuf_ExecuteText
============
*/
void Cbuf_ExecuteText(int exec_when, char * text)
void Cbuf_ExecuteText(cmd_exec_when_t exec_when, const char * text)
{
switch (exec_when)
{
case EXEC_NOW:
Cmd_ExecuteString(text);
break;
case EXEC_INSERT:
Cbuf_InsertText(text);
break;
case EXEC_APPEND:
Cbuf_AddText(text);
break;
default:
Com_Error(ERR_FATAL, "Cbuf_ExecuteText: bad exec_when");
}
@ -210,8 +215,10 @@ void Cbuf_Execute(void)
{
if (text[i] == '"')
quotes++;
if (!(quotes & 1) && text[i] == ';')
break; // don't break if inside a quoted string
if (text[i] == '\n')
break;
}
@ -312,8 +319,11 @@ qboolean Cbuf_AddLateCommands(void)
{
s += strlen(COM_Argv(i)) + 1;
}
if (!s)
{
return false;
}
text = Z_Malloc(s + 1);
text[0] = 0;
@ -321,7 +331,9 @@ qboolean Cbuf_AddLateCommands(void)
{
strcat(text, COM_Argv(i));
if (i != argc - 1)
{
strcat(text, " ");
}
}
// pull out the commands
@ -333,9 +345,9 @@ qboolean Cbuf_AddLateCommands(void)
if (text[i] == '+')
{
i++;
for (j = i; (text[j] != '+') && (text[j] != '-') && (text[j] != 0); j++)
;
{
}
c = text[j];
text[j] = 0;
@ -349,7 +361,9 @@ qboolean Cbuf_AddLateCommands(void)
ret = (build[0] != 0);
if (ret)
{
Cbuf_AddText(build);
}
Z_Free(text);
Z_Free(build);
@ -360,7 +374,7 @@ qboolean Cbuf_AddLateCommands(void)
/*
==============================================================================
SCRIPT COMMANDS
SCRIPT COMMANDS
==============================================================================
*/
@ -429,13 +443,15 @@ void Cmd_Alias_f(void)
cmdalias_t * a;
char cmd[1024];
int i, c;
char * s;
const char * s;
if (Cmd_Argc() == 1)
{
Com_Printf("Current alias commands:\n");
for (a = cmd_alias; a; a = a->next)
{
Com_Printf("%s : %s\n", a->name, a->value);
}
return;
}
@ -471,7 +487,9 @@ void Cmd_Alias_f(void)
{
strcat(cmd, Cmd_Argv(i));
if (i != (c - 1))
{
strcat(cmd, " ");
}
}
strcat(cmd, "\n");
@ -481,7 +499,7 @@ void Cmd_Alias_f(void)
/*
=============================================================================
COMMAND EXECUTION
COMMAND EXECUTION
=============================================================================
*/
@ -489,15 +507,14 @@ void Cmd_Alias_f(void)
typedef struct cmd_function_s
{
struct cmd_function_s * next;
char * name;
const char * name;
xcommand_t function;
} cmd_function_t;
static int cmd_argc;
static char * cmd_null_string = "";
static char * cmd_argv[MAX_STRING_TOKENS];
static char cmd_args[MAX_STRING_CHARS];
static cmd_function_t * cmd_functions; // possible commands to execute
static char * cmd_argv[MAX_STRING_TOKENS]; // Strings dynamically allocated with Z_Malloc
static cmd_function_t * cmd_functions; // possible commands to execute
/*
============
@ -514,11 +531,11 @@ int Cmd_Argc(void)
Cmd_Argv
============
*/
char * Cmd_Argv(int arg)
const char * Cmd_Argv(int arg)
{
if ((unsigned)arg >= cmd_argc)
{
return cmd_null_string;
return "";
}
return cmd_argv[arg];
}
@ -530,7 +547,7 @@ Cmd_Args
Returns a single string containing argv(1) to argv(argc()-1)
============
*/
char * Cmd_Args(void)
const char * Cmd_Args(void)
{
return cmd_args;
}
@ -540,14 +557,16 @@ char * Cmd_Args(void)
Cmd_MacroExpandString
======================
*/
char * Cmd_MacroExpandString(char * text)
const char * Cmd_MacroExpandString(const char * text)
{
int i, j, count, len;
qboolean inquote;
char * scan;
static char expanded[MAX_STRING_CHARS];
char temporary[MAX_STRING_CHARS];
char *token, *start;
int i, j, count, len;
qboolean inquote;
const char * scan;
const char * token;
const char * start;
inquote = false;
scan = text;
@ -565,13 +584,17 @@ char * Cmd_MacroExpandString(char * text)
{
if (scan[i] == '"')
inquote ^= 1;
if (inquote)
continue; // don't expand inside quotes
if (scan[i] != '$')
continue;
// scan out the complete macro
start = scan + i + 1;
token = COM_Parse(&start);
token = COM_Parse((char **)&start);
if (!start)
continue;
@ -617,14 +640,16 @@ Parses the given string into command line tokens.
$Cvars will be expanded unless they are in a quoted token
============
*/
void Cmd_TokenizeString(char * text, qboolean macroExpand)
void Cmd_TokenizeString(const char * text, qboolean macroExpand)
{
int i;
char * com_token;
// clear the args from the last string
for (i = 0; i < cmd_argc; i++)
{
Z_Free(cmd_argv[i]);
}
cmd_argc = 0;
cmd_args[0] = 0;
@ -632,6 +657,7 @@ void Cmd_TokenizeString(char * text, qboolean macroExpand)
// macro expand the text
if (macroExpand)
text = Cmd_MacroExpandString(text);
if (!text)
return;
@ -644,13 +670,15 @@ void Cmd_TokenizeString(char * text, qboolean macroExpand)
}
if (*text == '\n')
{ // a newline seperates commands in the buffer
{ // a newline separates commands in the buffer
text++;
break;
}
if (!*text)
{
return;
}
// set cmd_args to everything after the first arg
if (cmd_argc == 1)
@ -662,13 +690,15 @@ void Cmd_TokenizeString(char * text, qboolean macroExpand)
// strip off any trailing whitespace
l = strlen(cmd_args) - 1;
for (; l >= 0; l--)
{
if (cmd_args[l] <= ' ')
cmd_args[l] = 0;
else
break;
}
}
com_token = COM_Parse(&text);
com_token = COM_Parse((char **)&text);
if (!text)
return;
@ -686,7 +716,7 @@ void Cmd_TokenizeString(char * text, qboolean macroExpand)
Cmd_AddCommand
============
*/
void Cmd_AddCommand(char * cmd_name, xcommand_t function)
void Cmd_AddCommand(const char * cmd_name, xcommand_t function)
{
cmd_function_t * cmd;
@ -707,10 +737,10 @@ void Cmd_AddCommand(char * cmd_name, xcommand_t function)
}
}
cmd = Z_Malloc(sizeof(cmd_function_t));
cmd->name = cmd_name;
cmd = Z_Malloc(sizeof(*cmd));
cmd->name = cmd_name;
cmd->function = function;
cmd->next = cmd_functions;
cmd->next = cmd_functions;
cmd_functions = cmd;
}
@ -719,7 +749,7 @@ void Cmd_AddCommand(char * cmd_name, xcommand_t function)
Cmd_RemoveCommand
============
*/
void Cmd_RemoveCommand(char * cmd_name)
void Cmd_RemoveCommand(const char * cmd_name)
{
cmd_function_t *cmd, **back;
@ -765,7 +795,7 @@ qboolean Cmd_Exists(const char * cmd_name)
Cmd_CompleteCommand
============
*/
char * Cmd_CompleteCommand(char * partial)
const char * Cmd_CompleteCommand(const char * partial)
{
cmd_function_t * cmd;
int len;
@ -778,19 +808,29 @@ char * Cmd_CompleteCommand(char * partial)
// check for exact match
for (cmd = cmd_functions; cmd; cmd = cmd->next)
{
if (!strcmp(partial, cmd->name))
return cmd->name;
}
for (a = cmd_alias; a; a = a->next)
{
if (!strcmp(partial, a->name))
return a->name;
}
// check for partial match
for (cmd = cmd_functions; cmd; cmd = cmd->next)
{
if (!strncmp(partial, cmd->name, len))
return cmd->name;
}
for (a = cmd_alias; a; a = a->next)
{
if (!strncmp(partial, a->name, len))
return a->name;
}
return NULL;
}
@ -803,8 +843,10 @@ A complete command line has been parsed, so try to execute it
FIXME: lookupnoadd the token to speed search?
============
*/
void Cmd_ExecuteString(char * text)
void Cmd_ExecuteString(const char * text)
{
extern void Cmd_ForwardToServer(void);
cmd_function_t * cmd;
cmdalias_t * a;
@ -820,11 +862,14 @@ void Cmd_ExecuteString(char * text)
if (!Q_strcasecmp(cmd_argv[0], cmd->name))
{
if (!cmd->function)
{ // forward to server command
{
// forward to server command
Cmd_ExecuteString(va("cmd %s", text));
}
else
{
cmd->function();
}
return;
}
}

View File

@ -909,12 +909,12 @@ void * SZ_GetSpace(sizebuf_t * buf, int length)
return data;
}
void SZ_Write(sizebuf_t * buf, void * data, int length)
void SZ_Write(sizebuf_t * buf, const void * data, int length)
{
memcpy(SZ_GetSpace(buf, length), data, length);
}
void SZ_Print(sizebuf_t * buf, char * data)
void SZ_Print(sizebuf_t * buf, const char * data)
{
int len;
@ -928,7 +928,9 @@ void SZ_Print(sizebuf_t * buf, char * data)
memcpy((byte *)SZ_GetSpace(buf, len - 1) - 1, data, len); // write over trailing 0
}
else
{
memcpy((byte *)SZ_GetSpace(buf, len), data, len);
}
}
//============================================================================

View File

@ -100,8 +100,8 @@ typedef struct sizebuf_s
void SZ_Init(sizebuf_t * buf, byte * data, int length);
void SZ_Clear(sizebuf_t * buf);
void * SZ_GetSpace(sizebuf_t * buf, int length);
void SZ_Write(sizebuf_t * buf, void * data, int length);
void SZ_Print(sizebuf_t * buf, char * data); // strcats onto the sizebuf
void SZ_Write(sizebuf_t * buf, const void * data, int length);
void SZ_Print(sizebuf_t * buf, const char * data); // strcats onto the sizebuf
//============================================================================
@ -352,23 +352,26 @@ The game starts with a Cbuf_AddText ("exec quake.rc\n"); Cbuf_Execute ();
*/
#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
typedef enum
{
EXEC_NOW = 0, // don't return until completed
EXEC_INSERT = 1, // insert at current position, but don't run yet
EXEC_APPEND = 2 // add to end of the command buffer
} cmd_exec_when_t;
void Cbuf_Init(void);
// allocates an initial text buffer that will grow as needed
void Cbuf_AddText(char * text);
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.
void Cbuf_InsertText(char * text);
void Cbuf_InsertText(const 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.
void Cbuf_ExecuteText(int exec_when, char * text);
void Cbuf_ExecuteText(cmd_exec_when_t exec_when, const char * text);
// this can be used in place of either Cbuf_AddText or Cbuf_InsertText
void Cbuf_AddEarlyCommands(qboolean clear);
@ -403,33 +406,33 @@ typedef void (*xcommand_t)(void);
void Cmd_Init(void);
void Cmd_AddCommand(char * cmd_name, xcommand_t function);
void Cmd_AddCommand(const 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
void Cmd_RemoveCommand(char * cmd_name);
void Cmd_RemoveCommand(const char * cmd_name);
qboolean Cmd_Exists(const char * cmd_name);
// used by the cvar code to check for cvar / command name overlap
char * Cmd_CompleteCommand(char * partial);
const char * Cmd_CompleteCommand(const char * partial);
// attempts to match a partial command for automatic command line completion
// returns NULL if nothing fits
int Cmd_Argc(void);
char * Cmd_Argv(int arg);
char * Cmd_Args(void);
const char * Cmd_Argv(int arg);
const 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.
void Cmd_TokenizeString(char * text, qboolean macroExpand);
void Cmd_TokenizeString(const char * text, qboolean macroExpand);
// Takes a null terminated string. Does not need to be /n terminated.
// breaks the string up into arg tokens.
void Cmd_ExecuteString(char * text);
void Cmd_ExecuteString(const char * text);
// Parses a single line of text into arguments and tries to execute it
// as if it was typed at the console

View File

@ -35,7 +35,8 @@ The .pak files are just a linear collapse of a directory tree
typedef struct
{
char name[56];
int filepos, filelen;
int filepos;
int filelen;
} dpackfile_t;
typedef struct
@ -82,10 +83,10 @@ typedef struct
#define ALIAS_VERSION 8
#define MAX_TRIANGLES 4096
#define MAX_VERTS 2048
#define MAX_FRAMES 512
#define MAX_MD2SKINS 32
#define MAX_SKINNAME 64
#define MAX_VERTS 2048
#define MAX_FRAMES 512
#define MAX_MD2SKINS 32
#define MAX_SKINNAME 64
typedef struct
{
@ -105,10 +106,10 @@ typedef struct
byte lightnormalindex;
} dtrivertx_t;
#define DTRIVERTX_V0 0
#define DTRIVERTX_V1 1
#define DTRIVERTX_V2 2
#define DTRIVERTX_LNI 3
#define DTRIVERTX_V0 0
#define DTRIVERTX_V1 1
#define DTRIVERTX_V2 2
#define DTRIVERTX_LNI 3
#define DTRIVERTX_SIZE 4
typedef struct
@ -134,11 +135,11 @@ typedef struct
int skinwidth;
int skinheight;
int framesize; // byte size of each frame
int framesize; // byte size of each frame
int num_skins;
int num_xyz;
int num_st; // greater than num_xyz for seams
int num_st; // greater than num_xyz for seams
int num_tris;
int num_glcmds; // dwords in strip/fan command list
int num_frames;
@ -148,8 +149,7 @@ typedef struct
int ofs_tris; // offset for dtriangles
int ofs_frames; // offset for first frame
int ofs_glcmds;
int ofs_end; // end of file
int ofs_end; // end of file
} dmdl_t;
/*
@ -212,30 +212,29 @@ typedef struct miptex_s
// upper design bounds
// leaffaces, leafbrushes, planes, and verts are still bounded by 16 bit short limits
#define MAX_MAP_MODELS 1024
#define MAX_MAP_BRUSHES 8192
#define MAX_MAP_ENTITIES 2048
#define MAX_MAP_ENTSTRING 0x40000
#define MAX_MAP_TEXINFO 8192
#define MAX_MAP_AREAS 256
#define MAX_MAP_MODELS 1024
#define MAX_MAP_BRUSHES 8192
#define MAX_MAP_ENTITIES 2048
#define MAX_MAP_ENTSTRING 0x40000
#define MAX_MAP_TEXINFO 8192
#define MAX_MAP_AREAS 256
#define MAX_MAP_AREAPORTALS 1024
#define MAX_MAP_PLANES 65536
#define MAX_MAP_NODES 65536
#define MAX_MAP_BRUSHSIDES 65536
#define MAX_MAP_LEAFS 65536
#define MAX_MAP_VERTS 65536
#define MAX_MAP_FACES 65536
#define MAX_MAP_LEAFFACES 65536
#define MAX_MAP_PLANES 65536
#define MAX_MAP_NODES 65536
#define MAX_MAP_BRUSHSIDES 65536
#define MAX_MAP_LEAFS 65536
#define MAX_MAP_VERTS 65536
#define MAX_MAP_FACES 65536
#define MAX_MAP_LEAFFACES 65536
#define MAX_MAP_LEAFBRUSHES 65536
#define MAX_MAP_PORTALS 65536
#define MAX_MAP_EDGES 128000
#define MAX_MAP_SURFEDGES 256000
#define MAX_MAP_LIGHTING 0x200000
#define MAX_MAP_VISIBILITY 0x100000
#define MAX_MAP_PORTALS 65536
#define MAX_MAP_EDGES 128000
#define MAX_MAP_SURFEDGES 256000
#define MAX_MAP_LIGHTING 0x200000
#define MAX_MAP_VISIBILITY 0x100000
// key / value pair sizes
#define MAX_KEY 32
#define MAX_KEY 32
#define MAX_VALUE 1024
//=============================================================================
@ -246,26 +245,26 @@ typedef struct
int filelen;
} lump_t;
#define LUMP_ENTITIES 0
#define LUMP_PLANES 1
#define LUMP_VERTEXES 2
#define LUMP_VISIBILITY 3
#define LUMP_NODES 4
#define LUMP_TEXINFO 5
#define LUMP_FACES 6
#define LUMP_LIGHTING 7
#define LUMP_LEAFS 8
#define LUMP_LEAFFACES 9
#define LUMP_ENTITIES 0
#define LUMP_PLANES 1
#define LUMP_VERTEXES 2
#define LUMP_VISIBILITY 3
#define LUMP_NODES 4
#define LUMP_TEXINFO 5
#define LUMP_FACES 6
#define LUMP_LIGHTING 7
#define LUMP_LEAFS 8
#define LUMP_LEAFFACES 9
#define LUMP_LEAFBRUSHES 10
#define LUMP_EDGES 11
#define LUMP_SURFEDGES 12
#define LUMP_MODELS 13
#define LUMP_BRUSHES 14
#define LUMP_BRUSHSIDES 15
#define LUMP_POP 16
#define LUMP_AREAS 17
#define LUMP_EDGES 11
#define LUMP_SURFEDGES 12
#define LUMP_MODELS 13
#define LUMP_BRUSHES 14
#define LUMP_BRUSHSIDES 15
#define LUMP_POP 16
#define LUMP_AREAS 17
#define LUMP_AREAPORTALS 18
#define HEADER_LUMPS 19
#define HEADER_LUMPS 19
typedef struct
{
@ -314,49 +313,49 @@ typedef struct
// these definitions also need to be in q_shared.h!
// lower bits are stronger, and will eat weaker brushes completely
#define CONTENTS_SOLID 1 // an eye is never valid in a solid
#define CONTENTS_WINDOW 2 // translucent, but not watery
#define CONTENTS_AUX 4
#define CONTENTS_LAVA 8
#define CONTENTS_SLIME 16
#define CONTENTS_WATER 32
#define CONTENTS_MIST 64
#define CONTENTS_SOLID 1 // an eye is never valid in a solid
#define CONTENTS_WINDOW 2 // translucent, but not watery
#define CONTENTS_AUX 4
#define CONTENTS_LAVA 8
#define CONTENTS_SLIME 16
#define CONTENTS_WATER 32
#define CONTENTS_MIST 64
#define LAST_VISIBLE_CONTENTS 64
// remaining contents are non-visible, and don't eat brushes
#define CONTENTS_AREAPORTAL 0x8000
#define CONTENTS_PLAYERCLIP 0x10000
#define CONTENTS_MONSTERCLIP 0x20000
#define CONTENTS_AREAPORTAL 0x8000
#define CONTENTS_PLAYERCLIP 0x10000
#define CONTENTS_MONSTERCLIP 0x20000
// currents can be added to any other contents, and may be mixed
#define CONTENTS_CURRENT_0 0x40000
#define CONTENTS_CURRENT_90 0x80000
#define CONTENTS_CURRENT_180 0x100000
#define CONTENTS_CURRENT_270 0x200000
#define CONTENTS_CURRENT_UP 0x400000
#define CONTENTS_CURRENT_0 0x40000
#define CONTENTS_CURRENT_90 0x80000
#define CONTENTS_CURRENT_180 0x100000
#define CONTENTS_CURRENT_270 0x200000
#define CONTENTS_CURRENT_UP 0x400000
#define CONTENTS_CURRENT_DOWN 0x800000
#define CONTENTS_ORIGIN 0x1000000 // removed before bsping an entity
#define CONTENTS_MONSTER 0x2000000 // should never be on a brush, only in game
#define CONTENTS_DEADMONSTER 0x4000000
#define CONTENTS_DETAIL 0x8000000 // brushes to be added after vis leafs
#define CONTENTS_TRANSLUCENT 0x10000000 // auto set if any surface has trans
#define CONTENTS_LADDER 0x20000000
#define CONTENTS_ORIGIN 0x1000000 // removed before bsping an entity
#define CONTENTS_MONSTER 0x2000000 // should never be on a brush, only in game
#define CONTENTS_DEADMONSTER 0x4000000
#define CONTENTS_DETAIL 0x8000000 // brushes to be added after vis leafs
#define CONTENTS_TRANSLUCENT 0x10000000 // auto set if any surface has trans
#define CONTENTS_LADDER 0x20000000
#define SURF_LIGHT 0x1 // value will hold the light strength
#define SURF_SLICK 0x2 // effects game physics
#define SURF_SKY 0x4 // don't draw, but add to skybox
#define SURF_WARP 0x8 // turbulent water warp
#define SURF_TRANS33 0x10
#define SURF_TRANS66 0x20
#define SURF_FLOWING 0x40 // scroll towards angle
#define SURF_NODRAW 0x80 // don't bother referencing the texture
#define SURF_LIGHT 0x1 // value will hold the light strength
#define SURF_SLICK 0x2 // effects game physics
#define SURF_SKY 0x4 // don't draw, but add to skybox
#define SURF_WARP 0x8 // turbulent water warp
#define SURF_TRANS33 0x10
#define SURF_TRANS66 0x20
#define SURF_FLOWING 0x40 // scroll towards angle
#define SURF_NODRAW 0x80 // don't bother referencing the texture
typedef struct
{
int planenum;
int children[2]; // negative numbers are -(leafs+1), not nodes
short mins[3]; // for frustom culling
short mins[3]; // for frustum culling
short maxs[3];
unsigned short firstface;
unsigned short numfaces; // counting both sides
@ -424,7 +423,7 @@ typedef struct
int contents;
} dbrush_t;
#define ANGLE_UP -1
#define ANGLE_UP -1
#define ANGLE_DOWN -2
// the visibility lump consists of a header with a count, then

View File

@ -8,7 +8,7 @@ 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.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@ -150,7 +150,7 @@ Give items to a client
*/
void Cmd_Give_f(edict_t * ent)
{
char * name;
const char * name;
gitem_t * it;
int index;
int i;
@ -392,7 +392,7 @@ void Cmd_Use_f(edict_t * ent)
{
int index;
gitem_t * it;
char * s;
const char * s;
s = gi.args();
it = FindItem(s);
@ -427,7 +427,7 @@ void Cmd_Drop_f(edict_t * ent)
{
int index;
gitem_t * it;
char * s;
const char * s;
s = gi.args();
it = FindItem(s);
@ -780,7 +780,7 @@ void Cmd_Say_f(edict_t * ent, qboolean team, qboolean arg0)
{
int i, j;
edict_t * other;
char * p;
const char * p;
char text[2048];
gclient_t * cl;
@ -805,12 +805,15 @@ void Cmd_Say_f(edict_t * ent, qboolean team, qboolean arg0)
{
p = gi.args();
if (*p == '"')
if (*p == '"') // Copy ignoring quotes
{
p++;
p[strlen(p) - 1] = 0;
strncat(text, p, strlen(p) - 1);
}
else
{
strcat(text, p);
}
strcat(text, p);
}
// don't let text be too long for malicious reasons
@ -903,7 +906,7 @@ ClientCommand
*/
void ClientCommand(edict_t * ent)
{
char * cmd;
const char * cmd;
if (!ent->client)
return; // not fully in game yet

View File

@ -8,7 +8,7 @@ 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.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@ -69,10 +69,9 @@ gitem_t * GetItemByIndex(int index)
/*
===============
FindItemByClassname
===============
*/
gitem_t * FindItemByClassname(char * classname)
gitem_t * FindItemByClassname(const char * classname)
{
int i;
gitem_t * it;
@ -92,10 +91,9 @@ gitem_t * FindItemByClassname(char * classname)
/*
===============
FindItem
===============
*/
gitem_t * FindItem(char * pickup_name)
gitem_t * FindItem(const char * pickup_name)
{
int i;
gitem_t * it;

View File

@ -575,12 +575,13 @@ void Cmd_Score_f(edict_t * ent);
//
// g_items.c
//
#define ITEM_INDEX(x) ((x)-itemlist)
gitem_t * FindItem(const char * pickup_name);
gitem_t * FindItemByClassname(const char * classname);
void PrecacheItem(gitem_t * it);
void InitItems(void);
void SetItemNames(void);
gitem_t * FindItem(char * pickup_name);
gitem_t * FindItemByClassname(char * classname);
#define ITEM_INDEX(x) ((x)-itemlist)
edict_t * Drop_Item(edict_t * ent, gitem_t * item);
void SetRespawn(edict_t * ent, float delay);
void ChangeWeapon(edict_t * ent);

View File

@ -8,7 +8,7 @@ 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.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@ -29,7 +29,7 @@ void Svcmd_Test_f(void)
==============================================================================
PACKET FILTERING
You can add or remove addresses from the filter list with:
@ -62,17 +62,20 @@ typedef struct
unsigned compare;
} ipfilter_t;
#define MAX_IPFILTERS 1024
enum
{
MAX_IPFILTERS = 1024
};
ipfilter_t ipfilters[MAX_IPFILTERS];
int numipfilters;
static ipfilter_t ipfilters[MAX_IPFILTERS];
static int numipfilters;
/*
=================
StringToFilter
=================
*/
static qboolean StringToFilter(char * s, ipfilter_t * f)
static qboolean StringToFilter(const char * s, ipfilter_t * f)
{
char num[128];
int i, j;
@ -202,6 +205,7 @@ void SVCmd_RemoveIP_f(void)
return;
for (i = 0; i < numipfilters; i++)
{
if (ipfilters[i].mask == f.mask && ipfilters[i].compare == f.compare)
{
for (j = i + 1; j < numipfilters; j++)
@ -210,6 +214,7 @@ void SVCmd_RemoveIP_f(void)
gi.cprintf(NULL, PRINT_HIGH, "Removed.\n");
return;
}
}
gi.cprintf(NULL, PRINT_HIGH, "Didn't find %s.\n", gi.argv(2));
}
@ -282,7 +287,7 @@ of the parameters
*/
void ServerCommand(void)
{
char * cmd;
const char * cmd;
cmd = gi.argv(1);
if (Q_stricmp(cmd, "test") == 0)

View File

@ -181,12 +181,12 @@ typedef struct
// ClientCommand and ServerCommand parameter access
int (*argc)(void);
char * (*argv)(int n);
char * (*args)(void); // concatenation of all argv >= 1
const char * (*argv)(int n);
const char * (*args)(void); // concatenation of all argv >= 1
// add commands to the server console as if they were typed in
// for map changing, etc
void (*AddCommandString)(char * text);
void (*AddCommandString)(const char * text);
void (*DebugGraph)(float value, int color);
} game_import_t;

View File

@ -244,16 +244,44 @@ SYSTEM SPECIFIC
==============================================================
*/
extern int curtime; // time returned by last Sys_Milliseconds
//
// Large block stack allocation API
//
typedef struct
{
byte * base_ptr;
int max_size;
int curr_size;
} mem_hunk_t;
int Sys_Milliseconds(void);
void Sys_Mkdir(char * path);
// Allocate/free a new hunk of memory (allocation is zero filled).
void Hunk_New(mem_hunk_t * hunk, int max_size);
void Hunk_Free(mem_hunk_t * hunk);
// large block stack allocation routines
// Fetch a new slice from the hunk's end.
byte * Hunk_BlockAlloc(mem_hunk_t * hunk, int block_size);
// Get the offset to the end of the allocated region.
int Hunk_GetTail(mem_hunk_t * hunk);
// LAMPERT 2015-10-30:
// Original Hunk allocator API used by Quake2
// relied on global data. We provide a cleaner
// global-state-free replacement.
/*
void * Hunk_Begin(int maxsize);
void * Hunk_Alloc(int size);
void Hunk_Free(void * buf);
int Hunk_End(void);
*/
//=============================================
// time returned by last Sys_Milliseconds
extern int curtime;
int Sys_Milliseconds(void);
void Sys_Mkdir(const char * path);
// directory searching
#define SFF_ARCH 0x01
@ -265,7 +293,7 @@ int Hunk_End(void);
/*
** pass in an attribute mask of things you wish to REJECT
*/
char * Sys_FindFirst(char * path, unsigned musthave, unsigned canthave);
char * Sys_FindFirst(const char * path, unsigned musthave, unsigned canthave);
char * Sys_FindNext(unsigned musthave, unsigned canthave);
void Sys_FindClose(void);

View File

@ -27,6 +27,10 @@ unsigned sys_frame_time;
//=============================================================================
void Sys_Init(void)
{
}
void Sys_Error(const char * error, ...)
{
va_list argptr;
@ -80,6 +84,33 @@ char * Sys_GetClipboardData(void)
return NULL;
}
int Sys_Milliseconds(void)
{
return 0;
}
void Sys_Mkdir(const char * path)
{
}
char * Sys_FindFirst(const char * path, unsigned musthave, unsigned canthave)
{
return NULL;
}
char * Sys_FindNext(unsigned musthave, unsigned canthave)
{
return NULL;
}
void Sys_FindClose(void)
{
}
//=============================================================================
// Old Quake2 Hunk alloc API, now replaced.
/*
void * Hunk_Begin(int maxsize)
{
return NULL;
@ -98,39 +129,11 @@ int Hunk_End(void)
{
return 0;
}
int Sys_Milliseconds(void)
{
return 0;
}
void Sys_Mkdir(char * path)
{
}
char * Sys_FindFirst(char * path, unsigned musthave, unsigned canthave)
{
return NULL;
}
char * Sys_FindNext(unsigned musthave, unsigned canthave)
{
return NULL;
}
void Sys_FindClose(void)
{
}
void Sys_Init(void)
{
}
*/
//=============================================================================
//
// QPS2-Null:
//
//=============================================================================
#ifdef PS2_QUAKE
// This is missing on the PS2
struct tm * localtime(const time_t * timep)
@ -145,9 +148,12 @@ int rename(const char * a, const char * b)
return -1;
}
#endif // PS2_QUAKE
//=============================================================================
int main(/*int argc, char ** argv*/)
{
// PS2 main() takes no arguments.
int argc = 1;
char * argv[] = { "NULL_SYS" };
Qcommon_Init(argc, argv);

View File

@ -107,7 +107,7 @@ int main(void)
char * argv[] = { "QPS2.ELF" };
Qcommon_Init(argc, argv);
Cbuf_AddText((char *)all_menu_names[next_menu]);
//Cbuf_AddText(all_menu_names[next_menu]);
oldtime = Sys_Milliseconds();
for (;;)
@ -122,14 +122,16 @@ int main(void)
Qcommon_Frame(time);
oldtime = newtime;
/*
//TEST cycling all the menus
if (time_til_next_menu <= 0 && next_menu < NUM_MENUS)
{
Cbuf_AddText((char *)all_menu_names[next_menu++]);
Cbuf_AddText(all_menu_names[next_menu++]);
time_til_next_menu = MENU_MSEC;
}
time_til_next_menu -= time;
//TEST cycling all the menus
*/
}
#endif //0

View File

@ -11,6 +11,8 @@
* ================================================================================================ */
#include "ps2/mem_alloc.h"
#include "game/q_shared.h" // For mem_hunk_t
#include <stdlib.h>
#include <string.h>
@ -180,56 +182,21 @@ const char * PS2_FormatMemoryUnit(unsigned int size_bytes, int abbreviated)
//=============================================================================
//
// Hunk memory allocator (similar to a stack), used by the Game and FS:
// Hunk memory allocator (similar to a stack), used by the Game and Renderer:
//
//=============================================================================
static int hunk_count = 0;
static int hunk_max_size = 0;
static int hunk_curr_size = 0;
static char * hunk_mem_base = NULL;
/*
================
Hunk_Begin
Hunk_New
================
*/
void * Hunk_Begin(int maxsize)
void Hunk_New(mem_hunk_t * hunk, int max_size)
{
hunk_curr_size = 0;
hunk_max_size = maxsize;
hunk_mem_base = PS2_MemAlloc(maxsize, MEMTAG_HUNK_ALLOC);
memset(hunk_mem_base, 0, maxsize);
return hunk_mem_base;
}
/*
================
Hunk_End
================
*/
int Hunk_End(void)
{
++hunk_count;
return hunk_curr_size;
}
/*
================
Hunk_Alloc
================
*/
void * Hunk_Alloc(int size)
{
size = (size + 31) & ~31; // round to cacheline
hunk_curr_size += size;
if (hunk_curr_size > hunk_max_size)
{
Sys_Error("Hunk_Alloc: Overflowed!");
}
return hunk_mem_base + hunk_curr_size - size;
hunk->curr_size = 0;
hunk->max_size = max_size;
hunk->base_ptr = PS2_MemAlloc(max_size, MEMTAG_HUNK_ALLOC);
memset(hunk->base_ptr, 0, max_size);
}
/*
@ -237,11 +204,41 @@ void * Hunk_Alloc(int size)
Hunk_Free
================
*/
void Hunk_Free(void * base)
void Hunk_Free(mem_hunk_t * hunk)
{
if (base != NULL)
if (hunk->base_ptr != NULL)
{
PS2_MemFree(base, hunk_max_size, MEMTAG_HUNK_ALLOC);
PS2_MemFree(hunk->base_ptr, hunk->max_size, MEMTAG_HUNK_ALLOC);
PS2_MemClearObj(hunk);
}
--hunk_count;
}
/*
================
Hunk_BlockAlloc
================
*/
byte * Hunk_BlockAlloc(mem_hunk_t * hunk, int block_size)
{
// This is the way Quake2 does it, so I ain't changing it...
block_size = (block_size + 31) & ~31; // round to cacheline
// The hunk stack doesn't resize.
hunk->curr_size += block_size;
if (hunk->curr_size > hunk->max_size)
{
Sys_Error("Hunk_BlockAlloc: Overflowed with %d bytes request!", block_size);
}
return hunk->base_ptr + hunk->curr_size - block_size;
}
/*
================
Hunk_GetTail
================
*/
int Hunk_GetTail(mem_hunk_t * hunk)
{
return hunk->curr_size;
}

116
src/ps2/model.c Normal file
View File

@ -0,0 +1,116 @@
/* ================================================================================================
* -*- C -*-
* File: model.c
* Author: Guilherme R. Lampert
* Created on: 29/10/15
* Brief: 3D model loading routines.
*
* This source code is released under the GNU GPL v2 license.
* Check the accompanying LICENSE file for details.
* ================================================================================================ */
#include "ps2/model.h"
//=============================================================================
// Local data:
enum { MDL_POOL_SIZE = 512 };
// Pool of models used by world/entities/sprites:
static u32 model_pool_used = 0;
static ps2_model_t model_pool[MDL_POOL_SIZE];
// The inline * models from the current map are kept separate.
// These are only referenced by the world geometry.
static ps2_model_t inline_models[MDL_POOL_SIZE];
//=============================================================================
// Used to hash the model filenames.
extern u32 Sys_HashString(const char * str);
/*
==============
PS2_ModelInit
==============
*/
void PS2_ModelInit(void)
{
if (model_pool_used != 0)
{
Sys_Error("Invalid PS2_ModelInit call!");
}
//TODO
}
/*
==============
PS2_ModelShutdown
==============
*/
void PS2_ModelShutdown(void)
{
//TODO
// free all models, etc
memset(model_pool, 0, sizeof(model_pool));
memset(inline_models, 0, sizeof(inline_models));
model_pool_used = 0;
}
/*
==============
PS2_ModelAlloc
==============
*/
ps2_model_t * PS2_ModelAlloc(void)
{
if (model_pool_used == MDL_POOL_SIZE)
{
Sys_Error("Out of model objects!!!");
}
//TODO assume always sequential, or allow empty gaps???
// -- should also look into the registration_sequence trick used by ref_gl
return &model_pool[model_pool_used++];
}
/*
==============
PS2_ModelFindOrLoad
==============
*/
ps2_model_t * PS2_ModelFindOrLoad(const char * name, int flags)
{
if (name == NULL || *name == '\0')
{
Com_DPrintf("FindModel: Null/empty model name!");
return NULL;
}
//TODO
return NULL;
}
/*
==============
PS2_ModelLoadWorld
==============
*/
ps2_model_t * PS2_ModelLoadWorld(const char * name)
{
//TODO
return NULL;
}
/*
==============
PS2_ModelFree
==============
*/
void PS2_ModelFree(ps2_model_t * mdl)
{
//TODO
}

298
src/ps2/model.h Normal file
View File

@ -0,0 +1,298 @@
/* ================================================================================================
* -*- C -*-
* File: model.h
* Author: Guilherme R. Lampert
* Created on: 29/10/15
* Brief: Declarations related to 3D model loading and handling for entities and world/level.
* Structured found here were mostly adapted from 'ref_gl/gl_model.h'
*
* This source code is released under the GNU GPL v2 license.
* Check the accompanying LICENSE file for details.
* ================================================================================================ */
#ifndef PS2_MODEL_H
#define PS2_MODEL_H
#include "ps2/ref_ps2.h"
enum
{
// Plane sides:
SIDE_FRONT = 0,
SIDE_BACK = 1,
SIDE_ON = 2,
// Misc surface flags (same values used by ref_gl):
SURF_PLANEBACK = 2,
SURF_DRAWSKY = 4,
SURF_DRAWTURB = 16,
SURF_DRAWBACKGROUND = 64,
SURF_UNDERWATER = 128,
// Number of element in the poly vertex.
POLY_VERTEX_SIZE = 7
};
/*
==============================================================
In-memory representation of 3D models (world and entities):
==============================================================
*/
/*
* Model vertex position:
*/
typedef struct ps2_mdl_vertex_s
{
vec3_t position;
} ps2_mdl_vertex_t;
/*
* Sub-model mesh data:
*/
typedef struct ps2_mdl_sub_s
{
vec3_t mins;
vec3_t maxs;
vec3_t origin;
float radius;
int head_node;
int vis_leafs;
int first_face;
int num_faces;
} ps2_mdl_sub_t;
/*
* Edge description:
*/
typedef struct ps2_mdl_edge_s
{
u16 v[2]; // vertex numbers
u32 cached_edge_offset;
} ps2_mdl_edge_t;
/*
* Texture/material description:
*/
typedef struct ps2_mdl_texinfo_s
{
float vecs[2][4];
int flags;
int num_frames;
ps2_teximage_t * teximage;
struct ps2_mdl_texinfo_s * next; // animation chain
} ps2_mdl_texinfo_t;
/*
* Model polygon/face:
* List links are for draw sorting.
*/
typedef struct ps2_mdl_poly_s
{
struct ps2_mdl_poly_s * next;
struct ps2_mdl_poly_s * chain;
int flags; // for SURF_UNDERWATER (not needed anymore?)
int num_verts;
float verts[4][POLY_VERTEX_SIZE]; // variable sized (xyz s1t1 s2t2)
} ps2_mdl_poly_t;
/*
* Surface description:
* (holds a set of polygons)
*/
typedef struct ps2_mdl_surface_s
{
int vis_frame; // should be drawn when node is crossed
cplane_t * plane;
int flags;
int first_edge; // look up in model->surfedges[], negative numbers
int num_edges; // are backwards edges
s16 texture_mins[2];
s16 extents[2];
int light_s, light_t; // lightmap tex coordinates
int dlight_s, dlight_t; // lightmap tex coordinates for dynamic lightmaps
ps2_mdl_poly_t * polys; // multiple if warped
struct ps2_mdl_surface_s * texture_chain;
struct ps2_mdl_surface_s * lightmap_chain;
ps2_mdl_texinfo_t * texinfo;
// dynamic lighting info:
int dlight_frame;
int dlight_bits;
int lightmap_texture_num;
byte styles[MAXLIGHTMAPS];
float cached_light[MAXLIGHTMAPS]; // values currently used in lightmap
byte * samples; // [numstyles*surfsize]
} ps2_mdl_surface_t;
/*
* BSP world node:
*/
typedef struct ps2_mdl_node_s
{
// common with leaf
int contents; // -1, to differentiate from leafs
int vis_frame; // node needs to be traversed if current
// for bounding box culling
float minmaxs[6];
struct ps2_mdl_node_s * parent;
// node specific
cplane_t * plane;
struct ps2_mdl_node_s * children[2];
u16 first_surface;
u16 num_surfaces;
} ps2_mdl_node_t;
/*
* Special BSP leaf node (draw node):
*/
typedef struct ps2_mdl_leaf_s
{
// common with node
int contents; // will be a negative contents number
int vis_frame; // node needs to be traversed if current
// for bounding box culling
float minmaxs[6];
struct ps2_mdl_node_s * parent;
// leaf specific
int cluster;
int area;
ps2_mdl_surface_t ** first_mark_surface;
int num_mark_surfaces;
} ps2_mdl_leaf_t;
/*
* Misc model type flags:
*/
typedef enum
{
MDL_BRUSH = (1 << 1),
MDL_SPRITE = (1 << 2),
MDL_ENTITY = (1 << 3)
} ps2_mdl_type_t;
/*
==============================================================
Whole model (world or entity/sprite):
==============================================================
*/
typedef struct ps2_model_s
{
ps2_mdl_type_t type;
int num_frames;
int flags;
// Volume occupied by the model graphics.
vec3_t mins;
vec3_t maxs;
float radius;
// Solid volume for clipping.
qboolean clipbox;
vec3_t clipmins;
vec3_t clipmaxs;
// Brush model.
int first_model_surface;
int num_model_surfaces;
int lightmap; // Only for submodels
int num_submodels;
ps2_mdl_sub_t * submodels;
int num_planes;
cplane_t * planes;
int num_leafs; // Number of visible leafs, not counting 0
ps2_mdl_leaf_t * leafs;
int num_vertexes;
ps2_mdl_vertex_t * vertexes;
int num_edges;
ps2_mdl_edge_t * edges;
int num_nodes;
int first_node;
ps2_mdl_node_t * nodes;
int num_texinfos;
ps2_mdl_texinfo_t * texinfos;
int num_surfaces;
ps2_mdl_surface_t * surfaces;
int num_surf_edges;
int * surf_edges;
int num_mark_surfaces;
ps2_mdl_surface_t ** mark_surfaces;
dvis_t * vis;
byte * light_data;
// For alias models and skins.
ps2_teximage_t * skins[MAX_MD2SKINS];
// Registration number, so we know if it is currently referenced by the level being played.
int registration_sequence;
// Memory hunk backing the model's data.
mem_hunk_t hunk;
// Hash of the following name string, for faster lookup.
u32 hash;
// File name with path.
char name[MAX_QPATH];
} ps2_model_t;
/*
==============================================================
Public model loading/management functions:
==============================================================
*/
// Global initialization/shutdown:
void PS2_ModelInit(void);
void PS2_ModelShutdown(void);
// Allocate a blank model from the pool.
// Fails with a Sys_Error if no more slots are available.
ps2_model_t * PS2_ModelAlloc(void);
// Looks up an already loaded model or tries to load it from disk for the first time.
ps2_model_t * PS2_ModelFindOrLoad(const char * name, int flags);
// Loads the world model used by the current level the game wants.
// The returned pointer points to an internal shared instance, so
// only one world model is allowed at any time.
ps2_model_t * PS2_ModelLoadWorld(const char * name);
// Frees a model previously acquired from FindOrLoad.
void PS2_ModelFree(ps2_model_t * mdl);
#endif // PS2_MODEL_H

View File

@ -11,6 +11,7 @@
* ================================================================================================ */
#include "ps2/ref_ps2.h"
#include "ps2/model.h"
#include "ps2/mem_alloc.h"
// PS2DEV SDK:
@ -149,6 +150,8 @@ extern void Sys_Error(const char * error, ...);
/*
================
PS2_VRamAlloc
Remarks: Local function.
================
*/
static int PS2_VRamAlloc(int width, int height, int psm, int alignment)
@ -168,6 +171,8 @@ static int PS2_VRamAlloc(int width, int height, int psm, int alignment)
/*
================
PS2_InitGSBuffers
Remarks: Local function.
================
*/
static void PS2_InitGSBuffers(int vidMode, int fbPsm, int zPsm, qboolean interlaced)
@ -244,6 +249,8 @@ static void PS2_InitGSBuffers(int vidMode, int fbPsm, int zPsm, qboolean interla
/*
================
PS2_InitDrawingEnvironment
Remarks: Local function.
================
*/
static void PS2_InitDrawingEnvironment(void)
@ -276,6 +283,8 @@ static void PS2_InitDrawingEnvironment(void)
/*
================
PS2_ClearScreen
Remarks: Local function.
================
*/
static void PS2_ClearScreen(void)
@ -302,6 +311,8 @@ static void PS2_ClearScreen(void)
/*
================
PS2_Draw2DBegin
Remarks: Local function.
================
*/
static void PS2_Draw2DBegin(void)
@ -319,6 +330,8 @@ static void PS2_Draw2DBegin(void)
/*
================
PS2_Draw2DEnd
Remarks: Local function.
================
*/
static void PS2_Draw2DEnd(void)
@ -335,6 +348,8 @@ static void PS2_Draw2DEnd(void)
/*
================
PS2_FlushPipeline
Remarks: Local function.
================
*/
static void PS2_FlushPipeline(void)
@ -360,6 +375,8 @@ static void PS2_FlushPipeline(void)
/*
================
PS2_Draw2DAddToPacket
Remarks: Local function.
================
*/
enum elem2d_type
@ -444,12 +461,13 @@ static qword_t * PS2_Draw2DAddToPacket(qword_t * qwptr, const screen_quad_t * qu
/*
================
PS2_Draw2DTexChange
Only called by PS2_SortAndDraw2DElements.
Remarks: Local function.
================
*/
static void PS2_Draw2DTexChange(u32 tex_index)
{
// This is only called by PS2_SortAndDraw2DElements.
if (tex_index > MAX_TEXIMAGES)
{
Sys_Error("PS2_Draw2DTexChange: Invalid tex_index %d!!!", (int)tex_index);
@ -482,6 +500,9 @@ static void PS2_Draw2DTexChange(u32 tex_index)
/*
================
PS2_Draw2DBatchSortPredicate
Passed as callback to qsort().
Remarks: Local function.
================
*/
static int PS2_Draw2DBatchSortPredicate(const void * a, const void * b)
@ -505,6 +526,8 @@ static int PS2_Draw2DBatchSortPredicate(const void * a, const void * b)
/*
================
PS2_SortAndDraw2DElements
Remarks: Local function.
================
*/
static void PS2_SortAndDraw2DElements(screen_quad_t * batch, int batch_size)
@ -556,6 +579,8 @@ static void PS2_SortAndDraw2DElements(screen_quad_t * batch, int batch_size)
/*
================
PS2_Flush2DBatch
Remarks: Local function.
================
*/
static void PS2_Flush2DBatch(void)
@ -620,6 +645,8 @@ static void PS2_Flush2DBatch(void)
/*
================
PS2_DrawFullScreenCinematic
Remarks: Local function.
================
*/
static void PS2_DrawFullScreenCinematic(void)
@ -664,6 +691,8 @@ static void PS2_DrawFullScreenCinematic(void)
/*
================
PS2_DrawFPSCounter
Remarks: Local function.
================
*/
static void PS2_DrawFPSCounter(void)
@ -701,6 +730,8 @@ static void PS2_DrawFPSCounter(void)
/*
================
PS2_DrawMemTags
Remarks: Local function.
================
*/
static void PS2_DrawMemTags(void)
@ -846,6 +877,9 @@ qboolean PS2_RendererInit(void * unused1, void * unused2)
// And reserve a texture slot for the cinematic frame.
cinematic_frame.teximage = PS2_TexImageAlloc();
// 3D mesh rendering setup:
PS2_ModelInit();
Com_DPrintf("---- PS2_RendererInit completed! ( %d, %d ) ----\n", viddef.width, viddef.height);
ps2ref.initialized = true;
return true;
@ -907,6 +941,7 @@ void PS2_RendererShutdown(void)
packet_free(ps2ref.flip_fb_packet);
}
PS2_ModelShutdown();
PS2_TexImageShutdown();
PS2_MemClearObj(&ps2ref);
}
@ -1330,7 +1365,7 @@ void PS2_DrawString(int x, int y, const char * s)
x += GLYPH_SIZE;
if (*s == '\n')
{
y += GLYPH_SIZE + 2;
y += GLYPH_SIZE + 2; // 2 pixels of spacing between lines.
x = initial_x;
}
++s;
@ -1351,7 +1386,7 @@ void PS2_DrawAltString(int x, int y, const char * s)
x += GLYPH_SIZE;
if (*s == '\n')
{
y += GLYPH_SIZE + 2;
y += GLYPH_SIZE + 2; // 2 pixels of spacing between lines.
x = initial_x;
}
++s;

View File

@ -128,7 +128,7 @@ extern ps2_teximage_t * builtin_tex_debug;
/*
==============================================================
PS2 renderer API functions:
PS2 renderer API functions (ref_ps2.c):
==============================================================
*/
@ -181,12 +181,20 @@ void PS2_DrawFill(int x, int y, int w, int h, int c);
void PS2_DrawFadeScreen(void);
/*
* Miscellaneous:
* refexport_t miscellaneous:
*/
void PS2_CinematicSetPalette(const byte * restrict palette);
void PS2_AppActivate(qboolean activate);
/*
==============================================================
Textures and image loading from file (tex_image.c):
==============================================================
*/
/*
* PS2 Texture image setup/management:
*/
@ -219,11 +227,16 @@ qboolean TGA_LoadFromFile(const char * filename, byte ** pic,
* Convert from 8bit palettized to RGB[A]:
*/
void Img_UnPalettize32(int width, int height, const byte * restrict pic8in, // Palettized 8bits to RGBA 32bits.
// Palettized 8bits to RGBA 32bits.
void Img_UnPalettize32(int width, int height, const byte * restrict pic8in,
const u32 * restrict palette, byte * restrict pic32out);
void Img_UnPalettize24(int width, int height, const byte * restrict pic8in, // Palettized 8bits to RGB 24bits.
// Palettized 8bits to RGB 24bits.
void Img_UnPalettize24(int width, int height, const byte * restrict pic8in,
const u32 * restrict palette, byte * restrict pic24out);
void Img_UnPalettize16(int width, int height, const byte * restrict pic8in, // Palettized 8bits to RGBA 16bits (1-5-5-5).
// Palettized 8bits to RGBA 16bits (1-5-5-5).
void Img_UnPalettize16(int width, int height, const byte * restrict pic8in,
const u32 * restrict palette, byte * restrict pic16out);
/*
@ -232,7 +245,7 @@ void Img_UnPalettize16(int width, int height, const byte * restrict pic8in, // P
// Scrap texture atlas allocation. This is based on the same atlas used by ref_gl.
// Returns null if the atlas is full, a unique ps2_teximage_t handle referencing the atlas otherwise.
ps2_teximage_t * Scrap_AllocBlock(const byte * pic8in, int w, int h, const char * pic_name);
ps2_teximage_t * Img_ScrapAlloc(const byte * pic8in, int w, int h, const char * pic_name);
// Resize the input RGBA image using a box filter. Output and input must point to different buffers.
void Img_Resample32(const u32 * restrict in_img, int in_width, int in_height,

View File

@ -330,6 +330,32 @@ char * Sys_GetClipboardData(void)
return NULL; // Not available on PS2
}
/*
==============
Sys_HashString
OAT - One-At-a-Time hash of the input string.
See: https://en.wikipedia.org/wiki/Jenkins_hash_function
==============
*/
u32 Sys_HashString(const char * str)
{
u32 hash = 0;
while (*str != '\0')
{
hash += *str++;
hash += (hash << 10);
hash ^= (hash >> 6);
}
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
return hash;
}
//=============================================================================
//
// Misc file system utilities:
@ -339,6 +365,8 @@ char * Sys_GetClipboardData(void)
/*
================
Sys_LoadBinaryFile
Remarks: Uses the fio PS2DEV SDK API.
================
*/
qboolean Sys_LoadBinaryFile(const char * filename, int * size_bytes, void ** data_ptr)
@ -402,7 +430,7 @@ BAIL:
Sys_Mkdir
================
*/
void Sys_Mkdir(char * path)
void Sys_Mkdir(const char * path)
{
(void)path;
// Not available on PS2
@ -413,7 +441,7 @@ void Sys_Mkdir(char * path)
Sys_FindFirst
================
*/
char * Sys_FindFirst(char * path, unsigned musthave, unsigned canthave)
char * Sys_FindFirst(const char * path, unsigned musthave, unsigned canthave)
{
(void)path;
(void)musthave;
@ -445,7 +473,7 @@ void Sys_FindClose(void)
//=============================================================================
//
// Fix C-library gaps in the PlayStation-2:
// Fix C-library gaps on the PlayStation-2:
//
//=============================================================================

View File

@ -20,7 +20,7 @@ void Test_PS2_Cinematics(void);
//=============================================================================
//
// Scrap_AllocBlock tests:
// Img_ScrapAlloc tests:
//
//=============================================================================
@ -55,10 +55,10 @@ static byte * CheckerPattern(byte color0, byte color1, int size, byte * buffer)
static void InitTestScraps(void)
{
// Color values are indexed into the global_palette.
scrap_tex_0 = Scrap_AllocBlock(CheckerPattern(50, 65, 24, scrap_test_0), 24, 24, "scrap_test_0");
scrap_tex_1 = Scrap_AllocBlock(CheckerPattern(70, 85, 32, scrap_test_1), 32, 32, "scrap_test_1");
scrap_tex_2 = Scrap_AllocBlock(CheckerPattern(90, 110, 64, scrap_test_2), 64, 64, "scrap_test_2");
scrap_tex_3 = Scrap_AllocBlock(CheckerPattern(150, 210, 16, scrap_test_3), 16, 16, "scrap_test_3");
scrap_tex_0 = Img_ScrapAlloc(CheckerPattern(50, 65, 24, scrap_test_0), 24, 24, "scrap_test_0");
scrap_tex_1 = Img_ScrapAlloc(CheckerPattern(70, 85, 32, scrap_test_1), 32, 32, "scrap_test_1");
scrap_tex_2 = Img_ScrapAlloc(CheckerPattern(90, 110, 64, scrap_test_2), 64, 64, "scrap_test_2");
scrap_tex_3 = Img_ScrapAlloc(CheckerPattern(150, 210, 16, scrap_test_3), 16, 16, "scrap_test_3");
if (scrap_tex_0 == NULL) { Sys_Error("scrap_tex_0 not allocated!"); }
if (scrap_tex_1 == NULL) { Sys_Error("scrap_tex_1 not allocated!"); }

View File

@ -77,9 +77,15 @@ ps2_teximage_t * builtin_tex_debug = NULL;
#define RGBA16(r, g, b, a) \
((((a) & 0x1) << 15) | (((b) >> 3) << 10) | (((g) >> 3) << 5) | ((r) >> 3))
// Used for image name hashing.
extern u32 Sys_HashString(const char * str);
/*
==============
CheckerPattern
Makes a checker pattern texture for builtin_tex_debug.
Remarks: Local function.
==============
*/
enum
@ -167,6 +173,8 @@ void PS2_TexImageShutdown(void)
//TODO cleanup all allocated textures on ps2ref.teximages!!
//remember we can't free the debug tex since it is generated!!!
//teximages with type IT_BUILTIN can't be freed
ps2ref.num_teximages = 0;
}
/*
@ -178,7 +186,7 @@ ps2_teximage_t * PS2_TexImageAlloc(void)
{
if (ps2ref.num_teximages == MAX_TEXIMAGES)
{
Sys_Error("Out of tex images!!!");
Sys_Error("Out of tex image objects!!!");
}
//TODO assume always sequential, or allow empty gaps???
@ -188,17 +196,23 @@ ps2_teximage_t * PS2_TexImageAlloc(void)
/*
==============
Local helpers:
- IsPowerOfTwo
- RoundToPowerOfTwo
IsPowerOfTwo
Remarks: Local function.
==============
*/
static inline int IsPowerOfTwo(int x)
{
return (x > 0) && (x & (x - 1)) == 0;
}
/*
==============
RoundToPowerOfTwo
Remarks: Local function.
==============
*/
static inline int RoundToPowerOfTwo(int x)
{
if (IsPowerOfTwo(x))
@ -207,18 +221,21 @@ static inline int RoundToPowerOfTwo(int x)
}
// Round nearest:
int k;
int k, p2;
for (k = sizeof(int) * 8 - 1; ((1 << k) & x) == 0; --k)
{
}
if (((1 << (k - 1)) & x) == 0)
{
return 1 << k;
p2 = 1 << k;
}
else
{
p2 = 1 << (k + 1);
}
int pot = 1 << (k + 1);
return (pot < MAX_TEXIMAGE_SIZE) ? pot : MAX_TEXIMAGE_SIZE;
return (p2 < MAX_TEXIMAGE_SIZE) ? p2 : MAX_TEXIMAGE_SIZE;
// Round down:
/*
@ -230,10 +247,12 @@ static inline int RoundToPowerOfTwo(int x)
/*
==============
PS2_Common8BitTexSetup
Common8BitTexSetup
Remarks: Local function.
==============
*/
static ps2_teximage_t * PS2_Common8BitTexSetup(const byte * pic8, int width, int height, const char * name, int flags)
static ps2_teximage_t * Common8BitTexSetup(const byte * pic8, int width, int height, const char * name, int flags)
{
byte * expanded_pic;
byte * scaled_pic;
@ -319,10 +338,12 @@ static ps2_teximage_t * PS2_Common8BitTexSetup(const byte * pic8, int width, int
/*
==============
PS2_LoadPcxImpl
LoadPcxImpl
Remarks: Local function.
==============
*/
static ps2_teximage_t * PS2_LoadPcxImpl(const char * name, int flags)
static ps2_teximage_t * LoadPcxImpl(const char * name, int flags)
{
int width;
int height;
@ -344,13 +365,13 @@ static ps2_teximage_t * PS2_LoadPcxImpl(const char * name, int flags)
// a descent way on allocation, so I've change the atlas
// allocation criteria here to allow it's height, so it
// will not be a standalone image and won't require a resize.
teximage = Scrap_AllocBlock(pic8, width, height, name);
teximage = Img_ScrapAlloc(pic8, width, height, name);
}
// Atlas full or image too big, create a standalone texture:
if (teximage == NULL)
{
teximage = PS2_Common8BitTexSetup(pic8, width, height, name, flags);
teximage = Common8BitTexSetup(pic8, width, height, name, flags);
}
// The palettized image is no longer needed.
@ -360,10 +381,12 @@ static ps2_teximage_t * PS2_LoadPcxImpl(const char * name, int flags)
/*
==============
PS2_LoadWalImpl
LoadWalImpl
Remarks: Local function.
==============
*/
static ps2_teximage_t * PS2_LoadWalImpl(const char * name, int flags)
static ps2_teximage_t * LoadWalImpl(const char * name, int flags)
{
ps2_teximage_t * teximage;
const miptex_t * wall;
@ -385,7 +408,7 @@ static ps2_teximage_t * PS2_LoadWalImpl(const char * name, int flags)
offset = LittleLong(wall->offsets[0]);
pic8 = (const byte *)wall + offset;
teximage = PS2_Common8BitTexSetup(pic8, width, height, name, flags | IT_WALL);
teximage = Common8BitTexSetup(pic8, width, height, name, flags | IT_WALL);
FS_FreeFile((void *)wall);
return teximage;
@ -393,10 +416,12 @@ static ps2_teximage_t * PS2_LoadWalImpl(const char * name, int flags)
/*
==============
PS2_LoadTgaImpl
LoadTgaImpl
Remarks: Local function.
==============
*/
static ps2_teximage_t * PS2_LoadTgaImpl(const char * name, int flags)
static ps2_teximage_t * LoadTgaImpl(const char * name, int flags)
{
byte * pic32;
int width;
@ -413,10 +438,10 @@ static ps2_teximage_t * PS2_LoadTgaImpl(const char * name, int flags)
const int img_type = flags & (~IT_BUILTIN);
// TGA defaults:
const int psm = GS_PSM_32;
const int format = TEXTURE_COMPONENTS_RGBA;
const int mag_filter = LOD_MAG_LINEAR;
const int min_filter = LOD_MIN_LINEAR;
const int psm = GS_PSM_32;
const int format = TEXTURE_COMPONENTS_RGBA;
const int mag_filter = LOD_MAG_LINEAR;
const int min_filter = LOD_MIN_LINEAR;
//
// TGAs are always expanded to RGBA, so no extra conversion is needed.
@ -434,52 +459,28 @@ static ps2_teximage_t * PS2_LoadTgaImpl(const char * name, int flags)
/*
==============
PS2_ImageNameHash
FindImageImpl
OAT - One-At-a-Time hash of the filename of an image.
https://en.wikipedia.org/wiki/Jenkins_hash_function
Remarks: Local function.
==============
*/
static inline u32 PS2_ImageNameHash(const char * name)
static ps2_teximage_t * FindImageImpl(const char * name, int flags)
{
u32 hash = 0;
while (*name != '\0')
if (name == NULL || *name == '\0')
{
hash += *name++;
hash += (hash << 10);
hash ^= (hash >> 6);
}
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
return hash;
}
/*
==============
PS2_FindImageImpl
==============
*/
static ps2_teximage_t * PS2_FindImageImpl(const char * name, int flags)
{
if (name == NULL)
{
Com_DPrintf("PS2_FindImageImpl: Null name!\n");
Com_DPrintf("FindImage: Null/empty image name!\n");
return NULL;
}
const u32 name_len = strlen(name);
if (name_len < 5 || name_len >= MAX_QPATH)
{
Com_DPrintf("PS2_FindImageImpl: Bad image name: '%s'\n", name);
Com_DPrintf("FindImage: Bad image name length: '%s'\n", name);
return NULL;
}
// Compare by hash code, much cheaper.
const u32 name_hash = PS2_ImageNameHash(name);
const u32 name_hash = Sys_HashString(name);
//
// First, lookup our cache:
@ -501,17 +502,17 @@ static ps2_teximage_t * PS2_FindImageImpl(const char * name, int flags)
//
if (strcmp(name + name_len - 4, ".pcx") == 0)
{
return PS2_LoadPcxImpl(name, flags);
return LoadPcxImpl(name, flags);
}
if (strcmp(name + name_len - 4, ".wal") == 0)
{
return PS2_LoadWalImpl(name, flags);
return LoadWalImpl(name, flags);
}
if (strcmp(name + name_len - 4, ".tga") == 0)
{
return PS2_LoadTgaImpl(name, flags);
return LoadTgaImpl(name, flags);
}
Com_DPrintf("WARNING: Unable to find image '%s'\n", name);
@ -536,17 +537,17 @@ ps2_teximage_t * PS2_TexImageFindOrLoad(const char * name, int flags)
if (name[0] != '/' && name[0] != '\\')
{
Com_sprintf(fullname, sizeof(fullname), "pics/%s.pcx", name);
teximage = PS2_FindImageImpl(fullname, flags);
teximage = FindImageImpl(fullname, flags);
}
else
{
teximage = PS2_FindImageImpl(name + 1, flags);
teximage = FindImageImpl(name + 1, flags);
}
}
else
{
// Skins, walls, etc.
teximage = PS2_FindImageImpl(name, flags);
teximage = FindImageImpl(name, flags);
}
return teximage;
@ -594,7 +595,7 @@ void PS2_TexImageSetup(ps2_teximage_t * teximage, const char * name, int w, int
// Finally, copy and hash the name string:
strncpy(teximage->name, name, MAX_QPATH);
teximage->hash = PS2_ImageNameHash(name);
teximage->hash = Sys_HashString(name);
}
/*
@ -689,24 +690,20 @@ void Img_Resample32(const u32 * restrict in_img, int in_width, int in_height,
}
}
//=============================================================================
//
// Scrap allocation - AKA texture atlas
// Useful to group small textures into a larger one,
// reducing the number of texture switches when rendering.
//
//=============================================================================
static int scrap_allocated[MAX_TEXIMAGE_SIZE] __attribute__((aligned(16)));
static u32 scrap_pixels[MAX_TEXIMAGE_SIZE * MAX_TEXIMAGE_SIZE] __attribute__((aligned(16)));
/*
==============
Scrap_AllocBlock
Img_ScrapAlloc
Scrap allocation - AKA texture atlas.
Useful to group small textures into a larger one,
reducing the number of texture switches when rendering.
==============
*/
ps2_teximage_t * Scrap_AllocBlock(const byte * pic8in, int w, int h, const char * pic_name)
ps2_teximage_t * Img_ScrapAlloc(const byte * pic8in, int w, int h, const char * pic_name)
{
static int scrap_allocated[MAX_TEXIMAGE_SIZE] __attribute__((aligned(16)));
static u32 scrap_pixels[MAX_TEXIMAGE_SIZE * MAX_TEXIMAGE_SIZE] __attribute__((aligned(16)));
int i, j, k;
int sx, sy;
int best, best2;

View File

@ -223,7 +223,7 @@ void Master_Packet(void);
// sv_init.c
//
void SV_InitGame(void);
void SV_Map(qboolean attractloop, char * levelstring, qboolean loadgame);
void SV_Map(qboolean attractloop, const char * levelstring, qboolean loadgame);
//
// sv_phys.c

View File

@ -95,7 +95,7 @@ qboolean SV_SetPlayer(void)
client_t * cl;
int i;
int idnum;
char * s;
const char * s;
if (Cmd_Argc() < 2)
return false;
@ -154,7 +154,7 @@ SV_WipeSavegame
Delete save/<XXX>/
=====================
*/
void SV_WipeSavegame(char * savename)
void SV_WipeSavegame(const char * savename)
{
char name[MAX_OSPATH];
char * s;
@ -224,7 +224,7 @@ void CopyFile(char * src, char * dst)
SV_CopySaveGame
================
*/
void SV_CopySaveGame(char * src, char * dst)
void SV_CopySaveGame(const char * src, const char * dst)
{
char name[MAX_OSPATH], name2[MAX_OSPATH];
int l, len;
@ -483,7 +483,7 @@ goes to map jail.bsp.
*/
void SV_GameMap_f(void)
{
char * map;
const char * map;
int i;
client_t * cl;
qboolean * savedInuse;
@ -555,7 +555,7 @@ For development work
*/
void SV_Map_f(void)
{
char * map;
const char * map;
char expanded[MAX_QPATH];
// if not a pcx, demo, or cinematic, check to make sure the level exists
@ -593,7 +593,7 @@ void SV_Loadgame_f(void)
{
char name[MAX_OSPATH];
FILE * f;
char * dir;
const char * dir;
if (Cmd_Argc() != 2)
{
@ -636,7 +636,7 @@ SV_Savegame_f
*/
void SV_Savegame_f(void)
{
char * dir;
const char * dir;
if (sv.state != ss_game)
{
@ -790,7 +790,7 @@ void SV_ConSay_f(void)
{
client_t * client;
int j;
char * p;
const char * p;
char text[1024];
if (Cmd_Argc() < 2)
@ -799,18 +799,22 @@ void SV_ConSay_f(void)
strcpy(text, "console: ");
p = Cmd_Args();
// Strip leading/trailing quotes:
if (*p == '"')
{
p++;
p[strlen(p) - 1] = 0;
++p; // skip the first
strncat(text, p, strlen(p) - 1); // copy all except the last char (")
}
else
{
strcat(text, p);
}
strcat(text, p);
for (j = 0, client = svs.clients; j < maxclients->value; j++, client++)
{
if (client->state != cs_spawned)
continue;
SV_ClientPrintf(client, PRINT_CHAT, "%s\n", text);
}
}

View File

@ -414,7 +414,7 @@ another level:
map tram.cin+jail_e3
======================
*/
void SV_Map(qboolean attractloop, char * levelstring, qboolean loadgame)
void SV_Map(qboolean attractloop, const char * levelstring, qboolean loadgame)
{
char level[MAX_QPATH];
char * ch;

View File

@ -459,8 +459,8 @@ connectionless packets.
*/
void SV_ConnectionlessPacket(void)
{
char * s;
char * c;
const char * s;
const char * c;
MSG_BeginReading(&net_message);
MSG_ReadLong(&net_message); // skip the -1 marker

View File

@ -302,13 +302,14 @@ SV_BeginDownload_f
*/
void SV_BeginDownload_f(void)
{
char * name;
extern cvar_t * allow_download;
extern cvar_t * allow_download_players;
extern cvar_t * allow_download_models;
extern cvar_t * allow_download_sounds;
extern cvar_t * allow_download_maps;
extern int file_from_pak; // ZOID did file come from pak?
const char * name;
int offset = 0;
name = Cmd_Argv(1);