This page has been translated automatically.
UnigineScript
The Language
Core Library
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
Samples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Content Creation
Materials
Unigine Material Library
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.

Level Class

The level logic base class.

The Level class implementation can be found in the data/framework/game/level.h file.

Level Class

Members


Level ()

Constructor. Creates a new Level class instance.

void init (Game game, LevelData data)

Initializes a framework level. Creates entities, which are placed in the world.

Arguments

  • Game game - Game, to which the Level belongs to.
  • LevelData data - Level data.

void update ()

Updates a level.

void flush ()

Updates a level physics.

void render ()

The render is called after the update() function. At first, the onRender() function is called for entities, and then the onRender() function of the level is called.

void shutdown ()

Releases level resources.

void setPeriodicUpdate (variable instanse, string function, int frequency, int priority, variable arg0 = 0, variable arg1 = 0, variable arg2 = 0, variable arg3 = 0)

Sets the periodic update for the function.

Arguments

  • variable instanse - User class instance, for which the function is called. If the function is static, pass the NULL value.
  • string function - Function name.
  • int frequency - Frequency of the function call. The frequency takes on the values from 1 to 60.
  • int priority - Priority of the function call.
  • variable arg0 = 0 - Function argument, optional.
  • variable arg1 = 0 - Function argument, optional.
  • variable arg2 = 0 - Function argument, optional.
  • variable arg3 = 0 - Function argument, optional.

void removePeriodicUpdate (variable instanse, string function, int num_args = 0)

Removes the periodic update of the function.

Arguments

  • variable instanse - User class instance, for which the function is called. If the function is static, pass the NULL value.
  • string function - Function name.
  • int num_args = 0 - Number of function arguments.

void createEvent (string name)

Creates an event.

Arguments

  • string name - Unique event name.

void removeEvent (string name)

Removes an event.

Arguments

  • string name - Unique event name.

int isEvent (string name)

Returns a value indicating if an event with a specified name exists.

Arguments

  • string name - Event name.

Return value

1 if an event exists; otherwise 0.

void setEventEnabled (string name, int mode)

Sets a value indicating if an event enabled or disabled.

Arguments

  • string name - Event name.
  • int mode - 1 to enable an event; 0 to disable it.

int isEventEnabled (string name)

Returns a value indicating if an event is enabled.

Arguments

  • string name - Event name.

Return value

1 if the event is enabled; otherwise 0.

void callEvent (string name)

Calls an event.

Arguments

  • string name - Event name.

void callEvent (string name, variable p0, variable p1)

Calls an event within the specified area. Depending on the variables passed as p0 and p1 arguments, the specified area can be:
  • vec3 and vec3 - an event is called within the bounding box. Variables set the points of the bounding box minimum and maximum (by x, y, and z axes), respectively.
  • vec3 and float - an event is called within the bounding sphere. Variables set the sphere center and its radius, respectively.
  • mat4 and mat4 - an event is called within the view frustum. Variables set projection and modelview matrices, respectively.
Notice
Entities, subscribed to the event, must have a surface_base property to get an intersection and to be called.

Arguments

  • string name - Event name.
  • variable p0 - First variable.
  • variable p1 - Second variable.

void subscribe (string name, variable instanse, string function, variable arg0 = 0, variable arg1 = 0, variable arg2 = 0, variable arg3 = 0)

Subscribes a function to an event.

Arguments

  • string name - Event name.
  • variable instanse - User class instance, for which the function is called. If the function is static, pass the NULL value.
  • string function - Name of the function that is called when the event occurs.
  • variable arg0 = 0 - Function argument, optional.
  • variable arg1 = 0 - Function argument, optional.
  • variable arg2 = 0 - Function argument, optional.
  • variable arg3 = 0 - Function argument, optional.

void unsubscribe (string name, variable instanse, string function, int num_args = 0)

Unsubscribes a function from an event.

Arguments

  • string name - Event name.
  • variable instanse - User class instance, for which the function is called. If the function is static, pass the NULL value.
  • string function - Name of the function that is called when the event occurs.
  • int num_args = 0 - Number of function arguments.

void onWarm ()

Virtual method, which is called before the entities creation. This method is empty by default.

void onInit ()

Virtual method, which is called after the level initialization. This method is empty by default.

void onPreUpdate ()

Virtual method, which is called before the entity update. This method is empty by default.

void onPostUpdate ()

Virtual method, which is called after the entity update. This method is empty by default.

void onFlush ()

Virtual method, which is called after the entity physics update. This method is empty by default.

void onShutdown ()

Virtual method, which is called after the level resources release. In this method, you need to unsubscribe from the events and remove the periodic update of the functions. This method is empty by default.

void onRender ()

Virtual method, which is called after the render() call.

Entity createEntity (string type, string name = "")

Creates an entity of a specified type. This function checks presence of the entity of the specified type in the pool and returns such entity if exists; otherwise the function creates the new entity and loads a new node reference, which corresponds to the new entity class.

Arguments

  • string type - Entity type.
  • string name = "" - Entity name, optional.

Return value

Entity.

void removeEntity (Entity entity, int mode = 0)

Deletes an entity by using one of the deleting options.

Arguments

void appendEntity (Entity entity)

Appends an entity to the entity list.

Arguments

  • Entity entity - Entity to append.

int getNumEntities ()

Returns a number of entities.

Return value

Number of entities.

Entity getEntity (variable index)

Returns an entity by its index.

Arguments

  • variable index - Entity index if index is an integer; entity name if index is a string.

Return value

Entity if exists; otherwise NULL.

void getEntities (string type = "", Entity ret[])

Selects the specified entities from all of the level entities.

Arguments

  • string type = "" - Name of the entities class. If type is an empty string, all of the entities types are added to the pool.
  • Entity ret[] - An array, to which the entities will be placed to.

void getEntities (string type = "", int childs = 1, Entity ret[])

Selects the specified entities from all of the level entities.

Arguments

  • string type = "" - Name of the entities class. If type is an empty string, all of the entities types are added to the pool.
  • int childs = 1 - A flag indicating if the entity class children are added to the array.
  • Entity ret[] - An array, to which the entities will be placed to.

void getIntersectionNodesEntity (variable p0, variable p1, string type = "", int filter, int childs = 1, Entity ret[])

Searches for the entities among the nodes within the specified area. Depending on the variables passed as p0 and p1 arguments, the specified area can be:
  • vec3 and vec3 - an event is called within the bounding box. Variables set the points of the bounding box minimum and maximum (by x, y, and z axes), respectively.
  • vec3 and float - an event is called within the bounding sphere. Variables set the sphere center and its radius, respectively.
  • mat4 and mat4 - an event is called within the view frustum. Variables set projection and modelview matrices, respectively.
Notice
A root node of the node reference, to which an entity is binded, must have a surface_base property to get an intersection and to be returned.

Arguments

  • variable p0 - First variable.
  • variable p1 - Second variable.
  • string type = "" - Name of the entities class. If type is an empty string, all of the entities types are added to the pool.
  • int filter - Node type filter (one of the NODE_* variables), -1 not to use a filter.
  • int childs = 1 - A flag indicating if the entity class children are added to the array.
  • Entity ret[] - An array, to which the entities will be placed to.

void getIntersectionObjectsEntity (variable p0, variable p1, string type = "", int childs = 1, Entity ret[])

Searches for the entities among the objects within the specified area. Depending on the variables passed as p0 and p1 arguments, the specified area can be:
  • vec3 and vec3 - an event is called within the bounding box. Variables set the points of the bounding box minimum and maximum (by x, y, and z axes), respectively.
  • vec3 and float - an event is called within the bounding sphere. Variables set the sphere center and its radius, respectively.
  • mat4 and mat4 - an event is called within the view frustum. Variables set projection and modelview matrices, respectively.
Notice
A root node of the node reference, to which an entity is binded, must have a surface_base property to get an intersection and to be returned.

Arguments

  • variable p0 - First variable.
  • variable p1 - Second variable.
  • string type = "" - Name of the entities class. If type is an empty string, all of the entities types are added to the pool.
  • int childs = 1 - A flag indicating if the entity class children are added to the array.
  • Entity ret[] - An array, to which the entities will be placed to.

void setEntityEventEnabled (Entity entity, int event, int mode)

Toggles a call of the entity special function.

Arguments

  • Entity entity - Entity.
  • int event - One of the ENTITY_EVENT_* values.
  • int mode - 1 to enable a call of the function, which is specified by the ENTITY_EVENT_* value; 0 to disable it.

void setEntityEnabled (Entity entity, int mode)

Toggles an entity.

Arguments

  • Entity entity - Entity.
  • int mode - 1 to enable an entity; 0 to disable it.

void setEntityUpadeOrder (Entity entity, int order)

Sets an update order for the entity.

Arguments

  • Entity entity - Entity.
  • int order - Update order. This argument can take on the values from 0 to 16. The default is 8.

string getName ()

Returns a level name.

Return value

Level name.

Game getGame ()

Returns the game, to which the level belongs to.

Return value

Game.

int ENTITY_EVENT_UPDATE

Description

Represents the onUpdate() function.

int ENTITY_EVENT_FLUSH

Description

Represents the onFlush() function.

int ENTITY_EVENT_RENDER

Description

Represents the onRender() function.

int REMOVE_ENTITY_MODE_DEFAULT

Description

Deletes an entity, but not a node reference.

int REMOVE_ENTITY_MODE_DELETE_NODE

Description

Deletes an entity and a node reference.

int REMOVE_ENTITY_MODE_POOL

Description

Adds an entity and a node reference to the pool. The pool provides an ability to create new entities faster: if the entity is in the pool, there is no need to create the node reference from the file, because it is already in the pool.
Last update: 2017-07-03
Build: ()