Selaa lähdekoodia

Tried to put Graphics into a unique namepsace. Don't know if that compiles.

Florian DORMONT 10 vuotta sitten
vanhempi
commit
d779e5b8da
2 muutettua tiedostoa jossa 40 lisäystä ja 43 poistoa
  1. 29 33
      include/graphics.h
  2. 11 10
      src/Graphics.cpp

+ 29 - 33
include/graphics.h

@@ -1,51 +1,47 @@
 #ifndef INCLUDE_GRAPHICS_H
 #define INCLUDE_GRAPHICS_H
 
-#ifdef __cplusplus
-extern "C"
-{
-#endif
+namespace WalrusRPG{ namespace Graphics {
 
-typedef struct Rect Rect_t;
-struct Rect
-{
-	int x, y;
-	unsigned w, h;
-};
+	typedef struct Rect Rect_t;
+	struct Rect
+	{
+		int x, y;
+		unsigned w, h;
+	};
 
-/*
- * Buffer management
- */
+	/*
+	 * Buffer management
+	 */
 
-void buffer_allocate();
-void buffer_free();
-void buffer_swap();
-void buffer_fill(unsigned color);
+	void buffer_allocate();
+	void buffer_free();
+	void buffer_swap();
+	void buffer_fill(unsigned color);
 
 
-/*
- * Misc LCD functions
- */
+	/*
+	 * Misc LCD functions
+	 */
 
-void lcd_vsync();
+	void lcd_vsync();
 
 
-/*
- * Drawing
- */
+	/*
+	 * Drawing
+	 */
 
-void draw_pixel(unsigned x, unsigned y, unsigned short color);
-void draw_sprite_sheet(const unsigned short *sheet, int x, int y, const Rect_t *window);
+	void draw_pixel(unsigned x, unsigned y, unsigned short color);
+	void draw_sprite_sheet(const unsigned short *sheet, int x, int y, const Rect_t *window);
 
 
-/*
- * Sprite manipulation
- */
+	/*
+	 * Sprite manipulation
+	 */
 
-unsigned short sprite_pixel_get(const unsigned short *sprite, unsigned x, unsigned y);
+	unsigned short sprite_pixel_get(const unsigned short *sprite, unsigned x, unsigned y);
 
-#ifdef __cplusplus
 }
-#endif
-#endif
+}
 
+#endif

+ 11 - 10
src/graphics.c → src/Graphics.cpp

@@ -1,7 +1,9 @@
 #include <os.h>
-#include <graphics.h>
+#include <Graphics.h>
 #include <misc.h>
 
+#define GRAPHICS WalrusRPG::Graphics
+
 #define LCD_CONTROLLER 0xC0000000
 volatile unsigned *lcd_base = (unsigned *) (LCD_CONTROLLER + 0x10);
 volatile unsigned *lcd_ris = (unsigned *) (LCD_CONTROLLER + 0x20);
@@ -16,7 +18,7 @@ unsigned short *buffer_front = NULL, *buffer_back = NULL, *buffer_os;
  * Buffer management
  */
 
-void buffer_allocate()
+void GRAPHICS::buffer_allocate()
 {
 	buffer_front = (unsigned short *) malloc(BUFFER_SIZE);
 	buffer_back = (unsigned short *) malloc(BUFFER_SIZE);
@@ -37,7 +39,7 @@ void buffer_allocate()
 	*lcd_control |= 0b11 << 12;
 }
 
-void buffer_free()
+void GRAPHICS::buffer_free()
 {
 	free(buffer_front);
 	free(buffer_back);
@@ -47,7 +49,7 @@ void buffer_free()
 	*lcd_control = lcd_control_bkp;
 }
 
-void buffer_swap()
+void GRAPHICS::buffer_swap()
 {
 	unsigned short *buffer_front_tmp = buffer_front;
 	buffer_front = buffer_back;
@@ -56,7 +58,7 @@ void buffer_swap()
 	*lcd_base = (unsigned) buffer_front;
 }
 
-void buffer_fill(unsigned color)
+void GRAPHICS::buffer_fill(unsigned color)
 {
 	unsigned *buffer_back_32 = (unsigned *) buffer_back;
 	color += color << 16;
@@ -69,7 +71,7 @@ void buffer_fill(unsigned color)
  * Misc LCD functions
  */
 
-void lcd_vsync()
+void GRAPHICS::lcd_vsync()
 {
 	*lcd_icr = 1 << 3;
 	while (!(*lcd_ris & (1 << 3)));
@@ -80,12 +82,12 @@ void lcd_vsync()
  * Drawing
  */
 
-void draw_pixel(unsigned x, unsigned y, unsigned short color)
+void GRAPHICS::draw_pixel(unsigned x, unsigned y, unsigned short color)
 {
 	buffer_back[x + (y * 320)] = color;
 }
 
-void draw_sprite_sheet(const unsigned short *sheet, int x, int y, const Rect_t *window)
+void GRAPHICS::draw_sprite_sheet(const unsigned short *sheet, int x, int y, const GRAPHICS::Rect_t *window)
 {
 	unsigned short color;
 	int w = min(window->w + x, 320);
@@ -107,11 +109,10 @@ void draw_sprite_sheet(const unsigned short *sheet, int x, int y, const Rect_t *
  * Sprite manipulation
  */
 
-unsigned short sprite_pixel_get(const unsigned short *sprite, unsigned x, unsigned y)
+unsigned short GRAPHICS::sprite_pixel_get(const unsigned short *sprite, unsigned x, unsigned y)
 {
 	if (x < sprite[0] && y < sprite[1])
 		return sprite[x + (y * sprite[0]) + 3];
 	else
 		return sprite[2];
 }
-