Browse Source

There were still some uint used here and there.
Also replace the swap by a static inline function as it may be used later.

Godzil 3 years ago
parent
commit
b11a60e687
2 changed files with 21 additions and 12 deletions
  1. 12 10
      source/display.c
  2. 9 2
      source/include/display.h

+ 12 - 10
source/display.c

@@ -23,8 +23,8 @@ SDL_Window *window = NULL;
 SDL_Renderer *renderer = NULL;
 uint32_t *frameBuffer = NULL;
 SDL_Texture *frameBufferTexture = NULL;
-int32_t windowWidth = 800;
-int32_t windowHeight = 600;
+int32_t windowWidth = 1024;
+int32_t windowHeight = 768;
 
 /***********************************************************************************************************************
  * Functions
@@ -102,7 +102,7 @@ void renderFrameBuffer()
     SDL_RenderCopy(renderer, frameBufferTexture, NULL, NULL);
 }
 
-void drawPixel(uint32_t x, uint32_t y, uint32_t colour)
+void drawPixel(int32_t x, int32_t y, uint32_t colour)
 {
     if ((x >= 0) && (x < windowWidth) && (y >= 0) && (y < windowHeight))
     {
@@ -112,8 +112,9 @@ void drawPixel(uint32_t x, uint32_t y, uint32_t colour)
 
 void drawVLine(int32_t x, int32_t y0, int32_t y1, uint32_t colour)
 {
-    uint32_t i;
-    if (y0 > y1) { i = y1; y1 = y0; y0 = i; }
+    int32_t i;
+    if (y0 > y1) {
+        intSwap(&y0, &y1); }
 
     if ( ((x < 0) || (x > windowWidth)) ||
          ((y0 < 0) && (y1 < 0)) ||
@@ -135,8 +136,9 @@ void drawVLine(int32_t x, int32_t y0, int32_t y1, uint32_t colour)
 
 void drawHLine(int32_t x0, int32_t y, int32_t x1, uint32_t colour)
 {
-    uint32_t i;
-    if (x0 > x1) { i = x1; x1 = x0; x0 = i; }
+    int32_t i;
+    if (x0 > x1) {
+        intSwap(&x0, &x1); }
 
     if ( ((y < 0) || (y > windowHeight)) ||
          ((x0 < 0) && (x1 < 0)) ||
@@ -158,7 +160,7 @@ void drawHLine(int32_t x0, int32_t y, int32_t x1, uint32_t colour)
 
 void clearFrameBuffer(int32_t colour)
 {
-    uint32_t x, y;
+    int32_t x, y;
     for (y = 0 ; y < windowHeight ; y++)
     {
         for (x = 0 ; x < windowWidth ; x++)
@@ -183,9 +185,9 @@ void drawGrid(int spacing, uint32_t colour)
     }
 }
 
-void drawRectangle(int32_t x, int32_t y, int32_t w, uint32_t h, uint32_t colour)
+void drawRectangle(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t colour)
 {
-    uint32_t j;
+    int32_t j;
 
     for (j = 0 ; j < h ; j++)
     {

+ 9 - 2
source/include/display.h

@@ -39,14 +39,21 @@ void destroyWindow();
 void renderFrameBuffer();
 
 /* --- Drawing functions --- */
-void drawPixel(uint32_t x, uint32_t y, uint32_t colour);
+void drawPixel(int32_t x, int32_t y, uint32_t colour);
 
 void clearFrameBuffer(int32_t colour);
 void drawGrid(int spacing, uint32_t colour);
-void drawRectangle(int32_t x, int32_t y, int32_t w, uint32_t h, uint32_t colour);
+void drawRectangle(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t colour);
 void drawVLine(int32_t x, int32_t y0, int32_t y1, uint32_t colour);
 void drawHLine(int32_t x0, int32_t y, int32_t x1, uint32_t colour);
 void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t colour);
 void drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t colour);
 
+static inline void intSwap(int *a, int *b)
+{
+    int tmp = *a;
+    *a = *b;
+    *b = tmp;
+}
+
 #endif /* THREEDENGINE_SOURCE_INCLUDE_DISPLAY_H */