The engine is designed to be extremely modular. Everything in the way of user extension is performed by compiled, cross-platform virtual machine bytecode modules. There are no flat file formats involved from the start; any that you want to use are read by VM modules. The "world" is basically just a collection of entities with various attributes. When the server starts, it runs the module server.xc, which is responsible for initializing all settings, including adding all entities to be present at the start, however it sees fit. Similarly, the client uses client.xc. Various events occur throughout execution and they are sent to one of these modules or to an entity's module, all of which have their main function declared as:
void main(int Event, int Arg1, int Arg2, int Arg3)
or a compatible declaration. A unique integer code for the event is passed first, along with up to 3 event-specific integer arguments, is passed to the program to be used like argc/argv are for conventional C programs. The module is called anew for each event and is not kept running. Additional string arguments are used by some events and can be retrieved with GetStringArg() or GetStringArg2().
All client events stream output to the server if connected.
CLIENT_INIT
Triggered when the client program is first started.
CLIENT_MOVE
Triggered when the client has altered the avatar's position, velocity, or other related property. This event should stream calls to the server to synchronize the changed values.
CLIENT_COMMAND
Triggered when the user types a line into the console text entry blank and presses return. This event should determine if the text contains a /command (the module may actually use another way of determining what is a command than checking for a leading slash if desired) and stream a call to Cmd() if so.
CLIENT_CLICK
Triggered when the user clicks on an entity. This should stream a call to Click() to the server.
CLIENT_OLOGON
Should stream InformAvatar() to let the server know to which other connection this client belongs.
EVENT_INIT
Triggered when the server program first starts. Should initialize all world settings.
EVENT_SHUTDOWN
Triggered just before closing the server program.
EVENT_LOGON
Triggered when a client connects requesting an input stream (server to client). Should call SetUser() if the logon is accepted or Quit() otherwise. Should associate the user with an avatar, possibly after creating a new one.
EVENT_OLOGON
Triggered when a client connects requesting an output stream (client to server). Should call SetOUser() if the logon is accepted or Quit() otherwise. Should associate the user with an avatar, possibly after creating a new one.
EVENT_LOGOFF
Triggered when a client's main input stream disconnects.
EVENT_REMOTE_INIT
Triggered streaming output to the client right after a successfull logon. Should initialize all world settings on the client side.
EVENT_PRE_SYNC, EVENT_POST_SYNC
Triggered streaming output to the client before and after a period where critical information is being transferred. Generally uses SetFreeze() to freeze physics during this time.
EVENT_CREATE
Triggered streaming output to the client to create a locally existent entity on the client side with a call to AddEntity() specifying the ID# and synchronize all appropriate entity properties.
EVENT_POST_LOGON
Triggered streaming output to the client after a succesfull input stream logon. Should set the client's avatar.
EVENT_WRITE_TEXT
Should stream a call to WriteText() with the given message.
EVENT_SYNC
Should stream updates on the status of the specified entity.
EVENT_CLOSE
Triggered to synchronize the removal of an entity by streaming a RemoveEntity() call to each client. It is triggered once streaming to each affected client.
EVENT_MODEL
Should stream a call to ModelEvent() with the given arguments.
EVENT_QUIT
Should stream a call to Quit() with the appropriate message.
All render events are run without streaming. Arg1 is always the ID# of the entity for whom the event is being called. EVENT_INIT and EVENT_CLOSE are called when the entity is created and removed, respectively. On the server side, EVENT_SYNC is called, streaming output to the client, when changeable entity state information should be set. All other events will be generated as results of the use of callback functions.
All control events are run without streaming. Arg1 is always the ID# of the entity for whom the event is being called. EVENT_INIT and EVENT_CLOSE are called when the entity is created and removed, respectively. EVENT_SYNC is called, streaming output to the client, when changeable entity state information should be set. All other events will be generated as results of the use of callback functions.
The following sections describe the host functions available to modules, organized by use. A vector is an array of 3 GLfloats and a matrix is a 4x4 array of GLfloats. The standard ANSI 9899-1990 libc functions are also available, though a handful of them knowingly malfunction. In particular, don't expect *printf/*scanf functions to work with floating point values.
SetArgs
__host__ SetArgs(__string__ char *str);
Sets str as the active entity's argument string.
AddEntity
__host__ __output__ AddEntity(__string__ char *render_mod, __string__ char *control_mod, __string__ char *arg, int id);
This function creates a new entity and returns the entity ID# on success or 0 on failure. render_mod and control_mod give the relative paths to the .xc-file modules to control the entity (server side only) or draw the entity and handle other client-side things, respectively. The arg can be used to pass additional information that these modules can retrieve with GetArg(). id should be -1 when creating a new entity, and it should be the ID# of an entity when this call is being streamed from the server to the client and the ID# must be the same in all places.
RemoveEntity
__host__ __output__ void RemoveEntity(void);
This function removes the currently selected entity.
OpenEnt
__host__ __output__ OpenEnt(int id, int mode);
This function attempts to open an entity in the specified mode. It returns 0 on success and nonzero on failure. Mode can be ACC_PUBLIC (reading "visible" properties), ACC_READ (reading all properties), or ACC_WRITE (complete access). At a given time, an entity can be opened in a read mode by any number of module instances, or it can be opened for write by one. If the module has enough access to open the entity but another module has opened it in a mode that precludes access, OpenEnt() blocks until the entity is closed by the other instance(s). Some server-level actions, i.e. those meant to be performed by "admin"-owned entities, require that you open and select entity #0, "the Server," for write.
CloseEnt
__host__ __output__ void CloseEnt(int id);
This function closes an entity opened with OpenEnt().
The following functions are available, declared without __output__ so that they may be run locally even in streamed execution. They function identically to their similarly named counterparts.
__host__ LocalOpenEnt(int, int);
__host__ LocalCloseEnt(int);
__host__ LocalSelectEnt(int);
__host__ LocalSelectComponent(int);
SetName
__host__ __output__ SetName(__string__ char *str);
Sets the name of the selected entity.
SelectComponent
__host__ __output__ SelectComponent(int id);
Selects the active component of the current entity, returning 0 if the id is valid or nonzero otherwise. Entities are made up of hierarchies of objects with both polygonal definitions for physics and collision detection and, on the client side only, lists of OpenGL commands to execute to draw the object. The polygonal data is hopefully much more simplistic than the drawn object and optimized for fast collision testing. The ID used by this function is initially returned by ColBegin() or ColNode(). Pass 0 for id to select the entity's base object.
SetMass
__host__ __output__ void SetMass(float mass);
Sets the mass of the active entity.
SetWalk
__host__ __output__ void SetWalk(float walk);
Sets the walk speed for the active entity.
SetRV
__host__ __output__ void SetRV(__sync__ vector rv);
Gets the active entity's RV array.
GetRenderActive
__host__ GetRenderActive(void);
Returns the RenderActive flag of the active entity.
SetGlobal
__host__ __output__ void SetGlobal(int val);
Sets the active entity's Global flag.
GetOwner
__host__ GetOwner(void);
Returns the user ID# of the active entity's owner.
SetOwner
__host__ __output__ SetOwner(int uid);
CalcZone
RequestUpdate
ColEnd
OpenGL rendering specification
The following standard OpenGL functions are available. The appropriate constants are all defined when 3d.h is included. Calling these functions adds the specified OpenGL call to the end of the list of calls used to draw the active component.
__host__ __output__ void glBegin(GLenum);
SetFreeze
GetWorldX, GetWorldY, GetWorldZ, GetVZoneSize
Click
LogText
ZoneText
MultVectorMatrix
MultMatrix
RotationMatrix
InformAvatar
The rest of the functions in this section are server only.
GetUname
SetUname
GetPass
SetPass
GetAcc
SetAcc
Copyright Adam Chlipala 2000
Sets the owner of the active entity to be the user with the given ID#. Returns 0 on success and nonzero on failure.
__host__ CalcZone(void);
Recalculates in which VZone the active entity is.
__host__ __output__ void RequestUpdate(void);
Requests that the server send updates on the active entity's status to clients that can "see" it.
__host__ ColEnd(void);
Ends the definition of a component. Returns 0 on success and nonzero on failure.
__host__ __output__ void glEnd(void);
__host__ __output__ void glVertex3f(GLfloat, GLfloat, GLfloat);
__host__ __output__ void glColor3f(GLfloat, GLfloat, GLfloat);
__host__ __output__ void glEnable(GLenum);
__host__ __output__ void glDisable(Glenum);
__host__ __output__ void glTexCoord2f(GLfloat, GLfloat);
__host__ __output__ void glNormal3f(GLfloat, GLfloat, GLfloat);
__host__ __output__ void glMaterialfv(GLenum, GLenum, GLfloat*);
__host__ __output__ void glMaterialf(GLenum, GLenum, GLfloat);
__host__ __output__ void SetFreeze(int val);
Sets the freeze status of the world.
__host__ float GetWorldX(void);
__host__ float GetWorldY(void);
__host__ float GetWorldZ(void);
__host__ float GetVZoneSize(void);
These functions retrieve the settings passed to SetWorldInfo.
__host__ __input__ void Click(int entity_id, int component_id);
Streamed to the server by a client to indicate a click on the given entity's component.
__host__ LogText(char *msg);
Writes msg to the local log.
__host__ ZoneText(__string__ char *msg);
Writes msg to the logs of all clients that can "see" the active entity, which is all clients for Global entities.
__host__ MultVectorMatrix(vector u, vector v, matrix m);
u = v * m
__host__ MultMatrix(matrix m, matrix n, matrix o);
m = n * o
__host__ RotationMatrix(matrix m, float x, float y, float z, float a);
Stores a rotation matrix of a degrees about the axis (x, y, z) in m.
__host__ __output__ void InformAvatar(int id);
Streamed client to server to let the server know what avatar the user has been previously assigned when making additional connections beyond the first.
Sync
__host__ __output__ __input__ Sync(void);
Creates a pause that continues execution when the machine to which code is being streamed has acknowledged the Sync() request.
__host__ GetUname(int uid, char *str);
Stores the specified user's name in str.
__host__ SetUname(int uid, char *str);
Sets the specified user's name to str.
__host__ GetPass(int uid, char *str);
Stores the specified user's password in str.
__host__ SetPass(int uid, char *str);
Sets the specified user's password to str.
__host__ GetAcc(int uid);
Returns the specified user's access level.
__host__ SetAcc(int uid, int acc);
Sets the specified user's access level to acc.