Добавил shared_from_this как основной способ создать умный указатель на "себя". Добавил пример работы с ним

This commit is contained in:
Jiga228
2026-06-28 15:44:58 +07:00
parent 311772cca4
commit ad881a97a9
13 changed files with 77 additions and 47 deletions
+9 -13
View File
@@ -7,10 +7,11 @@
#include "Core/CoreInstance.hpp"
#include "Game/WorldFactory.hpp"
#include "Game/World/World.hpp"
#include "Log/Log.hpp"
extern std::vector<WorldFactory> world_factories;
GameInstance::GameInstance(CoreInstance& core) : core(core)
GameInstance::GameInstance(CoreInstance& core) : core_(core)
{
const std::string& base_world = core.getBaseWorldName();
@@ -21,33 +22,28 @@ GameInstance::GameInstance(CoreInstance& core) : core(core)
{
if (factories.world_name == base_world)
{
world = factories.factory(*this);
world_ = factories.factory(*this);
break;
}
}
if (world == nullptr)
if (world_ == nullptr)
throw std::runtime_error("Can't find world");
}
GameInstance::~GameInstance()
{
delete world;
}
void GameInstance::start()
{
world->BeginPlay();
world_->BeginPlay();
auto first = std::chrono::steady_clock::now();
while (is_running)
while (is_running_)
{
auto second = std::chrono::steady_clock::now();
std::chrono::milliseconds delta_time = std::chrono::duration_cast<std::chrono::milliseconds>(second - first);
world->Tick(delta_time.count() / 1000.0);
world_->Tick(delta_time.count() / 1000.0);
first = second;
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
@@ -55,11 +51,11 @@ void GameInstance::start()
void GameInstance::stop()
{
is_running = false;
is_running_ = false;
}
void GameInstance::quit()
{
stop();
core.quit();
core_.quit();
}