add experimental gameobject code that wont work lol

This commit is contained in:
hippoz 2021-02-16 04:33:28 +02:00
parent 3c721a4c1b
commit bbe6c6bdac
No known key found for this signature in database
GPG key ID: 7C52899193467641
5 changed files with 54 additions and 3 deletions

View file

@ -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

View file

@ -0,0 +1,19 @@
#ifndef _GAMEOBJECT_H
#define _GAMEOBJECT_H
#include <vector>
struct GameObject {
const char* name;
bool is_top_level;
GameObject* parent;
std::vector<GameObject*> children;
std::map<std::string, std::vector<std::function<int(int)>>> handlers;
void add(GameObject* child);
std::vector<GameObject*>& get_children();
GameObject* get(const char* targetedName);
};
#endif

View file

@ -0,0 +1,27 @@
// Bruh.
#include <LuaHandler/LuaHandler.hpp>
#include <Components/GameObject.hpp>
// 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*>& 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];
}
}
}

View file

@ -0,0 +1,5 @@
#include <Components/GameObject.cpp>
class Game : public GameObject {
}