Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#Actualuglybdavis

Posted 14 November 2012 - 11:24 AM

Constructor.

Ideally you would want: Constructor > [optional] Deserialization > Initialization. The nice thing about LUA reading plain text is you can at any point save the state of a lua file (Or lua object as i like to think of it), then read it back in.

Not related to my last post, but here is some pseudocode:
[source lang="cpp"]#include <iostream>class ScriptComponent : Component {protected: WhateverLuaWrapperYouHaveForInternalObject* lua_obj; std::vector<LuaCoroutineWrappers*> lua_coroutines; ScriptComponent(const ScriptComponent&); ScriptComponent& operator=(const ScriptComponent&);public: Component(char* luaFile) { // Some arbitrary way to get your lua "Object" lua_obj = LoadLuaFile(luaFile)->newObject("type"); lua_obj->Awake(); ObjectEnabled(); Start(); } ~Component() { ObjectDisable(); lua_obj->Destroy(); delete lua_obj; } void ObjectEnabled() { lua_obj->OnEnable(); } void ObjectDisable() { lua_obj->OnDisable(); } void Start() { lua_obj->Start(); } void Update(float dt) { lua_obj->Update(dt); for (int i = 0, size = int(lua_coroutines.size()); i < size; ++i) {} lua_coroutines[i]->ProcessYieldingForNull(); lua_coroutines[i]->ProcessYieldingForTime(dt); } } void FixedUpdate(float dt) { // dt being a constant at this point lua_obj->FixedUpdate(dt); for (int i = 0, size = int(lua_coroutines.size()); i < size; ++i) lua_coroutines[i]->ProcessYieldingForFixedUpdate(); } void LateUpdate(float dt) { lua_obj->LateUpdate(dt); for (int i = 0, size = int(lua_coroutines.size()); i < size; ++i) lua_coroutines[i]->ProcessYieldingForEndOfFrame(); } void ObjectWillRender() { lua_obj->OnWillRenderObject(); }};[/source]

Referring to an object lifecycle that looks something like so:
Posted Image

#1uglybdavis

Posted 14 November 2012 - 11:23 AM

Constructor.

Ideally you would want: Constructor > [optional] Deserialization > Initialization. The nice thing about LUA reading plain text is you can at any point save the state of a lua file (Or lua object as i like to think of it), then read it back in.

Not related to my last post, but here is some pseudocode:
[source lang="cpp"]#include <iostream>class ScriptComponent : Component {protected: WhateverLuaWrapperYouHaveForInternalObject* lua_obj; std::vector<LuaFunctionPointers*> lua_coroutines; ScriptComponent(const ScriptComponent&); ScriptComponent& operator=(const ScriptComponent&);public: Component(char* luaFile) { // Some arbitrary way to get your lua "Object" lua_obj = LoadLuaFile(luaFile)->newObject("type"); lua_obj->Awake(); ObjectEnabled(); Start(); } ~Component() { ObjectDisable(); lua_obj->Destroy(); delete lua_obj; } void ObjectEnabled() { lua_obj->OnEnable(); } void ObjectDisable() { lua_obj->OnDisable(); } void Start() { lua_obj->Start(); } void Update(float dt) { lua_obj->Update(dt); for (int i = 0, size = int(lua_coroutines.size()); i < size; ++i) {} lua_coroutines[i]->ProcessYieldingForNull(); lua_coroutines[i]->ProcessYieldingForTime(dt); } } void FixedUpdate(float dt) { // dt being a constant at this point lua_obj->FixedUpdate(dt); for (int i = 0, size = int(lua_coroutines.size()); i < size; ++i) lua_coroutines[i]->ProcessYieldingForFixedUpdate(); } void LateUpdate(float dt) { lua_obj->LateUpdate(dt); for (int i = 0, size = int(lua_coroutines.size()); i < size; ++i) lua_coroutines[i]->ProcessYieldingForEndOfFrame(); } void ObjectWillRender() { lua_obj->OnWillRenderObject(); }};[/source]

Referring to an object lifecycle that looks something like so:
Posted Image

PARTNERS