From 65d0276f3398500d3685a91acd6b8c60e62c92a0 Mon Sep 17 00:00:00 2001 From: div0 Date: Mon, 16 Mar 2009 07:19:57 +0000 Subject: [PATCH] cleanup: remove code to load w_*.zym weapon models; instead make the loading of the v_ model only happen if the h_ model defines the "weapon" tag. That way, the h_ model can be both an "invisible hand" model, or an old-style "full weapon" model. Also, note that the engine loads ZYM models properly as ZYM even if renamed to dpm, so there is no need to try all extensions. All in all, this saves quite some file open calls and should help with dedicated server performance, especially on operating systems with slow file opening (e.g. Windows with a running on-access virus scanner). git-svn-id: svn://svn.icculus.org/nexuiz/trunk@6186 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/qcsrc/server/cl_weaponsystem.qc | 77 ++++++++++------------------ data/qcsrc/server/havocbot.qc | 16 +++--- data/qcsrc/server/w_shotgun.qc | 16 +++--- 3 files changed, 42 insertions(+), 67 deletions(-) diff --git a/data/qcsrc/server/cl_weaponsystem.qc b/data/qcsrc/server/cl_weaponsystem.qc index 4e550ad10..5122c147a 100644 --- a/data/qcsrc/server/cl_weaponsystem.qc +++ b/data/qcsrc/server/cl_weaponsystem.qc @@ -307,7 +307,6 @@ void CL_Weaponentity_Think() string animfilename; float animfile; - float modelfile; if (self.owner.weaponname != "") { // if there is a child entity, hide it until we're sure we use it @@ -317,59 +316,34 @@ void CL_Weaponentity_Think() setmodel(self, strcat("models/weapons/v_", self.owner.weaponname, ".md3")); // precision set below else { - animfilename = strcat("models/weapons/h_", self.owner.weaponname, ".zym"); - modelfile = fopen(animfilename, FILE_READ); - if (modelfile >= 0) + setmodel(self, strcat("models/weapons/h_", self.owner.weaponname, ".dpm")); // precision set below + animfilename = strcat("models/weapons/h_", self.owner.weaponname, ".dpm.animinfo"); + animfile = fopen(animfilename, FILE_READ); + // preset some defaults that work great for renamed zym files (which don't need an animinfo) + self.anim_fire1 = '0 1 0.01'; + self.anim_fire2 = '1 1 0.01'; + self.anim_idle = '2 1 0.01'; + self.anim_reload = '3 1 0.01'; + if (animfile >= 0) { - fclose(modelfile); - self.anim_fire1 = '0 1 0.01'; - self.anim_fire2 = '1 1 0.01'; - self.anim_idle = '2 1 0.01'; - self.anim_reload = '3 1 0.01'; if (!self.weaponentity) self.weaponentity = spawn(); - setmodel(self, strcat("models/weapons/h_", self.owner.weaponname, ".zym")); // precision set below - setmodel(self.weaponentity, strcat("models/weapons/v_", self.owner.weaponname, ".md3")); // precision does not matter - setattachment(self.weaponentity, self, "weapon"); + animparseerror = FALSE; + self.anim_fire1 = animparseline(animfile); + self.anim_fire2 = animparseline(animfile); + self.anim_idle = animparseline(animfile); + self.anim_reload = animparseline(animfile); + fclose(animfile); + if (animparseerror) + print("Parse error in ", animfilename, ", some player animations are broken\n"); } - else + + // if we have a "weapon" tag, let's attach the v_ model to it ("invisible hand" style model) + // if we don't, this is a "real" animated model + if(gettagindex(self, "weapon")) { - animfilename = strcat("models/weapons/h_", self.owner.weaponname, ".dpm.animinfo"); - animfile = fopen(animfilename, FILE_READ); - if (animfile >= 0) - { - if (!self.weaponentity) - self.weaponentity = spawn(); - setmodel(self, strcat("models/weapons/h_", self.owner.weaponname, ".dpm")); // precision set below - setmodel(self.weaponentity, strcat("models/weapons/v_", self.owner.weaponname, ".md3")); // precision does not matter - setattachment(self.weaponentity, self, "weapon"); - } - else - { - animfilename = strcat("models/weapons/w_", self.owner.weaponname, ".dpm.animinfo"); - animfile = fopen(animfilename, FILE_READ); - if (animfile >= 0) - setmodel(self, strcat("models/weapons/w_", self.owner.weaponname, ".dpm")); // precision set below - } - if (animfile >= 0) - { - animparseerror = FALSE; - self.anim_fire1 = animparseline(animfile); - self.anim_fire2 = animparseline(animfile); - self.anim_idle = animparseline(animfile); - self.anim_reload = animparseline(animfile); - fclose(animfile); - if (animparseerror) - print("Parse error in ", animfilename, ", some player animations are broken\n"); - } - else - { - self.anim_fire1 = '0 1 0.01'; - self.anim_fire2 = '1 1 0.01'; - self.anim_idle = '2 1 0.01'; - self.anim_reload = '3 1 0.01'; - setmodel(self, strcat("models/weapons/w_", self.owner.weaponname, ".zym")); // precision set below - } + setmodel(self.weaponentity, strcat("models/weapons/v_", self.owner.weaponname, ".md3")); // precision does not matter + setattachment(self.weaponentity, self, "weapon"); } } } @@ -452,7 +426,8 @@ void CL_Weaponentity_Think() } tb = (self.effects & EF_TELEPORT_BIT); - self.effects = self.owner.effects - (self.owner.effects & EF_LOWPRECISION);// | EF_LOWPRECISION; + self.effects = self.owner.effects; + self.effects &~= EF_LOWPRECISION; self.effects &~= EF_FULLBRIGHT; // can mask team color, so get rid of it self.effects &~= EF_TELEPORT_BIT; self.effects |= tb; @@ -465,7 +440,7 @@ void CL_Weaponentity_Think() self.colormap = self.owner.colormap; if (self.weaponentity) { - self.weaponentity.effects = self.effects & EF_ADDITIVE; + self.weaponentity.effects = self.effects; self.weaponentity.alpha = self.alpha; self.weaponentity.colormap = self.colormap; } diff --git a/data/qcsrc/server/havocbot.qc b/data/qcsrc/server/havocbot.qc index 30c023ace..824372dbc 100644 --- a/data/qcsrc/server/havocbot.qc +++ b/data/qcsrc/server/havocbot.qc @@ -140,7 +140,7 @@ void havocbot_keyboard_movement(vector destorg) .float bot_canruntogoal; void havocbot_bunnyhop(vector dir) { - local float distance; + local float bunnyhopdistance; local vector deviation; if(self.goalcurrent.classname == "player") @@ -165,7 +165,7 @@ void havocbot_bunnyhop(vector dir) self.bot_timelastseengoal = 0; } - distance = vlen(self.origin - self.goalcurrent.origin); + bunnyhopdistance = vlen(self.origin - self.goalcurrent.origin); // Run only to visible goals traceline(self.origin + self.view_ofs , self.goalcurrent.origin, TRUE, world); @@ -186,7 +186,7 @@ void havocbot_bunnyhop(vector dir) // don't run if it is too close if(self.bot_canruntogoal==0) { - if(distance > cvar("bot_ai_bunnyhop_startdistance")) + if(bunnyhopdistance > cvar("bot_ai_bunnyhop_startdistance")) self.bot_canruntogoal = 1; else self.bot_canruntogoal = -1; @@ -206,7 +206,7 @@ void havocbot_bunnyhop(vector dir) while (deviation_y > 180) deviation_y = deviation_y - 360; if(fabs(deviation_y) < 15) - if(distance < vlen(self.origin - self.goalstack01.origin)) + if(bunnyhopdistance < vlen(self.origin - self.goalstack01.origin)) if(fabs(self.goalstack01.origin_z - self.goalcurrent.origin_z) < self.maxs_z - self.mins_z) { traceline(self.origin + self.view_ofs , self.goalstack01.origin, TRUE, world); @@ -220,7 +220,7 @@ void havocbot_bunnyhop(vector dir) if(checkdistance) { self.aistatus &~= AI_STATUS_RUNNING; - if(distance > cvar("bot_ai_bunnyhop_stopdistance")) + if(bunnyhopdistance > cvar("bot_ai_bunnyhop_stopdistance")) self.BUTTON_JUMP = TRUE; } else @@ -970,15 +970,15 @@ void havocbot_ai() self.aistatus &~= AI_STATUS_ATTACKING; local vector now,v,next;//,heading; - local float distance,skillblend,distanceblend,blend; + local float aimdistance,skillblend,distanceblend,blend; next = now = self.goalcurrent.origin - (self.origin + self.view_ofs); - distance = vlen(now); + aimdistance = vlen(now); //heading = self.velocity; //dprint(self.goalstack01.classname,etos(self.goalstack01),"\n"); if(self.goalstack01 != self && self.goalstack01 != world && self.aistatus & AI_STATUS_RUNNING == 0) next = self.goalstack01.origin - (self.origin + self.view_ofs); skillblend=bound(0,(skill-2.5)*0.5,1); //lower skill player can't preturn - distanceblend=bound(0,distance/cvar("bot_ai_keyboard_distance"),1); + distanceblend=bound(0,aimdistance/cvar("bot_ai_keyboard_distance"),1); blend = skillblend * (1-distanceblend); //v = (now * (distanceblend) + next * (1-distanceblend)) * (skillblend) + now * (1-skillblend); //v = now * (distanceblend) * (skillblend) + next * (1-distanceblend) * (skillblend) + now * (1-skillblend); diff --git a/data/qcsrc/server/w_shotgun.qc b/data/qcsrc/server/w_shotgun.qc index bce219c70..0643c99f6 100644 --- a/data/qcsrc/server/w_shotgun.qc +++ b/data/qcsrc/server/w_shotgun.qc @@ -2,7 +2,7 @@ void W_Shotgun_Attack (void) { float sc; - float ammo; + float ammoamount; float bullets; float d; float f; @@ -11,7 +11,7 @@ void W_Shotgun_Attack (void) float bulletconstant; local entity flash; - ammo = cvar("g_balance_shotgun_primary_ammo"); + ammoamount = cvar("g_balance_shotgun_primary_ammo"); bullets = cvar("g_balance_shotgun_primary_bullets"); d = cvar("g_balance_shotgun_primary_damage"); f = cvar("g_balance_shotgun_primary_force"); @@ -23,13 +23,13 @@ void W_Shotgun_Attack (void) for (sc = 0;sc < bullets;sc = sc + 1) fireBallisticBullet(w_shotorg, w_shotdir, spread, bulletspeed, 5, d, 0, f, WEP_SHOTGUN, 0, 1, bulletconstant); if not(self.items & IT_UNLIMITED_WEAPON_AMMO) - self.ammo_shells = self.ammo_shells - ammo; + self.ammo_shells = self.ammo_shells - ammoamount; pointparticles(particleeffectnum("shotgun_muzzleflash"), w_shotorg, w_shotdir * 1000, cvar("g_balance_shotgun_primary_ammo")); // casing code if (cvar("g_casings") >= 1) - for (sc = 0;sc < ammo;sc = sc + 1) + for (sc = 0;sc < ammoamount;sc = sc + 1) SpawnCasing (((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 30) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 1); // muzzle flash for 1st person view @@ -51,7 +51,7 @@ void W_Shotgun_Attack (void) void W_Shotgun_Attack2 (void) { float sc; - float ammo; + float ammoamount; float bullets; float d; float f; @@ -60,7 +60,7 @@ void W_Shotgun_Attack2 (void) float bulletconstant; local entity flash; - ammo = cvar("g_balance_shotgun_secondary_ammo"); + ammoamount = cvar("g_balance_shotgun_secondary_ammo"); bullets = cvar("g_balance_shotgun_secondary_bullets"); d = cvar("g_balance_shotgun_secondary_damage"); f = cvar("g_balance_shotgun_secondary_force"); @@ -72,13 +72,13 @@ void W_Shotgun_Attack2 (void) for (sc = 0;sc < bullets;sc = sc + 1) fireBallisticBullet(w_shotorg, w_shotdir, spread, bulletspeed, 5, d, 0, f, WEP_SHOTGUN | HITTYPE_SECONDARY, 0, 1, bulletconstant); if not(self.items & IT_UNLIMITED_WEAPON_AMMO) - self.ammo_shells = self.ammo_shells - ammo; + self.ammo_shells = self.ammo_shells - ammoamount; pointparticles(particleeffectnum("shotgun_muzzleflash"), w_shotorg, w_shotdir * 1000, cvar("g_balance_shotgun_secondary_ammo")); // casing code if (cvar("g_casings") >= 1) - for (sc = 0;sc < ammo;sc = sc + 1) + for (sc = 0;sc < ammoamount;sc = sc + 1) SpawnCasing (((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 30) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 1); flash = spawn(); -- 2.39.2