halflife-thewastes-sdk/cl_dll/ParticleBase.h
2023-09-09 03:01:15 +03:00

159 lines
4.4 KiB
C++

/***
*
* Copyright (C) 2002 The Wastes Project, All Rights Reserved.
*
* This product contains software technology from Valve Software, LLC,
* Copyright © 1996-2001, Valve LLC, 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.
*
***/
#if !defined( __PARTICLEBASE_H_ )
#define __PARTICLEBASE_H_
#include <string.h> // memset
#include <list>
using namespace std;
//
// Data types
//
// Identical to vec3_t only it wont convert to Vector
typedef vec_t psvec3_t[3];
enum PclRenderMode_e {
PRM_Normal = kRenderNormal,
PRM_TransColor = kRenderTransColor,
PRM_TransTexture = kRenderTransTexture,
PRM_TransGlow = kRenderGlow,
PRM_TransAlpha = kRenderTransAlpha,
PRM_TransAdd = kRenderTransAdd,
};
enum PclCoordSystem_e {
PCS_Standard, // Particles spawn based off emitter location then use world coordinates
PCS_Relative, // Particles spawn based off emitter location, and stays relative to emitter location
};
// singly-linked particle
struct CParticle
{
CParticle() :
m_flLifetime( 0 ), m_iModelIndex( 0 ), m_pNext( 0 )
{
memset( m_Origin, 0, sizeof( m_Origin ) );
memset( m_Velocity, 0, sizeof( m_Velocity ) );
}
void AddParticle( CParticle *pPcl )
{
if( m_pNext )
m_pNext->AddParticle( pPcl );
else
{
m_pNext = pPcl;
}
}
psvec3_t m_Origin;
psvec3_t m_Velocity;
float m_flLifetime;
float m_flScale;
float m_flGrowScale;
int m_iModelIndex;
CParticle *m_pNext;
};
//
// CSpriteEmitter
//
class CSpriteEmitter
{
public:
CSpriteEmitter();
CSpriteEmitter( const CSpriteEmitter &Cpy );
~CSpriteEmitter();
bool IsTransparent(){ return ( m_iRenderMode != PRM_Normal ) ? true : false; }
void Render();
void Update( double flFrametime );
char m_szName[64]; // Emitter name
int m_iNumSprites; // How many sprites does this emitter use?
int m_iSpriteHandles[10]; // Handles to sprites to utilize
psvec3_t m_Origin; // Location of this emitter
psvec3_t m_Acceleration; // Acceleration to apply to each particle
psvec3_t m_StartOriginOffset; // Offset to apply to each newly created particle
psvec3_t m_StartOriginRange[2]; // Location min/max range to apply to each particle randomly
psvec3_t m_StartVelocity[2]; // Starting velocity range for each particle
psvec3_t m_MinVelocity; // Min particle velocity
psvec3_t m_MaxVelocity; // Max particle velocity
int m_iMaxParticles; // Maximum number of particles.
float m_flParticlesPerSecond; // Particles to generate each second
float m_flParticleLifetime[2]; // Particle lifetime range
float m_flStartScaleRange[2]; // Particle starting scale range
float m_flGrowScaleRange[2]; // Particle grow rate, rate per sec
int m_iRenderMode; // Rendering mode of the particles
int m_iCoordSystem; // Coordinate system for particles
float m_flInactiveTime; // If the particle emitter can't be seen for this time, it wont be rendered.
private:
void AddParticle();
void ClearList( CParticle *pList );
CParticle *m_pParticles;
float m_flLastParticleTime;
float m_flNextPpsChange;
int m_iNumParticles;
float m_flInactiveStart;
};
class CParticleSystem
{
public:
CParticleSystem();
CParticleSystem( const CParticleSystem &Cpy );
~CParticleSystem();
void Render( int Transparent );
void Update( double flFrametime );
char m_szName[64]; // Particle system name
psvec3_t m_Origin; // Particle system origin
list<CSpriteEmitter> m_Emitters;
};
// Stores definitions of all particle systems read from disk
// Also maintains currently active particle systems
class CParticleSystemManager
{
public:
CParticleSystemManager();
~CParticleSystemManager();
void RenderNormal();
void RenderTransparent();
void Update( double flFrametime );
void AddParticleSystem( char *pszName, psvec3_t Origin );
const CParticleSystem *GetParticleSystem( char *pszName );
const CSpriteEmitter *GetEmitter( char *pszName );
void CheckMap();
private:
list<CParticleSystem> m_ActiveSystems; // Currently active particle systems
list<CSpriteEmitter> m_ReferenceEmitters; // Emitters loaded from disk
list<CParticleSystem> m_ReferenceSystems; // Particle Systems loaded from disk
char m_szCurrentLevel[1024];
};
extern CParticleSystemManager g_ParticleSystemManager;
#endif