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.329 by root, Sun Nov 18 13:07:51 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;
296 maprow *row; 296 maprow *row;
297}; 297};
298 298
299typedef mapgrid *DC__Map; 299typedef mapgrid *DC__Map;
300 300
301static char * 301template<typename T>
302static void
302prepend (char *ptr, int sze, int inc) 303prepend (T *&ptr, int sze, int inc)
303{ 304{
304 char *p; 305 T *p;
305 306
306 New (0, p, sze + inc, char); 307 New (0, p, sze + inc, T);
307 Zero (p, inc, char); 308 Zero (p, inc, T);
308 Move (ptr, p + inc, sze, char); 309 Move (ptr, p + inc, sze, T);
309 Safefree (ptr); 310 Safefree (ptr);
310 311
311 return p; 312 ptr = p;
312} 313}
313 314
314static char * 315template<typename T>
316static void
315append (char *ptr, int sze, int inc) 317append (T *&ptr, int sze, int inc)
316{ 318{
317 Renew (ptr, sze + inc, char); 319 Renew (ptr, sze + inc, T);
318 Zero (ptr + sze, inc, char); 320 Zero (ptr + sze, inc, T);
319
320 return ptr;
321} 321}
322
323#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))
325 322
326static void 323static void
327need_facenum (struct mapgrid *self, faceid face) 324need_facenum (struct mapgrid *self, faceid face)
328{ 325{
329 while (self->faces <= face) 326 while (self->faces <= face)
330 { 327 {
331 Append (tileid, self->face2tile, self->faces, self->faces); 328 append (self->face2tile, self->faces, self->faces);
332 self->faces *= 2; 329 self->faces *= 2;
333 } 330 }
334} 331}
335 332
336static void 333static void
337need_texid (struct mapgrid *self, int texid) 334need_texid (struct mapgrid *self, int texid)
338{ 335{
339 while (self->texs <= texid) 336 while (self->texs <= texid)
340 { 337 {
341 Append (maptex, self->tex, self->texs, self->texs); 338 append (self->tex, self->texs, self->texs);
342 self->texs *= 2; 339 self->texs *= 2;
343 } 340 }
344} 341}
345 342
346static maprow * 343static maprow *
347map_get_row (mapgrid *self, int y) 344map_get_row (mapgrid *self, int y)
348{ 345{
349 if (0 > y) 346 if (0 > y)
350 { 347 {
351 int extend = - y + MAP_EXTEND_Y; 348 int extend = - y + MAP_EXTEND_Y;
352 Prepend (maprow, self->row, self->rows, extend); 349 prepend (self->row, self->rows, extend);
353 350
354 self->rows += extend; 351 self->rows += extend;
355 self->y += extend; 352 self->y += extend;
356 y += extend; 353 y += extend;
357 } 354 }
358 else if (y >= self->rows) 355 else if (y >= self->rows)
359 { 356 {
360 int extend = y - self->rows + MAP_EXTEND_Y; 357 int extend = y - self->rows + MAP_EXTEND_Y;
361 Append (maprow, self->row, self->rows, extend); 358 append (self->row, self->rows, extend);
362 self->rows += extend; 359 self->rows += extend;
363 } 360 }
364 361
365 return self->row + y; 362 return self->row + y;
366} 363}
376 } 373 }
377 374
378 if (row->c0 > x) 375 if (row->c0 > x)
379 { 376 {
380 int extend = row->c0 - x + MAP_EXTEND_X; 377 int extend = row->c0 - x + MAP_EXTEND_X;
381 Prepend (mapcell, row->col, row->c1 - row->c0, extend); 378 prepend (row->col, row->c1 - row->c0, extend);
382 row->c0 -= extend; 379 row->c0 -= extend;
383 } 380 }
384 else if (x >= row->c1) 381 else if (x >= row->c1)
385 { 382 {
386 int extend = x - row->c1 + MAP_EXTEND_X; 383 int extend = x - row->c1 + MAP_EXTEND_X;
387 Append (mapcell, row->col, row->c1 - row->c0, extend); 384 append (row->col, row->c1 - row->c0, extend);
388 row->c1 += extend; 385 row->c1 += extend;
389 } 386 }
390 387
391 return row->col + (x - row->c0); 388 return row->col + (x - row->c0);
392} 389}
1369 tc_restore (); 1366 tc_restore ();
1370 1367
1371DC::Layout 1368DC::Layout
1372new (SV *klass) 1369new (SV *klass)
1373 CODE: 1370 CODE:
1374 New (0, RETVAL, 1, struct cf_layout); 1371 RETVAL = new cf_layout;
1375 1372
1376 RETVAL->pl = pango_layout_new (opengl_context); 1373 RETVAL->pl = pango_layout_new (opengl_context);
1377 RETVAL->r = 1.; 1374 RETVAL->r = 1.;
1378 RETVAL->g = 1.; 1375 RETVAL->g = 1.;
1379 RETVAL->b = 1.; 1376 RETVAL->b = 1.;
1380 RETVAL->a = 1.; 1377 RETVAL->a = 1.;
1381 RETVAL->base_height = MIN_FONT_HEIGHT; 1378 RETVAL->base_height = MIN_FONT_HEIGHT;
1382 RETVAL->font = 0; 1379 RETVAL->font = 0;
1383 RETVAL->rc = rc_alloc ();
1384 1380
1385 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); 1381 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR);
1386 layout_update_font (RETVAL); 1382 layout_update_font (RETVAL);
1387 OUTPUT: 1383 OUTPUT:
1388 RETVAL 1384 RETVAL
1389 1385
1390void 1386void
1391DESTROY (DC::Layout self) 1387DESTROY (DC::Layout self)
1392 CODE: 1388 CODE:
1393 g_object_unref (self->pl); 1389 g_object_unref (self->pl);
1394 rc_free (self->rc);
1395 Safefree (self); 1390 delete self;
1396 1391
1397void 1392void
1398set_text (DC::Layout self, SV *text_) 1393set_text (DC::Layout self, SV *text_)
1399 CODE: 1394 CODE:
1400{ 1395{
1654} 1649}
1655 1650
1656void 1651void
1657render (DC::Layout self, float x, float y, int flags = 0) 1652render (DC::Layout self, float x, float y, int flags = 0)
1658 CODE: 1653 CODE:
1659 rc_clear (self->rc); 1654 self->rc.clear ();
1660 pango_opengl_render_layout_subpixel ( 1655 pango_opengl_render_layout_subpixel (
1661 self->pl, 1656 self->pl,
1662 self->rc, 1657 &self->rc,
1663 x * PANGO_SCALE, y * PANGO_SCALE, 1658 x * PANGO_SCALE, y * PANGO_SCALE,
1664 self->r, self->g, self->b, self->a, 1659 self->r, self->g, self->b, self->a,
1665 flags 1660 flags
1666 ); 1661 );
1667 // we assume that context_change actually clears/frees stuff 1662 // we assume that context_change actually clears/frees stuff
1678 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 1673 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
1679 GL_ONE , GL_ONE_MINUS_SRC_ALPHA); 1674 GL_ONE , GL_ONE_MINUS_SRC_ALPHA);
1680 glEnable (GL_ALPHA_TEST); 1675 glEnable (GL_ALPHA_TEST);
1681 glAlphaFunc (GL_GREATER, 7.f / 255.f); 1676 glAlphaFunc (GL_GREATER, 7.f / 255.f);
1682 1677
1683 rc_draw (self->rc); 1678 self->rc.draw ();
1684 1679
1685 glDisable (GL_ALPHA_TEST); 1680 glDisable (GL_ALPHA_TEST);
1686 glDisable (GL_BLEND); 1681 glDisable (GL_BLEND);
1687 glDisable (GL_TEXTURE_2D); 1682 glDisable (GL_TEXTURE_2D);
1688} 1683}
2058 self->ox += dx; self->x += dx; 2053 self->ox += dx; self->x += dx;
2059 self->oy += dy; self->y += dy; 2054 self->oy += dy; self->y += dy;
2060 2055
2061 while (self->y < 0) 2056 while (self->y < 0)
2062 { 2057 {
2063 Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); 2058 prepend (self->row, self->rows, MAP_EXTEND_Y);
2064 2059
2065 self->rows += MAP_EXTEND_Y; 2060 self->rows += MAP_EXTEND_Y;
2066 self->y += MAP_EXTEND_Y; 2061 self->y += MAP_EXTEND_Y;
2067 } 2062 }
2068} 2063}
2227 int x, y, z; 2222 int x, y, z;
2228 2223
2229 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k), also, static! 2224 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k), also, static!
2230 int pl_x, pl_y; 2225 int pl_x, pl_y;
2231 maptex pl_tex; 2226 maptex pl_tex;
2232 rc_t *rc = rc_alloc (); 2227 rc_t rc;
2233 rc_t *rc_ov = rc_alloc (); 2228 rc_t rc_ov;
2234 rc_key_t key; 2229 rc_key_t key;
2235 rc_array_t *arr; 2230 rc_t::array_t *arr;
2236 2231
2237 pl_tex.name = 0; 2232 pl_tex.name = 0;
2238 2233
2239 // that's current max. sorry. 2234 // that's current max. sorry.
2240 if (sw > 255) sw = 255; 2235 if (sw > 255) sw = 255;
2277 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2272 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2278 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2273 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
2279 2274
2280 for (z = 0; z <= 2; z++) 2275 for (z = 0; z <= 2; z++)
2281 { 2276 {
2282 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level 2277 std::bitset<256> smooth_level; // one bit for every possible smooth level
2283 smooth_key skey; 2278 smooth_key skey;
2284 smooth_hash smooth; 2279 smooth_hash smooth;
2285 memset (smooth_level, 0, sizeof (smooth_level));
2286 key.texname = -1; 2280 key.texname = -1;
2287 2281
2288 for (y = 0; y < sh; y++) 2282 for (y = 0; y < sh; y++)
2289 if (0 <= y + my && y + my < self->rows) 2283 if (0 <= y + my && y + my < self->rows)
2290 { 2284 {
2307 2301
2308 if (!tex.name) 2302 if (!tex.name)
2309 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ 2303 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */
2310 2304
2311 key.texname = tex.name; 2305 key.texname = tex.name;
2312 arr = rc_array (rc, &key); 2306 arr = &rc.array (key);
2313 } 2307 }
2314 2308
2315 px = (x + 1) * Th - tex.w; 2309 px = (x + 1) * Th - tex.w;
2316 py = (y + 1) * Tw - tex.h; 2310 py = (y + 1) * Tw - tex.h;
2317 2311
2321 pl_y = py; 2315 pl_y = py;
2322 pl_tex = tex; 2316 pl_tex = tex;
2323 continue; 2317 continue;
2324 } 2318 }
2325 2319
2326 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2320 arr->t2f_v3f (0 , 0 , px , py , 0);
2327 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2321 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); 2322 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); 2323 arr->t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2330 2324
2331 // update smooth hash 2325 // update smooth hash
2332 if (tex.smoothtile) 2326 if (tex.smoothtile)
2333 { 2327 {
2334 skey.tile = tex.smoothtile; 2328 skey.tile = tex.smoothtile;
2335 skey.level = tex.smoothlevel; 2329 skey.level = tex.smoothlevel;
2336 2330
2337 smooth_level [tex.smoothlevel >> 5] |= ((uint32_t)1) << (tex.smoothlevel & 31); 2331 smooth_level[tex.smoothlevel] = 1;
2338 2332
2339 // 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
2340 // shifted +1|+1 so we always stay positive. 2334 // shifted +1|+1 so we always stay positive.
2341 2335
2342 // bits is ___n cccc CCCC bbbb 2336 // bits is ___n cccc CCCC bbbb
2372 { 2366 {
2373 // overlays such as the speech bubble, probably more to come 2367 // overlays such as the speech bubble, probably more to come
2374 if (cell->flags & 1) 2368 if (cell->flags & 1)
2375 { 2369 {
2376 rc_key_t key_ov = key; 2370 rc_key_t key_ov = key;
2377 maptex tex = self->tex [TEXID_SPEECH]; 2371 maptex tex = self->tex[TEXID_SPEECH];
2378 rc_array_t *arr;
2379 int px = x * Tw + Tw * 2 / 32; 2372 int px = x * Tw + Tw * 2 / 32;
2380 int py = y * Th - Th * 6 / 32; 2373 int py = y * Th - Th * 6 / 32;
2381 2374
2382 key_ov.texname = tex.name; 2375 key_ov.texname = tex.name;
2383 arr = rc_array (rc_ov, &key_ov); 2376 rc_t::array_t &arr = rc_ov.array (key_ov);
2384 2377
2385 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2378 arr.t2f_v3f (0 , 0 , px , py , 0);
2386 rc_t2f_v3f (arr, 0 , tex.t, px , py + Th, 0); 2379 arr.t2f_v3f (0 , tex.t, px , py + Th, 0);
2387 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);
2388 rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0); 2381 arr.t2f_v3f (tex.s, 0 , px + Tw, py , 0);
2389 } 2382 }
2390 } 2383 }
2391 } 2384 }
2392 } 2385 }
2393 2386
2394 rc_draw (rc); 2387 rc.draw ();
2395 rc_clear (rc); 2388 rc.clear ();
2396 2389
2397 // go through all smoothlevels, lowest to highest, then draw. 2390 // go through all smoothlevels, lowest to highest, then draw.
2398 // this is basically counting sort 2391 // this is basically counting sort
2399 { 2392 {
2400 int w, b; 2393 int w, b;
2401 2394
2402 glEnable (GL_TEXTURE_2D); 2395 glEnable (GL_TEXTURE_2D);
2403 glBegin (GL_QUADS); 2396 glBegin (GL_QUADS);
2404 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)
2405 { 2400 {
2406 uint32_t smask = smooth_level [w]; 2401 smooth_key &skey = it->first;
2407 if (smask) 2402 IV bits = it->second;
2408 for (b = 0; b < 32; ++b) 2403
2409 if (smask & (((uint32_t)1) << b)) 2404 if (!(bits & 0x1000)
2405 && skey.level == level
2406 && level > smooth_max [skey.x][skey.y])
2410 { 2407 {
2411 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
2412 HE *he; 2416 if (tex.name)
2413
2414 for (auto &&it = smooth.begin (); it != smooth.end (); ++it)
2415 { 2417 {
2416 smooth_key &skey = it->first; 2418 // this time avoiding texture state changes
2417 IV bits = it->second; 2419 // save gobs of state changes.
2418 2420 if (key.texname != tex.name)
2419 if (!(bits & 0x1000)
2420 && skey.level == level
2421 && level > smooth_max [skey.x][skey.y])
2422 { 2421 {
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; 2422 self->tex [skey.tile].unused = 0;
2438 2423
2439 glEnd (); 2424 glEnd ();
2440 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); 2425 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
2441 glBegin (GL_QUADS); 2426 glBegin (GL_QUADS);
2442 } 2427 }
2443 2428
2444 if (border) 2429 if (border)
2445 { 2430 {
2446 float ox = border * dx; 2431 float ox = border * dx;
2447 2432
2448 glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); 2433 glTexCoord2f (ox , 0.f ); glVertex2i (px , py );
2449 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); 2434 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th);
2450 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); 2435 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th);
2451 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); 2436 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py );
2452 } 2437 }
2453 2438
2454 if (corner) 2439 if (corner)
2455 { 2440 {
2456 float ox = corner * dx; 2441 float ox = corner * dx;
2457 2442
2458 glTexCoord2f (ox , dy ); glVertex2i (px , py ); 2443 glTexCoord2f (ox , dy ); glVertex2i (px , py );
2459 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); 2444 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th);
2460 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); 2445 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th);
2461 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); 2446 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py );
2462 }
2463 }
2464 } 2447 }
2465 } 2448 }
2466 } 2449 }
2467 } 2450 }
2468 2451
2469 glEnd (); 2452 glEnd ();
2470 glDisable (GL_TEXTURE_2D); 2453 glDisable (GL_TEXTURE_2D);
2471 key.texname = -1; 2454 key.texname = -1;
2472 } 2455 }
2477 maptex tex = pl_tex; 2460 maptex tex = pl_tex;
2478 int px = pl_x + sdx; 2461 int px = pl_x + sdx;
2479 int py = pl_y + sdy; 2462 int py = pl_y + sdy;
2480 2463
2481 key.texname = tex.name; 2464 key.texname = tex.name;
2482 arr = rc_array (rc, &key); 2465 rc_t::array_t &arr = rc.array (key);
2483 2466
2484 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2467 arr.t2f_v3f (0 , 0 , px , py , 0);
2485 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2468 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); 2469 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); 2470 arr.t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2488 2471
2489 rc_draw (rc); 2472 rc.draw ();
2490 } 2473 }
2491 2474
2492 rc_draw (rc_ov); 2475 rc_ov.draw ();
2493 rc_clear (rc_ov); 2476 rc_ov.clear ();
2494 2477
2495 glDisable (GL_BLEND); 2478 glDisable (GL_BLEND);
2496 rc_free (rc);
2497 rc_free (rc_ov);
2498 2479
2499 // top layer: overlays such as the health bar 2480 // top layer: overlays such as the health bar
2500 for (y = 0; y < sh; y++) 2481 for (y = 0; y < sh; y++)
2501 if (0 <= y + my && y + my < self->rows) 2482 if (0 <= y + my && y + my < self->rows)
2502 { 2483 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines