Skip to content

Commit

Permalink
memory leaks and shush
Browse files Browse the repository at this point in the history
  • Loading branch information
Kade-github committed Apr 24, 2024
1 parent b39c8c7 commit ba60b1c
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 43 deletions.
14 changes: 7 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
cmake_minimum_required(VERSION 3.27)

if (WIN32)
# /ENTRY:mainCRTStartup keeps the same "main" function instead of requiring "WinMain"
set(SUBSYSTEM_LINKER_OPTIONS "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
else()
set(SUBSYSTEM_LINKER_OPTIONS "-mwindows")
endif()

project(
TheFrim
VERSION 1.0
Expand Down Expand Up @@ -63,13 +70,6 @@ link_directories(bassLibrary)

add_executable(TheFrim ${SOURCE_FILES})

if (WIN32)
# /ENTRY:mainCRTStartup keeps the same "main" function instead of requiring "WinMain"
set(SUBSYSTEM_LINKER_OPTIONS "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
else()
set(SUBSYSTEM_LINKER_OPTIONS "-mwindows")
endif()

set_target_properties(TheFrim PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
Expand Down
13 changes: 11 additions & 2 deletions src/CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "clang_cl_x64" ]
},
Expand All @@ -58,6 +56,17 @@
"rsyncCommandArgs": "-t --delete",
"remoteCopyBuildOutput": false,
"remoteCopySourcesMethod": "rsync"
},
{
"name": "x64-Release-x86",
"generator": "Ninja",
"configurationType": "Release",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "clang_cl_x86" ],
"addressSanitizerEnabled": true
}
]
}
1 change: 1 addition & 0 deletions src/Engine/Objects/2DCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Camera2D::Camera2D(glm::vec3 pos) : GameObject(pos)

}


void Camera2D::Resize()
{
glm::vec2 size = Game::instance->GetWindowSize();
Expand Down
5 changes: 5 additions & 0 deletions src/Engine/Objects/2DGameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ class GameObject2D : public GameObject

}

~GameObject2D()
{
draws = {};
}

Texture* t = NULL;
Shader* s = NULL;

Expand Down
2 changes: 1 addition & 1 deletion src/Game/Objects/Base/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class Block

virtual void OnInteract() {};

virtual void Update(int tick) {};
virtual bool Update(int tick) { return true; };

void Draw(std::vector<GameObject::VVertex>& verts, std::vector<unsigned int>& inds);

Expand Down
11 changes: 7 additions & 4 deletions src/Game/Objects/Base/Blocks/Water.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,21 @@ void Water::PlaceWater(glm::vec3 _pos, int _strength)
changedBlocks = true;
}

void Water::Update(int tick) // water functionality
bool Water::Update(int tick) // water functionality
{
if (strength == 0 || tick % 8 != 0 || currentChunk == nullptr)
return;
if (strength == 0 || currentChunk == nullptr)
return true;

std::vector<glm::vec3> freeSpaces = GetFreeSpaces(position);

if (tick % 8 != 0 || (freeSpaces.size() != 0 && tick % 8 != 0))
return false;

for (glm::vec3 freeSpace : freeSpaces)
{
Chunk* c = WorldManager::instance->GetChunk(freeSpace.x, freeSpace.z);

PlaceWater(freeSpace, strength - 1);
}

return true;
}
2 changes: 1 addition & 1 deletion src/Game/Objects/Base/Blocks/Water.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Water : public Block

void PlaceWater(glm::vec3 _pos, int _strength);

void Update(int tick) override;
bool Update(int tick) override;
};

#endif
18 changes: 14 additions & 4 deletions src/Game/Objects/Base/Chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,9 @@ void Chunk::DestroySubChunk(int y)
{
subChunk* sbc = GetSubChunk(y);

if (sbc == nullptr)
return;

DestroySubChunk(sbc);
}

Expand All @@ -845,12 +848,14 @@ void Chunk::DestroySubChunk(subChunk* c)
}

delete c;

subChunks.erase(std::remove(subChunks.begin(), subChunks.end(), c), subChunks.end());
}

void Chunk::DestroySubChunks()
{
for (int i = 0; i < subChunks.size(); i++)
DestroySubChunk(subChunks[i]->y);
for (int i = CHUNK_HEIGHT; i > -1; i--)
DestroySubChunk(i);

subChunks.clear();
}
Expand Down Expand Up @@ -1077,7 +1082,10 @@ void Chunk::UpdateChunk(int tick)
modified = false;
}

if (wasModified)
if (wasModified || keepUpdating)
{
if (keepUpdating)
keepUpdating = false;
for (int i = 0; i < subChunks.size(); i++)
{
subChunk* sbc = subChunks[i];
Expand All @@ -1094,8 +1102,10 @@ void Chunk::UpdateChunk(int tick)
if (b == nullptr)
continue;

b->Update(tick);
if (!b->Update(tick))
keepUpdating = true;
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Game/Objects/Base/Chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Chunk : public GameObject
void CreateFaces(Block* b);

void ApplyNormal(std::vector<GameObject::VVertex>& vertices, glm::vec3 normal);

bool keepUpdating = false;

int shadowSize = 0;
int size = 0;
Expand Down
8 changes: 0 additions & 8 deletions src/Game/Objects/Base/Hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,6 @@ Hud::Hud(glm::vec3 _pos, Player* _p, Camera2D* _c2d) : GameObject(_pos)

Hud::~Hud()
{
delete crosshair;

for (auto h : hotbar)
{
c2d->RemoveObject(h);
Expand Down Expand Up @@ -335,12 +333,6 @@ Hud::~Hud()
}

armor.clear();

delete hand;
delete pauseBackground;
delete resume;
delete title;
delete pauseHeader;
}

void Hud::Draw()
Expand Down
Loading

0 comments on commit ba60b1c

Please sign in to comment.