Mercurial > LightClone
changeset 57:dc1f4a668d50
Fix issues with VM refactor
author | koryspansel <koryspansel@bendbroadband.com> |
---|---|
date | Fri, 30 Sep 2011 20:26:44 -0700 |
parents | 61b522f462e5 |
children | 5e382dee4c70 |
files | LightClone/Source/Compiler.cpp LightClone/Source/Mediator.cpp LightClone/Source/VirtualMachine.cpp LightClone/Source/World.cpp LightClone/Source/World.h LightClone/ToDo.txt |
diffstat | 6 files changed, 77 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/LightClone/Source/Compiler.cpp Fri Sep 30 18:39:58 2011 -0700 +++ b/LightClone/Source/Compiler.cpp Fri Sep 30 20:26:44 2011 -0700 @@ -57,19 +57,20 @@ // record the call to the specified function nCallTable[nOffset - 1] = nAction - Action_FunctionA + 1; } - else + //else - { - pData[nOffset++] = Instruction_Nop; - } - - nOffset += GetInstructionSizeFromAction(nAction); + //{ + // pData[nOffset++] = Instruction_Nop; + //} } else { return Error_Fail; } } + + // implicit return at the end of each function + pData[nOffset++] = Instruction_Return; } //PASS 2: Fixup function call addresses @@ -80,6 +81,8 @@ if(nFunction > 0) { + //ASSERT(nFunctionTable[nFunction] > 0); + // fixup address of function call pData[nAddress] = nFunctionTable[nFunction]; }
--- a/LightClone/Source/Mediator.cpp Fri Sep 30 18:39:58 2011 -0700 +++ b/LightClone/Source/Mediator.cpp Fri Sep 30 20:26:44 2011 -0700 @@ -28,7 +28,7 @@ ErrorCode eCode = Initialize(); if(eCode == Error_Success) { - float fAccumulator = 0.0f; + float fAccumulator = fUpdatePeriod; kClock.Reset();
--- a/LightClone/Source/VirtualMachine.cpp Fri Sep 30 18:39:58 2011 -0700 +++ b/LightClone/Source/VirtualMachine.cpp Fri Sep 30 20:26:44 2011 -0700 @@ -34,24 +34,19 @@ const uint8 nParameter = Advance(); TRACE(" -- Call Decoded: %d\n", nParameter); - const uint32 nFunction = nParameter; - const uint32 nContinuation = nInstructionPointer; - - PushFrame(nFunction, nContinuation); + PushFrame(nParameter, nInstructionPointer); } else if(nInstruction == Instruction_Return) { - if(pFrame) + if(!pFrame) { - PopFrame(); - } - else - { - // no frame to pop, we are done + // top level, program is complete return Action_Complete; } + + PopFrame(); } return Action_None; @@ -63,6 +58,14 @@ void VirtualMachine::Reset() { nInstructionPointer = 0; + + while(pFrame) + { + Frame* pInstance = pFrame; + pFrame = pInstance->pLast; + + kFrameAllocator.Free(pInstance); + } } /* @@ -131,6 +134,16 @@ pFrame = pInstance; } + uint32 nDepth = 0; + pInstance = pFrame; + while(pInstance) + { + ++nDepth; + pInstance = pInstance->pLast; + } + + TRACE("Stack Depth: %d\n", nDepth); + nInstructionPointer = nFunctionAddress; } @@ -139,16 +152,11 @@ */ void VirtualMachine::PopFrame() { - if(pFrame) - { - nInstructionPointer = pFrame->nContinuation; + //ASSERT(pFrame != NULL); + nInstructionPointer = pFrame->nContinuation; - Frame* pInstance = pFrame; - pFrame = pInstance->pLast; - - kFrameAllocator.Free(pInstance); - } - else - { - } + Frame* pInstance = pFrame; + pFrame = pInstance->pLast; + + kFrameAllocator.Free(pInstance); }
--- a/LightClone/Source/World.cpp Fri Sep 30 18:39:58 2011 -0700 +++ b/LightClone/Source/World.cpp Fri Sep 30 20:26:44 2011 -0700 @@ -13,7 +13,7 @@ */ World::World() { - nWorldState = WorldState_Main; + nWorldState = WorldState_Game; nLogicState = LogicState_LevelLoad; nSimulationState = SimulationState_Idle; nCurrentLevel = 0; @@ -46,7 +46,7 @@ } eCode = kProgram.Initialize(); - if(eCode == Error_Success) + if(eCode != Error_Success) { TRACE("Error: Failed to initialize program\n"); @@ -54,7 +54,7 @@ return eCode; } - eCode = InitializeInterface(pResourceManager); + eCode = InitializeInterface(pResourceManager, pInput); if(eCode != Error_Success) { TRACE("Error: Failed to initialize interface\n"); @@ -63,9 +63,11 @@ return eCode; } - pInputManager = pInput; - nLogicState = LogicState_LevelLoad; - nCurrentLevel = 0; + pInputManager = pInput; + nWorldState = WorldState_Game; + nLogicState = LogicState_LevelLoad; + nSimulationState = SimulationState_Idle; + nCurrentLevel = 0; return eCode; } @@ -142,7 +144,7 @@ */ void World::Update(float fElapsed) { - kInterface.Update(fElapsed); + pInputManager->Update(fElapsed); if(nWorldState == WorldState_Main) { @@ -159,6 +161,13 @@ if(nWorldState == WorldState_Pause) { } + else + + if(nWorldState == WorldState_Help) + { + } + + kInterface.Update(fElapsed); } /* @@ -170,24 +179,27 @@ kContext.Begin(nColor); - D3DVIEWPORT9 kOriginal; - kContext.GetViewport(&kOriginal); + if(nWorldState == WorldState_Game || nWorldState == WorldState_Confirm) + { + D3DVIEWPORT9 kOriginal; + kContext.GetViewport(&kOriginal); - D3DVIEWPORT9 kViewport; - kViewport.X = 0; - kViewport.Y = 0; - kViewport.Width = ScreenSizeX - 280; - kViewport.Height = ScreenSizeY; - kViewport.MinZ = kOriginal.MinZ; - kViewport.MaxZ = kOriginal.MaxZ; + D3DVIEWPORT9 kViewport; + kViewport.X = 0; + kViewport.Y = 0; + kViewport.Width = ScreenSizeX - 280; + kViewport.Height = ScreenSizeY; + kViewport.MinZ = kOriginal.MinZ; + kViewport.MaxZ = kOriginal.MaxZ; - kContext.SetViewport(kViewport); + kContext.SetViewport(kViewport); - kCameraController.SetMode(CameraMode_3D); - kEnvironment.Render(kContext, kCameraController); - kBot.Render(kContext, kCameraController); + kCameraController.SetMode(CameraMode_3D); + kEnvironment.Render(kContext, kCameraController); + kBot.Render(kContext, kCameraController); - kContext.SetViewport(kOriginal); + kContext.SetViewport(kOriginal); + } kCameraController.SetMode(CameraMode_2D); kInterface.Render(kContext, kCameraController); @@ -198,7 +210,7 @@ /* * InitializeInterface */ -ErrorCode World::InitializeInterface(ResourceManager* pResourceManager) +ErrorCode World::InitializeInterface(ResourceManager* pResourceManager, InputManager* pInputManager) { ErrorCode eCode = kInterface.Initialize(pResourceManager, pInputManager); if(eCode == Error_Success) @@ -354,8 +366,6 @@ */ void World::UpdateInput(float fElapsed) { - pInputManager->Update(fElapsed); - #if defined(_DEBUG) if(pInputManager->IsKeyDown(DIK_LEFT)) {
--- a/LightClone/Source/World.h Fri Sep 30 18:39:58 2011 -0700 +++ b/LightClone/Source/World.h Fri Sep 30 20:26:44 2011 -0700 @@ -212,7 +212,7 @@ /* * InitializeInterface */ - ErrorCode InitializeInterface(ResourceManager* pResourceManager); + ErrorCode InitializeInterface(ResourceManager* pResourceManager, InputManager* pInputManager); /* * RenderEnvironment
--- a/LightClone/ToDo.txt Fri Sep 30 18:39:58 2011 -0700 +++ b/LightClone/ToDo.txt Fri Sep 30 20:26:44 2011 -0700 @@ -5,7 +5,6 @@ 5. Help interface 6. Add asserts 7. Move resource manager into a service provider container -8. Refactor virtual machine -9. Rename CodePanel to ProgramPanel -10. Rename CodeSlot to ActionSlot -11. Refactor CodePanel/CodeSlot to read/write data to/from Program \ No newline at end of file +8. Rename CodePanel to ProgramPanel +9. Rename CodeSlot to ActionSlot +10. Refactor CodePanel/CodeSlot to read/write data to/from Program \ No newline at end of file