TombEngine/TR5Main/Game/drip.cpp

108 lines
2.9 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>
#include "control.h"
#include "level.h"
#include "room.h"
#include "trmath.h"
2020-06-18 14:24:52 +02:00
#include <Game\effect2.h>
2020-06-15 19:59:08 +02:00
namespace T5M {
namespace Effects {
namespace Drip {
using namespace DirectX::SimpleMath;
2020-06-18 14:24:52 +02:00
std::array<DripParticle, NUM_DRIPS> dripParticles;
2020-06-15 19:59:08 +02:00
constexpr Vector4 DRIP_COLOR = Vector4(1, 1, 1, 1);
void UpdateDrips()
{
for (int i = 0; i < dripParticles.size(); i++) {
DripParticle& d = dripParticles[i];
if (!d.active) continue;
d.age++;
2020-06-18 14:24:52 +02:00
if (d.age > d.life)
2020-06-15 19:59:08 +02:00
d.active = false;
d.velocity.y += d.gravity;
if (Rooms[d.room].flags & ENV_FLAG_WIND) {
d.velocity.x = SmokeWindX / 2;
d.velocity.z = SmokeWindZ / 2;
}
d.pos += d.velocity;
2020-06-16 19:13:41 +02:00
float normalizedAge = d.age / d.life;
2020-06-15 19:59:08 +02:00
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->floor;
2020-06-18 14:24:52 +02:00
int wh = GetWaterHeight(d.pos.x, d.pos.y, d.pos.z, d.room);
if (d.pos.y > floorheight) {
2020-06-15 19:59:08 +02:00
d.active = false;
2020-06-18 14:24:52 +02:00
}
if (d.pos.y > wh) {
d.active = false;
SetupRipple(d.pos.x, wh, d.pos.z, frandMinMax(16,24), RIPPLE_FLAG_SHORT_LIFE | RIPPLE_FLAG_RAND_ROT | RIPPLE_FLAG_LOW_OPACITY);
}
2020-06-15 19:59:08 +02:00
}
}
DripParticle& getFreeDrip()
{
for (int i = 0; i < dripParticles.size(); i++)
{
if (!dripParticles[i].active)
return dripParticles[i];
}
return dripParticles[0];
}
2020-06-16 19:13:41 +02:00
void SpawnWetnessDrip(Vector3 pos, int room)
2020-06-15 19:59:08 +02:00
{
DripParticle& d = getFreeDrip();
d = {};
d.active = true;
d.pos = pos;
d.room = room;
2020-06-16 19:13:41 +02:00
d.life = DRIP_LIFE;
2020-06-15 19:59:08 +02:00
d.gravity = frandMinMax(3, 6);
}
2020-06-16 19:13:41 +02:00
void SpawnSplashDrips(Vector3& pos, int num,int room)
{
for (int i = 0; i < num; i++) {
Vector3 dripPos = pos + Vector3(frandMinMax(-128, 128), frandMinMax(-128, 128), frandMinMax(-128, 128));
Vector3 dir = (dripPos - pos);
dir.Normalize();
DripParticle& drip = getFreeDrip();
drip = {};
drip.pos = dripPos;
drip.velocity = dir*16;
drip.velocity -= Vector3(0, frandMinMax(32, 64), 0);
drip.gravity = frandMinMax(3, 6);
drip.room = room;
drip.life = DRIP_LIFE_LONG;
drip.active = true;
}
}
2020-06-18 14:24:52 +02:00
void SpawnGunshellDrips(Vector3& pos, int room)
{
for (int i = 0; i < 4; i++) {
Vector3 dripPos = pos + Vector3(frandMinMax(-16, 16), frandMinMax(-16, 16), frandMinMax(-16, 16));
Vector3 dir = (dripPos - pos);
dir.Normalize();
DripParticle& drip = getFreeDrip();
drip = {};
drip.pos = dripPos;
drip.velocity = dir * 16;
drip.velocity -= Vector3(0, frandMinMax(16, 24), 0);
drip.gravity = frandMinMax(2, 3);
drip.room = room;
drip.life = DRIP_LIFE_LONG;
drip.active = true;
}
}
2020-06-15 19:59:08 +02:00
}
}
}