wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth ./changelog src/actions.cpp src/display...


From: Yann Dirson
Subject: [Wesnoth-cvs-commits] wesnoth ./changelog src/actions.cpp src/display...
Date: Wed, 09 Feb 2005 18:32:01 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Yann Dirson <address@hidden>    05/02/09 23:32:01

Modified files:
        .              : changelog 
        src            : actions.cpp display.cpp display.hpp font.cpp 
                         image.cpp sdl_utils.cpp sdl_utils.hpp unit.cpp 
                         unit.hpp unit_display.cpp unit_types.cpp 
                         unit_types.hpp util.hpp 

Log message:
        use fixed-point computations so owners of FPU-less machines can still 
enjoy the game

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/changelog.diff?tr1=1.486&tr2=1.487&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/actions.cpp.diff?tr1=1.189&tr2=1.190&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/display.cpp.diff?tr1=1.288&tr2=1.289&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/display.hpp.diff?tr1=1.92&tr2=1.93&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/font.cpp.diff?tr1=1.97&tr2=1.98&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/image.cpp.diff?tr1=1.75&tr2=1.76&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/sdl_utils.cpp.diff?tr1=1.71&tr2=1.72&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/sdl_utils.hpp.diff?tr1=1.51&tr2=1.52&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit.cpp.diff?tr1=1.120&tr2=1.121&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit.hpp.diff?tr1=1.59&tr2=1.60&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit_display.cpp.diff?tr1=1.50&tr2=1.51&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit_types.cpp.diff?tr1=1.77&tr2=1.78&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit_types.hpp.diff?tr1=1.57&tr2=1.58&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/util.hpp.diff?tr1=1.20&tr2=1.21&r1=text&r2=text

Patches:
Index: wesnoth/changelog
diff -u wesnoth/changelog:1.486 wesnoth/changelog:1.487
--- wesnoth/changelog:1.486     Wed Feb  9 21:30:06 2005
+++ wesnoth/changelog   Wed Feb  9 23:32:00 2005
@@ -3,7 +3,10 @@
   * 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 @@
  * 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
Index: wesnoth/src/actions.cpp
diff -u wesnoth/src/actions.cpp:1.189 wesnoth/src/actions.cpp:1.190
--- wesnoth/src/actions.cpp:1.189       Thu Feb  3 19:37:29 2005
+++ wesnoth/src/actions.cpp     Wed Feb  9 23:32:01 2005
@@ -1,4 +1,4 @@
-/* $Id: actions.cpp,v 1.189 2005/02/03 19:37:29 silene Exp $ */
+/* $Id: actions.cpp,v 1.190 2005/02/09 23:32:01 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -142,7 +142,7 @@
 
        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 @@
 
                        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 @@
 
                        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);
 
Index: wesnoth/src/display.cpp
diff -u wesnoth/src/display.cpp:1.288 wesnoth/src/display.cpp:1.289
--- wesnoth/src/display.cpp:1.288       Sun Feb  6 14:05:02 2005
+++ wesnoth/src/display.cpp     Wed Feb  9 23:32:01 2005
@@ -1,4 +1,4 @@
-/* $Id: display.cpp,v 1.288 2005/02/06 14:05:02 silene Exp $ */
+/* $Id: display.cpp,v 1.289 2005/02/09 23:32:01 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -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 @@
        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 @@
                        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_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 @@
                        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 @@
                          
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_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 @@
                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 @@
 
        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_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 @@
                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::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 @@
        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 @@
        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 @@
        }
 
        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 @@
        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;
Index: wesnoth/src/display.hpp
diff -u wesnoth/src/display.hpp:1.92 wesnoth/src/display.hpp:1.93
--- wesnoth/src/display.hpp:1.92        Sun Feb  6 10:40:12 2005
+++ wesnoth/src/display.hpp     Wed Feb  9 23:32:01 2005
@@ -1,4 +1,4 @@
-/* $Id: display.hpp,v 1.92 2005/02/06 10:40:12 isaaccp Exp $ */
+/* $Id: display.hpp,v 1.93 2005/02/09 23:32:01 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -176,7 +176,7 @@
        //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 @@
        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 @@
 
        //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 @@
        //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 @@
 
        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 @@
 
        //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 @@
        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_;
 
Index: wesnoth/src/font.cpp
diff -u wesnoth/src/font.cpp:1.97 wesnoth/src/font.cpp:1.98
--- wesnoth/src/font.cpp:1.97   Sat Jan  8 21:49:29 2005
+++ wesnoth/src/font.cpp        Wed Feb  9 23:32:01 2005
@@ -1,4 +1,4 @@
-/* $Id: font.cpp,v 1.97 2005/01/08 21:49:29 silene Exp $ */
+/* $Id: font.cpp,v 1.98 2005/02/09 23:32:01 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -841,7 +841,7 @@
                } 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);
                }
Index: wesnoth/src/image.cpp
diff -u wesnoth/src/image.cpp:1.75 wesnoth/src/image.cpp:1.76
--- wesnoth/src/image.cpp:1.75  Tue Feb  8 21:12:22 2005
+++ wesnoth/src/image.cpp       Wed Feb  9 23:32:01 2005
@@ -464,13 +464,13 @@
 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)
Index: wesnoth/src/sdl_utils.cpp
diff -u wesnoth/src/sdl_utils.cpp:1.71 wesnoth/src/sdl_utils.cpp:1.72
--- wesnoth/src/sdl_utils.cpp:1.71      Sun Jan  9 00:02:52 2005
+++ wesnoth/src/sdl_utils.cpp   Wed Feb  9 23:32:01 2005
@@ -1,4 +1,4 @@
-/* $Id: sdl_utils.cpp,v 1.71 2005/01/09 00:02:52 silene Exp $ */
+/* $Id: sdl_utils.cpp,v 1.72 2005/02/09 23:32:01 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -143,10 +143,8 @@
                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 @@
                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 @@
        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 @@
                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 @@
        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 @@
                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);
 
Index: wesnoth/src/sdl_utils.hpp
diff -u wesnoth/src/sdl_utils.hpp:1.51 wesnoth/src/sdl_utils.hpp:1.52
--- wesnoth/src/sdl_utils.hpp:1.51      Sun Jan  9 00:02:52 2005
+++ wesnoth/src/sdl_utils.hpp   Wed Feb  9 23:32:01 2005
@@ -1,4 +1,4 @@
-/* $Id: sdl_utils.hpp,v 1.51 2005/01/09 00:02:52 silene Exp $ */
+/* $Id: sdl_utils.hpp,v 1.52 2005/02/09 23:32:01 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -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_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);
Index: wesnoth/src/unit.cpp
diff -u wesnoth/src/unit.cpp:1.120 wesnoth/src/unit.cpp:1.121
--- wesnoth/src/unit.cpp:1.120  Sat Jan 22 12:09:36 2005
+++ wesnoth/src/unit.cpp        Wed Feb  9 23:32:01 2005
@@ -1,4 +1,4 @@
-/* $Id: unit.cpp,v 1.120 2005/01/22 12:09:36 silene Exp $ */
+/* $Id: unit.cpp,v 1.121 2005/02/09 23:32:01 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -236,7 +236,7 @@
        return unrenamable_;
 }
 
-double unit::alpha() const
+fixed_t unit::alpha() const
 {
        return type().alpha();
 }
Index: wesnoth/src/unit.hpp
diff -u wesnoth/src/unit.hpp:1.59 wesnoth/src/unit.hpp:1.60
--- wesnoth/src/unit.hpp:1.59   Sun Feb  6 10:40:12 2005
+++ wesnoth/src/unit.hpp        Wed Feb  9 23:32:01 2005
@@ -1,4 +1,4 @@
-/* $Id: unit.hpp,v 1.59 2005/02/06 10:40:12 isaaccp Exp $ */
+/* $Id: unit.hpp,v 1.60 2005/02/09 23:32:01 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -58,7 +58,7 @@
        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;
Index: wesnoth/src/unit_display.cpp
diff -u wesnoth/src/unit_display.cpp:1.50 wesnoth/src/unit_display.cpp:1.51
--- wesnoth/src/unit_display.cpp:1.50   Mon Feb  7 03:44:37 2005
+++ wesnoth/src/unit_display.cpp        Wed Feb  9 23:32:01 2005
@@ -107,7 +107,7 @@
                        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 @@
                        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 @@
                        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 @@
        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 @@
                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 @@
                }
 
                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 @@
                        }
 
                        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 @@
                }
 
                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 @@
                        }
 
                        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 @@
                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();
Index: wesnoth/src/unit_types.cpp
diff -u wesnoth/src/unit_types.cpp:1.77 wesnoth/src/unit_types.cpp:1.78
--- wesnoth/src/unit_types.cpp:1.77     Mon Feb  7 03:44:37 2005
+++ wesnoth/src/unit_types.cpp  Wed Feb  9 23:32:01 2005
@@ -1,4 +1,4 @@
-/* $Id: unit_types.cpp,v 1.77 2005/02/07 03:44:37 Sirp Exp $ */
+/* $Id: unit_types.cpp,v 1.78 2005/02/09 23:32:01 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -549,7 +549,7 @@
 
 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 @@
 
        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 @@
        return (aligns[align]);
 }
 
-double unit_type::alpha() const
+fixed_t unit_type::alpha() const
 {
        return alpha_;
 }
Index: wesnoth/src/unit_types.hpp
diff -u wesnoth/src/unit_types.hpp:1.57 wesnoth/src/unit_types.hpp:1.58
--- wesnoth/src/unit_types.hpp:1.57     Mon Feb  7 03:44:37 2005
+++ wesnoth/src/unit_types.hpp  Wed Feb  9 23:32:01 2005
@@ -1,4 +1,4 @@
-/* $Id: unit_types.hpp,v 1.57 2005/02/07 03:44:37 Sirp Exp $ */
+/* $Id: unit_types.hpp,v 1.58 2005/02/09 23:32:01 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -213,7 +213,7 @@
        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 @@
 
        const unit_race* race_;
 
-       double alpha_;
+       fixed_t alpha_;
 
        std::vector<std::string> abilities_;
 
Index: wesnoth/src/util.hpp
diff -u wesnoth/src/util.hpp:1.20 wesnoth/src/util.hpp:1.21
--- wesnoth/src/util.hpp:1.20   Wed Jan 19 21:40:37 2005
+++ wesnoth/src/util.hpp        Wed Feb  9 23:32:01 2005
@@ -1,4 +1,4 @@
-/* $Id: util.hpp,v 1.20 2005/01/19 21:40:37 silene Exp $ */
+/* $Id: util.hpp,v 1.21 2005/02/09 23:32:01 ydirson Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -85,4 +85,30 @@
        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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]