diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/editor/editor_node.cpp | 4 | ||||
-rw-r--r-- | tools/editor/plugins/script_editor_plugin.cpp | 83 | ||||
-rw-r--r-- | tools/editor/plugins/script_editor_plugin.h | 4 |
3 files changed, 90 insertions, 1 deletions
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 9f3c57b0df..7b44f2cad9 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -3047,7 +3047,7 @@ Error EditorNode::load_scene(const String& p_scene) { //_cleanup_scene(); // i'm sorry but this MUST happen to avoid modified resources to not be reloaded. - Ref<PackedScene> sdata = ResourceLoader::load(lpath); + Ref<PackedScene> sdata = ResourceLoader::load(lpath,"",true); if (!sdata.is_valid()) { current_option=-1; @@ -3064,6 +3064,8 @@ Error EditorNode::load_scene(const String& p_scene) { return ERR_FILE_NOT_FOUND; } + sdata->set_path(lpath,true); //take over path + Node*new_scene=sdata->instance(true); if (!new_scene) { diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index afde354e2d..b15abf8096 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -43,6 +43,83 @@ /*** SCRIPT EDITOR ****/ +class EditorScriptCodeCompletionCache : public ScriptCodeCompletionCache { + + + struct Cache { + uint64_t time_loaded; + RES cache; + }; + + Map<String,Cache> cached; + + +public: + + uint64_t max_time_cache; + int max_cache_size; + + void cleanup() { + + List< Map<String,Cache>::Element * > to_clean; + + + Map<String,Cache>::Element *I=cached.front(); + while(I) { + if ((OS::get_singleton()->get_ticks_msec()-I->get().time_loaded)>max_time_cache) { + to_clean.push_back(I); + } + I=I->next(); + } + + while(to_clean.front()) { + cached.erase(to_clean.front()->get()); + to_clean.pop_front(); + } + } + + RES get_cached_resource(const String& p_path) { + + Map<String,Cache>::Element *E=cached.find(p_path); + if (!E) { + + Cache c; + c.cache=ResourceLoader::load(p_path); + E=cached.insert(p_path,c); + } + + E->get().time_loaded=OS::get_singleton()->get_ticks_msec(); + + if (cached.size()>max_cache_size) { + uint64_t older; + Map<String,Cache>::Element *O=cached.front(); + older=O->get().time_loaded; + Map<String,Cache>::Element *I=O; + while(I) { + if (I->get().time_loaded<older) { + older = I->get().time_loaded; + O=I; + } + I=I->next(); + } + + if (O!=E) {//should never heppane.. + cached.erase(O); + } + } + + return E->get().cache; + } + + + EditorScriptCodeCompletionCache() { + + max_cache_size=128; + max_time_cache=5*60*1000; //minutes, five + } + +}; + #define SORT_SCRIPT_LIST void ScriptEditorQuickOpen::popup(const Vector<String>& p_functions, bool p_dontclear) { @@ -1694,6 +1771,7 @@ void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) { ScriptEditor::ScriptEditor(EditorNode *p_editor) { + completion_cache = memnew( EditorScriptCodeCompletionCache ); restoring_layout=false; waiting_update_names=false; editor=p_editor; @@ -1874,6 +1952,11 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { } +ScriptEditor::~ScriptEditor() { + + memdelete(completion_cache); +} + void ScriptEditorPlugin::edit(Object *p_object) { if (!p_object->cast_to<Script>()) diff --git a/tools/editor/plugins/script_editor_plugin.h b/tools/editor/plugins/script_editor_plugin.h index 74a7d7e3e5..0dd152cb25 100644 --- a/tools/editor/plugins/script_editor_plugin.h +++ b/tools/editor/plugins/script_editor_plugin.h @@ -106,6 +106,8 @@ public: }; +class EditorScriptCodeCompletionCache; + class ScriptEditor : public VBoxContainer { OBJ_TYPE(ScriptEditor, VBoxContainer ); @@ -191,6 +193,7 @@ class ScriptEditor : public VBoxContainer { ScriptEditorQuickOpen *quick_open; + EditorScriptCodeCompletionCache *completion_cache; void _editor_play(); void _editor_pause(); @@ -248,6 +251,7 @@ public: void get_window_layout(Ref<ConfigFile> p_layout); ScriptEditor(EditorNode *p_editor); + ~ScriptEditor(); }; class ScriptEditorPlugin : public EditorPlugin { |