1 | #include "EXTERN.h" |
1 | #include "EXTERN.h" |
2 | #include "perl.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
3 | #include "XSUB.h" |
4 | |
4 | |
5 | #include <string.h> |
5 | #include <string.h> |
|
|
6 | #include <stdio.h> |
6 | |
7 | |
7 | #include <SDL.h> |
8 | #include <SDL.h> |
|
|
9 | #include <SDL_image.h> |
8 | #include <SDL_opengl.h> |
10 | #include <SDL_opengl.h> |
9 | |
11 | |
10 | #include <pango/pango.h> |
12 | #include <pango/pango.h> |
11 | #include <pango/pangofc-fontmap.h> |
13 | #include <pango/pangofc-fontmap.h> |
12 | #include <pango/pangoft2.h> |
14 | #include <pango/pangoft2.h> |
13 | |
|
|
14 | #include <sys/time.h> |
|
|
15 | #include <sys/types.h> |
|
|
16 | #include <unistd.h> |
|
|
17 | |
15 | |
18 | #include <sys/types.h> |
16 | #include <sys/types.h> |
19 | #include <sys/socket.h> |
17 | #include <sys/socket.h> |
20 | #include <netinet/in.h> |
18 | #include <netinet/in.h> |
21 | #include <netinet/tcp.h> |
19 | #include <netinet/tcp.h> |
|
|
20 | |
|
|
21 | #include <inttypes.h> |
22 | |
22 | |
23 | static PangoContext *context; |
23 | static PangoContext *context; |
24 | static PangoFontMap *fontmap; |
24 | static PangoFontMap *fontmap; |
25 | |
25 | |
26 | typedef struct cf_layout { |
26 | typedef struct cf_layout { |
… | |
… | |
55 | *w = (*w + 3) & ~3; |
55 | *w = (*w + 3) & ~3; |
56 | if (!*w) *w = 1; |
56 | if (!*w) *w = 1; |
57 | if (!*h) *h = 1; |
57 | if (!*h) *h = 1; |
58 | } |
58 | } |
59 | |
59 | |
|
|
60 | typedef struct { |
|
|
61 | uint16_t face[3]; |
|
|
62 | uint8_t darkness; |
|
|
63 | uint8_t padding; |
|
|
64 | } mapcell; |
|
|
65 | |
|
|
66 | typedef struct { |
|
|
67 | uint32_t cols; |
|
|
68 | mapcell *col; |
|
|
69 | } maprow; |
|
|
70 | |
|
|
71 | typedef struct map { |
|
|
72 | int x, y, w, h; |
|
|
73 | int faces; |
|
|
74 | GLint *face; |
|
|
75 | |
|
|
76 | uint32_t rows; |
|
|
77 | maprow *row; |
|
|
78 | } *CFClient__Map; |
|
|
79 | |
60 | MODULE = CFClient PACKAGE = CFClient |
80 | MODULE = CFClient PACKAGE = CFClient |
61 | |
81 | |
62 | PROTOTYPES: ENABLE |
82 | PROTOTYPES: ENABLE |
63 | |
83 | |
64 | BOOT: |
84 | BOOT: |
… | |
… | |
100 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count); |
120 | FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count); |
101 | PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); |
121 | PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); |
102 | FcPatternDestroy (pattern); |
122 | FcPatternDestroy (pattern); |
103 | pango_context_set_font_description (context, font); |
123 | pango_context_set_font_description (context, font); |
104 | } |
124 | } |
|
|
125 | |
|
|
126 | void |
|
|
127 | load_image_inline (SV *image_) |
|
|
128 | ALIAS: |
|
|
129 | load_image_file = 1 |
|
|
130 | PPCODE: |
|
|
131 | { |
|
|
132 | STRLEN image_len; |
|
|
133 | char *image = (char *)SvPVbyte (image_, image_len); |
|
|
134 | SDL_Surface *surface, *surface2; |
|
|
135 | SDL_PixelFormat fmt; |
|
|
136 | SDL_RWops *rw = ix |
|
|
137 | ? SDL_RWFromFile (image, "r") |
|
|
138 | : SDL_RWFromConstMem (image, image_len); |
|
|
139 | |
|
|
140 | if (!rw) |
|
|
141 | croak ("load_image: unable to open file"); |
|
|
142 | |
|
|
143 | surface = IMG_Load_RW (rw, 1); |
|
|
144 | if (!surface) |
|
|
145 | croak ("load_image: unable to read file"); |
|
|
146 | |
|
|
147 | fmt.palette = NULL; |
|
|
148 | fmt.BitsPerPixel = 32; |
|
|
149 | fmt.BytesPerPixel = 4; |
|
|
150 | fmt.Rmask = 0x000000ff; |
|
|
151 | fmt.Gmask = 0x0000ff00; |
|
|
152 | fmt.Bmask = 0x00ff0000; |
|
|
153 | fmt.Amask = 0xff000000; |
|
|
154 | fmt.Rloss = 0; |
|
|
155 | fmt.Gloss = 0; |
|
|
156 | fmt.Bloss = 0; |
|
|
157 | fmt.Aloss = 0; |
|
|
158 | fmt.Rshift = 0; |
|
|
159 | fmt.Gshift = 8; |
|
|
160 | fmt.Bshift = 16; |
|
|
161 | fmt.Ashift = 24; |
|
|
162 | fmt.colorkey = 0; |
|
|
163 | fmt.alpha = 0; |
|
|
164 | |
|
|
165 | surface2 = SDL_ConvertSurface (surface, &fmt, SDL_SWSURFACE); |
|
|
166 | |
|
|
167 | EXTEND (SP, 5); |
|
|
168 | PUSHs (sv_2mortal (newSViv (surface2->w))); |
|
|
169 | PUSHs (sv_2mortal (newSViv (surface2->h))); |
|
|
170 | SDL_LockSurface (surface2); |
|
|
171 | PUSHs (sv_2mortal (newSVpvn (surface2->pixels, surface2->h * surface2->pitch))); |
|
|
172 | SDL_UnlockSurface (surface2); |
|
|
173 | PUSHs (sv_2mortal (newSViv (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA) ? GL_RGBA : GL_RGB))); |
|
|
174 | PUSHs (sv_2mortal (newSViv (GL_RGBA))); |
|
|
175 | PUSHs (sv_2mortal (newSViv (GL_UNSIGNED_INT_8_8_8_8_REV))); |
|
|
176 | |
|
|
177 | SDL_FreeSurface (surface); |
|
|
178 | SDL_FreeSurface (surface2); |
|
|
179 | } |
|
|
180 | |
|
|
181 | void |
|
|
182 | fatal (char *message) |
|
|
183 | CODE: |
|
|
184 | #ifdef WIN32 |
|
|
185 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR | MB_SETFOREGROUND); |
|
|
186 | #else |
|
|
187 | fprintf (stderr, "%s\n", message); |
|
|
188 | #endif |
|
|
189 | exit (1); |
105 | |
190 | |
106 | MODULE = CFClient PACKAGE = CFClient::Layout |
191 | MODULE = CFClient PACKAGE = CFClient::Layout |
107 | |
192 | |
108 | CFClient::Layout |
193 | CFClient::Layout |
109 | new (SV *class, int base_height = 10) |
194 | new (SV *class, int base_height = 10) |
… | |
… | |
238 | glTexCoord2d (0, t); glVertex2d (x , y + h); |
323 | glTexCoord2d (0, t); glVertex2d (x , y + h); |
239 | glTexCoord2d (s, t); glVertex2d (x + w, y + h); |
324 | glTexCoord2d (s, t); glVertex2d (x + w, y + h); |
240 | glTexCoord2d (s, 0); glVertex2d (x + w, y ); |
325 | glTexCoord2d (s, 0); glVertex2d (x + w, y ); |
241 | glEnd (); |
326 | glEnd (); |
242 | } |
327 | } |
|
|
328 | |
|
|
329 | MODULE = CFClient PACKAGE = CFClient::Map |
|
|
330 | |
|
|
331 | CFClient::Map |
|
|
332 | new (SV *class, int map_width, int map_height) |
|
|
333 | CODE: |
|
|
334 | New (0, RETVAL, 1, struct map); |
|
|
335 | RETVAL->x = 0; |
|
|
336 | RETVAL->y = 0; |
|
|
337 | RETVAL->w = map_width; |
|
|
338 | RETVAL->h = map_height; |
|
|
339 | RETVAL->faces = 0; |
|
|
340 | RETVAL->face = 0; |
|
|
341 | |
|
|
342 | RETVAL->rows = 0; |
|
|
343 | RETVAL->row = 0; |
|
|
344 | OUTPUT: |
|
|
345 | RETVAL |
|
|
346 | |
|
|
347 | void |
|
|
348 | DESTROY (CFClient::Map self) |
|
|
349 | CODE: |
|
|
350 | { |
|
|
351 | int r, c; |
|
|
352 | |
|
|
353 | Safefree (self->face); |
|
|
354 | for (r = 0; r < self->rows; r++) |
|
|
355 | { |
|
|
356 | maprow *row = self->row + r; |
|
|
357 | if (!row) |
|
|
358 | continue; |
|
|
359 | |
|
|
360 | Safefree (row->col); |
|
|
361 | } |
|
|
362 | |
|
|
363 | Safefree (self->row); |
|
|
364 | Safefree (self); |
|
|
365 | } |
|
|
366 | |