Change texture

now my project is a game have many roles, the number of role in the game is 40~50 but some type of roles have the same animation, the only different between them is their appearance, which could be modified by picture path changed. the number of this type is only 5~10. But my problem is the picture path changed is on the low-level of the orx structure, changing it need to change all up-level structure, include all anim and animLink. Thus, for every role not one type role, I have to write all anim sections. And the content in the section is almost the same except the name of section. the game could run normal but the performance and the storage and memory occupied will be increased.

after I read your code,I believe it could be solved but my solution to it seems a little complicated, and not sure accessible. the procedure is like that
when create an object
1. build a new animset name and copy all content into the section
(since animset won't be created when it has a same name of animset created)
2. change the path of some graphics.
after creating the object
3. restore all graphic path

But is there any better solution to it?
the attachment is the configs of two roles belong to the same type. you can see that too many dunplicated data in it. (it may contain some Chinese but it won't influence reading)
Thanks in advance.


  • edited April 2011
    It might be what you are already doing, but here's what I'd do in your case. I'd create a custom CreateObject() function and here's its code:
    orxOBJECT *CreateObject(const orxSTRING _zName)
      orxOBJECT *pstResult = orxNULL;
        const orxSTRING zAnimSet;
        zAnimSet = CreateAnimSetFromTemplate(orxConfig_GetListString("AnimationSet", 0), orxConfig_GetListString("AnimationSet", 1));
    	orxConfig_SetString("AnimationSet", zAnimSet);
    	orxConfig_SetBool("UseTemplateAnimSet", orxFALSE);
      pstResult = orxObject_CreateFromConfig(_zName);
      return pstResult;

    And in the CreateAnimSetFromTemplate, I'd use the skeleton you'd write once in config and create one with the right tags at the right place for this object.
    Of course if you think it'd take too much space in config (which should be ok, I think), you can then clear the created sections when you don't need to create anymore objects of this type.

    Here's a part of the content of the config skeleton:
    AnimationSet = AnimTemplate1 # Director180
    AnimationList = 左待机4 # 下待机5 # ...
    DefaultKeyDuration  = @AnimationParams.KeyDuration
    KeyData1 = _TAG_Director1.pngGraphic-9
    KeyEventName1 = _TAG_第0帧3
    KeyOffsetPos1 = (0.0,0.0,0)
    KeyEventObjects1 = _TAG_0第0帧3#_TAG_2第0帧3
    KeyEventValue1 = 1
    DefaultKeyDuration  = @AnimationParams.KeyDuration
    KeyData1 = _TAG_Director1.pngGraphic-9FlipX
    KeyEventName1 = _TAG_第0帧4
    KeyOffsetPos1 = (0.0,0.0,0)
    KeyEventObjects1 = _TAG_0第0帧4#_TAG_2第0帧4
    KeyEventValue1 = 1

    And now the pseudo code of CreateAnimSetFromTemplate:
    const orxSTRING CreateAnimSetFromTemplate(const orxSTRING _zTemplateName, const orxSTRING _zTag)
      orxSTRING zResult = orxNULL;
    	zResult = new string _zTag + _zTemplateName
    	azArray = Create an array of string of size = number of items in "AnimationList"
    	For all config values in "AnimationList"
    	  zNewSection = create new string _zTag + value
    	  For all zKey in current section's keys
    	    zValue = orxConfig_DuplicateRawValue(...);
    		While zValue contains "_TAG_"
    		  zValue.replace("_TAG_", _zTag);
    		orxConfig_SetString(zKey, zValue);
    		Delete zValue
    	  azArray[i] = zNewSection
    	orxConfig_SetListString("AnimationList", azArray);
    	Deletes all strings in azArray and azArray
      return zResult;
  • edited April 2011
    I know that would be a option that I have thought of. It would be work without problems, but my worry lie in the memory. More dunplicated config would be stored in the memory after creating according to the template.
    for my idea I mentioned in the thread, I don't know whether it could work normal. And if it functions well I tend to choose this option.
    could you give me some advice to help me choose?
  • edited April 2011
    The memory impact shouldn't be very big. It's only text. You can try to look at the memory use before and after to see how much is taken.
    I planned on adding a profiler for memory and CPU use but didn't have the time to do it yet.

    And again, when all your objects have been created, you can easily delete all the config data that you created this way. But I would only bother doing so if the memory use was really consequent.

    Otherwise your idea would work, but depending on how many objects and how often you create them, it'll use CPU time. It all depends on which unused resources you have in your project. :)
  • edited April 2011
    In fact now the data is created by a editor my company used before. Its outputs are in an MS Access database. I generator the orx config when it save all data to database.
    therefore, gen the orx configs like I sent to you in this thread is not a difficulty. but too many configs in the packet are still very hard to manage.
Sign In or Register to comment.