diff --git a/Makefile b/Makefile index f8a9d0e..5564aa5 100644 --- a/Makefile +++ b/Makefile @@ -6,9 +6,9 @@ OBJ_DIR := obj BIN_DIR := bin EXE := $(BIN_DIR)/out -OBJ_OUT_DIRS := obj/Main obj/LuaHandler -SRC := $(SRC_DIR)/Main/Main.cpp $(SRC_DIR)/LuaHandler/LuaHandler.cpp -OBJ := $(OBJ_DIR)/Main/Main.o $(OBJ_DIR)/LuaHandler/LuaHandler.o +OBJ_OUT_DIRS := obj/Main obj/LuaHandler obj/Components obj/Components/Objects obj/Components/Objects/TopLevel +SRC := $(SRC_DIR)/Main/Main.cpp $(SRC_DIR)/LuaHandler/LuaHandler.cpp $(SRC_DIR)/Components/GameObject.cpp +OBJ := $(OBJ_DIR)/Main/Main.o $(OBJ_DIR)/LuaHandler/LuaHandler.o $(OBJ_DIR)/Components/GameObject.o CC := g++ CPPFLAGS := -I/usr/include/$(LUA) -Iinclude -MMD -MP diff --git a/include/Components/GameObject.hpp b/include/Components/GameObject.hpp new file mode 100644 index 0000000..0d06c60 --- /dev/null +++ b/include/Components/GameObject.hpp @@ -0,0 +1,19 @@ +#ifndef _GAMEOBJECT_H +#define _GAMEOBJECT_H + +#include + +struct GameObject { + const char* name; + bool is_top_level; + + GameObject* parent; + std::vector children; + std::map>> handlers; + + void add(GameObject* child); + std::vector& get_children(); + GameObject* get(const char* targetedName); +}; + +#endif \ No newline at end of file diff --git a/include/Components/Objects/TopLevel/Game.hpp b/include/Components/Objects/TopLevel/Game.hpp new file mode 100644 index 0000000..e69de29 diff --git a/src/Components/GameObject.cpp b/src/Components/GameObject.cpp new file mode 100644 index 0000000..88ecd3c --- /dev/null +++ b/src/Components/GameObject.cpp @@ -0,0 +1,27 @@ +// Bruh. + +#include +#include + +// todo: might want to make these static methods inside the gameobject class to make inheritence easier +// also see this has an example http://lua-users.org/wiki/UserDataExample + +void GameObject::add(GameObject* child) { + this->children.push_back(child); +} + +std::vector& GameObject::get_children() { + return this->children; +} + +GameObject* GameObject::get(const char* targetedName) { + // Yes, using a loop is inefficient or something + // Yes, an unsigned short can be a bit too small for this + // Eh, its fine + // FIXME: Also what if no child is found at all? Hmm well we could just return the target gameobject, that could work + for (unsigned short i = 0; i < this->children.size(); i++) { + if (this->children[i]->name == targetedName) { + return this->children[i]; + } + } +} \ No newline at end of file diff --git a/src/Components/Objects/TopLevel/Game.cpp b/src/Components/Objects/TopLevel/Game.cpp new file mode 100644 index 0000000..701d3ef --- /dev/null +++ b/src/Components/Objects/TopLevel/Game.cpp @@ -0,0 +1,5 @@ +#include + +class Game : public GameObject { + +} \ No newline at end of file