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.329 by root, Sun Nov 18 13:07:51 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 int faces; tileid *face2tile; // [faceid]
287 int texs; maptex *tex; // [tileid] 293 int texs; maptex *tex; // [tileid]
288 294
289 int32_t rows; 295 int32_t rows;
290 maprow *row; 296 maprow *row;
291} *DC__Map; 297};
292 298
293static char * 299typedef mapgrid *DC__Map;
300
301template<typename T>
302static void
294prepend (char *ptr, int sze, int inc) 303prepend (T *&ptr, int sze, int inc)
295{ 304{
296 char *p; 305 T *p;
297 306
298 New (0, p, sze + inc, char); 307 New (0, p, sze + inc, T);
299 Zero (p, inc, char); 308 Zero (p, inc, T);
300 Move (ptr, p + inc, sze, char); 309 Move (ptr, p + inc, sze, T);
301 Safefree (ptr); 310 Safefree (ptr);
302 311
303 return p; 312 ptr = p;
304} 313}
305 314
306static char * 315template<typename T>
307append (char *ptr, int sze, int inc)
308{
309 Renew (ptr, sze + inc, char);
310 Zero (ptr + sze, inc, char);
311
312 return ptr;
313}
314
315#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))
317
318static void 316static void
317append (T *&ptr, int sze, int inc)
318{
319 Renew (ptr, sze + inc, T);
320 Zero (ptr + sze, inc, T);
321}
322
323static void
319need_facenum (struct map *self, faceid face) 324need_facenum (struct mapgrid *self, faceid face)
320{ 325{
321 while (self->faces <= face) 326 while (self->faces <= face)
322 { 327 {
323 Append (tileid, self->face2tile, self->faces, self->faces); 328 append (self->face2tile, self->faces, self->faces);
324 self->faces *= 2; 329 self->faces *= 2;
325 } 330 }
326} 331}
327 332
328static void 333static void
329need_texid (struct map *self, int texid) 334need_texid (struct mapgrid *self, int texid)
330{ 335{
331 while (self->texs <= texid) 336 while (self->texs <= texid)
332 { 337 {
333 Append (maptex, self->tex, self->texs, self->texs); 338 append (self->tex, self->texs, self->texs);
334 self->texs *= 2; 339 self->texs *= 2;
335 } 340 }
336} 341}
337 342
338static maprow * 343static maprow *
339map_get_row (DC__Map self, int y) 344map_get_row (mapgrid *self, int y)
340{ 345{
341 if (0 > y) 346 if (0 > y)
342 { 347 {
343 int extend = - y + MAP_EXTEND_Y; 348 int extend = - y + MAP_EXTEND_Y;
344 Prepend (maprow, self->row, self->rows, extend); 349 prepend (self->row, self->rows, extend);
345 350
346 self->rows += extend; 351 self->rows += extend;
347 self->y += extend; 352 self->y += extend;
348 y += extend; 353 y += extend;
349 } 354 }
350 else if (y >= self->rows) 355 else if (y >= self->rows)
351 { 356 {
352 int extend = y - self->rows + MAP_EXTEND_Y; 357 int extend = y - self->rows + MAP_EXTEND_Y;
353 Append (maprow, self->row, self->rows, extend); 358 append (self->row, self->rows, extend);
354 self->rows += extend; 359 self->rows += extend;
355 } 360 }
356 361
357 return self->row + y; 362 return self->row + y;
358} 363}
368 } 373 }
369 374
370 if (row->c0 > x) 375 if (row->c0 > x)
371 { 376 {
372 int extend = row->c0 - x + MAP_EXTEND_X; 377 int extend = row->c0 - x + MAP_EXTEND_X;
373 Prepend (mapcell, row->col, row->c1 - row->c0, extend); 378 prepend (row->col, row->c1 - row->c0, extend);
374 row->c0 -= extend; 379 row->c0 -= extend;
375 } 380 }
376 else if (x >= row->c1) 381 else if (x >= row->c1)
377 { 382 {
378 int extend = x - row->c1 + MAP_EXTEND_X; 383 int extend = x - row->c1 + MAP_EXTEND_X;
379 Append (mapcell, row->col, row->c1 - row->c0, extend); 384 append (row->col, row->c1 - row->c0, extend);
380 row->c1 += extend; 385 row->c1 += extend;
381 } 386 }
382 387
383 return row->col + (x - row->c0); 388 return row->col + (x - row->c0);
384} 389}
385 390
386static mapcell * 391static mapcell *
387map_get_cell (DC__Map self, int x, int y) 392map_get_cell (mapgrid *self, int x, int y)
388{ 393{
389 return row_get_cell (map_get_row (self, y), x); 394 return row_get_cell (map_get_row (self, y), x);
390} 395}
391 396
392static void 397static void
393map_clear (DC__Map self) 398map_clear (mapgrid *self)
394{ 399{
395 int r; 400 int r;
396 401
397 for (r = 0; r < self->rows; r++) 402 for (r = 0; r < self->rows; r++)
398 Safefree (self->row[r].col); 403 Safefree (self->row[r].col);
416 (cell)->flags = 0; \ 421 (cell)->flags = 0; \
417 (cell)->player = 0; \ 422 (cell)->player = 0; \
418 } while (0) 423 } while (0)
419 424
420static void 425static void
421map_blank (DC__Map self, int x0, int y0, int w, int h) 426map_blank (mapgrid *self, int x0, int y0, int w, int h)
422{ 427{
423 int x, y; 428 int x, y;
424 maprow *row; 429 maprow *row;
425 mapcell *cell; 430 mapcell *cell;
426 431
1361 tc_restore (); 1366 tc_restore ();
1362 1367
1363DC::Layout 1368DC::Layout
1364new (SV *klass) 1369new (SV *klass)
1365 CODE: 1370 CODE:
1366 New (0, RETVAL, 1, struct cf_layout); 1371 RETVAL = new cf_layout;
1367 1372
1368 RETVAL->pl = pango_layout_new (opengl_context); 1373 RETVAL->pl = pango_layout_new (opengl_context);
1369 RETVAL->r = 1.; 1374 RETVAL->r = 1.;
1370 RETVAL->g = 1.; 1375 RETVAL->g = 1.;
1371 RETVAL->b = 1.; 1376 RETVAL->b = 1.;
1372 RETVAL->a = 1.; 1377 RETVAL->a = 1.;
1373 RETVAL->base_height = MIN_FONT_HEIGHT; 1378 RETVAL->base_height = MIN_FONT_HEIGHT;
1374 RETVAL->font = 0; 1379 RETVAL->font = 0;
1375 RETVAL->rc = rc_alloc ();
1376 1380
1377 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); 1381 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR);
1378 layout_update_font (RETVAL); 1382 layout_update_font (RETVAL);
1379 OUTPUT: 1383 OUTPUT:
1380 RETVAL 1384 RETVAL
1381 1385
1382void 1386void
1383DESTROY (DC::Layout self) 1387DESTROY (DC::Layout self)
1384 CODE: 1388 CODE:
1385 g_object_unref (self->pl); 1389 g_object_unref (self->pl);
1386 rc_free (self->rc);
1387 Safefree (self); 1390 delete self;
1388 1391
1389void 1392void
1390set_text (DC::Layout self, SV *text_) 1393set_text (DC::Layout self, SV *text_)
1391 CODE: 1394 CODE:
1392{ 1395{
1646} 1649}
1647 1650
1648void 1651void
1649render (DC::Layout self, float x, float y, int flags = 0) 1652render (DC::Layout self, float x, float y, int flags = 0)
1650 CODE: 1653 CODE:
1651 rc_clear (self->rc); 1654 self->rc.clear ();
1652 pango_opengl_render_layout_subpixel ( 1655 pango_opengl_render_layout_subpixel (
1653 self->pl, 1656 self->pl,
1654 self->rc, 1657 &self->rc,
1655 x * PANGO_SCALE, y * PANGO_SCALE, 1658 x * PANGO_SCALE, y * PANGO_SCALE,
1656 self->r, self->g, self->b, self->a, 1659 self->r, self->g, self->b, self->a,
1657 flags 1660 flags
1658 ); 1661 );
1659 // we assume that context_change actually clears/frees stuff 1662 // we assume that context_change actually clears/frees stuff
1670 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 1673 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
1671 GL_ONE , GL_ONE_MINUS_SRC_ALPHA); 1674 GL_ONE , GL_ONE_MINUS_SRC_ALPHA);
1672 glEnable (GL_ALPHA_TEST); 1675 glEnable (GL_ALPHA_TEST);
1673 glAlphaFunc (GL_GREATER, 7.f / 255.f); 1676 glAlphaFunc (GL_GREATER, 7.f / 255.f);
1674 1677
1675 rc_draw (self->rc); 1678 self->rc.draw ();
1676 1679
1677 glDisable (GL_ALPHA_TEST); 1680 glDisable (GL_ALPHA_TEST);
1678 glDisable (GL_BLEND); 1681 glDisable (GL_BLEND);
1679 glDisable (GL_TEXTURE_2D); 1682 glDisable (GL_TEXTURE_2D);
1680} 1683}
1894PROTOTYPES: DISABLE 1897PROTOTYPES: DISABLE
1895 1898
1896DC::Map 1899DC::Map
1897new (SV *klass) 1900new (SV *klass)
1898 CODE: 1901 CODE:
1899 New (0, RETVAL, 1, struct map); 1902 New (0, RETVAL, 1, mapgrid);
1900 RETVAL->x = 0; 1903 RETVAL->x = 0;
1901 RETVAL->y = 0; 1904 RETVAL->y = 0;
1902 RETVAL->w = 0; 1905 RETVAL->w = 0;
1903 RETVAL->h = 0; 1906 RETVAL->h = 0;
1904 RETVAL->ox = 0; 1907 RETVAL->ox = 0;
2050 self->ox += dx; self->x += dx; 2053 self->ox += dx; self->x += dx;
2051 self->oy += dy; self->y += dy; 2054 self->oy += dy; self->y += dy;
2052 2055
2053 while (self->y < 0) 2056 while (self->y < 0)
2054 { 2057 {
2055 Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); 2058 prepend (self->row, self->rows, MAP_EXTEND_Y);
2056 2059
2057 self->rows += MAP_EXTEND_Y; 2060 self->rows += MAP_EXTEND_Y;
2058 self->y += MAP_EXTEND_Y; 2061 self->y += MAP_EXTEND_Y;
2059 } 2062 }
2060} 2063}
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) 2219draw (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: 2220 CODE:
2218{ 2221{
2219 int x, y, z; 2222 int x, y, z;
2220 2223
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) 2224 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; 2225 int pl_x, pl_y;
2225 maptex pl_tex; 2226 maptex pl_tex;
2226 rc_t *rc = rc_alloc (); 2227 rc_t rc;
2227 rc_t *rc_ov = rc_alloc (); 2228 rc_t rc_ov;
2228 rc_key_t key; 2229 rc_key_t key;
2229 rc_array_t *arr; 2230 rc_t::array_t *arr;
2230 2231
2231 pl_tex.name = 0; 2232 pl_tex.name = 0;
2232 2233
2233 // that's current max. sorry. 2234 // that's current max. sorry.
2234 if (sw > 255) sw = 255; 2235 if (sw > 255) sw = 255;
2235 if (sh > 255) sh = 255; 2236 if (sh > 255) sh = 255;
2236
2237 // clear key, in case of extra padding
2238 memset (&skey, 0, sizeof (skey));
2239 2237
2240 memset (&key, 0, sizeof (key)); 2238 memset (&key, 0, sizeof (key));
2241 key.r = 255; 2239 key.r = 255;
2242 key.g = 255; 2240 key.g = 255;
2243 key.b = 255; 2241 key.b = 255;
2249 my += self->y; 2247 my += self->y;
2250 2248
2251 // first pass: determine smooth_max 2249 // first pass: determine smooth_max
2252 // rather ugly, if you ask me 2250 // rather ugly, if you ask me
2253 // could also be stored inside mapcell and updated on change 2251 // could also be stored inside mapcell and updated on change
2254 memset (smooth_max, 0, sizeof (smooth_max)); 2252 memset (smooth_max, 0, sizeof (smooth_max[0]) * (sh + 1));
2255 2253
2256 for (y = 0; y < sh; y++) 2254 for (y = 0; y < sh; y++)
2257 if (0 <= y + my && y + my < self->rows) 2255 if (0 <= y + my && y + my < self->rows)
2258 { 2256 {
2259 maprow *row = self->row + (y + my); 2257 maprow *row = self->row + (y + my);
2274 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2272 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2275 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2273 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
2276 2274
2277 for (z = 0; z <= 2; z++) 2275 for (z = 0; z <= 2; z++)
2278 { 2276 {
2277 std::bitset<256> smooth_level; // one bit for every possible smooth level
2278 smooth_key skey;
2279 smooth_hash smooth; 2279 smooth_hash smooth;
2280 memset (smooth_level, 0, sizeof (smooth_level));
2281 key.texname = -1; 2280 key.texname = -1;
2282 2281
2283 for (y = 0; y < sh; y++) 2282 for (y = 0; y < sh; y++)
2284 if (0 <= y + my && y + my < self->rows) 2283 if (0 <= y + my && y + my < self->rows)
2285 { 2284 {
2302 2301
2303 if (!tex.name) 2302 if (!tex.name)
2304 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ 2303 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */
2305 2304
2306 key.texname = tex.name; 2305 key.texname = tex.name;
2307 arr = rc_array (rc, &key); 2306 arr = &rc.array (key);
2308 } 2307 }
2309 2308
2310 px = (x + 1) * Th - tex.w; 2309 px = (x + 1) * Th - tex.w;
2311 py = (y + 1) * Tw - tex.h; 2310 py = (y + 1) * Tw - tex.h;
2312 2311
2316 pl_y = py; 2315 pl_y = py;
2317 pl_tex = tex; 2316 pl_tex = tex;
2318 continue; 2317 continue;
2319 } 2318 }
2320 2319
2321 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2320 arr->t2f_v3f (0 , 0 , px , py , 0);
2322 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2321 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); 2322 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); 2323 arr->t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2325 2324
2326 // update smooth hash 2325 // update smooth hash
2327 if (tex.smoothtile) 2326 if (tex.smoothtile)
2328 { 2327 {
2329 skey.tile = tex.smoothtile; 2328 skey.tile = tex.smoothtile;
2330 skey.level = tex.smoothlevel; 2329 skey.level = tex.smoothlevel;
2331 2330
2332 smooth_level [tex.smoothlevel >> 5] |= ((uint32_t)1) << (tex.smoothlevel & 31); 2331 smooth_level[tex.smoothlevel] = 1;
2333 2332
2334 // add bits to current tile and all neighbours. skey.x|y is 2333 // add bits to current tile and all neighbours. skey.x|y is
2335 // shifted +1|+1 so we always stay positive. 2334 // shifted +1|+1 so we always stay positive.
2336 2335
2337 // bits is ___n cccc CCCC bbbb 2336 // bits is ___n cccc CCCC bbbb
2367 { 2366 {
2368 // overlays such as the speech bubble, probably more to come 2367 // overlays such as the speech bubble, probably more to come
2369 if (cell->flags & 1) 2368 if (cell->flags & 1)
2370 { 2369 {
2371 rc_key_t key_ov = key; 2370 rc_key_t key_ov = key;
2372 maptex tex = self->tex [TEXID_SPEECH]; 2371 maptex tex = self->tex[TEXID_SPEECH];
2373 rc_array_t *arr;
2374 int px = x * Tw + Tw * 2 / 32; 2372 int px = x * Tw + Tw * 2 / 32;
2375 int py = y * Th - Th * 6 / 32; 2373 int py = y * Th - Th * 6 / 32;
2376 2374
2377 key_ov.texname = tex.name; 2375 key_ov.texname = tex.name;
2378 arr = rc_array (rc_ov, &key_ov); 2376 rc_t::array_t &arr = rc_ov.array (key_ov);
2379 2377
2380 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2378 arr.t2f_v3f (0 , 0 , px , py , 0);
2381 rc_t2f_v3f (arr, 0 , tex.t, px , py + Th, 0); 2379 arr.t2f_v3f (0 , tex.t, px , py + Th, 0);
2382 rc_t2f_v3f (arr, tex.s, tex.t, px + Tw, py + Th, 0); 2380 arr.t2f_v3f (tex.s, tex.t, px + Tw, py + Th, 0);
2383 rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0); 2381 arr.t2f_v3f (tex.s, 0 , px + Tw, py , 0);
2384 } 2382 }
2385 } 2383 }
2386 } 2384 }
2387 } 2385 }
2388 2386
2389 rc_draw (rc); 2387 rc.draw ();
2390 rc_clear (rc); 2388 rc.clear ();
2391 2389
2392 // go through all smoothlevels, lowest to highest, then draw. 2390 // go through all smoothlevels, lowest to highest, then draw.
2393 // this is basically counting sort 2391 // this is basically counting sort
2394 { 2392 {
2395 int w, b; 2393 int w, b;
2396 2394
2397 glEnable (GL_TEXTURE_2D); 2395 glEnable (GL_TEXTURE_2D);
2398 glBegin (GL_QUADS); 2396 glBegin (GL_QUADS);
2399 for (w = 0; w < 256 / 32; ++w) 2397 for (int level = 0; level < smooth_level.size (); ++level)
2398 if (smooth_level[level])
2399 for (auto &&it = smooth.begin (); it != smooth.end (); ++it)
2400 { 2400 {
2401 uint32_t smask = smooth_level [w]; 2401 smooth_key &skey = it->first;
2402 if (smask) 2402 IV bits = it->second;
2403 for (b = 0; b < 32; ++b) 2403
2404 if (smask & (((uint32_t)1) << b)) 2404 if (!(bits & 0x1000)
2405 && skey.level == level
2406 && level > smooth_max [skey.x][skey.y])
2405 { 2407 {
2406 int level = (w << 5) | b; 2408 maptex tex = self->tex [skey.tile];
2409 int px = (((int)skey.x) - 1) * Tw;
2410 int py = (((int)skey.y) - 1) * Th;
2411 int border = bits & 15;
2412 int corner = (bits >> 8) & ~(bits >> 4) & 15;
2413 float dx = tex.s * .0625f; // 16 images/row
2414 float dy = tex.t * .5f ; // 2 images/column
2415
2407 HE *he; 2416 if (tex.name)
2408
2409 for (auto &&it = smooth.begin (); it != smooth.end (); ++it)
2410 { 2417 {
2411 smooth_key &skey = it->first; 2418 // this time avoiding texture state changes
2412 IV bits = it->second; 2419 // save gobs of state changes.
2413 2420 if (key.texname != tex.name)
2414 if (!(bits & 0x1000)
2415 && skey.level == level
2416 && level > smooth_max [skey.x][skey.y])
2417 { 2421 {
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; 2422 self->tex [skey.tile].unused = 0;
2433 2423
2434 glEnd (); 2424 glEnd ();
2435 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); 2425 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
2436 glBegin (GL_QUADS); 2426 glBegin (GL_QUADS);
2437 } 2427 }
2438 2428
2439 if (border) 2429 if (border)
2440 { 2430 {
2441 float ox = border * dx; 2431 float ox = border * dx;
2442 2432
2443 glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); 2433 glTexCoord2f (ox , 0.f ); glVertex2i (px , py );
2444 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); 2434 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th);
2445 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); 2435 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th);
2446 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); 2436 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py );
2447 } 2437 }
2448 2438
2449 if (corner) 2439 if (corner)
2450 { 2440 {
2451 float ox = corner * dx; 2441 float ox = corner * dx;
2452 2442
2453 glTexCoord2f (ox , dy ); glVertex2i (px , py ); 2443 glTexCoord2f (ox , dy ); glVertex2i (px , py );
2454 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); 2444 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th);
2455 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); 2445 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th);
2456 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); 2446 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py );
2457 }
2458 }
2459 } 2447 }
2460 } 2448 }
2461 } 2449 }
2462 } 2450 }
2463 2451
2464 glEnd (); 2452 glEnd ();
2465 glDisable (GL_TEXTURE_2D); 2453 glDisable (GL_TEXTURE_2D);
2466 key.texname = -1; 2454 key.texname = -1;
2467 } 2455 }
2472 maptex tex = pl_tex; 2460 maptex tex = pl_tex;
2473 int px = pl_x + sdx; 2461 int px = pl_x + sdx;
2474 int py = pl_y + sdy; 2462 int py = pl_y + sdy;
2475 2463
2476 key.texname = tex.name; 2464 key.texname = tex.name;
2477 arr = rc_array (rc, &key); 2465 rc_t::array_t &arr = rc.array (key);
2478 2466
2479 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2467 arr.t2f_v3f (0 , 0 , px , py , 0);
2480 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2468 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); 2469 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); 2470 arr.t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2483 2471
2484 rc_draw (rc); 2472 rc.draw ();
2485 } 2473 }
2486 2474
2487 rc_draw (rc_ov); 2475 rc_ov.draw ();
2488 rc_clear (rc_ov); 2476 rc_ov.clear ();
2489 2477
2490 glDisable (GL_BLEND); 2478 glDisable (GL_BLEND);
2491 rc_free (rc);
2492 rc_free (rc_ov);
2493 2479
2494 // top layer: overlays such as the health bar 2480 // top layer: overlays such as the health bar
2495 for (y = 0; y < sh; y++) 2481 for (y = 0; y < sh; y++)
2496 if (0 <= y + my && y + my < self->rows) 2482 if (0 <= y + my && y + my < self->rows)
2497 { 2483 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines