Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ modernize-use-bool-literals,
modernize-use-emplace,
modernize-use-equals-default,
modernize-use-equals-delete,
modernize-use-nodiscard,
modernize-use-noexcept,
modernize-use-nullptr,
modernize-use-override,
Expand All @@ -125,7 +124,6 @@ portability-simd-intrinsics,
readability-avoid-const-params-in-decls,
readability-const-return-type,
readability-container-size-empty,
readability-convert-member-functions-to-static,
readability-delete-null-pointer,
readability-deleted-default,
readability-inconsistent-declaration-parameter-name,
Expand Down
2 changes: 1 addition & 1 deletion src/apps/pong/src/strategies/MinimalLoopStrategy.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ TEST_F(MinimalLoopStrategyTest, HandleEventAndUpdate) {

// Simulate for ball movement

// Render again and check position
// RenderColorBuffer again and check position
strategy.OnUpdate(testWindow, testRenderer, deltaTime);

// Check if the paddle position is updated correctly
Expand Down
2 changes: 2 additions & 0 deletions src/packages/core-imgui/core-imgui/Strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ void Strategy::Init(Core::Window& window, Core::Renderer& renderer) {
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();

ImGui::StyleColorsDark();

ImGui_ImplSDL2_InitForSDLRenderer(window.Get().get(), renderer.Get().get());
ImGui_ImplSDLRenderer2_Init(renderer.Get().get());
}
Expand Down
15 changes: 14 additions & 1 deletion src/packages/core/core/Loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace Core {

Loop::Loop(std::vector<IStrategy*> strategies, int windowWidth, int windowHeight, const char *title)
Loop::Loop(
std::vector<IStrategy*> strategies, int windowWidth, int windowHeight,
const char* title
)
: window(windowWidth, windowHeight, title),
renderer(window.Get()),
strategies(std::move(strategies)),
Expand Down Expand Up @@ -30,6 +33,10 @@ void Loop::RunOneFrame() {
UpdateDeltaTime();
UpdateMsPreviousFrame();

if (deltaTime < 1.0 / fpsLimit) {
SDL_Delay((1.0 / fpsLimit - deltaTime) * 1000);
}

while (SDL_PollEvent(&event)) {
for (auto& strategy : strategies) {
strategy->HandleEvent(event);
Expand All @@ -42,8 +49,14 @@ void Loop::RunOneFrame() {

for (auto& strategy : strategies) {
strategy->OnBeforeRender(window, renderer);
}
for (auto& strategy : strategies) {
strategy->OnUpdate(window, renderer, deltaTime);
}
for (auto& strategy : strategies) {
strategy->OnRender(window, renderer);
}
for (auto& strategy : strategies) {
strategy->OnAfterRender(window, renderer);
}

Expand Down
1 change: 1 addition & 0 deletions src/packages/core/core/Loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Loop {
public:
double msPreviousFrame;
double deltaTime = 0;
double fpsLimit = 60;

explicit Loop(std::vector<IStrategy*> strategies, int windowWidth = 800, int windowHeight = 600, const char *title = "CPP Starter");

Expand Down
6 changes: 3 additions & 3 deletions src/packages/ecs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class PositionSystem : public ECS::System {
public:
PositionSystem() { RequireComponent<PositionComponent>(); }

void Render() {
void RenderColorBuffer() {
for (auto entity : GetSystemEntities()) {
auto& component = ECS::Registry::Instance().GetComponent<PositionComponent>(entity);
component.x += 1;
Expand All @@ -36,8 +36,8 @@ main() {
EXPECT_FLOAT_EQ(position.x, 0);
EXPECT_FLOAT_EQ(position.y, 0);

ECS::Registry::Instance().Render();
ECS::Registry::Instance().GetSystem<PositionSystem>().Render();
ECS::Registry::Instance().RenderColorBuffer();
ECS::Registry::Instance().GetSystem<PositionSystem>().RenderColorBuffer();

EXPECT_FLOAT_EQ(position.x, 1);
EXPECT_FLOAT_EQ(position.y, 1);
Expand Down