Bläddra i källkod

[sfml] Added testbed

# Conflicts:
#	CMakeLists.txt
#	spine-sfml/cpp/CMakeLists.txt
Mario Zechner 2 år sedan
förälder
incheckning
6e4c9517bc
2 ändrade filer med 94 tillägg och 20 borttagningar
  1. 19 20
      spine-sfml/cpp/CMakeLists.txt
  2. 75 0
      spine-sfml/cpp/example/testbed.cpp

+ 19 - 20
spine-sfml/cpp/CMakeLists.txt

@@ -62,7 +62,11 @@ install(FILES ${INCLUDES} DESTINATION dist/include)
 
 # Define spine-sfml example executable
 add_executable(spine-sfml-cpp-example example/main.cpp)
-add_executable(spine-sfml-cpp-test example/test.cpp)
+target_link_libraries(spine-sfml-cpp-example spine-cpp spine-sfml-cpp)
+
+# Define spine-sfml testbed executable
+add_executable(spine-sfml-cpp-testbed example/testbed.cpp)
+target_link_libraries(spine-sfml-cpp-testbed spine-cpp spine-sfml-cpp)
 
 # Link in SFML libraries and OS dependencies like OpenGL
 if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
@@ -71,10 +75,10 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
 	find_library(SFML_WINDOW sfml-window PATHS ${SFML_DIR}/Frameworks)
 	find_library(SFML_GRAPHICS sfml-graphics PATHS ${SFML_DIR}/Frameworks)
 	target_link_libraries(spine-sfml-cpp-example ${SFML} ${SFML_SYSTEM} ${SFML_WINDOW} ${SFML_GRAPHICS})
-	target_link_libraries(spine-sfml-cpp-test ${SFML} ${SFML_SYSTEM} ${SFML_WINDOW} ${SFML_GRAPHICS})
+	target_link_libraries(spine-sfml-cpp-testbed ${SFML} ${SFML_SYSTEM} ${SFML_WINDOW} ${SFML_GRAPHICS})
 elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
 	target_link_libraries(spine-sfml-cpp-example sfml-graphics sfml-window sfml-system)
-	target_link_libraries(spine-sfml-cpp-test sfml-graphics sfml-window sfml-system)
+	target_link_libraries(spine-sfml-cpp-testbed sfml-graphics sfml-window sfml-system)
 else()
 	set(SFML_LIBS ${SFML_DIR}/lib)
 	target_link_libraries(spine-sfml-cpp-example ${SFML_LIBS}/sfml-main-d.lib)
@@ -86,28 +90,23 @@ else()
 	target_link_libraries(spine-sfml-cpp-example opengl32)
 	target_link_libraries(spine-sfml-cpp-example gdi32)
 	target_link_libraries(spine-sfml-cpp-example winmm)
-	target_link_libraries(spine-sfml-cpp-test ${SFML_LIBS}/sfml-main-d.lib)
-	target_link_libraries(spine-sfml-cpp-test ${SFML_LIBS}/sfml-graphics-s-d.lib)
-	target_link_libraries(spine-sfml-cpp-test ${SFML_LIBS}/sfml-window-s-d.lib)
-	target_link_libraries(spine-sfml-cpp-test ${SFML_LIBS}/sfml-system-s-d.lib)
-	target_link_libraries(spine-sfml-cpp-test ${SFML_LIBS}/freetype.lib)
-	target_link_libraries(spine-sfml-cpp-test ${SFML_LIBS}/jpeg.lib)
-	target_link_libraries(spine-sfml-cpp-test opengl32)
-	target_link_libraries(spine-sfml-cpp-test gdi32)
-	target_link_libraries(spine-sfml-cpp-test winmm)
+	target_link_libraries(spine-sfml-cpp-testbed ${SFML_LIBS}/sfml-main-d.lib)
+	target_link_libraries(spine-sfml-cpp-testbed ${SFML_LIBS}/sfml-graphics-s-d.lib)
+	target_link_libraries(spine-sfml-cpp-testbed ${SFML_LIBS}/sfml-window-s-d.lib)
+	target_link_libraries(spine-sfml-cpp-testbed ${SFML_LIBS}/sfml-system-s-d.lib)
+	target_link_libraries(spine-sfml-cpp-testbed ${SFML_LIBS}/freetype.lib)
+	target_link_libraries(spine-sfml-cpp-testbed ${SFML_LIBS}/jpeg.lib)
+	target_link_libraries(spine-sfml-cpp-testbed opengl32)
+	target_link_libraries(spine-sfml-cpp-testbed gdi32)
+	target_link_libraries(spine-sfml-cpp-testbed winmm)
 	add_definitions(-DSFML_STATIC)
 endif()
 
 # copy data to build directory
-add_custom_command(TARGET spine-sfml-cpp-example PRE_BUILD
+add_custom_command(TARGET spine-sfml-cpp-example
 		COMMAND ${CMAKE_COMMAND} -E copy_directory
 		${CMAKE_CURRENT_LIST_DIR}/data $<TARGET_FILE_DIR:spine-sfml-cpp-example>/data)
-add_custom_command(TARGET spine-sfml-cpp-test PRE_BUILD
+
+add_custom_command(TARGET spine-sfml-cpp-testbed
 		COMMAND ${CMAKE_COMMAND} -E copy_directory
 		${CMAKE_CURRENT_LIST_DIR}/data $<TARGET_FILE_DIR:spine-sfml-cpp-example>/data)
-
-target_link_libraries(spine-sfml-cpp-example spine-cpp)
-target_link_libraries(spine-sfml-cpp-example spine-sfml-cpp)
-
-target_link_libraries(spine-sfml-cpp-test spine-cpp)
-target_link_libraries(spine-sfml-cpp-test spine-sfml-cpp)

+ 75 - 0
spine-sfml/cpp/example/testbed.cpp

@@ -0,0 +1,75 @@
+/******************************************************************************
+ * Spine Runtimes License Agreement
+ * Last updated January 1, 2020. Replaces all prior versions.
+ *
+ * Copyright (c) 2013-2020, Esoteric Software LLC
+ *
+ * Integration of the Spine Runtimes into software or otherwise creating
+ * derivative works of the Spine Runtimes is permitted under the terms and
+ * conditions of Section 2 of the Spine Editor License Agreement:
+ * http://esotericsoftware.com/spine-editor-license
+ *
+ * Otherwise, it is permitted to integrate the Spine Runtimes into software
+ * or otherwise create derivative works of the Spine Runtimes (collectively,
+ * "Products"), provided that each user of the Products must obtain their own
+ * Spine Editor license and redistribution of the Products in any form must
+ * include this license and copyright notice.
+ *
+ * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
+ * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *****************************************************************************/
+
+#include <SFML/Graphics.hpp>
+#include <spine/Log.h>
+#include <spine/spine-sfml.h>
+
+using namespace spine;
+
+int main(void) {
+    String atlasFile("data/spineboy-pma.atlas");
+    String skeletonFile("data/spineboy-pro.skel");
+    float scale = 0.6f;
+    SFMLTextureLoader textureLoader;
+    Atlas *atlas = new Atlas(atlasFile, &textureLoader);
+    SkeletonData *skeletonData = nullptr;
+    if (strncmp(skeletonFile.buffer(), ".skel", skeletonFile.length()) > 0) {
+        SkeletonBinary binary(atlas);
+        binary.setScale(scale);
+        skeletonData = binary.readSkeletonDataFile(skeletonFile);
+    } else {
+        SkeletonJson json(atlas);
+        json.setScale(scale);
+        skeletonData = json.readSkeletonDataFile(skeletonFile);
+    }
+
+    AnimationStateData stateData(skeletonData);
+    SkeletonDrawable drawable(skeletonData, &stateData);
+    drawable.skeleton->setPosition(320, 590);
+    drawable.state->setAnimation(0, "walk", true);
+
+    sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - testbed");
+    window.setFramerateLimit(60);
+    sf::Event event;
+    sf::Clock deltaClock;
+    while (window.isOpen()) {
+        while (window.pollEvent(event))
+            if (event.type == sf::Event::Closed) window.close();
+
+        float delta = deltaClock.getElapsedTime().asSeconds();
+        deltaClock.restart();
+        drawable.update(delta);
+        window.clear();
+        window.draw(drawable);
+        window.display();
+    }
+
+    return 0;
+}