2015-08-11 23:55:58 +02:00
|
|
|
#include "lumix.h"
|
|
|
|
#include "engine.h"
|
2014-11-26 22:40:37 +01:00
|
|
|
#include "core/blob.h"
|
2014-06-16 21:18:15 +02:00
|
|
|
#include "core/crc32.h"
|
|
|
|
#include "core/input_system.h"
|
|
|
|
#include "core/log.h"
|
2015-08-17 23:45:26 +02:00
|
|
|
#include "core/path.h"
|
2015-07-09 01:05:15 +02:00
|
|
|
#include "core/profiler.h"
|
2014-06-16 21:18:15 +02:00
|
|
|
#include "core/resource_manager.h"
|
|
|
|
#include "core/timer.h"
|
2014-07-10 22:20:55 +02:00
|
|
|
#include "core/fs/disk_file_device.h"
|
|
|
|
#include "core/fs/file_system.h"
|
|
|
|
#include "core/fs/memory_file_device.h"
|
|
|
|
#include "core/mtjd/manager.h"
|
2015-09-21 21:26:49 +02:00
|
|
|
#include "debug/allocator.h"
|
2014-11-12 21:51:01 +01:00
|
|
|
#include "debug/debug.h"
|
2015-08-26 22:06:42 +02:00
|
|
|
#include "engine/iplugin.h"
|
2015-08-18 22:57:22 +02:00
|
|
|
#include "engine/property_descriptor.h"
|
2015-08-11 23:55:58 +02:00
|
|
|
#include "plugin_manager.h"
|
2014-10-13 22:50:34 +02:00
|
|
|
#include "universe/hierarchy.h"
|
2015-07-30 09:18:37 +02:00
|
|
|
#include "universe/universe.h"
|
2014-06-29 15:20:21 +02:00
|
|
|
|
2015-10-06 00:08:18 +02:00
|
|
|
#include <cstdio>
|
2014-06-16 21:18:15 +02:00
|
|
|
|
|
|
|
namespace Lumix
|
|
|
|
{
|
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
static const uint32_t SERIALIZED_ENGINE_MAGIC = 0x5f4c454e; // == '_LEN'
|
2014-11-26 23:59:50 +01:00
|
|
|
|
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
enum class SerializedEngineVersion : int32_t
|
|
|
|
{
|
|
|
|
BASE,
|
2015-09-27 14:53:59 +02:00
|
|
|
SPARSE_TRANFORMATIONS,
|
2015-10-17 00:18:47 +02:00
|
|
|
FOG_PARAMS,
|
2014-11-26 23:59:50 +01:00
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
LATEST // must be the last one
|
|
|
|
};
|
2014-11-26 23:59:50 +01:00
|
|
|
|
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
#pragma pack(1)
|
|
|
|
class SerializedEngineHeader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
uint32_t m_magic;
|
|
|
|
SerializedEngineVersion m_version;
|
|
|
|
uint32_t m_reserved; // for crc
|
|
|
|
};
|
|
|
|
#pragma pack()
|
|
|
|
|
2015-08-12 22:57:22 +02:00
|
|
|
|
|
|
|
IScene* UniverseContext::getScene(uint32_t hash) const
|
|
|
|
{
|
|
|
|
for (auto* scene : m_scenes)
|
|
|
|
{
|
|
|
|
if (crc32(scene->getPlugin().getName()) == hash)
|
|
|
|
{
|
|
|
|
return scene;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
class EngineImpl : public Engine
|
|
|
|
{
|
|
|
|
public:
|
2015-08-02 15:36:52 +02:00
|
|
|
EngineImpl(FS::FileSystem* fs, IAllocator& allocator)
|
|
|
|
: m_allocator(allocator)
|
2015-07-22 00:33:10 +02:00
|
|
|
, m_resource_manager(m_allocator)
|
|
|
|
, m_mtjd_manager(m_allocator)
|
|
|
|
, m_fps(0)
|
2015-08-12 22:57:22 +02:00
|
|
|
, m_is_game_running(false)
|
2015-08-18 22:57:22 +02:00
|
|
|
, m_component_properties(m_allocator)
|
|
|
|
, m_component_types(m_allocator)
|
2014-06-16 21:18:15 +02:00
|
|
|
{
|
2015-07-22 00:33:10 +02:00
|
|
|
if (!fs)
|
|
|
|
{
|
|
|
|
m_file_system = FS::FileSystem::create(m_allocator);
|
2014-08-21 01:22:57 +02:00
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
m_mem_file_device =
|
|
|
|
m_allocator.newObject<FS::MemoryFileDevice>(m_allocator);
|
|
|
|
m_disk_file_device =
|
|
|
|
m_allocator.newObject<FS::DiskFileDevice>(m_allocator);
|
2014-08-21 01:22:57 +02:00
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
m_file_system->mount(m_mem_file_device);
|
|
|
|
m_file_system->mount(m_disk_file_device);
|
|
|
|
m_file_system->setDefaultDevice("memory:disk");
|
|
|
|
m_file_system->setSaveGameDevice("memory:disk");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_file_system = fs;
|
2015-07-25 19:33:19 +02:00
|
|
|
m_mem_file_device = nullptr;
|
|
|
|
m_disk_file_device = nullptr;
|
2015-07-22 00:33:10 +02:00
|
|
|
}
|
2014-08-21 01:22:57 +02:00
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
m_resource_manager.create(*m_file_system);
|
2014-09-29 22:58:36 +02:00
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
m_timer = Timer::create(m_allocator);
|
|
|
|
m_fps_timer = Timer::create(m_allocator);
|
2015-07-25 19:33:19 +02:00
|
|
|
m_fps_frame = 0;
|
2015-07-22 00:33:10 +02:00
|
|
|
}
|
2014-06-16 21:18:15 +02:00
|
|
|
|
2015-08-17 23:45:26 +02:00
|
|
|
bool create()
|
2015-07-22 00:33:10 +02:00
|
|
|
{
|
|
|
|
m_plugin_manager = PluginManager::create(*this);
|
|
|
|
if (!m_plugin_manager)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!m_input_system.create(m_allocator))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-16 21:18:15 +02:00
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-06-16 21:18:15 +02:00
|
|
|
|
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
virtual ~EngineImpl()
|
|
|
|
{
|
2015-08-18 22:57:22 +02:00
|
|
|
for (int j = 0; j < m_component_properties.size(); ++j)
|
|
|
|
{
|
|
|
|
Array<IPropertyDescriptor*>& props = m_component_properties.at(j);
|
|
|
|
for (int i = 0, c = props.size(); i < c; ++i)
|
|
|
|
{
|
|
|
|
m_allocator.deleteObject(props[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
Timer::destroy(m_timer);
|
|
|
|
Timer::destroy(m_fps_timer);
|
|
|
|
PluginManager::destroy(m_plugin_manager);
|
|
|
|
m_input_system.destroy();
|
|
|
|
if (m_disk_file_device)
|
|
|
|
{
|
|
|
|
FS::FileSystem::destroy(m_file_system);
|
|
|
|
m_allocator.deleteObject(m_mem_file_device);
|
|
|
|
m_allocator.deleteObject(m_disk_file_device);
|
|
|
|
}
|
2015-10-03 01:14:38 +02:00
|
|
|
|
|
|
|
m_resource_manager.destroy();
|
2015-07-22 00:33:10 +02:00
|
|
|
}
|
2014-06-16 21:18:15 +02:00
|
|
|
|
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
virtual IAllocator& getAllocator() override { return m_allocator; }
|
2014-11-07 22:18:47 +01:00
|
|
|
|
|
|
|
|
2015-08-18 22:57:22 +02:00
|
|
|
virtual const char* getComponentTypeName(int index) override
|
|
|
|
{
|
|
|
|
return m_component_types[index].m_name.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual const char* getComponentTypeID(int index) override
|
|
|
|
{
|
|
|
|
return m_component_types[index].m_id.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual int getComponentTypesCount() const override
|
|
|
|
{
|
|
|
|
return m_component_types.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Array<IPropertyDescriptor*>& getPropertyDescriptors(uint32_t type)
|
|
|
|
{
|
|
|
|
int props_index = m_component_properties.find(type);
|
|
|
|
if (props_index < 0)
|
|
|
|
{
|
|
|
|
m_component_properties.insert(
|
|
|
|
type, Array<IPropertyDescriptor*>(m_allocator));
|
|
|
|
props_index = m_component_properties.find(type);
|
|
|
|
}
|
|
|
|
return m_component_properties.at(props_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual const IPropertyDescriptor&
|
|
|
|
getPropertyDescriptor(uint32_t type, uint32_t name_hash) override
|
|
|
|
{
|
|
|
|
Array<IPropertyDescriptor*>& props = getPropertyDescriptors(type);
|
|
|
|
for (int i = 0; i < props.size(); ++i)
|
|
|
|
{
|
|
|
|
if (props[i]->getNameHash() == name_hash)
|
|
|
|
{
|
|
|
|
return *props[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ASSERT(false);
|
|
|
|
return *props[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual IPropertyDescriptor* getProperty(const char* component_type,
|
|
|
|
const char* property_name) override
|
|
|
|
{
|
|
|
|
auto& props = getPropertyDescriptors(crc32(component_type));
|
|
|
|
auto name_hash = crc32(property_name);
|
|
|
|
for (int i = 0; i < props.size(); ++i)
|
|
|
|
{
|
|
|
|
if (props[i]->getNameHash() == name_hash)
|
|
|
|
{
|
|
|
|
return props[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual void registerComponentType(const char* id, const char* name) override
|
|
|
|
{
|
|
|
|
ComponentType& type = m_component_types.emplace(m_allocator);
|
|
|
|
type.m_name = name;
|
|
|
|
type.m_id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual void registerProperty(const char* component_type,
|
|
|
|
IPropertyDescriptor* descriptor) override
|
|
|
|
{
|
|
|
|
ASSERT(descriptor);
|
|
|
|
getPropertyDescriptors(crc32(component_type)).push(descriptor);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-12 22:57:22 +02:00
|
|
|
virtual UniverseContext& createUniverse() override
|
2015-07-22 00:33:10 +02:00
|
|
|
{
|
2015-08-12 22:57:22 +02:00
|
|
|
UniverseContext* context =
|
|
|
|
m_allocator.newObject<UniverseContext>(m_allocator);
|
|
|
|
context->m_universe = m_allocator.newObject<Universe>(m_allocator);
|
|
|
|
context->m_hierarchy =
|
|
|
|
Hierarchy::create(*context->m_universe, m_allocator);
|
2015-07-22 00:33:10 +02:00
|
|
|
const Array<IPlugin*>& plugins = m_plugin_manager->getPlugins();
|
2015-07-24 22:38:11 +02:00
|
|
|
for (auto* plugin : plugins)
|
2015-07-22 00:33:10 +02:00
|
|
|
{
|
2015-08-12 22:57:22 +02:00
|
|
|
IScene* scene = plugin->createScene(*context);
|
2015-07-22 00:33:10 +02:00
|
|
|
if (scene)
|
2014-08-21 01:22:57 +02:00
|
|
|
{
|
2015-08-12 22:57:22 +02:00
|
|
|
context->m_scenes.push(scene);
|
2014-08-21 01:22:57 +02:00
|
|
|
}
|
2015-07-22 00:33:10 +02:00
|
|
|
}
|
|
|
|
|
2015-08-12 22:57:22 +02:00
|
|
|
return *context;
|
2015-07-22 00:33:10 +02:00
|
|
|
}
|
2014-06-16 21:18:15 +02:00
|
|
|
|
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
virtual MTJD::Manager& getMTJDManager() override { return m_mtjd_manager; }
|
2014-09-29 22:58:36 +02:00
|
|
|
|
|
|
|
|
2015-08-12 22:57:22 +02:00
|
|
|
virtual void destroyUniverse(UniverseContext& context) override
|
2015-07-22 00:33:10 +02:00
|
|
|
{
|
2015-08-12 22:57:22 +02:00
|
|
|
for (int i = context.m_scenes.size() - 1; i >= 0; --i)
|
2015-07-22 00:33:10 +02:00
|
|
|
{
|
2015-08-12 22:57:22 +02:00
|
|
|
context.m_scenes[i]->getPlugin().destroyScene(context.m_scenes[i]);
|
2015-07-22 00:33:10 +02:00
|
|
|
}
|
2015-08-12 22:57:22 +02:00
|
|
|
Hierarchy::destroy(context.m_hierarchy);
|
|
|
|
m_allocator.deleteObject(context.m_universe);
|
|
|
|
|
|
|
|
m_allocator.deleteObject(&context);
|
2015-07-22 00:33:10 +02:00
|
|
|
}
|
2014-06-16 21:18:15 +02:00
|
|
|
|
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
virtual PluginManager& getPluginManager() override
|
|
|
|
{
|
|
|
|
return *m_plugin_manager;
|
|
|
|
}
|
2014-06-16 21:18:15 +02:00
|
|
|
|
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
virtual FS::FileSystem& getFileSystem() override { return *m_file_system; }
|
|
|
|
|
|
|
|
|
2015-08-12 22:57:22 +02:00
|
|
|
virtual void startGame(UniverseContext& context) override
|
2015-08-12 21:54:47 +02:00
|
|
|
{
|
2015-08-12 22:57:22 +02:00
|
|
|
ASSERT(!m_is_game_running);
|
|
|
|
m_is_game_running = true;
|
|
|
|
for (auto* scene : context.m_scenes)
|
2015-08-12 21:54:47 +02:00
|
|
|
{
|
|
|
|
scene->startGame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-12 22:57:22 +02:00
|
|
|
virtual void stopGame(UniverseContext& context) override
|
2015-08-12 21:54:47 +02:00
|
|
|
{
|
2015-08-12 22:57:22 +02:00
|
|
|
ASSERT(m_is_game_running);
|
2015-08-17 21:23:56 +02:00
|
|
|
m_is_game_running = false;
|
2015-08-12 22:57:22 +02:00
|
|
|
for (auto* scene : context.m_scenes)
|
2015-08-12 21:54:47 +02:00
|
|
|
{
|
|
|
|
scene->stopGame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-14 22:12:51 +02:00
|
|
|
virtual void update(UniverseContext& context) override
|
2015-07-22 00:33:10 +02:00
|
|
|
{
|
|
|
|
PROFILE_FUNCTION();
|
|
|
|
float dt;
|
2015-08-14 22:12:51 +02:00
|
|
|
++m_fps_frame;
|
2015-09-21 11:43:31 +02:00
|
|
|
if (m_fps_timer->getTimeSinceTick() > 0.5f)
|
2015-07-22 00:33:10 +02:00
|
|
|
{
|
2015-09-21 11:43:31 +02:00
|
|
|
m_fps = m_fps_frame / m_fps_timer->tick();
|
2015-07-22 00:33:10 +02:00
|
|
|
m_fps_frame = 0;
|
|
|
|
}
|
2015-08-14 22:12:51 +02:00
|
|
|
dt = m_timer->tick();
|
2015-07-22 00:33:10 +02:00
|
|
|
m_last_time_delta = dt;
|
2015-08-18 22:57:22 +02:00
|
|
|
for (int i = 0; i < context.m_scenes.size(); ++i)
|
2015-07-22 00:33:10 +02:00
|
|
|
{
|
2015-08-18 22:57:22 +02:00
|
|
|
context.m_scenes[i]->update(dt);
|
2015-07-22 00:33:10 +02:00
|
|
|
}
|
2015-08-18 22:57:22 +02:00
|
|
|
m_plugin_manager->update(dt);
|
|
|
|
m_input_system.update(dt);
|
2015-07-22 00:33:10 +02:00
|
|
|
getFileSystem().updateAsyncTransactions();
|
|
|
|
}
|
2014-06-16 21:18:15 +02:00
|
|
|
|
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
virtual InputSystem& getInputSystem() override { return m_input_system; }
|
2014-06-16 21:18:15 +02:00
|
|
|
|
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
virtual ResourceManager& getResourceManager() override
|
|
|
|
{
|
|
|
|
return m_resource_manager;
|
|
|
|
}
|
2014-06-16 21:18:15 +02:00
|
|
|
|
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
virtual float getFPS() const override { return m_fps; }
|
2014-06-16 21:18:15 +02:00
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
|
2015-08-02 16:27:22 +02:00
|
|
|
void serializePluginList(OutputBlob& serializer)
|
|
|
|
{
|
|
|
|
serializer.write((int32_t)m_plugin_manager->getPlugins().size());
|
|
|
|
for (auto* plugin : m_plugin_manager->getPlugins())
|
|
|
|
{
|
|
|
|
serializer.writeString(plugin->getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool hasSerializedPlugins(InputBlob& serializer)
|
|
|
|
{
|
|
|
|
int32_t count;
|
|
|
|
serializer.read(count);
|
|
|
|
for (int i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
char tmp[32];
|
|
|
|
serializer.readString(tmp, sizeof(tmp));
|
|
|
|
if (!m_plugin_manager->getPlugin(tmp))
|
|
|
|
{
|
|
|
|
g_log_error.log("engine") << "Missing plugin " << tmp;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-12 22:57:22 +02:00
|
|
|
virtual uint32_t serialize(UniverseContext& ctx,
|
|
|
|
OutputBlob& serializer) override
|
2015-07-22 00:33:10 +02:00
|
|
|
{
|
|
|
|
SerializedEngineHeader header;
|
|
|
|
header.m_magic = SERIALIZED_ENGINE_MAGIC; // == '_LEN'
|
|
|
|
header.m_version = SerializedEngineVersion::LATEST;
|
|
|
|
header.m_reserved = 0;
|
|
|
|
serializer.write(header);
|
2015-08-02 16:27:22 +02:00
|
|
|
serializePluginList(serializer);
|
2015-07-22 00:33:10 +02:00
|
|
|
g_path_manager.serialize(serializer);
|
|
|
|
int pos = serializer.getSize();
|
2015-08-12 22:57:22 +02:00
|
|
|
ctx.m_universe->serialize(serializer);
|
|
|
|
ctx.m_hierarchy->serialize(serializer);
|
2015-07-22 00:33:10 +02:00
|
|
|
m_plugin_manager->serialize(serializer);
|
2015-08-12 22:57:22 +02:00
|
|
|
serializer.write((int32_t)ctx.m_scenes.size());
|
|
|
|
for (int i = 0; i < ctx.m_scenes.size(); ++i)
|
2015-07-22 00:33:10 +02:00
|
|
|
{
|
2015-08-12 22:57:22 +02:00
|
|
|
serializer.writeString(ctx.m_scenes[i]->getPlugin().getName());
|
|
|
|
ctx.m_scenes[i]->serialize(serializer);
|
2015-07-22 00:33:10 +02:00
|
|
|
}
|
|
|
|
uint32_t crc = crc32((const uint8_t*)serializer.getData() + pos,
|
|
|
|
serializer.getSize() - pos);
|
|
|
|
return crc;
|
|
|
|
}
|
2014-06-16 21:18:15 +02:00
|
|
|
|
|
|
|
|
2015-08-12 22:57:22 +02:00
|
|
|
virtual bool deserialize(UniverseContext& ctx,
|
|
|
|
InputBlob& serializer) override
|
2015-07-22 00:33:10 +02:00
|
|
|
{
|
|
|
|
SerializedEngineHeader header;
|
|
|
|
serializer.read(header);
|
|
|
|
if (header.m_magic != SERIALIZED_ENGINE_MAGIC)
|
|
|
|
{
|
|
|
|
g_log_error.log("engine") << "Wrong or corrupted file";
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-27 14:53:59 +02:00
|
|
|
if (header.m_version != SerializedEngineVersion::LATEST)
|
2015-07-22 00:33:10 +02:00
|
|
|
{
|
|
|
|
g_log_error.log("engine") << "Unsupported version";
|
|
|
|
return false;
|
|
|
|
}
|
2015-08-02 16:27:22 +02:00
|
|
|
if (!hasSerializedPlugins(serializer))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-07-22 00:33:10 +02:00
|
|
|
g_path_manager.deserialize(serializer);
|
2015-08-12 22:57:22 +02:00
|
|
|
ctx.m_universe->deserialize(serializer);
|
|
|
|
ctx.m_hierarchy->deserialize(serializer);
|
2015-07-22 00:33:10 +02:00
|
|
|
m_plugin_manager->deserialize(serializer);
|
2015-08-02 16:27:22 +02:00
|
|
|
int32_t scene_count;
|
|
|
|
serializer.read(scene_count);
|
|
|
|
for (int i = 0; i < scene_count; ++i)
|
2015-07-22 00:33:10 +02:00
|
|
|
{
|
2015-08-02 16:27:22 +02:00
|
|
|
char tmp[32];
|
|
|
|
serializer.readString(tmp, sizeof(tmp));
|
2015-08-25 17:25:58 +02:00
|
|
|
IScene* scene = ctx.getScene(crc32(tmp));
|
|
|
|
scene->deserialize(serializer);
|
2015-07-22 00:33:10 +02:00
|
|
|
}
|
2015-08-14 22:12:51 +02:00
|
|
|
g_path_manager.clear();
|
2015-07-22 00:33:10 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-08-22 22:02:53 +02:00
|
|
|
|
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
virtual float getLastTimeDelta() override { return m_last_time_delta; }
|
2014-11-07 22:18:47 +01:00
|
|
|
|
2015-08-18 22:57:22 +02:00
|
|
|
private:
|
|
|
|
struct ComponentType
|
|
|
|
{
|
|
|
|
ComponentType(IAllocator& allocator)
|
|
|
|
: m_name(allocator)
|
|
|
|
, m_id(allocator)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
string m_name;
|
|
|
|
string m_id;
|
|
|
|
};
|
2014-08-21 01:22:57 +02:00
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
private:
|
2015-09-21 21:26:49 +02:00
|
|
|
Debug::Allocator m_allocator;
|
2014-08-21 01:22:57 +02:00
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
FS::FileSystem* m_file_system;
|
|
|
|
FS::MemoryFileDevice* m_mem_file_device;
|
|
|
|
FS::DiskFileDevice* m_disk_file_device;
|
2014-09-29 22:58:36 +02:00
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
ResourceManager m_resource_manager;
|
2015-08-18 22:57:22 +02:00
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
MTJD::Manager m_mtjd_manager;
|
2014-06-16 21:18:15 +02:00
|
|
|
|
2015-08-18 22:57:22 +02:00
|
|
|
AssociativeArray<uint32_t, Array<IPropertyDescriptor*>>
|
|
|
|
m_component_properties;
|
|
|
|
Array<ComponentType> m_component_types;
|
2015-07-22 00:33:10 +02:00
|
|
|
PluginManager* m_plugin_manager;
|
|
|
|
InputSystem m_input_system;
|
|
|
|
Timer* m_timer;
|
|
|
|
Timer* m_fps_timer;
|
|
|
|
int m_fps_frame;
|
|
|
|
float m_fps;
|
|
|
|
float m_last_time_delta;
|
2015-08-12 22:57:22 +02:00
|
|
|
bool m_is_game_running;
|
2014-06-16 21:18:15 +02:00
|
|
|
|
2015-07-22 00:33:10 +02:00
|
|
|
private:
|
|
|
|
void operator=(const EngineImpl&);
|
|
|
|
EngineImpl(const EngineImpl&);
|
|
|
|
};
|
2014-06-16 21:18:15 +02:00
|
|
|
|
2014-08-21 20:05:18 +02:00
|
|
|
|
2015-10-06 00:08:18 +02:00
|
|
|
static void showLogInVS(const char*, const char* message)
|
2015-07-22 00:33:10 +02:00
|
|
|
{
|
2015-07-25 02:22:51 +02:00
|
|
|
Debug::debugOutput(message);
|
|
|
|
Debug::debugOutput("\n");
|
2015-07-22 00:33:10 +02:00
|
|
|
}
|
2014-11-11 20:03:36 +01:00
|
|
|
|
2014-06-16 21:18:15 +02:00
|
|
|
|
2015-10-06 00:08:18 +02:00
|
|
|
static FILE* g_error_file = nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
static void logErrorToFile(const char*, const char* message)
|
|
|
|
{
|
|
|
|
fputs(message, g_error_file);
|
|
|
|
fflush(g_error_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-17 23:45:26 +02:00
|
|
|
Engine* Engine::create(FS::FileSystem* fs, IAllocator& allocator)
|
2015-07-22 00:33:10 +02:00
|
|
|
{
|
2015-08-02 15:36:52 +02:00
|
|
|
installUnhandledExceptionHandler();
|
2014-06-16 21:18:15 +02:00
|
|
|
|
2015-10-06 00:08:18 +02:00
|
|
|
g_error_file = fopen("error.log", "wb");
|
|
|
|
|
|
|
|
g_log_error.getCallback().bind<logErrorToFile>();
|
2015-07-22 00:33:10 +02:00
|
|
|
g_log_info.getCallback().bind<showLogInVS>();
|
|
|
|
g_log_warning.getCallback().bind<showLogInVS>();
|
|
|
|
g_log_error.getCallback().bind<showLogInVS>();
|
2014-06-16 21:18:15 +02:00
|
|
|
|
2015-08-12 22:57:22 +02:00
|
|
|
EngineImpl* engine = allocator.newObject<EngineImpl>(fs, allocator);
|
2015-08-17 23:45:26 +02:00
|
|
|
if (!engine->create())
|
2014-06-16 21:18:15 +02:00
|
|
|
{
|
2015-07-22 00:33:10 +02:00
|
|
|
allocator.deleteObject(engine);
|
2015-07-25 19:33:19 +02:00
|
|
|
return nullptr;
|
2014-06-16 21:18:15 +02:00
|
|
|
}
|
2015-07-22 00:33:10 +02:00
|
|
|
return engine;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-21 21:39:28 +02:00
|
|
|
void Engine::destroy(Engine* engine, IAllocator& allocator)
|
2015-07-22 00:33:10 +02:00
|
|
|
{
|
2015-09-21 21:39:28 +02:00
|
|
|
allocator.deleteObject(engine);
|
2015-10-06 00:08:18 +02:00
|
|
|
|
|
|
|
fclose(g_error_file);
|
2015-10-06 00:30:12 +02:00
|
|
|
g_error_file = nullptr;
|
2015-07-22 00:33:10 +02:00
|
|
|
}
|
2014-06-16 21:18:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
} // ~namespace Lumix
|