The very simple preprocessor, unrelated to the above allows you to use -> object dereferencing and * pointers, allowing more code to be copy and pasted between your c++ code base and AngelScript scripts and set typedefs for types that aren't AngelScript builtins. This also lets you tell your editor that your AngelScript files are c++ files so you get code completion, error checking etc.
As an example the following is all AngelScript code for a simple test in my engine before it goes through the preprocessor:
#include "System/Engine.h"
#include "Effect/MarchingCubes.h"
#include "Effect/MetaSphere.h"
#include "Physics/PhysicsWorld.h"
#include "Renderer/Renderer.h"
#include "Renderer/GfxDevice.h"
#include "Physics/RigidBody.h"
#include "Physics/RigidBodyNode.h"
#include "3D/Entity.h"
void mainscript(Engine* engine, RenderNode* n)
{
PhysicsWorld* w = engine->GetPhysicsWorld();
Shape* sphere = w->CreateSphereShape(1.0);
Shape* plane = w->CreateStaticPlaneShape(Vector3(0,1,0), 1);
RigidBody* sphereBody = w->CreateRigidBody(1.0, sphere);
sphereBody->SetTransform(Transform(Quaternion(0,0,0,1), Vector3(0, 50, 0)));
RigidBody* planeBody = w->CreateRigidBody(0.0, plane);
planeBody->SetTransform(Transform(Quaternion(0,0,0,1), Vector3(0, -1, 0)));
n->SetTransformIndex(sphereBody->GetRigidBodyNode()->GetTransformIndex());
w->AddRigidBody(sphereBody);
w->AddRigidBody(planeBody);
MetaSphere ms;
MarchingCubes mc(&ms, 0.7f);
Camera camera;
camera.SetLocalTransform(Transform(Quaternion(0, 0, 0, 1), Vector3(0, 0, 40)));
GfxDevice* gfx = engine->GetGfxDevice();
Renderer* rend = gfx->GetRenderer();
float add = 3.0/60.0f;
float time = 0;
while (gfx->IsOpen())
{
time += add;
//LogDebug("Render");
ms.Update(time);
mc.Lock();
for (int i = 0; i < ms.GetCount(); i++)
{
// TODO: this starts walking from inside the center of the sphere.
// As we only care about the surface, it'd be better if we could
// start at a surface cube rather than having to scan all cubes
// from the center of the sphere out to the surface.
Vector3 pos = ms.GetCenter(i);
mc.WalkVoxel(pos.x(),pos.y(),pos.z());
}
mc.Unlock();
mc.Update();
n->SetMesh(mc.GetMesh());
engine->Update();
engine->PrepareRendering(&camera);
rend->Render(n);
engine->FinishRendering();
gfx->SwapBuffers();
}
sphere->DelRef();
plane->DelRef();
sphereBody->DelRef();
planeBody->DelRef();
}
Use if you want, don't if you don't