Refactor renderer and input handling; add OBJ loader and math utilities
- Updated renderer.h to replace Vec3 and Vec2 structs with Math namespace equivalents. - Introduced Texture struct to manage texture properties. - Modified Triangle struct to use Texture instead of GLuint for texture handling. - Removed deprecated matrix functions and replaced them with Math namespace methods. - Implemented InputManager class for better input handling, including key and mouse state tracking. - Added ObjLoader class to load OBJ files and associated textures, with MTL file parsing. - Created math utilities for fixed-point arithmetic and vector/matrix operations. - Added time management class for frame timing and delta time calculations.
This commit is contained in:
32
Engine/time/time_manager.cpp
Normal file
32
Engine/time/time_manager.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "time_manager.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
Time::Time()
|
||||
: lastFrameTime(glfwGetTime())
|
||||
, currentFrameTime(lastFrameTime)
|
||||
, deltaTime(0)
|
||||
, elapsedTime(0.0f) {
|
||||
}
|
||||
|
||||
void Time::Update() {
|
||||
currentFrameTime = glfwGetTime();
|
||||
float deltaTimeSeconds = static_cast<float>(currentFrameTime - lastFrameTime);
|
||||
|
||||
// Store delta time in fixed-point and update elapsed time
|
||||
deltaTime = SecondsToFixed(deltaTimeSeconds);
|
||||
elapsedTime += deltaTimeSeconds;
|
||||
|
||||
lastFrameTime = currentFrameTime;
|
||||
}
|
||||
|
||||
int32_t Time::GetDeltaTime() const {
|
||||
return deltaTime;
|
||||
}
|
||||
|
||||
float Time::GetElapsedTime() const {
|
||||
return elapsedTime;
|
||||
}
|
||||
|
||||
int32_t Time::SecondsToFixed(float seconds) const {
|
||||
return static_cast<int32_t>(seconds * FIXED_POINT_SCALE);
|
||||
}
|
||||
32
Engine/time/time_manager.h
Normal file
32
Engine/time/time_manager.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef TIME_H
|
||||
#define TIME_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
class Time {
|
||||
public:
|
||||
Time();
|
||||
|
||||
// Update time and calculate delta time (call each frame)
|
||||
void Update();
|
||||
|
||||
// Get delta time in seconds (fixed-point representation)
|
||||
int32_t GetDeltaTime() const;
|
||||
|
||||
// Get total elapsed time in seconds
|
||||
float GetElapsedTime() const;
|
||||
|
||||
private:
|
||||
// Fixed-point scale for PS1-style precision
|
||||
static constexpr int32_t FIXED_POINT_SCALE = 4096; // 12-bit fractional part
|
||||
|
||||
double lastFrameTime; // Last frame timestamp (in seconds, GLFW time)
|
||||
double currentFrameTime; // Current frame timestamp
|
||||
int32_t deltaTime; // Delta time in fixed-point
|
||||
float elapsedTime; // Total elapsed time in seconds
|
||||
|
||||
// Convert float seconds to fixed-point
|
||||
int32_t SecondsToFixed(float seconds) const;
|
||||
};
|
||||
|
||||
#endif // TIME_H
|
||||
Reference in New Issue
Block a user