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
8 changes: 7 additions & 1 deletion src/prune/core/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ namespace prune {
throw std::runtime_error(std::string("Failed to create SDL window: ") + SDL_GetError());
}

Uint32 renderer_flags = SDL_RENDERER_ACCELERATED;

if (config.vsync) {
renderer_flags |= SDL_RENDERER_PRESENTVSYNC;
}

m_renderer = SDL_CreateRenderer(
m_window,
-1,
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC
renderer_flags
);

if (!m_renderer) {
Expand Down
5 changes: 5 additions & 0 deletions src/prune/scene/game_object_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ namespace prune {

void GameObjectManager::select(GameObjectId id) noexcept
{
if (id == kInvalidGameObjectId) {
m_selected_id = kInvalidGameObjectId;
return;
}

if (get_by_id(id) != nullptr) {
m_selected_id = id;
}
Expand Down
7 changes: 7 additions & 0 deletions src/prune/scene/sandbox_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ namespace prune {
void SandboxScene::on_enter()
{
m_objects.clear();
m_player_id = kInvalidGameObjectId;

m_camera = {};
m_grid_options = {};
m_scene_options = {};
m_player_controller = {};

m_player_id = m_objects.create_object(create_player());
m_objects.create_object(create_initial_block());
Expand All @@ -32,6 +38,7 @@ namespace prune {

void SandboxScene::on_exit() {
m_objects.clear();
m_player_id = kInvalidGameObjectId;
}

GameObject SandboxScene::create_player() {
Expand Down
8 changes: 8 additions & 0 deletions src/prune/scene/sandbox_scene_editor.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <algorithm>
#include <cmath>
#include <string>

#include <SDL2/SDL.h>
Expand Down Expand Up @@ -73,6 +74,13 @@ namespace prune {
return;
}

const float length = std::sqrt((move_x * move_x) + (move_y * move_y));

if (length > 0.0f) {
move_x /= length;
move_y /= length;
}

const float move_amount = m_camera.speed * dt;
m_camera.x += move_x * move_amount;
m_camera.y += move_y * move_amount;
Expand Down
2 changes: 0 additions & 2 deletions src/prune/tooling/outliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ namespace prune {

if (ImGui::Button("Add Object (Temp)")) {
const Transform base = next_block_spawn_position(
objects,
static_cast<float>(viewport_width),
static_cast<float>(viewport_height),
camera_x,
Expand Down Expand Up @@ -115,7 +114,6 @@ namespace prune {
}

Transform Outliner::next_block_spawn_position(
GameObjectManager&,
float viewport_width,
float viewport_height,
float camera_x,
Expand Down
1 change: 0 additions & 1 deletion src/prune/tooling/outliner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace prune {
GameObjectId create_block(GameObjectManager& objects, float x, float y);
float random_color_component();
Transform next_block_spawn_position(
GameObjectManager& objects,
float viewport_width,
float viewport_height,
float camera_x,
Expand Down
13 changes: 10 additions & 3 deletions src/prune/tooling/stats.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
#include <string>

#include "prune/tooling/stats.hpp"
#include "prune/tooling/imgui/layout.hpp"
#include "prune/tooling/imgui/property_table.hpp"

namespace prune {

void Stats::draw(GameObjectManager& objects, GameObjectId player_id, int viewport_width, int viewport_height) {
void Stats::draw(GameObjectManager& objects, GameObjectId player_id, int viewport_width, int viewport_height)
{
Comment thread
deanblackborough marked this conversation as resolved.
ImGuiIO& io = ImGui::GetIO();

if (tooling::imgui::layout::collapsing_header("Performance")) {
tooling::imgui::property_table::begin("##performance");
tooling::imgui::property_table::text("FPS", std::to_string(io.Framerate).c_str());
tooling::imgui::property_table::text("Frame time", std::to_string(1000.0f / io.Framerate).c_str());

const float fps = io.Framerate;
const float frame_time_ms = (fps > 0.0f) ? (1000.0f / fps) : 0.0f;

tooling::imgui::property_table::text("FPS", std::to_string(fps).c_str());
tooling::imgui::property_table::text("Frame time", std::to_string(frame_time_ms).c_str());
tooling::imgui::property_table::end();
}

Expand Down
Loading