Add classes Mesh and StaticMesh
This commit is contained in:
@@ -44,7 +44,6 @@ class CoreInstance {
|
|||||||
RenderEngine* render_engine_;
|
RenderEngine* render_engine_;
|
||||||
GameInstance* game_;
|
GameInstance* game_;
|
||||||
|
|
||||||
|
|
||||||
bool is_ready = false;
|
bool is_ready = false;
|
||||||
public:
|
public:
|
||||||
CoreInstance();
|
CoreInstance();
|
||||||
@@ -58,4 +57,5 @@ public:
|
|||||||
double getMemorySize() const { return memorySize_; }
|
double getMemorySize() const { return memorySize_; }
|
||||||
const std::string& getBaseWorldName() const { return main_config_.base_world; }
|
const std::string& getBaseWorldName() const { return main_config_.base_world; }
|
||||||
const std::string& getGameName() const { return main_config_.game_name; }
|
const std::string& getGameName() const { return main_config_.game_name; }
|
||||||
|
GameInstance* GetGameInstance() const { return game_; }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,6 +8,10 @@
|
|||||||
#include "CoreInstance.h"
|
#include "CoreInstance.h"
|
||||||
#include "Log/Log.h"
|
#include "Log/Log.h"
|
||||||
|
|
||||||
|
#include "Game/GameInstance.h"
|
||||||
|
#include "Game/World/World.h"
|
||||||
|
#include "Game/Actors/Mesh/Mesh.hpp"
|
||||||
|
|
||||||
#include "GLFW/glfw3.h"
|
#include "GLFW/glfw3.h"
|
||||||
|
|
||||||
const std::vector<const char*> RenderEngine::deviceExtensions = {
|
const std::vector<const char*> RenderEngine::deviceExtensions = {
|
||||||
@@ -986,6 +990,11 @@ RenderEngine::~RenderEngine()
|
|||||||
|
|
||||||
void RenderEngine::start()
|
void RenderEngine::start()
|
||||||
{
|
{
|
||||||
|
World* world = core_.GetGameInstance()->GetWorld();
|
||||||
|
std::vector<Mesh*> meshes = world->GetActorsByClass<Mesh>();
|
||||||
|
for (auto& i : meshes)
|
||||||
|
i->load_model(i->GetModelName());
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window_))
|
while (!glfwWindowShouldClose(window_))
|
||||||
{
|
{
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|||||||
@@ -8,17 +8,16 @@ Actor::Actor()
|
|||||||
SetType(Classes::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");
|
return std::make_shared<SaveMap>("Actor")
|
||||||
save->SaveObject("loc", &loc)
|
->SaveObject("loc", &loc)
|
||||||
->SaveObject("rot", &rot)
|
->SaveObject("rot", &rot)
|
||||||
->SaveObject("scale", &scale)
|
->SaveObject("scale", &scale)
|
||||||
->SaveListStrings("tags", std::move(tags));
|
->SaveListStrings("tags", std::move(tags));
|
||||||
return save;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Actor::load(std::shared_ptr<SaveMap> save) noexcept
|
void Actor::load(std::shared_ptr<SaveMap> save)
|
||||||
{
|
{
|
||||||
loc = *reinterpret_cast<Vector3D*>(save->GetObject("loc"));
|
loc = *reinterpret_cast<Vector3D*>(save->GetObject("loc"));
|
||||||
rot = *reinterpret_cast<Vector3D*>(save->GetObject("rot"));
|
rot = *reinterpret_cast<Vector3D*>(save->GetObject("rot"));
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#include "Math/Vector.h"
|
#include "Math/Vector.h"
|
||||||
|
|
||||||
GENERATE_META(Actor)
|
GENERATE_META(Actor)
|
||||||
|
|
||||||
class Actor : public ISave, public IRTTI
|
class Actor : public ISave, public IRTTI
|
||||||
{
|
{
|
||||||
Vector3D loc;
|
Vector3D loc;
|
||||||
@@ -24,8 +23,8 @@ public:
|
|||||||
Delegate<const Vector3D&> OnSetActorRotate;
|
Delegate<const Vector3D&> OnSetActorRotate;
|
||||||
|
|
||||||
#pragma region ISave
|
#pragma region ISave
|
||||||
virtual std::shared_ptr<SaveMap> save() noexcept override;
|
virtual std::shared_ptr<SaveMap> save() override;
|
||||||
virtual void load(std::shared_ptr<SaveMap> save) noexcept override;
|
virtual void load(std::shared_ptr<SaveMap> save) override;
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
virtual void BeginPlay();
|
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 "ObjectFactory.h"
|
||||||
|
#include "Actors/Mesh/StaticMesh.hpp"
|
||||||
|
|
||||||
#include "Game/Actors/Actor.h"
|
#include "Game/Actors/Actor.h"
|
||||||
#include "Math/Vector.h"
|
#include "Math/Vector.h"
|
||||||
|
|
||||||
std::vector<ObjectFactory> base_object_factories = {
|
std::vector<ObjectFactory> base_object_factories = {
|
||||||
GENERATE_FACTORY_OBJECT(Actor)
|
GENERATE_FACTORY_OBJECT(Actor)
|
||||||
|
GENERATE_FACTORY_OBJECT(StaticMesh)
|
||||||
GENERATE_FACTORY_OBJECT(Vector2D)
|
GENERATE_FACTORY_OBJECT(Vector2D)
|
||||||
GENERATE_FACTORY_OBJECT(Vector3D)
|
GENERATE_FACTORY_OBJECT(Vector3D)
|
||||||
};
|
};
|
||||||
@@ -626,11 +626,11 @@ std::string SaveMap::serialize() noexcept
|
|||||||
return buffer;
|
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)
|
if (this->parent_ != nullptr)
|
||||||
throw std::runtime_error("Can't connect to second parent");
|
throw std::runtime_error("Can't connect to second parent");
|
||||||
|
|
||||||
this->parent_ = parent;
|
this->parent_ = parent;
|
||||||
return this;
|
return std::shared_ptr<SaveMap>(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,5 +77,5 @@ public:
|
|||||||
// Собирает все токены в JSON объект
|
// Собирает все токены в JSON объект
|
||||||
std::string serialize() noexcept;
|
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 "RTTI.h"
|
||||||
#include "Game/Actors/Actor.h"
|
#include "Game/Actors/Actor.h"
|
||||||
|
#include "Game/Actors/Mesh/Mesh.hpp"
|
||||||
|
|
||||||
class GameInstance;
|
class GameInstance;
|
||||||
|
|
||||||
@@ -36,8 +37,8 @@ public:
|
|||||||
Container list;
|
Container list;
|
||||||
for (auto i = actors.cbegin(); i != actors.cend(); ++i)
|
for (auto i = actors.cbegin(); i != actors.cend(); ++i)
|
||||||
{
|
{
|
||||||
if (RTTI::IsA<T>(*i))
|
if (T* cast_object = RTTI::dyn_cast<T>(*i))
|
||||||
list.push_back(*i);
|
list.push_back(cast_object);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@@ -52,7 +53,7 @@ public:
|
|||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Container = std::vector<Actor*>>
|
template<class T, class Container = std::vector<T*>>
|
||||||
Container GetActorsByTag(std::string tag)
|
Container GetActorsByTag(std::string tag)
|
||||||
{
|
{
|
||||||
Container container;
|
Container container;
|
||||||
|
|||||||
@@ -13,5 +13,5 @@ template<class T> struct Meta;
|
|||||||
// Enum type classes
|
// Enum type classes
|
||||||
enum class Classes
|
enum class Classes
|
||||||
{
|
{
|
||||||
IRTTI, IResource, Actor, TestActor
|
IRTTI, IResource, Actor, TestActor, Mesh, StaticMesh
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"Class name":"TestWorld","dtime":5.000000,"Parent parameters":{"Class name":"World","loActors":[]}}
|
{"Class name":"TestWorld","dtime":5.000000,"Parent parameters":{"Class name":"World","loActors":[{"Class name":"StaticMesh","Parent parameters":{"Class name":"Mesh","smodel_name_":"TestModel","Parent parameters":{"Class name":"Actor","oloc":{"Class name":"Vector3D","dx":"0.0","dy":"0.0","dz":"0.0"},"orot":{"Class name":"Vector3D","dx":"0.0","dy":"0.0","dz":"0.0"},"oscale":{"Class name":"Vector3D","dx":"0.0","dy":"0.0","dz":"0.0"},"tags":[]}}}]}}
|
||||||
Reference in New Issue
Block a user