summaryrefslogtreecommitdiffstats
path: root/nyan.c
diff options
context:
space:
mode:
Diffstat (limited to 'nyan.c')
-rw-r--r--nyan.c105
1 files changed, 86 insertions, 19 deletions
diff --git a/nyan.c b/nyan.c
index 91bcfe3..36b252a 100644
--- a/nyan.c
+++ b/nyan.c
@@ -4,8 +4,8 @@
/* If you like this software and would like to contribute to its continued improvement */
/* then please feel free to submit bug reports here: www.github.com/JohnAnthony */
/* */
-/* This program is licensed under the GPLv3 and in support of Free and Open Source */
-/* Software in general. The full license can be found at http://www.gnu.org/licenses/gpl.html */
+/* This program is licensed under the GPLv3 and is Free Software */
+/* The full license can be found at http://www.gnu.org/licenses/gpl.html */
/* ============================================================================================ */
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
@@ -18,7 +18,10 @@
#include <getopt.h>
#include <stdint.h>
#include <math.h>
-#include "list.h" /* Linked list implementation */
+#include <bsd/sys/queue.h> // linked list implementation
+
+#include <stdio.h>
+#include <X11/extensions/Xrandr.h>
/* Predecs */
void *ec_malloc(unsigned int size);
@@ -32,21 +35,70 @@ void usage(char *exname);
#include "globals.h"
#include "draw.h"
+void get_screen_info()
+{
+int iscres, icrtc;
+
+Display *disp = XOpenDisplay(0);
+XRRScreenResources *screen = XRRGetScreenResources(disp, DefaultRootWindow(disp));
+for (iscres = screen->noutput; iscres > 0; )
+ {
+ --iscres;
+
+ XRROutputInfo *info = XRRGetOutputInfo (disp, screen, screen->outputs[iscres]);
+ if (info->connection == RR_Connected)
+ {
+ for (icrtc = info->ncrtc; icrtc > 0;)
+ {
+ --icrtc;
+
+ XRRCrtcInfo *crtc_info = XRRGetCrtcInfo (disp, screen, screen->crtcs[icrtc]);
+ fprintf(stderr, "==> %dx%d+%dx%d\n", crtc_info->x, crtc_info->y, crtc_info->width, crtc_info->height);
+
+ XRRFreeCrtcInfo(crtc_info);
+ }
+ }
+ XRRFreeOutputInfo (info);
+ }
+ XRRFreeScreenResources(screen);
+}
+
+
+
+
+
+
void cleanup(void)
{
Mix_HaltMusic();
Mix_FreeMusic(music);
Mix_CloseAudio();
- /* Free cats */
- cat_instance *c, *tmpc;
- list_for_each_entry_safe(c, tmpc, &cat_list, list){list_del(&c->list); free(c);}
- /* Free rainbows */
- rainbow_instance *r, *tmpr;
- list_for_each_entry_safe(r, tmpr, &rainbow_list, list){list_del(&r->list); free(r);}
- /* Free sparkles */
- sparkle_instance *s, *tmps;
- list_for_each_entry_safe(s, tmps, &sparkle_list, list){list_del(&s->list); free(s);}
+ /* free cats */
+ cat_instance *c, *ctmp;
+ LIST_FOREACH_SAFE(c, &cat_list, entries, ctmp)
+ {
+ LIST_REMOVE(c, entries);
+ free(c);
+ }
+
+ /* free rainbows */
+ rainbow_instance *r, *rtmp;
+ LIST_FOREACH_SAFE(r, &rainbow_list, entries, rtmp)
+ {
+ LIST_REMOVE(r, entries);
+ free(r);
+ }
+
+
+ /* free sparkles */
+ sparkle_instance *s, *stmp;
+ LIST_FOREACH_SAFE(s, &sparkle_list, entries, stmp)
+ {
+ LIST_REMOVE(s, entries);
+ free(s);
+ }
+
SDL_DestroyRenderer(renderer);
SDL_Quit();
@@ -88,14 +140,15 @@ void handle_args(int argc, char *argv[])
{"data-set", required_argument, 0, 'd'},
{"sine", no_argument, 0, 's'},
{"count", required_argument, 0, 'n'},
+ {"version", no_argument, 0, 'V'},
{0, 0, 0, 0}
};
/* getopt_long stores the option index here. */
int option_index = 0;
- c = getopt_long(argc, argv, "hfwc:abev:r:d:sn:", long_options, &option_index);
+ c = getopt_long(argc, argv, "hfwc:abev:r:d:sn:V", long_options, &option_index);
- /* Detect the end of the options. */
+ /* detect the end of the options. */
if (c == -1){break;}
switch (c)
@@ -169,6 +222,12 @@ void handle_args(int argc, char *argv[])
cat_num = 1;
}
break;
+ case 'V':
+ printf("Copyright (C) 2020 John Antony, 2022 DiffieHellman\n"
+ "License GPLv3: GNU GPL version 3 <http://gnu.org/licenses/gpl.html>\n\n"
+ "This is free software; you are free to change and redistribute it.\n"
+ "There is NO WARRANTY, to the extent permitted by law.\n");
+ exit(0);
case '?':
/* getopt_long already printed an error message. */
@@ -236,6 +295,11 @@ void init(void)
Mix_VolumeMusic(sound_volume);
}
+ /* init the linked lists */
+ LIST_INIT(&cat_list);
+ LIST_INIT(&rainbow_list);
+ LIST_INIT(&sparkle_list);
+
if (cat_num == 1)
{
add_cat((SCREEN_WIDTH - cat_width) / 2, (SCREEN_HEIGHT - cat_height)/2);
@@ -331,7 +395,7 @@ void load_resource_data()
rainbow_count = atoi(fgets(buffer, BUF_SZ, fp));
sparkle_count = atoi(fgets(buffer, BUF_SZ, fp));
- if (!cat_count||!rainbow_count||!sparkle_count){errout("Error reading resource data file.");}
+ if (!cat_count||!rainbow_count||!sparkle_count){errout("Error reading or parsing resource data file.");}
fclose(fp);
}
@@ -349,7 +413,7 @@ void run()
{
last_draw = SDL_GetTicks();
- /* It's faster to just clear the whole renderer rather than individually overwriting each sprite */
+ /* it's faster to just clear the whole renderer rather than individually overwriting each sprite */
SDL_RenderClear(renderer);
update_sparkles();
@@ -362,10 +426,10 @@ void run()
if (sine){handle_sine();}
- /* Display the frame */
+ /* display the frame */
SDL_RenderPresent(renderer);
- /* Animation sequence increment and looping */
+ /* animation sequence increment and looping */
if (++cat_sprite >= cat_count){cat_sprite = 0;}
if (++rainbow_sprite >= rainbow_count){rainbow_sprite = 0;}
if (++sparkle_sprite >= sparkle_count){sparkle_sprite = 0;}
@@ -392,13 +456,16 @@ void usage(char* exname)
this program by default are \"default\"\n\
and \"freedom\" sets.\n\
-s, --sine Make cat move in a sine wave.\n\
- -n, --count Number of cats to spawn.\n", exname);
+ -n, --count Number of cats to spawn.\n\
+ -V, --version Version and copyright information.\n", exname);
exit(0);
}
int main(int argc, char *argv[])
{
+// get_screen_info();
+// exit(1);
handle_args(argc, argv);
init();
run();