Atrinik Client  4.0
Data Structures | Typedefs | Functions | Variables
tilestretcher.c File Reference
#include <global.h>

Go to the source code of this file.

Data Structures

struct  line_and_slope
 

Typedefs

typedef struct line_and_slope line_and_slope
 

Functions

static void determine_line (line_and_slope *dest, int sx, int sy, int ex, int ey)
 
static void determine_lines (line_and_slope *dest, int n, int e, int s, int w)
 
int tilestretcher_coords_in_tile (uint32_t stretch, int x, int y)
 
int add_color_to_surface (SDL_Surface *dest, Uint8 red, Uint8 green, Uint8 blue)
 
void copy_pixel_to_pixel (SDL_Surface *src, SDL_Surface *dest, int x, int y, int x2, int y2, double brightness)
 
void copy_vertical_line (SDL_Surface *src, SDL_Surface *dest, int src_x, int src_sy, int src_ey, int dest_x, int dest_sy, int dest_ey, double brightness, bool extra)
 
SDL_Surface * tile_stretch (SDL_Surface *src, int n, int e, int s, int w)
 

Variables

static int std_tile_half_len []
 

Detailed Description

Tile stretching routines.

Tile stretching stretches all floor tiles and modifies y position of all other layer objects, for example, floor tile with "z 4" would be stretched, and all objects above it would have z increased by 4. Layer 2 objects are also stretched.

align_tile_stretch() calculates how much to stretch each tile in all 4 directions based on the surrounding tiles.

Todo:
Most fmasks (grass, for example) are not properly stretched.
Author
James "JLittle" Little
Documentation by: Karon Webb

Definition in file tilestretcher.c.

Typedef Documentation

Line information structure.

Function Documentation

int add_color_to_surface ( SDL_Surface *  dest,
Uint8  red,
Uint8  green,
Uint8  blue 
)

Adds a color to the palette in a bitmap ("surface").

Definition at line 215 of file tilestretcher.c.

void copy_pixel_to_pixel ( SDL_Surface *  src,
SDL_Surface *  dest,
int  x,
int  y,
int  x2,
int  y2,
double  brightness 
)

Copy a pixel from a source pixel map's co-ordinates to a target pixel map's co-ordinates, adjusting the pixel's brightness.

Pseudo-code:

PIXEL(dest, x2, y2) = AdjustPixelBrightness(PIXEL(src, x1, y1),
brightness)
Note
The pixel colour is added to the palette in the destination bitmap if necessary.
Warning
brightness above 1.0 is (apparently) allowed but brightness < 0 is not tested and could cause problems.

Definition at line 253 of file tilestretcher.c.

void copy_vertical_line ( SDL_Surface *  src,
SDL_Surface *  dest,
int  src_x,
int  src_sy,
int  src_ey,
int  dest_x,
int  dest_sy,
int  dest_ey,
double  brightness,
bool  extra 
)

Copy a vertical line from a source pixel map's co-ordinates to a target pixel map's co-ordinates, adjusting all the pixels' brightness.

This also applies a transmutation, "stretching" or "shrinking the line as appropriate:

If the target is twice the length it will receive pairs of pixels from the source, and if half the length every other pixel.

brightness applies to all pixels: above 1.0 is (apparently) allowed but brightness < 0 is not tested and could cause problems.

Set extra to true to duplicate the top pixel if the target line height is shorter than the source.

Note
To allow for rounding, it is recommended to set extra unless the target line is the same length or shorter.
There is no "smoothing" or "averaging" done at all - the result could benefit hugely by adding logic to do things like that.
This function would be horribly inefficient if ever used to shrink a long line down to a few pixels.

Definition at line 330 of file tilestretcher.c.

static void determine_line ( line_and_slope dest,
int  sx,
int  sy,
int  ex,
int  ey 
)
static

Calculate line information given its start and end co-ordinates.

This populates a line_and_slope structure.

Parameters
destWhat line information structure to populate.
sxStarting X.
syStarting Y.
exEnding X.
eyEnding Y.

Definition at line 120 of file tilestretcher.c.

static void determine_lines ( line_and_slope dest,
int  n,
int  e,
int  s,
int  w 
)
static

Calculate the information about the lines which will form the edge of the stretched tile (see the comments above std_tile_half_len for a picture).

In the isometric view, closer objects are displayed lower down on the VDU (smaller y co-ordinate) and further objects are displayed higher up (larger y co-ordinate).

The SW corner moves closer the more West the tile is stretched. The NE corner moves closer the more East the tile is stretched. Both the SW and NE corners move further away the more North the tile is stretched. Both the SE and NW corners move close the more South and further away the more North the tile is stretched

Definition at line 149 of file tilestretcher.c.

SDL_Surface* tile_stretch ( SDL_Surface *  src,
int  n,
int  e,
int  s,
int  w 
)

Generates the bitmap ("surface") for displaying a tile after stretching.

Stretching takes place from the horizontal centre, so from a "standard" viewpoint (i.e. some distance away from the viewed object), horizontal stretching should be done with either e or w <= 0 and the other > 0 (the part of the object appearing the original size centres on the zero).

Their absolute difference controls the brightness of the edges, so at the moment a horizontal line of horizontally stretched objects will appear to have vertical "bars" - especially as the underlying pixel stretching only occurs vertically (i.e. the measured "width" doesn't change).

Recommended limit is that neither e nor w exceed n+9. Major problems may occur if the total horizontal stretching (i.e. ABS(e - w)) exceeds 25.

Parameter documentation repeated in the body:

  • In the isometric view, closer objects are displayed lower down
  • on the VDU (smaller y co-ordinate) and further objects are displayed higher up (larger y co-ordinate).
  • The SW corner moves closer the more West the tile is stretched.
  • The NE corner moves closer the more East the tile is stretched.
  • Both the SW and NE corners move further away the more North the tile is stretched.
  • Both the SE and NW corners move close the more South and further away the more North the tile is stretched

Definition at line 404 of file tilestretcher.c.

int tilestretcher_coords_in_tile ( uint32_t  stretch,
int  x,
int  y 
)

Checks whether the supplied coordinates (relative to the tile size, so for example: 0,0, 47,0, etc) are inside the (possibly stretched) isometric map tile shape.

Parameters
stretchCalculated stretch factor.
xX coordinate.
yY coordinate.
Returns
1 if the supplied coordinates are within the isometric map tile shape, 0 otherwise.

Definition at line 177 of file tilestretcher.c.

Variable Documentation

int std_tile_half_len[]
static
Initial value:
= {
0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
10, 10, 11, 11, 11, 11, 10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5,
5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0
}

Pixel y-co-ordinate (offset) of the edge of a standard (i.e. un-stretched) tile for each x co-ordinate pixel. In our isometric view the displayed "depth" is half the width. The tile pixels then form a rhombus on the VDU:

                       //\\
 ^                   //    \\
 |                 //        \\
 y               //            \\
         W     //                \\    N
             //                    \\
           //                        \\
         //                            \\
       //                                \\
     //                                    \\
   //                                        \\
 //                                            \\
 \\                                            //
   \\                                        //
     \\                                    //
       \\                                //
         \\                            //
           \\                        //
             \\                    //
         S     \\                //    E
                 \\            //
                   \\        //
 |                   \\    //
 + -                   \\//                x - >

Definition at line 77 of file tilestretcher.c.