Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 169 additions & 0 deletions src/common/mapbase_con_groups.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 =================
//
// Purpose: Mapbase classifies certain types of console messages into groups with specific colors.
// This is inspired by similar groups seen in CS:GO and Source 2 games.
//
// See game_con_groups.cpp for the default client/server implementation.
//
// $NoKeywords: $
//=============================================================================

#if defined(CLIENT_DLL) || defined(GAME_DLL)
#include "cbase.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "basetypes.h"
#include "mapbase_con_groups.h"
#include "KeyValues.h"
#include "filesystem.h"
#include "mapbase_matchers_base.h"

bool ConGroup_t::g_bIncludeConGroupNames = false;

static CUtlVector<ConGroup_t *> g_ConGroups;

//-----------------------------------------------------------------------------

ConGroup_t::ConGroup_t( CUtlVector<ConGroup_t *> &list, const char *_pszName )
{
pszName = _pszName;
clr.SetColor( 224, 224, 224, 255 ); // Default to a shade of gray

list.AddToTail( this );
}

ConGroup_t::~ConGroup_t()
{
// Assume we've already been added to the main list
g_ConGroups.FindAndRemove( this );
}

//-----------------------------------------------------------------------------

// Base console groups
ConGroup_t ConGroup_MapbaseMisc ( g_ConGroups, "Mapbase misc." );
ConGroup_t ConGroup_ResponseSys ( g_ConGroups, "Response System" );
ConGroup_t ConGroup_VScript ( g_ConGroups, "VScript" );
ConGroup_t ConGroup_VScriptPrint ( g_ConGroups, "VScript print" );

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

int FindConGroup( const char *pszName )
{
for (int i = 0; i < g_ConGroups.Count(); i++)
{
if (Q_stricmp( pszName, g_ConGroups[i]->pszName ) == 0)
return i;
}

return -1;
}

//-----------------------------------------------------------------------------
// Loads console groups
//-----------------------------------------------------------------------------
void LoadConsoleGroupsFromFile( IBaseFileSystem *filesystem, const char *pszFileName, const char *pathID = NULL )
{
KeyValues *pGroupRoot = new KeyValues( "ConsoleGroups" );

pGroupRoot->LoadFromFile( filesystem, pszFileName, pathID );

KeyValues *pGroup = NULL;
for ( pGroup = pGroupRoot->GetFirstTrueSubKey(); pGroup; pGroup = pGroup->GetNextTrueSubKey() )
{
int index = FindConGroup( pGroup->GetName() );
if (index != -1)
{
Color msgClr = pGroup->GetColor( "MessageColor" );

// Make sure the color isn't 0,0,0,0 before assigning
if (msgClr.GetRawColor() != 0)
g_ConGroups[index]->clr = msgClr;

g_ConGroups[index]->bDisabled = pGroup->GetBool( "Disabled", false );
}
else
{
Warning( "Invalid console group %s (new groups should be defined in the code)\n", pGroup->GetName() );
}
}

pGroupRoot->deleteThis();
}

void InitConsoleGroups( IBaseFileSystem *filesystem, CUtlVector<ConGroup_t *> *list )
{
if ( list )
{
g_ConGroups.AddVectorToTail( *list );
list->Purge();
}

LoadConsoleGroupsFromFile( filesystem, "scripts/mapbase_con_groups.txt" );
LoadConsoleGroupsFromFile( filesystem, "scripts/mod_con_groups.txt" );
}

void PrintAllConsoleGroups()
{
Msg( "============================================================\n" );
for (int i = 0; i < g_ConGroups.Count(); i++)
{
ConColorMsg( g_ConGroups[i]->clr, " # %s", g_ConGroups[i]->pszName );

if (g_ConGroups[i]->bDisabled)
Msg(" [DISABLED]");

//Msg( " - %s ", g_ConGroups[i]->pszDesc );

Msg("\n");
}
Msg( "============================================================\n" );
}

void ToggleConsoleGroups( const char *pszQuery )
{
bool bMatched = false;

for (int i = 0; i < g_ConGroups.Count(); i++)
{
if (Matcher_NamesMatch( pszQuery, g_ConGroups[i]->pszName ))
{
Msg( "%s is now %s\n", g_ConGroups[i]->pszName, g_ConGroups[i]->bDisabled ? "enabled" : "disabled" );
g_ConGroups[i]->bDisabled = !g_ConGroups[i]->bDisabled;
bMatched = true;
}
}

if (!bMatched)
Msg( "No groups matching \"%s\"\n", pszQuery );
}

void SetConsoleGroupIncludeNames( bool bToggle )
{
ConGroup_t::g_bIncludeConGroupNames = bToggle;
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

void _CGMsgFixup( int level, const ConGroup_t &group, const tchar* pMsg, ... )
{
// Return early if we're not at this level
if (!IsSpewActive("developer", level))
return;

char string[ 2048 ];
va_list argptr;
va_start( argptr, pMsg );
Q_vsnprintf( string, sizeof(string), pMsg, argptr );
va_end( argptr );

// For now, this is the only reason we would be here
Assert( ConGroup_t::g_bIncludeConGroupNames );

ConColorMsg( level, group.clr, "[%s] %s", group.pszName, string );
}
92 changes: 92 additions & 0 deletions src/common/mapbase_con_groups.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 =================
//
// Purpose: See mapbase_con_groups.cpp for more information
//
// $NoKeywords: $
//=============================================================================

#ifndef MAPBASE_CON_GROUPS_H
#define MAPBASE_CON_GROUPS_H
#ifdef _WIN32
#pragma once
#endif

#include "Color.h"

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

struct ConGroup_t
{
ConGroup_t( CUtlVector<ConGroup_t *> &list, const char *_pszName );
~ConGroup_t();

const char *pszName;
Color clr;

bool bDisabled;

//----------------------------------------

static bool g_bIncludeConGroupNames;
};

//-----------------------------------------------------------------------------

extern ConGroup_t ConGroup_MapbaseMisc;
extern ConGroup_t ConGroup_ResponseSys;
extern ConGroup_t ConGroup_VScript;
extern ConGroup_t ConGroup_VScriptPrint;

// Preprocessors for old naming convention

#define CON_GROUP_MAPBASE_MISC ConGroup_MapbaseMisc
#define CON_GROUP_RESPONSE_SYSTEM ConGroup_ResponseSys
#define CON_GROUP_VSCRIPT ConGroup_VScript
#define CON_GROUP_VSCRIPT_PRINT ConGroup_VScriptPrint

//-----------------------------------------------------------------------------

// Fixes up the message instead of passing it directly to ConColorMsg. (do not call directly; call CGMsg instead)
void _CGMsgFixup( int level, const ConGroup_t &group, PRINTF_FORMAT_STRING const tchar *pMsg, ... ) FMTFUNCTION( 3, 4 );

// Mapbase console group message.
//
// - "level" is developer level (like in DevMsg; use 0 for Msg)
// - "group" is the console group (use a string in the "CON_GROUP" function, or use one of the defaults)
// - "pMsg" and "..." are the message contents
//
// See below this macro for more information
#define CGMsg( level, group, pMsg, ... ) \
do { \
if ( !group.bDisabled ) \
{ \
if ( ConGroup_t::g_bIncludeConGroupNames ) \
_CGMsgFixup( level, group, pMsg, ##__VA_ARGS__ ); \
else \
ConColorMsg( level, group.clr, pMsg, ##__VA_ARGS__ ); \
} \
} while(0)

// We use a macro so that we can pass the variadic arguments directly without using va_list or variadic functions.
// (since the former is slow and the latter bloats too much with this)
// The "do while" is so that we can directly plug the name into instances of Msg/DevMsg without having to change
// anything else, since it needs to have multiple lines but also end with a semicolon.
//
// The necessity of this mess is arguable, but it's filling in for direct calls to Msg/DevMsg, so I wanted to
// minimize the performance difference.
// (although calling Msg more than a few times per frame is usually a sign of a larger problem, anyway...)

#define CGWarning CGMsg

//-----------------------------------------------------------------------------

class IBaseFileSystem;

void InitConsoleGroups( IBaseFileSystem *filesystem, CUtlVector<ConGroup_t *> *list = NULL );

void PrintAllConsoleGroups();
void ToggleConsoleGroups( const char *pszQuery );
void SetConsoleGroupIncludeNames( bool bToggle );

#endif
54 changes: 0 additions & 54 deletions src/game/client/C_Env_Projected_Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#include "c_baseentity.h"
#include "basetypes.h"

#ifdef ASW_PROJECTED_TEXTURES

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -111,56 +109,4 @@ bool C_EnvProjectedTexture::IsBBoxVisible( void )
return IsBBoxVisible( GetAbsOrigin() + m_vecExtentsMin, GetAbsOrigin() + m_vecExtentsMax );
}

#else

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class C_EnvProjectedTexture : public C_BaseEntity
{
DECLARE_CLASS( C_EnvProjectedTexture, C_BaseEntity );
public:
DECLARE_CLIENTCLASS();

C_EnvProjectedTexture();
~C_EnvProjectedTexture();

virtual void OnDataChanged( DataUpdateType_t updateType );
void ShutDownLightHandle( void );

virtual void Simulate();

void UpdateLight( bool bForceUpdate );

bool ShadowsEnabled();

float GetFOV();

private:

ClientShadowHandle_t m_LightHandle;

EHANDLE m_hTargetEntity;

bool m_bState;
float m_flLightFOV;
bool m_bEnableShadows;
bool m_bLightOnlyTarget;
bool m_bLightWorld;
bool m_bCameraSpace;
color32 m_cLightColor;
float m_flAmbient;
char m_SpotlightTextureName[ MAX_PATH ];
int m_nSpotlightTextureFrame;
int m_nShadowQuality;
bool m_bCurrentShadow;

public:
C_EnvProjectedTexture *m_pNext;
};

C_EnvProjectedTexture* GetEnvProjectedTextureList();

#endif

#endif // C_ENVPROJECTEDTEXTURE_H
44 changes: 22 additions & 22 deletions src/game/client/c_env_global_light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ void C_GlobalLight::ClientThink()
state.m_fQuadraticAtten = 0.0f;
state.m_fLinearAtten = m_flSunDistance * 2.0f;
state.m_fConstantAtten = 0.0f;
state.m_FarZAtten = m_flSunDistance * 2.0f;
#ifdef MAPBASE
float flAlpha = m_flCurrentLinearFloatLightAlpha * (1.0f / 255.0f);
state.m_Color[0] = (m_CurrentLinearFloatLightColor.x * ( 1.0f / 255.0f ) * flAlpha) * m_flCurrentBrightnessScale;
Expand All @@ -269,27 +268,6 @@ void C_GlobalLight::ClientThink()
state.m_Color[3] = 0.0f; // fixme: need to make ambient work m_flAmbient;
state.m_NearZ = 4.0f;
state.m_FarZ = m_flSunDistance * 2.0f;
state.m_fBrightnessScale = 2.0f;
state.m_bGlobalLight = true;

#ifdef MAPBASE
float flOrthoSize = m_flOrthoSize;
#else
float flOrthoSize = 1000.0f;
#endif

if ( flOrthoSize > 0 )
{
state.m_bOrtho = true;
state.m_fOrthoLeft = -flOrthoSize;
state.m_fOrthoTop = -flOrthoSize;
state.m_fOrthoRight = flOrthoSize;
state.m_fOrthoBottom = flOrthoSize;
}
else
{
state.m_bOrtho = false;
}

#ifdef MAPBASE
//state.m_bDrawShadowFrustum = true; // Don't draw that huge debug thing
Expand Down Expand Up @@ -334,6 +312,28 @@ void C_GlobalLight::ClientThink()
g_pClientShadowMgr->UpdateProjectedTexture( m_LocalFlashlightHandle, true );
}

#ifdef MAPBASE
FlashlightStateExtras_t stateExtras;
stateExtras.m_FarZAtten = m_flSunDistance * 2.0f;

if ( m_flOrthoSize > 0 )
{
stateExtras.m_bOrtho = true;
stateExtras.m_fOrthoLeft = -m_flOrthoSize;
stateExtras.m_fOrthoTop = -m_flOrthoSize;
stateExtras.m_fOrthoRight = m_flOrthoSize;
stateExtras.m_fOrthoBottom = m_flOrthoSize;
}
else
{
stateExtras.m_bOrtho = false;
}

stateExtras.m_bGlobalLight = true;

g_pClientShadowMgr->SetFlashlightExtras( m_LocalFlashlightHandle, stateExtras );
#endif

bSupressWorldLights = m_bEnableShadows;
}
else if ( m_LocalFlashlightHandle != CLIENTSHADOW_INVALID_HANDLE )
Expand Down
Loading
Loading