Little things

This commit is contained in:
2023-12-11 11:29:08 -05:00
parent 233861d467
commit d48c2c1096
13 changed files with 70 additions and 24 deletions

View File

@@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD 20)
add_executable(SDL3D src/main.cpp
src/types/entity.h
src/types/camera.h
src/types/world.h
src/engine/world.h
src/engine/engine.h
src/types/vector3.h
src/types/player.h
@@ -16,6 +16,7 @@ add_executable(SDL3D src/main.cpp
src/types/skybox.h
src/types/moby.h
src/types/animation/scriptedMove.h
src/engine/occlusion.h
)
find_package(OpenGL)

View File

@@ -1,4 +1,4 @@
Fullscreen: 0
Resolution: 1152 864
Debug: 1
Resolution: 1024 768
Debug: 0
CameraFOV: 72.5

View File

@@ -133,6 +133,8 @@ public:
std::cerr << "SDL_Error: " << SDL_GetError() << std::endl;
exit(1);
}
//Seed RNG.
srand(time(nullptr));
}
void debugInfo() const {

11
src/engine/occlusion.h Normal file
View File

@@ -0,0 +1,11 @@
#pragma once
#include "world.h"
namespace Occlusion {
inline void frustumCull() {
if (!world->loaded())
return;
//if ()
}
}

View File

@@ -4,7 +4,7 @@
#include "engine.h"
#include "../types/camera.h"
#include "../types/skybox.h"
#include "../types/world.h"
#include "world.h"
void process_sdl_events() {

View File

@@ -3,7 +3,7 @@
#include <chrono>
#include <thread>
#include "engine.h"
#include "../types/world.h"
#include "world.h"
#include "../types/camera.h"
[[noreturn]] void gameTick() {

View File

@@ -1,7 +1,7 @@
#pragma once
#include "vertex.h"
#include "entity.h"
#include "../engine/engine.h"
#include "../types/vertex.h"
#include "../types/entity.h"
class World {
public:
@@ -15,6 +15,12 @@ public:
entityList.push_back(e);
}
[[nodiscard]] inline bool loaded() const {
if (name.empty())
return false;
return true;
}
inline void load(const char* filename) {
std::ifstream file(filename);
if (!file.is_open()) {
@@ -28,12 +34,12 @@ public:
std::string prefix;
stream >> prefix;
//world name.
if (prefix == "name:") {
if (prefix == "Name:") {
std::string x;
stream >> x;
name = x;
}
else if (prefix == "geometry:") {
else if (prefix == "Geometry:") {
std::string x;
stream >> x;
levelGeometry.load("../models/worlds/"+x);
@@ -45,6 +51,18 @@ public:
//engine->quit();
//}
}
//TODO: Determine the inherited class of the entity and return that pointer instead.
//*Will probably be a pain in the ass*
//Will probably need some kind of forward declaration or per class basis stuff.
inline Entity* getEntityFromUUID(uint16_t UUID) {
for (auto& e : entityList)
if (e->UUID == UUID)
return e;
std::cerr << "Error: Tried to return pointer to entity which is not in the world." << std::endl;
engine->quit();
}
};
World* world = new(World);

View File

@@ -6,7 +6,7 @@
#include <iostream>
#include "../vector3.h"
#include "../../engine/engine.h"
#include "../world.h"
#include "../../engine/world.h"
//A "scripted move" is a vector of points and angles that function as keyframes.
//A moby will follow *and interpolate* between those points.

View File

@@ -3,7 +3,7 @@
#include "player.h"
#include "../engine/engine.h"
#include <glm/glm.hpp>
#include "world.h"
#include "../engine/world.h"
enum class CameraMode: uint8_t {
THIRD_PERSON = 0,
@@ -105,6 +105,6 @@ inline Camera* getCamera() {
for (auto& e : world->entityList)
if (auto* c = dynamic_cast<Camera*>(e))
return c;
std::cerr << "Attempt to get Camera pointer while not in scene." << std::endl;
std::cerr << "Error: Your world must have a camera." << std::endl;
engine->quit();
}

View File

@@ -8,10 +8,24 @@ public:
bool collidable = true;
uint32_t ticksAlive = 0; //At 64tps it'd take 776 days to overflow.
Position position = {0,0,0}; //X Y Z
uint16_t UUID;
Entity() {
//Assign UUID.
//TODO This has the potential to be very slow.
//It'd RNG roll a ton of times. Allocate a char and roll 4 uint8_t's and cast to char
//So the UUID is effectively 4 ascii characters.
int result;
do result = rand();
while (result < 0 || 65535 < result);
UUID = result;
}
void destruct() {
//TODO: Search entity list for this entity and remove it to avoid use-after-free.
delete this;
}
virtual ~Entity() {}
virtual void pre_render() {}
virtual void post_render() {}
virtual void render() {}
virtual ~Entity() = default;
};

View File

@@ -1,6 +1,5 @@
#pragma once
#include <tuple>
#include "entity.h"
#include "animation/scriptedMove.h"
@@ -12,7 +11,6 @@ public:
Angle velAngle = {0,0,0}; //The angle of an entities velocity.
vector3 upVector = {0.0f,1.0f,0.0f};
ScriptedMove scriptedMove;
void move(Angle a, float speed) {
this->position.z += (speed*engine->frameDelta) * a.x;
this->position.y += (speed*engine->frameDelta) * a.y;

View File

@@ -3,12 +3,11 @@
#include <iostream>
#include <cmath>
#include "moby.h"
#include "world.h"
#include "../engine/world.h"
#include "../engine/engine.h"
#include "vertex.h"
class Player : public Moby {
public:
bool alive;
uint8_t health;
uint8_t state;
Position cameraTarget;//The point where the 3rd-person camera will want to look at.
@@ -16,7 +15,11 @@ public:
//Each type of entity will have an "update" function and a "render" function.
//These will be declared in each type of entity and not in the base entity because
//It'll be different for each one.
[[nodiscard]] bool alive() const {
if (health == 0)
return false;
return true;
}
//The "camera point" is the position the camera will want to be while following the player.
//We will probably end up having a different camera point class controlled by the "world".
Position cameraPoint (float distance) {
@@ -60,6 +63,6 @@ inline Player* getPlayer() {
for (auto& e : world->entityList)
if (auto* p = dynamic_cast<Player*>(e) )
return p;
std::cerr << "Attempt to get Player pointer while not in scene." << std::endl;
std::cerr << "Error: Your world must have a player." << std::endl;
engine->quit();
}

View File

@@ -1,7 +1,7 @@
#pragma once
#include <SDL2/SDL_opengl.h>
#include "world.h"
#include "../engine/world.h"
#include "moby.h"
#include "camera.h"
#include "vertex.h"
@@ -24,13 +24,12 @@ public:
//geometry.draw();
glPopMatrix();
}
};
inline Skybox* getSkybox() {
for (auto& e : world->entityList)
if (auto* s = dynamic_cast<Skybox*>(e))
return s;
std::cerr << "Attempt to get Skybox pointer while not in scene." << std::endl;
std::cerr << "Error: Your world must have a skybox." << std::endl;
engine->quit();
}