Main Page | Alphabetical List | Class List | File List | Class Members | File Members

editor/transform.c

Go to the documentation of this file.
00001 #include "editor.h"
00002 
00003 //{{{
00004 void transform_mirror_horizontal(void)
00005 {
00006     int top, bottom, left, right;
00007     int yi, leftpos, rightpos;
00008     int temp;
00009     
00010     get_selected_region(&top, &left, &right, &bottom);
00011     
00012     for(yi=top; yi<=bottom; yi++)
00013     {
00014         for(leftpos=left, rightpos=right;
00015             rightpos>leftpos;
00016             leftpos++, rightpos--)
00017         {
00018             temp = current_map->t[yi][leftpos];
00019             current_map->t[yi][leftpos]=mirror_x(current_map->t[yi][rightpos]);
00020             current_map->t[yi][rightpos]=mirror_x(temp);
00021         }
00022     }
00023 }
00024 //}}}
00025 //{{{
00026 void transform_mirror_vertical(void)
00027 {
00028     int top, bottom, left, right;
00029     int xi, toppos, bottompos;
00030     int temp;
00031     
00032     get_selected_region(&top, &left, &right, &bottom);
00033     
00034     for(xi=left; xi<=right; xi++)
00035     {
00036         for(toppos=top, bottompos=bottom;
00037             toppos < bottompos;
00038             toppos++, bottompos--)
00039         {
00040             temp = current_map->t[toppos][xi];
00041             current_map->t[toppos][xi]=mirror_y(current_map->t[bottompos][xi]);
00042             current_map->t[bottompos][xi]=mirror_y(temp);
00043         }
00044     }
00045 }
00046 //}}}
00047 //{{{
00048 void transform_rotate_180(void)
00049 {
00050     transform_mirror_horizontal();
00051     transform_mirror_vertical();
00052 }
00053 //}}}
00054 
00055 //{{{
00056 int mirror_x(int t)
00057 {
00058     switch(t)
00059     {
00060         case TILE_SLIDER_E: return TILE_SLIDER_W;
00061         case TILE_SLIDER_W: return TILE_SLIDER_E;
00062         case TILE_ROCKY_E:   return TILE_ROCKY_W;
00063         case TILE_ROCKY_W:   return TILE_ROCKY_E;
00064         case TILE_TWIST_CW: return TILE_TWIST_CCW;
00065         case TILE_TWIST_CCW: return TILE_TWIST_CW;
00066         case TILE_PUSHER_W: return TILE_PUSHER_E;
00067         case TILE_PUSHER_E: return TILE_PUSHER_W;
00068         case TILE_WALL_1:   return TILE_WALL_3;
00069         case TILE_WALL_4:   return TILE_WALL_6;
00070         case TILE_WALL_7:   return TILE_WALL_9;
00071         case TILE_WALL_9:   return TILE_WALL_7;
00072         case TILE_WALL_6:   return TILE_WALL_4;
00073         case TILE_WALL_3:   return TILE_WALL_1;
00074         default: // For tiles without a known reflection, make no change
00075             return t;
00076     }
00077 }
00078 //}}}
00079 //{{{
00080 int mirror_y(int t)
00081 {
00082     switch(t)
00083     {
00084         case TILE_SLIDER_N: return TILE_SLIDER_S;
00085         case TILE_SLIDER_S: return TILE_SLIDER_N;
00086         case TILE_ROCKY_N:   return TILE_ROCKY_S;
00087         case TILE_ROCKY_S:   return TILE_ROCKY_N;
00088         case TILE_TWIST_CW: return TILE_TWIST_CCW;
00089         case TILE_TWIST_CCW: return TILE_TWIST_CW;
00090         case TILE_PUSHER_S: return TILE_PUSHER_N;
00091         case TILE_PUSHER_N: return TILE_PUSHER_S;
00092         case TILE_WALL_1:   return TILE_WALL_7;
00093         case TILE_WALL_2:   return TILE_WALL_8;
00094         case TILE_WALL_3:   return TILE_WALL_9;
00095         case TILE_WALL_7:   return TILE_WALL_1;
00096         case TILE_WALL_8:   return TILE_WALL_2;
00097         case TILE_WALL_9:   return TILE_WALL_3;
00098         default: // For tiles without a known reflection, make no change
00099             return t;
00100     }
00101 }
00102 //}}}
00103 
00104 //{{{
00105 int tile_is_wall(int x, int y)
00106 {
00107     if(!is_in_bounds(x,y)) return 0;
00108     switch(current_map->t[y][x])
00109     {
00110         case TILE_WALL_5: case TILE_WALL_1: case TILE_WALL_2:
00111         case TILE_WALL_3: case TILE_WALL_4: case TILE_WALL_6:
00112         case TILE_WALL_7: case TILE_WALL_8: case TILE_WALL_9:
00113             return 1;
00114         default:
00115             return 0;
00116     }
00117 }
00118 //}}}
00119 //{{{
00120 int wall_map[16] =
00121 // Bit N in an index into wall_map corresponds to whether relative position N 
00122 // contains a wall or not.
00123 //     +---+
00124 //     |   |
00125 //     | 1 |
00126 //     |   |
00127 // +---+---+---+
00128 // |   |###|   |
00129 // | 0 |###| 2 |
00130 // |   |###|   |
00131 // +---+---+---+
00132 //     |   |
00133 //     | 3 |
00134 //     |   |
00135 //     +---+
00136     {
00137     // Position 0 clear
00138         // Position 1 clear
00139             // Position 2 clear
00140             TILE_WALL_5, // Position 3 clear
00141             TILE_WALL_8, // Position 3 set
00142             // Position 2 set
00143             TILE_WALL_4,  // Position 3 clear
00144             TILE_WALL_7,  // Position 3 set
00145         // Position 1 set
00146             // Position 2 clear
00147             TILE_WALL_2, // Position 3 clear
00148             TILE_WALL_5, // Position 3 set
00149             // Position 2 set
00150             TILE_WALL_1, // Position 3 clear
00151             TILE_WALL_5, // Position 3 set
00152     // Position 0 set
00153         // Position 1 clear
00154             // Position 2 clear
00155             TILE_WALL_6, // Position 3 clear
00156             TILE_WALL_9, // Position 3 set
00157             // Position 2 set
00158             TILE_WALL_5, // Position 3 clear
00159             TILE_WALL_5, // Position 3 set
00160         // Position 1 set
00161             // Position 2 clear
00162             TILE_WALL_3, // Position 3 clear
00163             TILE_WALL_5, // Position 3 set
00164             // Position 2 set
00165             TILE_WALL_5, // Position 3 clear
00166             TILE_WALL_5, // Position 3 set
00167     };
00168 //}}}
00169 //{{{
00170 void transform_smooth(void)
00171 {
00172     int top, bottom, left, right;
00173     int xi, yi;
00174     int dirs[4];
00175     
00176     get_selected_region(&top, &left, &right, &bottom);
00177     
00178     for(yi=top; yi<=bottom; yi++)
00179     for(xi=left; xi<=right; xi++)
00180     {
00181         if(!tile_is_wall(xi, yi))
00182             continue;
00183         dirs[0] = tile_is_wall(xi-1, yi);
00184         dirs[1] = tile_is_wall(xi, yi-1);
00185         dirs[2] = tile_is_wall(xi+1, yi);
00186         dirs[3] = tile_is_wall(xi, yi+1);
00187         current_map->t[yi][xi] =
00188             wall_map[ dirs[0]<<3 | dirs[1]<<2 | dirs[2]<<1 | dirs[3] ];
00189     }
00190 }
00191 //}}}
00192 

Generated on Thu Apr 22 14:06:32 2004 for SKye by doxygen 1.3.6