halflife-thewastes-sdk/cl_dll/env_fog.cpp

119 lines
2.8 KiB
C++

/***
*
* Copyright (C) 2002 The Wastes Project, All Rights Reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* The Wastes Project. All other use, distribution, or modification is prohibited
* without written permission from The Wastes Project.
*
***/
//
// env_fog.cpp -> env_fog's are client side entities useful in manipulating
// the fog code in HL for more useful purposes
//
#include "hud.h"
#include "cl_util.h"
#include "ParseBspEnt.h"
#include "ParseBsp.h"
#include "tri.h"
#include <vector>
using namespace std;
#define VectorLength(a) sqrt((double) ((double)((a)[0] * (a)[0]) + (double)( (a)[1] * (a)[1]) + (double)( (a)[2] * (a)[2])) )
enum bsp_fogstate_e {
FOGSTATE_OFF = 0,
FOGSTATE_ON,
FOGSTATE_MAPDEFAULT,
};
vector<CBspEnvFog> g_EnvFogList;
CBspEnvFog *g_pActiveEnvFog = NULL;
extern cvar_t *cl_enablefog;
/*
==============================
EnvFog_RenderFog
Return 0 to use worldspawn fog
==============================
*/
int EnvFog_RenderFog(CBspEnvFog *pActive)
{
if(pActive == NULL)
return 0;
if(pActive->iFogState == FOGSTATE_MAPDEFAULT)
return 0;
R_SetFog(pActive->flFogcolor_r,
pActive->flFogcolor_g,
pActive->flFogcolor_b,
pActive->flFog_start,
pActive->flFog_end,
(cl_enablefog->value && pActive->iFogState == FOGSTATE_ON) ? 1 : 0);
return 1;
}
/*
==============================
EnvFog_SetFog
==============================
*/
int EnvFog_SetFog()
{
// Find the nearest valid env_fog
for( int i = 0;i < g_EnvFogList.size();i++ )
{
CBspEnvFog *pCurNode = &g_EnvFogList[i];
vec3_t location = pCurNode->flOrigin;
int radius = pCurNode->iRadius;
double dist = VectorLength(location - gEngfuncs.GetLocalPlayer()->origin);
// The player is inside this env_fog,
// So compare against the current active
// env_fog to fight for priority
if(radius && dist <= radius)
{
if(g_pActiveEnvFog == NULL)
{
g_pActiveEnvFog = pCurNode;
return EnvFog_RenderFog(g_pActiveEnvFog);
}
else
{
vec3_t activeloc = g_pActiveEnvFog->flOrigin;
double activedist = VectorLength(activeloc - gEngfuncs.GetLocalPlayer()->origin);
// See if this env_fog is better than the current
// active fog entity.
if(activedist <= radius)
{
if(dist < activedist)
{
g_pActiveEnvFog = pCurNode;
return EnvFog_RenderFog(g_pActiveEnvFog);
}
}
else
{
g_pActiveEnvFog = pCurNode;
return EnvFog_RenderFog(g_pActiveEnvFog);
}
}
}
}
return EnvFog_RenderFog(g_pActiveEnvFog);
}