Browse code

remove dependency to boost.geometry

devnewton authored on 28/09/2015 19:09:36
Showing 13 changed files
... ...
@@ -43,7 +43,6 @@ add_executable(superpaflaballe
43 43
  src/scenimp/progressbar.cpp
44 44
  src/scenimp/rectangle.cpp
45 45
  src/scenimp/rendering.cpp
46
- src/scenimp/geometry.cpp
47 46
  src/scenimp/sdl_exception.cpp
48 47
  src/intro.cpp
49 48
  src/main.cpp)
... ...
@@ -68,18 +68,18 @@ namespace superpaflaballe {
68 68
             auto& group = get<sprite_component>(e).group_;
69 69
             auto& pos = group->pos();
70 70
             dir_component& dir = get<dir_component>(e);
71
-            pos.x(pos.x() + dir.dx_);
72
-            pos.y(pos.y() + dir.dy_);
73
-            if (pos.x() < 0) {
71
+            pos.x += dir.dx_;
72
+            pos.y +=  dir.dy_;
73
+            if (pos.x < 0) {
74 74
                 dir.dx_ = -dir.dx_;
75 75
             }
76
-            if (pos.y() < 0) {
76
+            if (pos.y < 0) {
77 77
                 dir.dy_ = -dir.dy_;
78 78
             }
79
-            if (pos.x() >= screen_.logical_screen_width()) {
79
+            if (pos.x >= screen_.logical_screen_width()) {
80 80
                 dir.dx_ = -dir.dx_;
81 81
             }
82
-            if (pos.y() >= screen_.logical_screen_height()) {
82
+            if (pos.y >= screen_.logical_screen_height()) {
83 83
                 dir.dy_ = -dir.dy_;
84 84
             }
85 85
         }
... ...
@@ -131,8 +131,8 @@ namespace superpaflaballe {
131 131
         component.group_ = group;
132 132
 
133 133
         auto& pos = group->pos();
134
-        pos.x(std::rand() % screen_.logical_screen_width());
135
-        pos.y(std::rand() % screen_.logical_screen_height());
134
+        pos.x = std::rand() % screen_.logical_screen_width();
135
+        pos.y = std::rand() % screen_.logical_screen_height();
136 136
 
137 137
         dir_component& dir = world_.add<dir_component>(e);
138 138
         dir.dx_ = (1 + (std::rand() % 10)) * ((std::rand() % 1) ? -1 : 1);
... ...
@@ -142,7 +142,7 @@ namespace superpaflaballe {
142 142
         auto label = scene_.new_label(group);
143 143
         label->set_font(ned_font_);
144 144
         label->set_text("ned");
145
-        label->pos().y(32);
145
+        label->pos().y = 32;
146 146
 
147 147
         scene_.new_rectangle(group)->set_color({255, 0, 0, 255});
148 148
 
... ...
@@ -150,7 +150,7 @@ namespace superpaflaballe {
150 150
         int life = world_.add<life_component>(e).life_ = remaining_ticks_ > 0 ? std::rand() % remaining_ticks_ : 1;
151 151
 
152 152
         component.lifebar_ = scene_.new_progressbar(group);
153
-        component.lifebar_->pos().y(-16);
153
+        component.lifebar_->pos().y = -16;
154 154
         component.lifebar_->set_maximum(life);
155 155
         component.lifebar_->set_progress(life);
156 156
 
157 157
deleted file mode 100644
... ...
@@ -1 +0,0 @@
1
-#include "geometry.h"
2 0
\ No newline at end of file
3 1
deleted file mode 100644
... ...
@@ -1,12 +0,0 @@
1
-#pragma once
2
-
3
-#include <boost/geometry/geometries/point_xy.hpp>
4
-#include <boost/container/flat_set.hpp>
5
-
6
-namespace scenimp {
7
-
8
-    typedef boost::geometry::model::d2::point_xy<int> point;
9
-
10
-}
11
-
12
-
... ...
@@ -1,6 +1,7 @@
1 1
 #pragma once
2 2
 
3 3
 #include "node.h"
4
+#include <boost/container/flat_set.hpp>
4 5
 
5 6
 namespace scenimp {
6 7
 
... ...
@@ -20,9 +20,9 @@ namespace scenimp {
20 20
 
21 21
     void label::do_render(rendering& r) {
22 22
         if (font_ && !text_.empty()) {
23
-            const point& pos = r.current_pos();
23
+            const SDL_Point& pos = r.current_pos();
24 24
             update(r);
25
-            SDL_Rect rect_ = {pos.x() + -width_ / 2, pos.y() + -height_ / 2, width_, height_};
25
+            SDL_Rect rect_ = {pos.x + -width_ / 2, pos.y + -height_ / 2, width_, height_};
26 26
             SDL_RenderCopyEx(r.renderer(), texture_.get(), NULL, &rect_, angle_, NULL, flip_);
27 27
         }
28 28
     }
... ...
@@ -5,7 +5,7 @@
5 5
 namespace scenimp {
6 6
 
7 7
     node::node()
8
-    : pos_(0, 0) {
8
+    : pos_({0, 0}) {
9 9
     }
10 10
 
11 11
     node::~node() {
... ...
@@ -17,11 +17,11 @@ namespace scenimp {
17 17
         }
18 18
     }
19 19
 
20
-    const point& node::pos() const {
20
+    const SDL_Point& node::pos() const {
21 21
         return pos_;
22 22
     }
23 23
 
24
-    point& node::pos() {
24
+    SDL_Point& node::pos() {
25 25
         return pos_;
26 26
     }
27 27
 
... ...
@@ -1,6 +1,7 @@
1 1
 #pragma once
2 2
 
3
-#include "geometry.h"
3
+#include <SDL_rect.h>
4
+#include <memory>
4 5
 
5 6
 namespace scenimp {
6 7
 
... ...
@@ -18,14 +19,14 @@ namespace scenimp {
18 19
         
19 20
         void render(rendering& r);
20 21
 
21
-        const point& pos() const;
22
-        point& pos();
22
+        const SDL_Point& pos() const;
23
+        SDL_Point& pos();
23 24
 
24 25
     protected:
25 26
         virtual void do_render(rendering& r) = 0;
26 27
 
27 28
     private:
28
-        point pos_;
29
+        SDL_Point pos_;
29 30
         std::weak_ptr<group> parent_;
30 31
 
31 32
         friend class group;
... ...
@@ -17,13 +17,13 @@ namespace scenimp {
17 17
     }
18 18
 
19 19
     void progressbar::do_render(rendering& r) {
20
-        const point& pos = r.current_pos();
20
+        const SDL_Point& pos = r.current_pos();
21 21
 
22
-        SDL_Rect rect = {pos.x() + -width_ / 2, pos.y() + -height_ / 2, width_, height_};
22
+        SDL_Rect rect = {pos.x + -width_ / 2, pos.y + -height_ / 2, width_, height_};
23 23
         SDL_SetRenderDrawColor(r.renderer(), background_color_.r, background_color_.g, background_color_.b, background_color_.a);
24 24
         SDL_RenderFillRect(r.renderer(), &rect);
25 25
 
26
-        SDL_Rect rect_ = {pos.x() + -width_ / 2, pos.y() + -height_ / 2, (progress_ * width_) / maximum_, height_};
26
+        SDL_Rect rect_ = {pos.x + -width_ / 2, pos.y + -height_ / 2, (progress_ * width_) / maximum_, height_};
27 27
         SDL_SetRenderDrawColor(r.renderer(), progress_color_.r, progress_color_.g, progress_color_.b, progress_color_.a);
28 28
         SDL_RenderFillRect(r.renderer(), &rect_);
29 29
 
... ...
@@ -14,8 +14,8 @@ namespace scenimp {
14 14
 
15 15
     void rectangle::do_render(rendering& r) {
16 16
         prerender(r);
17
-        const point& pos = r.current_pos();
18
-        SDL_Rect rect = {pos.x() + -width_ / 2, pos.y() + -height_ / 2, width_, height_};
17
+        const SDL_Point& pos = r.current_pos();
18
+        SDL_Rect rect = {pos.x + -width_ / 2, pos.y + -height_ / 2, width_, height_};
19 19
         if (filled_) {
20 20
             SDL_RenderFillRect(r.renderer(), &rect);
21 21
         } else {
... ...
@@ -6,8 +6,8 @@
6 6
 namespace scenimp {
7 7
 
8 8
     rendering::rendering(SDL_Renderer* r)
9
-    : pos_(0, 0),
10
-    renderer_(r) {
9
+    : pos_({0, 0})
10
+    , renderer_(r) {
11 11
     }
12 12
 
13 13
     rendering::~rendering() {
... ...
@@ -18,18 +18,18 @@ namespace scenimp {
18 18
     }
19 19
 
20 20
     void rendering::push_pos(const node& n) {
21
-        const point& node_pos = n.pos();
22
-        pos_.x(pos_.x() + node_pos.x());
23
-        pos_.y(pos_.y() + node_pos.y());
21
+        const SDL_Point& node_pos = n.pos();
22
+        pos_.x += node_pos.x;
23
+        pos_.y += node_pos.y;
24 24
     }
25 25
 
26
-    const point& rendering::current_pos() const {
26
+    const SDL_Point& rendering::current_pos() const {
27 27
         return pos_;
28 28
     }
29 29
 
30 30
     void rendering::pop_pos(const node& n) {
31
-        const point& node_pos = n.pos();
32
-        pos_.x(pos_.x() - node_pos.x());
33
-        pos_.y(pos_.y() - node_pos.y());
31
+        const SDL_Point& node_pos = n.pos();
32
+        pos_.x -= node_pos.x;
33
+        pos_.y -= node_pos.y;
34 34
     }
35 35
 }
... ...
@@ -1,6 +1,5 @@
1 1
 #pragma once
2 2
 
3
-#include "geometry.h"
4 3
 #include <SDL.h>
5 4
 
6 5
 namespace scenimp {
... ...
@@ -13,13 +12,13 @@ namespace scenimp {
13 12
         ~rendering();
14 13
 
15 14
         void push_pos(const node& n);
16
-        const point& current_pos() const;
15
+        const SDL_Point& current_pos() const;
17 16
         void pop_pos(const node& n);
18 17
         
19 18
         SDL_Renderer* renderer();
20 19
 
21 20
     private:
22
-        point pos_;
21
+        SDL_Point pos_;
23 22
         SDL_Renderer* renderer_;
24 23
     };
25 24
 
... ...
@@ -14,8 +14,8 @@ namespace scenimp {
14 14
     }
15 15
 
16 16
     void sprite::do_render(rendering& r) {
17
-        const point& pos = r.current_pos();
18
-        SDL_Rect rect = {pos.x() + -width_ / 2, pos.y() + -height_ / 2, width_, height_};
17
+        const SDL_Point& pos = r.current_pos();
18
+        SDL_Rect rect = {pos.x + -width_ / 2, pos.y + -height_ / 2, width_, height_};
19 19
         SDL_RenderCopyEx(r.renderer(), play_->current_frame().image().get(), &play_->current_frame().rect(), &rect, angle_, NULL, flip_);
20 20
     }
21 21