#include "prvm_cmds.h"
#include "csprogs.h"
#include "cl_collision.h"
+#include "r_shadow.h"
//============================================================================
// Client
//[515]: unsolved PROBLEMS
//- finish player physics code (cs_runplayerphysics)
-//- fix R_AddDynamicLight
//- EntWasFreed ?
//- RF_DEPTHHACK is not like it should be
//- add builtin that sets cl.viewangles instead of reading "input_angles" global
char *Key_GetBind (int key);
model_t *CSQC_GetModelByIndex(int modelindex);
model_t *CSQC_GetModelFromEntity(prvm_edict_t *ed);
+void CL_LinkEdict(prvm_edict_t *ed);
}
org = PRVM_G_VECTOR(OFS_PARM1);
VectorCopy (org, e->fields.client->origin);
+ CL_LinkEdict(e);
}
// #3 void(entity e, string m) setmodel
VectorCopy (min, e->fields.client->mins);
VectorCopy (max, e->fields.client->maxs);
VectorSubtract (max, min, e->fields.client->size);
+
+ CL_LinkEdict(e);
}
// #8 void(entity e, float chan, string samp) sound
CL_ParticleEffect(EFFECT_SVC_PARTICLE, count, org, org, dir, dir, NULL, color);
}
-// #49 void(entity ent, float ideal_yaw, float speed_yaw) ChangeYaw
-void VM_CL_changeyaw (void)
-{
- prvm_edict_t *ent;
- float ideal, current, move, speed;
- VM_SAFEPARMCOUNT(3, VM_CL_changeyaw);
-
- ent = PRVM_G_EDICT(OFS_PARM0);
- if (ent == prog->edicts)
- {
- VM_Warning("changeyaw: can not modify world entity\n");
- return;
- }
- if (ent->priv.server->free)
- {
- 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);
-
- if (current == ideal)
- return;
- move = ideal - current;
- if (ideal > current)
- {
- if (move >= 180)
- move = move - 360;
- }
- else
- {
- if (move <= -180)
- move = move + 360;
- }
- if (move > 0)
- {
- if (move > speed)
- move = speed;
- }
- else
- {
- if (move < -speed)
- move = -speed;
- }
-
- ent->fields.client->angles[1] = ANGLEMOD (current + move);
-}
-
-// #63 void(entity ent, float ideal_pitch, float speed_pitch) changepitch (DP_QC_CHANGEPITCH)
-void VM_CL_changepitch (void)
-{
- prvm_edict_t *ent;
- float ideal, current, move, speed;
- VM_SAFEPARMCOUNT(3, VM_CL_changepitch);
-
- ent = PRVM_G_EDICT(OFS_PARM0);
- if (ent == prog->edicts)
- {
- VM_Warning("changepitch: can not modify world entity\n");
- return;
- }
- if (ent->priv.server->free)
- {
- 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);
-
- if (current == ideal)
- return;
- move = ideal - current;
- if (ideal > current)
- {
- if (move >= 180)
- move = move - 360;
- }
- else
- {
- if (move <= -180)
- move = move + 360;
- }
- if (move > 0)
- {
- if (move > speed)
- move = speed;
- }
- else
- {
- if (move < -speed)
- move = -speed;
- }
-
- ent->fields.client->angles[0] = ANGLEMOD (current + move);
-}
-
// #64 void(entity e, entity ignore) tracetoss (DP_QC_TRACETOSS)
void VM_CL_tracetoss (void)
{
static void CSQC_R_RecalcView (void)
{
extern matrix4x4_t viewmodelmatrix;
- 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], cl_viewmodel_scale.value);
}
+void CL_RelinkLightFlashes(void);
//#300 void() clearscene (EXT_CSQC)
void VM_R_ClearScene (void)
{
VM_SAFEPARMCOUNT(0, VM_R_ClearScene);
+ // clear renderable entity and light lists
r_refdef.numentities = 0;
+ r_refdef.numlights = 0;
}
//#301 void(float mask) addentities (EXT_CSQC)
VM_SAFEPARMCOUNT(1, VM_R_AddEntities);
drawmask = (int)PRVM_G_FLOAT(OFS_PARM0);
CSQC_RelinkAllEntities(drawmask);
+ CL_RelinkLightFlashes();
- *prog->time = cl.time;
+ prog->globals.client->time = cl.time;
for(i=1;i<prog->num_edicts;i++)
{
ed = &prog->edicts[i];
PRVM_G_FLOAT(OFS_RETURN) = 1;
}
+extern void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit);
//#304 void() renderscene (EXT_CSQC)
void VM_R_RenderScene (void) //#134
{
+ int i;
VM_SAFEPARMCOUNT(0, VM_R_RenderScene);
- // update all renderable network entities
- CL_UpdateEntities();
+ // we need to update any RENDER_VIEWMODEL entities at this point because
+ // csqc supplies its own view matrix
+ for (i = 1;i < cl.num_entities;i++)
+ {
+ if (cl.entities_active[i])
+ {
+ entity_t *ent = cl.entities + i;
+ if ((ent->render.flags & RENDER_VIEWMODEL) || ent->state_current.tagentity)
+ CL_UpdateNetworkEntity(ent, 32);
+ }
+ }
+ // and of course the engine viewmodel needs updating as well
+ CL_UpdateNetworkEntity(&cl.viewent, 32);
+ // now draw stuff!
R_RenderView();
}
void VM_R_AddDynamicLight (void)
{
float *pos, *col;
- matrix4x4_t tempmatrix;
+ matrix4x4_t matrix;
VM_SAFEPARMCOUNT(3, VM_R_AddDynamicLight);
+ // if we've run out of dlights, just return
+ if (r_refdef.numlights >= MAX_DLIGHTS)
+ return;
+
pos = PRVM_G_VECTOR(OFS_PARM0);
col = PRVM_G_VECTOR(OFS_PARM2);
- Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
- CL_AllocDlight(NULL, &tempmatrix, PRVM_G_FLOAT(OFS_PARM1), col[0], col[1], col[2], 500, 0, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
- //CL_AllocDlight(NULL, &tempmatrix, PRVM_G_FLOAT(OFS_PARM1), col[0], col[1], col[2], 500, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
+ Matrix4x4_CreateFromQuakeEntity(&matrix, pos[0], pos[1], pos[2], 0, 0, 0, PRVM_G_FLOAT(OFS_PARM1));
+ R_RTLight_Update(&r_refdef.lights[r_refdef.numlights++], false, &matrix, col, -1, NULL, true, 1, 0.25, 0, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
}
//============================================================================
CL_FindNonSolidLocation(pos, pos2, 10);
CL_ParticleExplosion(pos2);
Matrix4x4_CreateTranslate(&tempmatrix, pos2[0], pos2[1], pos2[2]);
- CL_AllocDlight(NULL, &tempmatrix, 350, PRVM_G_VECTOR(OFS_PARM1)[0], PRVM_G_VECTOR(OFS_PARM1)[1], PRVM_G_VECTOR(OFS_PARM1)[2], 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
+ CL_AllocLightFlash(NULL, &tempmatrix, 350, PRVM_G_VECTOR(OFS_PARM1)[0], PRVM_G_VECTOR(OFS_PARM1)[1], PRVM_G_VECTOR(OFS_PARM1)[2], 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
}
// #408 void(vector mincorner, vector maxcorner, vector vel, float howmany, float color, float gravityflag, float randomveljitter) te_particlecube (DP_TE_PARTICLECUBE)
pos = PRVM_G_VECTOR(OFS_PARM0);
CL_FindNonSolidLocation(pos, pos2, 4);
Matrix4x4_CreateTranslate(&tempmatrix, pos2[0], pos2[1], pos2[2]);
- CL_AllocDlight(NULL, &tempmatrix, PRVM_G_FLOAT(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM3)[0], PRVM_G_VECTOR(OFS_PARM3)[1], PRVM_G_VECTOR(OFS_PARM3)[2], PRVM_G_FLOAT(OFS_PARM1) / PRVM_G_FLOAT(OFS_PARM2), PRVM_G_FLOAT(OFS_PARM2), 0, -1, true, 1, 0.25, 1, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
+ CL_AllocLightFlash(NULL, &tempmatrix, PRVM_G_FLOAT(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM3)[0], PRVM_G_VECTOR(OFS_PARM3)[1], PRVM_G_VECTOR(OFS_PARM3)[2], PRVM_G_FLOAT(OFS_PARM1) / PRVM_G_FLOAT(OFS_PARM2), PRVM_G_FLOAT(OFS_PARM2), 0, -1, true, 1, 0.25, 1, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
}
// #418 void(vector org) te_gunshot (DP_TE_STANDARDEFFECTBUILTINS)
color[1] = tempcolor[1] * (2.0f / 255.0f);
color[2] = tempcolor[2] * (2.0f / 255.0f);
Matrix4x4_CreateTranslate(&tempmatrix, pos2[0], pos2[1], pos2[2]);
- CL_AllocDlight(NULL, &tempmatrix, 350, color[0], color[1], color[2], 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
+ CL_AllocLightFlash(NULL, &tempmatrix, 350, color[0], color[1], color[2], 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
S_StartSound(-1, 0, cl.sfx_r_exp3, pos2, 1, 1);
}
if (tagentity == NULL)
tagentity = prog->edicts;
- v = PRVM_GETEDICTFIELDVALUE(e, csqc_fieldoff_tag_entity);
+ v = PRVM_EDICTFIELDVALUE(e, prog->fieldoffsets.tag_entity);
if (v)
v->edict = PRVM_EDICT_TO_PROG(tagentity);
- v = PRVM_GETEDICTFIELDVALUE(e, csqc_fieldoff_tag_index);
+ v = PRVM_EDICTFIELDVALUE(e, prog->fieldoffsets.tag_index);
if (v)
v->_float = 0;
if (tagentity != NULL && tagentity != prog->edicts && tagname && tagname[0])
else
tagmatrix = identitymatrix;
- if ((val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_tag_entity)) && val->edict)
+ if ((val = PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.tag_entity)) && val->edict)
{ // DP_GFX_QUAKE3MODELTAGS, scan all chain and stop on unattached entity
attachloop = 0;
do
{
attachent = PRVM_EDICT_NUM(val->edict); // to this it entity our entity is attached
- val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_tag_index);
+ val = PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.tag_index);
model = CSQC_GetModelFromEntity(attachent);
attachmatrix = identitymatrix;
// apply transformation by child entity matrix
- val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_scale);
+ val = PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.scale);
if (val->_float == 0)
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);
if (attachloop > 255) // prevent runaway looping
return 5;
}
- while ((val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_tag_entity)) && val->edict);
+ while ((val = PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.tag_entity)) && val->edict);
}
// normal or RENDER_VIEWMODEL entity (or main parent entity on attach chain)
- val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_scale);
+ val = PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.scale);
if (val->_float == 0)
val->_float = 1;
// 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);
- if ((val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_renderflags)) && (RF_VIEWMODEL & (int)val->_float))
+ if ((val = PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.renderflags)) && (RF_VIEWMODEL & (int)val->_float))
{// RENDER_VIEWMODEL magic
Matrix4x4_Copy(&tagmatrix, out);
- val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_scale);
+ val = PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.scale);
if (val->_float == 0)
val->_float = 1;
VM_SAFEPARMCOUNT(1, VM_WasFreed);
e = PRVM_G_EDICT(OFS_PARM0);
- if (!e->priv.required->free || (e->priv.required->free && (e->priv.required->freetime < 2 || (*prog->time - e->priv.required->freetime) > 0.5 )))
+ if (!e->priv.required->free || (e->priv.required->free && (e->priv.required->freetime < 2 || (prog->globals.client->time - e->priv.required->freetime) > 0.5 )))
PRVM_G_FLOAT(OFS_RETURN) = false;
else
PRVM_G_FLOAT(OFS_RETURN) = true;
void VM_CL_select_cube (void)
{
int i;
- int chain_of;
float *mins2, *maxs2;
prvm_edict_t *ent, *chain;
vec3_t mins1, maxs1;
VM_SAFEPARMCOUNT(2, VM_CL_select_cube);
- // is the same like !(prog->flag & PRVM_FE_CHAIN) - even if the operator precedence is another
- if(!prog->flag & PRVM_FE_CHAIN)
+ if (prog->fieldoffsets.chain < 0)
PRVM_ERROR("VM_findchain: %s doesnt have a chain field !\n", PRVM_NAME);
- chain_of = PRVM_ED_FindField("chain")->ofs;
chain = prog->edicts;
mins2 = PRVM_G_VECTOR(OFS_PARM0);
continue;
if (maxs1[0] < mins2[0] || maxs1[1] < mins2[1] || maxs1[2] < mins2[2])
continue;
- PRVM_E_INT(ent,chain_of) = PRVM_NUM_FOR_EDICT(chain);
+ PRVM_EDICTFIELDVALUE(ent,prog->fieldoffsets.chain)->edict = PRVM_NUM_FOR_EDICT(chain);
chain = ent;
}
void VM_CL_select_super (void)
{
/* int i;
- int chain_of;
float *v[8];
prvm_edict_t *ent, *chain;
vec3_t mins1, maxs1;
for(i=0;i<8;i++)
v[i] = PRVM_G_VECTOR(OFS_PARM0+i*3);
- // is the same like !(prog->flag & PRVM_FE_CHAIN) - even if the operator precedence is another
- if(!prog->flag & PRVM_FE_CHAIN)
+ if (prog->fieldoffsets.chain < 0)
PRVM_ERROR("VM_findchain: %s doesnt have a chain field !\n", PRVM_NAME);
- chain_of = PRVM_ED_FindField("chain")->ofs;
chain = prog->edicts;
mins2 = PRVM_G_VECTOR(OFS_PARM0);
continue;
if (maxs1[0] < mins2[0] || maxs1[1] < mins2[1] || maxs1[2] < mins2[2])
continue;
- PRVM_E_INT(ent,chain_of) = PRVM_NUM_FOR_EDICT(chain);
+ PRVM_EDICTFIELDVALUE(ent,prog->fieldoffsets.chain)->edict = PRVM_NUM_FOR_EDICT(chain);
chain = ent;
}
VM_localcmd, // #46 void(string s) localcmd
VM_nextent, // #47 entity(entity e) nextent
VM_CL_particle, // #48 void(vector o, vector d, float color, float count) particle
-VM_CL_changeyaw, // #49 void(entity ent, float ideal_yaw, float speed_yaw) ChangeYaw
+VM_changeyaw, // #49 void(entity ent) ChangeYaw
NULL, // #50
VM_vectoangles, // #51 vector(vector v) vectoangles
0, // #52 void(float to, float f) WriteByte
VM_sin, // #60 float(float f) sin (DP_QC_SINCOSSQRTPOW)
VM_cos, // #61 float(float f) cos (DP_QC_SINCOSSQRTPOW)
VM_sqrt, // #62 float(float f) sqrt (DP_QC_SINCOSSQRTPOW)
-VM_CL_changepitch, // #63 void(entity ent, float ideal_pitch, float speed_pitch) changepitch (DP_QC_CHANGEPITCH)
+VM_changepitch, // #63 void(entity ent) changepitch (DP_QC_CHANGEPITCH)
VM_CL_tracetoss, // #64 void(entity e, entity ignore) tracetoss (DP_QC_TRACETOSS)
VM_etos, // #65 string(entity ent) etos (DP_QC_ETOS)
NULL, // #66