diff options
author | Juan Linietsky <reduzio@gmail.com> | 2015-06-26 01:14:31 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2015-06-26 01:14:49 -0300 |
commit | a67486a39ee629acac068a6d014015944cf83bb3 (patch) | |
tree | b101b6b94481d1ac074f917620a9545f9e516089 /tools/editor/plugins/script_editor_plugin.cpp | |
parent | 71cc2561c63b2b2bc692e370acbc8bb57f031567 (diff) |
improved get_node(), connect(), etc code completion.
-properly completes text arguments
-includes the "/root" autoloads
Diffstat (limited to 'tools/editor/plugins/script_editor_plugin.cpp')
-rw-r--r-- | tools/editor/plugins/script_editor_plugin.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
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>()) |