Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Particleman #444

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ option(USE_VGUI "Enable VGUI1." OFF)
option(USE_NOVGUI_MOTD "Prefer non-VGUI MOTD when USE_VGUI is enabled" OFF)
option(USE_NOVGUI_SCOREBOARD "Prefer non-VGUI Scoreboard when USE_VGUI is enabled" OFF)
option(USE_VOICEMGR "Enable VOICE MANAGER." OFF)
option(USE_PARTICLEMAN "Enable ParticleMan." OFF)
option(BUILD_CLIENT "Build client dll" ON)
option(BUILD_SERVER "Build server dll" ON)
option(LTO "Enable interprocedural optimization" OFF)
Expand Down
8 changes: 8 additions & 0 deletions cl_dll/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ if (USE_VGUI)
endif()
endif()

if (USE_PARTICLEMAN)
add_definitions(-DUSE_PARTICLEMAN)
endif()

set (CLDLL_SOURCES
../dlls/crossbow.cpp
../dlls/crowbar.cpp
Expand Down Expand Up @@ -160,6 +164,10 @@ else()
scoreboard.cpp)
endif()

if (USE_PARTICLEMAN)
list(APPEND CLDLL_SOURCES ../public/interface.cpp)
endif()

include_directories (. hl/ ../dlls ../dlls/wpn_shared ../common ../engine ../pm_shared ../game_shared ../public)

if (USE_VGUI)
Expand Down
111 changes: 111 additions & 0 deletions cl_dll/cdll_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@
#include "vgui_TeamFortressViewport.h"
#endif

#if USE_PARTICLEMAN
#include "interface.h"
#include "particleman.h"
#include "com_model.h"

CSysModule *g_hParticleManModule = NULL;
IParticleMan *g_pParticleMan = NULL;

void CL_LoadParticleMan( void );
void CL_UnloadParticleMan( void );
#endif

#if GOLDSOURCE_SUPPORT && (XASH_WIN32 || XASH_LINUX || XASH_APPLE) && XASH_X86
#define USE_FAKE_VGUI !USE_VGUI
#if USE_FAKE_VGUI
Expand Down Expand Up @@ -171,6 +183,10 @@ int DLLEXPORT Initialize( cl_enginefunc_t *pEnginefuncs, int iVersion )

EV_HookEvents();

#if USE_PARTICLEMAN
CL_LoadParticleMan();
#endif

return 1;
}

Expand Down Expand Up @@ -269,6 +285,14 @@ int DLLEXPORT HUD_VidInit( void )
#elif USE_VGUI
VGui_Startup();
#endif

#if USE_PARTICLEMAN
if (g_pParticleMan)
{
g_pParticleMan->ResetParticles();
}
#endif

return 1;
}

Expand Down Expand Up @@ -388,6 +412,93 @@ void DLLEXPORT HUD_DirectorMessage( int iSize, void *pbuf )
gHUD.m_Spectator.DirectorMessage( iSize, pbuf );
}

#if USE_PARTICLEMAN
void TestParticlesCmd()
{
static model_t* texture = 0;

if ( g_pParticleMan )
{
const float clTime = gEngfuncs.GetClientTime();

if (texture == 0)
{
texture = (model_t*)gEngfuncs.GetSpritePointer(SPR_Load("sprites/steam1.spr"));
}

if (!texture)
return;

cl_entity_t* player = gEngfuncs.GetLocalPlayer();
Vector origin = player->origin;
Vector forward;
AngleVectors(player->angles, forward, NULL, NULL);

for (int i = 0; i < 10; ++i)
{
Vector shift = forward * 64.0f + forward * 8.0f * i + Vector( 0.0f, 0.0f, i * 8.0f );

CBaseParticle *particle = g_pParticleMan->CreateParticle(origin + shift, Vector(0.0f, 0.0f, 0.0f), texture, 32.0f, 255.0f, "particle");

particle->SetLightFlag(LIGHT_NONE);
particle->SetCullFlag(CULL_PVS);
particle->SetRenderFlag(RENDER_FACEPLAYER);
particle->SetCollisionFlags(TRI_COLLIDEWORLD);
particle->m_iRendermode = kRenderTransAlpha;
particle->m_vColor = Vector(255, 255, 255);
particle->m_iFramerate = 10;
particle->m_iNumFrames = texture->numframes;
particle->m_flGravity = 0.01f;
particle->m_vVelocity = shift.Normalize() * 2;

particle->m_flDieTime = clTime + 5 + i;
}
}
}

void CL_UnloadParticleMan( void )
{
Sys_UnloadModule( g_hParticleManModule );

g_pParticleMan = NULL;
g_hParticleManModule = NULL;
}

void CL_LoadParticleMan( void )
{
char szPDir[512];

if ( gEngfuncs.COM_ExpandFilename( PARTICLEMAN_DLLNAME, szPDir, sizeof( szPDir ) ) == FALSE )
{
g_pParticleMan = NULL;
g_hParticleManModule = NULL;
return;
}

g_hParticleManModule = Sys_LoadModule( szPDir );
CreateInterfaceFn particleManFactory = Sys_GetFactory( g_hParticleManModule );

if ( particleManFactory == NULL )
{
g_pParticleMan = NULL;
g_hParticleManModule = NULL;
return;
}

g_pParticleMan = (IParticleMan *)particleManFactory( PARTICLEMAN_INTERFACE, NULL);

if ( g_pParticleMan )
{
g_pParticleMan->SetUp( &gEngfuncs );

// Add custom particle classes here BEFORE calling anything else or you will die.
g_pParticleMan->AddCustomParticleClassSize ( sizeof ( CBaseParticle ) );

gEngfuncs.pfnAddCommand("test_particles", &TestParticlesCmd);
}
}
#endif

void DLLEXPORT HUD_MobilityInterface( mobile_engfuncs_t *gpMobileEngfuncs )
{
if( gpMobileEngfuncs->version != MOBILITY_API_VERSION )
Expand Down
13 changes: 13 additions & 0 deletions cl_dll/entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include "pmtrace.h"
#include "pm_shared.h"

#if USE_PARTICLEMAN
#include "particleman.h"
#endif

void Game_AddObjects( void );

extern vec3_t v_origin;
Expand Down Expand Up @@ -591,6 +595,15 @@ void DLLEXPORT HUD_TempEntUpdate (
TEMPENTITY *pTemp, *pnext, *pprev;
float /*freq,*/ gravity, gravitySlow, life, fastFreq;

#if USE_PARTICLEMAN
Vector vAngles;

gEngfuncs.GetViewAngles( (float*)vAngles );

if ( g_pParticleMan )
g_pParticleMan->SetVariables( cl_gravity, vAngles );
#endif

// Nothing to simulate
if( !*ppTempEntActive )
return;
Expand Down
4 changes: 4 additions & 0 deletions cl_dll/hud_msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include "parsemsg.h"
#include "r_efx.h"

#if USE_PARTICLEMAN
#include "particleman.h"
#endif

#define MAX_CLIENTS 32

extern BEAM *pBeam;
Expand Down
9 changes: 9 additions & 0 deletions cl_dll/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,16 @@ void ShutdownInput( void )
KB_Shutdown();
}

#if USE_PARTICLEMAN
#include "interface.h"
void CL_UnloadParticleMan();
#endif

void DLLEXPORT HUD_Shutdown( void )
{
ShutdownInput();

#if USE_PARTICLEMAN
CL_UnloadParticleMan();
#endif
}
10 changes: 10 additions & 0 deletions cl_dll/tri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ extern "C"
void DLLEXPORT HUD_DrawTransparentTriangles( void );
}

#if USE_PARTICLEMAN
#include "com_model.h"
#include "particleman.h"
#endif

//#define TEST_IT 1
#if TEST_IT

Expand Down Expand Up @@ -113,4 +118,9 @@ void DLLEXPORT HUD_DrawTransparentTriangles( void )
#if TEST_IT
// Draw_Triangles();
#endif

#if USE_PARTICLEMAN
if ( g_pParticleMan )
g_pParticleMan->Update();
#endif
}
Loading
Loading