Objects constructor infinite allocation fix

This commit is contained in:
JackCarterSmith 2025-02-07 00:33:23 +01:00
parent 98cac71b2a
commit f9935d6b77
Signed by: JackCarterSmith
GPG Key ID: 832E52F4E23F8F24
6 changed files with 47 additions and 41 deletions

View File

@ -128,11 +128,11 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) {
void Graphic3DRenderer::UpdateInternalTestObjects() { void Graphic3DRenderer::UpdateInternalTestObjects() {
static float thetaAngle = 0.31f; static float thetaAngle = 0.31f;
thetaAngle = thetaAngle >= 6.283185f ? -6.283185f : thetaAngle + 0.004f; thetaAngle = thetaAngle >= M3D_2PI ? -M3D_2PI : thetaAngle + 0.004f;
static float thetaAngle2 = 2.12f; static float thetaAngle2 = 2.12f;
thetaAngle2 = thetaAngle2 >= 6.283185f ? -6.283185f : thetaAngle2 + 0.005f; thetaAngle2 = thetaAngle2 >= M3D_2PI ? -M3D_2PI : thetaAngle2 + 0.005f;
static float thetaAngle3 = -4.78f; static float thetaAngle3 = -4.78f;
thetaAngle3 = thetaAngle3 >= 6.283185f ? -6.283185f : thetaAngle3 + 0.008f; thetaAngle3 = thetaAngle3 >= M3D_2PI ? -M3D_2PI : thetaAngle3 + 0.008f;
mWorldObjsList[0]->SetRotation(thetaAngle, 0.f, thetaAngle * 0.5f); mWorldObjsList[0]->SetRotation(thetaAngle, 0.f, thetaAngle * 0.5f);
mWorldObjsList[1]->SetRotation(thetaAngle2, 0.f, thetaAngle2 * 0.5f); mWorldObjsList[1]->SetRotation(thetaAngle2, 0.f, thetaAngle2 * 0.5f);
mWorldObjsList[2]->SetRotation(thetaAngle3, 0.f, thetaAngle3 * 0.5f); mWorldObjsList[2]->SetRotation(thetaAngle3, 0.f, thetaAngle3 * 0.5f);

View File

@ -2,7 +2,7 @@
Camera::Camera() { Camera::Camera() {
SetFrustrum(90.f, (1280.f/1024.f), 1.0f, 1000.f); SetFrustrum(90.f, (1280.f/1024.f), 1.0f, 100.f);
} }
void Camera::SetFrustrum(float fov, float r, float zn, float zf) { void Camera::SetFrustrum(float fov, float r, float zn, float zf) {

View File

@ -56,23 +56,23 @@ void CockpitUI::Update() {
} }
void CockpitUI::Draw(std::shared_ptr<sf::RenderWindow>& context) { void CockpitUI::Draw(std::shared_ptr<sf::RenderWindow>& context) {
sf::BlendMode sBM = sf::BlendNone; sf::BlendMode sBM = sf::BlendAlpha;
sf::RenderStates sRS(sBM); sf::RenderStates sRS(sBM);
// Clear the UI screen // Clear the UI screen
mUIRender.clear(sf::Color::Transparent); mUIRender.clear(sf::Color::Transparent);
// Draw the static board
sf::Sprite staticBoardSprite(mStaticCockpitTexture);
mUIRender.draw(staticBoardSprite, sRS);
// Draw the radar display // Draw the radar display
sf::CircleShape radar(95, 8); sf::CircleShape radar(95, 8);
radar.setRotation(22.5f); radar.setRotation(22.5f);
radar.setPosition(sf::Vector2f(838,378)); radar.setPosition(sf::Vector2f(838,378));
radar.setFillColor(sf::Color::Yellow); radar.setFillColor(SF_COLOR_4CHEX(0x666666FF));
mUIRender.draw(radar, sRS); mUIRender.draw(radar, sRS);
// Draw the static board
sf::Sprite staticBoardSprite(mStaticCockpitTexture);
mUIRender.draw(staticBoardSprite, sRS);
// Do the final texture render // Do the final texture render
mUIRender.display(); mUIRender.display();

View File

@ -2,6 +2,7 @@
ObjectDbgCube::ObjectDbgCube() { ObjectDbgCube::ObjectDbgCube() {
if (!isMeshLoaded) {
try { try {
mMesh.vertices.resize(8); mMesh.vertices.resize(8);
} catch (const std::length_error& ex) { } catch (const std::length_error& ex) {
@ -34,3 +35,4 @@ ObjectDbgCube::ObjectDbgCube() {
UpdateAABBFromMesh(); UpdateAABBFromMesh();
} }
}

View File

@ -2,5 +2,8 @@
Tank::Tank() { Tank::Tank() {
if (!isMeshLoaded) {
LoadMeshFromObjFile("tank_sample.obj"); LoadMeshFromObjFile("tank_sample.obj");
isMeshLoaded = true;
}
} }

View File

@ -57,6 +57,7 @@ public:
protected: protected:
inline static Mesh mMesh; inline static Mesh mMesh;
inline static bool isMeshLoaded = false;
}; };