This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Landscape Tool
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Containers
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
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

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_signalremove(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: 2021-12-13
Build: ()