1void() main = 2{ 3}; 4 5float framecount; 6 7// 8// This function was created to test various aspects of the compiler and 9// serves as a good example of the advanced features which are supported. 10// 11void () RunTests = 12{ 13 local string s = "000":"001":"002":"003"; 14 local float i, p, p2; 15 local entity e; 16 17 dprint("*** Running compiler tests - pairs of lines should match exactly ***\n"); 18 19 dprint("--- integer test ---\n"); 20 dprint(ftos(((5 * %4) - %3) / %1), "\n"); 21 dprint("17\n"); 22 23 dprint("--- string test ---\n"); 24 p = &s; 25 dprint((@p)[%8], "\n"); 26 dprint("002\n"); 27 28 dprint("--- direct pointer test ---\n"); 29 &%100 = 23; 30 dprint(ftos(world.absmin_x), "\n"); 31 dprint("23\n"); 32 33 dprint("--- array test ---\n"); 34 p = &world + %4; 35 i = %0; 36 while (i < %3) 37 { 38 (*p)[i] = (i / %1) + 5; 39 i = i + %1; 40 } 41 e = world + %4; 42 i = %0; 43 while (i < %3) 44 { 45 dprint(ftos(e[i]), " "); 46 i = i + %1; 47 } 48 dprint("\n5 6 7\n"); 49 50 dprint("--- hex32 test ---\n"); 51 hex32(%65534); 52 dprint("0000fffe (65534)\n"); 53 hex32(%-5); 54 dprint("fffffffb (-5)\n"); 55 56 dprint("--- quakec pointer test ---\n"); 57 p = AddInt(&s, PSTRING_TO_PQUAKEC); 58 p2 = AddInt(&mapname, PSTRING_TO_PQUAKEC); 59 (*p)[%1] = (*p2)[0]; 60 dprint(s[%4], "\n"); 61 dprint("dm3\n"); 62 p = AddInt(&mapname, PSTRING_TO_PQUAKEC); 63 p = AddInt((*p)[%867], PC_TO_PQUAKEC); 64 hex32(p); 65 dprint("ffffffa0 (-96)\n"); 66 67 dprint("*** End of tests ***\n"); 68}; 69 70// 71// Print out contents of the internal sv data structure. 72// The sv entity is initialized in InternalInit 73// 74void () DumpSV = 75{ 76 local float p; 77 78 dprint("--- SERVER_T ---\n"); 79 dprint("sv.active = "); 80 hex32(sv[SV_ACTIVE]); 81 dprint("sv.paused = "); 82 hex32(sv[SV_PAUSED]); 83 dprint("sv.loadgame = "); 84 hex32(sv[SV_LOADGAME]); 85 dprint("sv.time = "); 86 hex32(sv[SV_TIME]); 87 dprint(" "); 88 hex32(sv[SV_TIME + %1]); 89 p = AddInt(AddInt(&sv, 4 * SV_NAME), PQUAKEC_TO_PSTRING); 90 dprint("sv.name = ", @p, "\n"); 91 p = AddInt(AddInt(&sv, 4 * SV_MODELNAME), PQUAKEC_TO_PSTRING); 92 dprint("sv.modelname = ", @p, "\n"); 93 dprint("sv.num_edicts = "); 94 hex32(sv[SV_NUM_EDICTS]); 95 dprint("sv.max_edicts = "); 96 hex32(sv[SV_MAX_EDICTS]); 97 dprint("sv.edicts = "); 98 hex32(AddInt(sv[SV_EDICTS], PC_TO_PQUAKEC)); 99 dprint("sv.state = "); 100 hex32(sv[SV_STATE]); 101 dprint("sv.signon.data = "); 102 hex32(AddInt(sv[SV_SIGNON_DATA], PC_TO_PQUAKEC)); 103 dprint("sv.signon.maxsize = "); 104 hex32(sv[SV_SIGNON_MAXSIZE]); 105 dprint("sv.signon.cursize = "); 106 hex32(sv[SV_SIGNON_CURSIZE]); 107 dprint("&sv.signon_buf = "); 108 hex32(AddInt(&sv, 4 * SV_SIGNON_BUF)); 109}; 110 111// 112// Print out the contents of the progs header. 113// The progs entity is initialized by the compiler. 114// 115void () DumpProgs = 116{ 117 dprint("--- DPROGRAMS_T ---\n"); 118 dprint("progs.version = "); 119 hex32(progs[PR_VERSION]); 120 dprint("progs.crc = "); 121 hex32(progs[PR_CRC]); 122 dprint("progs.ofs_statements = "); 123 hex32(progs[PR_OFS_STATEMENTS]); 124 dprint("progs.numstatements = "); 125 hex32(progs[PR_NUMSTATEMENTS]); 126 dprint("progs.ofs_globaldefs = "); 127 hex32(progs[PR_OFS_GLOBALDEFS]); 128 dprint("progs.numglobaldefs = "); 129 hex32(progs[PR_NUMGLOBALDEFS]); 130 dprint("progs.ofs_fielddefs = "); 131 hex32(progs[PR_OFS_FIELDDEFS]); 132 dprint("progs.numfielddefs = "); 133 hex32(progs[PR_NUMFIELDDEFS]); 134 dprint("progs.ofs_functions = "); 135 hex32(progs[PR_OFS_FUNCTIONS]); 136 dprint("progs.numfunctions = "); 137 hex32(progs[PR_NUMFUNCTIONS]); 138 dprint("progs.ofs_strings = "); 139 hex32(progs[PR_OFS_STRINGS]); 140 dprint("progs.numstrings = "); 141 hex32(progs[PR_NUMSTRINGS]); 142 dprint("progs.ofs_globals = "); 143 hex32(progs[PR_OFS_GLOBALS]); 144 dprint("progs.numglobals = "); 145 hex32(progs[PR_NUMGLOBALS]); 146 dprint("progs.entityfields = "); 147 hex32(progs[PR_ENTITYFIELDS]); 148}; 149 150// 151// Example of the '#' optimization 152// 153void (string s1, string s2, string s3) twice = 154{ 155 dprint(#, #, #, " <- first time!\n"); 156 dprint(#, #, #, " <- second time!\n"); 157}; 158 159// 160// First QuakeC function to be called. Always call InternalInit from 161// this function before you even think of doing anything else. 162// 163void() worldspawn = 164{ 165 // enable dprint 166 cvar_set("developer", "1"); 167 168 // Call this right away! 169 InternalInit(); 170 171 // quake complains if this isn't precached 172 precache_model("progs/player.mdl"); 173 174 // main tests 175 RunTests(); 176 177 // Some other stuff you can play around with 178 179 //DumpSV(); 180 //DumpProgs(); 181 //twice("This ", "is ", "a test"); 182 //fnstring(&worldspawn); 183 //fnstring(&fnstring); 184 185 // This one is really cool.. it inspects the hunk and finds everything in it. 186 187 //InitHunkSearch(); 188 189 190local entity e; 191local string s = "Hi tXXXXhere"; 192local float psource, pdest; 193 194e = *%600; 195psource = AddInt(&s, PSTRING_TO_PQUAKEC); 196e[0] = (*psource)[0]; 197e[%1] = (*psource)[%2]; 198pdest = AddInt(&e, PQUAKEC_TO_PSTRING); 199dprint(@pdest, "\n"); 200 201 202 cvar_set("developer", "0"); 203}; 204 205void() StartFrame = 206{ 207 // enable dprint 208 cvar_set("developer", "1"); 209 210 framecount = framecount + 1; 211 212 if (lasth) 213 SearchHunk(); 214 215 cvar_set("developer", "0"); 216}; 217