forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixel_minimap_projectors.cpp
98 lines (81 loc) · 2.4 KB
/
pixel_minimap_projectors.cpp
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
#if defined(TILES)
#include "pixel_minimap_projectors.h"
#include <algorithm>
pixel_minimap_ortho_projector::pixel_minimap_ortho_projector(
point total_tiles_count,
const SDL_Rect &max_screen_rect,
bool square_pixels )
{
tile_size.x = std::max( max_screen_rect.w / total_tiles_count.x, 1 );
tile_size.y = std::max( max_screen_rect.h / total_tiles_count.y, 1 );
if( square_pixels ) {
tile_size.x = tile_size.y = std::min( tile_size.x, tile_size.y );
}
}
SDL_Rect pixel_minimap_ortho_projector::get_chunk_rect(
point p,
point tiles_count ) const
{
return {
p.x * tile_size.x,
p.y * tile_size.y,
tiles_count.x * tile_size.x,
tiles_count.y *tile_size.y
};
}
point pixel_minimap_ortho_projector::get_tile_size() const
{
return tile_size;
}
point pixel_minimap_ortho_projector::get_tiles_size( point tiles_count ) const
{
return {
tiles_count.x * tile_size.x,
tiles_count.y *tile_size.y
};
}
point pixel_minimap_ortho_projector::get_tile_pos( point p,
point /*tiles_count*/ ) const
{
return { p.x * tile_size.x, p.y * tile_size.y };
}
pixel_minimap_iso_projector::pixel_minimap_iso_projector(
point total_tiles_count,
const SDL_Rect &max_screen_rect,
bool square_pixels ) :
total_tiles_count( total_tiles_count )
{
tile_size.x = std::max( max_screen_rect.w / ( 2 * total_tiles_count.x - 1 ), 2 );
tile_size.y = std::max( max_screen_rect.h / total_tiles_count.y, 2 );
if( square_pixels ) {
tile_size.x = tile_size.y = std::min( tile_size.x, tile_size.y );
}
}
SDL_Rect pixel_minimap_iso_projector::get_chunk_rect(
point p,
point tiles_count ) const
{
const point size = get_tiles_size( tiles_count );
const point offset = point{ 0, tile_size.y *tiles_count.y / 2 };
const point pos = get_tile_pos( p, total_tiles_count ) - offset;
return { pos.x, pos.y, size.x, size.y };
}
point pixel_minimap_iso_projector::get_tile_size() const
{
return tile_size;
}
point pixel_minimap_iso_projector::get_tiles_size( point tiles_count ) const
{
return {
tile_size.x *( 2 * tiles_count.x - 1 ),
tile_size.y *tiles_count.y
};
}
point pixel_minimap_iso_projector::get_tile_pos( point p, point tiles_count ) const
{
return {
tile_size.x *( p.x + p.y ),
tile_size.y *( tiles_count.y + p.y - p.x - 1 ) / 2,
};
}
#endif // TILES