Unigine::LandscapeMapFileCreator Class
Header: | #include <UnigineObjects.h> |
This class is used to generate a landscape map file (.lmap) to be used for landscape layer map creation.
Usage Example#
// callbacks to be fired in the process of landscape map file creation
void progress(LandscapeMapFileCreatorPtr creator)
{
Log::message("%d %f\n", int(creator->getProgress()), creator->getTimeSeconds());
}
void begin(LandscapeMapFileCreatorPtr creator)
{
Log::message("%f\n", creator->getProgress());
}
void end(LandscapeMapFileCreatorPtr creator)
{
Log::message("%f\n", creator->getTimeSeconds());
}
// ...
// defining grid size (2х2 tiles) and resolution
ivec2 grid = ivec2(2,2);
ivec2 resolution = ivec2(2048) * grid;
// creating a landscape map file creator and setting grid size, resolution, and path
creator = LandscapeMapFileCreator::create();
creator->setGrid(grid);
creator->setResolution(resolution);
creator->setPath("test.lmap");
// adding necessary callbacks
creator->addCreateCallback(MakeCallback(&create));
creator->addProgressCallback(MakeCallback(&progress));
creator->addBeginCallback(MakeCallback(&begin));
creator->addEndCallback(MakeCallback(&end));
// running the creator to generate a new "test.lmap" file
creator->run();
// ...
// creating a new landscape layer map based on the created "test.lmap" file
landscape_map = LandscapeLayerMap::create();
landscape_map->setPath("test.lmap");
LandscapeMapFileCreator Class
Members
LandscapeMapFileCreator ( ) #
The LandscapeMapFileCreator constructor.void setResolution ( const Math::ivec2 & resolution ) #
Sets a new landscape map resolution.Arguments
- const Math::ivec2 & resolution - Two-component vector (X, Y) representing new landscape map resolution along X and Y axes to be set.
Math::ivec2 getResolution ( ) #
Returns the current landscape map resolution.Return value
Two-component vector (X, Y) representing current landscape map resolution along X and Y axes.void setGrid ( const Math::ivec2 & grid ) #
Sets a new grid size for the landscape map.Arguments
- const Math::ivec2 & grid - Two-component vector (X, Y) representing number of tiles of the landscape map along X and Y axes.
Math::ivec2 getGrid ( ) #
Returns the current grid size for the landscape map.Return value
Two-component vector (X, Y) representing number of tiles of the landscape map along X and Y axes.float getProgress ( ) #
Returns the current landscape map file creation progress.Return value
Current landscape map file creation progress (percentage).double getTimeSeconds ( ) #
Returns the landscape map file creation time. You can use this method to get total file generation time when processing an End callback.Return value
Landscape map file creation time, in seconds.void setPath ( const char * path ) #
Sets a new path to the .lmap file to be generated.Arguments
- const char * path - New path to the .lmap file to be generated.
const char * getPath ( ) #
Returns a path to the .lmap file to be generated.Return value
Path to the .lmap file to be generated.void run ( bool is_empty = false, bool is_safe = true ) #
Runs the landscape map file creation process. You can set callbacks to be fired in the beginning, upon completion and during the process to monitor progress and display statistics.Arguments
- bool is_empty - true to create an empty .lmap file (e.g., when you create a layer map to be manually sculpted from scratch using brushes), false - to get necessary data from the sources and put them to the generated .lmap file.
- bool is_safe - true to make the Engine automatically call filesClose()/fileOpen() methods when performing operations (before modifying an .lmap file the Engine should release files via filesClose(), while after modification fileOpen() should be called), false - to call filesClose()/fileOpen() methods manually.
The Landscape class has two overloads for the filesClose() method:
- filesClose() - to be called in case of moving an .lmap file (no data reloading is performed as the file itself was not modified - saves time on reloading data)
- filesClose(reload_files) - to be called in case of deleting or modifying an .lmap file.
When is_safe = true the Engine shall always call filesClose(reload_files) with complete data reloading.
void * addCreateCallback ( Unigine::CallbackBase4< Ptr<LandscapeMapFileCreator>, Ptr<LandscapeImages>, int, int > * func ) #
Adds a callback function to be called on creating a landscape layer map file. The signature of the callback function must be as follows:void create_callback(LandscapeMapFileCreatorPtr creator, LandscapeImages images, int x, int, y);
You can set a callback function as follows:
addCreateCallback(MakeCallback(create_callback));
Example: Setting a landscape layer map file creation callback function for a certain class:
// callback function implementing certain actions to be performed on creating a landscape layer map file
void CreateFile(LandscapeMapFileCreatorPtr creator, LandscapeImages images, int x, int, y)
{
// insert your specific landscape layer map file creation handling code here
}
// ...
virtual int AppWorldLogic::init()
{
// setting the CreateFile() function to handle file creation
Landscape::addCreateCallback(MakeCallback(&CreateFile));
}
Arguments
- Unigine::CallbackBase4< Ptr<LandscapeMapFileCreator>, Ptr<LandscapeImages>, int, int > * func - Callback pointer.
Return value
ID of the last added landscape layer map file creation callback, if the callback was added successfully; otherwise, nullptr. This ID can be used to remove this callback when necessary.bool removeCreateCallback ( void * id ) #
Removes the specified callback from the list of create file callbacks.Arguments
- void * id - Create file callback ID obtained when adding it.
Return value
True if the create file callback with the given ID was removed successfully; otherwise false.void clearCreateCallback ( ) #
Clears all added create file callbacks.void * addProgressCallback ( Unigine::CallbackBase1< Ptr<LandscapeMapFileCreator> > * func ) #
Adds a callback function to be called on landscape map file creation progress. The signature of the callback function must be as follows:void progress_callback(LandscapeMapFileCreatorPtr creator);
You can set a callback function as follows:
addProgressCallback(MakeCallback(progress_callback));
Example: Setting a progress callback function for a certain class:
// callback function implementing certain actions to be performed on landscape map file creation progress
void FileCreationProgress(LandscapeMapFileCreatorPtr creator)
{
// insert your specific progress handling code here
}
// ...
virtual int AppWorldLogic::init()
{
// setting the FileCreationProgress() function to handle landscape map file creation progress
Landscape::addProgressCallback(MakeCallback(&FileCreationProgress));
}
Arguments
- Unigine::CallbackBase1< Ptr<LandscapeMapFileCreator> > * func - Callback pointer.
Return value
ID of the last added progress callback, if the callback was added successfully; otherwise, nullptr. This ID can be used to remove this callback when necessary.bool removeProgressCallback ( void * id ) #
Removes the specified callback from the list of progress callbacks.Arguments
- void * id - Progress callback ID obtained when adding it.
Return value
True if the progress callback with the given ID was removed successfully; otherwise false.void clearProgressCallback ( ) #
Clears all added progress callbacks.void * addBeginCallback ( Unigine::CallbackBase1< Ptr<LandscapeMapFileCreator> > * func ) #
Adds a callback function to be called on beginning the landscape map file creation. The signature of the callback function must be as follows:void begin_callback(LandscapeMapFileCreatorPtr creator);
You can set a callback function as follows:
addBeginCallback(MakeCallback(begin_callback));
Example: Setting a begin file creation callback function for a certain class:
// callback function implementing certain actions to be performed on beginning the landscape map file creation
void FileCreationBegin(LandscapeMapFileCreatorPtr creator)
{
// insert your specific handling code here
}
// ...
virtual int AppWorldLogic::init()
{
// setting the FileCreationBegin() function to handle beginning of the landscape map file creation
Landscape::addBeginCallback(MakeCallback(&FileCreationBegin));
}
Arguments
- Unigine::CallbackBase1< Ptr<LandscapeMapFileCreator> > * func - Callback pointer.
Return value
ID of the last added begin file creation callback, if the callback was added successfully; otherwise, nullptr. This ID can be used to remove this callback when necessary.bool removeBeginCallback ( void * id ) #
Removes the specified callback from the list of begin file creation callbacks.Arguments
- void * id - Begin callback ID obtained when adding it.
Return value
True if the begin file creation callback with the given ID was removed successfully; otherwise false.void clearBeginCallback ( ) #
Clears all added begin file creation callbacks.void * addEndCallback ( Unigine::CallbackBase1< Ptr<LandscapeMapFileCreator> > * func ) #
Adds a callback function to be called on completion of the landscape map file creation. The signature of the callback function must be as follows:void end_callback(LandscapeMapFileCreatorPtr creator);
You can set a callback function as follows:
addEndCallback(MakeCallback(end_callback));
Example: Setting a file creation completion callback function for a certain class:
// callback function implementing certain actions to be performed on completion of the landscape map file creation
void FileCreationEnd(LandscapeMapFileCreatorPtr creator)
{
// insert your specific handling code here
}
// ...
virtual int AppWorldLogic::init()
{
// setting the FileCreationEnd() function to handle completion of the landscape map file creation
Landscape::addEndCallback(MakeCallback(&FileCreationEnd));
}
Arguments
- Unigine::CallbackBase1< Ptr<LandscapeMapFileCreator> > * func - Callback pointer.
Return value
ID of the last added file creation completion callback, if the callback was added successfully; otherwise, nullptr. This ID can be used to remove this callback when necessary.bool removeEndCallback ( void * id ) #
Removes the specified callback from the list of file creation completion callbacks.Arguments
- void * id - End callback ID obtained when adding it.
Return value
True if the progress callback with the given ID was removed successfully; otherwise false.void clearEndCallback ( ) #
Clears all added file creation completion callbacks.Last update:
2021-04-09
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)