• Advertisement
Sign in to follow this  

Get unique IDs by reading the Instruction Pointer Register

This topic is 1788 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my code I have so far avoided the issue by not passing in an ID at all, and counting widgets internally per frame.

I use the ID to keep track of the current 'hot' and 'active' widgets. Not having fixed IDs means I cannot change the GUI while any widget is hot or active.

So I have a simple rule: the GUI can only change in response to a widget being triggered. At that point the hot and active flags are cleared, and the IDs are free to change.

This is in a level editor. It wouldn't work so well in a game environment where the interface could change in response to game events. There is the option though of explicitly setting the current ID through a function. It also wouldn't work if you used IDs to store information per widget, but I don't do that.

Share this post


Link to post
Share on other sites
Advertisement

. Maybe I find myself making lots of buttons with similar behavior/logic/etc... So I make a helper function to eliminate the boiler-plate parts of the API. Oops, nothing works anymore.

There should be helper functions to draw/process a button, draw/process a slider, etc. which presumably receive widget IDs as parameters (along with text, geometry, callback function pointers, etc.); you can do the same for composite or specialized widgets, and you can combine parent IDs and child IDs in case you process child widgets recursively, so what's the problem? Maybe that you are making lots of buttons, and you would be more comfortable with a retained mode GUI?

Share this post


Link to post
Share on other sites

Yeah I already tried to say that the linenumber is useless for composite widgets that get called more than 1 time.

If you for example make a do_okcancel function you cant just let it use __LINE__ for the ok button and __LINE__+1 for the cancel button it calls, because when dialog1 and dialog2 both call that it wouldnt work then cause of same id on the second call.

Thats why I hinted already at using the parent id, because it should by definition be unique already, and mangling it with a hashfunction. Then you could call the ok button with gen_id(id,2,0) and the cancel button with gen_id(id,2,1) and it magically just works, if you found a good gen_id hashfunction.

A simple example would be like gen_id(id,n,i)=id*n+i but it only works if n is the global max for all i=(childwidgetindex inside a widget) in all widgets and its guaranteed that it never overflows and nowhere a conflicting id is generated. I would encourage you to find a better one yourself. (I currently use some other, but it is more complicated and in some aspects better, in others possibly worse.)

Share this post


Link to post
Share on other sites

The ID is known at compile time, and in my case, I have a "std::vector<widget> DrawQueue" that I push widgets on with drawing information. I loop through this vector later at draw time for batching. This decouples the drawing and the interaction with the widget.

 

Nothing is stopping you from adding more data to the widget structure that gets added to the DrawQueue. A helper function could look for the widget with a certain ID and respond to whatever states are in that widget instance.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement