Commit 8792ceb5 authored by AL's avatar AL

added dust throw effect

parent 3e781954
......@@ -124,22 +124,32 @@ int CombatManager::ProcessInput(Keyboard::Event in_event) //why does it return
{
EH::AddEffect3D(EH::Effect::GhoulAttack);
}
if (in_event.GetCode() == 'T') //for testing
{
CM::PendScenario(CM::Scenario::ThrowSand);
}
if (in_event.GetCode() == 'Y') //for testing
{
CM::PendScenario(CM::Scenario::UnsettleDust);
}
if (in_event.GetCode() == 'U') //for testing
if (in_event.GetCode() == 'J') //for testing
{
CM::PendScenario(CM::Scenario::Strike);
EH::AddEffect3D(EH::Effect::PlayerSandThrowDamage);
}
if (in_event.GetCode() == 'I') //for testing
if (in_event.GetCode() == 'K') //for testing
{
CM::PendScenario(CM::Scenario::Defend);
EH::AddEffect3D(EH::Effect::PlayerSandThrow);
}
//if (in_event.GetCode() == 'T') //for testing
//{
// CM::PendScenario(CM::Scenario::ThrowSand);
//}
//if (in_event.GetCode() == 'Y') //for testing
//{
// CM::PendScenario(CM::Scenario::UnsettleDust);
//}
//if (in_event.GetCode() == 'U') //for testing
//{
// CM::PendScenario(CM::Scenario::Strike);
//}
//if (in_event.GetCode() == 'I') //for testing
//{
// CM::PendScenario(CM::Scenario::Defend);
//}
if (curTurn != Turn::NotInCombat)
{
......
......@@ -105,6 +105,8 @@ HudEffect<Effect3DSequence, PlaneTexNorm>::HudEffect(DXGraphics& gfx, Effect3DSe
s.AddBindable(scaleCbuf);
s.AddBindable(Bind::Blender::Resolve(gfx, true)); //alpha usage set to true by default
s.SetTargetPass(1u); //so that they are drawn after models without alpha
BindPositionData(&refPosData);
refPosData.emplace_back();
}
......@@ -201,7 +203,8 @@ void EffectHandler::AddEffect2D(PositionData posData,Effect e)
}
case Effect::Sparks: //is usually called alongside Effect::Shine:
{
e2df.push_back(std::make_unique<Effect2DPhysics>(30u, posData, 1.0f, 10.0f, 1.5f, 0.95f, L"Media\\Sprites\\effect_particle1.png", *gfx));
ParticleBurstData pbd{ 30u, posData, 1.0f, 10.0f, 1.5f, 0.95f };
e2df.push_back(std::make_unique<Effect2DPhysics>( pbd, L"Media\\Sprites\\effect_particle1.png", *gfx));
break;
}
default:
......@@ -214,24 +217,6 @@ void EffectHandler::AddEffect2D(Effect e)
{
switch (e)
{
case Effect::PlayerSandThrowDamage: //is called by Slass sandThrow : public Skill (method void Activate())
{
for (size_t i = 0u; i < 4u; i++)
{
PositionData posData = { RU.GetFloat(-0.1f,0.1), RU.GetFloat(-0.3f,0.3),0.1f,RU.GetFloat(0.0f,2.0f * PI) };
Effect2DSequence e2ds2;
e2ds2.AddStage({ posData.pos.x,posData.pos.y,posData.pos.z, 1.0f, posData.rot.x }, 1.0f);
e2ds2.AddStage({ posData.pos.x,posData.pos.y,posData.pos.z, 1.0f, posData.rot.x }, 0.0f);
EffectHandler::AddEffect2D(e2ds2, L"Media\\Sprites\\Player_SandThrow_damage.png");
Effect2DSequence e2ds1;
e2ds1.AddStage({ posData.pos.x,posData.pos.y,posData.pos.z * 1.0f, 0.8f,posData.rot.x }, 0.65f);
e2ds1.AddStage({ posData.pos.x,posData.pos.y,posData.pos.z * 1.5f, 0.0f,posData.rot.x }, 0.0f);
EffectHandler::AddEffect2D(e2ds1, L"Media\\Sprites\\Player_SandThrow_damage.png");
}
break;
}
case Effect::GhoulIntentShine_Attack: //are called by IntentIconManager
case Effect::GhoulIntentShine_Buff:
case Effect::GhoulIntentShine_Defence:
......@@ -319,6 +304,34 @@ void EffectHandler::AddEffect3D(Effect e)
}
break;
}
case Effect::PlayerSandThrowDamage: //is called by Class sandThrow : public Skill (method void Activate())
{
PositionData posData = { RU.GetFloat(3.85f,3.95f), RU.GetFloat(0.8f,1.2f), RU.GetFloat(0.7f,1.2f),0.0f, 3.0f * PI / 2.0f, RU.GetFloat(-0.4f, 0.4f) + PI / 2.0f };
Effect3DSequence e3ds2;
e3ds2.AddStage({ posData.pos.x + 0.01f,posData.pos.y,posData.pos.z, 1.0f ,1.0f,posData.rot.x,posData.rot.y,posData.rot.z }, 1.0f);
e3ds2.AddStage({ posData.pos.x + 0.01f,posData.pos.y,posData.pos.z, 1.0f ,1.0f,posData.rot.x,posData.rot.y,posData.rot.z }, 0.0f);
EffectHandler::AddEffect3D(e3ds2, L"Media\\Models\\Player_SandThrow_damage.obj", true);
Effect3DSequence e3ds1;
e3ds1.AddStage({ posData.pos.x,posData.pos.y,posData.pos.z , 1.0f ,0.8f,posData.rot.x,posData.rot.y,posData.rot.z }, 0.65f);
e3ds1.AddStage({ posData.pos.x - 1.0f,posData.pos.y,posData.pos.z,1.0f ,0.0f,posData.rot.x,posData.rot.y,posData.rot.z }, 0.0f);
EffectHandler::AddEffect3D(e3ds1, L"Media\\Models\\Player_SandThrow_damage.obj", true);
}
case Effect::PlayerSandThrow: //is called by Class sandThrow : public Skill (method void Activate())
{ // 0.0f, 3.0f * PI / 2.0f, PI / 2.0f
ParticleBurstData pbd{ 10u, {1.5f, 1.0f, 1.0f}, 1.0f, 5.0f, 1.5f, 0.95f };
ParticleSpreadData psd{
{ 0.0f,PI * 0.5,0.0f},
{ PI, PI, PI},
{ 3.9f, -1.0f, -1.0f},
{ 3.9f, 1.0f, 1.0f} };
e3df.push_back(std::make_unique<Effect3DPhysics>(pbd,psd, L"Media\\Models\\Player_SandThrow.obj", *gfx));
break;
}
default:
assert(false && "no such 3D effect exists");
break;
}
}
......@@ -335,6 +348,11 @@ void EffectHandler::SubmitAndUpdate(FrameCommander& fc, float dt)
e->SubmitAndUpdateParticles(fc, dt);
}
e2df.erase(std::remove_if(e2df.begin(), e2df.end(), [](std::unique_ptr <Effect2DPhysics>& o) {return o->isDead; }), e2df.end());
for (auto& e : e3df)
{
e->SubmitAndUpdateParticles(fc, dt);
}
e3df.erase(std::remove_if(e3df.begin(), e3df.end(), [](std::unique_ptr <Effect3DPhysics>& o) {return o->isDead; }), e3df.end());
}
std::optional<Effect2DData> Effect2DSequence::Update(float dt) //make friend of handler
......@@ -356,19 +374,19 @@ std::optional<Effect2DData> Effect2DSequence::Update(float dt) //make friend
}
}
Effect2DPhysics::Effect2DPhysics(size_t particleCount, PositionData particleOrigin, float speedMin, float speedMax, float lifeTime, float friction, std::wstring sprite, DXGraphics& gfx):
lifeTime(lifeTime),
Effect2DPhysics::Effect2DPhysics(ParticleBurstData partData, std::wstring sprite, DXGraphics& gfx):
lifeTime(partData.lifeTime),
particleSprite(sprite, gfx)
{
PositionData po = particleOrigin;
PositionData po = partData.origin;
auto& ru = RU;
po.pos.z *= partScale; //scaling down
for (size_t i = 0; i < particleCount; i++)
for (size_t i = 0; i < partData.count; i++)
{
partPos.push_back(po);
auto speed = ru.GetFloat(speedMin, speedMax);
auto speed = ru.GetFloat(partData.speedMin, partData.speedMax);
auto speedDist = ru.GetFloat0to1();
partVel.emplace_back(ru.GetBool()?speed * speedDist : -speed * speedDist, ru.GetBool() ? speed * (1.0f - speedDist): -speed * (1.0f - speedDist), friction);
partVel.emplace_back(ru.GetBool()?speed * speedDist : -speed * speedDist, ru.GetBool() ? speed * (1.0f - speedDist): -speed * (1.0f - speedDist), partData.friction);
}
particleSprite.BindPositionData(&partPos);
}
......@@ -399,12 +417,6 @@ void Effect2DPhysics::SubmitAndUpdateParticles(FrameCommander& fc, float dt)
}
}
std::vector<std::unique_ptr<HudEffect<Effect2DSequence,HudElement>>> EffectHandler::e2d;
std::vector<std::unique_ptr<HudEffect<Effect3DSequence, PlaneTexNorm>>> EffectHandler::e3d;
std::vector<std::unique_ptr<Effect2DPhysics>> EffectHandler::e2df;
std::vector<std::unique_ptr<HudEffect<Effect3DSequence, PlaneTexNorm>>> EffectHandler::e3dCamFace; //for cam facing 3d effects
DXGraphics* EffectHandler::gfx;
std::optional<Effect3DData> Effect3DSequence::Update(float dt)
{
currentStageTime += dt;
......@@ -423,3 +435,64 @@ std::optional<Effect3DData> Effect3DSequence::Update(float dt)
}
}
}
Effect3DPhysics::Effect3DPhysics(ParticleBurstData burstData, ParticleSpreadData partSpread, std::wstring model, DXGraphics& gfx) :
lifeTime(burstData.lifeTime),
particleModel(model, gfx),
friction(burstData.friction)
{
PositionData pos = burstData.origin;
auto& ru = RU;
for (size_t i = 0; i < burstData.count; i++)
{
partPos.emplace_back(pos.pos.x, pos.pos.y, pos.pos.z,
ru.GetFloat(partSpread.minRollPitchYaw.x, partSpread.maxRollPitchYaw.x),
ru.GetFloat(partSpread.minRollPitchYaw.y, partSpread.maxRollPitchYaw.y),
ru.GetFloat(partSpread.minRollPitchYaw.z, partSpread.maxRollPitchYaw.z));
auto speed = ru.GetFloat(burstData.speedMin, burstData.speedMax);
Vec3 velocity { ru.GetFloat(partSpread.minXYZDir.x,partSpread.maxXYZDir.x),
ru.GetFloat(partSpread.minXYZDir.y,partSpread.maxXYZDir.y),
ru.GetFloat(partSpread.minXYZDir.z,partSpread.maxXYZDir.z)
};
velocity *= speed;
auto speedDist = ru.GetFloat0to1();
partVel.emplace_back(velocity.x,velocity.y,velocity.z);
}
particleModel.BindPositionData(&partPos);
}
void Effect3DPhysics::SubmitAndUpdateParticles(FrameCommander& fc, float dt)
{
curTime += dt;
if (curTime <= lifeTime)
{
for (size_t i = 0; i < partPos.size(); i++)
{
partPos[i].pos.x += (partVel[i].pos.x * dt);
partPos[i].pos.y += (partVel[i].pos.y * dt);
partPos[i].pos.z += (partVel[i].pos.z * dt);
partVel[i].pos.x *= friction;
partVel[i].pos.y *= friction;
partVel[i].pos.z *= friction;
}
}
else
{
isDead = true;
partPos.clear();
partVel.clear();
}
if (partPos.size())
{
particleModel.SmartSubmit(fc, Techniques::Standart);
}
}
std::vector<std::unique_ptr<HudEffect<Effect2DSequence, HudElement>>> EffectHandler::e2d;
std::vector<std::unique_ptr<Effect2DPhysics>> EffectHandler::e2df;
std::vector<std::unique_ptr<HudEffect<Effect3DSequence, PlaneTexNorm>>> EffectHandler::e3d;
std::vector<std::unique_ptr<HudEffect<Effect3DSequence, PlaneTexNorm>>> EffectHandler::e3dCamFace;
std::vector<std::unique_ptr<Effect3DPhysics>> EffectHandler::e3df;
DXGraphics* EffectHandler::gfx;
\ No newline at end of file
......@@ -88,8 +88,8 @@ private:
struct ParticleBurstData
{
size_t particleCount;
PositionData particleOrigin;
size_t count;
PositionData origin;
float speedMin;
float speedMax;
float lifeTime;
......@@ -124,7 +124,7 @@ private:
class Effect3DPhysics
{
public:
Effect3DPhysics(ParticleBurstData burstData, std::wstring model, DXGraphics& gfx);
Effect3DPhysics(ParticleBurstData burstData, ParticleSpreadData partSpread, std::wstring model, DXGraphics& gfx);
Effect3DPhysics(Effect3DPhysics&&) = default;
Effect3DPhysics& operator=(Effect3DPhysics&&) = default;
void SubmitAndUpdateParticles(FrameCommander& fc, float dt); //make friend of handler
......@@ -134,8 +134,8 @@ private:
std::vector<PositionData> partVel; //here PositionData.pos represents velocities and .rot - acceleration
PlaneTexNorm particleModel;
float curTime = 0.0f;
const float friction = 1.0f; //actually the opposite of friction
const float lifeTime;
static constexpr float partScale = 0.025f;
};
template<typename T, typename Base>
......@@ -157,6 +157,17 @@ private:
T effectSequence;
DXGraphics& gfx;
};
class EffectScenario //is used to output same Effect3DPhysics several times with delay
{
public:
EffectScenario(ParticleBurstData burstData, ParticleSpreadData partSpread, std::wstring model, DXGraphics& gfx, size_t times, float delay);
private:
float lifeTime;
float stageTime;
};
#define EH EffectHandler
class EffectHandler
{
......@@ -172,7 +183,9 @@ public:
GhoulAttack,
PlayerSwordAttack,
PlayerSwordAttackUpgraded,
PlayerSandThrowDamage
PlayerSandThrowDamage,
PlayerSandThrow,
PlayerSandStorm
};
EffectHandler(DXGraphics& gfx);
static void AddEffect2D(Effect2DSequence data, std::wstring spriteName);
......@@ -187,6 +200,7 @@ private:
static std::vector<std::unique_ptr<Effect2DPhysics>> e2df;
static std::vector<std::unique_ptr<HudEffect<Effect3DSequence,PlaneTexNorm>>> e3d; //for normal 3d effects
static std::vector<std::unique_ptr<HudEffect<Effect3DSequence, PlaneTexNorm>>> e3dCamFace; //for cam facing 3d effects
static std::vector<std::unique_ptr<Effect3DPhysics>> e3df;
static DXGraphics* gfx;
};
......
......@@ -6,11 +6,11 @@ void FrameCommander::Execute(DXGraphics& gfx, float dt) const noxnd
Rasterizer::Resolve(gfx, true)->Bind(gfx); //backface culling is not needed, because there are literary no backfaces
// main phong lighting pass
Stencil::Resolve(gfx, Stencil::Mode::Off)->Bind(gfx);
passes[0].Execute(gfx);
passes[0].Execute(gfx); //most models
// outline masking pass
//Stencil::Resolve(gfx, Stencil::Mode::Write)->Bind(gfx);
//NullPixelShader::Resolve(gfx)->Bind(gfx);
//passes[1].Execute(gfx);
passes[1].Execute(gfx); //models that generally have alpha, so they are supposed to be drawn after normal models
//// outline drawing pass
//Stencil::Resolve(gfx, Stencil::Mode::Mask)->Bind(gfx);
//passes[2].Execute(gfx);
......
......@@ -36,6 +36,11 @@ bool Step::Bind(DXGraphics& gfx) const
//and there is no need to bind Index or vertex buffers, or topology
}
void Step::SetTargetPass(size_t newPass)
{
targetPass = newPass;
}
void Step::InitializeParentReferences( const Drawable& parent ) noexcept
{
for( auto& b : bindables )
......
......@@ -14,6 +14,7 @@ public:
void DeleteBindableByUID(std::wstring ID);
void Submit( class FrameCommander& frame,const class Drawable& drawable ) const;
bool Bind(DXGraphics& gfx) const;
void SetTargetPass(size_t newPass); //for cheap altering steps
std::vector<std::shared_ptr<Bind::Bindable>>& GetBindables()
{
return bindables;
......
# Blender MTL File: 'None'
# Material Count: 1
newmtl Player_SandThrow_damage
Ns 49.300000
Ka 1.000000 1.000000 1.000000
Kd 1.100000 2.900000 8.300000
Ks 1.300000 0.700000 0.200000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
map_Kd Player_SandThrow_damage.png
\ No newline at end of file
# Blender v2.81 (sub 16) OBJ File: ''
# www.blender.org
mtllib Player_SandThrow_damage.mtl
o Plane
v -0.25000 0.000000 0.25000
v 0.25000 0.000000 0.25000
v -0.25000 0.000000 -0.25000
v 0.25000 0.000000 -0.25000
vt 0.999900 0.999900
vt 0.000100 0.000100
vt 0.999900 0.000100
vt 0.000100 0.999900
vn 0.0000 1.0000 0.0000
usemtl Player_SandThrow_damage
s off
f 2/1/1 3/2/1 1/3/1
f 2/1/1 4/4/1 3/2/1
......@@ -16,8 +16,9 @@ void DustThrow::Activate()
if (upgraded)
{
owner->AddEvent(SkillEvent(EventType::Enemy_PhysicalDamage, dmg, dmg));
EH::AddEffect2D(EH::Effect::PlayerSandThrowDamage);
EH::AddEffect3D(EH::Effect::PlayerSandThrowDamage);
}
EH::AddEffect3D(EH::Effect::PlayerSandThrow);
AM::Alert(AM::Event::PLayerUsedDustThrow);
//std::unique_ptr<scenarios::dustThrowScenario> scen = std::make_unique<scenarios::dustThrowScenario>();
//MainScene::AddScenario(std::move(scen));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment