diff --git a/.gitignore b/.gitignore index 25c9fff..d4eb347 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,6 @@ *bin/data *pack *core -*screenshot.png +screenshots/*.png *VERSION diff --git a/screenshots/README b/screenshots/README new file mode 100644 index 0000000..f6d998e --- /dev/null +++ b/screenshots/README @@ -0,0 +1,2 @@ +I guess you can store some screenshots in here. + diff --git a/src/player.c b/src/player.c index 5af921d..e50ce4f 100644 --- a/src/player.c +++ b/src/player.c @@ -964,11 +964,33 @@ void player_brokeHyperspace(void) { } // Take a screenshot. +static int screenshot_cur = 0; void player_screenshot(void) { - char filename[20]; - // TODO not overwirte old screenshots. - strncpy(filename, "screenshot.png", 20); - DEBUG("SCREENSHOT!"); - gl_screenshot(filename); + FILE* fp; + int done; + char filename[PATH_MAX]; + + done = 0; + + do { + if(screenshot_cur >= 128) { + // Just incase I fucked up. :) + WARN("You have reached the maximum amount of screenshots [128]"); + return; + } + snprintf(filename, PATH_MAX, "../screenshots/screenshot%03d.png", screenshot_cur); + fp = fopen(filename, "r"); // Myeah, I know it's a horrible way to check. + if(fp == NULL) done = 1; + else { + // Next. + screenshot_cur++; + fclose(fp); + } + fp = NULL; + } while(!done); + + // Now gief me that screenshot. + DEBUG("Taking screenshot [%03d]..", screenshot_cur); + gl_screenshot(filename); }