-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfield.hpp
138 lines (125 loc) · 4.83 KB
/
field.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ifndef HEADER_FIELD_HPP_INCLUDED
#define HEADER_FIELD_HPP_INCLUDED
#include <QTimer>
#include <QPoint>
#include <QWidget>
#include "../qsfmlwidget/qsfmlwidget.hpp"
#include <functional>
#include <SFML/Graphics.hpp>
#include <SFML/Graphics/View.hpp>
#include <SFML/Window.hpp>
#include <SFML/Window/VideoMode.hpp>
#include <QKeyEvent>
#include <SFML/Graphics/Rect.hpp>
#include "../tile/tile.hpp"
#include "../matrix/matrix.hpp"
#include "../object/object.hpp"
#include "../generate_objects/generateobjects.hpp"
#include "../generate_map/generatemap.hpp"
#include "../do_step/dostep.hpp"
#include "../model_manager/modelmanager.hpp"
#include "../do_step/dostep.hpp"
class Field : public QSFMLWidget
{
Q_OBJECT
private:
friend class MapDump;
sf::Vector2u tile_size_;
// Objects on the field
std::vector< Entity > entities_;
Matrix<Tile> map_;
// Number of ticks between the field updates
// The animation frames are inserted uniformly
size_t animation_time_;
// Current animation frame in [0, animation_time_)
size_t animation_frame_;
// The amount of time between frames
QTimer timer_;
size_t max_FPS_;
std::map< int, int > statistics_;
std::shared_ptr<const ModelManager> model_manager_;
std::function< void(Matrix< Tile >&) > generate_map_;
std::function< void(Matrix< Tile >&, std::vector< Entity >&) > generate_entities_;
std::function< void(Matrix< Tile >&, std::vector< Entity >&) > do_step_;
void setTilePositions();
int getEdgeType(unsigned y, unsigned x);
void calcSpritePosition (double time, double step_count);
// MINIMAP INTERFACE //
sf::View minimap_;
// VIEW MOVING INTERFACE //
// Aspect Ratio = Window's Width / Window's Height
float view_aspect_ratio_;
sf::View field_view_;
// Are we mooving the view (left mouse button pressed)
bool moving_;
// The last place where the mouse was spotted
QPoint last_point_;
bool minimap_shown_;
// Valid positions for the view center
sf::FloatRect valid_rect_;
// Sets the maximum possible view
void zoomOut();
// Sets the minimum possible view
void zoomIn();
// Moves view by given offset in WIDGET's COORDINATES if possible
void moveView(const QPoint& from, const QPoint& to);
// Updates if the the view is updated
void updateValidRect();
void validateViewCenter();
void validateViewSize();
void validateView();
void drawMinimap();
protected:
void keyPressEvent(QKeyEvent * event);
void mousePressEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent *);
public:
Field(QWidget* parent = nullptr, const QPoint& pos = QPoint(),
const sf::Vector2u& sizeInTiles = sf::Vector2u(1, 1),
const sf::Vector2u& sizeInPixels = sf::Vector2u(600,600));
// Genrerates the entire new map
void init();
~Field();
void toggleMinimap();
// Sets model manager for every tile
void loadTileTextures();
// Sets model manager for every entity
void loadEntityTextures();
void drawEntities ();
void drawTiles ();
void generateTiles ();
void generateEntities ();
// Функция пересчета состояния поля на один игровой шаг
void doStep ();
void calcStatistics ();
// Save changes done by doStep
void syncronize ();
void nextFrame();
void drawAnimation();
void loadConfig(const std::string config_file);
// SETTERS & GETTERS //
std::function<void (Matrix<Tile> &)> getGenerateMap() const;
void setGenerateMap(const std::function<void (Matrix<Tile> &)> &generate_map);
std::function<void (Matrix<Tile> &, std::vector<Entity> &)> getGenerateEntities() const;
void setGenerateEntities(const std::function<void (Matrix<Tile> &, std::vector<Entity> &)> &generate_entities);
std::function<void (Matrix<Tile> &, std::vector<Entity> &)> getDoStep() const;
void setDoStep(const std::function<void (Matrix<Tile> &, std::vector<Entity> &)> &do_step);
void setMapSize(sf::Vector2u size);
sf::Vector2u getMapSize() const;
void setTileSize(sf::Vector2u size);
sf::Vector2u getTileSize() const;
void setModelManager (const std::shared_ptr<const ModelManager>& model_manager_ptr);
void setAnimationTime(int animation_time);
int getAnimationTime() const;
const std::map<int, int>& getStatistics() const;
void setStatistics(const std::map<int, int> &statistics);
public slots:
// Do step and animation
void proceed();
// Begin and stop the simulation process
void start();
void stop();
};
#endif