i would like for this program to be comprehensible
This commit is contained in:
parent
4b410a3511
commit
57ad9fd139
11 changed files with 2 additions and 395 deletions
124
slutpet.c
124
slutpet.c
|
@ -1,124 +0,0 @@
|
|||
#define SDL_MAIN_USE_CALLBACKS
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include "stb_image.h"
|
||||
|
||||
#include "dat.h"
|
||||
#include "fns.h"
|
||||
|
||||
void
|
||||
SDL_AppQuit(void *as, SDL_AppResult res)
|
||||
{
|
||||
State *st;
|
||||
|
||||
st = as;
|
||||
if (st) {
|
||||
babble("put samply to bed!!");
|
||||
put_samply_to_bed(st->sam);
|
||||
babble("free state...");
|
||||
SDL_free(st);
|
||||
}
|
||||
|
||||
babble("bye!");
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_AppResult
|
||||
SDL_AppEvent(void *as, SDL_Event *ev)
|
||||
{
|
||||
switch (ev->type) {
|
||||
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
||||
babble("mouse button down event");
|
||||
if (ev->button.button == SDL_BUTTON_RIGHT) {
|
||||
babble("right-click quit requested");
|
||||
return SDL_APP_SUCCESS;
|
||||
}
|
||||
break;
|
||||
case SDL_EVENT_QUIT:
|
||||
babble("quit requested");
|
||||
return SDL_APP_SUCCESS;
|
||||
break; /* unreachable; here for visual symmetry */
|
||||
}
|
||||
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
SDL_AppResult
|
||||
SDL_AppIterate(void *as)
|
||||
{
|
||||
State *st = as;
|
||||
SDL_Texture *tx;
|
||||
Uint64 ms;
|
||||
|
||||
st->frame++;
|
||||
SDL_SetRenderDrawColor(st->ren, 0, 0, 0, SDL_ALPHA_TRANSPARENT);
|
||||
SDL_RenderClear(st->ren);
|
||||
|
||||
if (samply_step(st) < 0)
|
||||
return SDL_APP_FAILURE;
|
||||
|
||||
SDL_RenderPresent(st->ren);
|
||||
st->lastframe = SDL_GetTicks();
|
||||
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
SDL_AppResult
|
||||
SDL_AppInit(void **as, int argc, char **argv)
|
||||
{
|
||||
State *st;
|
||||
|
||||
babble("init sdl...");
|
||||
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
||||
fuck("sdl init fail: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
babble("alloc state...");
|
||||
st = SDL_calloc(1, sizeof(State));
|
||||
if (!st) {
|
||||
fuck("mem alloc fail: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
*as = st;
|
||||
|
||||
SDL_SetHint(SDL_HINT_X11_FORCE_OVERRIDE_REDIRECT, "1");
|
||||
|
||||
st->lastframe = SDL_GetTicks();
|
||||
st->frame = 0;
|
||||
|
||||
babble("create win+render...");
|
||||
if (!SDL_CreateWindowAndRenderer("slutpet", 320, 320,
|
||||
SDL_WINDOW_TRANSPARENT | SDL_WINDOW_BORDERLESS
|
||||
| SDL_WINDOW_NOT_FOCUSABLE
|
||||
| SDL_WINDOW_ALWAYS_ON_TOP,
|
||||
&st->win, &st->ren)) {
|
||||
fuck("win creation fail: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
if (SDL_EnableScreenSaver() == false)
|
||||
shit("cannot disable screensaver: %s", SDL_GetError());
|
||||
|
||||
st->dpy = SDL_GetDisplayForWindow(st->win);
|
||||
if (!st->dpy) {
|
||||
fuck("cannot get current display: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
if (SDL_GetDisplayBounds(st->dpy, &st->bounds) == false) {
|
||||
fuck("cannot get display bounds: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
babble("create samply!!...");
|
||||
st->sam = wake_samply_up(st);
|
||||
if (!st->sam) {
|
||||
fuck("samply said no. too bad!");
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
babble("hi!!");
|
||||
babble("program startup took %llums!", SDL_GetTicks());
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue