mail[Wesnoth-commits] r44100 - in /trunk/src: builder.cpp builder.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by alinktomine on July 11, 2010 - 06:28:
Author: alink
Date: Sun Jul 11 06:28:07 2010
New Revision: 44100

URL: http://svn.gna.org/viewcvs/wesnoth?rev=44100&view=rev
Log:
Improve random start of animation
This fix a rare synchronization in the top half-hexes and prevent unwanted
synchronization between different rules. Also needed for future plans.

Modified:
    trunk/src/builder.cpp
    trunk/src/builder.hpp

Modified: trunk/src/builder.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/builder.cpp?rev=44100&r1=44099&r2=44100&view=diff
==============================================================================
--- trunk/src/builder.cpp (original)
+++ trunk/src/builder.cpp Sun Jul 11 06:28:07 2010
@@ -67,8 +67,7 @@
        images(),
        images_foreground(),
        images_background(),
-       last_tod("invalid_tod"),
-       rand_seed(rand())
+       last_tod("invalid_tod")
 {}
 
 void terrain_builder::tile::add_image_to_cache(const std::string &tod, 
ordered_ri_list::const_iterator itor)
@@ -114,10 +113,17 @@
 {
        flags.clear();
        images.clear();
-       rand_seed=rand();
        images_foreground.clear();
        images_background.clear();
        last_tod = "invalid_tod";
+}
+
+static unsigned int get_noise(const map_location& loc, unsigned int index){
+       unsigned int a = (loc.x + 92872973) ^ 918273;
+       unsigned int b = (loc.y + 1672517) ^ 128123;
+       unsigned int c = (index + 127390) ^ 13923787;
+       unsigned int abc = a*b*c + a*b + b*c + a*c + a + b + c;
+       return abc*abc;
 }
 
 void terrain_builder::tilemap::reset()
@@ -907,12 +913,7 @@
        }
 
        if(rule.probability != -1) {
-               unsigned int a = (loc.x + 92872973) ^ 918273;
-               unsigned int b = (loc.y + 1672517) ^ 128123;
-               unsigned int c = (rule_index + 127390) ^ 13923787;
-               unsigned int abc = a*b*c + a*b + b*c + a*c + a + b + c;
-               unsigned int random = (abc*abc) % 100;
-
+               unsigned int random = get_noise(loc, rule_index) % 100;
                if(random > static_cast<unsigned int>(rule.probability)) {
                        return false;
                }
@@ -958,9 +959,9 @@
        return true;
 }
 
-void terrain_builder::apply_rule(const terrain_builder::building_rule &rule, 
const map_location &loc)
-{
-       int rand_seed = tile_map_.on_map(loc) ? tile_map_[loc].rand_seed : 0;
+void terrain_builder::apply_rule(const terrain_builder::building_rule &rule, 
const map_location &loc, const int rule_index)
+{
+       unsigned int rand_seed = get_noise(loc, rule_index);
 
        for(constraint_set::const_iterator constraint = 
rule.constraints.begin();
                        constraint != rule.constraints.end(); ++constraint) {
@@ -1060,7 +1061,7 @@
                                const map_location loc = 
itor->legacy_difference(min_constraint->second.loc);
 
                                if(rule_matches(rule, loc, rule_index, 
min_constraint)) {
-                                       apply_rule(rule, loc);
+                                       apply_rule(rule, loc, rule_index);
                                }
                        }
                }

Modified: trunk/src/builder.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/builder.hpp?rev=44100&r1=44099&r2=44100&view=diff
==============================================================================
--- trunk/src/builder.hpp (original)
+++ trunk/src/builder.hpp Sun Jul 11 06:28:07 2010
@@ -257,7 +257,7 @@
        struct tile
        {
                /** An ordered rule_image list */
-               typedef std::multimap<int,std::pair<int, const rule_image*> > 
ordered_ri_list;
+               typedef std::multimap<int,std::pair<unsigned int, const 
rule_image*> > ordered_ri_list;
 
                /** Contructor for the tile() structure */
                tile();
@@ -306,10 +306,6 @@
                 * The time-of-day to which the image caches correspond.
                 */
                std::string last_tod;
-               /**
-                 * Unique random number used to start all animations 
originating from this tile
-                 */
-               int rand_seed;
 
        };
 
@@ -720,8 +716,9 @@
         *
         * @param rule      The rule to apply
         * @param loc       The location to which to apply the rule.
-        */
-       void apply_rule(const building_rule &rule, const map_location &loc);
+        * @param rule_index The index of the rule used for seed generation
+        */
+       void apply_rule(const building_rule &rule, const map_location &loc, 
const int rule_index);
 
        /**
         * Calculates the list of terrains, and fills the tile_map_ member,




Related Messages


Powered by MHonArc, Updated Sun Jul 11 06:40:12 2010