00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00068
00069
00070
00071
00072 #include <Python.h>
00073
00074 #include <stdio.h>
00075 #include <stdlib.h>
00076 #include <assert.h>
00077 #include <string.h>
00078 #include <ctype.h>
00079 #include <errno.h>
00080 #include <math.h>
00081
00082 #ifdef _WIN32
00083
00084 #include <winsock2.h>
00085 #include <sys/stat.h>
00086 #include <time.h>
00087
00088 #ifndef S_ISDIR
00089 #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
00090 #endif
00091
00092 #else
00093
00094 #include <unistd.h>
00095 #include <sys/time.h>
00096 #include <sys/file.h>
00097 #include <sys/types.h>
00098
00099 #endif
00100
00101 #include <string>
00102 #include <vector>
00103 #include <map>
00104
00105 #include <cairo.h>
00106 #include <pycairo.h>
00107
00108
00110
00111
00112
00113 #define TILEENGINE_VERSION "1.0"
00114
00115
00117
00118
00119
00120
00121 #define PycairoSurface_GET(obj) (((PycairoSurface *)(obj))->surface)
00122
00123
00125
00126
00127
00129 enum TileFormat {
00130 TILE_FORMAT_BYTE_SIGNED,
00131 TILE_FORMAT_BYTE_UNSIGNED,
00132 TILE_FORMAT_SHORT_SIGNED,
00133 TILE_FORMAT_SHORT_UNSIGNED,
00134 TILE_FORMAT_LONG_SIGNED,
00135 TILE_FORMAT_LONG_UNSIGNED,
00136 TILE_FORMAT_FLOAT,
00137 TILE_FORMAT_DOUBLE,
00138 TILE_FORMAT_COUNT,
00139 };
00140
00141
00143 enum TileCode {
00144 TILE_CODE_RAW_BINARY_16 = 0,
00145 TILE_CODE_COMPRESSED_TEXT = 1,
00146 TILE_CODE_COMPRESSED_BINARY_16 = 2,
00147 TILE_CODE_COUNT,
00148 };
00149
00150
00152 enum TileCodeCompressedText {
00153 TILE_CODE_COMPRESSED_TEXT_SKIP_0 = '.',
00154 TILE_CODE_COMPRESSED_TEXT_SKIP_1 = '!',
00155 TILE_CODE_COMPRESSED_TEXT_SKIP_2 = '@',
00156 TILE_CODE_COMPRESSED_TEXT_SKIP_3 = '#'
00157 };
00158
00159
00161 enum TileCodeCompressedBinary16 {
00162 TILE_CODE_COMPRESSED_BINARY_16_SKIP_0 = 0xff,
00163 TILE_CODE_COMPRESSED_BINARY_16_SKIP_1 = 0xfe,
00164 TILE_CODE_COMPRESSED_BINARY_16_SKIP_2 = 0xfd,
00165 TILE_CODE_COMPRESSED_BINARY_16_HIGH_MAX = 0xfc,
00166 };
00167
00168
00170
00171
00172
00173 class TileEngine {
00174
00175 public:
00176
00177 int width;
00178 int height;
00179 void *bufData;
00180 int colBytes;
00181 int rowBytes;
00182 char tileFormat;
00183 float floatOffset;
00184 float floatScale;
00185 unsigned int tileShift;
00186 unsigned int tileMask;
00187
00188
00190
00191
00192 TileEngine();
00193
00194 ~TileEngine();
00195
00196
00198
00199
00200 void setBuffer(
00201 void *buf);
00202
00203
00204 unsigned long getValue(
00205 int col,
00206 int row,
00207 PyObject *tileFunction = NULL,
00208 const int *tileMapData = NULL,
00209 unsigned int tileMapCount = 0);
00210
00211
00212 void renderTiles(
00213 cairo_t *ctx,
00214 cairo_surface_t *tilesSurf,
00215 int tilesWidth,
00216 int tilesHeight,
00217 PyObject *tileFunction,
00218 PyObject *tileMap,
00219 int tileSize,
00220 int renderCol,
00221 int renderRow,
00222 int renderCols,
00223 int renderRows,
00224 double alpha);
00225
00226
00227 void renderTilesLazy(
00228 cairo_t *ctx,
00229 PyObject *tileFunction,
00230 PyObject *tileMap,
00231 int tileSize,
00232 int renderCol,
00233 int renderRow,
00234 int renderCols,
00235 int renderRows,
00236 double alpha,
00237 PyObject *tileGenerator,
00238 PyObject *tileCache,
00239 PyObject *tileCacheSurfaces,
00240 PyObject *tileState);
00241
00242
00243 void renderPixels(
00244 cairo_surface_t *destSurf,
00245 cairo_surface_t *cmapSurf,
00246 PyObject *tileFunction,
00247 PyObject *tileMap,
00248 int renderCol,
00249 int renderRow,
00250 int renderCols,
00251 int renderRows);
00252
00253
00254 PyObject *getTileData(
00255 PyObject *tileFunction,
00256 PyObject *tileMap,
00257 int col,
00258 int row,
00259 int cols,
00260 int rows,
00261 int code,
00262 PyObject *tileViewCache);
00263
00264
00266
00267
00268 };
00269
00270