Small cleanup in some client-side gs-entbase code.

This commit is contained in:
Marco Cawthorne 2020-10-23 20:13:27 +02:00
parent 0cfa4df68a
commit 689ffe14bc
11 changed files with 160 additions and 150 deletions

View File

@ -39,70 +39,64 @@ class env_glow:CBaseEntity
virtual void(string, string) SpawnKey;
};
float env_glow::predraw(void)
float
env_glow::predraw(void)
{
vector forg;
vector fsize;
float falpha;
vector vecPlayer;
#ifdef WASTES
vecPlayer = viewClient.vecPlayerOrigin;
#else
int s = (float)getproperty(VF_ACTIVESEAT);
pSeat = &g_seats[s];
vecPlayer = pSeat->m_vecPredictedOrigin;
#endif
m_flAlpha = bound(0, m_flAlpha, 1.0f);
m_flAlpha = bound(0.0f, m_flAlpha, 1.0f);
if (m_flAlpha > 0) {
vector forg;
vector fsize;
float falpha;
/* Scale the glow somewhat with the players distance */
fsize = m_vecSize * m_flScale;
fsize *= bound(1, vlen(vecPlayer - origin) / 256, 4);
/* Fade out when the player is starting to move away */
falpha = 1 - bound(0, vlen(vecPlayer - origin) / 1024, 1);
falpha *= m_flAlpha;
/* Clamp the alpha by the glows' renderamt value */
falpha = bound(0, falpha, m_flMaxAlpha);
makevectors(view_angles);
/* Nudge this slightly towards the camera */
makevectors(vectoangles(origin - vecPlayer));
forg = origin + (v_forward * -16);
if (m_flAlpha < 0.0f)
return PREDRAW_NEXT;
/* Project it, always facing the player */
makevectors(view_angles);
R_BeginPolygon(m_strSprite, 1, 0);
R_PolygonVertex(forg + v_right * fsize[0] - v_up * fsize[1],
[1,1], m_vecColor, falpha);
R_PolygonVertex(forg - v_right * fsize[0] - v_up * fsize[1],
[0,1], m_vecColor, falpha);
R_PolygonVertex(forg - v_right * fsize[0] + v_up * fsize[1],
[0,0], m_vecColor, falpha);
R_PolygonVertex(forg + v_right * fsize[0] + v_up * fsize[1],
[1,0], m_vecColor, falpha);
R_EndPolygon();
addentity(this);
}
/* Scale the glow somewhat with the players distance */
fsize = m_vecSize * m_flScale;
fsize *= bound(1, vlen(vecPlayer - origin) / 256, 4);
/* Fade out when the player is starting to move away */
falpha = 1 - bound(0, vlen(vecPlayer - origin) / 1024, 1);
falpha *= m_flAlpha;
/* Clamp the alpha by the glows' renderamt value */
falpha = bound(0, falpha, m_flMaxAlpha);
makevectors(view_angles);
/* Nudge this slightly towards the camera */
makevectors(vectoangles(origin - vecPlayer));
forg = origin + (v_forward * -16);
/* Project it, always facing the player */
makevectors(view_angles);
R_BeginPolygon(m_strSprite, 1, 0);
R_PolygonVertex(forg + v_right * fsize[0] - v_up * fsize[1],
[1,1], m_vecColor, falpha);
R_PolygonVertex(forg - v_right * fsize[0] - v_up * fsize[1],
[0,1], m_vecColor, falpha);
R_PolygonVertex(forg - v_right * fsize[0] + v_up * fsize[1],
[0,0], m_vecColor, falpha);
R_PolygonVertex(forg + v_right * fsize[0] + v_up * fsize[1],
[1,0], m_vecColor, falpha);
R_EndPolygon();
addentity(this);
return PREDRAW_NEXT;
}
void env_glow::customphysics(void)
void
env_glow::customphysics(void)
{
vector vecPlayer;
#ifdef WASTES
vecPlayer = viewClient.vecPlayerOrigin;
#else
int s = (float)getproperty(VF_ACTIVESEAT);
pSeat = &g_seats[s];
vecPlayer = pSeat->m_vecPredictedOrigin;
#endif
if (checkpvs(vecPlayer, this) == FALSE) {
m_flAlpha -= clframetime;
@ -121,17 +115,8 @@ void env_glow::customphysics(void)
m_flAlpha += clframetime;
}
void env_glow::env_glow(void)
{
m_flScale = 1.0f;
m_flMaxAlpha = 1.0f;
m_vecColor = [1,1,1];
drawmask = MASK_ENGINE;
setorigin(this, origin);
Init();
}
void env_glow::SpawnKey(string strField, string strKey)
void
env_glow::SpawnKey(string strField, string strKey)
{
switch (strField) {
case "material":
@ -163,3 +148,14 @@ void env_glow::SpawnKey(string strField, string strKey)
CBaseEntity::SpawnKey(strField, strKey);
}
}
void
env_glow::env_glow(void)
{
m_flScale = 1.0f;
m_flMaxAlpha = 1.0f;
m_vecColor = [1,1,1];
drawmask = MASK_ENGINE;
setorigin(this, origin);
Init();
}

View File

@ -33,17 +33,14 @@ class env_laser
void(void) env_laser;
virtual void(void) Init;
virtual void(void) Initialized;
virtual void(float flChanged) ReceiveEntity;
virtual float(void) predraw;
};
float env_laser::predraw(void)
{
if (!m_iState) {
if (!m_iState)
return PREDRAW_NEXT;
}
R_BeginPolygon(m_strBeamTex, 0, 0);
R_PolygonVertex(angles, [0,0], [1,1,1], 1.0f);
@ -54,7 +51,8 @@ float env_laser::predraw(void)
return PREDRAW_NEXT;
}
void env_laser::ReceiveEntity(float flChanged)
void
env_laser::ReceiveEntity(float flChanged)
{
if (flChanged & ENVLASER_CHANGED_ORIGIN) {
origin[0] = readcoord();
@ -66,28 +64,18 @@ void env_laser::ReceiveEntity(float flChanged)
angles[1] = readcoord();
angles[2] = readcoord();
}
if (flChanged & ENVLASER_CHANGED_TEXTURE) {
if (flChanged & ENVLASER_CHANGED_TEXTURE)
m_strBeamTex = sprintf("%s_0.tga", readstring());
}
if (flChanged & ENVLASER_CHANGED_ENDTEXTURE) {
if (flChanged & ENVLASER_CHANGED_ENDTEXTURE)
m_strEndTex = readstring();
}
if (flChanged & ENVLASER_CHANGED_STATE) {
if (flChanged & ENVLASER_CHANGED_STATE)
m_iState = readbyte();
}
drawmask = MASK_ENGINE;
setorigin(this, origin);
}
void env_laser::Init(void)
{
}
void env_laser::Initialized(void)
{
}
void env_laser::env_laser(void)
void
env_laser::env_laser(void)
{
drawmask = MASK_ENGINE;
}

View File

@ -60,6 +60,10 @@ Client-side environmental reverb modifier.
This works only with the OpenAL sound backend.
*/
var int autocvar_dsp_environments = TRUE;
reverbinfo_t mix;
enum
{
DSP_DEFAULT,
@ -150,7 +154,8 @@ class env_sound:CBaseEntity
virtual void(string, string) SpawnKey;
};
void env_sound::env_sound(void)
void
env_sound::env_sound(void)
{
m_iRadius = 256;
Init();
@ -255,7 +260,8 @@ void env_sound::env_sound(void)
}
}
void env_sound::SpawnKey(string strField, string strKey)
void
env_sound::SpawnKey(string strField, string strKey)
{
switch (strField) {
case "roomtype":
@ -269,7 +275,8 @@ void env_sound::SpawnKey(string strField, string strKey)
}
}
void DSP_SetEnvironment(int id)
void
DSP_SetEnvironment(int id)
{
if (g_iDSP == id) {
return;
@ -280,8 +287,8 @@ void DSP_SetEnvironment(int id)
g_flDSPTime = 0.0f;
}
reverbinfo_t mix;
void DSP_Interpolate(int id)
void
DSP_Interpolate(int id)
{
mix.flDensity = Math_Lerp(mix.flDensity, reverbPresets[id].flDensity, g_flDSPTime);
mix.flDiffusion = Math_Lerp(mix.flDiffusion, reverbPresets[id].flDiffusion, g_flDSPTime);
@ -312,8 +319,8 @@ void DSP_Interpolate(int id)
mix.iDecayHFLimit = Math_Lerp(mix.iDecayHFLimit, reverbPresets[id].iDecayHFLimit, g_flDSPTime);
}
var int autocvar_dsp_environments = TRUE;
void DSP_UpdateListener(void)
void
DSP_UpdateListener(void)
{
static int old_dsp;
@ -327,13 +334,9 @@ void DSP_UpdateListener(void)
return;
}
#ifdef WASTES
vecPlayer = viewClient.vecPlayerOrigin;
#else
int s = (float)getproperty(VF_ACTIVESEAT);
pSeat = &g_seats[s];
vecPlayer = pSeat->m_vecPredictedOrigin;
#endif
float bestdist = 999999;
for (entity e = world; (e = find(e, classname, "env_sound"));) {
@ -386,7 +389,8 @@ void DSP_UpdateListener(void)
#endif
}
void DSP_Init(void)
void
DSP_Init(void)
{
g_iDSP = 0;
g_flDSPTime = 1.0f;

View File

@ -21,7 +21,7 @@
Client-side environmental soundscape modifier.
*/
int Sound_Precache(string shader);
var int autocvar_dsp_soundscapes = TRUE;
int g_scapes;
@ -38,8 +38,10 @@ class env_soundscape:CBaseEntity
env_soundscape g_entSoundScape;
env_soundscape g_entOldScape;
env_soundscape g_ambientsound;
void env_soundscape::SpawnKey(string strField, string strKey)
void
env_soundscape::SpawnKey(string strField, string strKey)
{
switch (strField) {
case "shader":
@ -59,7 +61,8 @@ void env_soundscape::SpawnKey(string strField, string strKey)
}
}
void env_soundscape::env_soundscape(void)
void
env_soundscape::env_soundscape(void)
{
g_scapes+=1;
m_iID = g_scapes;
@ -67,14 +70,14 @@ void env_soundscape::env_soundscape(void)
setorigin(this, origin);
}
void DSP_ResetSoundscape(void)
void
DSP_ResetSoundscape(void)
{
g_entSoundScape = __NULL__;
}
var int autocvar_dsp_soundscapes = TRUE;
env_soundscape g_ambientsound;
void DSP_UpdateSoundscape(void)
void
DSP_UpdateSoundscape(void)
{
vector vecPlayer;
@ -86,13 +89,9 @@ void DSP_UpdateSoundscape(void)
return;
}
#ifdef WASTES
vecPlayer = viewClient.vecPlayerOrigin;
#else
int s = (float)getproperty(VF_ACTIVESEAT);
pSeat = &g_seats[s];
vecPlayer = pSeat->m_vecPredictedOrigin;
#endif
float bestdist = 999999;
for (entity e = world; (e = find(e, classname, "env_soundscape"));) {

View File

@ -26,7 +26,8 @@ class env_sprite:CBaseEntity
virtual void(void) think;
};
void env_sprite::think(void)
void
env_sprite::think(void)
{
if (frame >= (maxframe-1)) {
if (loops == 0) {
@ -41,7 +42,8 @@ void env_sprite::think(void)
nextthink = time + (1 / framerate);
}
void env_sprite::ReceiveEntity(float flChanged)
void
env_sprite::ReceiveEntity(float flChanged)
{
origin[0] = readcoord();
origin[1] = readcoord();
@ -67,17 +69,21 @@ void env_sprite::ReceiveEntity(float flChanged)
}
/* make sure we're not spawning on the client-side */
void env_sprite::Init(void)
void
env_sprite::Init(void)
{
}
void env_sprite::Initialized(void)
void
env_sprite::Initialized(void)
{
}
void env_sprite::env_sprite(void)
void
env_sprite::env_sprite(void)
{
}
void EnvSprite_ParseEvent(void)
void
EnvSprite_ParseEvent(void)
{
env_sprite spr = spawn(env_sprite);
spr.origin[0] = readcoord();

View File

@ -26,7 +26,8 @@ STUB!
#define FLARE_SIZE [128,128]
int Util_IsSky(vector pos)
int
Util_IsSky(vector pos)
{
if (serverkeyfloat("*bspversion") == 30)
if (getsurfacetexture(world, getsurfacenearpoint(world, pos)) == "sky") {
@ -98,20 +99,23 @@ env_sun::postdraw(void)
drawpic(lens_1 - c * 0.5, "textures/sfx/flare3", FLARE_SIZE, [1,1,1] * m_flLensAlpha, 1.0f, DRAWFLAG_ADDITIVE);
}
void env_sun::Init(void)
void
env_sun::Init(void)
{
CBaseEntity::Init();
setorigin(this, origin);
drawmask = MASK_ENGINE;
}
void env_sun::Initialized(void)
void
env_sun::Initialized(void)
{
makevectors(m_vecLensPos);
m_vecLensPos = vectoangles(v_forward);
}
void env_sun::env_sun(void)
void
env_sun::env_sun(void)
{
precache_pic("textures/sfx/flare1");
precache_pic("textures/sfx/flare2");
@ -121,7 +125,8 @@ void env_sun::env_sun(void)
Init();
}
void env_sun::SpawnKey(string strField, string strKey)
void
env_sun::SpawnKey(string strField, string strKey)
{
switch (strField) {
case "pitch":

View File

@ -15,6 +15,7 @@
*/
/*QUAKED func_dustmotes (0 .5 .8) ?
"count" Number of dustmote particles that will float around on average.
Dustmote emitting brush volume.
*/
@ -31,15 +32,14 @@ class func_dustmotes:CBaseEntity
virtual void(string, string) SpawnKey;
};
float func_dustmotes::predraw(void)
float
func_dustmotes::predraw(void)
{
if (m_flNexTime > cltime) {
if (m_flNexTime > cltime)
return PREDRAW_NEXT;
}
if (checkpvs(getproperty(VF_ORIGIN), this) == FALSE) {
if (checkpvs(getproperty(VF_ORIGIN), this) == FALSE)
return PREDRAW_NEXT;
}
for (int i = 0; i < m_iCount; i++) {
vector vecPos;
@ -48,21 +48,15 @@ float func_dustmotes::predraw(void)
vecPos[2] = mins[2] + (random() * (maxs[2] - mins[2]));
pointparticles(PART_DUSTMOTE, vecPos, [0,0,0], 1);
}
m_flNexTime = cltime + 3.0f;
addentity(self);
return PREDRAW_NEXT;
}
void func_dustmotes::func_dustmotes(void)
{
solid = SOLID_NOT;
Init();
m_iCount = vlen(size) / 10;
}
void func_dustmotes::Init(void)
void
func_dustmotes::Init(void)
{
CBaseEntity::Init();
@ -73,7 +67,8 @@ void func_dustmotes::Init(void)
drawmask = MASK_ENGINE;
}
void func_dustmotes::SpawnKey(string strField, string strKey)
void
func_dustmotes::SpawnKey(string strField, string strKey)
{
switch (strField) {
case "count":
@ -84,3 +79,11 @@ void func_dustmotes::SpawnKey(string strField, string strKey)
CBaseEntity::SpawnKey(strField, strKey);
}
}
void
func_dustmotes::func_dustmotes(void)
{
solid = SOLID_NOT;
Init();
m_iCount = vlen(size) / 10;
}

View File

@ -39,17 +39,14 @@ class func_lod:CBaseEntity
virtual void(string,string) SpawnKey;
};
float func_lod::predraw(void)
float
func_lod::predraw(void)
{
vector vecPlayer;
#ifdef WASTES
vecPlayer = viewClient.vecPlayerOrigin;
#else
int s = (float)getproperty(VF_ACTIVESEAT);
pSeat = &g_seats[s];
vecPlayer = pSeat->m_vecPredictedOrigin;
#endif
if (checkpvs(vecPlayer, this) == FALSE) {
return PREDRAW_NEXT;
@ -75,7 +72,8 @@ float func_lod::predraw(void)
return PREDRAW_NEXT;
}
void func_lod::SpawnKey(string strField, string strKey)
void
func_lod::SpawnKey(string strField, string strKey)
{
switch (strField) {
case "DisappearDist":
@ -90,7 +88,8 @@ void func_lod::SpawnKey(string strField, string strKey)
}
}
void func_lod::Init(void)
void
func_lod::Init(void)
{
CBaseEntity::Init();
@ -105,7 +104,8 @@ void func_lod::Init(void)
m_vecTestPos[2] = absmin[2] + (0.5 * (absmax[2] - absmin[2]));
}
void func_lod::func_lod(void)
void
func_lod::func_lod(void)
{
m_iDisappearDist = 2000;
solid = SOLID_BSP;

View File

@ -97,9 +97,9 @@ void light_dynamic::ReceiveEntity(float flFlags)
m_iState = readbyte();
classname = "light_dynamic";
drawmask = MASK_ENGINE;
}
void light_dynamic::light_dynamic(void)
{
drawmask = MASK_ENGINE;
}

View File

@ -27,26 +27,23 @@ class light_environment:CBaseEntity
virtual void(string, string) SpawnKey;
};
void light_environment::light_environment(void)
{
solid = SOLID_NOT;
Init();
}
void light_environment::Init(void)
void
light_environment::Init(void)
{
CBaseEntity::Init();
setorigin(this, origin);
drawmask = MASK_ENGINE;
}
void light_environment::Initialized(void)
void
light_environment::Initialized(void)
{
makevectors(g_vecSunDir);
cvar_set("r_shadows_throwdirection", sprintf("%v", v_forward));
}
void light_environment::SpawnKey(string strField, string strKey)
void
light_environment::SpawnKey(string strField, string strKey)
{
switch (strField) {
case "pitch":
@ -59,3 +56,10 @@ void light_environment::SpawnKey(string strField, string strKey)
CBaseEntity::SpawnKey(strField, strKey);
}
}
void
light_environment::light_environment(void)
{
solid = SOLID_NOT;
Init();
}

View File

@ -38,13 +38,15 @@ class trigger_gravity:CBaseTrigger
#endif
};
void trigger_gravity::touch(void)
void
trigger_gravity::touch(void)
{
other.gravity = m_flGravity;
}
/* TODO: Make this redundant */
void trigger_gravity::Respawn(void)
void
trigger_gravity::Respawn(void)
{
solid = SOLID_BSPTRIGGER;
#ifdef GS_DEVELOPER
@ -52,7 +54,8 @@ void trigger_gravity::Respawn(void)
#endif
}
void trigger_gravity::SpawnKey(string strField, string strKey)
void
trigger_gravity::SpawnKey(string strField, string strKey)
{
switch (strField) {
case "gravity":
@ -63,7 +66,8 @@ void trigger_gravity::SpawnKey(string strField, string strKey)
}
}
void trigger_gravity::trigger_gravity(void)
void
trigger_gravity::trigger_gravity(void)
{
#ifdef SERVER
CBaseEntity::CBaseEntity();
@ -72,7 +76,8 @@ void trigger_gravity::trigger_gravity(void)
}
#ifdef CLIENT
void trigger_gravity::Initialized (void)
void
trigger_gravity::Initialized (void)
{
setmodel(this, model);
movetype = MOVETYPE_NONE;