AtomicGameEngine / AtomicGameEngine

The Atomic Game Engine is a multi-platform 2D and 3D engine with a consistent API in C++, C#, JavaScript, and TypeScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[AtomicNET] Provide a better way to implement the 'magic' callbacks

Alan-FGR opened this issue · comments

commented

CSComponent has these magic callbacks like Start() and Update(float dt) that you gotta blindly implement, the problem is, if for some reason the signature doesn't match, you have a situation that's very hard to debug, say you have Update(), it won't work and it may not be obvious why.
In my opinion we need to either provide overridable methods, or maybe just let the user subscribe to the events and don't provide any magical stuff at all... some other engines have IDE plugins to help you with the magical stuff, but in my opinion Atomic shouldn't do any magic. Is there any reason why CSComponent doesn't have virtual methods you can override?

My guess is that the reason for not just having overrideable methods is that there may be large numbers of CSComponents and having them all call empty Updates (and all other supported methods) would be wasteful. I am actually a fan of the automatically available common methods, rather than requiring explicit event registration, but that may be my Unity legacy :)

I do agree that it's problematic that they aren't obvious. Perhaps it's just a(nother) documentation issue?

commented

Yep, any ideas if currently it gets the methods by reflection and stores the handle to call them, or just calls by reflection every time? Because if it's the latter it's arguable whether it's better in terms of perf

It reflects and keeps references to them. There is a CSComponentInfo object corresponding to each CSComponent subclass in all referenced assemblies. There's probably room for optimization in how those are actually called though.