X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fclient%2Fcsqcmodel_hooks.qc;h=02ce4bcdd139ea5d4b6479e9dcb09ff5fb1994a5;hb=c820c5d595a896184aa9b2197303061a07aee1bf;hp=320ae656b89dc117133f025ee9a41b33151002bb;hpb=55384b17f6ad8154f79eeeefa17a1be3f060304a;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/client/csqcmodel_hooks.qc b/qcsrc/client/csqcmodel_hooks.qc index 320ae656b..02ce4bcdd 100644 --- a/qcsrc/client/csqcmodel_hooks.qc +++ b/qcsrc/client/csqcmodel_hooks.qc @@ -1,4 +1,4 @@ -void CSQCModel_Hook_PreDraw(); +void CSQCModel_Hook_PreDraw(float isplayer); .float isplayermodel; @@ -14,6 +14,9 @@ void CSQCPlayer_LOD_Apply(void) string modelname = self.model; string s; + vector mi = self.mins; + vector ma = self.maxs; + // set modelindex self.lodmodelindex0 = self.modelindex; self.lodmodelindex1 = self.modelindex; @@ -39,6 +42,7 @@ void CSQCPlayer_LOD_Apply(void) } setmodel(self, modelname); // make everything normal again + setsize(self, mi, ma); } // apply LOD @@ -53,8 +57,8 @@ void CSQCPlayer_LOD_Apply(void) } else { - float distance = vlen(self.origin - other.origin); - float f = (distance + 100.0) * autocvar_cl_playerdetailreduction; + float distance = vlen(self.origin - view_origin); + float f = (distance * current_viewzoom + 100.0) * autocvar_cl_playerdetailreduction; f *= 1.0 / bound(0.01, view_quality, 1); if(f > autocvar_cl_loddistance2) self.modelindex = self.lodmodelindex2; @@ -117,6 +121,7 @@ void CSQCPlayer_ForceModel_Apply(float islocalplayer) { entity e; e = spawn(); + precache_model(cvar_defstring("_cl_playermodel")); setmodel(e, cvar_defstring("_cl_playermodel")); forceplayermodels_goodmodel = e.model; forceplayermodels_goodmodelindex = e.modelindex; @@ -128,12 +133,15 @@ void CSQCPlayer_ForceModel_Apply(float islocalplayer) { if(islocalplayer) { - // trust server's idea of "own player model" - forceplayermodels_modelisgoodmodel = self.forceplayermodels_isgoodmodel; - forceplayermodels_model = self.forceplayermodels_savemodel; - forceplayermodels_modelindex = self.forceplayermodels_savemodelindex; - forceplayermodels_skin = self.forceplayermodels_saveskin; - forceplayermodels_attempted = 1; + if(!isdemo()) // this is mainly cheat protection; not needed for demos + { + // trust server's idea of "own player model" + forceplayermodels_modelisgoodmodel = self.forceplayermodels_isgoodmodel; + forceplayermodels_model = self.forceplayermodels_savemodel; + forceplayermodels_modelindex = self.forceplayermodels_savemodelindex; + forceplayermodels_skin = self.forceplayermodels_saveskin; + forceplayermodels_attempted = 1; + } } } @@ -165,7 +173,17 @@ void CSQCPlayer_ForceModel_Apply(float islocalplayer) } // apply it - if(autocvar_cl_forcemyplayermodel != "" && forceplayermodels_myisgoodmodel && islocalplayer) + float isfriend; + float cm; + cm = self.forceplayermodels_savecolormap; + cm = (cm >= 1024) ? cm : (stof(getplayerkeyvalue(self.colormap - 1, "colors")) + 1024); + + if(teamplay) + isfriend = (cm == 1024 + 17 * myteam); + else + isfriend = islocalplayer; + + if(autocvar_cl_forcemyplayermodel != "" && forceplayermodels_myisgoodmodel && isfriend) { self.model = forceplayermodels_mymodel; self.modelindex = forceplayermodels_mymodelindex; @@ -191,7 +209,56 @@ void CSQCPlayer_ForceModel_Apply(float islocalplayer) } // forceplayercolors too - if(!teamplay) + if(teamplay) + { + // own team's color is never forced + float forcecolor_friend = 0; + float forcecolor_enemy = 0; + float teams_count = 0; + entity tm; + + for(tm = teams.sort_next; tm; tm = tm.sort_next) + if(tm.team != COLOR_SPECTATOR) + ++teams_count; + + if(autocvar_cl_forcemyplayercolors) + forcecolor_friend = 1024 + autocvar_cl_forcemyplayercolors; + if(autocvar_cl_forceplayercolors && teams_count == 2) + forcecolor_enemy = 1024 + autocvar__cl_color; + + if(forcecolor_enemy && !forcecolor_friend) + { + // only enemy color is forced? + // verify it is not equal to the friend color + if(forcecolor_enemy == 1024 + 17 * myteam) + forcecolor_enemy = 0; + } + + if(forcecolor_friend && !forcecolor_enemy) + { + // only friend color is forced? + // verify it is not equal to the enemy color + for(tm = teams.sort_next; tm; tm = tm.sort_next) + // note: we even compare against our own team. + // if we rejected because we matched our OWN team color, + // this is not bad; we then simply keep our color as is + // anyway. + if(forcecolor_friend == 1024 + 17 * tm.team) + forcecolor_friend = 0; + } + + if(cm == 1024 + 17 * myteam) + { + if(forcecolor_friend) + self.colormap = forcecolor_friend; + } + else + { + if(forcecolor_enemy) + self.colormap = forcecolor_enemy; + } + } + else { if(autocvar_cl_forcemyplayercolors && islocalplayer) self.colormap = 1024 + autocvar_cl_forcemyplayercolors; @@ -203,45 +270,55 @@ void CSQCPlayer_ForceModel_Apply(float islocalplayer) // FEATURE: fallback frames .float csqcmodel_saveframe; .float csqcmodel_saveframe2; +#ifdef CSQCMODEL_HAVE_TWO_FRAMES .float csqcmodel_saveframe3; .float csqcmodel_saveframe4; +#endif .float csqcmodel_framecount; + +#define IS_DEAD_FRAME(f) ((f) == 0 || (f) == 1) void CSQCPlayer_FallbackFrame_PreUpdate(void) { self.frame = self.csqcmodel_saveframe; self.frame2 = self.csqcmodel_saveframe2; +#ifdef CSQCMODEL_HAVE_TWO_FRAMES self.frame3 = self.csqcmodel_saveframe3; self.frame4 = self.csqcmodel_saveframe4; +#endif } void CSQCPlayer_FallbackFrame_PostUpdate(float isnew) { self.csqcmodel_saveframe = self.frame; self.csqcmodel_saveframe2 = self.frame2; +#ifdef CSQCMODEL_HAVE_TWO_FRAMES self.csqcmodel_saveframe3 = self.frame3; self.csqcmodel_saveframe4 = self.frame4; +#endif // hack for death animations: set their frametime to zero in case a // player "pops in" if(isnew) { #define FIX_FRAMETIME(f,ft) \ - switch(self.f) \ + if(IS_DEAD_FRAME(self.f) && self.ft != 0 && self.death_time != 0) \ { \ - case 0: \ - case 1: \ - self.ft = 0; \ - break; \ + self.ft = self.death_time; \ } FIX_FRAMETIME(frame, frame1time) FIX_FRAMETIME(frame2, frame2time) +#ifdef CSQCMODEL_HAVE_TWO_FRAMES FIX_FRAMETIME(frame3, frame3time) FIX_FRAMETIME(frame4, frame4time) +#endif } + self.csqcmodel_isdead = IS_DEAD_FRAME(self.frame); } float CSQCPlayer_FallbackFrame(float f) { if(frameduration(self.modelindex, f) > 0) return f; // goooooood + if(frameduration(self.modelindex, 1) <= 0) + return f; // this is a static model. We can't fix it if we wanted to switch(f) { case 23: return 11; // anim_melee -> anim_shoot @@ -260,18 +337,10 @@ void CSQCPlayer_FallbackFrame_Apply(void) { self.frame = CSQCPlayer_FallbackFrame(self.frame); self.frame2 = CSQCPlayer_FallbackFrame(self.frame2); +#ifdef CSQCMODEL_HAVE_TWO_FRAMES self.frame3 = CSQCPlayer_FallbackFrame(self.frame3); self.frame4 = CSQCPlayer_FallbackFrame(self.frame4); -} - -// FEATURE: auto glowmod -.vector glowmod; -void CSQCPlayer_GlowMod_Apply(void) -{ - if(self.colormap > 0) - self.glowmod = colormapPaletteColor(((self.colormap >= 1024) ? self.colormap : stof(getplayerkeyvalue(self.colormap - 1, "colors"))) & 0x0F, TRUE) * 2; - else - self.glowmod = '1 1 1'; +#endif } // FEATURE: auto tag_index @@ -294,10 +363,11 @@ void CSQCModel_AutoTagIndex_Apply(void) } // recursive predraw call to fix issues with forcemodels and LOD if bone indexes mismatch + if(self.tag_entity.classname == "csqcmodel") { entity oldself = self; self = self.tag_entity; - CSQCModel_Hook_PreDraw(); + CSQCModel_Hook_PreDraw((self.entnum >= 1 && self.entnum <= maxclients)); self = oldself; } @@ -312,6 +382,7 @@ void CSQCModel_AutoTagIndex_Apply(void) { // the best part is: IT EXISTS if(substring(self.model, 0, 17) == "models/weapons/v_") + { if(substring(self.tag_entity.model, 0, 17) == "models/weapons/h_") { self.tag_index = gettagindex(self.tag_entity, "weapon"); @@ -325,14 +396,15 @@ void CSQCModel_AutoTagIndex_Apply(void) dprint("h_ model lacks weapon attachment, but v_ model is attached to it\n"); } } - - if(substring(self.model, 0, 17) == "models/weapons/v_") - if(substring(self.tag_entity.model, 0, 14) == "models/player/") + else if(self.tag_entity.isplayermodel) { - self.tag_index = gettagindex(self.tag_entity, "tag_weapon"); + self.tag_index = gettagindex(self.tag_entity, "weapon"); + if(!self.tag_index) + self.tag_index = gettagindex(self.tag_entity, "tag_weapon"); if(!self.tag_index) self.tag_index = gettagindex(self.tag_entity, "bip01 r hand"); } + } if(substring(self.tag_entity.model, 0, 17) == "models/weapons/v_") { @@ -357,6 +429,8 @@ float EF_DIMLIGHT = 8; float EF_DOUBLESIDED = 32768; float EF_NOSELFSHADOW = 65536; float EF_DYNAMICMODELLIGHT = 131072; +float EF_RESTARTANIM_BIT = 1048576; +float EF_TELEPORT_BIT = 2097152; float MF_ROCKET = 1; // leave a trail float MF_GRENADE = 2; // leave a trail float MF_GIB = 4; // leave a trail @@ -384,7 +458,7 @@ void CSQCModel_Effects_PostUpdate(void) void CSQCModel_Effects_Apply(void) { float eff = self.csqcmodel_effects; - eff &~= CSQCMODEL_EF_INVISIBLE; + eff &~= CSQCMODEL_EF_RESPAWNGHOST; self.renderflags &~= (RF_DEPTHHACK | RF_ADDITIVE | RF_FULLBRIGHT | EF_NOSHADOW | RF_USEAXIS); self.effects = 0; @@ -397,7 +471,7 @@ void CSQCModel_Effects_Apply(void) adddynamiclight(self.origin, 400, '3 3 3'); if(eff & EF_DIMLIGHT) adddynamiclight(self.origin, 200, '1.5 1.5 1.5'); - if((eff & EF_NODRAW) || (self.csqcmodel_effects & CSQCMODEL_EF_INVISIBLE) || (self.alpha < 0)) + if((eff & EF_NODRAW) || (self.alpha < 0)) self.drawmask = 0; if(eff & EF_ADDITIVE) self.renderflags |= RF_ADDITIVE; @@ -448,11 +522,49 @@ void CSQCModel_Effects_Apply(void) Projectile_DrawTrail(self.origin); else Projectile_ResetTrail(self.origin); + + if(self.csqcmodel_effects & CSQCMODEL_EF_RESPAWNGHOST) + self.renderflags |= RF_ADDITIVE; + // also special in CSQCPlayer_GlowMod_Apply +} + +// FEATURE: auto glowmod +.vector glowmod; +void CSQCPlayer_GlowMod_Apply(void) +{ + float cm = self.colormap; + + if(self.csqcmodel_effects & CSQCMODEL_EF_RESPAWNGHOST) + cm = 1024; + + if(self.colormap > 0) + self.glowmod = colormapPaletteColor(((self.colormap >= 1024) ? self.colormap : stof(getplayerkeyvalue(self.colormap - 1, "colors"))) & 0x0F, TRUE) * 2; + else + self.glowmod = '1 1 1'; + + if(autocvar_cl_deathglow > 0) + if(self.csqcmodel_isdead) + { + self.glowmod = self.glowmod * bound(0, 1 - (time - self.death_time) / autocvar_cl_deathglow, 1); + // prevent the zero vector + self.glowmod_x = max(self.glowmod_x, 0.0001); + self.glowmod_y = max(self.glowmod_y, 0.0001); + self.glowmod_z = max(self.glowmod_z, 0.0001); + } } // general functions .float csqcmodel_predraw_run; -void CSQCModel_Hook_PreDraw() +.float anim_frame; +.float anim_frame1time; +.float anim_frame2; +.float anim_frame2time; +.float anim_saveframe; +.float anim_saveframe1time; +.float anim_saveframe2; +.float anim_saveframe2time; +.float anim_prev_pmove_flags; +void CSQCModel_Hook_PreDraw(float isplayer) { if(self.csqcmodel_predraw_run == framecount) return; @@ -471,7 +583,64 @@ void CSQCModel_Hook_PreDraw() CSQCPlayer_ForceModel_Apply(self.entnum == player_localnum + 1); CSQCPlayer_GlowMod_Apply(); CSQCPlayer_LOD_Apply(); - CSQCPlayer_FallbackFrame_Apply(); + if(!isplayer) + CSQCPlayer_FallbackFrame_Apply(); + else + { + // we know that frame3 and frame4 fields, used by InterpolateAnimation, are left alone - but that is all we know! + float doblend = autocvar__animblend; + float onground = 0; + if(self == csqcplayer) + { + if(self.pmove_flags & PMF_ONGROUND) + onground = 1; + self.anim_prev_pmove_flags = self.pmove_flags; + if(self.pmove_flags & PMF_DUCKED) + animdecide_setstate(self, self.anim_state | ANIMSTATE_DUCK, FALSE); + else if(self.anim_state & ANIMSTATE_DUCK) + animdecide_setstate(self, self.anim_state - ANIMSTATE_DUCK, FALSE); + } + else + { + traceline(self.origin + '0 0 1' * self.maxs_z, self.origin + '0 0 1' * (self.mins_z - 4), MOVE_NOMONSTERS, self); + if(trace_startsolid || trace_fraction < 1) + onground = 1; + } + animdecide_init(self); // FIXME only do this on model change + animdecide_setimplicitstate(self, onground); + animdecide_setframes(self, doblend, anim_frame, anim_frame1time, anim_frame2, anim_frame2time); + float sf = 0; + if(self.anim_saveframe != self.anim_frame || self.anim_saveframe1time != self.anim_frame1time) + sf |= CSQCMODEL_PROPERTY_FRAME; + if(self.anim_saveframe2 != self.anim_frame2 || self.anim_saveframe2time != self.anim_frame2time) + sf |= CSQCMODEL_PROPERTY_FRAME2; + self.anim_saveframe = self.anim_frame; + self.anim_saveframe1time = self.anim_frame1time; + self.anim_saveframe2 = self.anim_frame2; + self.anim_saveframe2time = self.anim_frame2time; + if(sf) + { + CSQCModel_InterpolateAnimation_2To4_PreNote(sf | CSQCMODEL_PROPERTY_LERPFRAC); + self.lerpfrac = (doblend ? 0.5 : 0); + self.frame = self.anim_frame; + self.frame1time = self.anim_frame1time; + self.frame2 = self.anim_frame2; + self.frame2time = self.anim_frame2time; + CSQCModel_InterpolateAnimation_2To4_Note(sf | CSQCMODEL_PROPERTY_LERPFRAC, FALSE); + } + CSQCModel_InterpolateAnimation_2To4_Do(); + if(doblend) + { + skeleton_from_frames(self); + } + else + { + free_skeleton_from_frames(self); + // just in case, clear these + self.lerpfrac3 = 0; + self.lerpfrac4 = 0; + } + } } CSQCModel_AutoTagIndex_Apply(); @@ -485,7 +654,8 @@ void CSQCModel_Hook_PreUpdate(float isnew, float isplayer, float islocalplayer) CSQCModel_Effects_PreUpdate(); if(self.isplayermodel) { - CSQCPlayer_FallbackFrame_PreUpdate(); + if(!isplayer) + CSQCPlayer_FallbackFrame_PreUpdate(); CSQCPlayer_ForceModel_PreUpdate(); } } @@ -493,13 +663,14 @@ void CSQCModel_Hook_PreUpdate(float isnew, float isplayer, float islocalplayer) void CSQCModel_Hook_PostUpdate(float isnew, float isplayer, float islocalplayer) { // is it a player model? (shared state) - self.isplayermodel = (substring(self.model, 0, 14) == "models/player/"); + self.isplayermodel = (substring(self.model, 0, 14) == "models/player/" || substring(self.model, 0, 17) == "models/ok_player/"); // save values set by server if(self.isplayermodel) { CSQCPlayer_ForceModel_PostUpdate(); - CSQCPlayer_FallbackFrame_PostUpdate(isnew); + if(!isplayer) + CSQCPlayer_FallbackFrame_PostUpdate(isnew); } CSQCModel_Effects_PostUpdate(); }