-
-
Notifications
You must be signed in to change notification settings - Fork 21k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added basic support for custom resource savers and loaders #19501
Conversation
scene/main/custom_resource_loader.h
Outdated
|
||
#include "scene/main/node.h" | ||
|
||
class CustomResourceLoader : public Node, public ResourceFormatLoader { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple inheritance fucks up the godot cast system on some platforms due to pointer adjustment, so it cant be used. Maybe instead, the system should be modified for ResourceFormatLoader and ResourceFormatSaver to inherit Reference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more in detail, using multiple inheritance breaks godot type system when disabling rtti
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can implement with composition then. The thing is, I'd really like to have this feature in 3.1 because it makes my plugin really hard to use.
If we do the Reference change, how will they be registered if we don't make them autoloads?
I worked on making
I also thought about some alternatives:
I'd need some feedback on which approach I should take, since I've spent a few nights on this already, I don't want to spend too much time in the wrong direction ;) |
format savers and loaders could be just another thing different that autoload, should not be a problem.
In game this is not possible, because Godot will never do project filesystem scanning on startup, this does need to be registered in the editor at some point, and I think when plugin is disabled/enabled is probably the best time. |
Godot does not need to do that because the addons folder is fixed and obeys to specific rules (
Ok, but how do I make the setting recognized? What I tried so far didn't work, ProjectSettings says no to me. |
I think it should "just work", but maybe there's some bug?. Are you adding using the ProjectSettings API or manually with a text editor? It could just be stored in |
@vnen I'm adding the settings with |
I updated the PR with the new approach:
Tested so far using this project: Extra notes:
@vnen it looks like adding the project setting within a category made it work. Somehow it didn't when it was outside. |
7f46c17
to
b47e6d8
Compare
Formatting needs to be fixed :) |
@mhilbrunner but when I run clang-format on |
@Zylann depending on the clang-format version it gives different results. It's simpler to apply the patch that Travis gives just to make it pass. |
@vnen see, just rebased and the errors went away :) |
Rebased again and updated. |
That might be simpler, but also (as @Zylann said) it's not possible to disable the loaders/savers (though it might not be really needed). The major issue for plugins is that named classes have no namespace, so they have to use some unique naming convention.
This would happen only in editor. The inheritance of named script classes are already checked and saved in the |
I like the fact it would reduce the registration boilerplate, but what should I remove from this PR, and how should we do registration? Waiting for @reduz to have a look since he appears to have an idea how to complete this PR |
c0b7101
to
16f882f
Compare
I updated the PR:
|
97e3413
to
5892bb5
Compare
Moving to 3.2 milestone as we're about to enter the beta stage and release freeze for Godot 3.1. Only bug fixes against issues of the 3.1 milestone (or enhancements to core features of the 3.1 roadmap) will be considered until 3.1-stable is released. Note: If it's merged after 3.1-stable is released, this change might be considered for cherry-picking into a later 3.1.x release. |
core/io/custom_resource_loader.cpp
Outdated
@@ -0,0 +1,70 @@ | |||
#include "custom_resource_loader.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have the Godot copyright header (with the filename on line 2, see other existing files). Same with other added files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed those files now.
df71b6f
to
9a63378
Compare
I removed |
9a63378
to
05f6a3d
Compare
Docs written for |
05f6a3d
to
065e267
Compare
Thanks! |
Some used 'is_valid()' checks, others not. Validity is already checked in 'unref()', and 'remove_resource_format_*()' has an ERR_FAIL condition on 'is_null()' already (which shouldn't happen since we're only unregistering things that we previously registered. Also add missing GDCLASS statement in ResourceFormatLoaderVideoStreamGDNative, missed in godotengine#20552 which was last amended before godotengine#19501 was merged.
Adds support for custom loaders and savers, so you can add new file types for Godot to load and save using
ResourceLoader
andResourceSaver
.Jump here for updated proposal --> #19501 (comment)
Old proposal:
It basically exposes an internal API which was however unfit for the scripting API, but changing this core API could be more work, so a compromise is taken:
Custom loaders and savers are nodes, which you can add as autoloads.
Plugins defining new filetypes can then add those autoloads automatically when the get activated and deactivated (however, see #19499).
Notes:
.tres
in the save dialog, so you have to select the custom extension manually. I would like to make it default to the custom extension (or even remove the others), but I couldn't find how.remove_autoload_singleton
when my plugin exits the tree, Godot now crashes everytime on exit with errors about the scene tree. I thinkEditorPlugin
needs an additional function to know when it's disabled or enabled, as opposed to just being added or removed from the tree, because there is no clean way to differentiate this from an editor launch or exit (can't useis_plugin_enabled
because it isn't updated in time) @vnenCustomResourceLoader.zip