diff --git a/qteditor/QtEditor/scripts/scriptcompiler.cpp b/qteditor/QtEditor/scripts/scriptcompiler.cpp index bcffe2ff9..92f5d084e 100644 --- a/qteditor/QtEditor/scripts/scriptcompiler.cpp +++ b/qteditor/QtEditor/scripts/scriptcompiler.cpp @@ -100,8 +100,8 @@ ScriptCompiler::Status ScriptCompiler::getStatus(const Lumix::Path& path) hash = crc32(path.c_str()); } - Lumix::Map::iterator iter = m_status.find(hash); - return iter == m_status.end() ? UNKNOWN : iter.second(); + QMap::iterator iter = m_status.find(hash); + return iter == m_status.end() ? UNKNOWN : iter.value(); } diff --git a/qteditor/QtEditor/scripts/scriptcompiler.h b/qteditor/QtEditor/scripts/scriptcompiler.h index 0b08ba332..b033bd2a7 100644 --- a/qteditor/QtEditor/scripts/scriptcompiler.h +++ b/qteditor/QtEditor/scripts/scriptcompiler.h @@ -2,6 +2,7 @@ #include +#include #include "core/array.h" #include "core/delegate_list.h" #include "core/map.h" @@ -50,7 +51,7 @@ private: CompileCallbacks m_delegates; Lumix::Path m_base_path; Lumix::Array m_processes; - Lumix::Map m_status; - Lumix::Map m_log; + QMap m_status; + QMap m_log; }; diff --git a/qteditor/QtEditor/wgl_render_device.h b/qteditor/QtEditor/wgl_render_device.h index 1bdbcc06c..e4df61c2c 100644 --- a/qteditor/QtEditor/wgl_render_device.h +++ b/qteditor/QtEditor/wgl_render_device.h @@ -16,7 +16,7 @@ public: ASSERT(pipeline_object); if(pipeline_object) { - m_pipeline = Lumix::PipelineInstance::create(*pipeline_object); + m_pipeline = Lumix::PipelineInstance::create(*pipeline_object, engine.getAllocator()); m_pipeline->setRenderer(engine.getRenderer()); } diff --git a/src/core/hash_map.h b/src/core/hash_map.h index 1d95814c6..2125ec4e5 100644 --- a/src/core/hash_map.h +++ b/src/core/hash_map.h @@ -91,15 +91,14 @@ namespace Lumix } }; - template, class Allocator = DefaultAllocator> + template> class HashMap { public: typedef T value_type; typedef K key_type; typedef Hasher hasher_type; - typedef Allocator allocator_type; - typedef HashMap my_type; + typedef HashMap my_type; typedef HashNode node_type; typedef uint32_t size_type; @@ -107,17 +106,16 @@ namespace Lumix static const size_type s_default_ids_count = 8; - template + template class HashMapIterator { public: typedef U key_type; typedef S value_type; typedef _Hasher hasher_type; - typedef _Allocator allocator_type; typedef HashNode node_type; - typedef HashMap hm_type; - typedef HashMapIterator my_type; + typedef HashMap hm_type; + typedef HashMapIterator my_type; friend class hm_type; @@ -201,22 +199,25 @@ namespace Lumix node_type* m_current_node; }; - typedef HashMapIterator iterator; + typedef HashMapIterator iterator; - HashMap() + HashMap(IAllocator& allocator) : m_sentinel(&m_sentinel) + , m_allocator(allocator) { init(); } - explicit HashMap(size_type buckets) + explicit HashMap(size_type buckets, IAllocator& allocator) : m_sentinel(&m_sentinel) + , m_allocator(allocator) { init(buckets); } HashMap(const my_type& src) : m_sentinel(&m_sentinel) + , m_allocator(src.m_allocator) { init(src.m_max_id); copyTableUninitialized(src.m_table, &src.m_sentinel, src.m_max_id); @@ -532,6 +533,6 @@ namespace Lumix size_type m_size; size_type m_mask; size_type m_max_id; - allocator_type m_allocator; + IAllocator& m_allocator; }; } // ~namespace Lumix diff --git a/src/core/input_system.h b/src/core/input_system.h index 14e4d06fe..17a43b611 100644 --- a/src/core/input_system.h +++ b/src/core/input_system.h @@ -7,11 +7,7 @@ namespace Lumix { - /* action type - key pressed - key down - key down duration - */ + class IAllocator; class LUMIX_CORE_API InputSystem { @@ -25,7 +21,7 @@ namespace Lumix }; public: - bool create(); + bool create(IAllocator& allocator); void destroy(); void update(float dt); diff --git a/src/core/map.h b/src/core/map.h index 1d75c19ba..765cd383c 100644 --- a/src/core/map.h +++ b/src/core/map.h @@ -11,7 +11,7 @@ namespace Lumix { -template +template class Map { private: @@ -104,19 +104,13 @@ class Map }; public: - Map(const Allocator& allocator) + Map(IAllocator& allocator) : m_allocator(allocator) { m_root = NULL; m_size = 0; } - Map() - { - m_root = NULL; - m_size = 0; - } - ~Map() { clear(); @@ -471,7 +465,7 @@ class Map private: Node* m_root; int m_size; - Allocator m_allocator; + IAllocator& m_allocator; }; diff --git a/src/core/memory_tracker.cpp b/src/core/memory_tracker.cpp index ed0b13b18..1782d50a0 100644 --- a/src/core/memory_tracker.cpp +++ b/src/core/memory_tracker.cpp @@ -62,10 +62,10 @@ namespace Lumix } }; - typedef Map map_alloc_order; - typedef Map file_line_map; - typedef Map file_map; - typedef Map alloc_count_map; + typedef Map map_alloc_order; + typedef Map file_line_map; + typedef Map file_map; + typedef Map alloc_count_map; #pragma init_seg(compiler) MemoryTracker MemoryTracker::s_instance; @@ -196,7 +196,7 @@ namespace Lumix memTrackerLog("MemoryTracker", "MemoryTracker No leaks detected!"); } - map_alloc_order alloc_order_map; + map_alloc_order alloc_order_map(m_allocator); for (EntryTable::iterator it = m_map.begin(); it != m_map.end(); ++it) { Entry& entry = *it; @@ -222,7 +222,7 @@ namespace Lumix { memTrackerLog("MemoryTracker", "Dumping objects ->"); - file_line_map report_map; + file_line_map report_map(m_allocator); { MT::SpinLock lock(m_spin_mutex); for (EntryTable::iterator it = m_map.begin(); it != m_map.end(); ++it) @@ -266,7 +266,7 @@ namespace Lumix { memTrackerLog("MemoryTracker", "Dumping objects ->"); - file_map report_map; + file_map report_map(m_allocator); { MT::SpinLock lock(m_spin_mutex); for (EntryTable::iterator it = m_map.begin(); it != m_map.end(); ++it) diff --git a/src/core/memory_tracker.h b/src/core/memory_tracker.h index 79a1437c9..a0401eadb 100644 --- a/src/core/memory_tracker.h +++ b/src/core/memory_tracker.h @@ -12,12 +12,11 @@ namespace Lumix { - class MemTrackAllocator + class MemTrackAllocator : public IAllocator { public: void* allocate(size_t n) { return malloc(n); } void deallocate(void* p) { free(p); } - void* reallocate(void* p, size_t n) { return realloc(p, n); } }; class LUMIX_CORE_API MemoryTracker @@ -80,6 +79,7 @@ namespace Lumix MT::SpinMutex m_spin_mutex; intptr_t m_allocated_memory; uint8_t m_mark; + MemTrackAllocator m_allocator; static MemoryTracker s_instance; static uint32_t s_alloc_counter; diff --git a/src/core/pc/input_system.cpp b/src/core/pc/input_system.cpp index 107c65176..9fbd7f663 100644 --- a/src/core/pc/input_system.cpp +++ b/src/core/pc/input_system.cpp @@ -9,6 +9,10 @@ namespace Lumix struct InputSystemImpl { + InputSystemImpl(IAllocator& allocator) + : m_actions(allocator) + {} + struct Action { InputSystem::InputType type; @@ -27,9 +31,9 @@ namespace Lumix } - bool InputSystem::create() + bool InputSystem::create(IAllocator& allocator) { - m_impl = LUMIX_NEW(InputSystemImpl)(); + m_impl = LUMIX_NEW(InputSystemImpl)(allocator); m_impl->m_mouse_rel_x = 0; m_impl->m_mouse_rel_y = 0; return true; diff --git a/src/editor/entity_template_system.cpp b/src/editor/entity_template_system.cpp index 2d85cfd89..8e256fd54 100644 --- a/src/editor/entity_template_system.cpp +++ b/src/editor/entity_template_system.cpp @@ -104,6 +104,7 @@ namespace Lumix EntityTemplateSystemImpl(WorldEditor& editor) : m_editor(editor) , m_universe(NULL) + , m_instances(editor.getAllocator()) { editor.universeCreated().bind(this); editor.universeDestroyed().bind(this); diff --git a/src/editor/world_editor.cpp b/src/editor/world_editor.cpp index bf564b0fe..3b2558581 100644 --- a/src/editor/world_editor.cpp +++ b/src/editor/world_editor.cpp @@ -795,6 +795,12 @@ struct WorldEditorImpl : public WorldEditor } + virtual IAllocator& getAllocator() override + { + return m_allocator; + } + + virtual Engine& getEngine() override { return *m_engine; @@ -1709,6 +1715,8 @@ struct WorldEditorImpl : public WorldEditor , m_universe_mutex(false) , m_toggle_game_mode_requested(false) , m_gizmo(*this) + , m_component_properties(m_allocator) + , m_components(m_allocator) { m_go_to_parameters.m_is_active = false; m_undo_index = -1; @@ -2105,6 +2113,7 @@ struct WorldEditorImpl : public WorldEditor float m_speed; }; + DefaultAllocator m_allocator; GoToParameters m_go_to_parameters; MT::Mutex m_universe_mutex; Gizmo m_gizmo; diff --git a/src/editor/world_editor.h b/src/editor/world_editor.h index ab661a8fb..5ebeadde5 100644 --- a/src/editor/world_editor.h +++ b/src/editor/world_editor.h @@ -60,6 +60,7 @@ namespace Lumix virtual IPropertyDescriptor* getProperty(const char* component_type, const char* property_name) = 0; virtual void executeCommand(class IEditorCommand* command) = 0; virtual Engine& getEngine() = 0; + virtual IAllocator& getAllocator() = 0; virtual void render(IRenderDevice& render_device) = 0; virtual void renderIcons(IRenderDevice& render_device) = 0; virtual Component getEditCamera() = 0; diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 98186d6d0..b93987bd3 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -86,7 +86,7 @@ namespace Lumix return false; } m_plugin_manager.addPlugin(m_renderer); - if (!m_input_system.create()) + if (!m_input_system.create(m_allocator)) { return false; } @@ -127,8 +127,8 @@ namespace Lumix virtual Universe* createUniverse() override { - m_universe = m_allocator.newObject(); - m_hierarchy = Hierarchy::create(*m_universe); + m_universe = m_allocator.newObject(m_allocator); + m_hierarchy = Hierarchy::create(*m_universe, m_allocator); const Array& plugins = m_plugin_manager.getPlugins(); for (int i = 0; i < plugins.size(); ++i) { diff --git a/src/graphics/model.h b/src/graphics/model.h index 3e919704f..fa886ecd1 100644 --- a/src/graphics/model.h +++ b/src/graphics/model.h @@ -77,10 +77,11 @@ class Model : public Resource }; public: - Model(const Path& path, ResourceManager& resource_manager) + Model(const Path& path, ResourceManager& resource_manager, IAllocator& allocator) : Resource(path, resource_manager) , m_geometry() , m_bounding_radius() + , m_bone_map(allocator) { } ~Model(); diff --git a/src/graphics/model_manager.cpp b/src/graphics/model_manager.cpp index 1f9c85123..22205b98f 100644 --- a/src/graphics/model_manager.cpp +++ b/src/graphics/model_manager.cpp @@ -8,7 +8,7 @@ namespace Lumix { Resource* ModelManager::createResource(const Path& path) { - return m_allocator.newObject(path, getOwner()); + return m_allocator.newObject(path, getOwner(), m_allocator); } void ModelManager::destroyResource(Resource& resource) diff --git a/src/graphics/pipeline.cpp b/src/graphics/pipeline.cpp index 8a42d907b..d3c7ca517 100644 --- a/src/graphics/pipeline.cpp +++ b/src/graphics/pipeline.cpp @@ -334,9 +334,10 @@ struct PipelineImpl : public Pipeline struct PipelineInstanceImpl : public PipelineInstance { - PipelineInstanceImpl(Pipeline& pipeline) + PipelineInstanceImpl(Pipeline& pipeline, IAllocator& allocator) : m_source(static_cast(pipeline)) , m_active_camera(Component::INVALID) + , m_custom_commands_handlers(allocator) { m_scene = NULL; m_light_dir.set(0, -1, 0); @@ -793,9 +794,9 @@ Pipeline::Pipeline(const Path& path, ResourceManager& resource_manager) } -PipelineInstance* PipelineInstance::create(Pipeline& pipeline) +PipelineInstance* PipelineInstance::create(Pipeline& pipeline, IAllocator& allocator) { - return LUMIX_NEW(PipelineInstanceImpl)(pipeline); + return LUMIX_NEW(PipelineInstanceImpl)(pipeline, allocator); } diff --git a/src/graphics/pipeline.h b/src/graphics/pipeline.h index 90c5489b1..e4494dce8 100644 --- a/src/graphics/pipeline.h +++ b/src/graphics/pipeline.h @@ -67,7 +67,7 @@ class LUMIX_ENGINE_API PipelineInstance abstract virtual void resize(int w, int h) = 0; virtual FrameBuffer* getShadowmapFramebuffer() = 0; - static PipelineInstance* create(Pipeline& src); + static PipelineInstance* create(Pipeline& src, IAllocator& allocator); static void destroy(PipelineInstance* pipeline); virtual Renderer& getRenderer() = 0; diff --git a/src/graphics/render_scene.cpp b/src/graphics/render_scene.cpp index e1f4d5e17..d854940e9 100644 --- a/src/graphics/render_scene.cpp +++ b/src/graphics/render_scene.cpp @@ -131,6 +131,7 @@ namespace Lumix , m_universe(universe) , m_renderer(renderer) , m_allocator(allocator) + , m_dynamic_renderable_cache(allocator) { m_universe.entityMoved().bind(this); m_timer = Timer::create(); diff --git a/src/graphics/terrain.cpp b/src/graphics/terrain.cpp index 3cb3e9d0d..3a3327f52 100644 --- a/src/graphics/terrain.cpp +++ b/src/graphics/terrain.cpp @@ -173,6 +173,8 @@ namespace Lumix , m_brush_position(0, 0, 0) , m_brush_size(1) , m_allocator(allocator) + , m_grass_quads(m_allocator) + , m_last_camera_position(m_allocator) { generateGeometry(); } diff --git a/src/graphics/terrain.h b/src/graphics/terrain.h index dc701fe76..e28f5889f 100644 --- a/src/graphics/terrain.h +++ b/src/graphics/terrain.h @@ -103,6 +103,7 @@ class Terrain void forceGrassUpdate(); private: + IAllocator& m_allocator; Mesh* m_mesh; TerrainQuad* m_root; Geometry m_geometry; @@ -119,11 +120,10 @@ class Terrain Array m_grass_types; Array m_free_grass_quads; Map > m_grass_quads; - Map m_last_camera_position; + Map m_last_camera_position; Vec3 m_brush_position; float m_brush_size; bool m_force_grass_update; - IAllocator& m_allocator; }; diff --git a/src/unit_tests/core/ut_hash_map.cpp b/src/unit_tests/core/ut_hash_map.cpp index b9d6d213f..e3d76c4e0 100644 --- a/src/unit_tests/core/ut_hash_map.cpp +++ b/src/unit_tests/core/ut_hash_map.cpp @@ -6,7 +6,8 @@ namespace { void UT_insert(const char* params) { - Lumix::HashMap hash_table; + Lumix::DefaultAllocator allocator; + Lumix::HashMap hash_table(allocator); LUMIX_EXPECT_TRUE(hash_table.empty()); }; diff --git a/src/universe/hierarchy.cpp b/src/universe/hierarchy.cpp index d2d17919c..98d7a00a1 100644 --- a/src/universe/hierarchy.cpp +++ b/src/universe/hierarchy.cpp @@ -17,8 +17,10 @@ class HierarchyImpl : public Hierarchy typedef HashMap Parents; public: - HierarchyImpl(Universe& universe) + HierarchyImpl(Universe& universe, IAllocator& allocator) : m_universe(universe) + , m_parents(allocator) + , m_children(allocator) { universe.entityMoved().bind(this); } @@ -168,9 +170,9 @@ class HierarchyImpl : public Hierarchy }; -Hierarchy* Hierarchy::create(Universe& universe) +Hierarchy* Hierarchy::create(Universe& universe, IAllocator& allocator) { - return LUMIX_NEW(HierarchyImpl)(universe); + return LUMIX_NEW(HierarchyImpl)(universe, allocator); } diff --git a/src/universe/hierarchy.h b/src/universe/hierarchy.h index fa6446694..92895bcf4 100644 --- a/src/universe/hierarchy.h +++ b/src/universe/hierarchy.h @@ -24,7 +24,7 @@ namespace Lumix public: - static Hierarchy* create(Universe& universe); + static Hierarchy* create(Universe& universe, IAllocator& allocator); static void destroy(Hierarchy* hierarchy); virtual ~Hierarchy() {} diff --git a/src/universe/universe.cpp b/src/universe/universe.cpp index d78854af4..ef46518b8 100644 --- a/src/universe/universe.cpp +++ b/src/universe/universe.cpp @@ -17,7 +17,9 @@ Universe::~Universe() } -Universe::Universe() +Universe::Universe(IAllocator& allocator) + : m_name_to_id_map(allocator) + , m_id_to_name_map(allocator) { m_positions.reserve(RESERVED_ENTITIES); m_rotations.reserve(RESERVED_ENTITIES); diff --git a/src/universe/universe.h b/src/universe/universe.h index 275571e79..ba789d001 100644 --- a/src/universe/universe.h +++ b/src/universe/universe.h @@ -28,7 +28,7 @@ class LUMIX_ENGINE_API Universe final { friend struct Entity; public: - Universe(); + Universe(IAllocator& allocator); ~Universe(); Entity createEntity();