From fbedd77ed189cce2aaf2d1b6cd0891e37ac57df2 Mon Sep 17 00:00:00 2001 From: cat Date: Sat, 28 Jun 2025 15:59:51 +1000 Subject: [PATCH 1/2] finally start on the rewrite --- dat.h | 15 +++++++++++++ fns.h | 7 ++++++ img.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ samply/act.c | 4 ++++ samply/img.c | 7 ++++++ samply/samply.h | 6 +++++ slutpet.c | 0 7 files changed, 98 insertions(+) create mode 100644 dat.h create mode 100644 fns.h create mode 100644 img.c create mode 100644 samply/act.c create mode 100644 samply/img.c create mode 100644 samply/samply.h create mode 100644 slutpet.c diff --git a/dat.h b/dat.h new file mode 100644 index 0000000..9cac8d8 --- /dev/null +++ b/dat.h @@ -0,0 +1,15 @@ +typedef struct Action Action; +typedef struct Image Image; + +struct Action { + // step + // click +}; + +struct Image { + char *name; + int w, h, bpp; + unsigned char *data; + SDL_Surface *sur; + SDL_Texture *tex; +}; diff --git a/fns.h b/fns.h new file mode 100644 index 0000000..cc7db9c --- /dev/null +++ b/fns.h @@ -0,0 +1,7 @@ +#define babble(...) SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__) +#define info(...) SDL_Log(__VA_ARGS__) +#define shit(...) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__) +#define fuck(...) SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__) + +void free_image(Image *i); +int load_image(Image *i, SDL_Renderer *ren); diff --git a/img.c b/img.c new file mode 100644 index 0000000..99a2986 --- /dev/null +++ b/img.c @@ -0,0 +1,59 @@ +#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 +#include "stb_image.h" + +#include "dat.h" +#include "fns.h" + +void +free_image(Image *i) +{ + if (i->tex) { + babble("destroying texture for image %s...", i->name); + SDL_DestroyTexture(i->tex); + } + if (i->sur) { + babble("destroying surface for image %s...", i->name); + SDL_DestroySurface(i->sur); + } + if (i->data) { + babble("destroying data for image %s...", i->name); + stbi_image_free(i->data); + } +} + +int +load_image(Image *i, SDL_Renderer *ren) +{ + babble("opening image %s...", i->name); + i->data = stbi_load(i->name, &i->w, &i->h, &i->bpp, 4); + if (!i->data) { + shit("stbi_load: %s", stbi_failure_reason()); + goto err; + } + + babble("creating surface for image %s...", i->name); + i->sur = SDL_CreateSurfaceFrom(i->w, i->h, SDL_PIXELFORMAT_RGBA32, + i->data, i->w * 4); + if (!i->sur) { + shit("SDL_CreateSurfaceFrom: %s", SDL_GetError()); + goto err; + } + + babble("creating texture for image %s...", i->name); + i->tex = SDL_CreateTextureFromSurface(ren, i->sur); + if (!i->tex) { + shit("SDL_CreateTextureFromSurface: %s", SDL_GetError()); + goto err; + } + + babble("created image %s!", i->name); + return 0; + +err: + free_image(i); + return -1; +} diff --git a/samply/act.c b/samply/act.c new file mode 100644 index 0000000..0c0bbb2 --- /dev/null +++ b/samply/act.c @@ -0,0 +1,4 @@ +#include + +#include "../dat.h" +#include "samply.h" diff --git a/samply/img.c b/samply/img.c new file mode 100644 index 0000000..9e7686c --- /dev/null +++ b/samply/img.c @@ -0,0 +1,7 @@ +#include + +#include "../dat.h" +#include "samply.h" + +struct Image samply_sprites[] = { +}; diff --git a/samply/samply.h b/samply/samply.h new file mode 100644 index 0000000..c11d761 --- /dev/null +++ b/samply/samply.h @@ -0,0 +1,6 @@ +typedef struct Samply Samply; + +struct Samply { +}; + +extern Image samply_sprites[]; diff --git a/slutpet.c b/slutpet.c new file mode 100644 index 0000000..e69de29 From 5b256e74cde0d46b114931087fd34778aef67ede Mon Sep 17 00:00:00 2001 From: cat Date: Sat, 28 Jun 2025 16:01:22 +1000 Subject: [PATCH 2/2] why did this not commit --- slutpet.6 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/slutpet.6 b/slutpet.6 index 0a6d579..a9a1447 100644 --- a/slutpet.6 +++ b/slutpet.6 @@ -1,4 +1,4 @@ -.Dd May 24, 2025 +.Dd June 28, 2025 .Dt SLUTPET 6 .Os . @@ -15,3 +15,9 @@ be a desktop pet thing, but currently it doesn't actually exist. Try again later. +. +.Sh INTERNALS +Currently this section is just notes on how I'm going to +try to implement everything. Later this will just be +describing the program's layout, to hopefully make +it easier to figure out how to modify it.