This page has been translated automatically.
Programming
Setting Up Development Environment
UnigineScript
High-Level Systems
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
API
Core Library
Containers
Engine Classes
Node-Related Classes
Rendering-Related Classes
Physics-Related Classes
Bounds-Related Classes
GUI-Related Classes
Controls-Related Classes
Pathfinding-Related Classes
Utility Classes
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

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:

New classes' methods are called automatically by engine after equivalent scripts' methods.

Prior Knowledge
This article assumes you have prior knowledge of the following topics. Please read them before proceeding:
Notice
When you created a new project, all necessary classes are inherited automatically from corresponding new logic system classes.

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:

Source code(C++)
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):

Source code(C++)
#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:

Source code(C++)
#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;
}

Last update: 2017-07-03
Build: ()