/[hegemonie]/hegemonie/Map/Display/MapShadows.m
ViewVC logotype

Diff of /hegemonie/Map/Display/MapShadows.m

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by daniel, Wed Aug 27 21:45:57 2003 UTC revision 1.8 by gabby, Thu Sep 4 21:11:08 2003 UTC
# Line 173  Line 173 
173  /**  /**
174   * Initialize the shadow field from a sun position.   * Initialize the shadow field from a sun position.
175   * The sun must be beyond the map.   * The sun must be beyond the map.
176     * The values are between 9 and 17 if we have to make a shadow ,
177     * or <= 8 if no shadows.
178     * (bit shift >> 3 to have value between 1.125 and 2.125)
179   */   */
180  - (void) _initWithSun: (coord_t)sun  - (void) _initWithSun: (coord_t)sun
181  {  {
182    /* FIXME - test sun position */    /* FIXME - test sun position */
183    NSParameterAssert (sun.y > 256);    /* calculs are faster with a sun height > 256 */
184      NSParameterAssert (sun.y >= 0);
185    
186    int z;    int x, z;
187      for (z = 0; z < _zLength; z++)
188        for (x = 0; x < _xLength; x++)
189          {
190            *[self _shadowFieldAtPosition: MakeMapCoord (x, z)] = 0;
191          }
192    
193      int x_, z_;
194    for (z = 0; z < _zLength; z++)    for (z = 0; z < _zLength; z++)
195      {      {
       int x;  
196        for (x = 0; x < _xLength; x++)        for (x = 0; x < _xLength; x++)
197          {          {
198            coord_t pos            coord_t pos
# Line 190  Line 200 
200    
201            if ([self _bresenham3DFromPoint: pos            if ([self _bresenham3DFromPoint: pos
202                                    toPoint: sun])                                    toPoint: sun])
203              *[self _shadowFieldAtPosition: MakeMapCoord (x, z)] = 1;              {
204            else                if (*[self _shadowFieldAtPosition: MakeMapCoord (x, z)] <= 8)
205              *[self _shadowFieldAtPosition: MakeMapCoord (x, z)] = 0;                  *[self _shadowFieldAtPosition: MakeMapCoord (x, z)] += 8;
206                  
207                  for (x_ = -1; x_ <= 1; x_++)
208                    for (z_ = -1; z_ <= 1; z_++)
209                      *[self _shadowFieldAtPosition:
210                               MakeMapCoord (MOD (x + x_, _xLength),
211                                             MOD (z + z_, _zLength))] += 1;
212                }
213          }          }
214    
215        double val = (double) z / (double) _zLength * 100.0;        double val = (double) z / (double) _zLength * 100.0;
# Line 239  Line 256 
256        [self _initWithSun: sun];        [self _initWithSun: sun];
257      }      }
258    
259      RELEASE(_land);
260    return self;    return self;
261  }  }
262    
263  - (void) dealloc  - (void) dealloc
264  {  {
   RELEASE(_land);  
265    RELEASE(_image);    RELEASE(_image);
266    
267    [super dealloc];    [super dealloc];
268  }  }
269    
270  /**  /**
271   * Return YES if we have to make a shadow for the position.   * Return a value between 9 and 17 if we have to make a shadow for the
272     * position, or 0 if no shadows.
273     * (bit shift >> 3 to have value between 1.125 and 2.125)
274   * The position parameter must be contained in the map coordinates.   * The position parameter must be contained in the map coordinates.
275   */   */
276  - (BOOL) shadowAtPoint: (map_coord_t)position  - (u_int8_t) shadowAtPoint: (map_coord_t)position
277  {  {
278    return *[self _shadowFieldAtPosition: position];    return *[self _shadowFieldAtPosition: position];
279  }  }

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26