30 int time_chunk = std::max<int>(
duration, 1);
31 std::vector<std::string>::const_iterator tmp;
33 if (duration > 1 && first_pass.size() > 0) {
35 int total_specified_time = 0;
36 for(tmp=first_pass.begin(); tmp != first_pass.end(); ++tmp) {
37 std::vector<std::string> second_pass =
utils::split(*tmp,
':');
38 if(second_pass.size() > 1) {
39 total_specified_time += std::stoi(second_pass[1]);
42 time_chunk = std::max<int>((duration - total_specified_time) / first_pass.size(), 1);
45 for(tmp=first_pass.begin(); tmp != first_pass.end(); ++tmp) {
46 std::vector<std::string> second_pass =
utils::split(*tmp,
':');
47 if(second_pass.size() > 1) {
48 data_.push_back(std::pair<std::string,int>(second_pass[0],std::stoi(second_pass[1])));
50 data_.push_back(std::pair<std::string,int>(second_pass[0],time_chunk));
57 std::vector<std::pair<std::string,int> >::const_iterator cur_halo;
58 for(cur_halo =
data_.begin() ; cur_halo !=
data_.end() ; ++cur_halo) {
59 total += cur_halo->second;
69 int time_chunk = std::max<int>(
duration, 1);
70 std::vector<std::string>::const_iterator tmp;
72 if (duration > 1 && first_pass.size() > 0) {
74 int total_specified_time = 0;
75 for(tmp=first_pass.begin(); tmp != first_pass.end(); ++tmp) {
76 std::vector<std::string> second_pass =
utils::split(*tmp,
':');
77 if(second_pass.size() > 1) {
78 total_specified_time += std::stoi(second_pass[1]);
81 time_chunk = std::max<int>((duration - total_specified_time) / first_pass.size(), 1);
84 for(tmp=first_pass.begin(); tmp != first_pass.end(); ++tmp) {
85 std::vector<std::string> second_pass =
utils::split(*tmp,
':');
86 if(second_pass.size() > 1) {
87 data_.push_back(std::pair<image::locator,int>(second_pass[0],std::stoi(second_pass[1])));
89 data_.push_back(std::pair<image::locator,int>(second_pass[0],time_chunk));
96 std::vector<std::pair<image::locator,int> >::const_iterator cur_halo;
97 for(cur_halo =
data_.begin() ; cur_halo !=
data_.end() ; ++cur_halo) {
98 total += cur_halo->second;
108 unsigned int sub_image = 0;
109 if(
data_.empty())
return empty_image;
110 while(time < current_time&& sub_image <
data_.size()) {
111 time +=
data_[sub_image].second;
115 if(sub_image) sub_image--;
116 return data_[sub_image].first;
124 unsigned int sub_halo = 0;
126 while(time < current_time&& sub_halo <
data_.size()) {
127 time +=
data_[sub_halo].second;
131 if(sub_halo) sub_halo--;
132 return data_[sub_halo].first;
141 const std::vector<std::string> comma_split =
utils::split(data,
',',split_flag);
142 const int time_chunk = std::max<int>(1, duration / std::max<int>(comma_split.size(),1));
144 std::vector<std::string>::const_iterator com_it = comma_split.begin();
145 for(; com_it != comma_split.end(); ++com_it) {
146 std::vector<std::string> colon_split =
utils::split(*com_it,
':',split_flag);
147 int time = (colon_split.size() > 1) ? std::stoi(colon_split[1]) : time_chunk;
151 T range1 = (range.size() > 1) ? lexical_cast<T>(range[1]) : range0;
152 typedef std::pair<T,T> range_pair;
153 data_.push_back(std::pair<range_pair,int>(range_pair(range0, range1), time));
161 unsigned int sub_halo = 0;
162 int searched_time = current_time;
163 if(searched_time < 0) searched_time = 0;
164 if(searched_time > duration()) searched_time = duration();
165 if(data_.empty())
return default_val;
166 while(time < searched_time&& sub_halo < data_.size()) {
167 time += data_[sub_halo].second;
173 time -= data_[sub_halo].second;
176 const T
first = data_[sub_halo].first.first;
177 const T second = data_[sub_halo].first.second;
179 return T((static_cast<double>(searched_time - time) /
180 static_cast<double>(data_[sub_halo].second)) *
181 (second - first) + first);
188 typename std::vector<std::pair<std::pair<T, T>,
int> >::const_iterator cur_halo;
189 for(cur_halo = data_.begin() ; cur_halo != data_.end() ; ++cur_halo) {
190 total += cur_halo->second;
199 return data_.empty() ||
200 ( data_.size() == 1 && data_[0].first.first == data_[0].first.second);
218 throw "found unexpected tristate";
236 highlight_ratio(1.0),
246 drawing_layer(
display::LAYER_UNIT_DEFAULT -
display::LAYER_UNIT_FIRST)
263 highlight_ratio_(
""),
273 drawing_layer_(
std::to_string(
display::LAYER_UNIT_DEFAULT -
display::LAYER_UNIT_FIRST))
278 image_(cfg[frame_string +
"image"]),
279 image_diagonal_(cfg[frame_string +
"image_diagonal"]),
280 image_mod_(cfg[frame_string +
"image_mod"]),
281 halo_(cfg[frame_string +
"halo"]),
282 halo_x_(cfg[frame_string +
"halo_x"]),
283 halo_y_(cfg[frame_string +
"halo_y"]),
284 halo_mod_(cfg[frame_string +
"halo_mod"]),
285 sound_(cfg[frame_string +
"sound"]),
286 text_(cfg[frame_string +
"text"]),
289 blend_ratio_(cfg[frame_string +
"blend_ratio"]),
290 highlight_ratio_(cfg[frame_string +
"alpha"]),
291 offset_(cfg[frame_string +
"offset"]),
292 submerge_(cfg[frame_string +
"submerge"]),
293 x_(cfg[frame_string +
"x"]),
294 y_(cfg[frame_string +
"y"]),
295 directional_x_(cfg[frame_string +
"directional_x"]),
296 directional_y_(cfg[frame_string +
"directional_y"]),
300 drawing_layer_(cfg[frame_string +
"layer"])
304 }
else if(cfg[frame_string +
"auto_vflip"].to_bool()) {
311 }
else if(cfg[frame_string +
"auto_hflip"].to_bool()) {
318 }
else if(cfg[frame_string +
"primary"].to_bool()) {
324 if (color.size() == 3) {
326 std::stoi(color[1]), std::stoi(color[2]));
331 }
else if (!cfg.
get(frame_string +
"end")) {
335 duration(std::max(std::max(image_duration,image_diagonal_duration),halo_duration));
338 duration(cfg[frame_string +
"end"].to_int() - cfg[frame_string +
"begin"].to_int());
342 color =
utils::split(cfg[frame_string +
"blend_color"]);
343 if (color.size() == 3) {
345 std::stoi(color[1]), std::stoi(color[2]));
451 duration_(duration ? duration :builder.duration_),
453 image_diagonal_(builder.image_diagonal_,duration_),
454 image_mod_(builder.image_mod_),
455 halo_(builder.halo_,duration_),
456 halo_x_(builder.halo_x_,duration_),
457 halo_y_(builder.halo_y_,duration_),
458 halo_mod_(builder.halo_mod_),
459 sound_(builder.sound_),
461 text_color_(builder.text_color_),
462 blend_with_(builder.blend_with_),
463 blend_ratio_(builder.blend_ratio_,duration_),
464 highlight_ratio_(builder.highlight_ratio_,duration_),
465 offset_(builder.offset_,duration_),
466 submerge_(builder.submerge_,duration_),
467 x_(builder.
x_,duration_),
468 y_(builder.
y_,duration_),
469 directional_x_(builder.directional_x_,duration_),
470 directional_y_(builder.directional_y_,duration_),
471 auto_vflip_(builder.auto_vflip_),
472 auto_hflip_(builder.auto_hflip_),
473 primary_frame_(builder.primary_frame_),
474 drawing_layer_(builder.drawing_layer_,duration_)
554 if(!highlight.empty()) {
559 if(!offset.empty()) {
564 if(!blend_ratio.empty()) {
575 if(!modifiers.empty()) {
594 std::vector<std::string>
v;
604 if (!
text_.empty()) {
605 v.push_back(
"text="+
text_);
606 v.push_back(
"text_color="+std::to_string(
text_color_));
610 v.push_back(
"blend_with="+std::to_string(
blend_with_));
639 double tmp_offset = current_data.
offset;
648 if(!current_data.
sound.empty() ) {
651 if(!current_data.
text.empty() ) {
668 const int x =
static_cast<int>(tmp_offset * xdst + (1.0-tmp_offset) * xsrc) + d2;
669 const int y =
static_cast<int>(tmp_offset * ydst + (1.0-tmp_offset) * ysrc) + d2;
670 if (image !=
nullptr) {
672 bool facing_west =
false;
677 if(!current_data.
auto_hflip) facing_west =
false;
678 if(!current_data.
auto_vflip) facing_north =
true;
679 int my_x = x + current_data.
x- image->w/2;
680 int my_y = y + current_data.
y- image->h/2;
694 src, image, facing_west,
false,
700 if (!in_scope_of_frame) {
704 if(!current_data.
halo.empty()) {
761 double tmp_offset = current_data.
offset;
774 std::set<map_location>
result;
777 int my_y = current_data.
y;
779 if(!current_data.
auto_vflip) facing_north =
true;
789 }
else if(my_y > 0) {
798 #pragma omp critical(frame_surface) // with the way surfaces work it's hard to lock the refcount within sdl_utils
807 if(image !=
nullptr) {
812 if (w != 0 || h != 0) {
813 const int x =
static_cast<int>(tmp_offset * xdst + (1.0-tmp_offset) * xsrc);
814 const int y =
static_cast<int>(tmp_offset * ydst + (1.0-tmp_offset) * ysrc);
816 bool facing_west =
false;
821 if(!current_data.
auto_vflip) facing_north =
true;
822 if(!current_data.
auto_hflip) facing_west =
false;
823 int my_x = x +current_data.
x+d2- w/2;
824 int my_y = y +current_data.
y+d2- h/2;
843 result.insert(underlying_hex.
begin(),underlying_hex.
end());
898 assert(engine_val.
halo.empty());
901 assert(engine_val.
halo_x == 0);
914 assert(engine_val.
sound.empty());
917 assert(engine_val.
text.empty());
939 assert(engine_val.
offset == 0);
947 assert(engine_val.
x == 0);
948 result.
x = current_val.
x?current_val.
x:animation_val.
x;
951 result.
y = current_val.
y?current_val.
y:animation_val.
y;
952 result.
y += engine_val.
y;
bool does_not_change() const
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
tformula< unsigned > x_
The x coordinate of the rectangle.
frame_builder & y(const std::string &y)
const image::locator empty_image
std::vector< std::pair< std::string, int > > data_
static display * get_singleton()
Returns the display object if a display object exists.
progressive_double blend_ratio_
frame_parsed_parameters(const frame_builder &builder=frame_builder(), int override_duration=0)
progressive_image(const std::string &data="", int duration=0)
bool does_not_change() const
std::string directional_y_
std::vector< std::string > debug_strings() const
SDL_Color int_to_color(const Uint32 rgb)
Frame for unit's animation sequence.
frame_builder & drawing_layer(const std::string &drawing_layer)
frame_builder & image_diagonal(const std::string &image_diagonal, const std::string &image_mod="")
REMOVE_EMPTY : remove empty elements.
surface image_
The image is cached in this surface.
GLenum GLsizei GLenum GLenum const GLvoid * image
std::vector< std::pair< std::pair< T, T >, int > > data_
void float_label(const map_location &loc, const std::string &text, const SDL_Color &color)
Function to float a label above a tile.
std::string drawing_layer_
double get_zoom_factor() const
Returns the current zoom factor.
DIRECTION get_relative_dir(const map_location &loc, map_location::RELATIVE_DIR_MODE mode) const
int get_location_x(const map_location &loc) const
Functions to get the on-screen positions of hexes.
GLint GLint GLint GLint GLint GLint y
Audio output for sound and music.
image::locator image_diagonal
Rectangular area of hexes, allowing to decide how the top and bottom edges handles the vertical shift...
std::string get_original() const
All parameters from a frame at a given instant.
frame_builder & directional_x(const std::string &directional_x)
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
To lexical_cast(From value)
Lexical cast converts one type to another.
tformula< t_string > text_
The text to draw.
frame_builder & blend(const std::string &blend_ratio, const Uint32 blend_color)
frame_builder & image(const std::string &image, const std::string &image_mod="")
const frame_parameters parameters(int current_time) const
getters for the different parameters
Variant for storing WML attributes.
int get_location_y(const map_location &loc) const
void play_sound(const std::string &files, channel_group group, unsigned int repeats)
frame_builder & submerge(const std::string &submerge)
frame_parsed_parameters builder_
static const std::string empty_string
const frame_parameters merge_parameters(int current_time, const frame_parameters &animation_val, const frame_parameters &engine_val=frame_parameters()) const
frame_builder & auto_hflip(const bool auto_hflip)
std::set< map_location > get_overlaped_hex(const int frame_time, const map_location &src, const map_location &dst, const frame_parameters &animation_val, const frame_parameters &engine_val) const
std::string half_signed_value(int val)
Sign with Unicode "−" if negative.
frame_builder & sound(const std::string &sound)
std::string get_original() const
bool does_not_change() const
GLenum GLenum GLuint GLint GLint layer
progressive_image image_diagonal_
std::string highlight_ratio_
GLubyte GLubyte GLubyte GLubyte w
progressive_(const std::string &data="", int duration=0)
void render_image(int x, int y, const display::tdrawing_layer drawing_layer, const map_location &loc, surface image, bool hreverse=false, bool greyscale=false, fixed_t alpha=ftofxp(1.0), Uint32 blendto=0, double blend_ratio=0, double submerged=0.0, bool vreverse=false)
Draw an image at a certain location.
frame_builder & auto_vflip(const bool auto_vflip)
progressive_double highlight_ratio_
std::vector< std::pair< image::locator, int > > data_
std::string directional_x_
progressive_int drawing_layer_
handle add(int x, int y, const std::string &image, const map_location &loc, halo::ORIENTATION orientation=NORMAL, bool infinite=true)
Add a haloing effect using 'image centered on (x,y).
progressive_int directional_x_
Encapsulates the map of the game.
std::string get_original() const
const std::string & get_filename() const
Reserve layers to be selected for WML.
default layer for drawing units
const T get_current_element(int time, T default_val=0) const
frame_builder & text(const std::string &text, const Uint32 text_color)
const image::locator & get_current_element(int time) const
static Uint32 rgb(Uint8 red, Uint8 green, Uint8 blue)
static Uint32 max_rgb(Uint32 first, Uint32 second)
progressive_< int > progressive_int
GLfloat GLfloat GLfloat GLfloat h
frame_builder & offset(const std::string &offset)
GLint GLint GLint GLint GLint x
frame_builder & x(const std::string &x)
DIRECTION
Valid directions which can be moved in our hexagonal world.
bool does_not_change() const
tformula< unsigned > y_
The y coordinate of the rectangle.
GLdouble GLdouble GLdouble r
frame_builder & primary_frame(const bool primary_frame)
bool is_in_hex(const locator &i_locator)
function to check if an image fit into an hex return false if the image has not the standard size...
frame_builder & directional_y(const std::string &directional_y)
const rect_of_hexes hexes_under_rect(const SDL_Rect &r) const
Return the rectangular area of hexes overlapped by r (r is in screen coordinates) ...
progressive_double submerge_
const attribute_value * get(const std::string &key) const
Returns a pointer to the attribute with the given key or nullptr if it does not exist.
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an empty SDL_Rect.
bool has_attribute(const std::string &key) const
void override(int duration, const std::string &highlight="", const std::string &blend_ratio="", Uint32 blend_color=0, const std::string &offset="", const std::string &layer="", const std::string &modifiers="")
allow easy chained modifications will raised assert if used after initialization
progressive_int directional_y_
this module manages the cache of images.
progressive_< double > progressive_double
std::string image_diagonal_
frame_builder & duration(const int duration)
allow easy chained modifications will raised assert if used after initialization
map_location get_direction(DIRECTION d, unsigned int n=1u) const
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
progressive_double offset_
frame_builder & highlight(const std::string &highlight)
bool tristate_to_bool(tristate tri, bool def)
A config object defines a single node in a WML file, with access to child nodes.
int hex_size() const
Function which returns the size of a hex in pixels (from top tip to bottom tip or left edge to right ...
const std::string & get_current_element(int time) const
std::vector< std::string > square_parenthetical_split(std::string const &val, const char separator, std::string const &left, std::string const &right, const int flags)
Similar to parenthetical_split, but also expands embedded square brackets.
GLsizei const GLcharARB ** string
void redraw(const int frame_time, bool on_start_time, bool in_scope_of_frame, const map_location &src, const map_location &dst, halo::handle &halo_id, halo::manager &halo_man, const frame_parameters &animation_val, const frame_parameters &engine_val) const
frame_builder & halo(const std::string &halo, const std::string &halo_x, const std::string &halo_y, const std::string &halo_mod)
#define ftofxp(x)
IN: float or int - OUT: fixed_t.
progressive_string(const std::string &data="", int duration=0)
static game_display * get_singleton()
boost::shared_ptr< halo_record > handle