Jump to content

Spriter Generic C++ API


grimfang4

Recommended Posts

  • Replies 63
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Hi,

I've just found out about Spriter yesterday, and am still researching, but it looks like you've done a great job on the C++ library.

I'm considering making a plugin for Shiva3D to support SCML and your code looks like a good base to start from. Shiva preferably stores all its resources internally however, so some updates will be needed, and the renderer could be quite involved, translating 2D to 3D.

One of the big performace gains for Shiva is using texture atlases, which I see you haven't implemented yet. I'm not sure where this sits in the Spriter roadmap, but do you plan to implement it in your library?

Thanks. Russell.

Link to comment
Share on other sites

@8DashP

I'll let grimfang respond as far as this api directly supporting it, but as far as Spriter goes yes that is on the roadmap. Closer to 1.0, Spriter will allow you to export to a format that will be useable in Code'n'Web TexturePacker, and eventually load directly from TexturePacker packed spritesheets of a specific format.

In the meantime, you can very easily used packed textures instead of individual png images, and it's actually very simple, and a few other api's do it. Just use individual pngs in folders while animating in Spriter. Then in your engine, use the 'filename' attribute to locate the image in the textureatlas instead of a folder. Tools like TexturePacker will automatically name the atlus locations after the folder/filename.

Link to comment
Share on other sites

I'll let you know if any of the OpenGL stuff is worth committing. Very basic atm.

Is there anyway in the current version to easily control which animation is currently playing or query if an animation is finished for a particular entity? Some animation state control would be extremely handy.

Link to comment
Share on other sites

@8DashP

I'll let grimfang respond as far as this api directly supporting it, but as far as Spriter goes yes that is on the roadmap. Closer to 1.0, Spriter will allow you to export to a format that will be useable in Code'n'Web TexturePacker, and eventually load directly from TexturePacker packed spritesheets of a specific format.

In the meantime, you can very easily used packed textures instead of individual png images, and it's actually very simple, and a few other api's do it. Just use individual pngs in folders while animating in Spriter. Then in your engine, use the 'filename' attribute to locate the image in the textureatlas instead of a folder. Tools like TexturePacker will automatically name the atlus locations after the folder/filename.

Thanks lucid. It'll take me a while to get up and going anyway, I just didn't want to start with the wrong assumptions. So the SCML format is basically set now, and complete?

@Grimfang

I've just downloaded the code project so I can have a look at it in Visual Studio 2010. Out of the box, I'm getting compile errors. I assume others have gotten Visual Studio to work, so not sure what I've missed. I'm just using the SCMLpp and the XML files and trying to put them in a wrapper project of my own, to just get it compiled. It's producing the following errors :-

1>  SCMLpp.cpp
1>..\..\Sources\SCMLpp.cpp(26): error C2039: 'find' : is not a member of 'std'
1>..\..\Sources\SCMLpp.cpp(26): error C2228: left of '.base' must have class/struct/union
1> type is ''unknown-type''
1>..\..\Sources\SCMLpp.cpp(26): error C3861: 'find': identifier not found
1>..\..\Sources\SCMLpp.cpp(2370): error C3861: 'c99_snprintf': identifier not found
1>..\..\Sources\SCMLpp.cpp(2511): error C2065: 'M_PI' : undeclared identifier
1>..\..\Sources\SCMLpp.cpp(2512): error C2065: 'M_PI' : undeclared identifier
1> XML_Helpers.cpp
1>..\..\Sources\XML_Helpers.cpp(15): error C3861: 'c99_vsnprintf': identifier not found
1>..\..\Sources\XML_Helpers.cpp(54): warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
1>..\..\Sources\XML_Helpers.cpp(64): warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I see there are some tests for Visual Studio in the code, but that's where the first one about std::find is coming up, so I may have my compiler directives wrong. I'll work through the errors and see if I can resolve them, but is there something obvious missing that should maybe be documented for VS users?

Thanks. Russell.

*EDIT*

I've made the following changes to correct the errors

1. Replaced my line 26

source.erase(std::find(source.rbegin(), source.rend(), '/').base(), source.end());

with

source.erase(source.rfind('/'), source.length());

2. Added the following declaration to XML_Helpers.h

	int c99_snprintf(char* str, size_t size, const char* format, ...);

3. Added the following include to SCMLpp.cpp

#include 

4. Swapped the declaration of the print helpers in XML_Helpers.cpp as follows

// Visual Studio does not support snprintf properly.
// This is from Valentin Milea on Stack Overflow. http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010/8712996#8712996
#ifdef _MSC_VER
#define snprintf c99_snprintf

int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap)
{
int count = -1;

if (size != 0)
count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
if (count == -1)
count = _vscprintf(format, ap);

return count;
}

int c99_snprintf(char* str, size_t size, const char* format, ...)
{
int count;
va_list ap;

va_start(ap, format);
count = c99_vsnprintf(str, size, format, ap);
va_end(ap);

return count;
}

#else
#include "libgen.h"
#endif // _MSC_VER

5. And just because I don't like warnings either, I did an explicit conversion for the 2 remaining double to float warnings on setting s and c in SCMLpp.cpp

// This is for rotating untranslated points and offsetting them to a new origin.
static void rotate_point(float& x, float& y, float angle, float origin_x, float origin_y, bool flipped)
{
if(flipped)
angle = -angle;

float s = (float)sin(angle*M_PI/180);
float c = (float)cos(angle*M_PI/180);
float xnew = (x * c) - (y * s);
float ynew = (x * s) + (y * c);
xnew += origin_x;
ynew += origin_y;

x = xnew;
y = ynew;
}

After those changes, I had a clean compile.

Link to comment
Share on other sites

Thanks 8DashP. I'll work in those changes as soon as I can. Can you tell I don't have VS installed? :)

BigJDTec, you can check the index of the current animation (int Entity::animation) and if I remember correctly, it's safe to change it as long as it stays less than Entity::getNumAnimations(). I would like to add a better interface for that. There is not currently an easy way to see how far along the animation is, but if you look at Entity::update(), you can use some similar code to compare the current time to the time for the entire animation.

I invite you guys to send me any suggestions for APIs like that which you would find helpful. If you write an implementation of it, that's even better! I can set you up with commit access to the repository, just send me an email. I do intend to get all the features we need in there (including texture atlas support), but it depends on how much time I'm spending on projects using SCMLpp.

Link to comment
Share on other sites

Thanks 8DashP. I'll work in those changes as soon as I can. Can you tell I don't have VS installed? :)

No worries, but while I got it to compile, doesn't necessarily mean it works :) Won't be sure till I test, which will be a little ways off. The filename extraction may not be the most efficient, as it's deleting more than needed, but it's the simplest code I think, and given it shouldn't be a performance critical section, I doubt it matters.

Link to comment
Share on other sites

Thanks 8DashP. I'll work in those changes as soon as I can. Can you tell I don't have VS installed? :)

BigJDTec, you can check the index of the current animation (int Entity::animation) and if I remember correctly, it's safe to change it as long as it stays less than Entity::getNumAnimations(). I would like to add a better interface for that. There is not currently an easy way to see how far along the animation is, but if you look at Entity::update(), you can use some similar code to compare the current time to the time for the entire animation.

I invite you guys to send me any suggestions for APIs like that which you would find helpful. If you write an implementation of it, that's even better! I can set you up with commit access to the repository, just send me an email. I do intend to get all the features we need in there (including texture atlas support), but it depends on how much time I'm spending on projects using SCMLpp.

Thanks grimfang4, I've used those functions to get hold of what I needed. I'm currently writing some basic helper functions for stuff like playing a certain entities animation by name etc. I'll see how my use of the lib goes over the next week or so and then might be able to give some better feedback and hopefully code implementations.

Link to comment
Share on other sites

After a lot of fighting with unreferenced pointers and code revisions, I have something close to playing the example animation.

However, it plays the animation once and stops. Is there something specific you have to do to loop it, or am I missing the obvious?

I also need to integrate the z-order in somehow, as my images are overlapping and in 3d space, that's not playing nice.

Also, my images have gaps between them, but that could be because Shiva is resizing each part to a x2 dimension. Not sure how I'm going to get around that one just yet.

Anyway, the main question is on looping, if you can point me in the right direction?

Thanks. Russell.

Link to comment
Share on other sites

There's not a good interface for looping control yet, either. SCMLpp takes the looping setting for each animation from the SCML file. The variables which store that info are Animation::looping and Animation::loop_to (just as in the SCML spec). Animation::looping is a string, so my_anim->looping = "true" would make it loop. Animation::loop_to is an index to the key that comes after the loop (defaults to 0).

Link to comment
Share on other sites

OK thanks. Guess I'm being a little impatient. i'll check things out in a bit more detail.

By the way, I should have expanded on the pointer issue. It may be something to do with the shiva plugin environment, but where you are storing pointers to the images in your renderer code was a problem for me. When it got to draw_internal, the pointers were sometimes corrupt. I did find some google references that storing pointers in vectors is unreliable, as vector changes may invalidate existing pointers.

I'm not entirely sure what the final issue is, but I changed from using pointers to identfy my images, to a named string, which I then looked up. Not the most efficient, and I will review the code, but just a heads up that this might be another Visual Studio issue.

Link to comment
Share on other sites

Well, storing pointers to vector elements (in our case actually map elements) can indeed be hazardous as changes to the container can cause reallocations. However, storing pointers in a vector or map is perfectly safe. They're just integers, after all. The only way for it to go wrong is if something else tampers with the data stored at the address which the pointer points to. This is a very common problem. Using image data as a specific case, most of the time it is code (client code, asset manager, etc.) that deletes (frees) the image data and does not ensure that references to that data (i.e. the map) are cleaned up. Autopointers are often a good solution. I don't know how Shiva3D manages images/textures. Other times, memory errors (double frees, array overruns, mismatched struct definitions, etc.) can mess with the pointer value and then all bets are off. If you can set up a Linux development environment, I highly recommend using Valgrind for catching those memory errors in any code you write.

Link to comment
Share on other sites

Thanks for the tips. Shiva development only directly supports Visual Studio at the moment. A my work around is working at the moment, I'm just going to push on to at least confirm the basics all work in Shiva before I look at back-factoring.

I've almost got the example playing correctly now. Shiva insists on power of two texture sizes, so I had to do some UV manipulation to get the images lined up. Only thing left now is implementing z_index. Should be easy to do, but I'm curious why there's not already something in the renderer samples. Do SDL/Cocos2D just assume the draw order is sufficient?

The issues with Shiva is being a 3D space, overlapping planes do not render in draw order. As I said, should be easy to fix, just wondering is all.

Link to comment
Share on other sites

With software rendering, a painter's method is assumed. Things drawn later always draw on top. In hardware/GPU rendering, the framebuffer has a depth component in order to clip geometry (or fragments) based on the projected distance. In straight OpenGL at least, you can disable depth testing to make things draw in order.

Link to comment
Share on other sites

Not sure if you want to consider the z-order values for those who need them. If so, the following are the changes I made, they could be a little more generic maybe :-

In draw_simple_object, just before calling draw_internal, I added :-

	int zorder = obj1->z_index;

Similarly for draw_tweened_object

		int zorder = ref1->z_index;

Then I just added zorder to the paramater list for draw_internal

    void draw_internal(int folderID, int fileID, float x, float y, float angle, float scale_x, float scale_y, int zorder);

You could make it optional in the parameter list I suppose, otherwise it just gets ignored by those why don't need it.

Russell.

Link to comment
Share on other sites

Is the "hero" example supplied with this project supposed to load in A4.1? I just tried and it's crashing Sprite. The other two examples work.

I did note other forum posts on issues with the Hero example, something about old file format? The XML data says it's generator version a2, which is the same as the monster.

Any ideas why it isn't working?

Link to comment
Share on other sites

not sure how they ended up getting the same version number in the file, but it is a totally different format. The hero file was from a format we just used to prove the concept. The new format we created with the community to address all the needs of developers and animators

Link to comment
Share on other sites

not sure how they ended up getting the same version number in the file, but it is a totally different format. The hero file was from a format we just used to prove the concept. The new format we created with the community to address all the needs of developers and animators

Eh, OK. So is there a new version of the hero available? If not, this should be removed from the repository.

Also, maybe the Spriter import should reject a bit nicer than CTD? :)

Link to comment
Share on other sites

Alrighty,

Hey, I have really gave it a go, trying to port the C++ api to AGK, but got hung up ALL DAY trying to get the documentation to generate using Doxygen for windows version 1.8.3.1-setup.exe which I got setup, which installs a GUI, then I also installed Graphviz for windows also for DOT and class graphical inheritance displaying, as well as ensuring both tools are added to the path variables, I've tried to generate the documentation using first the GUI, loading the doxyfile first, then changing options as needed, and tried generating this way, it was kind of a NOGO, it made some docs, but when opened they were un-readable, with html tags throughout and java stuff... So then, I opened a command prompt and tried manually running doxygen doxyfile and got a slew of warnings, unknown tags, unable to open some files, etc.. etc...

Long story short, I really am trying to make this work here guys, but am hitting brick walls at every turn, I finally got the files I need to start with, and only the files I need, but I was wanting to get a set of docs to start off with, so I can understand the class relationships, references, inheritance, and what was on your mind when you did things, but even this seems to be more than a simple task... ??!!?? For someone that wants some help porting this to all kinds of platforms, we sure are making it hard to understand, and even harder just to obtain the main starting files, and simple set of source generated docs of the classes, and even better the graphical visualization of the class relationships and possibly a UML diagram or two..

Umm, my mind is fried, it has been a long day, I bet it is something simple like the doxyfile downloaded being saved improperly from google chrome in some java / html format instead of a simple human readable text file.. I just hope the other sourcefiles are not going to suffer from this problem as well, I simply browsed the directory since I do NOT want to setup a subversion app just to grab a copy of the source files needed to make a port of it for AGK, so I browsed the directory, and right clicked and selected save link as and left filenames as they were, and tried to re-create the folder structures on my harddrive under folder source with main 2 files: SCMLpp.cpp & .h inside source folder, then libraries folder under source folder and renderers also under source folder, inside libraries folder I saved the xml files listed as needed, inside renderers folder I basically grabbed all the other ported renderers such as SCML_cocos2dx.h &.cpp and SCML_SDL_gpu.cpp &.h I plan to use SDL version as the example to mimic for AGK versions, also have the *_main.cpp files for various renderers also, I'm hoping these are all the files I require, as well as I hope they are in a usable format, and not screwed up like the doxyfile was when saved under google chrome....

I'm sorry to go off, but man... My brain is screaming right now WTF!!!??!!! I'm just trying to help out some others.. I mean, if I really need to use Spriter, I can just use Construct 2 for those projects.. but it would be nice to use it under AGK as well..

anyways man, I'll report back sometime in a few days, after I get a handle on this sourcecode, hopfully getting the docs to generate something useful to human beings ;')..

A PDF file or HTML zipped folder of the correctly generated docs would be awesome! Just a thought..

Anyways, just thought I'd let you guys know, because I'm sure there are alot of other people experiencing issues very similar to mine, and may be holding some others back from creating other ports as well..

Ciao' Mano' Again, thanks for listening and giving me a sounding board to blow off some steam..

Ahh, to have my linux box back on the network to avoid stuff like this..

StOrM3 aka Ken

Link to comment
Share on other sites

Google Code does not let you just right-click and save the files that way. Those are HTML/Javascript files that control page layout when browsing the repository online. Really, a Subversion client is the way to go (how it is intended) and it's not tough at all to set up (and uninstall as necessary). You can get the raw files from Google Code with a few more clicks (browse the file, click "Show details" on the right, then click or save-as "View raw file". Here's an example of the URLs involved:

Browse Doxyfile:

https://code.google.com/p/scml-pp/sourc ... e/Doxyfile

Raw Doxyfile:

https://scml-pp.googlecode.com/svn/trun ... e/Doxyfile

Link to comment
Share on other sites

Yeah I'm using a Mac, and it was brain dead simple. Built in svn client, and the Doxygen client I used worked perfectly, although I'm getting more understanding just browsing the code as I go through making my changes.

For my work, i also just dragged all the required files into one directory, ss really TinyXML is the largest fileset, and even that I m replacing.

Link to comment
Share on other sites

Cool. As a matter of course, I'll be replacing TinyXML with TinyXML2 when I get around to it. It's very similar and, as a convenience bonus, is contained in only two files.

That should be good for file complexity. I could probably get by with it as is, but because Shiva works implicitly with internal resources, and has its own xml functions, it just ends up being easier if I make all resources loaded at build time instead of runtime, although I will try and keep the runtime option for those who want full flexibility.

So, I guess I'm not completely replacing it, just making the shiva internal XML the default, recommended method, so I'll have two processing flows within my code. Man, there sure are a lot of references to TiXML elements that I have to refactor :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...