2 Commits

Author SHA1 Message Date
145346fac3 update engine components 2024-08-21 21:07:54 -04:00
22711d1db1 Begin refactor to support 2D & 3D Scenes. 2024-08-19 22:31:40 -04:00
30 changed files with 295 additions and 258 deletions

View File

@@ -29,7 +29,7 @@ SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
CPMAddPackage( CPMAddPackage(
NAME ReWindow NAME ReWindow
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-3.zip URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-12.zip
) )
CPMAddPackage( CPMAddPackage(
@@ -44,17 +44,17 @@ CPMAddPackage(
CPMAddPackage( CPMAddPackage(
NAME J3ML NAME J3ML
URL https://git.redacted.cc/josh/j3ml/archive/Release-2.2.zip URL https://git.redacted.cc/josh/j3ml/archive/Release-3.0.zip
) )
CPMAddPackage( CPMAddPackage(
NAME JGL NAME JGL
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-20.zip URL https://git.redacted.cc/josh/JGL/archive/Prerelease-31.zip
) )
CPMAddPackage( CPMAddPackage(
NAME ReTexture NAME ReTexture
URL https://git.redacted.cc/Redacted/ReTexture/archive/Prerelease-2.zip URL https://git.redacted.cc/Redacted/ReTexture/archive/Release-1.2.zip
) )
CPMAddPackage( CPMAddPackage(
@@ -74,7 +74,7 @@ CPMAddPackage(
CPMAddPackage( CPMAddPackage(
NAME Collage NAME Collage
URL https://git.redacted.cc/Redacted/Collage/archive/v0.5.zip URL https://git.redacted.cc/Redacted/Collage/archive/v0.6.zip
) )
CPMAddPackage( CPMAddPackage(
@@ -97,7 +97,6 @@ target_include_directories(Re3D PUBLIC
${ReWindow_SOURCE_DIR}/include ${ReWindow_SOURCE_DIR}/include
#${ReHardwareID_SOURCE_DIR}/include #${ReHardwareID_SOURCE_DIR}/include
${J3ML_SOURCE_DIR}/include ${J3ML_SOURCE_DIR}/include
${ReTexture_SOURCE_DIR}/include
${glad_SOURCE_DIR}/include ${glad_SOURCE_DIR}/include
${UUID_SOURCE_DIR}/include ${UUID_SOURCE_DIR}/include
#${archive_SOURCE_DIR}/include #${archive_SOURCE_DIR}/include
@@ -110,11 +109,11 @@ set_target_properties(Re3D PROPERTIES LINKER_LANGUAGE CXX)
if (UNIX AND NOT APPLE) if (UNIX AND NOT APPLE)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
target_link_libraries(Re3D PUBLIC Event ReWindowLibrary ReTexture J3ML GL glad Collage JGL jlog) target_link_libraries(Re3D PUBLIC Event ReWindowLibrary J3ML GL glad Collage JGL jlog)
endif() endif()
if (WIN32) if (WIN32)
target_link_libraries(Re3D PUBLIC Event ReWindowLibrary ReTexture J3ML glad Collage JGL jlog) target_link_libraries(Re3D PUBLIC Event ReWindowLibrary J3ML glad Collage JGL jlog)
endif() endif()
include(src/demo/RuntimeTest/CMakeLists.txt) include(src/demo/RuntimeTest/CMakeLists.txt)

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <Redacted3D/types/vertex.h> #include <Redacted3D/types/vertex.h>
#include <J3ML/Geometry.h> #include <J3ML/Geometry.hpp>
using J3ML::Geometry::AABB; using J3ML::Geometry::AABB;
using J3ML::Geometry::OBB; using J3ML::Geometry::OBB;

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#include <Redacted3D/types/entity/camera.h> #include <Redacted3D/types/entity/3D/camera.h>
namespace Occlusion { namespace Occlusion {
//TODO //TODO

View File

@@ -3,8 +3,8 @@
#include <Redacted3D/types/vertex.h> #include <Redacted3D/types/vertex.h>
#include <Redacted3D/types/texture.h> #include <Redacted3D/types/texture.h>
#include <Redacted3D/types/shader.h> #include <Redacted3D/types/shader.h>
#include <Redacted3D/types/entity/entity.h> #include <Redacted3D/types/entity/baseEntity.h>
#include <J3ML/LinearAlgebra/Vector3.h> #include <J3ML/LinearAlgebra/Vector3.hpp>
using J3ML::LinearAlgebra::Vector3; using J3ML::LinearAlgebra::Vector3;
using J3ML::LinearAlgebra::Vector2; using J3ML::LinearAlgebra::Vector2;
@@ -24,21 +24,22 @@ class Serializable {
// A wrapper around a Tree Hierarchy Data Model. // A wrapper around a Tree Hierarchy Data Model.
class DataModel : public Entity { class DataModel : public BaseEntity {
public: public:
Entity * GetParent() const override {return nullptr;} [[nodiscard]] BaseEntity* GetParent() const override {return nullptr;}
std::vector<Entity> GetFlatEntityList(); std::vector<Entity> GetFlatEntityList();
template <class T> template <class T>
void Serialize(T& archive) { void Serialize(T& archive) {
Entity::SerializeMemberData(archive); BaseEntity::SerializeMemberData(archive);
archive & GetFlatEntityList(); archive & GetFlatEntityList();
} }
void SetParent(Entity *parent) override { void SetParent(BaseEntity *parent) override {
throw std::runtime_error("Cannot set parent of Hierarchy Root!"); throw std::runtime_error("Cannot set parent of Hierarchy Root!");
} }
DataModel() : Entity() {}
DataModel() : BaseEntity() {}
[[nodiscard]] int getEntityCount() const; [[nodiscard]] int getEntityCount() const;
[[nodiscard]] int getMobyCount() const; [[nodiscard]] int getMobyCount() const;
}; };

View File

@@ -0,0 +1,8 @@
///A moby with skeletal animations.
//TODO
#pragma once
#include <Redacted3D/types/entity/3D/moby.h>
class Actor : public Moby {};

View File

@@ -1,8 +1,8 @@
#pragma once #pragma once
#include <Redacted3D/types/entity/moby.h> #include <Redacted3D/types/entity/3D/moby.h>
#include <Redacted3D/engine/engine.h> #include <Redacted3D/engine/engine.h>
#include <glad/glad.h> #include <glad/glad.h>
#include <J3ML/Geometry.h> #include <J3ML/Geometry.hpp>
using J3ML::LinearAlgebra::Matrix4x4; using J3ML::LinearAlgebra::Matrix4x4;
using J3ML::Geometry::Frustum; using J3ML::Geometry::Frustum;

View File

@@ -1,9 +1,10 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <Redacted3D/types/entity/baseEntity.h>
#include <Redacted3D/types/vertex.h> #include <Redacted3D/types/vertex.h>
#include <Redacted3D/types/texture.h> #include <Redacted3D/types/texture.h>
#include <J3ML/LinearAlgebra/Matrix4x4.h> #include <J3ML/LinearAlgebra/Matrix4x4.hpp>
#include <J3ML/LinearAlgebra/Vector3.h> #include <J3ML/LinearAlgebra/Vector3.hpp>
#include <Redacted3D/engine/collision.h> #include <Redacted3D/engine/collision.h>
//#include <archive.h> //#include <archive.h>
@@ -13,7 +14,7 @@ using J3ML::LinearAlgebra::Vector3;
typedef Vector3 Direction; typedef Vector3 Direction;
///Base entity type. ///Base entity type.
class Entity { class Entity : public BaseEntity {
private: private:
///Pitch Yaw Roll, The orientation of the entity in the world, ///Pitch Yaw Roll, The orientation of the entity in the world,
Vector3 angle = {0,0,0}; Vector3 angle = {0,0,0};
@@ -22,11 +23,6 @@ private:
///The scale it should be rendered at. ///The scale it should be rendered at.
Vector3 scale = {1.0f, 1.0f, 1.0f}; Vector3 scale = {1.0f, 1.0f, 1.0f};
protected: protected:
///If the entity has a parent entity, It's here.
Entity* parent;
///Entity list of child entities.
std::vector<Entity*> children;
///Loads the geometry for it. ///Loads the geometry for it.
void loadGeometry(const std::string& file); void loadGeometry(const std::string& file);
void loadTexture(const std::string& file); void loadTexture(const std::string& file);
@@ -34,23 +30,6 @@ void loadMultiTexture(const std::vector<std::string>& files);
void loadMotionTexture(const std::vector<std::string>& files, u16 frameDelta, bool doAnim = true); void loadMotionTexture(const std::vector<std::string>& files, u16 frameDelta, bool doAnim = true);
public: public:
std::string name; //Entity name. TODO remove this.
bool alive;
virtual std::vector<std::string> GetEntityUUIDList() const { return std::vector<std::string> { "" }; }
template <class T>
void SerializeMemberData(T& archive)
{
archive & uuid.c_str() & name.c_str() & alive;
}
template <class T>
void Serialize(T& archive)
{
SerializeMemberData(archive);
archive & GetEntityUUIDList();
}
///Whether an entity is solid. Entities are solid by default. ///Whether an entity is solid. Entities are solid by default.
bool collidable = true; bool collidable = true;
@@ -64,45 +43,13 @@ public:
Sphere getSphere(); Sphere getSphere();
///Returns the OBB of the entity. ///Returns the OBB of the entity.
OBB getOBB(); OBB getOBB();
///Returns the entity list of the entities children.
std::vector<Entity*> GetChildren();
///Sets a given entity as this entities parent.
virtual void SetParent(Entity* parent);
bool IsDescendantOf(Entity* ancestor);
bool IsAncestorOf(Entity* descendant);
std::vector<Entity*> GetDescendants();
std::vector<Entity*> GetAncestors();
virtual Entity* GetParent() const { return parent;}
Entity* FindFirstChild(std::string search_name);
[[nodiscard]] Entity* GetFamilyTreeRoot() const;
Entity *Add(Entity *newChild);
void setScale(const float& multiplier); void setScale(const float& multiplier);
[[nodiscard]] Vector3 getScale() const; [[nodiscard]] Vector3 getScale() const;
// TODO: Constrain to DerivedEntityType
template <typename T>
T* FindFirstChildOfType() const
{
for (auto& child : children) {
T* p = dynamic_cast<T>(child);
if (p != nullptr)
return p;
}
return nullptr;
}
void DescendantAdded(Entity* ent) {}
void DescendantRemoved(Entity* ent) {}
void AncestorAdded(Entity* ent) {}
void AncestorRemoved(Entity* ent) {}
protected: protected:
Matrix4x4 coordinates; Matrix4x4 coordinates;
J3ML::LinearAlgebra::Position position; /// X Y Z J3ML::LinearAlgebra::Position position; /// X Y Z
public: public:
std::string uuid;
u32 ticksAlive; //At 64tps it'd take 776 days to overflow. u32 ticksAlive; //At 64tps it'd take 776 days to overflow.
[[nodiscard]] Position GetPos() const; [[nodiscard]] Position GetPos() const;
void SetPos(const Position& rhs); void SetPos(const Position& rhs);
@@ -114,19 +61,11 @@ public:
void setAngle(float pitch, float yaw, float roll); void setAngle(float pitch, float yaw, float roll);
///Removes an entity from the list, Checks if the assets are being used by any other entity. Removes them from their lists & deletes. Then deletes the entity. ///Removes an entity from the list, Checks if the assets are being used by any other entity. Removes them from their lists & deletes. Then deletes the entity.
void erase(); void erase();
bool draw = true;
bool occluded(); bool occluded();
bool isCollidingWith(Entity* entity); bool isCollidingWith(Entity* entity);
virtual void pre_render() {}
virtual void post_render() {} ///Default rendering routine. Works in 99% of cases.
virtual void jglRenderPass() {} void render() override;
///The default rendering routine. Works for 99% of cases.
virtual void render();
virtual void update(float elapsed) {}
virtual void ticc(int tics)
{
ticksAlive++;
}
Entity(); Entity();

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <Redacted3D/types/entity/entity.h> #include <Redacted3D/types/entity/3D/entity.h>
///A "Movable Object". Things that will move often are derived from this. ///A "Movable Object". Things that will move often are derived from this.
class Moby : public Entity { class Moby : public Entity {

View File

@@ -1,7 +1,7 @@
#pragma once #pragma once
#include <Redacted3D/types/vertex.h> #include <Redacted3D/types/vertex.h>
#include <Redacted3D/types/entity/moby.h> #include <Redacted3D/types/entity/3D/moby.h>
///Simple skybox, A sphere with a texture on it where the center of the sphere is always the camera. ///Simple skybox, A sphere with a texture on it where the center of the sphere is always the camera.
class Skybox : public Moby { class Skybox : public Moby {

View File

@@ -0,0 +1,67 @@
#pragma once
#include <vector>
#include <string>
#include <J3ML/J3ML.hpp>
class BaseEntity {
protected:
///If the entity has a parent entity, It's here.
BaseEntity* parent;
///Entity list of child entities.
std::vector<BaseEntity*> children;
public:
u32 ticksAlive;
bool draw = true;
std::string uuid;
std::string name;
bool alive;
virtual std::vector<std::string> GetEntityUUIDList() const { return std::vector<std::string> { "" }; }
BaseEntity() = default;
std::vector<BaseEntity*> GetChildren();
///Sets a given entity as this entities parent.
virtual void SetParent(BaseEntity* parent);
bool IsDescendantOf(BaseEntity* ancestor);
bool IsAncestorOf(BaseEntity* descendant);
std::vector<BaseEntity*> GetDescendants();
std::vector<BaseEntity*> GetAncestors();
[[nodiscard]] virtual BaseEntity* GetParent() const { return parent;}
BaseEntity* FindFirstChild(std::string search_name);
[[nodiscard]] BaseEntity* GetFamilyTreeRoot() const;
BaseEntity* Add(BaseEntity* newChild);
void DescendantAdded(BaseEntity* ent) {}
void DescendantRemoved(BaseEntity* ent) {}
void AncestorAdded(BaseEntity* ent) {}
void AncestorRemoved(BaseEntity* ent) {}
template <class T>
void SerializeMemberData(T& archive){ archive & uuid.c_str() & name.c_str() & alive; }
template <class T>
void Serialize(T& archive) {
SerializeMemberData(archive);
archive & GetEntityUUIDList();
}
// TODO: Constrain to DerivedEntityType
template <typename T>
T* FindFirstChildOfType() const
{
for (auto& child : children) {
T* p = dynamic_cast<T>(child);
if (p != nullptr)
return p;
}
return nullptr;
}
virtual void pre_render() {}
virtual void post_render() {}
virtual void jglRenderPass() {}
///The default rendering routine. Works for 99% of cases.
virtual void render() {}
virtual void update(float elapsed) {}
virtual void ticc(int tics) { ticksAlive++; }
};

View File

@@ -3,19 +3,18 @@
#include <glad/glad.h> #include <glad/glad.h>
#include <vector> #include <vector>
#include <string> #include <string>
#include <J3ML/LinearAlgebra.h> #include <J3ML/LinearAlgebra.hpp>
#include <JGL/Texture.h>
#include <chrono> #include <chrono>
//Forward declaration of entity. //Forward declaration of entity.
class Entity; class Entity;
//Base texture. One texture. //Base texture. One texture.
class Texture { class Texture : public JGL::Texture {
public: public:
///Reference counter. ///Reference counter.
std::vector<Entity*> usedBy; std::vector<Entity*> usedBy;
///The id OpenGL uses to keep track of where the texture is in vram.
GLuint id = 0;
///Loads a texture for a given entity type from a file you specify. ///Loads a texture for a given entity type from a file you specify.
void load(Entity* entity, const std::string& file, bool storeOnTextureList); void load(Entity* entity, const std::string& file, bool storeOnTextureList);
///removes texture from texture list and deletes it. ///removes texture from texture list and deletes it.

View File

@@ -1,7 +1,7 @@
#pragma once #pragma once
#include <vector> #include <vector>
#include <J3ML/LinearAlgebra.h> #include <J3ML/LinearAlgebra.hpp>
class Moby; class Moby;

View File

@@ -3,9 +3,9 @@
#include <vector> #include <vector>
#include <Collage/types/animation.h> #include <Collage/types/animation.h>
#include <Collage/types/model.h> #include <Collage/types/model.h>
#include <J3ML/LinearAlgebra/Vector3.h> #include <J3ML/LinearAlgebra/Vector3.hpp>
#include <J3ML/LinearAlgebra/Vector2.h> #include <J3ML/LinearAlgebra/Vector2.hpp>
#include <J3ML/Geometry/OBB.h> #include <J3ML/Geometry/OBB.hpp>
#include <glad/glad.h> #include <glad/glad.h>
///Forward declaration of entity. ///Forward declaration of entity.

View File

@@ -3,7 +3,7 @@
#include <iostream> #include <iostream>
#include <cmath> #include <cmath>
#include <cstdint> #include <cstdint>
#include <Redacted3D/types/entity/moby.h> #include <Redacted3D/types/entity/3D/moby.h>
class Ball : public Moby { class Ball : public Moby {
public: public:

View File

@@ -3,7 +3,7 @@
#include <iostream> #include <iostream>
#include <cmath> #include <cmath>
#include <cstdint> #include <cstdint>
#include <Redacted3D/types/entity/moby.h> #include <Redacted3D/types/entity/3D/moby.h>
class Cube : public Moby { class Cube : public Moby {
public: public:

View File

@@ -1,4 +1,4 @@
#include <Redacted3D/types/entity/skybox.h> #include <Redacted3D/types/entity/3D/skybox.h>
#pragma once #pragma once
class DemoSkybox : public Skybox { class DemoSkybox : public Skybox {

View File

@@ -1,13 +1,12 @@
#pragma once #pragma once
#include <JGL/JGL.h> #include <JGL/JGL.h>
#include <JGL/Colors.h>
namespace Fonts { namespace Fonts {
inline int Jupiteroid = -1; inline JGL::Font Jupiteroid;
inline int ModeSeven = -1; inline JGL::Font ModeSeven;
inline void initFonts() { inline void initFonts() {
Jupiteroid = JGL::LoadFont("assets/fonts/Jupiteroid/JupiteroidRegular.ttf"); Jupiteroid = JGL::Font("assets/fonts/Jupiteroid/JupiteroidRegular.ttf");
ModeSeven = JGL::LoadFont("assets/fonts/modeseven.ttf"); ModeSeven = JGL::Font("assets/fonts/modeseven.ttf");
} }
} }

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#include <Redacted3D/types/entity/camera.h> #include <Redacted3D/types/entity/3D/camera.h>
#include <fonts.h> #include <fonts.h>
class FreeCam : public Camera { class FreeCam : public Camera {

View File

@@ -10,6 +10,7 @@ int main()
engine->window = new ReWindow::RWindow("Re3D Test Application", 1152, 864, RenderingAPI::OPENGL); engine->window = new ReWindow::RWindow("Re3D Test Application", 1152, 864, RenderingAPI::OPENGL);
engine->world = new(World); engine->world = new(World);
Engine::init(); Engine::init();
JGL::InitTextEngine();
JGL::Update(engine->window->getSize()); JGL::Update(engine->window->getSize());
Fonts::initFonts(); Fonts::initFonts();
engine->window->setVsyncEnabled(false); engine->window->setVsyncEnabled(false);
@@ -37,6 +38,7 @@ int main()
skybox->setAngle(0,0,0); skybox->setAngle(0,0,0);
skybox->SetParent(engine->world); skybox->SetParent(engine->world);
JGL::J3D::Init(engine->window->getSize(), engine->fov, engine->farPlane);
engine->renderLoop(); engine->renderLoop();
} }

View File

@@ -1,5 +1,5 @@
#include <freeCam.h> #include <freeCam.h>
#include <JGL/Colors.h> #include <mcolor.h>
void FreeCam::pre_render() { void FreeCam::pre_render() {
if (engine->window->isKeyDown(Keys::W)) if (engine->window->isKeyDown(Keys::W))
@@ -43,17 +43,19 @@ Vector3 textAngle = {0,0,0};
void FreeCam::jglRenderPass() { void FreeCam::jglRenderPass() {
textAngle.x = textAngle.x - (96.f * engine->frameDelta); textAngle.x = textAngle.x - (96.f * engine->frameDelta);
using namespace JGL; using namespace JGL;
J3D::Begin();
J3D::DrawString(JGL::Colors::Red, "Text", {0, -2, 0}, textAngle, 4.f, 32, Fonts::Jupiteroid);
J3D::End();
J3D::Begin();
glDisable(GL_CULL_FACE);
J3D::DrawString(Colors::Red, "Text", {0, -2, 0}, textAngle, 4.f, 32, Fonts::Jupiteroid);
glEnable(GL_CULL_FACE);
J3D::End();
J2D::Begin(); J2D::Begin();
J2D::FillRect({255,0,0,128}, {0, 72}, {100, 100}); J2D::FillRect({255,0,0,128}, {0, 72}, {100, 100});
J2D::FillCircle(JGL::Colors::White, {16, 128}, 12, 16); J2D::FillCircle(Colors::White, {16, 128}, 12, 16);
J2D::DrawString(JGL::Colors::White, "Framerate: " + std::to_string((int) engine->framerate()), 0, -16, 1, 16, Fonts::Jupiteroid); J2D::DrawString(Colors::White, "Framerate: " + std::to_string((int) engine->framerate()), 0, 0, 1, 16, Fonts::Jupiteroid);
J2D::DrawString(JGL::Colors::White, "Framecount: " + std::to_string(engine->frameCount), 0, -33, 1,16, Fonts::Jupiteroid); J2D::DrawString(Colors::White, "Framecount: " + std::to_string(engine->frameCount), 0, 17, 1,16, Fonts::Jupiteroid);
J2D::DrawString(JGL::Colors::White, "Position: " + std::to_string(position.x) + " " + std::to_string(position.y) + " " + std::to_string(position.z), 0, -50, 1,16, Fonts::Jupiteroid); J2D::DrawString(Colors::White, "Position: " + std::to_string(position.x) + " " + std::to_string(position.y) + " " + std::to_string(position.z), 0, 33, 1,16, Fonts::Jupiteroid);
J2D::DrawString(JGL::Colors::White, "ViewAngle: " + std::to_string(getAngle().x) + " " + std::to_string(getAngle().y) + " " + std::to_string(getAngle().z), 0, -67, 1,16, Fonts::Jupiteroid); J2D::DrawString(Colors::White, "ViewAngle: " + std::to_string(getAngle().x) + " " + std::to_string(getAngle().y) + " " + std::to_string(getAngle().z), 0, 50, 1,16, Fonts::Jupiteroid);
J2D::End(); J2D::End();
} }

View File

@@ -2,7 +2,7 @@
#include <thread> #include <thread>
#include <JGL/JGL.h> #include <JGL/JGL.h>
#include <Redacted3D/engine/engine.h> #include <Redacted3D/engine/engine.h>
#include <Redacted3D/types/entity/camera.h> #include <Redacted3D/types/entity/3D/camera.h>
#include <jlog/jlog.hpp> #include <jlog/jlog.hpp>
using namespace J3ML; using namespace J3ML;

View File

@@ -1,5 +1,5 @@
#include <Redacted3D/engine/occlusion.h> #include <Redacted3D/engine/occlusion.h>
#include <Redacted3D/types/entity/entity.h> #include <Redacted3D/types/entity/3D/entity.h>
bool Occlusion::frustumCull(Camera* camera, Entity* entity) { return false; } bool Occlusion::frustumCull(Camera* camera, Entity* entity) { return false; }

View File

@@ -1,5 +1,5 @@
#include <Redacted3D/engine/world.h> #include <Redacted3D/engine/world.h>
#include <Redacted3D/types/entity/moby.h> #include <Redacted3D/types/entity/3D/moby.h>
int DataModel::getEntityCount() const { int DataModel::getEntityCount() const {
@@ -14,108 +14,6 @@ int DataModel::getMobyCount() const {
return count; return count;
} }
void Entity::SetParent(Entity *parent) {
// hold a reference to this so it doesn't get collected as we're working with it
Entity *oldParent = this->parent;
if (parent == oldParent)
return;
// Don't allow for an instance to be parented to itself
if (this == parent)
throw std::runtime_error("Cannot parent a widget to itself");
if (this->IsAncestorOf(parent))
throw std::runtime_error("Cannot create circular object reference");
for (Entity *ancestor: this->GetAncestors()) {
if (oldParent && !ancestor->IsAncestorOf(parent) && parent != ancestor) {
ancestor->DescendantRemoved(this);
for (Entity *descendant: this->GetDescendants()) {
ancestor->DescendantRemoved(descendant);
}
}
}
// Remove ourselves from our parent (if we have one)
if (this->parent) {
parent->children.erase(std::remove(parent->children.begin(), parent->children.end(), this),
parent->children.end());
}
// Update our old parent to the new one
this->parent = parent;
// If our parent is set to nullptr, we can't update it's vector of children
if (!parent) { return; }
parent->children.emplace_back(this);
for (Entity* ancestor: this->GetAncestors()) {
if (!oldParent || !(oldParent->IsDescendantOf(parent) && oldParent != ancestor)) {
ancestor->DescendantAdded(this);
for (auto* descendant : this->GetDescendants()) {
ancestor->DescendantAdded(descendant);
}
}
}
}
bool Entity::IsDescendantOf(Entity *ancestor) {
if (ancestor == nullptr)
return false;
Entity *instance = this;
while (instance->GetParent()) {
instance = instance->GetParent();
if (instance == ancestor)
return true;
}
return false;
}
bool Entity::IsAncestorOf(Entity *descendant) {
if (descendant == nullptr)
return false;
Entity *instance = descendant;
while (instance->GetParent()) {
instance = instance->GetParent();
if (instance == this)
return true;
}
return false;
}
std::vector<Entity *> Entity::GetChildren() {
return this->children;
}
std::vector<Entity *> Entity::GetAncestors() {
std::vector<Entity *> ancestors;
for (Entity *ancestor = this->parent; ancestor; ancestor = ancestor->parent) {
ancestors.push_back(ancestor);
}
return ancestors;
}
std::vector<Entity *> Entity::GetDescendants() {
std::vector<Entity *> descendants;
for (auto& child: this->children) {
descendants.push_back(child);
std::vector<Entity *> recursiveDescendants = child->GetDescendants();
descendants.insert(descendants.end(), recursiveDescendants.begin(), recursiveDescendants.end());
}
return descendants;
}
Entity *Entity::Add(Entity *newChild) {
newChild->SetParent(this);
return newChild;
}
Entity *Entity::GetFamilyTreeRoot() const {
//if (JUI::Scene* scene = dynamic_cast<JUI::Scene*>(parent); scene != nullptr)
// This is retarded, Fix ASAP!
auto parent = this->GetParent();
if (parent->GetParent() == nullptr)
return parent;
return parent->GetFamilyTreeRoot();
}
void World::setAmbientLightColor(GLfloat red, GLfloat green, GLfloat blue) { void World::setAmbientLightColor(GLfloat red, GLfloat green, GLfloat blue) {
GLfloat ambient[4] = {red, green, blue, 0.0f}; GLfloat ambient[4] = {red, green, blue, 0.0f};
globalLightColor.x = red; globalLightColor.y = green; globalLightColor.z = blue; globalLightColor.x = red; globalLightColor.y = green; globalLightColor.z = blue;

View File

@@ -1,5 +1,5 @@
#include <array> #include <array>
#include <Redacted3D/types/entity/camera.h> #include <Redacted3D/types/entity/3D/camera.h>
std::array<GLfloat, 16> lookAt(const Vector3& eye, const Vector3& center, const Vector3& up) { std::array<GLfloat, 16> lookAt(const Vector3& eye, const Vector3& center, const Vector3& up) {
Vector3 f = Vector3::Normalized((center - eye)); Vector3 f = Vector3::Normalized((center - eye));

View File

@@ -1,6 +1,6 @@
#include <Redacted3D/types/entity/entity.h> #include <Redacted3D/types/entity/3D/entity.h>
#include <Redacted3D/engine/occlusion.h> #include <Redacted3D/engine/occlusion.h>
#include <Redacted3D/types/entity/camera.h> #include <Redacted3D/types/entity/3D/camera.h>
#include <Redacted3D/engine/engine.h> #include <Redacted3D/engine/engine.h>
#include <Redacted3D/engine/utils/instanceOf.h> #include <Redacted3D/engine/utils/instanceOf.h>
#include <jlog/jlog.hpp> #include <jlog/jlog.hpp>
@@ -40,7 +40,7 @@ void Entity::SetPos(const Vector3 &rhs) {
Entity::Entity() { Entity::Entity() {
position = {0,0,0}; position = {0,0,0};
ticksAlive = 0; ticksAlive = 0;
children = std::vector<Entity*> (); children = std::vector<BaseEntity*> ();
parent = nullptr; parent = nullptr;
scale = {1.0f, 1.0f, 1.0f}; scale = {1.0f, 1.0f, 1.0f};
@@ -58,18 +58,31 @@ Vector3 Entity::getScale() const {
} }
void Entity::loadTexture(const std::string& file) { void Entity::loadTexture(const std::string& file) {
Texture texture(this, file.c_str(), true); for (const auto* e : engine->world->GetChildren())
if (instanceOf(this, e))
return;
Texture(this, file.c_str(), true);
} }
void Entity::loadMultiTexture(const std::vector<std::string>& files) { void Entity::loadMultiTexture(const std::vector<std::string>& files) {
MultiTexture texture(this, files, true); for (const auto* e : engine->world->GetChildren())
if (instanceOf(this, e))
return;
MultiTexture(this, files, true);
} }
void Entity::loadMotionTexture(const std::vector<std::string>& files, u16 frameDelta, bool doAnim) { void Entity::loadMotionTexture(const std::vector<std::string>& files, u16 frameDelta, bool doAnim) {
for (const auto* e : engine->world->GetChildren())
if (instanceOf(this, e))
return;
MotionTexture(this, files, frameDelta, true, doAnim); MotionTexture(this, files, frameDelta, true, doAnim);
} }
void Entity::loadGeometry(const std::string& file) { void Entity::loadGeometry(const std::string& file) {
for (const auto& e : engine->world->GetChildren())
if (instanceOf(this, e))
return;
VertexArray vArray(this, file, true); VertexArray vArray(this, file, true);
} }
@@ -95,26 +108,26 @@ Texture* Entity::getTexture() {
return nullptr; return nullptr;
} }
inline Texture* baseTexture = new Texture; inline Texture* baseTexture = new Texture();
void Entity::render() { void Entity::render() {
if (!baseTexture) { if (!baseTexture) {
Texture t; GLuint handle;
glGenTextures(1, &t.id); glGenTextures(1, &handle);
glBindTexture(GL_TEXTURE_2D, t.id); glBindTexture(GL_TEXTURE_2D, handle);
unsigned char whitePixel[4] = { 255, 255, 255, 255}; Color4 whitePixel = {255, 255, 255, 255};
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, whitePixel); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &whitePixel);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glActiveTexture(0); glActiveTexture(0);
baseTexture = new Texture(t); baseTexture->SetTextureHandle(handle);
} }
MultiTexture texture; MultiTexture texture;
texture.id = baseTexture->id; texture.SetTextureHandle(baseTexture->GetGLTextureHandle());
if (auto* t = dynamic_cast<MultiTexture*>(getTexture())) { if (auto* t = dynamic_cast<MultiTexture*>(getTexture())) {
texture.multi.emplace_back(*t); texture.multi.emplace_back(*t);
@@ -142,7 +155,7 @@ void Entity::render() {
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindTexture(GL_TEXTURE_2D, texture.id); glBindTexture(GL_TEXTURE_2D, texture.GetGLTextureHandle());
//Texture unit mode. //Texture unit mode.
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
@@ -173,7 +186,7 @@ void Entity::render() {
//Texture unit mode. //Texture unit mode.
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
glBindTexture(GL_TEXTURE_2D, t.id); glBindTexture(GL_TEXTURE_2D, t.GetGLTextureHandle());
i++; i++;
} }
getGeometry()->draw(); getGeometry()->draw();

View File

@@ -1,4 +1,4 @@
#include <Redacted3D/types/entity/moby.h> #include <Redacted3D/types/entity/3D/moby.h>
#include <Redacted3D/engine/engine.h> #include <Redacted3D/engine/engine.h>
using namespace J3ML; using namespace J3ML;

View File

@@ -1,6 +1,6 @@
#include <Redacted3D/types/entity/skybox.h> #include <Redacted3D/types/entity/3D/skybox.h>
#include <Redacted3D/engine/engine.h> #include <Redacted3D/engine/engine.h>
#include <Redacted3D/types/entity/camera.h> #include <Redacted3D/types/entity/3D/camera.h>
void Skybox::pre_render() { void Skybox::pre_render() {
if (engine->world->getActiveCamera() != nullptr) if (engine->world->getActiveCamera() != nullptr)
@@ -10,7 +10,7 @@ void Skybox::pre_render() {
void Skybox::render() { void Skybox::render() {
glPushMatrix(); glPushMatrix();
glTranslatef(position.x ,position.y, position.z); glTranslatef(position.x ,position.y, position.z);
glBindTexture(GL_TEXTURE_2D, getTexture()->id); glBindTexture(GL_TEXTURE_2D, getTexture()->GetGLTextureHandle());
glCullFace(GL_FRONT); glCullFace(GL_FRONT);
glScalef(getScale().x, getScale().y, getScale().z); glScalef(getScale().x, getScale().y, getScale().z);
getGeometry()->draw(); getGeometry()->draw();

View File

@@ -0,0 +1,108 @@
#include <Redacted3D/types/entity/baseEntity.h>
#include <stdexcept>
void BaseEntity::SetParent(BaseEntity* parent) {
// hold a reference to this so it doesn't get collected as we're working with it
BaseEntity* oldParent = this->parent;
if (parent == oldParent)
return;
// Don't allow for an instance to be parented to itself
if (this == parent)
throw std::runtime_error("Cannot parent a widget to itself");
if (this->IsAncestorOf(parent))
throw std::runtime_error("Cannot create circular object reference");
for (BaseEntity* ancestor: this->GetAncestors()) {
if (oldParent && !ancestor->IsAncestorOf(parent) && parent != ancestor) {
ancestor->DescendantRemoved(this);
for (BaseEntity* descendant: this->GetDescendants()) {
ancestor->DescendantRemoved(descendant);
}
}
}
// Remove ourselves from our parent (if we have one)
if (this->parent) {
for (auto it = parent->children.begin(); it != parent->children.end(); ++it) {
if (*it == this) {
parent->children.erase(it);
break;
}
}
}
// Update our old parent to the new one
this->parent = parent;
// If our parent is set to nullptr, we can't update it's vector of children
if (!parent) { return; }
parent->children.emplace_back(this);
for (BaseEntity* ancestor: this->GetAncestors()) {
if (!oldParent || !(oldParent->IsDescendantOf(parent) && oldParent != ancestor)) {
ancestor->DescendantAdded(this);
for (auto* descendant : this->GetDescendants()) {
ancestor->DescendantAdded(descendant);
}
}
}
}
bool BaseEntity::IsDescendantOf(BaseEntity* ancestor) {
if (ancestor == nullptr)
return false;
BaseEntity* instance = this;
while (instance->GetParent()) {
instance = instance->GetParent();
if (instance == ancestor)
return true;
}
return false;
}
bool BaseEntity::IsAncestorOf(BaseEntity* descendant) {
if (descendant == nullptr)
return false;
BaseEntity* instance = descendant;
while (instance->GetParent()) {
instance = instance->GetParent();
if (instance == this)
return true;
}
return false;
}
std::vector<BaseEntity* > BaseEntity::GetChildren() {
return this->children;
}
std::vector<BaseEntity* > BaseEntity::GetAncestors() {
std::vector<BaseEntity* > ancestors;
for (BaseEntity* ancestor = this->parent; ancestor; ancestor = ancestor->parent) {
ancestors.push_back(ancestor);
}
return ancestors;
}
std::vector<BaseEntity* > BaseEntity::GetDescendants() {
std::vector<BaseEntity* > descendants;
for (auto& child: this->children) {
descendants.push_back(child);
std::vector<BaseEntity* > recursiveDescendants = child->GetDescendants();
descendants.insert(descendants.end(), recursiveDescendants.begin(), recursiveDescendants.end());
}
return descendants;
}
BaseEntity* BaseEntity::Add(BaseEntity* newChild) {
newChild->SetParent(this);
return newChild;
}
BaseEntity* BaseEntity::GetFamilyTreeRoot() const {
//if (JUI::Scene* scene = dynamic_cast<JUI::Scene*>(parent); scene != nullptr)
// This is retarded, Fix ASAP!
auto parent = this->GetParent();
if (parent->GetParent() == nullptr)
return parent;
return parent->GetFamilyTreeRoot();
}

View File

@@ -1,16 +1,18 @@
#include <ReTexture/rTexture.h> #include <ReTexture/Texture.h>
#include <Redacted3D/types/texture.h> #include <Redacted3D/types/texture.h>
#include <Redacted3D/engine/engine.h> #include <Redacted3D/engine/engine.h>
void Texture::load(Entity* entity, const std::string& file, bool storeOnTextureList) { //TODO use JGL implementation of texture.
auto* texture = new RTexture(file, {RTextureFlag::INVERT_Y});
glGenTextures(1, &id); void Texture::load(Entity* entity, const std::string& file, bool storeOnTextureList) {
glBindTexture(GL_TEXTURE_2D, id); auto* texture = new ReTexture::SoftwareTexture(file, {ReTexture::TextureFlag::INVERT_Y});
if (texture->format == RTextureFormat::RGBA)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->width, texture->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture->pixelData.data()); glGenTextures(1, &texture_handle);
if (texture->format == RTextureFormat::RGB) glBindTexture(GL_TEXTURE_2D, texture_handle);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture->width, texture->height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->pixelData.data()); if (texture->getTextureFormat() == ReTexture::TextureFormat::RGBA)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->getWidth(), texture->getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, texture->pixelData.data());
if (texture->getTextureFormat() == ReTexture::TextureFormat::RGB)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture->getWidth(), texture->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, texture->pixelData.data());
delete texture; delete texture;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -20,10 +22,10 @@ void Texture::load(Entity* entity, const std::string& file, bool storeOnTextureL
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
//If we can't load the missing texture //If we can't load the missing texture
if (file == "assets/textures/missing.png" && id == 0) if (file == "assets/textures/missing.png" && texture_handle == 0)
engine->setError(ENGINE_ERROR_CODE::TEXTURE_NOT_FOUND, true); engine->setError(ENGINE_ERROR_CODE::TEXTURE_NOT_FOUND, true);
if (id == 0) if (texture_handle == 0)
engine->setError(ENGINE_ERROR_CODE::TEXTURE_NOT_FOUND, false), engine->setError(ENGINE_ERROR_CODE::TEXTURE_NOT_FOUND, false),
load(entity, "assets/textures/missing.png", false); load(entity, "assets/textures/missing.png", false);
@@ -36,12 +38,12 @@ void Texture::erase() {
Texture::erase(this); Texture::erase(this);
} }
Texture::Texture(Entity* entity, const char *filePath, bool storeOnTextureList) { Texture::Texture(Entity* entity, const char* filePath, bool storeOnTextureList) {
load(entity, filePath, storeOnTextureList); load(entity, filePath, storeOnTextureList);
} }
void Texture::erase(Texture* texture) const { void Texture::erase(Texture* texture) const {
glDeleteTextures(1, &texture->id); glDeleteTextures(1, &texture->texture_handle);
//If texture is being deleted while in use. //If texture is being deleted while in use.
//It won't crash the program. But it'll cause the texture to be reloaded from disk unnecessarily. //It won't crash the program. But it'll cause the texture to be reloaded from disk unnecessarily.
@@ -50,7 +52,7 @@ void Texture::erase(Texture* texture) const {
if (auto* t = dynamic_cast<MultiTexture*>(texture)) if (auto* t = dynamic_cast<MultiTexture*>(texture))
for (auto &m : t->multi) for (auto &m : t->multi)
glDeleteTextures(1, &m.id); glDeleteTextures(1, &m.texture_handle);
for (int i = 0; i < engine->world->textureList.size(); i++) for (int i = 0; i < engine->world->textureList.size(); i++)
if (engine->world->textureList[i] == texture) if (engine->world->textureList[i] == texture)
@@ -60,11 +62,11 @@ void Texture::erase(Texture* texture) const {
MultiTexture::MultiTexture(Entity* entity, const std::vector<std::string>& textures, bool storeOnTextureList) { MultiTexture::MultiTexture(Entity* entity, const std::vector<std::string>& textures, bool storeOnTextureList) {
Texture base; Texture base;
for (const auto& t : textures) { for (const auto& t : textures) {
if (id != 0) if (texture_handle != 0)
multi.emplace_back(entity, t.c_str(), false); multi.emplace_back(entity, t.c_str(), false);
else else
base = Texture(entity, t.c_str(), false), base = Texture(entity, t.c_str(), false),
id = base.id, texture_handle = base.GetGLTextureHandle(),
usedBy = base.usedBy; usedBy = base.usedBy;
} }
@@ -89,7 +91,7 @@ MotionTexture::MotionTexture(Entity* entity, const std::vector<std::string>& tex
for (auto& t : extra) for (auto& t : extra)
motion.emplace_back(entity, t.c_str(), false); motion.emplace_back(entity, t.c_str(), false);
id = base.id; texture_handle = base.GetGLTextureHandle();
usedBy = base.usedBy; usedBy = base.usedBy;
if (storeOnTextureList) if (storeOnTextureList)
engine->world->textureList.push_back(new MotionTexture(*this)); engine->world->textureList.push_back(new MotionTexture(*this));

View File

@@ -1,7 +1,7 @@
#include <fstream> #include <fstream>
#include <Redacted3D/types/track.h> #include <Redacted3D/types/track.h>
#include <Redacted3D/engine/engine.h> #include <Redacted3D/engine/engine.h>
#include <Redacted3D/types/entity/moby.h> #include <Redacted3D/types/entity/3D/moby.h>
#include <jlog/jlog.hpp> #include <jlog/jlog.hpp>
Track::Track(const std::string &file, Moby* moby) { Track::Track(const std::string &file, Moby* moby) {