Author: thonsew
Date: Sat Aug  6 13:32:19 2011
New Revision: 50620

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50620&view=rev
Log:
Fix for bug 18017 FADE_TO_BLACK and local tod don't play nice.  Implemented a 
local per tile color adjustment to go along with the local per tile time of day 
(tod) adjustment, during fades.  Also fixed scaling of tod lightmap, which was 
issuing errors.

Modified:
    trunk/src/display.cpp
    trunk/src/display.hpp
    trunk/src/game_display.cpp
    trunk/src/game_display.hpp
    trunk/src/image_modifications.cpp
    trunk/src/image_modifications.hpp
    trunk/src/tod_manager.hpp

Modified: trunk/src/display.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/display.cpp?rev=50620&r1=50619&r2=50620&view=diff
==============================================================================
--- trunk/src/display.cpp (original)
+++ trunk/src/display.cpp Sat Aug  6 13:32:19 2011
@@ -36,6 +36,8 @@
 #include "time_of_day.hpp"
 #include "tooltips.hpp"
 #include "arrow.hpp"
+#include "tod_manager.hpp"
+#include "resources.hpp"
 
 #include "SDL_image.h"
 
@@ -92,6 +94,9 @@
        turbo_(false),
        invalidateGameStatus_(true),
        map_labels_(new map_labels(*this, 0)),
+       color_adjust_red_(0),
+       color_adjust_green_(0),
+       color_adjust_blue_(0),
        scroll_event_("scrolled"),
        complete_redraw_event_("completely_redrawn"),
        nextDraw_(0),
@@ -159,11 +164,23 @@
 {
 }
 
-const time_of_day& display::get_time_of_day(const map_location& /*loc*/) const
-{
-       static const time_of_day tod;
+const time_of_day & display::get_time_of_day(const map_location& loc) const
+{
+       static time_of_day tod;
+       if(resources::tod_manager != NULL){ tod = 
resources::tod_manager->get_time_of_day(0, loc); }
        return tod;
 }
+
+void display::adjust_colors(int r, int g, int b)
+{
+       const time_of_day& tod = get_time_of_day();
+       image::set_color_adjustment(r + tod.red, g + tod.green, b + tod.blue);
+       color_adjust_red_ = r ;
+       color_adjust_green_ = g ;
+       color_adjust_blue_ = b ;
+}
+
+
 
 void display::fill_images_list(const std::string& prefix, 
std::vector<std::string>& images)
 {
@@ -646,17 +663,16 @@
                std::ostringstream light_trans;
                for(int d=0; d<6; ++d){
                        const time_of_day& atod = get_time_of_day(adjs[d]);
-                       if(atod.red == tod.red && atod.green == tod.green && 
atod.blue == tod.blue)
-                               continue;
+                       if(atod.red == tod.red  &&  atod.green  == tod.green  
&&  atod.blue == tod.blue) { continue; }
 
                        light_trans
                                << "~BLIT("
-                                       << "terrain/light-" << dir[d] << ".png"
-                                       << "~CS("
-                                               << atod.red << ","
-                                               << atod.green << ","
-                                               << atod.blue
-                                       << ")" // CS
+                               << "terrain/light-" << dir[d] << ".png"
+                               << "~CS("
+                               << (atod.red + color_adjust_red_) << ","
+                               << (atod.green + color_adjust_green_) << ","
+                               << (atod.blue + color_adjust_blue_)
+                               << ")" // CS
                                << ")"; //BLIT
                        use_lightmap = true;
                }
@@ -666,27 +682,29 @@
                        //generate the base of the lightmap
                        //and add light transitions on it
                        mod     << "~L("
-                                       << "terrain/light.png"
-                                       << "~CS("
-                                               << tod.red << ","
-                                               << tod.green << ","
-                                               << tod.blue
-                                       << ")" // CS
-                                       << light_trans.str()
+                               << "terrain/light.png"
+                               << "~CS("
+                               << (tod.red  + color_adjust_red_) << ","
+                               << (tod.green  + color_adjust_green_)<< ","
+                               << (tod.blue  + color_adjust_blue_)
+                               << ")" // CS
+                               << light_trans.str()
                                << ")"; // L
                } else {
                        // no light map needed, but still need to color the hex
-                       const time_of_day& global_tod =
-                               get_time_of_day(map_location::null_location);
-                       if(tod.red == global_tod.red && tod.green == 
global_tod.green && tod.blue == global_tod.blue) {
+                       const time_of_day& global_tod = 
get_time_of_day(map_location::null_location);
+                       bool is_same_as_global(tod.red == global_tod.red && 
tod.green == global_tod.green && tod.blue == global_tod.blue);
+                       if(is_same_as_global ) {
                                // It's the same as global ToD, don't use local 
light
                                use_local_light = false;
-                       } else if (tod.red != 0 || tod.green != 0 || tod.blue 
!= 0) {
+                       } else if ((tod.red + color_adjust_red_) != 0 
+                                          || (tod.green + color_adjust_green_) 
!= 0 
+                                          || (tod.blue + color_adjust_blue_) 
!= 0) {
                                // simply color it if needed
                                mod << "~CS("
-                                               << tod.red << ","
-                                               << tod.green << ","
-                                               << tod.blue
+                                       << (tod.red   + color_adjust_red_) << 
","
+                                       << (tod.green   + 
color_adjust_green_)<< ","
+                                       << (tod.blue  + color_adjust_blue_)
                                        << ")"; // CS
                        }
                }

Modified: trunk/src/display.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/display.hpp?rev=50620&r1=50619&r2=50620&view=diff
==============================================================================
--- trunk/src/display.hpp (original)
+++ trunk/src/display.hpp Sat Aug  6 13:32:19 2011
@@ -80,6 +80,16 @@
        static Uint32 max_rgb(Uint32 first,Uint32 second)
                { return 
rgb(std::max(red(first),red(second)),std::max(green(first),green(second)),std::max(blue(first),blue(second)))
 ; }
 
+       /**
+        * Add r,g,b to the colors for all images displayed on the map.
+        *
+        * Used for special effects like flashes.
+        */
+
+       void adjust_colors(int r, int g, int b);
+
+
+
        /** Gets the underlying screen object. */
        CVideo& video() { return screen_; }
 
@@ -454,7 +464,7 @@
         */
        void redraw_minimap() { redrawMinimap_ = true; }
 
-       virtual const time_of_day& get_time_of_day(const map_location& /*loc*/) 
const;
+       virtual const time_of_day& get_time_of_day(const map_location& loc = 
map_location::null_location) const;
 
        virtual bool has_time_area() const {return false;};
 
@@ -558,6 +568,10 @@
        bool turbo_;
        bool invalidateGameStatus_;
        boost::scoped_ptr<map_labels> map_labels_;
+       int color_adjust_red_;
+       int color_adjust_green_;
+       int color_adjust_blue_;
+
 
        /** Event raised when the map is being scrolled */
        mutable events::generic_event scroll_event_;

Modified: trunk/src/game_display.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_display.cpp?rev=50620&r1=50619&r2=50620&view=diff
==============================================================================
--- trunk/src/game_display.cpp (original)
+++ trunk/src/game_display.cpp Sat Aug  6 13:32:19 2011
@@ -197,16 +197,8 @@
 
        first_turn_ = false;
 
-       image::set_color_adjustment(tod.red,tod.green,tod.blue);
-
        invalidate_all();
        draw();
-}
-
-void game_display::adjust_colors(int r, int g, int b)
-{
-       const time_of_day& tod = tod_manager_.get_time_of_day();
-       image::set_color_adjustment(tod.red+r,tod.green+g,tod.blue+b);
 }
 
 void game_display::select_hex(map_location hex)

Modified: trunk/src/game_display.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_display.hpp?rev=50620&r1=50619&r2=50620&view=diff
==============================================================================
--- trunk/src/game_display.hpp (original)
+++ trunk/src/game_display.hpp Sat Aug  6 13:32:19 2011
@@ -55,13 +55,6 @@
         * Should be called on every new turn.
         */
        void new_turn();
-
-       /**
-        * Add r,g,b to the colors for all images displayed on the map.
-        *
-        * Used for special effects like flashes.
-        */
-       void adjust_colors(int r, int g, int b);
 
        /**
         * Scrolls to the leader of a certain side.

Modified: trunk/src/image_modifications.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/image_modifications.cpp?rev=50620&r1=50619&r2=50620&view=diff
==============================================================================
--- trunk/src/image_modifications.cpp (original)
+++ trunk/src/image_modifications.cpp Sat Aug  6 13:32:19 2011
@@ -208,8 +208,13 @@
        return y_;
 }
 
-surface light_modification::operator()(const surface& src) const
-{
+surface light_modification::operator()(const surface& src) const {
+       if(src == NULL) { return NULL; }
+
+       if (src->w != surf_->w) {
+               surf_ = scale_surface(surf_,  src->w, src->h);
+       }
+
        return light_surface(src, surf_);;
 }
 

Modified: trunk/src/image_modifications.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/image_modifications.hpp?rev=50620&r1=50619&r2=50620&view=diff
==============================================================================
--- trunk/src/image_modifications.hpp (original)
+++ trunk/src/image_modifications.hpp Sat Aug  6 13:32:19 2011
@@ -209,7 +209,7 @@
        const surface& get_surface() const;
 
 private:
-       surface surf_;
+       mutable surface surf_;
 };
 
 /**

Modified: trunk/src/tod_manager.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tod_manager.hpp?rev=50620&r1=50619&r2=50620&view=diff
==============================================================================
--- trunk/src/tod_manager.hpp (original)
+++ trunk/src/tod_manager.hpp Sat Aug  6 13:32:19 2011
@@ -15,6 +15,7 @@
 #define TOD_MANAGER_HPP_INCLUDED
 
 #include "map_location.hpp"
+#include "config.hpp"
 #include "time_of_day.hpp"
 #include "savegame_config.hpp"
 
@@ -26,7 +27,7 @@
 class tod_manager : public savegame::savegame_config
 {
        public:
-               tod_manager(const config& scenario_cfg, const int num_turns);
+       explicit tod_manager(const config& scenario_cfg = config(), const int 
num_turns = -1);
                ~tod_manager() {}
                tod_manager& operator=(const tod_manager& manager);
 


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to