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.330 by root, Sun Nov 18 15:24:24 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 Newxz (p, sze + inc, T);
307 Zero (p, inc, char);
308 Move (ptr, p + inc, sze, char); 308 Move (ptr, p + inc, sze, T);
309 Safefree (ptr); 309 Safefree (ptr);
310 310
311 return p; 311 ptr = p;
312} 312}
313 313
314static char * 314template<typename T>
315static void
315append (char *ptr, int sze, int inc) 316append (T *&ptr, int sze, int inc)
316{ 317{
317 Renew (ptr, sze + inc, char); 318 Renew (ptr, sze + inc, T);
318 Zero (ptr + sze, inc, char); 319 Zero (ptr + sze, inc, T);
319
320 return ptr;
321} 320}
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 321
326static void 322static void
327need_facenum (struct mapgrid *self, faceid face) 323need_facenum (struct mapgrid *self, faceid face)
328{ 324{
329 while (self->faces <= face) 325 while (self->faces <= face)
330 { 326 {
331 Append (tileid, self->face2tile, self->faces, self->faces); 327 append (self->face2tile, self->faces, self->faces);
332 self->faces *= 2; 328 self->faces *= 2;
333 } 329 }
334} 330}
335 331
336static void 332static void
337need_texid (struct mapgrid *self, int texid) 333need_texid (struct mapgrid *self, int texid)
338{ 334{
339 while (self->texs <= texid) 335 while (self->texs <= texid)
340 { 336 {
341 Append (maptex, self->tex, self->texs, self->texs); 337 append (self->tex, self->texs, self->texs);
342 self->texs *= 2; 338 self->texs *= 2;
343 } 339 }
344} 340}
345 341
346static maprow * 342static maprow *
347map_get_row (mapgrid *self, int y) 343map_get_row (mapgrid *self, int y)
348{ 344{
349 if (0 > y) 345 if (0 > y)
350 { 346 {
351 int extend = - y + MAP_EXTEND_Y; 347 int extend = - y + MAP_EXTEND_Y;
352 Prepend (maprow, self->row, self->rows, extend); 348 prepend (self->row, self->rows, extend);
353 349
354 self->rows += extend; 350 self->rows += extend;
355 self->y += extend; 351 self->y += extend;
356 y += extend; 352 y += extend;
357 } 353 }
358 else if (y >= self->rows) 354 else if (y >= self->rows)
359 { 355 {
360 int extend = y - self->rows + MAP_EXTEND_Y; 356 int extend = y - self->rows + MAP_EXTEND_Y;
361 Append (maprow, self->row, self->rows, extend); 357 append (self->row, self->rows, extend);
362 self->rows += extend; 358 self->rows += extend;
363 } 359 }
364 360
365 return self->row + y; 361 return self->row + y;
366} 362}
376 } 372 }
377 373
378 if (row->c0 > x) 374 if (row->c0 > x)
379 { 375 {
380 int extend = row->c0 - x + MAP_EXTEND_X; 376 int extend = row->c0 - x + MAP_EXTEND_X;
381 Prepend (mapcell, row->col, row->c1 - row->c0, extend); 377 prepend (row->col, row->c1 - row->c0, extend);
382 row->c0 -= extend; 378 row->c0 -= extend;
383 } 379 }
384 else if (x >= row->c1) 380 else if (x >= row->c1)
385 { 381 {
386 int extend = x - row->c1 + MAP_EXTEND_X; 382 int extend = x - row->c1 + MAP_EXTEND_X;
387 Append (mapcell, row->col, row->c1 - row->c0, extend); 383 append (row->col, row->c1 - row->c0, extend);
388 row->c1 += extend; 384 row->c1 += extend;
389 } 385 }
390 386
391 return row->col + (x - row->c0); 387 return row->col + (x - row->c0);
392} 388}
1369 tc_restore (); 1365 tc_restore ();
1370 1366
1371DC::Layout 1367DC::Layout
1372new (SV *klass) 1368new (SV *klass)
1373 CODE: 1369 CODE:
1374 New (0, RETVAL, 1, struct cf_layout); 1370 RETVAL = new cf_layout;
1375 1371
1376 RETVAL->pl = pango_layout_new (opengl_context); 1372 RETVAL->pl = pango_layout_new (opengl_context);
1377 RETVAL->r = 1.; 1373 RETVAL->r = 1.;
1378 RETVAL->g = 1.; 1374 RETVAL->g = 1.;
1379 RETVAL->b = 1.; 1375 RETVAL->b = 1.;
1380 RETVAL->a = 1.; 1376 RETVAL->a = 1.;
1381 RETVAL->base_height = MIN_FONT_HEIGHT; 1377 RETVAL->base_height = MIN_FONT_HEIGHT;
1382 RETVAL->font = 0; 1378 RETVAL->font = 0;
1383 RETVAL->rc = rc_alloc ();
1384 1379
1385 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); 1380 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR);
1386 layout_update_font (RETVAL); 1381 layout_update_font (RETVAL);
1387 OUTPUT: 1382 OUTPUT:
1388 RETVAL 1383 RETVAL
1389 1384
1390void 1385void
1391DESTROY (DC::Layout self) 1386DESTROY (DC::Layout self)
1392 CODE: 1387 CODE:
1393 g_object_unref (self->pl); 1388 g_object_unref (self->pl);
1394 rc_free (self->rc);
1395 Safefree (self); 1389 delete self;
1396 1390
1397void 1391void
1398set_text (DC::Layout self, SV *text_) 1392set_text (DC::Layout self, SV *text_)
1399 CODE: 1393 CODE:
1400{ 1394{
1654} 1648}
1655 1649
1656void 1650void
1657render (DC::Layout self, float x, float y, int flags = 0) 1651render (DC::Layout self, float x, float y, int flags = 0)
1658 CODE: 1652 CODE:
1659 rc_clear (self->rc); 1653 self->rc.clear ();
1660 pango_opengl_render_layout_subpixel ( 1654 pango_opengl_render_layout_subpixel (
1661 self->pl, 1655 self->pl,
1662 self->rc, 1656 &self->rc,
1663 x * PANGO_SCALE, y * PANGO_SCALE, 1657 x * PANGO_SCALE, y * PANGO_SCALE,
1664 self->r, self->g, self->b, self->a, 1658 self->r, self->g, self->b, self->a,
1665 flags 1659 flags
1666 ); 1660 );
1667 // we assume that context_change actually clears/frees stuff 1661 // we assume that context_change actually clears/frees stuff
1678 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 1672 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
1679 GL_ONE , GL_ONE_MINUS_SRC_ALPHA); 1673 GL_ONE , GL_ONE_MINUS_SRC_ALPHA);
1680 glEnable (GL_ALPHA_TEST); 1674 glEnable (GL_ALPHA_TEST);
1681 glAlphaFunc (GL_GREATER, 7.f / 255.f); 1675 glAlphaFunc (GL_GREATER, 7.f / 255.f);
1682 1676
1683 rc_draw (self->rc); 1677 self->rc.draw ();
1684 1678
1685 glDisable (GL_ALPHA_TEST); 1679 glDisable (GL_ALPHA_TEST);
1686 glDisable (GL_BLEND); 1680 glDisable (GL_BLEND);
1687 glDisable (GL_TEXTURE_2D); 1681 glDisable (GL_TEXTURE_2D);
1688} 1682}
2058 self->ox += dx; self->x += dx; 2052 self->ox += dx; self->x += dx;
2059 self->oy += dy; self->y += dy; 2053 self->oy += dy; self->y += dy;
2060 2054
2061 while (self->y < 0) 2055 while (self->y < 0)
2062 { 2056 {
2063 Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); 2057 prepend (self->row, self->rows, MAP_EXTEND_Y);
2064 2058
2065 self->rows += MAP_EXTEND_Y; 2059 self->rows += MAP_EXTEND_Y;
2066 self->y += MAP_EXTEND_Y; 2060 self->y += MAP_EXTEND_Y;
2067 } 2061 }
2068} 2062}
2227 int x, y, z; 2221 int x, y, z;
2228 2222
2229 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k), also, static! 2223 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k), also, static!
2230 int pl_x, pl_y; 2224 int pl_x, pl_y;
2231 maptex pl_tex; 2225 maptex pl_tex;
2232 rc_t *rc = rc_alloc (); 2226 rc_t rc;
2233 rc_t *rc_ov = rc_alloc (); 2227 rc_t rc_ov;
2234 rc_key_t key; 2228 rc_key_t key;
2235 rc_array_t *arr; 2229 rc_t::array_t *arr;
2236 2230
2237 pl_tex.name = 0; 2231 pl_tex.name = 0;
2238 2232
2239 // that's current max. sorry. 2233 // that's current max. sorry.
2240 if (sw > 255) sw = 255; 2234 if (sw > 255) sw = 255;
2306 2300
2307 if (!tex.name) 2301 if (!tex.name)
2308 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ 2302 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */
2309 2303
2310 key.texname = tex.name; 2304 key.texname = tex.name;
2311 arr = rc_array (rc, &key); 2305 arr = &rc.array (key);
2312 } 2306 }
2313 2307
2314 px = (x + 1) * Th - tex.w; 2308 px = (x + 1) * Th - tex.w;
2315 py = (y + 1) * Tw - tex.h; 2309 py = (y + 1) * Tw - tex.h;
2316 2310
2320 pl_y = py; 2314 pl_y = py;
2321 pl_tex = tex; 2315 pl_tex = tex;
2322 continue; 2316 continue;
2323 } 2317 }
2324 2318
2325 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2319 arr->t2f_v3f (0 , 0 , px , py , 0);
2326 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2320 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); 2321 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); 2322 arr->t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2329 2323
2330 // update smooth hash 2324 // update smooth hash
2331 if (tex.smoothtile) 2325 if (tex.smoothtile)
2332 { 2326 {
2333 skey.tile = tex.smoothtile; 2327 skey.tile = tex.smoothtile;
2371 { 2365 {
2372 // overlays such as the speech bubble, probably more to come 2366 // overlays such as the speech bubble, probably more to come
2373 if (cell->flags & 1) 2367 if (cell->flags & 1)
2374 { 2368 {
2375 rc_key_t key_ov = key; 2369 rc_key_t key_ov = key;
2376 maptex tex = self->tex [TEXID_SPEECH]; 2370 maptex tex = self->tex[TEXID_SPEECH];
2377 rc_array_t *arr;
2378 int px = x * Tw + Tw * 2 / 32; 2371 int px = x * Tw + Tw * 2 / 32;
2379 int py = y * Th - Th * 6 / 32; 2372 int py = y * Th - Th * 6 / 32;
2380 2373
2381 key_ov.texname = tex.name; 2374 key_ov.texname = tex.name;
2382 arr = rc_array (rc_ov, &key_ov); 2375 rc_t::array_t &arr = rc_ov.array (key_ov);
2383 2376
2384 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2377 arr.t2f_v3f (0 , 0 , px , py , 0);
2385 rc_t2f_v3f (arr, 0 , tex.t, px , py + Th, 0); 2378 arr.t2f_v3f (0 , tex.t, px , py + Th, 0);
2386 rc_t2f_v3f (arr, tex.s, tex.t, px + Tw, py + Th, 0); 2379 arr.t2f_v3f (tex.s, tex.t, px + Tw, py + Th, 0);
2387 rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0); 2380 arr.t2f_v3f (tex.s, 0 , px + Tw, py , 0);
2388 } 2381 }
2389 } 2382 }
2390 } 2383 }
2391 } 2384 }
2392 2385
2393 rc_draw (rc); 2386 rc.draw ();
2394 rc_clear (rc); 2387 rc.clear ();
2395 2388
2396 // go through all smoothlevels, lowest to highest, then draw. 2389 // go through all smoothlevels, lowest to highest, then draw.
2397 // this is basically counting sort 2390 // this is basically counting sort
2398 { 2391 {
2399 int w, b; 2392 int w, b;
2466 maptex tex = pl_tex; 2459 maptex tex = pl_tex;
2467 int px = pl_x + sdx; 2460 int px = pl_x + sdx;
2468 int py = pl_y + sdy; 2461 int py = pl_y + sdy;
2469 2462
2470 key.texname = tex.name; 2463 key.texname = tex.name;
2471 arr = rc_array (rc, &key); 2464 rc_t::array_t &arr = rc.array (key);
2472 2465
2473 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2466 arr.t2f_v3f (0 , 0 , px , py , 0);
2474 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2467 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); 2468 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); 2469 arr.t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2477 2470
2478 rc_draw (rc); 2471 rc.draw ();
2479 } 2472 }
2480 2473
2481 rc_draw (rc_ov); 2474 rc_ov.draw ();
2482 rc_clear (rc_ov); 2475 rc_ov.clear ();
2483 2476
2484 glDisable (GL_BLEND); 2477 glDisable (GL_BLEND);
2485 rc_free (rc);
2486 rc_free (rc_ov);
2487 2478
2488 // top layer: overlays such as the health bar 2479 // top layer: overlays such as the health bar
2489 for (y = 0; y < sh; y++) 2480 for (y = 0; y < sh; y++)
2490 if (0 <= y + my && y + my < self->rows) 2481 if (0 <= y + my && y + my < self->rows)
2491 { 2482 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines