This page has been translated automatically.
Видеоуроки
Интерфейс
Основы
Продвинутый уровень
Подсказки и советы
Основы
Программирование на C#
Рендеринг
Профессиональный уровень (SIM)
Принципы работы
Свойства (properties)
Компонентная Система
Рендер
Режимы вывода изображения
Физика
Браузер SDK 2
Лицензирование и типы лицензий
Дополнения (Add-Ons)
Демонстрационные проекты
API Samples
Редактор UnigineEditor
Обзор интерфейса
Работа с ассетами
Контроль версий
Настройки и предпочтения
Работа с проектами
Настройка параметров ноды
Setting Up Materials
Настройка свойств
Освещение
Sandworm
Использование инструментов редактора для конкретных задач
Расширение функционала редактора
Встроенные объекты
Ноды (Nodes)
Объекты (Objects)
Эффекты
Декали
Источники света
Geodetics
World-ноды
Звуковые объекты
Объекты поиска пути
Player-ноды
Программирование
Основы
Настройка среды разработки
Примеры использования
C++
C#
UnigineScript
Унифицированный язык шейдеров UUSL (Unified UNIGINE Shader Language)
Плагины
Форматы файлов
Материалы и шейдеры
Rebuilding the Engine Tools
Интерфейс пользователя (GUI)
Двойная точность координат
API
Animations-Related Classes
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
VR-Related Classes
Работа с контентом
Оптимизация контента
Материалы
Визуальный редактор материалов
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Учебные материалы

Unigine::Signal Class

Header: #include <UnigineSignal.h>

This class implements the system of signals enabling synchronization of certain actions with certain events that occur asynchronously.

Example#

The following example illustrates how to make multiple subscriptions for a signal and cancel them if they are no longer needed, as well as how to invoke signals when necessary.

Source code (C++)
#include <UnigineSignal.h>

class MyClass1
{
public:
	MyClass1() {}
	virtual ~MyClass1() {}

	// first callback function to be fired in case the signal is invoked
	int MySignalCallback1() {
		// do some actions
		Log::message("REPORT: MySignalCallback1() is called!");

		return 1;
	}
};
	
// second callback function to be fired in case the signal is invoked
int MySignalCallback2() {
	// do some actions (e.g. play a sound)
	Log::message("REPORT: MySignalCallback2() is called!");
	return 1;
}

// declaring an instance of the MyClass1
MyClass1 MyClass1Instance;

class MyClass2
{
public:
	Signal my_signal;	// Signal declaration

	int init() 
	{
		// subscribing MyClass1Instance for the signal by adding a callback
		my_signal.add(MakeCallback(&MyClass1Instance, &MyClass1::MySignalCallback1));
		
		// subscribing for the signal by adding another callback and saving its ID to unsubscribe later
		void *cb2_id = my_signal.add(MakeCallback(MySignalCallback2));
		
		//...
		
		// whenever you want, execute the event (at this moment both callbacks will be fired)
		my_signal.invoke();
		
		// cancelling a subscription by removing a callback via ID
		my_signal.remove(cb2_id);

		return 0;

	}
	int shutdown(){
		// execute the event on shutdown (at this moment only the MyClass1::MySignalCallback1() callbacks will be fired, as the second one is no longer subscribed)
		my_signal.invoke();
	}
};

Signal Class

Members


static SignalPtr create ( ) #

static SignalPtr create ( const Signal& ) #

Arguments

  • const Signal&

static SignalPtr create ( Signal&& ) #

Arguments

  • Signal&&

void * add ( CallbackBase* callback ) #

Adds a callback function to be fired when the signal is invoked (subscription for the signal). Callback functions can be used to determine specific actions to be performed when the signal is invoked.

Arguments

  • CallbackBase* callback

Return value

ID of the added callback, if the callback was added successfully; otherwise, nullptr. This ID can be used to remove this callback when necessary.

bool remove ( void* id ) #

Removes the specified callback from the list of callbacks associated with the signal. Callback functions can be used to determine specific actions to be performed when the signal is invoked.

Arguments

  • void* id - Callback ID obtained when adding it.

Return value

true if the callback with the given ID was removed successfully; otherwise false.

void clear ( ) #

Clears the list of callbacks subscribed for the signal (all subscriptions are removed).

bool empty ( ) const#

Returns a value indicating if the list of subscriptions for the signal is empty.

Return value

true if the list of subscriptions for the signal is empty otherwise false.

int size ( ) const#

Returns the total number of callback functions subscribed for the signal.

Return value

Number of subscriptions for the signal.

template<typename ... Ts> invoke ( Ts&& args ) #

Invokes the signal. Callback functions subscribed for this signal are executed according to their order in the list.

Arguments

  • Ts&& args

void swap ( Signal& first, Signal& second ) #

Swaps the two specified signals.

Arguments

  • Signal& first - First signal.
  • Signal& second - Second signal.
Last update: 13.12.2024
Build: ()