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.337 by root, Thu Nov 12 01:11:52 2009 UTC vs.
Revision 1.345 by root, Sat Jan 16 13:41:37 2010 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de>
6 * 5 *
7 * Deliantra is free software: you can redistribute it and/or modify it under 6 * Deliantra is free software: you can redistribute it and/or modify it under
8 * the terms of the Affero GNU General Public License as published by the 7 * the terms of the Affero GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your 8 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version. 9 * option) any later version.
29 28
30#include <cstdarg> 29#include <cstdarg>
31#include <typeinfo> 30#include <typeinfo>
32 31
33#include "global.h" 32#include "global.h"
34#include "loader.h"
35#include "../random_maps/random_map.h" 33#include "../random_maps/random_map.h"
36#include "evthread.h" 34#include "evthread.h"
37#include "sproto.h" 35#include "sproto.h"
38 36
39#include <unistd.h> 37#include <unistd.h>
97 *cv_cf_client_send_msg, 95 *cv_cf_client_send_msg,
98 *cv_cf_tick, 96 *cv_cf_tick,
99 *cv_cf_match_match; 97 *cv_cf_match_match;
100 98
101#ifndef newSVpv_utf8 99#ifndef newSVpv_utf8
102static inline SV * 100static SV *
103newSVpv_utf8 (const char *s) 101newSVpv_utf8 (const char *s)
104{ 102{
105 if (!s) 103 if (!s)
106 return newSV (0); 104 return newSV (0);
107 105
110 return sv; 108 return sv;
111} 109}
112#endif 110#endif
113 111
114#ifndef newSVpvn_utf8 112#ifndef newSVpvn_utf8
115static inline SV * 113static SV *
116newSVpvn_utf8 (const char *s, STRLEN l, int utf8) 114newSVpvn_utf8 (const char *s, STRLEN l, int utf8)
117{ 115{
118 if (!s) 116 if (!s)
119 return newSV (0); 117 return newSV (0);
120 118
124 SvUTF8_on (sv); 122 SvUTF8_on (sv);
125 123
126 return sv; 124 return sv;
127} 125}
128#endif 126#endif
127
128static noinline utf8_string
129cfSvPVutf8_nolen (SV *sv)
130{
131 SvGETMAGIC (sv);
132
133 if (SvPOK (sv))
134 {
135 if (!SvUTF8 (sv))
136 sv_utf8_upgrade_nomg (sv);
137
138 return SvPVX (sv);
139 }
140
141 return SvPV_nolen (sv);
142}
129 143
130// helper cast function, returns super class * or 0 144// helper cast function, returns super class * or 0
131template<class super> 145template<class super>
132static super * 146static super *
133is_a (attachable *at) 147is_a (attachable *at)
402 hv_clear ((HV *)sv); 416 hv_clear ((HV *)sv);
403 sv_unmagic (sv, PERL_MAGIC_ext); 417 sv_unmagic (sv, PERL_MAGIC_ext);
404} 418}
405#endif 419#endif
406 420
407static long SvPTR_nc (SV *sv) 421static long
422SvPTR_nc (SV *sv)
408{ 423{
409 sv = SvRV (sv); 424 sv = SvRV (sv);
410 425
411 // very important shortcut 426 // very important shortcut
412 if (expect_true (SvMAGIC (sv)->mg_type == PERL_MAGIC_ext)) 427 if (expect_true (SvMAGIC (sv) && SvMAGIC (sv)->mg_type == PERL_MAGIC_ext))
413 return (long)SvMAGIC (sv)->mg_ptr; 428 return (long)SvMAGIC (sv)->mg_ptr;
414 429
415 if (MAGIC *mg = mg_find (sv, PERL_MAGIC_ext)) 430 if (MAGIC *mg = mg_find (sv, PERL_MAGIC_ext))
416 return (long)mg->mg_ptr; 431 return (long)mg->mg_ptr;
417 432
470 485
471 if (!SvROK (sv) 486 if (!SvROK (sv)
472 || (SvSTASH (SvRV (sv)) != stash_cf_player_wrap 487 || (SvSTASH (SvRV (sv)) != stash_cf_player_wrap
473 && !sv_derived_from (sv, "cf::player"))) 488 && !sv_derived_from (sv, "cf::player")))
474 croak ("object of type cf::player expected"); 489 croak ("object of type cf::player expected");
475
476 if (SvSTASH (SvRV (sv)) != stash_cf_player_wrap)
477 printf ("unexpected stash %s:%s\n", HvNAME(SvSTASH(SvRV(sv))));//D
478
479 490
480 return SvPTR_nc (sv); 491 return SvPTR_nc (sv);
481} 492}
482 493
483static inline SV *to_sv (const shstr & v) { return newSVpvn_utf8 ((const char *)v, v.length (), 1); } 494static inline SV *to_sv (const shstr & v) { return newSVpvn_utf8 ((const char *)v, v.length (), 1); }
532 SV *sv = to_sv (static_cast<dynbuf *> (v)); 543 SV *sv = to_sv (static_cast<dynbuf *> (v));
533 SvUTF8_on (sv); 544 SvUTF8_on (sv);
534 return sv; 545 return sv;
535} 546}
536 547
537static inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPVutf8_nolen (sv) : 0; } 548static inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? cfSvPVutf8_nolen (sv) : 0; }
538static inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } 549static inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; }
539static inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } 550static inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); }
540static inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } 551static inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); }
541static inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } 552static inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); }
542static inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } 553static inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); }
1237 1248
1238 return retval; 1249 return retval;
1239} 1250}
1240 1251
1241void 1252void
1242log_backtrace (const char *msg) 1253log_backtrace (const_utf8_string msg)
1243{ 1254{
1244#if HAVE_BACKTRACE 1255#if HAVE_BACKTRACE
1245 void *addr [20]; 1256 void *addr [20];
1246 int size = backtrace (addr, 20); 1257 int size = backtrace (addr, 20);
1247 1258
2550 for (int x = 0; x < THIS->width; ++x) 2561 for (int x = 0; x < THIS->width; ++x)
2551 for (int y = 0; y < THIS->height; ++y) 2562 for (int y = 0; y < THIS->height; ++y)
2552 { 2563 {
2553 for (object *op = THIS->at (x, y).bot; op; op = op->above) 2564 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2554 if (op->flag [FLAG_IS_FLOOR]) 2565 if (op->flag [FLAG_IS_FLOOR])
2555 goto skip_space; 2566 goto skip;
2556 2567
2557 { 2568 {
2558 int offs = offset + y * stride + x; 2569 int offs = offset + y * stride + x;
2570
2559 if (IN_RANGE_EXC (offs, 0, idxlen)) 2571 if (IN_RANGE_EXC (offs, 0, idxlen))
2560 { 2572 {
2561 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2573 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2562 { 2574 {
2563 object *ob = get_archetype (SvPVutf8_nolen (*elem)); 2575 object *ob = get_archetype (cfSvPVutf8_nolen (*elem));
2564 ob->flag [FLAG_NO_MAP_SAVE] = true; 2576 ob->flag [FLAG_NO_MAP_SAVE] = true;
2565 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2577 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2566 2578
2567 if (ob->randomitems) 2579 if (ob->randomitems && !ob->above)
2568 { 2580 {
2569 if (!ob->above)
2570 {
2571 ob->create_treasure (ob->randomitems); 2581 ob->create_treasure (ob->randomitems);
2572 2582
2573 for (object *op = ob->above; op; op = op->above) 2583 for (object *op = ob->above; op; op = op->above)
2574 op->flag [FLAG_NO_MAP_SAVE] = true; 2584 op->flag [FLAG_NO_MAP_SAVE] = true;
2575 } 2585 // TODO: if this is a pickable object, then the item
2576 2586 // will at a bit weird - saving inside the player
2577 ob->randomitems = 0; 2587 // will clear the flag, but when the player drops
2588 // it without logging out, it keeps the flag.
2589 // nobody ahs reported this, but this can be rather
2590 // annoying on persistent maps.
2578 } 2591 }
2579 } 2592 }
2580 } 2593 }
2581 } 2594 }
2582 2595
2583 skip_space: ; 2596 skip: ;
2584 } 2597 }
2585} 2598}
2586 2599
2587void 2600void
2588maptile::set_regiondata (SV *data, int offset, int stride, SV *palette) 2601maptile::set_regiondata (SV *data, int offset, int stride, SV *palette)
2598 2611
2599 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; 2612 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2600 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2613 uint8_t *regions = salloc<uint8_t> (THIS->size ());
2601 2614
2602 for (int i = av_len ((AV *)palette) + 1; i--; ) 2615 for (int i = av_len ((AV *)palette) + 1; i--; )
2603 regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); 2616 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2604 2617
2605 for (int y = 0; y < THIS->height; ++y) 2618 for (int y = 0; y < THIS->height; ++y)
2606 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); 2619 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width);
2607 2620
2608 sfree (THIS->regions, THIS->size ()); 2621 sfree (THIS->regions, THIS->size ());
2833archetype *archetypes (U32 index) 2846archetype *archetypes (U32 index)
2834 CODE: 2847 CODE:
2835 RETVAL = index < archetypes.size () ? archetypes [index] : 0; 2848 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2836 OUTPUT: RETVAL 2849 OUTPUT: RETVAL
2837 2850
2838object *instantiate (archetype *arch)
2839 CODE:
2840 RETVAL = arch_to_object (arch);
2841 OUTPUT:
2842 RETVAL
2843
2844INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h | 2851INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h |
2845 2852
2846MODULE = cf PACKAGE = cf::party 2853MODULE = cf PACKAGE = cf::party
2847 2854
2848partylist *first () 2855partylist *first ()
3008 faceinfo *f = face_info (idx); assert (f); 3015 faceinfo *f = face_info (idx); assert (f);
3009 facedata *d = &(faceset ? f->data64 : f->data32); 3016 facedata *d = &(faceset ? f->data64 : f->data32);
3010 sv_to (data, d->data); 3017 sv_to (data, d->data);
3011 STRLEN clen; 3018 STRLEN clen;
3012 char *cdata = SvPVbyte (chksum, clen); 3019 char *cdata = SvPVbyte (chksum, clen);
3013 clen = min (CHKSUM_SIZE, clen); 3020 clen = min (CHKSUM_MAXLEN, clen);
3014 3021
3022 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
3023
3015 if (memcmp (d->chksum, cdata, clen)) 3024 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
3016 { 3025 {
3026 d->chksum_len = clen;
3017 memcpy (d->chksum, cdata, clen); 3027 memcpy (d->chksum, cdata, clen);
3018 3028
3019 // invalidate existing client face info 3029 // invalidate existing client face info
3020 for_all_clients (ns) 3030 for_all_clients (ns)
3021 if (ns->faceset == faceset) 3031 if (ns->faceset == faceset)
3036 3046
3037SV *get_chksum (faceidx idx, int faceset = 0) 3047SV *get_chksum (faceidx idx, int faceset = 0)
3038 CODE: 3048 CODE:
3039 facedata *d = face_data (idx, faceset); 3049 facedata *d = face_data (idx, faceset);
3040 if (!d) XSRETURN_UNDEF; 3050 if (!d) XSRETURN_UNDEF;
3041 RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE); 3051 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
3042 OUTPUT: 3052 OUTPUT:
3043 RETVAL 3053 RETVAL
3044 3054
3045SV *get_data (faceidx idx, int faceset = 0) 3055SV *get_data (faceidx idx, int faceset = 0)
3046 CODE: 3056 CODE:
3091 } 3101 }
3092 else 3102 else
3093 anim = &animation::create (name, av_len (av) + 1, facings); 3103 anim = &animation::create (name, av_len (av) + 1, facings);
3094 3104
3095 for (int i = 0; i < anim->num_animations; ++i) 3105 for (int i = 0; i < anim->num_animations; ++i)
3096 anim->faces [i] = face_find (SvPVutf8_nolen (*av_fetch (av, i, 1))); 3106 anim->faces [i] = face_find (cfSvPVutf8_nolen (*av_fetch (av, i, 1)));
3097} 3107}
3098 OUTPUT: RETVAL 3108 OUTPUT: RETVAL
3099 3109
3100void invalidate_all () 3110void invalidate_all ()
3101 CODE: 3111 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines