diff --git a/dat.h b/dat.h index 6457e27..4254bd2 100644 --- a/dat.h +++ b/dat.h @@ -21,6 +21,7 @@ struct Image { struct State { SDL_Window *win; SDL_Renderer *ren; + Uint64 lastframe; Samply *sam; }; diff --git a/readme b/readme index 09f31cc..26f7cf5 100644 --- a/readme +++ b/readme @@ -8,3 +8,12 @@ i want people to be able to create their own pets without having to figure out how to recompile. run it with `SDL_LOGGING=app=debug ./slutpet` for verbose logging + +file layout: + +dat.h - data structure header +fns.h - functions and macros header + +slutpet.c - sdl init and close +img.c - loading images +samply.c - pet Samply diff --git a/samply.c b/samply.c index 16ce3b1..a82bd31 100644 --- a/samply.c +++ b/samply.c @@ -13,10 +13,9 @@ put_samply_to_bed(Samply *sam) free_image(sam->walka); babble("free samply walk b!!"); free_image(sam->walkb); + babble("good night, samply!!"); + SDL_free(sam); } - - babble("good night, samply!!"); - SDL_free(sam); } Samply * @@ -34,7 +33,7 @@ wake_samply_up(SDL_Renderer *ren) 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()); + fuck("samply would rather stay in bed. too bad!"); put_samply_to_bed(sam); return NULL; } @@ -42,7 +41,7 @@ wake_samply_up(SDL_Renderer *ren) 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()); + fuck("samply would rather stay in bed. too bad!"); put_samply_to_bed(sam); return NULL; } @@ -50,7 +49,7 @@ wake_samply_up(SDL_Renderer *ren) 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()); + fuck("samply would rather stay in bed. too bad!"); put_samply_to_bed(sam); return NULL; } diff --git a/slutpet.c b/slutpet.c index 69ae2b2..883cd73 100644 --- a/slutpet.c +++ b/slutpet.c @@ -47,15 +47,24 @@ SDL_AppResult SDL_AppIterate(void *as) { State *st = as; + SDL_Texture *tx; + Uint64 ms; SDL_SetRenderDrawColor(st->ren, 0, 0, 0, SDL_ALPHA_TRANSPARENT); SDL_RenderClear(st->ren); - if (SDL_RenderTexture(st->ren, st->sam->idle->tex, NULL, NULL) == false) { + ms = SDL_GetTicks(); + if ((ms / 100) % 2) + tx = st->sam->walka->tex; + else + tx = st->sam->walkb->tex; + + if (SDL_RenderTexture(st->ren, tx, NULL, NULL) == false) { fuck("rendertexture fail: %s", SDL_GetError()); return SDL_APP_FAILURE; } SDL_RenderPresent(st->ren); + st->lastframe = SDL_GetTicks(); return SDL_APP_CONTINUE; } @@ -80,8 +89,10 @@ SDL_AppInit(void **as, int argc, char **argv) SDL_SetHint(SDL_HINT_X11_FORCE_OVERRIDE_REDIRECT, "1"); + st->lastframe = SDL_GetTicks(); + babble("create win+render..."); - if (!SDL_CreateWindowAndRenderer("slutpet", 320, 240, + if (!SDL_CreateWindowAndRenderer("slutpet", 320, 320, SDL_WINDOW_TRANSPARENT | SDL_WINDOW_BORDERLESS | SDL_WINDOW_NOT_FOCUSABLE | SDL_WINDOW_ALWAYS_ON_TOP, @@ -98,5 +109,6 @@ SDL_AppInit(void **as, int argc, char **argv) } babble("hi!!"); + babble("program startup took %llums!", SDL_GetTicks()); return SDL_APP_CONTINUE; }