db.h
teeny/includes/db.h · 4.3 KB
From the archive TeenyMUD-1.3.tar.gz
Download the archive « Back to the archive contents
/* db.h */
/*
* Basic structs and stuff for TeenyMUD
*/
struct dsc; /* Forward */
struct obj_data
{
/* The usual ints and dbref-ish ints */
int pennies;
int loc;
/* This also holds the destination of an exit. Do NOT change this. */
/* home_dropto is now memory resident */
/* owner is now memory resident */
int contents;
int exits;
#ifdef TIMESTAMPS
int timestamp; /* This will be in minutes into the epoch */
#endif
/* This is an array of ints */
int *lock;
/* These are the usual zero terminated strings. */
char *suc;
char *osuc;
char *fail;
char *ofail;
#ifdef DROP_FIELDS
char *drop;
char *odrop;
#endif
char *desc;
char *gender;
/* for use by the caching system */
struct dsc *descriptor;
struct obj_data *fwd;
struct obj_data *back;
/* Stow the current offset of where the disk version lives */
/* and size of this disk chunk here. Only disk.c knows about these */
long offset;
long chunk_size;
};
/*
* A little union to point at either in-memory or on-disk data, or even a
* live object descriptor.
*
*/
struct net_handle; /* Forward */
union raw_data
{
struct obj_data *data; /* If in cache, or... */
long chunk; /* .. on disk */
};
/*
* A typical memory resident descriptor. If it describes an actual object, it
* will be referenced by the main object index array, and the name field of
* the ptr union will be meaningful. If it describes a free chunk, the next
* field will be. We do it this way so objects can conveniently be destroyed.
*
*/
struct dsc
{
int flags;
int owner;
int home_dropto; /* Also destination for exits */
int size; /* Size on disk. */
int list_next; /* Used for exits/contents lists */
union
{
char *name; /* If describing real data, or.. */
struct dsc *next; /* .. a free chunk/descriptor */
} ptr;
union raw_data where; /* The actual data for the thing */
};
/*
* For reaching in to a descriptor.
*/
#define StickyP(a) ((a)->flags & STICKY)
#define WizP(a) ((a)->flags & WIZARD)
#define TempleP(a) ((a)->flags & TEMPLE)
#define LinkOkP(a) ((a)->flags & LINK_OK)
#define HavenP(a) ((a)->flags & HAVEN)
#define JumpOkP(a) ((a)->flags & JUMP_OK)
#define AbodeP(a) ((a)->flags & ABODE)
#define ResidentP(a) ((a)->flags & IN_MEMORY)
#define DirtyP(a) ((a)->flags & DIRTY)
#define AliveP(a) ((a)->flags & ALIVE)
#define PlayerP(a) (((a)->flags & TYPE_MASK) == TYP_PLAYER)
#define ThingP(a) (((a)->flags & TYPE_MASK) == TYP_THING)
#define RoomP(a) (((a)->flags & TYPE_MASK) == TYP_ROOM)
#define ExitP(a) (((a)->flags & TYPE_MASK) == TYP_EXIT)
#define DSC_NAME(a) (((a)->ptr).name)
#define DSC_CHUNK(a) (((a)->where).chunk)
#define DSC_DATA(a) (((a)->where).data)
#define DSC_SIZE(a) ((a)->size)
#define DSC_FLAGS(a) ((a)->flags)
#define DSC_OWNER(a) ((a)->owner)
#define DSC_HOME(a) ((a)->home_dropto)
#define DSC_DROPTO(a) ((a)->home_dropto)
#define DSC_DESTINATION(a) ((a)->home_dropto)
#define DSC_NEXT(a) ((a)->list_next)
/*
* This is the very largest an object can be on disk. We have to watch out
* for things growing too big (mostly in locks and contents lists).
*/
#define MAX_DISK_SIZE 5608
/*
* Initial size of an object (a *total* grey box). One int each for: pennies,
* location, exits, contents, One int for a blank lock (a -1 on disk), A \0
* on disk for each of the empty strings suc, osuc, fail, ofail, desc, etc.
*
*/
#ifdef TIMESTAMPS
#ifdef DROP_FIELDS
#define INITIAL_SIZE (6 * sizeof(int)) + 8
#else
#define INITIAL_SIZE (6 * sizeof(int)) + 6
#endif
#else
#ifdef DROP_FIELDS
#define INITIAL_SIZE (5 * sizeof(int)) + 8
#else
#define INITIAL_SIZE (5 * sizeof(int)) + 6
#endif
#endif
/*
* Tuning variables -- how much to grow the index by when you run out of
* space for more entries, and how much slack space to start with when you
* bring up an existing database. Ideally, SLACK is the number of objects
* that will be created between start time, and when you bring it down, so
* you never actually run out of index space.
*/
#define GROWTH_INCREMENT 1024
#define SLACK 512