Jump to content
Attention! On March 5 (Thursday) from 6:00 to 8:00 UTC, the forum will be unavailable due to scheduled maintenance.

Editor plugin making components which updates without focus


photo

Recommended Posts

Posted

Hello everyone,

Today is a question about Editor plugins and C++ components.

I'm doing a small terrain fetcher plugin (just to create in memory a dynamic mesh which would be exportable to FBX with FBXExporter). In order to deal with giant terrains I had the idea of creating on-the-fly in the editor CPP components attached to the terrain tiles (or objects with boundig boxes) which would fetch the landscape positions and generate a mesh. 

It works pretty well, but the components seem to stop updating (OR the landscape fetch are not updating) if I don't have the focus on Unigine editor. That is actually kind of annoying, since I plan on generating 40kmx40km terrains with a precision of 50cm, and it would be annoying to have to constantly keep focusing on the editor :).

I create components the standard way you describe in the documentation and use the same methods for fetching as in your terrain sample. For example here is my component declaration:
 

	class TerrainMesh final : public Unigine::ComponentBase
	{
	public:

		COMPONENT_DEFINE(TerrainMesh, Unigine::ComponentBase)
		COMPONENT_INIT(Init)
		COMPONENT_UPDATE(Update)
		COMPONENT_SHUTDOWN(Destroy)

		void Init();
		void Run();
		void Update();
    }

And here is the part of my loop that do not progress if I focus something else:
 

void TerrainMesh::Update()
{
  // Fetch update loop
  if (m_current_state == MeshGenerationState::FETCHING)
  {
    for (int i = 0; i < m_terrain_fetchers.size(); i++)
    {
      if (m_terrain_fetchers[i].landscape_fetch->isAsyncCompleted())
      {
        m_finished_fetchers_count++;

        m_fetch_data[m_terrain_fetchers[i].out_data_index].height = m_terrain_fetchers[i].landscape_fetch->getHeight();

        // Redirect this fetcher toward a new position
        if (m_next_fetcher_index < m_fetch_grid_positions.size())
        {
          m_terrain_fetchers[i].landscape_fetch->fetchAsync(m_fetch_grid_positions[m_next_fetcher_index]);
          m_terrain_fetchers[i].out_data_index = m_next_fetcher_index;

          m_next_fetcher_index++;
        }
      }
    }
  }
}


Can landscape fetch work if Unigine editor is not in focus ? Can components update ?

Posted (edited)

Well thanks, that was awfully easy. Can't believe I missed that one

Edit: Well it seems to work sometimes, when part of the editor is still on display, but there are times when it seems to get stuck. For my use, I think it will be enough :)

Edited by K.Wagrez
×
×
  • Create New...