Tesseract-Engine/src/Componenets/GameObject.h

51 lines
1.1 KiB
C
Raw Normal View History

2024-12-26 00:29:24 +00:00
// src/Components/GameObject.h
2024-12-25 23:58:56 +00:00
#pragma once
2024-12-26 00:29:24 +00:00
#include <string>
#include <unordered_map>
#include <memory>
#include "Component.h"
2024-12-25 23:58:56 +00:00
#include "Transform.h"
2024-12-27 21:27:05 +00:00
#include "ScriptComponent.h"
2024-12-25 23:58:56 +00:00
#include "Mesh.h"
#include "CameraComponent.h"
2024-12-25 23:58:56 +00:00
#include <yaml-cpp/yaml.h>
// GetComponent<CameraComponent>()
2024-12-26 00:29:24 +00:00
class GameObject
2024-12-25 23:58:56 +00:00
{
public:
int id;
std::string name;
std::unordered_map<std::string, std::shared_ptr<Component>> components;
int GetComponentCount() const;
GameObject(int id, const std::string &name);
2024-12-28 03:43:17 +00:00
std::string GetName() const;
void AddComponent(const std::shared_ptr<Component> &component);
std::shared_ptr<Component> GetComponentByName(const std::string &name) const;
void Update(float deltaTime);
template <typename T>
std::shared_ptr<T> GetComponent()
{
auto it = components.find(T::GetStaticName());
if (it != components.end())
{
return std::dynamic_pointer_cast<T>(it->second);
}
return nullptr;
}
// Serialization methods
YAML::Node Serialize();
void Deserialize(const YAML::Node &node);
2024-12-26 00:29:24 +00:00
};