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.322 by root, Sun Nov 18 01:43:12 2018 UTC vs.
Revision 1.327 by root, Sun Nov 18 12:01:50 2018 UTC

32#include <cstring> 32#include <cstring>
33#include <cstdio> 33#include <cstdio>
34#include <cstdlib> 34#include <cstdlib>
35 35
36#include <utility> 36#include <utility>
37#include <bitset>
37 38
38#define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW 39#define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW
39 40
40#include <SDL.h> 41#include <SDL.h>
41#include <SDL_thread.h> 42#include <SDL_thread.h>
199 } 200 }
200 201
201 return 0; 202 return 0;
202} 203}
203 204
204typedef struct cf_layout { 205struct cf_layout {
205 PangoLayout *pl; 206 PangoLayout *pl;
206 float r, g, b, a; // default color for rgba mode 207 float r, g, b, a; // default color for rgba mode
207 int base_height; 208 int base_height;
208 DC__Font font; 209 DC__Font font;
209 rc_t *rc; 210 rc_t rc;
210} *DC__Layout; 211};
212
213typedef cf_layout *DC__Layout;
211 214
212static DC__Font default_font; 215static DC__Font default_font;
213static PangoContext *opengl_context; 216static PangoContext *opengl_context;
214static PangoFontMap *opengl_fontmap; 217static PangoFontMap *opengl_fontmap;
215 218
256} 259}
257 260
258typedef uint16_t tileid; 261typedef uint16_t tileid;
259typedef uint16_t faceid; 262typedef uint16_t faceid;
260 263
261typedef struct { 264struct maptex
265{
262 GLuint name; 266 GLuint name;
263 int w, h; 267 int w, h;
264 float s, t; 268 float s, t;
265 uint8_t r, g, b, a; 269 uint8_t r, g, b, a;
266 tileid smoothtile; 270 tileid smoothtile;
267 uint8_t smoothlevel; 271 uint8_t smoothlevel;
268 uint8_t unused; /* set to zero on use */ 272 uint8_t unused; /* set to zero on use */
269} maptex; 273};
270 274
271typedef struct { 275struct mapcell
276{
272 uint32_t player; 277 uint32_t player;
273 tileid tile[3]; 278 tileid tile[3];
274 uint16_t darkness; 279 uint16_t darkness;
275 uint8_t stat_width, stat_hp, flags, smoothmax; 280 uint8_t stat_width, stat_hp, flags, smoothmax;
276} mapcell; 281};
277 282
278typedef struct { 283struct maprow
284{
279 int32_t c0, c1; 285 int32_t c0, c1;
280 mapcell *col; 286 mapcell *col;
281} maprow; 287};
282 288
283typedef struct map { 289struct mapgrid {
284 int x, y, w, h; 290 int x, y, w, h;
285 int ox, oy; /* offset to virtual global coordinate system */ 291 int ox, oy; /* offset to virtual global coordinate system */
286 int faces; tileid *face2tile; // [faceid] 292 std::vector<tileid> tile;
287 int texs; maptex *tex; // [tileid] 293 std::vector<maptex> tex;
288 294
289 int32_t rows; 295 int32_t rows;
290 maprow *row; 296 maprow *row;
291} *DC__Map; 297
298 ~mapgrid ()
299 {
300 clear_cells ();
301 }
302
303 void clear_cells ();
304};
305
306typedef mapgrid *DC__Map;
292 307
293static char * 308static char *
294prepend (char *ptr, int sze, int inc) 309prepend (char *ptr, int sze, int inc)
295{ 310{
296 char *p; 311 char *p;
313} 328}
314 329
315#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) 330#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
316#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) 331#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
317 332
318static void
319need_facenum (struct map *self, faceid face)
320{
321 while (self->faces <= face)
322 {
323 Append (tileid, self->face2tile, self->faces, self->faces);
324 self->faces *= 2;
325 }
326}
327
328static void
329need_texid (struct map *self, int texid)
330{
331 while (self->texs <= texid)
332 {
333 Append (maptex, self->tex, self->texs, self->texs);
334 self->texs *= 2;
335 }
336}
337
338static maprow * 333static maprow *
339map_get_row (DC__Map self, int y) 334map_get_row (mapgrid *self, int y)
340{ 335{
341 if (0 > y) 336 if (0 > y)
342 { 337 {
343 int extend = - y + MAP_EXTEND_Y; 338 int extend = - y + MAP_EXTEND_Y;
344 Prepend (maprow, self->row, self->rows, extend); 339 Prepend (maprow, self->row, self->rows, extend);
382 377
383 return row->col + (x - row->c0); 378 return row->col + (x - row->c0);
384} 379}
385 380
386static mapcell * 381static mapcell *
387map_get_cell (DC__Map self, int x, int y) 382map_get_cell (mapgrid *self, int x, int y)
388{ 383{
389 return row_get_cell (map_get_row (self, y), x); 384 return row_get_cell (map_get_row (self, y), x);
390} 385}
391 386
392static void 387void mapgrid::clear_cells ()
393map_clear (DC__Map self)
394{ 388{
395 int r; 389 int r;
396 390
397 for (r = 0; r < self->rows; r++) 391 for (r = 0; r < rows; r++)
398 Safefree (self->row[r].col); 392 Safefree (row[r].col);
399 393
400 Safefree (self->row); 394 Safefree (row);
401 395
402 self->x = 0; 396 x = 0;
403 self->y = 0; 397 y = 0;
404 self->ox = 0; 398 ox = 0;
405 self->oy = 0; 399 oy = 0;
406 self->row = 0; 400 row = 0;
407 self->rows = 0; 401 rows = 0;
408} 402}
409 403
410#define CELL_CLEAR(cell) \ 404#define CELL_CLEAR(cell) \
411 do { \ 405 do { \
412 if ((cell)->player) \ 406 if ((cell)->player) \
416 (cell)->flags = 0; \ 410 (cell)->flags = 0; \
417 (cell)->player = 0; \ 411 (cell)->player = 0; \
418 } while (0) 412 } while (0)
419 413
420static void 414static void
421map_blank (DC__Map self, int x0, int y0, int w, int h) 415map_blank (mapgrid *self, int x0, int y0, int w, int h)
422{ 416{
423 int x, y; 417 int x, y;
424 maprow *row; 418 maprow *row;
425 mapcell *cell; 419 mapcell *cell;
426 420
1361 tc_restore (); 1355 tc_restore ();
1362 1356
1363DC::Layout 1357DC::Layout
1364new (SV *klass) 1358new (SV *klass)
1365 CODE: 1359 CODE:
1366 New (0, RETVAL, 1, struct cf_layout); 1360 RETVAL = new cf_layout;
1367 1361
1368 RETVAL->pl = pango_layout_new (opengl_context); 1362 RETVAL->pl = pango_layout_new (opengl_context);
1369 RETVAL->r = 1.; 1363 RETVAL->r = 1.;
1370 RETVAL->g = 1.; 1364 RETVAL->g = 1.;
1371 RETVAL->b = 1.; 1365 RETVAL->b = 1.;
1372 RETVAL->a = 1.; 1366 RETVAL->a = 1.;
1373 RETVAL->base_height = MIN_FONT_HEIGHT; 1367 RETVAL->base_height = MIN_FONT_HEIGHT;
1374 RETVAL->font = 0; 1368 RETVAL->font = 0;
1375 RETVAL->rc = rc_alloc ();
1376 1369
1377 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); 1370 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR);
1378 layout_update_font (RETVAL); 1371 layout_update_font (RETVAL);
1379 OUTPUT: 1372 OUTPUT:
1380 RETVAL 1373 RETVAL
1381 1374
1382void 1375void
1383DESTROY (DC::Layout self) 1376DESTROY (DC::Layout self)
1384 CODE: 1377 CODE:
1385 g_object_unref (self->pl); 1378 g_object_unref (self->pl);
1386 rc_free (self->rc);
1387 Safefree (self); 1379 delete self;
1388 1380
1389void 1381void
1390set_text (DC::Layout self, SV *text_) 1382set_text (DC::Layout self, SV *text_)
1391 CODE: 1383 CODE:
1392{ 1384{
1646} 1638}
1647 1639
1648void 1640void
1649render (DC::Layout self, float x, float y, int flags = 0) 1641render (DC::Layout self, float x, float y, int flags = 0)
1650 CODE: 1642 CODE:
1651 rc_clear (self->rc); 1643 self->rc.clear ();
1652 pango_opengl_render_layout_subpixel ( 1644 pango_opengl_render_layout_subpixel (
1653 self->pl, 1645 self->pl,
1654 self->rc, 1646 &self->rc,
1655 x * PANGO_SCALE, y * PANGO_SCALE, 1647 x * PANGO_SCALE, y * PANGO_SCALE,
1656 self->r, self->g, self->b, self->a, 1648 self->r, self->g, self->b, self->a,
1657 flags 1649 flags
1658 ); 1650 );
1659 // we assume that context_change actually clears/frees stuff 1651 // we assume that context_change actually clears/frees stuff
1670 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 1662 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
1671 GL_ONE , GL_ONE_MINUS_SRC_ALPHA); 1663 GL_ONE , GL_ONE_MINUS_SRC_ALPHA);
1672 glEnable (GL_ALPHA_TEST); 1664 glEnable (GL_ALPHA_TEST);
1673 glAlphaFunc (GL_GREATER, 7.f / 255.f); 1665 glAlphaFunc (GL_GREATER, 7.f / 255.f);
1674 1666
1675 rc_draw (self->rc); 1667 self->rc.draw ();
1676 1668
1677 glDisable (GL_ALPHA_TEST); 1669 glDisable (GL_ALPHA_TEST);
1678 glDisable (GL_BLEND); 1670 glDisable (GL_BLEND);
1679 glDisable (GL_TEXTURE_2D); 1671 glDisable (GL_TEXTURE_2D);
1680} 1672}
1894PROTOTYPES: DISABLE 1886PROTOTYPES: DISABLE
1895 1887
1896DC::Map 1888DC::Map
1897new (SV *klass) 1889new (SV *klass)
1898 CODE: 1890 CODE:
1899 New (0, RETVAL, 1, struct map); 1891 RETVAL = new mapgrid;
1900 RETVAL->x = 0; 1892 RETVAL->x = 0;
1901 RETVAL->y = 0; 1893 RETVAL->y = 0;
1902 RETVAL->w = 0; 1894 RETVAL->w = 0;
1903 RETVAL->h = 0; 1895 RETVAL->h = 0;
1904 RETVAL->ox = 0; 1896 RETVAL->ox = 0;
1905 RETVAL->oy = 0; 1897 RETVAL->oy = 0;
1906 RETVAL->faces = 8192; Newz (0, RETVAL->face2tile, RETVAL->faces, tileid);
1907 RETVAL->texs = 8192; Newz (0, RETVAL->tex , RETVAL->texs , maptex);
1908 RETVAL->rows = 0; 1898 RETVAL->rows = 0;
1909 RETVAL->row = 0; 1899 RETVAL->row = 0;
1910 OUTPUT: 1900 OUTPUT:
1911 RETVAL 1901 RETVAL
1912 1902
1913void 1903void
1914DESTROY (DC::Map self) 1904DESTROY (DC::Map self)
1915 CODE: 1905 CODE:
1916{ 1906{
1917 map_clear (self);
1918 Safefree (self->face2tile);
1919 Safefree (self->tex);
1920 Safefree (self); 1907 delete self;
1921} 1908}
1922 1909
1923void 1910void
1924resize (DC::Map self, int map_width, int map_height) 1911resize (DC::Map self, int map_width, int map_height)
1925 CODE: 1912 CODE:
1927 self->h = map_height; 1914 self->h = map_height;
1928 1915
1929void 1916void
1930clear (DC::Map self) 1917clear (DC::Map self)
1931 CODE: 1918 CODE:
1932 map_clear (self); 1919 self->clear_cells ();
1933 1920
1934void 1921void
1935set_tileid (DC::Map self, int face, int tile) 1922set_tileid (DC::Map self, int face, int tile)
1936 CODE: 1923 CODE:
1937{ 1924{
1938 need_facenum (self, face); self->face2tile [face] = tile; 1925 if (self->tile.size () <= face) self->tile.resize (face + 1);
1939 need_texid (self, tile); 1926 self->tile[face] = tile;
1927 if (self->tex.size () <= tile) self->tex .resize (tile + 1);
1940} 1928}
1941 1929
1942void 1930void
1943set_smooth (DC::Map self, int face, int smooth, int level) 1931set_smooth (DC::Map self, int face, int smooth, int level)
1944 CODE: 1932 CODE:
1945{ 1933{
1946 tileid texid;
1947 maptex *tex;
1948
1949 if (face < 0 || face >= self->faces) 1934 if (face < 0 || face >= self->tile.size ())
1950 return; 1935 return;
1951 1936
1952 if (smooth < 0 || smooth >= self->faces) 1937 if (smooth < 0 || smooth >= self->tile.size ())
1953 return; 1938 return;
1954 1939
1955 texid = self->face2tile [face]; 1940 tileid texid = self->tile[face];
1956 1941
1957 if (!texid) 1942 if (!texid)
1958 return; 1943 return;
1959 1944
1960 tex = self->tex + texid; 1945 maptex &tex = self->tex[texid];
1961 tex->smoothtile = self->face2tile [smooth]; 1946 tex.smoothtile = self->tile[smooth];
1962 tex->smoothlevel = level; 1947 tex.smoothlevel = level;
1963} 1948}
1964 1949
1965void 1950void
1966set_texture (DC::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) 1951set_texture (DC::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a)
1967 CODE: 1952 CODE:
1968{ 1953{
1969 need_texid (self, texid); 1954 if (self->tex.size () < texid) self->tex.resize (texid + 1);
1970 1955
1971 { 1956 {
1972 maptex *tex = self->tex + texid; 1957 maptex &tex = self->tex[texid];
1973 1958
1974 tex->name = name; 1959 tex.name = name;
1975 tex->w = w; 1960 tex.w = w;
1976 tex->h = h; 1961 tex.h = h;
1977 tex->s = s; 1962 tex.s = s;
1978 tex->t = t; 1963 tex.t = t;
1979 tex->r = r; 1964 tex.r = r;
1980 tex->g = g; 1965 tex.g = g;
1981 tex->b = b; 1966 tex.b = b;
1982 tex->a = a; 1967 tex.a = a;
1983 } 1968 }
1984 1969
1985 // somewhat hackish, but for textures that require it, it really 1970 // somewhat hackish, but for textures that require it, it really
1986 // improves the look, and most others don't suffer. 1971 // improves the look, and most others don't suffer.
1987 glBindTexture (GL_TEXTURE_2D, name); 1972 glBindTexture (GL_TEXTURE_2D, name);
1993} 1978}
1994 1979
1995void 1980void
1996expire_textures (DC::Map self, int texid, int count) 1981expire_textures (DC::Map self, int texid, int count)
1997 PPCODE: 1982 PPCODE:
1998 for (; texid < self->texs && count; ++texid, --count) 1983 for (; texid < self->tex.size () && count; ++texid, --count)
1999 { 1984 {
2000 maptex *tex = self->tex + texid; 1985 maptex &tex = self->tex[texid];
2001 1986
2002 if (tex->name) 1987 if (tex.name)
2003 { 1988 {
2004 if (tex->unused) 1989 if (tex.unused)
2005 { 1990 {
2006 tex->name = 0; 1991 tex.name = 0;
2007 tex->unused = 0; 1992 tex.unused = 0;
2008 XPUSHs (sv_2mortal (newSViv (texid))); 1993 XPUSHs (sv_2mortal (newSViv (texid)));
2009 } 1994 }
2010 else 1995 else
2011 tex->unused = 1; 1996 tex.unused = 1;
2012 } 1997 }
2013 } 1998 }
2014 1999
2015int 2000int
2016ox (DC::Map self) 2001ox (DC::Map self)
2127 } 2112 }
2128 2113
2129 for (z = 0; z <= 2; ++z) 2114 for (z = 0; z <= 2; ++z)
2130 if (flags & (4 >> z)) 2115 if (flags & (4 >> z))
2131 { 2116 {
2132 faceid face = (data [0] << 8) + data [1]; data += 2; 2117 faceid face = (data[0] << 8) + data[1]; data += 2;
2133 need_facenum (self, face); 2118 if (self->tile.size () <= face) self->tile.resize (face + 1);
2134 cell->tile [z] = self->face2tile [face]; 2119 cell->tile[z] = self->tile[face];
2135 2120
2136 if (cell->tile [z]) 2121 if (cell->tile[z])
2137 { 2122 {
2138 maptex *tex = self->tex + cell->tile [z]; 2123 maptex &tex = self->tex[cell->tile[z]];
2139 tex->unused = 0; 2124 tex.unused = 0;
2140 if (!tex->name) 2125 if (!tex.name)
2141 av_push (missing, newSViv (cell->tile [z])); 2126 av_push (missing, newSViv (cell->tile [z]));
2142 2127
2143 if (tex->smoothtile) 2128 if (tex.smoothtile)
2144 { 2129 {
2145 maptex *smooth = self->tex + tex->smoothtile; 2130 maptex &smooth = self->tex[tex.smoothtile];
2146 smooth->unused = 0; 2131 smooth.unused = 0;
2147 if (!smooth->name) 2132 if (!smooth.name)
2148 av_push (missing, newSViv (tex->smoothtile)); 2133 av_push (missing, newSViv (tex.smoothtile));
2149 } 2134 }
2150 } 2135 }
2151 } 2136 }
2152 } 2137 }
2153 else 2138 else
2216draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) 2201draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0)
2217 CODE: 2202 CODE:
2218{ 2203{
2219 int x, y, z; 2204 int x, y, z;
2220 2205
2221 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level
2222 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) 2206 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k), also, static!
2223 smooth_key skey;
2224 int pl_x, pl_y; 2207 int pl_x, pl_y;
2225 maptex pl_tex; 2208 maptex pl_tex;
2226 rc_t *rc = rc_alloc (); 2209 rc_t rc;
2227 rc_t *rc_ov = rc_alloc (); 2210 rc_t rc_ov;
2228 rc_key_t key; 2211 rc_key_t key;
2229 rc_array_t *arr; 2212 rc_t::array_t *arr;
2230 2213
2231 pl_tex.name = 0; 2214 pl_tex.name = 0;
2232 2215
2233 // that's current max. sorry. 2216 // that's current max. sorry.
2234 if (sw > 255) sw = 255; 2217 if (sw > 255) sw = 255;
2235 if (sh > 255) sh = 255; 2218 if (sh > 255) sh = 255;
2236
2237 // clear key, in case of extra padding
2238 memset (&skey, 0, sizeof (skey));
2239 2219
2240 memset (&key, 0, sizeof (key)); 2220 memset (&key, 0, sizeof (key));
2241 key.r = 255; 2221 key.r = 255;
2242 key.g = 255; 2222 key.g = 255;
2243 key.b = 255; 2223 key.b = 255;
2249 my += self->y; 2229 my += self->y;
2250 2230
2251 // first pass: determine smooth_max 2231 // first pass: determine smooth_max
2252 // rather ugly, if you ask me 2232 // rather ugly, if you ask me
2253 // could also be stored inside mapcell and updated on change 2233 // could also be stored inside mapcell and updated on change
2254 memset (smooth_max, 0, sizeof (smooth_max)); 2234 memset (smooth_max, 0, sizeof (smooth_max[0]) * (sh + 1));
2255 2235
2256 for (y = 0; y < sh; y++) 2236 for (y = 0; y < sh; y++)
2257 if (0 <= y + my && y + my < self->rows) 2237 if (0 <= y + my && y + my < self->rows)
2258 { 2238 {
2259 maprow *row = self->row + (y + my); 2239 maprow *row = self->row + (y + my);
2274 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2254 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2275 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2255 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
2276 2256
2277 for (z = 0; z <= 2; z++) 2257 for (z = 0; z <= 2; z++)
2278 { 2258 {
2259 std::bitset<256> smooth_level; // one bit for every possible smooth level
2260 smooth_key skey;
2279 smooth_hash smooth; 2261 smooth_hash smooth;
2280 memset (smooth_level, 0, sizeof (smooth_level));
2281 key.texname = -1; 2262 key.texname = -1;
2282 2263
2283 for (y = 0; y < sh; y++) 2264 for (y = 0; y < sh; y++)
2284 if (0 <= y + my && y + my < self->rows) 2265 if (0 <= y + my && y + my < self->rows)
2285 { 2266 {
2302 2283
2303 if (!tex.name) 2284 if (!tex.name)
2304 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ 2285 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */
2305 2286
2306 key.texname = tex.name; 2287 key.texname = tex.name;
2307 arr = rc_array (rc, &key); 2288 arr = &rc.array (key);
2308 } 2289 }
2309 2290
2310 px = (x + 1) * Th - tex.w; 2291 px = (x + 1) * Th - tex.w;
2311 py = (y + 1) * Tw - tex.h; 2292 py = (y + 1) * Tw - tex.h;
2312 2293
2316 pl_y = py; 2297 pl_y = py;
2317 pl_tex = tex; 2298 pl_tex = tex;
2318 continue; 2299 continue;
2319 } 2300 }
2320 2301
2321 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2302 arr->t2f_v3f (0 , 0 , px , py , 0);
2322 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2303 arr->t2f_v3f (0 , tex.t, px , py + tex.h, 0);
2323 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); 2304 arr->t2f_v3f (tex.s, tex.t, px + tex.w, py + tex.h, 0);
2324 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); 2305 arr->t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2325 2306
2326 // update smooth hash 2307 // update smooth hash
2327 if (tex.smoothtile) 2308 if (tex.smoothtile)
2328 { 2309 {
2329 skey.tile = tex.smoothtile; 2310 skey.tile = tex.smoothtile;
2330 skey.level = tex.smoothlevel; 2311 skey.level = tex.smoothlevel;
2331 2312
2332 smooth_level [tex.smoothlevel >> 5] |= ((uint32_t)1) << (tex.smoothlevel & 31); 2313 smooth_level[tex.smoothlevel] = 1;
2333 2314
2334 // add bits to current tile and all neighbours. skey.x|y is 2315 // add bits to current tile and all neighbours. skey.x|y is
2335 // shifted +1|+1 so we always stay positive. 2316 // shifted +1|+1 so we always stay positive.
2336 2317
2337 // bits is ___n cccc CCCC bbbb 2318 // bits is ___n cccc CCCC bbbb
2367 { 2348 {
2368 // overlays such as the speech bubble, probably more to come 2349 // overlays such as the speech bubble, probably more to come
2369 if (cell->flags & 1) 2350 if (cell->flags & 1)
2370 { 2351 {
2371 rc_key_t key_ov = key; 2352 rc_key_t key_ov = key;
2372 maptex tex = self->tex [TEXID_SPEECH]; 2353 maptex tex = self->tex[TEXID_SPEECH];
2373 rc_array_t *arr;
2374 int px = x * Tw + Tw * 2 / 32; 2354 int px = x * Tw + Tw * 2 / 32;
2375 int py = y * Th - Th * 6 / 32; 2355 int py = y * Th - Th * 6 / 32;
2376 2356
2377 key_ov.texname = tex.name; 2357 key_ov.texname = tex.name;
2378 arr = rc_array (rc_ov, &key_ov); 2358 rc_t::array_t &arr = rc_ov.array (key_ov);
2379 2359
2380 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2360 arr.t2f_v3f (0 , 0 , px , py , 0);
2381 rc_t2f_v3f (arr, 0 , tex.t, px , py + Th, 0); 2361 arr.t2f_v3f (0 , tex.t, px , py + Th, 0);
2382 rc_t2f_v3f (arr, tex.s, tex.t, px + Tw, py + Th, 0); 2362 arr.t2f_v3f (tex.s, tex.t, px + Tw, py + Th, 0);
2383 rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0); 2363 arr.t2f_v3f (tex.s, 0 , px + Tw, py , 0);
2384 } 2364 }
2385 } 2365 }
2386 } 2366 }
2387 } 2367 }
2388 2368
2389 rc_draw (rc); 2369 rc.draw ();
2390 rc_clear (rc); 2370 rc.clear ();
2391 2371
2392 // go through all smoothlevels, lowest to highest, then draw. 2372 // go through all smoothlevels, lowest to highest, then draw.
2393 // this is basically counting sort 2373 // this is basically counting sort
2394 { 2374 {
2395 int w, b; 2375 int w, b;
2396 2376
2397 glEnable (GL_TEXTURE_2D); 2377 glEnable (GL_TEXTURE_2D);
2398 glBegin (GL_QUADS); 2378 glBegin (GL_QUADS);
2399 for (w = 0; w < 256 / 32; ++w) 2379 for (int level = 0; level < smooth_level.size (); ++level)
2380 if (smooth_level[level])
2381 for (auto &&it = smooth.begin (); it != smooth.end (); ++it)
2400 { 2382 {
2401 uint32_t smask = smooth_level [w]; 2383 smooth_key &skey = it->first;
2402 if (smask) 2384 IV bits = it->second;
2403 for (b = 0; b < 32; ++b) 2385
2404 if (smask & (((uint32_t)1) << b)) 2386 if (!(bits & 0x1000)
2387 && skey.level == level
2388 && level > smooth_max [skey.x][skey.y])
2405 { 2389 {
2406 int level = (w << 5) | b; 2390 maptex tex = self->tex [skey.tile];
2391 int px = (((int)skey.x) - 1) * Tw;
2392 int py = (((int)skey.y) - 1) * Th;
2393 int border = bits & 15;
2394 int corner = (bits >> 8) & ~(bits >> 4) & 15;
2395 float dx = tex.s * .0625f; // 16 images/row
2396 float dy = tex.t * .5f ; // 2 images/column
2397
2407 HE *he; 2398 if (tex.name)
2408
2409 for (auto &&it = smooth.begin (); it != smooth.end (); ++it)
2410 { 2399 {
2411 smooth_key &skey = it->first; 2400 // this time avoiding texture state changes
2412 IV bits = it->second; 2401 // save gobs of state changes.
2413 2402 if (key.texname != tex.name)
2414 if (!(bits & 0x1000)
2415 && skey.level == level
2416 && level > smooth_max [skey.x][skey.y])
2417 { 2403 {
2418 maptex tex = self->tex [skey.tile];
2419 int px = (((int)skey.x) - 1) * Tw;
2420 int py = (((int)skey.y) - 1) * Th;
2421 int border = bits & 15;
2422 int corner = (bits >> 8) & ~(bits >> 4) & 15;
2423 float dx = tex.s * .0625f; // 16 images/row
2424 float dy = tex.t * .5f ; // 2 images/column
2425
2426 if (tex.name)
2427 {
2428 // this time avoiding texture state changes
2429 // save gobs of state changes.
2430 if (key.texname != tex.name)
2431 {
2432 self->tex [skey.tile].unused = 0; 2404 self->tex [skey.tile].unused = 0;
2433 2405
2434 glEnd (); 2406 glEnd ();
2435 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); 2407 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
2436 glBegin (GL_QUADS); 2408 glBegin (GL_QUADS);
2437 } 2409 }
2438 2410
2439 if (border) 2411 if (border)
2440 { 2412 {
2441 float ox = border * dx; 2413 float ox = border * dx;
2442 2414
2443 glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); 2415 glTexCoord2f (ox , 0.f ); glVertex2i (px , py );
2444 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); 2416 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th);
2445 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); 2417 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th);
2446 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); 2418 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py );
2447 } 2419 }
2448 2420
2449 if (corner) 2421 if (corner)
2450 { 2422 {
2451 float ox = corner * dx; 2423 float ox = corner * dx;
2452 2424
2453 glTexCoord2f (ox , dy ); glVertex2i (px , py ); 2425 glTexCoord2f (ox , dy ); glVertex2i (px , py );
2454 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); 2426 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th);
2455 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); 2427 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th);
2456 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); 2428 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py );
2457 }
2458 }
2459 } 2429 }
2460 } 2430 }
2461 } 2431 }
2462 } 2432 }
2463 2433
2464 glEnd (); 2434 glEnd ();
2465 glDisable (GL_TEXTURE_2D); 2435 glDisable (GL_TEXTURE_2D);
2466 key.texname = -1; 2436 key.texname = -1;
2467 } 2437 }
2472 maptex tex = pl_tex; 2442 maptex tex = pl_tex;
2473 int px = pl_x + sdx; 2443 int px = pl_x + sdx;
2474 int py = pl_y + sdy; 2444 int py = pl_y + sdy;
2475 2445
2476 key.texname = tex.name; 2446 key.texname = tex.name;
2477 arr = rc_array (rc, &key); 2447 rc_t::array_t &arr = rc.array (key);
2478 2448
2479 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2449 arr.t2f_v3f (0 , 0 , px , py , 0);
2480 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2450 arr.t2f_v3f (0 , tex.t, px , py + tex.h, 0);
2481 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); 2451 arr.t2f_v3f (tex.s, tex.t, px + tex.w, py + tex.h, 0);
2482 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); 2452 arr.t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2483 2453
2484 rc_draw (rc); 2454 rc.draw ();
2485 } 2455 }
2486 2456
2487 rc_draw (rc_ov); 2457 rc_ov.draw ();
2488 rc_clear (rc_ov); 2458 rc_ov.clear ();
2489 2459
2490 glDisable (GL_BLEND); 2460 glDisable (GL_BLEND);
2491 rc_free (rc);
2492 rc_free (rc_ov);
2493 2461
2494 // top layer: overlays such as the health bar 2462 // top layer: overlays such as the health bar
2495 for (y = 0; y < sh; y++) 2463 for (y = 0; y < sh; y++)
2496 if (0 <= y + my && y + my < self->rows) 2464 if (0 <= y + my && y + my < self->rows)
2497 { 2465 {
2819 2787
2820 for (z = 0; z <= 2; z++) 2788 for (z = 0; z <= 2; z++)
2821 { 2789 {
2822 tileid t = tile [z]; 2790 tileid t = tile [z];
2823 2791
2824 if (t >= self->texs || (t && !self->tex [t].name)) 2792 if (t >= self->tex.size () || (t && !self->tex[t].name))
2825 { 2793 {
2826 PUSHs (sv_2mortal (newSViv (t))); 2794 PUSHs (sv_2mortal (newSViv (t)));
2827 need_texid (self, t); 2795 if (self->tex.size () <= t) self->tex.resize (t + 1);
2828 } 2796 }
2829 2797
2830 cell->tile [z] = t; 2798 cell->tile[z] = t;
2831 } 2799 }
2832 } 2800 }
2833 } 2801 }
2834 } 2802 }
2835 } 2803 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines