瀏覽代碼

Cleaned namespace callings/prefixing

Eiyeron Fulmincendii 9 年之前
父節點
當前提交
5510a58fd8

+ 3 - 5
platform/nspire/Graphics.cpp

@@ -1,13 +1,11 @@
+#include <stdio.h>
 #include "Graphics.h"
 #include "CXfb.h"
-#include "stdio.h"
 #include "utility/misc.h"
 #include "utility/minmax.h"
 
+using namespace WalrusRPG; /*::Graphics*/
 using namespace Nspire;
-using namespace WalrusRPG;
-using WalrusRPG::Graphics::Texture;
-using WalrusRPG::Graphics::Pixel;
 using WalrusRPG::Utils::Rect;
 
 void Graphics::init()
@@ -172,4 +170,4 @@ void Graphics::put_rectangle(const Rect &rect, const Pixel &color)
             CXfb::draw_pixel(x, y, color.value);
         }
     }
-}
+}

+ 7 - 8
platform/sfml/Graphics.cpp

@@ -4,18 +4,18 @@
 #include "utility/misc.h"
 #include "utility/minmax.h"
 
-using namespace WalrusRPG;
-using WalrusRPG::Graphics::Texture;
-using WalrusRPG::Graphics::Pixel;
+using namespace WalrusRPG; /*::Graphics*/
 using WalrusRPG::Utils::Rect;
 
 sf::RenderWindow window;
 sf::View view;
 sf::RenderTexture buffer;
 
+
 void Graphics::init()
 {
-    // window.create(sf::VideoMode::getDesktopMode(), "WalrusRPG", sf::Style::Fullscreen);
+    // window.create(sf::VideoMode::getDesktopMode(), "WalrusRPG",
+    // sf::Style::Fullscreen);
     window.create(sf::VideoMode(640, 480), "WalrusRPG");
     window.setFramerateLimit(60);
     view = sf::View(window.getDefaultView());
@@ -53,8 +53,7 @@ void Graphics::frame_end()
     window.display();
 }
 
-void Graphics::put_sprite(const WalrusRPG::Graphics::Texture &sheet, int x, int y,
-                          const Rect &window)
+void Graphics::put_sprite(const Texture &sheet, int x, int y, const Rect &window)
 {
     sf::Sprite sprite;
     sprite.setTexture(sheet.data);
@@ -63,8 +62,8 @@ void Graphics::put_sprite(const WalrusRPG::Graphics::Texture &sheet, int x, int
     buffer.draw(sprite);
 }
 
-void Graphics::put_sprite_tint(const WalrusRPG::Graphics::Texture &sheet, int x, int y,
-                               const Rect &window, const Pixel &color)
+void Graphics::put_sprite_tint(const Texture &sheet, int x, int y, const Rect &window,
+                               const Pixel &color)
 {
     sf::Sprite sprite;
     sprite.setTexture(sheet.data);

+ 57 - 63
src/engine/StateMachine.cpp

@@ -6,6 +6,7 @@
 #include "version.h"
 #include "input/Input.h"
 
+using namespace WalrusRPG; /*::StateMachine*/
 using namespace WalrusRPG::Graphics;
 using namespace WalrusRPG::Timing;
 using WalrusRPG::Input::Key;
@@ -52,82 +53,75 @@ namespace
         draw_button(48, 44, key_get_state(Key::K_B));
         draw_button(56, 36, key_get_state(Key::K_A));
     }
-    
-} /* namespace */
-
-namespace WalrusRPG{namespace StateMachine
-{
 
     static tinystl::vector<WalrusRPG::States::State *> stack;
 
-    void init()
-    {
+} /* namespace */
 
-    }
+void StateMachine::init()
+{
+}
 
-    void deinit()
-    {
-        stack.clear();
-    }
+void StateMachine::deinit()
+{
+    stack.clear();
+}
 
-    void push(State *state)
-    {
-        stack.push_back(state);
-    }
+void StateMachine::push(State *state)
+{
+    stack.push_back(state);
+}
 
-    void pop()
-    {
-        delete stack.back();
-        stack.pop_back();
-    }
+void StateMachine::pop()
+{
+    delete stack.back();
+    stack.pop_back();
+}
+
+void StateMachine::run()
+{
+    const unsigned loop_time = TIMER_FREQ / 60;
+    unsigned loop_next = loop_time;
+    unsigned last_update = 0, update_stamp, update_time;
+    unsigned last_frame = 0, frame_stamp, frame_time;
 
-    void run()
+    while (!stack.empty())
     {
-        const unsigned loop_time = TIMER_FREQ / 60;
-        unsigned loop_next = loop_time;
-        unsigned last_update = 0, update_stamp, update_time;
-        unsigned last_frame = 0, frame_stamp, frame_time;
+        update_stamp = Timing::gettime();
+        update_time = update_stamp - last_update;
+        Input::key_poll();
+        stack.back()->update(100 * update_time / TIMER_FREQ);
+        last_update = update_stamp;
 
-        while (!stack.empty())
+        if (Timing::gettime() < loop_next)
         {
-            update_stamp = Timing::gettime();
-            update_time = update_stamp - last_update;
-            Input::key_poll();
-            stack.back()->update(100 * update_time / TIMER_FREQ);
-            last_update = update_stamp;
-
-            if (Timing::gettime() < loop_next)
+            frame_stamp = Timing::gettime();
+            frame_time = frame_stamp - last_frame;
+            Graphics::frame_begin();
+            stack.back()->render(100 * frame_time / TIMER_FREQ);
+            last_frame = frame_stamp;
+
+            // Text::print_format(0, 0, "WalrusRPG test build %s", git_version);
+            if (frame_time != 0 && update_time != 0)
             {
-                frame_stamp = Timing::gettime();
-                frame_time = frame_stamp - last_frame;
-                Graphics::frame_begin();
-                stack.back()->render(100 * frame_time / TIMER_FREQ);
-                last_frame = frame_stamp;
-
-                // Text::print_format(0, 0, "WalrusRPG test build %s", git_version);
-                if (frame_time != 0 && update_time != 0)
-                {
-                    Text::print_format(0, 240 - 8, "%ufps, %uups", TIMER_FREQ / frame_time,
-                                       TIMER_FREQ / update_time);
-                }
-                // draw_buttons();
-                Graphics::frame_end();
+                Text::print_format(0, 240 - 8, "%ufps, %uups", TIMER_FREQ / frame_time,
+                                   TIMER_FREQ / update_time);
             }
-
-            if (Input::key_pressed(Key::K_SELECT))
-            {
-                while (Input::key_down(Key::K_SELECT))
-                    Input::key_poll();
-                StateMachine::pop();
-            }
-
-    #ifdef ACTIVE_WAIT
-            while (Timing::gettime() < loop_next)
-                ;
-    #endif
-            loop_next += loop_time;
+            // draw_buttons();
+            Graphics::frame_end();
         }
-    }
-}} /* namespace StateMachine */
 
+        if (Input::key_pressed(Key::K_SELECT))
+        {
+            while (Input::key_down(Key::K_SELECT))
+                Input::key_poll();
+            StateMachine::pop();
+        }
 
+#ifdef ACTIVE_WAIT
+        while (Timing::gettime() < loop_next)
+            ;
+#endif
+        loop_next += loop_time;
+    }
+}

+ 7 - 7
src/input/Input.cpp

@@ -2,7 +2,7 @@
 #include "Quirks.h"
 #include "platform.h"
 
-#define INPUT WalrusRPG::Input
+using namespace WalrusRPG; /*::Input*/
 using WalrusRPG::Input::Key;
 using WalrusRPG::Input::KeyState;
 
@@ -44,7 +44,7 @@ static InputMap key_map[] = {
 };
 #endif
 
-KeyState INPUT::key_get_state(Key key)
+KeyState Input::key_get_state(Key key)
 {
     // "Just" pressed/released before held/inactive to let these events through
     if (key_pressed(key))
@@ -60,7 +60,7 @@ KeyState INPUT::key_get_state(Key key)
     return KS_RELEASED;
 }
 
-void INPUT::key_poll()
+void Input::key_poll()
 {
     for (unsigned i = 0; i < K_SIZE; i++)
     {
@@ -69,19 +69,19 @@ void INPUT::key_poll()
     }
 }
 
-bool INPUT::key_pressed(Key key)
+bool Input::key_pressed(Key key)
 {
     return !key_states[key].previous && key_states[key].current;
 }
-bool INPUT::key_released(Key key)
+bool Input::key_released(Key key)
 {
     return key_states[key].previous && !key_states[key].current;
 }
-bool INPUT::key_down(Key key)
+bool Input::key_down(Key key)
 {
     return key_states[key].current;
 }
-bool INPUT::key_up(Key key)
+bool Input::key_up(Key key)
 {
     return !key_states[key].current;
 }

+ 5 - 5
src/map/Entity.cpp

@@ -2,21 +2,21 @@
 #include "utility/misc.h"
 #include "utility/Rect.h"
 
-#define ENTITY WalrusRPG::Entity
+using WalrusRPG::Entity;
 using namespace WalrusRPG::Utils;
 
-ENTITY::Entity(int x, int y, unsigned w, unsigned h, WalrusRPG::Renderer *tset,
+Entity::Entity(int x, int y, unsigned w, unsigned h, WalrusRPG::Renderer *tset,
                unsigned sprite_id)
     : coords(x, y, w, h), tset(tset), sprite_id(sprite_id)
 {
 }
 
-ENTITY::~Entity()
+Entity::~Entity()
 {
     // TODO if you allocate dynamically members
 }
 
-void ENTITY::render(Camera &camera, unsigned dt) const
+void Entity::render(Camera &camera, unsigned dt) const
 {
     UNUSED(dt);
 
@@ -29,7 +29,7 @@ void ENTITY::render(Camera &camera, unsigned dt) const
     }
 }
 
-void ENTITY::update(unsigned dt)
+void Entity::update(unsigned dt)
 {
     UNUSED(dt);
     // TODO update map's data according to elasped time

+ 9 - 9
src/map/Map.cpp

@@ -5,14 +5,14 @@
 #include "utility/Rect.h"
 #include "utility/misc.h"
 
-#define MAP WalrusRPG::Map
+using WalrusRPG::Map;
 using namespace WalrusRPG;
 using namespace WalrusRPG::Utils;
 using WalrusRPG::Graphics::Texture;
 
 // Graphics::Texture tex_overworld((char *) overworld);
 
-MAP::Map(int width, int height, uint16_t *layer0, uint16_t *layer1, Texture &tex)
+Map::Map(int width, int height, uint16_t *layer0, uint16_t *layer1, Texture &tex)
     : anim(), tex(tex)
 {
     this->renderer = new TileRenderer(tex, 16, 16);
@@ -22,18 +22,18 @@ MAP::Map(int width, int height, uint16_t *layer0, uint16_t *layer1, Texture &tex
     this->layer1 = layer1;
 }
 
-MAP::~Map()
+Map::~Map()
 {
     delete this->renderer;
 }
 
-void MAP::update(unsigned dt)
+void Map::update(unsigned dt)
 {
     // TODO update map's data according to elasped time
     UNUSED(dt);
 }
 
-void MAP::render(WalrusRPG::Camera &camera, unsigned dt)
+void Map::render(WalrusRPG::Camera &camera, unsigned dt)
 {
     anim.update(dt);
     signed t_width = renderer->get_tile_width();
@@ -79,24 +79,24 @@ void MAP::render(WalrusRPG::Camera &camera, unsigned dt)
     }
 }
 
-bool MAP::is_tile_solid(int x, int y) const
+bool Map::is_tile_solid(int x, int y) const
 {
     if (x >= width || y >= height)
         return true;
     return this->layer0[y * width + x] != 0;
 }
 
-bool MAP::is_pixel_solid(int x, int y) const
+bool Map::is_pixel_solid(int x, int y) const
 {
     return is_tile_solid(x / renderer->get_tile_width(), y / renderer->get_tile_height());
 }
 
-int MAP::get_width() const
+int Map::get_width() const
 {
     return this->width;
 }
 
-int MAP::get_height() const
+int Map::get_height() const
 {
     return this->width;
 }

+ 4 - 5
src/map/StateMap.cpp

@@ -2,8 +2,7 @@
 #include "Graphics.h"
 #include "render/Text.h"
 
-#define STATEMAP WalrusRPG::States::StateMap
-
+using WalrusRPG::States::StateMap;
 using namespace WalrusRPG;
 using namespace WalrusRPG::Graphics;
 
@@ -20,16 +19,16 @@ namespace
     }
 }
 
-STATEMAP::StateMap(int x, int y, Map &map) : camera(x, y), map(map)
+StateMap::StateMap(int x, int y, Map &map) : camera(x, y), map(map)
 {
 }
 
-void STATEMAP::update(unsigned dt)
+void StateMap::update(unsigned dt)
 {
     camera.update(dt);
 }
 
-void STATEMAP::render(unsigned dt)
+void StateMap::render(unsigned dt)
 {
     map.render(camera, dt);
 

+ 5 - 6
src/render/Animator.cpp

@@ -1,7 +1,6 @@
 #include "Animator.h"
 
-#define ANIMATOR WalrusRPG::Animator
-
+using WalrusRPG::Animator;
 using namespace WalrusRPG;
 
 namespace
@@ -43,25 +42,25 @@ namespace
     }
 }
 
-ANIMATOR::Animator()
+Animator::Animator()
 {
     elapsed_time = 0;
 }
 
-void ANIMATOR::add_animation(int index, Animation anim)
+void Animator::add_animation(int index, Animation anim)
 {
     animations[index] = anim;
     animations[index].duration = get_animation_duration(anim);
 }
 
-unsigned ANIMATOR::get_animation_frame(unsigned id)
+unsigned Animator::get_animation_frame(unsigned id)
 {
     if (animations[id].stripe.empty())
         return id;
     return find_frame(animations[id], elapsed_time);
 }
 
-void ANIMATOR::update(unsigned dt)
+void Animator::update(unsigned dt)
 {
     elapsed_time += dt;
 }

+ 9 - 10
src/render/Camera.cpp

@@ -2,12 +2,11 @@
 #include "utility/misc.h"
 #include "input/Input.h"
 
-#define CAMERA WalrusRPG::Camera
-
+using WalrusRPG::Camera;
 using namespace WalrusRPG;
 using WalrusRPG::Input::Key;
 
-CAMERA::Camera(signed x, signed y)
+Camera::Camera(signed x, signed y)
 {
     this->x = x;
     this->y = y;
@@ -15,12 +14,12 @@ CAMERA::Camera(signed x, signed y)
     render_area_height = 240;
 }
 
-CAMERA::~Camera()
+Camera::~Camera()
 {
     // TODO if you allocate dynamically members
 }
 
-void CAMERA::update(unsigned dt)
+void Camera::update(unsigned dt)
 {
     UNUSED(dt);
     // TODO update map's data according to elasped time
@@ -41,27 +40,27 @@ void CAMERA::update(unsigned dt)
         x--;
 }
 
-void CAMERA::set_x(signed x)
+void Camera::set_x(signed x)
 {
     this->x = x;
 }
 
-signed CAMERA::get_x() const
+signed Camera::get_x() const
 {
     return this->x;
 }
 
-void CAMERA::set_y(signed y)
+void Camera::set_y(signed y)
 {
     this->y = y;
 }
 
-signed CAMERA::get_y() const
+signed Camera::get_y() const
 {
     return this->y;
 }
 
-bool CAMERA::is_visible(const WalrusRPG::Utils::Rect &object) const
+bool Camera::is_visible(const WalrusRPG::Utils::Rect &object) const
 {
     if ((in_range(object.x, x, x + (signed) render_area_width) ||
          in_range(object.x + (signed) object.width - 1, x,

+ 8 - 8
src/render/Pixel.cpp

@@ -1,34 +1,34 @@
 #include "Pixel.h"
 
-#define PIXEL WalrusRPG::Graphics::Pixel
+using WalrusRPG::Graphics::Pixel;
 
-PIXEL::Pixel(std::uint16_t color) : value(color)
+Pixel::Pixel(std::uint16_t color) : value(color)
 {
 }
 
-PIXEL::Pixel(Pixel &pix) : value(pix.value)
+Pixel::Pixel(Pixel &pix) : value(pix.value)
 {
 }
 
-PIXEL::Pixel(std::uint8_t red, std::uint8_t green, std::uint8_t blue)
+Pixel::Pixel(std::uint8_t red, std::uint8_t green, std::uint8_t blue)
     : b(blue >> 3), g(green >> 2), r(red >> 3)
 {
 }
 
-PIXEL::operator std::uint16_t() const
+Pixel::operator std::uint16_t() const
 {
     return value;
 }
 
-PIXEL &PIXEL::operator=(unsigned value)
+Pixel &Pixel::operator=(unsigned value)
 {
     this->value = value;
     return *this;
 }
 
-bool PIXEL::operator==(const PIXEL& col)
+bool Pixel::operator==(const Pixel &col)
 {
-	return value == col.value;
+    return value == col.value;
 }
 
 #define CONST_COLOR(color, r, g, b) \

+ 2 - 2
src/render/Pixel.h

@@ -36,8 +36,8 @@ namespace WalrusRPG
             operator std::uint16_t() const;
 
             Pixel &operator=(unsigned value);
-           
-            bool operator==(const Pixel&col);
+
+            bool operator==(const Pixel &col);
         };
 
         extern const Pixel Black;

+ 5 - 5
src/render/SpriteRenderer.cpp

@@ -3,27 +3,27 @@
 #include "Graphics.h"
 #include "render/Pixel.h"
 
-#define SPRITERENDERER WalrusRPG::SpriteRenderer
+using WalrusRPG::SpriteRenderer;
 using namespace WalrusRPG;
 using namespace WalrusRPG::Utils;
 using WalrusRPG::Graphics::Pixel;
 
-SPRITERENDERER::SpriteRenderer(WalrusRPG::Graphics::Texture _tilesheet)
+SpriteRenderer::SpriteRenderer(WalrusRPG::Graphics::Texture _tilesheet)
     : tilesheet(_tilesheet)
 {
 }
 
-void SPRITERENDERER::add_sprite(unsigned id, WalrusRPG::Utils::Rect rect)
+void SpriteRenderer::add_sprite(unsigned id, WalrusRPG::Utils::Rect rect)
 {
     sprites[id] = rect;
 }
 
-void SPRITERENDERER::render(const unsigned id, const Rect &rect)
+void SpriteRenderer::render(const unsigned id, const Rect &rect)
 {
     Graphics::put_sprite(tilesheet, rect.x, rect.y, sprites[id]);
 }
 
-void SPRITERENDERER::render(const unsigned id, const Rect &rect, const Pixel &tint)
+void SpriteRenderer::render(const unsigned id, const Rect &rect, const Pixel &tint)
 {
     Graphics::put_sprite_tint(tilesheet, rect.x, rect.y, sprites[id], tint);
 }

+ 8 - 8
src/render/Text.cpp

@@ -4,18 +4,18 @@
 #include "sprites.h"
 #include "Graphics.h"
 
-#define TEXT WalrusRPG::Graphics::Text
+using namespace WalrusRPG::Graphics; /*Text*/
 using namespace WalrusRPG::Graphics;
 using namespace WalrusRPG::Utils;
 
 Texture tex_font((char *) font);
 
-void TEXT::print_char(char c, unsigned x, unsigned y)
+void Text::print_char(char c, unsigned x, unsigned y)
 {
     put_sprite(tex_font, x, y, Rect((c % 16) * 8, (c / 16) * 8, 8, 8));
 }
 
-void TEXT::print_string(const char *str, unsigned x, unsigned y)
+void Text::print_string(const char *str, unsigned x, unsigned y)
 {
     Rect rect;
     rect.width = 8;
@@ -30,12 +30,12 @@ void TEXT::print_string(const char *str, unsigned x, unsigned y)
     }
 }
 
-void TEXT::print_string(const std::string &str, unsigned x, unsigned y)
+void Text::print_string(const std::string &str, unsigned x, unsigned y)
 {
-    TEXT::print_string(str.c_str(), x, y);
+    Text::print_string(str.c_str(), x, y);
 }
 
-void TEXT::print_format(unsigned x, unsigned y, const char *format, ...)
+void Text::print_format(unsigned x, unsigned y, const char *format, ...)
 {
     char buffer[256] = "";
     va_list args;
@@ -44,7 +44,7 @@ void TEXT::print_format(unsigned x, unsigned y, const char *format, ...)
     print_string(buffer, x, y);
 }
 
-void TEXT::print_format(unsigned x, unsigned y, const std::string &format, ...)
+void Text::print_format(unsigned x, unsigned y, const std::string &format, ...)
 {
-    TEXT::print_format(x, y, format.c_str());
+    Text::print_format(x, y, format.c_str());
 }

+ 6 - 6
src/render/TileRenderer.cpp

@@ -1,17 +1,17 @@
 #include "TileRenderer.h"
 #include "Graphics.h"
 
-#define TILERENDERER WalrusRPG::TileRenderer
+using WalrusRPG::TileRenderer;
 using namespace WalrusRPG;
 using namespace WalrusRPG::Utils;
 
-TILERENDERER::TileRenderer(WalrusRPG::Graphics::Texture &_tilesheet, unsigned tile_width,
+TileRenderer::TileRenderer(WalrusRPG::Graphics::Texture &_tilesheet, unsigned tile_width,
                            unsigned tile_height)
     : tilesheet(_tilesheet), tile_width(tile_width), tile_height(tile_height)
 {
 }
 
-void TILERENDERER::render(const unsigned id, const Rect &rect)
+void TileRenderer::render(const unsigned id, const Rect &rect)
 {
     unsigned num_tiles_x = tilesheet.get_dimensions().width / tile_width;
     // unsigned num_tiles_y = sheet_height / tile_height;
@@ -20,17 +20,17 @@ void TILERENDERER::render(const unsigned id, const Rect &rect)
                               tile_height * (id / num_tiles_x), tile_width, tile_height));
 }
 
-int TILERENDERER::get_tile_width() const
+int TileRenderer::get_tile_width() const
 {
     return tile_width;
 }
-int TILERENDERER::get_tile_height() const
+int TileRenderer::get_tile_height() const
 {
     return tile_height;
 }
 
 
-TILERENDERER::~TileRenderer()
+TileRenderer::~TileRenderer()
 {
     // Nothing else than the current object is dynamically allocated, nothing should be
     // done here atm.