Set global default settings in a config

I would be nice if we could set defaults for templates that would be inherited by all future sections of that type.

For example, I would prefer the pivot point to always default to center rather than left. The way I am doing it now is:
[Center]
Pivot = center

[Obj1@Center]
; orxGRAPHIC definition

[Obj2@Center]
; Another orxGRAPHIC definition

This works just fine, but I have to remember to inherit from Center each time and I am doing it on a LOT of graphic sections.

It would be great to be able to override Orx's defaults, something like this:
[orxGRAPHICDefaults]
Pivot = center

And after that, all orxGRAPHIC objects automatically use a center pivot unless I explicitly specify something different.

Comments

  • edited February 2012
    That's a very good idea and I have now to think of a way to implement it without being too annoying to add or having too much of an impact or config query performances. :)
  • edited April 2012
    Hi iarwain, have you given any more thought to this one?

    I am in another scenario where this would be helpful. I'm going back and setting BlendMode = none on objects to try to increase the framerate of the game. The default for BlendMode is alpha, but I'd rather my game's default be none by default and set it explicitly to alpha when an Object needs transparency.
  • edited April 2012
    I actually thought about it a while ago, though I stumbled upon the issue of different section having using the same key and didn't find a graceful way to solve that.
    The issue being that the config module is structure agnostic and doesn't have a single clue if we're looking at an object property or a graphic one, for example.

    Now we could handle those default values on a per case basis in all the different modules, but that's *a lot* of work and a lot of duplicated code.

    So I'm still thinking about it but it's not one of my highest priority to be honest, the skeletal animation is giving me a much harder time than I anticipated as I want it to be as easy as possible to author animation in config files and the decentralized aspect of the object hierarchy isn't helping so I might have to take a different way, we'll see.
  • edited August 2012
    I think I might have a somewhat working compromise in mind and I' ll be working on it very soon.

    Somewhat related too is the use of a new keyword for config that I added tonight: @ (without anything after).

    When used, its value will always be the section name.

    That can help restraining the wild proliferation of sections in config:

    Example:
    [Template]
    Graphic = @
    
    [MyObject@Template]
    Texture = path/to/texture
    Pivot = center
    
    [MyOtherObject@Template]
    Body = @
    Texture = path/to/other/texture
    Pivot = top left
    

    This is actually equivalent to:
    [MyObject]
    Graphic = MyObject
    Texture = path/to/texture
    Pivot = Center
    
    [MyOtherObject]
    Body = MyOtherObject
    Graphic = MyOtherObject
    Texture = path/to/other/texture
    Pivot = top left
    

    Using the default system it'll allow to coalesce a lot of sections that would be scattered all over the place otherwise without having to manually write Graphic = ... for every section as their values would be different for each section anyway.
  • edited August 2012
    Ok, I've added tonight the option to have a default parent section for all other config sections.

    By default, no such section exist but one can specify one via the Config.DefaultParent property. Ex:
    [Config]
    DefaultParent = MyDefault
    
    [MyDefault]
    Graphic = @
    
    [MyObject]
    Texture = path/to/texture
    Pivot = center
    

    As we can see MyObject doesn't have an explicit parent and a default parent has been defined and is MyDefault. So MyObject is going to get the Graphic property from it, as it's @, it'll be the name of the current section (ie. MyObject), thus MyObject defines both the object and the graphic.

    Now imagine you don't want to inherit from the default parent, the syntax to use is:
    [MyObject@@]
    ; This section doesn't inherit from the default parent
    

    Finally, the default parent can be changed at runtime using orxConfig_SetDefaultParent().

    Let me know what you think! :)
  • edited August 2012
    Looks good. I will test it soon.
Sign In or Register to comment.