complete rework of the user interface (using raygui)
This commit is contained in:
35
src/main.cpp
35
src/main.cpp
@ -1,8 +1,10 @@
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <raylib.h>
|
||||
#include <raymath.h>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "gui.hpp"
|
||||
#include "input.hpp"
|
||||
#include "physics.hpp"
|
||||
#include "renderer.hpp"
|
||||
@ -27,7 +29,7 @@ auto main(int argc, char *argv[]) -> int {
|
||||
|
||||
// RayLib window setup
|
||||
SetTraceLogLevel(LOG_ERROR);
|
||||
// SetConfigFlags(FLAG_VSYNC_HINT);
|
||||
SetConfigFlags(FLAG_VSYNC_HINT);
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||
SetConfigFlags(FLAG_WINDOW_ALWAYS_RUN);
|
||||
@ -36,11 +38,17 @@ auto main(int argc, char *argv[]) -> int {
|
||||
// Game setup
|
||||
ThreadedPhysics physics;
|
||||
StateManager state(physics, preset_file);
|
||||
InputHandler input(state);
|
||||
OrbitCamera3D camera;
|
||||
Renderer renderer(camera, state, input);
|
||||
InputHandler input(state, camera);
|
||||
Gui gui(input, state, camera);
|
||||
Renderer renderer(camera, state, input, gui);
|
||||
|
||||
unsigned int ups;
|
||||
std::chrono::time_point last = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> fps_accumulator(0);
|
||||
unsigned int loop_iterations = 0;
|
||||
|
||||
unsigned int fps = 0;
|
||||
unsigned int ups = 0; // Read from physics
|
||||
std::vector<Vector3> masses; // Read from physics
|
||||
|
||||
// Game loop
|
||||
@ -49,6 +57,12 @@ auto main(int argc, char *argv[]) -> int {
|
||||
FrameMarkStart("MainThread");
|
||||
#endif
|
||||
|
||||
// Time tracking
|
||||
std::chrono::time_point now = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> deltatime = now - last;
|
||||
fps_accumulator += deltatime;
|
||||
last = now;
|
||||
|
||||
// Input update
|
||||
input.HandleInput();
|
||||
state.UpdateGraph(); // Add state added after user input
|
||||
@ -86,7 +100,7 @@ auto main(int argc, char *argv[]) -> int {
|
||||
std::size_t current_index = state.CurrentMassIndex();
|
||||
if (masses.size() > current_index) {
|
||||
const Mass ¤t_mass = masses.at(current_index);
|
||||
camera.Update(current_mass.position);
|
||||
camera.Update(current_mass.position, input.camera_lock);
|
||||
}
|
||||
|
||||
// Rendering
|
||||
@ -94,7 +108,16 @@ auto main(int argc, char *argv[]) -> int {
|
||||
renderer.DrawMassSprings(masses);
|
||||
renderer.DrawKlotski();
|
||||
renderer.DrawMenu(masses);
|
||||
renderer.DrawTextures(ups);
|
||||
renderer.DrawTextures(fps, ups);
|
||||
|
||||
if (fps_accumulator.count() > 1.0) {
|
||||
// Update each second
|
||||
fps = loop_iterations;
|
||||
loop_iterations = 0;
|
||||
fps_accumulator = std::chrono::duration<double>(0);
|
||||
}
|
||||
++loop_iterations;
|
||||
|
||||
#ifdef TRACY
|
||||
FrameMark;
|
||||
FrameMarkEnd("MainThread");
|
||||
|
||||
Reference in New Issue
Block a user