New Logic System
Since Unigine 2.2 version the logic implementing of C++ and C# application has a different approach.
From now you don't need to interfere the main loop of the engine by yourself, the engine provides you classes which should be inherited.
The logic of these classes is the same as for runtime scripts:
- WorldLogic class has the same logic as world script.
- SystemLogic class has the same logic as system script.
- EditorLogic class has the same logic as editor script.
New classes' methods are called automatically by engine after equivalent scripts' methods.
Essential Changes
In earlier Unigine versions, you need to interrupt the engine main loop by inserting your own my_update(), my_render(), my_swap() functions (when you develop C++/C# application). Here is a code example of such implementation:
while (engine->isDone() == 0) {
// update in the main loop
engine->update();
// update the application
my_update();
// render in the main loop
engine->render();
my_render();
// swap in the main loop
engine->swap();
my_swap();
}
Engine calls these functions after all the functions inside Engine::update() were performed:
Now you should create new classes by inheriting WorldLogic, SystemLogic, EditorLogic classes and implement your methods inside (here's an example of AppWorldLogic.h):
#include <UnigineLogic.h>
#include <UnigineStreams.h>
class AppWorldLogic : public Unigine::WorldLogic {
public:
AppWorldLogic();
virtual ~AppWorldLogic();
virtual int init();
virtual int shutdown();
virtual int destroy();
virtual int update();
virtual int render();
virtual int flush();
virtual int save(const Unigine::StreamPtr &stream);
virtual int restore(const Unigine::StreamPtr &stream);
};
All the implemented WorldLogic class functions will be called by engine after corresponding world script's methods: init(), update(), etc.
You should implement these methods (since they are virtual), create the instance of these classes and pass it to the engine main function:
#include <UnigineEngine.h>
#include "AppSystemLogic.h"
#include "AppWorldLogic.h"
#include "AppEditorLogic.h"
using namespace Unigine;
#ifdef _WIN32
int wmain(int argc,wchar_t *argv[]) {
#else
int main(int argc,char *argv[]) {
#endif
AppSystemLogic system_logic;
AppWorldLogic world_logic;
AppEditorLogic editor_logic;
Unigine::EnginePtr engine(UNIGINE_VERSION,argc,argv);
engine->main(&system_logic,&world_logic,&editor_logic);
return 0;
}