1
0
Fork 0
forked from fte/fteqw

Fixed/tweeked a few things.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@1681 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2005-12-06 15:40:52 +00:00
parent 55517b7257
commit 7e58306d03
3 changed files with 54 additions and 39 deletions

View file

@ -31,7 +31,7 @@ void *malloc(int size)
if (size <= 0) if (size <= 0)
return NULL; return NULL;
size = ((size+4) & 3) + sizeof(struct memhead_s); //round up size = ((size+4) & ~3) + sizeof(struct memhead_s); //round up
if (!head) if (!head)
{ //first call { //first call
struct memhead_s *last; struct memhead_s *last;
@ -63,9 +63,9 @@ void *malloc(int size)
if (head->isfree) if (head->isfree)
if (head->size >= size) if (head->size >= size)
{ {
struct memhead_s *split;
if (head->size > size + sizeof(struct memhead_s)+1) if (head->size > size + sizeof(struct memhead_s)+1)
{ //split { //split
struct memhead_s *split;
split = (struct memhead_s*)((char*)head + size); split = (struct memhead_s*)((char*)head + size);
split->size = head->size - size; split->size = head->size - size;
head->size = size; head->size = size;
@ -80,12 +80,15 @@ void *malloc(int size)
{ //no point in splitting { //no point in splitting
head->isfree = false; head->isfree = false;
} }
split = head;
return (char*)head + sizeof(struct memhead_s); head = head->next;
return (char*)split + sizeof(struct memhead_s);
} }
head = head->next; head = head->next;
} while (lasthead != head); } while (lasthead != head);
Sys_Errorf("VM Out of memory on allocation of %i bytes\n", size);
return NULL; return NULL;
} }
@ -117,4 +120,6 @@ void free(void *mem)
{ //merge next with this { //merge next with this
block = mergeblock(block, block->next); block = mergeblock(block, block->next);
} }
head = (struct memhead_s*)memory;
} }

View file

@ -60,43 +60,43 @@ BUILTIN(void, Con_RenameSub, (char *old, char *new)); //on to named sub console
BUILTIN(void, Sys_Error, (char *message)); //abort the entire engine. BUILTIN(void, Sys_Error, (char *message)); //abort the entire engine.
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES #define ARGNAMES
BUILTINR(unsigned int, Sys_Milliseconds, (void)); //abort the entire engine. BUILTINR(unsigned int, Sys_Milliseconds, (void)); //get the time the engine has been running.
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,buffer #define ARGNAMES ,buffer
BUILTIN(void, Cmd_AddCommand, (char *buffer)); //abort the entire engine. BUILTIN(void, Cmd_AddCommand, (char *buffer)); //register a command.
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,buffer,bufsize #define ARGNAMES ,buffer,bufsize
BUILTIN(void, Cmd_Args, (char *buffer, int bufsize)); //abort the entire engine. BUILTIN(void, Cmd_Args, (char *buffer, int bufsize)); //retrieve some arguments.
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,argnum,buffer,bufsize #define ARGNAMES ,argnum,buffer,bufsize
BUILTIN(void, Cmd_Argv, (int argnum, char *buffer, int bufsize)); //abort the entire engine. BUILTIN(void, Cmd_Argv, (int argnum, char *buffer, int bufsize)); //retrieve a single argument at a time.
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES #define ARGNAMES
BUILTINR(int, Cmd_Argc, (void)); //abort the entire engine. BUILTINR(int, Cmd_Argc, (void)); //get the argument count.
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,msg #define ARGNAMES ,msg
BUILTIN(void, Cmd_TokenizeString, (char *msg)); //abort the entire engine. BUILTIN(void, Cmd_TokenizeString, (char *msg)); //tokenize a string.
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,text,insert #define ARGNAMES ,text,insert
BUILTIN(void, Cmd_AddText, (char *text, qboolean insert)); //abort the entire engine. BUILTIN(void, Cmd_AddText, (char *text, qboolean insert)); //add stuff to the console input.
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,name,value #define ARGNAMES ,name,value
BUILTIN(void, Cvar_SetString, (char *name, char *value)); BUILTIN(void, Cvar_SetString, (char *name, char *value)); //set a cvar string
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,name,value #define ARGNAMES ,name,PASSFLOAT(value)
BUILTIN(void, Cvar_SetFloat, (char *name, float value)); BUILTIN(void, Cvar_SetFloat, (char *name, float value)); //set a cvar float
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,name,retstring,sizeofretstring #define ARGNAMES ,name,retstring,sizeofretstring
BUILTINR(qboolean, Cvar_GetString, (char *name, char *retstring, int sizeofretstring)); BUILTINR(qboolean, Cvar_GetString, (char *name, char *retstring, int sizeofretstring)); //retrieve a cvar string
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,name #define ARGNAMES ,name
BUILTINR(float, Cvar_GetFloat, (char *name)); BUILTINR(float, Cvar_GetFloat, (char *name)); //get a cvar's value
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,name,defaultval,flags,grouphint #define ARGNAMES ,name,defaultval,flags,grouphint
BUILTINR(qhandle_t, Cvar_Register, (char *name, char *defaultval, int flags, char *grouphint)); BUILTINR(qhandle_t, Cvar_Register, (char *name, char *defaultval, int flags, char *grouphint)); //register a new cvar
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,handle,modificationcount,stringv,floatv #define ARGNAMES ,handle,modificationcount,stringv,floatv
BUILTINR(int, Cvar_Update, (qhandle_t handle, int *modificationcount, char *stringv, float *floatv)); //stringv is 256 chars long, don't expect this function to do anything if modification count is unchanged. BUILTINR(int, Cvar_Update, (qhandle_t handle, int *modificationcount, char *stringv, float *floatv)); //stringv is 256 chars long, don't expect this function to do anything if modification count is unchanged.
@ -149,36 +149,36 @@ BUILTINR(int, Key_GetKeyCode, (char *keyname));
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,name,handle,mode #define ARGNAMES ,name,handle,mode
BUILTINR(int, FS_Open, (char *name, int *handle, int mode)); BUILTINR(int, FS_Open, (char *name, qhandle_t *handle, int mode));
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,handle #define ARGNAMES ,handle
BUILTIN(void, FS_Close, (int handle)); BUILTIN(void, FS_Close, (qhandle_t handle));
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,handle,data,len #define ARGNAMES ,handle,data,len
BUILTIN(void, FS_Write, (int handle, void *data, int len)); BUILTINR(int, FS_Write, (qhandle_t handle, void *data, int len));
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,handle,data,len #define ARGNAMES ,handle,data,len
BUILTIN(void, FS_Read, (int handle, void *data, int len)); BUILTINR(int, FS_Read, (qhandle_t handle, void *data, int len));
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,ip,port #define ARGNAMES ,ip,port
BUILTINR(int, Net_TCPConnect, (char *ip, int port)); BUILTINR(qhandle_t, Net_TCPConnect, (char *ip, int port));
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,ip,port,maxcount #define ARGNAMES ,ip,port,maxcount
BUILTINR(int, Net_TCPListen, (char *ip, int port, int maxcount)); BUILTINR(qhandle_t, Net_TCPListen, (char *ip, int port, int maxcount));
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,socket,address,addresslen #define ARGNAMES ,socket,address,addresslen
BUILTINR(int, Net_Accept, (int socket, char *address, int addresslen)); BUILTINR(qhandle_t, Net_Accept, (qhandle_t socket, char *address, int addresslen));
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,socket,buffer,len #define ARGNAMES ,socket,buffer,len
BUILTINR(int, Net_Recv, (int socket, void *buffer, int len)); BUILTINR(int, Net_Recv, (qhandle_t socket, void *buffer, int len));
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,socket,buffer,len #define ARGNAMES ,socket,buffer,len
BUILTINR(int, Net_Send, (int socket, void *buffer, int len)); BUILTINR(int, Net_Send, (qhandle_t socket, void *buffer, int len));
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,socket #define ARGNAMES ,socket
BUILTIN(void, Net_Close, (int socket)); BUILTIN(void, Net_Close, (qhandle_t socket));
#undef ARGNAMES #undef ARGNAMES
#ifdef Q3_VM #ifdef Q3_VM
@ -191,6 +191,9 @@ BUILTIN(void, memset, (void *out, int in, int len));
#define ARGNAMES ,out,in,len #define ARGNAMES ,out,in,len
BUILTIN(void, memmove, (void *out, void *in, int len)); BUILTIN(void, memmove, (void *out, void *in, int len));
#undef ARGNAMES #undef ARGNAMES
#define ARGNAMES ,PASSFLOAT(f)
BUILTINR(float, sqrt, (float f));
#undef ARGNAMES
#endif #endif
char *va(char *format, ...) //Identical in function to the one in Quake, though I can assure you that I wrote it... char *va(char *format, ...) //Identical in function to the one in Quake, though I can assure you that I wrote it...
@ -245,6 +248,7 @@ void Plug_InitStandardBuiltins(void)
CHECKBUILTIN(memcpy); CHECKBUILTIN(memcpy);
CHECKBUILTIN(memmove); CHECKBUILTIN(memmove);
CHECKBUILTIN(memset); CHECKBUILTIN(memset);
CHECKBUILTIN(sqrt);
#endif #endif
CHECKBUILTIN(Sys_Milliseconds); CHECKBUILTIN(Sys_Milliseconds);

View file

@ -38,19 +38,24 @@ char *strchr(char *str, char sub);
float atof(char *str); float atof(char *str);
int atoi(char *str); int atoi(char *str);
#define strcasecmp stricmp
void BadBuiltin(void); void BadBuiltin(void);
#else #else
#define strcasecmp stricmp
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include "math.h"
//DLLs need a wrapper to add the extra parameter and call a boring function. //DLLs need a wrapper to add the extra parameter and call a boring function.
#define EBUILTIN(t, n, args) extern int BUILTIN_##n; t n args #define EBUILTIN(t, n, args) extern int BUILTIN_##n; t n args
#define TEST #define TEST
#ifdef TEST #ifdef TEST
#define BUILTINR(t, n, args) int BUILTIN_##n; t n args {if (!BUILTINISVALID(n))Sys_Error("Builtin %s is not valid\n", #n);return (t)plugin_syscall(BUILTIN_##n ARGNAMES);} #define BUILTINR(t, n, args) int BUILTIN_##n; t n args {if (!BUILTINISVALID(n))Sys_Error("Builtin "#n" is not valid\n");return (t)plugin_syscall(BUILTIN_##n ARGNAMES);}
#define BUILTIN(t, n, args) int BUILTIN_##n; t n args {if (!BUILTINISVALID(n))Sys_Error("Builtin %s is not valid\n", #n);plugin_syscall(BUILTIN_##n ARGNAMES);} #define BUILTIN(t, n, args) int BUILTIN_##n; t n args {if (!BUILTINISVALID(n))Sys_Error("Builtin "#n" is not valid\n");plugin_syscall(BUILTIN_##n ARGNAMES);}
#else #else
#define BUILTINR(t, n, args) int BUILTIN_##n; t n args {return (t)plugin_syscall(BUILTIN_##n ARGNAMES);} #define BUILTINR(t, n, args) int BUILTIN_##n; t n args {return (t)plugin_syscall(BUILTIN_##n ARGNAMES);}
#define BUILTIN(t, n, args) int BUILTIN_##n; t n args {plugin_syscall(BUILTIN_##n ARGNAMES);} #define BUILTIN(t, n, args) int BUILTIN_##n; t n args {plugin_syscall(BUILTIN_##n ARGNAMES);}
@ -118,17 +123,17 @@ EBUILTIN(void, Draw_Colour3f, (float r, float g, float b));
EBUILTIN(void, Draw_Colour4f, (float r, float g, float b, float a)); EBUILTIN(void, Draw_Colour4f, (float r, float g, float b, float a));
EBUILTIN(void, SCR_CenterPrint, (char *s)); EBUILTIN(void, SCR_CenterPrint, (char *s));
EBUILTIN(int, FS_Open, (char *name, int *handle, int mode)); EBUILTIN(int, FS_Open, (char *name, qhandle_t *handle, int mode));
EBUILTIN(void, FS_Close, (int handle)); EBUILTIN(void, FS_Close, (qhandle_t handle));
EBUILTIN(void, FS_Write, (int handle, void *data, int len)); EBUILTIN(int, FS_Write, (qhandle_t handle, void *data, int len));
EBUILTIN(void, FS_Read, (int handle, void *data, int len)); EBUILTIN(int, FS_Read, (qhandle_t handle, void *data, int len));
EBUILTIN(int, Net_TCPConnect, (char *ip, int port)); EBUILTIN(qhandle_t, Net_TCPConnect, (char *ip, int port));
EBUILTIN(int, Net_TCPListen, (char *ip, int port, int maxcount)); EBUILTIN(qhandle_t, Net_TCPListen, (char *ip, int port, int maxcount));
EBUILTIN(int, Net_Accept, (int socket, char *address, int addresssize)); EBUILTIN(qhandle_t, Net_Accept, (qhandle_t socket, char *address, int addresssize));
EBUILTIN(int, Net_Recv, (int socket, void *buffer, int len)); EBUILTIN(int, Net_Recv, (qhandle_t socket, void *buffer, int len));
EBUILTIN(int, Net_Send, (int socket, void *buffer, int len)); EBUILTIN(int, Net_Send, (qhandle_t socket, void *buffer, int len));
EBUILTIN(void, Net_Close, (int socket)); EBUILTIN(void, Net_Close, (qhandle_t socket));
#define N_WOULDBLOCK -1 #define N_WOULDBLOCK -1
#define NET_CLIENTPORT -1 #define NET_CLIENTPORT -1
#define NET_SERVERPORT -2 #define NET_SERVERPORT -2
@ -139,6 +144,7 @@ EBUILTIN(void, Net_Close, (int socket));
EBUILTIN(void, memcpy, (void *, void *, int len)); EBUILTIN(void, memcpy, (void *, void *, int len));
EBUILTIN(void, memmove, (void *, void *, int len)); EBUILTIN(void, memmove, (void *, void *, int len));
EBUILTIN(void, memset, (void *, int, int len)); EBUILTIN(void, memset, (void *, int, int len));
EBUILTIN(float, sqrt, (float f));
#endif #endif
typedef int (*export_t) (int *args); typedef int (*export_t) (int *args);