… | |
… | |
1960 | glDisable (GL_BLEND); |
1960 | glDisable (GL_BLEND); |
1961 | glDisable (GL_TEXTURE_2D); |
1961 | glDisable (GL_TEXTURE_2D); |
1962 | } |
1962 | } |
1963 | |
1963 | |
1964 | void |
1964 | void |
1965 | fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh, int smoothing, const char *matrix) |
1965 | fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh) |
1966 | PPCODE: |
1966 | PPCODE: |
1967 | { |
1967 | { |
1968 | int x, y; |
1968 | int x, y; |
|
|
1969 | int sw1 = sw + 2; |
|
|
1970 | int sh1 = sh + 2; |
|
|
1971 | int sh3 = sh * 3; |
1969 | int sw4 = (sw + 3) & ~3; |
1972 | int sw34 = (sw * 3 + 3) & ~3; |
|
|
1973 | uint8_t *darkness1 = (uint8_t *)malloc (sw1 * sh1); |
1970 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
1974 | SV *darkness3_sv = sv_2mortal (newSV (sw34 * sh3)); |
1971 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
1975 | uint8_t *darkness3 = (uint8_t *)SvPVX (darkness3_sv); |
1972 | |
1976 | |
1973 | memset (darkness, 255, sw4 * sh); |
|
|
1974 | SvPOK_only (darkness_sv); |
1977 | SvPOK_only (darkness3_sv); |
1975 | SvCUR_set (darkness_sv, sw4 * sh); |
1978 | SvCUR_set (darkness3_sv, sw34 * sh3); |
1976 | |
1979 | |
1977 | mx += self->x; |
1980 | mx += self->x - 1; |
1978 | my += self->y; |
1981 | my += self->y - 1; |
1979 | |
1982 | |
|
|
1983 | memset (darkness1, 255, sw1 * sh1); |
|
|
1984 | |
1980 | for (y = 0; y < sh; y++) |
1985 | for (y = 0; y < sh1; y++) |
1981 | if (0 <= y + my && y + my < self->rows) |
1986 | if (0 <= y + my && y + my < self->rows) |
1982 | { |
1987 | { |
1983 | maprow *row = self->row + (y + my); |
1988 | maprow *row = self->row + (y + my); |
1984 | |
1989 | |
1985 | for (x = 0; x < sw; x++) |
1990 | for (x = 0; x < sw1; x++) |
1986 | if (row->c0 <= x + mx && x + mx < row->c1) |
1991 | if (row->c0 <= x + mx && x + mx < row->c1) |
1987 | { |
1992 | { |
1988 | mapcell *cell = row->col + (x + mx - row->c0); |
1993 | mapcell *cell = row->col + (x + mx - row->c0); |
1989 | |
1994 | |
1990 | darkness[y * sw4 + x] = cell->darkness |
1995 | darkness1 [y * sw1 + x] = cell->darkness |
1991 | ? 255 - (cell->darkness - 1) |
1996 | ? 255 - (cell->darkness - 1) |
1992 | : 255 - FOW_DARKNESS; |
1997 | : 255 - FOW_DARKNESS; |
1993 | } |
1998 | } |
1994 | } |
1999 | } |
1995 | |
2000 | |
1996 | if (smoothing) |
|
|
1997 | { |
|
|
1998 | SV *darkness2_sv = sv_2mortal (newSV (sw4 * sh)); |
|
|
1999 | uint8_t *darkness2 = (uint8_t *)SvPVX (darkness2_sv); |
|
|
2000 | |
|
|
2001 | SvPOK_only (darkness2_sv); |
|
|
2002 | SvCUR_set (darkness2_sv, sw4 * sh); |
|
|
2003 | |
|
|
2004 | for (y = 0; y < sh; ++y) |
2001 | for (y = 0; y < sh; ++y) |
2005 | for (x = 0; x < sw4; ++x) |
2002 | for (x = 0; x < sw; ++x) |
2006 | { |
2003 | { |
2007 | float *f = (float *)matrix; |
2004 | uint8_t d11 = darkness1 [(y ) * sw1 + x ]; |
2008 | int dx, dy; |
2005 | uint8_t d21 = darkness1 [(y ) * sw1 + x + 1]; |
2009 | 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]; |
2010 | |
2013 | |
2011 | for (dy = -1; dy <= 1; ++dy) |
2014 | uint8_t r11 = (d11 + d21 + d12) / 3; |
2012 | for (dx = -1; dx <= 1; ++dx) |
2015 | uint8_t r21 = d21; |
2013 | { |
2016 | uint8_t r31 = (d21 + d31 + d32) / 3; |
2014 | unsigned int x2 = x + dx; |
|
|
2015 | unsigned int y2 = y + dy; |
|
|
2016 | |
2017 | |
2017 | sum += (x2 < sw && y2 < sh ? darkness [y2 * sw4 + x2] : 255) * *f++; |
2018 | uint8_t r12 = d12; |
2018 | } |
2019 | uint8_t r22 = d22; |
|
|
2020 | uint8_t r32 = d32; |
2019 | |
2021 | |
2020 | darkness2 [y * sw4 + x] = sum > 255. ? 255. : sum; |
2022 | uint8_t r13 = (d13 + d23 + d12) / 3; |
2021 | } |
2023 | uint8_t r23 = d23; |
|
|
2024 | uint8_t r33 = (d23 + d33 + d32) / 3; |
2022 | |
2025 | |
2023 | 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); |
2024 | } |
2035 | } |
|
|
2036 | |
|
|
2037 | free (darkness1); |
2025 | |
2038 | |
2026 | EXTEND (SP, 3); |
2039 | EXTEND (SP, 3); |
2027 | PUSHs (sv_2mortal (newSViv (sw4))); |
2040 | PUSHs (sv_2mortal (newSViv (sw34))); |
2028 | PUSHs (sv_2mortal (newSViv (sh))); |
2041 | PUSHs (sv_2mortal (newSViv (sh3))); |
2029 | PUSHs (darkness_sv); |
2042 | PUSHs (darkness3_sv); |
2030 | } |
2043 | } |
2031 | |
2044 | |
2032 | SV * |
2045 | SV * |
2033 | get_rect (CFPlus::Map self, int x0, int y0, int w, int h) |
2046 | get_rect (CFPlus::Map self, int x0, int y0, int w, int h) |
2034 | CODE: |
2047 | CODE: |