A puzzle on Composite efficiency.

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

A puzzle on Composite efficiency.

#1 Post by Onishion » Thu Apr 14, 2016 11:23 pm

Ok, so I use some complex LCs in my projects, and I was curious as to which of these two methods would be the most efficient way of dealing with them:

Code: Select all

image MyImage:
    LiveComposite(
        (100,100),     
        (0,0), ConditionSwitch(            
            "VariableA == 3 and VariableB == 1", "images/image1.png", 
            "VariableA == 3 and VariableB == 2", "images/image2.png",  
            "VariableA == 3 and VariableB == 3", "images/image3.png",            
            "VariableB == 1", "images/image4.png", 
            "VariableB == 2", "images/image5.png",  
            "VariableB == 3", "images/image6.png",
            "True", Null(),
            ),     
        )
    
image MyImage2:
    LiveComposite(
        (100,100),     
        (0,0), ConditionSwitch(    
            "VariableA != 3", Null(),        
            "VariableB == 1", "images/image1.png", 
            "VariableB == 2", "images/image2.png",  
            "VariableB == 3", "images/image3.png",
            "True", Null(),
            ),     
        (0,0), ConditionSwitch(    
            "VariableA == 3", Null(),        
            "VariableB == 1", "images/image4.png", 
            "VariableB == 2", "images/image5.png",  
            "VariableB == 3", "images/image6.png",
            "True", Null(),
            ),   
        )
I may have made a mistake in there because I threw it together kind of quickly, but if I got it right, both methods would accomplish the same effect. If Variable A is 3, then one of images 1, 2, or 3 will display, depending on what Variable B is up to. If Variable A is not three, then one of images 4, 5, or 6 will appear. Obviously in such a small case the difference might not matter at all, but what if in the first example I were checking against 3-5 different conditions to determine whether to display the image? Would it add or reduce performance to the situation to have sets long "if and and and or" strings, or would it be better/worse to instead separate them out into individual layers of the composite and have each disqualify itself if one core condition fails? Which is more of a resource hog, having one condition switch that asks a lot of complex questions before reaching the end, or a bunch of individual layers that each ask only simple questions? Or would it not matter at all no matter how complex the composite got?

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: A puzzle on Composite efficiency.

#2 Post by xela » Fri Apr 15, 2016 2:47 am

Onishion wrote:Or would it not matter at all no matter how complex the composite got?
This. First way is prolly more efficient but it depends on case per case basis. You can use time.time() to figure out which is best if you really want to know.
Like what we're doing? Support us at:
Image

Post Reply

Who is online

Users browsing this forum: Alex, Google [Bot], nyeowmi