Game Engine Architecture

(Ben Green) #1

806 14. Runtime Gameplay Foundation Systems


// Get the next instruction. We will never run
// out, because the return instruction is always
// last, and it will pop the current stack frame
// below.
DCInstruction& instr
= pCurStackFrame->GetNextInstruction();
// Perform the operation of the instruction.
switch (instr.GetOperation())
{
case DC_LOAD_REGISTER_IMMEDIATE:
{
// Grab the immediate value to be loaded
// from the instruction.
Variant& data = instr.GetImmediateValue();
// Also determine into which register to
// put it.
U32 iReg = instr.GetDestRegisterIndex();
// Grab the register from the stack frame.
Variant& reg
= pCurStackFrame->GetRegister(iReg);
// Store the immediate data into the
// register.
reg = data;
}
break;
// Other load and store register operations...
case DC_ADD_REGISTERS:
{
// Determine the two registers to add. The
// result will be stored in register A.
U32 iRegA = instr.GetDestRegisterIndex();
U32 iRegB = instr.GetSrcRegisterIndex();
// Grab the 2 register variants from the
// stack.
Variant& dataA
= pCurStackFrame->GetRegister(iRegA);
Variant& dataB
= pCurStackFrame->GetRegister(iRegB);
// Add the registers and store in
// register A.
dataA = dataA + dataB;
}
break;
Free download pdf