ZombieSquirrel
Member
Hi everyone!
For a while now, I've had serious lag issues, to the point where the game becomes unplayable.
This only happens when I have a lot of tree objects in my game.
Trees have a chance to spawn a new one each day in my game. They also grow each day.
In order for a tree to be placed, it must first check if that is allowed (if no other object is present at that location).
When I have like 50 trees, it's fine. But once the numbers go up by a lot, it causes massive lag.
I can't pinpoint why. The other weird thing is , when I move to another room, the lag endures. Rooms are persistent by the way.
So since I'm out of solutions, let me sum up what I have:
-Many tree objects, 6 types of trees.
-They only turn to solid if the player is in a collision_rectangle around the tree.
-Collision check happens from the player object, not in each individual tree.
-Trees have a 1 in 4 chance each new day to spawn a seed.
-When a seed spawn triggers, it has a 1 in 12 chance to choose direction. Basically,
1 in 4 chance to spawn, and then spawns randomly in 1 out of 12 places around the original tree.
-Seeds can only be spawned in areas that are allowed (no other object present)
-There is no parent object.
-All together, it's a couple of hundred lines of code in the tree object (which causes tree types, tree spawns, tree growth, tree cut by player,... It really works great in low amounts of trees)
-Depth of trees is just a single number in their create event.
-Depth of player is updated in player step event
It leaves me wondering what the cause could be.
Is it the collision checks?
Is it the amount of code (hundreds of trees = hundreds x hundreds lines of code)?
Is it each individual draw event? (not drawing the tree reduces lag a lot, but not completely).
Why does the lag carry over to other rooms (also persistent) where there are only a couple of trees?
Is it just the amount of objects and there's no way around it?
It really comes down to "how to reduce lag when working with a large amount of objects" really. I probably have to start from scratch with my trees, however I already learned a lot about player interaction, growth, spawns,... So the knowledge doesn't go to waste.
I'm missing something here... Something NOT TO DO when having a lot of objects.
For a while now, I've had serious lag issues, to the point where the game becomes unplayable.
This only happens when I have a lot of tree objects in my game.
Trees have a chance to spawn a new one each day in my game. They also grow each day.
In order for a tree to be placed, it must first check if that is allowed (if no other object is present at that location).
When I have like 50 trees, it's fine. But once the numbers go up by a lot, it causes massive lag.
I can't pinpoint why. The other weird thing is , when I move to another room, the lag endures. Rooms are persistent by the way.
So since I'm out of solutions, let me sum up what I have:
-Many tree objects, 6 types of trees.
-They only turn to solid if the player is in a collision_rectangle around the tree.
-Collision check happens from the player object, not in each individual tree.
-Trees have a 1 in 4 chance each new day to spawn a seed.
-When a seed spawn triggers, it has a 1 in 12 chance to choose direction. Basically,
1 in 4 chance to spawn, and then spawns randomly in 1 out of 12 places around the original tree.
-Seeds can only be spawned in areas that are allowed (no other object present)
-There is no parent object.
-All together, it's a couple of hundred lines of code in the tree object (which causes tree types, tree spawns, tree growth, tree cut by player,... It really works great in low amounts of trees)
-Depth of trees is just a single number in their create event.
-Depth of player is updated in player step event
It leaves me wondering what the cause could be.
Is it the collision checks?
Is it the amount of code (hundreds of trees = hundreds x hundreds lines of code)?
Is it each individual draw event? (not drawing the tree reduces lag a lot, but not completely).
Why does the lag carry over to other rooms (also persistent) where there are only a couple of trees?
Is it just the amount of objects and there's no way around it?
It really comes down to "how to reduce lag when working with a large amount of objects" really. I probably have to start from scratch with my trees, however I already learned a lot about player interaction, growth, spawns,... So the knowledge doesn't go to waste.
I'm missing something here... Something NOT TO DO when having a lot of objects.