shithub: m8c

Download patch

ref: e066ceb5c0b61c0766884f2d9d30db57e22d4bdd
parent: f7ff83338d2636ebfbc2b9ea8964fe5c3ab2aea6
author: Jonne Kokkonen <jonne.kokkonen@gmail.com>
date: Thu Jun 2 19:21:37 EDT 2022

fix cube gfx glitch, add extra device check to prevent unnecessary sdl init

--- a/fx_cube.c
+++ b/fx_cube.c
@@ -5,7 +5,6 @@
 #define target_height 240
 static SDL_Texture *texture_cube;
 static SDL_Texture *texture_text;
-//static SDL_Texture *texture_gradient;
 static SDL_Renderer *fx_renderer;
 static SDL_Color line_color;
 
@@ -12,8 +11,8 @@
 const char *text_m8c = "M8C";
 const char *text_disconnected = "DEVICE DISCONNECTED";
 
-static const float center_x = target_width / 2;
-static const float center_y = target_height / 2;
+static const float center_x = (float)target_width / 2;
+static const float center_y = (float)target_height / 2;
 
 static const float default_nodes[8][3] = {
     {-1, -1, -1}, {-1, -1, 1}, {-1, 1, -1}, {-1, 1, 1},
@@ -64,7 +63,7 @@
       SDL_CreateTexture(fx_renderer, SDL_PIXELFORMAT_ARGB8888,
                         SDL_TEXTUREACCESS_TARGET, target_width, target_height);
 
-  //SDL_Texture *og_target = SDL_GetRenderTarget(fx_renderer);                        
+  SDL_Texture *og_target = SDL_GetRenderTarget(fx_renderer);                        
 
   SDL_SetRenderTarget(fx_renderer, texture_text);
 
@@ -71,21 +70,8 @@
   inprint(fx_renderer, text_disconnected, 168, 230, 0xFFFFFF, 0x000000);
   inprint(fx_renderer, text_m8c, 2, 2, 0xFFFFFF, 0x000000);
 
-  /* Create a texture for making a linear gradient. Scaling settings make the 2
-     pixels into a gradient. This requires OpenGL or Direct3d though. */
-  /* SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1");
-  texture_gradient = SDL_CreateTexture(fx_renderer, SDL_PIXELFORMAT_ARGB8888,
-                                       SDL_TEXTUREACCESS_TARGET, 1, 2);
-  SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
-
-  SDL_SetRenderTarget(fx_renderer, texture_gradient);
-  SDL_RenderClear(fx_renderer);
-  SDL_SetRenderDrawColor(fx_renderer, 0, 0, 0, 200);
-  SDL_RenderDrawPoint(fx_renderer, 0, 1);
-  SDL_SetRenderDrawColor(fx_renderer, 0, 0, 0, SDL_ALPHA_TRANSPARENT);
-  SDL_RenderDrawPoint(fx_renderer, 0, 0);
   SDL_SetRenderTarget(fx_renderer, og_target);
-  */
+
   // Initialize default nodes
   SDL_memcpy(nodes, default_nodes, sizeof(default_nodes));
 
@@ -93,13 +79,11 @@
   rotate_cube(M_PI / 4, SDL_atan(SDL_sqrt(2)));
 
   SDL_SetTextureBlendMode(texture_cube, SDL_BLENDMODE_BLEND);
-  //SDL_SetTextureBlendMode(texture_gradient, SDL_BLENDMODE_BLEND);
   SDL_SetTextureBlendMode(texture_text, SDL_BLENDMODE_BLEND);
 }
 
 void fx_cube_destroy() {
   SDL_DestroyTexture(texture_cube);
-  //SDL_DestroyTexture(texture_gradient);
   SDL_DestroyTexture(texture_text);
 }
 
@@ -126,7 +110,6 @@
     points[points_counter++] = (SDL_Point){p2[0] + center_x, p2[1] + center_y};
   }
 
-  //SDL_RenderCopy(fx_renderer, texture_gradient, NULL, NULL);
   SDL_RenderCopy(fx_renderer, texture_text, NULL, NULL);
   SDL_SetRenderDrawColor(fx_renderer, line_color.r, line_color.g, line_color.b,
                          line_color.a);
--- a/main.c
+++ b/main.c
@@ -58,7 +58,7 @@
   };
 
   static slip_handler_s slip;
-  struct sp_port *port;
+  struct sp_port *port = NULL;
 
   uint8_t prev_input = 0;
   uint8_t prev_note = 0;
@@ -69,6 +69,15 @@
 
   slip_init(&slip, &slip_descriptor);
 
+  // First device detection to avoid SDL init if it isn't necessary
+  if (conf.wait_for_device == 0) {
+    port = init_serial(1);
+    if (port == NULL) {
+      free(serial_buf);
+      return -1;
+    }
+  }
+
   // initialize all SDL systems
   if (initialize_sdl(conf.init_fullscreen, conf.init_use_gpu) == -1)
     run = QUIT;
@@ -79,7 +88,8 @@
 
   // main loop begin
   do {
-    port = init_serial(1);
+    if (port == NULL)
+      port = init_serial(1);
     if (port != NULL) {
       int result;
       result = enable_and_reset_display(port);
@@ -138,6 +148,7 @@
         close_game_controllers();
         close_renderer();
         SDL_Quit();
+        free(serial_buf);
         return -1;
       }
     }
--