performance with nested Otherwise statements
I finished coding my entire nested otherwise statements for automatic level creation, and it's killed the level loading time. when I manually place the buildings in the level it takes 3.2 seconds to load. when my level directors, it takes over 14.
I'm not sure i've done this the most efficient way, has anyone else had a large number of otherwise statements?
what I have right now is 7 positions. each position has it's own actor with 60 nested otherwise statements. I tried having everything contained within a single actor, but it was taking a minute to open it each time.
for example in actor 1, I have two groups:
if buildingNumber < 30 and if buildingNumber > 30
and in each of those, I have rules that go like this:
if buildingNumber = 1
spawn building1
otherwise
if buildingNumber = 2
spawn building2
otherwise
if buildingNumber = 3
spawn building3
otherwise
.....
so on and so forth until I hit 30, then the next rule group takes over.
is there a better way to do this that is more efficient? I'm hoping that once the new engine comes out that it will solve problems like this, but i'd rather not wish on the wind. I've read that having nested statements is better than 60 separate if statements, but this is no picnic.
is there a better way to do this?
I'm not sure i've done this the most efficient way, has anyone else had a large number of otherwise statements?
what I have right now is 7 positions. each position has it's own actor with 60 nested otherwise statements. I tried having everything contained within a single actor, but it was taking a minute to open it each time.
for example in actor 1, I have two groups:
if buildingNumber < 30 and if buildingNumber > 30
and in each of those, I have rules that go like this:
if buildingNumber = 1
spawn building1
otherwise
if buildingNumber = 2
spawn building2
otherwise
if buildingNumber = 3
spawn building3
otherwise
.....
so on and so forth until I hit 30, then the next rule group takes over.
is there a better way to do this that is more efficient? I'm hoping that once the new engine comes out that it will solve problems like this, but i'd rather not wish on the wind. I've read that having nested statements is better than 60 separate if statements, but this is no picnic.
is there a better way to do this?
Best Answer
-
gyroscope I am here.Posts: 6,598
Hang on in there, Jon!: have you seen the Sneak Peek of the NEW Lua-Free GameSalad Engine (Pre-Alpha) sticky?
http://forums.gamesalad.com/discussion/42144/sneak-peek-of-the-new-lua-free-gamesalad-engine-pre-alpha#Item_49""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Answers
I am currently using the same general idea, to check whether items have been purchased in the in-game store. However, I haven't found a different way to do it, but I'd love it if someone else has!
Henry
each levelDirector actor I have in the game increases the loading time by 1 second, and increases the engine RAM by 8MB.
I really want to be able to dynamically create levels based on table entries, but if that is not going to work, I'll have some restricting to do.
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left
yea, i have 7 actors with 2 groups of 30 each for a total of 420 if statements.
i wonder if i spilt it up further so each actor has 4 groups of 15? i dunno.
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left
May help so that it's not preloading all those rules?
Ace
Hey i believe a better way of doing this is not spawning at all and not nesting rules at all !
Put all your building actors in the scene - off screen .
And in every one of them give a rule :
When "game.start a new level" IS true
Change "self.position.X" and "self.position.Y" to the desired position .
Now i suggest making a Table with all the info for the X and Y values so that the actors can take the position data from that table .
Also you need to make it so that if there are actors that are not being used in that level, they won't execute their rules, and they'll be off screen.
The best way of doing this is:
You have an "index" attribute for the level number right ?
So this is how your actor rules will look like -
*************************
When - "game.start a new level" is True
Change "self.position.X" and "self.position.Y" to a table value .
now a new rule :
When "self.position.X" is grater than 0
When "self.position.X" is lower than 480
When "self.position.Y" is grater than 0
When "self.position.Y" is lower than 320
Be active .
Otherwise -
Don't be active.
*************************
Hope it helps Jon
@P-O-M - I may have to go down that route eventually, but I want to try and get this dynamic thing working first for 2 reasons. I want to have 200 levels, and it's a lot easier to fill out a table with the level layout than manually placing 100+ building pieces each level
If I can't get the nested performance issue solved. I'll scrap loading from the table and just drop my building constructor in each level. that actor creates the building based on it's location, so that will be a lot better.
Thankfully I did a ton of table work before starting on coding, so I've got a very large table with each piece's width and height as well as it's relative position to every other building piece, so I've got a few options to deal with this.
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left
if buildingNumber = 1
spawn building1
if buildingNumber = 2
spawn building2
if buildingNumber = 3
spawn building3 etc etc
@rob2 - I've always seen that having nested if statements is better performance because once it hits the right trigger, it stops executing everything.
Im going to do some playing around tonight to see if I can make it any better
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left
@jonmulcahy > Hi Jon, I'd agree with Rob, ( @Rob2 ); you surely won't get faster performance than a list of if's in this case, surely? Just a thought...
----------------------------------------------
http://davidgriffinapps.co.uk/
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
couldn't figure out whether level completion > sceneChange or just levelChange
… did try to demo some of this: http://www.mediafire.com/?m1l7181dht0326k
may not help … but hopefully it is a start or pointer in the right direction
@};- MH
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left
I think I've come up with a work around solution which requires a bunch more work per level, but should dramatically increase performance. At least as long as we use the lua engine.
Got some work ahead of me tonight!
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left