A few TODOs

This commit is contained in:
2024-05-20 07:51:29 -04:00
parent 8f6c0ea32e
commit 7ac97ae44d
8 changed files with 49 additions and 31 deletions

View File

@@ -88,7 +88,7 @@ CPMAddPackage(
CPMAddPackage(
NAME Collage
URL https://git.redacted.cc/Redacted/Collage/archive/v0.3.zip
URL https://git.redacted.cc/Redacted/Collage/archive/v0.4.zip
)

View File

@@ -1,13 +0,0 @@
start 0.0 0.0 0.0
velocity 2
loop 1
position 0.0 0.0 -3.2
angle 32.6 0
position -2.4 0 -1.3
angle 30.3 60.6 0
position -0.26 0.11 -2.5
angle 38.6 6.6 0.0
position -0.64 -3.42 -2.37
angle -8.5 14.6 0
position 0.0 0.0 -3.2
angle 32.6 0 0

View File

@@ -26,7 +26,8 @@ enum class ENGINE_ERROR_CODE: uint8_t {
SHADER_NOT_FOUND = 6,
MODEL_NOT_FOUND = 7,
MULTI_TEXTURE_SIZE_EXCEEDS = 8,
TEXTURE_ERASED_WHILE_IN_USE = 9
TEXTURE_ERASED_WHILE_IN_USE = 9,
VERTEX_ARRAY_ERASED_WHILE_IN_USE = 10
};
struct EngineError {

View File

@@ -18,4 +18,5 @@ public:
Shader(const char* name, const std::string& filePath, const GLenum& type);
void load(std::string filePath, GLenum type);
void link();
void erase(Shader* shader);
};

View File

@@ -8,6 +8,8 @@
#include <J3ML/LinearAlgebra/Vector2.h>
#include <glad/glad.h>
//Forward declaration of entity.
class Entity;
using J3ML::LinearAlgebra::Vector3;
using J3ML::LinearAlgebra::Vector2;
@@ -23,6 +25,7 @@ public:
std::vector<Vertex> vertices;
std::vector<unsigned int> indices;
std::vector<TextureCoordinate> texCoords;
std::vector<Entity*> usedBy;
VertexArray getBoundingVolume(Vector3 angle);
void rotate(const Vector3& angle);
/// Loads data from an OBJ mesh file to populate the VertexArray
@@ -31,8 +34,9 @@ public:
static void erase(const VertexArray& vArray);
virtual void draw();
void drawWireframe();
VertexArray(const std::string& filename);
explicit VertexArray(const std::string& filename);
VertexArray() = default;
void erase(VertexArray* vArray) const;
GLuint vbo = 0; //Vertices
GLuint ebo = 0; //Indices

View File

@@ -42,10 +42,9 @@ Entity::Entity() {
parent = nullptr;
scale = 1.0f;
//TODO
UUIDv4::UUIDGenerator<std::mt19937_64> uuidGenerator;
UUIDv4::UUID id = uuidGenerator.getUUID();
uuid = id.bytes();
//UUIDv4::UUIDGenerator<std::mt19937_64> uuidGenerator;
//UUIDv4::UUID id = uuidGenerator.getUUID();
//uuid = id.bytes();
}
void Entity::setScale(const float &multiplier) {
@@ -81,6 +80,8 @@ VertexArray* Entity::getGeometry() {
loadGeometry();
for (auto& vArray : engine->world->geometryList)
if (vArray.name == name) {
if (std::find(vArray.usedBy.begin(), vArray.usedBy.end(), this) == vArray.usedBy.end())
vArray.usedBy.push_back(this);
return &vArray;
}
loadGeometry();
@@ -226,20 +227,23 @@ Texture* Entity::getTexture() {
}
void Entity::erase() {
//Remove the usage reference from the list.
Texture* t = getTexture();
VertexArray* vA = getGeometry();
for (int i = 0; i < t->usedBy.size(); i++) {
if (t->usedBy[i] == this) {
for (int i = 0; i < t->usedBy.size(); i++)
if (t->usedBy[i] == this)
t->usedBy.erase(t->usedBy.begin() + i);
//If we just removed the last reference then the texture can be unloaded.
if (t->usedBy.empty())
t->erase();
}
}
if (t->usedBy.empty())
t->erase();
for (int i = 0; i < vA->usedBy.size(); i++)
if (vA->usedBy[i] == this)
vA->usedBy.erase(vA->usedBy.begin() + 1);
if (vA->usedBy.empty())
vA->erase(vA);
//TODO: ^^ Same thing for geometry.
for (int i = 0; i < engine->world->GetChildren().size(); i++)
if (engine->world->GetChildren()[i] == this)
engine->world->GetChildren().erase(engine->world->GetChildren().begin() + i);

View File

@@ -4,7 +4,6 @@
#include <fstream>
#include <sstream>
//TODO Shader::Erase
void compilationError(GLuint shader) {
GLint success;
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
@@ -87,3 +86,15 @@ Shader::Shader(const char *name, const std::string &filePath, const GLenum &type
load(filePath, type);
link();
}
void Shader::erase(Shader* shader) {
if (shader->fragment != 0)
glDeleteProgram(shader->fragment);
if (shader->vertex != 0)
glDeleteProgram(shader->vertex);
if(shader->id != 0)
glDeleteShader(shader->id);
}

View File

@@ -2,7 +2,7 @@
#include <types/vertex.h>
#include <engine/collision.h>
#include <cmath>
#include <types/model.h>
#include <Collage/types/model.h>
void VertexArray::load (const std::string& filename) {
Model m(filename);
vertices = m.getVertices();
@@ -163,6 +163,16 @@ void VertexArray::erase(const VertexArray& vArray) {
}
}
void VertexArray::erase(VertexArray* erasee) const {
if (!usedBy.empty())
engine->setError(ENGINE_ERROR_CODE::VERTEX_ARRAY_ERASED_WHILE_IN_USE, false);
for (int i = 0; i < engine->world->geometryList.size(); i++)
if (&engine->world->geometryList[i] == erasee)
engine->world->geometryList.erase(engine->world->geometryList.begin() + i);
delete erasee;
}
VertexArray::VertexArray(const std::string &filename) {
load(filename);
}