我目前正在实施一个用c 2D粒子系统++和SFMLSFML粒子系统架构
我发现这个漂亮post激励我在构建一个通用的系统。现在来了渲染代码,我要求提供一些关于我有不同选择的建议。
在SFML教程中,particle system显示为SFML实体的一个示例。在这种情况下,粒子系统嵌入顶点数组和其他渲染需求。这也意味着继承和本教程的设计模式是为了避免继承。我需要继承来构建一个SFML实体,但它应该放在哪里?
那么实现渲染解决方案的最佳选择是什么?
保持直奔SFML例子,只是增加一个
RenderPolicy
到的政策和纹理信息列表中颗粒:template < class Particle , class RenderPolicy, class OtherPolicies > ParticleSystem : public sf::Drawable, sf::Transformable { // implement the virtual function ... void update(){ RenderPolicy(Particles,VertexArray) // here the render policy update render info } // hold the VertexArray for the Particles ... }; // ParticleSystem
创建粒子系统渲染器作为SFML实体
template< class ParticleSystem , class RenderPolicy > ParticleSystemRenderer : public sf::Drawable, public sf::Transformable { // will use ParticleSystem array to build VertexArray // will hold texture information and other needs }
将RenderPolicy添加(或替换颜色策略)到作为SFML实体的ParticleSystem
template< class Particle > class RenderPolicy : public sf::Transformable , public sf::Drawable { // hold vertex array, texture and drawing routine ... }
另一个想法,因为所有这些都不好?
我认为,最好的解决办法是第三个,但一些建议或意见,欢迎 感谢所有,望柱理解;)
thx您的建议和经验分享,我会考虑和审查一下架构。几种多策略粒子系统的管理复杂性明显增加,我也必须考虑这一点 – leJon 2014-08-28 23:47:28