Migrating (1 sec)
This commit is contained in:
@@ -29,7 +29,8 @@ add_library(SDL3D SHARED ${SOURCES}
|
||||
src/engine/engine.cpp
|
||||
src/types/entity.cpp
|
||||
src/types/moby.cpp
|
||||
src/types/camera.cpp)
|
||||
src/types/camera.cpp
|
||||
src/types/vector.cpp)
|
||||
# Why god???
|
||||
set_target_properties(SDL3D PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
||||
|
@@ -1,12 +1,39 @@
|
||||
#include <thread>
|
||||
#include "engine/tick.h"
|
||||
#include "engine/render.h"
|
||||
#include "engine/render.h"1
|
||||
|
||||
class App
|
||||
{
|
||||
public:
|
||||
int Status;
|
||||
virtual void Run()
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
class GameApp : public App
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
class glDemoGameApp : public GameApp
|
||||
{
|
||||
public:
|
||||
void Run() override
|
||||
{
|
||||
std::thread renderThread(render_loop);
|
||||
std::thread tickThread (gameTick);
|
||||
renderThread.join();
|
||||
tickThread.join();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::thread renderThread(render_loop);
|
||||
std::thread tickThread (gameTick);
|
||||
renderThread.join();
|
||||
tickThread.join();
|
||||
return 0;
|
||||
auto* app = new glDemoGameApp();
|
||||
app->Run();
|
||||
return app->Status;
|
||||
}
|
||||
|
||||
#define WINDOWS_SMH
|
||||
|
@@ -10,10 +10,14 @@
|
||||
|
||||
void process_sdl_events() {
|
||||
while (SDL_PollEvent(&engine->event)) {
|
||||
|
||||
// TODO: Consider switch statements as opposed to ifs
|
||||
// This adds control flow in the form of "break" statement.
|
||||
// Which will save checking every single event type unnecessarily
|
||||
|
||||
// IMO premature optimization
|
||||
// I personally dislike deciphering switch statements aswell
|
||||
|
||||
if (engine->event.type == SDL_QUIT) {engine->quit();}
|
||||
if (engine->event.type == SDL_DROPFILE) {}
|
||||
|
||||
@@ -40,6 +44,7 @@ void process_sdl_events() {
|
||||
}
|
||||
|
||||
void pre_render() {
|
||||
// NO
|
||||
if(engine->frameCount == 0) {
|
||||
engine->initVideo();
|
||||
engine->initGL();
|
||||
|
@@ -6,14 +6,35 @@
|
||||
#include "entityList.h"
|
||||
#include <GL/glu.h>
|
||||
|
||||
#include "glm/ext/matrix_transform.hpp"
|
||||
|
||||
enum class CameraMode: uint8_t {
|
||||
THIRD_PERSON = 0,
|
||||
FREECAM = 1,
|
||||
SCRIPTED_MOVE = 2
|
||||
};
|
||||
|
||||
const glm::vec3 UP = {0, 1, 0};
|
||||
|
||||
class Camera : public Moby {
|
||||
protected:
|
||||
public:
|
||||
|
||||
glm::mat4x4 GetViewMatrix()
|
||||
{
|
||||
//return glm::lookAt(position, position + angle, UP);
|
||||
}
|
||||
|
||||
void MoveForward(float dist);
|
||||
void StrafeLeft(float dist);
|
||||
void StrafeRight(float dist);
|
||||
void TurnLeft(float deg = 90);
|
||||
void TurnRight(float deg = 90);
|
||||
|
||||
void LookAt(glm::vec3 pos, glm::vec3 target, glm::vec3 upaxis = UP) {}
|
||||
void Rotate(float amt, glm::vec3 axis) { }
|
||||
void Translate(glm::vec3 dir) { }
|
||||
|
||||
float fov;
|
||||
Camera() : Moby(), fov(60)
|
||||
{
|
||||
@@ -93,12 +114,13 @@ public:
|
||||
}
|
||||
|
||||
void render() {
|
||||
// Preferrably: Camera would return a coordinate system that GameEngine
|
||||
// would set gluLookAt() with, this helps keep objects self contained
|
||||
this->angle.clamp();
|
||||
glRotatef(angle.x,1.0f, 0.0f, 0.0f);
|
||||
glRotatef(-angle.y,0.0f, 1.0f, 0.0f);
|
||||
|
||||
glTranslatef(0.0f, 0.0f, 0.0f);
|
||||
|
||||
gluLookAt(position.x, position.y, position.z, // camera position
|
||||
position.x, position.y, engine->farPlane+position.z, // target position, We're always *looking at* the far plane straight ahead so the camera never turns around.
|
||||
upVector.x,upVector.y,upVector.z);
|
||||
|
@@ -22,7 +22,7 @@ public:
|
||||
|
||||
void destruct() {
|
||||
//TODO: Search entity list for this entity and remove it to avoid use-after-free.
|
||||
// Nah. This should be the concern of the object managing entities. Entity.h should JUST provide entity behavior.
|
||||
// Non. This should be the concern of the object managing entities. Entity.h should JUST provide entity behavior.
|
||||
}
|
||||
|
||||
virtual void pre_render() {}
|
||||
|
@@ -2,16 +2,66 @@
|
||||
#include <cstdint>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <bits/ranges_algo.h>
|
||||
|
||||
#include <glm/ext/scalar_constants.hpp>
|
||||
|
||||
class vector3 {
|
||||
inline float lerp(float a, float b, float t) {
|
||||
|
||||
}
|
||||
|
||||
// A stab at a vector<length> implementation suitable for game engineering
|
||||
template <std::size_t length>
|
||||
class numeric_vector<length> {
|
||||
public:
|
||||
virtual float operator[](std::size_t index) = 0;
|
||||
};
|
||||
|
||||
class vector2 : public numeric_vector<2> {};
|
||||
class vector3 : public numeric_vector<3>
|
||||
{
|
||||
public:
|
||||
float x = 0; //pitch
|
||||
float y = 0; //yaw
|
||||
float z = 0; //roll
|
||||
public:
|
||||
vector3() : x(0), y(0), z(0) {}
|
||||
vector3(float X, float Y, float Z): x(X), y(Y), z(Z) {}
|
||||
vector3(const vector3&); // Copy
|
||||
vector3(vector3&&) = default;
|
||||
vector3(const vector2&);
|
||||
|
||||
float operator[](std::size_t index) override;
|
||||
bool IsWithinMarginOfError(const vector3& rhs, float margin=0.001f) const;
|
||||
bool operator == (const vector3& rhs) const;
|
||||
bool operator != (const vector3& rhs) const;
|
||||
vector3 min(const vector3& min) const;
|
||||
vector3 max(const vector3& max) const;
|
||||
vector3 clamp(const vector3& min, const vector3& max) const;
|
||||
float distance(const vector3& to) const;
|
||||
float length() const;
|
||||
float lengthSquared() const;
|
||||
float magnitude() const;
|
||||
float dot(const vector3& rhs) const;
|
||||
vector3 project(const vector3& rhs) const;
|
||||
vector3 cross(const vector3& rhs) const;
|
||||
vector3 normalize() const;
|
||||
vector3 lerp(const vector3& goal, float alpha) const;
|
||||
vector3 operator+(const vector3& rhs) const;
|
||||
vector3 operator-(const vector3& rhs) const;
|
||||
float operator*(const vector3& rhs) const
|
||||
{
|
||||
return this->dot(rhs);
|
||||
}
|
||||
vector3 operator/(const vector3& rhs) const;
|
||||
vector3 operator*(float rhs) const;
|
||||
vector3 operator/(float rhs) const;
|
||||
vector3 operator+() const;
|
||||
vector3 operator-() const;
|
||||
};
|
||||
|
||||
class vector4 : public numeric_vector<4> {};
|
||||
|
||||
class Angle : public vector3 {
|
||||
public:
|
||||
bool operator==(const Angle& a) const {
|
||||
|
@@ -11,10 +11,9 @@ void Engine::quit() const {
|
||||
|
||||
float Engine::getGLVersion()
|
||||
{
|
||||
//std::string str = reinterpret_cast<const char *>(glGetString(GL_VERSION));
|
||||
//str.erase(str.begin()+3,str.end());
|
||||
// return std::stof(str);
|
||||
return 1.4f;
|
||||
std::string str = reinterpret_cast<const char *>(glGetString(GL_VERSION));
|
||||
str.erase(str.begin()+3,str.end());
|
||||
return std::stof(str);
|
||||
}
|
||||
|
||||
void Engine::initGL()
|
||||
|
Reference in New Issue
Block a user