Merge branch 'VehicleSprites'

# Conflicts:
#	TR5Main/Objects/TR2/Vehicles/boat.cpp
This commit is contained in:
Raildex 2020-09-15 08:13:58 +02:00
commit 624f5675b7
13 changed files with 157 additions and 24 deletions

View file

@ -44,11 +44,13 @@
#include <tr4_littlebeetle.h>
#include "explosion.h"
#include "drip.h"
#include "particle/SimpleParticle.h"
using std::vector;
using namespace T5M::Effects::Explosion;
using namespace T5M::Effects::Spark;
using namespace T5M::Effects::Smoke;
using namespace T5M::Effects;
using T5M::Renderer::g_Renderer;
short ShatterSounds[18][10] =
@ -548,6 +550,7 @@ GAME_STATUS ControlPhase(int numFrames, int demoMode)
UpdateLittleBeetles();
UpdateSparkParticles();
UpdateSmokeParticles();
updateSimpleParticles();
T5M::Effects::Drip::UpdateDrips();
UpdateExplosionParticles();
UpdateShockwaves();

View file

@ -0,0 +1,71 @@
#include "framework.h"
#include "SimpleParticle.h"
#include "items.h"
#include "trmath.h"
#include <Specific\setup.h>
namespace T5M::Effects{
std::array<SimpleParticle, 15> simpleParticles;
SimpleParticle& getFreeSimpleParticle()
{
for(auto& p : simpleParticles)
if(!p.active)
return p;
return simpleParticles[0];
}
void TriggerSnowmobileSnow(ITEM_INFO* snowMobile)
{
float angle = TO_RAD(snowMobile->pos.yRot);
const float angleVariation = frandMinMax(-10, 10) * RADIAN;
float x = std::sin(angle + angleVariation);
float z = std::cos(angle + angleVariation);
x = x* -500 + snowMobile->pos.xPos;
z = z* -500 + snowMobile->pos.zPos;
SimpleParticle& p = getFreeSimpleParticle();
p = {};
p.active = true;
p.life = frandMinMax(8, 14);
p.room = snowMobile->roomNumber;
p.ageRate = frandMinMax(0.9, 1.3);
float size = frandMinMax(96, 128);
p.worldPosition = {x,float(snowMobile->pos.yPos) - size/2,z};
p.sequence = ID_SKIDOO_SNOW_TRAIL_SPRITES;
p.size = frandMinMax(256, 512);
}
void TriggerSpeedboatFoam(ITEM_INFO* boat)
{
float angle = TO_RAD(boat->pos.yRot);
const float angleVariation = frandMinMax(-10, 10) * RADIAN;
float x = std::sin(angle + angleVariation);
float z = std::cos(angle + angleVariation);
x = x * -700 + boat->pos.xPos;
z = z * -700 + boat->pos.zPos;
SimpleParticle& p = getFreeSimpleParticle();
p = {};
p.active = true;
p.life = frandMinMax(8, 14);
p.room = boat->roomNumber;
p.ageRate = frandMinMax(0.9, 1.3);
float size = frandMinMax(96, 128);
p.worldPosition = {x,float(boat->pos.yPos) - size / 2,z};
p.sequence = ID_MOTOR_BOAT_FOAM_SPRITES;
p.size = frandMinMax(256, 512);
}
void updateSimpleParticles()
{
for(auto& p : simpleParticles){
if(!p.active)
continue;
p.age+= p.ageRate;
if(p.life < p.age)
p.active = false;
int numSprites = -Objects[p.sequence].nmeshes - 1;
float normalizedAge = p.age / p.life;
p.sprite = lerp(0, numSprites, normalizedAge);
}
}
}

View file

@ -0,0 +1,26 @@
#pragma once
#include <d3d11.h>
#include <SimpleMath.h>
#include <Objects\objectslist.h>
#include <array>
#include <unordered_map>
struct ITEM_INFO;
namespace T5M::Effects{
struct SimpleParticle {
DirectX::SimpleMath::Vector3 worldPosition;
float size;
float age;
float ageRate;
float life;
int room;
unsigned int sprite;
GAME_OBJECT_ID sequence;
bool active;
};
extern std::array<SimpleParticle, 15> simpleParticles;
SimpleParticle& getFreeSimpleParticle();
void TriggerSnowmobileSnow(ITEM_INFO* snowMobile);
void TriggerSpeedboatFoam(ITEM_INFO* boat);
void updateSimpleParticles();
}

View file

@ -10,6 +10,7 @@
#include "input.h"
#include "sound.h"
#include <Game\effect2.h>
#include <Game\particle\SimpleParticle.h>
struct BOAT_INFO
{
@ -80,6 +81,8 @@ enum BOAT_STATE
void DoBoatWakeEffect(ITEM_INFO* boat)
{
T5M::Effects::TriggerSpeedboatFoam(boat);
/*int c = phd_cos(boat->pos.yRot);
int s = phd_sin(boat->pos.yRot);
int c = phd_cos(boat->pos.yRot);
@ -147,7 +150,7 @@ void DoBoatWakeEffect(ITEM_INFO* boat)
spark->sSize = spark->size = ((GetRandomControl() & 3) + 16) * 4;
spark->dSize = 2 * spark->size;
spark->def = Objects[ID_DEFAULT_SPRITES].meshIndex + 17;
}
}*/
}
void SpeedBoatGetOff(ITEM_INFO* boat)

View file

@ -15,6 +15,7 @@
#include "level.h"
#include "input.h"
#include "sound.h"
#include <Game\particle\SimpleParticle.h>
using std::vector;
@ -313,7 +314,8 @@ bool SkidooCheckGetOff()
void DoSnowEffect(ITEM_INFO* skidoo)
{
SPARKS* spark = &Sparks[GetFreeSpark()];
T5M::Effects::TriggerSnowmobileSnow(skidoo);
/*SPARKS* spark = &Sparks[GetFreeSpark()];
spark->on = 1;
spark->sR = 64;
spark->sG = 64;
@ -339,7 +341,7 @@ void DoSnowEffect(ITEM_INFO* skidoo)
spark->rotAdd = (GetRandomControl() & 0x1F) - 16;
spark->gravity = -spark->yVel >> 2;
spark->sSize = spark->size = ((GetRandomControl() & 3) + 16) * 32;
spark->dSize = 2 * spark->size;
spark->dSize = 2 * spark->size;*/
}
void SkidooAnimation(ITEM_INFO* skidoo, int collide, bool dead)

View file

@ -973,6 +973,9 @@ typedef enum GAME_OBJECT_ID
ID_SPARK_SPRITE,
ID_DRIP_SPRITE,
ID_EXPLOSION_SPRITES,
ID_MOTOR_BOAT_FOAM_SPRITES,
ID_RUBBER_BOAT_WAVE_SPRITES,
ID_SKIDOO_SNOW_TRAIL_SPRITES,
ID_PANEL_BORDER = 1400,
ID_PANEL_MIDDLE,

View file

@ -43,7 +43,9 @@ typedef enum BLEND_MODES
BLENDMODE_OPAQUE = 0,
BLENDMODE_ALPHATEST = 1,
BLENDMODE_ALPHABLEND = 2,
BLENDMODE_SUBTRACTIVE = 3
BLENDMODE_SUBTRACTIVE = 3,
BLENDMODE_ADDITIVE = 4,
NUM_BLENDMODES
};
typedef enum RENDERER_CULLMODE

View file

@ -600,6 +600,7 @@ namespace T5M::Renderer
void drawExplosionParticles();
void renderToCubemap(const RenderTargetCube& dest,const Vector3& pos,int roomNumber);
void drawLaraHolsters(bool transparent);
void drawSimpleParticles();
public:
DirectX::SimpleMath::Matrix View;
DirectX::SimpleMath::Matrix Projection;

View file

@ -2017,6 +2017,7 @@ namespace T5M::Renderer
drawFires();
drawSmokes();
drawSmokeParticles();
drawSimpleParticles();
drawSparkParticles();
drawExplosionParticles();
drawFootprints();

View file

@ -17,6 +17,7 @@
#include "drip.h"
#include "explosion.h"
#include "Quad/RenderQuad.h"
#include <Game\particle\SimpleParticle.h>
extern BLOOD_STRUCT Blood[MAX_SPARKS_BLOOD];
extern FIRE_SPARKS FireSparks[MAX_SPARKS_FIRE];
@ -126,7 +127,7 @@ namespace T5M::Renderer {
1.0f,
32.0f,
Vector3::Distance(pos1, pos2),
BLENDMODE_ALPHABLEND,
BLENDMODE_ADDITIVE,
d);
}
}
@ -142,7 +143,7 @@ namespace T5M::Renderer {
Vector3(spark->x, spark->y, spark->z),
Vector4(spark->shade / 255.0f, spark->shade / 255.0f, spark->shade / 255.0f, 1.0f),
TO_RAD(spark->rotAng), spark->scalar, spark->size * 4.0f, spark->size * 4.0f,
BLENDMODE_ALPHABLEND);
BLENDMODE_ADDITIVE);
}
}
}
@ -227,7 +228,7 @@ namespace T5M::Renderer {
for (int i = 0; i < MAX_SPARKS_FIRE; i++) {
FIRE_SPARKS* spark = &FireSparks[i];
if (spark->on)
addSpriteBillboard(&m_sprites[spark->def], Vector3(fire->x + spark->x, fire->y + spark->y, fire->z + spark->z), Vector4(spark->r / 255.0f, spark->g / 255.0f, spark->b / 255.0f, 1.0f), TO_RAD(spark->rotAng), spark->scalar, spark->size * 4.0f, spark->size * 4.0f, BLENDMODE_ALPHABLEND);
addSpriteBillboard(&m_sprites[spark->def], Vector3(fire->x + spark->x, fire->y + spark->y, fire->z + spark->z), Vector4(spark->r / 255.0f, spark->g / 255.0f, spark->b / 255.0f, 1.0f), TO_RAD(spark->rotAng), spark->scalar, spark->size * 4.0f, spark->size * 4.0f, BLENDMODE_ADDITIVE);
}
}
}
@ -309,7 +310,7 @@ namespace T5M::Renderer {
pos,
Vector4(spark->r / 255.0f, spark->g / 255.0f, spark->b / 255.0f, 1.0f),
TO_RAD(spark->rotAng), spark->scalar, spark->size, spark->size,
BLENDMODE_ALPHABLEND);
BLENDMODE_ADDITIVE);
} else {
Vector3 pos = Vector3(spark->x, spark->y, spark->z);
Vector3 v = Vector3(spark->xVel, spark->yVel, spark->zVel);
@ -365,7 +366,7 @@ namespace T5M::Renderer {
x2Outer += splash.x;
z2Outer = outerRadius * cos(alpha * j * PI / 180);
z2Outer += splash.z;
addSprite3D(&m_sprites[Objects[ID_DEFAULT_SPRITES].meshIndex + splash.spriteSequenceStart + (int)splash.animationPhase], Vector3(xOuter, yOuter, zOuter), Vector3(x2Outer, yOuter, z2Outer), Vector3(x2Inner, yInner, z2Inner), Vector3(xInner, yInner, zInner), Vector4(color / 255.0f, color / 255.0f, color / 255.0f, 1.0f), 0, 1, 0, 0, BLENDMODE_ALPHABLEND);
addSprite3D(&m_sprites[Objects[ID_DEFAULT_SPRITES].meshIndex + splash.spriteSequenceStart + (int)splash.animationPhase], Vector3(xOuter, yOuter, zOuter), Vector3(x2Outer, yOuter, z2Outer), Vector3(x2Inner, yInner, z2Inner), Vector3(xInner, yInner, zInner), Vector4(color / 255.0f, color / 255.0f, color / 255.0f, 1.0f), 0, 1, 0, 0, BLENDMODE_ADDITIVE);
}
}
}
@ -375,7 +376,7 @@ namespace T5M::Renderer {
for (int i = 0; i < MAX_BUBBLES; i++) {
BUBBLE_STRUCT* bubble = &Bubbles[i];
if (bubble->active)
addSpriteBillboard(&m_sprites[Objects[ID_DEFAULT_SPRITES].meshIndex + bubble->spriteNum], Vector3(bubble->worldPosition.x, bubble->worldPosition.y, bubble->worldPosition.z), bubble->color, bubble->rotation, 1.0f, bubble->size * 0.5f, bubble->size * 0.5f, BLENDMODE_ALPHABLEND);
addSpriteBillboard(&m_sprites[Objects[ID_DEFAULT_SPRITES].meshIndex + bubble->spriteNum], Vector3(bubble->worldPosition.x, bubble->worldPosition.y, bubble->worldPosition.z), bubble->color, bubble->rotation, 1.0f, bubble->size * 0.5f, bubble->size * 0.5f, BLENDMODE_ADDITIVE);
}
}
@ -396,9 +397,9 @@ namespace T5M::Renderer {
if (ripple->active) {
float y = ripple->worldPos.y;
if (ripple->isBillboard) {
addSpriteBillboard(&m_sprites[Objects[ID_DEFAULT_SPRITES].meshIndex + ripple->SpriteID], ripple->worldPos, ripple->currentColor, ripple->rotation, 1, ripple->size, ripple->size, BLENDMODE_ALPHABLEND);
addSpriteBillboard(&m_sprites[Objects[ID_DEFAULT_SPRITES].meshIndex + ripple->SpriteID], ripple->worldPos, ripple->currentColor, ripple->rotation, 1, ripple->size, ripple->size, BLENDMODE_ADDITIVE);
} else {
addSpriteBillboardConstrainedLookAt(&m_sprites[Objects[ID_DEFAULT_SPRITES].meshIndex + ripple->SpriteID], ripple->worldPos, ripple->currentColor, ripple->rotation, 1, ripple->size*2, ripple->size*2, BLENDMODE_ALPHABLEND, Vector3(0,-1,0));
addSpriteBillboardConstrainedLookAt(&m_sprites[Objects[ID_DEFAULT_SPRITES].meshIndex + ripple->SpriteID], ripple->worldPos, ripple->currentColor, ripple->rotation, 1, ripple->size*2, ripple->size*2, BLENDMODE_ADDITIVE, Vector3(0,-1,0));
//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);
}
}
@ -457,7 +458,7 @@ namespace T5M::Renderer {
shockwave->g * shockwave->life / 255.0f / 16.0f,
shockwave->b * shockwave->life / 255.0f / 16.0f,
1.0f),
0, 1, 0, 0, BLENDMODE_ALPHABLEND);
0, 1, 0, 0, BLENDMODE_ADDITIVE);
p1 = p2;
p4 = p3;
@ -475,7 +476,7 @@ namespace T5M::Renderer {
Vector3(blood->x, blood->y, blood->z),
Vector4(blood->shade / 255.0f, blood->shade * 0, blood->shade * 0, 1.0f),
TO_RAD(blood->rotAng), 1.0f, blood->size * 8.0f, blood->size * 8.0f,
BLENDMODE_ALPHABLEND);
BLENDMODE_ADDITIVE);
}
}
}
@ -723,7 +724,7 @@ namespace T5M::Renderer {
dust->Life++;
byte color = (dust->Life > 16 ? 32 - dust->Life : dust->Life) * 4;
addSpriteBillboard(&m_sprites[Objects[ID_DEFAULT_SPRITES].meshIndex + SPR_UNDERWATERDUST], Vector3(dust->X, dust->Y, dust->Z), Vector4(color / 255.0f, color / 255.0f, color / 255.0f, 1.0f), 0.0f, 1.0f, 12, 12, BLENDMODE_ALPHABLEND);
addSpriteBillboard(&m_sprites[Objects[ID_DEFAULT_SPRITES].meshIndex + SPR_UNDERWATERDUST], Vector3(dust->X, dust->Y, dust->Z), Vector4(color / 255.0f, color / 255.0f, color / 255.0f, 1.0f), 0.0f, 1.0f, 12, 12, BLENDMODE_ADDITIVE);
if (dust->Life >= 32)
dust->Reset = true;
@ -751,18 +752,18 @@ namespace T5M::Renderer {
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
m_context->IASetInputLayout(m_inputLayout.Get());
m_context->IASetVertexBuffers(0, 1, quadVertexBuffer.GetAddressOf(), &stride, &offset);
for (int b = 0; b < 4; b++) {
for (int b = 0; b < NUM_BLENDMODES; b++) {
BLEND_MODES currentBlendMode = (BLEND_MODES)b;
int numSpritesToDraw = m_spritesToDraw.size();
int lastSprite = 0;
switch (currentBlendMode) {
case BLENDMODE_ALPHABLEND:
m_context->OMSetBlendState(m_states->Additive(), NULL, 0xFFFFFFFF);
m_context->OMSetBlendState(m_states->AlphaBlend(), NULL, 0xFFFFFFFF);
break;
case BLENDMODE_ALPHATEST:
m_context->OMSetBlendState(m_states->Additive(), NULL, 0xFFFFFFFF);
m_context->OMSetBlendState(m_states->AlphaBlend(), NULL, 0xFFFFFFFF);
break;
case BLENDMODE_OPAQUE:
@ -770,7 +771,9 @@ namespace T5M::Renderer {
break;
case BLENDMODE_SUBTRACTIVE:
m_context->OMSetBlendState(m_subtractiveBlendState.Get(), NULL, 0xFFFFFFFF);
break;
case BLENDMODE_ADDITIVE:
m_context->OMSetBlendState(m_states->Additive(), NULL, 0xFFFFFFFF);
break;
}
@ -1176,7 +1179,7 @@ namespace T5M::Renderer {
for (int i = 0; i < SmokeParticles.size(); i++) {
SmokeParticle& s = SmokeParticles[i];
if (!s.active) continue;
addSpriteBillboard(&m_sprites[Objects[ID_SMOKE_SPRITES].meshIndex + s.sprite], s.position, s.color, s.rotation, 1.0f, s.size, s.size, BLENDMODE_ALPHABLEND);
addSpriteBillboard(&m_sprites[Objects[ID_SMOKE_SPRITES].meshIndex + s.sprite], s.position, s.color, s.rotation, 1.0f, s.size, s.size, BLENDMODE_ADDITIVE);
}
}
@ -1190,7 +1193,7 @@ namespace T5M::Renderer {
if (!s.active) continue;
Vector3 v;
s.velocity.Normalize(v);
addSpriteBillboardConstrained(&m_sprites[Objects[ID_SPARK_SPRITE].meshIndex], s.pos, s.color, 0, 1, s.width, s.height, BLENDMODE_ALPHABLEND, v);
addSpriteBillboardConstrained(&m_sprites[Objects[ID_SPARK_SPRITE].meshIndex], s.pos, s.color, 0, 1, s.width, s.height, BLENDMODE_ADDITIVE, v);
}
}
@ -1204,7 +1207,7 @@ namespace T5M::Renderer {
if (!d.active) continue;
Vector3 v;
d.velocity.Normalize(v);
addSpriteBillboardConstrained(&m_sprites[Objects[ID_DRIP_SPRITE].meshIndex], d.pos, d.color, 0, 1, DRIP_WIDTH, d.height, BLENDMODE_ALPHABLEND, v);
addSpriteBillboardConstrained(&m_sprites[Objects[ID_DRIP_SPRITE].meshIndex], d.pos, d.color, 0, 1, DRIP_WIDTH, d.height, BLENDMODE_ADDITIVE, v);
}
}
@ -1215,7 +1218,15 @@ namespace T5M::Renderer {
for (int i = 0; i < explosionParticles.size(); i++) {
ExplosionParticle& e = explosionParticles[i];
if (!e.active) continue;
addSpriteBillboard(&m_sprites[Objects[ID_EXPLOSION_SPRITES].meshIndex + e.sprite], e.pos, e.tint, e.rotation, 1.0f, e.size, e.size, BLENDMODE_ALPHABLEND);
addSpriteBillboard(&m_sprites[Objects[ID_EXPLOSION_SPRITES].meshIndex + e.sprite], e.pos, e.tint, e.rotation, 1.0f, e.size, e.size, BLENDMODE_ADDITIVE);
}
}
void Renderer11::drawSimpleParticles()
{
using namespace T5M::Effects;
for(SimpleParticle& s : simpleParticles){
if(!s.active) continue;
addSpriteBillboard(&m_sprites[Objects[s.sequence].meshIndex + s.sprite], s.worldPosition, Vector4(1,1,1,1), 0, 1.0f, s.size, s.size/2, BLENDMODE_ALPHATEST);
}
}
}

View file

@ -378,3 +378,5 @@ void Renderer11::drawLaraHolsters(bool transparent)
}
}
}

View file

@ -152,6 +152,7 @@ xcopy /Y "$(ProjectDir)Scripting\Scripts\*.lua" "$(TargetDir)\Scripts"</Command>
<ClInclude Include="Game\memory\linearPoolAllocator.h" />
<ClInclude Include="Game\memory\PoolAllocator.h" />
<ClInclude Include="Game\memory\memory.h" />
<ClInclude Include="Game\particle\SimpleParticle.h" />
<ClInclude Include="Game\phd_global.h" />
<ClInclude Include="Game\memory\qmalloc.h" />
<ClInclude Include="Game\puzzles_keys.h" />
@ -448,6 +449,7 @@ xcopy /Y "$(ProjectDir)Scripting\Scripts\*.lua" "$(TargetDir)\Scripts"</Command>
<ClCompile Include="Game\Lara\lara_slide.cpp" />
<ClCompile Include="Game\Lara\lara_tests.cpp" />
<ClCompile Include="Game\misc.cpp" />
<ClCompile Include="Game\particle\SimpleParticle.cpp" />
<ClCompile Include="Game\puzzles_keys.cpp" />
<ClCompile Include="Game\trmath.cpp" />
<ClCompile Include="Game\smoke.cpp" />

View file

@ -915,6 +915,9 @@
<ClInclude Include="Objects\TR3\Vehicles\biggun.h">
<Filter>File di intestazione</Filter>
</ClInclude>
<ClInclude Include="Game\particle\SimpleParticle.h">
<Filter>File di intestazione</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Game\box.cpp">
@ -1676,6 +1679,9 @@
<ClCompile Include="Objects\TR3\Vehicles\biggun.cpp">
<Filter>File di origine</Filter>
</ClCompile>
<ClCompile Include="Game\particle\SimpleParticle.cpp">
<Filter>File di origine</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />