Josh Posted February 28, 2023 Share Posted February 28, 2023 This will assign new event Ids at compile time. This avoids the unpleasant situation where you need to assign the value of an event Id at startup, while still ensuring each ID is unique: #define ALLOCEVENTID EventId(10001 + __COUNTER__) #define EVENT_TEST1 ALLOCEVENTID #define EVENT_TEST2 ALLOCEVENTID You can use ALLOCEVENTID anywhere, across different files, so you don't need to worry about making sure your custom event IDs are all different. The Event Ids above can be used in switch statements since they are constant. 2 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
reepblue Posted March 1, 2023 Share Posted March 1, 2023 Seems the old method has been undocumented to I expect this to be the new standard in a future update. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted March 1, 2023 Author Share Posted March 1, 2023 Yeah, the problem is that only enums and defines can be used in switch statements, and even if you use if/else if you also an ugly situation before event IDs are initialized. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted March 1, 2023 Author Share Posted March 1, 2023 Ha...this actually increments the value each time it appears in the code. This needs modification to work right... #define EVENT_TEST ALLOCEVENTID void main(int argc, const char* argv[]) { Print(String(EVENT_TEST)); Print(String(EVENT_TEST)); return; } Prints: 10001 10002 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted March 1, 2023 Author Share Posted March 1, 2023 You can use an enum like this. The only problem is you have to cast your own custom events to the EventId enum. I don't know how to make it so CustomEventId gets automatically cast to EventId: enum CustomEventId { EVENT_RENDER = ALLOCEVENTID, EVENT_PROGRAMSTART = ALLOCEVENTID, EVENT_CONSOLEEXECUTE = ALLOCEVENTID, EVENT_THUMBNAILLOADED = ALLOCEVENTID, EVENT_OBJECTTEMPLATESELECT = ALLOCEVENTID, EVENT_RESETLAYOUT = ALLOCEVENTID }; Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
klepto2 Posted March 1, 2023 Share Posted March 1, 2023 #define ALLOCEVENTID EventId(10001 + __COUNTER__) #define RegisterEventEnum(T) \ bool operator==(const T& t, const EventId& g) { return static_cast<EventId>(t) == g; } \ bool operator==(const EventId& g, const T& t) { return static_cast<EventId>(t) == g; } \ \ bool operator!=(const T& t, const EventId& g) { return static_cast<EventId>(t) != g; } \ bool operator!=(const EventId& g, const T& t) { return static_cast<EventId>(t) != g; } \ \ EventId& operator<<=(EventId& g, T t) { g = static_cast<EventId>(t); return g; } \ T& operator<<=(T& t, EventId g) { t = static_cast<T>(g); return t; }; \ enum CustomEvent { TEST_1 = ALLOCEVENTID, TEST_2 = ALLOCEVENTID, }; RegisterEventEnum(CustomEvent); Try this. [Edit] Forget it, it is not working. switch statements work out of the box, but functions will not work without proper casting Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Josh Posted March 1, 2023 Author Share Posted March 1, 2023 This is da wey const EventId EVENT_TEST1 = ALLOCEVENTID; void main(int argc, const char* argv[]) { int i = 3; switch (i) { case EVENT_TEST1: break; } EmitEvent(EVENT_TEST1); Print(EVENT_TEST1); Print(EVENT_TEST1); } Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted March 23, 2023 Author Share Posted March 23, 2023 I think this approach does not work with partial builds. I am seeing some values that appears twice and make no sense. The only thing you can do is declare all your custom event IDs in a single file. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.