Thread: XNA using C#
View Single Post
Old 05-05-2008, 01:43 PM   #140 (permalink)
Froofy-D
upper management material
 
Froofy-D's Avatar
 
Join Date: Nov 2002
Location: Orlando, FL
Posts: 2,040
+8 Internets
In Java do Action Listeners give similar functionality to Delegates? I don't do much Java either besides what was required in some undergrad classes.

I've recently migrated from C++ to C# for all my personal and work projects when I can use it. I will NEVER go back to C++ ... C# is that much better.

BTW, I'm using Delegates to speed up some C# Neural Network code that must be executed 100's of time per frame in game. Each node in the network is assigned a random mathematical function, from out of approximately 15 functions. Each network has possibly dozens of nodes, and there are a lot of networks.

Instead of a switch of if-else at each node like this ...

Code:
switch(functionNumber) { case 0: Sin(); case 1: Cos(); case 2: HyperbolicTangent(); case 3: Inverse(); case 4: Ramp(); case 5: Step(); case 6: Gaussian(); case 7: Spike(); case 8: Tangent(); etc... }
... each node gets assigned a Delegate called "functionPointer" that points to it's correct function. So the above switch statement within a node is replaced by simply:

Code:
node.functionPointer();
So, because nodes get activated 100's of times per frame, possibly thousands of 'switch' cases per frame are avoided, resulting in significant speedup.
Froofy-D is offline   Reply With Quote

 
Uberguilds Network