add experimental gameobject code that wont work lol
This commit is contained in:
parent
3c721a4c1b
commit
bbe6c6bdac
5 changed files with 54 additions and 3 deletions
6
Makefile
6
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
|
||||
|
|
19
include/Components/GameObject.hpp
Normal file
19
include/Components/GameObject.hpp
Normal 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
|
0
include/Components/Objects/TopLevel/Game.hpp
Normal file
0
include/Components/Objects/TopLevel/Game.hpp
Normal file
27
src/Components/GameObject.cpp
Normal file
27
src/Components/GameObject.cpp
Normal 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];
|
||||
}
|
||||
}
|
||||
}
|
5
src/Components/Objects/TopLevel/Game.cpp
Normal file
5
src/Components/Objects/TopLevel/Game.cpp
Normal file
|
@ -0,0 +1,5 @@
|
|||
#include <Components/GameObject.cpp>
|
||||
|
||||
class Game : public GameObject {
|
||||
|
||||
}
|
Reference in a new issue