3 #include "clprogdefs.h"
5 #include "cl_collision.h"
10 //============================================================================
11 // Client prog handling
12 //[515]: omg !!! optimize it ! a lot of hacks here and there also :P
14 #define CSQC_RETURNVAL prog->globals.fp[OFS_RETURN]
18 void CL_VM_PreventInformationLeaks(void)
20 prvm_prog_t *prog = CLVM_prog;
24 VM_ClearTraceGlobals(prog);
25 PRVM_clientglobalfloat(trace_networkentity) = 0;
29 //[515]: these are required funcs
30 static const char *cl_required_func[] =
35 "CSQC_ConsoleCommand",
38 static int cl_numrequiredfunc = sizeof(cl_required_func) / sizeof(char*);
40 #define CL_REQFIELDS (sizeof(cl_reqfields) / sizeof(prvm_required_field_t))
42 prvm_required_field_t cl_reqfields[] =
44 #define PRVM_DECLARE_serverglobalfloat(x)
45 #define PRVM_DECLARE_serverglobalvector(x)
46 #define PRVM_DECLARE_serverglobalstring(x)
47 #define PRVM_DECLARE_serverglobaledict(x)
48 #define PRVM_DECLARE_serverglobalfunction(x)
49 #define PRVM_DECLARE_clientglobalfloat(x)
50 #define PRVM_DECLARE_clientglobalvector(x)
51 #define PRVM_DECLARE_clientglobalstring(x)
52 #define PRVM_DECLARE_clientglobaledict(x)
53 #define PRVM_DECLARE_clientglobalfunction(x)
54 #define PRVM_DECLARE_menuglobalfloat(x)
55 #define PRVM_DECLARE_menuglobalvector(x)
56 #define PRVM_DECLARE_menuglobalstring(x)
57 #define PRVM_DECLARE_menuglobaledict(x)
58 #define PRVM_DECLARE_menuglobalfunction(x)
59 #define PRVM_DECLARE_serverfieldfloat(x)
60 #define PRVM_DECLARE_serverfieldvector(x)
61 #define PRVM_DECLARE_serverfieldstring(x)
62 #define PRVM_DECLARE_serverfieldedict(x)
63 #define PRVM_DECLARE_serverfieldfunction(x)
64 #define PRVM_DECLARE_clientfieldfloat(x) {ev_float, #x },
65 #define PRVM_DECLARE_clientfieldvector(x) {ev_vector, #x },
66 #define PRVM_DECLARE_clientfieldstring(x) {ev_string, #x },
67 #define PRVM_DECLARE_clientfieldedict(x) {ev_entity, #x },
68 #define PRVM_DECLARE_clientfieldfunction(x) {ev_function, #x },
69 #define PRVM_DECLARE_menufieldfloat(x)
70 #define PRVM_DECLARE_menufieldvector(x)
71 #define PRVM_DECLARE_menufieldstring(x)
72 #define PRVM_DECLARE_menufieldedict(x)
73 #define PRVM_DECLARE_menufieldfunction(x)
74 #define PRVM_DECLARE_serverfunction(x)
75 #define PRVM_DECLARE_clientfunction(x)
76 #define PRVM_DECLARE_menufunction(x)
77 #define PRVM_DECLARE_field(x)
78 #define PRVM_DECLARE_global(x)
79 #define PRVM_DECLARE_function(x)
80 #include "prvm_offsets.h"
81 #undef PRVM_DECLARE_serverglobalfloat
82 #undef PRVM_DECLARE_serverglobalvector
83 #undef PRVM_DECLARE_serverglobalstring
84 #undef PRVM_DECLARE_serverglobaledict
85 #undef PRVM_DECLARE_serverglobalfunction
86 #undef PRVM_DECLARE_clientglobalfloat
87 #undef PRVM_DECLARE_clientglobalvector
88 #undef PRVM_DECLARE_clientglobalstring
89 #undef PRVM_DECLARE_clientglobaledict
90 #undef PRVM_DECLARE_clientglobalfunction
91 #undef PRVM_DECLARE_menuglobalfloat
92 #undef PRVM_DECLARE_menuglobalvector
93 #undef PRVM_DECLARE_menuglobalstring
94 #undef PRVM_DECLARE_menuglobaledict
95 #undef PRVM_DECLARE_menuglobalfunction
96 #undef PRVM_DECLARE_serverfieldfloat
97 #undef PRVM_DECLARE_serverfieldvector
98 #undef PRVM_DECLARE_serverfieldstring
99 #undef PRVM_DECLARE_serverfieldedict
100 #undef PRVM_DECLARE_serverfieldfunction
101 #undef PRVM_DECLARE_clientfieldfloat
102 #undef PRVM_DECLARE_clientfieldvector
103 #undef PRVM_DECLARE_clientfieldstring
104 #undef PRVM_DECLARE_clientfieldedict
105 #undef PRVM_DECLARE_clientfieldfunction
106 #undef PRVM_DECLARE_menufieldfloat
107 #undef PRVM_DECLARE_menufieldvector
108 #undef PRVM_DECLARE_menufieldstring
109 #undef PRVM_DECLARE_menufieldedict
110 #undef PRVM_DECLARE_menufieldfunction
111 #undef PRVM_DECLARE_serverfunction
112 #undef PRVM_DECLARE_clientfunction
113 #undef PRVM_DECLARE_menufunction
114 #undef PRVM_DECLARE_field
115 #undef PRVM_DECLARE_global
116 #undef PRVM_DECLARE_function
119 #define CL_REQGLOBALS (sizeof(cl_reqglobals) / sizeof(prvm_required_field_t))
121 prvm_required_field_t cl_reqglobals[] =
123 #define PRVM_DECLARE_serverglobalfloat(x)
124 #define PRVM_DECLARE_serverglobalvector(x)
125 #define PRVM_DECLARE_serverglobalstring(x)
126 #define PRVM_DECLARE_serverglobaledict(x)
127 #define PRVM_DECLARE_serverglobalfunction(x)
128 #define PRVM_DECLARE_clientglobalfloat(x) {ev_float, #x},
129 #define PRVM_DECLARE_clientglobalvector(x) {ev_vector, #x},
130 #define PRVM_DECLARE_clientglobalstring(x) {ev_string, #x},
131 #define PRVM_DECLARE_clientglobaledict(x) {ev_entity, #x},
132 #define PRVM_DECLARE_clientglobalfunction(x) {ev_function, #x},
133 #define PRVM_DECLARE_menuglobalfloat(x)
134 #define PRVM_DECLARE_menuglobalvector(x)
135 #define PRVM_DECLARE_menuglobalstring(x)
136 #define PRVM_DECLARE_menuglobaledict(x)
137 #define PRVM_DECLARE_menuglobalfunction(x)
138 #define PRVM_DECLARE_serverfieldfloat(x)
139 #define PRVM_DECLARE_serverfieldvector(x)
140 #define PRVM_DECLARE_serverfieldstring(x)
141 #define PRVM_DECLARE_serverfieldedict(x)
142 #define PRVM_DECLARE_serverfieldfunction(x)
143 #define PRVM_DECLARE_clientfieldfloat(x)
144 #define PRVM_DECLARE_clientfieldvector(x)
145 #define PRVM_DECLARE_clientfieldstring(x)
146 #define PRVM_DECLARE_clientfieldedict(x)
147 #define PRVM_DECLARE_clientfieldfunction(x)
148 #define PRVM_DECLARE_menufieldfloat(x)
149 #define PRVM_DECLARE_menufieldvector(x)
150 #define PRVM_DECLARE_menufieldstring(x)
151 #define PRVM_DECLARE_menufieldedict(x)
152 #define PRVM_DECLARE_menufieldfunction(x)
153 #define PRVM_DECLARE_serverfunction(x)
154 #define PRVM_DECLARE_clientfunction(x)
155 #define PRVM_DECLARE_menufunction(x)
156 #define PRVM_DECLARE_field(x)
157 #define PRVM_DECLARE_global(x)
158 #define PRVM_DECLARE_function(x)
159 #include "prvm_offsets.h"
160 #undef PRVM_DECLARE_serverglobalfloat
161 #undef PRVM_DECLARE_serverglobalvector
162 #undef PRVM_DECLARE_serverglobalstring
163 #undef PRVM_DECLARE_serverglobaledict
164 #undef PRVM_DECLARE_serverglobalfunction
165 #undef PRVM_DECLARE_clientglobalfloat
166 #undef PRVM_DECLARE_clientglobalvector
167 #undef PRVM_DECLARE_clientglobalstring
168 #undef PRVM_DECLARE_clientglobaledict
169 #undef PRVM_DECLARE_clientglobalfunction
170 #undef PRVM_DECLARE_menuglobalfloat
171 #undef PRVM_DECLARE_menuglobalvector
172 #undef PRVM_DECLARE_menuglobalstring
173 #undef PRVM_DECLARE_menuglobaledict
174 #undef PRVM_DECLARE_menuglobalfunction
175 #undef PRVM_DECLARE_serverfieldfloat
176 #undef PRVM_DECLARE_serverfieldvector
177 #undef PRVM_DECLARE_serverfieldstring
178 #undef PRVM_DECLARE_serverfieldedict
179 #undef PRVM_DECLARE_serverfieldfunction
180 #undef PRVM_DECLARE_clientfieldfloat
181 #undef PRVM_DECLARE_clientfieldvector
182 #undef PRVM_DECLARE_clientfieldstring
183 #undef PRVM_DECLARE_clientfieldedict
184 #undef PRVM_DECLARE_clientfieldfunction
185 #undef PRVM_DECLARE_menufieldfloat
186 #undef PRVM_DECLARE_menufieldvector
187 #undef PRVM_DECLARE_menufieldstring
188 #undef PRVM_DECLARE_menufieldedict
189 #undef PRVM_DECLARE_menufieldfunction
190 #undef PRVM_DECLARE_serverfunction
191 #undef PRVM_DECLARE_clientfunction
192 #undef PRVM_DECLARE_menufunction
193 #undef PRVM_DECLARE_field
194 #undef PRVM_DECLARE_global
195 #undef PRVM_DECLARE_function
198 void CL_VM_UpdateDmgGlobals (int dmg_take, int dmg_save, vec3_t dmg_origin)
200 prvm_prog_t *prog = CLVM_prog;
204 PRVM_clientglobalfloat(dmg_take) = dmg_take;
205 PRVM_clientglobalfloat(dmg_save) = dmg_save;
206 VectorCopy(dmg_origin, PRVM_clientglobalvector(dmg_origin));
211 void CSQC_UpdateNetworkTimes(double newtime, double oldtime)
213 prvm_prog_t *prog = CLVM_prog;
217 PRVM_clientglobalfloat(servertime) = newtime;
218 PRVM_clientglobalfloat(serverprevtime) = oldtime;
219 PRVM_clientglobalfloat(serverdeltatime) = newtime - oldtime;
223 //[515]: set globals before calling R_UpdateView, WEIRD CRAP
224 static void CSQC_SetGlobals (void)
227 prvm_prog_t *prog = CLVM_prog;
229 PRVM_clientglobalfloat(time) = cl.time;
230 PRVM_clientglobalfloat(frametime) = max(0, cl.time - cl.oldtime);
231 PRVM_clientglobalfloat(servercommandframe) = cls.servermovesequence;
232 PRVM_clientglobalfloat(clientcommandframe) = cl.movecmd[0].sequence;
233 VectorCopy(cl.viewangles, PRVM_clientglobalvector(input_angles));
234 // // FIXME: this actually belongs into getinputstate().. [12/17/2007 Black]
235 PRVM_clientglobalfloat(input_buttons) = cl.movecmd[0].buttons;
236 VectorSet(PRVM_clientglobalvector(input_movevalues), cl.movecmd[0].forwardmove, cl.movecmd[0].sidemove, cl.movecmd[0].upmove);
237 VectorCopy(cl.csqc_vieworiginfromengine, cl.csqc_vieworigin);
238 VectorCopy(cl.csqc_viewanglesfromengine, cl.csqc_viewangles);
240 // LordHavoc: Spike says not to do this, but without pmove_org the
241 // CSQC is useless as it can't alter the view origin without
242 // completely replacing it
243 Matrix4x4_OriginFromMatrix(&cl.entities[cl.viewentity].render.matrix, pmove_org);
244 VectorCopy(pmove_org, PRVM_clientglobalvector(pmove_org));
245 VectorCopy(cl.movement_velocity, PRVM_clientglobalvector(pmove_vel));
246 PRVM_clientglobalfloat(pmove_onground) = cl.onground;
247 PRVM_clientglobalfloat(pmove_inwater) = cl.inwater;
249 VectorCopy(cl.viewangles, PRVM_clientglobalvector(view_angles));
250 VectorCopy(cl.punchangle, PRVM_clientglobalvector(view_punchangle));
251 VectorCopy(cl.punchvector, PRVM_clientglobalvector(view_punchvector));
252 PRVM_clientglobalfloat(maxclients) = cl.maxclients;
254 PRVM_clientglobalfloat(player_localentnum) = cl.viewentity;
260 void CSQC_Predraw (prvm_edict_t *ed)
262 prvm_prog_t *prog = CLVM_prog;
264 if(!PRVM_clientedictfunction(ed, predraw))
266 b = PRVM_clientglobaledict(self);
267 PRVM_clientglobaledict(self) = PRVM_EDICT_TO_PROG(ed);
268 prog->ExecuteProgram(prog, PRVM_clientedictfunction(ed, predraw), "CSQC_Predraw: NULL function\n");
269 PRVM_clientglobaledict(self) = b;
272 void CSQC_Think (prvm_edict_t *ed)
274 prvm_prog_t *prog = CLVM_prog;
276 if(PRVM_clientedictfunction(ed, think))
277 if(PRVM_clientedictfloat(ed, nextthink) && PRVM_clientedictfloat(ed, nextthink) <= PRVM_clientglobalfloat(time))
279 PRVM_clientedictfloat(ed, nextthink) = 0;
280 b = PRVM_clientglobaledict(self);
281 PRVM_clientglobaledict(self) = PRVM_EDICT_TO_PROG(ed);
282 prog->ExecuteProgram(prog, PRVM_clientedictfunction(ed, think), "CSQC_Think: NULL function\n");
283 PRVM_clientglobaledict(self) = b;
287 extern cvar_t cl_noplayershadow;
288 extern cvar_t r_equalize_entities_fullbright;
289 qboolean CSQC_AddRenderEdict(prvm_edict_t *ed, int edictnum)
291 prvm_prog_t *prog = CLVM_prog;
295 entity_render_t *entrender;
298 model = CL_GetModelFromEdict(ed);
304 if (r_refdef.scene.numentities >= r_refdef.scene.maxentities)
306 entrender = cl.csqcrenderentities + edictnum;
307 r_refdef.scene.entities[r_refdef.scene.numentities++] = entrender;
308 entrender->entitynumber = edictnum + MAX_EDICTS;
309 //entrender->shadertime = 0; // shadertime was set by spawn()
310 entrender->flags = 0;
311 entrender->effects = 0;
312 entrender->alpha = 1;
313 entrender->scale = 1;
314 VectorSet(entrender->colormod, 1, 1, 1);
315 VectorSet(entrender->glowmod, 1, 1, 1);
316 entrender->allowdecals = true;
320 entrender = CL_NewTempEntity(0);
325 entrender->userwavefunc_param[0] = PRVM_clientedictfloat(ed, userwavefunc_param0);
326 entrender->userwavefunc_param[1] = PRVM_clientedictfloat(ed, userwavefunc_param1);
327 entrender->userwavefunc_param[2] = PRVM_clientedictfloat(ed, userwavefunc_param2);
328 entrender->userwavefunc_param[3] = PRVM_clientedictfloat(ed, userwavefunc_param3);
330 entrender->model = model;
331 entrender->skinnum = (int)PRVM_clientedictfloat(ed, skin);
332 entrender->effects |= entrender->model->effects;
333 renderflags = (int)PRVM_clientedictfloat(ed, renderflags);
334 entrender->alpha = PRVM_clientedictfloat(ed, alpha);
335 entrender->scale = scale = PRVM_clientedictfloat(ed, scale);
336 VectorCopy(PRVM_clientedictvector(ed, colormod), entrender->colormod);
337 VectorCopy(PRVM_clientedictvector(ed, glowmod), entrender->glowmod);
338 if(PRVM_clientedictfloat(ed, effects)) entrender->effects |= (int)PRVM_clientedictfloat(ed, effects);
339 if (!entrender->alpha)
340 entrender->alpha = 1.0f;
341 if (!entrender->scale)
342 entrender->scale = scale = 1.0f;
343 if (!VectorLength2(entrender->colormod))
344 VectorSet(entrender->colormod, 1, 1, 1);
345 if (!VectorLength2(entrender->glowmod))
346 VectorSet(entrender->glowmod, 1, 1, 1);
348 // LordHavoc: use the CL_GetTagMatrix function on self to ensure consistent behavior (duplicate code would be bad)
349 CL_GetTagMatrix(prog, &entrender->matrix, ed, 0);
351 // set up the animation data
352 VM_GenerateFrameGroupBlend(prog, ed->priv.server->framegroupblend, ed);
353 VM_FrameBlendFromFrameGroupBlend(ed->priv.server->frameblend, ed->priv.server->framegroupblend, model, cl.time);
354 VM_UpdateEdictSkeleton(prog, ed, model, ed->priv.server->frameblend);
355 if (PRVM_clientedictfloat(ed, shadertime)) // hack for csprogs.dat files that do not set shadertime, leaves the value at entity spawn time
356 entrender->shadertime = PRVM_clientedictfloat(ed, shadertime);
358 // transparent offset
359 if (renderflags & RF_USETRANSPARENTOFFSET)
360 entrender->transparent_offset = PRVM_clientglobalfloat(transparent_offset);
363 if (renderflags & RF_MODELLIGHT)
365 if (PRVM_clientedictvector(ed, modellight_ambient)) VectorCopy(PRVM_clientedictvector(ed, modellight_ambient), entrender->modellight_ambient); else VectorClear(entrender->modellight_ambient);
366 if (PRVM_clientedictvector(ed, modellight_diffuse)) VectorCopy(PRVM_clientedictvector(ed, modellight_diffuse), entrender->modellight_diffuse); else VectorClear(entrender->modellight_diffuse);
367 if (PRVM_clientedictvector(ed, modellight_dir)) VectorCopy(PRVM_clientedictvector(ed, modellight_dir), entrender->modellight_lightdir); else VectorClear(entrender->modellight_lightdir);
368 entrender->flags |= RENDER_CUSTOMIZEDMODELLIGHT;
373 if(renderflags & RF_VIEWMODEL) entrender->flags |= RENDER_VIEWMODEL | RENDER_NODEPTHTEST;
374 if(renderflags & RF_EXTERNALMODEL) entrender->flags |= RENDER_EXTERIORMODEL;
375 if(renderflags & RF_WORLDOBJECT) entrender->flags |= RENDER_WORLDOBJECT;
376 if(renderflags & RF_DEPTHHACK) entrender->flags |= RENDER_NODEPTHTEST;
377 if(renderflags & RF_ADDITIVE) entrender->flags |= RENDER_ADDITIVE;
378 if(renderflags & RF_DYNAMICMODELLIGHT) entrender->flags |= RENDER_DYNAMICMODELLIGHT;
381 c = (int)PRVM_clientedictfloat(ed, colormap);
383 CL_SetEntityColormapColors(entrender, -1);
384 else if (c <= cl.maxclients && cl.scores != NULL)
385 CL_SetEntityColormapColors(entrender, cl.scores[c-1].colors);
387 CL_SetEntityColormapColors(entrender, c);
389 entrender->flags &= ~(RENDER_SHADOW | RENDER_LIGHT | RENDER_NOSELFSHADOW);
390 // either fullbright or lit
391 if(!r_fullbright.integer)
393 if (!(entrender->effects & EF_FULLBRIGHT) && !(renderflags & RF_FULLBRIGHT))
394 entrender->flags |= RENDER_LIGHT;
395 else if(r_equalize_entities_fullbright.integer)
396 entrender->flags |= RENDER_LIGHT | RENDER_EQUALIZE;
398 // hide player shadow during intermission or nehahra movie
399 if (!(entrender->effects & (EF_NOSHADOW | EF_ADDITIVE | EF_NODEPTHTEST))
400 && (entrender->alpha >= 1)
401 && !(renderflags & RF_NOSHADOW)
402 && !(entrender->flags & RENDER_VIEWMODEL)
403 && (!(entrender->flags & RENDER_EXTERIORMODEL) || (!cl.intermission && cls.protocol != PROTOCOL_NEHAHRAMOVIE && !cl_noplayershadow.integer)))
404 entrender->flags |= RENDER_SHADOW;
405 if (entrender->flags & RENDER_VIEWMODEL)
406 entrender->flags |= RENDER_NOSELFSHADOW;
407 if (entrender->effects & EF_NOSELFSHADOW)
408 entrender->flags |= RENDER_NOSELFSHADOW;
409 if (entrender->effects & EF_NODEPTHTEST)
410 entrender->flags |= RENDER_NODEPTHTEST;
411 if (entrender->effects & EF_ADDITIVE)
412 entrender->flags |= RENDER_ADDITIVE;
413 if (entrender->effects & EF_DOUBLESIDED)
414 entrender->flags |= RENDER_DOUBLESIDED;
415 if (entrender->effects & EF_DYNAMICMODELLIGHT)
416 entrender->flags |= RENDER_DYNAMICMODELLIGHT;
418 // make the other useful stuff
419 memcpy(entrender->framegroupblend, ed->priv.server->framegroupblend, sizeof(ed->priv.server->framegroupblend));
420 CL_UpdateRenderEntity(entrender);
422 // override animation data with full control
423 memcpy(entrender->frameblend, ed->priv.server->frameblend, sizeof(ed->priv.server->frameblend));
424 if (ed->priv.server->skeleton.relativetransforms)
425 entrender->skeleton = &ed->priv.server->skeleton;
427 entrender->skeleton = NULL;
432 // 0 = keydown, key, character (EXT_CSQC)
433 // 1 = keyup, key, character (EXT_CSQC)
434 // 2 = mousemove relative, x, y (EXT_CSQC)
435 // 3 = mousemove absolute, x, y (DP_CSQC)
436 qboolean CL_VM_InputEvent (int eventtype, int x, int y)
438 prvm_prog_t *prog = CLVM_prog;
445 if (!PRVM_clientfunction(CSQC_InputEvent))
449 PRVM_clientglobalfloat(time) = cl.time;
450 PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[cl.playerentity];
451 PRVM_G_FLOAT(OFS_PARM0) = eventtype;
452 PRVM_G_FLOAT(OFS_PARM1) = x; // key or x
453 PRVM_G_FLOAT(OFS_PARM2) = y; // ascii or y
454 prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_InputEvent), "QC function CSQC_InputEvent is missing");
455 r = CSQC_RETURNVAL != 0;
461 extern r_refdef_view_t csqc_original_r_refdef_view;
462 extern r_refdef_view_t csqc_main_r_refdef_view;
463 qboolean CL_VM_UpdateView (void)
465 prvm_prog_t *prog = CLVM_prog;
473 R_TimeReport("pre-UpdateView");
475 r_refdef.view.ismain = true;
476 csqc_original_r_refdef_view = r_refdef.view;
477 csqc_main_r_refdef_view = r_refdef.view;
478 //VectorCopy(cl.viewangles, oldangles);
479 PRVM_clientglobalfloat(time) = cl.time;
480 PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[cl.playerentity];
482 // clear renderable entity and light lists to prevent crashes if the
483 // CSQC_UpdateView function does not call R_ClearScene as it should
484 r_refdef.scene.numentities = 0;
485 r_refdef.scene.numlights = 0;
486 // pass in width and height as parameters (EXT_CSQC_1)
487 PRVM_G_FLOAT(OFS_PARM0) = vid.width;
488 PRVM_G_FLOAT(OFS_PARM1) = vid.height;
489 prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_UpdateView), "QC function CSQC_UpdateView is missing");
490 //VectorCopy(oldangles, cl.viewangles);
491 // Dresk : Reset Dmg Globals Here
492 CL_VM_UpdateDmgGlobals(0, 0, emptyvector);
493 r_refdef.view = csqc_main_r_refdef_view;
494 R_RenderView_UpdateViewVectors(); // we have to do this, as we undid the scene render doing this for us
497 R_TimeReport("UpdateView");
501 qboolean CL_VM_ConsoleCommand (const char *cmd)
503 prvm_prog_t *prog = CLVM_prog;
504 int restorevm_tempstringsbuf_cursize;
509 if (PRVM_clientfunction(CSQC_ConsoleCommand))
511 PRVM_clientglobalfloat(time) = cl.time;
512 PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[cl.playerentity];
513 restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
514 PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, cmd);
515 prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_ConsoleCommand), "QC function CSQC_ConsoleCommand is missing");
516 prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
517 r = CSQC_RETURNVAL != 0;
523 qboolean CL_VM_Parse_TempEntity (void)
525 prvm_prog_t *prog = CLVM_prog;
531 if(PRVM_clientfunction(CSQC_Parse_TempEntity))
533 t = cl_message.readcount;
534 PRVM_clientglobalfloat(time) = cl.time;
535 PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[cl.playerentity];
536 prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_Parse_TempEntity), "QC function CSQC_Parse_TempEntity is missing");
537 r = CSQC_RETURNVAL != 0;
540 cl_message.readcount = t;
541 cl_message.badread = false;
548 void CL_VM_Parse_StuffCmd (const char *msg)
550 prvm_prog_t *prog = CLVM_prog;
551 int restorevm_tempstringsbuf_cursize;
557 // if this is setting a csqc variable, deprotect csqc_progcrc
558 // temporarily so that it can be set by the cvar command,
559 // and then reprotect it afterwards
560 int crcflags = csqc_progcrc.flags;
561 int sizeflags = csqc_progcrc.flags;
562 csqc_progcrc.flags &= ~CVAR_READONLY;
563 csqc_progsize.flags &= ~CVAR_READONLY;
564 Cmd_ExecuteString (msg, src_command, true);
565 csqc_progcrc.flags = crcflags;
566 csqc_progsize.flags = sizeflags;
571 if(!strncmp(msg, "curl --clear_autodownload\ncurl --pak --forthismap --as ", 55))
573 // special handling for map download commands
574 // run these commands IMMEDIATELY, instead of waiting for a client frame
575 // that way, there is no black screen when playing back demos
576 // I know this is a really ugly hack, but I can't think of any better way
577 // FIXME find the actual CAUSE of this, and make demo playback WAIT
578 // until all maps are loaded, then remove this hack
580 char buf[MAX_INPUTLINE];
593 if(l > sizeof(buf) - 1)
595 strlcpy(buf, p, l + 1); // strlcpy needs a + 1 as it includes the newline!
597 Cmd_ExecuteString(buf, src_command, true);
601 ++p; // skip the newline and continue
603 break; // end of string or overflow
605 Cmd_ExecuteString("curl --clear_autodownload", src_command, true); // don't inhibit CSQC loading
615 if(PRVM_clientfunction(CSQC_Parse_StuffCmd))
617 PRVM_clientglobalfloat(time) = cl.time;
618 PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[cl.playerentity];
619 restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
620 PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, msg);
621 prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_Parse_StuffCmd), "QC function CSQC_Parse_StuffCmd is missing");
622 prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
629 static void CL_VM_Parse_Print (const char *msg)
631 prvm_prog_t *prog = CLVM_prog;
632 int restorevm_tempstringsbuf_cursize;
633 PRVM_clientglobalfloat(time) = cl.time;
634 PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[cl.playerentity];
635 restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
636 PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, msg);
637 prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_Parse_Print), "QC function CSQC_Parse_Print is missing");
638 prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
641 void CSQC_AddPrintText (const char *msg)
643 prvm_prog_t *prog = CLVM_prog;
651 if(PRVM_clientfunction(CSQC_Parse_Print))
653 // FIXME: is this bugged?
655 if(msg[i] != '\n' && msg[i] != '\r')
657 if(strlen(cl.csqc_printtextbuf)+i >= MAX_INPUTLINE)
659 CL_VM_Parse_Print(cl.csqc_printtextbuf);
660 cl.csqc_printtextbuf[0] = 0;
663 strlcat(cl.csqc_printtextbuf, msg, MAX_INPUTLINE);
666 strlcat(cl.csqc_printtextbuf, msg, MAX_INPUTLINE);
667 CL_VM_Parse_Print(cl.csqc_printtextbuf);
668 cl.csqc_printtextbuf[0] = 0;
675 void CL_VM_Parse_CenterPrint (const char *msg)
677 prvm_prog_t *prog = CLVM_prog;
678 int restorevm_tempstringsbuf_cursize;
681 SCR_CenterPrint(msg);
685 if(PRVM_clientfunction(CSQC_Parse_CenterPrint))
687 PRVM_clientglobalfloat(time) = cl.time;
688 PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[cl.playerentity];
689 restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
690 PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, msg);
691 prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_Parse_CenterPrint), "QC function CSQC_Parse_CenterPrint is missing");
692 prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
695 SCR_CenterPrint(msg);
699 void CL_VM_UpdateIntermissionState (int intermission)
701 prvm_prog_t *prog = CLVM_prog;
705 PRVM_clientglobalfloat(intermission) = intermission;
709 void CL_VM_UpdateShowingScoresState (int showingscores)
711 prvm_prog_t *prog = CLVM_prog;
715 PRVM_clientglobalfloat(sb_showscores) = showingscores;
719 qboolean CL_VM_Event_Sound(int sound_num, float volume, int channel, float attenuation, int ent, vec3_t pos, int flags, float speed)
721 prvm_prog_t *prog = CLVM_prog;
726 if(PRVM_clientfunction(CSQC_Event_Sound))
728 PRVM_clientglobalfloat(time) = cl.time;
729 PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[cl.playerentity];
730 PRVM_G_FLOAT(OFS_PARM0) = ent;
731 PRVM_G_FLOAT(OFS_PARM1) = CHAN_ENGINE2USER(channel);
732 PRVM_G_INT(OFS_PARM2) = PRVM_SetTempString(prog, cl.sound_name[sound_num] );
733 PRVM_G_FLOAT(OFS_PARM3) = volume;
734 PRVM_G_FLOAT(OFS_PARM4) = attenuation;
735 VectorCopy(pos, PRVM_G_VECTOR(OFS_PARM5) );
736 PRVM_G_FLOAT(OFS_PARM6) = speed * 100.0f;
737 PRVM_G_FLOAT(OFS_PARM7) = flags; // flags
738 prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_Event_Sound), "QC function CSQC_Event_Sound is missing");
739 r = CSQC_RETURNVAL != 0;
746 static void CL_VM_UpdateCoopDeathmatchGlobals (int gametype)
748 prvm_prog_t *prog = CLVM_prog;
749 // Avoid global names for clean(er) coding
755 if(gametype == GAME_COOP)
761 if(gametype == GAME_DEATHMATCH)
768 // How did the ServerInfo send an unknown gametype?
769 // Better just assign the globals as 0...
774 PRVM_clientglobalfloat(coop) = localcoop;
775 PRVM_clientglobalfloat(deathmatch) = localdeathmatch;
780 static float CL_VM_Event (float event) //[515]: needed ? I'd say "YES", but don't know for what :D
782 prvm_prog_t *prog = CLVM_prog;
787 if(PRVM_clientfunction(CSQC_Event))
789 PRVM_clientglobalfloat(time) = cl.time;
790 PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[cl.playerentity];
791 PRVM_G_FLOAT(OFS_PARM0) = event;
792 prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_Event), "QC function CSQC_Event is missing");
800 void CSQC_ReadEntities (void)
802 prvm_prog_t *prog = CLVM_prog;
803 unsigned short entnum, oldself, realentnum;
806 Host_Error ("CSQC_ReadEntities: CSQC is not loaded");
811 PRVM_clientglobalfloat(time) = cl.time;
812 oldself = PRVM_clientglobaledict(self);
815 entnum = MSG_ReadShort(&cl_message);
816 if(!entnum || cl_message.badread)
818 realentnum = entnum & 0x7FFF;
819 PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[realentnum];
822 if(PRVM_clientglobaledict(self))
824 prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_Ent_Remove), "QC function CSQC_Ent_Remove is missing");
825 cl.csqc_server2csqcentitynumber[realentnum] = 0;
829 // LordHavoc: removing an entity that is already gone on
830 // the csqc side is possible for legitimate reasons (such
831 // as a repeat of the remove message), so no warning is
833 //Con_Printf("Bad csqc_server2csqcentitynumber map\n"); //[515]: never happens ?
838 if(!PRVM_clientglobaledict(self))
840 if(!PRVM_clientfunction(CSQC_Ent_Spawn))
843 ed = PRVM_ED_Alloc(prog);
844 PRVM_clientedictfloat(ed, entnum) = realentnum;
845 PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[realentnum] = PRVM_EDICT_TO_PROG(ed);
849 // entity( float entnum ) CSQC_Ent_Spawn;
850 // the qc function should set entnum, too (this way it also can return world [2/1/2008 Andreas]
851 PRVM_G_FLOAT(OFS_PARM0) = (float) realentnum;
852 // make sure no one gets wrong ideas
853 PRVM_clientglobaledict(self) = 0;
854 prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_Ent_Spawn), "QC function CSQC_Ent_Spawn is missing");
855 PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[realentnum] = PRVM_EDICT( PRVM_G_INT( OFS_RETURN ) );
857 PRVM_G_FLOAT(OFS_PARM0) = 1;
858 prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_Ent_Update), "QC function CSQC_Ent_Update is missing");
861 PRVM_G_FLOAT(OFS_PARM0) = 0;
862 prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_Ent_Update), "QC function CSQC_Ent_Update is missing");
866 PRVM_clientglobaledict(self) = oldself;
870 static void CLVM_begin_increase_edicts(prvm_prog_t *prog)
872 // links don't survive the transition, so unlink everything
873 World_UnlinkAll(&cl.world);
876 static void CLVM_end_increase_edicts(prvm_prog_t *prog)
881 // link every entity except world
882 for (i = 1, ent = prog->edicts;i < prog->num_edicts;i++, ent++)
883 if (!ent->priv.server->free)
887 static void CLVM_init_edict(prvm_prog_t *prog, prvm_edict_t *e)
889 int edictnum = PRVM_NUM_FOR_EDICT(e);
890 entity_render_t *entrender;
891 CL_ExpandCSQCRenderEntities(edictnum);
892 entrender = cl.csqcrenderentities + edictnum;
893 e->priv.server->move = false; // don't move on first frame
894 memset(entrender, 0, sizeof(*entrender));
895 entrender->shadertime = cl.time;
898 static void CLVM_free_edict(prvm_prog_t *prog, prvm_edict_t *ed)
900 entity_render_t *entrender = cl.csqcrenderentities + PRVM_NUM_FOR_EDICT(ed);
901 R_DecalSystem_Reset(&entrender->decalsystem);
902 memset(entrender, 0, sizeof(*entrender));
903 World_UnlinkEdict(ed);
904 memset(ed->fields.fp, 0, prog->entityfields * sizeof(prvm_vec_t));
905 VM_RemoveEdictSkeleton(prog, ed);
906 World_Physics_RemoveFromEntity(&cl.world, ed);
907 World_Physics_RemoveJointFromEntity(&cl.world, ed);
910 static void CLVM_count_edicts(prvm_prog_t *prog)
914 int active = 0, models = 0, solid = 0;
916 for (i=0 ; i<prog->num_edicts ; i++)
918 ent = PRVM_EDICT_NUM(i);
919 if (ent->priv.server->free)
922 if (PRVM_clientedictfloat(ent, solid))
924 if (PRVM_clientedictstring(ent, model))
928 Con_Printf("num_edicts:%3i\n", prog->num_edicts);
929 Con_Printf("active :%3i\n", active);
930 Con_Printf("view :%3i\n", models);
931 Con_Printf("touch :%3i\n", solid);
934 static qboolean CLVM_load_edict(prvm_prog_t *prog, prvm_edict_t *ent)
939 // returns true if the packet is valid, false if end of file is reached
940 // used for dumping the CSQC download into demo files
941 qboolean MakeDownloadPacket(const char *filename, unsigned char *data, size_t len, int crc, int cnt, sizebuf_t *buf, int protocol)
943 int packetsize = buf->maxsize - 7; // byte short long
944 int npackets = (len + packetsize - 1) / (packetsize);
947 if(protocol == PROTOCOL_QUAKEWORLD)
948 return false; // CSQC can't run in QW anyway
953 MSG_WriteByte(buf, svc_stufftext);
954 MSG_WriteString(buf, va(vabuf, sizeof(vabuf), "\ncl_downloadbegin %lu %s\n", (unsigned long)len, filename));
957 else if(cnt >= 1 && cnt <= npackets)
959 unsigned long thispacketoffset = (cnt - 1) * packetsize;
960 int thispacketsize = len - thispacketoffset;
961 if(thispacketsize > packetsize)
962 thispacketsize = packetsize;
964 MSG_WriteByte(buf, svc_downloaddata);
965 MSG_WriteLong(buf, thispacketoffset);
966 MSG_WriteShort(buf, thispacketsize);
967 SZ_Write(buf, data + thispacketoffset, thispacketsize);
971 else if(cnt == npackets + 1)
973 MSG_WriteByte(buf, svc_stufftext);
974 MSG_WriteString(buf, va(vabuf, sizeof(vabuf), "\ncl_downloadfinished %lu %d\n", (unsigned long)len, crc));
980 extern cvar_t csqc_usedemoprogs;
981 void CL_VM_Init (void)
983 prvm_prog_t *prog = CLVM_prog;
984 const char* csprogsfn = NULL;
985 unsigned char *csprogsdata = NULL;
986 fs_offset_t csprogsdatasize = 0;
987 int csprogsdatacrc, requiredcrc;
991 // reset csqc_progcrc after reading it, so that changing servers doesn't
992 // expect csqc on the next server
993 requiredcrc = csqc_progcrc.integer;
994 requiredsize = csqc_progsize.integer;
995 Cvar_SetValueQuick(&csqc_progcrc, -1);
996 Cvar_SetValueQuick(&csqc_progsize, -1);
998 // if the server is not requesting a csprogs, then we're done here
1002 // see if the requested csprogs.dat file matches the requested crc
1003 csprogsdatacrc = -1;
1004 if (!cls.demoplayback || csqc_usedemoprogs.integer)
1006 csprogsfn = va(vabuf, sizeof(vabuf), "dlcache/%s.%i.%i", csqc_progname.string, requiredsize, requiredcrc);
1007 csprogsdata = FS_LoadFile(csprogsfn, tempmempool, true, &csprogsdatasize);
1011 csprogsfn = csqc_progname.string;
1012 csprogsdata = FS_LoadFile(csprogsfn, tempmempool, true, &csprogsdatasize);
1016 csprogsdatacrc = CRC_Block(csprogsdata, (size_t)csprogsdatasize);
1017 if (csprogsdatacrc != requiredcrc || csprogsdatasize != requiredsize)
1019 if (cls.demoplayback)
1021 Con_Printf("^1Warning: Your %s is not the same version as the demo was recorded with (CRC/size are %i/%i but should be %i/%i)\n", csqc_progname.string, csprogsdatacrc, (int)csprogsdatasize, requiredcrc, requiredsize);
1022 // Mem_Free(csprogsdata);
1024 // We WANT to continue here, and play the demo with different csprogs!
1025 // After all, this is just a warning. Sure things may go wrong from here.
1029 Mem_Free(csprogsdata);
1030 Con_Printf("^1Your %s is not the same version as the server (CRC is %i/%i but should be %i/%i)\n", csqc_progname.string, csprogsdatacrc, (int)csprogsdatasize, requiredcrc, requiredsize);
1038 if (requiredcrc >= 0)
1040 if (cls.demoplayback)
1041 Con_Printf("CL_VM_Init: demo requires CSQC, but \"%s\" wasn't found\n", csqc_progname.string);
1043 Con_Printf("CL_VM_Init: server requires CSQC, but \"%s\" wasn't found\n", csqc_progname.string);
1049 PRVM_Prog_Init(prog);
1051 // allocate the mempools
1052 prog->progs_mempool = Mem_AllocPool(csqc_progname.string, 0, NULL);
1053 prog->edictprivate_size = 0; // no private struct used
1054 prog->name = "client";
1055 prog->num_edicts = 1;
1056 prog->max_edicts = 512;
1057 prog->limit_edicts = CL_MAX_EDICTS;
1058 prog->reserved_edicts = 0;
1059 prog->edictprivate_size = sizeof(edict_engineprivate_t);
1060 // TODO: add a shared extension string #define and add real support for csqc extension strings [12/5/2007 Black]
1061 prog->extensionstring = vm_sv_extensions;
1062 prog->builtins = vm_cl_builtins;
1063 prog->numbuiltins = vm_cl_numbuiltins;
1065 // all callbacks must be defined (pointers are not checked before calling)
1066 prog->begin_increase_edicts = CLVM_begin_increase_edicts;
1067 prog->end_increase_edicts = CLVM_end_increase_edicts;
1068 prog->init_edict = CLVM_init_edict;
1069 prog->free_edict = CLVM_free_edict;
1070 prog->count_edicts = CLVM_count_edicts;
1071 prog->load_edict = CLVM_load_edict;
1072 prog->init_cmd = CLVM_init_cmd;
1073 prog->reset_cmd = CLVM_reset_cmd;
1074 prog->error_cmd = Host_Error;
1075 prog->ExecuteProgram = CLVM_ExecuteProgram;
1077 PRVM_Prog_Load(prog, csprogsfn, cl_numrequiredfunc, cl_required_func, CL_REQFIELDS, cl_reqfields, CL_REQGLOBALS, cl_reqglobals);
1081 Host_Error("CSQC %s ^2failed to load\n", csprogsfn);
1084 Mem_Free(csprogsdata);
1088 Con_DPrintf("CSQC %s ^5loaded (crc=%i, size=%i)\n", csprogsfn, csprogsdatacrc, (int)csprogsdatasize);
1090 if(cls.demorecording)
1092 if(cls.demo_lastcsprogssize != csprogsdatasize || cls.demo_lastcsprogscrc != csprogsdatacrc)
1095 static char buf[NET_MAXMESSAGE];
1097 unsigned char *demobuf; fs_offset_t demofilesize;
1099 sb.data = (unsigned char *) buf;
1100 sb.maxsize = sizeof(buf);
1103 CL_CutDemo(&demobuf, &demofilesize);
1104 while(MakeDownloadPacket(csqc_progname.string, csprogsdata, (size_t)csprogsdatasize, csprogsdatacrc, i++, &sb, cls.protocol))
1105 CL_WriteDemoMessage(&sb);
1106 CL_PasteDemo(&demobuf, &demofilesize);
1108 cls.demo_lastcsprogssize = csprogsdatasize;
1109 cls.demo_lastcsprogscrc = csprogsdatacrc;
1112 Mem_Free(csprogsdata);
1114 // check if OP_STATE animation is possible in this dat file
1115 if (prog->fieldoffsets.nextthink >= 0 && prog->fieldoffsets.frame >= 0 && prog->fieldoffsets.think >= 0 && prog->globaloffsets.self >= 0)
1116 prog->flag |= PRVM_OP_STATE;
1119 PRVM_clientglobalfloat(time) = cl.time;
1120 PRVM_clientglobaledict(self) = 0;
1122 PRVM_clientglobalstring(mapname) = PRVM_SetEngineString(prog, cl.worldname);
1123 PRVM_clientglobalfloat(player_localnum) = cl.realplayerentity - 1;
1124 PRVM_clientglobalfloat(player_localentnum) = cl.viewentity;
1126 // set map description (use world entity 0)
1127 PRVM_clientedictstring(prog->edicts, message) = PRVM_SetEngineString(prog, cl.worldmessage);
1128 VectorCopy(cl.world.mins, PRVM_clientedictvector(prog->edicts, mins));
1129 VectorCopy(cl.world.maxs, PRVM_clientedictvector(prog->edicts, maxs));
1131 // call the prog init
1132 prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_Init), "QC function CSQC_Init is missing");
1134 cl.csqc_loaded = true;
1136 cl.csqc_vidvars.drawcrosshair = false;
1137 cl.csqc_vidvars.drawenginesbar = false;
1139 // Update Coop and Deathmatch Globals (at this point the client knows them from ServerInfo)
1140 CL_VM_UpdateCoopDeathmatchGlobals(cl.gametype);
1143 void CL_VM_ShutDown (void)
1145 prvm_prog_t *prog = CLVM_prog;
1146 Cmd_ClearCsqcFuncs();
1147 //Cvar_SetValueQuick(&csqc_progcrc, -1);
1148 //Cvar_SetValueQuick(&csqc_progsize, -1);
1152 PRVM_clientglobalfloat(time) = cl.time;
1153 PRVM_clientglobaledict(self) = 0;
1154 if (PRVM_clientfunction(CSQC_Shutdown))
1155 prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_Shutdown), "QC function CSQC_Shutdown is missing");
1156 PRVM_Prog_Reset(prog);
1158 Con_DPrint("CSQC ^1unloaded\n");
1159 cl.csqc_loaded = false;
1162 qboolean CL_VM_GetEntitySoundOrigin(int entnum, vec3_t out)
1164 prvm_prog_t *prog = CLVM_prog;
1172 // FIXME consider attachments here!
1174 ed = PRVM_EDICT_NUM(entnum - MAX_EDICTS);
1176 if(!ed->priv.required->free)
1178 mod = CL_GetModelFromEdict(ed);
1179 VectorCopy(PRVM_clientedictvector(ed, origin), out);
1180 if(CL_GetTagMatrix(prog, &matrix, ed, 0) == 0)
1181 Matrix4x4_OriginFromMatrix(&matrix, out);
1182 if (mod && mod->soundfromcenter)
1183 VectorMAMAM(1.0f, out, 0.5f, mod->normalmins, 0.5f, mod->normalmaxs, out);
1192 qboolean CL_VM_TransformView(int entnum, matrix4x4_t *viewmatrix, mplane_t *clipplane, vec3_t visorigin)
1194 prvm_prog_t *prog = CLVM_prog;
1195 qboolean ret = false;
1197 vec3_t forward, left, up, origin, ang;
1198 matrix4x4_t mat, matq;
1201 ed = PRVM_EDICT_NUM(entnum);
1204 if(PRVM_clientedictfunction(ed, camera_transform))
1207 if(viewmatrix || clipplane || visorigin)
1209 Matrix4x4_ToVectors(viewmatrix, forward, left, up, origin);
1210 AnglesFromVectors(ang, forward, up, false);
1211 PRVM_clientglobalfloat(time) = cl.time;
1212 PRVM_clientglobaledict(self) = entnum;
1213 VectorCopy(origin, PRVM_G_VECTOR(OFS_PARM0));
1214 VectorCopy(ang, PRVM_G_VECTOR(OFS_PARM1));
1215 VectorCopy(forward, PRVM_clientglobalvector(v_forward));
1216 VectorScale(left, -1, PRVM_clientglobalvector(v_right));
1217 VectorCopy(up, PRVM_clientglobalvector(v_up));
1218 VectorCopy(origin, PRVM_clientglobalvector(trace_endpos));
1219 prog->ExecuteProgram(prog, PRVM_clientedictfunction(ed, camera_transform), "QC function e.camera_transform is missing");
1220 VectorCopy(PRVM_G_VECTOR(OFS_RETURN), origin);
1221 VectorCopy(PRVM_clientglobalvector(v_forward), forward);
1222 VectorScale(PRVM_clientglobalvector(v_right), -1, left);
1223 VectorCopy(PRVM_clientglobalvector(v_up), up);
1224 VectorCopy(PRVM_clientglobalvector(trace_endpos), visorigin);
1225 Matrix4x4_Invert_Full(&mat, viewmatrix);
1226 Matrix4x4_FromVectors(viewmatrix, forward, left, up, origin);
1227 Matrix4x4_Concat(&matq, viewmatrix, &mat);
1228 Matrix4x4_TransformPositivePlane(&matq, clipplane->normal[0], clipplane->normal[1], clipplane->normal[2], clipplane->dist, &clipplane->normal[0]);
1236 int CL_VM_GetViewEntity(void)
1238 if(cl.csqc_server2csqcentitynumber[cl.viewentity])
1239 return cl.csqc_server2csqcentitynumber[cl.viewentity] + MAX_EDICTS;
1240 return cl.viewentity;