Jump to content

sync ObjectTerrainGlobal


photo

Recommended Posts

image.thumb.png.c7b607f86af28d30a18cd957e8a307fd.png

I applied the seasonal changes of the terrain using the parameters shown in the picture.

To apply syncker synchronization, should I just use "syncNode (const unigine::NodePtr &in_node, unsigned char mask = ~0)" function?
(put in landsacpe node in "in_node" parameter, mask = Master::OBJECT)

Link to comment

runtime terrain changes are not synchronized.

you can do it manually using custom messages.

int AppWorldLogic::init()
{
  	// for slave
	auto sm = Plugins::Syncker::Manager::get();
	if (sm)
	{
		auto slave = sm->getSlave();
		if (slave)
		{
			// method on_terrain_update will be called on the slave when the message "terrain_update" arrives.
			slave->setMessageReceivedCallback("terrain_update", MakeCallback(this, &AppWorldLogic::on_terrain_update));
		}
	}
	
	return 1;
}

void AppWorldLogic::update_terrain(int detail, float threshold, float width, float contrast)
{
	auto terrain = checked_ptr_cast<ObjectTerrainGlobal>(World::getNodeByType(Node::OBJECT_TERRAIN_GLOBAL)); // < too slow. find and save terrain should be in init
	
	// apply parameters to terrain
	terrain->getDetail(detail)->setMaskThreshold(threshold);
	terrain->getDetail(detail)->setMaskWidth(width);
	terrain->getDetail(detail)->setMaskContrast(contrast);
	
	
	auto sm = Plugins::Syncker::Manager::get(); // < too slow. find and save syncker should be in init
	if (sm)
	{
		auto master = sm->getMaster();
		if (master)
		{
			// send message "terrain_update" with parameters
			BlobPtr blob = Blob::create();
			blob->writeInt(detail);
			blob->writeFloat(threshold);
			blob->writeFloat(width);
			blob->writeFloat(contrast);
			
			master->sendMessage("terrain_update", blob);
		}
	}
}

void AppWorldLogic::on_terrain_update(const Unigine::BlobPtr &message)
{
	// read message in the same order of parameters
	int detail = message->readInt();
	float threshold = message->readFloat();
	float width = message->readFloat();
	float contrast = message->readFloat();
	// invoke update_terrain for apply parameters
	update_terrain(detail, threshold, width, contrast);
}

int AppWorldLogic::update()
{
    // for master
	if (App::clearKeyState('t'))
	{
		update_terrain(1, 2.0, 3.0f, 4.0f);
	}
	
	return 1;
}

 

  • Like 1
Link to comment

Thank you for the detailed sample. It wasn't as simple as I thought.

I have question....

image.png.51a495f96ee994e32dd491c74495d2d3.png

Exactly what changes do the two masks I marked synchronize?

 

Edited by dongju.jeong
Link to comment

OBJECT - other parameters of objects except NodeFlags and Transform (particles trasform for object particles, bones transform for object skinned) 
OBJECT_SURFACE - all paramters of surfaces (surface flags and information about inherit materials on each surfaces)

  • Thanks 1
Link to comment
×
×
  • Create New...