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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines