Conitec 3d gamestudio-source development 用户手册

下载
页码 21
3D Gamestudio Programmer's Manual
                        
© Conitec July 2002
                       8
// rolls the given entity by 180 degrees
DLLFUNC fixed FlipUpsideDown(long entity)
{
if (!entity) return 0;
// retrieve the pointer to the given entity
A4_ENTITY *ent = (A4_ENTITY *)entity;
// set the entity's roll angle to 180 degrees
ent->roll = FLOAT2FIX(180);
return 0;
}
This would be called by C-Script through
FlipUpsideDown(my)
. For controlling entities totally
through a DLL – for instance, when you intend to write your whole game in C++ or Delphi,
instead of C-Script – C-Script dummy actions can be assigned to the entity, like this:
var appdll_handle;
dllfunction dll_entmain(entity);
dllfunction dll_entevent(entity);
function main()
{
// open the application DLL
appdll_handle = dll_open("myapp.dll");
...
}
action myent_event {
dll_handle = appdll_handle;
dll_entevent(my);
// this DLL function handles all entity events
}
action myentity {
my.event = myent_event;
while(1) {
dll_handle = appdll_handle;
dll_entmain(my); // this DLL function controls the entity
wait(1);
}
}
C-Script object and DLL interface structures
Pointers to C-Script objects can be transferred to DLL functions, thus allowing object
manipulation. The internal engine format of the basic C-Script objects (
A4_ENTITY
,
A4_PARTICLE
A4_BMAP
A4_TEX
 etc.) is defined in the
 a5dll.h
 file. 
Interface structs are handed over to the DLL for accessing engine variables and pointers, which
are also defined in the 
a5dll.h
:
typedef struct {
long dll_version;
// The version is automatically tested against A5DLL_VERSION
// on opening the DLL. DLLs work with engines with the same or a higher
// version number, but not with a lower version engine.
WDL_INTERFACE
*wdl; // access to MY and YOU pointers
FRAME_INTERFACE *fb;
// access to the frame buffer and the Direct3D Device
DX_INTERFACE
*dx;
// access to directx pointers
ENGINE_INTERFACE *eng; // access to engine functions
} A5_INTERFACE;