refactor
This commit is contained in:
parent
219b1feaea
commit
fb37abf7a1
|
@ -25,7 +25,7 @@ Controller::~Controller() {
|
|||
ASSERT(isEmpty());
|
||||
}
|
||||
|
||||
void Controller::destroy() {
|
||||
void Controller::clear() {
|
||||
unload();
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
void destroyRuntime(RuntimeContext& ctx);
|
||||
void update(RuntimeContext& ctx, LocalRigidTransform& root_motion) const;
|
||||
void getPose(RuntimeContext& ctx, struct Pose& pose);
|
||||
void destroy();
|
||||
void clear();
|
||||
|
||||
ResourceType getType() const override { return TYPE; }
|
||||
static const ResourceType TYPE;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "engine/hash_map.h"
|
||||
#include "engine/log.h"
|
||||
#include "engine/os.h"
|
||||
#include "engine/resource_manager.h"
|
||||
#include "controller_editor.h"
|
||||
#include "engine/reflection.h"
|
||||
#include "engine/world.h"
|
||||
|
@ -80,24 +81,12 @@ struct PropertyAnimationPlugin : AssetBrowser::Plugin, AssetCompiler::IPlugin
|
|||
|
||||
bool canCreateResource() const override { return true; }
|
||||
const char* getDefaultExtension() const override { return "anp"; }
|
||||
void createResource(OutputMemoryStream& blob) override {}
|
||||
|
||||
bool compile(const Path& src) override {
|
||||
return m_app.getAssetCompiler().copyCompile(src);
|
||||
}
|
||||
|
||||
bool createResource(const char* path) override
|
||||
{
|
||||
os::OutputFile file;
|
||||
FileSystem& fs = m_app.getEngine().getFileSystem();
|
||||
if (!fs.open(path, file)) {
|
||||
logError("Failed to create ", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool hasFloatProperty(const reflection::ComponentBase* cmp) {
|
||||
struct : reflection::IEmptyPropertyVisitor {
|
||||
void visit(const reflection::Property<float>& prop) override { result = true; }
|
||||
|
@ -276,45 +265,6 @@ struct PropertyAnimationPlugin : AssetBrowser::Plugin, AssetCompiler::IPlugin
|
|||
PropertyAnimation* m_current_resource = nullptr;
|
||||
};
|
||||
|
||||
|
||||
struct AnimControllerAssetBrowserPlugin : AssetBrowser::Plugin, AssetCompiler::IPlugin
|
||||
{
|
||||
explicit AnimControllerAssetBrowserPlugin(StudioApp& app)
|
||||
: m_app(app)
|
||||
, AssetBrowser::Plugin(app.getAllocator())
|
||||
{
|
||||
app.getAssetCompiler().registerExtension("act", anim::Controller::TYPE);
|
||||
}
|
||||
|
||||
void deserialize(InputMemoryStream& blob) override { ASSERT(false); }
|
||||
void serialize(OutputMemoryStream& blob) override {}
|
||||
|
||||
bool compile(const Path& src) override {
|
||||
return m_app.getAssetCompiler().copyCompile(src);
|
||||
}
|
||||
|
||||
bool onGUI(Span<AssetBrowser::ResourceView*> resources) override {
|
||||
if (resources.length() == 1 && ImGui::Button("Open in animation editor")) {
|
||||
m_controller_editor->show(resources[0]->getPath().c_str());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* getName() const override { return "Animation Controller"; }
|
||||
ResourceType getResourceType() const override { return anim::Controller::TYPE; }
|
||||
|
||||
bool createTile(const char* in_path, const char* out_path, ResourceType type) override
|
||||
{
|
||||
if (type == anim::Controller::TYPE) return m_app.getAssetBrowser().copyTile("editor/textures/tile_animation_graph.tga", out_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
StudioApp& m_app;
|
||||
anim::ControllerEditor* m_controller_editor = nullptr;
|
||||
};
|
||||
|
||||
|
||||
struct AnimablePropertyGridPlugin final : PropertyGrid::IPlugin
|
||||
{
|
||||
explicit AnimablePropertyGridPlugin(StudioApp& app)
|
||||
|
@ -388,44 +338,34 @@ struct StudioAppPlugin : StudioApp::IPlugin
|
|||
, m_animable_plugin(app)
|
||||
, m_animation_plugin(app)
|
||||
, m_prop_anim_plugin(app)
|
||||
, m_anim_ctrl_plugin(app)
|
||||
{}
|
||||
|
||||
const char* getName() const override { return "animation"; }
|
||||
|
||||
void init() override {
|
||||
AssetCompiler& compiler = m_app.getAssetCompiler();
|
||||
const char* act_exts[] = { "act", nullptr };
|
||||
const char* anp_exts[] = { "anp", nullptr };
|
||||
compiler.addPlugin(m_anim_ctrl_plugin, act_exts);
|
||||
compiler.addPlugin(m_prop_anim_plugin, anp_exts);
|
||||
|
||||
AssetBrowser& asset_browser = m_app.getAssetBrowser();
|
||||
asset_browser.addPlugin(m_animation_plugin);
|
||||
asset_browser.addPlugin(m_prop_anim_plugin);
|
||||
asset_browser.addPlugin(m_anim_ctrl_plugin);
|
||||
|
||||
m_app.getPropertyGrid().addPlugin(m_animable_plugin);
|
||||
|
||||
m_anim_editor = anim::ControllerEditor::create(m_app);
|
||||
m_app.addPlugin(*m_anim_editor);
|
||||
|
||||
m_anim_ctrl_plugin.m_controller_editor = m_anim_editor.get();
|
||||
m_anim_editor = anim::ControllerEditor::create(m_app);
|
||||
}
|
||||
|
||||
bool showGizmo(WorldView&, ComponentUID) override { return false; }
|
||||
|
||||
~StudioAppPlugin() {
|
||||
AssetCompiler& compiler = m_app.getAssetCompiler();
|
||||
compiler.removePlugin(m_anim_ctrl_plugin);
|
||||
compiler.removePlugin(m_prop_anim_plugin);
|
||||
|
||||
AssetBrowser& asset_browser = m_app.getAssetBrowser();
|
||||
asset_browser.removePlugin(m_animation_plugin);
|
||||
asset_browser.removePlugin(m_prop_anim_plugin);
|
||||
asset_browser.removePlugin(m_anim_ctrl_plugin);
|
||||
m_app.getPropertyGrid().removePlugin(m_animable_plugin);
|
||||
m_app.removePlugin(*m_anim_editor);
|
||||
}
|
||||
|
||||
|
||||
|
@ -433,7 +373,6 @@ struct StudioAppPlugin : StudioApp::IPlugin
|
|||
AnimablePropertyGridPlugin m_animable_plugin;
|
||||
AnimationAssetBrowserPlugin m_animation_plugin;
|
||||
PropertyAnimationPlugin m_prop_anim_plugin;
|
||||
AnimControllerAssetBrowserPlugin m_anim_ctrl_plugin;
|
||||
UniquePtr<anim::ControllerEditor> m_anim_editor;
|
||||
};
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,10 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
#include "engine/hash.h"
|
||||
#include "editor/studio_app.h"
|
||||
#include "engine/string.h"
|
||||
|
||||
|
||||
namespace Lumix {
|
||||
|
||||
|
@ -18,17 +14,15 @@ struct EventType {
|
|||
u16 size;
|
||||
|
||||
virtual ~EventType() {}
|
||||
virtual bool onGUI(u8* data, const struct ControllerEditor& editor) const = 0;
|
||||
virtual bool onGUI(u8* data, const struct Controller& controller) const = 0;
|
||||
};
|
||||
|
||||
struct ControllerEditor : StudioApp::GUIPlugin {
|
||||
struct ControllerEditor {
|
||||
static UniquePtr<ControllerEditor> create(StudioApp& app);
|
||||
|
||||
virtual void show(const char* path) = 0;
|
||||
virtual void registerEventType(UniquePtr<EventType>&& type) = 0;
|
||||
virtual ~ControllerEditor() {}
|
||||
};
|
||||
|
||||
|
||||
} // namespace anim
|
||||
} // namespace Lumix
|
||||
} // namespace Lumix
|
|
@ -130,17 +130,18 @@ struct AssetBrowserImpl : AssetBrowser {
|
|||
};
|
||||
|
||||
AssetBrowserImpl(StudioApp& app)
|
||||
: m_selected_resources(app.getAllocator())
|
||||
, m_history(app.getAllocator())
|
||||
, m_dir_history(app.getAllocator())
|
||||
, m_plugins(app.getAllocator())
|
||||
: m_allocator(app.getAllocator(), "asset browser")
|
||||
, m_selected_resources(m_allocator)
|
||||
, m_history(m_allocator)
|
||||
, m_dir_history(m_allocator)
|
||||
, m_plugins(m_allocator)
|
||||
, m_app(app)
|
||||
, m_is_open(false)
|
||||
, m_show_thumbnails(true)
|
||||
, m_show_subresources(true)
|
||||
, m_file_infos(app.getAllocator())
|
||||
, m_immediate_tiles(app.getAllocator())
|
||||
, m_subdirs(app.getAllocator())
|
||||
, m_file_infos(m_allocator)
|
||||
, m_immediate_tiles(m_allocator)
|
||||
, m_subdirs(m_allocator)
|
||||
{
|
||||
m_filter[0] = '\0';
|
||||
|
||||
|
@ -689,8 +690,12 @@ struct AssetBrowserImpl : AssetBrowser {
|
|||
bool input_entered = ImGui::InputTextWithHint("##name", "Name", tmp, sizeof(tmp), ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll);
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Create") || input_entered) {
|
||||
OutputMemoryStream blob(m_allocator);
|
||||
plugin->createResource(blob);
|
||||
StaticString<LUMIX_MAX_PATH> path(m_dir, "/", tmp, ".", plugin->getDefaultExtension());
|
||||
plugin->createResource(path);
|
||||
if (!fs.saveContentSync(Path(path), blob)) {
|
||||
logError("Failed to write ", path);
|
||||
}
|
||||
m_wanted_resource = path;
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
|
@ -1074,8 +1079,7 @@ struct AssetBrowserImpl : AssetBrowser {
|
|||
FileSystem& fs = m_app.getEngine().getFileSystem();
|
||||
if (os::dirExists(path)) {
|
||||
const Path tmp(fs.getBasePath(), "/", m_dir, "/");
|
||||
IAllocator& allocator = m_app.getAllocator();
|
||||
copyDir(path, tmp, allocator);
|
||||
copyDir(path, tmp, m_allocator);
|
||||
}
|
||||
PathInfo fi(path);
|
||||
const Path dest(fs.getBasePath(), "/", m_dir, "/", fi.m_basename, ".", fi.m_extension);
|
||||
|
@ -1244,7 +1248,7 @@ struct AssetBrowserImpl : AssetBrowser {
|
|||
thumbnail(m_immediate_tiles[idx], 50.f, selected);
|
||||
}
|
||||
|
||||
bool resourceList(Span<char> buf, FilePathHash& selected_path_hash, ResourceType type, bool can_create_new, bool enter_submit) const override {
|
||||
bool resourceList(Span<char> buf, FilePathHash& selected_path_hash, ResourceType type, bool can_create_new, bool enter_submit) override {
|
||||
auto iter = m_plugins.find(type);
|
||||
if (!iter.isValid()) return false;
|
||||
|
||||
|
@ -1257,8 +1261,11 @@ struct AssetBrowserImpl : AssetBrowser {
|
|||
|
||||
FileSelector& file_selector = m_app.getFileSelector();
|
||||
if (file_selector.gui("Save As", &show_new_fs, plugin->getDefaultExtension(), true)) {
|
||||
if (!plugin->createResource(file_selector.getPath())) {
|
||||
logError("Failed to create ", file_selector.getPath());
|
||||
OutputMemoryStream blob(m_allocator);
|
||||
plugin->createResource(blob);
|
||||
FileSystem& fs = m_app.getEngine().getFileSystem();
|
||||
if (!fs.saveContentSync(Path(file_selector.getPath()), blob)) {
|
||||
logError("Failed to write ", file_selector.getPath());
|
||||
return false;
|
||||
}
|
||||
copyString(buf, file_selector.getPath());
|
||||
|
@ -1354,7 +1361,7 @@ struct AssetBrowserImpl : AssetBrowser {
|
|||
void onBeforeSettingsSaved() override { m_app.getSettings().m_is_asset_browser_open = m_is_open; }
|
||||
|
||||
bool copyTile(const char* from, const char* to) override {
|
||||
OutputMemoryStream img(m_app.getAllocator());
|
||||
OutputMemoryStream img(m_allocator);
|
||||
if (!m_app.getEngine().getFileSystem().getContentSync(Path(from), img)) return false;
|
||||
|
||||
os::OutputFile file;
|
||||
|
@ -1373,6 +1380,7 @@ struct AssetBrowserImpl : AssetBrowser {
|
|||
return !file.isError();
|
||||
}
|
||||
|
||||
TagAllocator m_allocator;
|
||||
bool m_is_open;
|
||||
StudioApp& m_app;
|
||||
StaticString<LUMIX_MAX_PATH> m_dir;
|
||||
|
|
|
@ -30,7 +30,7 @@ struct LUMIX_EDITOR_API AssetBrowser : StudioApp::GUIPlugin {
|
|||
Plugin(IAllocator& allocator) : SimpleUndoRedo(allocator) {}
|
||||
|
||||
virtual bool canCreateResource() const { return false; }
|
||||
virtual bool createResource(const char* path) { return false; }
|
||||
virtual void createResource(OutputMemoryStream& content) {}
|
||||
virtual const char* getDefaultExtension() const { return ""; }
|
||||
|
||||
virtual bool onGUI(Span<ResourceView*> resource) = 0;
|
||||
|
@ -62,7 +62,7 @@ struct LUMIX_EDITOR_API AssetBrowser : StudioApp::GUIPlugin {
|
|||
virtual void removePlugin(Plugin& plugin) = 0;
|
||||
virtual void openInExternalEditor(struct Resource* resource) const = 0;
|
||||
virtual void openInExternalEditor(const char* path) const = 0;
|
||||
virtual bool resourceList(Span<char> buf, FilePathHash& selected_idx, ResourceType type, bool can_create_new, bool enter_submit = false) const = 0;
|
||||
virtual bool resourceList(Span<char> buf, FilePathHash& selected_idx, ResourceType type, bool can_create_new, bool enter_submit = false) = 0;
|
||||
virtual void tile(const Path& path, bool selected) = 0;
|
||||
virtual void saveResource(Resource& resource, OutputMemoryStream& file) = 0;
|
||||
virtual void releaseResources() = 0;
|
||||
|
|
|
@ -108,7 +108,7 @@ struct AssetCompilerImpl : AssetCompiler {
|
|||
Engine& engine = app.getEngine();
|
||||
FileSystem& fs = engine.getFileSystem();
|
||||
const char* base_path = fs.getBasePath();
|
||||
m_watcher = FileSystemWatcher::create(base_path, app.getAllocator());
|
||||
m_watcher = FileSystemWatcher::create(base_path, m_allocator);
|
||||
m_watcher->getCallback().bind<&AssetCompilerImpl::onFileChanged>(this);
|
||||
m_task.create("Asset compiler", true);
|
||||
Path path(base_path, ".lumix/resources");
|
||||
|
@ -136,7 +136,7 @@ struct AssetCompilerImpl : AssetCompiler {
|
|||
file.close();
|
||||
if (version != 0) {
|
||||
logWarning("Unsupported version of .lumix/resources. Rebuilding all assets.");
|
||||
os::FileIterator* iter = os::createFileIterator(".lumix/resources", m_app.getAllocator());
|
||||
os::FileIterator* iter = os::createFileIterator(".lumix/resources", m_allocator);
|
||||
os::FileInfo info;
|
||||
bool all_deleted = true;
|
||||
while (os::getNextFile(iter, &info)) {
|
||||
|
@ -209,7 +209,7 @@ struct AssetCompilerImpl : AssetCompiler {
|
|||
Engine& engine = m_app.getEngine();
|
||||
FileSystem& fs = engine.getFileSystem();
|
||||
const char* base_path = fs.getBasePath();
|
||||
m_watcher = FileSystemWatcher::create(base_path, m_app.getAllocator());
|
||||
m_watcher = FileSystemWatcher::create(base_path, m_allocator);
|
||||
m_watcher->getCallback().bind<&AssetCompilerImpl::onFileChanged>(this);
|
||||
m_dependencies.clear();
|
||||
m_resources.clear();
|
||||
|
@ -226,7 +226,7 @@ struct AssetCompilerImpl : AssetCompiler {
|
|||
|
||||
bool copyCompile(const Path& src) override {
|
||||
FileSystem& fs = m_app.getEngine().getFileSystem();
|
||||
OutputMemoryStream tmp(m_app.getAllocator());
|
||||
OutputMemoryStream tmp(m_allocator);
|
||||
if (!fs.getContentSync(src, tmp)) {
|
||||
logError("Failed to read ", src);
|
||||
return false;
|
||||
|
@ -238,7 +238,7 @@ struct AssetCompilerImpl : AssetCompiler {
|
|||
|
||||
bool writeCompiledResource(const char* locator, Span<const u8> data) override {
|
||||
constexpr u32 COMPRESSION_SIZE_LIMIT = 4096;
|
||||
OutputMemoryStream compressed(m_app.getAllocator());
|
||||
OutputMemoryStream compressed(m_allocator);
|
||||
i32 compressed_size = 0;
|
||||
if (data.length() > COMPRESSION_SIZE_LIMIT) {
|
||||
const i32 cap = LZ4_compressBound((i32)data.length());
|
||||
|
@ -402,7 +402,7 @@ struct AssetCompilerImpl : AssetCompiler {
|
|||
void fillDB() {
|
||||
FileSystem& fs = m_app.getEngine().getFileSystem();
|
||||
const Path list_path(fs.getBasePath(), ".lumix/resources/_list.txt");
|
||||
OutputMemoryStream content(m_app.getAllocator());
|
||||
OutputMemoryStream content(m_allocator);
|
||||
if (fs.getContentSync(Path(".lumix/resources/_list.txt"), content)) {
|
||||
lua_State* L = luaL_newstate();
|
||||
[&](){
|
||||
|
@ -458,9 +458,8 @@ struct AssetCompilerImpl : AssetCompiler {
|
|||
}
|
||||
|
||||
const char* key = lua_tostring(L, -2);
|
||||
IAllocator& allocator = m_app.getAllocator();
|
||||
const Path key_path(key);
|
||||
m_dependencies.insert(key_path, Array<Path>(allocator));
|
||||
m_dependencies.insert(key_path, Array<Path>(m_allocator));
|
||||
Array<Path>& values = m_dependencies.find(key_path).value();
|
||||
|
||||
LuaWrapper::forEachArrayItem<Path>(L, -1, "array of strings expected", [&values](const Path& p){
|
||||
|
@ -513,12 +512,12 @@ struct AssetCompilerImpl : AssetCompiler {
|
|||
}
|
||||
}
|
||||
|
||||
bool getMeta(const Path& res, void* user_ptr, void (*callback)(void*, lua_State*)) const override
|
||||
bool getMeta(const Path& res, void* user_ptr, void (*callback)(void*, lua_State*)) override
|
||||
{
|
||||
const StaticString<LUMIX_MAX_PATH> meta_path(res.c_str(), ".meta");
|
||||
|
||||
FileSystem& fs = m_app.getEngine().getFileSystem();
|
||||
OutputMemoryStream buf(m_app.getAllocator());
|
||||
OutputMemoryStream buf(m_allocator);
|
||||
|
||||
if (!fs.getContentSync(Path(meta_path), buf)) return false;
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ struct LUMIX_EDITOR_API AssetCompiler {
|
|||
virtual void addPlugin(IPlugin& plugin, const char** extensions) = 0;
|
||||
virtual void removePlugin(IPlugin& plugin) = 0;
|
||||
virtual bool compile(const Path& path) = 0;
|
||||
virtual bool getMeta(const Path& res, void* user_ptr, void (*callback)(void*, lua_State*)) const = 0;
|
||||
virtual bool getMeta(const Path& res, void* user_ptr, void (*callback)(void*, lua_State*)) = 0;
|
||||
virtual void updateMeta(const Path& res, const char* src) const = 0;
|
||||
virtual const HashMap<FilePathHash, ResourceItem>& lockResources() = 0;
|
||||
virtual void unlockResources() = 0;
|
||||
|
|
|
@ -12,11 +12,11 @@ namespace Lumix
|
|||
|
||||
|
||||
LogUI::LogUI(StudioApp& app, IAllocator& allocator)
|
||||
: m_allocator(allocator)
|
||||
: m_allocator(allocator, "log ui")
|
||||
, m_app(app)
|
||||
, m_messages(allocator)
|
||||
, m_messages(m_allocator)
|
||||
, m_level_filter(2 | 4)
|
||||
, m_notifications(allocator)
|
||||
, m_notifications(m_allocator)
|
||||
, m_last_uid(1)
|
||||
, m_is_open(false)
|
||||
, m_are_notifications_hovered(false)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "editor/studio_app.h"
|
||||
#include "editor/utils.h"
|
||||
#include "engine/allocators.h"
|
||||
#include "engine/array.h"
|
||||
#include "engine/log.h"
|
||||
#include "engine/sync.h"
|
||||
|
@ -55,7 +56,7 @@ struct LUMIX_EDITOR_API LogUI : StudioApp::GUIPlugin
|
|||
bool isOpen() const { return m_is_open; }
|
||||
void toggleUI() { m_is_open = !m_is_open; }
|
||||
|
||||
IAllocator& m_allocator;
|
||||
TagAllocator m_allocator;
|
||||
StudioApp& m_app;
|
||||
Array<Message> m_messages;
|
||||
Array<Notification> m_notifications;
|
||||
|
|
|
@ -205,7 +205,7 @@ struct Block {
|
|||
|
||||
struct ProfilerUIImpl final : StudioApp::GUIPlugin {
|
||||
ProfilerUIImpl(StudioApp& app, debug::Allocator* allocator, Engine& engine)
|
||||
: m_allocator(engine.getAllocator())
|
||||
: m_allocator(engine.getAllocator(), "profiler ui")
|
||||
, m_debug_allocator(allocator)
|
||||
, m_app(app)
|
||||
, m_threads(m_allocator)
|
||||
|
@ -1406,7 +1406,7 @@ struct ProfilerUIImpl final : StudioApp::GUIPlugin {
|
|||
}
|
||||
|
||||
StudioApp& m_app;
|
||||
IAllocator& m_allocator;
|
||||
TagAllocator m_allocator;
|
||||
debug::Allocator* m_debug_allocator;
|
||||
Array<AllocationTag> m_allocation_tags;
|
||||
int m_current_frame;
|
||||
|
|
|
@ -1378,7 +1378,7 @@ struct StudioAppImpl final : StudioApp
|
|||
ASSERT(false);
|
||||
return;
|
||||
}
|
||||
Lumix::menuItem(*action, enabled);
|
||||
if (Lumix::menuItem(*action, enabled)) action->func.invoke();
|
||||
}
|
||||
|
||||
void editMenu()
|
||||
|
@ -1463,7 +1463,9 @@ struct StudioAppImpl final : StudioApp
|
|||
menuItem("autosnapDown", true);
|
||||
menuItem("export_game", true);
|
||||
for (Action* action : m_tools_actions) {
|
||||
Lumix::menuItem(*action, true);
|
||||
if (Lumix::menuItem(*action, true)) {
|
||||
action->func.invoke();
|
||||
}
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
@ -1475,7 +1477,7 @@ struct StudioAppImpl final : StudioApp
|
|||
menuItem("settings", true);
|
||||
ImGui::Separator();
|
||||
for (Action* action : m_window_actions) {
|
||||
Lumix::menuItem(*action, true);
|
||||
if (Lumix::menuItem(*action, true)) action->func.invoke();
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
@ -1986,6 +1988,7 @@ struct StudioAppImpl final : StudioApp
|
|||
m_settings.m_is_entity_list_open = m_is_entity_list_open;
|
||||
m_settings.setValue(Settings::LOCAL, "fileselector_dir", m_file_selector.m_current_dir.c_str());
|
||||
|
||||
m_settings.m_is_maximized = os::isMaximized(m_main_window);
|
||||
if (!os::isMinimized(m_main_window)) {
|
||||
os::Rect win_rect = os::getWindowScreenRect(m_main_window);
|
||||
m_settings.m_window.x = win_rect.left;
|
||||
|
|
|
@ -162,11 +162,7 @@ void getShortcut(const Action& action, Span<char> buf) {
|
|||
bool menuItem(Action& a, bool enabled) {
|
||||
char buf[20];
|
||||
getShortcut(a, Span(buf));
|
||||
if (ImGui::MenuItem(a.label_short, buf, a.is_selected.invoke(), enabled)) {
|
||||
if (a.func.isValid()) a.func.invoke();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return ImGui::MenuItem(a.label_short, buf, a.is_selected.invoke(), enabled);
|
||||
}
|
||||
|
||||
void getEntityListDisplayName(StudioApp& app, World& world, Span<char> buf, EntityPtr entity)
|
||||
|
|
|
@ -57,7 +57,7 @@ inline Action::Modifiers operator |(Action::Modifiers a, Action::Modifiers b) {
|
|||
inline void operator |= (Action::Modifiers& a, Action::Modifiers b) { a = a | b; }
|
||||
|
||||
LUMIX_EDITOR_API void getShortcut(const Action& action, Span<char> buf);
|
||||
LUMIX_EDITOR_API bool menuItem(Action& a, bool enabled);
|
||||
LUMIX_EDITOR_API [[nodiscard]] bool menuItem(Action& a, bool enabled);
|
||||
LUMIX_EDITOR_API void getEntityListDisplayName(struct StudioApp& app, struct World& editor, Span<char> buf, EntityPtr entity);
|
||||
LUMIX_EDITOR_API bool inputString(const char* label, String* value);
|
||||
LUMIX_EDITOR_API bool inputString(const char* str_id, const char* label, String* value);
|
||||
|
|
|
@ -2592,7 +2592,7 @@ public:
|
|||
|
||||
|
||||
WorldEditorImpl(Engine& engine, IAllocator& allocator)
|
||||
: m_allocator(allocator)
|
||||
: m_allocator(allocator, "world editor")
|
||||
, m_world_destroyed(m_allocator)
|
||||
, m_world_created(m_allocator)
|
||||
, m_selected_entities(m_allocator)
|
||||
|
@ -2706,7 +2706,7 @@ public:
|
|||
};
|
||||
|
||||
|
||||
EntityRef cloneEntity(World& src_world, EntityRef src_e, World& dst_world, EntityPtr dst_parent, Array<EntityRef>& entities, const HashMap<EntityPtr, EntityPtr>& map) const override {
|
||||
EntityRef cloneEntity(World& src_world, EntityRef src_e, World& dst_world, EntityPtr dst_parent, Array<EntityRef>& entities, const HashMap<EntityPtr, EntityPtr>& map) override {
|
||||
entities.push(src_e);
|
||||
const EntityRef dst_e = (EntityRef)map[src_e];
|
||||
if (dst_parent.isValid()) {
|
||||
|
@ -3003,7 +3003,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
IAllocator& m_allocator;
|
||||
TagAllocator m_allocator;
|
||||
Engine& m_engine;
|
||||
WorldView* m_view = nullptr;
|
||||
UniquePtr<PrefabSystem> m_prefab_system;
|
||||
|
|
|
@ -153,7 +153,7 @@ struct LUMIX_EDITOR_API WorldEditor
|
|||
virtual void toggleGameMode() = 0;
|
||||
virtual void destroyWorldPartition(World::PartitionHandle partition) = 0;
|
||||
virtual void serializeWorldPartition(World::PartitionHandle partition, OutputMemoryStream& blob) = 0;
|
||||
virtual EntityRef cloneEntity(World& src_u, EntityRef src_e, World& dst_u, EntityPtr dst_parent, Array<EntityRef>& entities, const HashMap<EntityPtr, EntityPtr>& map) const = 0;
|
||||
virtual EntityRef cloneEntity(World& src_u, EntityRef src_e, World& dst_u, EntityPtr dst_parent, Array<EntityRef>& entities, const HashMap<EntityPtr, EntityPtr>& map) = 0;
|
||||
|
||||
virtual DelegateList<void()>& worldCreated() = 0;
|
||||
virtual DelegateList<void()>& worldDestroyed() = 0;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "engine/atomic.h"
|
||||
#include "engine/allocators.h"
|
||||
#include "engine/array.h"
|
||||
#include "engine/atomic.h"
|
||||
#include "engine/engine.h"
|
||||
#include "engine/fibers.h"
|
||||
#include "engine/allocator.h"
|
||||
|
@ -51,18 +52,18 @@ struct Work {
|
|||
Type type;
|
||||
};
|
||||
|
||||
struct System
|
||||
{
|
||||
struct System {
|
||||
System(IAllocator& allocator)
|
||||
: m_allocator(allocator)
|
||||
, m_workers(allocator)
|
||||
, m_free_fibers(allocator)
|
||||
, m_backup_workers(allocator)
|
||||
, m_work_queue(allocator)
|
||||
, m_sleeping_workers(allocator)
|
||||
: m_allocator(allocator, "job system")
|
||||
, m_workers(m_allocator)
|
||||
, m_free_fibers(m_allocator)
|
||||
, m_backup_workers(m_allocator)
|
||||
, m_work_queue(m_allocator)
|
||||
, m_sleeping_workers(m_allocator)
|
||||
{}
|
||||
|
||||
|
||||
TagAllocator m_allocator;
|
||||
Lumix::Mutex m_sync;
|
||||
Lumix::Mutex m_job_queue_sync;
|
||||
Lumix::Mutex m_sleeping_sync;
|
||||
|
@ -71,7 +72,6 @@ struct System
|
|||
Array<WorkerTask*> m_backup_workers;
|
||||
FiberDecl m_fiber_pool[512];
|
||||
Array<FiberDecl*> m_free_fibers;
|
||||
IAllocator& m_allocator;
|
||||
RingBuffer<Work, 64> m_work_queue;
|
||||
};
|
||||
|
||||
|
@ -359,6 +359,9 @@ static bool popWork(Work& work, WorkerTask* worker) {
|
|||
Fiber::switchTo(&this_fiber->fiber, getWorker()->m_primary_fiber);
|
||||
}
|
||||
|
||||
IAllocator& getAllocator() {
|
||||
return g_system->m_allocator;
|
||||
}
|
||||
|
||||
bool init(u8 workers_count, IAllocator& allocator)
|
||||
{
|
||||
|
@ -377,7 +380,7 @@ bool init(u8 workers_count, IAllocator& allocator)
|
|||
|
||||
int count = maximum(1, int(workers_count));
|
||||
for (int i = 0; i < count; ++i) {
|
||||
WorkerTask* task = LUMIX_NEW(allocator, WorkerTask)(*g_system, i < 64 ? u64(1) << i : 0);
|
||||
WorkerTask* task = LUMIX_NEW(getAllocator(), WorkerTask)(*g_system, i < 64 ? u64(1) << i : 0);
|
||||
if (task->create("Worker", false)) {
|
||||
task->m_is_enabled = true;
|
||||
g_system->m_workers.push(task);
|
||||
|
@ -385,7 +388,7 @@ bool init(u8 workers_count, IAllocator& allocator)
|
|||
}
|
||||
else {
|
||||
logError("Job system worker failed to initialize.");
|
||||
LUMIX_DELETE(allocator, task);
|
||||
LUMIX_DELETE(getAllocator(), task);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -400,10 +403,6 @@ u8 getWorkersCount()
|
|||
return (u8)c;
|
||||
}
|
||||
|
||||
IAllocator& getAllocator() {
|
||||
return g_system->m_allocator;
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
{
|
||||
IAllocator& allocator = g_system->m_allocator;
|
||||
|
|
|
@ -57,6 +57,8 @@ void Path::endUpdate() {
|
|||
}
|
||||
|
||||
void Path::operator =(const char* rhs) {
|
||||
if (rhs == m_path) return;
|
||||
|
||||
normalize(rhs, Span(m_path));
|
||||
endUpdate();
|
||||
}
|
||||
|
|
|
@ -54,17 +54,8 @@ struct SpritePlugin final : AssetBrowser::Plugin, AssetCompiler::IPlugin
|
|||
bool canCreateResource() const override { return true; }
|
||||
const char* getDefaultExtension() const override { return "spr"; }
|
||||
|
||||
bool createResource(const char* path) override {
|
||||
os::OutputFile file;
|
||||
FileSystem& fs = m_app.getEngine().getFileSystem();
|
||||
if (!fs.open(path, file)) {
|
||||
logError("Failed to create ", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
file << "type \"simple\"";
|
||||
file.close();
|
||||
return true;
|
||||
void createResource(OutputMemoryStream& blob) override {
|
||||
blob << "type \"simple\"";
|
||||
}
|
||||
|
||||
void deserialize(InputMemoryStream& blob) override {
|
||||
|
|
|
@ -98,15 +98,8 @@ struct AssetPlugin : AssetBrowser::Plugin, AssetCompiler::IPlugin
|
|||
|
||||
bool canCreateResource() const override { return true; }
|
||||
|
||||
bool createResource(const char* path) override {
|
||||
OutputMemoryStream blob(m_app.getAllocator());
|
||||
void createResource(OutputMemoryStream& blob) override {
|
||||
blob << "function update(time_delta)\nend\n";
|
||||
|
||||
if (!m_app.getEngine().getFileSystem().saveContentSync(Path(path), blob)) {
|
||||
logError("Failed to write ", path);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const char* getDefaultExtension() const override { return "lua"; }
|
||||
|
|
|
@ -858,19 +858,7 @@ struct PhysicsMaterialPlugin final : AssetBrowser::Plugin, AssetCompiler::IPlugi
|
|||
|
||||
bool canCreateResource() const override { return true; }
|
||||
const char* getDefaultExtension() const override { return "pma"; }
|
||||
|
||||
bool createResource(const char* path) override
|
||||
{
|
||||
os::OutputFile file;
|
||||
FileSystem& fs = m_app.getEngine().getFileSystem();
|
||||
if (!fs.open(path, file)) {
|
||||
logError("Failed to create ", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
void createResource(OutputMemoryStream& blob) override {}
|
||||
|
||||
bool compile(const Path& src) override {
|
||||
return m_app.getAssetCompiler().copyCompile(src);
|
||||
|
|
|
@ -2701,17 +2701,11 @@ struct ParticleSystemPlugin final : AssetBrowser::Plugin, AssetCompiler::IPlugin
|
|||
|
||||
bool canCreateResource() const override { return true; }
|
||||
|
||||
bool createResource(const char* path) override {
|
||||
ParticleSystemEditorResource res(Path(path), m_app, m_app.getAllocator());
|
||||
void createResource(OutputMemoryStream& blob) override {
|
||||
ParticleSystemEditorResource res(Path("new particle system"), m_app, m_app.getAllocator());
|
||||
res.addEmitter();
|
||||
res.m_emitters[0]->initDefault(ParticleSystemResourceType::SYSTEM);
|
||||
OutputMemoryStream blob(m_app.getAllocator());
|
||||
res.serialize(blob);
|
||||
if (!m_app.getEngine().getFileSystem().saveContentSync(Path(path), blob)) {
|
||||
logError("Failed to write ", path);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const char* getDefaultExtension() const override { return "par"; }
|
||||
|
@ -2793,17 +2787,11 @@ struct FunctionBrowserPlugin : AssetBrowser::Plugin {
|
|||
|
||||
bool canCreateResource() const override { return true; }
|
||||
|
||||
bool createResource(const char* path) override {
|
||||
ParticleSystemEditorResource res(Path(path), m_app, m_app.getAllocator());
|
||||
void createResource(OutputMemoryStream& blob) override {
|
||||
ParticleSystemEditorResource res(Path("new particle function"), m_app, m_app.getAllocator());
|
||||
res.addEmitter();
|
||||
res.m_emitters[0]->initDefault(ParticleSystemResourceType::FUNCTION);
|
||||
OutputMemoryStream blob(m_app.getAllocator());
|
||||
res.serialize(blob);
|
||||
if (!m_app.getEngine().getFileSystem().saveContentSync(Path(path), blob)) {
|
||||
logError("Failed to write ", path);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const char* getDefaultExtension() const override { return "pfn"; }
|
||||
|
@ -3594,9 +3582,9 @@ struct ParticleEditorWindow : StudioApp::GUIPlugin, NodeEditor {
|
|||
if (ImGui::BeginMenuBar()) {
|
||||
if (ImGui::BeginMenu("File")) {
|
||||
const ParticleSystem* emitter = getSelectedParticleSystem();
|
||||
menuItem(m_app.getSaveAction(), true);
|
||||
if (menuItem(m_app.getSaveAction(), true)) saveAs(m_resource.m_path);
|
||||
if (ImGui::MenuItem("Save as")) m_show_save_as = true;
|
||||
menuItem(m_editor.m_apply_action, emitter && emitter->getResource());
|
||||
if (menuItem(m_editor.m_apply_action, emitter && emitter->getResource())) apply();
|
||||
ImGui::MenuItem("Autoapply", nullptr, &m_autoapply, emitter && emitter->getResource());
|
||||
if (ImGui::MenuItem("Debug entity", nullptr, false, emitter)) m_show_debug = true;
|
||||
|
||||
|
@ -3604,8 +3592,8 @@ struct ParticleEditorWindow : StudioApp::GUIPlugin, NodeEditor {
|
|||
}
|
||||
if (ImGui::BeginMenu("Edit")) {
|
||||
ImGui::MenuItem("World space", 0, &m_resource.m_world_space);
|
||||
menuItem(m_app.getUndoAction(), canUndo());
|
||||
menuItem(m_app.getRedoAction(), canRedo());
|
||||
if (menuItem(m_app.getUndoAction(), canUndo())) undo();
|
||||
if (menuItem(m_app.getRedoAction(), canRedo())) redo();
|
||||
if (ImGui::MenuItem(ICON_FA_BRUSH "Clear")) deleteUnreachable();
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
|
|
@ -782,17 +782,8 @@ struct MaterialPlugin final : AssetBrowser::Plugin, AssetCompiler::IPlugin
|
|||
bool canCreateResource() const override { return true; }
|
||||
const char* getDefaultExtension() const override { return "mat"; }
|
||||
|
||||
bool createResource(const char* path) override {
|
||||
os::OutputFile file;
|
||||
FileSystem& fs = m_app.getEngine().getFileSystem();
|
||||
if (!fs.open(path, file)) {
|
||||
logError("Failed to create ", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
file << "shader \"/pipelines/standard.shd\"";
|
||||
file.close();
|
||||
return true;
|
||||
void createResource(OutputMemoryStream& blob) override {
|
||||
blob << "shader \"/pipelines/standard.shd\"";
|
||||
}
|
||||
|
||||
bool compile(const Path& src) override
|
||||
|
@ -1126,11 +1117,10 @@ struct TexturePlugin final : AssetBrowser::Plugin, AssetCompiler::IPlugin
|
|||
|
||||
const char* getDefaultExtension() const override { return "ltc"; }
|
||||
bool canCreateResource() const override { return true; }
|
||||
bool createResource(const char* path) override {
|
||||
FileSystem& fs = m_app.getEngine().getFileSystem();
|
||||
void createResource(OutputMemoryStream& blob) override {
|
||||
CompositeTexture ltc(m_app, m_app.getAllocator());
|
||||
ltc.initDefault();
|
||||
return ltc.save(fs, Path(path));
|
||||
ltc.serialize(blob);
|
||||
}
|
||||
|
||||
struct TextureTileJob
|
||||
|
@ -5414,6 +5404,6 @@ struct StudioAppPlugin : StudioApp::IPlugin
|
|||
|
||||
LUMIX_STUDIO_ENTRY(renderer)
|
||||
{
|
||||
auto& allocator = app.getAllocator();
|
||||
IAllocator& allocator = app.getAllocator();
|
||||
return LUMIX_NEW(allocator, StudioAppPlugin)(app);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue