Event IDs in EventManger

Caliom

Warlord
Joined
Dec 17, 2007
Messages
164
I like to use the EventManger for some popups in the Improved Worldbuilder. But it's problematic to synchronize the EventIDs with other modules. BUG has a nice way to deal with this and i suggest to use this in RFCE too. Here is what BUG does:

There is a getNewEventID function in CvUtil.py that returns a unique EventID
Code:
g_nextEventID = 5050

def getNewEventID():
  """
  Defines a new event and returns its unique ID to be passed to BugEventManager.beginEvent(id).
  """
  global g_nextEventID
  id = g_nextEventID
  g_nextEventID += 1

  return id

This function is used in the beginning of a module to initialize your module variables. instead of
Code:
MY_EVENT_ID = 4711
you write
Code:
MY_EVENT_ID = CvUtil.getNewEventID()

For new events this function could be used. Only the initial value to g_nextEventID must be synchronized (i.e. it must be higher than any currently used values). IDs that are already in use can be left as they are. There is no need to change them now, although i would suggest to change them too, but step by step.

I think this would also lead to a cleaner use of the event interface in the long run. At the moment some events do not use IDs at all. They are hard coded into the EventManager or EventHandler. If your are looking for event-code you probably have to look into five different files to find the lines you are looking for.

Implementing this little function for new events is not much effort, and old code can be reworked later on step by step.

Edit:
if i rethink it, i think the eventID problematic only applies to popups. So this is actually a request for two things: to implement this nice little function for new popups (RFCE++ could profit from this two ;)), and to clean the event-code in general:D
 
Sounds nice!
I don't think 3Miro will be against this either
 
Events code is in the Crusades, Reformation, Birth and re-Spawns and probably other places that I am missing now. I would rather not touch this code.

Caliom: add this now to your module, since you are having problems with this. Later, we can easily move the function to RFCUtils.py and the rest of the code can be changed if needed.

This way, your code will be fine and we will not have to touch the rest of the code.
 
Hey Caliom!
I'm also willing to include these changes, if you are still up to it
The eventmanager and the eventIDs really could use some updates
 
Great! Then i'll do it.
Actually i was looking forward to do this for years now but never dared to start. It's time to see it done :)
 
Top Bottom