Conitec 3d gamestudio-source development Manuel D’Utilisation

Page de 21
3D Gamestudio Programmer's Manual
                        
© Conitec July 2002
                       4
The A5 DLL interface
DLLs can be used as extensions (plugins) to the engine and to the C-Script language, as well as
for programming a game totally in C++ or Delphi, instead of C-Script. The DLL interface is
available on all A5 editions. For creating an A5 DLL, the SDK (source development kit) is
required. SDK owners can create DLLs for adding new effects, actor AI or C-Script instructions,
and distribute or sell them to other 3D GameStudio users.
 
The Microsoft Visual C++™ development (versions 6.0 or .NET) system normally is used for
creating DLL plugins. Borland C++™C++ Builder™, or Delphi™ can also be used. The DLL
SDK contains an interface library that must be linked to any DLL. An example project with a
DLL template is also provided, which makes it easy to create extensions even for not-so-
experienced C or Delphi programmers who have never used DLLs before. The SDK license
includes the right to freely distribute DLLs created with it, as long as the DLL functions only
provide application functionality. It is not allowed to distribute DLLs that work as a 'wrapper'
for the library by providing functions that allow direct access of the interface structures or the
library functions from outside the DLL.
DLL extensions work bidirectionally: C-Script instructions can access C++ or Pascal DLL
functions, and DLL functions can access engine and C-Script functions and variables. So you
can – if you want - arbitrarily mix C-Script, C++ and Pascal in your application. On opening a
DLL, the engine transfers the pointer to an internal interface structure to the interface library.
The interface contains pointers to engine variables and functions, like the frame buffer, the
DirectX interface, the network interface, the DirectInput interface, the level, the C-Script
functions and so on. Theoretically everything - MP3 or MOD players, a physics engine, another
3D engine or even another scripting language - could be added to the engine this way.
Note that the following documentation contains just the description of the DLL interface to the
C-Script API, and some examples. The API functions are described in the GameStudio Manual.
The same C-Script functions are used for the DLL as well as for C-Scripts, so you'll need both
manuals for creating DLL plugins.
Getting started with the SDK
You'll find the SDK either as a ZIP file on your key disk, or on a separate SDK disk. Unzip or
copy the SDK into a directory of your choice, and open it as a VC++ 6.0 project. The code for
Borland C++ oder Delphi can be found in the BCPP and Delphi subfolders – read the readme
text files for more information about how to create Borland and Delphi projects. The SDK
comes with a DLL source,
ackdll.cpp
and
ackdll.pas,
that contains some typical examples
for DLL functions. Examine the examples carefully – it's the best way to see how to program
DLL functions and access engine parameters! You can use it as a 'template' for your own DLL. 
On accessing system resources like sound, video, joystick and so on, the DLL must take care of
possible resource conflicts. The engine shares its resources and expects the same from the code
inside the DLL. For instance, code that requires exclusive access to the sound device (like some
old MOD players) won't work. Some resources (like the midi player) can't be shared - if midi
music is played by the DLL, the engine must not play a midi file at the same time and vice
versa. Also care must be taken that for writing something into the frame buffer it must be
locked before, and unlocked afterwards. The interface library provides functions for that.