[airstrike] Notes on aiming, generators and triggers

Eero Tamminen eero.tamminen at netsonic.fi
Sun Jan 9 13:27:59 EST 2005


Hi,

(I'm CC'ing this to list in case somebody else is interested)

> How about this for a "class" foundation (we can add messages to
> object_type as we wish):
>
> typedef struct object_type object_type_t;
> typedef struct object object_t;
> typedef struct objref objref_t; /* Use this when storing references to
> objects */
>
> /* Register a new object type ("class"), with a name
>    and a function to free the data of each object */
> object_type_t *obj_new_type(const char *name, void (*free)(void *));
> /* Create an object wrapping data, of the give type */
> object_t *obj_new(void *data, object_type_t *type);
>
> /* Make the reference point to NULL. Needed every time a
>    reference variable is created */
> void obj_refinit(objref_t *ref);
>
> /* Make ref point to object, and increase the object refcount.
>    It's not allowed to use this if the reference is not pointing
>    to NULL. */
> void obj_ref(objref_t *ref, object_t *object);
>
> /* Release the reference and points the reference to NULL. Ok to
>    call on ref's which point to NULL. */
> void obj_deref(objref_t *ref);
>
> /* Check if ref references a valid object, in that case return a
>    pointer to the object. If the object is dead then deref. */
> object_t *obj_access(objref_t *ref);
>
> /* Free the data wrapped by obj, and keep only the object struct
>    if it's referenced in other places. Future calls to obj_access
>    will return null. */
> void obj_kill(object_t *obj);
>
> /* Return the object type */
> object_type_t *obj_type(object_t *obj);
>
> /* Return the wrapped data. The idea is to add i.e.
>    sprite_t *obj_as_sprite(object_t *obj); which does type checking as
> needed. */
> void *obj_as_void(object_t *obj);
>
> /* Print statistics on stderr */
> void obj_print_stats(void);

If I've understood above correctly, this looks good to me. :-)


> ---- The struct internals: -----
>
> struct object_type
> {
>   const char *name;
>   void (*free)(void *data);
>   int nr_created;
>   int nr_freed;
>   struct object_type *next; /* This is just for an internal list of types
> */ /* We can add more things here of course, since each type is created
> only once */
> };

I'd like counts on creates and kills on each level, I guess kills
corresponds to frees with a little delay if there are multiple refs?


> struct object
> {
>   void *data;
>   struct object_type *type;
>   int refcount;
> };
>
> struct objref
> {
>   struct object *object;
> };
>
> Btw, I added aerodynamics for the bomb, it looks less stupid that way.

Thanks, it *did* look a bit stupid... :)

Have you any comments on the plane dying I mailed about earlier?


	- Eero



More information about the airstrike mailing list