they're very hasty
This commit is contained in:
parent
3840fb0321
commit
d65a270aab
10 changed files with 102 additions and 17 deletions
2
Makefile
2
Makefile
|
@ -4,7 +4,7 @@ PREFIX ?= /usr/local
|
||||||
CFLAGS := $(CFLAGS) `pkg-config --cflags --libs sdl3`
|
CFLAGS := $(CFLAGS) `pkg-config --cflags --libs sdl3`
|
||||||
LDFLAGS := $(LDFLAGS) -lm
|
LDFLAGS := $(LDFLAGS) -lm
|
||||||
|
|
||||||
SRCS = slutpet.c img.c
|
SRCS = slutpet.c img.c samply.c
|
||||||
|
|
||||||
all: slutpet
|
all: slutpet
|
||||||
|
|
||||||
|
|
10
dat.h
10
dat.h
|
@ -1,12 +1,20 @@
|
||||||
|
typedef struct Samply Samply;
|
||||||
typedef struct Image Image;
|
typedef struct Image Image;
|
||||||
typedef struct State State;
|
typedef struct State State;
|
||||||
|
|
||||||
|
struct Samply {
|
||||||
|
Image *idle;
|
||||||
|
Image *walka;
|
||||||
|
Image *walkb;
|
||||||
|
};
|
||||||
|
|
||||||
struct Image {
|
struct Image {
|
||||||
char *name; /* used for debugging purposes */
|
char *name; /* used for debugging purposes */
|
||||||
int w;
|
int w;
|
||||||
int h;
|
int h;
|
||||||
int bpp;
|
int bpp;
|
||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
|
SDL_Surface *sur;
|
||||||
SDL_Texture *tex;
|
SDL_Texture *tex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,5 +22,5 @@ struct State {
|
||||||
SDL_Window *win;
|
SDL_Window *win;
|
||||||
SDL_Renderer *ren;
|
SDL_Renderer *ren;
|
||||||
|
|
||||||
Image *test;
|
Samply *sam;
|
||||||
};
|
};
|
||||||
|
|
3
fns.h
3
fns.h
|
@ -5,3 +5,6 @@
|
||||||
|
|
||||||
void free_image(Image *i);
|
void free_image(Image *i);
|
||||||
Image *load_image(SDL_Renderer *ren, char *path);
|
Image *load_image(SDL_Renderer *ren, char *path);
|
||||||
|
|
||||||
|
void put_samply_to_bed(Samply *sam);
|
||||||
|
Samply *wake_samply_up(SDL_Renderer *ren);
|
||||||
|
|
26
img.c
26
img.c
|
@ -1,4 +1,7 @@
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#define STBI_MALLOC(sz) SDL_malloc(sz)
|
||||||
|
#define STBI_REALLOC(p,newsz) SDL_realloc(p,newsz)
|
||||||
|
#define STBI_FREE(p) SDL_free(p)
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include "stb_image.h"
|
#include "stb_image.h"
|
||||||
|
|
||||||
|
@ -13,9 +16,13 @@ free_image(Image *i)
|
||||||
babble("free img %s texture...", i->name);
|
babble("free img %s texture...", i->name);
|
||||||
SDL_DestroyTexture(i->tex);
|
SDL_DestroyTexture(i->tex);
|
||||||
}
|
}
|
||||||
|
if (i->sur) {
|
||||||
|
babble("destroy image %s surface...", i->name);
|
||||||
|
SDL_DestroySurface(i->sur);
|
||||||
|
}
|
||||||
if (i->data) {
|
if (i->data) {
|
||||||
babble("free img %s data...", i->name);
|
babble("free img %s data...", i->name);
|
||||||
SDL_free(i->data);
|
stbi_image_free(i->data);
|
||||||
}
|
}
|
||||||
if (i->name) {
|
if (i->name) {
|
||||||
babble("free img %s name...", i->name);
|
babble("free img %s name...", i->name);
|
||||||
|
@ -30,7 +37,6 @@ Image *
|
||||||
load_image(SDL_Renderer *ren, char *path)
|
load_image(SDL_Renderer *ren, char *path)
|
||||||
{
|
{
|
||||||
Image *i;
|
Image *i;
|
||||||
SDL_Surface *sur;
|
|
||||||
|
|
||||||
babble("create image %s...", path);
|
babble("create image %s...", path);
|
||||||
|
|
||||||
|
@ -41,7 +47,7 @@ load_image(SDL_Renderer *ren, char *path)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
babble("alloc image name...", path);
|
babble("alloc image %s name...", path);
|
||||||
i->name = SDL_strdup(path);
|
i->name = SDL_strdup(path);
|
||||||
if (!i->name) {
|
if (!i->name) {
|
||||||
shit("strdup fail: %s", SDL_GetError());
|
shit("strdup fail: %s", SDL_GetError());
|
||||||
|
@ -49,31 +55,33 @@ load_image(SDL_Renderer *ren, char *path)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
babble("alloc image %s data...", i->name);
|
||||||
i->data = stbi_load(path, &i->w, &i->h,
|
i->data = stbi_load(path, &i->w, &i->h,
|
||||||
&i->bpp, 4);
|
&i->bpp, 4);
|
||||||
if (!i->data) {
|
if (!i->data) {
|
||||||
shit("mem alloc fail: %s", SDL_GetError());
|
shit("img load fail: %s", stbi_failure_reason());
|
||||||
free_image(i);
|
free_image(i);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sur = SDL_CreateSurfaceFrom(i->w, i->h,
|
babble("alloc image %s surface...", i->name);
|
||||||
|
i->sur = SDL_CreateSurfaceFrom(i->w, i->h,
|
||||||
SDL_PIXELFORMAT_RGBA32, i->data,
|
SDL_PIXELFORMAT_RGBA32, i->data,
|
||||||
i->w * 4);
|
i->w * 4);
|
||||||
if (!sur) {
|
if (!i->sur) {
|
||||||
shit("surface creation fail: %s", SDL_GetError());
|
shit("surface creation fail: %s", SDL_GetError());
|
||||||
free_image(i);
|
free_image(i);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
i->tex = SDL_CreateTextureFromSurface(ren, sur);
|
babble("alloc image %s texture...", i->name);
|
||||||
|
i->tex = SDL_CreateTextureFromSurface(ren, i->sur);
|
||||||
if (!i->tex) {
|
if (!i->tex) {
|
||||||
shit("surface creation fail: %s", SDL_GetError());
|
shit("surface creation fail: %s", SDL_GetError());
|
||||||
SDL_DestroySurface(sur);
|
SDL_DestroySurface(i->sur);
|
||||||
free_image(i);
|
free_image(i);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
SDL_DestroySurface(sur);
|
|
||||||
|
|
||||||
babble("image %s created", path);
|
babble("image %s created", path);
|
||||||
return i;
|
return i;
|
||||||
|
|
59
samply.c
Normal file
59
samply.c
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
|
#include "dat.h"
|
||||||
|
#include "fns.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
put_samply_to_bed(Samply *sam)
|
||||||
|
{
|
||||||
|
if (sam) {
|
||||||
|
babble("free samply idle!!");
|
||||||
|
free_image(sam->idle);
|
||||||
|
babble("free samply walk a!!");
|
||||||
|
free_image(sam->walka);
|
||||||
|
babble("free samply walk b!!");
|
||||||
|
free_image(sam->walkb);
|
||||||
|
}
|
||||||
|
|
||||||
|
babble("good night, samply!!");
|
||||||
|
SDL_free(sam);
|
||||||
|
}
|
||||||
|
|
||||||
|
Samply *
|
||||||
|
wake_samply_up(SDL_Renderer *ren)
|
||||||
|
{
|
||||||
|
Samply *sam;
|
||||||
|
|
||||||
|
babble("wake up, samply!!");
|
||||||
|
sam = SDL_calloc(1, sizeof(Samply));
|
||||||
|
if (!sam) {
|
||||||
|
fuck("samply would rather stay in bed. too bad! %s", SDL_GetError());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
babble("stand samply up!!");
|
||||||
|
sam->idle = load_image(ren, "samply/Samply.png");
|
||||||
|
if (!sam->idle) {
|
||||||
|
fuck("samply would rather stay in bed. too bad! %s", SDL_GetError());
|
||||||
|
put_samply_to_bed(sam);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
babble("samply walk! part 1!!");
|
||||||
|
sam->walka = load_image(ren, "samply/Samply_Walk1.png");
|
||||||
|
if (!sam->walka) {
|
||||||
|
fuck("samply would rather stay in bed. too bad! %s", SDL_GetError());
|
||||||
|
put_samply_to_bed(sam);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
babble("samply walk! part 2!!");
|
||||||
|
sam->walkb = load_image(ren, "samply/Samply_Walk2.png");
|
||||||
|
if (!sam->walkb) {
|
||||||
|
fuck("samply would rather stay in bed. too bad! %s", SDL_GetError());
|
||||||
|
put_samply_to_bed(sam);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sam;
|
||||||
|
}
|
BIN
samply/Samply.png
Normal file
BIN
samply/Samply.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 90 KiB |
BIN
samply/Samply_Walk1.png
Normal file
BIN
samply/Samply_Walk1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 71 KiB |
BIN
samply/Samply_Walk2.png
Normal file
BIN
samply/Samply_Walk2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 71 KiB |
3
samply/readme
Normal file
3
samply/readme
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
theyre very hasty
|
||||||
|
|
||||||
|
h/t zyre
|
16
slutpet.c
16
slutpet.c
|
@ -13,7 +13,8 @@ SDL_AppQuit(void *as, SDL_AppResult res)
|
||||||
|
|
||||||
st = as;
|
st = as;
|
||||||
if (st) {
|
if (st) {
|
||||||
free_image(st->test);
|
babble("put samply to bed!!");
|
||||||
|
put_samply_to_bed(st->sam);
|
||||||
babble("free state...");
|
babble("free state...");
|
||||||
SDL_free(st);
|
SDL_free(st);
|
||||||
}
|
}
|
||||||
|
@ -50,7 +51,10 @@ SDL_AppIterate(void *as)
|
||||||
SDL_SetRenderDrawColor(st->ren, 0, 0, 0, SDL_ALPHA_TRANSPARENT);
|
SDL_SetRenderDrawColor(st->ren, 0, 0, 0, SDL_ALPHA_TRANSPARENT);
|
||||||
SDL_RenderClear(st->ren);
|
SDL_RenderClear(st->ren);
|
||||||
|
|
||||||
SDL_RenderTexture(st->ren, st->test->tex, NULL, NULL);
|
if (SDL_RenderTexture(st->ren, st->sam->idle->tex, NULL, NULL) == false) {
|
||||||
|
fuck("rendertexture fail: %s", SDL_GetError());
|
||||||
|
return SDL_APP_FAILURE;
|
||||||
|
}
|
||||||
SDL_RenderPresent(st->ren);
|
SDL_RenderPresent(st->ren);
|
||||||
return SDL_APP_CONTINUE;
|
return SDL_APP_CONTINUE;
|
||||||
}
|
}
|
||||||
|
@ -86,10 +90,10 @@ SDL_AppInit(void **as, int argc, char **argv)
|
||||||
return SDL_APP_FAILURE;
|
return SDL_APP_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
babble("create test image...");
|
babble("create samply!!...");
|
||||||
st->test = load_image(st->ren, "test.png");
|
st->sam = wake_samply_up(st->ren);
|
||||||
if (!st->test) {
|
if (!st->sam) {
|
||||||
fuck("img creation fail: %s", SDL_GetError());
|
fuck("samply said no. too bad!");
|
||||||
return SDL_APP_FAILURE;
|
return SDL_APP_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue