VgaGames4

VgaGames4 - object man-pages

[.. upper level ..]

# vg4->object->mgmt_create()

Create an object-management for an object.

SYNTAX
struct VG_ObjMgmt * vg4->object->mgmt_create(const char *objid)
FUNCTION PARAMETERS

objid | Object-ID

RETURN VALUE
Returns created object-management
DESCRIPTION
Create an object-management for an object. An object-management is mainly used for creating and destroying object-instances of an object. The functions of the returned object-management must be set individually. Not all functions must exist, their values may remain NULL: - f_free() is used for individual freeing if needed will be called from vg4->object->mgmt_destroy() - f_run() is used to manage object-instances will be called from vg4->object->call_mgmt_run() - f_data() is used to exchange data of the object-management will be called from vg4->object->call_mgmt_data()
EXAMPLE

    obj-otest_mgmt.c

    /* object-management for "OTEST" */
    #define OBJID "OTEST"

    /* internal data */
    struct {
      int nr_max, nr_curr;
    } mgmt_data;

    void new_OTEST_mgmt(int);

    static void f_run(void *);
    static int f_data(void *, void *);

    /* export-function to create a new object-management for object "OTEST" */
    void
    new_OTEST_mgmt(int max)
    {
      struct VG_ObjMgmt *omgmt;

      /* create object-management */
      omgmt = vg4->object->mgmt_create(OBJID);
      /* set functions */
      /* f_free() is not needed here */
      omgmt->f_data = mgmt_f_data;
      omgmt->f_run = mgmt_f_run;

      /* set internal data */
      mgmt_data.nr_max = max;
      mgmt_data.nr_curr = 0;
    }

    /* manage object-management, called from vg4->object->call_mgmt_run() */
    static void
    f_run(void *vgame)
    {
      /* if current number of object-instances is less then required, create a new one */
      if (mgmt_data.nr_curr < mgmt_data.nr_max) {
        /* create a new object-instance */
        [...]
        mgmt_data.nr_curr++;
      }
    }

    /* exchange data of the object-management, called from vg4->object->call_mgmt_data() */
    static int
    f_data(void *vgame, void *vptr)
    {
      /* we just want to return the number of current object-instances */
      return mgmt_data.nr_curr;
    }

    game.c

    /* create new object-management of object "OTEST" */
    new_OTEST_mgmt(30);