use fixed-point computations...
...so owners of FPU-less machines can still enjoy the game
This commit is contained in:
parent
43bbdc2623
commit
81ffd3dc99
14 changed files with 102 additions and 70 deletions
|
@ -3,7 +3,10 @@ CVS HEAD:
|
|||
* British English
|
||||
* updated translations:
|
||||
* catalan
|
||||
* In language-selection dialog, consistently use native name for all languages, with the (hopefully) official latin transcription for those that cannot be displayed in the default font (russian, bulgarian, greek)
|
||||
* In language-selection dialog, consistently use native name for
|
||||
all languages, with the (hopefully) official latin transcription
|
||||
for those that cannot be displayed in the default font (russian,
|
||||
bulgarian, greek)
|
||||
* language fixes and polishing (English)
|
||||
* fixed Delfador appearing in the water when turns run out in 'The Bay of Pearls'
|
||||
* fixed the talking tentacle in 'Temple of the Deep'
|
||||
|
@ -16,6 +19,8 @@ CVS HEAD:
|
|||
* fixed locale-dependent numeric input/output bug,
|
||||
it allowed units to walk on the water, and prevented
|
||||
the AI from being correctly configured in campaigns
|
||||
* use fixed-point arithmetics in critical functions, so that wesnoth
|
||||
can reasonably run on an FPU-less machine (eg. ipaq PDA)
|
||||
|
||||
Version 0.8.10:
|
||||
* user interface tweaks
|
||||
|
|
|
@ -142,7 +142,7 @@ std::string recruit_unit(const gamemap& map, int side,
|
|||
|
||||
if(show) {
|
||||
|
||||
for(double alpha = 0.0; alpha <= 1.0; alpha += 0.1) {
|
||||
for(fixed_t alpha = ftofxp(0.0); alpha <= ftofxp(1.0); alpha += ftofxp(0.1)) {
|
||||
events::pump();
|
||||
disp->draw_tile(recruit_location.x,recruit_location.y,NULL,alpha);
|
||||
disp->update_display();
|
||||
|
@ -1220,7 +1220,7 @@ void calculate_healing(display& disp, const gamestatus& status, const gamemap& m
|
|||
|
||||
if(show_healing) {
|
||||
if(is_odd(h->second))
|
||||
disp.draw_tile(loc.x,loc.y,NULL,0.5,heal_colour);
|
||||
disp.draw_tile(loc.x,loc.y,NULL,ftofxp(0.5),heal_colour);
|
||||
else
|
||||
disp.draw_tile(loc.x,loc.y);
|
||||
|
||||
|
@ -1238,7 +1238,7 @@ void calculate_healing(display& disp, const gamestatus& status, const gamemap& m
|
|||
|
||||
if(show_healing) {
|
||||
if(is_odd(h->second))
|
||||
disp.draw_tile(loc.x,loc.y,NULL,0.5,damage_colour);
|
||||
disp.draw_tile(loc.x,loc.y,NULL,ftofxp(0.5),damage_colour);
|
||||
else
|
||||
disp.draw_tile(loc.x,loc.y);
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
|
||||
#define ERR_DP lg::err(lg::display)
|
||||
|
||||
std::map<gamemap::location,double> display::debugHighlights_;
|
||||
std::map<gamemap::location,fixed_t> display::debugHighlights_;
|
||||
|
||||
namespace {
|
||||
const int DefaultZoom = 72;
|
||||
|
@ -73,7 +73,7 @@ display::display(unit_map& units, CVideo& video, const gamemap& map,
|
|||
invalidateAll_(true), invalidateUnit_(true),
|
||||
invalidateGameStatus_(true), panelsDrawn_(false),
|
||||
currentTeam_(0), activeTeam_(0), hideEnergy_(false),
|
||||
deadAmount_(0.0), advancingAmount_(0.0), updatesLocked_(0),
|
||||
deadAmount_(ftofxp(0.0)), advancingAmount_(0.0), updatesLocked_(0),
|
||||
turbo_(false), grid_(false), sidebarScaling_(1.0),
|
||||
theme_(theme_cfg,screen_area()), builder_(cfg, level, map),
|
||||
first_turn_(true), in_game_(false), map_labels_(*this,map),
|
||||
|
@ -148,12 +148,12 @@ void display::new_turn()
|
|||
for(int i = 0; i != niterations; ++i) {
|
||||
|
||||
if(old_mask != NULL) {
|
||||
const double proportion = 1.0 - double(i)/double(niterations);
|
||||
const fixed_t proportion = ftofxp(1.0) - fxpdiv(i,niterations);
|
||||
tod_hex_mask1.assign(adjust_surface_alpha(old_mask,proportion));
|
||||
}
|
||||
|
||||
if(new_mask != NULL) {
|
||||
const double proportion = double(i)/double(niterations);
|
||||
const fixed_t proportion = fxpdiv(i,niterations);
|
||||
tod_hex_mask2.assign(adjust_surface_alpha(new_mask,proportion));
|
||||
}
|
||||
|
||||
|
@ -1111,7 +1111,7 @@ void display::draw_halo_on_tile(int x, int y)
|
|||
}
|
||||
|
||||
void display::draw_unit_on_tile(int x, int y, surface unit_image_override,
|
||||
double highlight_ratio, Uint32 blend_with)
|
||||
fixed_t highlight_ratio, Uint32 blend_with)
|
||||
{
|
||||
if(updatesLocked_)
|
||||
return;
|
||||
|
@ -1183,18 +1183,18 @@ void display::draw_unit_on_tile(int x, int y, surface unit_image_override,
|
|||
return;
|
||||
}
|
||||
|
||||
if(highlight_ratio == 1.0)
|
||||
if(highlight_ratio == ftofxp(1.0))
|
||||
highlight_ratio = it->second.alpha();
|
||||
|
||||
if(u.invisible(map_.underlying_terrain(map_[x][y]),
|
||||
status_.get_time_of_day().lawful_bonus,loc,
|
||||
units_,teams_) &&
|
||||
highlight_ratio > 0.5) {
|
||||
highlight_ratio = 0.5;
|
||||
highlight_ratio > ftofxp(0.5)) {
|
||||
highlight_ratio = ftofxp(0.5);
|
||||
}
|
||||
|
||||
if(loc == selectedHex_ && highlight_ratio == 1.0) {
|
||||
highlight_ratio = 1.5;
|
||||
if(loc == selectedHex_ && highlight_ratio == ftofxp(1.0)) {
|
||||
highlight_ratio = ftofxp(1.5);
|
||||
// blend_with = rgb(255,255,255);
|
||||
}
|
||||
|
||||
|
@ -1277,7 +1277,7 @@ void display::draw_unit_on_tile(int x, int y, surface unit_image_override,
|
|||
highlight_ratio,blend_with,blend_ratio,submerge,ellipse_back,ellipse_front);
|
||||
}
|
||||
|
||||
const double bar_alpha = highlight_ratio < 1.0 && blend_with == 0 ? highlight_ratio : 1.0;
|
||||
const fixed_t bar_alpha = highlight_ratio < ftofxp(1.0) && blend_with == 0 ? highlight_ratio : ftofxp(1.0);
|
||||
if(energy_file != NULL) {
|
||||
draw_bar(*energy_file,xpos,ypos,(u.max_hitpoints()*2)/3,unit_energy,energy_colour,bar_alpha);
|
||||
}
|
||||
|
@ -1309,7 +1309,7 @@ void display::draw_unit_on_tile(int x, int y, surface unit_image_override,
|
|||
}
|
||||
}
|
||||
|
||||
void display::draw_bar(const std::string& image, int xpos, int ypos, size_t height, double filled, const SDL_Color& col, double alpha)
|
||||
void display::draw_bar(const std::string& image, int xpos, int ypos, size_t height, double filled, const SDL_Color& col, fixed_t alpha)
|
||||
{
|
||||
filled = minimum<double>(maximum<double>(filled,0.0),1.0);
|
||||
|
||||
|
@ -1324,7 +1324,7 @@ void display::draw_bar(const std::string& image, int xpos, int ypos, size_t heig
|
|||
height = bar_loc.h;
|
||||
}
|
||||
|
||||
if(alpha != 1.0) {
|
||||
if(alpha != ftofxp(1.0)) {
|
||||
surf.assign(adjust_surface_alpha(surf,alpha));
|
||||
if(surf == NULL) {
|
||||
return;
|
||||
|
@ -1342,7 +1342,7 @@ void display::draw_bar(const std::string& image, int xpos, int ypos, size_t heig
|
|||
|
||||
const size_t unfilled = (const size_t)(height*(1.0 - filled));
|
||||
|
||||
if(unfilled < height && alpha >= 0.3) {
|
||||
if(unfilled < height && alpha >= ftofxp(0.3)) {
|
||||
SDL_Rect filled_area = {xpos+bar_loc.x,ypos+bar_loc.y+unfilled,bar_loc.w,height-unfilled};
|
||||
const Uint32 colour = SDL_MapRGB(video().getSurface()->format,col.r,col.g,col.b);
|
||||
SDL_FillRect(video().getSurface(),&filled_area,colour);
|
||||
|
@ -1376,7 +1376,7 @@ void display::draw_terrain_on_tile(int x, int y, image::TYPE image_type, ADJACEN
|
|||
}
|
||||
}
|
||||
|
||||
void display::draw_tile(int x, int y, surface unit_image, double alpha, Uint32 blend_to)
|
||||
void display::draw_tile(int x, int y, surface unit_image, fixed_t alpha, Uint32 blend_to)
|
||||
{
|
||||
if(updatesLocked_)
|
||||
return;
|
||||
|
@ -1592,7 +1592,7 @@ void display::draw_footstep(const gamemap::location& loc, int xloc, int yloc)
|
|||
image.assign(image::reverse_image(image));
|
||||
}
|
||||
|
||||
draw_unit(xloc,yloc,image,vflip,0.5);
|
||||
draw_unit(xloc,yloc,image,vflip,ftofxp(0.5));
|
||||
|
||||
if(show_time && route_.move_left > 0 && route_.move_left < 10) {
|
||||
const SDL_Rect& rect = map_area();
|
||||
|
@ -1843,14 +1843,14 @@ void display::float_label(const gamemap::location& loc, const std::string& text,
|
|||
}
|
||||
|
||||
void display::draw_unit(int x, int y, surface image,
|
||||
bool upside_down, double alpha, Uint32 blendto, double blend_ratio, double submerged,
|
||||
bool upside_down, fixed_t alpha, Uint32 blendto, double blend_ratio, double submerged,
|
||||
surface ellipse_back, surface ellipse_front)
|
||||
{
|
||||
//calculate the y position of the ellipse. It should be the same as the y position of the image, unless
|
||||
//the image is partially submerged, in which case the ellipse should appear to float 'on top of' the water
|
||||
const int ellipse_ypos = y - (ellipse_back != NULL && submerged > 0.0 ? int(double(ellipse_back->h)*submerged) : 0)/2;
|
||||
if(ellipse_back != NULL) {
|
||||
draw_unit(x,ellipse_ypos,ellipse_back,false,blendto == 0 ? alpha : 1.0,0,0.0);
|
||||
draw_unit(x,ellipse_ypos,ellipse_back,false,blendto == 0 ? alpha : ftofxp(1.0),0,0.0);
|
||||
}
|
||||
|
||||
surface surf(image);
|
||||
|
@ -1862,11 +1862,11 @@ void display::draw_unit(int x, int y, surface image,
|
|||
if(blend_ratio != 0) {
|
||||
surf = blend_surface(surf, blend_ratio, blendto);
|
||||
}
|
||||
if(alpha > 1.0) {
|
||||
if(alpha > ftofxp(1.0)) {
|
||||
surf = brighten_image(surf,alpha);
|
||||
//} else if(alpha != 1.0 && blendto != 0) {
|
||||
// surf.assign(blend_surface(surf,1.0-alpha,blendto));
|
||||
} else if(alpha != 1.0) {
|
||||
} else if(alpha != ftofxp(1.0)) {
|
||||
surf = adjust_surface_alpha(surf,alpha);
|
||||
}
|
||||
|
||||
|
@ -1882,7 +1882,7 @@ void display::draw_unit(int x, int y, surface image,
|
|||
blit_surface(x,y,surf,&srcrect,&clip_rect);
|
||||
|
||||
if(submerge_height != surf->h) {
|
||||
surf.assign(adjust_surface_alpha(surf,0.2));
|
||||
surf.assign(adjust_surface_alpha(surf,ftofxp(0.2)));
|
||||
|
||||
srcrect.y = submerge_height;
|
||||
srcrect.h = surf->h-submerge_height;
|
||||
|
@ -1892,7 +1892,7 @@ void display::draw_unit(int x, int y, surface image,
|
|||
}
|
||||
|
||||
if(ellipse_front != NULL) {
|
||||
draw_unit(x,ellipse_ypos,ellipse_front,false,blendto == 0 ? alpha : 1.0,0,0.0);
|
||||
draw_unit(x,ellipse_ypos,ellipse_front,false,blendto == 0 ? alpha : ftofxp(1.0),0,0.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2081,7 +2081,7 @@ void display::set_grid(bool grid)
|
|||
grid_ = grid;
|
||||
}
|
||||
|
||||
void display::debug_highlight(const gamemap::location& loc, double amount)
|
||||
void display::debug_highlight(const gamemap::location& loc, fixed_t amount)
|
||||
{
|
||||
wassert(game_config::debug);
|
||||
debugHighlights_[loc] += amount;
|
||||
|
|
|
@ -176,7 +176,7 @@ public:
|
|||
//alpha controls how faded the unit is. If blend_to is not 0, then the
|
||||
//unit will be alpha-blended to blend_to instead of the background colour
|
||||
void draw_tile(int x, int y, surface unit_image=surface(NULL),
|
||||
double alpha=1.0, Uint32 blend_to=0);
|
||||
fixed_t alpha=ftofxp(1.0), Uint32 blend_to=0);
|
||||
|
||||
//function to float a label above a tile
|
||||
void float_label(const gamemap::location& loc, const std::string& text,
|
||||
|
@ -189,7 +189,7 @@ private:
|
|||
void draw_terrain_on_tile(int x, int y, image::TYPE image_type, ADJACENT_TERRAIN_TYPE type);
|
||||
|
||||
void draw_unit_on_tile(int x, int y, surface unit_image=surface(NULL),
|
||||
double alpha=1.0, Uint32 blend_to=0);
|
||||
fixed_t alpha=ftofxp(1.0), Uint32 blend_to=0);
|
||||
|
||||
void draw_halo_on_tile(int x, int y);
|
||||
|
||||
|
@ -287,7 +287,7 @@ public:
|
|||
|
||||
//a debug highlight draws a cross on a tile to emphasize something there.
|
||||
//it is used in debug mode, typically to show AI plans.
|
||||
static void debug_highlight(const gamemap::location& loc, double amount);
|
||||
static void debug_highlight(const gamemap::location& loc, fixed_t amount);
|
||||
static void clear_debug_highlights();
|
||||
|
||||
//function which returns true if location (x,y) is covered in shroud.
|
||||
|
@ -328,7 +328,7 @@ public:
|
|||
//submerged: the amount of the unit out of 1.0 that is submerged
|
||||
// (presumably under water) and thus shouldn't be drawn
|
||||
void draw_unit(int x, int y, surface image,
|
||||
bool upside_down=false,double alpha=1.0,
|
||||
bool upside_down=false,fixed_t alpha=ftofxp(1.0),
|
||||
Uint32 blendto=0, double blend_ratio=0,
|
||||
double submerged=0.0,
|
||||
surface ellipse_back=surface(NULL),
|
||||
|
@ -399,7 +399,7 @@ private:
|
|||
|
||||
unit_map& units_;
|
||||
|
||||
void draw_bar(const std::string& image, int xpos, int ypos, size_t height, double filled, const SDL_Color& col, double alpha);
|
||||
void draw_bar(const std::string& image, int xpos, int ypos, size_t height, double filled, const SDL_Color& col, fixed_t alpha);
|
||||
|
||||
//function which finds the start and end rows on the energy bar image
|
||||
//where white pixels are substituted for the colour of the energy
|
||||
|
@ -452,7 +452,7 @@ private:
|
|||
|
||||
//used to store any unit that is dying
|
||||
gamemap::location deadUnit_;
|
||||
double deadAmount_;
|
||||
fixed_t deadAmount_;
|
||||
|
||||
//used to store any unit that is advancing
|
||||
gamemap::location advancingUnit_;
|
||||
|
@ -497,7 +497,7 @@ private:
|
|||
halo_map haloes_;
|
||||
|
||||
//for debug mode
|
||||
static std::map<gamemap::location,double> debugHighlights_;
|
||||
static std::map<gamemap::location,fixed_t> debugHighlights_;
|
||||
|
||||
std::set<gamemap::location> highlighted_locations_;
|
||||
|
||||
|
|
|
@ -841,7 +841,7 @@ surface floating_label::create_surface()
|
|||
} else {
|
||||
surface background = font::render_text(get_font(font_size_), text_, font::BLACK_COLOUR, 0);
|
||||
background = blur_surface(background,4);
|
||||
background = adjust_surface_alpha(background, 4);
|
||||
background = adjust_surface_alpha(background, ftofxp(4.0));
|
||||
|
||||
surf_.assign(background);
|
||||
}
|
||||
|
|
|
@ -464,13 +464,13 @@ surface get_greyed(const locator i_locator, COLOUR_ADJUSTMENT adj)
|
|||
surface get_brightened(const locator i_locator, COLOUR_ADJUSTMENT adj)
|
||||
{
|
||||
surface image(get_image(i_locator, SCALED, adj));
|
||||
return surface(brighten_image(image, 1.5));
|
||||
return surface(brighten_image(image, ftofxp(1.5)));
|
||||
}
|
||||
|
||||
surface get_semi_brightened(const locator i_locator, COLOUR_ADJUSTMENT adj)
|
||||
{
|
||||
surface image(get_image(i_locator, SCALED, adj));
|
||||
return surface(brighten_image(image, 1.25));
|
||||
return surface(brighten_image(image, ftofxp(1.25)));
|
||||
}
|
||||
|
||||
surface get_image(const image::locator& i_locator, TYPE type, COLOUR_ADJUSTMENT adj)
|
||||
|
|
|
@ -143,10 +143,8 @@ surface scale_surface(surface const &surf, int w, int h)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
const double xratio = static_cast<double>(surf->w)/
|
||||
static_cast<double>(w);
|
||||
const double yratio = static_cast<double>(surf->h)/
|
||||
static_cast<double>(h);
|
||||
const fixed_t xratio = fxpdiv(surf->w,w);
|
||||
const fixed_t yratio = fxpdiv(surf->h,h);
|
||||
|
||||
{
|
||||
surface_lock src_lock(src);
|
||||
|
@ -155,12 +153,12 @@ surface scale_surface(surface const &surf, int w, int h)
|
|||
Uint32* const src_pixels = reinterpret_cast<Uint32*>(src_lock.pixels());
|
||||
Uint32* const dst_pixels = reinterpret_cast<Uint32*>(dst_lock.pixels());
|
||||
|
||||
double ysrc = 0.0;
|
||||
fixed_t ysrc = ftofxp(0.0);
|
||||
for(int ydst = 0; ydst != h; ++ydst, ysrc += yratio) {
|
||||
double xsrc = 0.0;
|
||||
fixed_t xsrc = ftofxp(0.0);
|
||||
for(int xdst = 0; xdst != w; ++xdst, xsrc += xratio) {
|
||||
const int xsrcint = static_cast<int>(xsrc);
|
||||
const int ysrcint = static_cast<int>(ysrc);
|
||||
const int xsrcint = fxptoi(xsrc);
|
||||
const int ysrcint = fxptoi(ysrc);
|
||||
|
||||
dst_pixels[ydst*dst->w + xdst] = src_pixels[ysrcint*src->w + xsrcint];
|
||||
}
|
||||
|
@ -320,7 +318,7 @@ surface greyscale_image(surface const &surf)
|
|||
return create_optimized_surface(nsurf);
|
||||
}
|
||||
|
||||
surface brighten_image(surface const &surf, double amount)
|
||||
surface brighten_image(surface const &surf, fixed_t amount)
|
||||
{
|
||||
if(surf == NULL) {
|
||||
return NULL;
|
||||
|
@ -338,13 +336,14 @@ surface brighten_image(surface const &surf, double amount)
|
|||
Uint32* beg = lock.pixels();
|
||||
Uint32* end = beg + nsurf->w*surf->h;
|
||||
|
||||
if (amount < 0) amount = 0;
|
||||
while(beg != end) {
|
||||
Uint8 red, green, blue, alpha;
|
||||
SDL_GetRGBA(*beg,nsurf->format,&red,&green,&blue,&alpha);
|
||||
|
||||
red = Uint8(minimum<double>(maximum<double>(double(red) * amount,0.0),255.0));
|
||||
green = Uint8(minimum<double>(maximum<double>(double(green) * amount,0.0),255.0));
|
||||
blue = Uint8(minimum<double>(maximum<double>(double(blue) * amount,0.0),255.0));
|
||||
red = minimum<unsigned>(unsigned(fxpmult(red,amount)),255);
|
||||
green = minimum<unsigned>(unsigned(fxpmult(green,amount)),255);
|
||||
blue = minimum<unsigned>(unsigned(fxpmult(blue,amount)),255);
|
||||
|
||||
*beg = SDL_MapRGBA(nsurf->format,red,green,blue,alpha);
|
||||
|
||||
|
@ -355,7 +354,7 @@ surface brighten_image(surface const &surf, double amount)
|
|||
return create_optimized_surface(nsurf);
|
||||
}
|
||||
|
||||
surface adjust_surface_alpha(surface const &surf, double amount)
|
||||
surface adjust_surface_alpha(surface const &surf, fixed_t amount)
|
||||
{
|
||||
if(surf== NULL) {
|
||||
return NULL;
|
||||
|
@ -373,11 +372,12 @@ surface adjust_surface_alpha(surface const &surf, double amount)
|
|||
Uint32* beg = lock.pixels();
|
||||
Uint32* end = beg + nsurf->w*surf->h;
|
||||
|
||||
if (amount < 0) amount = 0;
|
||||
while(beg != end) {
|
||||
Uint8 red, green, blue, alpha;
|
||||
SDL_GetRGBA(*beg,nsurf->format,&red,&green,&blue,&alpha);
|
||||
|
||||
alpha = Uint8(minimum<double>(maximum<double>(double(alpha) * amount,0.0),255.0));
|
||||
alpha = minimum<unsigned>(unsigned(fxpmult(alpha,amount)),255);
|
||||
|
||||
*beg = SDL_MapRGBA(nsurf->format,red,green,blue,alpha);
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#define SDL_UTILS_INCLUDED
|
||||
|
||||
#include "scoped_resource.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
|
@ -103,9 +104,9 @@ surface scale_surface(surface const &surf, int w, int h);
|
|||
surface scale_surface_blended(surface const &surf, int w, int h);
|
||||
surface adjust_surface_colour(surface const &surf, int r, int g, int b);
|
||||
surface greyscale_image(surface const &surf);
|
||||
surface brighten_image(surface const &surf, double amount);
|
||||
surface brighten_image(surface const &surf, fixed_t amount);
|
||||
surface get_surface_portion(surface const &surf, SDL_Rect &rect);
|
||||
surface adjust_surface_alpha(surface const &surf, double amount);
|
||||
surface adjust_surface_alpha(surface const &surf, fixed_t amount);
|
||||
surface adjust_surface_alpha_add(surface const &surf, int amount);
|
||||
surface mask_surface(surface const &surf, surface const &mask);
|
||||
surface blur_surface(surface const &surf, int depth = 1);
|
||||
|
|
|
@ -236,7 +236,7 @@ bool unit::unrenamable() const
|
|||
return unrenamable_;
|
||||
}
|
||||
|
||||
double unit::alpha() const
|
||||
fixed_t unit::alpha() const
|
||||
{
|
||||
return type().alpha();
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
int side() const;
|
||||
unit_race::GENDER gender() const;
|
||||
void set_side(int new_side);
|
||||
double alpha() const;
|
||||
fixed_t alpha() const;
|
||||
void make_recruiter();
|
||||
bool can_recruit() const;
|
||||
int total_movement() const;
|
||||
|
|
|
@ -107,7 +107,7 @@ void move_unit_between(display& disp, const gamemap& map, const gamemap::locatio
|
|||
for(int tile = 0; tile != 6; ++tile) {
|
||||
disp.draw_tile(src_adjacent[tile].x, src_adjacent[tile].y);
|
||||
}
|
||||
disp.draw_unit(xsrc,ysrc,image,false, 1.0, 0, 0.0, src_submerge);
|
||||
disp.draw_unit(xsrc,ysrc,image,false, ftofxp(1.0), 0, 0.0, src_submerge);
|
||||
disp.update_display();
|
||||
events::pump();
|
||||
teleport_animation.update_current_frames();
|
||||
|
@ -157,7 +157,7 @@ void move_unit_between(display& disp, const gamemap& map, const gamemap::locatio
|
|||
const double submerge = src_submerge + (dst_submerge - src_submerge) * i / nsteps;
|
||||
const int xpos = xloc;
|
||||
const int ypos = yloc - height_adjust;
|
||||
disp.draw_unit(xpos, ypos, image, false, 1.0, 0, 0.0, submerge);
|
||||
disp.draw_unit(xpos, ypos, image, false, ftofxp(1.0), 0, 0.0, submerge);
|
||||
|
||||
if (halo_effect != 0) {
|
||||
int d = disp.hex_size() / 2;
|
||||
|
@ -202,7 +202,7 @@ void move_unit_between(display& disp, const gamemap& map, const gamemap::locatio
|
|||
for(int tile = 0; tile != 6; ++tile) {
|
||||
disp.draw_tile(dst_adjacent[tile].x,dst_adjacent[tile].y);
|
||||
}
|
||||
disp.draw_unit(xdst, ydst, image, false, 1.0, 0, 0.0, dst_submerge);
|
||||
disp.draw_unit(xdst, ydst, image, false, ftofxp(1.0), 0, 0.0, dst_submerge);
|
||||
disp.update_display();
|
||||
events::pump();
|
||||
teleport_animation.update_current_frames();
|
||||
|
@ -280,7 +280,7 @@ void unit_die(display& disp, const gamemap::location& loc, const unit& u)
|
|||
const int frame_time = 30;
|
||||
int ticks = SDL_GetTicks();
|
||||
|
||||
for(double alpha = 1.0; alpha > 0.0; alpha -= 0.05) {
|
||||
for(fixed_t alpha = ftofxp(1.0); alpha > ftofxp(0.0); alpha -= ftofxp(0.05)) {
|
||||
disp.draw_tile(loc.x,loc.y,NULL,alpha);
|
||||
|
||||
const int wait_time = ticks + frame_time - SDL_GetTicks();
|
||||
|
@ -293,7 +293,7 @@ void unit_die(display& disp, const gamemap::location& loc, const unit& u)
|
|||
disp.update_display();
|
||||
}
|
||||
|
||||
disp.draw_tile(loc.x,loc.y,NULL,0.0);
|
||||
disp.draw_tile(loc.x,loc.y,NULL,ftofxp(0.0));
|
||||
disp.update_display();
|
||||
}
|
||||
|
||||
|
@ -438,7 +438,7 @@ bool unit_attack_ranged(display& disp, unit_map& units,
|
|||
}
|
||||
|
||||
Uint32 defensive_colour = 0;
|
||||
double defensive_alpha = 1.0;
|
||||
fixed_t defensive_alpha = ftofxp(1.0);
|
||||
|
||||
LOG_DP << "Waiting for missile impact at " << missile_impact << "\n";
|
||||
if(damage > 0 && animation_time >= missile_impact) {
|
||||
|
@ -450,7 +450,7 @@ bool unit_attack_ranged(display& disp, unit_map& units,
|
|||
}
|
||||
|
||||
if(flash_num == 0 || flash_num == 2) {
|
||||
defensive_alpha = 0.0;
|
||||
defensive_alpha = ftofxp(0.0);
|
||||
defensive_colour = disp.rgb(200,0,0);
|
||||
}
|
||||
|
||||
|
@ -728,7 +728,7 @@ bool unit_attack(display& disp, unit_map& units, const gamemap& map,
|
|||
}
|
||||
|
||||
Uint32 defender_colour = 0;
|
||||
double defender_alpha = 1.0;
|
||||
fixed_t defender_alpha = ftofxp(1.0);
|
||||
|
||||
if(damage > 0 && animation_time >= 0 && shown_label == false) {
|
||||
shown_label = true;
|
||||
|
@ -744,7 +744,7 @@ bool unit_attack(display& disp, unit_map& units, const gamemap& map,
|
|||
}
|
||||
|
||||
if(flash_num == 0 || flash_num == 2) {
|
||||
defender_alpha = 0.0;
|
||||
defender_alpha = ftofxp(0.0);
|
||||
defender_colour = disp.rgb(200,0,0);
|
||||
}
|
||||
|
||||
|
@ -808,7 +808,7 @@ bool unit_attack(display& disp, unit_map& units, const gamemap& map,
|
|||
const double submerge = src_submerge*pos + dst_submerge*(1.0-pos);
|
||||
|
||||
if(image != NULL && !hide) {
|
||||
disp.draw_unit(posx, posy - height_adjust, image, false, 1.0, 0, 0.0, submerge);
|
||||
disp.draw_unit(posx, posy - height_adjust, image, false, ftofxp(1.0), 0, 0.0, submerge);
|
||||
}
|
||||
|
||||
const int wait_time = ticks + time_resolution - SDL_GetTicks();
|
||||
|
|
|
@ -549,7 +549,7 @@ unit_type::unit_type(const unit_type& o)
|
|||
|
||||
unit_type::unit_type(const config& cfg, const movement_type_map& mv_types,
|
||||
const race_map& races, const std::vector<config*>& traits)
|
||||
: cfg_(cfg), alpha_(1.0), movementType_(cfg), possibleTraits_(traits)
|
||||
: cfg_(cfg), alpha_(ftofxp(1.0)), movementType_(cfg), possibleTraits_(traits)
|
||||
{
|
||||
const config::child_list& variations = cfg.get_children("variation");
|
||||
for(config::child_list::const_iterator var = variations.begin(); var != variations.end(); ++var) {
|
||||
|
@ -619,7 +619,7 @@ unit_type::unit_type(const config& cfg, const movement_type_map& mv_types,
|
|||
|
||||
const std::string& alpha_blend = cfg_["alpha"];
|
||||
if(alpha_blend.empty() == false) {
|
||||
alpha_ = atof(alpha_blend.c_str());
|
||||
alpha_ = ftofxp(atof(alpha_blend.c_str()));
|
||||
}
|
||||
|
||||
const std::string& move_type = cfg_["movement_type"];
|
||||
|
@ -913,7 +913,7 @@ const char* unit_type::alignment_id(unit_type::ALIGNMENT align)
|
|||
return (aligns[align]);
|
||||
}
|
||||
|
||||
double unit_type::alpha() const
|
||||
fixed_t unit_type::alpha() const
|
||||
{
|
||||
return alpha_;
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ public:
|
|||
static const char* alignment_description(ALIGNMENT align);
|
||||
static const char* alignment_id(ALIGNMENT align);
|
||||
|
||||
double alpha() const;
|
||||
fixed_t alpha() const;
|
||||
|
||||
const std::vector<std::string>& abilities() const;
|
||||
|
||||
|
@ -257,7 +257,7 @@ private:
|
|||
|
||||
const unit_race* race_;
|
||||
|
||||
double alpha_;
|
||||
fixed_t alpha_;
|
||||
|
||||
std::vector<std::string> abilities_;
|
||||
|
||||
|
|
26
src/util.hpp
26
src/util.hpp
|
@ -85,4 +85,30 @@ void push_back(T& str, C c)
|
|||
str[str.size()-1] = c;
|
||||
}
|
||||
|
||||
#if 1
|
||||
# include <SDL_types.h>
|
||||
typedef Sint32 fixed_t;
|
||||
# define fxp_shift 8
|
||||
# define fxp_base (1 << fxp_shift)
|
||||
|
||||
// IN: float or int - OUT: fixed_t
|
||||
# define ftofxp(x) (fixed_t((x) * fxp_base))
|
||||
|
||||
// IN: unsigned and fixed_t - OUT: unsigned
|
||||
# define fxpmult(x,y) (((x)*(y)) >> fxp_shift)
|
||||
|
||||
// IN: unsigned and int - OUT: fixed_t
|
||||
# define fxpdiv(x,y) (((x) << fxp_shift) / (y))
|
||||
|
||||
// IN: fixed_t - OUT: int
|
||||
# define fxptoi(x) ( ((x)>0) ? ((x) >> fxp_shift) : (-((-(x)) >> fxp_shift)) )
|
||||
|
||||
#else
|
||||
typedef float fixed_t;
|
||||
# define ftofxp(x) (x)
|
||||
# define fxpmult(x,y) ((x)*(y))
|
||||
# define fxpdiv(x,y) (static_cast<float>(x) / static_cast<float>(y))
|
||||
# define fxptoi(x) ( static_cast<int>(x) )
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue