TombEngine/TR5Main/Game/effects/drip.cpp

135 lines
3.2 KiB
C++
Raw Normal View History

2020-06-15 19:59:08 +02:00
#include "framework.h"
#include "drip.h"
#include <d3d11.h>
#include <SimpleMath.h>
2021-09-19 23:41:26 +03:00
#include "control/control.h"
2020-06-15 19:59:08 +02:00
#include "level.h"
#include "room.h"
2021-09-08 18:31:35 +03:00
#include "Specific\trmath.h"
#include "effects\effects.h"
2021-09-15 11:13:47 +03:00
#include "effects\weather.h"
#include "setup.h"
2021-09-08 18:31:35 +03:00
#include "Specific\prng.h"
2021-09-15 11:13:47 +03:00
using namespace TEN::Effects::Environment;
2021-08-30 18:03:21 +03:00
using namespace TEN::Math::Random;
2021-09-15 11:13:47 +03:00
2021-08-30 18:03:21 +03:00
namespace TEN {
2021-09-16 01:12:19 +03:00
namespace Effects {
namespace Drip
{
using namespace DirectX::SimpleMath;
2020-06-15 19:59:08 +02:00
2021-09-16 01:12:19 +03:00
std::array<DripParticle, NUM_DRIPS> dripParticles;
constexpr Vector4 DRIP_COLOR = Vector4(1, 1, 1, 1);
2020-06-15 19:59:08 +02:00
void DisableDripParticles()
{
for (int i = 0; i < dripParticles.size(); i++)
dripParticles[i].active = false;
}
void UpdateDripParticles()
2021-09-16 01:12:19 +03:00
{
for (int i = 0; i < dripParticles.size(); i++)
{
DripParticle& d = dripParticles[i];
if (!d.active) continue;
d.age++;
2020-06-15 19:59:08 +02:00
2021-09-16 01:12:19 +03:00
if (d.age > d.life)
d.active = false;
d.velocity.y += d.gravity;
if (g_Level.Rooms[d.room].flags & ENV_FLAG_WIND)
2020-06-15 19:59:08 +02:00
{
2021-09-16 01:12:19 +03:00
d.velocity.x = Weather.Wind().x;
d.velocity.z = Weather.Wind().z;
2020-06-15 19:59:08 +02:00
}
2021-09-16 01:12:19 +03:00
d.pos += d.velocity;
float normalizedAge = d.age / d.life;
d.color = Vector4::Lerp(DRIP_COLOR, Vector4::Zero, normalizedAge);
d.height = lerp(DRIP_WIDTH / 0.15625, 0, normalizedAge);
short room = d.room;
FLOOR_INFO* floor = GetFloor(d.pos.x, d.pos.y, d.pos.z, &room);
int floorheight = floor->FloorHeight(d.pos.x, d.pos.z);
int wh = GetWaterHeight(d.pos.x, d.pos.y, d.pos.z, d.room);
if (d.pos.y > floorheight)
2020-06-16 19:13:41 +02:00
{
2021-09-16 01:12:19 +03:00
d.active = false;
2020-06-16 19:13:41 +02:00
}
2021-09-16 01:12:19 +03:00
if (d.pos.y > wh)
2020-06-18 14:24:52 +02:00
{
2021-09-16 01:12:19 +03:00
d.active = false;
2021-09-17 16:07:53 +03:00
SetupRipple(d.pos.x, wh, d.pos.z, GenerateFloat(16, 24),
2021-09-16 01:12:19 +03:00
RIPPLE_FLAG_SHORT_LIFE | RIPPLE_FLAG_RAND_ROT | RIPPLE_FLAG_LOW_OPACITY,
Objects[ID_DEFAULT_SPRITES].meshIndex + SPR_RIPPLES);
2020-06-18 14:24:52 +02:00
}
2020-06-15 19:59:08 +02:00
}
}
2021-09-16 01:12:19 +03:00
DripParticle& getFreeDrip()
{
for (int i = 0; i < dripParticles.size(); i++)
{
if (!dripParticles[i].active)
return dripParticles[i];
}
return dripParticles[0];
}
void SpawnWetnessDrip(Vector3 const & pos, int room)
{
DripParticle& d = getFreeDrip();
d = {};
d.active = true;
d.pos = pos;
d.room = room;
d.life = DRIP_LIFE;
2021-09-17 16:07:53 +03:00
d.gravity = GenerateFloat(3, 6);
2021-09-16 01:12:19 +03:00
}
void SpawnSplashDrips(Vector3 const& pos, int num,int room)
{
for (int i = 0; i < num; i++)
{
2021-09-17 16:07:53 +03:00
Vector3 dripPos = pos + Vector3(GenerateFloat(-128, 128), GenerateFloat(-128, 128), GenerateFloat(-128, 128));
2021-09-16 01:12:19 +03:00
Vector3 dir = (dripPos - pos);
dir.Normalize();
DripParticle& drip = getFreeDrip();
drip = {};
drip.pos = dripPos;
drip.velocity = dir*16;
2021-09-17 16:07:53 +03:00
drip.velocity -= Vector3(0, GenerateFloat(32, 64), 0);
drip.gravity = GenerateFloat(3, 6);
2021-09-16 01:12:19 +03:00
drip.room = room;
drip.life = DRIP_LIFE_LONG;
drip.active = true;
}
}
void SpawnGunshellDrips(Vector3 const & pos, int room)
{
for (int i = 0; i < 4; i++)
{
2021-09-17 16:07:53 +03:00
Vector3 dripPos = pos + Vector3(GenerateFloat(-16, 16), GenerateFloat(-16, 16), GenerateFloat(-16, 16));
2021-09-16 01:12:19 +03:00
Vector3 dir = (dripPos - pos);
dir.Normalize();
DripParticle& drip = getFreeDrip();
drip = {};
drip.pos = dripPos;
drip.velocity = dir * 16;
2021-09-17 16:07:53 +03:00
drip.velocity -= Vector3(0, GenerateFloat(16, 24), 0);
drip.gravity = GenerateFloat(2, 3);
2021-09-16 01:12:19 +03:00
drip.room = room;
drip.life = DRIP_LIFE_LONG;
drip.active = true;
}
}
}}}