Hello all,
Its been awhile since the last time I looked in on BYOND, and it seems like there have been some fairly exciting recent developments.
I'm just curious if anyone has implemented an entity component framework (see http://gameprogrammingpatterns.com/component.html if you're unfamiliar with the pattern).
ID:1879080
Jun 21 2015, 3:46 pm
|
|
That looks fairly elegant. The only thing I'd be concerned about is passing around the event names as strings-- that seems like it could come back and bite you in the rear end.
Thanks for sharing! |
The only thing I'd be concerned about is passing around the event names as strings-- that seems like it could come back and bite you in the rear end. Well, there's not much choice otherwise. An associative list is the best approach, and we need those strings for the call(). Since the event handler can't know ahead of time what it needs to call without requiring a lot of overrides all over your code, passing strings is genuinely the best way to handle things. Though I suppose if function pointers in DM were a thing, that'd probably be more ideal. |
Yeah, fair enough. I'm still re-acquainting myself with DM, so I'm not really on top of the limitations of the collections. Is it possible to use constants as the index for associative lists in DM?
|
In response to Bdjewkes
|
|
You can use any value other than numbers, such as strings, object instances, and type paths, as the key in a key=value pair. Keys are kept in the order they were first assigned, so a numerical index would be used as a positional index.
|
And here's an example of how to use it:
The flag business could be left out if you'd like.
Simply define a proc named "event[name]" on whatever object you want to link up to an event handler, and process your event there.
This approach is actually quite nice if you know what you are doing with it.