ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/cfperl.xs
(Generate patch)

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.402 by root, Sun May 1 13:18:24 2011 UTC vs.
Revision 1.405 by root, Wed May 4 19:04:45 2011 UTC

67static int tick_inhibit; 67static int tick_inhibit;
68static int tick_pending; 68static int tick_pending;
69 69
70global gbl_ev; 70global gbl_ev;
71static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; 71static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map;
72static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now; 72static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now, *sv_server_tick;
73static AV *av_reflect; 73static AV *av_reflect;
74 74
75bitset<NUM_EVENT_TYPES> ev_want_event; 75bitset<NUM_EVENT_TYPES> ev_want_event;
76bitset<NUM_TYPES> ev_want_type; 76bitset<NUM_TYPES> ev_want_type;
77 77
1404 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1404 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1405 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1405 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1406 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); 1406 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1407 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); 1407 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1408 1408
1409 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1409 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1410 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); 1410 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1411 sv_server_tick = get_sv ("cf::SERVER_TICK", 1); SvUPGRADE (sv_server_tick, SVt_IV);
1411 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1412 sv_tick_start = get_sv ("cf::TICK_START" , 1); SvUPGRADE (sv_tick_start , SVt_NV);
1412 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); 1413 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1413 1414
1414 cb_global = get_av ("cf::CB_GLOBAL", 1); 1415 cb_global = get_av ("cf::CB_GLOBAL", 1);
1415 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1416 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1416 cb_object = get_av ("cf::CB_OBJECT", 1); 1417 cb_object = get_av ("cf::CB_OBJECT", 1);
1417 cb_player = get_av ("cf::CB_PLAYER", 1); 1418 cb_player = get_av ("cf::CB_PLAYER", 1);
1486 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1487 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1487 1488
1488 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) 1489 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE)
1489 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) 1490 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY)
1490 1491
1491 const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING)
1492 const_iv (MAP_INACTIVE)
1493
1494 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) 1492 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT)
1495 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) 1493 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1496 1494
1497 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1495 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1498 1496
1613 { 1611 {
1614 ev_async_send (EV_DEFAULT, &tick_watcher); 1612 ev_async_send (EV_DEFAULT, &tick_watcher);
1615 coroapi::cede (); 1613 coroapi::cede ();
1616 } 1614 }
1617 1615
1618void server_tick () 1616void one_tick ()
1619 CODE: 1617 CODE:
1620{ 1618{
1621 ev_now_update (EV_DEFAULT); 1619 ev_now_update (EV_DEFAULT);
1622 NOW = ev_now (EV_DEFAULT); 1620 NOW = ev_now (EV_DEFAULT);
1623 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1621 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1624 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1622 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1625 runtime = SvNVX (sv_runtime); 1623 runtime = SvNVX (sv_runtime);
1626 1624
1625 one_tick ();
1626
1627 server_tick (); 1627 ++server_tick;
1628 SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick);
1628 1629
1629 ev_now_update (EV_DEFAULT); 1630 ev_now_update (EV_DEFAULT);
1630 NOW = ev_now (EV_DEFAULT); 1631 NOW = ev_now (EV_DEFAULT);
1631 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1632 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1633
1632 runtime += TICK; 1634 runtime += TICK;
1633 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1635 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1634} 1636}
1635 1637
1636NV floor (NV x) 1638NV floor (NV x)
2103# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2105# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2104 2106
2105object *new (utf8_string archetype = 0) 2107object *new (utf8_string archetype = 0)
2106 PROTOTYPE: ;$ 2108 PROTOTYPE: ;$
2107 CODE: 2109 CODE:
2108 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2110 RETVAL = archetype
2111 ? archetype::get (archetype)
2112 : object::create ();
2109 OUTPUT: 2113 OUTPUT:
2110 RETVAL 2114 RETVAL
2111 2115
2112object *generate (utf8_string arch, object *creator) 2116object *generate (utf8_string arch, object *creator)
2113 CODE: 2117 CODE:
2114 object *obj = get_archetype (arch); 2118 object *obj = archetype::get (arch);
2115 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2119 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2116 RETVAL = obj; 2120 RETVAL = obj;
2117 OUTPUT: 2121 OUTPUT:
2118 RETVAL 2122 RETVAL
2119 2123
2357 for_all_players (pl) 2361 for_all_players (pl)
2358 if (pl->ob && pl->ob->map == THIS) 2362 if (pl->ob && pl->ob->map == THIS)
2359 PUSHs (sv_2mortal (to_sv (pl->ob))); 2363 PUSHs (sv_2mortal (to_sv (pl->ob)));
2360 } 2364 }
2361 2365
2362#if 0
2363
2364void 2366void
2365maptile::add_quadland (int mx, int my, int mz, SV *biome_map, SV *biome_plt) 2367maptile::gen_quadmap (int x, int y, int z)
2366 CODE: 2368 CODE:
2367{ 2369 gen_quadmap (THIS, x * 50, y * 50, z);
2368 static frac_gen<vec2d> frac;
2369 2370
2371void
2372maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2373 CODE:
2374{
2370 if (!SvROK (biome_plt) || SvTYPE (SvRV (biome_plt)) != SVt_PVAV) 2375 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2371 croak ("maptile::add_quadland: biome_plt must be arrayref"); 2376 croak ("maptile::add_underlay: palette must be arrayref");
2372 2377
2373 biome_plt = SvRV (biome_plt); 2378 palette = SvRV (palette);
2374 2379
2380 STRLEN idxlen;
2375 const uint8_t *bmap = (const uint8_t *)SvPVbyte_nolen (biome_map); 2381 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2376 2382
2377 for (int x = 0; x < THIS->width; ++x) 2383 for (int x = 0; x < THIS->width; ++x)
2378 for (int y = 0; y < THIS->height; ++y) 2384 for (int y = 0; y < THIS->height; ++y)
2379 { 2385 {
2380 for (object *op = THIS->at (x, y).bot; op; op = op->above) 2386 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2381 if (op->flag [FLAG_IS_FLOOR]) 2387 if (op->flag [FLAG_IS_FLOOR])
2382 goto skip; 2388 goto skip;
2383 2389
2384 { 2390 {
2385 float fx = mx * THIS->width + x;
2386 float fy = my * THIS->height + y;
2387
2388 int temp = clamp (int (32 * frac.fBm (vec2d (fx * 0.001, fy * 0.001), 2) ) - 8, 0, 15);
2389 int rain = clamp (int (16 * frac.ridgedmultifractal (vec2d (fx * 0.01, fy * 0.01), 3, 1.03, 2)) - 8, 0, 15);
2390
2391 rain = lerp (rain, 0, 15, 0, temp);
2392 printf ("rain %d\n", temp);//D
2393
2394 int biome = bmap [rain * 16 + temp];
2395
2396 //printf ("%2d %2d => %s\n", temp, rain, SvPV_nolen (AvARRAY ((AV *)biome_plt)[biome]));//D
2397#if 1
2398 if (SV **elem = av_fetch ((AV *)biome_plt, bmap [rain * 16 + temp], 0))
2399 {
2400 object *ob = get_archetype (cfSvPVutf8_nolen (*elem));
2401 ob->flag [FLAG_NO_MAP_SAVE] = true;
2402 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2403
2404 if (ob->randomitems && !ob->above)
2405 {
2406 ob->create_treasure (ob->randomitems);
2407
2408 for (object *op = ob->above; op; op = op->above)
2409 op->flag [FLAG_NO_MAP_SAVE] = true;
2410 }
2411 }
2412#endif
2413 }
2414 skip: ;
2415 }
2416}
2417
2418#endif
2419
2420void
2421maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2422 CODE:
2423{
2424 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2425 croak ("maptile::add_underlay: palette must be arrayref");
2426
2427 palette = SvRV (palette);
2428
2429 STRLEN idxlen;
2430 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2431
2432 for (int x = 0; x < THIS->width; ++x)
2433 for (int y = 0; y < THIS->height; ++y)
2434 {
2435 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2436 if (op->flag [FLAG_IS_FLOOR])
2437 goto skip;
2438
2439 {
2440 int offs = offset + y * stride + x; 2391 int offs = offset + y * stride + x;
2441 2392
2442 if (IN_RANGE_EXC (offs, 0, idxlen)) 2393 if (IN_RANGE_EXC (offs, 0, idxlen))
2443 { 2394 {
2444 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2395 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2445 { 2396 {
2446 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2397 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2447 ob->flag [FLAG_NO_MAP_SAVE] = true; 2398 ob->flag [FLAG_NO_MAP_SAVE] = true;
2448 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2399 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2449 2400
2450 if (ob->randomitems && !ob->above) 2401 if (ob->randomitems && !ob->above)
2451 { 2402 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines