From faeca7123be05af89abc8cb66ba27651d7d0944a Mon Sep 17 00:00:00 2001 From: Xottab-DUTY Date: Fri, 18 Aug 2017 21:36:46 +0500 Subject: [PATCH] Refactor xrParticles Reformatting and code cleanup --- src/editors/ActorEditor/stdafx.h | 34 +-- src/editors/LevelEditor/stdafx.h | 2 +- src/xrEngine/psystem.h | 208 ------------------ src/xrEngine/xrEngine.vcxproj | 1 - src/xrEngine/xrEngine.vcxproj.filters | 3 - src/xrParticles/noise.cpp | 6 +- src/xrParticles/noise.h | 1 + src/xrParticles/particle_actions.cpp | 2 - src/xrParticles/particle_actions.h | 18 +- .../particle_actions_collection.cpp | 38 ++-- src/xrParticles/particle_actions_collection.h | 4 +- .../particle_actions_collection_io.cpp | 30 ++- src/xrParticles/particle_core.cpp | 73 +++--- src/xrParticles/particle_core.h | 9 +- src/xrParticles/particle_effect.h | 60 +++-- src/xrParticles/particle_manager.cpp | 145 +++++++----- src/xrParticles/particle_manager.h | 40 ++-- src/xrParticles/psystem.h | 63 ++++-- 18 files changed, 312 insertions(+), 425 deletions(-) delete mode 100644 src/xrEngine/psystem.h diff --git a/src/editors/ActorEditor/stdafx.h b/src/editors/ActorEditor/stdafx.h index af16de0a37b..3178ed1d217 100644 --- a/src/editors/ActorEditor/stdafx.h +++ b/src/editors/ActorEditor/stdafx.h @@ -76,7 +76,7 @@ __inline float expf(float val) { return ::exp(val); } #define clMsg Msg // core -#include +#include #ifdef _EDITOR class PropValue; @@ -87,32 +87,32 @@ class ListItem; DEFINE_VECTOR(ListItem*, ListItemsVec, ListItemsIt); #endif -#include "../../xrCDB/xrCDB.h" -#include "../../xrSound/Sound.h" -#include "../../xrEngine/PSystem.h" +#include "xrCDB/xrCDB.h" +#include "xrSound/Sound.h" +#include "xrParticles/PSystem.h" // DirectX headers #include #include -#include "..\..\Layers\xrRender\xrD3dDefs.h" +#include "Layers/xrRender/xrD3dDefs.h" #include #include // some user components -#include "../../xrEngine/fmesh.h" -#include "../../xrEngine/_d3d_extensions.h" +#include "xrCore/FMesh.hpp" +#include "Common/_d3d_extensions.h" -#include "../ECore/editor/D3DX_Wrapper.h" +#include "editors/ECore/editor/D3DX_Wrapper.h" DEFINE_VECTOR(AnsiString, AStringVec, AStringIt); DEFINE_VECTOR(AnsiString*, LPAStringVec, LPAStringIt); -#include "../../xrServerEntities/xrEProps.h" -#include "../../xrCore/Log.h" -#include "../ECore/editor/engine.h" -#include "../../xrEngine/defines.h" +#include "xrServerEntities/xrEProps.h" +#include "xrCore/log.h" +#include "editors/ECore/editor/engine.h" +#include "xrEngine/defines.h" -#include "../../xrphysics/xrphysics.h" +#include "xrPhysics/xrPhysics.h" struct str_pred : public std::binary_function { @@ -137,15 +137,15 @@ struct astr_pred : public std::binary_function +#include // DirectX headers #include diff --git a/src/xrEngine/psystem.h b/src/xrEngine/psystem.h deleted file mode 100644 index a5c6b85866a..00000000000 --- a/src/xrEngine/psystem.h +++ /dev/null @@ -1,208 +0,0 @@ -#ifndef PSystemH -#define PSystemH -#pragma once - -#include "Common/Platform.hpp" - -#ifdef XR_PARTICLES_EXPORTS -#define PARTICLES_API XR_EXPORT -#else -#define PARTICLES_API XR_IMPORT -#ifdef _EDITOR -#pragma comment(lib, "x:\\xrParticlesB.lib") -#else -#pragma comment(lib, "xrParticles.lib") -#endif -#endif - -// Actually this must be < sqrt(MAXFLOAT) since we store this value squared. -#define P_MAXFLOAT 1.0e16f - -#ifdef MAXINT -#define P_MAXINT MAXINT -#else -#define P_MAXINT 0x7fffffff -#endif - -#define drand48() ::Random.randF() -//#define drand48() (((float) rand())/((float) RAND_MAX)) - -namespace PAPI -{ -class pVector : public Fvector -{ -public: - IC pVector(float ax, float ay, float az) { set(ax, ay, az); } - IC pVector() {} - IC float length() const { return _sqrt(x * x + y * y + z * z); } - IC float length2() const { return (x * x + y * y + z * z); } - IC float operator*(const pVector& a) const { return x * a.x + y * a.y + z * a.z; } - IC pVector operator*(const float s) const { return pVector(x * s, y * s, z * s); } - IC pVector operator/(const float s) const - { - float invs = 1.0f / s; - return pVector(x * invs, y * invs, z * invs); - } - IC pVector operator+(const pVector& a) const { return pVector(x + a.x, y + a.y, z + a.z); } - IC pVector operator-(const pVector& a) const { return pVector(x - a.x, y - a.y, z - a.z); } - IC pVector operator-() - { - x = -x; - y = -y; - z = -z; - return *this; - } - IC pVector& operator+=(const pVector& a) - { - x += a.x; - y += a.y; - z += a.z; - return *this; - } - IC pVector& operator-=(const pVector& a) - { - x -= a.x; - y -= a.y; - z -= a.z; - return *this; - } - IC pVector& operator*=(const float a) - { - x *= a; - y *= a; - z *= a; - return *this; - } - IC pVector& operator/=(const float a) - { - float b = 1.0f / a; - x *= b; - y *= b; - z *= b; - return *this; - } - IC pVector& operator=(const pVector& a) - { - x = a.x; - y = a.y; - z = a.z; - return *this; - } - IC pVector operator^(const pVector& b) const - { - return pVector(y * b.z - z * b.y, z * b.x - x * b.z, x * b.y - y * b.x); - } -}; -// A single particle -struct Particle -{ - enum - { - ANIMATE_CCW = (1 << 0), - }; - pVector pos; // 12 - pVector posB; // 12 - pVector vel; // 12 - pVector size; // 12 - pVector rot; // 12 60 - u32 color; // 4 - float age; // 4 - u16 frame; // 2 - Flags16 flags; // 2 -}; // 72 - -typedef void (*OnBirthParticleCB)(void* owner, u32 param, PAPI::Particle& P, u32 idx); -typedef void (*OnDeadParticleCB)(void* owner, u32 param, PAPI::Particle& P, u32 idx); -////////////////////////////////////////////////////////////////////// -// Type codes for domains -enum PDomainEnum -{ - PDPoint = 0, // Single point - PDLine = 1, // Line segment - PDTriangle = 2, // Triangle - PDPlane = 3, // Arbitrarily-oriented plane - PDBox = 4, // Axis-aligned box - PDSphere = 5, // Sphere - PDCylinder = 6, // Cylinder - PDCone = 7, // Cone - PDBlob = 8, // Gaussian blob - PDDisc = 9, // Arbitrarily-oriented disc - PDRectangle = 10, // Rhombus-shaped planar region - domain_enum_force_dword = u32(-1) -}; -////////////////////////////////////////////////////////////////////// -// Type codes for all actions -enum PActionEnum -{ - PAAvoidID, // Avoid entering the domain of space. - PABounceID, // Bounce particles off a domain of space. - PACallActionListID_obsolette, // - PACopyVertexBID, // Set the secondary position from current position. - PADampingID, // Dampen particle velocities. - PAExplosionID, // An Explosion. - PAFollowID, // Accelerate toward the previous particle in the effect. - PAGravitateID, // Accelerate each particle toward each other particle. - PAGravityID, // Acceleration in the given direction. - PAJetID, // - PAKillOldID, // - PAMatchVelocityID, // - PAMoveID, // - PAOrbitLineID, // - PAOrbitPointID, // - PARandomAccelID, // - PARandomDisplaceID, // - PARandomVelocityID, // - PARestoreID, // - PASinkID, // - PASinkVelocityID, // - PASourceID, // - PASpeedLimitID, // - PATargetColorID, // - PATargetSizeID, // - PATargetRotateID, // - PATargetRotateDID, // - PATargetVelocityID, // - PATargetVelocityDID, // - PAVortexID, // - PATurbulenceID, // - PAScatterID, // - action_enum_force_dword = u32(-1) -}; -struct ParticleAction; - -class IParticleManager -{ -public: - IParticleManager() {} - virtual ~IParticleManager() {} - // create&destroy - virtual int CreateEffect(u32 max_particles) = 0; - virtual void DestroyEffect(int effect_id) = 0; - virtual int CreateActionList() = 0; - virtual void DestroyActionList(int alist_id) = 0; - - // control - virtual void PlayEffect(int effect_id, int alist_id) = 0; - virtual void StopEffect(int effect_id, int alist_id, BOOL deffered = TRUE) = 0; - - // update&render - virtual void Update(int effect_id, int alist_id, float dt) = 0; - virtual void Render(int effect_id) = 0; - virtual void Transform(int alist_id, const Fmatrix& m, const Fvector& velocity) = 0; - - // effect - virtual void RemoveParticle(int effect_id, u32 p_id) = 0; - virtual void SetMaxParticles(int effect_id, u32 max_particles) = 0; - virtual void SetCallback(int effect_id, OnBirthParticleCB b, OnDeadParticleCB d, void* owner, u32 param) = 0; - virtual void GetParticles(int effect_id, Particle*& particles, u32& cnt) = 0; - virtual u32 GetParticlesCount(int effect_id) = 0; - - // action - virtual ParticleAction* CreateAction(PActionEnum type) = 0; - virtual u32 LoadActions(int alist_id, IReader& R) = 0; - virtual void SaveActions(int alist_id, IWriter& W) = 0; -}; - -PARTICLES_API IParticleManager* ParticleManager(); -}; -#endif // PSystemH diff --git a/src/xrEngine/xrEngine.vcxproj b/src/xrEngine/xrEngine.vcxproj index 65dcccbd7a2..f524aa1305f 100644 --- a/src/xrEngine/xrEngine.vcxproj +++ b/src/xrEngine/xrEngine.vcxproj @@ -805,7 +805,6 @@ - diff --git a/src/xrEngine/xrEngine.vcxproj.filters b/src/xrEngine/xrEngine.vcxproj.filters index 3525da69960..a3cc88e2f59 100644 --- a/src/xrEngine/xrEngine.vcxproj.filters +++ b/src/xrEngine/xrEngine.vcxproj.filters @@ -255,9 +255,6 @@ General\Resources - - Interfaces - Interfaces\Input diff --git a/src/xrParticles/noise.cpp b/src/xrParticles/noise.cpp index 56d970531cc..5ae6548b3a1 100644 --- a/src/xrParticles/noise.cpp +++ b/src/xrParticles/noise.cpp @@ -1,12 +1,11 @@ #include "stdafx.h" -#pragma hdrstop #include "noise.h" #ifndef _EDITOR #include -__forceinline int iFloor_SSE(float const x) { return _mm_cvtt_ss2si(_mm_set_ss(x)); } +ICF int iFloor_SSE(float const x) { return _mm_cvtt_ss2si(_mm_set_ss(x)); } #endif //============================================================================== @@ -59,7 +58,8 @@ void noise3Init() v[j] = float((rnd % (B + B)) - B) / B; } s = DOT(v, v); - } while (s > 1.0); + } + while (s > 1.0); s = _sqrt(s); for (j = 0; j < 3; j++) g[i][j] = v[j] / s; diff --git a/src/xrParticles/noise.h b/src/xrParticles/noise.h index 0b3835d733e..66318d34c39 100644 --- a/src/xrParticles/noise.h +++ b/src/xrParticles/noise.h @@ -1,3 +1,4 @@ +#pragma once #ifndef noiseH #define noiseH diff --git a/src/xrParticles/particle_actions.cpp b/src/xrParticles/particle_actions.cpp index 2b9e9e5d0ab..c44c59cc4b2 100644 --- a/src/xrParticles/particle_actions.cpp +++ b/src/xrParticles/particle_actions.cpp @@ -1,5 +1,3 @@ -//--------------------------------------------------------------------------- #include "stdafx.h" -#pragma hdrstop #include "particle_actions.h" diff --git a/src/xrParticles/particle_actions.h b/src/xrParticles/particle_actions.h index 94b06203d30..4d938b8201e 100644 --- a/src/xrParticles/particle_actions.h +++ b/src/xrParticles/particle_actions.h @@ -1,4 +1,4 @@ -//--------------------------------------------------------------------------- +#pragma once #ifndef particle_actionsH #define particle_actionsH @@ -6,12 +6,14 @@ namespace PAPI { // refs struct ParticleEffect; + struct PARTICLES_API ParticleAction { enum { - ALLOW_ROTATE = (1 << 1) + ALLOW_ROTATE = 1 << 1 }; + Flags32 m_Flags; PActionEnum type; // Type field ParticleAction() { m_Flags.zero(); } @@ -21,6 +23,7 @@ struct PARTICLES_API ParticleAction virtual void Load(IReader& F) = 0; virtual void Save(IWriter& F) = 0; }; + using PAVec = xr_vector; using PAVecIt = PAVec::iterator; @@ -35,12 +38,13 @@ class ParticleActions actions.reserve(4); m_bLocked = false; } + ~ParticleActions() { clear(); } void clear() { R_ASSERT(!m_bLocked); - for (PAVecIt it = actions.begin(); it != actions.end(); it++) + for (PAVecIt it = actions.begin(); it != actions.end(); ++it) xr_delete(*it); actions.clear(); } @@ -51,22 +55,25 @@ class ParticleActions actions.push_back(pa); } - bool empty() { return actions.empty(); } + bool empty() const { return actions.empty(); } PAVecIt begin() { return actions.begin(); } PAVecIt end() { return actions.end(); } - int size() { return actions.size(); } + int size() const { return actions.size(); } void resize(int cnt) { R_ASSERT(!m_bLocked); actions.resize(cnt); } + void copy(ParticleActions* src); + void lock() { R_ASSERT(!m_bLocked); m_bLocked = true; } + void unlock() { R_ASSERT(m_bLocked); @@ -74,5 +81,6 @@ class ParticleActions } }; }; + //--------------------------------------------------------------------------- #endif diff --git a/src/xrParticles/particle_actions_collection.cpp b/src/xrParticles/particle_actions_collection.cpp index 64f43f9b6d4..a99d6d7a26a 100644 --- a/src/xrParticles/particle_actions_collection.cpp +++ b/src/xrParticles/particle_actions_collection.cpp @@ -678,25 +678,23 @@ void PABounce::Transform(const Fmatrix& m) { position.transform(positionL, m); } // Set the secondary position of each particle to be its position. void PACopyVertexB::Execute(ParticleEffect* effect, const float dt, float& tm_max) { - u32 i; - if (copy_pos) { - for (i = 0; i < effect->p_count; i++) + for (u32 i = 0; i < effect->p_count; i++) { Particle& m = effect->particles[i]; m.posB = m.pos; } } /* - if(copy_vel) + if (copy_vel) + { + for (u32 i = 0; i < effect->p_count; i++) { - for(i = 0; i < effect->p_count; i++) - { - Particle &m = effect->particles[i]; - m.velB = m.vel; - } + Particle& m = effect->particles[i]; + m.velB = m.vel; } + } */ } void PACopyVertexB::Transform(const Fmatrix&) { ; } @@ -707,7 +705,7 @@ void PADamping::Execute(ParticleEffect* effect, const float dt, float& tm_max) { // This is important if dt is != 1. pVector one(1, 1, 1); - pVector scale(one - ((one - damping) * dt)); + pVector scale(one - (one - damping) * dt); for (u32 i = 0; i < effect->p_count; i++) { @@ -944,10 +942,9 @@ void PAScatter::Execute(ParticleEffect* effect, const float dt, float& tm_max) if (rSqr < max_radiusSqr) { - pVector accel; - accel = dir / _sqrt(rSqr); + pVector accel = dir / _sqrt(rSqr); - // acc.Generate(accel); + //acc.Generate(accel); // Step velocity with acceleration m.vel += accel * (magdt / (rSqr + epsilon)); @@ -967,8 +964,7 @@ void PAScatter::Execute(ParticleEffect* effect, const float dt, float& tm_max) // Soften by epsilon to avoid tight encounters to infinity float rSqr = dir.length2(); - pVector accel; - accel = dir / _sqrt(rSqr); + pVector accel = dir / _sqrt(rSqr); // Step velocity with acceleration m.vel += accel * (magdt / (rSqr + epsilon)); @@ -1624,7 +1620,7 @@ extern void noise3Init(); #include #include "xrCore/Threading/ttapi.h" -__forceinline __m128 _mm_load_fvector(const Fvector& v) +ICF __m128 _mm_load_fvector(const Fvector& v) { __m128 R1, R2; @@ -1637,7 +1633,7 @@ __forceinline __m128 _mm_load_fvector(const Fvector& v) return R1; } -__forceinline void _mm_store_fvector(Fvector& v, const __m128 R1) +ICF void _mm_store_fvector(Fvector& v, const __m128 R1) { __m128 R2; @@ -1749,7 +1745,7 @@ void PATurbulence::Execute(ParticleEffect* effect, const float dt, float& tm_max { noise_start = 0; noise3Init(); - }; + } age += dt; @@ -1769,10 +1765,10 @@ void PATurbulence::Execute(ParticleEffect* effect, const float dt, float& tm_max // to minimize wait in final spin u32 nSlice = p_cnt / 128; - u32 nStep = ((p_cnt - nSlice) / nWorkers); - // u32 nStep = ( p_cnt / nWorkers ); + u32 nStep = (p_cnt - nSlice) / nWorkers; - // Msg( "Trb: %u" , nStep ); + //u32 nStep = (p_cnt / nWorkers); + //Msg("Trb: %u", nStep); for (u32 i = 0; i < nWorkers; ++i) { diff --git a/src/xrParticles/particle_actions_collection.h b/src/xrParticles/particle_actions_collection.h index 11c2669c9f6..0181784330f 100644 --- a/src/xrParticles/particle_actions_collection.h +++ b/src/xrParticles/particle_actions_collection.h @@ -1,9 +1,10 @@ -//--------------------------------------------------------------------------- +#pragma once #ifndef particle_actions_collectionH #define particle_actions_collectionH #include "particle_actions.h" #include "particle_core.h" + namespace PAPI { #define _METHODS \ @@ -223,6 +224,7 @@ struct PARTICLES_API PASource : public ParticleAction flVertexB_tracks = (1ul << 31ul), // True to get positionB from position. fl_FORCEDWORD = u32(-1) }; + pDomain positionL; // Choose a position in this domain. (local_space) pDomain velocityL; // Choose a velocity in this domain. (local_space) pDomain position; // Choose a position in this domain. diff --git a/src/xrParticles/particle_actions_collection_io.cpp b/src/xrParticles/particle_actions_collection_io.cpp index 757da4a7bc3..3944e294325 100644 --- a/src/xrParticles/particle_actions_collection_io.cpp +++ b/src/xrParticles/particle_actions_collection_io.cpp @@ -1,5 +1,4 @@ #include "stdafx.h" -#pragma hdrstop #include "particle_actions_collection.h" using namespace PAPI; @@ -9,6 +8,7 @@ void ParticleAction::Load(IReader& F) m_Flags.assign(F.r_u32()); type = (PActionEnum)F.r_u32(); } + void ParticleAction::Save(IWriter& F) { F.w_u32(m_Flags.get()); @@ -24,6 +24,7 @@ void PAAvoid::Load(IReader& F) epsilon = F.r_float(); positionL = position; } + void PAAvoid::Save(IWriter& F) { ParticleAction::Save(F); @@ -42,6 +43,7 @@ void PABounce::Load(IReader& F) cutoffSqr = F.r_float(); positionL = position; } + void PABounce::Save(IWriter& F) { ParticleAction::Save(F); @@ -56,6 +58,7 @@ void PACopyVertexB::Load(IReader& F) ParticleAction::Load(F); copy_pos = F.r_u32(); } + void PACopyVertexB::Save(IWriter& F) { ParticleAction::Save(F); @@ -69,6 +72,7 @@ void PADamping::Load(IReader& F) vlowSqr = F.r_float(); vhighSqr = F.r_float(); } + void PADamping::Save(IWriter& F) { ParticleAction::Save(F); @@ -88,6 +92,7 @@ void PAExplosion::Load(IReader& F) epsilon = F.r_float(); centerL = center; } + void PAExplosion::Save(IWriter& F) { ParticleAction::Save(F); @@ -106,6 +111,7 @@ void PAFollow::Load(IReader& F) epsilon = F.r_float(); max_radius = F.r_float(); } + void PAFollow::Save(IWriter& F) { ParticleAction::Save(F); @@ -121,6 +127,7 @@ void PAGravitate::Load(IReader& F) epsilon = F.r_float(); max_radius = F.r_float(); } + void PAGravitate::Save(IWriter& F) { ParticleAction::Save(F); @@ -135,6 +142,7 @@ void PAGravity::Load(IReader& F) F.r_fvector3(direction); directionL = direction; } + void PAGravity::Save(IWriter& F) { ParticleAction::Save(F); @@ -152,6 +160,7 @@ void PAJet::Load(IReader& F) centerL = center; accL = acc; } + void PAJet::Save(IWriter& F) { ParticleAction::Save(F); @@ -168,6 +177,7 @@ void PAKillOld::Load(IReader& F) age_limit = F.r_float(); kill_less_than = F.r_u32(); } + void PAKillOld::Save(IWriter& F) { ParticleAction::Save(F); @@ -182,6 +192,7 @@ void PAMatchVelocity::Load(IReader& F) epsilon = F.r_float(); max_radius = F.r_float(); } + void PAMatchVelocity::Save(IWriter& F) { ParticleAction::Save(F); @@ -192,6 +203,7 @@ void PAMatchVelocity::Save(IWriter& F) void PAMove::Load(IReader& F) { ParticleAction::Load(F); } void PAMove::Save(IWriter& F) { ParticleAction::Save(F); } + void PAOrbitLine::Load(IReader& F) { ParticleAction::Load(F); @@ -203,6 +215,7 @@ void PAOrbitLine::Load(IReader& F) pL = p; axisL = axis; } + void PAOrbitLine::Save(IWriter& F) { ParticleAction::Save(F); @@ -222,6 +235,7 @@ void PAOrbitPoint::Load(IReader& F) max_radius = F.r_float(); centerL = center; } + void PAOrbitPoint::Save(IWriter& F) { ParticleAction::Save(F); @@ -237,6 +251,7 @@ void PARandomAccel::Load(IReader& F) F.r(&gen_acc, sizeof(pDomain)); gen_accL = gen_acc; } + void PARandomAccel::Save(IWriter& F) { ParticleAction::Save(F); @@ -249,6 +264,7 @@ void PARandomDisplace::Load(IReader& F) F.r(&gen_disp, sizeof(pDomain)); gen_dispL = gen_disp; } + void PARandomDisplace::Save(IWriter& F) { ParticleAction::Save(F); @@ -261,6 +277,7 @@ void PARandomVelocity::Load(IReader& F) F.r(&gen_vel, sizeof(pDomain)); gen_velL = gen_vel; } + void PARandomVelocity::Save(IWriter& F) { ParticleAction::Save(F); @@ -272,6 +289,7 @@ void PARestore::Load(IReader& F) ParticleAction::Load(F); time_left = F.r_float(); } + void PARestore::Save(IWriter& F) { ParticleAction::Save(F); @@ -287,6 +305,7 @@ void PAScatter::Load(IReader& F) max_radius = F.r_float(); centerL = center; } + void PAScatter::Save(IWriter& F) { ParticleAction::Save(F); @@ -303,6 +322,7 @@ void PASink::Load(IReader& F) F.r(&position, sizeof(pDomain)); positionL = position; } + void PASink::Save(IWriter& F) { ParticleAction::Save(F); @@ -317,6 +337,7 @@ void PASinkVelocity::Load(IReader& F) F.r(&velocity, sizeof(pDomain)); velocityL = velocity; } + void PASinkVelocity::Save(IWriter& F) { ParticleAction::Save(F); @@ -330,6 +351,7 @@ void PASpeedLimit::Load(IReader& F) min_speed = F.r_float(); max_speed = F.r_float(); } + void PASpeedLimit::Save(IWriter& F) { ParticleAction::Save(F); @@ -354,6 +376,7 @@ void PASource::Load(IReader& F) positionL = position; velocityL = velocity; } + void PASource::Save(IWriter& F) { ParticleAction::Save(F); @@ -396,6 +419,7 @@ void PATargetSize::Load(IReader& F) F.r_fvector3(size); F.r_fvector3(scale); } + void PATargetSize::Save(IWriter& F) { ParticleAction::Save(F); @@ -409,6 +433,7 @@ void PATargetRotate::Load(IReader& F) F.r_fvector3(rot); scale = F.r_float(); } + void PATargetRotate::Save(IWriter& F) { ParticleAction::Save(F); @@ -423,6 +448,7 @@ void PATargetVelocity::Load(IReader& F) scale = F.r_float(); velocityL = velocity; } + void PATargetVelocity::Save(IWriter& F) { ParticleAction::Save(F); @@ -441,6 +467,7 @@ void PAVortex::Load(IReader& F) centerL = center; axisL = axis; } + void PAVortex::Save(IWriter& F) { ParticleAction::Save(F); @@ -460,6 +487,7 @@ void PATurbulence::Load(IReader& F) epsilon = F.r_float(); F.r_fvector3(offset); } + void PATurbulence::Save(IWriter& F) { ParticleAction::Save(F); diff --git a/src/xrParticles/particle_core.cpp b/src/xrParticles/particle_core.cpp index bcde2e51a66..c77d953ab6d 100644 --- a/src/xrParticles/particle_core.cpp +++ b/src/xrParticles/particle_core.cpp @@ -1,6 +1,4 @@ -//--------------------------------------------------------------------------- #include "stdafx.h" -#pragma hdrstop #include "particle_core.h" #include "xrCore/_fbox.h" @@ -23,13 +21,14 @@ float PAPI::NRand(float sigma) do { y = -logf(drand48()); - } while (drand48() > expf(-_sqr(y - 1.0f) * 0.5f)); + } + while (drand48() > expf(-_sqr(y - 1.0f) * 0.5f)); if (rand() & 0x1) return y * sigma * ONE_OVER_SIGMA_EXP; - else - return -y * sigma * ONE_OVER_SIGMA_EXP; + return -y * sigma * ONE_OVER_SIGMA_EXP; } + //////////////////////////////////////////////////////////////////////////////// // Stuff for the pDomain. pDomain::pDomain( @@ -38,7 +37,8 @@ pDomain::pDomain( type = dtype; switch (type) { - case PDPoint: p1 = pVector(a0, a1, a2); break; + case PDPoint: p1 = pVector(a0, a1, a2); + break; case PDLine: { p1 = pVector(a0, a1, a2); @@ -46,7 +46,7 @@ pDomain::pDomain( // p2 is vector3 from p1 to other endpoint. p2 = tmp - p1; } - break; + break; case PDBox: // p1 is the min corner. p2 is the max corner. if (a0 < a3) @@ -101,7 +101,7 @@ pDomain::pDomain( // radius1 stores the d of the plane eqn. radius1 = -(p1 * p2); } - break; + break; case PDRectangle: { p1 = pVector(a0, a1, a2); @@ -120,7 +120,7 @@ pDomain::pDomain( // radius1 stores the d of the plane eqn. radius1 = -(p1 * p2); } - break; + break; case PDPlane: { p1 = pVector(a0, a1, a2); @@ -130,7 +130,7 @@ pDomain::pDomain( // radius1 stores the d of the plane eqn. radius1 = -(p1 * p2); } - break; + break; case PDSphere: p1 = pVector(a0, a1, a2); if (a3 > a4) @@ -189,7 +189,7 @@ pDomain::pDomain( u.normalize_safe(); v = n ^ u; } - break; + break; case PDBlob: { p1 = pVector(a0, a1, a2); @@ -198,7 +198,7 @@ pDomain::pDomain( radius2Sqr = -0.5f * _sqr(tmp); radius2 = ONEOVERSQRT2PI * tmp; } - break; + break; case PDDisc: { p1 = pVector(a0, a1, a2); // Center point @@ -228,18 +228,18 @@ pDomain::pDomain( v = p2 ^ u; radius1Sqr = -(p1 * p2); // D of the plane eqn. } - break; + break; } } // Determines if pos is inside the domain -BOOL pDomain::Within(const pVector& pos) const +bool pDomain::Within(const pVector& pos) const { switch (type) { case PDBox: return !( - (pos.x < p1.x) || (pos.x > p2.x) || (pos.y < p1.y) || (pos.y > p2.y) || (pos.z < p1.z) || (pos.z > p2.z)); + pos.x < p1.x || pos.x > p2.x || pos.y < p1.y || pos.y > p2.y || pos.z < p1.z || pos.z > p2.z); case PDPlane: // Distance from plane = n * p + d // Inside is the positive half-space. @@ -270,23 +270,22 @@ BOOL pDomain::Within(const pVector& pos) const // radius2Sqr stores 1 / (p2.p2) float dist = (p2 * x) * radius2Sqr; if (dist < 0.0f || dist > 1.0f) - return FALSE; + return false; // Check radial distance; scale radius along axis for cones pVector xrad = x - p2 * dist; // Radial component of x float rSqr = xrad.length2(); if (type == PDCone) - return (rSqr <= _sqr(dist * radius1) && rSqr >= _sqr(dist * radius2)); - else - return (rSqr <= radius1Sqr && rSqr >= _sqr(radius2)); + return rSqr <= _sqr(dist * radius1) && rSqr >= _sqr(dist * radius2); + return rSqr <= radius1Sqr && rSqr >= _sqr(radius2); } case PDBlob: { pVector x(pos - p1); // return exp(-0.5 * xSq * Sqr(oneOverSigma)) * ONEOVERSQRT2PI * oneOverSigma; float Gx = expf(x.length2() * radius2Sqr) * radius2; - return (drand48() < Gx); + return drand48() < Gx; } case PDPoint: case PDLine: @@ -294,17 +293,19 @@ BOOL pDomain::Within(const pVector& pos) const case PDTriangle: case PDDisc: default: - return FALSE; // XXX Is there something better? + return false; // XXX Is there something better? } } -// Generate a random point uniformly distrbuted within the domain +// Generate a random point uniformly distributed within the domain void pDomain::Generate(pVector& pos) const { switch (type) { - case PDPoint: pos = p1; break; - case PDLine: pos = p1 + p2 * drand48(); break; + case PDPoint: pos = p1; + break; + case PDLine: pos = p1 + p2 * drand48(); + break; case PDBox: // Scale and translate [0,1] random to fit box pos.x = p1.x + (p2.x - p1.x) * drand48(); @@ -320,8 +321,9 @@ void pDomain::Generate(pVector& pos) const else pos = p1 + u * (1.0f - r1) + v * (1.0f - r2); } - break; - case PDRectangle: pos = p1 + u * drand48() + v * drand48(); break; + break; + case PDRectangle: pos = p1 + u * drand48() + v * drand48(); + break; case PDPlane: // How do I sensibly make a point on an infinite plane? pos = p1; break; @@ -358,7 +360,7 @@ void pDomain::Generate(pVector& pos) const pos = p1 + p2 * dist + u * x + v * y; } - break; + break; case PDBlob: pos.x = p1.x + NRand(radius1); pos.y = p1.y + NRand(radius1); @@ -376,7 +378,7 @@ void pDomain::Generate(pVector& pos) const pos = p1 + u * x + v * y; } - break; + break; default: pos = pVector(0, 0, 0); } } @@ -387,18 +389,19 @@ void pDomain::transform(const pDomain& domain, const Fmatrix& m) { case PDBox: { - Fbox* bb_dest = (Fbox*)&p1; - Fbox* bb_from = (Fbox*)&domain.p1; + auto bb_dest = (Fbox*)&p1; + auto bb_from = (Fbox*)&domain.p1; bb_dest->xform(*bb_from, m); } - break; + break; case PDPlane: m.transform_tiny(p1, domain.p1); m.transform_dir(p2, domain.p2); // radius1 stores the d of the plane eqn. radius1 = -(p1 * p2); break; - case PDSphere: m.transform_tiny(p1, domain.p1); break; + case PDSphere: m.transform_tiny(p1, domain.p1); + break; case PDCylinder: case PDCone: m.transform_tiny(p1, domain.p1); @@ -406,8 +409,10 @@ void pDomain::transform(const pDomain& domain, const Fmatrix& m) m.transform_dir(u, domain.u); m.transform_dir(v, domain.v); break; - case PDBlob: m.transform_tiny(p1, domain.p1); break; - case PDPoint: m.transform_tiny(p1, domain.p1); break; + case PDBlob: m.transform_tiny(p1, domain.p1); + break; + case PDPoint: m.transform_tiny(p1, domain.p1); + break; case PDLine: m.transform_tiny(p1, domain.p1); m.transform_dir(p2, domain.p2); diff --git a/src/xrParticles/particle_core.h b/src/xrParticles/particle_core.h index 3a730052465..04c07e787b8 100644 --- a/src/xrParticles/particle_core.h +++ b/src/xrParticles/particle_core.h @@ -1,4 +1,4 @@ -//--------------------------------------------------------------------------- +#pragma once #ifndef particle_coreH #define particle_coreH @@ -18,21 +18,22 @@ struct PARTICLES_API pDomain float radius1Sqr; // Used for fast Within test of spheres, float radius2Sqr; // and for mag. of u and v vectors for plane. - BOOL Within(const pVector&) const; + bool Within(const pVector&) const; void Generate(pVector&) const; // transformation void transform(const pDomain& domain, const Fmatrix& m); void transform_dir(const pDomain& domain, const Fmatrix& m); // This constructor is used when default constructing a // ParticleAction that has a pDomain. - IC pDomain() {} + pDomain() {} // Construct a domain in the standard way. pDomain(PDomainEnum dtype, float a0 = 0.0f, float a1 = 0.0f, float a2 = 0.0f, float a3 = 0.0f, float a4 = 0.0f, - float a5 = 0.0f, float a6 = 0.0f, float a7 = 0.0f, float a8 = 0.0f); + float a5 = 0.0f, float a6 = 0.0f, float a7 = 0.0f, float a8 = 0.0f); }; #pragma pack(pop) // misc float NRand(float sigma = 1.0f); }; + //--------------------------------------------------------------------------- #endif diff --git a/src/xrParticles/particle_effect.h b/src/xrParticles/particle_effect.h index 33bf09cb9a8..54d607027c7 100644 --- a/src/xrParticles/particle_effect.h +++ b/src/xrParticles/particle_effect.h @@ -1,4 +1,4 @@ -//--------------------------------------------------------------------------- +#pragma once #ifndef particle_effectH #define particle_effectH @@ -17,7 +17,6 @@ struct ParticleEffect void* owner; u32 param; -public: ParticleEffect(int mp) { owner = nullptr; @@ -29,15 +28,16 @@ struct ParticleEffect particles_allocated = max_particles; real_ptr = xr_malloc(sizeof(Particle) * (max_particles + 1)); - + particles = (Particle*)((uintptr_t)real_ptr + (64 - ((uintptr_t)real_ptr & 63))); //particles = static_cast(real_ptr); - // Msg( "Allocated %u bytes (%u particles) with base address 0x%p" , max_particles * sizeof( Particle ) , - // max_particles , particles ); + //Msg("Allocated %u bytes (%u particles) with base address 0x%p", max_particles * sizeof(Particle), max_particles, particles); } + ~ParticleEffect() { xr_free(real_ptr); } - IC int Resize(u32 max_count) + + int Resize(u32 max_count) { // Reducing max. if (particles_allocated >= max_count) @@ -62,8 +62,7 @@ struct ParticleEffect } Particle* new_particles = (Particle*)((uintptr_t)new_real_ptr + (64 - ((uintptr_t)new_real_ptr & 63))); - // Msg( "Re-allocated %u bytes (%u particles) with base address 0x%p" , max_count * sizeof( Particle ) , - // max_count , new_particles ); + Msg("Re-allocated %u bytes (%u particles) with base address 0x%p", max_count * sizeof(Particle), max_count, new_particles); CopyMemory(new_particles, particles, p_count * sizeof(Particle)); xr_free(real_ptr); @@ -75,7 +74,8 @@ struct ParticleEffect particles_allocated = max_count; return max_count; } - IC void Remove(int i) + + void Remove(int i) { if (0 == p_count) return; @@ -83,34 +83,32 @@ struct ParticleEffect if (d_cb) d_cb(owner, param, m, i); m = particles[--p_count]; // не менять правило удаления !!! (dependence ParticleGroup) - // Msg( "pDel() : %u" , p_count ); + //Msg("pDel() : %u", p_count); } - IC BOOL Add(const pVector& pos, const pVector& posB, const pVector& size, const pVector& rot, const pVector& vel, - u32 color, const float age = 0.0f, u16 frame = 0, u16 flags = 0) + bool Add(const pVector& pos, const pVector& posB, const pVector& size, const pVector& rot, const pVector& vel, + u32 color, const float age = 0.0f, u16 frame = 0, u16 flags = 0) { if (p_count >= max_particles) - return FALSE; - else - { - Particle& P = particles[p_count]; - P.pos = pos; - P.posB = posB; - P.size = size; - P.rot.x = rot.x; - P.vel = vel; - P.color = color; - P.age = age; - P.frame = frame; - P.flags.assign(flags); - if (b_cb) - b_cb(owner, param, P, p_count); - p_count++; - // Msg( "pAdd() : %u" , p_count ); - return TRUE; - } + return false; + Particle& P = particles[p_count]; + P.pos = pos; + P.posB = posB; + P.size = size; + P.rot.x = rot.x; + P.vel = vel; + P.color = color; + P.age = age; + P.frame = frame; + P.flags.assign(flags); + if (b_cb) + b_cb(owner, param, P, p_count); + p_count++; + //Msg("pAdd() : %u", p_count); + return true; } }; }; + //--------------------------------------------------------------------------- #endif diff --git a/src/xrParticles/particle_manager.cpp b/src/xrParticles/particle_manager.cpp index 46f6e208c4c..9ae0449a975 100644 --- a/src/xrParticles/particle_manager.cpp +++ b/src/xrParticles/particle_manager.cpp @@ -1,6 +1,4 @@ -//--------------------------------------------------------------------------- #include "stdafx.h" -#pragma hdrstop #include "particle_manager.h" #include "particle_effect.h" @@ -14,6 +12,7 @@ PARTICLES_API IParticleManager* PAPI::ParticleManager() { return &PM; } // CParticleManager::CParticleManager() {} CParticleManager::~CParticleManager() {} + ParticleEffect* CParticleManager::GetEffectPtr(int effect_id) { R_ASSERT(effect_id >= 0 && effect_id < (int)effect_vec.size()); @@ -41,18 +40,20 @@ int CParticleManager::CreateEffect(u32 max_particles) { // Couldn't find a big enough gap. Reallocate. eff_id = effect_vec.size(); - effect_vec.push_back(0); + effect_vec.push_back(nullptr); } effect_vec[eff_id] = new ParticleEffect(max_particles); return eff_id; } + void CParticleManager::DestroyEffect(int effect_id) { R_ASSERT(effect_id >= 0 && effect_id < (int)effect_vec.size()); xr_delete(effect_vec[effect_id]); } + int CParticleManager::CreateActionList() { int list_id = -1; @@ -67,13 +68,14 @@ int CParticleManager::CreateActionList() { // Couldn't find a big enough gap. Reallocate. list_id = m_alist_vec.size(); - m_alist_vec.push_back(0); + m_alist_vec.push_back(nullptr); } m_alist_vec[list_id] = new ParticleActions(); return list_id; } + void CParticleManager::DestroyActionList(int alist_id) { R_ASSERT(alist_id >= 0 && alist_id < (int)m_alist_vec.size()); @@ -84,11 +86,11 @@ void CParticleManager::DestroyActionList(int alist_id) void CParticleManager::PlayEffect(int effect_id, int alist_id) { // effect - // ParticleEffect* pe = GetEffectPtr(effect_id); + //ParticleEffect* pe = GetEffectPtr(effect_id); // Execute the specified action list. ParticleActions* pa = GetActionListPtr(alist_id); VERIFY(pa); - if (pa == NULL) + if (pa == nullptr) return; // ERROR pa->lock(); // Step through all the actions in the action list. @@ -97,29 +99,33 @@ void CParticleManager::PlayEffect(int effect_id, int alist_id) VERIFY((*it)); switch ((*it)->type) { - case PASourceID: static_cast(*it)->m_Flags.set(PASource::flSilent, FALSE); break; - case PAExplosionID: static_cast(*it)->age = 0.f; break; - case PATurbulenceID: static_cast(*it)->age = 0.f; break; + case PASourceID: static_cast(*it)->m_Flags.set(PASource::flSilent, false); + break; + case PAExplosionID: static_cast(*it)->age = 0.f; + break; + case PATurbulenceID: static_cast(*it)->age = 0.f; + break; } } pa->unlock(); } -void CParticleManager::StopEffect(int effect_id, int alist_id, BOOL deffered) +void CParticleManager::StopEffect(int effect_id, int alist_id, bool deffered) { // Execute the specified action list. ParticleActions* pa = GetActionListPtr(alist_id); VERIFY(pa); - if (pa == NULL) + if (pa == nullptr) return; // ERROR pa->lock(); // Step through all the actions in the action list. - for (PAVecIt it = pa->begin(); it != pa->end(); it++) + for (PAVecIt it = pa->begin(); it != pa->end(); ++it) { switch ((*it)->type) { - case PASourceID: static_cast(*it)->m_Flags.set(PASource::flSilent, TRUE); break; + case PASourceID: static_cast(*it)->m_Flags.set(PASource::flSilent, true); + break; } } if (!deffered) @@ -144,24 +150,26 @@ void CParticleManager::Update(int effect_id, int alist_id, float dt) // Step through all the actions in the action list. float kill_old_time = 1.0f; - for (PAVecIt it = pa->begin(); it != pa->end(); it++) + for (PAVecIt it = pa->begin(); it != pa->end(); ++it) { VERIFY((*it)); (*it)->Execute(pe, dt, kill_old_time); } pa->unlock(); } + void CParticleManager::Render(int effect_id) { // ParticleEffect* pe = GetEffectPtr(effect_id); } + void CParticleManager::Transform(int alist_id, const Fmatrix& full, const Fvector& vel) { // Execute the specified action list. ParticleActions* pa = GetActionListPtr(alist_id); VERIFY(pa); - if (pa == NULL) + if (pa == nullptr) return; // ERROR pa->lock(); @@ -169,9 +177,9 @@ void CParticleManager::Transform(int alist_id, const Fmatrix& full, const Fvecto mT.translate(full.c); // Step through all the actions in the action list. - for (PAVecIt it = pa->begin(); it != pa->end(); it++) + for (PAVecIt it = pa->begin(); it != pa->end(); ++it) { - BOOL r = (*it)->m_Flags.is(ParticleAction::ALLOW_ROTATE); + bool r = (*it)->m_Flags.is(ParticleAction::ALLOW_ROTATE); const Fmatrix& m = r ? full : mT; (*it)->Transform(m); switch ((*it)->type) @@ -191,11 +199,13 @@ void CParticleManager::RemoveParticle(int effect_id, u32 p_id) ParticleEffect* pe = GetEffectPtr(effect_id); pe->Remove(p_id); } + void CParticleManager::SetMaxParticles(int effect_id, u32 max_particles) { ParticleEffect* pe = GetEffectPtr(effect_id); pe->Resize(max_particles); } + void CParticleManager::SetCallback(int effect_id, OnBirthParticleCB b, OnDeadParticleCB d, void* owner, u32 param) { ParticleEffect* pe = GetEffectPtr(effect_id); @@ -204,12 +214,14 @@ void CParticleManager::SetCallback(int effect_id, OnBirthParticleCB b, OnDeadPar pe->owner = owner; pe->param = param; } + void CParticleManager::GetParticles(int effect_id, Particle*& particles, u32& cnt) { ParticleEffect* pe = GetEffectPtr(effect_id); particles = pe->particles; cnt = pe->p_count; } + u32 CParticleManager::GetParticlesCount(int effect_id) { ParticleEffect* pe = GetEffectPtr(effect_id); @@ -219,45 +231,77 @@ u32 CParticleManager::GetParticlesCount(int effect_id) // action ParticleAction* CParticleManager::CreateAction(PActionEnum type) { - ParticleAction* pa = 0; + ParticleAction* pa = nullptr; switch (type) { - case PAAvoidID: pa = new PAAvoid(); break; - case PABounceID: pa = new PABounce(); break; - case PACopyVertexBID: pa = new PACopyVertexB(); break; - case PADampingID: pa = new PADamping(); break; - case PAExplosionID: pa = new PAExplosion(); break; - case PAFollowID: pa = new PAFollow(); break; - case PAGravitateID: pa = new PAGravitate(); break; - case PAGravityID: pa = new PAGravity(); break; - case PAJetID: pa = new PAJet(); break; - case PAKillOldID: pa = new PAKillOld(); break; - case PAMatchVelocityID: pa = new PAMatchVelocity(); break; - case PAMoveID: pa = new PAMove(); break; - case PAOrbitLineID: pa = new PAOrbitLine(); break; - case PAOrbitPointID: pa = new PAOrbitPoint(); break; - case PARandomAccelID: pa = new PARandomAccel(); break; - case PARandomDisplaceID: pa = new PARandomDisplace(); break; - case PARandomVelocityID: pa = new PARandomVelocity(); break; - case PARestoreID: pa = new PARestore(); break; - case PASinkID: pa = new PASink(); break; - case PASinkVelocityID: pa = new PASinkVelocity(); break; - case PASourceID: pa = new PASource(); break; - case PASpeedLimitID: pa = new PASpeedLimit(); break; - case PATargetColorID: pa = new PATargetColor(); break; - case PATargetSizeID: pa = new PATargetSize(); break; - case PATargetRotateID: pa = new PATargetRotate(); break; - case PATargetRotateDID: pa = new PATargetRotate(); break; - case PATargetVelocityID: pa = new PATargetVelocity(); break; - case PATargetVelocityDID: pa = new PATargetVelocity(); break; - case PAVortexID: pa = new PAVortex(); break; - case PATurbulenceID: pa = new PATurbulence(); break; - case PAScatterID: pa = new PAScatter(); break; + case PAAvoidID: pa = new PAAvoid(); + break; + case PABounceID: pa = new PABounce(); + break; + case PACopyVertexBID: pa = new PACopyVertexB(); + break; + case PADampingID: pa = new PADamping(); + break; + case PAExplosionID: pa = new PAExplosion(); + break; + case PAFollowID: pa = new PAFollow(); + break; + case PAGravitateID: pa = new PAGravitate(); + break; + case PAGravityID: pa = new PAGravity(); + break; + case PAJetID: pa = new PAJet(); + break; + case PAKillOldID: pa = new PAKillOld(); + break; + case PAMatchVelocityID: pa = new PAMatchVelocity(); + break; + case PAMoveID: pa = new PAMove(); + break; + case PAOrbitLineID: pa = new PAOrbitLine(); + break; + case PAOrbitPointID: pa = new PAOrbitPoint(); + break; + case PARandomAccelID: pa = new PARandomAccel(); + break; + case PARandomDisplaceID: pa = new PARandomDisplace(); + break; + case PARandomVelocityID: pa = new PARandomVelocity(); + break; + case PARestoreID: pa = new PARestore(); + break; + case PASinkID: pa = new PASink(); + break; + case PASinkVelocityID: pa = new PASinkVelocity(); + break; + case PASourceID: pa = new PASource(); + break; + case PASpeedLimitID: pa = new PASpeedLimit(); + break; + case PATargetColorID: pa = new PATargetColor(); + break; + case PATargetSizeID: pa = new PATargetSize(); + break; + case PATargetRotateID: pa = new PATargetRotate(); + break; + case PATargetRotateDID: pa = new PATargetRotate(); + break; + case PATargetVelocityID: pa = new PATargetVelocity(); + break; + case PATargetVelocityDID: pa = new PATargetVelocity(); + break; + case PAVortexID: pa = new PAVortex(); + break; + case PATurbulenceID: pa = new PATurbulence(); + break; + case PAScatterID: pa = new PAScatter(); + break; default: NODEFAULT; } pa->type = type; return pa; } + u32 CParticleManager::LoadActions(int alist_id, IReader& R) { // Execute the specified action list. @@ -276,6 +320,7 @@ u32 CParticleManager::LoadActions(int alist_id, IReader& R) } return pa->size(); } + void CParticleManager::SaveActions(int alist_id, IWriter& W) { // Execute the specified action list. @@ -283,7 +328,7 @@ void CParticleManager::SaveActions(int alist_id, IWriter& W) VERIFY(pa); pa->lock(); W.w_u32(pa->size()); - for (PAVecIt it = pa->begin(); it != pa->end(); it++) + for (PAVecIt it = pa->begin(); it != pa->end(); ++it) (*it)->Save(W); pa->unlock(); } diff --git a/src/xrParticles/particle_manager.h b/src/xrParticles/particle_manager.h index 0309fd9d508..ee13d37e006 100644 --- a/src/xrParticles/particle_manager.h +++ b/src/xrParticles/particle_manager.h @@ -1,7 +1,6 @@ -//--------------------------------------------------------------------------- +#pragma once #ifndef particle_managerH #define particle_managerH -//--------------------------------------------------------------------------- #include "particle_actions.h" namespace PAPI @@ -23,32 +22,33 @@ class CParticleManager : public IParticleManager ParticleActions* GetActionListPtr(int alist_id); // create&destroy - virtual int CreateEffect(u32 max_particles); - virtual void DestroyEffect(int effect_id); - virtual int CreateActionList(); - virtual void DestroyActionList(int alist_id); + int CreateEffect(u32 max_particles) override; + void DestroyEffect(int effect_id) override; + int CreateActionList() override; + void DestroyActionList(int alist_id) override; // control - virtual void PlayEffect(int effect_id, int alist_id); - virtual void StopEffect(int effect_id, int alist_id, BOOL deffered = TRUE); + void PlayEffect(int effect_id, int alist_id) override; + void StopEffect(int effect_id, int alist_id, bool deffered = true) override; // update&render - virtual void Update(int effect_id, int alist_id, float dt); - virtual void Render(int effect_id); - virtual void Transform(int alist_id, const Fmatrix& m, const Fvector& velocity); + void Update(int effect_id, int alist_id, float dt) override; + void Render(int effect_id) override; + void Transform(int alist_id, const Fmatrix& m, const Fvector& velocity) override; // effect - virtual void RemoveParticle(int effect_id, u32 p_id); - virtual void SetMaxParticles(int effect_id, u32 max_particles); - virtual void SetCallback(int effect_id, OnBirthParticleCB b, OnDeadParticleCB d, void* owner, u32 param); - virtual void GetParticles(int effect_id, Particle*& particles, u32& cnt); - virtual u32 GetParticlesCount(int effect_id); + void RemoveParticle(int effect_id, u32 p_id) override; + void SetMaxParticles(int effect_id, u32 max_particles) override; + void SetCallback(int effect_id, OnBirthParticleCB b, OnDeadParticleCB d, void* owner, u32 param) override; + void GetParticles(int effect_id, Particle*& particles, u32& cnt) override; + u32 GetParticlesCount(int effect_id) override; // action - virtual ParticleAction* CreateAction(PActionEnum action_id); - virtual u32 LoadActions(int alist_id, IReader& R); - virtual void SaveActions(int alist_id, IWriter& W); -}; + ParticleAction* CreateAction(PActionEnum action_id) override; + u32 LoadActions(int alist_id, IReader& R) override; + void SaveActions(int alist_id, IWriter& W) override; }; +} + //--------------------------------------------------------------------------- #endif diff --git a/src/xrParticles/psystem.h b/src/xrParticles/psystem.h index 8df868132f6..2a7a25ff6b6 100644 --- a/src/xrParticles/psystem.h +++ b/src/xrParticles/psystem.h @@ -28,48 +28,55 @@ namespace PAPI class pVector : public Fvector { public: - IC pVector(float ax, float ay, float az) { set(ax, ay, az); } - IC pVector() {} - IC float length() const { return _sqrt(x * x + y * y + z * z); } - IC float length2() const { return (x * x + y * y + z * z); } - IC float operator*(const pVector& a) const { return x * a.x + y * a.y + z * a.z; } - IC pVector operator*(const float s) const { return pVector(x * s, y * s, z * s); } - IC pVector operator/(const float s) const + pVector(float ax, float ay, float az) { set(ax, ay, az); } + pVector() {} + float length() const { return _sqrt(x * x + y * y + z * z); } + float length2() const { return (x * x + y * y + z * z); } + float operator*(const pVector& a) const { return x * a.x + y * a.y + z * a.z; } + pVector operator*(const float s) const { return pVector(x * s, y * s, z * s); } + + pVector operator/(const float s) const { float invs = 1.0f / s; return pVector(x * invs, y * invs, z * invs); } - IC pVector operator+(const pVector& a) const { return pVector(x + a.x, y + a.y, z + a.z); } - IC pVector operator-(const pVector& a) const { return pVector(x - a.x, y - a.y, z - a.z); } - IC pVector operator-() + + pVector operator+(const pVector& a) const { return pVector(x + a.x, y + a.y, z + a.z); } + pVector operator-(const pVector& a) const { return pVector(x - a.x, y - a.y, z - a.z); } + + pVector operator-() { x = -x; y = -y; z = -z; return *this; } - IC pVector& operator+=(const pVector& a) + + pVector& operator+=(const pVector& a) { x += a.x; y += a.y; z += a.z; return *this; } - IC pVector& operator-=(const pVector& a) + + pVector& operator-=(const pVector& a) { x -= a.x; y -= a.y; z -= a.z; return *this; } - IC pVector& operator*=(const float a) + + pVector& operator*=(const float a) { x *= a; y *= a; z *= a; return *this; } - IC pVector& operator/=(const float a) + + pVector& operator/=(const float a) { float b = 1.0f / a; x *= b; @@ -77,42 +84,50 @@ class pVector : public Fvector z *= b; return *this; } - IC pVector& operator=(const pVector& a) + + pVector& operator=(const pVector& a) { x = a.x; y = a.y; z = a.z; return *this; } - IC pVector operator^(const pVector& b) const + + pVector operator^(const pVector& b) const { return pVector(y * b.z - z * b.y, z * b.x - x * b.z, x * b.y - y * b.x); } }; -// A single particle + struct Rotation { float x; }; + +// A single particle struct Particle { enum { - ANIMATE_CCW = (1 << 0), + ANIMATE_CCW = 1 << 0, }; + Rotation rot; // 4 pVector pos; // 12 pVector posB; // 12 pVector vel; // 12 pVector size; // 12 + //pVector rot; // 12 60 // From xrEngine/psystem.h u32 color; // 4 float age; // 4 u16 frame; // 2 Flags16 flags; // 2 -}; // = 64 +}; // = 64 here +// = 72 was in xrEngine/psystem.h + +using OnBirthParticleCB = void(*)(void* owner, u32 param, PAPI::Particle& P, u32 idx); +using OnDeadParticleCB = void(*)(void* owner, u32 param, PAPI::Particle& P, u32 idx); -typedef void (*OnBirthParticleCB)(void* owner, u32 param, PAPI::Particle& P, u32 idx); -typedef void (*OnDeadParticleCB)(void* owner, u32 param, PAPI::Particle& P, u32 idx); ////////////////////////////////////////////////////////////////////// // Type codes for domains enum PDomainEnum @@ -130,6 +145,7 @@ enum PDomainEnum PDRectangle = 10, // Rhombus-shaped planar region domain_enum_force_dword = u32(-1) }; + ////////////////////////////////////////////////////////////////////// // Type codes for all actions enum PActionEnum @@ -168,6 +184,7 @@ enum PActionEnum PAScatterID, // action_enum_force_dword = u32(-1) }; + struct ParticleAction; class IParticleManager @@ -183,7 +200,7 @@ class IParticleManager // control virtual void PlayEffect(int effect_id, int alist_id) = 0; - virtual void StopEffect(int effect_id, int alist_id, BOOL deffered = TRUE) = 0; + virtual void StopEffect(int effect_id, int alist_id, bool deffered = true) = 0; // update&render virtual void Update(int effect_id, int alist_id, float dt) = 0; @@ -204,5 +221,5 @@ class IParticleManager }; PARTICLES_API IParticleManager* ParticleManager(); -}; +} #endif // PSystemH