Skip to content

Commit

Permalink
fog improvements
Browse files Browse the repository at this point in the history
- use MOVETYPE_FOLLOW for color layers (50% less network data)
- don't render fog for software users (overdraw kills that renderer)

also added a hook for cvar queries and added renderer to client info
  • Loading branch information
wootguy committed Dec 12, 2024
1 parent f35e384 commit e23e2b2
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
24 changes: 23 additions & 1 deletion dlls/env/CEnvWeather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ void CFogLayer::Precache() {
}

int CFogLayer::AddToFullPack(struct entity_state_s* state, CBasePlayer* player) {
state->origin = player->GetViewPosition();
if (pev->movetype != MOVETYPE_FOLLOW)
state->origin = player->GetViewPosition();
return 1;
}

Expand Down Expand Up @@ -928,6 +929,9 @@ void CEnvWeather::UpdateFog() {
fog->pev->renderamt = renderamtAdd;
renderamtAdd *= scalingFactorAdd;

fog->pev->aiment = g_fog_ents[k+1].GetEdict();
fog->pev->movetype = MOVETYPE_FOLLOW;

// use same distance as upcoming black layer
layerOffset = k + 1;
}
Expand Down Expand Up @@ -1160,13 +1164,31 @@ void CEnvWeather::PlayWeatherSounds(CBasePlayer* plr) {
void CEnvWeather::WeatherThink(void)
{
if (g_fog_enabled && m_useFog) {
uint32_t softwarePlayers = 0;

for (int i = 1; i <= gpGlobals->maxClients; i++) {
CBasePlayer* plr = (CBasePlayer*)UTIL_PlayerByIndex(i);
if (!plr) {
continue;
}

if (plr->GetClientInfo().renderer == CLIENT_RENDERER_SOFTWARE) {
softwarePlayers |= PLRBIT(i);
}
}

CFogLayer* fog0 = (CFogLayer*)g_fog_ents[0].GetEntity();

for (int k = 0; k < FOG_LAYERS; k++) {
CFogLayer* fog = (CFogLayer*)g_fog_ents[k].GetEntity();
if (fog) {
// smoothes movement somehow.
// TODO: HOW? velocity is not sent to the client and the origin will be overridden
// later with m_fakeFollow.
fog->pev->velocity = Vector(0, 0, 1) * sinf(gpGlobals->time);

// overdraw is the software mode killer. Don't even try to render fog.
fog->m_hidePlayers |= softwarePlayers;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions dlls/hooks/PluginHooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ struct HLCOOP_PLUGIN_HOOKS {

// called before the mod processes a newly uploaded customization (tempdecal.wad spray)
HOOK_RETURN_DATA (*pfnPlayerCustomization)(edict_t* pEntity, customization_t* pCust);

// called when a client responds to a cvar query
HOOK_RETURN_DATA (*pfnCvarValue2)(const edict_t* pEntity, int requestID, const char* pszCvarName, const char* pszValue);
};

// do not call directly, use RegisterPlugin instead
Expand Down
3 changes: 3 additions & 0 deletions dlls/hooks/hlds_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ void ClientDisconnect( edict_t *pEntity )
ent->m_pvsPlayers &= ~plrbit;
ent->m_pasPlayers &= ~plrbit;
ent->m_netPlayers &= ~plrbit;
ent->m_hidePlayers &= ~plrbit;
}
}

Expand Down Expand Up @@ -337,6 +338,8 @@ void ClientKill( edict_t *pEntity )


void CvarValue2(const edict_t* pEnt, int requestID, const char* pszCvarName, const char* pszValue) {
CALL_HOOKS_VOID(pfnCvarValue2, pEnt, requestID, pszCvarName, pszValue);

CBasePlayer* plr = UTIL_PlayerByIndex(ENTINDEX(pEnt));

if (!plr || strstr(pszValue, "Bad Player")) {
Expand Down
15 changes: 14 additions & 1 deletion dlls/player/CBasePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5754,6 +5754,12 @@ void CBasePlayer::HandleClientCvarResponse(int requestID, const char* pszCvarNam
bool hasCvar = strstr(pszValue, "Bad CVAR request") == 0;
m_clientEngineVersion = hasCvar ? CLIENT_ENGINE_HL_LATEST : CLIENT_ENGINE_HL_LEGACY;

g_engfuncs.pfnQueryClientCvarValue2(edict(), "gl_fog", 2);
}
else if (requestID == 2) {
bool hasCvar = strstr(pszValue, "Bad CVAR request") == 0;
m_clientRenderer = hasCvar ? CLIENT_RENDERER_OPENGL : CLIENT_RENDERER_SOFTWARE;

UTIL_LogPlayerEvent(edict(), "Client version: %s\n", GetClientVersionString());
}
}
Expand All @@ -5763,6 +5769,7 @@ client_info_t CBasePlayer::GetClientInfo() {

info.engine_version = m_clientEngineVersion;
info.mod_version = m_clientModVersion;
info.renderer = m_clientRenderer;

switch (m_clientEngineVersion) {
case CLIENT_ENGINE_HL_LATEST:
Expand Down Expand Up @@ -5798,11 +5805,17 @@ void CBasePlayer::SendLegacyClientWarning() {

const char* CBasePlayer::GetClientVersionString() {
const char* engineVersion = "";
const char* renderer = "";

if (m_clientEngineVersion == CLIENT_ENGINE_HL_LEGACY)
engineVersion = " (steam_legacy)";

return UTIL_VarArgs("%s%s", STRING(m_clientModVersionString), engineVersion);
if (m_clientRenderer == CLIENT_RENDERER_OPENGL)
renderer = " (OpenGL)";
else if (m_clientRenderer == CLIENT_RENDERER_SOFTWARE)
renderer = " (Software)";

return UTIL_VarArgs("%s%s%s", STRING(m_clientModVersionString), engineVersion, renderer);
}

const char* CBasePlayer::GetSteamID() {
Expand Down
10 changes: 9 additions & 1 deletion dlls/player/CBasePlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,16 @@ enum HL_CLIENT_MOD_VERSION {
CLIENT_MOD_BOT, // bot's don't use mods
};

enum HL_CLIENT_RENDERER {
CLIENT_RENDERER_NOT_CHECKED, // player hasn't responded to cvar queries yet
CLIENT_RENDERER_OPENGL,
CLIENT_RENDERER_SOFTWARE
};

struct client_info_t {
int engine_version;
int mod_version;
int renderer;
int max_edicts;
int max_packet_entities;
};
Expand Down Expand Up @@ -437,9 +444,10 @@ class EXPORT CBasePlayer : public CBaseMonster
float m_extraRespawnDelay; // set to non-zero to increase respawn delay (sums with map default)

float m_initSoundTime;

HL_CLIENT_ENGINE_VERSION m_clientEngineVersion; // which game engine is the is this player using?
HL_CLIENT_MOD_VERSION m_clientModVersion; // which mod is this player using?
HL_CLIENT_RENDERER m_clientRenderer;
string_t m_clientModVersionString; // version string for the client mod
bool m_sentClientWarning; // has this client been warned about their client incompatability?

Expand Down

0 comments on commit e23e2b2

Please sign in to comment.