# HG changeset patch
# User koryspansel
# Date 1316632695 25200
# Node ID b60cbf3fa894506276679e1be6f7bfebe604f7a6
# Parent 4750819f465d203b5446f61ec28380b2786259c4
Refactoring 'Code' & VM logic
diff -r 4750819f465d -r b60cbf3fa894 LightClone/LightClone.vcproj
--- a/LightClone/LightClone.vcproj Wed Sep 21 10:26:48 2011 -0700
+++ b/LightClone/LightClone.vcproj Wed Sep 21 12:18:15 2011 -0700
@@ -213,6 +213,10 @@
>
+
+
@@ -359,6 +363,10 @@
>
+
+
diff -r 4750819f465d -r b60cbf3fa894 LightClone/Source/Program.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LightClone/Source/Program.cpp Wed Sep 21 12:18:15 2011 -0700
@@ -0,0 +1,90 @@
+/*
+ * Program
+ */
+
+#include "Program.h"
+
+/*
+ * CalculateSize
+ */
+uint32 Program::Function::CalculateSize()
+{
+ uint32 nSize = 0;
+
+ for(uint32 i = 0; i < MaximumInstructionCount; ++i)
+ {
+ if(nInstruction[i] > 0)
+ {
+ ++nSize;
+ }
+ }
+
+ return nSize;
+}
+
+/*
+ * Program
+ */
+Program::Program()
+{
+}
+
+/*
+ * Upload
+ */
+ErrorCode Program::Upload(VirtualMachine& kMachine)
+{
+ ErrorCode eCode = Error_Success;
+
+ kMachine.Reset();
+ kMachine.ClearMemory();
+ kMachine.RemoveAllFunctions();
+
+ for(uint32 i = 0; i < nFunctionCount && eCode == Error_Success; ++i)
+ {
+ kMachine.AddFunction(i, kFunction[i].CalculateSize());
+
+ uint32 nSize = kMachine.GetFunctionSize(i);
+ uint8* pData = kMachine.GetFunctionMemory(i);
+
+ eCode = Compile(i, pData, nSize);
+ }
+
+ return eCode;
+}
+
+/*
+ * Compile
+ */
+ErrorCode Program::Compile(uint32 nIndex, uint8* pData, uint32 nSize)
+{
+ for(uint32 i = 0; i < Function::MaximumInstructionCount; ++i)
+ {
+ const uint32 nAction = kFunction[nIndex].nInstruction[i];
+
+ if(Action_Forward <= nAction && nAction <= Action_Light)
+ {
+ if(nSize < 2)
+ return Error_Fail;
+
+ *pData++ = Instruction_Action;
+ *pData++ = nAction;
+
+ nSize -= 2;
+ }
+ else
+
+ if(Action_FunctionA <= nAction && nAction <= Action_FunctionB)
+ {
+ if(nSize < 2)
+ return Error_Fail;
+
+ *pData++ = Instruction_Call;
+ *pData++ = nAction - Action_FunctionA + 1;
+
+ nSize -= 2;
+ }
+ }
+
+ return Error_Success;
+}
diff -r 4750819f465d -r b60cbf3fa894 LightClone/Source/Program.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LightClone/Source/Program.h Wed Sep 21 12:18:15 2011 -0700
@@ -0,0 +1,73 @@
+/*
+ * Program
+ */
+
+#ifndef __PROGRAM_H__
+#define __PROGRAM_H__
+
+#include "Core.h"
+#include "VirtualMachine.h"
+
+/*
+ * Program
+ */
+class Program
+{
+ /*
+ * MaximumFunctionCount
+ */
+ static const uint32 MaximumFunctionCount = 3;
+
+ /*
+ * Function
+ */
+ struct Function
+ {
+ /*
+ * MaximumInstructionCount
+ */
+ static const uint32 MaximumInstructionCount = 16;
+
+ /*
+ * nInstruction
+ */
+ uint32 nInstruction[MaximumInstructionCount];
+
+ /*
+ * CalculateSize
+ */
+ uint32 CalculateSize();
+
+ };
+
+ /*
+ * kFunction
+ */
+ Function kFunction[MaximumFunctionCount];
+
+ /*
+ * nFunctionCount
+ */
+ uint32 nFunctionCount;
+
+public:
+
+ /*
+ * Program
+ */
+ Program();
+
+ /*
+ * Upload
+ */
+ ErrorCode Upload(VirtualMachine& kMachine);
+
+private:
+
+ /*
+ * Compile
+ */
+ ErrorCode Compile(uint32 nFunction, uint8* pData, uint32 nSize);
+};
+
+#endif //__PROGRAM_H__
diff -r 4750819f465d -r b60cbf3fa894 LightClone/Source/VirtualMachine.cpp
--- a/LightClone/Source/VirtualMachine.cpp Wed Sep 21 10:26:48 2011 -0700
+++ b/LightClone/Source/VirtualMachine.cpp Wed Sep 21 12:18:15 2011 -0700
@@ -152,7 +152,7 @@
if(nFunctionCount + 1 < MaximumFunctionCount)
{
kFunction[nFunctionCount].nAddress = nFunctionCount * FunctionStride;
- kFunction[nFunctionCount].nSize = nSize;
+ kFunction[nFunctionCount].nSize = nSize * 2;
++nFunctionCount;
diff -r 4750819f465d -r b60cbf3fa894 LightClone/Source/World.cpp
--- a/LightClone/Source/World.cpp Wed Sep 21 10:26:48 2011 -0700
+++ b/LightClone/Source/World.cpp Wed Sep 21 12:18:15 2011 -0700
@@ -16,7 +16,6 @@
nGameState = GameState_Active;
nSimulationState = SimulationState_Idle;
pFunction = 0;
- nCurrentFunction = 0;
nCurrentLevel = 0;
}
@@ -122,7 +121,7 @@
kBot.kPosition = kLoader.GetInitialPosition();
kBot.kDirection = kLoader.GetInitialDirection();
- const uint32 nCount = kLoader.GetFunctionCount();
+ const uint32 nCount = 2;//kLoader.GetFunctionCount();
pFunction = new Code[nCount + 1];
pFunction[0].Initialize(MainFunctionLength);
@@ -135,6 +134,12 @@
pFunction[i + 1].Initialize(nLength);
pFunction[i + 1].Clear();
}
+
+ for(uint32 i = 0; i < nCount; ++i)
+ {
+ //kProgram.Initialize(i, kLoader.GetFunctionLength(i));
+ //kProgram.Clear(i);
+ }
}
}
@@ -292,6 +297,7 @@
pFunctionA->Initialize(pResourceManager);
pFunctionA->SetTexture("Data\\Textures\\PanelA.png");
pFunctionA->SetPosition(16.0f, 360.0f);
+ //pFunctionA->Upload(
GuiLabel* pFunctionBLabel = new GuiLabel();
pFunctionBLabel->Initialize(pResourceManager);
diff -r 4750819f465d -r b60cbf3fa894 LightClone/Source/World.h
--- a/LightClone/Source/World.h Wed Sep 21 10:26:48 2011 -0700
+++ b/LightClone/Source/World.h Wed Sep 21 12:18:15 2011 -0700
@@ -71,11 +71,6 @@
uint32 nCurrentLevel;
/*
- * nCurrentFunction
- */
- uint32 nCurrentFunction;
-
- /*
* kCameraController
*/
CameraController kCameraController;