Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizables loop frames #102

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tools/rescomp/inc/spr_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ typedef struct
frameSprite_* getFlippedFrameSprite(frameSprite_* frameSprite, int wf, int hf, int hflip, int vflip);
frameSprite_* getFrameSprite(unsigned char *image8bpp, tileset_* tileset, int wi, int x, int y, int w, int h);
animFrame_* getAnimFrame(unsigned char *image8bpp, int wi, int fx, int fy, int wf, int hf, int time, int collisionType);
animation_* getAnimation(unsigned char *image8bpp, int wi, int anim, int wf, int hf, int time, int collisionType);
spriteDefinition_* getSpriteDefinition(unsigned char *image8bpp, int w, int h, int wf, int hf, int time, int collisionType);
animation_* getAnimation(unsigned char *image8bpp, int wi, int anim, int wf, int hf, int time, int collisionType, int loopFrame);
spriteDefinition_* getSpriteDefinition(unsigned char *image8bpp, int w, int h, int wf, int hf, int time, int collisionType, int *loopFrames, int loopFramesCount);

int* getLoopFrames(char *loopStr, int *numberOfFrames);

int packSpriteDef(spriteDefinition_* spriteDef, int method);
void removeEmptyFrame(spriteDefinition_ *spriteDef);
Expand Down
Binary file added tools/rescomp/out/rescomp.exe
Binary file not shown.
246 changes: 246 additions & 0 deletions tools/rescomp/rescomp.depend
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
# depslib dependency file v1.0
1512888862 source:c:\users\heito\documents\projects\sgdk\tools\rescomp\src\bin.c
<stdio.h>
<string.h>
<stdlib.h>
"../inc/rescomp.h"
"../inc/plugin.h"
"../inc/bin.h"
"../inc/tools.h"

1512888862 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\rescomp.h

1512888862 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\plugin.h

1512888862 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\bin.h

1512888862 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\tools.h

1512888862 source:c:\users\heito\documents\projects\sgdk\tools\rescomp\src\bitmap.c
<stdio.h>
<string.h>
"../inc/rescomp.h"
"../inc/plugin.h"
"../inc/tools.h"
"../inc/img_tools.h"
"../inc/bitmap.h"
"../inc/palette.h"

1512888862 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\img_tools.h

1512888862 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\bitmap.h

1512888862 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\palette.h

1512888862 source:c:\users\heito\documents\projects\sgdk\tools\rescomp\src\image.c
<stdio.h>
<string.h>
"../inc/rescomp.h"
"../inc/plugin.h"
"../inc/tools.h"
"../inc/img_tools.h"
"../inc/tile_tools.h"
"../inc/image.h"
"../inc/palette.h"
"../inc/map.h"
"../inc/tileset.h"

1512888862 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\tile_tools.h

1512888862 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\image.h

1512888862 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\map.h
"../inc/tile_tools.h"

1512888862 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\tileset.h
"../inc/tile_tools.h"

1512888862 source:c:\users\heito\documents\projects\sgdk\tools\rescomp\src\img_tools.c
<stdio.h>
<string.h>
<stdlib.h>
<stdbool.h>
<math.h>
"../inc/libpng.h"
"../inc/tools.h"
"../inc/img_tools.h"

1512888862 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\libpng.h
<string.h>
<vector>
<string>
"lodepng.h"
<iostream>
"lodepng.h"

1512888862 source:c:\users\heito\documents\projects\sgdk\tools\rescomp\src\libpng.c
"../inc/libpng.h"
<stdio.h>
<stdlib.h>
<fstream>

1512888862 source:c:\users\heito\documents\projects\sgdk\tools\rescomp\src\map.c
<stdio.h>
<string.h>
"../inc/rescomp.h"
"../inc/plugin.h"
"../inc/tools.h"
"../inc/img_tools.h"
"../inc/tile_tools.h"

1512888862 source:c:\users\heito\documents\projects\sgdk\tools\rescomp\src\palette.c
<stdio.h>
<string.h>
<stdlib.h>
"../inc/rescomp.h"
"../inc/plugin.h"
"../inc/tools.h"
"../inc/img_tools.h"
"../inc/palette.h"

1512888862 source:c:\users\heito\documents\projects\sgdk\tools\rescomp\src\pcm.c
<stdio.h>
<string.h>
<stdlib.h>
"../inc/rescomp.h"
"../inc/plugin.h"
"../inc/pcm.h"
"../inc/tools.h"
"../inc/snd_tools.h"

1512888862 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\pcm.h

1512888862 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\snd_tools.h

1512888862 source:c:\users\heito\documents\projects\sgdk\tools\rescomp\src\rescomp.c
<stdlib.h>
<stdio.h>
<string.h>
<dirent.h>
<sys/types.h>
"../inc/rescomp.h"
"../inc/tools.h"
"../inc/plugin.h"
"../inc/palette.h"
"../inc/bitmap.h"
"../inc/tileset.h"
"../inc/map.h"
"../inc/image.h"
"../inc/sprite.h"
"../inc/xgmmusic.h"
"../inc/tfmmusic.h"
"../inc/vgmmusic.h"
"../inc/pcm.h"
"../inc/wav.h"
"../inc/bin.h"

1512888862 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\sprite.h
"../inc/spr_tools.h"

1513056638 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\spr_tools.h
"tools.h"
"tile_tools.h"

1512888862 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\xgmmusic.h

1512888862 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\tfmmusic.h

1512888862 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\vgmmusic.h

1512888862 c:\users\heito\documents\projects\sgdk\tools\rescomp\inc\wav.h

1512888862 source:c:\users\heito\documents\projects\sgdk\tools\rescomp\src\snd_tools.c
<stdio.h>
<string.h>
<stdlib.h>
"../inc/rescomp.h"
"../inc/tools.h"
"../inc/snd_tools.h"

1513055880 source:c:\users\heito\documents\projects\sgdk\tools\rescomp\src\spr_tools.c
<stdio.h>
<stdbool.h>
<stdlib.h>
<memory.h>
<string.h>
"../inc/spr_tools.h"
"../inc/tools.h"

1513056230 source:c:\users\heito\documents\projects\sgdk\tools\rescomp\src\sprite.c
<stdio.h>
<string.h>
"../inc/rescomp.h"
"../inc/plugin.h"
"../inc/tools.h"
"../inc/img_tools.h"
"../inc/spr_tools.h"
"../inc/sprite.h"
"../inc/palette.h"
"../inc/tileset.h"

1512888862 source:c:\users\heito\documents\projects\sgdk\tools\rescomp\src\tfmmusic.c
<stdio.h>
<string.h>
<stdlib.h>
"../inc/rescomp.h"
"../inc/plugin.h"
"../inc/tfmmusic.h"
"../inc/tools.h"

1512888862 source:c:\users\heito\documents\projects\sgdk\tools\rescomp\src\tile_tools.c
<stdio.h>
<stdbool.h>
<stdlib.h>
<memory.h>
"../inc/tile_tools.h"
"../inc/tools.h"

1512888862 source:c:\users\heito\documents\projects\sgdk\tools\rescomp\src\tileset.c
<stdio.h>
<string.h>
"../inc/rescomp.h"
"../inc/plugin.h"
"../inc/tools.h"
"../inc/img_tools.h"
"../inc/tile_tools.h"
"../inc/tileset.h"
"../inc/palette.h"

1512888862 source:c:\users\heito\documents\projects\sgdk\tools\rescomp\src\tools.c
<stdio.h>
<string.h>
<stdlib.h>
<ctype.h>
"../inc/rescomp.h"
"../inc/tools.h"
"../inc/img_tools.h"

1512888862 source:c:\users\heito\documents\projects\sgdk\tools\rescomp\src\vgmmusic.c
<stdio.h>
<string.h>
<stdlib.h>
"../inc/rescomp.h"
"../inc/plugin.h"
"../inc/vgmmusic.h"
"../inc/tools.h"

1512888862 source:c:\users\heito\documents\projects\sgdk\tools\rescomp\src\wav.c
<stdio.h>
<string.h>
<stdlib.h>
"../inc/rescomp.h"
"../inc/plugin.h"
"../inc/wav.h"
"../inc/tools.h"
"../inc/snd_tools.h"

1512888862 source:c:\users\heito\documents\projects\sgdk\tools\rescomp\src\xgmmusic.c
<stdio.h>
<string.h>
<stdlib.h>
"../inc/rescomp.h"
"../inc/plugin.h"
"../inc/xgmmusic.h"
"../inc/tools.h"
"../inc/snd_tools.h"

59 changes: 55 additions & 4 deletions tools/rescomp/src/spr_tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>

#include "../inc/spr_tools.h"
#include "../inc/tools.h"
Expand Down Expand Up @@ -183,7 +184,7 @@ animFrame_* getAnimFrame(unsigned char *image8bpp, int wi, int fx, int fy, int w
return result;
}

animation_* getAnimation(unsigned char *image8bpp, int wi, int anim, int wf, int hf, int time, int collision)
animation_* getAnimation(unsigned char *image8bpp, int wi, int anim, int wf, int hf, int time, int collision, int loopFrame)
{
int i;
animation_* result;
Expand All @@ -194,6 +195,19 @@ animation_* getAnimation(unsigned char *image8bpp, int wi, int anim, int wf, int
// get max number of frame
numFrame = wi / wf;

if (loopFrame >= numFrame)
{
printf("Warning: Animation has %d frames but the loop is defined at frame %d (at index %d)\n", numFrame, loopFrame + 1, loopFrame);
printf("Loop frame will be set to last frame (at index %d)\n", numFrame - 1);
loopFrame = numFrame - 1;
}
if (loopFrame < 0)
{
printf("Warning: Loop frame for animation is negative (%d)\n", loopFrame);
printf("Loop frame will be set to 0\n");
loopFrame = 0;
}

// allocate result
result = malloc(sizeof(animation_));
result->numFrame = numFrame;
Expand All @@ -206,7 +220,7 @@ animation_* getAnimation(unsigned char *image8bpp, int wi, int anim, int wf, int
sequence = malloc(numFrame * sizeof(unsigned char));
result->sequence = sequence;
// default: loop to frame 0
result->loop = 0;
result->loop = loopFrame;

for(i = 0; i < numFrame; i++)
{
Expand All @@ -219,7 +233,7 @@ animation_* getAnimation(unsigned char *image8bpp, int wi, int anim, int wf, int
return result;
}

spriteDefinition_* getSpriteDefinition(unsigned char *image8bpp, int w, int h, int wf, int hf, int time, int collision)
spriteDefinition_* getSpriteDefinition(unsigned char *image8bpp, int w, int h, int wf, int hf, int time, int collision, int *loopFrames, int loopFramesCount)
{
int i;
int numAnim;
Expand All @@ -240,7 +254,14 @@ spriteDefinition_* getSpriteDefinition(unsigned char *image8bpp, int w, int h, i

for(i = 0; i < numAnim; i++)
{
*animations = getAnimation(image8bpp, w, i, wf, hf, time, collision);
int loopFrame = 0;
if (loopFrames != NULL)
{
if (i < loopFramesCount)
loopFrame = loopFrames[i];
}

*animations = getAnimation(image8bpp, w, i, wf, hf, time, collision, loopFrame);
if (*animations == NULL) return NULL;

// update maximum number of tile and sprite
Expand All @@ -253,6 +274,36 @@ spriteDefinition_* getSpriteDefinition(unsigned char *image8bpp, int w, int h, i
return result;
}

int* getLoopFrames(char* loopsStr, int* numberOfFrames)
{
if (loopsStr == NULL || strlen(loopsStr) == 0)
return NULL;

char *token;
int *frames;
int i = 0;

frames = malloc(sizeof(int));
token = strtok(loopsStr, ",");

while(token != NULL)
{
char *temp;
frames = realloc(frames, sizeof(int) * (i + 1));
frames[i] = (int) strtol(token, &temp, 10);
if (token == temp)
{
printf("Warning: Invalid value (%s) for the loop frame of animation %d\n", token, i);
printf("Loop frame will default to 0\n");
}
token = strtok(NULL, ",");
i++;
}

*numberOfFrames = i;
return frames;
}


static int getMaxNumTileAnimation(animation_* animation)
{
Expand Down
Loading