diff LightClone/Source/Program.cpp @ 38:2caa7c7e2cb5

Refactored program; Added dialog
author koryspansel
date Wed, 21 Sep 2011 21:40:19 -0700
parents 58a16d529d95
children 8cefb65577cc
line wrap: on
line diff
--- a/LightClone/Source/Program.cpp	Wed Sep 21 20:30:29 2011 -0700
+++ b/LightClone/Source/Program.cpp	Wed Sep 21 21:40:19 2011 -0700
@@ -5,24 +5,6 @@
 #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()
@@ -34,7 +16,7 @@
  */
 ErrorCode Program::Initialize()
 {
-	return Error_Success;
+	return Clear(), Error_Success;
 }
 
 /*
@@ -45,16 +27,34 @@
 }
 
 /*
+ * SetAction
+ */
+void Program::SetAction(uint32 nFunction, uint32 nIndex, uint32 nAction)
+{
+	if(nFunction < FunctionCount && nIndex < Function::MaximumInstructionCount)
+	{
+		kFunction[nFunction].nInstruction[nIndex] = nAction;
+	}
+}
+
+/*
  * Clear
  */
 void Program::Clear()
 {
+	for(uint32 i = 0; i < FunctionCount; ++i)
+	{
+		for(uint32 j = 0; j < Function::MaximumInstructionCount; ++j)
+		{
+			kFunction[i].nInstruction[j] = Action_Default;
+		}
+	}
 }
 
 /*
  * Upload
  */
-ErrorCode Program::Upload(VirtualMachine& kMachine)
+ErrorCode Program::Upload(VirtualMachine& kMachine) const
 {
 	ErrorCode eCode = Error_Success;
 
@@ -62,7 +62,7 @@
 	kMachine.ClearMemory();
 	kMachine.RemoveAllFunctions();
 
-	for(uint32 i = 0; i < nFunctionCount && eCode == Error_Success; ++i)
+	for(uint32 i = 0; i < FunctionCount && eCode == Error_Success; ++i)
 	{
 		kMachine.AddFunction(i, kFunction[i].CalculateSize());
 
@@ -78,7 +78,7 @@
 /*
  * Compile
  */
-ErrorCode Program::Compile(uint32 nIndex, uint8* pData, uint32 nSize)
+ErrorCode Program::Compile(uint32 nIndex, uint8* pData, uint32 nSize) const
 {
 	for(uint32 i = 0; i < Function::MaximumInstructionCount; ++i)
 	{