Skip to content
This repository was archived by the owner on Nov 17, 2024. It is now read-only.

Commit 977651f

Browse files
committed
Full interface working & super cool
1 parent 150532b commit 977651f

26 files changed

+471
-37
lines changed

.idea/cmake.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Game/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ SET(GAME_SOURCES
2121
Map/TerrainGenerator.cpp
2222
Map/ChunkContainer.hpp
2323
Map/ChunkContainer.cpp
24-
)
24+
UISystem/UiText.cpp UISystem/UiText.hpp UISystem/UiButton.cpp UISystem/UiButton.hpp UISystem/UiInputInt.cpp UISystem/UiInputInt.hpp UISystem/UISliderFloat.cpp UISystem/UISliderFloat.hpp UISystem/UiSliderInt.cpp UISystem/UiSliderInt.hpp)
2525

2626
# Packages
2727
find_package(GLEW REQUIRED)

Game/GameLoop/GameLoop.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ GameLoop* GameLoop::s_instance = nullptr;
1515
const sf::ContextSettings contextSettings = sf::ContextSettings(24, 8, 4, 4, 6);
1616

1717
GameLoop::GameLoop()
18-
: window(sf::VideoMode(1000, 800), "Game", sf::Style::Default, contextSettings)
18+
: window(sf::VideoMode(1700, 1000), "Game", sf::Style::Default, contextSettings)
1919
// Dirty way to manage camera lifetime i will refactor it later
2020
, camera(new GameCamera(window))
2121
{
@@ -40,12 +40,12 @@ void GameLoop::Init()
4040

4141
ImGui::SFML::Init(window);
4242

43-
//ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable;
44-
//auto& io = ImGui::GetIO();
45-
46-
//io.ConfigWindowsMoveFromTitleBarOnly = false;
47-
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
43+
// Can't be used because of our dumb version of imgui & OpenGL
44+
// ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable;
45+
auto& io = ImGui::GetIO();
4846

47+
io.ConfigWindowsMoveFromTitleBarOnly = false;
48+
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
4949

5050
m_scene->AddObject<GameCamera>(camera);
5151
m_scene->Init();

Game/GameLoop/Scene.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ void Scene::Update(float dt)
1010
{
1111
updatable->Update(dt);
1212
}
13+
14+
OnUpdate(dt);
1315
}
1416

1517
void Scene::Render(Camera& camera)

Game/GameLoop/Scene.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ class Scene
6565
std::remove(m_objects.begin(), m_objects.end(), object);
6666
}
6767

68+
protected:
69+
virtual void OnUpdate(float deltaTime) {};
70+
6871
protected:
6972
// Only purpose is to manage objects lifetime
7073
std::vector<std::unique_ptr<void, void(*)(void const*)>> m_objects;

Game/Map/ChunkContainer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct ChunkContainer
2424
const Chunk& operator()(int32_t x, int32_t z) const;
2525

2626
[[nodiscard]] std::vector<Chunk*>& GetActiveChunks() { return m_activeChunks; }
27+
[[nodiscard]] const std::vector<Chunk*>& GetActiveChunks() const { return m_activeChunks; }
2728
[[nodiscard]] std::map<ChunkContainerIndex, Chunk>& GetData() { return m_data; }
2829

2930
private:

Game/Map/TerrainGenerator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ void TerrainGenerator::GenerateNewChunks(int32_t chunkX, int32_t chunkZ)
3636

3737
void TerrainGenerator::GenerateAllChunks(int playerPosX, int playerPosZ)
3838
{
39+
m_needToGenerateAllChunks = false;
3940
m_terrain->Cleanup();
4041

4142
m_perlin.~PerlinNoise();

Game/Map/TerrainGenerator.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class TerrainGenerator : public IUpdatable
2222
[[nodiscard]] int GetSeed() const { return m_seed; };
2323
void SetSeed(unsigned int seed);
2424

25+
bool IsNeedToGenerateAllChunks() const { return m_needToGenerateAllChunks; }
26+
void SetNeedToGenerateAllChunks() { m_needToGenerateAllChunks = true; }
2527
public:
2628
int m_seed = 0;
2729

@@ -46,4 +48,6 @@ class TerrainGenerator : public IUpdatable
4648
//Debug number of new chunks generated
4749
int m_newGeneratedChunks = 0;
4850
ChunkContainer::ChunkContainerIndex m_lastChunkIndex { 0, 0 };
51+
52+
bool m_needToGenerateAllChunks = false;
4953
};

Game/Renderer/Renderable/Terrain/Chunk.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class Chunk : public IRenderable
2525
void Render(Camera& camera) override;
2626
void Cleanup() override;
2727

28-
bool IsGenerated() const { return m_generated; }
28+
[[nodiscard]] bool IsGenerated() const { return m_generated; }
29+
[[nodiscard]] size_t GetVerticesCount() const { return m_vertices.size() / 5; }
2930

3031
private:
3132
bool m_generated = false;

Game/Renderer/Renderable/Terrain/Terrain.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,13 @@ void Terrain::GenerateVertices()
9393
chunk.Load();
9494
}
9595
}
96+
97+
size_t Terrain::GetTotalVertices() const
98+
{
99+
size_t totalVertices = 0;
100+
101+
for (const auto *chunk: m_chunks.GetActiveChunks())
102+
totalVertices += chunk->GetVerticesCount();
103+
104+
return totalVertices;
105+
}

0 commit comments

Comments
 (0)