Game Engine Architecture

(Ben Green) #1

258 5. Engine Support Systems


(define-exportanim-walk-fast
(new simple-animation
:name "walk"
:speed 2.0
)
)
(define-exportanim-jump
(new simple-animation
:name "jump"
:fade-in-seconds 0.1
:fade-out-seconds 0.1
)
)

This Scheme code would generate the following C/C++ header fi le:

simple-animation.h

// WARNING: This file was automatically generated from
// Scheme. Do not hand-edit.

struct SimpleAnimation
{
const char* m_name;
float m_speed;
float m_fadeInSeconds;
float m_fadeOutSeconds;
};
In-game, the data can be read by calling the LookupSymbol() function, which
is templated on the data type returned, as follows:
#include "simple-animation.h"

void someFunction()
{

SimpleAnimation* pWalkAnim
= LookupSymbol<SimpleAnimation*>("anim-walk");

SimpleAnimation* pFastWalkAnim
= LookupSymbol<SimpleAnimation*>(
" anim-walk-fast");

SimpleAnimation* pJumpAnim
= LookupSymbol<SimpleAnimation*>("anim-jump");

// use the data here...
}
Free download pdf