Clyde学习笔记三(Config)

在clyde中,几乎所有的外部资源都是以config的形式存在。每个config都有一个name来唯一标识这个config。ManagedConfig是所有config的基类,它是一个抽象类,定义了一些最基础的方法,ParameterizedConfig是它直接的子类。

 

1. ParameterizedConfig

 

ParameterizedConfig引入了parameter这一概念,利用parameter可以实现对config的个性化定制,这样可以复用绝大多数的config,并且减少config的数量。比如你有一个model,这个model在不同的场景需要应用不同的贴图,那么与其制作2个不同的config,不如利用parameter这一特性,在resource editor中选择创建一个direct parameter,给它一个名字叫“Texture”,然后把鼠标移到material mapping这一栏,按下ctrl-shift-C,复制material mapping属性的路径到剪贴板,然后再把此路径粘贴到刚才创建的parameter的path中。完成后,以后在代码中,可以这样来引用:

 

new Model(ctx, "flag.dat", "Texture", "texture.png");


 

“Texture”是parameter的name,“texture.png”是parameter的值。在其内部是以一个argumentMap来实现的。

 

 

/** The arguments applied to the configuration, if any. */
    @DeepOmit
    protected transient ArgumentMap _args;

 

以此也引申出base和derived概念。

 

 

    /** The instance from which the configuration is derived, if any (used to prevent the base
     * from being garbage-collected). */
    @DeepOmit
    protected transient ParameterizedConfig _base;

   /** Maps arguments to derived instances. */
    @DeepOmit
    protected transient SoftCache<ArgumentMap, ParameterizedConfig> _derived;

 

2. ConfigReference

 

ConfigReference以name和argumentMap属性保存了对一个config的引用,因为我们已经知道每个config都有一个name,但是这个name指向的config包括base和derived部分,所以以name和argumentMap可以唯一确定一个config的值。

 

 

    /** The name of the referenced configuration. */
    @Intern
    protected String _name;

    /** The arguments of the reference, mapped by name. */
    protected ArgumentMap _arguments = new ArgumentMap();
 

如果这个configReference是可以被编辑的,即标注有@Editable,在config editor中可以被编辑,并且在编辑时可以看到保存在configReference中的parameter的值。而且这个configreference是可以被嵌套的,比如说modelConfig中有materialMapping,materialMapping中有一个configReference<MaterialConfig>,在MaterialConfig中有一个configReference<TextureConfig>,那么在创建一个materialMapping的时候可以编辑一个MaterialConfig,在编辑MaterialConfig时可以再继续编辑TextureConfig。

 

3. ConfigGroup

 

在clyde中,几乎所有的配置都保存为config,都是从同一个基类中派生出来,但是从应用的角度来讲,一般可以分成2类,一类是所谓的managed config,像角色或者场景中的对象,它们在ConfigManager启动的时候被加载进来,保存在文件系统的rsrc/config路径下,并且在classpath中的rsrc/config路径下有一个manager.properties文件,一个典型配置文件看起来如下:

 

 

types = global, model, user_interface, scene

global.classes = com.threerings.tudey.config.ActorConfig, \
  com.threerings.tudey.config.AreaConfig, \
  com.threerings.tudey.config.BehaviorConfig, \
  com.threerings.opengl.gui.config.CursorConfig, \
  com.threerings.tudey.config.EffectConfig, \
  com.threerings.opengl.gui.config.FontConfig, \
  com.threerings.tudey.config.GroundConfig, \
  com.threerings.opengl.material.config.MaterialConfig, \

model.classes = com.threerings.opengl.gui.config.CursorConfig, \
  com.threerings.opengl.gui.config.FontConfig, \
  com.threerings.opengl.material.config.MaterialConfig, \

user_interface.classes = com.threerings.opengl.gui.config.CursorConfig, \
  com.threerings.opengl.gui.config.FontConfig, \
  com.threerings.opengl.gui.config.StyleConfig

scene.classes = com.threerings.tudey.config.ActorConfig, \
  com.threerings.tudey.config.AreaConfig, \
  com.threerings.tudey.config.EffectConfig, \
  com.threerings.tudey.config.GroundConfig, \

resource.classes = com.threerings.opengl.model.config.ModelConfig, \
  com.threerings.opengl.model.config.AnimationConfig, \
  com.threerings.opengl.gui.config.UserInterfaceConfig
 

在这里,每个config class对应的不再是一个单个的config,而是一个config group,每一个config group在文件系统rsrc/config路径下会有一个对应的.dat文件,在configManager启动时,会默认的读取type为global下每个config class对应的.dat文件,载入相应的config group。这些config可以在config editor中被编辑。


在上图可以看到,global标签页对应的是global type,group对应的是每一个config class,在每个group下有多个config,这些config还可以以目录的形式组织起来。

 

除了managed config之外,还有单个形式的config,比如model或者animation,这些config只有在需要用到的时候才会被载入,model和animation是在resource editor中编辑的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值