Add classes Mesh and StaticMesh
This commit is contained in:
@@ -8,17 +8,16 @@ Actor::Actor()
|
||||
SetType(Classes::Actor);
|
||||
}
|
||||
|
||||
std::shared_ptr<SaveMap> Actor::save() noexcept
|
||||
std::shared_ptr<SaveMap> Actor::save()
|
||||
{
|
||||
std::shared_ptr<SaveMap> save = std::make_shared<SaveMap>("Actor");
|
||||
save->SaveObject("loc", &loc)
|
||||
->SaveObject("rot", &rot)
|
||||
->SaveObject("scale", &scale)
|
||||
->SaveListStrings("tags", std::move(tags));
|
||||
return save;
|
||||
return std::make_shared<SaveMap>("Actor")
|
||||
->SaveObject("loc", &loc)
|
||||
->SaveObject("rot", &rot)
|
||||
->SaveObject("scale", &scale)
|
||||
->SaveListStrings("tags", std::move(tags));
|
||||
}
|
||||
|
||||
void Actor::load(std::shared_ptr<SaveMap> save) noexcept
|
||||
void Actor::load(std::shared_ptr<SaveMap> save)
|
||||
{
|
||||
loc = *reinterpret_cast<Vector3D*>(save->GetObject("loc"));
|
||||
rot = *reinterpret_cast<Vector3D*>(save->GetObject("rot"));
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "Math/Vector.h"
|
||||
|
||||
GENERATE_META(Actor)
|
||||
|
||||
class Actor : public ISave, public IRTTI
|
||||
{
|
||||
Vector3D loc;
|
||||
@@ -24,8 +23,8 @@ public:
|
||||
Delegate<const Vector3D&> OnSetActorRotate;
|
||||
|
||||
#pragma region ISave
|
||||
virtual std::shared_ptr<SaveMap> save() noexcept override;
|
||||
virtual void load(std::shared_ptr<SaveMap> save) noexcept override;
|
||||
virtual std::shared_ptr<SaveMap> save() override;
|
||||
virtual void load(std::shared_ptr<SaveMap> save) override;
|
||||
#pragma endregion
|
||||
|
||||
virtual void BeginPlay();
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "Mesh.hpp"
|
||||
|
||||
#include "Game/SaveMap/SaveMap.h"
|
||||
|
||||
Mesh::Mesh()
|
||||
{
|
||||
SetType(Classes::Mesh);
|
||||
}
|
||||
|
||||
std::shared_ptr<SaveMap> Mesh::save()
|
||||
{
|
||||
return std::make_shared<SaveMap>("Mesh")
|
||||
->SaveString("model_name_", model_name_)
|
||||
->connect_to(Actor::save());
|
||||
}
|
||||
|
||||
void Mesh::load(std::shared_ptr<SaveMap> save)
|
||||
{
|
||||
Actor::load(save->getParent());
|
||||
model_name_ = save->GetString("model_name_");
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../Actor.h"
|
||||
|
||||
GENERATE_META(Mesh)
|
||||
class Mesh : public Actor
|
||||
{
|
||||
std::string model_name_;
|
||||
protected:
|
||||
void SetModelName(const std::string& new_model_name) { model_name_ = new_model_name; }
|
||||
|
||||
public:
|
||||
Mesh();
|
||||
|
||||
#pragma region ISave
|
||||
virtual std::shared_ptr<SaveMap> save() override;
|
||||
virtual void load(std::shared_ptr<SaveMap> save) override;
|
||||
#pragma endregion
|
||||
|
||||
virtual void load_model(const std::string& model_name) = 0;
|
||||
const std::string& GetModelName() const { return model_name_; }
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
#include "StaticMesh.hpp"
|
||||
|
||||
#include "Log/Log.h"
|
||||
#include "Game/SaveMap/SaveMap.h"
|
||||
|
||||
StaticMesh::StaticMesh()
|
||||
{
|
||||
SetType(Classes::StaticMesh);
|
||||
}
|
||||
|
||||
std::shared_ptr<SaveMap> StaticMesh::save()
|
||||
{
|
||||
return std::make_shared<SaveMap>("StaticMesh")->connect_to(Mesh::save());
|
||||
}
|
||||
|
||||
void StaticMesh::load(std::shared_ptr<SaveMap> save)
|
||||
{
|
||||
Mesh::load(save->getParent());
|
||||
}
|
||||
|
||||
void StaticMesh::load_model(const std::string& model_name)
|
||||
{
|
||||
SetModelName(model_name);
|
||||
// TODO
|
||||
Message("Load mesh: " + model_name);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "Mesh.hpp"
|
||||
|
||||
GENERATE_META(StaticMesh)
|
||||
class StaticMesh : public Mesh
|
||||
{
|
||||
public:
|
||||
StaticMesh();
|
||||
|
||||
#pragma region ISave
|
||||
virtual std::shared_ptr<SaveMap> save() override;
|
||||
virtual void load(std::shared_ptr<SaveMap> save) override;
|
||||
#pragma endregion
|
||||
|
||||
void load_model(const std::string& model_name) override;
|
||||
};
|
||||
@@ -1,10 +1,12 @@
|
||||
#include "ObjectFactory.h"
|
||||
#include "Actors/Mesh/StaticMesh.hpp"
|
||||
|
||||
#include "Game/Actors/Actor.h"
|
||||
#include "Math/Vector.h"
|
||||
|
||||
std::vector<ObjectFactory> base_object_factories = {
|
||||
GENERATE_FACTORY_OBJECT(Actor)
|
||||
GENERATE_FACTORY_OBJECT(StaticMesh)
|
||||
GENERATE_FACTORY_OBJECT(Vector2D)
|
||||
GENERATE_FACTORY_OBJECT(Vector3D)
|
||||
};
|
||||
@@ -626,11 +626,11 @@ std::string SaveMap::serialize() noexcept
|
||||
return buffer;
|
||||
}
|
||||
|
||||
SaveMap* SaveMap::connect_to(const std::shared_ptr<SaveMap>& parent)
|
||||
std::shared_ptr<SaveMap> SaveMap::connect_to(const std::shared_ptr<SaveMap>& parent)
|
||||
{
|
||||
if (this->parent_ != nullptr)
|
||||
throw std::runtime_error("Can't connect to second parent");
|
||||
|
||||
this->parent_ = parent;
|
||||
return this;
|
||||
return std::shared_ptr<SaveMap>(this);
|
||||
}
|
||||
|
||||
@@ -77,5 +77,5 @@ public:
|
||||
// Собирает все токены в JSON объект
|
||||
std::string serialize() noexcept;
|
||||
|
||||
SaveMap* connect_to(const std::shared_ptr<SaveMap>& parent);
|
||||
std::shared_ptr<SaveMap> connect_to(const std::shared_ptr<SaveMap>& parent);
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "RTTI.h"
|
||||
#include "Game/Actors/Actor.h"
|
||||
#include "Game/Actors/Mesh/Mesh.hpp"
|
||||
|
||||
class GameInstance;
|
||||
|
||||
@@ -36,8 +37,8 @@ public:
|
||||
Container list;
|
||||
for (auto i = actors.cbegin(); i != actors.cend(); ++i)
|
||||
{
|
||||
if (RTTI::IsA<T>(*i))
|
||||
list.push_back(*i);
|
||||
if (T* cast_object = RTTI::dyn_cast<T>(*i))
|
||||
list.push_back(cast_object);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -52,7 +53,7 @@ public:
|
||||
return object;
|
||||
}
|
||||
|
||||
template<class Container = std::vector<Actor*>>
|
||||
template<class T, class Container = std::vector<T*>>
|
||||
Container GetActorsByTag(std::string tag)
|
||||
{
|
||||
Container container;
|
||||
|
||||
Reference in New Issue
Block a user