Mercurial > LightClone
comparison LightClone/Source/Program.cpp @ 53:8cefb65577cc
Clean up world states
author | koryspansel |
---|---|
date | Fri, 30 Sep 2011 15:23:16 -0700 |
parents | 2caa7c7e2cb5 |
children | 95677f648a2c |
comparison
equal
deleted
inserted
replaced
52:2444937929ae | 53:8cefb65577cc |
---|---|
58 { | 58 { |
59 ErrorCode eCode = Error_Success; | 59 ErrorCode eCode = Error_Success; |
60 | 60 |
61 kMachine.Reset(); | 61 kMachine.Reset(); |
62 kMachine.ClearMemory(); | 62 kMachine.ClearMemory(); |
63 kMachine.RemoveAllFunctions(); | 63 //kMachine.RemoveAllFunctions(); |
64 | 64 |
65 for(uint32 i = 0; i < FunctionCount && eCode == Error_Success; ++i) | 65 //uint32 nSize = kMachine.GetMemorySize(); |
66 { | 66 //uint8* pData = kMachine.GetMemoryPointer(); |
67 kMachine.AddFunction(i, kFunction[i].CalculateSize()); | |
68 | 67 |
69 uint32 nSize = kMachine.GetFunctionSize(i); | 68 //for(uint32 i = 0; i < FunctionCount && eCode == Error_Success; ++i) |
70 uint8* pData = kMachine.GetFunctionMemory(i); | 69 //{ |
71 | 70 // eCode = Compile(i, pData, nSize); |
72 eCode = Compile(i, pData, nSize); | 71 //} |
73 } | |
74 | 72 |
75 return eCode; | 73 return eCode; |
76 } | 74 } |
77 | 75 |
78 /* | 76 /* |
79 * Compile | 77 * Compile |
80 */ | 78 */ |
81 ErrorCode Program::Compile(uint32 nIndex, uint8* pData, uint32 nSize) const | 79 ErrorCode Program::Compile(uint32 nIndex, uint8* pData, uint32 nSize) const |
82 { | 80 { |
83 for(uint32 i = 0; i < Function::MaximumInstructionCount; ++i) | 81 ErrorCode eCode = Error_Success; |
82 | |
83 for(uint32 i = 0; i < Function::MaximumInstructionCount && eCode == Error_Success; ++i) | |
84 { | 84 { |
85 const uint32 nAction = kFunction[nIndex].nInstruction[i]; | 85 // encode user-defined actions |
86 eCode = EncodeAction(kFunction[nIndex].nInstruction[i], pData, nSize); | |
87 } | |
86 | 88 |
87 if(Action_Forward <= nAction && nAction <= Action_Light) | 89 if(eCode == Error_Success) |
90 { | |
91 if(nSize > 0) | |
88 { | 92 { |
89 if(nSize < 2) | 93 // add implicit return statement |
90 return Error_Fail; | 94 *pData++ = Instruction_End; |
95 } | |
96 else | |
97 { | |
98 eCode = Error_Fail; | |
99 } | |
100 } | |
91 | 101 |
102 return eCode; | |
103 } | |
104 | |
105 /* | |
106 * EncodeAction | |
107 */ | |
108 ErrorCode Program::EncodeAction(uint32 nAction, uint8*& pData, uint32& nSize) const | |
109 { | |
110 if(Action_Forward <= nAction && nAction <= Action_Light) | |
111 { | |
112 if(nSize >= 2) | |
113 { | |
92 *pData++ = Instruction_Action; | 114 *pData++ = Instruction_Action; |
93 *pData++ = nAction; | 115 *pData++ = nAction; |
94 | 116 |
95 nSize -= 2; | 117 return nSize -= 2, Error_Success; |
96 } | 118 } |
97 else | 119 } |
120 else | |
98 | 121 |
99 if(Action_FunctionA <= nAction && nAction <= Action_FunctionB) | 122 if(Action_FunctionA <= nAction && nAction <= Action_FunctionB) |
123 { | |
124 if(nSize >= 2) | |
100 { | 125 { |
101 if(nSize < 2) | |
102 return Error_Fail; | |
103 | |
104 *pData++ = Instruction_Call; | 126 *pData++ = Instruction_Call; |
105 *pData++ = nAction - Action_FunctionA + 1; | 127 *pData++ = nAction - Action_FunctionA + 1; |
106 | 128 |
107 nSize -= 2; | 129 return nSize -= 2, Error_Success; |
130 } | |
131 } | |
132 else | |
133 | |
134 { | |
135 if(nSize >= 1) | |
136 { | |
137 *pData++ = Instruction_None; | |
138 | |
139 return nSize -= 1, Error_Success; | |
108 } | 140 } |
109 } | 141 } |
110 | 142 |
111 return Error_Success; | 143 return Error_Fail; |
112 } | 144 } |