Skip to content

Commit

Permalink
rd_map_texture entity, so we can finally say WHA-? No! QADIM!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
BenLubar committed Nov 10, 2023
1 parent c1caef1 commit b028fe7
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 23 deletions.
7 changes: 7 additions & 0 deletions reactivedrop/fgd/reactivedrop.fgd
Original file line number Diff line number Diff line change
Expand Up @@ -876,3 +876,10 @@ asw_pickup_50calmg : "50cal Machine Gun"
maxs(vector) : "BBox Maxes" : "32 32 32" : "Maximum offset from the entity, defining the shape."
radius(float) : "Cubemap Radius" : "32" : "Bounding radius to find env_cubemap entities to modify."
]

@PointClass base(Targetname, Parentname, EnableDisable, Angles) iconsprite("editor/asw_objective_dummy.vmt") obb(mins, maxs) = rd_map_texture : "Overlays a texture on top of the minimap. Can be used for moving or toggleable terrain."
[
material(material) : "Material" : "" : "Texture to draw over the minimap."
mins(vector) : "Top Left Corner" : "-128 -128 0" : "Top left corner of the texture, in world coordinates relative to this entity."
maxs(vector) : "Bottom Right Corner" : "128 128 0" : "Bottom right corner of the texture, in world coordinates relative to this entity."
]
67 changes: 44 additions & 23 deletions src/game/client/swarm/vgui/asw_hud_minimap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ using namespace vgui;
#include "c_asw_parasite.h"
#include "asw_weapon_revive_tool_shared.h"
#include "asw_util_shared.h"
#include "rd_map_texture_shared.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
Expand Down Expand Up @@ -840,6 +841,8 @@ void CASWHudMinimap::GetScaledOffset( int &ox, int &oy )

void CASWHudMinimap::PaintMapSection()
{
ISurface *pSurface = surface();

int wide, tall;
GetSize( wide, tall );
wide *= asw_hud_scale.GetFloat();
Expand All @@ -856,6 +859,8 @@ void CASWHudMinimap::PaintMapSection()
m_pLinePanel->SetBounds( m_MapCornerInPanel.x, m_MapCornerInPanel.y,
m_MapCornerInPanel.x + m_iMapSize, m_MapCornerInPanel.y + m_iMapSize );

int alpha = clamp<int>( rd_draw_minimap.GetFloat() * 255.0f, 0, 255 );

C_ASW_Player *local = C_ASW_Player::GetLocalASWPlayer();
if ( local )
{
Expand Down Expand Up @@ -890,9 +895,34 @@ void CASWHudMinimap::PaintMapSection()

ClipToSquare( nPoints, points, m_MapCornerInPanel, m_iMapSize );

surface()->DrawSetColor( 255, 255, 255, clamp<int>( rd_draw_minimap.GetFloat() * 255.0f, 0, 255 ) );
surface()->DrawSetTexture( m_nMapTextureID[iMapTextureIndex] );
surface()->DrawTexturedPolygon( nPoints, points );
pSurface->DrawSetColor( 255, 255, 255, alpha );
pSurface->DrawSetTexture( m_nMapTextureID[iMapTextureIndex] );
pSurface->DrawTexturedPolygon( nPoints, points );

FOR_EACH_VEC( IRDMapTextures::AutoList(), i )
{
C_RD_Map_Texture *pTexture = assert_cast< C_RD_Map_Texture * >( IRDMapTextures::AutoList()[i]->GetEntity() );
Assert( pTexture );
if ( !pTexture || pTexture->m_bDisabled )
continue;

if ( !pTexture->m_hVGuiTexture )
{
pTexture->m_hVGuiTexture = pSurface->CreateNewTextureID();
pSurface->DrawSetTextureFile( pTexture->m_hVGuiTexture, pTexture->m_szMaterialName, 1, false );
}

nPoints = 4;
points[0].Init( MapTextureToPanel( WorldToMapTexture( pTexture->GetTopLeftCorner() ) ), Vector2D( 0, 0 ) );
points[1].Init( MapTextureToPanel( WorldToMapTexture( pTexture->GetTopRightCorner() ) ), Vector2D( 1, 0 ) );
points[2].Init( MapTextureToPanel( WorldToMapTexture( pTexture->GetBottomRightCorner() ) ), Vector2D( 1, 1 ) );
points[3].Init( MapTextureToPanel( WorldToMapTexture( pTexture->GetBottomLeftCorner() ) ), Vector2D( 0, 1 ) );

ClipToSquare( nPoints, points, m_MapCornerInPanel, m_iMapSize );

pSurface->DrawSetTexture( pTexture->m_hVGuiTexture );
pSurface->DrawTexturedPolygon( nPoints, points );
}
}
else
{
Expand All @@ -912,9 +942,9 @@ void CASWHudMinimap::PaintMapSection()
{ Vector2D( map_left, map_bottom ), Vector2D( 0, 1 ) },
};

surface()->DrawSetColor( 255, 255, 255, 255 );
surface()->DrawSetTexture( m_nMapTextureID[iMapTextureIndex] );
surface()->DrawTexturedPolygon( 4, points );
pSurface->DrawSetColor( 255, 255, 255, alpha );
pSurface->DrawSetTexture( m_nMapTextureID[iMapTextureIndex] );
pSurface->DrawTexturedPolygon( 4, points );
}
}
}
Expand Down Expand Up @@ -1296,7 +1326,7 @@ void CASWHudMinimapLinePanel::PaintScannerRing()

C_BaseEntity::EmitSound( filter, -1 /*SOUND_FROM_LOCAL_PLAYER*/, ep );
// if the tech is ours, then check for saying something about the incoming aliens
if ( pPlayer->entindex() == pMR->GetCommanderIndex() && m_pMap && pScanner->m_BlipType[k] == 0 ) // only do the speech when it's an alien, not a door
if ( pPlayer->entindex() == pMR->GetCommanderIndex() && pScanner->m_BlipType[k] == 0 ) // only do the speech when it's an alien, not a door
{
//Msg("client checking blip speech %d\n", i);
m_pMap->CheckBlipSpeech( i );
Expand Down Expand Up @@ -1324,12 +1354,12 @@ void CASWHudMinimapLinePanel::PaintScannerRing()
float ring_center_x = 0;
float ring_center_y = 0;
TextureToLinePanel( m_pMap, marine_pos, ring_center_x, ring_center_y );
Vertex_t points[4] =
Vertex_t points[4]
{
Vertex_t( Vector2D( ring_center_x - scanner_range, ring_center_y - scanner_range ), Vector2D( 0,0 ) ),
Vertex_t( Vector2D( ring_center_x + scanner_range, ring_center_y - scanner_range ), Vector2D( 1,0 ) ),
Vertex_t( Vector2D( ring_center_x + scanner_range, ring_center_y + scanner_range ), Vector2D( 1,1 ) ),
Vertex_t( Vector2D( ring_center_x - scanner_range, ring_center_y + scanner_range ), Vector2D( 0,1 ) )
{ { ring_center_x - scanner_range, ring_center_y - scanner_range }, { 0, 0 } },
{ { ring_center_x + scanner_range, ring_center_y - scanner_range }, { 1, 0 } },
{ { ring_center_x + scanner_range, ring_center_y + scanner_range }, { 1, 1 } },
{ { ring_center_x - scanner_range, ring_center_y + scanner_range }, { 0, 1 } },
};
surface()->DrawTexturedPolygon( 4, points );
}
Expand Down Expand Up @@ -2214,21 +2244,12 @@ void CASWHudMinimap_Border::PaintBackground()
return;

if ( !asw_draw_hud.GetBool() || rd_draw_minimap.GetFloat() <= 0 || m_nBlackBarTexture == -1 )
{
return;
}

if ( !asw_scanner_background.GetBool() )
return;
//BaseClass::PaintBackground();

vgui::surface()->DrawSetColor( Color( 255, 255, 255, asw_hud_alpha.GetInt() ) );
vgui::surface()->DrawSetTexture( m_nBlackBarTexture );
vgui::Vertex_t points[4] =
{
vgui::Vertex_t( Vector2D( 0, 0 ), Vector2D( 0,0 ) ),
vgui::Vertex_t( Vector2D( GetWide(), 0 ), Vector2D( 1,0 ) ),
vgui::Vertex_t( Vector2D( GetWide(), GetTall() ), Vector2D( 1,1 ) ),
vgui::Vertex_t( Vector2D( 0, GetTall() ), Vector2D( 0,1 ) )
};
vgui::surface()->DrawTexturedPolygon( 4, points );
vgui::surface()->DrawTexturedRect( 0, 0, GetWide(), GetTall() );
}
2 changes: 2 additions & 0 deletions src/game/client/swarm_sdk_client.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ if exist ..\..\devtools\bin\postbuild.cmd ..\..\devtools\bin\postbuild.cmd clien
<ClInclude Include="..\..\public\steam\steam_api_common.h" />
<ClInclude Include="..\..\public\steam\steam_api_internal.h" />
<ClInclude Include="..\shared\swarm\rd_crafting_defs.h" />
<ClInclude Include="..\shared\swarm\rd_map_texture_shared.h" />
<ClInclude Include="swarm\rd_font_zbalermorna.h" />
<ClInclude Include="swarm\vgui\asw_scalable_text.inc">
<FileType>Document</FileType>
Expand Down Expand Up @@ -878,6 +879,7 @@ if exist ..\..\devtools\bin\postbuild.cmd ..\..\devtools\bin\postbuild.cmd clien
<ClCompile Include="..\shared\swarm\rd_inventory_shared.cpp" />
<ClCompile Include="..\shared\swarm\rd_loadout.cpp" />
<ClCompile Include="..\shared\swarm\rd_lobby_utils.cpp" />
<ClCompile Include="..\shared\swarm\rd_map_texture_shared.cpp" />
<ClCompile Include="..\shared\swarm\rd_missions_shared.cpp" />
<ClCompile Include="..\shared\swarm\rd_weapon_generic_object_shared.cpp" />
<ClCompile Include="..\shared\swarm\rd_workshop.cpp" />
Expand Down
2 changes: 2 additions & 0 deletions src/game/server/swarm_sdk_server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ if exist ..\..\devtools\bin\postbuild.cmd ..\..\devtools\bin\postbuild.cmd serve
<ClCompile Include="..\shared\swarm\rd_inventory_shared.cpp" />
<ClCompile Include="..\shared\swarm\rd_loadout.cpp" />
<ClCompile Include="..\shared\swarm\rd_lobby_utils.cpp" />
<ClCompile Include="..\shared\swarm\rd_map_texture_shared.cpp" />
<ClCompile Include="..\shared\swarm\rd_missions_shared.cpp" />
<ClCompile Include="..\shared\swarm\rd_weapon_generic_object_shared.cpp" />
<ClCompile Include="..\shared\swarm\rd_workshop.cpp" />
Expand Down Expand Up @@ -1832,6 +1833,7 @@ if exist ..\..\devtools\bin\postbuild.cmd ..\..\devtools\bin\postbuild.cmd serve
<ClInclude Include="..\shared\swarm\rd_inventory_shared.h" />
<ClInclude Include="..\shared\swarm\rd_loadout.h" />
<ClInclude Include="..\shared\swarm\rd_lobby_utils.h" />
<ClInclude Include="..\shared\swarm\rd_map_texture_shared.h" />
<ClInclude Include="..\shared\swarm\rd_missions_shared.h" />
<ClInclude Include="..\shared\swarm\rd_release_flags.h" />
<ClInclude Include="..\shared\swarm\rd_weapon_generic_object_shared.h" />
Expand Down
141 changes: 141 additions & 0 deletions src/game/shared/swarm/rd_map_texture_shared.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#include "cbase.h"
#include "rd_map_texture_shared.h"
#ifdef CLIENT_DLL
#include <vgui_controls/Controls.h>
#include <vgui/ISurface.h>
#endif

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"


#ifdef CLIENT_DLL
IMPLEMENT_AUTO_LIST( IRDMapTexture );
#else
LINK_ENTITY_TO_CLASS( rd_map_texture, CRD_Map_Texture );

BEGIN_DATADESC( CRD_Map_Texture )
DEFINE_KEYFIELD( m_szMaterialName, FIELD_STRING, "material" ),
DEFINE_KEYFIELD( m_MapMins, FIELD_VECTOR, "mins" ),
DEFINE_KEYFIELD( m_MapMaxs, FIELD_VECTOR, "maxs" ),
DEFINE_KEYFIELD( m_bDisabled, FIELD_BOOLEAN, "StartDisabled" ),
DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
DEFINE_INPUTFUNC( FIELD_VOID, "Toggle", InputToggle ),
END_DATADESC();

extern void SendProxy_String_tToString( const SendProp *pProp, const void *pStruct, const void *pData, DVariant *pOut, int iElement, int objectID );
#endif

IMPLEMENT_NETWORKCLASS_ALIASED( RD_Map_Texture, DT_RD_Map_Texture );

BEGIN_NETWORK_TABLE( CRD_Map_Texture, DT_RD_Map_Texture )
#ifdef CLIENT_DLL
RecvPropString( RECVINFO( m_szMaterialName ) ),
RecvPropVectorXY( RECVINFO( m_MapMins ) ),
RecvPropVectorXY( RECVINFO( m_MapMaxs ) ),
RecvPropBool( RECVINFO( m_bDisabled ) ),
#else
SendPropString( SENDINFO( m_szMaterialName ), 0, SendProxy_String_tToString ),
SendPropVectorXY( SENDINFO( m_MapMins ) ),
SendPropVectorXY( SENDINFO( m_MapMaxs ) ),
SendPropBool( SENDINFO( m_bDisabled ) ),
#endif
END_NETWORK_TABLE();

CRD_Map_Texture::CRD_Map_Texture()
{
#ifdef CLIENT_DLL
m_szMaterialName.GetForModify()[0] = '\0';

m_hVGuiTexture = NULL;
#else
m_szMaterialName.Set( NULL_STRING );
#endif

m_MapMins.Init();
m_MapMaxs.Init();
m_bDisabled = false;
}

CRD_Map_Texture::~CRD_Map_Texture()
{
#ifdef CLIENT_DLL
if ( m_hVGuiTexture && vgui::surface() )
{
vgui::surface()->DestroyTextureID( m_hVGuiTexture );
m_hVGuiTexture = NULL;
}
#endif
}

void CRD_Map_Texture::Precache()
{
BaseClass::Precache();

if ( const char *szMaterialName = STRING( m_szMaterialName.Get() ) )
{
PrecacheMaterial( szMaterialName );
}
}

Vector CRD_Map_Texture::GetTopLeftCorner() const
{
Vector pos;
EntityToWorldSpace( Vector{ m_MapMins.GetX(), m_MapMins.GetY(), 0.0f }, &pos );
return pos;
}
Vector CRD_Map_Texture::GetTopRightCorner() const
{
Vector pos;
EntityToWorldSpace( Vector{ m_MapMaxs.GetX(), m_MapMins.GetY(), 0.0f }, &pos );
return pos;
}
Vector CRD_Map_Texture::GetBottomLeftCorner() const
{
Vector pos;
EntityToWorldSpace( Vector{ m_MapMins.GetX(), m_MapMaxs.GetY(), 0.0f }, &pos );
return pos;
}
Vector CRD_Map_Texture::GetBottomRightCorner() const
{
Vector pos;
EntityToWorldSpace( Vector{ m_MapMaxs.GetX(), m_MapMaxs.GetY(), 0.0f }, &pos );
return pos;
}

#ifndef CLIENT_DLL
void CRD_Map_Texture::Spawn()
{
Precache();

if ( m_szMaterialName.Get() == NULL_STRING )
{
Warning( "rd_map_texture entity (%d:%s) @ %f %f %f has no material assigned. Deleting.\n", GetHammerID(), GetDebugName(), VectorExpand( GetAbsOrigin() ) );
UTIL_Remove( this );
return;
}

BaseClass::Spawn();
}

int CRD_Map_Texture::UpdateTransmitState()
{
return SetTransmitState( FL_EDICT_ALWAYS );
}

void CRD_Map_Texture::InputEnable( inputdata_t &inputdata )
{
m_bDisabled = false;
}

void CRD_Map_Texture::InputDisable( inputdata_t &inputdata )
{
m_bDisabled = true;
}

void CRD_Map_Texture::InputToggle( inputdata_t &inputdata )
{
m_bDisabled = !m_bDisabled;
}
#endif
49 changes: 49 additions & 0 deletions src/game/shared/swarm/rd_map_texture_shared.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once

#ifdef CLIENT_DLL
#define CRD_Map_Texture C_RD_Map_Texture

DECLARE_AUTO_LIST( IRDMapTextures );
#endif

class CRD_Map_Texture : public CBaseEntity
#ifdef CLIENT_DLL
, public IRDMapTextures
#endif
{
DECLARE_CLASS( CRD_Map_Texture, CBaseEntity );
public:
DECLARE_NETWORKCLASS();

CRD_Map_Texture();
virtual ~CRD_Map_Texture();

void Precache() override;

Vector GetTopLeftCorner() const;
Vector GetTopRightCorner() const;
Vector GetBottomLeftCorner() const;
Vector GetBottomRightCorner() const;

#ifndef CLIENT_DLL
DECLARE_DATADESC();

void Spawn() override;
int UpdateTransmitState() override;

CNetworkVar( string_t, m_szMaterialName );

void InputEnable( inputdata_t &inputdata );
void InputDisable( inputdata_t &inputdata );
void InputToggle( inputdata_t &inputdata );
#else
IMPLEMENT_AUTO_LIST_GET();

CNetworkString( m_szMaterialName, 255 );
vgui::HTexture m_hVGuiTexture;
#endif

CNetworkVector( m_MapMins );
CNetworkVector( m_MapMaxs );
CNetworkVar( bool, m_bDisabled );
};

0 comments on commit b028fe7

Please sign in to comment.