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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines