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