From e89043b1f69ffd94b30f80bc705f19c15e6baf30 Mon Sep 17 00:00:00 2001 From: badlogic Date: Wed, 18 Sep 2019 17:29:21 +0200 Subject: [PATCH 1/4] [cpp] Fixes #1444. SpineObject was using the wrong calloc. --- spine-cocos2dx/example/Classes/AppDelegate.cpp | 2 +- spine-cpp/spine-cpp/include/spine/Debug.h | 11 +++++++++++ spine-cpp/spine-cpp/src/spine/SpineObject.cpp | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/spine-cocos2dx/example/Classes/AppDelegate.cpp b/spine-cocos2dx/example/Classes/AppDelegate.cpp index 3775a9893..dcade70a0 100644 --- a/spine-cocos2dx/example/Classes/AppDelegate.cpp +++ b/spine-cocos2dx/example/Classes/AppDelegate.cpp @@ -112,7 +112,7 @@ bool AppDelegate::applicationDidFinishLaunching () { // create a scene. it's an autorelease object //auto scene = RaptorExample::scene(); - auto scene = MixAndMatchExample::scene(); + auto scene = BatchingExample::scene(); // run director->runWithScene(scene); diff --git a/spine-cpp/spine-cpp/include/spine/Debug.h b/spine-cpp/spine-cpp/include/spine/Debug.h index 13c3213ec..04768a31b 100644 --- a/spine-cpp/spine-cpp/include/spine/Debug.h +++ b/spine-cpp/spine-cpp/include/spine/Debug.h @@ -63,12 +63,14 @@ public: void clearAllocations() { _allocated.clear(); + _usedMemory = 0; } virtual void *_alloc(size_t size, const char *file, int line) { void *result = _extension->_alloc(size, file, line); _allocated[result] = Allocation(result, size, file, line); _allocations++; + _usedMemory += size; return result; } @@ -76,14 +78,17 @@ public: void *result = _extension->_calloc(size, file, line); _allocated[result] = Allocation(result, size, file, line); _allocations++; + _usedMemory += size; return result; } virtual void *_realloc(void *ptr, size_t size, const char *file, int line) { + if (_allocated.count(ptr)) _usedMemory -= _allocated[ptr].size; _allocated.erase(ptr); void *result = _extension->_realloc(ptr, size, file, line); _reallocations++; _allocated[result] = Allocation(result, size, file, line); + _usedMemory += size; return result; } @@ -91,6 +96,7 @@ public: if (_allocated.count(mem)) { _extension->_free(mem, file, line); _frees++; + _usedMemory -= _allocated[mem].size; _allocated.erase(mem); return; } @@ -102,6 +108,10 @@ public: virtual char *_readFile(const String &path, int *length) { return _extension->_readFile(path, length); } + + size_t getUsedMemory() { + return _usedMemory; + } private: SpineExtension* _extension; @@ -109,6 +119,7 @@ private: size_t _allocations; size_t _reallocations; size_t _frees; + size_t _usedMemory; }; } diff --git a/spine-cpp/spine-cpp/src/spine/SpineObject.cpp b/spine-cpp/spine-cpp/src/spine/SpineObject.cpp index fdcdc49bf..98e8dc6f8 100644 --- a/spine-cpp/spine-cpp/src/spine/SpineObject.cpp +++ b/spine-cpp/spine-cpp/src/spine/SpineObject.cpp @@ -36,11 +36,11 @@ using namespace spine; void *SpineObject::operator new(size_t sz) { - return SpineExtension::calloc(sz, __FILE__, __LINE__); + return SpineExtension::getInstance()->_calloc(sz, __FILE__, __LINE__); } void *SpineObject::operator new(size_t sz, const char *file, int line) { - return SpineExtension::calloc(sz, file, line); + return SpineExtension::getInstance()->_calloc(sz, file, line); } void *SpineObject::operator new(size_t sz, void *ptr) { From 0e9978b5d2eb441e708962dbde153cca16af7de1 Mon Sep 17 00:00:00 2001 From: badlogic Date: Thu, 19 Sep 2019 14:26:00 +0200 Subject: [PATCH 2/4] [cocos2d] Updated README.md with better instructions for Windows. --- spine-cocos2dx/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spine-cocos2dx/README.md b/spine-cocos2dx/README.md index e0cd1f86f..42cd1de42 100644 --- a/spine-cocos2dx/README.md +++ b/spine-cocos2dx/README.md @@ -39,7 +39,8 @@ The Spine cocos2d-x example works on Windows, Mac OS X, iOS and Android. 4. Run CMake GUI from the start menu 5. Click `Browse Source` and select the directory `spine-runtimes` 6. Click `Browse Build` and select the `spine-runtimes/spine-cocos2dx/build` directory. You can create the `build` folder directly in the file dialog via `New Folder`. -7. Click `Configure`. This will download the cocos2d-x dependency and wire it up with the example source code in `spine-runtimes/spine-cocos2dx/example`. The download is 400mb, so get yourself a cup of tea. +7. Click `Configure`. Check `SPINE_COCOS2D_X` +8. Click `Configure` again. This will download the cocos2d-x dependency and wire it up with the example source code in `spine-runtimes/spine-cocos2dx/example`. The download is 400mb, so get yourself a cup of tea. 7. Open the file `spine-cocos2dx\example\cocos2d\cocos\2d\cocos2dx.props` and remove the `libSpine.lib` entry from the `` tag. 8. Open the `spine-runtimes/spine-cocos2dx/example/proj.win32/spine-cocos2d-x.sln` file in Visual Studio 2015. Visual Studio may ask you to install the Windows XP/7 SDK, which you should install. 9. Expand `References` of the libcocos2d sub project, and remove the entry for `libSpine`, which should be marked with an error. From 6e4a6925a2f50e267ea92448217d54efe7cd0f27 Mon Sep 17 00:00:00 2001 From: badlogic Date: Thu, 19 Sep 2019 14:36:09 +0200 Subject: [PATCH 3/4] [cocos2d] Updated CHANGELOG and README.md for VS2019 upgrade. --- CHANGELOG.md | 1 + spine-cocos2dx/README.md | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec4f421ed..660dfd1b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -86,6 +86,7 @@ ### Cocos2d-x * Updated to cocos2d-x 3.17.1 * Added mix-and-match example to demonstrate the new Skin API. +* Exmaple project requires Visual Studio 2019 on Windows ### SFML * Added mix-and-match example to demonstrate the new Skin API. diff --git a/spine-cocos2dx/README.md b/spine-cocos2dx/README.md index 42cd1de42..46c03653f 100644 --- a/spine-cocos2dx/README.md +++ b/spine-cocos2dx/README.md @@ -33,7 +33,7 @@ The setup for cocos2d-x differs from most other Spine Runtimes because the cocos The Spine cocos2d-x example works on Windows, Mac OS X, iOS and Android. ### Windows -1. Install [Visual Studio 2015 Community](https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx) +1. Install [Visual Studio 2019 Community](https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx) 2. Install CMake via the [Windows installer package](https://cmake.org/download/). 3. Download the Spine Runtimes repository using git (`git clone https://github.com/esotericsoftware/spine-runtimes`) or download it as a zip via the download button above. 4. Run CMake GUI from the start menu @@ -42,7 +42,7 @@ The Spine cocos2d-x example works on Windows, Mac OS X, iOS and Android. 7. Click `Configure`. Check `SPINE_COCOS2D_X` 8. Click `Configure` again. This will download the cocos2d-x dependency and wire it up with the example source code in `spine-runtimes/spine-cocos2dx/example`. The download is 400mb, so get yourself a cup of tea. 7. Open the file `spine-cocos2dx\example\cocos2d\cocos\2d\cocos2dx.props` and remove the `libSpine.lib` entry from the `` tag. -8. Open the `spine-runtimes/spine-cocos2dx/example/proj.win32/spine-cocos2d-x.sln` file in Visual Studio 2015. Visual Studio may ask you to install the Windows XP/7 SDK, which you should install. +8. Open the `spine-runtimes/spine-cocos2dx/example/proj.win32/spine-cocos2d-x.sln` file in Visual Studio 2019. Visual Studio may ask you to install the Windows XP/7 SDK, which you should install. 9. Expand `References` of the libcocos2d sub project, and remove the entry for `libSpine`, which should be marked with an error. 9. Right click the `spine-cocos2d-x` project in the solution explorer and select `Set as Startup Project` from the context menu 10. Click `Local Windows Debugger` to run the example From 8ba4bf269b7816496096ea5e793e8061c74dc0c7 Mon Sep 17 00:00:00 2001 From: badlogic Date: Thu, 19 Sep 2019 15:27:25 +0200 Subject: [PATCH 4/4] [cpp] Add stdint.h for VS2019 build tools. Closes #1498. --- spine-cpp/spine-cpp/src/spine/Animation.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spine-cpp/spine-cpp/src/spine/Animation.cpp b/spine-cpp/spine-cpp/src/spine/Animation.cpp index d94579510..4ac7b2a71 100644 --- a/spine-cpp/spine-cpp/src/spine/Animation.cpp +++ b/spine-cpp/spine-cpp/src/spine/Animation.cpp @@ -38,6 +38,8 @@ #include +#include + using namespace spine; Animation::Animation(const String &name, Vector &timelines, float duration) :