Skip to content

Commit

Permalink
pipeline editor
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Aug 2, 2023
1 parent dae4fe0 commit 44af15e
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 18 deletions.
10 changes: 5 additions & 5 deletions src/editor/asset_browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,14 +918,14 @@ struct AssetBrowserImpl : AssetBrowser {
}
}
else {
ResourceLocator rl(Span(path.c_str(), stringLength(path)));
if (!m_filter[0] && !Path::isSame(Span<const char>(m_dir, stringLength(m_dir)), rl.dir)) {
StaticString<LUMIX_MAX_PATH> 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<const char>(m_dir, stringLength(m_dir)), rl.dir)) {
StaticString<LUMIX_MAX_PATH> dir(rl.dir);
changeDir(dir, true);
}
m_wanted_resource = "";
}

Expand Down
4 changes: 1 addition & 3 deletions src/engine/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}


Expand Down
71 changes: 66 additions & 5 deletions src/renderer/editor/render_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PipelineResource>(path);
}

~EditorWindow() {
m_resource->decRefCount();
}

void save() {
Span<const u8> 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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions src/renderer/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -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<char> content;
String content;
};


Expand Down

0 comments on commit 44af15e

Please sign in to comment.