具有多种插件类型的插件架构(XNA)

发布于 2024-11-27 15:45:13 字数 207 浏览 3 评论 0原文

我希望在 XNA 中为自己设计一个多用途 RPG 引擎,并希望使其依赖于插件。在大多数情况下,我理解整个一般概念......并且我有一个基本的 IPlugin 界面。

然而,当您意识到您需要针对不同系统的多种类型的插件以及一种容纳所有插件的方法时,问题就出现了。事实上,你可以说我正在努力让一切都变得调制。我应该使用多个接口来实现不同的东西吗?不同的主机接口?任何提示表示赞赏。 :)

I'm looking to design a multi purpose RPG engine for myself in XNA, and would like to make it reliant on plugins. For the most part, I understand the whole general concept... and I have a basic IPlugin interface.

However, the problem arises when you realize you need several types of plugins for different systems, and a way to accommodate it all. In fact, you could say I'm trying to make everything modulated. Should I use multiple interfaces, that implement different things? Different host interfaces? Any tips are appreciated. :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

另类 2024-12-04 15:45:13

取决于您将如何管理以及从性能角度看待这一点。但是你可以做这样的事情。 伪代码

public class Host {

   HostEventDispatcher dispatcher = new HostEventDispatcher ();
   MenuTypes {File, Tools, Options, Help}
   ToolBarTypes {MainBar}

   AddSubMenuToMainMenu(IMenu menu, MenuTypes hostMenu);
   AddSubMenuToMainMenu(IToolbar toolbar, ToolBarTypes hostToolbar);   

   public void LoadPlugin(IPlugin plugin) 
   {
       plugin.Dispatcher = dispatcher;
   }
}

interface IMenu {/* control warpper implementation */} 

interface IToolBar {/* control wrapper implementation */}

public HostEventDispatcher {
   //raises events to subscribers (Host, plugins)

   /***** event list ***/
}

public interface IPlugin 
{
    Dispatcher {get;set} //using this plugin can raise/recieve evets to/from Host.
}

非常基本的想法。但它在真正的实现中肯定会变得更加复杂,并且之后很容易变得更加复杂。请注意复杂性,因为它会影响性能,因为遵循“最大灵活性”模式很容易忽略它。

问候。

Depends how you gonna manage and also look from performance perspective on this. BUt yu can do something like this. Pseudocode:

public class Host {

   HostEventDispatcher dispatcher = new HostEventDispatcher ();
   MenuTypes {File, Tools, Options, Help}
   ToolBarTypes {MainBar}

   AddSubMenuToMainMenu(IMenu menu, MenuTypes hostMenu);
   AddSubMenuToMainMenu(IToolbar toolbar, ToolBarTypes hostToolbar);   

   public void LoadPlugin(IPlugin plugin) 
   {
       plugin.Dispatcher = dispatcher;
   }
}

interface IMenu {/* control warpper implementation */} 

interface IToolBar {/* control wrapper implementation */}

public HostEventDispatcher {
   //raises events to subscribers (Host, plugins)

   /***** event list ***/
}

public interface IPlugin 
{
    Dispatcher {get;set} //using this plugin can raise/recieve evets to/from Host.
}

Very basic idea. But it for sure will become more complicated in real implementation, and can easily become much more complicated after. Keep attention on complexity as it affects performance cause it's something that easily can be missed following "maximum flexibility" pattern.

Regards.

山色无中 2024-12-04 15:45:13

您没有 IPlugin 界面。您有一个 IEnemy 接口和 IWeapon 接口等。

You don't have a IPlugin interface. You have an IEnemy interface and an IWeapon interface etc.

你怎么这么可爱啊 2024-12-04 15:45:13

您可以使用您自己的组件或游戏组件,默认情况下这些组件是不活动的。
然后您可以自己选择要激活的内容,例如 xml 文档。

<Plugins>
  <Plugin name="MyNamespace.CombatManager"/>
  <Plugin name="MyNamespace.GuiManager"/>
</Plugins>

然后您可以激活选定的插件:

using System.Xml.Linq;
public void ActivatePlugins(string filePath)
{
    XElement plugins = XElement.Load(filePath);
    foreach(var plugin in plugins.Elements("Plugin"))
    {
        for(int i = 0; i < Components.Count; i++)
        {
            if(Type.GetType(plugin.Value) == Components[i].GetType()) 
            { ((GameCompoent)Components[i]).Enabled = true; }
            break;
        }
    }
}

You can use components, either your own or gameComponents, that are by default inactive.
Then you can yourself choose which ones to activate with for example a xml doc.

<Plugins>
  <Plugin name="MyNamespace.CombatManager"/>
  <Plugin name="MyNamespace.GuiManager"/>
</Plugins>

And then you can activate the selected plugins:

using System.Xml.Linq;
public void ActivatePlugins(string filePath)
{
    XElement plugins = XElement.Load(filePath);
    foreach(var plugin in plugins.Elements("Plugin"))
    {
        for(int i = 0; i < Components.Count; i++)
        {
            if(Type.GetType(plugin.Value) == Components[i].GetType()) 
            { ((GameCompoent)Components[i]).Enabled = true; }
            break;
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文