--- deliantra/server/include/cfperl.h 2006/08/26 08:44:06 1.6 +++ deliantra/server/include/cfperl.h 2006/08/26 23:36:32 1.7 @@ -8,6 +8,9 @@ struct object; struct mapstruct; +void cfperl_init (); +void cfperl_main (); + // could have used templates, but a more traditional C api // uses more explicit typing which is ok for this purpose. enum data_type @@ -24,11 +27,7 @@ DT_ARCH, DT_PARTY, DT_REGION, - - // following are only for cfapi-compatibility - DT_INT_PTR, - DT_INT64_PTR, - DT_DOUBLE_PTR, + DT_AV, // av that needs to be flattened out }; enum event_klass @@ -41,7 +40,7 @@ enum event_type { -# define def(klass,name) EV_ ## klass ## _ ## name, +# define def(klass,name) EVENT_ ## klass ## _ ## name, # include "eventinc.h" # undef def NUM_EVENT_TYPES @@ -62,13 +61,20 @@ // the ", ## __VA_ARGS" is, unfortunately, a gnu-cpp extension // all these return true when the normal event processing should be skipped (if any) -#define INVOKE(klass, event, ...) cfperl_invoke (EV_ ## klass ## _ ## event, ## __VA_ARGS__, DT_END) +#define INVOKE(klass, event, ...) cfperl_invoke (EVENT_ ## klass ## _ ## event, ## __VA_ARGS__, DT_END) #define INVOKE_GLOBAL(event, ...) INVOKE (GLOBAL, event, ## __VA_ARGS__) #define INVOKE_OBJECT(event, op, ...) INVOKE (OBJECT, event, ARG_OBJECT (op), ## __VA_ARGS__) #define INVOKE_PLAYER(event, pl, ...) INVOKE (PLAYER, event, ARG_PLAYER (pl), ## __VA_ARGS__) #define INVOKE_MAP(event, map, ...) INVOKE (MAP , event, ARG_MAP (map) , ## __VA_ARGS__) +//TODO should index into @result +#define RESULT(idx,type) cfperl_result_ ## type (idx) +#define RESULT_INT(idx) RESULT(idx, INT) + +bool cfperl_invoke (event_type event, ...); +int cfperl_result_INT (int idx); + struct extendable_base { void *self, *cb; // CF+ perl self and callback @@ -77,8 +83,6 @@ void clear (); // called when free'ing objects void optimise (); // possibly save some memory by destroying unneeded data void reattach (data_type type, void *self); // called after swapin - void instantiate (data_type type, void *self); // called on first instantiation - void clone (data_type type, void *self, void *dest); }; // objects extendable from perl (or any other extension) should include or @@ -87,19 +91,6 @@ template struct extendable : extendable_base { - void clear () - { - if (self || cb) - extendable_base::clear (); - } - void instantiate () - { - if (attach) - extendable_base::instantiate ( - static_cast(this)->get_dt (), - static_cast(this) - ); - } void reattach () { if (attach) @@ -108,22 +99,26 @@ static_cast(this) ); } - void clone (subclass *destination) - { - if (self || cb) - extendable_base::clone ( - static_cast(this)->get_dt (), - static_cast(this), - destination - ); - } }; -bool cfperl_invoke (event_type event, ...); -void cfperl_free_ob (struct object *op); +struct object_freezer +{ + const char *filename; + void *av; -void cfperl_init (); -void cfperl_main (); + object_freezer (const char *filename) : filename (filename) { } + void put (extendable_base *object); + void finish (); +}; + +struct object_thawer +{ + void *av; + + object_thawer (const char *filename); + void get (extendable_base *object); + void finish (); +}; #endif