ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/Client.xs
(Generate patch)

Comparing deliantra/Deliantra-Client/Client.xs (file contents):
Revision 1.201 by root, Tue Jul 17 17:39:06 2007 UTC vs.
Revision 1.204 by root, Thu Jul 19 14:54:50 2007 UTC

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
1257MODULE = CFPlus PACKAGE = CFPlus::Texture 1258MODULE = CFPlus PACKAGE = CFPlus::Texture
1258 1259
1259int minpot (int n) 1260int minpot (int n)
1260 1261
1261void 1262void
1262pad2pot (SV *data_, SV *w_, SV *h_) 1263pad (SV *data_, int ow, int oh, int nw, int nh)
1263 CODE: 1264 CODE:
1264{ 1265{
1265 int ow = SvIV (w_); 1266 if ((nw != ow || nh != oh) && SvOK (data_))
1266 int oh = SvIV (h_);
1267
1268 if (ow && oh)
1269 { 1267 {
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; 1268 STRLEN datalen;
1278 char *data = SvPVbyte (data_, datalen); 1269 char *data = SvPVbyte (data_, datalen);
1279 int bpp = datalen / (ow * oh); 1270 int bpp = datalen / (ow * oh);
1280 SV *result_ = sv_2mortal (newSV (nw * nh * bpp)); 1271 SV *result_ = sv_2mortal (newSV (nw * nh * bpp));
1281 1272
1282 SvPOK_only (result_); 1273 SvPOK_only (result_);
1283 SvCUR_set (result_, nw * nh * bpp); 1274 SvCUR_set (result_, nw * nh * bpp);
1284 1275
1285 memset (SvPVX (result_), 0, nw * nh * bpp); 1276 memset (SvPVX (result_), 0, nw * nh * bpp);
1286 while (oh--) 1277 while (oh--)
1287 memcpy (SvPVX (result_) + oh * nw * bpp, data + oh * ow * bpp, ow * bpp); 1278 memcpy (SvPVX (result_) + oh * nw * bpp, data + oh * ow * bpp, ow * bpp);
1288 1279
1289 sv_setsv (data_, result_); 1280 sv_setsv (data_, result_);
1290 }
1291
1292 sv_setiv (w_, nw);
1293 sv_setiv (h_, nh);
1294 }
1295 } 1281 }
1296} 1282}
1297 1283
1298void 1284void
1299draw_quad (SV *self, float x, float y, float w = 0., float h = 0.) 1285draw_quad (SV *self, float x, float y, float w = 0., float h = 0.)
1974 glDisable (GL_BLEND); 1960 glDisable (GL_BLEND);
1975 glDisable (GL_TEXTURE_2D); 1961 glDisable (GL_TEXTURE_2D);
1976} 1962}
1977 1963
1978void 1964void
1979fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh, int smoothing, const char *matrix) 1965fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh)
1980 PPCODE: 1966 PPCODE:
1981{ 1967{
1982 int x, y; 1968 int x, y;
1969 int sw1 = sw + 2;
1970 int sh1 = sh + 2;
1971 int sh3 = sh * 3;
1983 int sw4 = (sw + 3) & ~3; 1972 int sw34 = (sw * 3 + 3) & ~3;
1973 uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1);
1984 SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); 1974 SV *darkness3_sv = sv_2mortal (newSV (sw34 * sh3));
1985 uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); 1975 uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv);
1986 1976
1987 memset (darkness, 255, sw4 * sh);
1988 SvPOK_only (darkness_sv); 1977 SvPOK_only (darkness3_sv);
1989 SvCUR_set (darkness_sv, sw4 * sh); 1978 SvCUR_set (darkness3_sv, sw34 * sh3);
1990 1979
1991 mx += self->x; 1980 mx += self->x - 1;
1992 my += self->y; 1981 my += self->y - 1;
1993 1982
1983 memset (darkness1, 255, sw1 * sh1);
1984
1994 for (y = 0; y < sh; y++) 1985 for (y = 0; y < sh1; y++)
1995 if (0 <= y + my && y + my < self->rows) 1986 if (0 <= y + my && y + my < self->rows)
1996 { 1987 {
1997 maprow *row = self->row + (y + my); 1988 maprow *row = self->row + (y + my);
1998 1989
1999 for (x = 0; x < sw; x++) 1990 for (x = 0; x < sw1; x++)
2000 if (row->c0 <= x + mx && x + mx < row->c1) 1991 if (row->c0 <= x + mx && x + mx < row->c1)
2001 { 1992 {
2002 mapcell *cell = row->col + (x + mx - row->c0); 1993 mapcell *cell = row->col + (x + mx - row->c0);
2003 1994
2004 darkness[y * sw4 + x] = cell->darkness 1995 darkness1 [y * sw1 + x] = cell->darkness
2005 ? 255 - (cell->darkness - 1) 1996 ? 255 - (cell->darkness - 1)
2006 : 255 - FOW_DARKNESS; 1997 : 255 - FOW_DARKNESS;
2007 } 1998 }
2008 } 1999 }
2009 2000
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) 2001 for (y = 0; y < sh; ++y)
2019 for (x = 0; x < sw4; ++x) 2002 for (x = 0; x < sw; ++x)
2020 { 2003 {
2021 float *f = (float *)matrix; 2004 uint8_t d11 = darkness1 [(y ) * sw1 + x ];
2022 int dx, dy; 2005 uint8_t d21 = darkness1 [(y ) * sw1 + x + 1];
2023 float sum = 0.f; 2006 uint8_t d31 = darkness1 [(y ) * sw1 + x + 2];
2007 uint8_t d12 = darkness1 [(y + 1) * sw1 + x ];
2008 uint8_t d22 = darkness1 [(y + 1) * sw1 + x + 1];
2009 uint8_t d32 = darkness1 [(y + 1) * sw1 + x + 2];
2010 uint8_t d13 = darkness1 [(y + 2) * sw1 + x ];
2011 uint8_t d23 = darkness1 [(y + 2) * sw1 + x + 1];
2012 uint8_t d33 = darkness1 [(y + 2) * sw1 + x + 2];
2024 2013
2025 for (dy = -1; dy <= 1; ++dy) 2014 uint8_t r11 = (d11 + d21 + d12) / 3;
2026 for (dx = -1; dx <= 1; ++dx) 2015 uint8_t r21 = d21;
2027 { 2016 uint8_t r31 = (d21 + d31 + d32) / 3;
2028 unsigned int x2 = x + dx;
2029 unsigned int y2 = y + dy;
2030 2017
2031 sum += (x2 < sw && y2 < sh ? darkness [y2 * sw4 + x2] : 255) * *f++; 2018 uint8_t r12 = d12;
2032 } 2019 uint8_t r22 = d22;
2020 uint8_t r32 = d32;
2033 2021
2034 darkness2 [y * sw4 + x] = sum > 255. ? 255. : sum; 2022 uint8_t r13 = (d13 + d23 + d12) / 3;
2035 } 2023 uint8_t r23 = d23;
2024 uint8_t r33 = (d23 + d33 + d32) / 3;
2036 2025
2037 darkness_sv = darkness2_sv; 2026 darkness3 [(y * 3 ) * sw34 + (x * 3 )] = MAX (d22, r11);
2027 darkness3 [(y * 3 ) * sw34 + (x * 3 + 1)] = MAX (d22, r21);
2028 darkness3 [(y * 3 ) * sw34 + (x * 3 + 2)] = MAX (d22, r31);
2029 darkness3 [(y * 3 + 1) * sw34 + (x * 3 )] = MAX (d22, r12);
2030 darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 1)] = MAX (d22, r22);
2031 darkness3 [(y * 3 + 1) * sw34 + (x * 3 + 2)] = MAX (d22, r32);
2032 darkness3 [(y * 3 + 2) * sw34 + (x * 3 )] = MAX (d22, r13);
2033 darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 1)] = MAX (d22, r23);
2034 darkness3 [(y * 3 + 2) * sw34 + (x * 3 + 2)] = MAX (d22, r33);
2038 } 2035 }
2036
2037 free (darkness1);
2039 2038
2040 EXTEND (SP, 3); 2039 EXTEND (SP, 3);
2041 PUSHs (sv_2mortal (newSViv (sw4))); 2040 PUSHs (sv_2mortal (newSViv (sw34)));
2042 PUSHs (sv_2mortal (newSViv (sh))); 2041 PUSHs (sv_2mortal (newSViv (sh3)));
2043 PUSHs (darkness_sv); 2042 PUSHs (darkness3_sv);
2044} 2043}
2045 2044
2046SV * 2045SV *
2047get_rect (CFPlus::Map self, int x0, int y0, int w, int h) 2046get_rect (CFPlus::Map self, int x0, int y0, int w, int h)
2048 CODE: 2047 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines