… | |
… | |
199 | } |
199 | } |
200 | |
200 | |
201 | return 0; |
201 | return 0; |
202 | } |
202 | } |
203 | |
203 | |
204 | typedef struct cf_layout { |
204 | struct cf_layout { |
205 | PangoLayout *pl; |
205 | PangoLayout *pl; |
206 | float r, g, b, a; // default color for rgba mode |
206 | float r, g, b, a; // default color for rgba mode |
207 | int base_height; |
207 | int base_height; |
208 | DC__Font font; |
208 | DC__Font font; |
209 | rc_t *rc; |
209 | rc_t *rc; |
210 | } *DC__Layout; |
210 | }; |
|
|
211 | |
|
|
212 | typedef cf_layout *DC__Layout; |
211 | |
213 | |
212 | static DC__Font default_font; |
214 | static DC__Font default_font; |
213 | static PangoContext *opengl_context; |
215 | static PangoContext *opengl_context; |
214 | static PangoFontMap *opengl_fontmap; |
216 | static PangoFontMap *opengl_fontmap; |
215 | |
217 | |
… | |
… | |
256 | } |
258 | } |
257 | |
259 | |
258 | typedef uint16_t tileid; |
260 | typedef uint16_t tileid; |
259 | typedef uint16_t faceid; |
261 | typedef uint16_t faceid; |
260 | |
262 | |
261 | typedef struct { |
263 | struct maptex |
|
|
264 | { |
262 | GLuint name; |
265 | GLuint name; |
263 | int w, h; |
266 | int w, h; |
264 | float s, t; |
267 | float s, t; |
265 | uint8_t r, g, b, a; |
268 | uint8_t r, g, b, a; |
266 | tileid smoothtile; |
269 | tileid smoothtile; |
267 | uint8_t smoothlevel; |
270 | uint8_t smoothlevel; |
268 | uint8_t unused; /* set to zero on use */ |
271 | uint8_t unused; /* set to zero on use */ |
269 | } maptex; |
272 | }; |
270 | |
273 | |
271 | typedef struct { |
274 | struct mapcell |
|
|
275 | { |
272 | uint32_t player; |
276 | uint32_t player; |
273 | tileid tile[3]; |
277 | tileid tile[3]; |
274 | uint16_t darkness; |
278 | uint16_t darkness; |
275 | uint8_t stat_width, stat_hp, flags, smoothmax; |
279 | uint8_t stat_width, stat_hp, flags, smoothmax; |
276 | } mapcell; |
280 | }; |
277 | |
281 | |
278 | typedef struct { |
282 | struct maprow |
|
|
283 | { |
279 | int32_t c0, c1; |
284 | int32_t c0, c1; |
280 | mapcell *col; |
285 | mapcell *col; |
281 | } maprow; |
286 | }; |
282 | |
287 | |
283 | typedef struct map { |
288 | struct mapgrid { |
284 | int x, y, w, h; |
289 | int x, y, w, h; |
285 | int ox, oy; /* offset to virtual global coordinate system */ |
290 | int ox, oy; /* offset to virtual global coordinate system */ |
286 | int faces; tileid *face2tile; // [faceid] |
291 | int faces; tileid *face2tile; // [faceid] |
287 | int texs; maptex *tex; // [tileid] |
292 | int texs; maptex *tex; // [tileid] |
288 | |
293 | |
289 | int32_t rows; |
294 | int32_t rows; |
290 | maprow *row; |
295 | maprow *row; |
291 | } *DC__Map; |
296 | }; |
|
|
297 | |
|
|
298 | typedef mapgrid *DC__Map; |
292 | |
299 | |
293 | static char * |
300 | static char * |
294 | prepend (char *ptr, int sze, int inc) |
301 | prepend (char *ptr, int sze, int inc) |
295 | { |
302 | { |
296 | char *p; |
303 | char *p; |
… | |
… | |
314 | |
321 | |
315 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
322 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
316 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
323 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
317 | |
324 | |
318 | static void |
325 | static void |
319 | need_facenum (struct map *self, faceid face) |
326 | need_facenum (struct mapgrid *self, faceid face) |
320 | { |
327 | { |
321 | while (self->faces <= face) |
328 | while (self->faces <= face) |
322 | { |
329 | { |
323 | Append (tileid, self->face2tile, self->faces, self->faces); |
330 | Append (tileid, self->face2tile, self->faces, self->faces); |
324 | self->faces *= 2; |
331 | self->faces *= 2; |
325 | } |
332 | } |
326 | } |
333 | } |
327 | |
334 | |
328 | static void |
335 | static void |
329 | need_texid (struct map *self, int texid) |
336 | need_texid (struct mapgrid *self, int texid) |
330 | { |
337 | { |
331 | while (self->texs <= texid) |
338 | while (self->texs <= texid) |
332 | { |
339 | { |
333 | Append (maptex, self->tex, self->texs, self->texs); |
340 | Append (maptex, self->tex, self->texs, self->texs); |
334 | self->texs *= 2; |
341 | self->texs *= 2; |
335 | } |
342 | } |
336 | } |
343 | } |
337 | |
344 | |
338 | static maprow * |
345 | static maprow * |
339 | map_get_row (DC__Map self, int y) |
346 | map_get_row (mapgrid *self, int y) |
340 | { |
347 | { |
341 | if (0 > y) |
348 | if (0 > y) |
342 | { |
349 | { |
343 | int extend = - y + MAP_EXTEND_Y; |
350 | int extend = - y + MAP_EXTEND_Y; |
344 | Prepend (maprow, self->row, self->rows, extend); |
351 | Prepend (maprow, self->row, self->rows, extend); |
… | |
… | |
382 | |
389 | |
383 | return row->col + (x - row->c0); |
390 | return row->col + (x - row->c0); |
384 | } |
391 | } |
385 | |
392 | |
386 | static mapcell * |
393 | static mapcell * |
387 | map_get_cell (DC__Map self, int x, int y) |
394 | map_get_cell (mapgrid *self, int x, int y) |
388 | { |
395 | { |
389 | return row_get_cell (map_get_row (self, y), x); |
396 | return row_get_cell (map_get_row (self, y), x); |
390 | } |
397 | } |
391 | |
398 | |
392 | static void |
399 | static void |
393 | map_clear (DC__Map self) |
400 | map_clear (mapgrid *self) |
394 | { |
401 | { |
395 | int r; |
402 | int r; |
396 | |
403 | |
397 | for (r = 0; r < self->rows; r++) |
404 | for (r = 0; r < self->rows; r++) |
398 | Safefree (self->row[r].col); |
405 | Safefree (self->row[r].col); |
… | |
… | |
416 | (cell)->flags = 0; \ |
423 | (cell)->flags = 0; \ |
417 | (cell)->player = 0; \ |
424 | (cell)->player = 0; \ |
418 | } while (0) |
425 | } while (0) |
419 | |
426 | |
420 | static void |
427 | static void |
421 | map_blank (DC__Map self, int x0, int y0, int w, int h) |
428 | map_blank (mapgrid *self, int x0, int y0, int w, int h) |
422 | { |
429 | { |
423 | int x, y; |
430 | int x, y; |
424 | maprow *row; |
431 | maprow *row; |
425 | mapcell *cell; |
432 | mapcell *cell; |
426 | |
433 | |
… | |
… | |
1894 | PROTOTYPES: DISABLE |
1901 | PROTOTYPES: DISABLE |
1895 | |
1902 | |
1896 | DC::Map |
1903 | DC::Map |
1897 | new (SV *klass) |
1904 | new (SV *klass) |
1898 | CODE: |
1905 | CODE: |
1899 | New (0, RETVAL, 1, struct map); |
1906 | New (0, RETVAL, 1, mapgrid); |
1900 | RETVAL->x = 0; |
1907 | RETVAL->x = 0; |
1901 | RETVAL->y = 0; |
1908 | RETVAL->y = 0; |
1902 | RETVAL->w = 0; |
1909 | RETVAL->w = 0; |
1903 | RETVAL->h = 0; |
1910 | RETVAL->h = 0; |
1904 | RETVAL->ox = 0; |
1911 | RETVAL->ox = 0; |