SceneComposer "Add Control" context menu not showing my item

@jayfella said: It does occur in the control logic, but since the control is created by the plugin and returned to the original project, I would have to have an instance of SimpleApplication in the plugin so I can give it to the newly created control in the constructor and use it - hence the original question of how to obtain it in the lookup.

There is none. Theres only one Application and its not a standard one, AppStates run in a fake application. You could get the FakeApp of the current SceneRequest if you listen to SceneRequest events somewhere… Then again, if you need a whole Application maybe an AppState to manage the terrain would be better? (I don’t say it is, I don’t know the code well enough)

1 Like

Thinking about this again… Why do you use enqueue at all? The Control already is a callback to the main thread…

1 Like

Bear with me, it’s a little tongue twister.

When a TerrainQuad is requested for addition to the scene (by moving around) and cannot be found anywhere (cache, etc), the requested co-ordinates goes into a “generation” que. That que just notifies the update loop that its being generated, so in the next frame - if it requests that tile again - a simple .contains() will tell us that it’s already being dealt with. Immediately after adding it to the “generation” que, a new thread is spawned from the threadpool telling it to create a TerrainQuad and assign its position to the given co-ords. Upon its creation, it is added to a “pendingAddition” ConcurrentLinkedQueue (a queue of tiles waiting to be added to the scene) - and the co-ordinates are removed from the “generation” because it has now been generated.

Each frame the “pendingAddition” ConcurrentLinkedQueue is popped, and if not null, added to the scene, then returns. We do this so that only one terrainquad is added per-frame (as to avoid too many additions in one frame and cause stutter).

That last bit (remove from the generation que) is called in a thread (as shown in the snipped above) - and the generation que is just a regular hashset - not concurrent - so I used app.enque() to jump back to the gl thread and remove it from the queue there. If I make it concurrent it seems to put everything out of sync and tiles don’t get removed or generated sometimes… It all kind of breaks up unto itself.

1 Like

Yes. What I suggest is that you put your finished tiles in a queue and add them in the update method of the control instead of depending on the enqueue method of app (and thus needing a reference to it). Its an allover cleaner approach.

1 Like

snip. ninja’d

Boom. Finally some of the good stuff. You are a star, sir. Thank you very much =D

=D

2 Likes

Awesome :slight_smile: