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.326 by root, Sun Nov 18 03:06:13 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;
1369 tc_restore (); 1369 tc_restore ();
1370 1370
1371DC::Layout 1371DC::Layout
1372new (SV *klass) 1372new (SV *klass)
1373 CODE: 1373 CODE:
1374 New (0, RETVAL, 1, struct cf_layout); 1374 RETVAL = new cf_layout;
1375 1375
1376 RETVAL->pl = pango_layout_new (opengl_context); 1376 RETVAL->pl = pango_layout_new (opengl_context);
1377 RETVAL->r = 1.; 1377 RETVAL->r = 1.;
1378 RETVAL->g = 1.; 1378 RETVAL->g = 1.;
1379 RETVAL->b = 1.; 1379 RETVAL->b = 1.;
1380 RETVAL->a = 1.; 1380 RETVAL->a = 1.;
1381 RETVAL->base_height = MIN_FONT_HEIGHT; 1381 RETVAL->base_height = MIN_FONT_HEIGHT;
1382 RETVAL->font = 0; 1382 RETVAL->font = 0;
1383 RETVAL->rc = rc_alloc ();
1384 1383
1385 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); 1384 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR);
1386 layout_update_font (RETVAL); 1385 layout_update_font (RETVAL);
1387 OUTPUT: 1386 OUTPUT:
1388 RETVAL 1387 RETVAL
1389 1388
1390void 1389void
1391DESTROY (DC::Layout self) 1390DESTROY (DC::Layout self)
1392 CODE: 1391 CODE:
1393 g_object_unref (self->pl); 1392 g_object_unref (self->pl);
1394 rc_free (self->rc);
1395 Safefree (self); 1393 delete self;
1396 1394
1397void 1395void
1398set_text (DC::Layout self, SV *text_) 1396set_text (DC::Layout self, SV *text_)
1399 CODE: 1397 CODE:
1400{ 1398{
1654} 1652}
1655 1653
1656void 1654void
1657render (DC::Layout self, float x, float y, int flags = 0) 1655render (DC::Layout self, float x, float y, int flags = 0)
1658 CODE: 1656 CODE:
1659 rc_clear (self->rc); 1657 self->rc.clear ();
1660 pango_opengl_render_layout_subpixel ( 1658 pango_opengl_render_layout_subpixel (
1661 self->pl, 1659 self->pl,
1662 self->rc, 1660 &self->rc,
1663 x * PANGO_SCALE, y * PANGO_SCALE, 1661 x * PANGO_SCALE, y * PANGO_SCALE,
1664 self->r, self->g, self->b, self->a, 1662 self->r, self->g, self->b, self->a,
1665 flags 1663 flags
1666 ); 1664 );
1667 // we assume that context_change actually clears/frees stuff 1665 // we assume that context_change actually clears/frees stuff
1678 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 1676 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
1679 GL_ONE , GL_ONE_MINUS_SRC_ALPHA); 1677 GL_ONE , GL_ONE_MINUS_SRC_ALPHA);
1680 glEnable (GL_ALPHA_TEST); 1678 glEnable (GL_ALPHA_TEST);
1681 glAlphaFunc (GL_GREATER, 7.f / 255.f); 1679 glAlphaFunc (GL_GREATER, 7.f / 255.f);
1682 1680
1683 rc_draw (self->rc); 1681 self->rc.draw ();
1684 1682
1685 glDisable (GL_ALPHA_TEST); 1683 glDisable (GL_ALPHA_TEST);
1686 glDisable (GL_BLEND); 1684 glDisable (GL_BLEND);
1687 glDisable (GL_TEXTURE_2D); 1685 glDisable (GL_TEXTURE_2D);
1688} 1686}
2227 int x, y, z; 2225 int x, y, z;
2228 2226
2229 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k), also, static! 2227 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k), also, static!
2230 int pl_x, pl_y; 2228 int pl_x, pl_y;
2231 maptex pl_tex; 2229 maptex pl_tex;
2232 rc_t *rc = rc_alloc (); 2230 rc_t rc;
2233 rc_t *rc_ov = rc_alloc (); 2231 rc_t rc_ov;
2234 rc_key_t key; 2232 rc_key_t key;
2235 rc_array_t *arr; 2233 rc_t::array_t *arr;
2236 2234
2237 pl_tex.name = 0; 2235 pl_tex.name = 0;
2238 2236
2239 // that's current max. sorry. 2237 // that's current max. sorry.
2240 if (sw > 255) sw = 255; 2238 if (sw > 255) sw = 255;
2277 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2275 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2278 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2276 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
2279 2277
2280 for (z = 0; z <= 2; z++) 2278 for (z = 0; z <= 2; z++)
2281 { 2279 {
2282 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level 2280 std::bitset<256> smooth_level; // one bit for every possible smooth level
2283 smooth_key skey; 2281 smooth_key skey;
2284 smooth_hash smooth; 2282 smooth_hash smooth;
2285 memset (smooth_level, 0, sizeof (smooth_level));
2286 key.texname = -1; 2283 key.texname = -1;
2287 2284
2288 for (y = 0; y < sh; y++) 2285 for (y = 0; y < sh; y++)
2289 if (0 <= y + my && y + my < self->rows) 2286 if (0 <= y + my && y + my < self->rows)
2290 { 2287 {
2307 2304
2308 if (!tex.name) 2305 if (!tex.name)
2309 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ 2306 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */
2310 2307
2311 key.texname = tex.name; 2308 key.texname = tex.name;
2312 arr = rc_array (rc, &key); 2309 arr = &rc.array (key);
2313 } 2310 }
2314 2311
2315 px = (x + 1) * Th - tex.w; 2312 px = (x + 1) * Th - tex.w;
2316 py = (y + 1) * Tw - tex.h; 2313 py = (y + 1) * Tw - tex.h;
2317 2314
2321 pl_y = py; 2318 pl_y = py;
2322 pl_tex = tex; 2319 pl_tex = tex;
2323 continue; 2320 continue;
2324 } 2321 }
2325 2322
2326 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2323 arr->t2f_v3f (0 , 0 , px , py , 0);
2327 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2324 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); 2325 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); 2326 arr->t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2330 2327
2331 // update smooth hash 2328 // update smooth hash
2332 if (tex.smoothtile) 2329 if (tex.smoothtile)
2333 { 2330 {
2334 skey.tile = tex.smoothtile; 2331 skey.tile = tex.smoothtile;
2335 skey.level = tex.smoothlevel; 2332 skey.level = tex.smoothlevel;
2336 2333
2337 smooth_level [tex.smoothlevel >> 5] |= ((uint32_t)1) << (tex.smoothlevel & 31); 2334 smooth_level[tex.smoothlevel] = 1;
2338 2335
2339 // add bits to current tile and all neighbours. skey.x|y is 2336 // add bits to current tile and all neighbours. skey.x|y is
2340 // shifted +1|+1 so we always stay positive. 2337 // shifted +1|+1 so we always stay positive.
2341 2338
2342 // bits is ___n cccc CCCC bbbb 2339 // bits is ___n cccc CCCC bbbb
2372 { 2369 {
2373 // overlays such as the speech bubble, probably more to come 2370 // overlays such as the speech bubble, probably more to come
2374 if (cell->flags & 1) 2371 if (cell->flags & 1)
2375 { 2372 {
2376 rc_key_t key_ov = key; 2373 rc_key_t key_ov = key;
2377 maptex tex = self->tex [TEXID_SPEECH]; 2374 maptex tex = self->tex[TEXID_SPEECH];
2378 rc_array_t *arr;
2379 int px = x * Tw + Tw * 2 / 32; 2375 int px = x * Tw + Tw * 2 / 32;
2380 int py = y * Th - Th * 6 / 32; 2376 int py = y * Th - Th * 6 / 32;
2381 2377
2382 key_ov.texname = tex.name; 2378 key_ov.texname = tex.name;
2383 arr = rc_array (rc_ov, &key_ov); 2379 rc_t::array_t &arr = rc_ov.array (key_ov);
2384 2380
2385 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2381 arr.t2f_v3f (0 , 0 , px , py , 0);
2386 rc_t2f_v3f (arr, 0 , tex.t, px , py + Th, 0); 2382 arr.t2f_v3f (0 , tex.t, px , py + Th, 0);
2387 rc_t2f_v3f (arr, tex.s, tex.t, px + Tw, py + Th, 0); 2383 arr.t2f_v3f (tex.s, tex.t, px + Tw, py + Th, 0);
2388 rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0); 2384 arr.t2f_v3f (tex.s, 0 , px + Tw, py , 0);
2389 } 2385 }
2390 } 2386 }
2391 } 2387 }
2392 } 2388 }
2393 2389
2394 rc_draw (rc); 2390 rc.draw ();
2395 rc_clear (rc); 2391 rc.clear ();
2396 2392
2397 // go through all smoothlevels, lowest to highest, then draw. 2393 // go through all smoothlevels, lowest to highest, then draw.
2398 // this is basically counting sort 2394 // this is basically counting sort
2399 { 2395 {
2400 int w, b; 2396 int w, b;
2401 2397
2402 glEnable (GL_TEXTURE_2D); 2398 glEnable (GL_TEXTURE_2D);
2403 glBegin (GL_QUADS); 2399 glBegin (GL_QUADS);
2404 for (w = 0; w < 256 / 32; ++w) 2400 for (int level = 0; level < smooth_level.size (); ++level)
2401 if (smooth_level[level])
2402 for (auto &&it = smooth.begin (); it != smooth.end (); ++it)
2405 { 2403 {
2406 uint32_t smask = smooth_level [w]; 2404 smooth_key &skey = it->first;
2407 if (smask) 2405 IV bits = it->second;
2408 for (b = 0; b < 32; ++b) 2406
2409 if (smask & (((uint32_t)1) << b)) 2407 if (!(bits & 0x1000)
2408 && skey.level == level
2409 && level > smooth_max [skey.x][skey.y])
2410 { 2410 {
2411 int level = (w << 5) | b; 2411 maptex tex = self->tex [skey.tile];
2412 int px = (((int)skey.x) - 1) * Tw;
2413 int py = (((int)skey.y) - 1) * Th;
2414 int border = bits & 15;
2415 int corner = (bits >> 8) & ~(bits >> 4) & 15;
2416 float dx = tex.s * .0625f; // 16 images/row
2417 float dy = tex.t * .5f ; // 2 images/column
2418
2412 HE *he; 2419 if (tex.name)
2413
2414 for (auto &&it = smooth.begin (); it != smooth.end (); ++it)
2415 { 2420 {
2416 smooth_key &skey = it->first; 2421 // this time avoiding texture state changes
2417 IV bits = it->second; 2422 // save gobs of state changes.
2418 2423 if (key.texname != tex.name)
2419 if (!(bits & 0x1000)
2420 && skey.level == level
2421 && level > smooth_max [skey.x][skey.y])
2422 { 2424 {
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; 2425 self->tex [skey.tile].unused = 0;
2438 2426
2439 glEnd (); 2427 glEnd ();
2440 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); 2428 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
2441 glBegin (GL_QUADS); 2429 glBegin (GL_QUADS);
2442 } 2430 }
2443 2431
2444 if (border) 2432 if (border)
2445 { 2433 {
2446 float ox = border * dx; 2434 float ox = border * dx;
2447 2435
2448 glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); 2436 glTexCoord2f (ox , 0.f ); glVertex2i (px , py );
2449 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); 2437 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th);
2450 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); 2438 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th);
2451 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); 2439 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py );
2452 } 2440 }
2453 2441
2454 if (corner) 2442 if (corner)
2455 { 2443 {
2456 float ox = corner * dx; 2444 float ox = corner * dx;
2457 2445
2458 glTexCoord2f (ox , dy ); glVertex2i (px , py ); 2446 glTexCoord2f (ox , dy ); glVertex2i (px , py );
2459 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); 2447 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th);
2460 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); 2448 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th);
2461 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); 2449 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py );
2462 }
2463 }
2464 } 2450 }
2465 } 2451 }
2466 } 2452 }
2467 } 2453 }
2468 2454
2469 glEnd (); 2455 glEnd ();
2470 glDisable (GL_TEXTURE_2D); 2456 glDisable (GL_TEXTURE_2D);
2471 key.texname = -1; 2457 key.texname = -1;
2472 } 2458 }
2477 maptex tex = pl_tex; 2463 maptex tex = pl_tex;
2478 int px = pl_x + sdx; 2464 int px = pl_x + sdx;
2479 int py = pl_y + sdy; 2465 int py = pl_y + sdy;
2480 2466
2481 key.texname = tex.name; 2467 key.texname = tex.name;
2482 arr = rc_array (rc, &key); 2468 rc_t::array_t &arr = rc.array (key);
2483 2469
2484 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2470 arr.t2f_v3f (0 , 0 , px , py , 0);
2485 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2471 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); 2472 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); 2473 arr.t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2488 2474
2489 rc_draw (rc); 2475 rc.draw ();
2490 } 2476 }
2491 2477
2492 rc_draw (rc_ov); 2478 rc_ov.draw ();
2493 rc_clear (rc_ov); 2479 rc_ov.clear ();
2494 2480
2495 glDisable (GL_BLEND); 2481 glDisable (GL_BLEND);
2496 rc_free (rc);
2497 rc_free (rc_ov);
2498 2482
2499 // top layer: overlays such as the health bar 2483 // top layer: overlays such as the health bar
2500 for (y = 0; y < sh; y++) 2484 for (y = 0; y < sh; y++)
2501 if (0 <= y + my && y + my < self->rows) 2485 if (0 <= y + my && y + my < self->rows)
2502 { 2486 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines