diff --git a/src/editor/asset_browser.cpp b/src/editor/asset_browser.cpp index c74ca8c476..8e1946031b 100644 --- a/src/editor/asset_browser.cpp +++ b/src/editor/asset_browser.cpp @@ -918,14 +918,14 @@ struct AssetBrowserImpl : AssetBrowser { } } else { + ResourceLocator rl(Span(path.c_str(), stringLength(path))); + if (!m_filter[0] && !Path::isSame(Span(m_dir, stringLength(m_dir)), rl.dir)) { + StaticString dir(rl.dir); + changeDir(dir, true); + } m_selected_resources.clear(); m_selected_resources.push(path); } - ResourceLocator rl(Span(path.c_str(), stringLength(path))); - if (!m_filter[0] && !Path::isSame(Span(m_dir, stringLength(m_dir)), rl.dir)) { - StaticString dir(rl.dir); - changeDir(dir, true); - } m_wanted_resource = ""; } diff --git a/src/engine/string.cpp b/src/engine/string.cpp index 24b88d9c4e..78e95d37b5 100644 --- a/src/engine/string.cpp +++ b/src/engine/string.cpp @@ -197,13 +197,11 @@ void String::resize(u32 size) { if (isSmall()) { if (size < sizeof(m_small)) { - m_size = size; m_small[size] = '\0'; } else { char* tmp = (char*)m_allocator.allocate(size + 1); memcpy(tmp, m_small, m_size + 1); - m_size = size; m_big = tmp; } } @@ -216,10 +214,10 @@ void String::resize(u32 size) } else { m_big = (char*)m_allocator.reallocate(m_big, size + 1, m_size + 1); - m_size = size; m_big[size] = '\0'; } } + m_size = size; } diff --git a/src/renderer/editor/render_plugins.cpp b/src/renderer/editor/render_plugins.cpp index c9846144c3..1ddd6fdd50 100644 --- a/src/renderer/editor/render_plugins.cpp +++ b/src/renderer/editor/render_plugins.cpp @@ -657,15 +657,74 @@ struct FontPlugin final : AssetBrowser::Plugin, AssetCompiler::IPlugin }; -struct PipelinePlugin final : AssetCompiler::IPlugin -{ +struct PipelinePlugin final : AssetCompiler::IPlugin, AssetBrowser::Plugin { + struct EditorWindow : AssetEditorWindow { + EditorWindow(const Path& path, StudioApp& app, IAllocator& allocator) + : AssetEditorWindow(app) + , m_allocator(allocator) + , m_buffer(allocator) + , m_app(app) + { + m_resource = app.getEngine().getResourceManager().load(path); + } + + ~EditorWindow() { + m_resource->decRefCount(); + } + + void save() { + Span data((const u8*)m_buffer.getData(), m_buffer.length()); + m_app.getAssetBrowser().saveResource(*m_resource, data); + m_dirty = false; + } + + bool onAction(const Action& action) override { + if (&action == &m_app.getSaveAction()) save(); + else return false; + return true; + } + + void windowGUI() override { + if (ImGui::BeginMenuBar()) { + if (ImGuiEx::IconButton(ICON_FA_SAVE, "Save")) save(); + if (ImGuiEx::IconButton(ICON_FA_EXTERNAL_LINK_ALT, "Open externally")) m_app.getAssetBrowser().openInExternalEditor(m_resource); + ImGui::EndMenuBar(); + } + + if (m_resource->isEmpty()) { + ImGui::TextUnformatted("Loading..."); + return; + } + + if (m_buffer.length() == 0) m_buffer = m_resource->content; + + if (inputStringMultiline("##code", &m_buffer, ImGui::GetContentRegionAvail())) { + m_dirty = true; + } + } + + void destroy() override { LUMIX_DELETE(m_allocator, this); } + const Path& getPath() override { return m_resource->getPath(); } + const char* getName() const override { return "lua script editor"; } + + IAllocator& m_allocator; + StudioApp& m_app; + PipelineResource* m_resource; + String m_buffer; + }; + explicit PipelinePlugin(StudioApp& app) : m_app(app) {} - bool compile(const Path& src) override - { - return m_app.getAssetCompiler().copyCompile(src); + bool compile(const Path& src) override { return m_app.getAssetCompiler().copyCompile(src); } + const char* getName() const override { return "Pipeline"; } + ResourceType getResourceType() const override { return ResourceType("pipeline"); } + + void onResourceDoubleClicked(const struct Path& path) { + IAllocator& allocator = m_app.getAllocator(); + EditorWindow* win = LUMIX_NEW(allocator, EditorWindow)(Path(path), m_app, m_app.getAllocator()); + m_app.getAssetBrowser().addWindow(win); } StudioApp& m_app; @@ -5206,6 +5265,7 @@ struct StudioAppPlugin : StudioApp::IPlugin asset_browser.addPlugin(m_font_plugin); asset_browser.addPlugin(m_shader_plugin); asset_browser.addPlugin(m_texture_plugin); + asset_browser.addPlugin(m_pipeline_plugin); m_app.addPlugin(m_scene_view); m_app.addPlugin(m_game_view); @@ -5424,6 +5484,7 @@ struct StudioAppPlugin : StudioApp::IPlugin asset_browser.removePlugin(m_font_plugin); asset_browser.removePlugin(m_texture_plugin); asset_browser.removePlugin(m_shader_plugin); + asset_browser.removePlugin(m_pipeline_plugin); AssetCompiler& asset_compiler = m_app.getAssetCompiler(); asset_compiler.removePlugin(m_font_plugin); diff --git a/src/renderer/pipeline.cpp b/src/renderer/pipeline.cpp index ac2f2a34b9..513adedbd1 100644 --- a/src/renderer/pipeline.cpp +++ b/src/renderer/pipeline.cpp @@ -358,14 +358,15 @@ ResourceType PipelineResource::TYPE("pipeline"); void PipelineResource::unload() { - content.clear(); + content.resize(0); } bool PipelineResource::load(u64 size, const u8* mem) { content.resize((int)size); - memcpy(content.begin(), mem, size); + memcpy(content.getData(), mem, size); + content.getData()[size] = '\0'; return true; } @@ -931,8 +932,8 @@ struct PipelineImpl final : Pipeline setDefine(); - const char* content = m_resource->content.begin(); - const int content_size = m_resource->content.size(); + const char* content = m_resource->content.c_str(); + const int content_size = m_resource->content.length(); bool errors = luaL_loadbuffer(m_lua_state, content, content_size, m_resource->getPath().c_str()) != 0; if (errors) diff --git a/src/renderer/pipeline.h b/src/renderer/pipeline.h index 03f6cc9c4c..4f7dcf55fb 100644 --- a/src/renderer/pipeline.h +++ b/src/renderer/pipeline.h @@ -4,6 +4,7 @@ #include "engine/delegate.h" #include "engine/hash.h" #include "engine/resource.h" +#include "engine/string.h" #include "renderer/gpu/gpu.h" @@ -52,7 +53,7 @@ struct LUMIX_RENDERER_API PipelineResource : Resource { bool load(u64 size, const u8* mem) override; ResourceType getType() const override { return TYPE; } - Array content; + String content; };