ソースを参照

Format the whole sauce using clang-format

Streetwalrus Einstein 10 年 前
コミット
e95afa03a7
共有18 個のファイルを変更した484 個の追加390 個の削除を含む
  1. 65 0
      .clang-format
  2. 3 0
      Makefile
  3. 24 24
      include/Camera.h
  4. 14 15
      include/Entity.h
  5. 24 23
      include/Graphics.h
  6. 17 17
      include/Map.h
  7. 40 35
      include/Pixel.h
  8. 11 6
      include/Text.h
  9. 0 1
      include/misc.h
  10. 2 2
      include/timers.h
  11. 18 14
      src/Camera.cpp
  12. 5 5
      src/Entity.cpp
  13. 50 49
      src/Graphics.cpp
  14. 60 56
      src/Map.cpp
  15. 16 11
      src/Pixel.cpp
  16. 21 18
      src/Text.cpp
  17. 96 95
      src/main.cpp
  18. 18 19
      src/timers.c

+ 65 - 0
.clang-format

@@ -0,0 +1,65 @@
+---
+Language:        Cpp
+# BasedOnStyle:  LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: true
+AlignEscapedNewlinesLeft: true
+AlignOperands:   true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AlwaysBreakAfterDefinitionReturnType: false
+AlwaysBreakTemplateDeclarations: false
+AlwaysBreakBeforeMultilineStrings: true
+BreakBeforeBinaryOperators: None
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+BinPackParameters: true
+BinPackArguments: true
+ColumnLimit:     0
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+DerivePointerAlignment: false
+ExperimentalAutoDetectBinPacking: false
+IndentCaseLabels: true
+IndentWrappedFunctionNames: false
+IndentFunctionDeclarationAfterType: false
+MaxEmptyLinesToKeep: 2
+KeepEmptyLinesAtTheStartOfBlocks: false
+NamespaceIndentation: All
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakString: 1000
+PenaltyBreakFirstLessLess: 120
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Right
+SpacesBeforeTrailingComments: 1
+Cpp11BracedListStyle: true
+Standard:        Cpp11
+IndentWidth:     4
+TabWidth:        8
+UseTab:          Never
+BreakBeforeBraces: Allman
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+SpacesInAngles:  false
+SpaceInEmptyParentheses: false
+SpacesInCStyleCastParentheses: false
+SpaceAfterCStyleCast: true
+SpacesInContainerLiterals: true
+SpaceBeforeAssignmentOperators: true
+ContinuationIndentWidth: 4
+CommentPragmas:  '^ IWYU pragma:'
+ForEachMacros:   [ foreach, Q_FOREACH, BOOST_FOREACH ]
+SpaceBeforeParens: ControlStatements
+DisableFormat:   false
+...
+

+ 3 - 0
Makefile

@@ -61,5 +61,8 @@ clean:
 	rm -f $(OBJS)
 	@$(MAKE) -C art/ clean
 
+format:
+	clang-format -i -style=file src/*.c src/*.cpp include/*.h
+
 run: all
 	tilp -ns $(EXE) > /dev/null

+ 24 - 24
include/Camera.h

@@ -3,33 +3,33 @@
 
 namespace WalrusRPG
 {
-	class Camera
-	{
-		protected:
-			// So, how will track camera's position? Top left or center?
-			signed x; // You'll probably want to switch over signed coordonates.
-			signed y;
-			unsigned render_area_width; // What if you only want to display the map on a part of the screen?
-			unsigned render_area_height;
+    class Camera
+    {
+      protected:
+        // So, how will track camera's position? Top left or center?
+        signed x; // You'll probably want to switch over signed coordonates.
+        signed y;
+        unsigned render_area_width; // What if you only want to display the map on a part of the screen?
+        unsigned render_area_height;
 
-			// Do you want to use classes for coordinates and allow them to have vector-based mathematics? With operator overriding that could be doable to have
-			// Vector2 a(3, 2); Vector2 b(1, 2); Vector3 c = a+b;
-			// Vector2 destination;
-			// Vector2 velocity;
-			// Vector2 acceleration;
+        // Do you want to use classes for coordinates and allow them to have vector-based mathematics? With operator overriding that could be doable to have
+        // Vector2 a(3, 2); Vector2 b(1, 2); Vector3 c = a+b;
+        // Vector2 destination;
+        // Vector2 velocity;
+        // Vector2 acceleration;
 
-		public:
-			Camera(signed x, signed y);
-			~Camera();
-			// This doesn't need any render as it's the utility which helps rendering. Unless you want to show debnug things.
-			// void render(float dt) const;
-			void update(unsigned dt);
+      public:
+        Camera(signed x, signed y);
+        ~Camera();
+        // This doesn't need any render as it's the utility which helps rendering. Unless you want to show debnug things.
+        // void render(float dt) const;
+        void update(unsigned dt);
 
-			void set_x(signed x);
-			signed get_x() const;
-			void set_y(signed y);
-			signed get_y() const;
-	};
+        void set_x(signed x);
+        signed get_x() const;
+        void set_y(signed y);
+        signed get_y() const;
+    };
 }
 
 #endif

+ 14 - 15
include/Entity.h

@@ -5,26 +5,25 @@
 
 namespace WalrusRPG
 {
-	/**
+    /**
 	 * Well, for now, this class will be a non abstract for ALPHA PROGRAMMING REASONS.
 	 * Expect this sooner or later to be abstract.
 	 * I don't know at this moment how will we manage the different classes heriting or compositing from this, if we use components or heritance.
 	 */
-	class Entity
-	{
-		protected:
-			unsigned x;
-			unsigned y;
-			unsigned width;
-			unsigned height;
+    class Entity
+    {
+      protected:
+        unsigned x;
+        unsigned y;
+        unsigned width;
+        unsigned height;
 
-		public:
-			Entity();
-			~Entity();
-			void render(Camera &camera, unsigned dt) const;
-			void update(unsigned dt);
-	};
+      public:
+        Entity();
+        ~Entity();
+        void render(Camera &camera, unsigned dt) const;
+        void update(unsigned dt);
+    };
 }
 
 #endif
-

+ 24 - 23
include/Graphics.h

@@ -1,47 +1,48 @@
 #ifndef INCLUDE_GRAPHICS_H
 #define INCLUDE_GRAPHICS_H
 
-namespace WalrusRPG{ namespace Graphics {
-
-	typedef struct Rect Rect_t;
-	struct Rect
-	{
-		int x, y;
-		unsigned w, h;
-	};
-
-	/*
+namespace WalrusRPG
+{
+    namespace Graphics
+    {
+        typedef struct Rect Rect_t;
+        struct Rect
+        {
+            int x, y;
+            unsigned w, h;
+        };
+
+        /*
 	 * 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
 	 */
 
-	void lcd_vsync();
+        void lcd_vsync();
 
 
-	/*
+        /*
 	 * 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
 	 */
 
-	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);
+    }
 }
 
 #endif

+ 17 - 17
include/Map.h

@@ -6,23 +6,23 @@
 
 namespace WalrusRPG
 {
-	class Map
-	{
-		protected:
-			// <Tiles> data;
-			// <Tileset> tileset;
-			unsigned int width;
-			unsigned int height;
-			unsigned *layer0;
-			unsigned *layer1;
-			// TODO?: add a boolean/getter to know if a second layer exist?
-		public:
-			Map(int width, int height, unsigned *layer0, unsigned *layer1);
-			~Map();
-			void render(Camera &camera, unsigned dt) const;
-			void update(unsigned dt);
-			bool entity_collide(Entity &entity) const;
-	};
+    class Map
+    {
+      protected:
+        // <Tiles> data;
+        // <Tileset> tileset;
+        unsigned int width;
+        unsigned int height;
+        unsigned *layer0;
+        unsigned *layer1;
+        // TODO?: add a boolean/getter to know if a second layer exist?
+      public:
+        Map(int width, int height, unsigned *layer0, unsigned *layer1);
+        ~Map();
+        void render(Camera &camera, unsigned dt) const;
+        void update(unsigned dt);
+        bool entity_collide(Entity &entity) const;
+    };
 }
 
 #endif

+ 40 - 35
include/Pixel.h

@@ -3,43 +3,48 @@
 
 #include <cstdint>
 
-namespace WalrusRPG { namespace Graphics {
-
-  /*
+namespace WalrusRPG
+{
+    namespace Graphics
+    {
+        /*
 	 * Pixel structure
 	 */
-	class Pixel {
-    union {
-  		std::uint16_t value;
-      public: // hack to be able to do pixel.r. Clever!
-  		struct {
-  			unsigned r : 5;
-  			unsigned g : 6;
-  			unsigned b : 5;
-  		};
-    };
-
-    public:
-		Pixel(std::uint16_t color);
-
-		Pixel(Pixel &pix);
-
-		Pixel(std::uint8_t red, std::uint8_t green, std::uint8_t blue);
-
-		// Overloading (unsigned) typecast
-		operator std::uint16_t() const;
-
-		Pixel& operator=(unsigned value);
-
-	};
-
-  extern const Pixel Black;
-  extern const Pixel White;
-  extern const Pixel Red;
-  extern const Pixel Green;
-  extern const Pixel Blue;
-
-}}
+        class Pixel
+        {
+            union
+            {
+                std::uint16_t value;
+
+              public: // hack to be able to do pixel.r. Clever!
+                struct
+                {
+                    unsigned r : 5;
+                    unsigned g : 6;
+                    unsigned b : 5;
+                };
+            };
+
+          public:
+            Pixel(std::uint16_t color);
+
+            Pixel(Pixel &pix);
+
+            Pixel(std::uint8_t red, std::uint8_t green, std::uint8_t blue);
+
+            // Overloading (unsigned) typecast
+            operator std::uint16_t() const;
+
+            Pixel &operator=(unsigned value);
+        };
+
+        extern const Pixel Black;
+        extern const Pixel White;
+        extern const Pixel Red;
+        extern const Pixel Green;
+        extern const Pixel Blue;
+    }
+}
 
 
 #endif

+ 11 - 6
include/Text.h

@@ -3,13 +3,18 @@
 
 #include <string>
 
-namespace WalrusRPG { namespace Graphics { namespace Text {
+namespace WalrusRPG
+{
+    namespace Graphics
+    {
+        namespace Text
+        {
+            void print_char(char c, unsigned x, unsigned y);
 
-void print_char(char c, unsigned x, unsigned y);
-
-void print_string(const char *str, unsigned x, unsigned y);
-
-}}}
+            void print_string(const char *str, unsigned x, unsigned y);
+        }
+    }
+}
 
 
 #endif

+ 0 - 1
include/misc.h

@@ -7,4 +7,3 @@
 #define max(a, b) (((a) > (b)) ? (a) : (b))
 
 #endif
-

+ 2 - 2
include/timers.h

@@ -2,8 +2,8 @@
 #define INCLUDE_TIMERS_H
 
 #ifdef __cplusplus
-extern "C"
-{
+extern
+    "C" {
 #endif
 
 // TODO : Move these functions to C++ namespace

+ 18 - 14
src/Camera.cpp

@@ -7,47 +7,51 @@
 
 CAMERA::Camera(signed x, signed y)
 {
-	this->x = x;
-	this->y = y;
+    this->x = x;
+    this->y = y;
 }
 
 CAMERA::~Camera()
 {
-	// TODO if you allocate dynamically members
+    // TODO if you allocate dynamically members
 }
 
 void CAMERA::update(unsigned dt)
 {
-	UNUSED(dt);
-	// TODO update map's data according to elasped time
-	/*
+    UNUSED(dt);
+    // TODO update map's data according to elasped time
+    /*
 		// Need to think aagain on how to go to a target point and/or we need to align the corner OR the center to this point.
 		position += velocity * dt;
 		velocity += acceleration * dt;
 	 */
 
-	if (isKeyPressed(KEY_NSPIRE_5)) y++;
-	if (isKeyPressed(KEY_NSPIRE_8)) y--;
-	if (isKeyPressed(KEY_NSPIRE_6)) x++;
-	if (isKeyPressed(KEY_NSPIRE_4)) x--;
+    if (isKeyPressed(KEY_NSPIRE_5))
+        y++;
+    if (isKeyPressed(KEY_NSPIRE_8))
+        y--;
+    if (isKeyPressed(KEY_NSPIRE_6))
+        x++;
+    if (isKeyPressed(KEY_NSPIRE_4))
+        x--;
 }
 
 void CAMERA::set_x(signed x)
 {
-	this->x = x;
+    this->x = x;
 }
 
 signed CAMERA::get_x() const
 {
-	return this->x;
+    return this->x;
 }
 
 void CAMERA::set_y(signed y)
 {
-	this->y = y;
+    this->y = y;
 }
 
 signed CAMERA::get_y() const
 {
-	return this->y;
+    return this->y;
 }

+ 5 - 5
src/Entity.cpp

@@ -5,19 +5,19 @@
 
 ENTITY::Entity()
 {
-	// TODO
+    // TODO
 }
 
 ENTITY::~Entity()
 {
-	// TODO if you allocate dynamically members
+    // TODO if you allocate dynamically members
 }
 
 void ENTITY::update(unsigned dt)
 {
-	UNUSED(dt);
-	// TODO update map's data according to elasped time
-	/*
+    UNUSED(dt);
+    // TODO update map's data according to elasped time
+    /*
 		// Need to think aagain on how to go to a target point and/or we need to align the corner OR the center to this point.
 		position += velocity * dt;
 		velocity += acceleration * dt;

+ 50 - 49
src/Graphics.cpp

@@ -20,50 +20,50 @@ unsigned short *buffer_front = NULL, *buffer_back = NULL, *buffer_os;
 
 void GRAPHICS::buffer_allocate()
 {
-	buffer_front = (unsigned short *) malloc(BUFFER_SIZE);
-	buffer_back = (unsigned short *) malloc(BUFFER_SIZE);
-
-	if (buffer_front == NULL || buffer_back == NULL)
-	{
-		free(buffer_front);
-		free(buffer_back);
-		exit(0);
-	}
-
-	buffer_os = (unsigned short *) *lcd_base;
-	*lcd_base = (unsigned) buffer_front;
-
-	// Set up the controller in order to use vsync signals
-	lcd_control_bkp = *lcd_control;
-	*lcd_control &= ~(0b11 << 12);
-	*lcd_control |= 0b11 << 12;
+    buffer_front = (unsigned short *) malloc(BUFFER_SIZE);
+    buffer_back = (unsigned short *) malloc(BUFFER_SIZE);
+
+    if (buffer_front == NULL || buffer_back == NULL)
+    {
+        free(buffer_front);
+        free(buffer_back);
+        exit(0);
+    }
+
+    buffer_os = (unsigned short *) *lcd_base;
+    *lcd_base = (unsigned) buffer_front;
+
+    // Set up the controller in order to use vsync signals
+    lcd_control_bkp = *lcd_control;
+    *lcd_control &= ~(0b11 << 12);
+    *lcd_control |= 0b11 << 12;
 }
 
 void GRAPHICS::buffer_free()
 {
-	free(buffer_front);
-	free(buffer_back);
+    free(buffer_front);
+    free(buffer_back);
 
-	*lcd_base = (unsigned) buffer_os;
+    *lcd_base = (unsigned) buffer_os;
 
-	*lcd_control = lcd_control_bkp;
+    *lcd_control = lcd_control_bkp;
 }
 
 void GRAPHICS::buffer_swap()
 {
-	unsigned short *buffer_front_tmp = buffer_front;
-	buffer_front = buffer_back;
-	buffer_back = buffer_front_tmp;
+    unsigned short *buffer_front_tmp = buffer_front;
+    buffer_front = buffer_back;
+    buffer_back = buffer_front_tmp;
 
-	*lcd_base = (unsigned) buffer_front;
+    *lcd_base = (unsigned) buffer_front;
 }
 
 void GRAPHICS::buffer_fill(unsigned color)
 {
-	unsigned *buffer_back_32 = (unsigned *) buffer_back;
-	color |= color << 16; // To avoid stupid overflows
-	for (unsigned i = 0; i < (BUFFER_SIZE / 4); i++)
-		buffer_back_32[i] = color;
+    unsigned *buffer_back_32 = (unsigned *) buffer_back;
+    color |= color << 16; // To avoid stupid overflows
+    for (unsigned i = 0; i < (BUFFER_SIZE / 4); i++)
+        buffer_back_32[i] = color;
 }
 
 
@@ -73,8 +73,9 @@ void GRAPHICS::buffer_fill(unsigned color)
 
 void GRAPHICS::lcd_vsync()
 {
-	*lcd_icr = 1 << 3;
-	while (!(*lcd_ris & (1 << 3)));
+    *lcd_icr = 1 << 3;
+    while (!(*lcd_ris & (1 << 3)))
+        ;
 }
 
 
@@ -84,24 +85,24 @@ void GRAPHICS::lcd_vsync()
 
 void GRAPHICS::draw_pixel(unsigned x, unsigned y, unsigned short color)
 {
-	buffer_back[x + (y * 320)] = color;
+    buffer_back[x + (y * 320)] = color;
 }
 
 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);
-	int h = min(window->h + y, 240);
-
-	for (int j = max(y, 0), l = window->y - min(y, 0); j < h; j++, l++)
-	{
-		for (int i = max(x, 0), k = window->x - min(x, 0); i < w; i++, k++)
-		{
-			color = sprite_pixel_get(sheet, k, l);
-			if (color != sheet[2])
-				draw_pixel(i, j, color);
-		}
-	}
+    unsigned short color;
+    int w = min(window->w + x, 320);
+    int h = min(window->h + y, 240);
+
+    for (int j = max(y, 0), l = window->y - min(y, 0); j < h; j++, l++)
+    {
+        for (int i = max(x, 0), k = window->x - min(x, 0); i < w; i++, k++)
+        {
+            color = sprite_pixel_get(sheet, k, l);
+            if (color != sheet[2])
+                draw_pixel(i, j, color);
+        }
+    }
 }
 
 
@@ -111,8 +112,8 @@ void GRAPHICS::draw_sprite_sheet(const unsigned short *sheet, int x, int y, cons
 
 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];
+    if (x < sprite[0] && y < sprite[1])
+        return sprite[x + (y * sprite[0]) + 3];
+    else
+        return sprite[2];
 }

+ 60 - 56
src/Map.cpp

@@ -8,82 +8,86 @@
 
 MAP::Map(int width, int height, unsigned *layer0, unsigned *layer1)
 {
-	this->width = width;
-	this->height = height;
-	this->layer0 = layer0;
-	this->layer1 = layer1;
+    this->width = width;
+    this->height = height;
+    this->layer0 = layer0;
+    this->layer1 = layer1;
 }
 
 MAP::~Map()
 {
-	// TODO if you allocate dynamically members
+    // TODO if you allocate dynamically members
 }
 
 void MAP::update(unsigned dt)
 {
-	UNUSED(dt);
-	// TODO update map's data according to elasped time
+    UNUSED(dt);
+    // TODO update map's data according to elasped time
 }
 
 void MAP::render(WalrusRPG::Camera &camera, unsigned dt) const
 {
-	UNUSED(dt);
-	// By Eiyeron : I assumed that the camera's position is the top left pixel.
-	// Margins moves the rendered map if we go outside of the bounds (specially on the left or on the top).
-	signed offset_x = camera.get_x() % 24 * -1;
-	signed offset_y = camera.get_y() % 24 * -1;
-	signed start_x = camera.get_x() / 24;
-	signed start_y = camera.get_y() / 24;
-	signed end_x = start_x + 15;
-	signed end_y = start_y + 16;
+    UNUSED(dt);
+    // By Eiyeron : I assumed that the camera's position is the top left pixel.
+    // Margins moves the rendered map if we go outside of the bounds (specially on the left or on the top).
+    signed offset_x = camera.get_x() % 24 * -1;
+    signed offset_y = camera.get_y() % 24 * -1;
+    signed start_x = camera.get_x() / 24;
+    signed start_y = camera.get_y() / 24;
+    signed end_x = start_x + 15;
+    signed end_y = start_y + 16;
 
-	// Bound-checking code. To avoid reading outside of the map.
-	// The offset edition allows the map to be correctly moved to the right to make up for the lack of renderable tiles.
-	if(start_x < 0){
-		offset_x -= start_x*24;
-		start_x = 0;
-		}
+    // Bound-checking code. To avoid reading outside of the map.
+    // The offset edition allows the map to be correctly moved to the right to make up for the lack of renderable tiles.
+    if (start_x < 0)
+    {
+        offset_x -= start_x * 24;
+        start_x = 0;
+    }
 
-	if(start_y < 0) {
-		offset_y -= start_y*24;
-		start_y = 0;
-	}
-	// warning fix. Even if end_x/y is negative, it should be higher than width/height.
-	if((unsigned)end_x > this->width) end_x = this->width;
-	if((unsigned)end_y > this->height) end_y = this->height;
+    if (start_y < 0)
+    {
+        offset_y -= start_y * 24;
+        start_y = 0;
+    }
+    // warning fix. Even if end_x/y is negative, it should be higher than width/height.
+    if ((unsigned) end_x > this->width)
+        end_x = this->width;
+    if ((unsigned) end_y > this->height)
+        end_y = this->height;
 
-	// pre-calculating variables to speed up loop condition check
-	signed delta_x = end_x - start_x;
-	signed delta_y = end_y - start_y;
+    // pre-calculating variables to speed up loop condition check
+    signed delta_x = end_x - start_x;
+    signed delta_y = end_y - start_y;
 
-	// Creating a region clip. Why does it smell like SDL?
-	WalrusRPG::Graphics::Rect_t sprite;
-	sprite.y = 0;
-	sprite.w = 24;
-	sprite.h = 24;
+    // Creating a region clip. Why does it smell like SDL?
+    WalrusRPG::Graphics::Rect_t sprite;
+    sprite.y = 0;
+    sprite.w = 24;
+    sprite.h = 24;
 
-	// rendering part.
-	for (signed j = 0; j < delta_y; j++)
-	{
-		for (signed i = 0; i < delta_x; i++)
-		{
-			unsigned index = (start_x + i) + (start_y + j) * this->width;
-			sprite.x = this->layer0[index] * 24;
-			draw_sprite_sheet(tiles, offset_x + i * 24, offset_y + j * 24, &sprite);
-
-			unsigned tile_over = this->layer1[index];
-			// layer1 : Over-layer
-			if(tile_over != 0) {
-				sprite.x = tile_over * 24;
-				draw_sprite_sheet(tiles, offset_x + i * 24, offset_y + j * 24, &sprite);
-			}
-		}
-	}
+    // rendering part.
+    for (signed j = 0; j < delta_y; j++)
+    {
+        for (signed i = 0; i < delta_x; i++)
+        {
+            unsigned index = (start_x + i) + (start_y + j) * this->width;
+            sprite.x = this->layer0[index] * 24;
+            draw_sprite_sheet(tiles, offset_x + i * 24, offset_y + j * 24, &sprite);
 
+            unsigned tile_over = this->layer1[index];
+            // layer1 : Over-layer
+            if (tile_over != 0)
+            {
+                sprite.x = tile_over * 24;
+                draw_sprite_sheet(tiles, offset_x + i * 24, offset_y + j * 24, &sprite);
+            }
+        }
+    }
 }
 
 bool MAP::entity_collide(Entity &entity) const
 {
-	UNUSED(entity);
-	return false;
+    UNUSED(entity);
+    return false;
 }

+ 16 - 11
src/Pixel.cpp

@@ -2,25 +2,30 @@
 
 #define PIXEL WalrusRPG::Graphics::Pixel
 
-PIXEL::Pixel(std::uint16_t color) : value(color) {
-
+PIXEL::Pixel(std::uint16_t color)
+    : value(color)
+{
 }
 
-PIXEL::Pixel(Pixel &pix) : value((std::uint8_t)pix) {
-
+PIXEL::Pixel(Pixel &pix)
+    : value((std::uint8_t) pix)
+{
 }
 
-PIXEL::Pixel(std::uint8_t red, std::uint8_t green, std::uint8_t blue) : r(red>>3), g(green>>2), b(blue>>3) {
-
+PIXEL::Pixel(std::uint8_t red, std::uint8_t green, std::uint8_t blue)
+    : r(red >> 3), g(green >> 2), b(blue >> 3)
+{
 }
 
-PIXEL::operator std::uint16_t() const {
-  return value;
+PIXEL::operator std::uint16_t() const
+{
+    return value;
 }
 
-PIXEL& PIXEL::operator=(unsigned value) {
-  this->value = value;
-	return *this;
+PIXEL &PIXEL::operator=(unsigned value)
+{
+    this->value = value;
+    return *this;
 }
 
 #define CONST_COLOR(color, r, g, b) const WalrusRPG::Graphics::Pixel WalrusRPG::Graphics::color(r, g, b)

+ 21 - 18
src/Text.cpp

@@ -6,24 +6,27 @@
 #define TEXT WalrusRPG::Graphics::Text
 #define GRAPHICS WalrusRPG::Graphics
 
-void TEXT::print_char(char c, unsigned x, unsigned y) {
-  GRAPHICS::Rect_t rect;
-  rect.w = 8;
-  rect.h = 8;
-  rect.x = (c%16)*8;
-  rect.y = (c/16)*8;
-  draw_sprite_sheet(font, x, y, &rect);
+void TEXT::print_char(char c, unsigned x, unsigned y)
+{
+    GRAPHICS::Rect_t rect;
+    rect.w = 8;
+    rect.h = 8;
+    rect.x = (c % 16) * 8;
+    rect.y = (c / 16) * 8;
+    draw_sprite_sheet(font, x, y, &rect);
 }
 
-void TEXT::print_string(const char *str, unsigned x, unsigned y) {
-  GRAPHICS::Rect_t rect;
-  rect.w = 8;
-  rect.h = 8;
-  for(unsigned index = 0; str[index]; index++) {
-    char c = str[index];
-    rect.x = (c%16)*8;
-    rect.y = (c/16)*8;
-    draw_sprite_sheet(font, x, y, &rect);
-    x +=8;
-  }
+void TEXT::print_string(const char *str, unsigned x, unsigned y)
+{
+    GRAPHICS::Rect_t rect;
+    rect.w = 8;
+    rect.h = 8;
+    for (unsigned index = 0; str[index]; index++)
+    {
+        char c = str[index];
+        rect.x = (c % 16) * 8;
+        rect.y = (c / 16) * 8;
+        draw_sprite_sheet(font, x, y, &rect);
+        x += 8;
+    }
 }

+ 96 - 95
src/main.cpp

@@ -13,103 +13,104 @@ using namespace WalrusRPG::Graphics::Text;
 
 void map_loop(unsigned x, unsigned y, Map &map)
 {
-	timer_mode(0, 0b0000010); // Free-running, no interrupts, divider = 1, 32 bit, wrapping
-	timer_load(0, 0);
-	unsigned loop_time = 546; // 32768Hz/60ups
-	unsigned loop_next = -loop_time;
-
-	unsigned keep_running = 1;
-	Camera camera((signed)x, (signed)y);
-
-	while (keep_running)
-	{
-		if (isKeyPressed(KEY_NSPIRE_ESC)) keep_running = 0;
-
-		camera.update(0);
-
-		// Frameskip
-		if (timer_read(0) > loop_next)
-		{
-			Pixel pix(Green);
-			// TODO?: Preset color macros/consts?
-			buffer_fill(pix);
-			map.render(camera, loop_next);
-			print_string("WalrusRPG test build \001", 0, 0);
-			lcd_vsync();
-			buffer_swap();
-		}
-
-		// Frame limiting
-		while (timer_read(0) > loop_next);
-		loop_next -= loop_time;
-	}
+    timer_mode(0, 0b0000010); // Free-running, no interrupts, divider = 1, 32 bit, wrapping
+    timer_load(0, 0);
+    unsigned loop_time = 546; // 32768Hz/60ups
+    unsigned loop_next = -loop_time;
+
+    unsigned keep_running = 1;
+    Camera camera((signed) x, (signed) y);
+
+    while (keep_running)
+    {
+        if (isKeyPressed(KEY_NSPIRE_ESC))
+            keep_running = 0;
+
+        camera.update(0);
+
+        // Frameskip
+        if (timer_read(0) > loop_next)
+        {
+            Pixel pix(Green);
+            // TODO?: Preset color macros/consts?
+            buffer_fill(pix);
+            map.render(camera, loop_next);
+            print_string(
+                "WalrusRPG test build \001", 0, 0);
+            lcd_vsync();
+            buffer_swap();
+        }
+
+        // Frame limiting
+        while (timer_read(0) > loop_next)
+            ;
+        loop_next -= loop_time;
+    }
 }
 
 int main(int argc, char *argv[])
 {
-	UNUSED(argc);
-	UNUSED(argv);
-
-	buffer_allocate();
-	timer_init(0);
-
-
-	unsigned mapdata0[] =
-	{
-		2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-		2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
-	};
-
-	unsigned mapdata1[] =
-	{
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 6, 0, 0, 4, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-	};
-
-	Map map(15, 21, mapdata0, mapdata1);
-
-
-	map_loop(0, 0, map);
-
-	timer_restore(0);
-	buffer_free();
-	return 0;
+    UNUSED(argc);
+    UNUSED(argv);
+
+    buffer_allocate();
+    timer_init(0);
+
+
+    unsigned mapdata0[] =
+        {
+         2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+         2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
+
+    unsigned mapdata1[] =
+        {
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 6, 0, 0, 4, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+
+    Map map(15, 21, mapdata0, mapdata1);
+
+
+    map_loop(0, 0, map);
+
+    timer_restore(0);
+    buffer_free();
+    return 0;
 }

+ 18 - 19
src/timers.c

@@ -6,42 +6,41 @@ unsigned timer_ctl_bkp[2], timer_load_bkp[2];
 
 void timer_init(unsigned timer)
 {
-	volatile unsigned *timer_ctl = (unsigned *) (TIMER + 0x08 + 0x20 * timer);
-	volatile unsigned *timer_load = (unsigned *) (TIMER + 0x20 * timer);
+    volatile unsigned *timer_ctl = (unsigned *) (TIMER + 0x08 + 0x20 * timer);
+    volatile unsigned *timer_load = (unsigned *) (TIMER + 0x20 * timer);
 
-	timer_ctl_bkp[timer] = *timer_ctl;
-	timer_load_bkp[timer] = *timer_load;
+    timer_ctl_bkp[timer] = *timer_ctl;
+    timer_load_bkp[timer] = *timer_load;
 }
 
 void timer_restore(unsigned timer)
 {
-	volatile unsigned *timer_ctl = (unsigned *) (TIMER + 0x08 + 0x20 * timer);
-	volatile unsigned *timer_load = (unsigned *) (TIMER + 0x20 * timer);
+    volatile unsigned *timer_ctl = (unsigned *) (TIMER + 0x08 + 0x20 * timer);
+    volatile unsigned *timer_load = (unsigned *) (TIMER + 0x20 * timer);
 
-	*timer_ctl &= ~(1 << 7);
-	*timer_ctl = timer_ctl_bkp[timer] & ~(1 << 7);
-	*timer_load = timer_load_bkp[timer];
-	*timer_ctl = timer_ctl_bkp[timer];
+    *timer_ctl &= ~(1 << 7);
+    *timer_ctl = timer_ctl_bkp[timer] & ~(1 << 7);
+    *timer_load = timer_load_bkp[timer];
+    *timer_ctl = timer_ctl_bkp[timer];
 }
 
 void timer_mode(unsigned timer, unsigned mode)
 {
-	volatile unsigned *timer_ctl = (unsigned *) (TIMER + 0x08 + 0x20 * timer);
+    volatile unsigned *timer_ctl = (unsigned *) (TIMER + 0x08 + 0x20 * timer);
 
-	*timer_ctl &= ~(1 << 7);
-	*timer_ctl = mode;
-	*timer_ctl |= (1 << 7);
+    *timer_ctl &= ~(1 << 7);
+    *timer_ctl = mode;
+    *timer_ctl |= (1 << 7);
 }
 
 void timer_load(unsigned timer, unsigned value)
 {
-	volatile unsigned *timer_load = (unsigned *) (TIMER + 0x20 * timer);
-	*timer_load = value;
+    volatile unsigned *timer_load = (unsigned *) (TIMER + 0x20 * timer);
+    *timer_load = value;
 }
 
 unsigned timer_read(unsigned timer)
 {
-	volatile unsigned *timer_value = (unsigned *) (TIMER + 0x04 + 0x20 * timer);
-	return *timer_value;
+    volatile unsigned *timer_value = (unsigned *) (TIMER + 0x04 + 0x20 * timer);
+    return *timer_value;
 }
-