Conitec 3d gamestudio-source development 用户手册

下载
页码 21
3D Gamestudio Programmer's Manual
                        
© Conitec July 2002
                       5
We are using VC++ for our following examples - you'll find the corresponding Pascal versions
in the Delphi folders. For testing one of those DLL functions, compile the DLL, copy it into your
work folder, and insert the following C-Script instructions into a function assigned to a key:
  dllfunction PaintScreenWhite(x); // dll function declaration
  ...
  dll_open("ackdll.dll");
  PaintScreenWhite(0); // call a DLL function
  dll_close(dll_handle);
All exported DLL functions must be of type
DLLFUNC fixed function(...)
, while
fixed
is a
long integer interpreted by C-Script as 22.10 fixed point value. Conversion functions to/from
float and integer are available in the
a5dll.h
header. The engine structs and functions
accessible from DLL functions are described at the end of this chapter. All DLL functions can be
declared and called in scripts just like each other C-Script function, after having activated the
DLL through the 
dll_open
 and 
dll_close
 instructions that are described in the script manual.
Implementing new C-Script functions
A DLL can contain a library of new arithmetic or other functions that can be accessed by C-
Script. The following example implements an Ldexp function (which is already available in C-
Script) just for demonstration purpose: 
// returns the value of x 
*
 2
n
DLLFUNC fixed ldexp(fixed x,fixed n)
{
return (FLOAT2FIX(FIX2FLOAT(x)*pow(2.0,FIX2FLOAT(n))));
}
Don't forget the
FLOAT2FIX()
- all C-Script functions expect and return fixed point numbers.
This function can be added to the set of C-Script functions by declaring it in the script:
dllfunction ldexp(x,n); // declaration of a DLL function
After having openend the DLL, the new function can be used like each other function:
x = Ldexp(y,n); // calculates x = y * 2
n
Writing to the screen buffer
The following simple example shows how to lock the screen buffer, write into it and unlock it
again. It paints the screen all white for one frame. This works in D3D as well as in 8-bit mode.
From C-Script, activate this function through declaring it, and then executing
PaintScreenWhite(0)
. You'll see a short white flash when you call this function once. If you
call it in a 
wait(1)
-loop, the screen will become all white.
DLLFUNC fixed PaintScreenWhite (long unused)
{
// retrieve the pointer to the screen buffer
FRAME_INTERFACE *a5fb = a5->fb;
// lock the screen buffer to get direct access to it
(*a5fb->Lock)();
// paint it all white; note the use of a5fb->pitch here