This commit is contained in:
Montagna Marco 2020-03-29 20:06:13 +02:00
commit 767abaaf32
5 changed files with 110 additions and 91 deletions

View file

@ -1125,35 +1125,33 @@ void UpdateSplashes()
{ {
RIPPLE_STRUCT* ripple = &Ripples[i]; RIPPLE_STRUCT* ripple = &Ripples[i];
if (ripple->flags & 1) if (ripple->active)
{ {
if (ripple->size < 252) if (ripple->lifeTime > ripple->life) {
{ ripple->active = false;
if (ripple->flags & 2) continue;
ripple->size += 2;
else
ripple->size += 4;
if (ripple->init)
{
if (ripple->init < ripple->life)
{
if (ripple->flags & 2)
ripple->init += 8;
else
ripple->init += 4;
if (ripple->init >= ripple->life)
ripple->init = 0;
}
}
else
{
ripple->life -= 3;
if (ripple->life > 250)
ripple->flags = 0;
}
} }
//normalized Lifetime
float n = ripple->lifeTime / ripple->life;
n = fmin(n, 1.0f);
n = fmax(0.0f, n);
constexpr float peakTime = 0.2f;
constexpr float expIn = 1.5f;
constexpr float expOut = 1.0f;
if (n <= peakTime) {
float alpha = pow((n / peakTime), expIn);
//we ascend our color
ripple->currentColor = Vector4::Lerp(Vector4::Zero, ripple->initialColor, alpha);
}
else {
float alphaTerm = 1.0f - ((n - peakTime) / 1 - peakTime);
// float alpha = pow(alphaTerm, expOut);
float alpha = alphaTerm;
ripple->currentColor = Vector4::Lerp(Vector4::Zero, ripple->initialColor, alpha);
//we descend
}
ripple->size += ripple->sizeRate;
ripple->lifeTime += ripple->lifeRate;
} }
} }
} }
@ -1166,44 +1164,53 @@ void SetupRipple(int x, int y, int z, char size, char flags)
for (i = 0; i < MAX_RIPPLES; i++) for (i = 0; i < MAX_RIPPLES; i++)
{ {
ripple = &Ripples[i]; ripple = &Ripples[i];
if (!(ripple->flags & 1)) if (!(ripple->active)) {
ripple->active = true;
ripple->size = size;
ripple->lifeTime = 0;
if (flags & RIPPLE_FLAG_SHORT_LIFE) {
ripple->life = (rand() & 16) + 16;
}
else {
ripple->life = (rand() & 16) + 48;
}
ripple->worldPos = { (float)x,(float)y,(float)z };
ripple->currentColor = Vector4(0, 0, 0, 0);
if (flags & RIPPLE_FLAG_BLOOD ) {
ripple->SpriteID = SPR_FIRE1;
ripple->initialColor = Vector4(1, 0, 0, 1);
ripple->lifeRate = 0.9f;
ripple->sizeRate = 8.0f;
ripple->isBillboard = true;
}
else {
ripple->SpriteID = SPR_RIPPLES;
ripple->initialColor = Vector4(1, 1, 1, 1);
ripple->lifeRate = 1.0f;
ripple->sizeRate = 4.0f;
ripple->isBillboard = false;
}
if (flags & RIPPLE_FLAG_RAND_POS)
{
ripple->worldPos.x += frandMinMax(-32, 32);
ripple->worldPos.z += frandMinMax(-32, 32);
}
if (flags & RIPPLE_FLAG_RAND_ROT)
{
ripple->rotation = frandMinMax(-PI, PI);
}
else {
ripple->rotation = 0;
}
break; break;
} }
if (i == MAX_RIPPLES)
return;
ripple->flags = flags | 1;
ripple->size = size;
ripple->life = (GetRandomControl() & 0xF) + 48;
ripple->init = 1;
ripple->x = x;
ripple->y = y;
ripple->z = z;
if (flags & 0x40)
{
ripple->x += (GetRandomControl() & 0x7F) - 64;
ripple->z += (GetRandomControl() & 0x7F) - 64;
} }
} }
void TriggerUnderwaterBlood(int x, int y, int z, int sizeme) void TriggerUnderwaterBlood(int x, int y, int z, int sizeme)
{ {
for (int i = 0; i < MAX_RIPPLES; i++) SetupRipple(x, y, z, sizeme, RIPPLE_FLAG_BLOOD | RIPPLE_FLAG_RAND_POS | RIPPLE_FLAG_RAND_ROT);
{
RIPPLE_STRUCT* ripple = &Ripples[i];
if (!(ripple->flags & 1))
{
ripple->flags = 0x31;
ripple->init = 1;
ripple->life = (GetRandomControl() & 7) - 16;
ripple->size = sizeme;
ripple->x = (GetRandomControl() & 0x3F) + x - 32;
ripple->y = y;
ripple->z = (GetRandomControl() & 0x3F) + z - 32;
return;
}
}
} }
void TriggerWaterfallMist(int x, int y, int z, int angle) void TriggerWaterfallMist(int x, int y, int z, int angle)
@ -1401,11 +1408,11 @@ void WadeSplash(ITEM_INFO* item, int wh, int wd)
{ {
if (item->currentAnimState == STATE_LARA_STOP) if (item->currentAnimState == STATE_LARA_STOP)
{ {
SetupRipple(item->pos.xPos, wh, item->pos.zPos, (GetRandomControl() & 0xF) + 112, 16); SetupRipple(item->pos.xPos, wh, item->pos.zPos, (GetRandomControl() & 0xF) + 112, RIPPLE_FLAG_RAND_ROT | RIPPLE_FLAG_RAND_POS);
} }
else else
{ {
SetupRipple(item->pos.xPos, wh, item->pos.zPos, (GetRandomControl() & 0xF) + 112, 18); SetupRipple(item->pos.xPos, wh, item->pos.zPos, (GetRandomControl() & 0xF) + 112, RIPPLE_FLAG_RAND_ROT | RIPPLE_FLAG_RAND_POS);
} }
} }
} }

View file

@ -1,12 +1,40 @@
#pragma once #pragma once
#include <d3d11.h>
#include "..\Global\global.h" #include "..\Global\global.h"
#define ExplodingDeath ((void (__cdecl*)(short, int, int)) 0x00484080) #define ExplodingDeath ((void (__cdecl*)(short, int, int)) 0x00484080)
//#define InitialiseSmokeEmitter ((void (__cdecl*)(short)) 0x0043D9D0) //#define InitialiseSmokeEmitter ((void (__cdecl*)(short)) 0x0043D9D0)
//#define SmokeEmitterControl ((void (__cdecl*)(short)) 0x00431560) //#define SmokeEmitterControl ((void (__cdecl*)(short)) 0x00431560)
#define DrawLensFlare ((void (__cdecl*)(ITEM_INFO*)) 0x00485290) #define DrawLensFlare ((void (__cdecl*)(ITEM_INFO*)) 0x00485290)
#define RIPPLE_FLAG_BLOOD 0x80
#define RIPPLE_FLAG_RAND_POS 0x40
#define RIPPLE_FLAG_RAND_ROT 0x20
#define RIPPLE_FLAG_SHORT_LIFE 0x01
struct RIPPLE_STRUCT
{
Vector4 currentColor;
Vector4 initialColor;
Vector3 worldPos;
unsigned int SpriteID;
float rotation;
float size;
float sizeRate;
float life; //max life
float lifeTime; // current life
float lifeRate; // life change rate
bool active;
bool isBillboard; //used for Blood
};
struct SPLASH_SETUP
{
float x;
float y;
float z;
float splashPower;
float innerRadius;
};
extern SPLASH_STRUCT Splashes[MAX_SPLASH]; extern SPLASH_STRUCT Splashes[MAX_SPLASH];
extern RIPPLE_STRUCT Ripples[32]; extern RIPPLE_STRUCT Ripples[32];
extern int DeadlyBounds[6]; extern int DeadlyBounds[6];

View file

@ -1163,7 +1163,7 @@ void UpdateBubbles()
if (!(Rooms[roomNumber].flags & ENV_FLAG_WATER)) if (!(Rooms[roomNumber].flags & ENV_FLAG_WATER))
{ {
SetupRipple(bubble->pos.x, Rooms[bubble->roomNumber].maxceiling, bubble->pos.z, (GetRandomControl() & 0xF) + 48, 2); SetupRipple(bubble->pos.x, Rooms[bubble->roomNumber].maxceiling, bubble->pos.z, (GetRandomControl() & 0xF) + 48, RIPPLE_FLAG_SHORT_LIFE+RIPPLE_FLAG_RAND_ROT);
bubble->size = 0; bubble->size = 0;
continue; continue;
} }

View file

@ -1044,25 +1044,7 @@ struct DRIP_STRUCT
byte pad; // size=0, offset=23 byte pad; // size=0, offset=23
}; };
struct RIPPLE_STRUCT
{
int x; // size=0, offset=0
int y; // size=0, offset=4
int z; // size=0, offset=8
byte flags; // size=0, offset=12
unsigned char life; // size=0, offset=13
unsigned char size; // size=0, offset=14
unsigned char init; // size=0, offset=15
};
struct SPLASH_SETUP
{
float x;
float y;
float z;
float splashPower;
float innerRadius;
};
struct FIRE_LIST struct FIRE_LIST
{ {

View file

@ -401,17 +401,19 @@ void Renderer11::drawRipples()
{ {
RIPPLE_STRUCT* ripple = &Ripples[i]; RIPPLE_STRUCT* ripple = &Ripples[i];
if (ripple->flags & 1) if (ripple->active)
{ {
float x1 = ripple->x - ripple->size; float x1 = ripple->worldPos.x - ripple->size;
float z1 = ripple->z - ripple->size; float z1 = ripple->worldPos.z - ripple->size;
float x2 = ripple->x + ripple->size; float x2 = ripple->worldPos.x + ripple->size;
float z2 = ripple->z + ripple->size; float z2 = ripple->worldPos.z + ripple->size;
float y = ripple->y; float y = ripple->worldPos.y;
if (ripple->isBillboard) {
byte color = (ripple->init ? ripple->init << 1 : ripple->life << 1); AddSpriteBillboard(m_sprites[Objects[ID_DEFAULT_SPRITES].meshIndex + ripple->SpriteID], ripple->worldPos, ripple->currentColor, 0, 1, ripple->size, ripple->size, BLENDMODE_ALPHABLEND);
}
AddSprite3D(m_sprites[Objects[ID_DEFAULT_SPRITES].meshIndex + SPR_RIPPLES], Vector3(x1, y, z2), Vector3(x2, y, z2), Vector3(x2, y, z1), Vector3(x1, y, z1), Vector4(color / 255.0f, color / 255.0f, color / 255.0f, 1.0f), 0.0f, 1.0f, ripple->size, ripple->size, BLENDMODE_ALPHABLEND); else {
AddSprite3D(m_sprites[Objects[ID_DEFAULT_SPRITES].meshIndex + ripple->SpriteID], Vector3(x1, y, z2), Vector3(x2, y, z2), Vector3(x2, y, z1), Vector3(x1, y, z1), ripple->currentColor, 0.0f, 1.0f, ripple->size, ripple->size, BLENDMODE_ALPHABLEND);
}
} }
} }
} }