This commit is contained in:
Mikulas Florek 2015-08-12 22:57:22 +02:00
parent a4e4bd3489
commit c8ba681dc9
15 changed files with 240 additions and 173 deletions

View file

@ -45,16 +45,24 @@ private:
public:
AnimationSceneImpl(IPlugin& anim_system,
Engine& engine,
Universe& universe,
UniverseContext& ctx,
IAllocator& allocator)
: m_universe(universe)
: m_universe(*ctx.m_universe)
, m_engine(engine)
, m_anim_system(anim_system)
, m_animables(allocator)
{
IScene* scene = engine.getScene(crc32("renderer"));
ASSERT(scene);
m_render_scene = static_cast<RenderScene*>(scene);
m_render_scene = nullptr;
uint32_t hash = crc32("renderer");
for (auto* scene : ctx.m_scenes)
{
if (crc32(scene->getPlugin().getName()) == hash)
{
m_render_scene = static_cast<RenderScene*>(scene);
break;
}
}
ASSERT(m_render_scene);
m_render_scene->renderableCreated()
.bind<AnimationSceneImpl, &AnimationSceneImpl::onRenderableCreated>(
this);
@ -286,10 +294,10 @@ public:
{
}
virtual IScene* createScene(Universe& universe) override
virtual IScene* createScene(UniverseContext& ctx) override
{
return m_allocator.newObject<AnimationSceneImpl>(
*this, m_engine, universe, m_allocator);
*this, m_engine, ctx, m_allocator);
}

View file

@ -52,7 +52,7 @@ void Gizmo::create()
.getResourceManager()
.get(ResourceManager::MODEL)
->load(Path("models/editor/gizmo.msh")));
m_scene = static_cast<RenderScene*>(m_editor.getEngine().getScene(crc32("renderer")));
m_scene = static_cast<RenderScene*>(m_editor.getScene(crc32("renderer")));
}

View file

@ -550,8 +550,7 @@ public:
serializer.deserialize("entity_index", m_component.entity, 0);
serializer.deserialize("component_index", m_component.index, 0);
serializer.deserialize("component_type", m_component.type, 0);
m_component.scene =
m_editor.getEngine().getSceneByComponentType(m_component.type);
m_component.scene = m_editor.getSceneByComponentType(m_component.type);
uint32_t property_name_hash;
serializer.deserialize("property_name_hash", property_name_hash, 0);
m_descriptor = static_cast<const IArrayDescriptor*>(
@ -632,8 +631,7 @@ public:
serializer.deserialize("entity_index", m_component.entity, 0);
serializer.deserialize("component_index", m_component.index, 0);
serializer.deserialize("component_type", m_component.type, 0);
m_component.scene =
m_editor.getEngine().getSceneByComponentType(m_component.type);
m_component.scene = m_editor.getSceneByComponentType(m_component.type);
uint32_t property_name_hash;
serializer.deserialize("property_name_hash", property_name_hash, 0);
m_descriptor = static_cast<const IArrayDescriptor*>(
@ -947,7 +945,7 @@ private:
virtual void execute() override
{
const Array<IScene*>& scenes = m_editor.getEngine().getScenes();
const Array<IScene*>& scenes = m_editor.getScenes();
for (int j = 0; j < m_entities.size(); ++j)
{
@ -1114,7 +1112,7 @@ private:
virtual void undo() override
{
Universe* universe = m_editor.getUniverse();
const Array<IScene*>& scenes = m_editor.getEngine().getScenes();
const Array<IScene*>& scenes = m_editor.getScenes();
InputBlob blob(m_old_values);
for (int i = 0; i < m_entities.size(); ++i)
{
@ -1217,7 +1215,7 @@ private:
serializer.deserialize("component", m_component.index, 0);
serializer.deserialize("component_type", m_component.type, 0);
m_component.scene =
m_editor.getEngine().getSceneByComponentType(m_component.type);
m_editor.getSceneByComponentType(m_component.type);
}
@ -1225,7 +1223,7 @@ private:
{
uint32_t template_hash =
m_editor.m_template_system->getTemplate(m_component.entity);
const Array<IScene*>& scenes = m_editor.m_engine->getScenes();
const Array<IScene*>& scenes = m_editor.getScenes();
int props_index =
m_editor.m_component_properties.find(m_component.type);
@ -1424,7 +1422,42 @@ public:
virtual IAllocator& getAllocator() override { return m_allocator; }
virtual Universe* getUniverse() override { return m_engine->getUniverse(); }
virtual IScene* getSceneByComponentType(uint32_t hash) override
{
for (auto* scene : m_universe_context->m_scenes)
{
if (scene->ownComponentType(hash))
{
return scene;
}
}
return nullptr;
}
virtual IScene* getScene(uint32_t hash) override
{
for (auto* scene : m_universe_context->m_scenes)
{
if (crc32(scene->getPlugin().getName()) == hash)
{
return scene;
}
}
return nullptr;
}
virtual Hierarchy* getHierarchy() override
{
return m_universe_context->m_hierarchy;
}
virtual Universe* getUniverse() override
{
return m_universe_context->m_universe;
}
virtual Engine& getEngine() override { return *m_engine; }
@ -1613,8 +1646,9 @@ public:
virtual void updateEngine(float forced_time_delta,
float time_delta_multiplier) override
{
ASSERT(m_universe_context);
m_engine->update(
m_is_game_mode, time_delta_multiplier, forced_time_delta);
*m_universe_context, time_delta_multiplier, forced_time_delta);
}
@ -1856,12 +1890,14 @@ public:
void save(FS::IFile& file)
{
ASSERT(m_universe_context);
OutputBlob blob(m_allocator);
blob.reserve(1 << 20);
uint32_t hash = 0;
blob.write(hash);
blob.write(hash);
uint32_t engine_hash = m_engine->serialize(blob);
uint32_t engine_hash = m_engine->serialize(*m_universe_context, blob);
(*(((uint32_t*)blob.getData()) + 1)) = engine_hash;
m_template_system->serialize(blob);
hash = crc32((const uint8_t*)blob.getData() + sizeof(hash),
@ -1877,8 +1913,8 @@ public:
if (!m_selected_entities.empty())
{
Array<Vec3> new_positions(m_allocator);
RenderScene* scene = static_cast<RenderScene*>(
m_engine->getScene(crc32("renderer")));
RenderScene* scene =
static_cast<RenderScene*>(getScene(crc32("renderer")));
Universe* universe = getUniverse();
for (int i = 0; i < m_selected_entities.size(); ++i)
@ -2109,6 +2145,7 @@ public:
virtual void toggleGameMode() override
{
ASSERT(m_universe_context);
if (m_is_game_mode)
{
stopGameMode();
@ -2121,14 +2158,15 @@ public:
FS::Mode::WRITE);
save(*m_game_mode_file);
m_is_game_mode = true;
m_engine->startGame();
m_engine->startGame(*m_universe_context);
}
}
void stopGameMode()
{
m_engine->stopGame();
ASSERT(m_universe_context);
m_engine->stopGame(*m_universe_context);
selectEntities(nullptr, 0);
for (int i = 0; i < m_editor_icons.size(); ++i)
{
@ -2215,7 +2253,7 @@ public:
{
ComponentUID clone = ComponentUID::INVALID;
const Array<IScene*>& scenes = m_engine->getScenes();
const Array<IScene*>& scenes = getScenes();
for (int i = 0; i < scenes.size(); ++i)
{
clone = ComponentUID(entity,
@ -2311,14 +2349,13 @@ public:
}
virtual void getRelativePath(char* relative_path,
int max_length,
const char* source) override
int max_length,
const char* source) override
{
char tmp[MAX_PATH_LENGTH];
makeLowercase(tmp, sizeof(tmp), source);
if (strncmp(
m_base_path.c_str(), tmp, m_base_path.length()) == 0)
if (strncmp(m_base_path.c_str(), tmp, m_base_path.length()) == 0)
{
const char* rel_path_start = tmp + m_base_path.length();
if (rel_path_start[0] == '/')
@ -2371,11 +2408,11 @@ public:
m_is_loading = false;
return;
}
if (m_engine->deserialize(blob))
if (m_engine->deserialize(*m_universe_context, blob))
{
m_template_system->deserialize(blob);
auto* render_scene = static_cast<RenderScene*>(
m_engine->getScene(crc32("renderer")));
auto* render_scene =
static_cast<RenderScene*>(getScene(crc32("renderer")));
m_camera = render_scene->getCameraEntity(
render_scene->getCameraInSlot("editor"));
@ -2384,7 +2421,7 @@ public:
<< timer->getTimeSinceStart()
<< " seconds";
Universe* universe = m_engine->getUniverse();
Universe* universe = getUniverse();
for (int i = 0; i < universe->getEntityCount(); ++i)
{
Entity e(i);
@ -2518,6 +2555,7 @@ public:
, m_component_types(m_allocator)
, m_is_loading(false)
, m_universe_path("")
, m_universe_context(nullptr)
{
m_go_to_parameters.m_is_active = false;
m_undo_index = -1;
@ -2817,6 +2855,7 @@ public:
void destroyUniverse()
{
ASSERT(m_universe_context);
destroyUndoStack();
m_universe_destroyed.invoke();
m_gizmo.setUniverse(nullptr);
@ -2829,7 +2868,8 @@ public:
selectEntities(nullptr, 0);
m_camera = INVALID_ENTITY;
m_editor_icons.clear();
m_engine->destroyUniverse();
m_engine->destroyUniverse(*m_universe_context);
m_universe_context = nullptr;
}
@ -2898,7 +2938,7 @@ public:
ComponentUID createComponent(uint32_t hash, Entity entity)
{
const Array<IScene*>& scenes = m_engine->getScenes();
const Array<IScene*>& scenes = getScenes();
ComponentUID cmp;
for (int i = 0; i < scenes.size(); ++i)
{
@ -2918,8 +2958,11 @@ public:
void createUniverse(bool create_basic_entities)
{
ASSERT(!m_universe_context);
destroyUndoStack();
Universe* universe = m_engine->createUniverse();
m_universe_context = &m_engine->createUniverse();
Universe* universe = m_universe_context->m_universe;
m_gizmo.create();
m_gizmo.setUniverse(universe);
@ -3110,6 +3153,12 @@ public:
}
virtual const Array<IScene*>& getScenes() const override
{
return m_universe_context->m_scenes;
}
private:
struct MouseMode
{
@ -3183,6 +3232,7 @@ private:
int m_undo_index;
OutputBlob m_copy_buffer;
bool m_is_loading;
UniverseContext* m_universe_context;
};

View file

@ -12,6 +12,7 @@ namespace Lumix
class Engine;
class EntityTemplateSystem;
class Hierarchy;
class IArrayDescriptor;
class IPlugin;
class IPropertyDescriptor;
@ -80,6 +81,10 @@ public:
virtual IEditorCommand* createEditorCommand(uint32_t command_type) = 0;
virtual Engine& getEngine() = 0;
virtual Universe* getUniverse() = 0;
virtual Hierarchy* getHierarchy() = 0;
virtual const Array<IScene*>& getScenes() const = 0;
virtual IScene* getScene(uint32_t hash) = 0;
virtual IScene* getSceneByComponentType(uint32_t hash) = 0;
virtual IAllocator& getAllocator() = 0;
virtual void renderIcons(PipelineInstance& pipeline) = 0;
virtual ComponentUID getEditCamera() = 0;

View file

@ -55,6 +55,20 @@ public:
};
#pragma pack()
IScene* UniverseContext::getScene(uint32_t hash) const
{
for (auto* scene : m_scenes)
{
if (crc32(scene->getPlugin().getName()) == hash)
{
return scene;
}
}
return nullptr;
}
class EngineImpl : public Engine
{
public:
@ -62,9 +76,9 @@ public:
: m_allocator(allocator)
, m_resource_manager(m_allocator)
, m_mtjd_manager(m_allocator)
, m_scenes(m_allocator)
, m_fps(0)
, m_editor(nullptr)
, m_is_game_running(false)
{
if (!fs)
{
@ -92,8 +106,6 @@ public:
m_timer = Timer::create(m_allocator);
m_fps_timer = Timer::create(m_allocator);
m_fps_frame = 0;
m_universe = nullptr;
m_hierarchy = nullptr;
}
bool create()
@ -141,74 +153,40 @@ public:
virtual IAllocator& getAllocator() override { return m_allocator; }
virtual Universe* createUniverse() override
virtual UniverseContext& createUniverse() override
{
m_universe = m_allocator.newObject<Universe>(m_allocator);
m_hierarchy = Hierarchy::create(*m_universe, m_allocator);
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);
const Array<IPlugin*>& plugins = m_plugin_manager->getPlugins();
for (auto* plugin : plugins)
{
IScene* scene = plugin->createScene(*m_universe);
IScene* scene = plugin->createScene(*context);
if (scene)
{
m_scenes.push(scene);
context->m_scenes.push(scene);
}
}
return m_universe;
}
virtual IScene* getSceneByComponentType(uint32_t type) const override
{
for (int i = 0; i < m_scenes.size(); ++i)
{
if (m_scenes[i]->ownComponentType(type))
{
return m_scenes[i];
}
}
return nullptr;
}
virtual IScene* getScene(uint32_t type) const override
{
for (int i = 0; i < m_scenes.size(); ++i)
{
if (crc32(m_scenes[i]->getPlugin().getName()) == type)
{
return m_scenes[i];
}
}
return nullptr;
return *context;
}
virtual MTJD::Manager& getMTJDManager() override { return m_mtjd_manager; }
virtual const Array<IScene*>& getScenes() const override
virtual void destroyUniverse(UniverseContext& context) override
{
return m_scenes;
}
virtual void destroyUniverse() override
{
ASSERT(m_universe);
if (m_universe)
for (int i = context.m_scenes.size() - 1; i >= 0; --i)
{
for (int i = m_scenes.size() - 1; i >= 0; --i)
{
m_scenes[i]->getPlugin().destroyScene(m_scenes[i]);
}
m_scenes.clear();
Hierarchy::destroy(m_hierarchy);
m_hierarchy = nullptr;
m_allocator.deleteObject(m_universe);
m_universe = nullptr;
context.m_scenes[i]->getPlugin().destroyScene(context.m_scenes[i]);
}
Hierarchy::destroy(context.m_hierarchy);
m_allocator.deleteObject(context.m_universe);
m_allocator.deleteObject(&context);
}
virtual void setWorldEditor(WorldEditor& editor) override
@ -236,37 +214,40 @@ public:
virtual Renderer& getRenderer() override { return *m_renderer; }
void updateGame(float dt)
void updateGame(UniverseContext& context, float dt)
{
PROFILE_FUNCTION();
for (int i = 0; i < m_scenes.size(); ++i)
for (int i = 0; i < context.m_scenes.size(); ++i)
{
m_scenes[i]->update(dt);
context.m_scenes[i]->update(dt);
}
m_plugin_manager->update(dt);
m_input_system.update(dt);
}
virtual void startGame() override
virtual void startGame(UniverseContext& context) override
{
for (auto* scene : m_scenes)
ASSERT(!m_is_game_running);
m_is_game_running = true;
for (auto* scene : context.m_scenes)
{
scene->startGame();
}
}
virtual void stopGame() override
virtual void stopGame(UniverseContext& context) override
{
for (auto* scene : m_scenes)
ASSERT(m_is_game_running);
for (auto* scene : context.m_scenes)
{
scene->stopGame();
}
}
virtual void update(bool is_game_running,
virtual void update(UniverseContext& context,
float time_delta_multiplier,
float forced_time_delta) override
{
@ -292,17 +273,17 @@ public:
dt = m_timer->tick() * time_delta_multiplier;
}
m_last_time_delta = dt;
if (is_game_running)
if (m_is_game_running)
{
updateGame(dt);
updateGame(context, dt);
}
else
{
for (int i = 0; i < m_scenes.size(); ++i)
for (int i = 0; i < context.m_scenes.size(); ++i)
{
if (&m_scenes[i]->getPlugin() == m_renderer)
if (&context.m_scenes[i]->getPlugin() == m_renderer)
{
m_scenes[i]->update(dt);
context.m_scenes[i]->update(dt);
}
}
}
@ -319,12 +300,6 @@ public:
virtual InputSystem& getInputSystem() override { return m_input_system; }
virtual Universe* getUniverse() const override { return m_universe; }
virtual Hierarchy* getHierarchy() const override { return m_hierarchy; }
virtual ResourceManager& getResourceManager() override
{
return m_resource_manager;
@ -362,7 +337,8 @@ public:
}
virtual uint32_t serialize(OutputBlob& serializer) override
virtual uint32_t serialize(UniverseContext& ctx,
OutputBlob& serializer) override
{
SerializedEngineHeader header;
header.m_magic = SERIALIZED_ENGINE_MAGIC; // == '_LEN'
@ -372,15 +348,15 @@ public:
serializePluginList(serializer);
g_path_manager.serialize(serializer);
int pos = serializer.getSize();
m_universe->serialize(serializer);
m_hierarchy->serialize(serializer);
ctx.m_universe->serialize(serializer);
ctx.m_hierarchy->serialize(serializer);
m_renderer->serialize(serializer);
m_plugin_manager->serialize(serializer);
serializer.write((int32_t)m_scenes.size());
for (int i = 0; i < m_scenes.size(); ++i)
serializer.write((int32_t)ctx.m_scenes.size());
for (int i = 0; i < ctx.m_scenes.size(); ++i)
{
serializer.writeString(m_scenes[i]->getPlugin().getName());
m_scenes[i]->serialize(serializer);
serializer.writeString(ctx.m_scenes[i]->getPlugin().getName());
ctx.m_scenes[i]->serialize(serializer);
}
uint32_t crc = crc32((const uint8_t*)serializer.getData() + pos,
serializer.getSize() - pos);
@ -388,7 +364,8 @@ public:
}
virtual bool deserialize(InputBlob& serializer) override
virtual bool deserialize(UniverseContext& ctx,
InputBlob& serializer) override
{
SerializedEngineHeader header;
serializer.read(header);
@ -407,8 +384,8 @@ public:
return false;
}
g_path_manager.deserialize(serializer);
m_universe->deserialize(serializer);
m_hierarchy->deserialize(serializer);
ctx.m_universe->deserialize(serializer);
ctx.m_hierarchy->deserialize(serializer);
m_renderer->deserialize(serializer);
m_plugin_manager->deserialize(serializer);
int32_t scene_count;
@ -417,7 +394,7 @@ public:
{
char tmp[32];
serializer.readString(tmp, sizeof(tmp));
getScene(crc32(tmp))->deserialize(serializer);
ctx.getScene(crc32(tmp))->deserialize(serializer);
}
return true;
}
@ -440,15 +417,13 @@ private:
WorldEditor* m_editor;
PluginManager* m_plugin_manager;
Universe* m_universe;
Hierarchy* m_hierarchy;
Array<IScene*> m_scenes;
InputSystem m_input_system;
Timer* m_timer;
Timer* m_fps_timer;
int m_fps_frame;
float m_fps;
float m_last_time_delta;
bool m_is_game_running;
private:
void operator=(const EngineImpl&);
@ -471,8 +446,7 @@ Engine* Engine::create(FS::FileSystem* fs, IAllocator& allocator)
g_log_warning.getCallback().bind<showLogInVS>();
g_log_error.getCallback().bind<showLogInVS>();
EngineImpl* engine =
allocator.newObject<EngineImpl>(fs, allocator);
EngineImpl* engine = allocator.newObject<EngineImpl>(fs, allocator);
if (!engine->create())
{
allocator.deleteObject(engine);

View file

@ -32,6 +32,22 @@ class Universe;
class WorldEditor;
struct LUMIX_ENGINE_API UniverseContext
{
UniverseContext(IAllocator& allocator)
: m_scenes(allocator)
{
}
IScene* getScene(uint32_t hash) const;
Universe* m_universe;
Hierarchy* m_hierarchy;
Array<IScene*> m_scenes;
};
class LUMIX_ENGINE_API Engine
{
public:
@ -40,8 +56,8 @@ public:
static Engine* create(FS::FileSystem* fs, IAllocator& allocator);
static void destroy(Engine* engine);
virtual Universe* createUniverse() = 0;
virtual void destroyUniverse() = 0;
virtual UniverseContext& createUniverse() = 0;
virtual void destroyUniverse(UniverseContext& context) = 0;
virtual void setWorldEditor(WorldEditor& editor) = 0;
virtual WorldEditor* getWorldEditor() const = 0;
@ -50,24 +66,19 @@ public:
virtual InputSystem& getInputSystem() = 0;
virtual PluginManager& getPluginManager() = 0;
virtual IPlugin* loadPlugin(const char* name) = 0;
virtual Universe* getUniverse() const = 0;
virtual Hierarchy* getHierarchy() const = 0;
virtual const Array<IScene*>& getScenes() const = 0;
virtual IScene* getScene(uint32_t type) const = 0;
virtual IScene* getSceneByComponentType(uint32_t type) const = 0;
virtual MTJD::Manager& getMTJDManager() = 0;
virtual IAllocator& getAllocator() = 0;
virtual ResourceManager& getResourceManager() = 0;
virtual void startGame() = 0;
virtual void stopGame() = 0;
virtual void startGame(UniverseContext& context) = 0;
virtual void stopGame(UniverseContext& context) = 0;
virtual void update(bool is_game_running,
virtual void update(UniverseContext& context,
float time_delta_multiplier,
float forced_time_delta) = 0;
virtual uint32_t serialize(OutputBlob& serializer) = 0;
virtual bool deserialize(InputBlob& serializer) = 0;
virtual uint32_t serialize(UniverseContext& ctx, OutputBlob& serializer) = 0;
virtual bool deserialize(UniverseContext& ctx, InputBlob& serializer) = 0;
virtual float getFPS() const = 0;
virtual float getLastTimeDelta() = 0;

View file

@ -168,10 +168,10 @@ struct RendererImpl : public Renderer
}
virtual IScene* createScene(Universe& universe) override
virtual IScene* createScene(UniverseContext& ctx) override
{
return RenderScene::createInstance(
*this, m_engine, universe, true, m_allocator);
*this, m_engine, *ctx.m_universe, true, m_allocator);
}

View file

@ -11,6 +11,7 @@ namespace Lumix
class IPlugin;
class OutputBlob;
class Universe;
struct UniverseContext;
class LUMIX_ENGINE_API IScene abstract
@ -45,7 +46,7 @@ namespace Lumix
virtual void sendMessage(const char*) {};
virtual void setWorldEditor(class WorldEditor& editor) {}
virtual IScene* createScene(Universe&) { return nullptr; }
virtual IScene* createScene(UniverseContext&) { return nullptr; }
virtual void destroyScene(IScene*) { ASSERT(false); }
};

View file

@ -15,11 +15,18 @@ namespace LuaAPI
{
static void* getScene(Engine* engine, const char* name)
static void* getScene(UniverseContext* ctx, const char* name)
{
if (engine)
if (ctx)
{
return engine->getScene(crc32(name));
uint32_t hash = crc32(name);
for (auto* scene : ctx->m_scenes)
{
if (crc32(scene->getPlugin().getName()) == hash)
{
return scene;
}
}
}
return nullptr;
}
@ -124,9 +131,12 @@ registerCFunction(lua_State* L, const char* name, lua_CFunction func)
}
void registerEngineLuaAPI(Engine& engine, Universe& universe, lua_State* L)
void registerEngineLuaAPI(Engine& engine, UniverseContext& ctx, lua_State* L)
{
lua_pushlightuserdata(L, &universe);
lua_pushlightuserdata(L, &ctx);
lua_setglobal(L, "g_universe_context");
lua_pushlightuserdata(L, ctx.m_universe);
lua_setglobal(L, "g_universe");
lua_pushlightuserdata(L, &engine);

View file

@ -34,7 +34,7 @@ namespace Lumix
class LuaScriptSystemImpl;
void registerEngineLuaAPI(Engine&, Universe&, lua_State* L);
void registerEngineLuaAPI(Engine&, UniverseContext&, lua_State* L);
void registerPhysicsLuaAPI(Engine&, Universe&, lua_State* L);
@ -48,7 +48,7 @@ public:
virtual ~LuaScriptSystem();
IAllocator& getAllocator();
virtual IScene* createScene(Universe& universe) override;
virtual IScene* createScene(UniverseContext& universe) override;
virtual void destroyScene(IScene* scene) override;
virtual bool create() override;
virtual void destroy() override;
@ -93,9 +93,9 @@ public:
public:
LuaScriptScene(LuaScriptSystem& system, Engine& engine, Universe& universe)
LuaScriptScene(LuaScriptSystem& system, Engine& engine, UniverseContext& ctx)
: m_system(system)
, m_universe(universe)
, m_universe_context(ctx)
, m_scripts(system.getAllocator())
, m_valid(system.getAllocator())
, m_global_state(nullptr)
@ -123,15 +123,15 @@ public:
}
virtual Universe& getUniverse() override { return m_universe; }
virtual Universe& getUniverse() override { return *m_universe_context.m_universe; }
void registerAPI(lua_State* L)
{
registerEngineLuaAPI(m_system.m_engine, m_universe, L);
registerEngineLuaAPI(m_system.m_engine, m_universe_context, L);
if (m_system.m_engine.getPluginManager().getPlugin("physics"))
{
registerPhysicsLuaAPI(m_system.m_engine, m_universe, L);
registerPhysicsLuaAPI(m_system.m_engine, *m_universe_context.m_universe, L);
}
}
@ -273,7 +273,8 @@ public:
script.m_script = nullptr;
script.m_state = nullptr;
m_valid.push(true);
m_universe.addComponent(entity, type, this, m_scripts.size() - 1);
m_universe_context.m_universe->addComponent(
entity, type, this, m_scripts.size() - 1);
return m_scripts.size() - 1;
}
return INVALID_COMPONENT;
@ -285,7 +286,7 @@ public:
{
if (type == LUA_SCRIPT_HASH)
{
m_universe.destroyComponent(
m_universe_context.m_universe->destroyComponent(
Entity(m_scripts[component].m_entity), type, this, component);
m_valid[component] = false;
}
@ -346,7 +347,7 @@ public:
serializer.readString(tmp, sizeof(tmp));
prop.m_value = tmp;
}
m_universe.addComponent(
m_universe_context.m_universe->addComponent(
Entity(m_scripts[i].m_entity), LUA_SCRIPT_HASH, this, i);
}
}
@ -439,7 +440,7 @@ private:
BinaryArray m_valid;
Array<Script> m_scripts;
lua_State* m_global_state;
Universe& m_universe;
UniverseContext& m_universe_context;
};
@ -466,9 +467,9 @@ IAllocator& LuaScriptSystem::getAllocator()
}
IScene* LuaScriptSystem::createScene(Universe& universe)
IScene* LuaScriptSystem::createScene(UniverseContext& ctx)
{
return m_allocator.newObject<LuaScriptScene>(*this, m_engine, universe);
return m_allocator.newObject<LuaScriptScene>(*this, m_engine, ctx);
}

View file

@ -36,7 +36,7 @@ struct PhysicsSystemImpl : public PhysicsSystem
}
virtual bool create() override;
virtual IScene* createScene(Universe& universe) override;
virtual IScene* createScene(UniverseContext& universe) override;
virtual void destroyScene(IScene* scene) override;
virtual void destroy() override;
@ -86,9 +86,9 @@ struct CustomErrorCallback : public physx::PxErrorCallback
virtual void reportError(physx::PxErrorCode::Enum code, const char* message, const char* file, int line);
};
IScene* PhysicsSystemImpl::createScene(Universe& universe)
IScene* PhysicsSystemImpl::createScene(UniverseContext& ctx)
{
return PhysicsScene::create(*this, universe, m_engine, m_allocator);
return PhysicsScene::create(*this, *ctx.m_universe, m_engine, m_allocator);
}

View file

@ -268,10 +268,11 @@ public:
SetParentEditorCommand* command =
m_engine->getWorldEditor()
->getAllocator()
.newObject<SetParentEditorCommand>(*m_engine->getWorldEditor(),
*m_engine->getHierarchy(),
child,
parent_entity);
.newObject<SetParentEditorCommand>(
*m_engine->getWorldEditor(),
*m_engine->getWorldEditor()->getHierarchy(),
child,
parent_entity);
m_engine->getWorldEditor()->executeCommand(command);
return false;
@ -472,7 +473,8 @@ public:
void fillChildren(EntityNode* node)
{
Lumix::Array<Lumix::Hierarchy::Child>* children =
m_engine->getHierarchy()->getChildren(node->m_entity);
m_engine->getWorldEditor()->getHierarchy()->getChildren(
node->m_entity);
if (children)
{
for (int i = 0; i < children->size(); ++i)
@ -527,7 +529,8 @@ public:
m_universe = universe;
if (m_universe)
{
m_engine->getHierarchy()
m_engine->getWorldEditor()
->getHierarchy()
->parentSet()
.bind<EntityListModel, &EntityListModel::onParentSet>(this);
m_universe->entityCreated()
@ -538,7 +541,8 @@ public:
Lumix::Entity e = m_universe->getFirstEntity();
while (e >= 0)
{
Lumix::Entity parent = m_engine->getHierarchy()->getParent(e);
Lumix::Entity parent =
m_engine->getWorldEditor()->getHierarchy()->getParent(e);
if (parent < 0)
{
EntityNode* node = new EntityNode(m_root, e);

View file

@ -53,10 +53,10 @@ void InsertMeshCommand::deserialize(Lumix::JsonSerializer& serializer)
void InsertMeshCommand::execute()
{
Lumix::Engine& engine = m_editor.getEngine();
Lumix::Universe* universe = engine.getUniverse();
Lumix::Universe* universe = m_editor.getUniverse();
m_entity = universe->createEntity();
universe->setPosition(m_entity, m_position);
const Lumix::Array<Lumix::IScene*>& scenes = engine.getScenes();
const Lumix::Array<Lumix::IScene*>& scenes = m_editor.getScenes();
Lumix::ComponentIndex cmp;
Lumix::IScene* scene = nullptr;
for (int i = 0; i < scenes.size(); ++i)

View file

@ -61,10 +61,10 @@ public:
void renderPhysics()
{
Lumix::RenderScene* render_scene =
(Lumix::RenderScene*)m_world_editor->getEngine().getScene(
(Lumix::RenderScene*)m_world_editor->getScene(
Lumix::crc32("renderer"));
Lumix::PhysicsScene* scene = static_cast<Lumix::PhysicsScene*>(
m_world_editor->getEngine().getScene(Lumix::crc32("physics")));
m_world_editor->getScene(Lumix::crc32("physics")));
if (scene && render_scene)
{
scene->render(*render_scene);
@ -155,7 +155,8 @@ public:
m_world_editor = Lumix::WorldEditor::create(
QDir::currentPath().toLocal8Bit().data(), *m_engine);
m_engine->update(false, 1, -1);
Lumix::UniverseContext ctx(m_allocator);
m_engine->update(ctx, 1, -1);
m_main_window->setWorldEditor(*m_world_editor);
Lumix::PipelineInstance* pipeline = scene_view->getPipeline();

View file

@ -21,7 +21,8 @@ WGLRenderDevice::WGLRenderDevice(Lumix::Engine& engine,
m_pipeline = Lumix::PipelineInstance::create(*pipeline_object,
engine.getAllocator());
m_pipeline->setScene(
(Lumix::RenderScene*)engine.getScene(Lumix::crc32("renderer")));
(Lumix::RenderScene*)engine.getWorldEditor()->getScene(
Lumix::crc32("renderer")));
}
engine.getWorldEditor()
->universeCreated()
@ -49,7 +50,8 @@ void WGLRenderDevice::setWidget(QWidget& widget)
void WGLRenderDevice::onUniverseCreated()
{
getPipeline().setScene(
(Lumix::RenderScene*)m_engine.getScene(Lumix::crc32("renderer")));
(Lumix::RenderScene*)m_engine.getWorldEditor()->getScene(
Lumix::crc32("renderer")));
}