Begin refactor, add documentation
This commit is contained in:
84
core/CMakeLists.txt
Normal file
84
core/CMakeLists.txt
Normal file
@@ -0,0 +1,84 @@
|
||||
project(Couch)
|
||||
|
||||
## Find OPENGL packages
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(GLEW REQUIRED)
|
||||
find_package(glfw3 3.3 REQUIRED)
|
||||
|
||||
## Find Bullet
|
||||
find_package(Bullet REQUIRED)
|
||||
|
||||
## Find Lua
|
||||
find_package(Lua REQUIRED)
|
||||
|
||||
add_library(couchlib SHARED)
|
||||
target_sources(couchlib PUBLIC
|
||||
Camera.h
|
||||
Camera.cpp
|
||||
CollisionShape.h
|
||||
CollisionShape.cpp
|
||||
constants.h
|
||||
Index.h
|
||||
Index.cpp
|
||||
Input.h
|
||||
Input.cpp
|
||||
Light.h
|
||||
Light.cpp
|
||||
Material.h
|
||||
Material.cpp
|
||||
Mesh.h
|
||||
Mesh.cpp
|
||||
Node.h
|
||||
Node.cpp
|
||||
Rigidbody.h
|
||||
Rigidbody.cpp
|
||||
Screen.h
|
||||
Screen.cpp
|
||||
Skybox.h
|
||||
Skybox.cpp
|
||||
Spatial.h
|
||||
Spatial.cpp
|
||||
Transform.h
|
||||
Transform.cpp
|
||||
types.h
|
||||
types.cpp
|
||||
Util.h
|
||||
Util.cpp
|
||||
Vertex.h
|
||||
Vertex.cpp
|
||||
World.h
|
||||
World.cpp
|
||||
Scripting/Lua.h
|
||||
Scripting/Lua.cpp
|
||||
Scripting/ScriptingLanguage.h
|
||||
Scripting/ScriptingLanguage.cpp
|
||||
Shaders/FlatShader.h
|
||||
Shaders/FlatShader.cpp
|
||||
Shaders/ScreenShader.h
|
||||
Shaders/ScreenShader.cpp
|
||||
Shaders/Shader.h
|
||||
Shaders/Shader.cpp
|
||||
Shaders/SkyboxShader.h
|
||||
Shaders/SkyboxShader.cpp)
|
||||
|
||||
target_include_directories(couchlib
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
target_include_directories(couchlib
|
||||
PUBLIC
|
||||
${BULLET_INCLUDE_DIRS})
|
||||
|
||||
if(NOT WIN32)
|
||||
target_link_libraries(couchlib glfw)
|
||||
endif()
|
||||
target_link_libraries(couchlib OpenGL::GL)
|
||||
target_link_libraries(couchlib GLEW::GLEW)
|
||||
target_link_libraries(couchlib ${LUA_LIBRARIES})
|
||||
target_link_libraries(couchlib ${BULLET_LIBRARIES})
|
||||
|
||||
## Add documentation
|
||||
find_package(Doxygen REQUIRED
|
||||
OPTIONAL_COMPONENTS dot mscgen dia)
|
||||
doxygen_add_docs(Node.h)
|
||||
|
||||
@@ -1,18 +1,37 @@
|
||||
#include "Node.h"
|
||||
#include "Util.h"
|
||||
|
||||
void NodeList::Append(Node *node) {
|
||||
if (this->isPrefabList and not node->isPrefab) {
|
||||
Util::Die("Attempt to add instanced node to prefab list!");
|
||||
}
|
||||
if (node->isPrefab and not this->isPrefabList) {
|
||||
Util::Die("Attempt to add prefab node to instanced list!");
|
||||
}
|
||||
push_back(node);
|
||||
}
|
||||
|
||||
bool NodeList::IsPrefabList() {
|
||||
return isPrefabList;
|
||||
}
|
||||
|
||||
Name Node::GetType() const {return "Node";}
|
||||
|
||||
Node *Node::root = {Node().Instance()};
|
||||
bool Node::IsPrefab() {
|
||||
return isPrefab;
|
||||
}
|
||||
|
||||
NodeList Node::GetChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
void Node::AddChild(Node *child) {
|
||||
children.Append(child);
|
||||
}
|
||||
|
||||
Node *Node::GetRoot() {
|
||||
return root;
|
||||
}
|
||||
bool Node::IsDrawable() const {
|
||||
return false;
|
||||
}
|
||||
bool Node::IsTransformable() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
Node* Node::Create() {
|
||||
return new Node;
|
||||
@@ -23,13 +42,13 @@ Node* Node::Duplicate() {
|
||||
}
|
||||
|
||||
Node* Node::Instance() {
|
||||
if (not this->isPrefab) {
|
||||
if (not isPrefab) {
|
||||
Util::Die("Attempt to instance an instanced node!");
|
||||
}
|
||||
Node* instance = Duplicate();
|
||||
instance->isPrefab = false;
|
||||
instance->children = NodeList();
|
||||
instance->children.isPrefabList = false;
|
||||
// Instance the children to the instanced list
|
||||
for (Node *child : children) {
|
||||
instance->children.Append(child->Instance());
|
||||
}
|
||||
@@ -37,12 +56,4 @@ Node* Node::Instance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
void NodeList::Append(Node *node) {
|
||||
if (this->isPrefabList and not node->isPrefab) {
|
||||
Util::Die("Attempt to add instanced node to prefab list!");
|
||||
}
|
||||
if (node->isPrefab and not this->isPrefabList) {
|
||||
Util::Die("Attempt to add prefab node to instanced list!");
|
||||
}
|
||||
push_back(node);
|
||||
}
|
||||
Node *Node::root = {Node().Instance()};
|
||||
|
||||
93
core/Node.h
93
core/Node.h
@@ -1,3 +1,26 @@
|
||||
/**
|
||||
@file
|
||||
@author Dane Johnson <dane@danejohnson.org>
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Couch Copyright (C) 2021 Dane Johnson
|
||||
This program comes with ABSOLUTELY NO WARRANTY; without event the
|
||||
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
See the GNU General Public LICENSE for details at
|
||||
https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation; either version 3 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
@section DESCRIPTION
|
||||
|
||||
Node is the parent class for all classes that would be in the scene
|
||||
tree. The root of the scene tree is always a node.
|
||||
*/
|
||||
|
||||
#ifndef NODE_H
|
||||
#define NODE_H
|
||||
|
||||
@@ -6,26 +29,84 @@
|
||||
#include "types.h"
|
||||
|
||||
class Node; // Forwards declare
|
||||
/**
|
||||
A list of nodes, tagged as either a list of prefabs
|
||||
or a list of instanced nodes.
|
||||
*/
|
||||
class NodeList : public std::vector<Node*> {
|
||||
public:
|
||||
/**
|
||||
Add a node to this list, will check if it is a prefab
|
||||
or an instance.
|
||||
@param node The node to add
|
||||
*/
|
||||
void Append(Node *node);
|
||||
/**
|
||||
Whether or not this is a list of prefabs
|
||||
@returns true if this is a prefab list,
|
||||
false if it is an instanced list.
|
||||
*/
|
||||
bool IsPrefabList();
|
||||
private:
|
||||
bool isPrefabList = true;
|
||||
friend class Node;
|
||||
};
|
||||
|
||||
/**
|
||||
The parent class for any object that will go into the scene tree
|
||||
*/
|
||||
class Node {
|
||||
public:
|
||||
NodeList children;
|
||||
static Node *GetRoot();
|
||||
virtual bool IsDrawable() const;
|
||||
virtual void Draw() {};
|
||||
virtual bool IsTransformable() const;
|
||||
virtual Name GetType() const;
|
||||
|
||||
/**
|
||||
Whether or not this object is a prefab, that is, if it is
|
||||
an object being set up to be instanced one or more times.
|
||||
The alternative to being a prefab is being instanced, in which
|
||||
case it will be drawn, added to the physics system, etc.
|
||||
@return true if the object is a prefab, false if it is instanced.
|
||||
*/
|
||||
bool IsPrefab();
|
||||
/**
|
||||
Returns the children of this node
|
||||
@return The list of children
|
||||
*/
|
||||
NodeList GetChildren();
|
||||
/**
|
||||
Adds a node to this nodes list of children
|
||||
@param child The node to add
|
||||
*/
|
||||
void AddChild(Node *child);
|
||||
|
||||
/**
|
||||
Gets the root of the game scene tree
|
||||
@return The root node
|
||||
*/
|
||||
static Node *GetRoot();
|
||||
/**
|
||||
Allocates a new "default" version of this node.
|
||||
@return A reference to the node.
|
||||
*/
|
||||
|
||||
virtual Node* Create();
|
||||
virtual Node* Instance();
|
||||
/**
|
||||
Copies the properties of this node to a newly allocated node,
|
||||
created via @ref Create. Subclasses should override this to copy
|
||||
additional class attributes
|
||||
@return A reference to the duplicate
|
||||
*/
|
||||
virtual Node* Duplicate();
|
||||
/**
|
||||
Creates an instanced version of this node, by calling @ref Duplicate.
|
||||
Subclasses should override this to perform neccesary tasks for
|
||||
instantiation, i.e. adding a physic object to the physics world.
|
||||
Any children of this node will also be instanced.
|
||||
@return an instanced version of this node.
|
||||
*/
|
||||
virtual Node* Instance();
|
||||
|
||||
private:
|
||||
NodeList children;
|
||||
static Node *root;
|
||||
bool isPrefab = true;
|
||||
friend class NodeList;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "Lua.h"
|
||||
#include "../Util.h"
|
||||
|
||||
#ifdef LUA_SCRIPTING
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#ifndef LUA_H
|
||||
#define LUA_H
|
||||
|
||||
#include "Input.h"
|
||||
#include "Util.h"
|
||||
#include "../Input.h"
|
||||
|
||||
#ifdef LUA_SCRIPTING
|
||||
// Lua includes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef SCRIPTINGLANGUAGE_H
|
||||
#define SCRIPTINGLANGUAGE_H
|
||||
|
||||
#include "types.h"
|
||||
#include "../types.h"
|
||||
|
||||
class ScriptingLanguage {
|
||||
public:
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include "types.h"
|
||||
#include "Material.h"
|
||||
#include "Light.h"
|
||||
#include "../types.h"
|
||||
#include "../Material.h"
|
||||
#include "../Light.h"
|
||||
|
||||
class Shader {
|
||||
public:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define SKYBOXSHADER_H
|
||||
|
||||
#include "Shader.h"
|
||||
#include "Skybox.h"
|
||||
#include "../Skybox.h"
|
||||
|
||||
class SkyboxShader : public Shader {
|
||||
public:
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Util {
|
||||
return dynamic_cast<T*>(root);
|
||||
}
|
||||
|
||||
for (Node *child : root->children) {
|
||||
for (Node *child : root->GetChildren()) {
|
||||
T* res = FindNodeByType<T>(child, type);
|
||||
if (res) {
|
||||
return res;
|
||||
|
||||
@@ -41,8 +41,8 @@ const int height = 600;
|
||||
Node *root;
|
||||
|
||||
void render(Node *curr, Shader *shader, Matrix model) {
|
||||
if (curr->IsTransformable()) {
|
||||
Spatial *spatial = dynamic_cast<Spatial*>(curr);
|
||||
Spatial *spatial = dynamic_cast<Spatial*>(curr);
|
||||
if (spatial) {
|
||||
model = glm::rotate(model, spatial->transform.rotation.x, Vector3(1.0f, 0.0f, 0.0f));
|
||||
model = glm::rotate(model, spatial->transform.rotation.y, Vector3(0.0f, 1.0f, 0.0f));
|
||||
model = glm::rotate(model, spatial->transform.rotation.z, Vector3(0.0f, 0.0f, 1.0f));
|
||||
@@ -51,11 +51,12 @@ void render(Node *curr, Shader *shader, Matrix model) {
|
||||
shader->UpdateModel(model);
|
||||
shader->UpdateNormal(glm::mat3(glm::transpose(glm::inverse(model))));
|
||||
}
|
||||
if (curr->IsDrawable()) {
|
||||
Mesh *mesh = dynamic_cast<Mesh*>(curr);
|
||||
|
||||
Mesh *mesh = dynamic_cast<Mesh*>(curr);
|
||||
if (mesh) {
|
||||
mesh->Draw(shader);
|
||||
}
|
||||
for (Node *child : curr->children) {
|
||||
for (Node *child : curr->GetChildren()) {
|
||||
render(child, shader, model);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user