From b58395bfae0465bb22c33a781a36e32892bd0847 Mon Sep 17 00:00:00 2001 From: Alexandre Tolstenko Date: Tue, 22 Nov 2022 17:11:45 -0500 Subject: [PATCH] feat: lots of basic code --- engine/CMakeLists.txt | 2 +- engine/Component.cpp | 1 + engine/Component.h | 18 ++++++++++++++++++ engine/GameObject.h | 25 ++++++++++++++++++++++++- engine/Transform.cpp | 5 +++++ engine/Transform.h | 8 ++++++++ 6 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 engine/Component.cpp create mode 100644 engine/Component.h create mode 100644 engine/Transform.cpp create mode 100644 engine/Transform.h diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index 9938c5e4..b4ed6e0e 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -20,7 +20,7 @@ SET(ENGINE_INC_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH "ENGINE INCLUDE SOURCE add_library (engine STATIC ${ENGINE_SRC} ${ENGINE_SRC_COMPONENTS} ${ENGINE_INC} ${ENGINE_INC_COMPONENTS}) -#target_link_libraries(engine libglew_static) +target_link_libraries(engine glm) IF(EMSCRIPTEN) target_compile_options(engine PUBLIC "-O0") diff --git a/engine/Component.cpp b/engine/Component.cpp new file mode 100644 index 00000000..0cc69a81 --- /dev/null +++ b/engine/Component.cpp @@ -0,0 +1 @@ +#include "Component.h" diff --git a/engine/Component.h b/engine/Component.h new file mode 100644 index 00000000..4e7a600f --- /dev/null +++ b/engine/Component.h @@ -0,0 +1,18 @@ +#ifndef MOBAGEN_ENGINE_COMPONENT_H_ +#define MOBAGEN_ENGINE_COMPONENT_H_ + +#include "Object.h" +class Component: public Object { + private: + // todo: add active and enabled logic + // todo: access the reference of the game object and the transform + public: + Component()= default; + virtual void Start(){}; + virtual void OnGui(){}; + virtual void OnDraw(){}; + virtual void Update(){}; + // todo: get the transform and game object associated +}; + +#endif //MOBAGEN_ENGINE_COMPONENT_H_ diff --git a/engine/GameObject.h b/engine/GameObject.h index 3dc5615a..f4531eb0 100644 --- a/engine/GameObject.h +++ b/engine/GameObject.h @@ -1,8 +1,31 @@ #ifndef MOBAGEN_ENGINE_GAMEOBJECT_H_ #define MOBAGEN_ENGINE_GAMEOBJECT_H_ -class GameObject { +#include "Object.h" +#include "Transform.h" +// a game object attaches components/behaviors +class GameObject: public Object { + private: + Transform _transform; + public: + const Transform& transform() const { return _transform; } + public: + template + std::vector GetComponents(); + + template + std::vector GetComponentsInChildren(); + + template + std::vector GetComponentsInParent(); + + template + T* AddComponent(); + + static GameObject* Find(std::string name); + + // todo: tag, layer, sendmessage }; #endif //MOBAGEN_ENGINE_GAMEOBJECT_H_ diff --git a/engine/Transform.cpp b/engine/Transform.cpp new file mode 100644 index 00000000..e5cf4fa4 --- /dev/null +++ b/engine/Transform.cpp @@ -0,0 +1,5 @@ +// +// Created by atolstenko on 11/22/2022. +// + +#include "Transform.h" diff --git a/engine/Transform.h b/engine/Transform.h new file mode 100644 index 00000000..5496f22b --- /dev/null +++ b/engine/Transform.h @@ -0,0 +1,8 @@ +#ifndef MOBAGEN_ENGINE_TRANSFORM_H_ +#define MOBAGEN_ENGINE_TRANSFORM_H_ + +class Transform { + +}; + +#endif //MOBAGEN_ENGINE_TRANSFORM_H_