GameObjectPool

This commit is contained in:
2024-09-13 22:58:31 +05:00
parent bff2182ff0
commit 3df4361779
12 changed files with 306 additions and 20 deletions

View File

@@ -1,15 +1,41 @@
#pragma once
#include <map>
#include <iostream>
#include "../math.hpp"
#include <set>
#include "../UsefulException.hpp"
#include "../Mono/Mono.hpp"
class GameObject {
class GameObject;
class Component {
Mono::ObjectHandle object_handle;
GameObject* owner;
public:
Vec2 scale = { 1, 1 };
Vec2 position;
angle_t rotation;
private:
// std::set<Component> components;
inline Component(Mono::Object managed_obj, GameObject* owner)
: object_handle(managed_obj), owner(owner) {}
};
struct Transform {
Vec2 scale = { 1, 1 };
Vec2 position = { 0, 0 };
angle_t rotation = 0;
};
std::ostream& operator<<(std::ostream& s, Transform& t);
class GameObject {
Transform transform;
std::map<std::u16string, Component> components;
Mono::ObjectHandle object_handle;
GameObject* parent;
public:
GameObject(Mono::Object managed_obj, GameObject* parent);
GameObject& operator=(GameObject&& o);
inline Transform& getTransform(){ return transform; }
bool tryGetComponent(const std::u16string& name, Component** out_component);
bool tryAddComponent(const std::u16string& name, Component&& component);
};