Skip to content

Commit

Permalink
Add readme file
Browse files Browse the repository at this point in the history
  • Loading branch information
Geequlim committed Jun 10, 2017
1 parent 9ca596a commit a0301dc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
This module add [Spine](http://esotericsoftware.com/) animation support for godot game engie 2.x. It was tested with godot 2.1.

Current useing the spine runtime version **3.5.51**.

## About the lisence
This module is forked from [sanikoyes's godot branch](https://github.com/sanikoyes/godot/tree/develop/modules/spine) and some of code are forked from [godot-spine-module](https://github.com/jjay/godot-spine-module). Both of the code are declared as MIT lisence.
The lisence of this module is MIT

```
MIT License
Copyright (c) 2017 Godot Explorer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
18 changes: 10 additions & 8 deletions register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ void _spAtlasPage_disposeTexture(spAtlasPage* self) {
char* _spUtil_readFile(const char* p_path, int* p_length) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
ERR_FAIL_COND_V(!f, NULL);

String str_path = String::utf8(p_path);

char *data = (char *)_malloc(*p_length, __FILE__, __LINE__);
*p_length = f->get_len();
data = (char *)_malloc(*p_length, __FILE__, __LINE__);
ERR_FAIL_COND_V(data == NULL, NULL);
f->get_buffer((uint8_t *)data, *p_length);

/*
* A pretty hacky part of patching Spine files
* Preface: If I create spine atlas from images with some deep
Expand All @@ -90,7 +90,7 @@ char* _spUtil_readFile(const char* p_path, int* p_length) {
* - may be find actual reason of my buggy animations
*
*/

Array _sp_invalid_names = Spine::get_invalid_names();
if (str_path.ends_with(".atlas")){
Array current_string = Array();
Expand Down Expand Up @@ -125,7 +125,7 @@ char* _spUtil_readFile(const char* p_path, int* p_length) {
if (data[i-k] != (int)(in[idx-k])){ match=false; break; }
}
if (!match) continue;

IntArray extra_replaces;
for (int k=1; k<in.size()-idx;k++){
if (i+k >= *p_length){ match=false; break; }
Expand All @@ -140,7 +140,7 @@ char* _spUtil_readFile(const char* p_path, int* p_length) {
}
}
}

_sp_invalid_names.resize(0);
}
memdelete(f);
Expand All @@ -149,6 +149,8 @@ char* _spUtil_readFile(const char* p_path, int* p_length) {

static void *spine_malloc(size_t p_size) {

if (p_size == 0)
return NULL;
return memalloc(p_size);
}

Expand All @@ -169,12 +171,12 @@ class ResourceFormatLoaderSpine : public ResourceFormatLoader {
String p_atlas = p_path.basename() + ".atlas";
res->atlas = spAtlas_createFromFile(p_atlas.utf8().get_data(), 0);
ERR_FAIL_COND_V(res->atlas == NULL, RES());

if (p_path.extension() == "json"){
spSkeletonJson *json = spSkeletonJson_create(res->atlas);
ERR_FAIL_COND_V(json == NULL, RES());
json->scale = 1;

res->data = spSkeletonJson_readSkeletonDataFile(json, p_path.utf8().get_data());
ERR_EXPLAIN(json->error ? json->error : "");
spSkeletonJson_dispose(json);
Expand All @@ -188,7 +190,7 @@ class ResourceFormatLoaderSpine : public ResourceFormatLoader {
spSkeletonBinary_dispose(bin);
ERR_FAIL_COND_V(res->data == NULL, RES());
}

res->set_path(p_path);
float finish = OS::get_singleton()->get_ticks_msec();
print_line("Spine resource (" + p_path + ") loaded in " + itos(finish-start) + " msecs");
Expand Down
10 changes: 7 additions & 3 deletions spine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,13 +612,17 @@ void Spine::_notification(int p_what) {

void Spine::set_resource(Ref<Spine::SpineResource> p_data) {

// cleanup
_spine_dispose();
if (res == p_data)
return;

_spine_dispose(); // cleanup

res = p_data;
if (res.is_null() || !res->data)
if (res.is_null())
return;

ERR_FAIL_COND(!res->data);

skeleton = spSkeleton_create(res->data);
root_bone = skeleton->bones[0];

Expand Down

0 comments on commit a0301dc

Please sign in to comment.