//4 feature darkplaces csqc: add builtin to clientside qc for reading triangles of model meshes (useful to orient a ui along a triangle of a model mesh)
//4 feature darkplaces csqc: add builtins to clientside qc for gl calls
-#ifndef PF_WARNING
-#define PF_WARNING(s) do{Con_Printf(s);PRVM_PrintState();return;}while(0)
-#endif
-
//[515]: really need new list ?
char *vm_cl_extensions =
"DP_CON_SET "
e = PRVM_G_EDICT(OFS_PARM0);
if (e == prog->edicts)
- PF_WARNING("setorigin: can not modify world entity\n");
+ {
+ VM_Warning("setorigin: can not modify world entity\n");
+ return;
+ }
if (e->priv.required->free)
- PF_WARNING("setorigin: can not modify free entity\n");
+ {
+ VM_Warning("setorigin: can not modify free entity\n");
+ return;
+ }
org = PRVM_G_VECTOR(OFS_PARM1);
VectorCopy (org, e->fields.client->origin);
}
e = PRVM_G_EDICT(OFS_PARM0);
if (e == prog->edicts)
- PF_WARNING("setsize: can not modify world entity\n");
+ {
+ VM_Warning("setsize: can not modify world entity\n");
+ return;
+ }
if (e->priv.server->free)
- PF_WARNING("setsize: can not modify free entity\n");
+ {
+ VM_Warning("setsize: can not modify free entity\n");
+ return;
+ }
min = PRVM_G_VECTOR(OFS_PARM1);
max = PRVM_G_VECTOR(OFS_PARM2);
attenuation = PRVM_G_FLOAT(OFS_PARM4);
if (volume < 0 || volume > 255)
- PF_WARNING("VM_CL_sound: volume must be in range 0-1\n");
+ {
+ VM_Warning("VM_CL_sound: volume must be in range 0-1\n");
+ return;
+ }
if (attenuation < 0 || attenuation > 4)
- PF_WARNING("VM_CL_sound: attenuation must be in range 0-4\n");
+ {
+ VM_Warning("VM_CL_sound: attenuation must be in range 0-4\n");
+ return;
+ }
if (channel < 0 || channel > 7)
- PF_WARNING("VM_CL_sound: channel must be in range 0-7\n");
+ {
+ VM_Warning("VM_CL_sound: channel must be in range 0-7\n");
+ return;
+ }
S_StartSound(32768 + PRVM_NUM_FOR_EDICT(entity), channel, S_FindName(sample), entity->fields.client->origin, volume, attenuation);
}
if(!cl.csqc_model_precache[i])
break;
if(i == MAX_MODELS)
- PF_WARNING("VM_CL_precache_model: no free models\n");
+ {
+ VM_Warning("VM_CL_precache_model: no free models\n");
+ return;
+ }
cl.csqc_model_precache[i] = (model_t*)m;
PRVM_G_FLOAT(OFS_RETURN) = -(i+1);
return;
}
- Con_Printf("VM_CL_precache_model: model \"%s\" not found\n", name);
+ VM_Warning("VM_CL_precache_model: model \"%s\" not found\n", name);
}
int CSQC_EntitiesInBox (vec3_t mins, vec3_t maxs, int maxlist, prvm_edict_t **list)
ent = PRVM_PROG_TO_EDICT(prog->globals.client->self);
if (ent == prog->edicts)
- PF_WARNING("droptofloor: can not modify world entity\n");
+ {
+ VM_Warning("droptofloor: can not modify world entity\n");
+ return;
+ }
if (ent->priv.server->free)
- PF_WARNING("droptofloor: can not modify free entity\n");
+ {
+ VM_Warning("droptofloor: can not modify free entity\n");
+ return;
+ }
VectorCopy (ent->fields.client->origin, end);
end[2] -= 256;
i = (int)PRVM_G_FLOAT(OFS_PARM0);
c = PRVM_G_STRING(OFS_PARM1);
if (i >= cl.max_lightstyle)
- PF_WARNING("VM_CL_lightstyle >= MAX_LIGHTSTYLES\n");
+ {
+ VM_Warning("VM_CL_lightstyle >= MAX_LIGHTSTYLES\n");
+ return;
+ }
strlcpy (cl.lightstyle[i].map, MSG_ReadString(), sizeof (cl.lightstyle[i].map));
cl.lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
cl.lightstyle[i].length = (int)strlen(cl.lightstyle[i].map);
ent = PRVM_G_EDICT(OFS_PARM0);
if (ent == prog->edicts)
- PF_WARNING("changeyaw: can not modify world entity\n");
+ {
+ VM_Warning("changeyaw: can not modify world entity\n");
+ return;
+ }
if (ent->priv.server->free)
- PF_WARNING("changeyaw: can not modify free entity\n");
+ {
+ VM_Warning("changeyaw: can not modify free entity\n");
+ return;
+ }
current = ANGLEMOD(ent->fields.client->angles[1]);
ideal = PRVM_G_FLOAT(OFS_PARM1);
speed = PRVM_G_FLOAT(OFS_PARM2);
ent = PRVM_G_EDICT(OFS_PARM0);
if (ent == prog->edicts)
- PF_WARNING("changepitch: can not modify world entity\n");
+ {
+ VM_Warning("changepitch: can not modify world entity\n");
+ return;
+ }
if (ent->priv.server->free)
- PF_WARNING("changepitch: can not modify free entity\n");
+ {
+ VM_Warning("changepitch: can not modify free entity\n");
+ return;
+ }
current = ANGLEMOD( ent->fields.client->angles[0] );
ideal = PRVM_G_FLOAT(OFS_PARM1);
speed = PRVM_G_FLOAT(OFS_PARM2);
ent = PRVM_G_EDICT(OFS_PARM0);
if (ent == prog->edicts)
- PF_WARNING("tracetoss: can not use world entity\n");
+ {
+ VM_Warning("tracetoss: can not use world entity\n");
+ return;
+ }
ignore = PRVM_G_EDICT(OFS_PARM1);
//FIXME
//============================================================================
//[515]: SCENE MANAGER builtins
-void V_CalcRefdef (void);//view.c
-void CSQC_R_ClearScreen (void);//gl_rmain.c
-void CSQC_R_RenderScene (void);//gl_rmain.c
-void CSQC_AddEntity (int n);//csprogs.c
-void CSQC_ClearCSQCEntities (void);
+extern void V_CalcRefdef (void);//view.c
+extern qboolean CSQC_AddRenderEdict (prvm_edict_t *ed);//csprogs.c
+extern void CSQC_ClearCSQCEntities (void);//csprogs.c
matrix4x4_t csqc_listenermatrix;
qboolean csqc_usecsqclistener = false, csqc_frame = false;//[515]: per-frame
-qboolean csqc_onground;
static void CSQC_R_RecalcView (void)
{
viewmodelmatrix = identitymatrix;
r_view.matrix = identitymatrix;
Matrix4x4_CreateFromQuakeEntity(&r_view.matrix, csqc_origin[0], csqc_origin[1], csqc_origin[2], csqc_angles[0], csqc_angles[1], csqc_angles[2], 1);
- Matrix4x4_CreateFromQuakeEntity(&viewmodelmatrix, csqc_origin[0], csqc_origin[1], csqc_origin[2], csqc_angles[0], csqc_angles[1], csqc_angles[2], 0.3);
+ Matrix4x4_CreateFromQuakeEntity(&viewmodelmatrix, csqc_origin[0], csqc_origin[1], csqc_origin[2], csqc_angles[0], csqc_angles[1], csqc_angles[2], cl_viewmodel_scale.value);
}
//#300 void() clearscene (EXT_CSQC)
{
VM_SAFEPARMCOUNT(0, VM_R_ClearScene);
// CSQC_R_RecalcView();
- if(csqc_frame)
- CSQC_ClearCSQCEntities();
- CSQC_R_ClearScreen();
+ CSQC_ClearCSQCEntities();
}
//#301 void(float mask) addentities (EXT_CSQC)
+extern void CSQC_Predraw (prvm_edict_t *ed);//csprogs.c
+extern void CSQC_Think (prvm_edict_t *ed);//csprogs.c
void VM_R_AddEntities (void)
{
+ int i, drawmask;
+ prvm_edict_t *ed;
VM_SAFEPARMCOUNT(1, VM_R_AddEntities);
- csqc_drawmask = (int)PRVM_G_FLOAT(OFS_PARM0);
+ drawmask = (int)PRVM_G_FLOAT(OFS_PARM0);
+ CSQC_RelinkAllEntities(drawmask);
+
+ *prog->time = cl.time;
+ for(i=1;i<prog->num_edicts;i++)
+ {
+ ed = &prog->edicts[i];
+ if(ed->priv.required->free)
+ continue;
+ VectorAdd(ed->fields.client->origin, ed->fields.client->mins, ed->fields.client->absmin);
+ VectorAdd(ed->fields.client->origin, ed->fields.client->maxs, ed->fields.client->absmax);
+ CSQC_Think(ed);
+ if(ed->priv.required->free)
+ continue;
+ // note that for RF_USEAXIS entities, Predraw sets v_forward/v_right/v_up globals that are read by CSQC_AddRenderEdict
+ CSQC_Predraw(ed);
+ if(ed->priv.required->free)
+ continue;
+ if(!((int)ed->fields.client->drawmask & drawmask))
+ continue;
+ CSQC_AddRenderEdict(ed);
+ }
}
//#302 void(entity ent) addentity (EXT_CSQC)
void VM_R_AddEntity (void)
{
VM_SAFEPARMCOUNT(1, VM_R_AddEntity);
- CSQC_AddEntity(PRVM_NUM_FOR_EDICT(PRVM_G_EDICT(OFS_PARM0)));
+ CSQC_AddRenderEdict(PRVM_G_EDICT(OFS_PARM0));
}
//#303 float(float property, ...) setproperty (EXT_CSQC)
case VF_CL_VIEWANGLES_Z:cl.viewangles[2] = k;
break;
- default: Con_Printf("VM_R_SetView : unknown parm %i\n", c);
- PRVM_G_FLOAT(OFS_RETURN) = 0;
+ default: PRVM_G_FLOAT(OFS_RETURN) = 0;
+ VM_Warning("VM_R_SetView : unknown parm %i\n", c);
return;
}
PRVM_G_FLOAT(OFS_RETURN) = 1;
void VM_R_RenderScene (void) //#134
{
VM_SAFEPARMCOUNT(0, VM_R_RenderScene);
-
- if(csqc_frame)
- {
- CSQC_RelinkCSQCEntities();
- CSQC_RelinkAllEntities(csqc_drawmask);
- }
-
- CSQC_R_RenderScene();
+ R_RenderView();
}
//#305 void(vector org, float radius, vector lightcolours) adddynamiclight (EXT_CSQC)
i = (int)PRVM_G_FLOAT(OFS_PARM0);
if(i < 0 || i >= MAX_CL_STATS)
{
- Con_Printf("VM_CL_getstatf: index>=MAX_CL_STATS or index<0\n");
+ VM_Warning("VM_CL_getstatf: index>=MAX_CL_STATS or index<0\n");
return;
}
dat.l = cl.stats[i];
if(index < 0 || index >= MAX_CL_STATS)
{
- Con_Printf("VM_CL_getstati: index>=MAX_CL_STATS or index<0\n");
+ VM_Warning("VM_CL_getstati: index>=MAX_CL_STATS or index<0\n");
return;
}
i = cl.stats[index];
i = (int)PRVM_G_FLOAT(OFS_PARM0);
if(i < 0 || i > MAX_CL_STATS-4)
{
- Con_Printf("VM_CL_getstats: index>MAX_CL_STATS-4 or index<0\n");
+ VM_Warning("VM_CL_getstats: index>MAX_CL_STATS-4 or index<0\n");
return;
}
t = VM_GetTempString();
{
i = -(i+1);
if(i >= MAX_MODELS)
- PF_WARNING("VM_CL_setmodelindex >= MAX_MODELS\n");
+ {
+ VM_Warning("VM_CL_setmodelindex >= MAX_MODELS\n");
+ return;
+ }
m = cl.csqc_model_precache[i];
}
else
if(i >= MAX_MODELS)
- PF_WARNING("VM_CL_setmodelindex >= MAX_MODELS\n");
+ {
+ VM_Warning("VM_CL_setmodelindex >= MAX_MODELS\n");
+ return;
+ }
else
m = cl.model_precache[i];
if(!m)
- PF_WARNING("VM_CL_setmodelindex: null model\n");
+ {
+ VM_Warning("VM_CL_setmodelindex: null model\n");
+ return;
+ }
t->fields.client->model = PRVM_SetEngineString(m->name);
t->fields.client->modelindex = i;
}
{
i = -(i+1);
if(i >= MAX_MODELS)
- PF_WARNING("VM_CL_modelnameforindex >= MAX_MODELS\n");
+ {
+ VM_Warning("VM_CL_modelnameforindex >= MAX_MODELS\n");
+ return;
+ }
if(cl.csqc_model_precache[i])
PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(cl.csqc_model_precache[i]->name);
return;
}
if(i >= MAX_MODELS)
- PF_WARNING("VM_CL_modelnameforindex >= MAX_MODELS\n");
+ {
+ VM_Warning("VM_CL_modelnameforindex >= MAX_MODELS\n");
+ return;
+ }
if(cl.model_precache[i])
PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(cl.model_precache[i]->name);
}
if (entnum >= MAX_EDICTS)
{
- Con_Printf("CSQC_ParseBeam: invalid entity number %i\n", entnum);
+ VM_Warning("CSQC_ParseBeam: invalid entity number %i\n", entnum);
return;
}
if (entnum >= cl.max_csqcentities)
t[0] = 0;
if(!strcasecmp(c, "name"))
- strcpy(t, cl.scores[i].name);
+ strlcpy(t, cl.scores[i].name, sizeof(t));
else
if(!strcasecmp(c, "frags"))
sprintf(t, "%i", cl.scores[i].frags);
if(!t[0])
return;
temp = VM_GetTempString();
- strcpy(temp, t);
+ strlcpy(temp, t, VM_STRINGTEMP_LENGTH);
PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(temp);
}
VM_SAFEPARMCOUNT(1, VM_CL_registercmd);
if(!Cmd_Exists(PRVM_G_STRING(OFS_PARM0)))
{
- t = (char *)Z_Malloc(strlen(PRVM_G_STRING(OFS_PARM0))+1);
- strcpy(t, PRVM_G_STRING(OFS_PARM0));
+ size_t alloclen;
+
+ alloclen = strlen(PRVM_G_STRING(OFS_PARM0)) + 1;
+ t = (char *)Z_Malloc(alloclen);
+ memcpy(t, PRVM_G_STRING(OFS_PARM0), alloclen);
Cmd_AddCommand(t, NULL, "console command created by QuakeC");
}
else
//#355 float() cl_onground (EXT_CSQC)
void VM_CL_onground (void)
{
- PRVM_G_FLOAT(OFS_RETURN) = csqc_onground;
+ PRVM_G_FLOAT(OFS_RETURN) = cl.onground;
}
//#360 float() readbyte (EXT_CSQC)
PRVM_G_INT(OFS_RETURN) = 0;
if(s)
{
- strcpy(t, s);
+ strlcpy(t, s, VM_STRINGTEMP_LENGTH);
PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(t);
}
}
model_t *model;
if (e == prog->edicts)
- PF_WARNING("setattachment: can not modify world entity\n");
+ {
+ VM_Warning("setattachment: can not modify world entity\n");
+ return;
+ }
if (e->priv.server->free)
- PF_WARNING("setattachment: can not modify free entity\n");
+ {
+ VM_Warning("setattachment: can not modify free entity\n");
+ return;
+ }
if (tagentity == NULL)
tagentity = prog->edicts;
val->_float = 1;
Matrix4x4_CreateFromQuakeEntity(&entitymatrix, ent->fields.client->origin[0], ent->fields.client->origin[1], ent->fields.client->origin[2], -ent->fields.client->angles[0], ent->fields.client->angles[1], ent->fields.client->angles[2], val->_float);
Matrix4x4_Concat(out, &entitymatrix, &tagmatrix);
- out->m[0][3] = entitymatrix.m[0][3] + val->_float*(entitymatrix.m[0][0]*tagmatrix.m[0][3] + entitymatrix.m[0][1]*tagmatrix.m[1][3] + entitymatrix.m[0][2]*tagmatrix.m[2][3]);
- out->m[1][3] = entitymatrix.m[1][3] + val->_float*(entitymatrix.m[1][0]*tagmatrix.m[0][3] + entitymatrix.m[1][1]*tagmatrix.m[1][3] + entitymatrix.m[1][2]*tagmatrix.m[2][3]);
- out->m[2][3] = entitymatrix.m[2][3] + val->_float*(entitymatrix.m[2][0]*tagmatrix.m[0][3] + entitymatrix.m[2][1]*tagmatrix.m[1][3] + entitymatrix.m[2][2]*tagmatrix.m[2][3]);
Matrix4x4_Copy(&tagmatrix, out);
// finally transformate by matrix of tag on parent entity
Matrix4x4_Concat(out, &attachmatrix, &tagmatrix);
- out->m[0][3] = attachmatrix.m[0][3] + attachmatrix.m[0][0]*tagmatrix.m[0][3] + attachmatrix.m[0][1]*tagmatrix.m[1][3] + attachmatrix.m[0][2]*tagmatrix.m[2][3];
- out->m[1][3] = attachmatrix.m[1][3] + attachmatrix.m[1][0]*tagmatrix.m[0][3] + attachmatrix.m[1][1]*tagmatrix.m[1][3] + attachmatrix.m[1][2]*tagmatrix.m[2][3];
- out->m[2][3] = attachmatrix.m[2][3] + attachmatrix.m[2][0]*tagmatrix.m[0][3] + attachmatrix.m[2][1]*tagmatrix.m[1][3] + attachmatrix.m[2][2]*tagmatrix.m[2][3];
Matrix4x4_Copy(&tagmatrix, out);
ent = attachent;
// Alias models have inverse pitch, bmodels can't have tags, so don't check for modeltype...
Matrix4x4_CreateFromQuakeEntity(&entitymatrix, ent->fields.client->origin[0], ent->fields.client->origin[1], ent->fields.client->origin[2], -ent->fields.client->angles[0], ent->fields.client->angles[1], ent->fields.client->angles[2], val->_float);
Matrix4x4_Concat(out, &entitymatrix, &tagmatrix);
- out->m[0][3] = entitymatrix.m[0][3] + val->_float*(entitymatrix.m[0][0]*tagmatrix.m[0][3] + entitymatrix.m[0][1]*tagmatrix.m[1][3] + entitymatrix.m[0][2]*tagmatrix.m[2][3]);
- out->m[1][3] = entitymatrix.m[1][3] + val->_float*(entitymatrix.m[1][0]*tagmatrix.m[0][3] + entitymatrix.m[1][1]*tagmatrix.m[1][3] + entitymatrix.m[1][2]*tagmatrix.m[2][3]);
- out->m[2][3] = entitymatrix.m[2][3] + val->_float*(entitymatrix.m[2][0]*tagmatrix.m[0][3] + entitymatrix.m[2][1]*tagmatrix.m[1][3] + entitymatrix.m[2][2]*tagmatrix.m[2][3]);
if ((val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_renderflags)) && (RF_VIEWMODEL & (int)val->_float))
{// RENDER_VIEWMODEL magic
Matrix4x4_CreateFromQuakeEntity(&entitymatrix, csqc_origin[0], csqc_origin[1], csqc_origin[2], csqc_angles[0], csqc_angles[1], csqc_angles[2], val->_float);
Matrix4x4_Concat(out, &entitymatrix, &tagmatrix);
- out->m[0][3] = entitymatrix.m[0][3] + val->_float*(entitymatrix.m[0][0]*tagmatrix.m[0][3] + entitymatrix.m[0][1]*tagmatrix.m[1][3] + entitymatrix.m[0][2]*tagmatrix.m[2][3]);
- out->m[1][3] = entitymatrix.m[1][3] + val->_float*(entitymatrix.m[1][0]*tagmatrix.m[0][3] + entitymatrix.m[1][1]*tagmatrix.m[1][3] + entitymatrix.m[1][2]*tagmatrix.m[2][3]);
- out->m[2][3] = entitymatrix.m[2][3] + val->_float*(entitymatrix.m[2][0]*tagmatrix.m[0][3] + entitymatrix.m[2][1]*tagmatrix.m[1][3] + entitymatrix.m[2][2]*tagmatrix.m[2][3]);
/*
// Cl_bob, ported from rendering code
// (don't count Z, or jumping messes it up)
bob = sqrt(ent->fields.client->velocity[0]*ent->fields.client->velocity[0] + ent->fields.client->velocity[1]*ent->fields.client->velocity[1])*cl_bob.value;
bob = bob*0.3 + bob*0.7*cycle;
- out->m[2][3] += bound(-7, bob, 4);
+ Matrix4x4_AdjustOrigin(out, 0, 0, bound(-7, bob, 4));
}
*/
}
int modelindex, tag_index;
if (ent == prog->edicts)
- PF_WARNING("gettagindex: can't affect world entity\n");
+ {
+ VM_Warning("gettagindex: can't affect world entity\n");
+ return;
+ }
if (ent->priv.server->free)
- PF_WARNING("gettagindex: can't affect free entity\n");
+ {
+ VM_Warning("gettagindex: can't affect free entity\n");
+ return;
+ }
modelindex = (int)ent->fields.client->modelindex;
if(modelindex < 0)
switch(returncode)
{
case 1:
- PF_WARNING("gettagindex: can't affect world entity\n");
+ VM_Warning("gettagindex: can't affect world entity\n");
break;
case 2:
- PF_WARNING("gettagindex: can't affect free entity\n");
+ VM_Warning("gettagindex: can't affect free entity\n");
break;
case 3:
Con_DPrintf("CL_GetTagMatrix(entity #%i): null or non-precached model\n", PRVM_NUM_FOR_EDICT(e));
char c2 = c - (c & 128);
char t2 = t - (t & 128);
- if(c != '^' && c2 != '^') return 0;
+ if(c != STRING_COLOR_TAG && c2 != STRING_COLOR_TAG) return 0;
if(t >= '0' && t <= '9') a = 1;
if(t2 >= '0' && t2 <= '9') a = 1;
/* if(t >= 'A' && t <= 'Z') a = 2;
if((csqcents && ignore > cl.num_csqcentities) || (!csqcents && ignore > cl.num_entities))
{
- Con_Printf("VM_CL_selecttraceline: out of entities\n");
+ VM_Warning("VM_CL_selecttraceline: out of entities\n");
return;
}
else