We have two exciting new features coming to ODB.
New Math types
Given that DBP is a language designed for making games, it makes sense to include vector, matrix and quaternion types and operators as part of the language's builtin types. Our compiler can make use of SIMD to make operations on these types blazingly fast. The following list of types is now supported by the parser:
rem matrix types
var as mat2x2
var as mat2x3
var as mat2x4
var as mat3x2
var as mat3x3
var as mat3x4
var as mat4x2
var as mat4x3
var as mat4x4
rem vector types
var as vec2
var as vec3
var as vec4
rem higher dimensional numbers
var as complex
var as quat
The standard binary operators can be used to do math with these types, and there will also be some additional special operators such as
cross,
dot,
inv det or
conj. Examples:
rem calculating the inverse of a world/view/projection matrix
world as mat4x4
view as mat4x4
proj as mat4x4
wvp = inv (world * view * proj)
rem transforming a vector
pos as vec4
pos = wvp * pos
rem rotating a 3D vector
pos as vec3
rot as quat
pos = quat * pos
Modifying values in these types can be done using the same syntax you'd use for UDTs:
pos as vec3
pos.x = bla
pos.y = bla
pos.z = bla
mat as mat2x2
mat.m00 = bla
mat.m01 = bla
mat.m10 = bla
mat.m11 = bla
For quaternions and complex numbers the parser also supports complex and quaternion literals:
q as quat = 1 + 2i + 3j + 4k
c as complex = 1 + 2i
New initializer syntax
One of the annoying things I found with DBP is the inability to initialize UDTs on the same line. The parser now lets you write the initial values you want inside a UDT declaration:
type udt
x# as float = 2
y# as float = 4
endtype
var as udt
`var.x# is 2
`var.y# is 4
It is also possible to use initializer lists when defining UDT variables:
var as udt = 5, 6
`var.x# is 5
`var.y# is 6
This syntax goes much further than the above. For instance, you can initialize arrays that are inside nested UDTs:
type pos_type
x# as float
y# as float
endtype
type udt
id as integer
dim positions(3) as pos_type
endtype
var as udt = 1, ((3, 3), (4, 4), (5, 5))
It's also possible to pass initializer lists to functions:
foo((1, 2))
function foo(pos as pos_type)
`pos.x# is 1
`pos.y# is 2
endfunction