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:
parent
55517b7257
commit
7e58306d03
3 changed files with 54 additions and 39 deletions
|
@ -31,7 +31,7 @@ void *malloc(int size)
|
|||
if (size <= 0)
|
||||
return NULL;
|
||||
|
||||
size = ((size+4) & 3) + sizeof(struct memhead_s); //round up
|
||||
size = ((size+4) & ~3) + sizeof(struct memhead_s); //round up
|
||||
if (!head)
|
||||
{ //first call
|
||||
struct memhead_s *last;
|
||||
|
@ -63,9 +63,9 @@ void *malloc(int size)
|
|||
if (head->isfree)
|
||||
if (head->size >= size)
|
||||
{
|
||||
struct memhead_s *split;
|
||||
if (head->size > size + sizeof(struct memhead_s)+1)
|
||||
{ //split
|
||||
struct memhead_s *split;
|
||||
split = (struct memhead_s*)((char*)head + size);
|
||||
split->size = head->size - size;
|
||||
head->size = size;
|
||||
|
@ -80,12 +80,15 @@ void *malloc(int size)
|
|||
{ //no point in splitting
|
||||
head->isfree = false;
|
||||
}
|
||||
|
||||
return (char*)head + sizeof(struct memhead_s);
|
||||
split = head;
|
||||
head = head->next;
|
||||
return (char*)split + sizeof(struct memhead_s);
|
||||
}
|
||||
head = head->next;
|
||||
} while (lasthead != head);
|
||||
|
||||
Sys_Errorf("VM Out of memory on allocation of %i bytes\n", size);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -117,4 +120,6 @@ void free(void *mem)
|
|||
{ //merge next with this
|
||||
block = mergeblock(block, block->next);
|
||||
}
|
||||
|
||||
head = (struct memhead_s*)memory;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
#undef 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
|
||||
|
||||
#define ARGNAMES ,buffer
|
||||
BUILTIN(void, Cmd_AddCommand, (char *buffer)); //abort the entire engine.
|
||||
BUILTIN(void, Cmd_AddCommand, (char *buffer)); //register a command.
|
||||
#undef ARGNAMES
|
||||
#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
|
||||
#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
|
||||
#define ARGNAMES
|
||||
BUILTINR(int, Cmd_Argc, (void)); //abort the entire engine.
|
||||
BUILTINR(int, Cmd_Argc, (void)); //get the argument count.
|
||||
#undef ARGNAMES
|
||||
#define ARGNAMES ,msg
|
||||
BUILTIN(void, Cmd_TokenizeString, (char *msg)); //abort the entire engine.
|
||||
BUILTIN(void, Cmd_TokenizeString, (char *msg)); //tokenize a string.
|
||||
#undef ARGNAMES
|
||||
|
||||
#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
|
||||
|
||||
#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
|
||||
#define ARGNAMES ,name,value
|
||||
BUILTIN(void, Cvar_SetFloat, (char *name, float value));
|
||||
#define ARGNAMES ,name,PASSFLOAT(value)
|
||||
BUILTIN(void, Cvar_SetFloat, (char *name, float value)); //set a cvar float
|
||||
#undef ARGNAMES
|
||||
#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
|
||||
#define ARGNAMES ,name
|
||||
BUILTINR(float, Cvar_GetFloat, (char *name));
|
||||
BUILTINR(float, Cvar_GetFloat, (char *name)); //get a cvar's value
|
||||
#undef ARGNAMES
|
||||
#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
|
||||
#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.
|
||||
|
@ -149,36 +149,36 @@ BUILTINR(int, Key_GetKeyCode, (char *keyname));
|
|||
#undef ARGNAMES
|
||||
|
||||
#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
|
||||
#define ARGNAMES ,handle
|
||||
BUILTIN(void, FS_Close, (int handle));
|
||||
BUILTIN(void, FS_Close, (qhandle_t handle));
|
||||
#undef ARGNAMES
|
||||
#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
|
||||
#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
|
||||
|
||||
|
||||
#define ARGNAMES ,ip,port
|
||||
BUILTINR(int, Net_TCPConnect, (char *ip, int port));
|
||||
BUILTINR(qhandle_t, Net_TCPConnect, (char *ip, int port));
|
||||
#undef ARGNAMES
|
||||
#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
|
||||
#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
|
||||
#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
|
||||
#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
|
||||
#define ARGNAMES ,socket
|
||||
BUILTIN(void, Net_Close, (int socket));
|
||||
BUILTIN(void, Net_Close, (qhandle_t socket));
|
||||
#undef ARGNAMES
|
||||
|
||||
#ifdef Q3_VM
|
||||
|
@ -191,6 +191,9 @@ BUILTIN(void, memset, (void *out, int in, int len));
|
|||
#define ARGNAMES ,out,in,len
|
||||
BUILTIN(void, memmove, (void *out, void *in, int len));
|
||||
#undef ARGNAMES
|
||||
#define ARGNAMES ,PASSFLOAT(f)
|
||||
BUILTINR(float, sqrt, (float f));
|
||||
#undef ARGNAMES
|
||||
#endif
|
||||
|
||||
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(memmove);
|
||||
CHECKBUILTIN(memset);
|
||||
CHECKBUILTIN(sqrt);
|
||||
#endif
|
||||
|
||||
CHECKBUILTIN(Sys_Milliseconds);
|
||||
|
|
|
@ -38,19 +38,24 @@ char *strchr(char *str, char sub);
|
|||
float atof(char *str);
|
||||
int atoi(char *str);
|
||||
|
||||
#define strcasecmp stricmp
|
||||
|
||||
void BadBuiltin(void);
|
||||
|
||||
#else
|
||||
|
||||
#define strcasecmp stricmp
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include "math.h"
|
||||
//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 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 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 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 "#n" is not valid\n");plugin_syscall(BUILTIN_##n ARGNAMES);}
|
||||
#else
|
||||
#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);}
|
||||
|
@ -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, SCR_CenterPrint, (char *s));
|
||||
|
||||
EBUILTIN(int, FS_Open, (char *name, int *handle, int mode));
|
||||
EBUILTIN(void, FS_Close, (int handle));
|
||||
EBUILTIN(void, FS_Write, (int handle, void *data, int len));
|
||||
EBUILTIN(void, FS_Read, (int handle, void *data, int len));
|
||||
EBUILTIN(int, FS_Open, (char *name, qhandle_t *handle, int mode));
|
||||
EBUILTIN(void, FS_Close, (qhandle_t handle));
|
||||
EBUILTIN(int, FS_Write, (qhandle_t 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(int, Net_TCPListen, (char *ip, int port, int maxcount));
|
||||
EBUILTIN(int, Net_Accept, (int socket, char *address, int addresssize));
|
||||
EBUILTIN(int, Net_Recv, (int socket, void *buffer, int len));
|
||||
EBUILTIN(int, Net_Send, (int socket, void *buffer, int len));
|
||||
EBUILTIN(void, Net_Close, (int socket));
|
||||
EBUILTIN(qhandle_t, Net_TCPConnect, (char *ip, int port));
|
||||
EBUILTIN(qhandle_t, Net_TCPListen, (char *ip, int port, int maxcount));
|
||||
EBUILTIN(qhandle_t, Net_Accept, (qhandle_t socket, char *address, int addresssize));
|
||||
EBUILTIN(int, Net_Recv, (qhandle_t socket, void *buffer, int len));
|
||||
EBUILTIN(int, Net_Send, (qhandle_t socket, void *buffer, int len));
|
||||
EBUILTIN(void, Net_Close, (qhandle_t socket));
|
||||
#define N_WOULDBLOCK -1
|
||||
#define NET_CLIENTPORT -1
|
||||
#define NET_SERVERPORT -2
|
||||
|
@ -139,6 +144,7 @@ EBUILTIN(void, Net_Close, (int socket));
|
|||
EBUILTIN(void, memcpy, (void *, void *, int len));
|
||||
EBUILTIN(void, memmove, (void *, void *, int len));
|
||||
EBUILTIN(void, memset, (void *, int, int len));
|
||||
EBUILTIN(float, sqrt, (float f));
|
||||
#endif
|
||||
|
||||
typedef int (*export_t) (int *args);
|
||||
|
|
Loading…
Reference in a new issue