Jump to content

  • Log In with Google      Sign In   
  • Create Account

Project Z



The CScript macro programming language

Posted by , 05 September 2013 - - - - - - · 803 views

This describes the CScript macro programming language used by the CScript macro processor / code generator.






--------------------------------------------------------------------------------------------------------------------
CScript macro processing language synatx description
CScript macro processor / code generator
© 1996-2013 Rockland Software Productions
--------------------------------------------------------------------------------------------------------------------






--------------------------------------------------------------------------------------------------------------------
What is CScript ?
--------------------------------------------------------------------------------------------------------------------
CScript is a macro processor and code generator for C++.
Its also the name of the macro processor langauage used by the CScript macro processor / code generator.
The CScript macro processor translates CScript code into C++ code.
It takes a CScript source file as input, and generates a C++ source file as output, ready to compile.

CScript is designed to help speed up code entry.
If you can think in code at light-speed, but your fingers can only type in code at sub-light speed,
CScript is designed with you in mind.
The syntax is designed to reduce the number of keystrokes requied for code entry.
The keywords of the language are designed to be short, quick, and easy to type in, but still be mnemonic.

A CScript source file can contain both CScript and C++ code feely mixed together.
Any line that does not begin with a CScript keyword is assumed to be C++ code,
and is automatically passed through unaltered, and written to the C++ output file.
This lets you use CScript for fast code entry of common everyday C++ code,
and true C++ for synatx that CScript doesn't handle directly.







--------------------------------------------------------------------------------------------------------------------
CScript statements
--------------------------------------------------------------------------------------------------------------------
CScript statements consist of a keyword and optional tokens, separated by whitespace.







--------------------------------------------------------------------------------------------------------------------
CScript tokens
--------------------------------------------------------------------------------------------------------------------
Tokens are similar to function or macro parameters. in C++.
There are two types of tokens in CScript: string tokens and non-string tokens.
A string token is a string enclosed by double quotes: "this is a string token"
A string token may contain whitespace between the double quotes.
A non-string token is any string of non-whitespace charaters, not enclosed in double quotes.
Cscript statements are whitespace delimited, so a token can't have whitespace in it.
Only string tokens enclosed in double quotes can have whitespace in them.
If a token not enclosed in double quotes has whitespace in it, CScript treats it as two separate tokens .
CScript treats tokens enclosed in double quotes as C++ string literals.
So the double quotes are passed along with the string to the C++ output file:
c printf "%s\n" "this is a test"
printf("%s\n","this is a test");







--------------------------------------------------------------------------------------------------------------------
Example tokens:
--------------------------------------------------------------------------------------------------------------------
1 / / a literal value
-0.084f // a token can include type info!
"this is a string" / / a string
my_var // a variable name
SomeFunctionCall(param1,param2,param3) // a function call
if((a>b)&&(c<d)) / / a conditional expression
x-=3*y+b // a code statement

ANYTHING that can be expressed in C++ code as a string with no whitespace can be a token!
Anything that uses double quotes can also be a token.








--------------------------------------------------------------------------------------------------------------------
CScript macro processing language synatx description
--------------------------------------------------------------------------------------------------------------------
In the following syntax desciptions, A , B, etc, represent tokens.
a "code block" is simply a set of statements, such as would normally be enclosed in squiggly brackets in C++.

The syntax descriptions use the following format:
Keyword name: the name of the keyword - such as "if equals" or "limit".
Keyword symbol: the keyword symbol that gets typed in at the start of a new line to begin this type of CScript statement.
What it does: a short descrription of what the keyword does.
Syntax: the CSript sytax for using the keyword.
Translates to: the C++ code geenrated by the CScript syntax.
Notes: special notes about the keyword, such as only working with specific data types,
or being part of the Cscript langauge extensions for a particular library such as directX.
Examples: examples of Cscript code usng the keyword, and the C++ code generated in the output file.








--------------------------------------------------------------------------------------------------------------------
Comment statements
--------------------------------------------------------------------------------------------------------------------


keyword name: COMMENT LINE
keyword symbol: ' (apostrophe)
what it does: the line is treated as a comment. it is not translated or passed through to the C++ output file.
syntax: ' your comment goes here
translates to: nothing - no line is genrate as output. the comment line is stripped out of the C++ output file.
example: ' this is a comment




Keyword name: BEGIN COMMENT BLOCK
Keyword symbol: [
What it des: same as /* in C++
Syntax: [
Translates to: /*
Example: [
this is a comment block
]








Keyword name: END COMMENT BLOCK
Keyword symbol: [
What it des: same as */ in C++
Syntax: ]
Translates to: */
Example: [
this is a comment block
]







--------------------------------------------------------------------------------------------------------------------
C++ preprocessor statements
--------------------------------------------------------------------------------------------------------------------





Keyword name: DEFINE
Keyword symbol: #d
What it des: C++ #define preprocessor directive
Syntax: #d A B
where A is the symbol name, and B is its value.
Translates to: #define A B
Example: #d g -32.0f

#define g -32.0f // define acceleration of gravity








Keyword name: INCLUDE
Keyword symbol: #i
What it des: C++ #include preprocessor directive
Syntax: #i A
where A is the include file.
Translates to: #include A
Example: #i <d3d11.h>

#include <d3dx11>







--------------------------------------------------------------------------------------------------------------------
Data declaration statements
--------------------------------------------------------------------------------------------------------------------




Keyword name: INT
Keyword symbol: i
What it does: declares integers
Syntax: i A B C .....
Translates to: int A, B, C;
Examples: i myint
int myint;

i joe fred[100] *james **tom harold[max_this][max_that]
int joe, fred[100], *james, **tom, harold[max_this][max_that];







Keyword name: FLOAT
Keyword symbol: f
What it does: declares a float
Syntax: f A B ....
Translates to: float A, B, .... ;
Example: f et fps vec3[3] *f-addr
float et, fps, vec3[3], *f_addr ;







Keyword name: STRING
Keyword symbol: s
What it does: declares a string
Syntax: s A B ......
Translates to: char A[100] B[100]
Example: s s s2 ( 6 keystrokes )
char s[100],s2 [100]; ( 21 keystrokes )










Keyword name: STRUCT
Keyword symbol: st
What it does: declares a struct
Syntax: st A
/ code block - variable declarations
.st / .st ends a struct
where A is the name of the struct
Translates to: struct A
{
// code block
} ;
Example: st postion
f x
f y
f z
.st

struct postion
{
float x;
float y;
float z;
};







Keyword name: END STRUCT
Keyword symbol: .st
What it does: ends a struct declaration
Syntax: st A
/ code block - variable declarations
.st / .st ends a struct
where A is the name of the struct
Translates to: struct A
{
// code block
} ;
Example: st postion
f x
f y
f z
.st

struct postion
{
float x;
float y;
float z;
};






--------------------------------------------------------------------------------------------------------------------
Math statements
--------------------------------------------------------------------------------------------------------------------





keyword name: SET
keyword symbol: =
what it does: sets a value
syntax: = A B
translates to: A = B ;
where A and B are any two tokens that evluate to comptabel typs



keyword name: ADD
keyword symbol: +
what it does: adds two values
syntax: + A B
translates to: A += B ;




keyword name: SUBTRACT
keyword symbol: -
what it does: subtracts two values
syntax: - A B
translates to: A -= B ;



keyword name: MULTIPLY
keyword symbol: *
what it does: multiply two values
syntax: * A B
translates to: A *= B ;



keyword name: DIVIDE / DIV
keyword symbol: /
what it does: division
syntax: / A B
translates to: A /= B ;
NOTE: this does div or divide depending on what A is ( IE float or int type token).



keyword name: MOD
keyword symbol: %
what it does: modulus
syntax: % A B
translates to: A = A % B ;



keyword name: INC
keyword symbol: ++
what it does: increment
syntax: ++ A
translates to: A++;




keyword name: DEC
keyword symbol: --
what it does: decrement
syntax: -- A
translates to: A--;






--------------------------------------------------------------------------------------------------------------------
If then else statments
--------------------------------------------------------------------------------------------------------------------



keyword name: IF
keyword symbol: ?
what it does: if statement
syntax: ? A
// code block goes here
. / / a preiod ends the code block
translates to: if ( A )
{
// code block
}
NOTE: the period is required at the end of the statement block, even if there are no statments or just one statement !






keyword name: ELSEIF
keyword symbol: e?
what it does: a non-last else in an "if then else" statement
syntax: e?
translates to: else
use it before the second and subsequent else-ifs in an if-then-else statement.
exaample: == A B // if a == b
/ code block
.
e? // else
!= A C // if a != c
/ code block
.
el // else
/ code block
.








keyword name: ELSE
keyword symbol: el
what it does: last else in an "if then else" statement
syntax: el
/ code block
.
translates to:
else
{
// code block
}
NOTE: the period is required at the end of the code block, even if there are no statments or just one statement !
example: == A B
/ code block
.
el
/ code block
.







keyword name: DOUBLE EQUALS
keyword symbol: ==
what it does: compares two values to see if they are equal
syntax: == A B
// code block goes here
. / / a preiod ends the statement block
translates to: if ( A == B )
{
// code block
}
NOTE: the period is required at the end of the statement block, even if there are no statments or just one statement !







keyword name: NOT EQUAL
keyword symbol: !=
what it does: compares two values to see if they are unequal
syntax: != A B
/ code block
.
translates to: if ( A !+ B )
{
// code block
}
NOTE: the period is required at the end of the statement block, even if there are no statments or just one statement !






keyword name: GREATER THAN
keyword symbol: >
what it does: compares two values to see if one is greater
syntax: > A B
/ code block
.
translates to: if ( A > B )
{
// code block
}
NOTE: the period is required at the end of the statement block, even if there are no statments or just one statement !





keyword name: LESS THAN
keyword symbol: >
what it does: compares two values to see if one is lesser
syntax: < A B
/ code block
.
translates to: if ( A < B )
{
// code block
}
NOTE: the period is required at the end of the statement block, even if there are no statments or just one statement !







keyword name: GREATER THAN OR EQUAL
keyword symbol: >=
what it does: compares two values to see if one is greater than or equal to the other
syntax: > = A B
/ code block
.
translates to: if ( A >= B )
{
// code block
}
NOTE: the period is required at the end of the statement block, even if there are no statments or just one statement !





keyword name: LESS THAN OR EQUAL
keyword symbol: <=
what it does: compares two values to see if one is lesser than or equal to the other
syntax: < = A B
/ code block
.
translates to: if ( A <= B )
{
// code block
}
NOTE: the period is required at the end of the statement block, even if there are no statments or just one statement !







keyword name: STRING EQUALS
keyword symbol: s=
what it does: ccompares two strings
syntax: S= A B
/ code block
.
translates to: if ( strcmp( A, B) == 0 )
{
// code block
}
NOTE: the period is required at the end of the statement block, even if there are no statments or just one statement !








--------------------------------------------------------------------------------------------------------------------
Switch statements
--------------------------------------------------------------------------------------------------------------------




Keyword name: SWITCH
Keyword symbol: sw
What it does: switch statement
Syntax: sw A
ca B
/ code block
.
ca C
/ code block
.
ca D ......
.
Translates to: switch( A )
{
case B:
// code block
break;
case C:
// code block
break;
case D:
.....
}
Example: sw menu(3)
ca 1
c newgame
.
ca 2
c loadgame
.
ca 3
ret
.

switch(menu(3))
{
case 1: newgame();
break;
case 2: loadgame();
break;
case 3: return;
break; // a break; statement gets generated for each case statement automatically.
// in this case its redundant, but its ok, because its still legal syntax.
}










Keyword name: CASE
Keyword symbol: ca
What it does: case statement
Syntax: sw A
ca B
/ code block
.
ca C
/ code block
.
ca D ......
.
Translates to: switch( A )
{
case B:
// code block
break;
case C:
// code block
break;
case D:
.....
}
Example: sw menu(3)
ca 1
c newgame
.
ca 2
c loadgame
.
ca 3
ret
.

switch(menu(3))
{
case 1: newgame();
break;
case 2: loadgame();
break;
case 3: return;
break; // a break; statement gets generated for each case statement automatically.
// in this case its redundant, but its ok, because its still legal syntax.
}








--------------------------------------------------------------------------------------------------------------------
Do loop statemements
--------------------------------------------------------------------------------------------------------------------






Keyword name: DO
Keyword symbol: do
What it does: a do loop
Syntax: do A
// code block goes here
.do
Translates to: do
{
// code block goes here
}
while ( A );


Example: = quitgame 0
do !quitgame
c input
c update
c render
.do

quitgame=0;
do
{
input();
update();
render();
}
while ( !quitgame );







Keyword name: END DO
Keyword symbol: .do
What it does: ends a do loop
Syntax: do A
/ code block
.do
Translates to: do
{
// code block
}
while ( A );
Example: = a 0
do !eof(f)
cr var[a] readfileint f
++ a
.do

a=0;
do
{
var[a]=readfileint(f);
a++;
}
while (!eof(f));







--------------------------------------------------------------------------------------------------------------------
While statements
--------------------------------------------------------------------------------------------------------------------





keyword name: WHILE
keyword symbol: wh
what it does: while loop
syntax: wh A
/ code block
.
translates to: while ( A )
{
// code bock
}
NOTE: the period is required at the end of the code block, even if there are no statments or just one statement !
example: wh !quitgame
/ main game loop code block goes here
.






--------------------------------------------------------------------------------------------------------------------
For loop statements
--------------------------------------------------------------------------------------------------------------------




keyword name: FOR
keyword symbol: 4
what it does: a for loop
syntax: 4 A B
/ code block
.
NOTE: the period is required at the end of the code block, even if there are no statments or just one statement !
translates to: for ( A=0; A < B; A ++ )
{
/ code block
}
example: 4 a max_entities
c update_each a
.

for (a=0; a<max_entities; a++)
{
update_each(a);
}







--------------------------------------------------------------------------------------------------------------------
Flow control statements
--------------------------------------------------------------------------------------------------------------------







Keyword name: END ( code block )
Keyword symbol: . ( period )
What it does: adds the close squiggly at the end of a code block.
The END symbol (period) is used by many CScript statements that use code blocks.
It can also be used alnoe to inject a closed squiggly into the C++ output file if desired.
Syntax: .
Translates to : }
Example: 4 a 5
c somefunc
. / END code block

for (a=0; a<5; a++)
{
somefunc();
} // this squiggly is generated by the END symbol (a period).







Keyword name: CONTINUE
Keyword symbol: >>
What it does: inserts a continue; statement
Syntax: >>
Translates to: continue;
Example: 4 a maxtgts
? !tgt[a].active
>>
.
// do some stuff with tgt a
.

for (a=0; a<matgts; a++)
{
if ( ! tgt[a].active )
{
continue;
}
// do some stuff with tgt a
}








Keyword name: BREAK
Keyword symbol: brk
What it does: inserts a break; statement into the C++ code generated.
Syntax: brk
Translates to: break;
Example: 4 i 0 maxtgts
? !tgt[i].active
brk
.
' CScript comment line. i is now the index of the first inactive target.
// C++ comment line. i is now the index of the first inactive target.


for (i=0; i<maxtgts; i++)
{
if ( ! tgt[i].active )
{
break;
}
}
// C++ comment line. i is now the index of the first inactive target.

Note that the Cscript comment line does not appear in the C++ output file.






Keyword name: RETURN
Keyword symbol: ret
What it does: inserts a return() call in the C++ optut file
Syntax: ret - or - ret A
where A is an optional return value.
Translates to: return; if "ret" appears by itself on the line.
return ( A ); if a token "A " appears after the "ret" keyword.
Example: fn v movetgt i ID
? !tgt[ID].active
ret
.
' tgt is active, so move it accrding to game specific "flight model"
// TODO: code goes here
.

void movetgt( int ID )
{
if ( !tgt[ID].active )
{
return;
}
// TODO: code goes here
}








--------------------------------------------------------------------------------------------------------------------
Function statements
--------------------------------------------------------------------------------------------------------------------



keyword name: FUNCTION
keyword symbol: fn
what it does: declares a function
syntax: fn type1 A type2 B type2 C ....
/ code block
.
where type1 can be: v for void, i for int, or f for float,
and type2 can be i for int, f for f loat, or c for char.
A is the funciton name. B, C, etc are parameter names
line length is the only limit on the nunber of paramters.
NOTE: the period is required at the end of the code block, even if there are no statments or just one statement !
translates to: void | float | int A ( int | float | char B, int | float | char C, ... )
{
// code block
}
examples:
fn v myfunc i myint f myfloat c *mystring
/ code block
.

void myfunc ( int myint, float myfloat, char *mystring )
{
// code block
}



fn i myfunc i myint f myfloat c *mystring
/ code block
.

int myfunc ( int myint, float myfloat, char *mystring )
{
// code block
}


fn f myfunc i myint f myfloat c *mystring f x f y f z
/ code block
.

float myfunc ( int myint, float myfloat, char *mystring , float x,float y,float z)
{
// code block
}








Keyword name: CALL
Keyword symbol: c
What it does: calls a function
Syntax: c A [ B C D .... ]
where A is the function name, and B, C, etc are optional parameters.
Translates to: A(B,C,D...);
Example: c update_each cur_entity

update_each(cur_entity);







Keyword name: CALL WITH RETURN
Keyword symbol: cr
What it does: calls a function that returns a value
Syntax: cr A B [ C D .... }
where A is the variable to receive the return value, B is the function name, and C, D, etc are optional parameters.
Translates to: A = B ( C, D, .... );
Example: cr y heightmap x z

y=heightmap(x,z);









--------------------------------------------------------------------------------------------------------------------
String manipulation statements
--------------------------------------------------------------------------------------------------------------------





Keyword name: SET STRING
Keyword symbol: ss
What it does: strcpy
Syntax: ss A B
Translates to: strcpy_s( A, 100, B );
NOTE : A and B are expected to be tokens of type char[100]
Example: ss menu[0] "File exists - overwrite?"
ss menu[1] "Yes"
ss menu[2] "No"
== menu(2) 2
ret
.

strcpy_s(menu[0],100,"File exists -overwrite?");
strcpy_s(menu[1],100,"Yes");
strcpy_s(menu[2],100,"No");
if (menu(2)==2)
{
return;
}







Keyword name: STRING ADD
Keyword symbol: s+
What it does: concatenate two strings together
Syntax: s+ A B
where A and B are tokens that reslove to type char[100]
Translates to: strcat_s( A, 100, B )
Example: s s s2
ss s "Health: "
c i2s item_health s2
s+ s s2
tx 700 400 s

char s[100], s2[100];
strcpy_s(s,100,"Health: ");
i2s(item_health,s2); // convert int to string
strcat_s(s,100,s2);
Ztext3d(700,400,s); // display string
In this example, i2s and Ztext3d are routines in the Z3D game library.
The "tx" keyword on the last line of CScript code is part of the Cscript langauge extenstions for the Z3D game library.





--------------------------------------------------------------------------------------------------------------------
CScript language extenstions for DirectX
--------------------------------------------------------------------------------------------------------------------





Keyword name: V3
Keyword symbol: v3
What it does: declares a D3DXVECTOR3
Syntax: v3 A B C .....
Translates to: D3DXVECTOR3 A, B, C, ..... ;
NOTE D3DXVECTOR3 is a data structure defined in the D3DX library in DirectX .
Examples: v3 v
D3DXVECCTOR3 v;


// used in a struct declaration....
st axes
v3 fwd up right
.st

struct axes
{
D3DXVECTOR3 fwd, up, right;
};







Keyword name: V4
Keyword symbol: v4
What it does: declares a D3DXVECTOR4
Syntax: v4 A B C .....
Translates to: D3DXVECTOR4 A, B, C, ..... ;
NOTE D3DXVECTOR4 is a data structure defined in the D3DX library in DirectX .
Examples: v4 v
D3DXVECCTOR4 v;


// used in a struct declaration....
st homogeneous_axes
v3 fwd up right
.st

struct homogeneous_axes
{
D3DXVECTOR4 fwd, up, right;
};







Keyword name: MATRIX
Keyword symbol: mat
What it does: declares a D3DXMATRIX
Syntax: mat A B C .....
Translates to: D3DXMATRIX A, B, C, ...... ;
NOTE D3DXMATRIX is a data structure defined in the D3DX library in DirectX .
Example: mat m1 m2
D3DXMATRIX m1, m2;







--------------------------------------------------------------------------------------------------------------------
CScript langauage extensions for the Z3D Game Library
--------------------------------------------------------------------------------------------------------------------




Keyword name: LOWER LIMIT
Keyword symbol: min
What it does: limits an integer variable to a minimum integer value, basically a floor function.
Syntax: min A B
where A and B are integer type tokens
Translates to: a function call to llim(&A, B), whch implements: if ( A < B ) A = B ;
Note: llim() is part of the Z3D game library.
Example: -= heath damage ' health -=damage;
min health 0 ' llim (&health,0); implements ===> if (health < 0) health = 0;
== health 0 ' if (health==0) {
// He's dead Jim!
. ' }









Keyword name: UPPER LIMIT
Keyword symbol: max
What it does: limits an integer variable to a maximum integer value, basically a ceiling function.
Syntax: max A B
where A and B are integer type tokens
Translates to: a function call to ulim(&A, B), whch implements: if ( A > B ) A = B ;
Note: ulim() is part of the Z3D game library.
Example: += heath heal_amnt ' health += heal_amnt;
min health 0 ' llim (&health,0); implements ===> if (health < 0) health = 0;
== health 0 ' if (health==0) {
// He's dead Jim!
. ' }










Keyword name: LIMIT
Keyword symbol: lim
What it does: limits an integer variable to an integer range, basically a floor and ceiling function all in one.
Syntax: max A B C
where A , B, and C are integer type tokens.
Translates to: a function call to limit(&A, B,C), whch implements: if ( A < B ) A = B ; if ( A > C ) A = C ;
Note: limit() is part of the Z3D game library.
Example: += spd delta // delta can be negative!
lim spd 0 maxspd

spd+=delta;
limit(&spd,0,maxspd); // implements : if (spd<0) spd=0; if (spd>maxspd) spd=maxspd;










Keyword name: GETMOUSE
Keyword symbol: gm
What it does: gets current mouse state
Syntax: gm A B C
where A, B, and C resolve to pointers to ints.
Translates to: Zgetmouse(&A, &B, &C); x=A. y=B. C: 1=Lbutton 2= Rbutton 3=both 0=none.
Note: Zgetmouse is part of the Z3D game library.
Example: gm &x &y &b
== b 1
tx x y "You clicked here!"
.

Zgetmouse(&x,&y,&b);
if (b == 1)
{
Ztext3d(x, y, "You clicked here!");
}








Keyword name: TEXT
Keyword symbol: tx
What it does: displays text
Syntax: tx X Y S
Translates to: Ztext3d( X, Y, S );
where X,Y are the screen coordinates, and S is a string.
Example: tx 700 400 "Hello world!"

Ztext3d(x,y,"Hello world!");







Keyword name: NEWMENU
Keyword symbol: m0
What it does: initilaizes the Z3D menu system.
Syntax: m0 A
where A resolves to a string. A is the menu title / prompt for the new menu.
Translates to: Znewmenu(A);
Example: m0 "Main menu:"
m+ "New game"
m+ "Load game"
m+ "Quit"
sw menu(3)
ca 1
c newgame
.
ca 2
c loadgame
.
ca 3
= quit 1
.
.

Znewmenu("Main menu:");
Zaddmenu("New game");
Zaddmenu("Load game");
Zaddmenu("Quit");
switch ( menu(3) )
{
case 1: newagme();
break;
case 2: loadgame();
break;
case 3: quit=1;
break;
}










Keyword name: ADDMENU
Keyword symbol: m+
What it does: adds a menu option string to the Z3D menu system
Syntax: m+ A
where A resolves to a string. A is the menu option text.
Translates to: Zaddmenu(A);
Example: m0 "Main menu:"
m+ "New game"
m+ "Load game"
m+ "Quit"
sw menu(3)
ca 1
c newgame
.
ca 2
c loadgame
.
ca 3
= quit 1
.
.

Znewmenu("Main menu:");
Zaddmenu("New game");
Zaddmenu("Load game");
Zaddmenu("Quit");
switch ( menu(3) )
{
case 1: newagme();
break;
case 2: loadgame();
break;
case 3: quit=1;
break;
}








Keyword name: GETSTRING
Keyword symbol: gs
What it does: gets string input
Syntax: gs A B
Translates to: Zgetstring(A, B);
where A and B resolve to strings. A is the prompt string, and B is the retrn value (the string entered by the user).
NOTE: Zgetstring is part of the Z3d game library.
Example: s item_name s
gs "Enter a name..." item_name
ss s "You entered "
s+ s item_name
tx 700 400 s

char item_name[100], s[100];
Zgetstring("Enter a name...", item_name);
strcpy_s(s,100,"You entered ");
strcat(s,100,item_name);
Ztext3d(700,400,s);









Keyword name: MESSAGE
Keyword symbol: msg
What it des: diplays a one line message. waits for the user to click "Ok".
Syntax: msg A
where A resolves to a string.
Translates to: Zmsg2( A );
NOTE: Zmsg2 is part of the Z3D game library.
Example: ? !filefound(s)
msg "Fiel not found!"
ret
.

if ( ! filefound( s) )
{
Zmsg2("File not found!");
return;
}









Keyword name: NOBUTON
Keyword symbol: nb
What it des: waits until no mouse buttons are pressed
Syntax: nb
Translates to: nobtton();
NOTE: nobutton is part of the Z3D game library.
Example: tx 700 400 "Click to continue..."
nb
p

Ztext3d(700,400,"Click to contine...");
nobutton(); // wait for no button, in case they're still holding one down.
pause(); // wait for a mosue click









Keyword name: PAUSE
Keyword symbol: p
What it des: waits for a mouse click
Syntax: p
Translates to: pause();
NOTE: pause() is part of the Z3D game library.
Example: tx 700 400 "Click to continue..."
nb
p

Ztext3d(700,400,"Click to contine...");
nobutton(); // wait for no button, in case they're still holding one down.
pause(); // wait for a mosue click









keyword name: ISIN
keyword symbol: in
what it does: checks if a 2d point IS IN a rectangle
syntax: is A B C D E F
/ code block
.
translates to: if ( isin( A,B,C,D,E,F ) )
{
// code block
}
NOTES:
1. the period is required at the end of the statement block, even if there are no statments or just one statement !
2. the isin function is part of the Z3D game library







keyword name: KEYPRESSED
keyword symbol: kb
what it does: check for a key being pressed
syntax: kb A
/ code block
.
where A is a vitrual keycode
translates to: if ( ZKeypressed( A ) )
{
// code block
}
NOTES:
1. the period is required at the end of the statement block, even if there are no statments or just one statement !
2. the Zkeypressed function is part of the Z3D game library.











Z3D String manipulator keywords ----------------------------------------------------------------------------------------

The String Manipulator in the Z3D game library implements a 1000 character
string "register" with get, set, add string, add int, and add float operations.
Its a handy tool for building up strings of text for display.

Keyword name: SET STRING ( string manipulator )
Keyword symbol: Ss
What it des: Sets the string manipulator to a value
Syntax: Ss A
where A is a string type token.
Translates to: Ss( A );
NOTE: Ss() is part of the string manipulator API in the Z3D game library.
Example: f fps
Ss ""
Saf fps
Sa " fps"
tx 700 400 S

float fps;
Ss(""); // set string a manipulator to "". IE clear it.
Saf(fps); // convert fps to string and concatenate onto the end of the string manipulator string
Sa(" fps"); // concatenate " fps" onto the end of the string manipulator string
Ztext3d(400,700,S); // display the string manipulator string "S".








Keyword name: STRING ADD ( string manipulator )
Keyword symbol: Sa
[size=4]What it des: concatenates a string onto the end of the string manipulator string[/size]
[size=4]Syntax: Sa A[/size]
[size=4]where A is a string type token.[/size]
[size=4]Translates to: Sa( A ); [/size]
[size=4]NOTE: Sa() is part of the string manipulator API in the Z3D game library.[/size]
[size=4]Example: f fps[/size]
[size=4] Ss ""[/size]
[size=4] Saf fps[/size]
[size=4] Sa " fps"[/size]
[size=4] tx 700 400 S[/size]

[size=4] float fps;[/size]
[size=4] Ss(""); // set string a manipulator to "". IE clear it.[/size]
[size=4] Saf(fps); // convert fps to string and concatenate onto the end of the string manipulator string[/size]
[size=4] Sa(" fps"); // concatenate " fps" onto the end of the string manipulator string[/size]
[size=4] Ztext3d(400,700,S); // display the string manipulator string "S".[/size]







[size=4]Keyword name: STRING ADD INT ( string manipulator )[/size]
[size=4]Keyword symbol: Sai[/size]
[size=4]What it des: converts an integer to a string, then concatenates it onto the end of the string manipulator string[/size]
[size=4]Syntax: Sai A[/size]
[size=4]where A is an integer type token.[/size]
[size=4]Translates to: Sai( A ); [/size]
[size=4]NOTE: Sai() is part of the string manipulator API in the Z3D game library.[/size]
[size=4]Example: i hp;[/size]
[size=4] Ss ""[/size]
[size=4] Sai hp[/size]
[size=4] Sa " hit points"[/size]
[size=4] tx 700 400 S[/size]

[size=4] int hp;[/size]
[size=4] Ss(""); // set string a manipulator to "". IE clear it.[/size]
[size=4] Sai(hp); // convert hp to string and concatenate it onto the end of the string manipulator string[/size]
[size=4] Sa(" hitpoints"); // concatenate " hit points" onto the end of the string manipulator string[/size]
[size=4] Ztext3d(400,700,S); // display the string manipulator string "S".[/size]








[size=4]Keyword name: STRING ADD FLOAT ( string manipulator )[/size]
[size=4]Keyword symbol: Saf[/size]
[size=4]What it des: converts a float to a string, then concatenates it onto the end of the string manipulator string[/size]
[size=4]Syntax: Saf A[/size]
[size=4]where A is a float type token.[/size]
[size=4]Translates to: Saf( A ); [/size]
[size=4]NOTE: Saf() is part of the string manipulator API in the Z3D game library.[/size]
[size=4]Example: f fps[/size]
[size=4] Ss ""[/size]
[size=4] Saf fps[/size]
[size=4] Sa " fps"[/size]
[size=4] tx 700 400 S[/size]

[size=4] float fps;[/size]
[size=4] Ss(""); // set string a manipulator to "". IE clear it.[/size]
[size=4] Saf(fps); // convert fps to string and concatenate onto the end of the string manipulator string[/size]
[size=4] Sa(" fps"); // concatenate " fps" onto the end of the string manipulator string[/size]
[size=4] Ztext3d(400,700,S); // display the string manipulator string "S".[/size]









[size=4]Z3D Matrix Manipulator keywords --------------------------------------------------------------------------------------------------------[/size]

[size=4]The Matrix Manipulator in the Z3D game library implements a D3DXMATRIX [/size]
[size=4] "register" with operations like get, set, clear, scale, rotate, translate, and transform vertex. [/size]
[size=4] Its handy for concatenating matrices together for drawing or transforming points.[/size]



[size=4]Keyword name: Mstart[/size]
[size=4]Keyword symbol: M0[/size]
[size=4]What it does: sets the Matrix Manipulator to identity.[/size]
[size=4]Syntax: M0[/size]
[size=4]Translates to: Mstart();[/size]
[size=4]Example: mat mWorld[/size]
[size=4] M0[/size]
[size=4] Ms 1.0f 1.5f 2.5f[/size]
[size=4]Mrr 0 item.xr[/size]
[size=4]Mrr 1 item.yr[/size]
[size=4]Mm item.x item.y item.z[/size]
[size=4]= mWorld Mmat[/size]

[size=4] D3DXMATRIX mWorld;[/size]
[size=4]Mstart();[/size]
[size=4]Mscale(1.0f,1.5f,2.5f); // scale mesh [/size]
[size=4]MrotateRADS(0,item.xr); // rotate around world axis zero ( the x axis)[/size]
[size=4]MrotateRADS(1,item.yr); // rotate around world axis one ( the y axis)[/size]
[size=4]Mmove(item.x, item.y, item.z); // move to items location in the world[/size]
[size=4]mWolrd=Mmat; // set mWorld to the matrix manipulator's matrix [/size]








[size=4]Keyword name: Mscale[/size]
[size=4]Keyword symbol: Ms[/size]
[size=4]What it does: post-multiplies the Matrix Manipulator matrix by a scaling matrix [/size]
[size=4]Syntax: Ms A B C[/size]
[size=4]where A B C are the x,y,z scaling values and are float tokens .[/size]
[size=4]Translates to: Mscale(A, B, C);[/size]
[size=4]Example: mat mWorld[/size]
[size=4] M0[/size]
[size=4] Ms 1.0f 1.5f 2.5f[/size]
[size=4]Mrr 0 item.xr[/size]
[size=4]Mrr 1 item.yr[/size]
[size=4]Mm item.x item.y item.z[/size]
[size=4]= mWorld Mmat[/size]

[size=4] D3DXMATRIX mWorld;[/size]
[size=4]Mstart();[/size]
[size=4]Mscale(1.0f,1.5f,2.5f); // scale mesh [/size]
[size=4]MrotateRADS(0,item.xr); // rotate around world axis zero ( the x axis)[/size]
[size=4]MrotateRADS(1,item.yr); // rotate around world axis one ( the y axis)[/size]
[size=4]Mmove(item.x, item.y, item.z); // move to items location in the world[/size]
[size=4]mWolrd=Mmat; // set mWorld to the matrix manipulator's matrix [/size]







[size=4]Keyword name: Mrotate [/size]
[size=4]Keyword symbol: Mr[/size]
[size=4]What it does: post-multiplies the Matrix Manipulator matrix by a rotation matrix [/size]
[size=4]Syntax: Mr A B [/size]
[size=4]where A is the world axis of rotation ( 0=x, 1=y, 2=z) and B is the integer rotation amount in degrees.[/size]
[size=4]Translates to: Mrotate(A, B);[/size]
[size=4]Example: mat mWorld // delare a matrix mWorld[/size]
[size=4] M0 // set the matrix maanipulator to identity[/size]
[size=4] Ms 10.0f 15.0f 25.0f // scale the mesh[/size]
[size=4]Mr 0 tgt[i].angle // rotate around world x by "downward inclination angle"[/size]
[size=4]Mr 1 tgt[i].heading // rotate around world y by "compass heading in degrees"[/size]
[size=4]Mm tgt[i].x tgt[i].y tgt[i].z // move to target's location in the world[/size]
[size=4]= mWorld Mmat // set mWolrd to the matrix manipulator's matrix.[/size]

[size=4] D3DXMATRIX mWorld;[/size]
[size=4]Mstart();[/size]
[size=4]Mscale(10.0f,15.0f,25.0f); // scale mesh [/size]
[size=4]Mrotate(0,tgt[i].angle); // rotate around world axis zero ( the x axis)[/size]
[size=4]Mrotate(1,tgt[i].heading); // rotate around world axis one ( the y axis)[/size]
[size=4]Mmove( tgt[i].x, tgt[i].y, tgt[i].z ); // move to target's location in the world[/size]
[size=4]mWolrd=Mmat; // set mWorld to the matrix manipulator's matrix [/size]






[size=4]Keyword name: MrotateRADS [/size]
[size=4]Keyword symbol: Mrr[/size]
[size=4]What it does: post-multiplies the Matrix Manipulator matrix by a rotation matrix [/size]
[size=4]Syntax: Mrr A B [/size]
[size=4]where A is the world axis of rotation ( 0=x, 1=y, 2=z) and B is the floating point rotation amount in radians.[/size]
[size=4]Translates to: MrotateRADS(A, B);[/size]
[size=4]Example: f x y z [/size]
[size=4] M0[/size]
[size=4] Ms 1.0f 1.5f 2.5f[/size]
[size=4]Mrr 0 item.xr[/size]
[size=4]Mrr 1 item.yr[/size]
[size=4]Mm item.x item.y item.z[/size]
[size=4]= x 0.0f[/size]
[size=4]= y 0.0f[/size]
[size=4]= z 10.0f[/size]
[size=4]Mt &x &y &z[/size]
[size=4]// x,y,z is now a point 10 units in front of the item in the world.[/size]

[size=4] float x,y,z;[/size]
[size=4]Mstart();[/size]
[size=4]Mscale(1.0f,1.5f,2.5f);[/size]
[size=4]MrotateRADS(0,item.xr); // rotate around world axis zero ( the x axis)[/size]
[size=4]MrotateRADS(1,item.yr); // rotate around world axis one ( the y axis)[/size]
[size=4]Mmove(item.x, item.y, item.z);[/size]
[size=4]x=0.0f;[/size]
[size=4]y=0.0f;[/size]
[size=4]z=10.0f;[/size]
[size=4]Mtrans(&x,&y,&z); // transform x,y,z by the Matrix Manipulator matrix[/size]
[size=4]// x,y,z is now a point 10 units in front of the item in the world.[/size]








[size=4]Keyword name: Mmove [/size]
[size=4]Keyword symbol: Mm[/size]
[size=4]What it does: post-multiplies the Matrix Manipulator matrix by a translation matrix [/size]
[size=4]Syntax: Mm A B C[/size]
[size=4]where A , B, and C are the amounts to translate in x, y, and z. A, B, and C are expected to be float type tokens.[/size]
[size=4]Translates to: Mmove(A, B,C);[/size]
[size=4]Example: mat mWorld // delare a matrix mWorld[/size]
[size=4] M0 // set the matrix maanipulator to identity[/size]
[size=4] Ms 10.0f 15.0f 25.0f // scale the mesh[/size]
[size=4]Mr 0 tgt[i].angle // rotate around world x by "downward inclination angle"[/size]
[size=4]Mr 1 tgt[i].heading // rotate around world y by "compass heading in degrees"[/size]
[size=4]Mm tgt[i].x tgt[i].y tgt[i].z // move to target's location in the world[/size]
[size=4]= mWorld Mmat // set mWolrd to the matrix manipulator's matrix.[/size]

[size=4] D3DXMATRIX mWorld;[/size]
[size=4]Mstart();[/size]
[size=4]Mscale(10.0f,15.0f,25.0f); // scale mesh [/size]
[size=4]Mrotate(0,tgt[i].angle); // rotate around world axis zero ( the x axis)[/size]
[size=4]Mrotate(1,tgt[i].heading); // rotate around world axis one ( the y axis)[/size]
[size=4]Mmove( tgt[i].x, tgt[i].y, tgt[i].z ); // move to target's location in the world[/size]
[size=4]mWolrd=Mmat; // set mWorld to the matrix manipulator's matrix [/size]









[size=4]Keyword name: Mtrans [/size]
[size=4]Keyword symbol: Mm=t[/size]
[size=4]What it does: transforms a 3d point by the matrix manipulator's matrix.[/size]
[size=4]Syntax: Mt A B C[/size]
[size=4]where A , B, and C are the x,y,z coordinates of the point. A, B, and C are expected to be float type tokens.[/size]
[size=4]Translates to: Mtrans(&A, &B,&C);[/size]
[size=4]Example: f x y z [/size]
[size=4] M0[/size]
[size=4] Ms 1.0f 1.5f 2.5f[/size]
[size=4]Mrr 0 item.xr[/size]
[size=4]Mrr 1 item.yr[/size]
[size=4]Mm item.x item.y item.z[/size]
[size=4]= x 0.0f[/size]
[size=4]= y 0.0f[/size]
[size=4]= z 10.0f[/size]
[size=4]Mt &x &y &z[/size]
[size=4]// x,y,z is now a point 10 units in front of the item in the world.[/size]

[size=4] float x,y,z;[/size]
[size=4]Mstart();[/size]
[size=4]Mscale(1.0f,1.5f,2.5f);[/size]
[size=4]MrotateRADS(0,item.xr); // rotate around world axis zero ( the x axis)[/size]
[size=4]MrotateRADS(1,item.yr); // rotate around world axis one ( the y axis)[/size]
[size=4]Mmove(item.x, item.y, item.z);[/size]
[size=4]x=0.0f;[/size]
[size=4]y=0.0f;[/size]
[size=4]z=10.0f;[/size]
[size=4]Mtrans(&x,&y,&z); // transform x,y,z by the Matrix Manipulator matrix[/size]
[size=4]// x,y,z is now a point 10 units in front of the item in the world.[/size]


The Z testbed game engine API

Posted by , 05 September 2013 - - - - - - · 665 views

This is the API for the Z testbed game engine.

The Z engine is an experimental prototype used to investigate game code architecture. For example, i recently inverted it from a low level engine that made callbacks to the higher level game, to high level boilerplate code, and lower level library routines. And then i inverted it back again to a low level engine that makes callbacks to the high level game.







#ifndef Zengine_h
#define Zengine_h



#include <Z3d.h>


void Zmain(HINSTANCE hInstance); // called by main() to start the engine.
void Zrungame(); // called by user_mainmenu to run a game.
void Zquitgame(); // called by user_process_input to quit a game.

void Zengine_setcam(float x,float y,float z,float xr,float yr,float zr); // called by user_set_lights_and_amera

void Zuse_clearscreen(int on_off);
void Zset_clearscreen_colors(int r,int g,int b);

void Zuse_skybox(int on_off);
void Zset_skybox_params(int meshID,int texID);

void Zuse_drawground(int on_off);
void Zset_drawground_location(float x,float z);
void Zset_drawground_params(int radius,int quadsize,int meshID,int cliprng);


#endif










These are the user defined callback functions:


//######################## USER DEFINED CALLBACK DECLARATIONS ##########################################

//------------------- user implemented ----------------------------------------------------------
int user_collision(int a,float x,float y,float z);
// user implemented. returns 1 if a user defined (world / non entity vs entity) collision occured

float user_heightmap(float x,float z);
// user implemented // returns ground y given x,z

void user_handle_collision(int a,int b);
// user implemented // a is tgt. b: -2 = ground collsion occured. -3 = user defined collsion occured. b >= 0 means a collsion with entity b occured.

void user_draw_UI(); // user implemented // hook inside Zrender_all to draw UI display

int user_groundtex(float x,float z); // user implemented // returns groundtexID at x,z

void user_process_input(); // user implemented

void user_mainmenu(); // user implemented main menu. calls Zrungame.

void user_set_lights_and_camera(); // user implemented. set lights, camera.


//------------------------- hooks ----------------------------------------------------------------

void user_endprog(); // hook

void user_update_all(); // hook at end of Zupdate_all


void user_render_all(); // hook inside Zrender_all

void user_initgame(); // hook

void user_endgame(); // hook

void user_initprog(); // hook

//###################### END OF USER DEFINED CALLBACK DECLARATIONS ##########################################







and this is an actual testbed game that uses it. other than the user implemented callback routines, this is the ENTIRE program:



// zoom2 Zengine testbed program

#include <Zengine.h>

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
nCmdShow=0;
lpCmdLine=0;
hPrevInstance=0;
Zmain(hInstance);
PostQuitMessage(0);
return(0);
}


The Z3D API

Posted by , 05 September 2013 - - - - - - · 656 views

This is the current API for the Z3D game library. Note that this is a constantly evolving API.








// Z3D.h

#ifndef z3d_h
#define z3d_h


#include <SDKDDKVer.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <stdio.h>
#include <io.h>
#include <time.h>
#include <d3dx9.h>



//####################### PUBLIC GLOBAL DEFINITIONS ##################################

#define pi D3DX_PI



//################## PUBLIC GLOBAL VARIABLES #####################################################

extern HWND Zprogram_window_handle;

extern int Zalphatestlvl;

extern int mousewheel;

// d3d font objects
extern ID3DXFont *pFont;
extern ID3DXFont *pFont2;
extern ID3DXFont *pFont3;

// d3d sprite obj
extern ID3DXSprite *Zsprite;

extern D3DPRESENT_PARAMETERS Zparams;
extern LARGE_INTEGER Ztimer_freq;

extern int Ztrace[20];

extern DWORD Znum_verts,Znum_primitives;

extern int Zcurrentmesh,Zcurrenttex;

extern int old_mousex,old_mousey;



//######################### MATERIALS #####################################


#define ZMAXMATERIALS 10

extern D3DMATERIAL9 Zmaterial[ZMAXMATERIALS];

void Zsetmaterial(int materialID);

void Zinit_materials();



//############################# MENU STRINGS ###################################

#define MaxMenuStrings 50
#define MenuStringLength 100

extern char Zmenu[MaxMenuStrings][MenuStringLength]; // menu strings
extern int LastMenuOption;

void Zgetstring(char *s,char *s2);
int Zdomenu(int mousetex);
void Zclearmenu();
void Zaddmenu(char *s);
void Znewmenu(char *s); // clear + add


//############################# SPRITES ######################################


extern ID3DXSprite *Zsprite; // d3d sprite obj

void Zbeginsprite();
void Zendsprite();
void Zdrawsprite(int texID,int x,int y,float sx,float sy); // x,y are UL corner of sprite
void Zdrawsprite2(int texID,int x,int y,float sx,float sy,float rz); // draw a rotated sprite. x,y are screen coords of the center.
void Zflushsprites();


//########################## tex DB ############################################

#define Zmaxtextures 350

struct Ztexrec
{
char name[100];
LPDIRECT3DTEXTURE9 tex;
};

extern Ztexrec Ztex[Zmaxtextures];
extern int numtextures;

void Zloadtex(char *s);
void Zloadbitmap(char *s);
void Zloadsprite(char *s);
void Zload_dynamic_bitmap(char *s);
void Zloadspritetex(char *s); // alpha transparency
void Zloadspritetex2(char *s); // alpha transparency, 5 mip lvls in dds file.
void Zloadspritetex3(char *s); // colorkey transparency
void Zunload_last_bitmap();

void Zload_textures();



//########################### mesh DB ###########################################

#define maxmeshes 300

struct Zmesh
{
IDirect3DVertexBuffer9 *vb;
IDirect3DIndexBuffer9 *ib;
int numverts,numfaces;
};


// meshDB record
struct meshrec
{
char name[100];
//LPD3DXMESH mesh;
Zmesh mesh2;
};

// mesh DB
extern meshrec mesh[maxmeshes];

void Zloadmesh(char *s,int dynamic); // dynamic = 0 or 1.

extern int DBnummeshes;

void Zload_meshes();


//######################### DRAWLIST #################################################

struct Zdrawinfo
{
int type, // 0=mesh, 1=model, 2=2d billboard, 3=3d billboard
meshID, // for models: modelID
texID, // for models: aniID
alphatest,cull,clamp,materialID,rad,cliprng;
float sx,sy,sz,x,y,z,rx,ry,rz,range; // range is rng to camera. not currently used.
D3DXMATRIX mWorld;
};

extern int Znumdrawrecs;
//extern int alphatest_numdrawrecs;

void Zcleardrawlist();
void Zdrawlist();
void Zdraw(Zdrawinfo *info);
void Zpresent();
int Zshowscene(); // 1=success 0=failure
void Zdraw2(Zdrawinfo *info);

void Zd(Zdrawinfo *b); // draw mesh, model, 2d billbaord, or 3d billboard



//############################# models ###################################################



#define maxlimbs 20



// limb record
struct limbrec
{
int parent,meshID,texID,alphatest; // parent = index of parent limb. -1=no parent.
float x,y,z,xr,yr,zr,sx,sy,sz; // location of limbs origin (in parent's coords). current orientation of limb.
float xr0,yr0,zr0; // "at rest" orientation of the limb
char name[20];
};

// model record
struct modelrec
{
int numlimbs;
limbrec limb[maxlimbs];
char name[20];
};

void Zdrawmodel(Zdrawinfo *info); // meshID=modelID. uses x,y,z,xr,yr,zr.
void Zdrawmodel2(Zdrawinfo *info); // meshID=modelID. uses mWorld.




//################################### models datatbase ##########################################



#define maxmodels 200
extern modelrec model[maxmodels];
extern int nummodels;

void loadmodel(char *s);
void savemodel(int modelID,char *s);



//####################### animations ################################################


#define maxkeyframes 20


// a 3d vector (position, orientation, etc)
struct xyzrec
{
float x,y,z;
};

// keyframe record
struct keyframerec
{
int numframes,numlimbs;
xyzrec rotation[maxlimbs];
};

// animation record
struct anirec
{
int numkeyframes;
keyframerec keyframe[maxkeyframes];
};

int startani(int aniID,int modelID);
void stopani(int playerID);
int set_animation_frame(int playerID);


// animation player record
struct aniplayerrec
{
int active,aniID,modelID,curkeyframe,curframe;
};

#define maxaniplayers 200


// animation player
extern aniplayerrec aniplayer[maxaniplayers];



//############################ animations DB ####################################

#define maxanimations 50

extern anirec animation[maxanimations];
extern int numanimations;

void loadani(char *s);
void saveani(int aniID,char *s);


//########################## MATRIX MANIPULATOR ################################

extern D3DXMATRIX Mmat;
void Mstart();
void Mrotate(int axis,int degrees);
void MrotateRADS(int axis,float radians);
void Mmove(float x,float y,float z);
void Mscale(float x,float y,float z);
void Mtrans(float *x,float *y,float *z); // transform point x,y,z by matrix Mmat


//#################### STRING MANIPULATOR #################################

extern char S[1000];
void Ss(char *s2);
void Sa(char *s2);

// string add int
void Sai(int i);

// string add float
void Saf(float f);


//###################### GRAPHICS ENGINE #########################################

const DWORD ZFVF=(D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0) ); // D3DFVF_DIFFUSE | D3DFVF_SPECULAR |




/*
struct Zvertexrec
{
float x,y,z;
float nx,ny,nz;
float tu,tv;
DWORD diffuse,specular;
};
*/


struct Zvertexrec
{
D3DVECTOR position,normal;
//D3DCOLOR diffuse,specular;
float tu,tv;
};


extern IDirect3DDevice9 *Zd3d_device_ptr;
extern D3DXMATRIX ZmView; // view matrix
extern D3DXMATRIX Zprojection_matrix; // projection matrix
extern float Zcamx,Zcamy,Zcamz,Zcamxr,Zcamyr,Zcamzr; // camera position



int Zinit(HINSTANCE program_instance_handle,int width,int height,char *progname,float nearplane,int farplane); // ,int zbuf24bit);
void Zshutdown();
void Zsetlite(DWORD liteID,float x,float y,float z,float brightness);
void Zsetcam(float x,float y,float z,float rx,float ry,float rz);
void Zsetcam2(float x,float y,float z,D3DXMATRIX *m); // m is rot matrix
void Zclearscreen(int r,int g,int b);
void Zclearscreen2(); // clears screen to z game engine default color (blacklight)
void Zclearzbuf();
void Zbeginscene();
void Zambient(int r,int g,int b);
void Zlighting(int onoff);
void Zalphablend(int onoff);
void zbuftest(int onoff);
void zbufwrite(int onoff);
void Zcull(int onoff);
void Znormalize(int onoff);
void Zlite(DWORD liteID,int onoff);
void Zalphatest(int onoff);
void Zmipmaps(int onoff);
void Zclamp(int onoff);
//void Zanisotropic(int onoff);
void Zminmagfilter(int filter_type); // filter_type: 0=point, 1=linear, 2=anisotropic
void Zspecular(int onoff);

int Zsuperclip(int x,int y,int z,int rad,int cliprng);

void Zset_clip_planes(float nearplane,int farplane);

void Zcalc_frustum_planes(); // must set proj and view mats first!

int Zsuperclip2(int x, int y, int z, int rad, int cliprng); // must call Zcalc_frustum_planes first!

int Zarea_in_frustum(int x1,int z1,int x2,int z2); // must call Zcalc_frustum_planes first!

void Zsetmesh(int meshID);

void Zcreate_mesh(int vbsize,int maxverts);

void Zsettex(int texID);

void Zdrawimmediate(Zdrawinfo *a);

void Zdrawimmediate2(Zdrawinfo *a); // uses Zdrawinfo's mWorld mat

void Zcalc_frustum_planes2(); // rotation only




//############################ TEXT ########################################


void Ztextcolor(int r,int g,int b);
void Ztext(int x,int y,char *s);
void Ztext3d(int x,int y,char *s);
void Zsetfont(int font); // 0=comic ms sans 1= ariel 2=times new roman
int textwidth(char *s); // returns width of string s in pixels. uses current font setting.




//################################ MOUSE #########################################

void Zgetmouse(int *x,int *y,int *b);
void Zputmouse(int x,int y);
void nobutton();
void pause();

//########################## WINDOWS MESSAGE PROCESSOR ############################

void Zdomessages();

//########################### GENERIC GUI COMPONENTS ###################################

void Zmsg(char *s,char *title);
void Zmsg2(char *s);


//############################ KEYBOARD ##########################################

int Zkeypressed(int vkey);

//####################### STRING CONVERSION ROUTINES #############################

int s2i(char *s);
void i2s(int i, char *s);
void f2s(float f,char *s);
float s2f(char *s);

//############################ DICE ######################################

int dice(int a);

//####################### TIMERS ########################################

void Zstarttimer(int a);
int Zelapsedtime(int a);
int Zelapsedticks(int a);


//####################### FILEIO ##########################################

FILE* infile(char *s);
FILE* infilebin(char *s);
FILE* outfile(char *s);
FILE* outfilebin(char *s);
void closefile(FILE *f);
int readfile(FILE *f,char *s); // returns: 0=fail 1=success
int readfilebin(FILE *f,unsigned char *buf,int numbytes); // returns numbytes read
void writefile(FILE *f,char *s);
void writefilebin(FILE *f,unsigned char *buf,int numbytes);
int readfileint(FILE *f);
void writefileint(FILE *f,int i);
float readfilefloat(FILE *f);
void writefilefloat(FILE *f,float i);
int filefound(char *s);
void writeFBint(FILE *f,int a);
void writeFBfloat(FILE *f,float a);
int readFBint(FILE *f);
float readFBfloat(FILE *f);
time_t timestamp(char *s); // returns file create time (UTC format: secs since 1970). returns -1 if file not found.






//####################### GENERIC MATH ROUTINES #############################

int isin(int x,int y,int x1,int y1,int x2,int y2);
int dist(int x1,int z1,int x2,int z2); // diamond bounding box dist
int dist3d(int x1,int y1,int z1,int x2,int y2,int z2);
int BBdist(int x1,int z1,int x2,int z2); // sq bounding box dist
float deg2rad(float deg);
float rad2deg(float rad);
int heading(int x1,int z1,int x2,int z2);
int relheading(int x1,int z1,int h1,int x2,int z2);
void llim(int *a,int b);
void ulim(int *a,int b);
void limit(int *a,int b,int c);
int angle(int x1,int y1,int z1,int x2,int y2,int z2);
int rng2D(int x1,int z1,int x2,int z2);
int BBdist3d(int x1,int y1,int z1,int x2,int y2,int z2); // 3d bounding box distance
void normangl(float *a); // normalize angle to 0 to 2 pi
float rng3d(float x1,float y1,float z1,float x2,float y2,float z2);


//################################ TEXT COLORS ###############################

void redtext();
void greentext();
void bluetext();
void yellowtext();
void magentatext();
void cyantext();
void whitetext();
void blacktext();
void greytext();




// ################################### mouse aimed camera ###################################

void Zresetmouse();

extern float cam_xr;
extern float cam_yr;

int Zmouse_aim_camera(); // returns mouse button pressed: 0 none, 1 LB, 2 RB, etc.


// load meshes and textures using a list of filenames stored on disk in a text file


//################################## SCREEN DUMP ##############################################

void Zscreendump();


void Zload_models(); // load models from models.dat file
void Zload_anis(); // load anis from anis.dat file
void Zload_materials(); // load materials from materials.dat file




//############################ TARGET LIST #########################################################





// #################################################### TARGET LIST DATA STRUCTURES #####################################################

#define stepsize 0.1f


struct ttyperec // a target type record
{
float maxspd,turnrate;
int ai,rad,hp,mass,canfly,userID,value,animated,usefuel,maxfuel;
Zdrawinfo d;
};



struct tgtrec
{
float x,y,z,xr,yr,spd;
int type,dp,owner,fuel,alive,active,userID,aniplayerID,dontdraw;
};



#define maxttypes 50
#define maxtgts 200

extern ttyperec ttype[maxttypes]; // target types database

extern tgtrec tgt[maxtgts]; // targets database



extern int numtgts; // index of last active tgt + 1.
// max possible number of active tgts at the moment.
// search tgt list using: for a=0 a<numtgts a++.



// ####################################################### INIT TARGETS SYSTEM #################################################################

void Zinit_targets_system(); // initializes the z game library

void load_target_types(); // load ttypes from file ttypes.dat

void load_targets(char *s2); // load targets from file s2



// ##################################################### TARGET ROUTINES ###############################################################

// new, del, turn, pitch, move

int get_inactive_tgt(); // returns index of 1st inactive tgt. adjusts numtgts accordingly. returns -1 if none available.

void deactivate_tgt(int a); // deativates tgt a. adjusts numtgts accordingly.

void turntgt(int a,float amnt); // turns a target around y axis by amnt radians. amnt is limited by ttype.turnrate

void pitchtgt(int a,float amnt); // turns a target around x axis by amnt radians. amnt is limited by ttype.turnrate

// ##################################################### TARGET DRAWING ROUTINES ##############################################################

void Zdrawtgt(int a); // draws target a

void Zdrawtgts(); // draws all targets

// ########################################################### TARGET AI ROUTINES ##################################################################



float AI_turn_amount(int a,float x,float z); // returns amount to turn tgt to face location x,z. amnt=AI_turn_amount(a,x,z) turntgt(a,amnt)

float AI_turn_from_amount(int a,float x,float z); // returns amount to turn tgt to face away from location x,z. amnt=AI_turn_from_amount(a,x,z) turntgt(a,amnt)

void AI_turntgt(int a,float x,float z); // turn tgt towards x,z

void AI_turntgt_from(int a,float x,float z); // turn tgt away from x,z

void AI_turn_tgt_to_tgt(int a,int c); // turn tgt a towards tgt c

void AI_turn_tgt_from_tgt(int a,int c); // turn tgt a away from tgt c

void AI_turn_static_to_tgt(int a,int c); // turn static tgt a towards tgt c

void AI_turn_static_from_tgt(int a,int c); // turn static tgt a away from tgt c

float AI_pitch_amount(int a,float x,float y,float z); // returns amount (in rads) to pitch tgt a to face x,y,z

float AI_pitch_from_amount(int a,float x,float y,float z); // returns amount (in rads) to pitch tgt a to face away from x,z,y.
// assumes tgt is heading away from xyz.
// returns 360 - AI_pitch_amount, not AI_pitch_amount + 180.

void AI_pitch_tgt_towards_xyz(int a,float x,float y,float z); // pitches tgt a towards xyz

void AI_pitch_tgt_awayfrom_xyz(int a,float x,float y,float z); // pitches tgt a away from xyz

void AI_pitch_tgt_towards_tgt(int a,int c); // pitches tgt a towards tgt c

void AI_pitch_tgt_awayfrom_tgt(int a,int c); // pitches tgt a away from tgt c




//############################################################ FPS METER #############################################################



void Zinit_fps_meter();

void Zupdate_fps_meter();

float Zget_fps();


//################################################################### skybox ########################################################


void Zdrawskybox(int skybox_meshID,int skybox_texID);


//######################################## TGT LIST COLLISION TABLE #############################################################

void Zset_collision_table(int ttype1,int ttype2,int value); // sets the "collision table" values for a pair of target types.

int Zcan_collide(int ttype1,int ttype2);

int collided(int a,float x,float y,float z,int r); // a is the target being moved


//##############################################################################################################################



int Zinitall(HINSTANCE hInstance);






#endif


About Project Z

Posted by , 05 September 2013 - - - - - - · 588 views

About Project Z

Project Z is a term i came up with to describe my activities related to the Z game development library, the Z "game engine", and other related technologies.

All programmers start to build up a library of useful code over time. its their "bag of tricks".

Mine originally evolved as a collection of useful routines that could be used again and again to build games. Things like a function that implements rolling dice, and high precision timers. It was originally written in pascal, and DOS was the OS at the time.

I used to sell my library for use with Borland Pascal 6 and 7, and Borland C 4.0. When i switched to Watcom C for speed, i ported the library to Watcom, but never released it again. It later grew to include a complete 3d poly engine, as well as support for midi and cd quality digital audio.

I got out of game development for a while. When i got back into it, the library was re-written from scratch to work with windows and directx.

I got out of game development again. When i got back into it, the library was re-written again from scratch to use the latest version of DIrectX. At this time i used it to write a prototype game engine that was called the Z engine. Although it was just an in-house R&D project, it was good enough that the artist i was working with at the time could use it to build a shooter.

I got out of game development a THIRD time! When i got back into it again (this time) the library was once again re-written from scratch. But i didn't know what to call it. It hadn't had a name other than "my game library" since it was sold under the titles BP60LIB, BP70LIB, and BC40LIB. since i need a name of some sort just for file naming, i chose Z, from the name for the old prototype engine. Since the library was being written to work with direct3D, the library ended up being called Z3D.cpp and Z3D.h, even though its much more than just 3D graphics code.

I now use the current version for building games and for experimenting with game code architecture.

in its current form, the library consists of one .cpp file of about 5600 lines of code. Its currently designed to work with directX 9.0c fixed function pipeline as that's sufficient for my needs at the moment. However it has also been tested with Directx 11, and a prototype of a directx 11 version already exists. It includes things like data structures and functions for storing meshes, textures, materials, models, and animations in memory (asset managers? or "databases" as i call them), and a render queue with state manager built-in. Its also implements a wide variety of useful functions for timers, file i/o, string conversion, etc. it also includes a rigid body modeling and animation system.

there is a second module to the library. its the modeling and animation editor for the rigid body system in the library. its a stand alone module that uses the library and can be linked into any game to instantly provide and in-game rigid body modeling and animation editor.

recently i stared working on a generic "active entities list" for the library. This quickly evolved into a test bed "engine" which i'm now using to experiment with game engine design and to explore just how generic an engine / library system can be.

Another related technology is CScript, a macro processor / code generator for C++. Its designed to help speed up coding. its lets you enter code using a "shorthand" syntax. it then translates the "shorthand" code into ready to compile C++ source code. You can freely mix CScript and C++ syntax in a CScrpit source file. So using CScript with existing game code is as simple as making a copy of your .cpp file with a .cs (for CScrpit) extension. You can then immediately start coding in the Cscript file using BOTH CScript and C++, as you prefer. CScript doesn't make you give up C++ or anything in it. It simply augments it with shorthand syntax designed to reduce keystrokes.





September 2013 »

S M T W T F S
1234567
891011121314
15161718192021
22232425262728
2930     

Recent Entries



PARTNERS