浏览代码

Remove sdl_extra translation unit

rexim 2 年之前
父节点
当前提交
8a8df11641
共有 4 个文件被更改,包括 24 次插入63 次删除
  1. 1 1
      build.sh
  2. 23 14
      src/main.c
  3. 0 26
      src/sdl_extra.c
  4. 0 22
      src/sdl_extra.h

+ 1 - 1
build.sh

@@ -6,7 +6,7 @@ CC="${CXX:-cc}"
 PKGS="sdl2 glew freetype2"
 CFLAGS="-Wall -Wextra -std=c11 -pedantic -ggdb"
 LIBS=-lm
-SRC="src/main.c src/la.c src/editor.c src/sdl_extra.c src/file.c src/gl_extra.c src/free_glyph.c src/simple_renderer.c"
+SRC="src/main.c src/la.c src/editor.c src/file.c src/gl_extra.c src/free_glyph.c src/simple_renderer.c"
 
 if [ `uname` = "Darwin" ]; then
     CFLAGS+=" -framework OpenGL"

+ 23 - 14
src/main.c

@@ -16,7 +16,6 @@
 
 #include "./editor.h"
 #include "./la.h"
-#include "./sdl_extra.h"
 #include "./gl_extra.h"
 #include "./free_glyph.h"
 #include "./simple_renderer.h"
@@ -160,7 +159,7 @@ int main(int argc, char **argv)
     FT_Error error = FT_Init_FreeType(&library);
     if (error) {
         fprintf(stderr, "ERROR: could initialize FreeType2 library\n");
-        exit(1);
+        return 1;
     }
 
     const char *const font_file_path = "./VictorMono-Regular.ttf";
@@ -169,10 +168,10 @@ int main(int argc, char **argv)
     error = FT_New_Face(library, font_file_path, 0, &face);
     if (error == FT_Err_Unknown_File_Format) {
         fprintf(stderr, "ERROR: `%s` has an unknown format\n", font_file_path);
-        exit(1);
+        return 1;
     } else if (error) {
         fprintf(stderr, "ERROR: could not load file `%s`\n", font_file_path);
-        exit(1);
+        return 1;
     }
 
     FT_UInt pixel_size = FREE_GLYPH_FONT_SIZE;
@@ -181,7 +180,7 @@ int main(int argc, char **argv)
     error = FT_Set_Pixel_Sizes(face, 0, pixel_size);
     if (error) {
         fprintf(stderr, "ERROR: could not set pixel size to %u\n", pixel_size);
-        exit(1);
+        return 1;
     }
 
     const char *file_path = NULL;
@@ -198,13 +197,20 @@ int main(int argc, char **argv)
         }
     }
 
-    scc(SDL_Init(SDL_INIT_VIDEO));
+    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
+        fprintf(stderr, "ERROR: Could not initialize SDL: %s\n", SDL_GetError());
+        return 1;
+    }
 
     SDL_Window *window =
-        scp(SDL_CreateWindow("Text Editor",
-                             0, 0,
-                             SCREEN_WIDTH, SCREEN_HEIGHT,
-                             SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL));
+        SDL_CreateWindow("Text Editor",
+                         0, 0,
+                         SCREEN_WIDTH, SCREEN_HEIGHT,
+                         SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
+    if (window == NULL) {
+        fprintf(stderr, "ERROR: Could not create SDL window: %s\n", SDL_GetError());
+        return 1;
+    }
 
     {
         SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
@@ -218,21 +224,24 @@ int main(int argc, char **argv)
         printf("GL version %d.%d\n", major, minor);
     }
 
-    scp(SDL_GL_CreateContext(window));
+    if (SDL_GL_CreateContext(window) == NULL) {
+        fprintf(stderr, "Could not create OpenGL context: %s\n", SDL_GetError());
+        return 1;
+    }
 
     if (GLEW_OK != glewInit()) {
         fprintf(stderr, "Could not initialize GLEW!");
-        exit(1);
+        return 1;
     }
 
     if (!GLEW_ARB_draw_instanced) {
         fprintf(stderr, "ARB_draw_instanced is not supported; game may not work properly!!\n");
-        exit(1);
+        return 1;
     }
 
     if (!GLEW_ARB_instanced_arrays) {
         fprintf(stderr, "ARB_instanced_arrays is not supported; game may not work properly!!\n");
-        exit(1);
+        return 1;
     }
 
     glEnable(GL_BLEND);

+ 0 - 26
src/sdl_extra.c

@@ -1,26 +0,0 @@
-#include "./sdl_extra.h"
-
-void scc(int code)
-{
-    if (code < 0) {
-        fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError());
-        exit(1);
-    }
-}
-
-void *scp(void *ptr)
-{
-    if (ptr == NULL) {
-        fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError());
-        exit(1);
-    }
-
-    return ptr;
-}
-
-Vec2f window_size(SDL_Window *window)
-{
-    int w, h;
-    SDL_GetWindowSize(window, &w, &h);
-    return vec2f((float) w, (float) h);
-}

+ 0 - 22
src/sdl_extra.h

@@ -1,22 +0,0 @@
-#ifndef SDL_EXTRA_H_
-#define SDL_EXTRA_H_
-
-#include <SDL2/SDL.h>
-
-#include "./la.h"
-
-#define UNHEX(color) \
-    ((color) >> (8 * 0)) & 0xFF, \
-    ((color) >> (8 * 1)) & 0xFF, \
-    ((color) >> (8 * 2)) & 0xFF, \
-    ((color) >> (8 * 3)) & 0xFF
-
-// SDL Check Code
-void scc(int code);
-
-// SDL Check Pointer
-void *scp(void *ptr);
-
-Vec2f window_size(SDL_Window *window);
-
-#endif // SDL_EXTRA_H_