调用函数 #1 后自动调用函数 #2
这应该是一个很快的事情。 是否可以这样做:
[Callback(funtionY)]
void functionX()
{
}
void functionY()
{
}
这样当调用 functionX 时, functionY 也会自动调用? 我问的原因是因为我要为基于 XNA 的小型游戏引擎实现网络功能,并且我想将函数标记为“同步”,以标记当调用函数时应该在所有客户端上调用它。
谢谢。
This should be a quick one. Is it possible to do something like this:
[Callback(funtionY)]
void functionX()
{
}
void functionY()
{
}
So that when functionX is called, functionY is called automatically too? Reason I ask is because I'm going to implement networking functionality to a small XNA based game engine, and I want to mark functions as Synched, to mark that when a function gets called it should be called across all clients.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
听起来您想要面向方面的编程。
我之前已经使用过 PostSharp 来实现此目的,并且效果很好。
Sounds like you want Aspect-Oriented Programming.
I've used PostSharp for this before now, and it works pretty well.
您可以使用 PostSharp 轻松做到这一点,但一般来说:不; 你必须明确地调用它。
You can probably do that quite easily with PostSharp, but in general: no; you'd have to call it explicitly.
是的,您可以,只需将它们创建为委托即可。
更新:乔恩(谢谢)指出,调用顺序实际上是确定的。 然而我永远不会依赖这个。 看评论。
Yes, you can, just create them as a delegate.
UPDATE: Jon (thanks) pointed out that invocation order is in fact determined. I would NEVER rely on this however. See comments.
是否有某种原因您不能这样做:
根据问题中的描述,这是一个有效的答案。 不过,我想你已经考虑过了。
另一种可能性是使用事件系统来发挥你的优势,例如(未编译):
Is there some reason you can't do this:
Based on the description in the question, that's a valid answer. I assume that you've considered it already, though.
Another possibility would be to use the eventing system to your advantage, something like (uncompiled):
怎么样:
how about: