about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--demo.c42
1 files changed, 22 insertions, 20 deletions
diff --git a/demo.c b/demo.c
index a5116de..812e5f4 100644
--- a/demo.c
+++ b/demo.c
@@ -26,8 +26,13 @@ enum {
 	Height = 402,
 };
 
+static void fail(const char *prefix) {
+	fprintf(stderr, "%s: %s\n", prefix, SDL_GetError());
+	exit(EXIT_FAILURE);
+}
+
 int main(void) {
-	if (SDL_Init(SDL_INIT_VIDEO) < 0) goto fail;
+	if (SDL_Init(SDL_INIT_VIDEO) < 0) fail("SDL_Init");
 	atexit(SDL_Quit);
 
 	SDL_Window *window;
@@ -36,25 +41,27 @@ int main(void) {
 		Width, Height, SDL_WINDOW_ALLOW_HIGHDPI,
 		&window, &render
 	);
-	if (error) goto fail;
+	if (error) fail("SDL_CreateWindowAndRenderer");
 
 	int width, height;
-	if (SDL_GetRendererOutputSize(render, &width, &height) < 0) goto fail;
-	if (width != Width || height != Height) {
-		float scaleX = (float)width / Width;
-		float scaleY = (float)height / Height;
-		if (SDL_RenderSetIntegerScale(render, SDL_TRUE) < 0) goto fail;
-		if (SDL_RenderSetScale(render, scaleX, scaleY) < 0) goto fail;
+	SDL_GetRendererOutputSize(render, &width, &height);
+	if (width > Width || height > Height) {
+		SDL_RenderSetIntegerScale(render, SDL_TRUE);
+		SDL_RenderSetScale(
+			render,
+			(float)width / Width,
+			(float)height / Height
+		);
 	}
 
 	// TODO: Path search/option.
 	SDL_RWops *rw = SDL_RWFromFile("CARDS.DLL", "rb");
-	if (!rw) goto fail;
+	if (!rw) fail("CARDS.DLL");
 
 	struct Cards *cards = Cards_Load(
 		rw, Cards_ColorKey | Cards_AlphaCorners | Cards_BlackBorders
 	);
-	if (!cards) goto fail;
+	if (!cards) fail("Cards_Load");
 	SDL_RWclose(rw);
 
 	SDL_Texture *textures[Cards_Count];
@@ -62,7 +69,7 @@ int main(void) {
 		textures[i] = NULL;
 		if (!cards->surfaces[i]) continue;
 		textures[i] = SDL_CreateTextureFromSurface(render, cards->surfaces[i]);
-		if (!textures[i]) goto fail;
+		if (!textures[i]) fail("SDL_CreateTextureFromSurface");
 	}
 	Cards_Free(cards);
 
@@ -71,7 +78,7 @@ int main(void) {
 
 	for (;;) {
 		SDL_Event event;
-		if (!SDL_WaitEvent(&event)) goto fail;
+		SDL_WaitEvent(&event);
 		if (event.type == SDL_QUIT) break;
 
 		if (event.type == SDL_KEYDOWN) {
@@ -95,17 +102,12 @@ int main(void) {
 			}
 		}
 
-		// TODO: Determine if these checks are really necessary.
-		if (SDL_SetRenderDrawColor(render, 0x00, 0xAA, 0x55, 0xFF) < 0) goto fail;
-		if (SDL_RenderClear(render) < 0) goto fail;
-		if (SDL_RenderCopy(render, textures[card], NULL, &rect) < 0) goto fail;
+		SDL_SetRenderDrawColor(render, 0x00, 0xAA, 0x55, 0xFF);
+		SDL_RenderClear(render);
+		SDL_RenderCopy(render, textures[card], NULL, &rect);
 
 		SDL_RenderPresent(render);
 	}
 
 	return EXIT_SUCCESS;
-
-fail:
-	fprintf(stderr, "%s\n", SDL_GetError());
-	return EXIT_FAILURE;
 }