Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
145346fac3 | |||
22711d1db1 |
@@ -29,7 +29,7 @@ SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
|
||||
|
||||
CPMAddPackage(
|
||||
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(
|
||||
@@ -44,17 +44,17 @@ CPMAddPackage(
|
||||
|
||||
CPMAddPackage(
|
||||
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(
|
||||
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(
|
||||
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(
|
||||
@@ -74,7 +74,7 @@ CPMAddPackage(
|
||||
|
||||
CPMAddPackage(
|
||||
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(
|
||||
@@ -97,7 +97,6 @@ target_include_directories(Re3D PUBLIC
|
||||
${ReWindow_SOURCE_DIR}/include
|
||||
#${ReHardwareID_SOURCE_DIR}/include
|
||||
${J3ML_SOURCE_DIR}/include
|
||||
${ReTexture_SOURCE_DIR}/include
|
||||
${glad_SOURCE_DIR}/include
|
||||
${UUID_SOURCE_DIR}/include
|
||||
#${archive_SOURCE_DIR}/include
|
||||
@@ -110,11 +109,11 @@ set_target_properties(Re3D PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
||||
if (UNIX AND NOT APPLE)
|
||||
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()
|
||||
|
||||
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()
|
||||
|
||||
include(src/demo/RuntimeTest/CMakeLists.txt)
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <Redacted3D/types/vertex.h>
|
||||
#include <J3ML/Geometry.h>
|
||||
#include <J3ML/Geometry.hpp>
|
||||
|
||||
using J3ML::Geometry::AABB;
|
||||
using J3ML::Geometry::OBB;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <Redacted3D/types/entity/camera.h>
|
||||
#include <Redacted3D/types/entity/3D/camera.h>
|
||||
|
||||
namespace Occlusion {
|
||||
//TODO
|
||||
|
@@ -3,8 +3,8 @@
|
||||
#include <Redacted3D/types/vertex.h>
|
||||
#include <Redacted3D/types/texture.h>
|
||||
#include <Redacted3D/types/shader.h>
|
||||
#include <Redacted3D/types/entity/entity.h>
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
#include <Redacted3D/types/entity/baseEntity.h>
|
||||
#include <J3ML/LinearAlgebra/Vector3.hpp>
|
||||
|
||||
using J3ML::LinearAlgebra::Vector3;
|
||||
using J3ML::LinearAlgebra::Vector2;
|
||||
@@ -24,21 +24,22 @@ class Serializable {
|
||||
|
||||
|
||||
// A wrapper around a Tree Hierarchy Data Model.
|
||||
class DataModel : public Entity {
|
||||
class DataModel : public BaseEntity {
|
||||
public:
|
||||
Entity * GetParent() const override {return nullptr;}
|
||||
[[nodiscard]] BaseEntity* GetParent() const override {return nullptr;}
|
||||
std::vector<Entity> GetFlatEntityList();
|
||||
|
||||
template <class T>
|
||||
void Serialize(T& archive) {
|
||||
Entity::SerializeMemberData(archive);
|
||||
BaseEntity::SerializeMemberData(archive);
|
||||
archive & GetFlatEntityList();
|
||||
}
|
||||
|
||||
void SetParent(Entity *parent) override {
|
||||
void SetParent(BaseEntity *parent) override {
|
||||
throw std::runtime_error("Cannot set parent of Hierarchy Root!");
|
||||
}
|
||||
DataModel() : Entity() {}
|
||||
|
||||
DataModel() : BaseEntity() {}
|
||||
[[nodiscard]] int getEntityCount() const;
|
||||
[[nodiscard]] int getMobyCount() const;
|
||||
};
|
||||
|
8
include/Redacted3D/types/entity/3D/actor.h
Normal file
8
include/Redacted3D/types/entity/3D/actor.h
Normal file
@@ -0,0 +1,8 @@
|
||||
///A moby with skeletal animations.
|
||||
//TODO
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Redacted3D/types/entity/3D/moby.h>
|
||||
|
||||
class Actor : public Moby {};
|
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
#include <Redacted3D/types/entity/moby.h>
|
||||
#include <Redacted3D/types/entity/3D/moby.h>
|
||||
#include <Redacted3D/engine/engine.h>
|
||||
#include <glad/glad.h>
|
||||
#include <J3ML/Geometry.h>
|
||||
#include <J3ML/Geometry.hpp>
|
||||
|
||||
using J3ML::LinearAlgebra::Matrix4x4;
|
||||
using J3ML::Geometry::Frustum;
|
@@ -1,9 +1,10 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <Redacted3D/types/entity/baseEntity.h>
|
||||
#include <Redacted3D/types/vertex.h>
|
||||
#include <Redacted3D/types/texture.h>
|
||||
#include <J3ML/LinearAlgebra/Matrix4x4.h>
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
#include <J3ML/LinearAlgebra/Matrix4x4.hpp>
|
||||
#include <J3ML/LinearAlgebra/Vector3.hpp>
|
||||
#include <Redacted3D/engine/collision.h>
|
||||
//#include <archive.h>
|
||||
|
||||
@@ -13,7 +14,7 @@ using J3ML::LinearAlgebra::Vector3;
|
||||
typedef Vector3 Direction;
|
||||
|
||||
///Base entity type.
|
||||
class Entity {
|
||||
class Entity : public BaseEntity {
|
||||
private:
|
||||
///Pitch Yaw Roll, The orientation of the entity in the world,
|
||||
Vector3 angle = {0,0,0};
|
||||
@@ -22,11 +23,6 @@ private:
|
||||
///The scale it should be rendered at.
|
||||
Vector3 scale = {1.0f, 1.0f, 1.0f};
|
||||
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.
|
||||
void loadGeometry(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);
|
||||
|
||||
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.
|
||||
bool collidable = true;
|
||||
|
||||
@@ -64,45 +43,13 @@ public:
|
||||
Sphere getSphere();
|
||||
///Returns the OBB of the entity.
|
||||
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);
|
||||
[[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:
|
||||
Matrix4x4 coordinates;
|
||||
J3ML::LinearAlgebra::Position position; /// X Y Z
|
||||
public:
|
||||
std::string uuid;
|
||||
u32 ticksAlive; //At 64tps it'd take 776 days to overflow.
|
||||
[[nodiscard]] Position GetPos() const;
|
||||
void SetPos(const Position& rhs);
|
||||
@@ -114,19 +61,11 @@ public:
|
||||
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.
|
||||
void erase();
|
||||
bool draw = true;
|
||||
bool occluded();
|
||||
bool isCollidingWith(Entity* entity);
|
||||
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++;
|
||||
}
|
||||
|
||||
///Default rendering routine. Works in 99% of cases.
|
||||
void render() override;
|
||||
|
||||
Entity();
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#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.
|
||||
class Moby : public Entity {
|
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#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.
|
||||
class Skybox : public Moby {
|
67
include/Redacted3D/types/entity/baseEntity.h
Normal file
67
include/Redacted3D/types/entity/baseEntity.h
Normal 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++; }
|
||||
};
|
@@ -3,19 +3,18 @@
|
||||
#include <glad/glad.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
#include <J3ML/LinearAlgebra.hpp>
|
||||
#include <JGL/Texture.h>
|
||||
#include <chrono>
|
||||
|
||||
//Forward declaration of entity.
|
||||
class Entity;
|
||||
|
||||
//Base texture. One texture.
|
||||
class Texture {
|
||||
class Texture : public JGL::Texture {
|
||||
public:
|
||||
///Reference counter.
|
||||
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.
|
||||
void load(Entity* entity, const std::string& file, bool storeOnTextureList);
|
||||
///removes texture from texture list and deletes it.
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
#include <J3ML/LinearAlgebra.hpp>
|
||||
|
||||
class Moby;
|
||||
|
||||
|
@@ -3,9 +3,9 @@
|
||||
#include <vector>
|
||||
#include <Collage/types/animation.h>
|
||||
#include <Collage/types/model.h>
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
#include <J3ML/LinearAlgebra/Vector2.h>
|
||||
#include <J3ML/Geometry/OBB.h>
|
||||
#include <J3ML/LinearAlgebra/Vector3.hpp>
|
||||
#include <J3ML/LinearAlgebra/Vector2.hpp>
|
||||
#include <J3ML/Geometry/OBB.hpp>
|
||||
#include <glad/glad.h>
|
||||
|
||||
///Forward declaration of entity.
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <Redacted3D/types/entity/moby.h>
|
||||
#include <Redacted3D/types/entity/3D/moby.h>
|
||||
|
||||
class Ball : public Moby {
|
||||
public:
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <Redacted3D/types/entity/moby.h>
|
||||
#include <Redacted3D/types/entity/3D/moby.h>
|
||||
|
||||
class Cube : public Moby {
|
||||
public:
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include <Redacted3D/types/entity/skybox.h>
|
||||
#include <Redacted3D/types/entity/3D/skybox.h>
|
||||
#pragma once
|
||||
|
||||
class DemoSkybox : public Skybox {
|
||||
|
@@ -1,13 +1,12 @@
|
||||
#pragma once
|
||||
#include <JGL/JGL.h>
|
||||
#include <JGL/Colors.h>
|
||||
|
||||
namespace Fonts {
|
||||
inline int Jupiteroid = -1;
|
||||
inline int ModeSeven = -1;
|
||||
inline JGL::Font Jupiteroid;
|
||||
inline JGL::Font ModeSeven;
|
||||
|
||||
inline void initFonts() {
|
||||
Jupiteroid = JGL::LoadFont("assets/fonts/Jupiteroid/JupiteroidRegular.ttf");
|
||||
ModeSeven = JGL::LoadFont("assets/fonts/modeseven.ttf");
|
||||
Jupiteroid = JGL::Font("assets/fonts/Jupiteroid/JupiteroidRegular.ttf");
|
||||
ModeSeven = JGL::Font("assets/fonts/modeseven.ttf");
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <Redacted3D/types/entity/camera.h>
|
||||
#include <Redacted3D/types/entity/3D/camera.h>
|
||||
#include <fonts.h>
|
||||
|
||||
class FreeCam : public Camera {
|
||||
|
@@ -10,6 +10,7 @@ int main()
|
||||
engine->window = new ReWindow::RWindow("Re3D Test Application", 1152, 864, RenderingAPI::OPENGL);
|
||||
engine->world = new(World);
|
||||
Engine::init();
|
||||
JGL::InitTextEngine();
|
||||
JGL::Update(engine->window->getSize());
|
||||
Fonts::initFonts();
|
||||
engine->window->setVsyncEnabled(false);
|
||||
@@ -37,6 +38,7 @@ int main()
|
||||
skybox->setAngle(0,0,0);
|
||||
skybox->SetParent(engine->world);
|
||||
|
||||
JGL::J3D::Init(engine->window->getSize(), engine->fov, engine->farPlane);
|
||||
engine->renderLoop();
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#include <freeCam.h>
|
||||
#include <JGL/Colors.h>
|
||||
#include <mcolor.h>
|
||||
|
||||
void FreeCam::pre_render() {
|
||||
if (engine->window->isKeyDown(Keys::W))
|
||||
@@ -43,17 +43,19 @@ Vector3 textAngle = {0,0,0};
|
||||
void FreeCam::jglRenderPass() {
|
||||
textAngle.x = textAngle.x - (96.f * engine->frameDelta);
|
||||
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::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(JGL::Colors::White, "Framecount: " + std::to_string(engine->frameCount), 0, -33, 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(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, "Framerate: " + std::to_string((int) engine->framerate()), 0, 0, 1, 16, Fonts::Jupiteroid);
|
||||
J2D::DrawString(Colors::White, "Framecount: " + std::to_string(engine->frameCount), 0, 17, 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(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();
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#include <thread>
|
||||
#include <JGL/JGL.h>
|
||||
#include <Redacted3D/engine/engine.h>
|
||||
#include <Redacted3D/types/entity/camera.h>
|
||||
#include <Redacted3D/types/entity/3D/camera.h>
|
||||
#include <jlog/jlog.hpp>
|
||||
|
||||
using namespace J3ML;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#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; }
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#include <Redacted3D/engine/world.h>
|
||||
#include <Redacted3D/types/entity/moby.h>
|
||||
#include <Redacted3D/types/entity/3D/moby.h>
|
||||
|
||||
|
||||
int DataModel::getEntityCount() const {
|
||||
@@ -14,108 +14,6 @@ int DataModel::getMobyCount() const {
|
||||
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) {
|
||||
GLfloat ambient[4] = {red, green, blue, 0.0f};
|
||||
globalLightColor.x = red; globalLightColor.y = green; globalLightColor.z = blue;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#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) {
|
||||
Vector3 f = Vector3::Normalized((center - eye));
|
@@ -1,6 +1,6 @@
|
||||
#include <Redacted3D/types/entity/entity.h>
|
||||
#include <Redacted3D/types/entity/3D/entity.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/utils/instanceOf.h>
|
||||
#include <jlog/jlog.hpp>
|
||||
@@ -40,7 +40,7 @@ void Entity::SetPos(const Vector3 &rhs) {
|
||||
Entity::Entity() {
|
||||
position = {0,0,0};
|
||||
ticksAlive = 0;
|
||||
children = std::vector<Entity*> ();
|
||||
children = std::vector<BaseEntity*> ();
|
||||
parent = nullptr;
|
||||
scale = {1.0f, 1.0f, 1.0f};
|
||||
|
||||
@@ -58,18 +58,31 @@ Vector3 Entity::getScale() const {
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
for (const auto* e : engine->world->GetChildren())
|
||||
if (instanceOf(this, e))
|
||||
return;
|
||||
MotionTexture(this, files, frameDelta, true, doAnim);
|
||||
|
||||
}
|
||||
|
||||
void Entity::loadGeometry(const std::string& file) {
|
||||
for (const auto& e : engine->world->GetChildren())
|
||||
if (instanceOf(this, e))
|
||||
return;
|
||||
VertexArray vArray(this, file, true);
|
||||
}
|
||||
|
||||
@@ -95,26 +108,26 @@ Texture* Entity::getTexture() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline Texture* baseTexture = new Texture;
|
||||
inline Texture* baseTexture = new Texture();
|
||||
void Entity::render() {
|
||||
if (!baseTexture) {
|
||||
Texture t;
|
||||
glGenTextures(1, &t.id);
|
||||
glBindTexture(GL_TEXTURE_2D, t.id);
|
||||
GLuint handle;
|
||||
glGenTextures(1, &handle);
|
||||
glBindTexture(GL_TEXTURE_2D, handle);
|
||||
|
||||
unsigned char whitePixel[4] = { 255, 255, 255, 255};
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, whitePixel);
|
||||
Color4 whitePixel = {255, 255, 255, 255};
|
||||
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_T, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glActiveTexture(0);
|
||||
baseTexture = new Texture(t);
|
||||
baseTexture->SetTextureHandle(handle);
|
||||
}
|
||||
|
||||
MultiTexture texture;
|
||||
texture.id = baseTexture->id;
|
||||
texture.SetTextureHandle(baseTexture->GetGLTextureHandle());
|
||||
|
||||
if (auto* t = dynamic_cast<MultiTexture*>(getTexture())) {
|
||||
texture.multi.emplace_back(*t);
|
||||
@@ -142,7 +155,7 @@ void Entity::render() {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glBindTexture(GL_TEXTURE_2D, texture.id);
|
||||
glBindTexture(GL_TEXTURE_2D, texture.GetGLTextureHandle());
|
||||
//Texture unit mode.
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
|
||||
@@ -173,7 +186,7 @@ void Entity::render() {
|
||||
|
||||
//Texture unit mode.
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
|
||||
glBindTexture(GL_TEXTURE_2D, t.id);
|
||||
glBindTexture(GL_TEXTURE_2D, t.GetGLTextureHandle());
|
||||
i++;
|
||||
}
|
||||
getGeometry()->draw();
|
@@ -1,4 +1,4 @@
|
||||
#include <Redacted3D/types/entity/moby.h>
|
||||
#include <Redacted3D/types/entity/3D/moby.h>
|
||||
#include <Redacted3D/engine/engine.h>
|
||||
using namespace J3ML;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include <Redacted3D/types/entity/skybox.h>
|
||||
#include <Redacted3D/types/entity/3D/skybox.h>
|
||||
#include <Redacted3D/engine/engine.h>
|
||||
#include <Redacted3D/types/entity/camera.h>
|
||||
#include <Redacted3D/types/entity/3D/camera.h>
|
||||
|
||||
void Skybox::pre_render() {
|
||||
if (engine->world->getActiveCamera() != nullptr)
|
||||
@@ -10,7 +10,7 @@ void Skybox::pre_render() {
|
||||
void Skybox::render() {
|
||||
glPushMatrix();
|
||||
glTranslatef(position.x ,position.y, position.z);
|
||||
glBindTexture(GL_TEXTURE_2D, getTexture()->id);
|
||||
glBindTexture(GL_TEXTURE_2D, getTexture()->GetGLTextureHandle());
|
||||
glCullFace(GL_FRONT);
|
||||
glScalef(getScale().x, getScale().y, getScale().z);
|
||||
getGeometry()->draw();
|
108
src/types/entity/baseEntity.cpp
Normal file
108
src/types/entity/baseEntity.cpp
Normal 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();
|
||||
}
|
@@ -1,16 +1,18 @@
|
||||
#include <ReTexture/rTexture.h>
|
||||
#include <ReTexture/Texture.h>
|
||||
#include <Redacted3D/types/texture.h>
|
||||
#include <Redacted3D/engine/engine.h>
|
||||
|
||||
void Texture::load(Entity* entity, const std::string& file, bool storeOnTextureList) {
|
||||
auto* texture = new RTexture(file, {RTextureFlag::INVERT_Y});
|
||||
//TODO use JGL implementation of texture.
|
||||
|
||||
glGenTextures(1, &id);
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
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());
|
||||
if (texture->format == RTextureFormat::RGB)
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture->width, texture->height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->pixelData.data());
|
||||
void Texture::load(Entity* entity, const std::string& file, bool storeOnTextureList) {
|
||||
auto* texture = new ReTexture::SoftwareTexture(file, {ReTexture::TextureFlag::INVERT_Y});
|
||||
|
||||
glGenTextures(1, &texture_handle);
|
||||
glBindTexture(GL_TEXTURE_2D, texture_handle);
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
//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);
|
||||
|
||||
if (id == 0)
|
||||
if (texture_handle == 0)
|
||||
engine->setError(ENGINE_ERROR_CODE::TEXTURE_NOT_FOUND, false),
|
||||
load(entity, "assets/textures/missing.png", false);
|
||||
|
||||
@@ -36,12 +38,12 @@ void Texture::erase() {
|
||||
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);
|
||||
}
|
||||
|
||||
void Texture::erase(Texture* texture) const {
|
||||
glDeleteTextures(1, &texture->id);
|
||||
glDeleteTextures(1, &texture->texture_handle);
|
||||
|
||||
//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.
|
||||
@@ -50,7 +52,7 @@ void Texture::erase(Texture* texture) const {
|
||||
|
||||
if (auto* t = dynamic_cast<MultiTexture*>(texture))
|
||||
for (auto &m : t->multi)
|
||||
glDeleteTextures(1, &m.id);
|
||||
glDeleteTextures(1, &m.texture_handle);
|
||||
|
||||
for (int i = 0; i < engine->world->textureList.size(); i++)
|
||||
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) {
|
||||
Texture base;
|
||||
for (const auto& t : textures) {
|
||||
if (id != 0)
|
||||
if (texture_handle != 0)
|
||||
multi.emplace_back(entity, t.c_str(), false);
|
||||
else
|
||||
base = Texture(entity, t.c_str(), false),
|
||||
id = base.id,
|
||||
texture_handle = base.GetGLTextureHandle(),
|
||||
usedBy = base.usedBy;
|
||||
}
|
||||
|
||||
@@ -89,7 +91,7 @@ MotionTexture::MotionTexture(Entity* entity, const std::vector<std::string>& tex
|
||||
for (auto& t : extra)
|
||||
motion.emplace_back(entity, t.c_str(), false);
|
||||
|
||||
id = base.id;
|
||||
texture_handle = base.GetGLTextureHandle();
|
||||
usedBy = base.usedBy;
|
||||
if (storeOnTextureList)
|
||||
engine->world->textureList.push_back(new MotionTexture(*this));
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include <fstream>
|
||||
#include <Redacted3D/types/track.h>
|
||||
#include <Redacted3D/engine/engine.h>
|
||||
#include <Redacted3D/types/entity/moby.h>
|
||||
#include <Redacted3D/types/entity/3D/moby.h>
|
||||
#include <jlog/jlog.hpp>
|
||||
|
||||
Track::Track(const std::string &file, Moby* moby) {
|
||||
|
Reference in New Issue
Block a user