Skip to content

Commit

Permalink
[godot] Fix module build for Godot 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
badlogic committed Oct 9, 2024
1 parent 64c3e9a commit 13127aa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 36 deletions.
4 changes: 3 additions & 1 deletion spine-godot/spine_godot/SpineEditorPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ Error SpineAtlasResourceImportPlugin::import(const String &source_file, const St
atlas->set_normal_texture_prefix(options["normal_map_prefix"]);
atlas->load_from_atlas_file_internal(source_file, true);

String file_name = save_path + String(".") + _get_save_extension();
#if VERSION_MAJOR > 3
#ifdef SPINE_GODOT_EXTENSION
String file_name = save_path + String(".") + _get_save_extension();
auto error = ResourceSaver::get_singleton()->save(atlas, file_name);
#else
String file_name = save_path + String(".") + get_save_extension();
auto error = ResourceSaver::save(atlas, file_name);
#endif
#else
String file_name = save_path + String(".") + get_save_extension();
auto error = ResourceSaver::save(file_name, atlas);
#endif
return error;
Expand Down
2 changes: 2 additions & 0 deletions spine-godot/spine_godot/SpineSkeletonDataResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#ifdef SPINE_GODOT_EXTENSION
#include <godot_cpp/classes/encoded_object_as_id.hpp>
#else
#include <core/io/marshalls.h>
#endif

void SpineAnimationMix::_bind_methods() {
Expand Down
65 changes: 30 additions & 35 deletions spine-godot/spine_godot/SpineSprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,32 @@ struct SpineSpriteStatics {
Vector<Vector2> scratch_points;
#endif

SpineSpriteStatics(): sprite_count(0) {}
SpineSpriteStatics() : sprite_count(0) {
quad_indices.setSize(6, 0);
quad_indices[0] = 0;
quad_indices[1] = 1;
quad_indices[2] = 2;
quad_indices[3] = 2;
quad_indices[4] = 3;
quad_indices[5] = 0;
scratch_vertices.ensureCapacity(1200);

Ref<CanvasItemMaterial> material_normal(memnew(CanvasItemMaterial));
material_normal->set_blend_mode(CanvasItemMaterial::BLEND_MODE_MIX);
default_materials[spine::BlendMode_Normal] = material_normal;

Ref<CanvasItemMaterial> material_additive(memnew(CanvasItemMaterial));
material_additive->set_blend_mode(CanvasItemMaterial::BLEND_MODE_ADD);
default_materials[spine::BlendMode_Additive] = material_additive;

Ref<CanvasItemMaterial> material_multiply(memnew(CanvasItemMaterial));
material_multiply->set_blend_mode(CanvasItemMaterial::BLEND_MODE_MUL);
default_materials[spine::BlendMode_Multiply] = material_multiply;

Ref<CanvasItemMaterial> material_screen(memnew(CanvasItemMaterial));
material_screen->set_blend_mode(CanvasItemMaterial::BLEND_MODE_SUB);
default_materials[spine::BlendMode_Screen] = material_screen;
}

static SpineSpriteStatics &instance() {
static SpineSpriteStatics inst;
Expand Down Expand Up @@ -417,36 +442,6 @@ 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();
auto statics = SpineSpriteStatics::instance();
// One material per blend mode, shared across all sprites.
if (!statics.default_materials[0].is_valid()) {
Ref<CanvasItemMaterial> material_normal(memnew(CanvasItemMaterial));
material_normal->set_blend_mode(CanvasItemMaterial::BLEND_MODE_MIX);
statics.default_materials[spine::BlendMode_Normal] = material_normal;

Ref<CanvasItemMaterial> material_additive(memnew(CanvasItemMaterial));
material_additive->set_blend_mode(CanvasItemMaterial::BLEND_MODE_ADD);
statics.default_materials[spine::BlendMode_Additive] = material_additive;

Ref<CanvasItemMaterial> material_multiply(memnew(CanvasItemMaterial));
material_multiply->set_blend_mode(CanvasItemMaterial::BLEND_MODE_MUL);
statics.default_materials[spine::BlendMode_Multiply] = material_multiply;

Ref<CanvasItemMaterial> material_screen(memnew(CanvasItemMaterial));
material_screen->set_blend_mode(CanvasItemMaterial::BLEND_MODE_SUB);
statics.default_materials[spine::BlendMode_Screen] = material_screen;
}

// Setup static scratch buffers
if (statics.quad_indices.size() == 0) {
statics.quad_indices.setSize(6, 0);
statics.quad_indices[0] = 0;
statics.quad_indices[1] = 1;
statics.quad_indices[2] = 2;
statics.quad_indices[3] = 2;
statics.quad_indices[4] = 3;
statics.quad_indices[5] = 0;
statics.scratch_vertices.ensureCapacity(1200);
}

// Default debug settings
debug_root = false;
Expand Down Expand Up @@ -1003,7 +998,7 @@ void SpineSprite::draw() {
#ifdef SPINE_GODOT_EXTENSION
if (GEOMETRY2D::get_singleton()->is_point_in_polygon(mouse_position, statics.scratch_points)) {
#else
if (GEOMETRY2D::is_point_in_polygon(mouse_position, scratch_points)) {
if (GEOMETRY2D::is_point_in_polygon(mouse_position, statics.scratch_points)) {
#endif
hovered_slot = slot;
color = Color(1, 1, 1, 1);
Expand Down Expand Up @@ -1043,7 +1038,7 @@ void SpineSprite::draw() {
#ifdef SPINE_GODOT_EXTENSION
if (GEOMETRY2D::get_singleton()->is_point_in_polygon(mouse_position, statics.scratch_points)) {
#else
if (GEOMETRY2D::is_point_in_polygon(mouse_position, scratch_points)) {
if (GEOMETRY2D::is_point_in_polygon(mouse_position, statics.scratch_points)) {
#endif
hovered_slot = slot;
color = Color(1, 1, 1, 1);
Expand Down Expand Up @@ -1116,7 +1111,7 @@ void SpineSprite::draw() {
#ifdef SPINE_GODOT_EXTENSION
if (GEOMETRY2D::get_singleton()->is_point_in_polygon(mouse_local_position, statics.scratch_points)) {
#else
if (GEOMETRY2D::is_point_in_polygon(mouse_local_position, scratch_points)) {
if (GEOMETRY2D::is_point_in_polygon(mouse_local_position, statics.scratch_points)) {
#endif
hovered_bone = bone;
}
Expand Down Expand Up @@ -1144,7 +1139,7 @@ void SpineSprite::draw() {
#ifdef SPINE_GODOT_EXTENSION
if (GEOMETRY2D::get_singleton()->is_point_in_polygon(mouse_local_position, statics.scratch_points)) {
#else
if (GEOMETRY2D::is_point_in_polygon(mouse_local_position, scratch_points)) {
if (GEOMETRY2D::is_point_in_polygon(mouse_local_position, statics.scratch_points)) {
#endif
hovered_bone = bone;
}
Expand Down

0 comments on commit 13127aa

Please sign in to comment.