Skip to content

Commit

Permalink
[cpp][flutter] Added spine-lite-cpp, changed spine-flutter to use spi…
Browse files Browse the repository at this point in the history
…ne-lite-cpp.
  • Loading branch information
badlogic committed Apr 19, 2024
1 parent 3507c8e commit ac7f065
Show file tree
Hide file tree
Showing 12 changed files with 1,020 additions and 1,023 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -200,3 +200,4 @@ spine-godot/godot-spine-csharp
spine-ue/Plugins/Developer
spine-haxe/export
spine-godot/example-v4-csharp/.godot
spine-flutter/src/spine-cpp-lite
4 changes: 1 addition & 3 deletions formatters/build.gradle
Expand Up @@ -30,9 +30,7 @@ spotless {
'spine-ue/**/*.cpp',
'spine-ue/**/*.h',
'spine-godot/spine_godot/*.cpp',
'spine-godot/spine_godot/*.h',
'spine-flutter/src/spine_flutter.cpp',
'spine-flutter/src/spine_flutter.h'
'spine-godot/spine_godot/*.h'
clangFormat("13.0.1").pathToExe("$System.env.CLANGFORMAT").style('file')
}

Expand Down
3 changes: 3 additions & 0 deletions spine-cpp/CMakeLists.txt
Expand Up @@ -14,6 +14,9 @@ file(GLOB SOURCES "spine-cpp/src/**/*.cpp")
add_library(spine-cpp STATIC ${SOURCES} ${INCLUDES})
target_include_directories(spine-cpp PUBLIC spine-cpp/include)

add_library(spine-cpp-lite STATIC ${SOURCES} ${INCLUDES} spine-cpp-lite/spine-cpp-lite.cpp)
target_include_directories(spine-cpp-lite PUBLIC spine-cpp/include)

# Install target
install(TARGETS spine-cpp EXPORT spine-cpp_TARGETS DESTINATION dist/lib)
install(FILES ${INCLUDES} DESTINATION dist/include)
Expand Down
996 changes: 996 additions & 0 deletions spine-cpp/spine-cpp-lite/spine-cpp-light.h

Large diffs are not rendered by default.

Expand Up @@ -27,7 +27,7 @@
* SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/

#include "spine_flutter.h"
#include "spine-cpp-light.h"
#include <spine/spine.h>
#include <spine/Version.h>
#include <spine/Debug.h>
Expand Down Expand Up @@ -64,7 +64,7 @@ class BlockAllocator : public SpineObject {
}

~BlockAllocator() {
for (int i = 0; i < blocks.size(); i++) {
for (int i = 0, n = (int) blocks.size(); i < n; i++) {
SpineExtension::free(blocks[i].memory, __FILE__, __LINE__);
}
}
Expand All @@ -82,7 +82,7 @@ class BlockAllocator : public SpineObject {

void compress() {
int totalSize = 0;
for (int i = 0; i < blocks.size(); i++) {
for (int i = 0, n = blocks.size(); i < n; i++) {
totalSize += blocks[i].size;
SpineExtension::free(blocks[i].memory, __FILE__, __LINE__);
}
Expand Down Expand Up @@ -115,6 +115,7 @@ struct EventListener : public AnimationStateListenerObject {

void callback(AnimationState *state, EventType type, TrackEntry *entry, Event *event) {
events.add(AnimationStateEvent(type, entry, event));
SP_UNUSED(state);
}
};

Expand Down Expand Up @@ -715,8 +716,8 @@ static _spine_render_command *batch_commands(BlockAllocator &allocator, Vector<_
int i = 1;
int numVertices = first->numVertices;
int numIndices = first->numIndices;
while (i <= commands.size()) {
_spine_render_command *cmd = i < commands.size() ? commands[i] : nullptr;
while (i <= (int) commands.size()) {
_spine_render_command *cmd = i < (int) commands.size() ? commands[i] : nullptr;
if (cmd != nullptr && cmd->atlasPage == first->atlasPage &&
cmd->blendMode == first->blendMode &&
cmd->colors[0] == first->colors[0] &&
Expand All @@ -731,7 +732,7 @@ static _spine_render_command *batch_commands(BlockAllocator &allocator, Vector<_
last->next = batched;
last = batched;
}
if (i == commands.size()) break;
if (i == (int) commands.size()) break;
first = commands[i];
startIndex = i;
numVertices = first->numVertices;
Expand Down Expand Up @@ -1097,21 +1098,21 @@ spine_event_type spine_animation_state_events_get_event_type(spine_animation_sta
if (events == nullptr) return SPINE_EVENT_TYPE_DISPOSE;
if (index < 0) return SPINE_EVENT_TYPE_DISPOSE;
EventListener *_events = (EventListener *) events;
if (index >= _events->events.size()) return SPINE_EVENT_TYPE_DISPOSE;
if (index >= (int) _events->events.size()) return SPINE_EVENT_TYPE_DISPOSE;
return (spine_event_type) _events->events[index].type;
}

spine_track_entry spine_animation_state_events_get_track_entry(spine_animation_state_events events, int32_t index) {
if (events == nullptr) return nullptr;
EventListener *_events = (EventListener *) events;
if (index >= _events->events.size()) return nullptr;
if (index >= (int) _events->events.size()) return nullptr;
return (spine_track_entry) _events->events[index].entry;
}

spine_event spine_animation_state_events_get_event(spine_animation_state_events events, int32_t index) {
if (events == nullptr) return nullptr;
EventListener *_events = (EventListener *) events;
if (index >= _events->events.size()) return nullptr;
if (index >= (int) _events->events.size()) return nullptr;
return (spine_event) _events->events[index].event;
}

Expand Down
2 changes: 1 addition & 1 deletion spine-flutter/compile-wasm.sh
Expand Up @@ -22,7 +22,7 @@ em++ \
--no-entry \
--extern-pre-js pre.js \
-s EXPORT_NAME=libspine_flutter \
src/spine_flutter.cpp `find src/spine-cpp/src -type f` \
src/spine-cpp-lite/spine-cpp-lite.cpp `find src/spine-cpp/src -type f` \
-o lib/assets/libspine_flutter.js
ls -lah lib/assets
rm pre.js
Expand Down
2 changes: 1 addition & 1 deletion spine-flutter/ios/Classes/spine_flutter.cpp
@@ -1,3 +1,3 @@
// Relative import to be able to reuse the C sources.
// See the comment in ../{projectName}}.podspec for more information.
#include "../../src/spine_flutter.cpp"
#include "../../src/spine-cpp-lite/spine-cpp-lite.cpp"
Binary file modified spine-flutter/lib/assets/libspine_flutter.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion spine-flutter/macos/Classes/spine_flutter.cpp
@@ -1,3 +1,3 @@
// Relative import to be able to reuse the C sources.
// See the comment in ../{projectName}}.podspec for more information.
#include "../../src/spine_flutter.cpp"
#include "../../src/spine-cpp-lite/spine-cpp-lite.cpp"
1 change: 1 addition & 0 deletions spine-flutter/setup.sh
Expand Up @@ -7,4 +7,5 @@ pushd $dir > /dev/null
cp -r ../spine-cpp/spine-cpp ios/Classes
cp -r ../spine-cpp/spine-cpp macos/Classes
cp -r ../spine-cpp/spine-cpp src
cp -r ../spine-cpp/spine-cpp-lite src
popd
17 changes: 5 additions & 12 deletions spine-flutter/src/CMakeLists.txt
Expand Up @@ -6,23 +6,16 @@ cmake_minimum_required(VERSION 3.10)
project(pine_flutter_library VERSION 0.0.1)

file(GLOB SPINE_SOURCES "spine-cpp/src/**/*.cpp")
file(GLOB SPINE_LITE_SOURCES "spine-cpp-lite/*.cpp")

add_library(spine_flutter SHARED
"spine_flutter.cpp"
${SPINE_SOURCES}
${SPINE_LITE_SOURCES}
)

set_target_properties(spine_flutter PROPERTIES
PUBLIC_HEADER spine_flutter.h
PUBLIC_HEADER spine-cpp-lite/spine_flutter.h
OUTPUT_NAME "spine_flutter"
)
target_include_directories(spine_flutter PUBLIC spine-cpp/include)
target_compile_definitions(spine_flutter PUBLIC DART_SHARED_LIB)

if(${SPINE_FLUTTER_TESTBED})
set (CMAKE_CXX_STANDARD 11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=undefined")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=undefined")
add_executable(spine_flutter_test main.cpp spine_flutter.cpp ${SPINE_SOURCES})
include_directories(spine_flutter_test PUBLIC spine-cpp/include)
endif()
target_include_directories(spine_flutter PUBLIC spine-cpp/include spine-cpp-lite)
target_compile_definitions(spine_flutter PUBLIC DART_SHARED_LIB)

0 comments on commit ac7f065

Please sign in to comment.