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.325 by root, Sun Nov 18 02:04:48 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;
2306 2301
2307 if (!tex.name) 2302 if (!tex.name)
2308 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ 2303 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */
2309 2304
2310 key.texname = tex.name; 2305 key.texname = tex.name;
2311 arr = rc_array (rc, &key); 2306 arr = &rc.array (key);
2312 } 2307 }
2313 2308
2314 px = (x + 1) * Th - tex.w; 2309 px = (x + 1) * Th - tex.w;
2315 py = (y + 1) * Tw - tex.h; 2310 py = (y + 1) * Tw - tex.h;
2316 2311
2320 pl_y = py; 2315 pl_y = py;
2321 pl_tex = tex; 2316 pl_tex = tex;
2322 continue; 2317 continue;
2323 } 2318 }
2324 2319
2325 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2320 arr->t2f_v3f (0 , 0 , px , py , 0);
2326 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2321 arr->t2f_v3f (0 , tex.t, px , py + tex.h, 0);
2327 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);
2328 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); 2323 arr->t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2329 2324
2330 // update smooth hash 2325 // update smooth hash
2331 if (tex.smoothtile) 2326 if (tex.smoothtile)
2332 { 2327 {
2333 skey.tile = tex.smoothtile; 2328 skey.tile = tex.smoothtile;
2371 { 2366 {
2372 // overlays such as the speech bubble, probably more to come 2367 // overlays such as the speech bubble, probably more to come
2373 if (cell->flags & 1) 2368 if (cell->flags & 1)
2374 { 2369 {
2375 rc_key_t key_ov = key; 2370 rc_key_t key_ov = key;
2376 maptex tex = self->tex [TEXID_SPEECH]; 2371 maptex tex = self->tex[TEXID_SPEECH];
2377 rc_array_t *arr;
2378 int px = x * Tw + Tw * 2 / 32; 2372 int px = x * Tw + Tw * 2 / 32;
2379 int py = y * Th - Th * 6 / 32; 2373 int py = y * Th - Th * 6 / 32;
2380 2374
2381 key_ov.texname = tex.name; 2375 key_ov.texname = tex.name;
2382 arr = rc_array (rc_ov, &key_ov); 2376 rc_t::array_t &arr = rc_ov.array (key_ov);
2383 2377
2384 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2378 arr.t2f_v3f (0 , 0 , px , py , 0);
2385 rc_t2f_v3f (arr, 0 , tex.t, px , py + Th, 0); 2379 arr.t2f_v3f (0 , tex.t, px , py + Th, 0);
2386 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);
2387 rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0); 2381 arr.t2f_v3f (tex.s, 0 , px + Tw, py , 0);
2388 } 2382 }
2389 } 2383 }
2390 } 2384 }
2391 } 2385 }
2392 2386
2393 rc_draw (rc); 2387 rc.draw ();
2394 rc_clear (rc); 2388 rc.clear ();
2395 2389
2396 // go through all smoothlevels, lowest to highest, then draw. 2390 // go through all smoothlevels, lowest to highest, then draw.
2397 // this is basically counting sort 2391 // this is basically counting sort
2398 { 2392 {
2399 int w, b; 2393 int w, b;
2466 maptex tex = pl_tex; 2460 maptex tex = pl_tex;
2467 int px = pl_x + sdx; 2461 int px = pl_x + sdx;
2468 int py = pl_y + sdy; 2462 int py = pl_y + sdy;
2469 2463
2470 key.texname = tex.name; 2464 key.texname = tex.name;
2471 arr = rc_array (rc, &key); 2465 rc_t::array_t &arr = rc.array (key);
2472 2466
2473 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2467 arr.t2f_v3f (0 , 0 , px , py , 0);
2474 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2468 arr.t2f_v3f (0 , tex.t, px , py + tex.h, 0);
2475 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);
2476 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); 2470 arr.t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2477 2471
2478 rc_draw (rc); 2472 rc.draw ();
2479 } 2473 }
2480 2474
2481 rc_draw (rc_ov); 2475 rc_ov.draw ();
2482 rc_clear (rc_ov); 2476 rc_ov.clear ();
2483 2477
2484 glDisable (GL_BLEND); 2478 glDisable (GL_BLEND);
2485 rc_free (rc);
2486 rc_free (rc_ov);
2487 2479
2488 // top layer: overlays such as the health bar 2480 // top layer: overlays such as the health bar
2489 for (y = 0; y < sh; y++) 2481 for (y = 0; y < sh; y++)
2490 if (0 <= y + my && y + my < self->rows) 2482 if (0 <= y + my && y + my < self->rows)
2491 { 2483 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines