forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixel_minimap.h
98 lines (71 loc) · 2.65 KB
/
pixel_minimap.h
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
#pragma once
#ifndef CATA_SRC_PIXEL_MINIMAP_H
#define CATA_SRC_PIXEL_MINIMAP_H
#include <map>
#include <memory>
#include "point.h"
#include "sdl_wrappers.h"
#include "sdl_geometry.h"
class pixel_minimap_projector;
enum class pixel_minimap_type {
ortho,
iso
};
enum class pixel_minimap_mode {
solid,
squares,
dots
};
struct pixel_minimap_settings {
pixel_minimap_mode mode = pixel_minimap_mode::solid;
int brightness = 100;
int beacon_size = 2;
int beacon_blink_interval = 0;
bool square_pixels = true;
bool scale_to_fit = false;
};
class pixel_minimap
{
public:
pixel_minimap( const SDL_Renderer_Ptr &renderer, const GeometryRenderer_Ptr &geometry );
~pixel_minimap();
void set_type( pixel_minimap_type type );
void set_settings( const pixel_minimap_settings &settings );
void draw( const SDL_Rect &screen_rect, const tripoint ¢er );
bool has_animated_elements() const;
private:
struct submap_cache;
submap_cache &get_cache_at( const tripoint &abs_sm_pos );
void set_screen_rect( const SDL_Rect &screen_rect );
void reset();
void draw_beacon( const SDL_Rect &rect, const SDL_Color &color );
void process_cache( const tripoint ¢er );
void flush_cache_updates();
void update_cache_at( const tripoint &pos );
void prepare_cache_for_updates( const tripoint ¢er );
void clear_unused_cache();
void render( const tripoint ¢er );
void render_cache( const tripoint ¢er );
void render_critters( const tripoint ¢er );
std::unique_ptr<pixel_minimap_projector> create_projector( const SDL_Rect &max_screen_rect ) const;
private:
const SDL_Renderer_Ptr &renderer;
const GeometryRenderer_Ptr &geometry;
pixel_minimap_type type;
pixel_minimap_settings settings;
point pixel_size;
//track the previous viewing area to determine if the minimap cache needs to be cleared
tripoint cached_center_sm;
// track presence of animated beacons to determine whether the minimap needs to be animated
bool cached_has_animated_beacons = true;
SDL_Rect screen_rect;
SDL_Rect main_tex_clip_rect;
SDL_Rect screen_clip_rect;
SDL_Texture_Ptr main_tex;
std::unique_ptr<pixel_minimap_projector> projector;
//the minimap texture pool which is used to reduce new texture allocation spam
class shared_texture_pool;
std::unique_ptr<shared_texture_pool> tex_pool;
std::map<tripoint, submap_cache> cache;
};
#endif // CATA_SRC_PIXEL_MINIMAP_H