1

So I'm working on a project and I'm running into conceptual problems in creating my user interface. It's for a DirectX11 multi-monitor game I'm writing.

I've got a prototype working, with entity menus popping up and more entities inside those menus. All is well and good, except it's a coding fuster-cluck. I'm doing it wrong, so I've been spending the past couple weeks on learning & deciding how to refactor it to be better.

So far, I've decided to separate it into three parts, similar to MVC: One is the Event Listener, or the Controller, which will contain the bounding boxes, the base class, and the GUID for the entity. And a bunch of virtual methods, that each act towards a single type of input. I'm planning in arranging the memory structure of the entities in a Quad-Tree, with objects that span multiple quad's to be allocated to both, and for the quads to be broken down until no more than 8 items are in a quad, whereupon a linear search will be made, from highest GUID item to lowest. Input is run through the Event Listener, and it runs the virtual functions on a entity.

The next part is the Entity Class, or Model, which holds the type for all entities. Units, menus, etc, etc. The base Entity class has virtual functions for all the click-types, as well as Scrolling, Hovering, and Keyboard input. By running final virtual functions in derived classes, I update my Gamestate,

Lastly, in my Gamestate or View, I'm recording what Entities are active on the screen, as well as the state of all other entities. Here is also where I register/unregister things from the event listener. It also contains methods that direct what is shown to the user.

Now, my problem is like this. For stationary entities, or ones that move rarely, like menu items and scroll-bars, the cost for recalculating the quad-tree for them is fairly low cost. Menu objects don't always need to be added or removed every frame. The problem comes in when I'm dealing with the viewing of multiple unit entities (there could be up to several hundred on screen at a time). They are moving on a 2d plane, and can be moving between bounding boxes fairly rapidly. Assembling the quad tree is something like nlog^2n in the worst case scenario, where everything is clustered or large enough to span multiple bounding boxes. So I don't think that rebuilding it each frame is the best solution.

Unregistering items also looks to be a pain, as I'll have to traverse the entire tree to find the particular GUID, unless I make second tree of GUID entities and use it to point to the particular node on a tree which will contain pointers to the node(s) on the other tree that contain that entities GUID. Or I could just rebuild the entire tree each gamestate update. Which, again, would be expensive.

Is there a better design pattern to set up my user interface, or at least the Event Listener part of it, and if so, what is it?

  • Sprites? – Robert Harvey Jan 21 '18 at 22:27
  • The user interface does use sprites to draw it, if that's what you're asking. – ChrisPy Jan 22 '18 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.