瀏覽代碼

Use tinystl

Streetwalrus Einstein 10 年之前
父節點
當前提交
e9ae52cb2b
共有 2 個文件被更改,包括 10 次插入10 次删除
  1. 5 5
      include/Tileset.h
  2. 5 5
      src/Tileset.cpp

+ 5 - 5
include/Tileset.h

@@ -1,8 +1,8 @@
 #ifndef INCLUDE_TILESET_H
 #define INCLUDE_TILESET_H
 
-#include <vector>
-#include <unordered_map>
+#include <TINYSTL/vector.h>
+#include <TINYSTL/unordered_map.h>
 
 namespace WalrusRPG
 {
@@ -19,13 +19,13 @@ namespace WalrusRPG
         unsigned sheet_height;
         unsigned tile_width;
         unsigned tile_height;
-        std::unordered_map<unsigned, std::vector<Frame>> animations;
+        tinystl::unordered_map<unsigned, tinystl::vector<Frame>> animations;
 
       public:
         Tileset(unsigned short *sheet, unsigned sheet_width, unsigned sheet_height, unsigned tile_width, unsigned tile_heihgt);
-        void add_animation(int index, std::vector<WalrusRPG::Frame> anim);
+        void add_animation(int index, tinystl::vector<WalrusRPG::Frame> anim);
         void render_tile(unsigned int index, unsigned x, unsigned y) const;
-        void render_tile(unsigned int index, unsigned x, unsigned y, unsigned time) const;
+        void render_tile(unsigned int index, unsigned x, unsigned y, unsigned time);
 
         int get_tile_width() const;
         int get_tile_height() const;

+ 5 - 5
src/Tileset.cpp

@@ -6,7 +6,7 @@
 
 namespace
 {
-    unsigned find_frame(const std::vector<WalrusRPG::Frame> &anim, signed frame_time)
+    unsigned find_frame(const tinystl::vector<WalrusRPG::Frame> &anim, signed frame_time)
     {
         unsigned index = 0;
         do
@@ -23,7 +23,7 @@ TILESET::Tileset(unsigned short *sheet, unsigned sheet_width, unsigned sheet_hei
 {
 }
 
-void TILESET::add_animation(int index, std::vector<WalrusRPG::Frame> anim)
+void TILESET::add_animation(int index, tinystl::vector<WalrusRPG::Frame> anim)
 {
     animations[index] = anim;
 }
@@ -41,11 +41,11 @@ void TILESET::render_tile(unsigned int index, unsigned x, unsigned y) const
     draw_sprite_sheet(sheet, x, y, &sprite);
 }
 
-void TILESET::render_tile(unsigned int index, unsigned x, unsigned y, unsigned time) const
+void TILESET::render_tile(unsigned int index, unsigned x, unsigned y, unsigned time)
 {
-    if (animations.count(index))
+    if (!animations[index].empty())
     {
-        render_tile(animations.at(index).at(find_frame(this->animations.at(index), time)).frame, x, y);
+        render_tile(animations[index][find_frame(this->animations[index], time)].frame, x, y);
         // If an animation already exists.
     }
     else