mirror of https://github.com/AxioDL/metaforce.git
CFluidPlaneManager: Make use of std::array where applicable
Eliminates any potential implicit array to pointer decay.
This commit is contained in:
parent
2069694b59
commit
3c8619ba44
|
@ -79,53 +79,58 @@ void CFluidPlaneManager::CreateSplash(TUniqueId splasher, CStateManager& mgr, co
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool g_RippleMapSetup = false;
|
static bool g_RippleMapSetup = false;
|
||||||
u8 CFluidPlaneManager::RippleValues[64][64] = {};
|
std::array<std::array<u8, 64>, 64> CFluidPlaneManager::RippleValues{};
|
||||||
u8 CFluidPlaneManager::RippleMins[64] = {};
|
std::array<u8, 64> CFluidPlaneManager::RippleMins{};
|
||||||
u8 CFluidPlaneManager::RippleMaxs[64] = {};
|
std::array<u8, 64> CFluidPlaneManager::RippleMaxs{};
|
||||||
boo::ObjToken<boo::ITextureS> CFluidPlaneManager::RippleMapTex;
|
boo::ObjToken<boo::ITextureS> CFluidPlaneManager::RippleMapTex;
|
||||||
|
|
||||||
void CFluidPlaneManager::SetupRippleMap() {
|
void CFluidPlaneManager::SetupRippleMap() {
|
||||||
if (g_RippleMapSetup)
|
if (g_RippleMapSetup) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
g_RippleMapSetup = true;
|
g_RippleMapSetup = true;
|
||||||
|
|
||||||
float curX = 0.f;
|
float curX = 0.f;
|
||||||
for (int i = 0; i < 64; ++i) {
|
for (size_t i = 0; i < 64; ++i) {
|
||||||
float curY = 0.f;
|
float curY = 0.f;
|
||||||
float minY = 1.f;
|
float minY = 1.f;
|
||||||
float maxY = 0.f;
|
float maxY = 0.f;
|
||||||
for (int j = 0; j < 64; ++j) {
|
for (size_t j = 0; j < 64; ++j) {
|
||||||
float rVal = 1.f - curY;
|
const float rVal = 1.f - curY;
|
||||||
float minX = curY;
|
float minX = curY;
|
||||||
float maxX = 1.25f * (0.25f * rVal + 0.1f) + curY;
|
float maxX = 1.25f * (0.25f * rVal + 0.1f) + curY;
|
||||||
if (curY < 0.f)
|
if (curY < 0.f) {
|
||||||
minX = 0.f;
|
minX = 0.f;
|
||||||
else if (maxX > 1.f)
|
} else if (maxX > 1.f) {
|
||||||
maxX = 1.f;
|
maxX = 1.f;
|
||||||
|
}
|
||||||
|
|
||||||
float val = 0.f;
|
float val = 0.f;
|
||||||
if (curX >= minX && curX <= maxX) {
|
if (curX >= minX && curX <= maxX) {
|
||||||
float t = (curX - minX) / (maxX - minX);
|
const float t = (curX - minX) / (maxX - minX);
|
||||||
if (t < 0.4f)
|
if (t < 0.4f) {
|
||||||
val = 2.5f * t;
|
val = 2.5f * t;
|
||||||
else if (t > 0.75f)
|
} else if (t > 0.75f) {
|
||||||
val = 4.f * (1.f - t);
|
val = 4.f * (1.f - t);
|
||||||
else
|
} else {
|
||||||
val = 1.f;
|
val = 1.f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto valA = u8(std::max(int(255.f * val * rVal * rVal) - 1, 0));
|
const auto valA = u8(std::max(int(255.f * val * rVal * rVal) - 1, 0));
|
||||||
RippleValues[i][j] = valA;
|
RippleValues[i][j] = valA;
|
||||||
if (valA != 0 && curY < minY)
|
if (valA != 0 && curY < minY) {
|
||||||
minY = curY;
|
minY = curY;
|
||||||
if (valA != 0 && curY > maxY)
|
}
|
||||||
|
if (valA != 0 && curY > maxY) {
|
||||||
maxY = curY;
|
maxY = curY;
|
||||||
|
}
|
||||||
|
|
||||||
curY += (1.f / 63.f);
|
curY += (1.f / 63.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto valB = u8(std::max(int(255.f * minY) - 1, 0));
|
const auto valB = u8(std::max(int(255.f * minY) - 1, 0));
|
||||||
auto valC = u8(std::min(int(255.f * maxY) + 1, 255));
|
const auto valC = u8(std::min(int(255.f * maxY) + 1, 255));
|
||||||
RippleMins[i] = valB;
|
RippleMins[i] = valB;
|
||||||
RippleMaxs[i] = valC;
|
RippleMaxs[i] = valC;
|
||||||
curX += (1.f / 63.f);
|
curX += (1.f / 63.f);
|
||||||
|
@ -133,7 +138,7 @@ void CFluidPlaneManager::SetupRippleMap() {
|
||||||
|
|
||||||
CGraphics::CommitResources([](boo::IGraphicsDataFactory::Context& ctx) {
|
CGraphics::CommitResources([](boo::IGraphicsDataFactory::Context& ctx) {
|
||||||
RippleMapTex = ctx.newStaticTexture(64, 64, 1, boo::TextureFormat::I8, boo::TextureClampMode::ClampToBlack,
|
RippleMapTex = ctx.newStaticTexture(64, 64, 1, boo::TextureFormat::I8, boo::TextureClampMode::ClampToBlack,
|
||||||
RippleValues, 64 * 64);
|
RippleValues.data(), 64 * 64);
|
||||||
return true;
|
return true;
|
||||||
} BooTrace);
|
} BooTrace);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,9 +44,9 @@ class CFluidPlaneManager {
|
||||||
static void SetupRippleMap();
|
static void SetupRippleMap();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static u8 RippleValues[64][64];
|
static std::array<std::array<u8, 64>, 64> RippleValues;
|
||||||
static u8 RippleMins[64];
|
static std::array<u8, 64> RippleMins;
|
||||||
static u8 RippleMaxs[64];
|
static std::array<u8, 64> RippleMaxs;
|
||||||
static boo::ObjToken<boo::ITextureS> RippleMapTex;
|
static boo::ObjToken<boo::ITextureS> RippleMapTex;
|
||||||
|
|
||||||
CFluidPlaneManager();
|
CFluidPlaneManager();
|
||||||
|
|
Loading…
Reference in New Issue