Convert some more C arrays to std::array
This commit is contained in:
parent
4c29a0dd58
commit
f7cf73307b
4 changed files with 39 additions and 23 deletions
|
@ -719,12 +719,12 @@ void display::draw_fog_shroud_transition_images(const map_location& loc, image::
|
||||||
adjacent_loc_array_t adjacent;
|
adjacent_loc_array_t adjacent;
|
||||||
get_adjacent_tiles(loc, adjacent.data());
|
get_adjacent_tiles(loc, adjacent.data());
|
||||||
|
|
||||||
enum visibility { FOG = 0, SHROUD = 1, CLEAR = 2 };
|
enum VISIBILITY { FOG = 0, SHROUD = 1, CLEAR = 2 };
|
||||||
visibility tiles[6];
|
std::array<VISIBILITY, 6> tiles;
|
||||||
|
|
||||||
const std::string* image_prefix[]{&game_config::fog_prefix, &game_config::shroud_prefix};
|
const std::array<const std::string*, 2> image_prefix {&game_config::fog_prefix, &game_config::shroud_prefix};
|
||||||
|
|
||||||
for(int i = 0; i < 6; ++i) {
|
for(unsigned i = 0; i < tiles.size(); ++i) {
|
||||||
if(shrouded(adjacent[i])) {
|
if(shrouded(adjacent[i])) {
|
||||||
tiles[i] = SHROUD;
|
tiles[i] = SHROUD;
|
||||||
} else if(!fogged(loc) && fogged(adjacent[i])) {
|
} else if(!fogged(loc) && fogged(adjacent[i])) {
|
||||||
|
@ -789,7 +789,7 @@ void display::draw_fog_shroud_transition_images(const map_location& loc, image::
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now render the images
|
// Now render the images
|
||||||
for(std::string& name : names) {
|
for(const std::string& name : names) {
|
||||||
render_scaled_to_zoom(image::get_texture(name), loc); // TODO: image_type
|
render_scaled_to_zoom(image::get_texture(name), loc); // TODO: image_type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1153,10 +1153,10 @@ std::string default_map_generator_job::default_generate_map(generator_data data,
|
||||||
starting_positions.insert(t_translation::starting_positions::value_type(std::to_string(player), coord));
|
starting_positions.insert(t_translation::starting_positions::value_type(std::to_string(player), coord));
|
||||||
terrain[x][y] = t_translation::HUMAN_KEEP;
|
terrain[x][y] = t_translation::HUMAN_KEEP;
|
||||||
|
|
||||||
const int castle_array[13][2] {
|
const std::array<std::array<int, 2>, 13> castle_array {{
|
||||||
{-1, 0}, {-1, -1}, {0, -1}, {1, -1}, {1, 0}, {0, 1}, {-1, 1},
|
{-1, 0}, {-1, -1}, {0, -1}, {1, -1}, {1, 0}, {0, 1}, {-1, 1},
|
||||||
{-2, 1}, {-2, 0}, {-2, -1}, {-1, -2}, {0, -2}, {1, -2}
|
{-2, 1}, {-2, 0}, {-2, -1}, {-1, -2}, {0, -2}, {1, -2}
|
||||||
};
|
}};
|
||||||
|
|
||||||
for(int i = 0; i < data.castle_size - 1; i++) {
|
for(int i = 0; i < data.castle_size - 1; i++) {
|
||||||
terrain[x+ castle_array[i][0]][y+ castle_array[i][1]] = t_translation::HUMAN_CASTLE;
|
terrain[x+ castle_array[i][0]][y+ castle_array[i][1]] = t_translation::HUMAN_CASTLE;
|
||||||
|
|
|
@ -1250,9 +1250,10 @@ REGISTER_MOD_PARSER(RIGHT, )
|
||||||
// Add a background color.
|
// Add a background color.
|
||||||
REGISTER_MOD_PARSER(BG, args)
|
REGISTER_MOD_PARSER(BG, args)
|
||||||
{
|
{
|
||||||
int c[4] { 0, 0, 0, SDL_ALPHA_OPAQUE };
|
std::array<int, 4> c { 0, 0, 0, SDL_ALPHA_OPAQUE };
|
||||||
std::vector<std::string> factors = utils::split(args, ',');
|
std::vector<std::string> factors = utils::split(args, ',');
|
||||||
|
|
||||||
|
// Doesn't use color_t::from_rgba_string since there maybe fewer than 4 arguments
|
||||||
for(int i = 0; i < std::min<int>(factors.size(), 4); ++i) {
|
for(int i = 0; i < std::min<int>(factors.size(), 4); ++i) {
|
||||||
c[i] = lexical_cast_default<int>(factors[i]);
|
c[i] = lexical_cast_default<int>(factors[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -493,15 +493,36 @@ bool terrain_builder::load_images(building_rule& rule)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
struct rotations_t
|
||||||
|
{
|
||||||
|
int ii;
|
||||||
|
int ij;
|
||||||
|
int ji;
|
||||||
|
int jj;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct xy_rotations_t
|
||||||
|
{
|
||||||
|
double xx;
|
||||||
|
double xy;
|
||||||
|
double yx;
|
||||||
|
double yy;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end anon namespace
|
||||||
|
|
||||||
void terrain_builder::rotate(terrain_constraint& ret, int angle)
|
void terrain_builder::rotate(terrain_constraint& ret, int angle)
|
||||||
{
|
{
|
||||||
static const struct
|
static const std::array<rotations_t, 6> rotations {{
|
||||||
{
|
{1, 0, 0, 1},
|
||||||
int ii;
|
{1, 1, -1, 0},
|
||||||
int ij;
|
{0, 1, -1, -1},
|
||||||
int ji;
|
{-1, 0, 0, -1},
|
||||||
int jj;
|
{-1, -1, 1, 0},
|
||||||
} rotations[6] {{1, 0, 0, 1}, {1, 1, -1, 0}, {0, 1, -1, -1}, {-1, 0, 0, -1}, {-1, -1, 1, 0}, {0, -1, 1, 1}};
|
{0, -1, 1, 1}
|
||||||
|
}};
|
||||||
|
|
||||||
// The following array of matrices is intended to rotate the (x,y)
|
// The following array of matrices is intended to rotate the (x,y)
|
||||||
// coordinates of a point in a wesnoth hex (and wesnoth hexes are not
|
// coordinates of a point in a wesnoth hex (and wesnoth hexes are not
|
||||||
|
@ -530,20 +551,14 @@ void terrain_builder::rotate(terrain_constraint& ret, int angle)
|
||||||
//
|
//
|
||||||
// And the following array contains I(2), r, r^2, r^3, r^4, r^5
|
// And the following array contains I(2), r, r^2, r^3, r^4, r^5
|
||||||
// (with r^3 == -I(2)), which are the successive rotations.
|
// (with r^3 == -I(2)), which are the successive rotations.
|
||||||
static const struct
|
static const std::array<xy_rotations_t, 6> xyrotations {{
|
||||||
{
|
|
||||||
double xx;
|
|
||||||
double xy;
|
|
||||||
double yx;
|
|
||||||
double yy;
|
|
||||||
} xyrotations[6] {
|
|
||||||
{ 1., 0., 0., 1. },
|
{ 1., 0., 0., 1. },
|
||||||
{ 1./2. , -3./4., 1., 1./2. },
|
{ 1./2. , -3./4., 1., 1./2. },
|
||||||
{ -1./2., -3./4., 1, -1./2.},
|
{ -1./2., -3./4., 1, -1./2.},
|
||||||
{ -1. , 0., 0., -1. },
|
{ -1. , 0., 0., -1. },
|
||||||
{ -1./2., 3./4., -1., -1./2.},
|
{ -1./2., 3./4., -1., -1./2.},
|
||||||
{ 1./2. , 3./4., -1., 1./2. },
|
{ 1./2. , 3./4., -1., 1./2. },
|
||||||
};
|
}};
|
||||||
|
|
||||||
assert(angle >= 0);
|
assert(angle >= 0);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue