add logging macros
yes i am keeping those log level macro names
This commit is contained in:
parent
1490067dfd
commit
f6a75ff1af
3 changed files with 25 additions and 25 deletions
4
fns.h
Normal file
4
fns.h
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#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__)
|
2
readme
2
readme
|
@ -6,3 +6,5 @@ i have not tried cross-compiling to windows yet.
|
||||||
i think it's probably best to use some sort of extension language.
|
i think it's probably best to use some sort of extension language.
|
||||||
i want people to be able to create their own pets without having to
|
i want people to be able to create their own pets without having to
|
||||||
figure out how to recompile.
|
figure out how to recompile.
|
||||||
|
|
||||||
|
run it with `SDL_LOGGING=app=debug ./slutpet` for verbose logging
|
||||||
|
|
44
slutpet.c
44
slutpet.c
|
@ -4,6 +4,7 @@
|
||||||
#include <SDL3/SDL_main.h>
|
#include <SDL3/SDL_main.h>
|
||||||
#include "stb_image.h"
|
#include "stb_image.h"
|
||||||
|
|
||||||
|
#include "fns.h"
|
||||||
#include "dat.h"
|
#include "dat.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -15,21 +16,21 @@ SDL_AppQuit(void *as, SDL_AppResult res)
|
||||||
if (st) {
|
if (st) {
|
||||||
if (st->test) {
|
if (st->test) {
|
||||||
if (st->test->tex) {
|
if (st->test->tex) {
|
||||||
SDL_Log("free test texture...");
|
babble("free test texture...");
|
||||||
SDL_DestroyTexture(st->test->tex);
|
SDL_DestroyTexture(st->test->tex);
|
||||||
}
|
}
|
||||||
if (st->test->data) {
|
if (st->test->data) {
|
||||||
SDL_Log("free test img data...");
|
babble("free test img data...");
|
||||||
SDL_free(st->test->data);
|
SDL_free(st->test->data);
|
||||||
}
|
}
|
||||||
SDL_Log("free test img...");
|
babble("free test img...");
|
||||||
SDL_free(st->test);
|
SDL_free(st->test);
|
||||||
}
|
}
|
||||||
SDL_Log("free state...");
|
babble("free state...");
|
||||||
SDL_free(st);
|
SDL_free(st);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Log("bye!");
|
babble("bye!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ SDL_AppEvent(void *as, SDL_Event *ev)
|
||||||
{
|
{
|
||||||
switch (ev->type) {
|
switch (ev->type) {
|
||||||
case SDL_EVENT_QUIT:
|
case SDL_EVENT_QUIT:
|
||||||
SDL_Log("quit requested");
|
babble("quit requested");
|
||||||
return SDL_APP_SUCCESS;
|
return SDL_APP_SUCCESS;
|
||||||
break; /* unreachable; here for visual symmetry */
|
break; /* unreachable; here for visual symmetry */
|
||||||
}
|
}
|
||||||
|
@ -65,46 +66,41 @@ SDL_AppInit(void **as, int argc, char **argv)
|
||||||
State *st;
|
State *st;
|
||||||
SDL_Surface *sur;
|
SDL_Surface *sur;
|
||||||
|
|
||||||
SDL_Log("init sdl...");
|
babble("init sdl...");
|
||||||
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION,
|
fuck("sdl init fail: %s", SDL_GetError());
|
||||||
"sdl init fail: %s", SDL_GetError());
|
|
||||||
return SDL_APP_FAILURE;
|
return SDL_APP_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Log("alloc state...");
|
babble("alloc state...");
|
||||||
st = SDL_calloc(1, sizeof(State));
|
st = SDL_calloc(1, sizeof(State));
|
||||||
if (!st) {
|
if (!st) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION,
|
fuck("mem alloc fail: %s", SDL_GetError());
|
||||||
"mem alloc fail: %s", SDL_GetError());
|
|
||||||
return SDL_APP_FAILURE;
|
return SDL_APP_FAILURE;
|
||||||
}
|
}
|
||||||
*as = st;
|
*as = st;
|
||||||
|
|
||||||
SDL_Log("create win+render...");
|
babble("create win+render...");
|
||||||
if (!SDL_CreateWindowAndRenderer("slutpet", 320, 240,
|
if (!SDL_CreateWindowAndRenderer("slutpet", 320, 240,
|
||||||
SDL_WINDOW_TRANSPARENT | SDL_WINDOW_BORDERLESS
|
SDL_WINDOW_TRANSPARENT | SDL_WINDOW_BORDERLESS
|
||||||
| SDL_WINDOW_NOT_FOCUSABLE
|
| SDL_WINDOW_NOT_FOCUSABLE
|
||||||
| SDL_WINDOW_ALWAYS_ON_TOP,
|
| SDL_WINDOW_ALWAYS_ON_TOP,
|
||||||
&st->win, &st->ren)) {
|
&st->win, &st->ren)) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION,
|
fuck("win creation fail: %s", SDL_GetError());
|
||||||
"win creation fail: %s", SDL_GetError());
|
|
||||||
return SDL_APP_FAILURE;
|
return SDL_APP_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Log("create test image...");
|
babble("create test image...");
|
||||||
st->test = SDL_calloc(1, sizeof(Image));
|
st->test = SDL_calloc(1, sizeof(Image));
|
||||||
if (!st->test) {
|
if (!st->test) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION,
|
fuck("mem alloc fail: %s", SDL_GetError());
|
||||||
"mem alloc fail: %s", SDL_GetError());
|
|
||||||
return SDL_APP_FAILURE;
|
return SDL_APP_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
st->test->data = stbi_load("test.png", &st->test->w, &st->test->h,
|
st->test->data = stbi_load("test.png", &st->test->w, &st->test->h,
|
||||||
&st->test->bpp, 4);
|
&st->test->bpp, 4);
|
||||||
if (!st->test->data) {
|
if (!st->test->data) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION,
|
fuck("mem alloc fail: %s", SDL_GetError());
|
||||||
"mem alloc fail: %s", SDL_GetError());
|
|
||||||
return SDL_APP_FAILURE;
|
return SDL_APP_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,19 +108,17 @@ SDL_AppInit(void **as, int argc, char **argv)
|
||||||
SDL_PIXELFORMAT_RGBA32, st->test->data,
|
SDL_PIXELFORMAT_RGBA32, st->test->data,
|
||||||
st->test->w * 4);
|
st->test->w * 4);
|
||||||
if (!sur) {
|
if (!sur) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION,
|
fuck("surface creation fail: %s", SDL_GetError());
|
||||||
"surface creation fail: %s", SDL_GetError());
|
|
||||||
return SDL_APP_FAILURE;
|
return SDL_APP_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
st->test->tex = SDL_CreateTextureFromSurface(st->ren, sur);
|
st->test->tex = SDL_CreateTextureFromSurface(st->ren, sur);
|
||||||
if (!st->test->tex) {
|
if (!st->test->tex) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION,
|
fuck("surface creation fail: %s", SDL_GetError());
|
||||||
"surface creation fail: %s", SDL_GetError());
|
|
||||||
SDL_DestroySurface(sur);
|
SDL_DestroySurface(sur);
|
||||||
return SDL_APP_FAILURE;
|
return SDL_APP_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Log("it work");
|
babble("hi!!");
|
||||||
return SDL_APP_CONTINUE;
|
return SDL_APP_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue