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