mirror of
https://github.com/nzp-team/fteqw.git
synced 2024-11-14 08:21:05 +00:00
8d5b217266
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines removed MAX_VISEDICTS limit. PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default. TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW. added android multitouch emulation for windows/rawinput (in_simulatemultitouch). split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature. now using utf-8 for windows consoles. qcc warnings/errors now give clickable console links for quick+easy editing. disabled menutint when the currently active item changes contrast or gamma (for OneManClan). Added support for drawfont/drawfontscale. tweaked the qcvm a little to reduce the number of pointers. .doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up. windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings. fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen. editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts. Added support for .framegroups files for psk(psa) and iqm formats. True support for ezquake's colour codes. Mutually exclusive with background colours. path command output slightly more readable. added support for digest_hex (MD4, SHA1, CRC16). skingroups now colourmap correctly. Fix terrain colour hints, and litdata from the wrong bsp. fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported). remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother. fix v *= v.x and similar opcodes. fteqcc: fixed support for áéíóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported. fteqcc: fixed '#if 1 == 3 && 4' parsing. fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable. fteqcc: copyright message now includes compile date instead. fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile. fteqccgui: the output window is now focused and scrolls down as compilation progresses. pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue. rewrote prespawn/modelist/soundlist code. server tracks progress now. ------------------------------------------------------------------------ git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
221 lines
5.4 KiB
C
221 lines
5.4 KiB
C
//This is basically a sample program.
|
|
//It deomnstrates the code required to get qclib up and running.
|
|
//This code does not demonstrate entities, however.
|
|
//It does demonstrate the built in qc compiler, and does demonstrate a globals-only progs interface.
|
|
//It also demonstrates basic builtin(s).
|
|
|
|
|
|
|
|
#include "progtype.h"
|
|
#include "progslib.h"
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
|
|
//builtins and builtin management.
|
|
void PF_prints (pubprogfuncs_t *prinst, struct globalvars_s *gvars)
|
|
{
|
|
char *s;
|
|
s = prinst->VarString(prinst, 0);
|
|
|
|
printf("%s", s);
|
|
}
|
|
|
|
void PF_printv (pubprogfuncs_t *prinst, struct globalvars_s *pr_globals)
|
|
{
|
|
printf("%f %f %f\n", G_FLOAT(OFS_PARM0+0), G_FLOAT(OFS_PARM0+1), G_FLOAT(OFS_PARM0+2));
|
|
}
|
|
|
|
void PF_printf (pubprogfuncs_t *prinst, struct globalvars_s *pr_globals)
|
|
{
|
|
printf("%f\n", G_FLOAT(OFS_PARM0));
|
|
}
|
|
|
|
|
|
void PF_bad (pubprogfuncs_t *prinst, struct globalvars_s *gvars)
|
|
{
|
|
printf("bad builtin\n");
|
|
}
|
|
|
|
builtin_t builtins[] = {
|
|
PF_bad,
|
|
PF_prints,
|
|
PF_printv,
|
|
PF_printf
|
|
};
|
|
|
|
|
|
|
|
|
|
//Called when the qc library has some sort of serious error.
|
|
void Sys_Abort(char *s, ...)
|
|
{ //quake handles this with a longjmp.
|
|
va_list ap;
|
|
va_start(ap, s);
|
|
vprintf(s, ap);
|
|
va_end(ap);
|
|
exit(1);
|
|
}
|
|
//Called when the library has something to say.
|
|
//Kinda required for the compiler...
|
|
//Not really that useful for the normal vm.
|
|
int Sys_Printf(char *s, ...)
|
|
{ //look up quake's va function to find out how to deal with variable arguments properly.
|
|
return printf("%s", s);
|
|
}
|
|
|
|
#include <stdio.h>
|
|
//copy file into buffer. note that the buffer will have been sized to fit the file (obtained via FileSize)
|
|
unsigned char *Sys_ReadFile (char *fname, void *buffer, int buflen)
|
|
{
|
|
int len;
|
|
FILE *f;
|
|
if (!strncmp(fname, "src/", 4))
|
|
fname+=4; //skip the src part
|
|
f = fopen(fname, "rb");
|
|
if (!f)
|
|
return NULL;
|
|
fseek(f, 0, SEEK_END);
|
|
len = ftell(f);
|
|
if (buflen < len)
|
|
return NULL;
|
|
fseek(f, 0, SEEK_SET);
|
|
fread(buffer, 1, len, f);
|
|
fclose(f);
|
|
return buffer;
|
|
}
|
|
//Finds the size of a file.
|
|
int Sys_FileSize (char *fname)
|
|
{
|
|
int len;
|
|
FILE *f;
|
|
if (!strncmp(fname, "src/", 4))
|
|
fname+=4; //skip the src part
|
|
f = fopen(fname, "rb");
|
|
if (!f)
|
|
return -1;
|
|
fseek(f, 0, SEEK_END);
|
|
len = ftell(f);
|
|
fclose(f);
|
|
return len;
|
|
}
|
|
//Writes a file.
|
|
pbool Sys_WriteFile (char *fname, void *data, int len)
|
|
{
|
|
FILE *f;
|
|
f = fopen(fname, "wb");
|
|
if (!f)
|
|
return 0;
|
|
fwrite(data, 1, len, f);
|
|
fclose(f);
|
|
return 1;
|
|
}
|
|
|
|
void runtest(char *progsname)
|
|
{
|
|
pubprogfuncs_t *pf;
|
|
func_t func;
|
|
progsnum_t pn;
|
|
|
|
progparms_t ext;
|
|
memset(&ext, 0, sizeof(ext));
|
|
|
|
ext.progsversion = PROGSTRUCT_VERSION;
|
|
ext.ReadFile = Sys_ReadFile;
|
|
ext.FileSize= Sys_FileSize;
|
|
ext.Abort = Sys_Abort;
|
|
ext.Printf = printf;
|
|
|
|
ext.numglobalbuiltins = sizeof(builtins)/sizeof(builtins[0]);
|
|
ext.globalbuiltins = builtins;
|
|
|
|
pf = InitProgs(&ext);
|
|
pf->Configure(pf, 1024*1024, 1); //memory quantity of 1mb. Maximum progs loadable into the instance of 1
|
|
//If you support multiple progs types, you should tell the VM the offsets here, via RegisterFieldVar
|
|
pn = pf->LoadProgs(pf, progsname, 0, NULL, 0); //load the progs, don't care about the crc, and use those builtins.
|
|
if (pn < 0)
|
|
printf("test: Failed to load progs \"%s\"\n", progsname);
|
|
else
|
|
{
|
|
//allocate qc-acessable strings here for 64bit cpus. (allocate via AddString, tempstringbase is a holding area not used by the actual vm)
|
|
//you can call functions before InitEnts if you want. it's not really advised for anything except naming additional progs. This sample only allows one max.
|
|
|
|
pf->InitEnts(pf, 10); //Now we know how many fields required, we can say how many maximum ents we want to allow. 10 in this case. This can be huge without too many problems.
|
|
|
|
//now it's safe to ED_Alloc.
|
|
|
|
func = pf->FindFunction(pf, "main", PR_ANY); //find the function 'main' in the first progs that has it.
|
|
if (!func)
|
|
printf("Couldn't find function\n");
|
|
else
|
|
pf->ExecuteProgram(pf, func); //call the function
|
|
}
|
|
pf->CloseProgs(pf);
|
|
}
|
|
|
|
|
|
//Run a compiler and nothing else.
|
|
//Note that this could be done with an autocompile of PR_COMPILEALWAYS.
|
|
void compile(int argc, char **argv)
|
|
{
|
|
pubprogfuncs_t *pf;
|
|
|
|
progparms_t ext;
|
|
|
|
if (0)
|
|
{
|
|
char *testsrcfile = //newstyle progs.src must start with a #.
|
|
//it's newstyle to avoid using multiple source files.
|
|
"#pragma PROGS_DAT \"testprogs.dat\"\r\n"
|
|
"//INTERMEDIATE FILE - EDIT TEST.C INSTEAD\r\n"
|
|
"\r\n"
|
|
"void(...) print = #1;\r\n"
|
|
"void() main =\r\n"
|
|
"{\r\n"
|
|
" print(\"hello world\\n\");\r\n"
|
|
"};\r\n";
|
|
|
|
//so that the file exists. We could insert it via the callbacks instead
|
|
Sys_WriteFile("progs.src", testsrcfile, strlen(testsrcfile));
|
|
}
|
|
|
|
memset(&ext, 0, sizeof(ext));
|
|
ext.progsversion = PROGSTRUCT_VERSION;
|
|
ext.ReadFile = Sys_ReadFile;
|
|
ext.FileSize= Sys_FileSize;
|
|
ext.WriteFile= Sys_WriteFile;
|
|
ext.Abort = Sys_Abort;
|
|
ext.Printf = printf;
|
|
|
|
pf = InitProgs(&ext);
|
|
if (pf->StartCompile)
|
|
{
|
|
if (pf->StartCompile(pf, argc, argv))
|
|
{
|
|
while(pf->ContinueCompile(pf) == 1)
|
|
;
|
|
}
|
|
}
|
|
else
|
|
printf("no compiler in this qcvm build\n");
|
|
pf->CloseProgs(pf);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
if (argc < 2)
|
|
{
|
|
printf("Invalid arguments!\nPlease run as, for example:\n%s testprogs.dat -srcfile progs.src\nThe first argument is the name of the progs.dat to run, the remaining arguments are the qcc args to use", argv[0]);
|
|
return 0;
|
|
}
|
|
|
|
compile(argc-1, argv+1);
|
|
runtest(argv[1]);
|
|
|
|
return 0;
|
|
}
|