Убрал паттерн Builder из SaveMap из-за неправильной работы
This commit is contained in:
@@ -14,11 +14,12 @@ Actor::Actor() : loc_(new Vector3D), rot_(new Vector3D), scale_(new Vector3D)
|
||||
|
||||
std::shared_ptr<SaveMap> Actor::save()
|
||||
{
|
||||
return std::make_shared<SaveMap>("Actor")
|
||||
->SaveObject("loc", loc_)
|
||||
->SaveObject("rot", rot_)
|
||||
->SaveObject("scale", scale_)
|
||||
->SaveListStrings("tags", std::move(tags));
|
||||
std::shared_ptr<SaveMap> save = std::make_shared<SaveMap>("Actor");
|
||||
save->SaveObject("loc", loc_);
|
||||
save->SaveObject("rot", rot_);
|
||||
save->SaveObject("scale", scale_);
|
||||
save->SaveListStrings("tags", std::move(tags));
|
||||
return save;
|
||||
}
|
||||
|
||||
void Actor::load(std::shared_ptr<SaveMap> save)
|
||||
|
||||
@@ -371,76 +371,64 @@ save_list_objects(std::move(save_map.save_list_objects))
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<SaveMap> SaveMap::SaveInteger(const char* name, int value) noexcept
|
||||
void SaveMap::SaveInteger(const char* name, int value) noexcept
|
||||
{
|
||||
save_long[name] = value;
|
||||
return std::shared_ptr<SaveMap>(this);
|
||||
}
|
||||
|
||||
std::shared_ptr<SaveMap> SaveMap::SaveDouble(const char* name, double value) noexcept
|
||||
void SaveMap::SaveDouble(const char* name, double value) noexcept
|
||||
{
|
||||
save_double[name] = value;
|
||||
return std::shared_ptr<SaveMap>(this);
|
||||
}
|
||||
|
||||
std::shared_ptr<SaveMap> SaveMap::SaveString(const char* name, const std::string& value) noexcept
|
||||
void SaveMap::SaveString(const char* name, const std::string& value) noexcept
|
||||
{
|
||||
save_string[name] = value;
|
||||
return std::shared_ptr<SaveMap>(this);
|
||||
}
|
||||
|
||||
std::shared_ptr<SaveMap> SaveMap::SaveObject(const char* name, std::shared_ptr<ISave> object) noexcept
|
||||
void SaveMap::SaveObject(const char* name, std::shared_ptr<ISave> object) noexcept
|
||||
{
|
||||
save_objects[name] = object;
|
||||
return std::shared_ptr<SaveMap>(this);
|
||||
}
|
||||
|
||||
std::shared_ptr<SaveMap> SaveMap::SaveVectorInteger(const char* name, std::vector<long long>&& value) noexcept
|
||||
void SaveMap::SaveVectorInteger(const char* name, std::vector<long long>&& value) noexcept
|
||||
{
|
||||
save_vector_integer[name] = std::move(value);
|
||||
return std::shared_ptr<SaveMap>(this);
|
||||
}
|
||||
|
||||
std::shared_ptr<SaveMap> SaveMap::SaveVectorDouble(const char* name, std::vector<double>&& value) noexcept
|
||||
void SaveMap::SaveVectorDouble(const char* name, std::vector<double>&& value) noexcept
|
||||
{
|
||||
save_vector_double[name] = std::move(value);
|
||||
return std::shared_ptr<SaveMap>(this);
|
||||
}
|
||||
|
||||
std::shared_ptr<SaveMap> SaveMap::SaveVectorStrings(const char* name, std::vector<std::string>&& value) noexcept
|
||||
void SaveMap::SaveVectorStrings(const char* name, std::vector<std::string>&& value) noexcept
|
||||
{
|
||||
save_vector_strings[name] = std::move(value);
|
||||
return std::shared_ptr<SaveMap>(this);
|
||||
}
|
||||
|
||||
std::shared_ptr<SaveMap> SaveMap::SaveVectorObject(const char* name, std::vector<std::shared_ptr<ISave>>&& value) noexcept
|
||||
void SaveMap::SaveVectorObject(const char* name, std::vector<std::shared_ptr<ISave>>&& value) noexcept
|
||||
{
|
||||
save_vector_objects[name] = std::move(value);
|
||||
return std::shared_ptr<SaveMap>(this);
|
||||
}
|
||||
|
||||
std::shared_ptr<SaveMap> SaveMap::SaveListInteger(const char* name, std::list<long long>&& value) noexcept
|
||||
void SaveMap::SaveListInteger(const char* name, std::list<long long>&& value) noexcept
|
||||
{
|
||||
save_list_integer[name] = std::move(value);
|
||||
return std::shared_ptr<SaveMap>(this);
|
||||
}
|
||||
|
||||
std::shared_ptr<SaveMap> SaveMap::SaveListDouble(const char* name, std::list<double>&& value) noexcept
|
||||
void SaveMap::SaveListDouble(const char* name, std::list<double>&& value) noexcept
|
||||
{
|
||||
save_list_double[name] = std::move(value);
|
||||
return std::shared_ptr<SaveMap>(this);
|
||||
}
|
||||
|
||||
std::shared_ptr<SaveMap> SaveMap::SaveListStrings(const char* name, std::list<std::string>&& value) noexcept
|
||||
void SaveMap::SaveListStrings(const char* name, std::list<std::string>&& value) noexcept
|
||||
{
|
||||
save_list_strings[name] = std::move(value);
|
||||
return std::shared_ptr<SaveMap>(this);
|
||||
}
|
||||
|
||||
std::shared_ptr<SaveMap> SaveMap::SaveListObject(const char* name, std::list<std::shared_ptr<ISave>>&& value) noexcept
|
||||
void SaveMap::SaveListObject(const char* name, std::list<std::shared_ptr<ISave>>&& value) noexcept
|
||||
{
|
||||
save_list_objects[name] = std::move(value);
|
||||
return std::shared_ptr<SaveMap>(this);
|
||||
}
|
||||
|
||||
long long SaveMap::GetInteger(const char* name)
|
||||
@@ -517,7 +505,7 @@ std::string SaveMap::serialize() noexcept
|
||||
buffer += ",\"s" + key + "\":\"" + value + '\"';
|
||||
|
||||
for (auto& [key, value] : save_objects)
|
||||
buffer += ",\"o" + key + "\":\"" + value->save()->serialize();
|
||||
buffer += ",\"o" + key + "\":" + value->save()->serialize();
|
||||
|
||||
for (auto& [key, value] : save_vector_integer)
|
||||
{
|
||||
@@ -631,13 +619,12 @@ std::string SaveMap::serialize() noexcept
|
||||
return buffer;
|
||||
}
|
||||
|
||||
std::shared_ptr<SaveMap> SaveMap::connect_to(const std::shared_ptr<SaveMap>& parent)
|
||||
void 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 std::shared_ptr<SaveMap>(this);
|
||||
}
|
||||
|
||||
std::string SaveMap::CleaningJSON(const std::string& json_data)
|
||||
|
||||
@@ -44,18 +44,18 @@ public:
|
||||
SaveMap(SaveMap&& save_map) noexcept;
|
||||
|
||||
// Методы созранения значений
|
||||
std::shared_ptr<SaveMap> SaveInteger(const char* name, int value) noexcept;
|
||||
std::shared_ptr<SaveMap> SaveDouble(const char* name, double value) noexcept;
|
||||
std::shared_ptr<SaveMap> SaveString(const char* name, const std::string& value) noexcept;
|
||||
std::shared_ptr<SaveMap> SaveObject(const char* name, std::shared_ptr<ISave> object) noexcept;
|
||||
std::shared_ptr<SaveMap> SaveVectorInteger(const char* name, std::vector<long long>&& value) noexcept;
|
||||
std::shared_ptr<SaveMap> SaveVectorDouble(const char* name, std::vector<double>&& value) noexcept;
|
||||
std::shared_ptr<SaveMap> SaveVectorStrings(const char* name, std::vector<std::string>&& value) noexcept;
|
||||
std::shared_ptr<SaveMap> SaveVectorObject(const char* name, std::vector<std::shared_ptr<ISave>>&& value) noexcept;
|
||||
std::shared_ptr<SaveMap> SaveListInteger(const char* name, std::list<long long>&& value) noexcept;
|
||||
std::shared_ptr<SaveMap> SaveListDouble(const char* name, std::list<double>&& value) noexcept;
|
||||
std::shared_ptr<SaveMap> SaveListStrings(const char* name, std::list<std::string>&& value) noexcept;
|
||||
std::shared_ptr<SaveMap> SaveListObject(const char* name, std::list<std::shared_ptr<ISave>>&& value) noexcept;
|
||||
void SaveInteger(const char* name, int value) noexcept;
|
||||
void SaveDouble(const char* name, double value) noexcept;
|
||||
void SaveString(const char* name, const std::string& value) noexcept;
|
||||
void SaveObject(const char* name, std::shared_ptr<ISave> object) noexcept;
|
||||
void SaveVectorInteger(const char* name, std::vector<long long>&& value) noexcept;
|
||||
void SaveVectorDouble(const char* name, std::vector<double>&& value) noexcept;
|
||||
void SaveVectorStrings(const char* name, std::vector<std::string>&& value) noexcept;
|
||||
void SaveVectorObject(const char* name, std::vector<std::shared_ptr<ISave>>&& value) noexcept;
|
||||
void SaveListInteger(const char* name, std::list<long long>&& value) noexcept;
|
||||
void SaveListDouble(const char* name, std::list<double>&& value) noexcept;
|
||||
void SaveListStrings(const char* name, std::list<std::string>&& value) noexcept;
|
||||
void SaveListObject(const char* name, std::list<std::shared_ptr<ISave>>&& value) noexcept;
|
||||
|
||||
// Методы получения значенй
|
||||
long long GetInteger(const char* name);
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
// Собирает все токены в JSON объект
|
||||
std::string serialize() noexcept;
|
||||
|
||||
std::shared_ptr<SaveMap> connect_to(const std::shared_ptr<SaveMap>& parent);
|
||||
void connect_to(const std::shared_ptr<SaveMap>& parent);
|
||||
|
||||
static std::string CleaningJSON(const std::string& json_data);
|
||||
};
|
||||
|
||||
@@ -28,6 +28,18 @@ void World::Tick(double delta_time)
|
||||
std::shared_ptr<SaveMap> World::save()
|
||||
{
|
||||
std::shared_ptr<SaveMap> save = std::make_shared<SaveMap>("World");
|
||||
|
||||
std::vector<std::string> ActorsIDs;
|
||||
ActorsIDs.reserve(actors_map.size());
|
||||
std::list<std::shared_ptr<ISave>> actors;
|
||||
for (auto[it, flag] : actors_map)
|
||||
{
|
||||
ActorsIDs.push_back(it);
|
||||
actors.push_back(flag);
|
||||
}
|
||||
save->SaveVectorStrings("ActorsIDs", std::move(ActorsIDs));
|
||||
save->SaveListObject("Actors", std::move(actors));
|
||||
|
||||
return save;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,8 +49,8 @@ public:
|
||||
std::shared_ptr<T> object = std::make_shared<T>();
|
||||
object->SetActorLocate(loc);
|
||||
object->SetActorRotate(rot);
|
||||
static_cast<Actor*>(object)->world_ = this;
|
||||
static_cast<Actor*>(object)->name_ = name;
|
||||
std::static_pointer_cast<Actor>(object)->world_ = this;
|
||||
std::static_pointer_cast<Actor>(object)->name_ = name;
|
||||
actors_map.try_emplace(name, object);
|
||||
return object;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,9 @@ Vector2D Vector2D::operator-(const Vector2D& v) const
|
||||
|
||||
std::shared_ptr<SaveMap> Vector2D::save()
|
||||
{
|
||||
std::unique_ptr<SaveMap> save = std::make_unique<SaveMap>("Vector2D");
|
||||
save->SaveDouble("x", x)->SaveDouble("y", y);
|
||||
std::shared_ptr<SaveMap> save = std::make_shared<SaveMap>("Vector2D");
|
||||
save->SaveDouble("x", x);
|
||||
save->SaveDouble("y", y);
|
||||
return save;
|
||||
}
|
||||
|
||||
@@ -50,7 +51,9 @@ Vector3D Vector3D::operator-(const Vector3D& v) const
|
||||
std::shared_ptr<SaveMap> Vector3D::save()
|
||||
{
|
||||
std::unique_ptr<SaveMap> save = std::make_unique<SaveMap>("Vector3D");
|
||||
save->SaveDouble("x", x)->SaveDouble("y", y)->SaveDouble("z", z);
|
||||
save->SaveDouble("x", x);
|
||||
save->SaveDouble("y", y);
|
||||
save->SaveDouble("z", z);
|
||||
return save;
|
||||
}
|
||||
|
||||
|
||||
+121
-91
@@ -1,93 +1,123 @@
|
||||
{
|
||||
"Class name": "TestWorld",
|
||||
"dtime": 5.000000,
|
||||
"Parent parameters": {
|
||||
"Class name":"World",
|
||||
"vsActorsIDs": ["MainCamera", "TestMesh1","TestMesh2"],
|
||||
"loActors": [
|
||||
{
|
||||
"Class name": "Camera",
|
||||
"Parent parameters": {
|
||||
"Class name":"Actor",
|
||||
"oloc": {
|
||||
"Class name":"Vector3D",
|
||||
"dx":2.0,
|
||||
"dy":2.0,
|
||||
"dz":2.0
|
||||
},
|
||||
"orot": {
|
||||
"Class name":"Vector3D",
|
||||
"dx":-2.335,
|
||||
"dy":-0.785,
|
||||
"dz":0.0
|
||||
},
|
||||
"oscale": {
|
||||
"Class name": "Vector3D",
|
||||
"dx": 1.0,
|
||||
"dy": 1.0,
|
||||
"dz": 1.0
|
||||
},
|
||||
"tags":[]
|
||||
}
|
||||
},
|
||||
{
|
||||
"Class name": "StaticMesh",
|
||||
"Parent parameters": {
|
||||
"Class name": "Mesh",
|
||||
"smodel_name_": "TestModel",
|
||||
"Parent parameters": {
|
||||
"Class name":"Actor",
|
||||
"oloc": {
|
||||
"Class name":"Vector3D",
|
||||
"dx":1.0,
|
||||
"dy":-1.0,
|
||||
"dz":1.0
|
||||
},
|
||||
"orot": {
|
||||
"Class name":"Vector3D",
|
||||
"dx":0.0,
|
||||
"dy":0.0,
|
||||
"dz":0.0
|
||||
},
|
||||
"oscale": {
|
||||
"Class name": "Vector3D",
|
||||
"dx": 1.0,
|
||||
"dy": 1.0,
|
||||
"dz": 1.0
|
||||
},
|
||||
"tags":[]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Class name": "StaticMesh",
|
||||
"Parent parameters": {
|
||||
"Class name": "Mesh",
|
||||
"smodel_name_": "TestModel",
|
||||
"Parent parameters": {
|
||||
"Class name":"Actor",
|
||||
"oloc": {
|
||||
"Class name":"Vector3D",
|
||||
"dx":0.0,
|
||||
"dy":-1.0,
|
||||
"dz":1.0
|
||||
},
|
||||
"orot": {
|
||||
"Class name":"Vector3D",
|
||||
"dx":0.0,
|
||||
"dy":0.0,
|
||||
"dz":0.0
|
||||
},
|
||||
"oscale": {
|
||||
"Class name": "Vector3D",
|
||||
"dx": 1.0,
|
||||
"dy": 1.0,
|
||||
"dz": 1.0
|
||||
},
|
||||
"tags":[]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
"Class name": "TestWorld",
|
||||
"dtime": 5,
|
||||
"Parent parameters": {
|
||||
"Class name": "World",
|
||||
"vsActorsIDs": [
|
||||
"TestMesh1",
|
||||
"MainCamera",
|
||||
"TestMesh2",
|
||||
"TestActor1"
|
||||
],
|
||||
"loActors": [
|
||||
{
|
||||
"Class name": "StaticMesh",
|
||||
"Parent parameters": {
|
||||
"Class name": "Mesh",
|
||||
"smodel_name_": "TestModel",
|
||||
"Parent parameters": {
|
||||
"Class name": "Actor",
|
||||
"oloc": {
|
||||
"Class name": "Vector3D",
|
||||
"dx": 1,
|
||||
"dy": -1,
|
||||
"dz": 1
|
||||
},
|
||||
"orot": {
|
||||
"Class name": "Vector3D",
|
||||
"dx": 0,
|
||||
"dy": 0,
|
||||
"dz": 0
|
||||
},
|
||||
"oscale": {
|
||||
"Class name": "Vector3D",
|
||||
"dx": 1,
|
||||
"dy": 1,
|
||||
"dz": 1
|
||||
},
|
||||
"lstags": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Class name": "Camera",
|
||||
"Parent parameters": {
|
||||
"Class name": "Actor",
|
||||
"oloc": {
|
||||
"Class name": "Vector3D",
|
||||
"dx": 2,
|
||||
"dy": 2,
|
||||
"dz": 2
|
||||
},
|
||||
"orot": {
|
||||
"Class name": "Vector3D",
|
||||
"dx": -2.335,
|
||||
"dy": -0.785,
|
||||
"dz": 0
|
||||
},
|
||||
"oscale": {
|
||||
"Class name": "Vector3D",
|
||||
"dx": 1,
|
||||
"dy": 1,
|
||||
"dz": 1
|
||||
},
|
||||
"lstags": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"Class name": "StaticMesh",
|
||||
"Parent parameters": {
|
||||
"Class name": "Mesh",
|
||||
"smodel_name_": "TestModel",
|
||||
"Parent parameters": {
|
||||
"Class name": "Actor",
|
||||
"oloc": {
|
||||
"Class name": "Vector3D",
|
||||
"dx": 0,
|
||||
"dy": -1,
|
||||
"dz": 1
|
||||
},
|
||||
"orot": {
|
||||
"Class name": "Vector3D",
|
||||
"dx": 0,
|
||||
"dy": 0,
|
||||
"dz": 0
|
||||
},
|
||||
"oscale": {
|
||||
"Class name": "Vector3D",
|
||||
"dx": 1,
|
||||
"dy": 1,
|
||||
"dz": 1
|
||||
},
|
||||
"lstags": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Class name": "TestActor",
|
||||
"Parent parameters": {
|
||||
"Class name": "Actor",
|
||||
"oloc": {
|
||||
"Class name": "Vector3D",
|
||||
"dx": 0,
|
||||
"dy": 0,
|
||||
"dz": 0
|
||||
},
|
||||
"orot": {
|
||||
"Class name": "Vector3D",
|
||||
"dx": 0,
|
||||
"dy": 0,
|
||||
"dz": 0
|
||||
},
|
||||
"oscale": {
|
||||
"Class name": "Vector3D",
|
||||
"dx": 0,
|
||||
"dy": 0,
|
||||
"dz": 0
|
||||
},
|
||||
"lstags": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,22 @@
|
||||
#include "TestActor.h"
|
||||
|
||||
#include "Game/SaveMap/SaveMap.hpp"
|
||||
#include "Log/Log.hpp"
|
||||
|
||||
void TestActor::BeginPlay()
|
||||
{
|
||||
Actor::BeginPlay();
|
||||
Loging::Log("TestActor::BeginPlay");
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<SaveMap> TestActor::save()
|
||||
{
|
||||
std::shared_ptr<SaveMap> save = std::make_shared<SaveMap>("TestActor");
|
||||
save->connect_to(Actor::save());
|
||||
return save;
|
||||
}
|
||||
|
||||
void TestActor::load(std::shared_ptr<SaveMap> save)
|
||||
{
|
||||
Actor::load(save->getParent());
|
||||
}
|
||||
|
||||
@@ -7,4 +7,7 @@ class TestActor final : public Actor
|
||||
{
|
||||
public:
|
||||
void BeginPlay() override;
|
||||
|
||||
std::shared_ptr<SaveMap> save() override;
|
||||
void load(std::shared_ptr<SaveMap> save) override;
|
||||
};
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext/scalar_constants.hpp>
|
||||
|
||||
#include "../Actors/TestActor.h"
|
||||
#include "Game/GameInstance.hpp"
|
||||
#include "Game/Actors/Camera.hpp"
|
||||
#include "Game/SaveMap/SaveMap.hpp"
|
||||
@@ -22,6 +23,9 @@ void TestWorld::BeginPlay()
|
||||
}
|
||||
|
||||
GetActorsByClass<Camera>()[0].lock()->SetActive();
|
||||
//SpawnActorFormClass<TestActor>("TestActor1");
|
||||
//std::shared_ptr<SaveMap> save_world = save();
|
||||
//Loging::Log(save_world->serialize());
|
||||
}
|
||||
|
||||
void TestWorld::Tick(double delta_time)
|
||||
@@ -56,7 +60,8 @@ std::shared_ptr<SaveMap> TestWorld::save()
|
||||
{
|
||||
std::shared_ptr<SaveMap> save = World::save();
|
||||
std::shared_ptr<SaveMap> my_save = std::make_shared<SaveMap>("TestWorld");
|
||||
my_save->SaveDouble("time", time)->connect_to(save);
|
||||
my_save->SaveDouble("time", time);
|
||||
my_save->connect_to(save);
|
||||
return my_save;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,9 @@ Camera::Camera()
|
||||
|
||||
std::shared_ptr<SaveMap> Camera::save()
|
||||
{
|
||||
return std::make_shared<SaveMap>("Camera")->connect_to(Actor::save());
|
||||
std::shared_ptr<SaveMap> save = std::make_shared<SaveMap>("Camera");
|
||||
save->connect_to(Actor::save());
|
||||
return save;
|
||||
}
|
||||
|
||||
void Camera::load(std::shared_ptr<SaveMap> save)
|
||||
|
||||
@@ -9,9 +9,10 @@ Mesh::Mesh()
|
||||
|
||||
std::shared_ptr<SaveMap> Mesh::save()
|
||||
{
|
||||
return std::make_shared<SaveMap>("Mesh")
|
||||
->SaveString("model_name_", model_name_)
|
||||
->connect_to(Actor::save());
|
||||
std::shared_ptr<SaveMap> save = std::make_shared<SaveMap>("Mesh");
|
||||
save->SaveString("model_name_", model_name_);
|
||||
save->connect_to(Actor::save());
|
||||
return save;
|
||||
}
|
||||
|
||||
void Mesh::load(std::shared_ptr<SaveMap> save)
|
||||
|
||||
@@ -13,7 +13,9 @@ StaticMesh::StaticMesh()
|
||||
|
||||
std::shared_ptr<SaveMap> StaticMesh::save()
|
||||
{
|
||||
return std::make_shared<SaveMap>("StaticMesh")->connect_to(Mesh::save());
|
||||
std::shared_ptr<SaveMap> save = std::make_shared<SaveMap>("StaticMesh");
|
||||
save->connect_to(Mesh::save());
|
||||
return save;
|
||||
}
|
||||
|
||||
void StaticMesh::load(std::shared_ptr<SaveMap> save)
|
||||
|
||||
Reference in New Issue
Block a user