Skip to content

Commit

Permalink
Add SmokeParticleGenerator2. Unverified and crashes because of the la…
Browse files Browse the repository at this point in the history
…ck of Init()
  • Loading branch information
lhog committed Sep 12, 2024
1 parent 2ab9e8e commit 828bf02
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions rts/Rendering/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ set(sources_engine_Rendering
"${CMAKE_CURRENT_SOURCE_DIR}/Env/Particles/Generators/NanoParticleGenerator.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Env/Particles/Generators/SimpleParticleGenerator.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Env/Particles/Generators/SmokeParticleGenerator.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Env/Particles/Generators/SmokeParticleGenerator2.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/GL/FBO.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/GL/StreamBuffer.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/GL/GeometryBuffer.cpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "GeoThermSmokeProjectile.h"
#include "Sim/Features/Feature.h"
#include "Sim/Projectiles/ProjectileHandler.h"
#include "Rendering/Env/Particles/Generators/ParticleGeneratorHandler.h"
#include "Sim/Misc/GlobalConstants.h"
#include "Sim/Misc/Wind.h"

Expand Down Expand Up @@ -43,8 +44,14 @@ void CGeoThermSmokeProjectile::Update()
const float curSpeed = fastmath::sqrt_builtin(speed.SqLength());
const float newSpeed = speed.w * (speed.w / curSpeed);

CWorldObject::SetVelocity((dir = (speed / curSpeed)) * newSpeed);
dir = static_cast<float3>(speed) / curSpeed;

CWorldObject::SetVelocity(dir * newSpeed);
CSmokeProjectile::Update();

auto& pg = ParticleGeneratorHandler::GetInstance().GetGenerator<SmokeParticleGenerator>();
auto& data = pg.Get(pgOffset);
data.speed = speed;
}

void CGeoThermSmokeProjectile::UpdateDir()
Expand Down
3 changes: 2 additions & 1 deletion rts/Rendering/Env/Particles/Classes/SmokeProjectile.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ class CSmokeProjectile : public CProjectile

public:
float size;
protected:
size_t pgOffset;
private:
float color;
float age;
float ageSpeed;
float startSize;
float sizeExpansion;
int textureNum;
size_t pgOffset;
};

#endif /* SMOKE_PROJECTILE_H */
24 changes: 24 additions & 0 deletions rts/Rendering/Env/Particles/Classes/SmokeProjectile2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Rendering/GlobalRendering.h"
#include "Rendering/Env/Particles/ProjectileDrawer.h"
#include "Rendering/GL/RenderBuffers.h"
#include "Rendering/Env/Particles/Generators/ParticleGeneratorHandler.h"
#include "Rendering/Textures/TextureAtlas.h"
#include "Sim/Misc/Wind.h"
#include "Sim/Projectiles/ExpGenSpawnableMemberInfo.h"
Expand Down Expand Up @@ -71,8 +72,31 @@ CSmokeProjectile2::CSmokeProjectile2(

glowFalloff = 4.5f + guRNG.NextFloat() * 6;
textureNum = (int)(guRNG.NextInt(projectileDrawer->NumSmokeTextures()));

auto& pg = ParticleGeneratorHandler::GetInstance().GetGenerator<SmokeParticleGenerator2>();
pgOffset = pg.Add({
.pos = pos,
.size = size,
.wantedPos = wantedPos,
.startSize = startSize,
.sizeExpansion = sizeExpansion,
.ageRate = ageSpeed,
.glowFalloff = glowFalloff,
.speed = speed,
.createFrame = createFrame,
.animParams = animParams,
.color = SColor{color, color, color, 1.0f},
.rotParams = rotParams,
.drawOrder = drawOrder,
.texCoord = *projectileDrawer->GetSmokeTexture(textureNum)
});
}

CSmokeProjectile2::~CSmokeProjectile2()
{
auto& pg = ParticleGeneratorHandler::GetInstance().GetGenerator<SmokeParticleGenerator2>();
pg.Del(pgOffset);
}


void CSmokeProjectile2::Init(const CUnit* owner, const float3& offset)
Expand Down
2 changes: 2 additions & 0 deletions rts/Rendering/Env/Particles/Classes/SmokeProjectile2.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class CSmokeProjectile2 : public CProjectile
float sizeExpansion,
float color = 0.7f
);
~CSmokeProjectile2() override;

void Update() override;
void Draw() override;
Expand All @@ -43,6 +44,7 @@ class CSmokeProjectile2 : public CProjectile
int textureNum;
float3 wantedPos;
float glowFalloff;
size_t pgOffset;
};

#endif /* SMOKE_PROJECTILE_2_H */
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "NanoParticleGenerator.h"
#include "SimpleParticleGenerator.h"
#include "SmokeParticleGenerator.h"
#include "SmokeParticleGenerator2.h"

namespace Shader {
struct IProgramObject;
Expand Down Expand Up @@ -105,7 +106,8 @@ class ParticleGeneratorHandler {
NanoParticleGenerator,
// skipped shields and repulsor
SimpleParticleGenerator,
SmokeParticleGenerator
SmokeParticleGenerator,
SmokeParticleGenerator2
>;

std::unique_ptr<GeneratorsTuple> generators;
Expand Down

0 comments on commit 828bf02

Please sign in to comment.