… | |
… | |
15 | |
15 | |
16 | #include "EXTERN.h" |
16 | #include "EXTERN.h" |
17 | #include "perl.h" |
17 | #include "perl.h" |
18 | #include "XSUB.h" |
18 | #include "XSUB.h" |
19 | |
19 | |
|
|
20 | #include "flat_hash_map.hpp" |
|
|
21 | |
20 | #ifdef _WIN32 |
22 | #ifdef _WIN32 |
21 | # undef pipe |
23 | # undef pipe |
22 | // microsoft vs. C |
24 | // microsoft vs. C |
23 | # define sqrtf(x) sqrt(x) |
25 | # define sqrtf(x) sqrt(x) |
24 | # define roundf(x) (int)(x) |
|
|
25 | # define atan2f(x,y) atan2(x,y) |
26 | # define atan2f(x,y) atan2(x,y) |
26 | # define M_PI 3.14159265f |
27 | # define M_PI 3.14159265f |
27 | #endif |
28 | #endif |
28 | |
29 | |
29 | #include <assert.h> |
30 | #include <cassert> |
30 | #include <math.h> |
31 | #include <cmath> |
31 | #include <string.h> |
32 | #include <cstring> |
32 | #include <stdio.h> |
33 | #include <cstdio> |
33 | #include <stdlib.h> |
34 | #include <cstdlib> |
|
|
35 | |
|
|
36 | #include <utility> |
|
|
37 | #include <bitset> |
34 | |
38 | |
35 | #define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW |
39 | #define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW |
36 | |
40 | |
37 | #include <SDL.h> |
41 | #include <SDL.h> |
38 | #include <SDL_thread.h> |
42 | #include <SDL_thread.h> |
39 | #include <SDL_endian.h> |
43 | #include <SDL_endian.h> |
40 | #include <SDL_image.h> |
44 | #include <SDL_image.h> |
41 | #include <SDL_mixer.h> |
45 | #include <SDL_mixer.h> |
42 | #include <SDL_opengl.h> |
46 | #include <SDL_opengl.h> |
43 | |
47 | |
|
|
48 | /* work around os x broken headers */ |
|
|
49 | #ifdef __MACOSX__ |
|
|
50 | typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); |
|
|
51 | typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); |
|
|
52 | typedef void (APIENTRYP PFNGLMULTITEXCOORD2FPROC) (GLenum target, GLfloat s, GLfloat t); |
|
|
53 | #endif |
|
|
54 | |
44 | #define PANGO_ENABLE_BACKEND |
55 | #define PANGO_ENABLE_BACKEND |
45 | #define G_DISABLE_CAST_CHECKS |
56 | #define G_DISABLE_CAST_CHECKS |
46 | |
57 | |
47 | #include <glib/gmacros.h> |
58 | #include <glib.h> |
48 | |
59 | |
49 | #include <pango/pango.h> |
60 | #include <pango/pango.h> |
|
|
61 | |
|
|
62 | #ifndef PANGO_VERSION_CHECK |
|
|
63 | # define PANGO_VERSION_CHECK(a,b,c) 0 |
|
|
64 | #endif |
|
|
65 | |
|
|
66 | #if !PANGO_VERSION_CHECK (1, 15, 2) |
|
|
67 | # define pango_layout_get_line_readonly pango_layout_get_line |
|
|
68 | # define pango_layout_get_lines_readonly pango_layout_get_lines |
|
|
69 | # define pango_layout_iter_get_line_readonly pango_layout_iter_get_line |
|
|
70 | # define pango_layout_iter_get_run_readonly pango_layout_iter_get_run |
|
|
71 | #endif |
50 | |
72 | |
51 | #ifndef _WIN32 |
73 | #ifndef _WIN32 |
52 | # include <sys/types.h> |
74 | # include <sys/types.h> |
53 | # include <sys/socket.h> |
75 | # include <sys/socket.h> |
54 | # include <netinet/in.h> |
76 | # include <netinet/in.h> |
55 | # include <netinet/tcp.h> |
77 | # include <netinet/tcp.h> |
56 | # include <inttypes.h> |
78 | # include <inttypes.h> |
57 | #endif |
79 | #endif |
58 | |
80 | |
|
|
81 | #if __GNUC__ >= 4 |
|
|
82 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
|
|
83 | #else |
|
|
84 | # define expect(expr,value) (expr) |
|
|
85 | #endif |
|
|
86 | |
|
|
87 | #define expect_false(expr) expect ((expr) != 0, 0) |
|
|
88 | #define expect_true(expr) expect ((expr) != 0, 1) |
|
|
89 | |
59 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ |
90 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ |
60 | |
91 | |
|
|
92 | /* this is used as fow flag as well, so has to have a different value */ |
|
|
93 | /* then anything that is computed by incoming darkness */ |
61 | #define FOW_DARKNESS 32 |
94 | #define FOW_DARKNESS 50 |
|
|
95 | #define DARKNESS_ADJUST(n) (n) |
62 | |
96 | |
63 | #define MAP_EXTEND_X 32 |
97 | #define MAP_EXTEND_X 32 |
64 | #define MAP_EXTEND_Y 512 |
98 | #define MAP_EXTEND_Y 512 |
65 | |
99 | |
66 | #define MIN_FONT_HEIGHT 10 |
100 | #define MIN_FONT_HEIGHT 10 |
67 | |
101 | |
68 | #if 0 |
102 | /* mask out modifiers we are not interested in */ |
69 | # define PARACHUTE SDL_INIT_NOPARACHUTE |
103 | #define MOD_MASK (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_META) |
70 | #else |
104 | |
71 | # define PARACHUTE 0 |
105 | #define KMOD_LRAM 0x10000 // our extension |
72 | #endif |
106 | |
|
|
107 | #define TEXID_SPEECH 1 |
|
|
108 | #define TEXID_NOFACE 2 |
|
|
109 | |
|
|
110 | static char * |
|
|
111 | fast_sv_grow (SV *sv, STRLEN need) |
|
|
112 | { |
|
|
113 | STRLEN len = SvLEN (sv); |
|
|
114 | STRLEN want = SvCUR (sv) + need; |
|
|
115 | |
|
|
116 | if (expect_false (len < want)) |
|
|
117 | { |
|
|
118 | do |
|
|
119 | len *= 2; |
|
|
120 | while (len < want); |
|
|
121 | |
|
|
122 | sv_grow (sv, len); |
|
|
123 | } |
|
|
124 | |
|
|
125 | SvCUR_set (sv, want); |
|
|
126 | return SvEND (sv) - need; |
|
|
127 | } |
73 | |
128 | |
74 | static AV *texture_av; |
129 | static AV *texture_av; |
75 | |
130 | |
76 | static struct |
131 | static struct |
77 | { |
132 | { |
… | |
… | |
120 | |
175 | |
121 | #include "pango-font.c" |
176 | #include "pango-font.c" |
122 | #include "pango-fontmap.c" |
177 | #include "pango-fontmap.c" |
123 | #include "pango-render.c" |
178 | #include "pango-render.c" |
124 | |
179 | |
125 | typedef IV CFPlus__Channel; |
180 | typedef IV DC__Channel; |
126 | typedef SDL_RWops *CFPlus__RW; |
181 | typedef SDL_RWops *DC__RW; |
127 | typedef Mix_Chunk *CFPlus__MixChunk; |
182 | typedef Mix_Chunk *DC__MixChunk; |
128 | typedef Mix_Music *CFPlus__MixMusic; |
183 | typedef Mix_Music *DC__MixMusic; |
129 | |
184 | |
130 | typedef PangoFontDescription *CFPlus__Font; |
185 | typedef PangoFontDescription *DC__Font; |
131 | |
186 | |
132 | static int |
187 | static int |
133 | shape_attr_p (PangoLayoutRun *run) |
188 | shape_attr_p (PangoLayoutRun *run) |
134 | { |
189 | { |
135 | GSList *attrs = run->item->analysis.extra_attrs; |
190 | GSList *attrs = run->item->analysis.extra_attrs; |
136 | |
191 | |
137 | while (attrs) |
192 | while (attrs) |
138 | { |
193 | { |
139 | PangoAttribute *attr = attrs->data; |
194 | PangoAttribute *attr = (PangoAttribute *)attrs->data; |
140 | |
195 | |
141 | if (attr->klass->type == PANGO_ATTR_SHAPE) |
196 | if (attr->klass->type == PANGO_ATTR_SHAPE) |
142 | return 1; |
197 | return 1; |
143 | |
198 | |
144 | attrs = attrs->next; |
199 | attrs = attrs->next; |
145 | } |
200 | } |
146 | |
201 | |
147 | return 0; |
202 | return 0; |
148 | } |
203 | } |
149 | |
204 | |
150 | typedef struct cf_layout { |
205 | struct cf_layout { |
151 | PangoLayout *pl; |
206 | PangoLayout *pl; |
152 | float r, g, b, a; // default color for rgba mode |
207 | float r, g, b, a; // default color for rgba mode |
153 | int base_height; |
208 | int base_height; |
154 | CFPlus__Font font; |
209 | DC__Font font; |
155 | rc_t *rc; |
210 | rc_t rc; |
156 | } *CFPlus__Layout; |
211 | }; |
157 | |
212 | |
|
|
213 | typedef cf_layout *DC__Layout; |
|
|
214 | |
158 | static CFPlus__Font default_font; |
215 | static DC__Font default_font; |
159 | static PangoContext *opengl_context; |
216 | static PangoContext *opengl_context; |
160 | static PangoFontMap *opengl_fontmap; |
217 | static PangoFontMap *opengl_fontmap; |
161 | |
218 | |
162 | static void |
219 | static void |
163 | substitute_func (FcPattern *pattern, gpointer data) |
220 | substitute_func (FcPattern *pattern, gpointer data) |
164 | { |
221 | { |
165 | FcPatternAddBool (pattern, FC_HINTING, 1); |
222 | FcPatternAddBool (pattern, FC_HINTING, 1); |
166 | #ifdef FC_HINT_STYLE |
223 | #ifdef FC_HINT_STYLE |
167 | FcPatternAddBool (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
224 | FcPatternAddInteger (pattern, FC_HINT_STYLE, FC_HINT_FULL); |
168 | #endif |
225 | #endif |
169 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
226 | FcPatternAddBool (pattern, FC_AUTOHINT, 0); |
170 | } |
227 | } |
171 | |
228 | |
172 | static void |
229 | static void |
173 | layout_update_font (CFPlus__Layout self) |
230 | layout_update_font (DC__Layout self) |
174 | { |
231 | { |
175 | /* use a random scale factor to account for unknown descenders, 0.8 works |
232 | /* use a random scale factor to account for unknown descenders, 0.8 works |
176 | * reasonably well with bitstream vera |
233 | * reasonably well with dejavu/bistream fonts |
177 | */ |
234 | */ |
178 | PangoFontDescription *font = self->font ? self->font : default_font; |
235 | PangoFontDescription *font = self->font ? self->font : default_font; |
179 | |
236 | |
180 | pango_font_description_set_absolute_size (font, |
237 | pango_font_description_set_absolute_size (font, |
181 | MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); |
238 | MAX (MIN_FONT_HEIGHT, self->base_height) * (PANGO_SCALE * 8 / 10)); |
182 | |
239 | |
183 | pango_layout_set_font_description (self->pl, font); |
240 | pango_layout_set_font_description (self->pl, font); |
184 | } |
241 | } |
185 | |
242 | |
186 | static void |
243 | static void |
187 | layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) |
244 | layout_get_pixel_size (DC__Layout self, int *w, int *h) |
188 | { |
245 | { |
189 | PangoRectangle rect; |
246 | PangoRectangle rect; |
190 | |
247 | |
191 | // get_pixel_* wrongly rounds down |
248 | // get_pixel_* wrongly rounds down |
192 | pango_layout_get_extents (self->pl, 0, &rect); |
249 | pango_layout_get_extents (self->pl, 0, &rect); |
… | |
… | |
202 | } |
259 | } |
203 | |
260 | |
204 | typedef uint16_t tileid; |
261 | typedef uint16_t tileid; |
205 | typedef uint16_t faceid; |
262 | typedef uint16_t faceid; |
206 | |
263 | |
207 | typedef struct { |
264 | struct maptex |
|
|
265 | { |
208 | GLuint name; |
266 | GLuint name; |
209 | int w, h; |
267 | int w, h; |
210 | float s, t; |
268 | float s, t; |
211 | uint8_t r, g, b, a; |
269 | uint8_t r, g, b, a; |
212 | tileid smoothtile; |
270 | tileid smoothtile; |
213 | uint8_t smoothlevel; |
271 | uint8_t smoothlevel; |
214 | } maptex; |
272 | uint8_t unused; /* set to zero on use */ |
|
|
273 | }; |
215 | |
274 | |
216 | typedef struct { |
275 | struct mapcell |
|
|
276 | { |
217 | uint32_t player; |
277 | uint32_t player; |
218 | tileid tile[3]; |
278 | tileid tile[3]; |
219 | uint16_t darkness; |
279 | uint16_t darkness; |
220 | uint8_t stat_width, stat_hp, flags, smoothmax; |
280 | uint8_t stat_width, stat_hp, flags, smoothmax; |
221 | } mapcell; |
281 | }; |
222 | |
282 | |
223 | typedef struct { |
283 | struct maprow |
|
|
284 | { |
224 | int32_t c0, c1; |
285 | int32_t c0, c1; |
225 | mapcell *col; |
286 | mapcell *col; |
226 | } maprow; |
287 | }; |
227 | |
288 | |
228 | typedef struct map { |
289 | struct mapgrid { |
229 | int x, y, w, h; |
290 | int x, y, w, h; |
230 | int ox, oy; /* offset to virtual global coordinate system */ |
291 | int ox, oy; /* offset to virtual global coordinate system */ |
231 | int faces; tileid *face2tile; // [faceid] |
292 | int faces; tileid *face2tile; // [faceid] |
232 | int texs; maptex *tex; // [tileid] |
293 | int texs; maptex *tex; // [tileid] |
233 | |
294 | |
234 | int32_t rows; |
295 | int32_t rows; |
235 | maprow *row; |
296 | maprow *row; |
236 | } *CFPlus__Map; |
297 | }; |
|
|
298 | |
|
|
299 | typedef mapgrid *DC__Map; |
237 | |
300 | |
238 | static char * |
301 | static char * |
239 | prepend (char *ptr, int sze, int inc) |
302 | prepend (char *ptr, int sze, int inc) |
240 | { |
303 | { |
241 | char *p; |
304 | char *p; |
… | |
… | |
259 | |
322 | |
260 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
323 | #define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
261 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
324 | #define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) |
262 | |
325 | |
263 | static void |
326 | static void |
264 | need_facenum (struct map *self, faceid face) |
327 | need_facenum (struct mapgrid *self, faceid face) |
265 | { |
328 | { |
266 | while (self->faces <= face) |
329 | while (self->faces <= face) |
267 | { |
330 | { |
268 | Append (tileid, self->face2tile, self->faces, self->faces); |
331 | Append (tileid, self->face2tile, self->faces, self->faces); |
269 | self->faces *= 2; |
332 | self->faces *= 2; |
270 | } |
333 | } |
271 | } |
334 | } |
272 | |
335 | |
273 | static void |
336 | static void |
274 | need_texid (struct map *self, int texid) |
337 | need_texid (struct mapgrid *self, int texid) |
275 | { |
338 | { |
276 | while (self->texs <= texid) |
339 | while (self->texs <= texid) |
277 | { |
340 | { |
278 | Append (maptex, self->tex, self->texs, self->texs); |
341 | Append (maptex, self->tex, self->texs, self->texs); |
279 | self->texs *= 2; |
342 | self->texs *= 2; |
280 | } |
343 | } |
281 | } |
344 | } |
282 | |
345 | |
283 | static maprow * |
346 | static maprow * |
284 | map_get_row (CFPlus__Map self, int y) |
347 | map_get_row (mapgrid *self, int y) |
285 | { |
348 | { |
286 | if (0 > y) |
349 | if (0 > y) |
287 | { |
350 | { |
288 | int extend = - y + MAP_EXTEND_Y; |
351 | int extend = - y + MAP_EXTEND_Y; |
289 | Prepend (maprow, self->row, self->rows, extend); |
352 | Prepend (maprow, self->row, self->rows, extend); |
… | |
… | |
327 | |
390 | |
328 | return row->col + (x - row->c0); |
391 | return row->col + (x - row->c0); |
329 | } |
392 | } |
330 | |
393 | |
331 | static mapcell * |
394 | static mapcell * |
332 | map_get_cell (CFPlus__Map self, int x, int y) |
395 | map_get_cell (mapgrid *self, int x, int y) |
333 | { |
396 | { |
334 | return row_get_cell (map_get_row (self, y), x); |
397 | return row_get_cell (map_get_row (self, y), x); |
335 | } |
398 | } |
336 | |
399 | |
337 | static void |
400 | static void |
338 | map_clear (CFPlus__Map self) |
401 | map_clear (mapgrid *self) |
339 | { |
402 | { |
340 | int r; |
403 | int r; |
341 | |
404 | |
342 | for (r = 0; r < self->rows; r++) |
405 | for (r = 0; r < self->rows; r++) |
343 | Safefree (self->row[r].col); |
406 | Safefree (self->row[r].col); |
… | |
… | |
350 | self->oy = 0; |
413 | self->oy = 0; |
351 | self->row = 0; |
414 | self->row = 0; |
352 | self->rows = 0; |
415 | self->rows = 0; |
353 | } |
416 | } |
354 | |
417 | |
|
|
418 | #define CELL_CLEAR(cell) \ |
|
|
419 | do { \ |
|
|
420 | if ((cell)->player) \ |
|
|
421 | (cell)->tile [2] = 0; \ |
|
|
422 | (cell)->darkness = 0; \ |
|
|
423 | (cell)->stat_hp = 0; \ |
|
|
424 | (cell)->flags = 0; \ |
|
|
425 | (cell)->player = 0; \ |
|
|
426 | } while (0) |
|
|
427 | |
355 | static void |
428 | static void |
356 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
429 | map_blank (mapgrid *self, int x0, int y0, int w, int h) |
357 | { |
430 | { |
358 | int x, y; |
431 | int x, y; |
359 | maprow *row; |
432 | maprow *row; |
360 | mapcell *cell; |
433 | mapcell *cell; |
361 | |
434 | |
… | |
… | |
373 | if (x >= row->c1) |
446 | if (x >= row->c1) |
374 | break; |
447 | break; |
375 | |
448 | |
376 | cell = row->col + x - row->c0; |
449 | cell = row->col + x - row->c0; |
377 | |
450 | |
378 | cell->darkness = 0; |
451 | CELL_CLEAR (cell); |
379 | cell->stat_hp = 0; |
|
|
380 | cell->flags = 0; |
|
|
381 | cell->player = 0; |
|
|
382 | } |
452 | } |
383 | } |
453 | } |
384 | } |
454 | } |
385 | |
455 | |
386 | typedef struct { |
456 | struct smooth_key |
|
|
457 | { |
387 | tileid tile; |
458 | tileid tile; |
388 | uint8_t x, y, level; |
459 | uint8_t x, y, level; |
389 | } smooth_key; |
460 | |
|
|
461 | bool operator == (const smooth_key &o) const |
|
|
462 | { |
|
|
463 | return tile == o.tile && x == o.x && y == o.y && level == o.level; |
|
|
464 | } |
|
|
465 | }; |
|
|
466 | |
|
|
467 | typedef ska::flat_hash_map<smooth_key, IV> smooth_hash; |
|
|
468 | |
|
|
469 | namespace std { |
|
|
470 | template <> |
|
|
471 | struct hash<smooth_key> |
|
|
472 | { |
|
|
473 | size_t operator () (const smooth_key &v) const |
|
|
474 | { |
|
|
475 | return v.tile + (v.x << 8) + (v.y << 16) + (v.level << 24); |
|
|
476 | } |
|
|
477 | }; |
|
|
478 | } |
390 | |
479 | |
391 | static void |
480 | static void |
392 | smooth_or_bits (HV *hv, smooth_key *key, IV bits) |
481 | smooth_or_bits (smooth_hash &h, smooth_key &key, IV bits) |
393 | { |
482 | { |
394 | SV **sv = hv_fetch (hv, (char *)key, sizeof (*key), 1); |
483 | auto &&it = h.find (key); |
395 | |
484 | |
396 | if (SvIOK (*sv)) |
485 | if (it == h.end ()) |
397 | SvIV_set (*sv, SvIVX (*sv) | bits); |
486 | h.insert (std::make_pair (key, bits)); |
398 | else |
487 | else |
399 | sv_setiv (*sv, bits); |
488 | it->second |= bits; |
400 | } |
489 | } |
401 | |
490 | |
402 | static void |
491 | static void |
403 | music_finished (void) |
492 | music_finished (void) |
404 | { |
493 | { |
… | |
… | |
421 | ev.code = 1; |
510 | ev.code = 1; |
422 | ev.data1 = (void *)(long)channel; |
511 | ev.data1 = (void *)(long)channel; |
423 | ev.data2 = 0; |
512 | ev.data2 = 0; |
424 | |
513 | |
425 | SDL_PushEvent ((SDL_Event *)&ev); |
514 | SDL_PushEvent ((SDL_Event *)&ev); |
|
|
515 | } |
|
|
516 | |
|
|
517 | // approximately divide by 255 |
|
|
518 | static unsigned int |
|
|
519 | div255 (unsigned int n) |
|
|
520 | { |
|
|
521 | return (n + (n >> 8)) >> 8; |
426 | } |
522 | } |
427 | |
523 | |
428 | static unsigned int |
524 | static unsigned int |
429 | minpot (unsigned int n) |
525 | minpot (unsigned int n) |
430 | { |
526 | { |
… | |
… | |
440 | n |= n >> 16; |
536 | n |= n >> 16; |
441 | |
537 | |
442 | return n + 1; |
538 | return n + 1; |
443 | } |
539 | } |
444 | |
540 | |
|
|
541 | static unsigned int |
|
|
542 | popcount (unsigned int n) |
|
|
543 | { |
|
|
544 | n -= (n >> 1) & 0x55555555U; |
|
|
545 | n = ((n >> 2) & 0x33333333U) + (n & 0x33333333U); |
|
|
546 | n = ((n >> 4) + n) & 0x0f0f0f0fU; |
|
|
547 | n *= 0x01010101U; |
|
|
548 | |
|
|
549 | return n >> 24; |
|
|
550 | } |
|
|
551 | |
445 | /* SDL should provide this, really. */ |
552 | /* SDL should provide this, really. */ |
446 | #define SDLK_MODIFIER_MIN 300 |
553 | #define SDLK_MODIFIER_MIN 300 |
447 | #define SDLK_MODIFIER_MAX 314 |
554 | #define SDLK_MODIFIER_MAX 314 |
448 | |
555 | |
449 | /******************************************************************************/ |
556 | /******************************************************************************/ |
… | |
… | |
487 | return 0; |
594 | return 0; |
488 | |
595 | |
489 | return 1; |
596 | return 1; |
490 | } |
597 | } |
491 | |
598 | |
492 | MODULE = CFPlus PACKAGE = CFPlus |
599 | /******************************************************************************/ |
|
|
600 | |
|
|
601 | /* process keyboard modifiers */ |
|
|
602 | static int |
|
|
603 | mod_munge (int mod) |
|
|
604 | { |
|
|
605 | mod &= MOD_MASK; |
|
|
606 | |
|
|
607 | if (mod & (KMOD_META | KMOD_ALT)) |
|
|
608 | mod |= KMOD_LRAM; |
|
|
609 | |
|
|
610 | return mod; |
|
|
611 | } |
|
|
612 | |
|
|
613 | static void |
|
|
614 | deliantra_main (SV *real_main) |
|
|
615 | { |
|
|
616 | dSP; |
|
|
617 | |
|
|
618 | PUSHMARK (SP); |
|
|
619 | call_sv (real_main, G_DISCARD | G_VOID); |
|
|
620 | } |
|
|
621 | |
|
|
622 | #ifdef __MACOSX__ |
|
|
623 | static SV *real_main; |
|
|
624 | |
|
|
625 | /* to due surprising braindamage on the side of SDL design, we |
|
|
626 | * do some mind-boggling hack here: SDL requires a custom main() |
|
|
627 | * on OS X, so... we provide one and call the original main(), which, |
|
|
628 | * due to shared library magic, calls -lSDLmain's main, not perl's main, |
|
|
629 | * and which calls our main (== SDL_main) back. |
|
|
630 | */ |
|
|
631 | extern C_LINKAGE int |
|
|
632 | main (int argc, char *argv[]) |
|
|
633 | { |
|
|
634 | deliantra_main (real_main); |
|
|
635 | } |
|
|
636 | |
|
|
637 | #undef main |
|
|
638 | |
|
|
639 | extern C_LINKAGE int main (int argc, char *argv[]); |
|
|
640 | |
|
|
641 | static void |
|
|
642 | SDL_main_hack (SV *real_main_) |
|
|
643 | { |
|
|
644 | real_main = real_main_; |
|
|
645 | |
|
|
646 | char *argv[] = { "deliantra client", 0 }; |
|
|
647 | (main) (1, argv); |
|
|
648 | } |
|
|
649 | #else |
|
|
650 | static void |
|
|
651 | SDL_main_hack (SV *real_main) |
|
|
652 | { |
|
|
653 | deliantra_main (real_main); |
|
|
654 | } |
|
|
655 | #endif |
|
|
656 | |
|
|
657 | MODULE = Deliantra::Client PACKAGE = DC |
493 | |
658 | |
494 | PROTOTYPES: ENABLE |
659 | PROTOTYPES: ENABLE |
495 | |
660 | |
496 | BOOT: |
661 | BOOT: |
497 | { |
662 | { |
498 | HV *stash = gv_stashpv ("CFPlus", 1); |
663 | HV *stash = gv_stashpv ("DC", 1); |
499 | static const struct { |
664 | static const struct { |
500 | const char *name; |
665 | const char *name; |
501 | IV iv; |
666 | IV iv; |
502 | } *civ, const_iv[] = { |
667 | } *civ, const_iv[] = { |
503 | # define const_iv(name) { # name, (IV)name } |
668 | # define const_iv(name) { # name, (IV)name } |
… | |
… | |
525 | |
690 | |
526 | const_iv (SDL_APPINPUTFOCUS), |
691 | const_iv (SDL_APPINPUTFOCUS), |
527 | const_iv (SDL_APPMOUSEFOCUS), |
692 | const_iv (SDL_APPMOUSEFOCUS), |
528 | const_iv (SDL_APPACTIVE), |
693 | const_iv (SDL_APPACTIVE), |
529 | |
694 | |
|
|
695 | |
|
|
696 | const_iv (SDLK_UNKNOWN), |
|
|
697 | const_iv (SDLK_FIRST), |
|
|
698 | const_iv (SDLK_BACKSPACE), |
|
|
699 | const_iv (SDLK_TAB), |
|
|
700 | const_iv (SDLK_CLEAR), |
|
|
701 | const_iv (SDLK_RETURN), |
|
|
702 | const_iv (SDLK_PAUSE), |
|
|
703 | const_iv (SDLK_ESCAPE), |
|
|
704 | const_iv (SDLK_SPACE), |
|
|
705 | const_iv (SDLK_EXCLAIM), |
|
|
706 | const_iv (SDLK_QUOTEDBL), |
|
|
707 | const_iv (SDLK_HASH), |
|
|
708 | const_iv (SDLK_DOLLAR), |
|
|
709 | const_iv (SDLK_AMPERSAND), |
|
|
710 | const_iv (SDLK_QUOTE), |
|
|
711 | const_iv (SDLK_LEFTPAREN), |
|
|
712 | const_iv (SDLK_RIGHTPAREN), |
|
|
713 | const_iv (SDLK_ASTERISK), |
|
|
714 | const_iv (SDLK_PLUS), |
|
|
715 | const_iv (SDLK_COMMA), |
|
|
716 | const_iv (SDLK_MINUS), |
|
|
717 | const_iv (SDLK_PERIOD), |
|
|
718 | const_iv (SDLK_SLASH), |
|
|
719 | const_iv (SDLK_0), |
|
|
720 | const_iv (SDLK_1), |
|
|
721 | const_iv (SDLK_2), |
|
|
722 | const_iv (SDLK_3), |
|
|
723 | const_iv (SDLK_4), |
|
|
724 | const_iv (SDLK_5), |
|
|
725 | const_iv (SDLK_6), |
|
|
726 | const_iv (SDLK_7), |
|
|
727 | const_iv (SDLK_8), |
|
|
728 | const_iv (SDLK_9), |
|
|
729 | const_iv (SDLK_COLON), |
|
|
730 | const_iv (SDLK_SEMICOLON), |
|
|
731 | const_iv (SDLK_LESS), |
|
|
732 | const_iv (SDLK_EQUALS), |
|
|
733 | const_iv (SDLK_GREATER), |
|
|
734 | const_iv (SDLK_QUESTION), |
|
|
735 | const_iv (SDLK_AT), |
|
|
736 | |
|
|
737 | const_iv (SDLK_LEFTBRACKET), |
|
|
738 | const_iv (SDLK_BACKSLASH), |
|
|
739 | const_iv (SDLK_RIGHTBRACKET), |
|
|
740 | const_iv (SDLK_CARET), |
|
|
741 | const_iv (SDLK_UNDERSCORE), |
|
|
742 | const_iv (SDLK_BACKQUOTE), |
|
|
743 | const_iv (SDLK_DELETE), |
|
|
744 | |
|
|
745 | const_iv (SDLK_FIRST), |
|
|
746 | const_iv (SDLK_LAST), |
530 | const_iv (SDLK_KP0), |
747 | const_iv (SDLK_KP0), |
531 | const_iv (SDLK_KP1), |
748 | const_iv (SDLK_KP1), |
532 | const_iv (SDLK_KP2), |
749 | const_iv (SDLK_KP2), |
533 | const_iv (SDLK_KP3), |
750 | const_iv (SDLK_KP3), |
534 | const_iv (SDLK_KP4), |
751 | const_iv (SDLK_KP4), |
… | |
… | |
606 | const_iv (KMOD_LMETA), |
823 | const_iv (KMOD_LMETA), |
607 | const_iv (KMOD_RMETA), |
824 | const_iv (KMOD_RMETA), |
608 | const_iv (KMOD_NUM), |
825 | const_iv (KMOD_NUM), |
609 | const_iv (KMOD_CAPS), |
826 | const_iv (KMOD_CAPS), |
610 | const_iv (KMOD_MODE), |
827 | const_iv (KMOD_MODE), |
|
|
828 | |
|
|
829 | const_iv (KMOD_LRAM), |
|
|
830 | |
|
|
831 | const_iv (MIX_DEFAULT_FORMAT), |
|
|
832 | |
|
|
833 | const_iv (SDL_INIT_TIMER), |
|
|
834 | const_iv (SDL_INIT_AUDIO), |
|
|
835 | const_iv (SDL_INIT_VIDEO), |
|
|
836 | const_iv (SDL_INIT_CDROM), |
|
|
837 | const_iv (SDL_INIT_JOYSTICK), |
|
|
838 | const_iv (SDL_INIT_EVERYTHING), |
|
|
839 | const_iv (SDL_INIT_NOPARACHUTE), |
|
|
840 | const_iv (SDL_INIT_EVENTTHREAD), |
|
|
841 | |
|
|
842 | const_iv (SDL_GL_RED_SIZE), |
|
|
843 | const_iv (SDL_GL_GREEN_SIZE), |
|
|
844 | const_iv (SDL_GL_BLUE_SIZE), |
|
|
845 | const_iv (SDL_GL_ALPHA_SIZE), |
|
|
846 | const_iv (SDL_GL_DOUBLEBUFFER), |
|
|
847 | const_iv (SDL_GL_BUFFER_SIZE), |
|
|
848 | const_iv (SDL_GL_DEPTH_SIZE), |
|
|
849 | const_iv (SDL_GL_STENCIL_SIZE), |
|
|
850 | const_iv (SDL_GL_ACCUM_RED_SIZE), |
|
|
851 | const_iv (SDL_GL_ACCUM_GREEN_SIZE), |
|
|
852 | const_iv (SDL_GL_ACCUM_BLUE_SIZE), |
|
|
853 | const_iv (SDL_GL_ACCUM_ALPHA_SIZE), |
|
|
854 | const_iv (SDL_GL_STEREO), |
|
|
855 | const_iv (SDL_GL_MULTISAMPLEBUFFERS), |
|
|
856 | const_iv (SDL_GL_MULTISAMPLESAMPLES), |
|
|
857 | const_iv (SDL_GL_ACCELERATED_VISUAL), |
|
|
858 | const_iv (SDL_GL_SWAP_CONTROL), |
|
|
859 | |
|
|
860 | const_iv (FOW_DARKNESS) |
611 | # undef const_iv |
861 | # undef const_iv |
612 | }; |
862 | }; |
613 | |
863 | |
614 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
864 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
615 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
865 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
616 | |
866 | |
617 | assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK); |
867 | assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK); |
618 | assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE); |
868 | assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE); |
619 | } |
869 | } |
620 | |
870 | |
… | |
… | |
632 | RETVAL |
882 | RETVAL |
633 | |
883 | |
634 | NV floor (NV x) |
884 | NV floor (NV x) |
635 | |
885 | |
636 | NV ceil (NV x) |
886 | NV ceil (NV x) |
|
|
887 | |
|
|
888 | IV minpot (UV n) |
|
|
889 | |
|
|
890 | IV popcount (UV n) |
|
|
891 | |
|
|
892 | NV distance (NV dx, NV dy) |
|
|
893 | CODE: |
|
|
894 | RETVAL = pow (dx * dx + dy * dy, 0.5); |
|
|
895 | OUTPUT: |
|
|
896 | RETVAL |
637 | |
897 | |
638 | void |
898 | void |
639 | pango_init () |
899 | pango_init () |
640 | CODE: |
900 | CODE: |
641 | { |
901 | { |
642 | opengl_fontmap = pango_opengl_font_map_new (); |
902 | opengl_fontmap = pango_opengl_font_map_new (); |
643 | pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); |
903 | pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); |
644 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
904 | opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); |
|
|
905 | /*pango_context_set_font_description (opengl_context, default_font);*/ |
|
|
906 | #if PANGO_VERSION_CHECK (1, 15, 2) |
|
|
907 | pango_context_set_language (opengl_context, pango_language_from_string ("en")); |
|
|
908 | /*pango_context_set_base_dir (opengl_context, PANGO_DIRECTION_WEAK_LTR);*/ |
|
|
909 | #endif |
645 | } |
910 | } |
646 | |
911 | |
647 | char * |
|
|
648 | SDL_GetError () |
912 | char *SDL_GetError () |
649 | |
913 | |
650 | int |
914 | void SDL_main_hack (SV *real_main) |
651 | SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE) |
915 | PROTOTYPE: & |
652 | |
916 | |
653 | void |
917 | int SDL_Init (U32 flags) |
|
|
918 | |
|
|
919 | int SDL_InitSubSystem (U32 flags) |
|
|
920 | |
|
|
921 | void SDL_QuitSubSystem (U32 flags) |
|
|
922 | |
654 | SDL_Quit () |
923 | void SDL_Quit () |
|
|
924 | |
|
|
925 | int SDL_GL_SetAttribute (int attr, int value) |
|
|
926 | C_ARGS: (SDL_GLattr)attr, value |
|
|
927 | |
|
|
928 | int SDL_GL_GetAttribute (int attr) |
|
|
929 | CODE: |
|
|
930 | if (SDL_GL_GetAttribute ((SDL_GLattr)attr, &RETVAL)) |
|
|
931 | XSRETURN_UNDEF; |
|
|
932 | OUTPUT: |
|
|
933 | RETVAL |
655 | |
934 | |
656 | void |
935 | void |
657 | SDL_ListModes (int rgb, int alpha) |
936 | SDL_ListModes (int rgb, int alpha) |
658 | PPCODE: |
937 | PPCODE: |
659 | { |
938 | { |
… | |
… | |
671 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
950 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
672 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); |
951 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE , 0); |
673 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
952 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
674 | |
953 | |
675 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
954 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
676 | #if SDL_VERSION_ATLEAST(1,2,10) |
|
|
677 | SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1); |
|
|
678 | SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); |
955 | SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); |
679 | #endif |
|
|
680 | |
956 | |
681 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
957 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
682 | |
958 | |
683 | if (m && m != (SDL_Rect **)-1) |
959 | if (m && m != (SDL_Rect **)-1) |
684 | while (*m) |
960 | while (*m) |
685 | { |
961 | { |
686 | if ((*m)->w >= 640 && (*m)->h >= 480) |
962 | if ((*m)->w >= 400 && (*m)->h >= 300) |
687 | { |
963 | { |
688 | AV *av = newAV (); |
964 | AV *av = newAV (); |
689 | av_push (av, newSViv ((*m)->w)); |
965 | av_push (av, newSViv ((*m)->w)); |
690 | av_push (av, newSViv ((*m)->h)); |
966 | av_push (av, newSViv ((*m)->h)); |
691 | av_push (av, newSViv (rgb)); |
967 | av_push (av, newSViv (rgb)); |
… | |
… | |
714 | ); |
990 | ); |
715 | |
991 | |
716 | if (RETVAL) |
992 | if (RETVAL) |
717 | { |
993 | { |
718 | av_clear (texture_av); |
994 | av_clear (texture_av); |
719 | |
|
|
720 | SDL_WM_SetCaption ("Crossfire+ Client " VERSION, "Crossfire+"); |
|
|
721 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
995 | #define GL_FUNC(ptr,name) gl.name = (ptr)SDL_GL_GetProcAddress ("gl" # name); |
722 | #include "glfunc.h" |
996 | #include "glfunc.h" |
723 | #undef GL_FUNC |
997 | #undef GL_FUNC |
|
|
998 | if (!gl.ActiveTexture ) gl.ActiveTexture = gl.ActiveTextureARB; |
|
|
999 | if (!gl.MultiTexCoord2f) gl.MultiTexCoord2f = gl.MultiTexCoord2fARB; |
724 | } |
1000 | } |
725 | } |
1001 | } |
726 | OUTPUT: |
1002 | OUTPUT: |
727 | RETVAL |
1003 | RETVAL |
|
|
1004 | |
|
|
1005 | void |
|
|
1006 | SDL_WM_SetCaption (const char *title, const char *icon) |
728 | |
1007 | |
729 | void |
1008 | void |
730 | SDL_GL_SwapBuffers () |
1009 | SDL_GL_SwapBuffers () |
731 | |
1010 | |
732 | char * |
1011 | char * |
733 | SDL_GetKeyName (int sym) |
1012 | SDL_GetKeyName (int sym) |
|
|
1013 | C_ARGS: (SDLKey)sym |
734 | |
1014 | |
735 | int |
1015 | int |
736 | SDL_GetAppState () |
1016 | SDL_GetAppState () |
737 | |
1017 | |
|
|
1018 | int |
|
|
1019 | SDL_GetModState () |
|
|
1020 | |
|
|
1021 | int |
|
|
1022 | SDL_WaitEvent () |
|
|
1023 | C_ARGS: 0 |
|
|
1024 | |
738 | void |
1025 | void |
|
|
1026 | SDL_PumpEvents () |
|
|
1027 | |
|
|
1028 | void |
739 | poll_events () |
1029 | peep_events () |
740 | PPCODE: |
1030 | PPCODE: |
741 | { |
1031 | { |
742 | SDL_Event ev; |
1032 | SDL_Event ev; |
743 | |
1033 | |
744 | SDL_PumpEvents (); |
1034 | SDL_PumpEvents (); |
… | |
… | |
751 | { |
1041 | { |
752 | case SDL_KEYDOWN: |
1042 | case SDL_KEYDOWN: |
753 | case SDL_KEYUP: |
1043 | case SDL_KEYUP: |
754 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
1044 | hv_store (hv, "state", 5, newSViv (ev.key.state), 0); |
755 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
1045 | hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); |
756 | hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); |
1046 | hv_store (hv, "mod", 3, newSViv (mod_munge (ev.key.keysym.mod)), 0); |
757 | hv_store (hv, "cmod", 4, newSViv (SDL_GetModState ()), 0); /* current mode */ |
1047 | hv_store (hv, "cmod", 4, newSViv (mod_munge (SDL_GetModState ())), 0); /* current mode */ |
758 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
1048 | hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); |
759 | break; |
1049 | break; |
760 | |
1050 | |
761 | case SDL_ACTIVEEVENT: |
1051 | case SDL_ACTIVEEVENT: |
762 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
1052 | hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); |
… | |
… | |
780 | x = ev.motion.x; |
1070 | x = ev.motion.x; |
781 | y = ev.motion.y; |
1071 | y = ev.motion.y; |
782 | SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); |
1072 | SDL_PeepEvents (&ev, 1, SDL_GETEVENT, SDL_EVENTMASK (SDL_MOUSEMOTION)); |
783 | } |
1073 | } |
784 | |
1074 | |
785 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); |
1075 | hv_store (hv, "mod", 3, newSViv (mod_munge (SDL_GetModState ())), 0); |
786 | hv_store (hv, "state", 5, newSViv (state), 0); |
1076 | hv_store (hv, "state", 5, newSViv (state), 0); |
787 | hv_store (hv, "x", 1, newSViv (x), 0); |
1077 | hv_store (hv, "x", 1, newSViv (x), 0); |
788 | hv_store (hv, "y", 1, newSViv (y), 0); |
1078 | hv_store (hv, "y", 1, newSViv (y), 0); |
789 | hv_store (hv, "xrel", 4, newSViv (xrel), 0); |
1079 | hv_store (hv, "xrel", 4, newSViv (xrel), 0); |
790 | hv_store (hv, "yrel", 4, newSViv (yrel), 0); |
1080 | hv_store (hv, "yrel", 4, newSViv (yrel), 0); |
791 | } |
1081 | } |
792 | break; |
1082 | break; |
793 | |
1083 | |
794 | case SDL_MOUSEBUTTONDOWN: |
1084 | case SDL_MOUSEBUTTONDOWN: |
795 | case SDL_MOUSEBUTTONUP: |
1085 | case SDL_MOUSEBUTTONUP: |
796 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState ()), 0); |
1086 | hv_store (hv, "mod", 3, newSViv (SDL_GetModState () & MOD_MASK), 0); |
797 | |
1087 | |
798 | hv_store (hv, "button", 6, newSViv (ev.button.button), 0); |
1088 | hv_store (hv, "button", 6, newSViv (ev.button.button), 0); |
799 | hv_store (hv, "state", 5, newSViv (ev.button.state), 0); |
1089 | hv_store (hv, "state", 5, newSViv (ev.button.state), 0); |
800 | hv_store (hv, "x", 1, newSViv (ev.button.x), 0); |
1090 | hv_store (hv, "x", 1, newSViv (ev.button.x), 0); |
801 | hv_store (hv, "y", 1, newSViv (ev.button.y), 0); |
1091 | hv_store (hv, "y", 1, newSViv (ev.button.y), 0); |
… | |
… | |
806 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
1096 | hv_store (hv, "data1", 5, newSViv ((IV)ev.user.data1), 0); |
807 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
1097 | hv_store (hv, "data2", 5, newSViv ((IV)ev.user.data2), 0); |
808 | break; |
1098 | break; |
809 | } |
1099 | } |
810 | |
1100 | |
811 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("CFPlus::UI::Event", 1)))); |
1101 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc ((SV *)hv), gv_stashpv ("DC::UI::Event", 1)))); |
812 | } |
1102 | } |
813 | } |
1103 | } |
814 | |
1104 | |
|
|
1105 | char * |
|
|
1106 | SDL_AudioDriverName () |
|
|
1107 | CODE: |
|
|
1108 | { |
|
|
1109 | char buf [256]; |
|
|
1110 | if (!SDL_AudioDriverName (buf, sizeof (buf))) |
|
|
1111 | XSRETURN_UNDEF; |
|
|
1112 | |
|
|
1113 | RETVAL = buf; |
|
|
1114 | } |
|
|
1115 | OUTPUT: |
|
|
1116 | RETVAL |
|
|
1117 | |
815 | int |
1118 | int |
816 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 1024) |
1119 | Mix_OpenAudio (int frequency = 44100, int format = MIX_DEFAULT_FORMAT, int channels = 2, int chunksize = 4096) |
817 | POSTCALL: |
1120 | POSTCALL: |
818 | Mix_HookMusicFinished (music_finished); |
1121 | Mix_HookMusicFinished (music_finished); |
819 | Mix_ChannelFinished (channel_finished); |
1122 | Mix_ChannelFinished (channel_finished); |
|
|
1123 | |
|
|
1124 | void |
|
|
1125 | Mix_QuerySpec () |
|
|
1126 | PPCODE: |
|
|
1127 | { |
|
|
1128 | int freq, channels; |
|
|
1129 | Uint16 format; |
|
|
1130 | |
|
|
1131 | if (Mix_QuerySpec (&freq, &format, &channels)) |
|
|
1132 | { |
|
|
1133 | EXTEND (SP, 3); |
|
|
1134 | PUSHs (sv_2mortal (newSViv (freq))); |
|
|
1135 | PUSHs (sv_2mortal (newSViv (format))); |
|
|
1136 | PUSHs (sv_2mortal (newSViv (channels))); |
|
|
1137 | } |
|
|
1138 | } |
820 | |
1139 | |
821 | void |
1140 | void |
822 | Mix_CloseAudio () |
1141 | Mix_CloseAudio () |
823 | |
1142 | |
824 | int |
1143 | int |
… | |
… | |
859 | } |
1178 | } |
860 | } |
1179 | } |
861 | #endif |
1180 | #endif |
862 | } |
1181 | } |
863 | |
1182 | |
864 | void |
1183 | int |
865 | add_font (char *file) |
1184 | add_font (char *file) |
866 | CODE: |
1185 | CODE: |
867 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
1186 | RETVAL = FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
|
|
1187 | OUTPUT: |
|
|
1188 | RETVAL |
|
|
1189 | |
|
|
1190 | void |
|
|
1191 | IMG_Init (int flags = IMG_INIT_JPG | IMG_INIT_PNG) |
|
|
1192 | |
|
|
1193 | # MIX_INIT_MP3 gives smpeg + libstdc++ + libgcc_s |
|
|
1194 | void |
|
|
1195 | Mix_Init (int flags = MIX_INIT_MOD | MIX_INIT_OGG) |
868 | |
1196 | |
869 | void |
1197 | void |
870 | load_image_inline (SV *image_) |
1198 | load_image_inline (SV *image_) |
871 | ALIAS: |
1199 | ALIAS: |
872 | load_image_file = 1 |
1200 | load_image_file = 1 |
… | |
… | |
918 | |
1246 | |
919 | SDL_LockSurface (surface2); |
1247 | SDL_LockSurface (surface2); |
920 | EXTEND (SP, 6); |
1248 | EXTEND (SP, 6); |
921 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
1249 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
922 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
1250 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
923 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
1251 | PUSHs (sv_2mortal (newSVpvn ((const char *)surface2->pixels, surface2->h * surface2->pitch))); |
924 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
1252 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
925 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
1253 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
926 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
1254 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_BYTE))); |
927 | SDL_UnlockSurface (surface2); |
1255 | SDL_UnlockSurface (surface2); |
928 | |
1256 | |
… | |
… | |
958 | void |
1286 | void |
959 | error (char *message) |
1287 | error (char *message) |
960 | CODE: |
1288 | CODE: |
961 | fprintf (stderr, "ERROR: %s\n", message); |
1289 | fprintf (stderr, "ERROR: %s\n", message); |
962 | #ifdef _WIN32 |
1290 | #ifdef _WIN32 |
963 | MessageBox (0, message, "Crossfire+ Error", MB_OK | MB_ICONERROR); |
1291 | MessageBox (0, message, "Deliantra Client Error", MB_OK | MB_ICONERROR); |
964 | #endif |
1292 | #endif |
965 | |
1293 | |
966 | void |
1294 | void |
967 | fatal (char *message) |
1295 | fatal (char *message) |
968 | CODE: |
1296 | CODE: |
969 | fprintf (stderr, "FATAL: %s\n", message); |
1297 | fprintf (stderr, "FATAL: %s\n", message); |
970 | #ifdef _WIN32 |
1298 | #ifdef _WIN32 |
971 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
1299 | MessageBox (0, message, "Deliantra Client Fatal Error", MB_OK | MB_ICONERROR); |
972 | #endif |
1300 | #endif |
973 | _exit (1); |
1301 | _exit (1); |
974 | |
1302 | |
975 | void |
1303 | void |
976 | _exit (int retval = 0) |
1304 | _exit (int retval = 0) |
… | |
… | |
988 | #if DEBUG |
1316 | #if DEBUG |
989 | VALGRIND_DO_LEAK_CHECK; |
1317 | VALGRIND_DO_LEAK_CHECK; |
990 | #endif |
1318 | #endif |
991 | } |
1319 | } |
992 | |
1320 | |
993 | MODULE = CFPlus PACKAGE = CFPlus::Font |
1321 | int |
|
|
1322 | SvREFCNT (SV *sv) |
|
|
1323 | CODE: |
|
|
1324 | RETVAL = SvREFCNT (sv); |
|
|
1325 | OUTPUT: |
|
|
1326 | RETVAL |
|
|
1327 | |
|
|
1328 | MODULE = Deliantra::Client PACKAGE = DC::Font |
994 | |
1329 | |
995 | PROTOTYPES: DISABLE |
1330 | PROTOTYPES: DISABLE |
996 | |
1331 | |
997 | CFPlus::Font |
1332 | DC::Font |
998 | new_from_file (SV *class, char *path, int id = 0) |
1333 | new_from_file (SV *klass, char *path, int id = 0) |
999 | CODE: |
1334 | CODE: |
1000 | { |
1335 | { |
1001 | int count; |
1336 | int count; |
1002 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1337 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)path, id, 0, &count); |
1003 | RETVAL = pango_fc_font_description_from_pattern (pattern, 0); |
1338 | RETVAL = pango_fc_font_description_from_pattern (pattern, 0); |
… | |
… | |
1005 | } |
1340 | } |
1006 | OUTPUT: |
1341 | OUTPUT: |
1007 | RETVAL |
1342 | RETVAL |
1008 | |
1343 | |
1009 | void |
1344 | void |
1010 | DESTROY (CFPlus::Font self) |
1345 | DESTROY (DC::Font self) |
1011 | CODE: |
1346 | CODE: |
1012 | pango_font_description_free (self); |
1347 | pango_font_description_free (self); |
1013 | |
1348 | |
1014 | void |
1349 | void |
1015 | make_default (CFPlus::Font self) |
1350 | make_default (DC::Font self) |
1016 | PROTOTYPE: $ |
1351 | PROTOTYPE: $ |
1017 | CODE: |
1352 | CODE: |
1018 | default_font = self; |
1353 | default_font = self; |
1019 | |
1354 | |
1020 | MODULE = CFPlus PACKAGE = CFPlus::Layout |
1355 | MODULE = Deliantra::Client PACKAGE = DC::Layout |
1021 | |
1356 | |
1022 | PROTOTYPES: DISABLE |
1357 | PROTOTYPES: DISABLE |
1023 | |
1358 | |
1024 | void |
1359 | void |
1025 | reset_glyph_cache () |
1360 | glyph_cache_backup () |
1026 | PROTOTYPE: |
1361 | PROTOTYPE: |
1027 | CODE: |
1362 | CODE: |
|
|
1363 | tc_backup (); |
|
|
1364 | |
|
|
1365 | void |
|
|
1366 | glyph_cache_restore () |
|
|
1367 | PROTOTYPE: |
|
|
1368 | CODE: |
1028 | tc_clear (); |
1369 | tc_restore (); |
1029 | |
1370 | |
1030 | CFPlus::Layout |
1371 | DC::Layout |
1031 | new (SV *class) |
1372 | new (SV *klass) |
1032 | CODE: |
1373 | CODE: |
1033 | New (0, RETVAL, 1, struct cf_layout); |
1374 | RETVAL = new cf_layout; |
1034 | |
1375 | |
1035 | RETVAL->pl = pango_layout_new (opengl_context); |
1376 | RETVAL->pl = pango_layout_new (opengl_context); |
1036 | RETVAL->r = 1.; |
1377 | RETVAL->r = 1.; |
1037 | RETVAL->g = 1.; |
1378 | RETVAL->g = 1.; |
1038 | RETVAL->b = 1.; |
1379 | RETVAL->b = 1.; |
1039 | RETVAL->a = 1.; |
1380 | RETVAL->a = 1.; |
1040 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1381 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1041 | RETVAL->font = 0; |
1382 | RETVAL->font = 0; |
1042 | RETVAL->rc = rc_alloc (); |
|
|
1043 | |
1383 | |
1044 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1384 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1045 | layout_update_font (RETVAL); |
1385 | layout_update_font (RETVAL); |
1046 | OUTPUT: |
1386 | OUTPUT: |
1047 | RETVAL |
1387 | RETVAL |
1048 | |
1388 | |
1049 | void |
1389 | void |
1050 | DESTROY (CFPlus::Layout self) |
1390 | DESTROY (DC::Layout self) |
1051 | CODE: |
1391 | CODE: |
1052 | g_object_unref (self->pl); |
1392 | g_object_unref (self->pl); |
1053 | rc_free (self->rc); |
|
|
1054 | Safefree (self); |
1393 | delete self; |
1055 | |
1394 | |
1056 | void |
1395 | void |
1057 | set_text (CFPlus::Layout self, SV *text_) |
1396 | set_text (DC::Layout self, SV *text_) |
1058 | CODE: |
1397 | CODE: |
1059 | { |
1398 | { |
1060 | STRLEN textlen; |
1399 | STRLEN textlen; |
1061 | char *text = SvPVutf8 (text_, textlen); |
1400 | char *text = SvPVutf8 (text_, textlen); |
1062 | |
1401 | |
1063 | pango_layout_set_text (self->pl, text, textlen); |
1402 | pango_layout_set_text (self->pl, text, textlen); |
1064 | } |
1403 | } |
1065 | |
1404 | |
1066 | void |
1405 | void |
1067 | set_markup (CFPlus::Layout self, SV *text_) |
1406 | set_markup (DC::Layout self, SV *text_) |
1068 | CODE: |
1407 | CODE: |
1069 | { |
1408 | { |
1070 | STRLEN textlen; |
1409 | STRLEN textlen; |
1071 | char *text = SvPVutf8 (text_, textlen); |
1410 | char *text = SvPVutf8 (text_, textlen); |
1072 | |
1411 | |
1073 | pango_layout_set_markup (self->pl, text, textlen); |
1412 | pango_layout_set_markup (self->pl, text, textlen); |
1074 | } |
1413 | } |
1075 | |
1414 | |
1076 | void |
1415 | void |
1077 | set_shapes (CFPlus::Layout self, ...) |
1416 | set_shapes (DC::Layout self, ...) |
1078 | CODE: |
1417 | CODE: |
1079 | { |
1418 | { |
1080 | PangoAttrList *attrs = 0; |
1419 | PangoAttrList *attrs = 0; |
1081 | const char *text = pango_layout_get_text (self->pl); |
1420 | const char *text = pango_layout_get_text (self->pl); |
1082 | const char *pos = text; |
1421 | const char *pos = text; |
… | |
… | |
1117 | if (attrs) |
1456 | if (attrs) |
1118 | pango_layout_set_attributes (self->pl, attrs); |
1457 | pango_layout_set_attributes (self->pl, attrs); |
1119 | } |
1458 | } |
1120 | |
1459 | |
1121 | void |
1460 | void |
1122 | get_shapes (CFPlus::Layout self) |
1461 | get_shapes (DC::Layout self) |
1123 | PPCODE: |
1462 | PPCODE: |
1124 | { |
1463 | { |
1125 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
1464 | PangoLayoutIter *iter = pango_layout_get_iter (self->pl); |
1126 | |
1465 | |
1127 | do |
1466 | do |
1128 | { |
1467 | { |
1129 | PangoLayoutRun *run = pango_layout_iter_get_run (iter); |
1468 | PangoLayoutRun *run = pango_layout_iter_get_run_readonly (iter); |
1130 | |
1469 | |
1131 | if (run && shape_attr_p (run)) |
1470 | if (run && shape_attr_p (run)) |
1132 | { |
1471 | { |
1133 | PangoRectangle extents; |
1472 | PangoRectangle extents; |
1134 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
1473 | pango_layout_iter_get_run_extents (iter, 0, &extents); |
… | |
… | |
1142 | |
1481 | |
1143 | pango_layout_iter_free (iter); |
1482 | pango_layout_iter_free (iter); |
1144 | } |
1483 | } |
1145 | |
1484 | |
1146 | int |
1485 | int |
1147 | has_wrapped (CFPlus::Layout self) |
1486 | has_wrapped (DC::Layout self) |
1148 | CODE: |
1487 | CODE: |
1149 | { |
1488 | { |
1150 | int lines = 1; |
1489 | int lines = 1; |
1151 | const char *text = pango_layout_get_text (self->pl); |
1490 | const char *text = pango_layout_get_text (self->pl); |
1152 | |
1491 | |
… | |
… | |
1157 | } |
1496 | } |
1158 | OUTPUT: |
1497 | OUTPUT: |
1159 | RETVAL |
1498 | RETVAL |
1160 | |
1499 | |
1161 | SV * |
1500 | SV * |
1162 | get_text (CFPlus::Layout self) |
1501 | get_text (DC::Layout self) |
1163 | CODE: |
1502 | CODE: |
1164 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
1503 | RETVAL = newSVpv (pango_layout_get_text (self->pl), 0); |
1165 | sv_utf8_decode (RETVAL); |
1504 | sv_utf8_decode (RETVAL); |
1166 | OUTPUT: |
1505 | OUTPUT: |
1167 | RETVAL |
1506 | RETVAL |
1168 | |
1507 | |
1169 | void |
1508 | void |
1170 | set_foreground (CFPlus::Layout self, float r, float g, float b, float a = 1.) |
1509 | set_foreground (DC::Layout self, float r, float g, float b, float a = 1.) |
1171 | CODE: |
1510 | CODE: |
1172 | self->r = r; |
1511 | self->r = r; |
1173 | self->g = g; |
1512 | self->g = g; |
1174 | self->b = b; |
1513 | self->b = b; |
1175 | self->a = a; |
1514 | self->a = a; |
1176 | |
1515 | |
1177 | void |
1516 | void |
1178 | set_font (CFPlus::Layout self, CFPlus::Font font = 0) |
1517 | set_font (DC::Layout self, DC::Font font = 0) |
1179 | CODE: |
1518 | CODE: |
1180 | if (self->font != font) |
1519 | if (self->font != font) |
1181 | { |
1520 | { |
1182 | self->font = font; |
1521 | self->font = font; |
1183 | layout_update_font (self); |
1522 | layout_update_font (self); |
1184 | } |
1523 | } |
1185 | |
1524 | |
1186 | void |
1525 | void |
1187 | set_height (CFPlus::Layout self, int base_height) |
1526 | set_height (DC::Layout self, int base_height) |
1188 | CODE: |
1527 | CODE: |
1189 | if (self->base_height != base_height) |
1528 | if (self->base_height != base_height) |
1190 | { |
1529 | { |
1191 | self->base_height = base_height; |
1530 | self->base_height = base_height; |
1192 | layout_update_font (self); |
1531 | layout_update_font (self); |
1193 | } |
1532 | } |
1194 | |
1533 | |
1195 | void |
1534 | void |
1196 | set_width (CFPlus::Layout self, int max_width = -1) |
1535 | set_width (DC::Layout self, int max_width = -1) |
1197 | CODE: |
1536 | CODE: |
1198 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
1537 | pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); |
1199 | |
1538 | |
1200 | void |
1539 | void |
1201 | set_indent (CFPlus::Layout self, int indent) |
1540 | set_indent (DC::Layout self, int indent) |
1202 | CODE: |
1541 | CODE: |
1203 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1542 | pango_layout_set_indent (self->pl, indent * PANGO_SCALE); |
1204 | |
1543 | |
1205 | void |
1544 | void |
1206 | set_spacing (CFPlus::Layout self, int spacing) |
1545 | set_spacing (DC::Layout self, int spacing) |
1207 | CODE: |
1546 | CODE: |
1208 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1547 | pango_layout_set_spacing (self->pl, spacing * PANGO_SCALE); |
1209 | |
1548 | |
1210 | void |
1549 | void |
1211 | set_ellipsise (CFPlus::Layout self, int ellipsise) |
1550 | set_ellipsise (DC::Layout self, int ellipsise) |
1212 | CODE: |
1551 | CODE: |
1213 | pango_layout_set_ellipsize (self->pl, |
1552 | pango_layout_set_ellipsize (self->pl, |
1214 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1553 | ellipsise == 1 ? PANGO_ELLIPSIZE_START |
1215 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1554 | : ellipsise == 2 ? PANGO_ELLIPSIZE_MIDDLE |
1216 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1555 | : ellipsise == 3 ? PANGO_ELLIPSIZE_END |
1217 | : PANGO_ELLIPSIZE_NONE |
1556 | : PANGO_ELLIPSIZE_NONE |
1218 | ); |
1557 | ); |
1219 | |
1558 | |
1220 | void |
1559 | void |
1221 | set_single_paragraph_mode (CFPlus::Layout self, int spm) |
1560 | set_single_paragraph_mode (DC::Layout self, int spm) |
1222 | CODE: |
1561 | CODE: |
1223 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1562 | pango_layout_set_single_paragraph_mode (self->pl, !!spm); |
1224 | |
1563 | |
1225 | void |
1564 | void |
1226 | size (CFPlus::Layout self) |
1565 | size (DC::Layout self) |
1227 | PPCODE: |
1566 | PPCODE: |
1228 | { |
1567 | { |
1229 | int w, h; |
1568 | int w, h; |
1230 | |
1569 | |
1231 | layout_get_pixel_size (self, &w, &h); |
1570 | layout_get_pixel_size (self, &w, &h); |
… | |
… | |
1234 | PUSHs (sv_2mortal (newSViv (w))); |
1573 | PUSHs (sv_2mortal (newSViv (w))); |
1235 | PUSHs (sv_2mortal (newSViv (h))); |
1574 | PUSHs (sv_2mortal (newSViv (h))); |
1236 | } |
1575 | } |
1237 | |
1576 | |
1238 | int |
1577 | int |
1239 | descent (CFPlus::Layout self) |
1578 | descent (DC::Layout self) |
1240 | CODE: |
1579 | CODE: |
1241 | { |
1580 | { |
1242 | PangoRectangle rect; |
1581 | PangoRectangle rect; |
1243 | PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); |
1582 | PangoLayoutLine *line = pango_layout_get_line_readonly (self->pl, 0); |
1244 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1583 | pango_layout_line_get_pixel_extents (line, 0, &rect); |
1245 | RETVAL = PANGO_DESCENT (rect); |
1584 | RETVAL = PANGO_DESCENT (rect); |
1246 | } |
1585 | } |
1247 | OUTPUT: |
1586 | OUTPUT: |
1248 | RETVAL |
1587 | RETVAL |
1249 | |
1588 | |
1250 | int |
1589 | int |
1251 | xy_to_index (CFPlus::Layout self, int x, int y) |
1590 | xy_to_index (DC::Layout self, int x, int y) |
1252 | CODE: |
1591 | CODE: |
1253 | { |
1592 | { |
1254 | int index, trailing; |
1593 | int index, trailing; |
1255 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1594 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1256 | RETVAL = index + trailing; |
1595 | RETVAL = index + trailing; |
1257 | } |
1596 | } |
1258 | OUTPUT: |
1597 | OUTPUT: |
1259 | RETVAL |
1598 | RETVAL |
1260 | |
1599 | |
1261 | void |
1600 | void |
1262 | cursor_pos (CFPlus::Layout self, int index) |
1601 | cursor_pos (DC::Layout self, int index) |
1263 | PPCODE: |
1602 | PPCODE: |
1264 | { |
1603 | { |
1265 | PangoRectangle strong_pos; |
1604 | PangoRectangle pos; |
1266 | pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); |
1605 | pango_layout_get_cursor_pos (self->pl, index, &pos, 0); |
1267 | |
1606 | |
1268 | EXTEND (SP, 3); |
1607 | EXTEND (SP, 3); |
1269 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
1608 | PUSHs (sv_2mortal (newSViv (pos.x / PANGO_SCALE))); |
1270 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1609 | PUSHs (sv_2mortal (newSViv (pos.y / PANGO_SCALE))); |
1271 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1610 | PUSHs (sv_2mortal (newSViv (pos.height / PANGO_SCALE))); |
1272 | } |
1611 | } |
1273 | |
1612 | |
1274 | void |
1613 | void |
1275 | index_to_line_x (CFPlus::Layout self, int index, int trailing = 0) |
1614 | index_to_line_x (DC::Layout self, int index, int trailing = 0) |
1276 | PPCODE: |
1615 | PPCODE: |
1277 | { |
1616 | { |
1278 | int line, x; |
1617 | int line, x; |
1279 | |
1618 | |
1280 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
1619 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
|
|
1620 | #if !PANGO_VERSION_CHECK (1, 17, 3) |
1281 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1621 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
1282 | |
1622 | --line; |
|
|
1623 | #endif |
1283 | EXTEND (SP, 2); |
1624 | EXTEND (SP, 2); |
1284 | PUSHs (sv_2mortal (newSViv (line - 1))); |
1625 | PUSHs (sv_2mortal (newSViv (line))); |
1285 | PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); |
1626 | PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); |
1286 | } |
1627 | } |
1287 | |
1628 | |
1288 | void |
1629 | void |
1289 | line_x_to_index (CFPlus::Layout self, int line, int x) |
1630 | line_x_to_index (DC::Layout self, int line, int x) |
1290 | PPCODE: |
1631 | PPCODE: |
1291 | { |
1632 | { |
1292 | PangoLayoutLine *lp; |
1633 | PangoLayoutLine *lp; |
1293 | int index, trailing; |
1634 | int index, trailing; |
1294 | |
1635 | |
1295 | if (line < 0) |
1636 | if (line < 0) |
1296 | XSRETURN_EMPTY; |
1637 | XSRETURN_EMPTY; |
1297 | |
1638 | |
1298 | if (!(lp = pango_layout_get_line (self->pl, line))) |
1639 | if (!(lp = pango_layout_get_line_readonly (self->pl, line))) |
1299 | XSRETURN_EMPTY; /* do better */ |
1640 | XSRETURN_EMPTY; /* do better */ |
1300 | |
1641 | |
1301 | pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); |
1642 | pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); |
1302 | |
1643 | |
1303 | EXTEND (SP, 2); |
1644 | EXTEND (SP, 2); |
… | |
… | |
1309 | PUSHs (sv_2mortal (newSViv (trailing))); |
1650 | PUSHs (sv_2mortal (newSViv (trailing))); |
1310 | } |
1651 | } |
1311 | } |
1652 | } |
1312 | |
1653 | |
1313 | void |
1654 | void |
1314 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1655 | render (DC::Layout self, float x, float y, int flags = 0) |
1315 | CODE: |
1656 | CODE: |
1316 | rc_clear (self->rc); |
1657 | self->rc.clear (); |
1317 | pango_opengl_render_layout_subpixel ( |
1658 | pango_opengl_render_layout_subpixel ( |
1318 | self->pl, |
1659 | self->pl, |
1319 | self->rc, |
1660 | &self->rc, |
1320 | x * PANGO_SCALE, y * PANGO_SCALE, |
1661 | x * PANGO_SCALE, y * PANGO_SCALE, |
1321 | self->r, self->g, self->b, self->a, |
1662 | self->r, self->g, self->b, self->a, |
1322 | flags |
1663 | flags |
1323 | ); |
1664 | ); |
1324 | // we assume that context_change actually clears/frees stuff |
1665 | // we assume that context_change actually clears/frees stuff |
1325 | // and does not do any recomputation... |
1666 | // and does not do any recomputation... |
1326 | pango_layout_context_changed (self->pl); |
1667 | pango_layout_context_changed (self->pl); |
1327 | |
1668 | |
1328 | void |
1669 | void |
1329 | draw (CFPlus::Layout self) |
1670 | draw (DC::Layout self) |
1330 | CODE: |
1671 | CODE: |
1331 | { |
1672 | { |
1332 | glEnable (GL_TEXTURE_2D); |
1673 | glEnable (GL_TEXTURE_2D); |
1333 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
1674 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
1334 | glEnable (GL_BLEND); |
1675 | glEnable (GL_BLEND); |
1335 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
1676 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
1336 | GL_ONE , GL_ONE_MINUS_SRC_ALPHA); |
1677 | GL_ONE , GL_ONE_MINUS_SRC_ALPHA); |
1337 | glEnable (GL_ALPHA_TEST); |
1678 | glEnable (GL_ALPHA_TEST); |
1338 | glAlphaFunc (GL_GREATER, 7.f / 255.f); |
1679 | glAlphaFunc (GL_GREATER, 7.f / 255.f); |
1339 | |
1680 | |
1340 | rc_draw (self->rc); |
1681 | self->rc.draw (); |
1341 | |
1682 | |
1342 | glDisable (GL_ALPHA_TEST); |
1683 | glDisable (GL_ALPHA_TEST); |
1343 | glDisable (GL_BLEND); |
1684 | glDisable (GL_BLEND); |
1344 | glDisable (GL_TEXTURE_2D); |
1685 | glDisable (GL_TEXTURE_2D); |
1345 | } |
1686 | } |
1346 | |
1687 | |
1347 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1688 | MODULE = Deliantra::Client PACKAGE = DC::Texture |
1348 | |
1689 | |
1349 | PROTOTYPES: ENABLE |
1690 | PROTOTYPES: ENABLE |
1350 | |
|
|
1351 | int minpot (int n) |
|
|
1352 | |
1691 | |
1353 | void |
1692 | void |
1354 | pad (SV *data_, int ow, int oh, int nw, int nh) |
1693 | pad (SV *data_, int ow, int oh, int nw, int nh) |
1355 | CODE: |
1694 | CODE: |
1356 | { |
1695 | { |
… | |
… | |
1422 | glDisable (GL_ALPHA_TEST); |
1761 | glDisable (GL_ALPHA_TEST); |
1423 | glDisable (GL_BLEND); |
1762 | glDisable (GL_BLEND); |
1424 | } |
1763 | } |
1425 | } |
1764 | } |
1426 | |
1765 | |
|
|
1766 | void |
|
|
1767 | draw_fow_texture (float intensity, int hidden_tex, int name1, uint8_t *data1, float s, float t, int w, int h, float blend = 0.f, int dx = 0, int dy = 0, int name2 = 0, uint8_t *data2 = data1) |
|
|
1768 | PROTOTYPE: @ |
|
|
1769 | CODE: |
|
|
1770 | { |
|
|
1771 | glEnable (GL_BLEND); |
|
|
1772 | glBlendFunc (intensity ? GL_SRC_ALPHA : GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
|
|
1773 | glEnable (GL_TEXTURE_2D); |
|
|
1774 | glBindTexture (GL_TEXTURE_2D, name1); |
|
|
1775 | |
|
|
1776 | glColor3f (intensity, intensity, intensity); |
|
|
1777 | glPushMatrix (); |
|
|
1778 | glScalef (1./3, 1./3, 1.); |
|
|
1779 | |
|
|
1780 | if (blend > 0.f) |
|
|
1781 | { |
|
|
1782 | float dx3 = dx * -3.f / w; |
|
|
1783 | float dy3 = dy * -3.f / h; |
|
|
1784 | GLfloat env_color[4] = { 0., 0., 0., blend }; |
|
|
1785 | |
|
|
1786 | /* interpolate the two shadow textures */ |
|
|
1787 | /* stage 0 == rgb(glcolor) + alpha(t0) */ |
|
|
1788 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
|
|
1789 | |
|
|
1790 | /* stage 1 == rgb(glcolor) + alpha(interpolate t0, t1, texenv) */ |
|
|
1791 | gl.ActiveTexture (GL_TEXTURE1); |
|
|
1792 | glEnable (GL_TEXTURE_2D); |
|
|
1793 | glBindTexture (GL_TEXTURE_2D, name2); |
|
|
1794 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); |
|
|
1795 | |
|
|
1796 | /* rgb == rgb(glcolor) */ |
|
|
1797 | glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE); |
|
|
1798 | glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PRIMARY_COLOR); |
|
|
1799 | glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); |
|
|
1800 | |
|
|
1801 | /* alpha = interpolate t0, t1 by env_alpha */ |
|
|
1802 | glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, env_color); |
|
|
1803 | |
|
|
1804 | glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_INTERPOLATE); |
|
|
1805 | glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE); |
|
|
1806 | glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); |
|
|
1807 | |
|
|
1808 | glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PREVIOUS); |
|
|
1809 | glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA); |
|
|
1810 | |
|
|
1811 | glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_CONSTANT); |
|
|
1812 | glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA); |
|
|
1813 | |
|
|
1814 | glBegin (GL_QUADS); |
|
|
1815 | gl.MultiTexCoord2f (GL_TEXTURE0, 0, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 , dy3 ); glVertex2i (0, 0); |
|
|
1816 | gl.MultiTexCoord2f (GL_TEXTURE0, 0, t); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 , dy3 + t); glVertex2i (0, h); |
|
|
1817 | gl.MultiTexCoord2f (GL_TEXTURE0, s, t); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 + s, dy3 + t); glVertex2i (w, h); |
|
|
1818 | gl.MultiTexCoord2f (GL_TEXTURE0, s, 0); gl.MultiTexCoord2f (GL_TEXTURE1, dx3 + s, dy3 ); glVertex2i (w, 0); |
|
|
1819 | glEnd (); |
|
|
1820 | |
|
|
1821 | glDisable (GL_TEXTURE_2D); |
|
|
1822 | gl.ActiveTexture (GL_TEXTURE0); |
|
|
1823 | } |
|
|
1824 | else |
|
|
1825 | { |
|
|
1826 | /* simple blending of one texture, also opengl <1.3 path */ |
|
|
1827 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
|
|
1828 | |
|
|
1829 | glBegin (GL_QUADS); |
|
|
1830 | glTexCoord2f (0, 0); glVertex2f (0, 0); |
|
|
1831 | glTexCoord2f (0, t); glVertex2f (0, h); |
|
|
1832 | glTexCoord2f (s, t); glVertex2f (w, h); |
|
|
1833 | glTexCoord2f (s, 0); glVertex2f (w, 0); |
|
|
1834 | glEnd (); |
|
|
1835 | } |
|
|
1836 | |
|
|
1837 | /* draw ?-marks or equivalent, this is very clumsy code :/ */ |
|
|
1838 | { |
|
|
1839 | int x, y; |
|
|
1840 | int dx3 = dx * 3; |
|
|
1841 | int dy3 = dy * 3; |
|
|
1842 | |
|
|
1843 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
|
|
1844 | glBindTexture (GL_TEXTURE_2D, hidden_tex); |
|
|
1845 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
1846 | glTranslatef (-1., -1., 0); |
|
|
1847 | glBegin (GL_QUADS); |
|
|
1848 | |
|
|
1849 | for (y = 1; y < h; y += 3) |
|
|
1850 | { |
|
|
1851 | int y1 = y - dy3; |
|
|
1852 | int y1valid = y1 >= 0 && y1 < h; |
|
|
1853 | |
|
|
1854 | for (x = 1; x < w; x += 3) |
|
|
1855 | { |
|
|
1856 | int x1 = x - dx3; |
|
|
1857 | uint8_t h1 = data1 [x + y * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS); |
|
|
1858 | uint8_t h2; |
|
|
1859 | |
|
|
1860 | if (y1valid && x1 >= 0 && x1 < w) |
|
|
1861 | h2 = data2 [x1 + y1 * w] == DARKNESS_ADJUST (255 - FOW_DARKNESS); |
|
|
1862 | else |
|
|
1863 | h2 = 1; /* out of range == invisible */ |
|
|
1864 | |
|
|
1865 | if (h1 || h2) |
|
|
1866 | { |
|
|
1867 | float alpha = h1 == h2 ? 1.f : h1 ? 1.f - blend : blend; |
|
|
1868 | glColor4f (1., 1., 1., alpha); |
|
|
1869 | |
|
|
1870 | glTexCoord2f (0, 0.); glVertex2i (x , y ); |
|
|
1871 | glTexCoord2f (0, 1.); glVertex2i (x , y + 3); |
|
|
1872 | glTexCoord2f (1, 1.); glVertex2i (x + 3, y + 3); |
|
|
1873 | glTexCoord2f (1, 0.); glVertex2i (x + 3, y ); |
|
|
1874 | } |
|
|
1875 | } |
|
|
1876 | } |
|
|
1877 | } |
|
|
1878 | |
|
|
1879 | glEnd (); |
|
|
1880 | |
|
|
1881 | glPopMatrix (); |
|
|
1882 | |
|
|
1883 | glDisable (GL_TEXTURE_2D); |
|
|
1884 | glDisable (GL_BLEND); |
|
|
1885 | } |
|
|
1886 | |
1427 | IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type) |
1887 | IV texture_valid_2d (GLint internalformat, GLsizei w, GLsizei h, GLenum format, GLenum type) |
1428 | CODE: |
1888 | CODE: |
1429 | { |
1889 | { |
1430 | GLint width; |
1890 | GLint width; |
1431 | glTexImage2D (GL_PROXY_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, 0); |
1891 | glTexImage2D (GL_PROXY_TEXTURE_2D, 0, internalformat, w, h, 0, format, type, 0); |
… | |
… | |
1433 | RETVAL = width > 0; |
1893 | RETVAL = width > 0; |
1434 | } |
1894 | } |
1435 | OUTPUT: |
1895 | OUTPUT: |
1436 | RETVAL |
1896 | RETVAL |
1437 | |
1897 | |
1438 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1898 | MODULE = Deliantra::Client PACKAGE = DC::Map |
1439 | |
1899 | |
1440 | PROTOTYPES: DISABLE |
1900 | PROTOTYPES: DISABLE |
1441 | |
1901 | |
1442 | CFPlus::Map |
1902 | DC::Map |
1443 | new (SV *class) |
1903 | new (SV *klass) |
1444 | CODE: |
1904 | CODE: |
1445 | New (0, RETVAL, 1, struct map); |
1905 | New (0, RETVAL, 1, mapgrid); |
1446 | RETVAL->x = 0; |
1906 | RETVAL->x = 0; |
1447 | RETVAL->y = 0; |
1907 | RETVAL->y = 0; |
1448 | RETVAL->w = 0; |
1908 | RETVAL->w = 0; |
1449 | RETVAL->h = 0; |
1909 | RETVAL->h = 0; |
1450 | RETVAL->ox = 0; |
1910 | RETVAL->ox = 0; |
… | |
… | |
1455 | RETVAL->row = 0; |
1915 | RETVAL->row = 0; |
1456 | OUTPUT: |
1916 | OUTPUT: |
1457 | RETVAL |
1917 | RETVAL |
1458 | |
1918 | |
1459 | void |
1919 | void |
1460 | DESTROY (CFPlus::Map self) |
1920 | DESTROY (DC::Map self) |
1461 | CODE: |
1921 | CODE: |
1462 | { |
1922 | { |
1463 | map_clear (self); |
1923 | map_clear (self); |
1464 | Safefree (self->face2tile); |
1924 | Safefree (self->face2tile); |
1465 | Safefree (self->tex); |
1925 | Safefree (self->tex); |
1466 | Safefree (self); |
1926 | Safefree (self); |
1467 | } |
1927 | } |
1468 | |
1928 | |
1469 | void |
1929 | void |
1470 | resize (CFPlus::Map self, int map_width, int map_height) |
1930 | resize (DC::Map self, int map_width, int map_height) |
1471 | CODE: |
1931 | CODE: |
1472 | self->w = map_width; |
1932 | self->w = map_width; |
1473 | self->h = map_height; |
1933 | self->h = map_height; |
1474 | |
1934 | |
1475 | void |
1935 | void |
1476 | clear (CFPlus::Map self) |
1936 | clear (DC::Map self) |
1477 | CODE: |
1937 | CODE: |
1478 | map_clear (self); |
1938 | map_clear (self); |
1479 | |
1939 | |
1480 | void |
1940 | void |
1481 | set_tileid (CFPlus::Map self, int face, int tile) |
1941 | set_tileid (DC::Map self, int face, int tile) |
1482 | CODE: |
1942 | CODE: |
1483 | { |
1943 | { |
1484 | need_facenum (self, face); self->face2tile [face] = tile; |
1944 | need_facenum (self, face); self->face2tile [face] = tile; |
1485 | need_texid (self, tile); |
1945 | need_texid (self, tile); |
1486 | } |
1946 | } |
1487 | |
1947 | |
1488 | void |
1948 | void |
1489 | set_smooth (CFPlus::Map self, int face, int smooth, int level) |
1949 | set_smooth (DC::Map self, int face, int smooth, int level) |
1490 | CODE: |
1950 | CODE: |
1491 | { |
1951 | { |
1492 | tileid texid; |
1952 | tileid texid; |
1493 | maptex *tex; |
1953 | maptex *tex; |
1494 | |
1954 | |
1495 | if (face < 0 || face >= self->faces) |
1955 | if (face < 0 || face >= self->faces) |
1496 | return; |
1956 | return; |
1497 | |
1957 | |
1498 | if (smooth < 0 || smooth >= self->faces) |
1958 | if (smooth < 0 || smooth >= self->faces) |
1499 | return; |
1959 | return; |
1500 | |
1960 | |
1501 | texid = self->face2tile [face]; |
1961 | texid = self->face2tile [face]; |
1502 | |
1962 | |
1503 | if (!texid) |
1963 | if (!texid) |
1504 | return; |
1964 | return; |
1505 | |
1965 | |
1506 | tex = self->tex + texid; |
1966 | tex = self->tex + texid; |
1507 | tex->smoothtile = self->face2tile [smooth]; |
1967 | tex->smoothtile = self->face2tile [smooth]; |
1508 | tex->smoothlevel = level; |
1968 | tex->smoothlevel = level; |
1509 | } |
1969 | } |
1510 | |
1970 | |
1511 | void |
1971 | void |
1512 | set_texture (CFPlus::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) |
1972 | set_texture (DC::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) |
1513 | CODE: |
1973 | CODE: |
1514 | { |
1974 | { |
1515 | need_texid (self, texid); |
1975 | need_texid (self, texid); |
1516 | |
1976 | |
1517 | { |
1977 | { |
… | |
… | |
1536 | // use uglier nearest interpolation because linear suffers |
1996 | // use uglier nearest interpolation because linear suffers |
1537 | // from transparent color bleeding and ugly wrapping effects. |
1997 | // from transparent color bleeding and ugly wrapping effects. |
1538 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1998 | glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
1539 | } |
1999 | } |
1540 | |
2000 | |
|
|
2001 | void |
|
|
2002 | expire_textures (DC::Map self, int texid, int count) |
|
|
2003 | PPCODE: |
|
|
2004 | for (; texid < self->texs && count; ++texid, --count) |
|
|
2005 | { |
|
|
2006 | maptex *tex = self->tex + texid; |
|
|
2007 | |
|
|
2008 | if (tex->name) |
|
|
2009 | { |
|
|
2010 | if (tex->unused) |
|
|
2011 | { |
|
|
2012 | tex->name = 0; |
|
|
2013 | tex->unused = 0; |
|
|
2014 | XPUSHs (sv_2mortal (newSViv (texid))); |
|
|
2015 | } |
|
|
2016 | else |
|
|
2017 | tex->unused = 1; |
|
|
2018 | } |
|
|
2019 | } |
|
|
2020 | |
1541 | int |
2021 | int |
1542 | ox (CFPlus::Map self) |
2022 | ox (DC::Map self) |
1543 | ALIAS: |
2023 | ALIAS: |
1544 | oy = 1 |
2024 | oy = 1 |
1545 | x = 2 |
2025 | x = 2 |
1546 | y = 3 |
2026 | y = 3 |
1547 | w = 4 |
2027 | w = 4 |
… | |
… | |
1558 | } |
2038 | } |
1559 | OUTPUT: |
2039 | OUTPUT: |
1560 | RETVAL |
2040 | RETVAL |
1561 | |
2041 | |
1562 | void |
2042 | void |
1563 | scroll (CFPlus::Map self, int dx, int dy) |
2043 | scroll (DC::Map self, int dx, int dy) |
1564 | CODE: |
2044 | CODE: |
1565 | { |
2045 | { |
1566 | if (dx > 0) |
2046 | if (dx > 0) |
1567 | map_blank (self, self->x, self->y, dx, self->h); |
2047 | map_blank (self, self->x, self->y, dx, self->h); |
1568 | else if (dx < 0) |
2048 | else if (dx < 0) |
… | |
… | |
1584 | self->y += MAP_EXTEND_Y; |
2064 | self->y += MAP_EXTEND_Y; |
1585 | } |
2065 | } |
1586 | } |
2066 | } |
1587 | |
2067 | |
1588 | SV * |
2068 | SV * |
1589 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
2069 | map1a_update (DC::Map self, SV *data_) |
1590 | CODE: |
2070 | CODE: |
1591 | { |
2071 | { |
1592 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
2072 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1593 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
2073 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1594 | mapcell *cell; |
2074 | mapcell *cell; |
… | |
… | |
1615 | |
2095 | |
1616 | //TODO: don't trust server data to be in-range(!) |
2096 | //TODO: don't trust server data to be in-range(!) |
1617 | |
2097 | |
1618 | if (flags & 8) |
2098 | if (flags & 8) |
1619 | { |
2099 | { |
|
|
2100 | uint8_t ext, cmd; |
|
|
2101 | |
1620 | if (extmap) |
2102 | do |
1621 | { |
2103 | { |
1622 | uint8_t ext, cmd; |
2104 | ext = *data++; |
|
|
2105 | cmd = ext & 0x7f; |
1623 | |
2106 | |
1624 | do |
2107 | if (cmd < 4) |
|
|
2108 | cell->darkness = 255 - ext * 64 + 1; /* make sure this doesn't collide with FOW_DARKNESS */ |
|
|
2109 | else if (cmd == 5) // health |
1625 | { |
2110 | { |
1626 | ext = *data++; |
|
|
1627 | cmd = ext & 0x3f; |
|
|
1628 | |
|
|
1629 | if (cmd < 4) |
|
|
1630 | cell->darkness = 255 - ext * 64 + 1; |
|
|
1631 | else if (cmd == 5) // health |
|
|
1632 | { |
|
|
1633 | cell->stat_width = 1; |
2111 | cell->stat_width = 1; |
1634 | cell->stat_hp = *data++; |
2112 | cell->stat_hp = *data++; |
1635 | } |
|
|
1636 | else if (cmd == 6) // monster width |
|
|
1637 | cell->stat_width = *data++ + 1; |
|
|
1638 | else if (cmd == 0x47) |
|
|
1639 | { |
|
|
1640 | if (*data == 4) |
|
|
1641 | ; // decode player count |
|
|
1642 | |
|
|
1643 | data += *data + 1; |
|
|
1644 | } |
|
|
1645 | else if (cmd == 8) // cell flags |
|
|
1646 | cell->flags = *data++; |
|
|
1647 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
1648 | data += *data + 1; |
|
|
1649 | else |
|
|
1650 | data++; |
|
|
1651 | } |
2113 | } |
1652 | while (ext & 0x80); |
2114 | else if (cmd == 6) // monster width |
|
|
2115 | cell->stat_width = *data++ + 1; |
|
|
2116 | else if (cmd == 0x47) |
|
|
2117 | { |
|
|
2118 | if (*data == 1) cell->player = data [1]; |
|
|
2119 | else if (*data == 2) cell->player = data [2] + (data [1] << 8); |
|
|
2120 | else if (*data == 3) cell->player = data [3] + (data [2] << 8) + (data [1] << 16); |
|
|
2121 | else if (*data == 4) cell->player = data [4] + (data [3] << 8) + (data [2] << 16) + (data [1] << 24); |
|
|
2122 | |
|
|
2123 | data += *data + 1; |
|
|
2124 | } |
|
|
2125 | else if (cmd == 8) // cell flags |
|
|
2126 | cell->flags = *data++; |
|
|
2127 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
2128 | data += *data + 1; |
|
|
2129 | else |
|
|
2130 | data++; |
1653 | } |
2131 | } |
1654 | else |
2132 | while (ext & 0x80); |
1655 | cell->darkness = *data++ + 1; |
|
|
1656 | } |
2133 | } |
1657 | |
2134 | |
1658 | for (z = 0; z <= 2; ++z) |
2135 | for (z = 0; z <= 2; ++z) |
1659 | if (flags & (4 >> z)) |
2136 | if (flags & (4 >> z)) |
1660 | { |
2137 | { |
… | |
… | |
1663 | cell->tile [z] = self->face2tile [face]; |
2140 | cell->tile [z] = self->face2tile [face]; |
1664 | |
2141 | |
1665 | if (cell->tile [z]) |
2142 | if (cell->tile [z]) |
1666 | { |
2143 | { |
1667 | maptex *tex = self->tex + cell->tile [z]; |
2144 | maptex *tex = self->tex + cell->tile [z]; |
|
|
2145 | tex->unused = 0; |
1668 | if (!tex->name) |
2146 | if (!tex->name) |
1669 | av_push (missing, newSViv (cell->tile [z])); |
2147 | av_push (missing, newSViv (cell->tile [z])); |
1670 | |
2148 | |
1671 | if (tex->smoothtile) |
2149 | if (tex->smoothtile) |
1672 | { |
2150 | { |
1673 | maptex *smooth = self->tex + tex->smoothtile; |
2151 | maptex *smooth = self->tex + tex->smoothtile; |
|
|
2152 | smooth->unused = 0; |
1674 | if (!smooth->name) |
2153 | if (!smooth->name) |
1675 | av_push (missing, newSViv (tex->smoothtile)); |
2154 | av_push (missing, newSViv (tex->smoothtile)); |
1676 | } |
2155 | } |
1677 | } |
2156 | } |
1678 | } |
2157 | } |
1679 | } |
2158 | } |
1680 | else |
2159 | else |
1681 | cell->darkness = 0; |
2160 | CELL_CLEAR (cell); |
1682 | } |
2161 | } |
1683 | } |
2162 | } |
1684 | OUTPUT: |
2163 | OUTPUT: |
1685 | RETVAL |
2164 | RETVAL |
1686 | |
2165 | |
1687 | SV * |
2166 | SV * |
1688 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
2167 | mapmap (DC::Map self, int x0, int y0, int w, int h) |
1689 | CODE: |
2168 | CODE: |
1690 | { |
2169 | { |
1691 | int x1, x; |
2170 | int x1, x; |
1692 | int y1, y; |
2171 | int y1, y; |
1693 | int z; |
2172 | int z; |
… | |
… | |
1706 | ? self->row + y |
2185 | ? self->row + y |
1707 | : 0; |
2186 | : 0; |
1708 | |
2187 | |
1709 | for (x = x0; x < x1; x++) |
2188 | for (x = x0; x < x1; x++) |
1710 | { |
2189 | { |
1711 | int r = 32, g = 32, b = 32, a = 192; |
2190 | unsigned int r = 32, g = 32, b = 32, a = 192; |
1712 | |
2191 | |
1713 | if (row && row->c0 <= x && x < row->c1) |
2192 | if (row && row->c0 <= x && x < row->c1) |
1714 | { |
2193 | { |
1715 | mapcell *cell = row->col + (x - row->c0); |
2194 | mapcell *cell = row->col + (x - row->c0); |
1716 | |
2195 | |
… | |
… | |
1718 | { |
2197 | { |
1719 | maptex tex = self->tex [cell->tile [z]]; |
2198 | maptex tex = self->tex [cell->tile [z]]; |
1720 | int a0 = 255 - tex.a; |
2199 | int a0 = 255 - tex.a; |
1721 | int a1 = tex.a; |
2200 | int a1 = tex.a; |
1722 | |
2201 | |
1723 | r = (r * a0 + tex.r * a1) / 255; |
2202 | r = div255 (r * a0 + tex.r * a1); |
1724 | g = (g * a0 + tex.g * a1) / 255; |
2203 | g = div255 (g * a0 + tex.g * a1); |
1725 | b = (b * a0 + tex.b * a1) / 255; |
2204 | b = div255 (b * a0 + tex.b * a1); |
1726 | a = (a * a0 + tex.a * a1) / 255; |
2205 | a = div255 (a * a0 + tex.a * a1); |
1727 | } |
2206 | } |
1728 | } |
2207 | } |
1729 | |
2208 | |
1730 | *map++ = (r ) |
2209 | *map++ = (r ) |
1731 | | (g << 8) |
2210 | | (g << 8) |
1732 | | (b << 16) |
2211 | | (b << 16) |
1733 | | (a << 24); |
2212 | | (a << 24); |
1734 | } |
2213 | } |
1735 | } |
2214 | } |
1736 | |
2215 | |
1737 | RETVAL = map_sv; |
2216 | RETVAL = map_sv; |
1738 | } |
2217 | } |
1739 | OUTPUT: |
2218 | OUTPUT: |
1740 | RETVAL |
2219 | RETVAL |
1741 | |
2220 | |
1742 | void |
2221 | void |
1743 | draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T) |
2222 | draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) |
1744 | CODE: |
2223 | CODE: |
1745 | { |
2224 | { |
1746 | int x, y, z; |
2225 | int x, y, z; |
1747 | |
2226 | |
1748 | HV *smooth = (HV *)sv_2mortal ((SV *)newHV ()); |
|
|
1749 | uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level |
|
|
1750 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) |
2227 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k), also, static! |
1751 | smooth_key skey; |
2228 | int pl_x, pl_y; |
1752 | |
2229 | maptex pl_tex; |
1753 | rc_t *rc = rc_alloc (); |
2230 | rc_t rc; |
|
|
2231 | rc_t rc_ov; |
1754 | rc_key_t key; |
2232 | rc_key_t key; |
1755 | rc_array_t *arr; |
2233 | rc_t::array_t *arr; |
1756 | |
2234 | |
|
|
2235 | pl_tex.name = 0; |
|
|
2236 | |
1757 | // thats current max. sorry. |
2237 | // that's current max. sorry. |
1758 | if (sw > 255) sw = 255; |
2238 | if (sw > 255) sw = 255; |
1759 | if (sh > 255) sh = 255; |
2239 | if (sh > 255) sh = 255; |
1760 | |
|
|
1761 | // clear key, in case of extra padding |
|
|
1762 | memset (&skey, 0, sizeof (skey)); |
|
|
1763 | |
2240 | |
1764 | memset (&key, 0, sizeof (key)); |
2241 | memset (&key, 0, sizeof (key)); |
1765 | key.r = 255; |
2242 | key.r = 255; |
1766 | key.g = 255; |
2243 | key.g = 255; |
1767 | key.b = 255; |
2244 | key.b = 255; |
1768 | key.a = 255; |
2245 | key.a = 255; |
1769 | key.mode = GL_QUADS; |
2246 | key.mode = GL_QUADS; |
1770 | key.format = GL_T2F_V3F; |
2247 | key.format = GL_T2F_V3F; |
1771 | key.texname = -1; |
|
|
1772 | |
2248 | |
1773 | mx += self->x; |
2249 | mx += self->x; |
1774 | my += self->y; |
2250 | my += self->y; |
1775 | |
2251 | |
1776 | // first pass: determine smooth_max |
2252 | // first pass: determine smooth_max |
1777 | // rather ugly, if you ask me |
2253 | // rather ugly, if you ask me |
1778 | // could also be stored inside mapcell and updated on change |
2254 | // could also be stored inside mapcell and updated on change |
1779 | memset (smooth_max, 0, sizeof (smooth_max)); |
2255 | memset (smooth_max, 0, sizeof (smooth_max[0]) * (sh + 1)); |
1780 | |
2256 | |
1781 | for (y = 0; y < sh; y++) |
2257 | for (y = 0; y < sh; y++) |
1782 | if (0 <= y + my && y + my < self->rows) |
2258 | if (0 <= y + my && y + my < self->rows) |
1783 | { |
2259 | { |
1784 | maprow *row = self->row + (y + my); |
2260 | maprow *row = self->row + (y + my); |
… | |
… | |
1799 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2275 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1800 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2276 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
1801 | |
2277 | |
1802 | for (z = 0; z <= 2; z++) |
2278 | for (z = 0; z <= 2; z++) |
1803 | { |
2279 | { |
1804 | memset (smooth_level, 0, sizeof (smooth_level)); |
2280 | std::bitset<256> smooth_level; // one bit for every possible smooth level |
|
|
2281 | smooth_key skey; |
|
|
2282 | smooth_hash smooth; |
|
|
2283 | key.texname = -1; |
1805 | |
2284 | |
1806 | for (y = 0; y < sh; y++) |
2285 | for (y = 0; y < sh; y++) |
1807 | if (0 <= y + my && y + my < self->rows) |
2286 | if (0 <= y + my && y + my < self->rows) |
1808 | { |
2287 | { |
1809 | maprow *row = self->row + (y + my); |
2288 | maprow *row = self->row + (y + my); |
… | |
… | |
1819 | maptex tex = self->tex [tile]; |
2298 | maptex tex = self->tex [tile]; |
1820 | int px, py; |
2299 | int px, py; |
1821 | |
2300 | |
1822 | if (key.texname != tex.name) |
2301 | if (key.texname != tex.name) |
1823 | { |
2302 | { |
|
|
2303 | self->tex [tile].unused = 0; |
|
|
2304 | |
1824 | if (!tex.name) |
2305 | if (!tex.name) |
1825 | tex = self->tex [2]; /* missing, replace by noface */ |
2306 | tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ |
1826 | |
2307 | |
1827 | key.texname = tex.name; |
2308 | key.texname = tex.name; |
1828 | arr = rc_array (rc, &key); |
2309 | arr = &rc.array (key); |
1829 | } |
2310 | } |
1830 | |
2311 | |
1831 | px = (x + 1) * T - tex.w; |
2312 | px = (x + 1) * Th - tex.w; |
1832 | py = (y + 1) * T - tex.h; |
2313 | py = (y + 1) * Tw - tex.h; |
1833 | |
2314 | |
1834 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
2315 | if (expect_false (cell->player == player) && expect_false (z == 2)) |
1835 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
|
|
1836 | rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); |
|
|
1837 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
|
|
1838 | |
|
|
1839 | if (cell->flags && z == 2) |
|
|
1840 | { |
2316 | { |
1841 | // overlays such as the speech bubble, probably more to come |
2317 | pl_x = px; |
1842 | if (cell->flags & 1) |
2318 | pl_y = py; |
|
|
2319 | pl_tex = tex; |
1843 | { |
2320 | continue; |
1844 | maptex tex = self->tex [1]; |
|
|
1845 | int px = x * T + T * 2 / 32; |
|
|
1846 | int py = y * T - T * 6 / 32; |
|
|
1847 | |
|
|
1848 | if (tex.name) |
|
|
1849 | { |
|
|
1850 | if (key.texname != tex.name) |
|
|
1851 | { |
|
|
1852 | key.texname = tex.name; |
|
|
1853 | arr = rc_array (rc, &key); |
|
|
1854 | } |
|
|
1855 | |
|
|
1856 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
|
|
1857 | rc_t2f_v3f (arr, 0 , tex.t, px , py + T, 0); |
|
|
1858 | rc_t2f_v3f (arr, tex.s, tex.t, px + T, py + T, 0); |
|
|
1859 | rc_t2f_v3f (arr, tex.s, 0 , px + T, py , 0); |
|
|
1860 | } |
|
|
1861 | } |
|
|
1862 | } |
2321 | } |
|
|
2322 | |
|
|
2323 | arr->t2f_v3f (0 , 0 , px , py , 0); |
|
|
2324 | arr->t2f_v3f (0 , tex.t, px , py + tex.h, 0); |
|
|
2325 | arr->t2f_v3f (tex.s, tex.t, px + tex.w, py + tex.h, 0); |
|
|
2326 | arr->t2f_v3f (tex.s, 0 , px + tex.w, py , 0); |
1863 | |
2327 | |
1864 | // update smooth hash |
2328 | // update smooth hash |
1865 | if (tex.smoothtile) |
2329 | if (tex.smoothtile) |
1866 | { |
2330 | { |
1867 | skey.tile = tex.smoothtile; |
2331 | skey.tile = tex.smoothtile; |
1868 | skey.level = tex.smoothlevel; |
2332 | skey.level = tex.smoothlevel; |
1869 | |
2333 | |
1870 | smooth_level [tex.smoothlevel >> 5] |= ((uint32_t)1) << (tex.smoothlevel & 31); |
2334 | smooth_level[tex.smoothlevel] = 1; |
1871 | |
2335 | |
1872 | // add bits to current tile and all neighbours. skey.x|y is |
2336 | // add bits to current tile and all neighbours. skey.x|y is |
1873 | // shifted +1|+1 so we always stay positive. |
2337 | // shifted +1|+1 so we always stay positive. |
1874 | |
2338 | |
1875 | // bits is ___n cccc CCCC bbbb |
2339 | // bits is ___n cccc CCCC bbbb |
… | |
… | |
1883 | |
2347 | |
1884 | // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· |
2348 | // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· |
1885 | // ·· ·· ·┏ ┓· |
2349 | // ·· ·· ·┏ ┓· |
1886 | |
2350 | |
1887 | // full tile |
2351 | // full tile |
1888 | skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x1000); |
2352 | skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x1000); |
1889 | |
2353 | |
1890 | // borders |
2354 | // borders |
1891 | skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0091); |
2355 | skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0091); |
1892 | skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0032); |
2356 | skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0032); |
1893 | skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0064); |
2357 | skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0064); |
1894 | skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, &skey, 0x00c8); |
2358 | skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, skey, 0x00c8); |
1895 | |
2359 | |
1896 | // corners |
2360 | // corners |
1897 | skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100); |
2361 | skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0100); |
1898 | skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200); |
2362 | skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0200); |
1899 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); |
2363 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, skey, 0x0400); |
1900 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); |
2364 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, skey, 0x0800); |
|
|
2365 | } |
|
|
2366 | } |
|
|
2367 | |
|
|
2368 | if (expect_false (z == 2) && expect_false (cell->flags)) |
|
|
2369 | { |
|
|
2370 | // overlays such as the speech bubble, probably more to come |
|
|
2371 | if (cell->flags & 1) |
|
|
2372 | { |
|
|
2373 | rc_key_t key_ov = key; |
|
|
2374 | maptex tex = self->tex[TEXID_SPEECH]; |
|
|
2375 | int px = x * Tw + Tw * 2 / 32; |
|
|
2376 | int py = y * Th - Th * 6 / 32; |
|
|
2377 | |
|
|
2378 | key_ov.texname = tex.name; |
|
|
2379 | rc_t::array_t &arr = rc_ov.array (key_ov); |
|
|
2380 | |
|
|
2381 | arr.t2f_v3f (0 , 0 , px , py , 0); |
|
|
2382 | arr.t2f_v3f (0 , tex.t, px , py + Th, 0); |
|
|
2383 | arr.t2f_v3f (tex.s, tex.t, px + Tw, py + Th, 0); |
|
|
2384 | arr.t2f_v3f (tex.s, 0 , px + Tw, py , 0); |
1901 | } |
2385 | } |
1902 | } |
2386 | } |
1903 | } |
2387 | } |
1904 | } |
2388 | } |
1905 | |
2389 | |
1906 | rc_draw (rc); |
2390 | rc.draw (); |
1907 | rc_clear (rc); |
2391 | rc.clear (); |
1908 | |
2392 | |
1909 | // go through all smoothlevels, lowest to highest, then draw. |
2393 | // go through all smoothlevels, lowest to highest, then draw. |
1910 | // this is basically counting sort |
2394 | // this is basically counting sort |
1911 | { |
2395 | { |
1912 | int w, b; |
2396 | int w, b; |
1913 | |
2397 | |
1914 | glEnable (GL_TEXTURE_2D); |
2398 | glEnable (GL_TEXTURE_2D); |
1915 | glBegin (GL_QUADS); |
2399 | glBegin (GL_QUADS); |
1916 | for (w = 0; w < 256 / 32; ++w) |
2400 | for (int level = 0; level < smooth_level.size (); ++level) |
|
|
2401 | if (smooth_level[level]) |
|
|
2402 | for (auto &&it = smooth.begin (); it != smooth.end (); ++it) |
1917 | { |
2403 | { |
1918 | uint32_t smask = smooth_level [w]; |
2404 | smooth_key &skey = it->first; |
1919 | if (smask) |
2405 | IV bits = it->second; |
1920 | for (b = 0; b < 32; ++b) |
2406 | |
1921 | if (smask & (((uint32_t)1) << b)) |
2407 | if (!(bits & 0x1000) |
|
|
2408 | && skey.level == level |
|
|
2409 | && level > smooth_max [skey.x][skey.y]) |
1922 | { |
2410 | { |
1923 | int level = (w << 5) | b; |
2411 | maptex tex = self->tex [skey.tile]; |
|
|
2412 | int px = (((int)skey.x) - 1) * Tw; |
|
|
2413 | int py = (((int)skey.y) - 1) * Th; |
|
|
2414 | int border = bits & 15; |
|
|
2415 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
|
|
2416 | float dx = tex.s * .0625f; // 16 images/row |
|
|
2417 | float dy = tex.t * .5f ; // 2 images/column |
|
|
2418 | |
1924 | HE *he; |
2419 | if (tex.name) |
1925 | |
|
|
1926 | hv_iterinit (smooth); |
|
|
1927 | while ((he = hv_iternext (smooth))) |
|
|
1928 | { |
2420 | { |
1929 | smooth_key *skey = (smooth_key *)HeKEY (he); |
2421 | // this time avoiding texture state changes |
1930 | IV bits = SvIVX (HeVAL (he)); |
2422 | // save gobs of state changes. |
1931 | |
2423 | if (key.texname != tex.name) |
1932 | if (!(bits & 0x1000) |
|
|
1933 | && skey->level == level |
|
|
1934 | && level > smooth_max [skey->x][skey->y]) |
|
|
1935 | { |
2424 | { |
1936 | maptex tex = self->tex [skey->tile]; |
2425 | self->tex [skey.tile].unused = 0; |
1937 | int px = (((int)skey->x) - 1) * T; |
|
|
1938 | int py = (((int)skey->y) - 1) * T; |
|
|
1939 | int border = bits & 15; |
|
|
1940 | int corner = (bits >> 8) & ~(bits >> 4) & 15; |
|
|
1941 | float dx = tex.s * .0625f; // 16 images/row |
|
|
1942 | float dy = tex.t * .5f ; // 2 images/column |
|
|
1943 | |
2426 | |
1944 | if (tex.name) |
|
|
1945 | { |
|
|
1946 | // this time avoiding texture state changes |
|
|
1947 | // save gobs of state changes. |
|
|
1948 | if (key.texname != tex.name) |
|
|
1949 | { |
|
|
1950 | glEnd (); |
2427 | glEnd (); |
1951 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
2428 | glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); |
1952 | glBegin (GL_QUADS); |
2429 | glBegin (GL_QUADS); |
1953 | } |
2430 | } |
1954 | |
2431 | |
1955 | if (border) |
2432 | if (border) |
1956 | { |
2433 | { |
1957 | float ox = border * dx; |
2434 | float ox = border * dx; |
1958 | |
2435 | |
1959 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
2436 | glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); |
1960 | glTexCoord2f (ox , dy ); glVertex2i (px , py + T); |
2437 | glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); |
1961 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py + T); |
2438 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); |
1962 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + T, py ); |
2439 | glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); |
1963 | } |
2440 | } |
1964 | |
2441 | |
1965 | if (corner) |
2442 | if (corner) |
1966 | { |
2443 | { |
1967 | float ox = corner * dx; |
2444 | float ox = corner * dx; |
1968 | |
2445 | |
1969 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
2446 | glTexCoord2f (ox , dy ); glVertex2i (px , py ); |
1970 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + T); |
2447 | glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); |
1971 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + T, py + T); |
2448 | glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); |
1972 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + T, py ); |
2449 | glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); |
1973 | } |
|
|
1974 | } |
|
|
1975 | } |
2450 | } |
1976 | } |
2451 | } |
1977 | } |
2452 | } |
1978 | } |
2453 | } |
1979 | |
2454 | |
1980 | glEnd (); |
2455 | glEnd (); |
1981 | glDisable (GL_TEXTURE_2D); |
2456 | glDisable (GL_TEXTURE_2D); |
1982 | key.texname = -1; |
2457 | key.texname = -1; |
1983 | } |
2458 | } |
1984 | |
|
|
1985 | hv_clear (smooth); |
|
|
1986 | } |
2459 | } |
1987 | |
2460 | |
|
|
2461 | if (pl_tex.name) |
|
|
2462 | { |
|
|
2463 | maptex tex = pl_tex; |
|
|
2464 | int px = pl_x + sdx; |
|
|
2465 | int py = pl_y + sdy; |
|
|
2466 | |
|
|
2467 | key.texname = tex.name; |
|
|
2468 | rc_t::array_t &arr = rc.array (key); |
|
|
2469 | |
|
|
2470 | arr.t2f_v3f (0 , 0 , px , py , 0); |
|
|
2471 | arr.t2f_v3f (0 , tex.t, px , py + tex.h, 0); |
|
|
2472 | arr.t2f_v3f (tex.s, tex.t, px + tex.w, py + tex.h, 0); |
|
|
2473 | arr.t2f_v3f (tex.s, 0 , px + tex.w, py , 0); |
|
|
2474 | |
|
|
2475 | rc.draw (); |
|
|
2476 | } |
|
|
2477 | |
|
|
2478 | rc_ov.draw (); |
|
|
2479 | rc_ov.clear (); |
|
|
2480 | |
1988 | glDisable (GL_BLEND); |
2481 | glDisable (GL_BLEND); |
1989 | rc_free (rc); |
|
|
1990 | |
2482 | |
1991 | // top layer: overlays such as the health bar |
2483 | // top layer: overlays such as the health bar |
1992 | for (y = 0; y < sh; y++) |
2484 | for (y = 0; y < sh; y++) |
1993 | if (0 <= y + my && y + my < self->rows) |
2485 | if (0 <= y + my && y + my < self->rows) |
1994 | { |
2486 | { |
… | |
… | |
1997 | for (x = 0; x < sw; x++) |
2489 | for (x = 0; x < sw; x++) |
1998 | if (row->c0 <= x + mx && x + mx < row->c1) |
2490 | if (row->c0 <= x + mx && x + mx < row->c1) |
1999 | { |
2491 | { |
2000 | mapcell *cell = row->col + (x + mx - row->c0); |
2492 | mapcell *cell = row->col + (x + mx - row->c0); |
2001 | |
2493 | |
2002 | int px = x * T; |
2494 | int px = x * Tw; |
2003 | int py = y * T; |
2495 | int py = y * Th; |
|
|
2496 | |
|
|
2497 | if (expect_false (cell->player == player)) |
|
|
2498 | { |
|
|
2499 | px += sdx; |
|
|
2500 | py += sdy; |
|
|
2501 | } |
2004 | |
2502 | |
2005 | if (cell->stat_hp) |
2503 | if (cell->stat_hp) |
2006 | { |
2504 | { |
2007 | int width = cell->stat_width * T; |
2505 | int width = cell->stat_width * Tw; |
2008 | int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width; |
2506 | int thick = (sh * Th / 32 + 27) / 28 + 1 + cell->stat_width; |
2009 | |
2507 | |
2010 | glColor3ub (0, 0, 0); |
2508 | glColor3ub (0, 0, 0); |
2011 | glRectf (px + 1, py - thick - 2, |
2509 | glRectf (px + 1, py - thick - 2, |
2012 | px + width - 1, py); |
2510 | px + width - 1, py); |
2013 | |
2511 | |
… | |
… | |
2019 | } |
2517 | } |
2020 | } |
2518 | } |
2021 | } |
2519 | } |
2022 | |
2520 | |
2023 | void |
2521 | void |
2024 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
2522 | draw_magicmap (DC::Map self, int w, int h, unsigned char *data) |
2025 | CODE: |
2523 | CODE: |
2026 | { |
2524 | { |
2027 | static float color[16][3] = { |
2525 | static float color[16][3] = { |
2028 | { 0.00F, 0.00F, 0.00F }, |
2526 | { 0.00f, 0.00f, 0.00f }, |
2029 | { 1.00F, 1.00F, 1.00F }, |
2527 | { 1.00f, 1.00f, 1.00f }, |
2030 | { 0.00F, 0.00F, 0.55F }, |
2528 | { 0.00f, 0.00f, 0.55f }, |
2031 | { 1.00F, 0.00F, 0.00F }, |
2529 | { 1.00f, 0.00f, 0.00f }, |
2032 | |
2530 | |
2033 | { 1.00F, 0.54F, 0.00F }, |
2531 | { 1.00f, 0.54f, 0.00f }, |
2034 | { 0.11F, 0.56F, 1.00F }, |
2532 | { 0.11f, 0.56f, 1.00f }, |
2035 | { 0.93F, 0.46F, 0.00F }, |
2533 | { 0.93f, 0.46f, 0.00f }, |
2036 | { 0.18F, 0.54F, 0.34F }, |
2534 | { 0.18f, 0.54f, 0.34f }, |
2037 | |
2535 | |
2038 | { 0.56F, 0.73F, 0.56F }, |
2536 | { 0.56f, 0.73f, 0.56f }, |
2039 | { 0.80F, 0.80F, 0.80F }, |
2537 | { 0.80f, 0.80f, 0.80f }, |
2040 | { 0.55F, 0.41F, 0.13F }, |
2538 | { 0.55f, 0.41f, 0.13f }, |
2041 | { 0.99F, 0.77F, 0.26F }, |
2539 | { 0.99f, 0.77f, 0.26f }, |
2042 | |
2540 | |
2043 | { 0.74F, 0.65F, 0.41F }, |
2541 | { 0.74f, 0.65f, 0.41f }, |
2044 | |
2542 | |
2045 | { 0.00F, 1.00F, 1.00F }, |
2543 | { 0.00f, 1.00f, 1.00f }, |
2046 | { 1.00F, 0.00F, 1.00F }, |
2544 | { 1.00f, 0.00f, 1.00f }, |
2047 | { 1.00F, 1.00F, 0.00F }, |
2545 | { 1.00f, 1.00f, 0.00f }, |
2048 | }; |
2546 | }; |
2049 | |
2547 | |
2050 | int x, y; |
2548 | int x, y; |
2051 | |
2549 | |
2052 | glEnable (GL_TEXTURE_2D); |
2550 | glEnable (GL_TEXTURE_2D); |
|
|
2551 | /* GL_REPLACE would be correct, as we don't need to modulate alpha, |
|
|
2552 | * but the nvidia driver (185.18.14) mishandles alpha textures |
|
|
2553 | * and takes the colour from god knows where instead of using |
|
|
2554 | * Cp. MODULATE results in the same colour, but slightly different |
|
|
2555 | * alpha, but atcually gives us the correct colour with nvidia. |
|
|
2556 | */ |
2053 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
2557 | glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
2054 | glEnable (GL_BLEND); |
2558 | glEnable (GL_BLEND); |
2055 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2559 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
2056 | glBegin (GL_QUADS); |
2560 | glBegin (GL_QUADS); |
2057 | |
2561 | |
2058 | for (y = 0; y < h; y++) |
2562 | for (y = 0; y < h; y++) |
… | |
… | |
2062 | |
2566 | |
2063 | if (m) |
2567 | if (m) |
2064 | { |
2568 | { |
2065 | float *c = color [m & 15]; |
2569 | float *c = color [m & 15]; |
2066 | |
2570 | |
2067 | float tx1 = m & 0x40 ? 0.5 : 0.; |
2571 | float tx1 = m & 0x40 ? 0.5f : 0.f; |
2068 | float tx2 = tx1 + 0.5; |
2572 | float tx2 = tx1 + 0.5f; |
2069 | |
2573 | |
2070 | glColor4f (c[0], c[1], c[2], 0.75); |
2574 | glColor4f (c[0], c[1], c[2], 1); |
2071 | glTexCoord2f (tx1, 0.); glVertex2i (x , y ); |
2575 | glTexCoord2f (tx1, 0.); glVertex2i (x , y ); |
2072 | glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); |
2576 | glTexCoord2f (tx1, 1.); glVertex2i (x , y + 1); |
2073 | glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); |
2577 | glTexCoord2f (tx2, 1.); glVertex2i (x + 1, y + 1); |
2074 | glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); |
2578 | glTexCoord2f (tx2, 0.); glVertex2i (x + 1, y ); |
2075 | } |
2579 | } |
… | |
… | |
2079 | glDisable (GL_BLEND); |
2583 | glDisable (GL_BLEND); |
2080 | glDisable (GL_TEXTURE_2D); |
2584 | glDisable (GL_TEXTURE_2D); |
2081 | } |
2585 | } |
2082 | |
2586 | |
2083 | void |
2587 | void |
2084 | fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh) |
2588 | fow_texture (DC::Map self, int mx, int my, int sw, int sh) |
2085 | PPCODE: |
2589 | PPCODE: |
2086 | { |
2590 | { |
2087 | int x, y; |
2591 | int x, y; |
2088 | int sw1 = sw + 2; |
2592 | int sw1 = sw + 2; |
2089 | int sh1 = sh + 2; |
2593 | int sh1 = sh + 2; |
2090 | int sh3 = sh * 3; |
2594 | int sh3 = sh * 3; |
2091 | int sw34 = (sw * 3 + 3) & ~3; |
2595 | int sw3 = sw * 3; |
|
|
2596 | SV *darkness3_sv = sv_2mortal (newSV (sw3 * sh3)); |
|
|
2597 | uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); |
2092 | uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); |
2598 | uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); |
2093 | SV *darkness3_sv = sv_2mortal (newSV (sw34 * sh3)); |
2599 | memset (darkness1, 0, sw1*sh1); |
2094 | uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); |
|
|
2095 | |
2600 | |
2096 | SvPOK_only (darkness3_sv); |
2601 | SvPOK_only (darkness3_sv); |
2097 | SvCUR_set (darkness3_sv, sw34 * sh3); |
2602 | SvCUR_set (darkness3_sv, sw3 * sh3); |
2098 | |
2603 | |
2099 | mx += self->x - 1; |
2604 | mx += self->x - 1; |
2100 | my += self->y - 1; |
2605 | my += self->y - 1; |
2101 | |
|
|
2102 | memset (darkness1, 255, sw1 * sh1); |
|
|
2103 | |
2606 | |
2104 | for (y = 0; y < sh1; y++) |
2607 | for (y = 0; y < sh1; y++) |
2105 | if (0 <= y + my && y + my < self->rows) |
2608 | if (0 <= y + my && y + my < self->rows) |
2106 | { |
2609 | { |
2107 | maprow *row = self->row + (y + my); |
2610 | maprow *row = self->row + (y + my); |
… | |
… | |
2110 | if (row->c0 <= x + mx && x + mx < row->c1) |
2613 | if (row->c0 <= x + mx && x + mx < row->c1) |
2111 | { |
2614 | { |
2112 | mapcell *cell = row->col + (x + mx - row->c0); |
2615 | mapcell *cell = row->col + (x + mx - row->c0); |
2113 | |
2616 | |
2114 | darkness1 [y * sw1 + x] = cell->darkness |
2617 | darkness1 [y * sw1 + x] = cell->darkness |
2115 | ? 255 - (cell->darkness - 1) |
2618 | ? DARKNESS_ADJUST (255 - (cell->darkness - 1)) |
2116 | : 255 - FOW_DARKNESS; |
2619 | : DARKNESS_ADJUST (255 - FOW_DARKNESS); |
2117 | } |
2620 | } |
2118 | } |
2621 | } |
2119 | |
2622 | |
2120 | for (y = 0; y < sh; ++y) |
2623 | for (y = 0; y < sh; ++y) |
2121 | for (x = 0; x < sw; ++x) |
2624 | for (x = 0; x < sw; ++x) |
… | |
… | |
2140 | |
2643 | |
2141 | uint8_t r13 = (d13 + d23 + d12) / 3; |
2644 | uint8_t r13 = (d13 + d23 + d12) / 3; |
2142 | uint8_t r23 = d23; |
2645 | uint8_t r23 = d23; |
2143 | uint8_t r33 = (d23 + d33 + d32) / 3; |
2646 | uint8_t r33 = (d23 + d33 + d32) / 3; |
2144 | |
2647 | |
2145 | darkness3 [(y * 3 ) * sw34 + (x * 3 )] = MAX (d22, r11); |
2648 | darkness3 [(y * 3 ) * sw3 + (x * 3 )] = MAX (d22, r11); |
2146 | darkness3 [(y * 3 ) * sw34 + (x * 3 + 1)] = MAX (d22, r21); |
2649 | darkness3 [(y * 3 ) * sw3 + (x * 3 + 1)] = MAX (d22, r21); |
2147 | darkness3 [(y * 3 ) * sw34 + (x * 3 + 2)] = MAX (d22, r31); |
2650 | darkness3 [(y * 3 ) * sw3 + (x * 3 + 2)] = MAX (d22, r31); |
2148 | darkness3 [(y * 3 + 1) * sw34 + (x * 3 )] = MAX (d22, r12); |
2651 | darkness3 [(y * 3 + 1) * sw3 + (x * 3 )] = MAX (d22, r12); |
2149 | darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 1)] = MAX (d22, r22); |
2652 | darkness3 [(y * 3 + 1) * sw3 + (x * 3 + 1)] = MAX (d22, r22); /* this MUST be == d22 */ |
2150 | darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 2)] = MAX (d22, r32); |
2653 | darkness3 [(y * 3 + 1) * sw3 + (x * 3 + 2)] = MAX (d22, r32); |
2151 | darkness3 [(y * 3 + 2) * sw34 + (x * 3 )] = MAX (d22, r13); |
2654 | darkness3 [(y * 3 + 2) * sw3 + (x * 3 )] = MAX (d22, r13); |
2152 | darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 1)] = MAX (d22, r23); |
2655 | darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 1)] = MAX (d22, r23); |
2153 | darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 2)] = MAX (d22, r33); |
2656 | darkness3 [(y * 3 + 2) * sw3 + (x * 3 + 2)] = MAX (d22, r33); |
2154 | } |
2657 | } |
2155 | |
2658 | |
2156 | free (darkness1); |
2659 | free (darkness1); |
2157 | |
2660 | |
2158 | EXTEND (SP, 3); |
2661 | EXTEND (SP, 3); |
2159 | PUSHs (sv_2mortal (newSViv (sw34))); |
2662 | PUSHs (sv_2mortal (newSViv (sw3))); |
2160 | PUSHs (sv_2mortal (newSViv (sh3))); |
2663 | PUSHs (sv_2mortal (newSViv (sh3))); |
2161 | PUSHs (darkness3_sv); |
2664 | PUSHs (darkness3_sv); |
2162 | } |
2665 | } |
2163 | |
2666 | |
2164 | SV * |
2667 | SV * |
2165 | get_rect (CFPlus::Map self, int x0, int y0, int w, int h) |
2668 | get_rect (DC::Map self, int x0, int y0, int w, int h) |
2166 | CODE: |
2669 | CODE: |
2167 | { |
2670 | { |
2168 | int x, y, x1, y1; |
2671 | int x, y, x1, y1; |
2169 | SV *data_sv = newSV (w * h * 7 + 5); |
2672 | SV *data_sv = newSV (w * h * 7 + 5); |
2170 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
2673 | uint8_t *data = (uint8_t *)SvPVX (data_sv); |
… | |
… | |
2227 | else |
2730 | else |
2228 | *data++ = 0; |
2731 | *data++ = 0; |
2229 | } |
2732 | } |
2230 | } |
2733 | } |
2231 | |
2734 | |
|
|
2735 | /* if size is w*h + 5 then no data has been found */ |
|
|
2736 | if (data - (uint8_t *)SvPVX (data_sv) != w * h + 5) |
|
|
2737 | { |
2232 | SvPOK_only (data_sv); |
2738 | SvPOK_only (data_sv); |
2233 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
2739 | SvCUR_set (data_sv, data - (uint8_t *)SvPVX (data_sv)); |
|
|
2740 | } |
|
|
2741 | |
2234 | RETVAL = data_sv; |
2742 | RETVAL = data_sv; |
2235 | } |
2743 | } |
2236 | OUTPUT: |
2744 | OUTPUT: |
2237 | RETVAL |
2745 | RETVAL |
2238 | |
2746 | |
2239 | void |
2747 | void |
2240 | set_rect (CFPlus::Map self, int x0, int y0, uint8_t *data) |
2748 | set_rect (DC::Map self, int x0, int y0, SV *data_sv) |
2241 | PPCODE: |
2749 | PPCODE: |
2242 | { |
2750 | { |
2243 | int x, y, z; |
2751 | int x, y, z; |
2244 | int w, h; |
2752 | int w, h; |
2245 | int x1, y1; |
2753 | int x1, y1; |
|
|
2754 | STRLEN len; |
|
|
2755 | uint8_t *data, *end; |
|
|
2756 | |
|
|
2757 | len = SvLEN (data_sv); |
|
|
2758 | SvGROW (data_sv, len + 8); // reserve at least 7+ bytes more |
|
|
2759 | data = (uint8_t *)SvPVbyte_nolen (data_sv); |
|
|
2760 | end = data + len + 8; |
|
|
2761 | |
|
|
2762 | if (len < 5) |
|
|
2763 | XSRETURN_EMPTY; |
2246 | |
2764 | |
2247 | if (*data++ != 0) |
2765 | if (*data++ != 0) |
2248 | XSRETURN_EMPTY; /* version mismatch */ |
2766 | XSRETURN_EMPTY; /* version mismatch */ |
2249 | |
2767 | |
2250 | w = *data++ << 8; w |= *data++; |
2768 | w = *data++ << 8; w |= *data++; |
… | |
… | |
2265 | { |
2783 | { |
2266 | maprow *row = map_get_row (self, y); |
2784 | maprow *row = map_get_row (self, y); |
2267 | |
2785 | |
2268 | for (x = x0; x < x1; x++) |
2786 | for (x = x0; x < x1; x++) |
2269 | { |
2787 | { |
|
|
2788 | uint8_t flags; |
|
|
2789 | |
|
|
2790 | if (data + 7 >= end) |
|
|
2791 | XSRETURN_EMPTY; |
|
|
2792 | |
2270 | uint8_t flags = *data++; |
2793 | flags = *data++; |
2271 | |
2794 | |
2272 | if (flags) |
2795 | if (flags) |
2273 | { |
2796 | { |
2274 | mapcell *cell = row_get_cell (row, x); |
2797 | mapcell *cell = row_get_cell (row, x); |
2275 | tileid tile[3] = { 0, 0, 0 }; |
2798 | tileid tile[3] = { 0, 0, 0 }; |
… | |
… | |
2278 | if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; } |
2801 | if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; } |
2279 | if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; } |
2802 | if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; } |
2280 | |
2803 | |
2281 | if (cell->darkness == 0) |
2804 | if (cell->darkness == 0) |
2282 | { |
2805 | { |
2283 | cell->darkness = 0; |
2806 | /*cell->darkness = 0;*/ |
|
|
2807 | EXTEND (SP, 3); |
2284 | |
2808 | |
2285 | for (z = 0; z <= 2; z++) |
2809 | for (z = 0; z <= 2; z++) |
2286 | { |
2810 | { |
2287 | tileid t = tile [z]; |
2811 | tileid t = tile [z]; |
2288 | |
2812 | |
2289 | if (t >= self->texs || (t && !self->tex [t].name)) |
2813 | if (t >= self->texs || (t && !self->tex [t].name)) |
2290 | { |
2814 | { |
2291 | XPUSHs (sv_2mortal (newSViv (t))); |
2815 | PUSHs (sv_2mortal (newSViv (t))); |
2292 | need_texid (self, t); |
2816 | need_texid (self, t); |
2293 | } |
2817 | } |
2294 | |
2818 | |
2295 | cell->tile [z] = t; |
2819 | cell->tile [z] = t; |
2296 | } |
2820 | } |
… | |
… | |
2298 | } |
2822 | } |
2299 | } |
2823 | } |
2300 | } |
2824 | } |
2301 | } |
2825 | } |
2302 | |
2826 | |
2303 | MODULE = CFPlus PACKAGE = CFPlus::RW |
2827 | MODULE = Deliantra::Client PACKAGE = DC::RW |
2304 | |
2828 | |
2305 | CFPlus::RW |
2829 | DC::RW |
2306 | new (SV *class, SV *data_sv) |
2830 | new (SV *klass, SV *data_sv) |
2307 | CODE: |
2831 | CODE: |
2308 | { |
2832 | { |
2309 | STRLEN datalen; |
2833 | STRLEN datalen; |
2310 | char *data = SvPVbyte (data_sv, datalen); |
2834 | char *data = SvPVbyte (data_sv, datalen); |
2311 | |
2835 | |
2312 | RETVAL = SDL_RWFromConstMem (data, datalen); |
2836 | RETVAL = SDL_RWFromConstMem (data, datalen); |
2313 | } |
2837 | } |
2314 | OUTPUT: |
2838 | OUTPUT: |
2315 | RETVAL |
2839 | RETVAL |
2316 | |
2840 | |
2317 | CFPlus::RW |
2841 | DC::RW |
2318 | new_from_file (SV *class, const char *path, const char *mode = "rb") |
2842 | new_from_file (SV *klass, const char *path, const char *mode = "rb") |
2319 | CODE: |
2843 | CODE: |
2320 | RETVAL = SDL_RWFromFile (path, mode); |
2844 | RETVAL = SDL_RWFromFile (path, mode); |
2321 | OUTPUT: |
2845 | OUTPUT: |
2322 | RETVAL |
2846 | RETVAL |
2323 | |
2847 | |
2324 | # fails on win32: |
2848 | # fails on win32: |
2325 | # CFPlus.xs(2268) : error C2059: syntax error : '(' |
2849 | # dc.xs(2268) : error C2059: syntax error : '(' |
2326 | #void |
2850 | #void |
2327 | #close (CFPlus::RW self) |
2851 | #close (DC::RW self) |
2328 | # CODE: |
2852 | # CODE: |
2329 | # (self->(close)) (self); |
2853 | # (self->(close)) (self); |
2330 | |
2854 | |
2331 | MODULE = CFPlus PACKAGE = CFPlus::Channel |
2855 | MODULE = Deliantra::Client PACKAGE = DC::Channel |
2332 | |
2856 | |
2333 | PROTOTYPES: DISABLE |
2857 | PROTOTYPES: DISABLE |
2334 | |
2858 | |
2335 | CFPlus::Channel |
2859 | DC::Channel |
2336 | find () |
2860 | find () |
2337 | CODE: |
2861 | CODE: |
2338 | { |
2862 | { |
2339 | RETVAL = Mix_GroupAvailable (-1); |
2863 | RETVAL = Mix_GroupAvailable (-1); |
2340 | |
2864 | |
2341 | if (RETVAL < 0) |
2865 | if (RETVAL < 0) |
2342 | { |
2866 | { |
2343 | RETVAL = Mix_GroupOldest (-1); |
2867 | RETVAL = Mix_GroupOldest (-1); |
2344 | |
2868 | |
2345 | if (RETVAL < 0) |
2869 | if (RETVAL < 0) |
|
|
2870 | { |
|
|
2871 | // happens sometimes, maybe it just stopped playing(?) |
|
|
2872 | RETVAL = Mix_GroupAvailable (-1); |
|
|
2873 | |
|
|
2874 | if (RETVAL < 0) |
2346 | XSRETURN_UNDEF; |
2875 | XSRETURN_UNDEF; |
2347 | |
2876 | } |
|
|
2877 | else |
2348 | Mix_HaltChannel (RETVAL); |
2878 | Mix_HaltChannel (RETVAL); |
2349 | } |
2879 | } |
2350 | |
2880 | |
2351 | Mix_UnregisterAllEffects (RETVAL); |
2881 | Mix_UnregisterAllEffects (RETVAL); |
2352 | Mix_Volume (RETVAL, 128); |
2882 | Mix_Volume (RETVAL, 128); |
2353 | } |
2883 | } |
2354 | OUTPUT: |
2884 | OUTPUT: |
2355 | RETVAL |
2885 | RETVAL |
2356 | |
2886 | |
2357 | void |
2887 | void |
2358 | halt (CFPlus::Channel self) |
2888 | halt (DC::Channel self) |
2359 | CODE: |
2889 | CODE: |
2360 | Mix_HaltChannel (self); |
2890 | Mix_HaltChannel (self); |
2361 | |
2891 | |
2362 | void |
2892 | void |
2363 | expire (CFPlus::Channel self, int ticks = -1) |
2893 | expire (DC::Channel self, int ticks = -1) |
2364 | CODE: |
2894 | CODE: |
2365 | Mix_ExpireChannel (self, ticks); |
2895 | Mix_ExpireChannel (self, ticks); |
2366 | |
2896 | |
2367 | void |
2897 | void |
2368 | fade_out (CFPlus::Channel self, int ticks = -1) |
2898 | fade_out (DC::Channel self, int ticks = -1) |
2369 | CODE: |
2899 | CODE: |
2370 | Mix_FadeOutChannel (self, ticks); |
2900 | Mix_FadeOutChannel (self, ticks); |
2371 | |
2901 | |
2372 | int |
2902 | int |
2373 | volume (CFPlus::Channel self, int volume) |
2903 | volume (DC::Channel self, int volume) |
2374 | CODE: |
2904 | CODE: |
2375 | RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); |
2905 | RETVAL = Mix_Volume (self, CLAMP (volume, 0, 128)); |
2376 | OUTPUT: |
2906 | OUTPUT: |
2377 | RETVAL |
2907 | RETVAL |
2378 | |
2908 | |
2379 | void |
2909 | void |
2380 | unregister_all_effects (CFPlus::Channel self) |
2910 | unregister_all_effects (DC::Channel self) |
2381 | CODE: |
2911 | CODE: |
2382 | Mix_UnregisterAllEffects (self); |
2912 | Mix_UnregisterAllEffects (self); |
2383 | |
2913 | |
2384 | void |
2914 | void |
2385 | set_panning (CFPlus::Channel self, int left, int right) |
2915 | set_panning (DC::Channel self, int left, int right) |
2386 | CODE: |
2916 | CODE: |
2387 | left = CLAMP (left , 0, 255); |
2917 | left = CLAMP (left , 0, 255); |
2388 | right = CLAMP (right, 0, 255); |
2918 | right = CLAMP (right, 0, 255); |
2389 | Mix_SetPanning (self, left, right); |
2919 | Mix_SetPanning (self, left, right); |
2390 | |
2920 | |
2391 | void |
2921 | void |
2392 | set_distance (CFPlus::Channel self, int distance) |
2922 | set_distance (DC::Channel self, int distance) |
2393 | CODE: |
2923 | CODE: |
2394 | Mix_SetDistance (self, CLAMP (distance, 0, 255)); |
2924 | Mix_SetDistance (self, CLAMP (distance, 0, 255)); |
2395 | |
2925 | |
2396 | void |
2926 | void |
2397 | set_position (CFPlus::Channel self, int angle, int distance) |
2927 | set_position (DC::Channel self, int angle, int distance) |
2398 | CODE: |
2928 | CODE: |
2399 | |
2929 | |
2400 | void |
2930 | void |
2401 | set_position_r (CFPlus::Channel self, int dx, int dy, int maxdistance) |
2931 | set_position_r (DC::Channel self, int dx, int dy, int maxdistance) |
2402 | CODE: |
2932 | CODE: |
2403 | { |
2933 | { |
2404 | int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); |
2934 | int distance = sqrtf (dx * dx + dy * dy) * (255.f / sqrtf (maxdistance * maxdistance)); |
2405 | int angle = 360 + (int)roundf (atan2f (dx, -dy) * 180.f / (float)M_PI); |
2935 | int angle = atan2f (dx, -dy) * 180.f / (float)M_PI + 360.f; |
2406 | Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); |
2936 | Mix_SetPosition (self, angle, CLAMP (distance, 0, 255)); |
2407 | } |
2937 | } |
2408 | |
2938 | |
2409 | void |
2939 | void |
2410 | set_reverse_stereo (CFPlus::Channel self, int flip) |
2940 | set_reverse_stereo (DC::Channel self, int flip) |
2411 | CODE: |
2941 | CODE: |
2412 | Mix_SetReverseStereo (self, flip); |
2942 | Mix_SetReverseStereo (self, flip); |
2413 | |
2943 | |
2414 | MODULE = CFPlus PACKAGE = CFPlus::MixChunk |
2944 | MODULE = Deliantra::Client PACKAGE = DC::MixChunk |
2415 | |
2945 | |
2416 | PROTOTYPES: DISABLE |
2946 | PROTOTYPES: DISABLE |
2417 | |
2947 | |
|
|
2948 | void |
|
|
2949 | decoders () |
|
|
2950 | PPCODE: |
|
|
2951 | #if SDL_MIXER_MAJOR_VERSION > 1 || SDL_MIXER_MINOR_VERSION > 2 || SDL_MIXER_PATCHLEVEL >= 10 |
|
|
2952 | int i, num = Mix_GetNumChunkDecoders (); |
|
|
2953 | EXTEND (SP, num); |
|
|
2954 | for (i = 0; i < num; ++i) |
|
|
2955 | PUSHs (sv_2mortal (newSVpv (Mix_GetChunkDecoder (i), 0))); |
|
|
2956 | #else |
|
|
2957 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
|
|
2958 | #endif |
|
|
2959 | |
2418 | CFPlus::MixChunk |
2960 | DC::MixChunk |
2419 | new (SV *class, CFPlus::RW rwops) |
2961 | new (SV *klass, DC::RW rwops) |
2420 | CODE: |
2962 | CODE: |
2421 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2963 | RETVAL = Mix_LoadWAV_RW (rwops, 1); |
2422 | OUTPUT: |
2964 | OUTPUT: |
2423 | RETVAL |
2965 | RETVAL |
2424 | |
2966 | |
2425 | void |
2967 | void |
2426 | DESTROY (CFPlus::MixChunk self) |
2968 | DESTROY (DC::MixChunk self) |
2427 | CODE: |
2969 | CODE: |
2428 | Mix_FreeChunk (self); |
2970 | Mix_FreeChunk (self); |
2429 | |
2971 | |
2430 | int |
2972 | int |
2431 | volume (CFPlus::MixChunk self, int volume = -1) |
2973 | volume (DC::MixChunk self, int volume = -1) |
2432 | CODE: |
2974 | CODE: |
2433 | if (items > 1) |
2975 | if (items > 1) |
2434 | volume = CLAMP (volume, 0, 128); |
2976 | volume = CLAMP (volume, 0, 128); |
2435 | RETVAL = Mix_VolumeChunk (self, volume); |
2977 | RETVAL = Mix_VolumeChunk (self, volume); |
2436 | OUTPUT: |
2978 | OUTPUT: |
2437 | RETVAL |
2979 | RETVAL |
2438 | |
2980 | |
2439 | CFPlus::Channel |
2981 | DC::Channel |
2440 | play (CFPlus::MixChunk self, CFPlus::Channel channel = -1, int loops = 0, int ticks = -1) |
2982 | play (DC::MixChunk self, DC::Channel channel = -1, int loops = 0, int ticks = -1) |
2441 | CODE: |
2983 | CODE: |
2442 | { |
2984 | { |
2443 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
2985 | RETVAL = Mix_PlayChannelTimed (channel, self, loops, ticks); |
2444 | |
2986 | |
2445 | if (RETVAL < 0) |
2987 | if (RETVAL < 0) |
… | |
… | |
2452 | } |
2994 | } |
2453 | } |
2995 | } |
2454 | OUTPUT: |
2996 | OUTPUT: |
2455 | RETVAL |
2997 | RETVAL |
2456 | |
2998 | |
2457 | MODULE = CFPlus PACKAGE = CFPlus::MixMusic |
2999 | MODULE = Deliantra::Client PACKAGE = DC::MixMusic |
|
|
3000 | |
|
|
3001 | void |
|
|
3002 | decoders () |
|
|
3003 | PPCODE: |
|
|
3004 | #if SDL_MIXER_MAJOR_VERSION > 1 || SDL_MIXER_MINOR_VERSION > 2 || SDL_MIXER_PATCHLEVEL >= 10 |
|
|
3005 | int i, num = Mix_GetNumMusicDecoders (); |
|
|
3006 | EXTEND (SP, num); |
|
|
3007 | for (i = 0; i < num; ++i) |
|
|
3008 | PUSHs (sv_2mortal (newSVpv (Mix_GetMusicDecoder (i), 0))); |
|
|
3009 | #else |
|
|
3010 | XPUSHs (sv_2mortal (newSVpv ("(sdl mixer too old)", 0))); |
|
|
3011 | #endif |
2458 | |
3012 | |
2459 | int |
3013 | int |
2460 | volume (int volume = -1) |
3014 | volume (int volume = -1) |
2461 | PROTOTYPE: ;$ |
3015 | PROTOTYPE: ;$ |
2462 | CODE: |
3016 | CODE: |
… | |
… | |
2474 | void |
3028 | void |
2475 | halt () |
3029 | halt () |
2476 | CODE: |
3030 | CODE: |
2477 | Mix_HaltMusic (); |
3031 | Mix_HaltMusic (); |
2478 | |
3032 | |
|
|
3033 | int |
|
|
3034 | playing () |
|
|
3035 | CODE: |
|
|
3036 | RETVAL = Mix_PlayingMusic (); |
|
|
3037 | OUTPUT: |
|
|
3038 | RETVAL |
|
|
3039 | |
2479 | CFPlus::MixMusic |
3040 | DC::MixMusic |
2480 | new (SV *class, CFPlus::RW rwops) |
3041 | new (SV *klass, DC::RW rwops) |
2481 | CODE: |
3042 | CODE: |
2482 | RETVAL = Mix_LoadMUS_RW (rwops); |
3043 | RETVAL = Mix_LoadMUS_RW (rwops); |
2483 | OUTPUT: |
3044 | OUTPUT: |
2484 | RETVAL |
3045 | RETVAL |
2485 | |
3046 | |
2486 | void |
3047 | void |
2487 | DESTROY (CFPlus::MixMusic self) |
3048 | DESTROY (DC::MixMusic self) |
2488 | CODE: |
3049 | CODE: |
2489 | Mix_FreeMusic (self); |
3050 | Mix_FreeMusic (self); |
2490 | |
3051 | |
2491 | int |
3052 | int |
2492 | play (CFPlus::MixMusic self, int loops = -1) |
3053 | play (DC::MixMusic self, int loops = -1) |
2493 | CODE: |
3054 | CODE: |
2494 | RETVAL = Mix_PlayMusic (self, loops); |
3055 | RETVAL = Mix_PlayMusic (self, loops); |
2495 | OUTPUT: |
3056 | OUTPUT: |
2496 | RETVAL |
3057 | RETVAL |
2497 | |
3058 | |
2498 | void |
3059 | void |
2499 | fade_in_pos (CFPlus::MixMusic self, int loops, int ms, double position) |
3060 | fade_in_pos (DC::MixMusic self, int loops, int ms, double position) |
2500 | CODE: |
3061 | CODE: |
2501 | Mix_FadeInMusicPos (self, loops, ms, position); |
3062 | Mix_FadeInMusicPos (self, loops, ms, position); |
2502 | |
3063 | |
2503 | MODULE = CFPlus PACKAGE = CFPlus::OpenGL |
3064 | MODULE = Deliantra::Client PACKAGE = DC::OpenGL |
2504 | |
3065 | |
2505 | PROTOTYPES: ENABLE |
3066 | PROTOTYPES: ENABLE |
2506 | |
3067 | |
2507 | BOOT: |
3068 | BOOT: |
2508 | { |
3069 | { |
2509 | HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); |
3070 | HV *stash = gv_stashpv ("DC::OpenGL", 1); |
2510 | static const struct { |
3071 | static const struct { |
2511 | const char *name; |
3072 | const char *name; |
2512 | IV iv; |
3073 | IV iv; |
2513 | } *civ, const_iv[] = { |
3074 | } *civ, const_iv[] = { |
2514 | # define const_iv(name) { # name, (IV)name } |
3075 | # define const_iv(name) { # name, (IV)name } |
2515 | const_iv (GL_VENDOR), |
3076 | const_iv (GL_VENDOR), |
2516 | const_iv (GL_VERSION), |
3077 | const_iv (GL_VERSION), |
2517 | const_iv (GL_EXTENSIONS), |
3078 | const_iv (GL_EXTENSIONS), |
|
|
3079 | const_iv (GL_MAX_TEXTURE_UNITS), |
2518 | const_iv (GL_COLOR_MATERIAL), |
3080 | const_iv (GL_COLOR_MATERIAL), |
2519 | const_iv (GL_SMOOTH), |
3081 | const_iv (GL_SMOOTH), |
2520 | const_iv (GL_FLAT), |
3082 | const_iv (GL_FLAT), |
2521 | const_iv (GL_DITHER), |
3083 | const_iv (GL_DITHER), |
2522 | const_iv (GL_BLEND), |
3084 | const_iv (GL_BLEND), |
… | |
… | |
2534 | const_iv (GL_ZERO), |
3096 | const_iv (GL_ZERO), |
2535 | const_iv (GL_SRC_ALPHA), |
3097 | const_iv (GL_SRC_ALPHA), |
2536 | const_iv (GL_DST_ALPHA), |
3098 | const_iv (GL_DST_ALPHA), |
2537 | const_iv (GL_ONE_MINUS_SRC_ALPHA), |
3099 | const_iv (GL_ONE_MINUS_SRC_ALPHA), |
2538 | const_iv (GL_ONE_MINUS_DST_ALPHA), |
3100 | const_iv (GL_ONE_MINUS_DST_ALPHA), |
|
|
3101 | const_iv (GL_SRC_COLOR), |
|
|
3102 | const_iv (GL_DST_COLOR), |
|
|
3103 | const_iv (GL_ONE_MINUS_SRC_COLOR), |
|
|
3104 | const_iv (GL_ONE_MINUS_DST_COLOR), |
2539 | const_iv (GL_SRC_ALPHA_SATURATE), |
3105 | const_iv (GL_SRC_ALPHA_SATURATE), |
2540 | const_iv (GL_RGB), |
3106 | const_iv (GL_RGB), |
2541 | const_iv (GL_RGBA), |
3107 | const_iv (GL_RGBA), |
2542 | const_iv (GL_RGBA4), |
3108 | const_iv (GL_RGBA4), |
2543 | const_iv (GL_RGBA8), |
3109 | const_iv (GL_RGBA8), |
… | |
… | |
2549 | const_iv (GL_INTENSITY), |
3115 | const_iv (GL_INTENSITY), |
2550 | const_iv (GL_LUMINANCE), |
3116 | const_iv (GL_LUMINANCE), |
2551 | const_iv (GL_LUMINANCE_ALPHA), |
3117 | const_iv (GL_LUMINANCE_ALPHA), |
2552 | const_iv (GL_FLOAT), |
3118 | const_iv (GL_FLOAT), |
2553 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
3119 | const_iv (GL_UNSIGNED_INT_8_8_8_8_REV), |
|
|
3120 | const_iv (GL_COMPRESSED_ALPHA_ARB), |
|
|
3121 | const_iv (GL_COMPRESSED_LUMINANCE_ARB), |
|
|
3122 | const_iv (GL_COMPRESSED_LUMINANCE_ALPHA_ARB), |
|
|
3123 | const_iv (GL_COMPRESSED_INTENSITY_ARB), |
|
|
3124 | const_iv (GL_COMPRESSED_RGB_ARB), |
|
|
3125 | const_iv (GL_COMPRESSED_RGBA_ARB), |
2554 | const_iv (GL_COMPILE), |
3126 | const_iv (GL_COMPILE), |
2555 | const_iv (GL_PROXY_TEXTURE_1D), |
3127 | const_iv (GL_PROXY_TEXTURE_1D), |
2556 | const_iv (GL_PROXY_TEXTURE_2D), |
3128 | const_iv (GL_PROXY_TEXTURE_2D), |
2557 | const_iv (GL_TEXTURE_1D), |
3129 | const_iv (GL_TEXTURE_1D), |
2558 | const_iv (GL_TEXTURE_2D), |
3130 | const_iv (GL_TEXTURE_2D), |
… | |
… | |
2597 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
3169 | const_iv (GL_PERSPECTIVE_CORRECTION_HINT), |
2598 | const_iv (GL_POINT_SMOOTH_HINT), |
3170 | const_iv (GL_POINT_SMOOTH_HINT), |
2599 | const_iv (GL_LINE_SMOOTH_HINT), |
3171 | const_iv (GL_LINE_SMOOTH_HINT), |
2600 | const_iv (GL_POLYGON_SMOOTH_HINT), |
3172 | const_iv (GL_POLYGON_SMOOTH_HINT), |
2601 | const_iv (GL_GENERATE_MIPMAP_HINT), |
3173 | const_iv (GL_GENERATE_MIPMAP_HINT), |
|
|
3174 | const_iv (GL_TEXTURE_COMPRESSION_HINT), |
2602 | const_iv (GL_FASTEST), |
3175 | const_iv (GL_FASTEST), |
2603 | const_iv (GL_DONT_CARE), |
3176 | const_iv (GL_DONT_CARE), |
2604 | const_iv (GL_NICEST), |
3177 | const_iv (GL_NICEST), |
2605 | const_iv (GL_V2F), |
3178 | const_iv (GL_V2F), |
2606 | const_iv (GL_V3F), |
3179 | const_iv (GL_V3F), |
2607 | const_iv (GL_T2F_V3F), |
3180 | const_iv (GL_T2F_V3F), |
2608 | const_iv (GL_T2F_N3F_V3F), |
3181 | const_iv (GL_T2F_N3F_V3F), |
|
|
3182 | const_iv (GL_FUNC_ADD), |
|
|
3183 | const_iv (GL_FUNC_SUBTRACT), |
|
|
3184 | const_iv (GL_FUNC_REVERSE_SUBTRACT), |
2609 | # undef const_iv |
3185 | # undef const_iv |
2610 | }; |
3186 | }; |
2611 | |
3187 | |
2612 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
3188 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
2613 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
3189 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
2614 | |
3190 | |
2615 | texture_av = newAV (); |
3191 | texture_av = newAV (); |
2616 | AvREAL_off (texture_av); |
3192 | AvREAL_off (texture_av); |
2617 | } |
3193 | } |
2618 | |
3194 | |
2619 | char * |
3195 | void |
|
|
3196 | disable_GL_EXT_blend_func_separate () |
|
|
3197 | CODE: |
|
|
3198 | gl.BlendFuncSeparate = 0; |
|
|
3199 | gl.BlendFuncSeparateEXT = 0; |
|
|
3200 | |
|
|
3201 | void |
|
|
3202 | apple_nvidia_bug (int enable) |
|
|
3203 | |
|
|
3204 | const char * |
2620 | gl_vendor () |
3205 | gl_vendor () |
2621 | CODE: |
3206 | CODE: |
2622 | RETVAL = (char *)glGetString (GL_VENDOR); |
3207 | RETVAL = (const char *)glGetString (GL_VENDOR); |
2623 | OUTPUT: |
3208 | OUTPUT: |
2624 | RETVAL |
3209 | RETVAL |
2625 | |
3210 | |
2626 | char * |
3211 | const char * |
2627 | gl_version () |
3212 | gl_version () |
2628 | CODE: |
3213 | CODE: |
2629 | RETVAL = (char *)glGetString (GL_VERSION); |
3214 | RETVAL = (const char *)glGetString (GL_VERSION); |
2630 | OUTPUT: |
3215 | OUTPUT: |
2631 | RETVAL |
3216 | RETVAL |
2632 | |
3217 | |
2633 | char * |
3218 | const char * |
2634 | gl_extensions () |
3219 | gl_extensions () |
2635 | CODE: |
3220 | CODE: |
2636 | RETVAL = (char *)glGetString (GL_EXTENSIONS); |
3221 | RETVAL = (const char *)glGetString (GL_EXTENSIONS); |
2637 | OUTPUT: |
3222 | OUTPUT: |
2638 | RETVAL |
3223 | RETVAL |
2639 | |
3224 | |
2640 | const char *glGetString (GLenum pname) |
3225 | const char *glGetString (GLenum pname) |
|
|
3226 | CODE: |
|
|
3227 | RETVAL = (const char *)glGetString (pname); |
|
|
3228 | OUTPUT: |
|
|
3229 | RETVAL |
2641 | |
3230 | |
2642 | GLint glGetInteger (GLenum pname) |
3231 | GLint glGetInteger (GLenum pname) |
2643 | CODE: |
3232 | CODE: |
2644 | glGetIntegerv (pname, &RETVAL); |
3233 | glGetIntegerv (pname, &RETVAL); |
2645 | OUTPUT: |
3234 | OUTPUT: |
… | |
… | |
2653 | |
3242 | |
2654 | int glGetError () |
3243 | int glGetError () |
2655 | |
3244 | |
2656 | void glFinish () |
3245 | void glFinish () |
2657 | |
3246 | |
|
|
3247 | void glFlush () |
|
|
3248 | |
2658 | void glClear (int mask) |
3249 | void glClear (int mask) |
2659 | |
3250 | |
2660 | void glClearColor (float r, float g, float b, float a = 1.0) |
3251 | void glClearColor (float r, float g, float b, float a = 1.0) |
2661 | PROTOTYPE: @ |
3252 | PROTOTYPE: @ |
2662 | |
3253 | |
… | |
… | |
2671 | void glBlendFunc (int sfactor, int dfactor) |
3262 | void glBlendFunc (int sfactor, int dfactor) |
2672 | |
3263 | |
2673 | void glBlendFuncSeparate (int sa, int da, int saa, int daa) |
3264 | void glBlendFuncSeparate (int sa, int da, int saa, int daa) |
2674 | CODE: |
3265 | CODE: |
2675 | gl_BlendFuncSeparate (sa, da, saa, daa); |
3266 | gl_BlendFuncSeparate (sa, da, saa, daa); |
|
|
3267 | |
|
|
3268 | # void glBlendEquation (int se) |
2676 | |
3269 | |
2677 | void glDepthMask (int flag) |
3270 | void glDepthMask (int flag) |
2678 | |
3271 | |
2679 | void glLogicOp (int opcode) |
3272 | void glLogicOp (int opcode) |
2680 | |
3273 | |
… | |
… | |
2715 | void glRotate (float angle, float x, float y, float z) |
3308 | void glRotate (float angle, float x, float y, float z) |
2716 | CODE: |
3309 | CODE: |
2717 | glRotatef (angle, x, y, z); |
3310 | glRotatef (angle, x, y, z); |
2718 | |
3311 | |
2719 | void glColor (float r, float g, float b, float a = 1.0) |
3312 | void glColor (float r, float g, float b, float a = 1.0) |
|
|
3313 | PROTOTYPE: @ |
2720 | ALIAS: |
3314 | ALIAS: |
2721 | glColor_premultiply = 1 |
3315 | glColor_premultiply = 1 |
2722 | CODE: |
3316 | CODE: |
2723 | if (ix) |
3317 | if (ix) |
2724 | { |
3318 | { |
… | |
… | |
2744 | |
3338 | |
2745 | void glRect (float x1, float y1, float x2, float y2) |
3339 | void glRect (float x1, float y1, float x2, float y2) |
2746 | CODE: |
3340 | CODE: |
2747 | glRectf (x1, y1, x2, y2); |
3341 | glRectf (x1, y1, x2, y2); |
2748 | |
3342 | |
|
|
3343 | void glRect_lineloop (float x1, float y1, float x2, float y2) |
|
|
3344 | CODE: |
|
|
3345 | glBegin (GL_LINE_LOOP); |
|
|
3346 | glVertex2f (x1, y1); |
|
|
3347 | glVertex2f (x2, y1); |
|
|
3348 | glVertex2f (x2, y2); |
|
|
3349 | glVertex2f (x1, y2); |
|
|
3350 | glEnd (); |
|
|
3351 | |
2749 | PROTOTYPES: ENABLE |
3352 | PROTOTYPES: ENABLE |
2750 | |
3353 | |
2751 | void glBegin (int mode) |
3354 | void glBegin (int mode) |
2752 | |
3355 | |
2753 | void glEnd () |
3356 | void glEnd () |
… | |
… | |
2785 | void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) |
3388 | void glSeparableFilter2D (int target, int internalformat, int width, int height, int format, int type, char *row, char *column) |
2786 | CODE: |
3389 | CODE: |
2787 | if (gl.SeparableFilter2D) |
3390 | if (gl.SeparableFilter2D) |
2788 | gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); |
3391 | gl.SeparableFilter2D (target, internalformat, width, height, format, type, row, column); |
2789 | |
3392 | |
2790 | void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data) |
3393 | void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type, char *data = 0) |
2791 | |
3394 | |
2792 | void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) |
3395 | void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) |
2793 | |
3396 | |
2794 | void glDrawPixels (int width, int height, int format, int type, char *pixels) |
3397 | void glDrawPixels (int width, int height, int format, int type, char *pixels) |
2795 | |
3398 | |
… | |
… | |
2821 | |
3424 | |
2822 | void glEndList () |
3425 | void glEndList () |
2823 | |
3426 | |
2824 | void glCallList (int list) |
3427 | void glCallList (int list) |
2825 | |
3428 | |
2826 | MODULE = CFPlus PACKAGE = CFPlus::UI::Base |
3429 | void c_init () |
|
|
3430 | CODE: |
|
|
3431 | glPixelStorei (GL_PACK_ALIGNMENT , 1); |
|
|
3432 | glPixelStorei (GL_UNPACK_ALIGNMENT, 1); |
|
|
3433 | |
|
|
3434 | MODULE = Deliantra::Client PACKAGE = DC::UI::Base |
2827 | |
3435 | |
2828 | PROTOTYPES: DISABLE |
3436 | PROTOTYPES: DISABLE |
2829 | |
3437 | |
2830 | void |
3438 | void |
2831 | find_widget (SV *self, NV x, NV y) |
3439 | find_widget (SV *self, NV x, NV y) |
2832 | PPCODE: |
3440 | PPCODE: |
2833 | { |
3441 | { |
2834 | if (within_widget (self, x, y)) |
3442 | if (within_widget (self, x, y)) |
2835 | XPUSHs (self); |
3443 | XPUSHs (self); |
2836 | } |
3444 | } |
2837 | |
3445 | |
2838 | BOOT: |
3446 | BOOT: |
2839 | { |
3447 | { |
2840 | hover_gv = gv_fetchpv ("CFPlus::UI::HOVER", 1, SVt_NV); |
3448 | hover_gv = gv_fetchpv ("DC::UI::HOVER", 1, SVt_NV); |
2841 | |
3449 | |
2842 | draw_x_gv = gv_fetchpv ("CFPlus::UI::Base::draw_x", 1, SVt_NV); |
3450 | draw_x_gv = gv_fetchpv ("DC::UI::Base::draw_x", 1, SVt_NV); |
2843 | draw_y_gv = gv_fetchpv ("CFPlus::UI::Base::draw_y", 1, SVt_NV); |
3451 | draw_y_gv = gv_fetchpv ("DC::UI::Base::draw_y", 1, SVt_NV); |
2844 | draw_w_gv = gv_fetchpv ("CFPlus::UI::Base::draw_w", 1, SVt_NV); |
3452 | draw_w_gv = gv_fetchpv ("DC::UI::Base::draw_w", 1, SVt_NV); |
2845 | draw_h_gv = gv_fetchpv ("CFPlus::UI::Base::draw_h", 1, SVt_NV); |
3453 | draw_h_gv = gv_fetchpv ("DC::UI::Base::draw_h", 1, SVt_NV); |
2846 | } |
3454 | } |
2847 | |
3455 | |
2848 | void |
3456 | void |
2849 | draw (SV *self) |
3457 | draw (SV *self) |
2850 | CODE: |
3458 | CODE: |
2851 | { |
3459 | { |
2852 | HV *hv; |
3460 | HV *hv; |
2853 | SV **svp; |
3461 | SV **svp; |
2854 | NV x, y, w, h; |
3462 | NV x, y, w, h; |
2855 | SV *draw_x_sv = GvSV (draw_x_gv); |
3463 | SV *draw_x_sv = GvSV (draw_x_gv); |
2856 | SV *draw_y_sv = GvSV (draw_y_gv); |
3464 | SV *draw_y_sv = GvSV (draw_y_gv); |
2857 | SV *draw_w_sv = GvSV (draw_w_gv); |
3465 | SV *draw_w_sv = GvSV (draw_w_gv); |
2858 | SV *draw_h_sv = GvSV (draw_h_gv); |
3466 | SV *draw_h_sv = GvSV (draw_h_gv); |
2859 | double draw_x, draw_y; |
3467 | double draw_x, draw_y; |
2860 | |
3468 | |
2861 | if (!SvROK (self)) |
3469 | if (!SvROK (self)) |
2862 | croak ("CFPlus::Base::draw: %s not a reference", SvPV_nolen (self)); |
3470 | croak ("DC::Base::draw: %s not a reference", SvPV_nolen (self)); |
2863 | |
3471 | |
2864 | hv = (HV *)SvRV (self); |
3472 | hv = (HV *)SvRV (self); |
2865 | |
3473 | |
2866 | if (SvTYPE (hv) != SVt_PVHV) |
3474 | if (SvTYPE (hv) != SVt_PVHV) |
2867 | croak ("CFPlus::Base::draw: %s not a hashref", SvPV_nolen (self)); |
3475 | croak ("DC::Base::draw: %s not a hashref", SvPV_nolen (self)); |
2868 | |
3476 | |
2869 | svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; |
3477 | svp = hv_fetch (hv, "w", 1, 0); w = svp ? SvNV (*svp) : 0.; |
2870 | svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; |
3478 | svp = hv_fetch (hv, "h", 1, 0); h = svp ? SvNV (*svp) : 0.; |
2871 | |
3479 | |
2872 | if (!h || !w) |
3480 | if (!h || !w) |
… | |
… | |
2905 | glEnd (); |
3513 | glEnd (); |
2906 | glDisable (GL_BLEND); |
3514 | glDisable (GL_BLEND); |
2907 | } |
3515 | } |
2908 | } |
3516 | } |
2909 | #if 0 |
3517 | #if 0 |
2910 | if ($ENV{CFPLUS_DEBUG} & 1) { |
3518 | // draw borders, for debugging |
2911 | glPushMatrix; |
3519 | glPushMatrix (); |
2912 | glColor 1, 1, 0, 1; |
3520 | glColor4f (1., 1., 0., 1.); |
2913 | glTranslate 0.375, 0.375; |
3521 | glTranslatef (.5, .5, 0.); |
2914 | glBegin GL_LINE_LOOP; |
3522 | glBegin (GL_LINE_LOOP); |
2915 | glVertex 0 , 0; |
3523 | glVertex2f (0 , 0); |
2916 | glVertex $self->{w} - 1, 0; |
3524 | glVertex2f (w - 1, 0); |
2917 | glVertex $self->{w} - 1, $self->{h} - 1; |
3525 | glVertex2f (w - 1, h - 1); |
2918 | glVertex 0 , $self->{h} - 1; |
3526 | glVertex2f (0 , h - 1); |
2919 | glEnd; |
3527 | glEnd (); |
2920 | glPopMatrix; |
3528 | glPopMatrix (); |
2921 | #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
|
|
2922 | } |
|
|
2923 | #endif |
3529 | #endif |
2924 | PUSHMARK (SP); |
3530 | PUSHMARK (SP); |
2925 | XPUSHs (self); |
3531 | XPUSHs (self); |
2926 | PUTBACK; |
3532 | PUTBACK; |
2927 | call_method ("_draw", G_VOID | G_DISCARD); |
3533 | call_method ("_draw", G_VOID | G_DISCARD); |