2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CFluidPlaneManager.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/World/CExplosion.hpp"
|
|
|
|
#include "Runtime/World/CScriptWater.hpp"
|
2017-03-30 22:36:18 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2017-03-30 22:36:18 +00:00
|
|
|
|
|
|
|
CFluidPlaneManager::CFluidProfile CFluidPlaneManager::sProfile = {};
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CFluidPlaneManager::CFluidPlaneManager() : x0_rippleManager(20, 0.5f) {
|
|
|
|
sProfile.Clear();
|
|
|
|
SetupRippleMap();
|
2017-03-30 22:36:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CFluidPlaneManager::CFluidProfile::Clear() {
|
|
|
|
x0_ = 0.f;
|
|
|
|
x4_ = 0.f;
|
|
|
|
x8_ = 0.f;
|
|
|
|
xc_ = 0.f;
|
|
|
|
x10_ = 0.f;
|
2017-03-30 22:36:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CFluidPlaneManager::StartFrame(bool b) {
|
|
|
|
x121_ = b;
|
|
|
|
sProfile.Clear();
|
2017-03-30 22:36:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CFluidPlaneManager::Update(float dt) {
|
|
|
|
x11c_uvT += dt;
|
|
|
|
x0_rippleManager.Update(dt);
|
|
|
|
for (CSplashRecord& record : x18_splashes) {
|
|
|
|
record.SetTime(record.GetTime() + dt);
|
|
|
|
if (record.GetTime() > 9999.f)
|
|
|
|
record.SetTime(9999.f);
|
|
|
|
}
|
2017-03-30 22:36:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float CFluidPlaneManager::GetLastRippleDeltaTime(TUniqueId rippler) const {
|
|
|
|
return x0_rippleManager.GetLastRippleDeltaTime(rippler);
|
2017-03-30 22:36:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float CFluidPlaneManager::GetLastSplashDeltaTime(TUniqueId splasher) const {
|
|
|
|
float newestTime = 9999.f;
|
|
|
|
for (const CSplashRecord& record : x18_splashes)
|
|
|
|
if (record.GetUniqueId() == splasher && newestTime > record.GetTime())
|
|
|
|
newestTime = record.GetTime();
|
|
|
|
return newestTime;
|
2017-07-05 18:34:12 +00:00
|
|
|
}
|
|
|
|
|
2017-03-30 22:36:18 +00:00
|
|
|
void CFluidPlaneManager::CreateSplash(TUniqueId splasher, CStateManager& mgr, const CScriptWater& water,
|
2018-12-08 05:30:43 +00:00
|
|
|
const zeus::CVector3f& pos, float factor, bool sfx) {
|
|
|
|
if (water.CanRippleAtPoint(pos)) {
|
|
|
|
float oldestTime = 0.f;
|
|
|
|
CSplashRecord* oldestRecord = nullptr;
|
|
|
|
for (CSplashRecord& record : x18_splashes) {
|
|
|
|
if (record.GetTime() > oldestTime) {
|
|
|
|
oldestRecord = &record;
|
|
|
|
oldestTime = record.GetTime();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (oldestRecord)
|
|
|
|
*oldestRecord = CSplashRecord(0.f, splasher);
|
|
|
|
else
|
|
|
|
x18_splashes.emplace_back(0.f, splasher);
|
|
|
|
float splashScale = water.GetSplashEffectScale(factor);
|
|
|
|
if (water.GetSplashEffect(factor)) {
|
|
|
|
CExplosion* expl = new CExplosion(*water.GetSplashEffect(factor), mgr.AllocateUniqueId(), true,
|
|
|
|
CEntityInfo(water.GetAreaIdAlways(), CEntity::NullConnectionList), "Splash",
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CTransform(zeus::CMatrix3f(), pos), 1,
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f{splashScale}, water.GetSplashColor());
|
|
|
|
mgr.AddObject(expl);
|
|
|
|
}
|
|
|
|
if (sfx) {
|
2019-02-24 07:15:54 +00:00
|
|
|
CSfxManager::AddEmitter(water.GetSplashSound(factor), pos, zeus::skUp, true, false, 0x7f,
|
2018-12-08 05:30:43 +00:00
|
|
|
kInvalidAreaId);
|
2018-02-01 23:19:34 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-30 22:36:18 +00:00
|
|
|
}
|
|
|
|
|
2018-06-07 04:43:26 +00:00
|
|
|
static bool g_RippleMapSetup = false;
|
2020-04-12 13:03:28 +00:00
|
|
|
std::array<std::array<u8, 64>, 64> CFluidPlaneManager::RippleValues{};
|
|
|
|
std::array<u8, 64> CFluidPlaneManager::RippleMins{};
|
|
|
|
std::array<u8, 64> CFluidPlaneManager::RippleMaxs{};
|
2018-06-07 04:43:26 +00:00
|
|
|
boo::ObjToken<boo::ITextureS> CFluidPlaneManager::RippleMapTex;
|
2017-08-08 06:03:57 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CFluidPlaneManager::SetupRippleMap() {
|
2020-04-12 13:03:28 +00:00
|
|
|
if (g_RippleMapSetup) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-04-12 13:03:28 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
g_RippleMapSetup = true;
|
|
|
|
|
|
|
|
float curX = 0.f;
|
2020-04-12 13:03:28 +00:00
|
|
|
for (size_t i = 0; i < 64; ++i) {
|
2018-12-08 05:30:43 +00:00
|
|
|
float curY = 0.f;
|
|
|
|
float minY = 1.f;
|
|
|
|
float maxY = 0.f;
|
2020-04-12 13:03:28 +00:00
|
|
|
for (size_t j = 0; j < 64; ++j) {
|
|
|
|
const float rVal = 1.f - curY;
|
2018-12-08 05:30:43 +00:00
|
|
|
float minX = curY;
|
|
|
|
float maxX = 1.25f * (0.25f * rVal + 0.1f) + curY;
|
2020-04-12 13:03:28 +00:00
|
|
|
if (curY < 0.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
minX = 0.f;
|
2020-04-12 13:03:28 +00:00
|
|
|
} else if (maxX > 1.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
maxX = 1.f;
|
2020-04-12 13:03:28 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
float val = 0.f;
|
|
|
|
if (curX >= minX && curX <= maxX) {
|
2020-04-12 13:03:28 +00:00
|
|
|
const float t = (curX - minX) / (maxX - minX);
|
|
|
|
if (t < 0.4f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
val = 2.5f * t;
|
2020-04-12 13:03:28 +00:00
|
|
|
} else if (t > 0.75f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
val = 4.f * (1.f - t);
|
2020-04-12 13:03:28 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
val = 1.f;
|
2020-04-12 13:03:28 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 13:03:28 +00:00
|
|
|
const auto valA = u8(std::max(int(255.f * val * rVal * rVal) - 1, 0));
|
2018-12-08 05:30:43 +00:00
|
|
|
RippleValues[i][j] = valA;
|
2020-04-12 13:03:28 +00:00
|
|
|
if (valA != 0 && curY < minY) {
|
2018-12-08 05:30:43 +00:00
|
|
|
minY = curY;
|
2020-04-12 13:03:28 +00:00
|
|
|
}
|
|
|
|
if (valA != 0 && curY > maxY) {
|
2018-12-08 05:30:43 +00:00
|
|
|
maxY = curY;
|
2020-04-12 13:03:28 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
curY += (1.f / 63.f);
|
2017-08-08 06:03:57 +00:00
|
|
|
}
|
2018-06-07 04:43:26 +00:00
|
|
|
|
2020-04-12 13:03:28 +00:00
|
|
|
const auto valB = u8(std::max(int(255.f * minY) - 1, 0));
|
|
|
|
const auto valC = u8(std::min(int(255.f * maxY) + 1, 255));
|
2018-12-08 05:30:43 +00:00
|
|
|
RippleMins[i] = valB;
|
|
|
|
RippleMaxs[i] = valC;
|
|
|
|
curX += (1.f / 63.f);
|
|
|
|
}
|
|
|
|
|
|
|
|
CGraphics::CommitResources([](boo::IGraphicsDataFactory::Context& ctx) {
|
|
|
|
RippleMapTex = ctx.newStaticTexture(64, 64, 1, boo::TextureFormat::I8, boo::TextureClampMode::ClampToBlack,
|
2020-04-12 13:03:28 +00:00
|
|
|
RippleValues.data(), 64 * 64);
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
|
|
|
} BooTrace);
|
2017-08-08 06:03:57 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|