… | |
… | |
26 | #include <string.h> |
26 | #include <string.h> |
27 | #include <stdio.h> |
27 | #include <stdio.h> |
28 | #include <stdlib.h> |
28 | #include <stdlib.h> |
29 | |
29 | |
30 | #include <SDL.h> |
30 | #include <SDL.h> |
|
|
31 | #include <SDL_thread.h> |
31 | #include <SDL_endian.h> |
32 | #include <SDL_endian.h> |
32 | #include <SDL_image.h> |
33 | #include <SDL_image.h> |
33 | #include <SDL_mixer.h> |
34 | #include <SDL_mixer.h> |
34 | #include <SDL_opengl.h> |
35 | #include <SDL_opengl.h> |
35 | |
36 | |
… | |
… | |
932 | #endif |
933 | #endif |
933 | } |
934 | } |
934 | |
935 | |
935 | MODULE = CFPlus PACKAGE = CFPlus::Font |
936 | MODULE = CFPlus PACKAGE = CFPlus::Font |
936 | |
937 | |
|
|
938 | PROTOTYPES: DISABLE |
|
|
939 | |
937 | CFPlus::Font |
940 | CFPlus::Font |
938 | new_from_file (SV *class, char *path, int id = 0) |
941 | new_from_file (SV *class, char *path, int id = 0) |
939 | CODE: |
942 | CODE: |
940 | { |
943 | { |
941 | int count; |
944 | int count; |
… | |
… | |
951 | CODE: |
954 | CODE: |
952 | pango_font_description_free (self); |
955 | pango_font_description_free (self); |
953 | |
956 | |
954 | void |
957 | void |
955 | make_default (CFPlus::Font self) |
958 | make_default (CFPlus::Font self) |
|
|
959 | PROTOTYPE: $ |
956 | CODE: |
960 | CODE: |
957 | default_font = self; |
961 | default_font = self; |
958 | |
962 | |
959 | MODULE = CFPlus PACKAGE = CFPlus::Layout |
963 | MODULE = CFPlus PACKAGE = CFPlus::Layout |
960 | |
964 | |
|
|
965 | PROTOTYPES: DISABLE |
|
|
966 | |
961 | void |
967 | void |
962 | reset_glyph_cache () |
968 | reset_glyph_cache () |
|
|
969 | PROTOTYPE: |
963 | CODE: |
970 | CODE: |
964 | tc_clear (); |
971 | tc_clear (); |
965 | |
972 | |
966 | CFPlus::Layout |
973 | CFPlus::Layout |
967 | new (SV *class) |
974 | new (SV *class) |
… | |
… | |
1254 | flags |
1261 | flags |
1255 | ); |
1262 | ); |
1256 | |
1263 | |
1257 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1264 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1258 | |
1265 | |
|
|
1266 | PROTOTYPES: ENABLE |
|
|
1267 | |
1259 | int minpot (int n) |
1268 | int minpot (int n) |
1260 | |
1269 | |
1261 | void |
1270 | void |
1262 | pad2pot (SV *data_, SV *w_, SV *h_) |
1271 | pad (SV *data_, int ow, int oh, int nw, int nh) |
1263 | CODE: |
1272 | CODE: |
1264 | { |
1273 | { |
1265 | int ow = SvIV (w_); |
1274 | if ((nw != ow || nh != oh) && SvOK (data_)) |
1266 | int oh = SvIV (h_); |
|
|
1267 | |
|
|
1268 | if (ow && oh) |
|
|
1269 | { |
1275 | { |
1270 | int nw = minpot (ow); |
|
|
1271 | int nh = minpot (oh); |
|
|
1272 | |
|
|
1273 | if (nw != ow || nh != oh) |
|
|
1274 | { |
|
|
1275 | if (SvOK (data_)) |
|
|
1276 | { |
|
|
1277 | STRLEN datalen; |
1276 | STRLEN datalen; |
1278 | char *data = SvPVbyte (data_, datalen); |
1277 | char *data = SvPVbyte (data_, datalen); |
1279 | int bpp = datalen / (ow * oh); |
1278 | int bpp = datalen / (ow * oh); |
1280 | SV *result_ = sv_2mortal (newSV (nw * nh * bpp)); |
1279 | SV *result_ = sv_2mortal (newSV (nw * nh * bpp)); |
1281 | |
1280 | |
1282 | SvPOK_only (result_); |
1281 | SvPOK_only (result_); |
1283 | SvCUR_set (result_, nw * nh * bpp); |
1282 | SvCUR_set (result_, nw * nh * bpp); |
1284 | |
1283 | |
1285 | memset (SvPVX (result_), 0, nw * nh * bpp); |
1284 | memset (SvPVX (result_), 0, nw * nh * bpp); |
1286 | while (oh--) |
1285 | while (oh--) |
1287 | memcpy (SvPVX (result_) + oh * nw * bpp, data + oh * ow * bpp, ow * bpp); |
1286 | memcpy (SvPVX (result_) + oh * nw * bpp, data + oh * ow * bpp, ow * bpp); |
1288 | |
1287 | |
1289 | sv_setsv (data_, result_); |
1288 | sv_setsv (data_, result_); |
1290 | } |
|
|
1291 | |
|
|
1292 | sv_setiv (w_, nw); |
|
|
1293 | sv_setiv (h_, nh); |
|
|
1294 | } |
|
|
1295 | } |
1289 | } |
1296 | } |
1290 | } |
1297 | |
1291 | |
1298 | void |
1292 | void |
1299 | draw_quad (SV *self, float x, float y, float w = 0., float h = 0.) |
1293 | draw_quad (SV *self, float x, float y, float w = 0., float h = 0.) |
… | |
… | |
1354 | } |
1348 | } |
1355 | OUTPUT: |
1349 | OUTPUT: |
1356 | RETVAL |
1350 | RETVAL |
1357 | |
1351 | |
1358 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1352 | MODULE = CFPlus PACKAGE = CFPlus::Map |
|
|
1353 | |
|
|
1354 | PROTOTYPES: DISABLE |
1359 | |
1355 | |
1360 | CFPlus::Map |
1356 | CFPlus::Map |
1361 | new (SV *class) |
1357 | new (SV *class) |
1362 | CODE: |
1358 | CODE: |
1363 | New (0, RETVAL, 1, struct map); |
1359 | New (0, RETVAL, 1, struct map); |
… | |
… | |
1974 | glDisable (GL_BLEND); |
1970 | glDisable (GL_BLEND); |
1975 | glDisable (GL_TEXTURE_2D); |
1971 | glDisable (GL_TEXTURE_2D); |
1976 | } |
1972 | } |
1977 | |
1973 | |
1978 | void |
1974 | void |
1979 | fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh, int smoothing, const char *matrix) |
1975 | fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh) |
1980 | PPCODE: |
1976 | PPCODE: |
1981 | { |
1977 | { |
1982 | int x, y; |
1978 | int x, y; |
|
|
1979 | int sw1 = sw + 2; |
|
|
1980 | int sh1 = sh + 2; |
|
|
1981 | int sh3 = sh * 3; |
1983 | int sw4 = (sw + 3) & ~3; |
1982 | int sw34 = (sw * 3 + 3) & ~3; |
|
|
1983 | uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); |
1984 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
1984 | SV *darkness3_sv = sv_2mortal (newSV (sw34 * sh3)); |
1985 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
1985 | uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); |
1986 | |
1986 | |
1987 | memset (darkness, 255, sw4 * sh); |
|
|
1988 | SvPOK_only (darkness_sv); |
1987 | SvPOK_only (darkness3_sv); |
1989 | SvCUR_set (darkness_sv, sw4 * sh); |
1988 | SvCUR_set (darkness3_sv, sw34 * sh3); |
1990 | |
1989 | |
1991 | mx += self->x; |
1990 | mx += self->x - 1; |
1992 | my += self->y; |
1991 | my += self->y - 1; |
1993 | |
1992 | |
|
|
1993 | memset (darkness1, 255, sw1 * sh1); |
|
|
1994 | |
1994 | for (y = 0; y < sh; y++) |
1995 | for (y = 0; y < sh1; y++) |
1995 | if (0 <= y + my && y + my < self->rows) |
1996 | if (0 <= y + my && y + my < self->rows) |
1996 | { |
1997 | { |
1997 | maprow *row = self->row + (y + my); |
1998 | maprow *row = self->row + (y + my); |
1998 | |
1999 | |
1999 | for (x = 0; x < sw; x++) |
2000 | for (x = 0; x < sw1; x++) |
2000 | if (row->c0 <= x + mx && x + mx < row->c1) |
2001 | if (row->c0 <= x + mx && x + mx < row->c1) |
2001 | { |
2002 | { |
2002 | mapcell *cell = row->col + (x + mx - row->c0); |
2003 | mapcell *cell = row->col + (x + mx - row->c0); |
2003 | |
2004 | |
2004 | darkness[y * sw4 + x] = cell->darkness |
2005 | darkness1 [y * sw1 + x] = cell->darkness |
2005 | ? 255 - (cell->darkness - 1) |
2006 | ? 255 - (cell->darkness - 1) |
2006 | : 255 - FOW_DARKNESS; |
2007 | : 255 - FOW_DARKNESS; |
2007 | } |
2008 | } |
2008 | } |
2009 | } |
2009 | |
2010 | |
2010 | if (smoothing) |
|
|
2011 | { |
|
|
2012 | SV *darkness2_sv = sv_2mortal (newSV (sw4 * sh)); |
|
|
2013 | uint8_t *darkness2 = (uint8_t *)SvPVX (darkness2_sv); |
|
|
2014 | |
|
|
2015 | SvPOK_only (darkness2_sv); |
|
|
2016 | SvCUR_set (darkness2_sv, sw4 * sh); |
|
|
2017 | |
|
|
2018 | for (y = 0; y < sh; ++y) |
2011 | for (y = 0; y < sh; ++y) |
2019 | for (x = 0; x < sw4; ++x) |
2012 | for (x = 0; x < sw; ++x) |
2020 | { |
2013 | { |
2021 | float *f = (float *)matrix; |
2014 | uint8_t d11 = darkness1 [(y ) * sw1 + x ]; |
2022 | int dx, dy; |
2015 | uint8_t d21 = darkness1 [(y ) * sw1 + x + 1]; |
2023 | float sum = 0.f; |
2016 | uint8_t d31 = darkness1 [(y ) * sw1 + x + 2]; |
|
|
2017 | uint8_t d12 = darkness1 [(y + 1) * sw1 + x ]; |
|
|
2018 | uint8_t d22 = darkness1 [(y + 1) * sw1 + x + 1]; |
|
|
2019 | uint8_t d32 = darkness1 [(y + 1) * sw1 + x + 2]; |
|
|
2020 | uint8_t d13 = darkness1 [(y + 2) * sw1 + x ]; |
|
|
2021 | uint8_t d23 = darkness1 [(y + 2) * sw1 + x + 1]; |
|
|
2022 | uint8_t d33 = darkness1 [(y + 2) * sw1 + x + 2]; |
2024 | |
2023 | |
2025 | for (dy = -1; dy <= 1; ++dy) |
2024 | uint8_t r11 = (d11 + d21 + d12) / 3; |
2026 | for (dx = -1; dx <= 1; ++dx) |
2025 | uint8_t r21 = d21; |
2027 | { |
2026 | uint8_t r31 = (d21 + d31 + d32) / 3; |
2028 | unsigned int x2 = x + dx; |
|
|
2029 | unsigned int y2 = y + dy; |
|
|
2030 | |
2027 | |
2031 | sum += (x2 < sw && y2 < sh ? darkness [y2 * sw4 + x2] : 255) * *f++; |
2028 | uint8_t r12 = d12; |
2032 | } |
2029 | uint8_t r22 = d22; |
|
|
2030 | uint8_t r32 = d32; |
2033 | |
2031 | |
2034 | darkness2 [y * sw4 + x] = sum > 255. ? 255. : sum; |
2032 | uint8_t r13 = (d13 + d23 + d12) / 3; |
2035 | } |
2033 | uint8_t r23 = d23; |
|
|
2034 | uint8_t r33 = (d23 + d33 + d32) / 3; |
2036 | |
2035 | |
2037 | darkness_sv = darkness2_sv; |
2036 | darkness3 [(y * 3 ) * sw34 + (x * 3 )] = MAX (d22, r11); |
|
|
2037 | darkness3 [(y * 3 ) * sw34 + (x * 3 + 1)] = MAX (d22, r21); |
|
|
2038 | darkness3 [(y * 3 ) * sw34 + (x * 3 + 2)] = MAX (d22, r31); |
|
|
2039 | darkness3 [(y * 3 + 1) * sw34 + (x * 3 )] = MAX (d22, r12); |
|
|
2040 | darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 1)] = MAX (d22, r22); |
|
|
2041 | darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 2)] = MAX (d22, r32); |
|
|
2042 | darkness3 [(y * 3 + 2) * sw34 + (x * 3 )] = MAX (d22, r13); |
|
|
2043 | darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 1)] = MAX (d22, r23); |
|
|
2044 | darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 2)] = MAX (d22, r33); |
2038 | } |
2045 | } |
|
|
2046 | |
|
|
2047 | free (darkness1); |
2039 | |
2048 | |
2040 | EXTEND (SP, 3); |
2049 | EXTEND (SP, 3); |
2041 | PUSHs (sv_2mortal (newSViv (sw4))); |
2050 | PUSHs (sv_2mortal (newSViv (sw34))); |
2042 | PUSHs (sv_2mortal (newSViv (sh))); |
2051 | PUSHs (sv_2mortal (newSViv (sh3))); |
2043 | PUSHs (darkness_sv); |
2052 | PUSHs (darkness3_sv); |
2044 | } |
2053 | } |
2045 | |
2054 | |
2046 | SV * |
2055 | SV * |
2047 | get_rect (CFPlus::Map self, int x0, int y0, int w, int h) |
2056 | get_rect (CFPlus::Map self, int x0, int y0, int w, int h) |
2048 | CODE: |
2057 | CODE: |
… | |
… | |
2182 | } |
2191 | } |
2183 | } |
2192 | } |
2184 | |
2193 | |
2185 | MODULE = CFPlus PACKAGE = CFPlus::MixChunk |
2194 | MODULE = CFPlus PACKAGE = CFPlus::MixChunk |
2186 | |
2195 | |
|
|
2196 | PROTOTYPES: DISABLE |
|
|
2197 | |
2187 | CFPlus::MixChunk |
2198 | CFPlus::MixChunk |
2188 | new_from_file (SV *class, char *path) |
2199 | new_from_file (SV *class, char *path) |
2189 | CODE: |
2200 | CODE: |
2190 | RETVAL = Mix_LoadWAV (path); |
2201 | RETVAL = Mix_LoadWAV (path); |
2191 | OUTPUT: |
2202 | OUTPUT: |
… | |
… | |
2212 | |
2223 | |
2213 | MODULE = CFPlus PACKAGE = CFPlus::MixMusic |
2224 | MODULE = CFPlus PACKAGE = CFPlus::MixMusic |
2214 | |
2225 | |
2215 | int |
2226 | int |
2216 | volume (int volume = -1) |
2227 | volume (int volume = -1) |
|
|
2228 | PROTOTYPE: ;$ |
2217 | CODE: |
2229 | CODE: |
2218 | RETVAL = Mix_VolumeMusic (volume); |
2230 | RETVAL = Mix_VolumeMusic (volume); |
2219 | OUTPUT: |
2231 | OUTPUT: |
2220 | RETVAL |
2232 | RETVAL |
2221 | |
2233 | |
… | |
… | |
2251 | RETVAL = Mix_FadeInMusicPos (self, loops, ms, position); |
2263 | RETVAL = Mix_FadeInMusicPos (self, loops, ms, position); |
2252 | OUTPUT: |
2264 | OUTPUT: |
2253 | RETVAL |
2265 | RETVAL |
2254 | |
2266 | |
2255 | MODULE = CFPlus PACKAGE = CFPlus::OpenGL |
2267 | MODULE = CFPlus PACKAGE = CFPlus::OpenGL |
|
|
2268 | |
|
|
2269 | PROTOTYPES: ENABLE |
2256 | |
2270 | |
2257 | BOOT: |
2271 | BOOT: |
2258 | { |
2272 | { |
2259 | HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); |
2273 | HV *stash = gv_stashpv ("CFPlus::OpenGL", 1); |
2260 | static const struct { |
2274 | static const struct { |