Ver Fonte

more sokol_spine.h wip

Andre Weissflog há 3 anos atrás
pai
commit
37e8421fd1

+ 8 - 6
tests/functional/CMakeLists.txt

@@ -1,14 +1,16 @@
 if (NOT ANDROID AND NOT UWP)
 
 file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/assets/comsi.s3m DESTINATION ${CMAKE_BINARY_DIR})
-file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/assets/spineboy-pro.json DESTINATION ${CMAKE_BINARY_DIR})
-file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/assets/spineboy.atlas DESTINATION ${CMAKE_BINARY_DIR})
-file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/assets/spineboy.png DESTINATION ${CMAKE_BINARY_DIR})
+file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../ext/spine-runtimes/examples/spineboy/export/spineboy-pro.json DESTINATION ${CMAKE_BINARY_DIR})
+file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../ext/spine-runtimes/examples/spineboy/export/spineboy-pro.skel DESTINATION ${CMAKE_BINARY_DIR})
+file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../ext/spine-runtimes/examples/spineboy/export/spineboy.atlas DESTINATION ${CMAKE_BINARY_DIR})
+file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../ext/spine-runtimes/examples/spineboy/export/spineboy.png DESTINATION ${CMAKE_BINARY_DIR})
 
 file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/assets/comsi.s3m DESTINATION ${CMAKE_BINARY_DIR}/Debug)
-file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/assets/spineboy-pro.json DESTINATION ${CMAKE_BINARY_DIR}/Debug)
-file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/assets/spineboy.atlas DESTINATION ${CMAKE_BINARY_DIR}/Debug)
-file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/assets/spineboy.png DESTINATION ${CMAKE_BINARY_DIR}/Debug)
+file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../ext/spine-runtimes/examples/spineboy/export/spineboy-pro.json DESTINATION ${CMAKE_BINARY_DIR}/Debug)
+file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../ext/spine-runtimes/examples/spineboy/export/spineboy-pro.skel DESTINATION ${CMAKE_BINARY_DIR}/Debug)
+file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../ext/spine-runtimes/examples/spineboy/export/spineboy.atlas DESTINATION ${CMAKE_BINARY_DIR}/Debug)
+file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../ext/spine-runtimes/examples/spineboy/export/spineboy.png DESTINATION ${CMAKE_BINARY_DIR}/Debug)
 
 set(c_sources
     sokol_args_test.c

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 541
tests/functional/assets/spineboy-pro.json


+ 0 - 101
tests/functional/assets/spineboy.atlas

@@ -1,101 +0,0 @@
-spineboy.png
-	size: 1024, 256
-	filter: Linear, Linear
-	scale: 0.5
-crosshair
-	bounds: 813, 160, 45, 45
-eye-indifferent
-	bounds: 569, 2, 47, 45
-eye-surprised
-	bounds: 643, 7, 47, 45
-	rotate: 90
-front-bracer
-	bounds: 811, 51, 29, 40
-front-fist-closed
-	bounds: 807, 93, 38, 41
-front-fist-open
-	bounds: 815, 210, 43, 44
-front-foot
-	bounds: 706, 64, 63, 35
-	rotate: 90
-front-shin
-	bounds: 80, 11, 41, 92
-front-thigh
-	bounds: 754, 12, 23, 56
-front-upper-arm
-	bounds: 618, 5, 23, 49
-goggles
-	bounds: 214, 20, 131, 83
-gun
-	bounds: 347, 14, 105, 102
-	rotate: 90
-head
-	bounds: 80, 105, 136, 149
-hoverboard-board
-	bounds: 2, 8, 246, 76
-	rotate: 90
-hoverboard-thruster
-	bounds: 478, 2, 30, 32
-hoverglow-small
-	bounds: 218, 117, 137, 38
-	rotate: 90
-mouth-grind
-	bounds: 775, 80, 47, 30
-	rotate: 90
-mouth-oooo
-	bounds: 779, 31, 47, 30
-	rotate: 90
-mouth-smile
-	bounds: 783, 207, 47, 30
-	rotate: 90
-muzzle-glow
-	bounds: 779, 4, 25, 25
-muzzle-ring
-	bounds: 451, 14, 25, 105
-muzzle01
-	bounds: 664, 60, 67, 40
-	rotate: 90
-muzzle02
-	bounds: 580, 56, 68, 42
-	rotate: 90
-muzzle03
-	bounds: 478, 36, 83, 53
-	rotate: 90
-muzzle04
-	bounds: 533, 49, 75, 45
-	rotate: 90
-muzzle05
-	bounds: 624, 56, 68, 38
-	rotate: 90
-neck
-	bounds: 806, 8, 18, 21
-portal-bg
-	bounds: 258, 121, 133, 133
-portal-flare1
-	bounds: 690, 2, 56, 30
-	rotate: 90
-portal-flare2
-	bounds: 510, 3, 57, 31
-portal-flare3
-	bounds: 722, 4, 58, 30
-	rotate: 90
-portal-shade
-	bounds: 393, 121, 133, 133
-portal-streaks1
-	bounds: 528, 126, 126, 128
-portal-streaks2
-	bounds: 656, 129, 125, 125
-rear-bracer
-	bounds: 826, 13, 28, 36
-rear-foot
-	bounds: 743, 70, 57, 30
-	rotate: 90
-rear-shin
-	bounds: 174, 14, 38, 89
-rear-thigh
-	bounds: 783, 158, 28, 47
-rear-upper-arm
-	bounds: 783, 136, 20, 44
-	rotate: 90
-torso
-	bounds: 123, 13, 49, 90

BIN
tests/functional/assets/spineboy.png


+ 134 - 4
tests/functional/sokol_spine_test.c

@@ -19,7 +19,8 @@ static void shutdown() {
     sg_shutdown();
 }
 
-// NOTE: this guarantees that the data is zero terminated (the returned size doesn't count the zero!)
+// NOTE: this guarantees that the data is zero terminated because the loaded data
+// might either be binary or text (the zero sentinel is counted in the returned size)
 static sspine_range load_data(const char* path) {
     assert(path);
     FILE* fp = fopen(path, "rb");
@@ -59,11 +60,36 @@ static sspine_skeleton create_skeleton_json(sspine_atlas atlas) {
     return skeleton;
 }
 
+static sspine_skeleton create_skeleton_binary(sspine_atlas atlas) {
+    sspine_range skeleton_binary_data = load_data("spineboy-pro.skel");
+    sspine_skeleton skeleton = sspine_make_skeleton(&(sspine_skeleton_desc){
+        .atlas = atlas,
+        .binary_data = skeleton_binary_data
+    });
+    free_data(skeleton_binary_data);
+    return skeleton;
+}
+
 UTEST(sokol_spine, default_init_shutdown) {
     // FIXME!
     T(true);
 }
 
+UTEST(sokol_spine, atlas_pool_exhausted) {
+    sg_setup(&(sg_desc){0});
+    sspine_setup(&(sspine_desc){
+        .atlas_pool_size = 4
+    });
+    for (int i = 0; i < 4; i++) {
+        sspine_atlas atlas = sspine_make_atlas(&(sspine_atlas_desc){0});
+        T(sspine_get_atlas_resource_state(atlas) == SSPINE_RESOURCESTATE_FAILED);
+    }
+    sspine_atlas atlas = sspine_make_atlas(&(sspine_atlas_desc){0});
+    T(SSPINE_INVALID_ID == atlas.id);
+    T(sspine_get_atlas_resource_state(atlas) == SSPINE_RESOURCESTATE_INVALID);
+    shutdown();
+}
+
 UTEST(sokol_spine, make_destroy_atlas_ok) {
     init();
     sspine_atlas atlas = create_atlas();
@@ -115,7 +141,22 @@ UTEST(sokol_spine, atlas_image_info) {
     shutdown();
 }
 
-UTEST(sokol_spine, make_destroy_skeleton_ok) {
+UTEST(sokol_spine, skeleton_pool_exhausted) {
+    sg_setup(&(sg_desc){0});
+    sspine_setup(&(sspine_desc){
+        .skeleton_pool_size = 4
+    });
+    for (int i = 0; i < 4; i++) {
+        sspine_skeleton skeleton = sspine_make_skeleton(&(sspine_skeleton_desc){0});
+        T(sspine_get_skeleton_resource_state(skeleton) == SSPINE_RESOURCESTATE_FAILED);
+    }
+    sspine_skeleton skeleton = sspine_make_skeleton(&(sspine_skeleton_desc){0});
+    T(SSPINE_INVALID_ID == skeleton.id);
+    T(sspine_get_skeleton_resource_state(skeleton) == SSPINE_RESOURCESTATE_INVALID);
+    shutdown();
+}
+
+UTEST(sokol_spine, make_destroy_skeleton_json_ok) {
     init();
     sspine_skeleton skeleton = create_skeleton_json(create_atlas());
     T(sspine_get_skeleton_resource_state(skeleton) == SSPINE_RESOURCESTATE_VALID);
@@ -126,6 +167,17 @@ UTEST(sokol_spine, make_destroy_skeleton_ok) {
     shutdown();
 }
 
+UTEST(sokol_spine, make_destroy_skeleton_binary_ok) {
+    init();
+    sspine_skeleton skeleton = create_skeleton_binary(create_atlas());
+    T(sspine_get_skeleton_resource_state(skeleton) == SSPINE_RESOURCESTATE_VALID);
+    T(sspine_skeleton_valid(skeleton));
+    sspine_destroy_skeleton(skeleton);
+    T(sspine_get_skeleton_resource_state(skeleton) == SSPINE_RESOURCESTATE_INVALID);
+    T(!sspine_skeleton_valid(skeleton));
+    shutdown();
+}
+
 UTEST(sokol_spine, make_skeleton_fail_no_data) {
     init();
     sspine_atlas atlas = create_atlas();
@@ -159,7 +211,7 @@ UTEST(sokol_spine, make_skeleton_fail_with_failed_atlas) {
     shutdown();
 }
 
-UTEST(sokol_spine, make_skeleton_fail_corrupt_data) {
+UTEST(sokol_spine, make_skeleton_json_fail_corrupt_data) {
     init();
     sspine_atlas atlas = create_atlas();
     const char* invalid_json_data = "This is not valid JSON!";
@@ -173,4 +225,82 @@ UTEST(sokol_spine, make_skeleton_fail_corrupt_data) {
     shutdown();
 }
 
-// FIXME: test for binary skeleton data
+// FIXME: this crashes the spine-c runtime
+/*
+UTEST(sokol_spine, make_skeleton_binary_fail_corrupt_data) {
+    init();
+    sspine_atlas atlas = create_atlas();
+    uint8_t invalid_binary_data[] = { 0x23, 0x63, 0x11, 0xFF };
+    sspine_skeleton skeleton = sspine_make_skeleton(&(sspine_skeleton_desc){
+        .atlas = atlas,
+        .binary_data = { .ptr = invalid_binary_data, .size = sizeof(invalid_binary_data) }
+    });
+    T(sspine_get_skeleton_resource_state(skeleton) == SSPINE_RESOURCESTATE_FAILED);
+    sspine_destroy_skeleton(skeleton);
+    T(sspine_get_skeleton_resource_state(skeleton) == SSPINE_RESOURCESTATE_INVALID);
+    shutdown();
+}
+*/
+
+UTEST(sokol_spine, instance_pool_exhausted) {
+    sg_setup(&(sg_desc){0});
+    sspine_setup(&(sspine_desc){
+        .instance_pool_size = 4
+    });
+    for (int i = 0; i < 4; i++) {
+        sspine_instance instance = sspine_make_instance(&(sspine_instance_desc){0});
+        T(sspine_get_instance_resource_state(instance) == SSPINE_RESOURCESTATE_FAILED);
+    }
+    sspine_instance instance = sspine_make_instance(&(sspine_instance_desc){0});
+    T(SSPINE_INVALID_ID == instance.id);
+    T(sspine_get_instance_resource_state(instance) == SSPINE_RESOURCESTATE_INVALID);
+    shutdown();
+}
+
+UTEST(sokol_spine, make_destroy_instance_ok) {
+    init();
+    sspine_instance instance = sspine_make_instance(&(sspine_instance_desc){
+        .skeleton = create_skeleton_json(create_atlas())
+    });
+    T(sspine_get_instance_resource_state(instance) == SSPINE_RESOURCESTATE_VALID);
+    T(sspine_instance_valid(instance));
+    sspine_destroy_instance(instance);
+    T(sspine_get_instance_resource_state(instance) == SSPINE_RESOURCESTATE_INVALID);
+    T(!sspine_instance_valid(instance));
+    shutdown();
+}
+
+UTEST(sokol_spine, make_instance_fail_no_skeleton) {
+    init();
+    sspine_instance instance = sspine_make_instance(&(sspine_instance_desc){0});
+    T(sspine_get_instance_resource_state(instance) == SSPINE_RESOURCESTATE_FAILED);
+    sspine_destroy_instance(instance);
+    T(sspine_get_instance_resource_state(instance) == SSPINE_RESOURCESTATE_INVALID);
+    shutdown();
+}
+
+UTEST(sokol_spine, make_instance_fail_with_failed_skeleton) {
+    init();
+    sspine_skeleton failed_skeleton = sspine_make_skeleton(&(sspine_skeleton_desc){0});
+    T(sspine_get_skeleton_resource_state(failed_skeleton) == SSPINE_RESOURCESTATE_FAILED);
+    sspine_instance instance = sspine_make_instance(&(sspine_instance_desc){
+        .skeleton = failed_skeleton
+    });
+    T(sspine_get_instance_resource_state(instance) == SSPINE_RESOURCESTATE_FAILED);
+    shutdown();
+}
+
+UTEST(sokol_spine, make_instance_fail_with_destroyed_atlas) {
+    init();
+    sspine_atlas atlas = create_atlas();
+    T(sspine_atlas_valid(atlas));
+    sspine_skeleton skeleton = create_skeleton_json(atlas);
+    T(sspine_skeleton_valid(skeleton));
+    sspine_destroy_atlas(atlas);
+    T(!sspine_atlas_valid(atlas));
+    sspine_instance instance = sspine_make_instance(&(sspine_instance_desc){
+        .skeleton = skeleton
+    });
+    T(sspine_get_instance_resource_state(instance) == SSPINE_RESOURCESTATE_FAILED);
+    shutdown();
+}

+ 1 - 4
util/sokol_spine.h

@@ -209,7 +209,7 @@ SOKOL_SPINE_API_DECL void sspine_destroy_atlas(sspine_atlas atlas);
 SOKOL_SPINE_API_DECL void sspine_destroy_skeleton(sspine_skeleton skeleton);
 SOKOL_SPINE_API_DECL void sspine_destroy_instance(sspine_instance instance);
 
-// get current resource state (INITIAL, ALLOC, VALID, FAILD, INVALID)
+// get current resource state (INITIAL, ALLOC, VALID, FAILED, INVALID)
 SOKOL_SPINE_API_DECL sspine_resource_state sspine_get_context_resource_state(sspine_context context);
 SOKOL_SPINE_API_DECL sspine_resource_state sspine_get_atlas_resource_state(sspine_atlas atlas);
 SOKOL_SPINE_API_DECL sspine_resource_state sspine_get_skeleton_resource_state(sspine_skeleton skeleton);
@@ -1190,7 +1190,6 @@ SOKOL_API_IMPL sspine_atlas sspine_make_atlas(const sspine_atlas_desc* desc) {
         }
     }
     else {
-        atlas->slot.state = SSPINE_RESOURCESTATE_FAILED;
         SOKOL_LOG("sokol_spine.h: atlas pool exhausted");
     }
     return atlas_id;
@@ -1215,7 +1214,6 @@ SOKOL_API_IMPL sspine_skeleton sspine_make_skeleton(const sspine_skeleton_desc*
         }
     }
     else {
-        skeleton->slot.state = SSPINE_RESOURCESTATE_FAILED;
         SOKOL_LOG("sokol_spine.h: skeleton pool exhausted");
     }
     return skeleton_id;
@@ -1240,7 +1238,6 @@ SOKOL_API_IMPL sspine_instance sspine_make_instance(const sspine_instance_desc*
         }
     }
     else {
-        instance->slot.state = SSPINE_RESOURCESTATE_FAILED;
         SOKOL_LOG("sokol_spine.h: instance pool exhausted");
     }
     return instance_id;

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff