00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef INCL_CITERATE
00026 #define INCL_CITERATE 1
00027
00028
00029
00030
00031
00032
00033 class Chunk_intersect_iterator
00034 {
00035 Rectangle tiles;
00036 int start_tx;
00037
00038 int startcx, stopcx, stopcy;
00039 int curcx, curcy;
00040 public:
00041 Chunk_intersect_iterator(Rectangle t) : tiles(t),
00042 startcx(t.x/c_tiles_per_chunk),
00043 stopcx(INCR_CHUNK((t.x + t.w - 1)/c_tiles_per_chunk)),
00044 stopcy(INCR_CHUNK((t.y + t.h - 1)/c_tiles_per_chunk)),
00045 curcy(t.y/c_tiles_per_chunk)
00046 {
00047 curcx = startcx;
00048 tiles.shift(-curcx*c_tiles_per_chunk,-curcy*c_tiles_per_chunk);
00049 start_tx = tiles.x;
00050 if (t.x < 0 || t.y < 0)
00051 {
00052 curcx = stopcx;
00053 curcy = stopcy;
00054 }
00055 }
00056
00057 int get_next(Rectangle& intersect, int& cx, int& cy)
00058 {
00059 if (curcx == stopcx)
00060 if (curcy == stopcy)
00061 return (0);
00062 else
00063 {
00064 tiles.y -= c_tiles_per_chunk;
00065 tiles.x = start_tx;
00066 curcy = INCR_CHUNK(curcy);
00067 curcx = startcx;
00068 }
00069 Rectangle cr(0, 0, c_tiles_per_chunk, c_tiles_per_chunk);
00070
00071 intersect = cr.intersect(tiles);
00072 cx = curcx;
00073 cy = curcy;
00074 curcx = INCR_CHUNK(curcx);
00075 tiles.x -= c_tiles_per_chunk;
00076 return (1);
00077 }
00078 };
00079
00080 #endif