Skip to content

Commit

Permalink
[godot] Non-working but compiling state. Crashes when registering var…
Browse files Browse the repository at this point in the history
…ious inspectors/editor plugins
  • Loading branch information
badlogic committed Oct 7, 2024
1 parent e9b43f9 commit 887f204
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,4 @@ spine-godot/example-v4-extension/.godot
spine-godot/src
spine-godot/compile_commands.json
spine-godot/bin
spine-godot/example-v4-extension/bin/macos/macos.framework/libspine_godot.macos.editor
20 changes: 20 additions & 0 deletions spine-godot/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@
"program": "${workspaceFolder}/godot/bin/godot.macos.editor.dev.arm64"
}
},
{
"type": "cppvsdbg",
"request": "launch",
"name": "debug editor extension",
"program": "godot/bin/godot.windows.editor.dev.x86_64.exe",
"args": ["-e", "--path", "example-v4-extension"],
"cwd": "${workspaceFolder}",
"linux": {
"type": "lldb",
"request": "launch",
"name": "debug editor extension",
"program": "${workspaceFolder}/godot/bin/godot.linux.editor.dev.x86_64"
},
"osx": {
"type": "lldb",
"request": "launch",
"name": "debug editor extension",
"program": "/Applications/Godot 4.3 Debug.app/Contents/MacOS/Godot"
}
},
{
"type": "cppvsdbg",
"request": "launch",
Expand Down
40 changes: 37 additions & 3 deletions spine-godot/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,43 @@ Run the following command to download godot-cpp:
env = SConscript("godot-cpp/SConstruct", {"env": env, "customs": customs})

env.Append(CPPDEFINES=["SPINE_GODOT_EXTENSION"])
env.Append(CPPPATH=["spine_godot/", "spine_godot/spine-cpp/include"])

sources = Glob("spine_godot/*.cpp") + Glob("spine_godot/spine-cpp/src/spine/*.cpp")
env.Append(CPPPATH=["spine_godot", "spine_godot/spine-cpp/include"])

# sources = Glob("spine_godot/*.cpp") + Glob("spine_godot/spine-cpp/src/spine/*.cpp")
sources = Glob("spine_godot/spine-cpp/src/spine/*.cpp")
sources.append("spine_godot/GodotSpineExtension.cpp")
sources.append("spine_godot/SpineAnimation.cpp")
sources.append("spine_godot/SpineAnimationState.cpp")
sources.append("spine_godot/SpineAnimationTrack.cpp")
sources.append("spine_godot/SpineAtlasResource.cpp")
sources.append("spine_godot/SpineAttachment.cpp")
sources.append("spine_godot/SpineBone.cpp")
sources.append("spine_godot/SpineBoneData.cpp")
sources.append("spine_godot/SpineBoneNode.cpp")
sources.append("spine_godot/SpineConstant.cpp")
sources.append("spine_godot/SpineConstraintData.cpp")
sources.append("spine_godot/SpineEditorPlugin.cpp")
sources.append("spine_godot/SpineEvent.cpp")
sources.append("spine_godot/SpineEventData.cpp")
sources.append("spine_godot/SpineIkConstraint.cpp")
sources.append("spine_godot/SpineIkConstraintData.cpp")
sources.append("spine_godot/SpinePathConstraint.cpp")
sources.append("spine_godot/SpinePathConstraintData.cpp")
sources.append("spine_godot/SpinePhysicsConstraint.cpp")
sources.append("spine_godot/SpinePhysicsConstraintData.cpp")
sources.append("spine_godot/SpineSkeleton.cpp")
sources.append("spine_godot/SpineSkeletonDataResource.cpp")
sources.append("spine_godot/SpineSkeletonFileResource.cpp")
sources.append("spine_godot/SpineSkin.cpp")
sources.append("spine_godot/SpineSlot.cpp")
sources.append("spine_godot/SpineSlotData.cpp")
sources.append("spine_godot/SpineSlotNode.cpp")
sources.append("spine_godot/SpineSprite.cpp")
sources.append("spine_godot/SpineTimeline.cpp")
sources.append("spine_godot/SpineTrackEntry.cpp")
sources.append("spine_godot/SpineTransformConstraint.cpp")
sources.append("spine_godot/SpineTransformConstraintData.cpp")
sources.append("spine_godot/register_types.cpp")

if env["target"] in ["editor", "template_debug"]:
try:
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ compatibility_minimum = "4.1"

[libraries]

macos.debug = "res://bin/macos/macos.framework/libspine_godot.macos.template_debug"
macos.debug = "res://bin/macos/macos.framework/libspine_godot.macos.editor"
macos.release = "res://bin/macos/macos.framework/libspine_godot.macos.template_release"
ios.debug = "res://bin/ios/ios.framework/libspine_godot.ios.template_debug"
ios.release = "res://bin/ios/ios.framework/libspine_godot.ios.template_release"
Expand Down
2 changes: 1 addition & 1 deletion spine-godot/gdextension.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ compatibility_minimum = "4.1"

[libraries]

macos.debug = "res://bin/macos/macos.framework/libspine_godot.macos.template_debug"
macos.debug = "res://bin/macos/macos.framework/libspine_godot.macos.editor"
macos.release = "res://bin/macos/macos.framework/libspine_godot.macos.template_release"
ios.debug = "res://bin/ios/ios.framework/libspine_godot.ios.template_debug"
ios.release = "res://bin/ios/ios.framework/libspine_godot.ios.template_release"
Expand Down
6 changes: 6 additions & 0 deletions spine-godot/spine_godot/SpineAtlasResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class SpineAtlasResourceFormatLoader : public ResourceFormatLoader {

public:
#ifdef SPINE_GODOT_EXTENSION
static void _bind_methods() {};

PackedStringArray _get_recognized_extensions();

bool _handles_type(const StringName &type);
Expand Down Expand Up @@ -134,8 +136,12 @@ class SpineAtlasResourceFormatSaver : public ResourceFormatSaver {

public:
#ifdef SPINE_GODOT_EXTENSION
static void _bind_methods() {};

Error _save(const Ref<Resource> &resource, const String &path, uint32_t flags) override;

bool _recognize(const Ref<Resource> &resource);

PackedStringArray _get_recognized_extensions(const Ref<Resource> &resource);
#else
#if VERSION_MAJOR > 3
Expand Down
2 changes: 1 addition & 1 deletion spine-godot/spine_godot/SpineEditorPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ SpineEditorPlugin::SpineEditorPlugin() {
add_import_plugin(memnew(SpineJsonResourceImportPlugin));
add_import_plugin(memnew(SpineBinaryResourceImportPlugin));
add_inspector_plugin(memnew(SpineSkeletonDataResourceInspectorPlugin));
add_inspector_plugin(memnew(SpineSpriteInspectorPlugin));
// add_inspector_plugin(memnew(SpineSpriteInspectorPlugin));
}
#else
SpineEditorPlugin::SpineEditorPlugin(EditorNode *node) {
Expand Down
8 changes: 8 additions & 0 deletions spine-godot/spine_godot/SpineEditorPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class SpineAtlasResourceImportPlugin : public EditorImportPlugin {

public:
#ifdef SPINE_GODOT_EXTENSION
static void _bind_methods() {};

String _get_importer_name() const override { return "spine.atlas"; }

String _get_visible_name() const override { return "Spine Runtime Atlas"; }
Expand Down Expand Up @@ -120,6 +122,8 @@ class SpineJsonResourceImportPlugin : public EditorImportPlugin {

public:
#ifdef SPINE_GODOT_EXTENSION
static void _bind_methods() {};

String _get_importer_name() const override { return "spine.json"; }

String _get_visible_name() const override { return "Spine Skeleton Json"; }
Expand Down Expand Up @@ -187,6 +191,8 @@ class SpineBinaryResourceImportPlugin : public EditorImportPlugin {

public:
#ifdef SPINE_GODOT_EXTENSION
static void _bind_methods() {};

String _get_importer_name() const override { return "spine.skel"; }

String _get_visible_name() const override { return "Spine Skeleton Binary"; }
Expand Down Expand Up @@ -271,6 +277,8 @@ class SpineSkeletonDataResourceInspectorPlugin : public EditorInspectorPlugin {

public:
#ifdef SPINE_GODOT_EXTENSION
static void _bind_methods() {}

bool _can_handle(Object *p_object) const override;
bool _parse_property(Object *object, Variant::Type type, const String &path, PropertyHint hint, const String &hint_text, const BitField<PropertyUsageFlags> p_usage, bool wide) override;
#else
Expand Down
6 changes: 6 additions & 0 deletions spine-godot/spine_godot/SpineSkeletonFileResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class SpineSkeletonFileResourceFormatLoader : public ResourceFormatLoader {

public:
#ifdef SPINE_GODOT_EXTENSION
static void _bind_methods() {};

PackedStringArray _get_recognized_extensions();

bool _handles_type(const StringName &type);
Expand Down Expand Up @@ -114,8 +116,12 @@ class SpineSkeletonFileResourceFormatSaver : public ResourceFormatSaver {

public:
#ifdef SPINE_GODOT_EXTENSION
static void _bind_methods() {};

Error _save(const Ref<Resource> &resource, const String &path, uint32_t flags) override;

bool _recognize(const Ref<Resource> &resource);

PackedStringArray _get_recognized_extensions(const Ref<Resource> &resource);
#else
#if VERSION_MAJOR > 3
Expand Down
24 changes: 12 additions & 12 deletions spine-godot/spine_godot/SpineSprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
#endif
#endif

Ref<CanvasItemMaterial>
/*Ref<CanvasItemMaterial>
SpineSprite::default_materials[4] = {};
static int sprite_count = 0;
static spine::Vector<unsigned short> quad_indices;
Expand All @@ -93,7 +93,7 @@ static spine::Vector<float> scratch_vertices;
static PackedVector2Array scratch_points;
#else
static Vector<Vector2> scratch_points;
#endif
#endif*/


static void clear_triangles(SpineMesh2D *mesh_instance) {
Expand Down Expand Up @@ -403,7 +403,7 @@ void SpineSprite::_bind_methods() {
}

SpineSprite::SpineSprite() : update_mode(SpineConstant::UpdateMode_Process), preview_skin("Default"), preview_animation("-- Empty --"), preview_frame(false), preview_time(0), skeleton_clipper(nullptr), modified_bones(false) {
skeleton_clipper = new spine::SkeletonClipping();
/*skeleton_clipper = new spine::SkeletonClipping();
// One material per blend mode, shared across all sprites.
if (!default_materials[0].is_valid()) {
Expand Down Expand Up @@ -453,16 +453,16 @@ SpineSprite::SpineSprite() : update_mode(SpineConstant::UpdateMode_Process), pre
debug_clipping = false;
debug_clipping_color = Color(0.8, 0, 0, 0.8);
sprite_count++;
sprite_count++;*/
}

SpineSprite::~SpineSprite() {
delete skeleton_clipper;
sprite_count--;
/*sprite_count--;
if (!sprite_count) {
for (int i = 0; i < 4; i++)
default_materials[i].unref();
}
}*/
}

void SpineSprite::set_skeleton_data_res(const Ref<SpineSkeletonDataResource> &_skeleton_data) {
Expand Down Expand Up @@ -513,7 +513,7 @@ void SpineSprite::on_skeleton_data_changed() {
}

void SpineSprite::generate_meshes_for_slots(Ref<SpineSkeleton> skeleton_ref) {
auto skeleton = skeleton_ref->get_spine_object();
/*auto skeleton = skeleton_ref->get_spine_object();
for (int i = 0, n = (int) skeleton->getSlots().size(); i < n; i++) {
auto mesh_instance = memnew(SpineMesh2D);
mesh_instance->set_position(Vector2(0, 0));
Expand All @@ -523,7 +523,7 @@ void SpineSprite::generate_meshes_for_slots(Ref<SpineSkeleton> skeleton_ref) {
add_child(mesh_instance);
mesh_instances.push_back(mesh_instance);
slot_nodes.add(spine::Vector<SpineSlotNode *>());
}
}*/
}

void SpineSprite::remove_meshes() {
Expand Down Expand Up @@ -758,7 +758,7 @@ void SpineSprite::update_skeleton(float delta) {
}

void SpineSprite::update_meshes(Ref<SpineSkeleton> skeleton_ref) {
spine::Skeleton *skeleton = skeleton_ref->get_spine_object();
/*spine::Skeleton *skeleton = skeleton_ref->get_spine_object();
for (int i = 0, n = (int) skeleton->getSlots().size(); i < n; ++i) {
spine::Slot *slot = skeleton->getDrawOrder()[i];
spine::Attachment *attachment = slot->getAttachment();
Expand Down Expand Up @@ -917,7 +917,7 @@ void SpineSprite::update_meshes(Ref<SpineSkeleton> skeleton_ref) {
}
skeleton_clipper->clipEnd(*slot);
}
skeleton_clipper->clipEnd();
skeleton_clipper->clipEnd();*/
}

#ifdef SPINE_GODOT_EXTENSION
Expand All @@ -943,7 +943,7 @@ void createLinesFromMesh(Vector<Vector2> &scratch_points, spine::Vector<unsigned
}

void SpineSprite::draw() {
if (!animation_state.is_valid() && !skeleton.is_valid()) return;
/*if (!animation_state.is_valid() && !skeleton.is_valid()) return;
if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) return;
#if VERSION_MAJOR > 3
Expand Down Expand Up @@ -1199,7 +1199,7 @@ void SpineSprite::draw() {
draw_string(default_font, Vector2(10, 0 + i * default_font->get_height()), hover_text_lines[i], Color(1, 1, 1, 1));
#endif
}
#endif
#endif*/
}

void SpineSprite::draw_bone(spine::Bone *bone, const Color &color) {
Expand Down
2 changes: 1 addition & 1 deletion spine-godot/spine_godot/SpineSprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class SpineSprite : public Node2D,

spine::Vector<spine::Vector<SpineSlotNode *>> slot_nodes;
Vector<SpineMesh2D *> mesh_instances;
static Ref<CanvasItemMaterial> default_materials[4];
// static Ref<CanvasItemMaterial> default_materials[4];
Ref<Material> normal_material;
Ref<Material> additive_material;
Ref<Material> multiply_material;
Expand Down
17 changes: 16 additions & 1 deletion spine-godot/spine_godot/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/


#include "SpineCommon.h"
#ifdef SPINE_GODOT_EXTENSION
#else
Expand Down Expand Up @@ -79,10 +80,17 @@ static void editor_init_callback() {

#ifdef SPINE_GODOT_EXTENSION
void initialize_spine_godot_module(ModuleInitializationLevel level) {
printf(">>>>>>>>>>>> level: %i\n", level);
if (level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
GDREGISTER_CLASS(SpineAtlasResourceImportPlugin);
GDREGISTER_CLASS(SpineJsonResourceImportPlugin);
GDREGISTER_CLASS(SpineBinaryResourceImportPlugin);
GDREGISTER_CLASS(SpineSkeletonDataResourceInspectorPlugin);
GDREGISTER_CLASS(SpineEditorPlugin);
EditorPlugins::add_plugin_class(StringName("SpineEditorPlugin"));
printf(">>>>>>>>>>>> registered editor plugin");
}
if (level != MODULE_INITIALIZATION_LEVEL_SCENE) return;
#else
#if VERSION_MAJOR > 3
void initialize_spine_godot_module(ModuleInitializationLevel level) {
Expand All @@ -103,6 +111,12 @@ void register_spine_godot_types() {
#endif
#endif
spine::Bone::setYDown(true);

GDREGISTER_CLASS(SpineAtlasResourceFormatLoader);
GDREGISTER_CLASS(SpineAtlasResourceFormatSaver);
GDREGISTER_CLASS(SpineSkeletonFileResourceFormatLoader);
GDREGISTER_CLASS(SpineSkeletonFileResourceFormatSaver);

GDREGISTER_CLASS(SpineObjectWrapper);
GDREGISTER_CLASS(SpineAtlasResource);
GDREGISTER_CLASS(SpineSkeletonFileResource);
Expand Down Expand Up @@ -180,10 +194,12 @@ void register_spine_godot_types() {
ResourceSaver::add_resource_format_saver(skeleton_file_saver);
#endif
#endif
printf(">>>>>>>>>>>>>>>>>>>> fuck\n");
}

#if VERSION_MAJOR > 3
void uninitialize_spine_godot_module(ModuleInitializationLevel level) {
return;
if (level != MODULE_INITIALIZATION_LEVEL_CORE) return;
#else
void unregister_spine_godot_types() {
Expand All @@ -208,7 +224,6 @@ extern "C" GDExtensionBool GDE_EXPORT spine_godot_library_init(GDExtensionInterf
init_obj.register_initializer(initialize_spine_godot_module);
init_obj.register_terminator(uninitialize_spine_godot_module);
init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_CORE);

return init_obj.init();
}
#endif

0 comments on commit 887f204

Please sign in to comment.