supertux
sector.hpp
1 // SuperTux - A Jump'n Run
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HEADER_SUPERTUX_SUPERTUX_SECTOR_HPP
18 #define HEADER_SUPERTUX_SUPERTUX_SECTOR_HPP
19 
20 #include "supertux/sector_base.hpp"
21 
22 #include <vector>
23 #include <stdint.h>
24 
25 #include "collision/collision_system.hpp"
26 #include "math/anchor_point.hpp"
27 #include "math/easing.hpp"
28 #include "math/fwd.hpp"
29 #include "supertux/d_scope.hpp"
30 #include "supertux/tile.hpp"
31 #include "video/color.hpp"
32 
33 namespace collision {
34 class Constraints;
35 }
36 
37 class Camera;
39 class DisplayEffect;
40 class DrawingContext;
41 class Level;
42 class MovingObject;
43 class Player;
44 class ReaderMapping;
45 class Rectf;
46 class Size;
47 class SpawnPointMarker;
48 class TextObject;
49 class TileMap;
50 class Writer;
51 
61 class Sector final : public Base::Sector
62 {
63  friend class CollisionSystem;
64  friend class EditorSectorMenu;
65 
66 public:
67  static void register_class(ssq::VM& vm);
68 
69 private:
70  static Sector* s_current;
71 
72 public:
74  static Sector& get() { assert(s_current != nullptr); return *s_current; }
75  static Sector* current() { return s_current; }
76 
77 public:
78  Sector(Level& parent);
79  ~Sector() override;
80 
81  void finish_construction(bool editable) override;
82 
83  std::string get_exposed_class_name() const override { return "Sector"; }
84 
85  Level& get_level() const { return m_level; }
86  TileSet* get_tileset() const override;
87  bool in_worldmap() const override;
88 
90  void activate(const std::string& spawnpoint);
91  void activate(const Vector& player_pos);
92  void deactivate();
93 
94  void draw(DrawingContext& context) override;
95  void update(float dt_sec) override;
96 
97  void save(Writer &writer);
98 
100  void stop_looping_sounds();
101 
103  void pause_camera_interpolation();
104 
106  void play_looping_sounds();
107 
110  bool inside(const Rectf& rectangle) const;
111 
114  bool is_free_of_tiles(const Rectf& rect, const bool ignoreUnisolid = false, uint32_t tiletype = Tile::SOLID) const;
124  bool is_free_of_solid_tiles(float left, float top, float right, float bottom,
125  bool ignore_unisolid) const;
126 
131  bool is_free_of_statics(const Rectf& rect, const MovingObject* ignore_object = nullptr, const bool ignoreUnisolid = false) const;
144  bool is_free_of_statics(float left, float top, float right, float bottom,
145  bool ignore_unisolid) const;
146 
151  bool is_free_of_movingstatics(const Rectf& rect, const MovingObject* ignore_object = nullptr) const;
163  bool is_free_of_movingstatics(float left, float top, float right, float bottom) const;
164 
167  bool is_free_of_specifically_movingstatics(const Rectf& rect, const MovingObject* ignore_object = nullptr) const;
177  bool is_free_of_specifically_movingstatics(float left, float top, float right, float bottom) const;
178 
179  CollisionSystem::RaycastResult get_first_line_intersection(const Vector& line_start,
180  const Vector& line_end,
181  bool ignore_objects,
182  const CollisionObject* ignore_object) const;
183  bool free_line_of_sight(const Vector& line_start, const Vector& line_end, bool ignore_objects = false, const MovingObject* ignore_object = nullptr) const;
184  bool can_see_player(const Vector& eye) const;
185 
186  Player* get_nearest_player (const Vector& pos) const;
187  Player* get_nearest_player (const Rectf& pos) const {
188  return (get_nearest_player (get_anchor_pos (pos, ANCHOR_MIDDLE)));
189  }
190 
191  std::vector<MovingObject*> get_nearby_objects (const Vector& center, float max_distance) const;
192 
193  Rectf get_active_region() const;
194 
195  int get_foremost_opaque_layer() const;
196  int get_foremost_layer() const;
197 
199  Size get_editor_size() const;
200 
202  void resize_sector(const Size& old_size, const Size& new_size, const Size& resize_offset);
203 
205  void change_solid_tiles(uint32_t old_tile_id, uint32_t new_tile_id);
206 
213  void set_gravity(float gravity);
220  float get_gravity() const;
221 
222  Camera& get_camera() const;
223  std::vector<Player*> get_players() const;
224  DisplayEffect& get_effect() const;
225  TextObject& get_text_object() const { return m_text_object; }
226 
227  Vector get_spawn_point_position(const std::string& spawnpoint);
228 
229 private:
230  uint32_t collision_tile_attributes(const Rectf& dest, const Vector& mov) const;
231 
232  virtual bool before_object_add(GameObject& object) override;
233  virtual void before_object_remove(GameObject& object) override;
234 
235  int calculate_foremost_layer(bool including_transparent = true) const;
236 
239  void convert_tiles2gameobject();
240 
241  SpawnPointMarker* get_spawn_point(const std::string& spawnpoint);
242 
243 private:
244  Level& m_level; // Parent level
245 
246  bool m_fully_constructed;
247  int m_foremost_layer;
248  int m_foremost_opaque_layer;
249 
254  float m_gravity;
255 
256  std::unique_ptr<CollisionSystem> m_collision_system;
257 
258  TextObject& m_text_object;
259 
260  Vector m_last_translation; // For camera interpolation at high frame rates
261  float m_last_scale;
262  float m_last_dt;
263 
264 private:
265  Sector(const Sector&) = delete;
266  Sector& operator=(const Sector&) = delete;
267 };
268 
269 #endif
270 
271 /* EOF */
solid tile that is indestructible by Tux
Definition: tile.hpp:41
Definition: collision_system.hpp:39
A text object intended for scripts that want to tell a story.
Definition: text_object.hpp:38
Definition: collision_system.hpp:36
Represents one of (potentially) multiple, separate parts of a Level.
Definition: sector.hpp:61
Definition: size.hpp:24
Definition: spawnpoint.hpp:28
Definition: collision.cpp:24
This class takes care of moving objects that have collided on top of other moving objects or on top o...
Definition: collision_movement_manager.hpp:32
Definition: rectf.hpp:31
""DisplayEffect"" is an interface for toying with the display.
Definition: display_effect.hpp:29
A base for sector classes.
Definition: sector_base.hpp:30
Represents a collection of Sectors running in a single GameSession.
Definition: level.hpp:30
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
Base class for all dynamic/moving game objects.
Definition: moving_object.hpp:35
Definition: editor_sector_menu.hpp:25
Definition: collision_object.hpp:33
This class is responsible for managing an array of tiles.
Definition: tilemap.hpp:49
A ""Camera"" that was given a name can be manipulated by scripts.
Definition: camera.hpp:40
Definition: reader_mapping.hpp:32
Definition: tile_set.hpp:44
This module contains methods controlling the player.
Definition: player.hpp:47
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
Definition: writer.cpp:23