Still couldn’t entirely penetrate that, but I think you’re asking advise on how to handle really large ‘worlds’, where the content in those worlds may be off screen.
You also said something about culling and stuttering.
I’ll give a partial and unorganized answer, because a full answer would be pages and pages.
1. There is an upper limit to system and video memory (sometimes a combined value) as well as texture units, buffers, etc.
>> Breaching these limits on any specific system/device will cause the hardware to start swapping resources which will cause noticeable slowdowns.
- Even before you reach the limits of memory, you may saturate computing. i.e. You may accumulate too much per-frame work. This per-frame work is of two general types:
A. Work done by Corona.
B. Your scripts: Listeners, Timers, and the code you call as a result of events.
>> Once you breach the work-per-frame capacity of your CPU you will see skipped frames and other weird behavior.
Between #1 and #2 my guess is you are probably seeing #2 for the most part, but you may also be seeing #1 if you use a lot of different textures or many big textures at the same time.
You can solve some of this big texture/too many textures problem by combining textures that are often used together into sheets. This however is a very tricky thing and easily done wrong.
So I’d save that kind of optimization for last. In fact, I’d read up a lot on optimization before trying it. Also, keep a backup of your project in a working state before you start putting in optimizations. You may want to unroll those changes after you find out they saved you nothing and complicated your design.
What about #1? How can you minimize encounters with this problem for really large worlds? Some suggestions:
- Minimize the amount of work you are doing.
- If you can defer work to every other frame do it.
- If you can pre-calculate values do it.
- If you can use a less accurate calculation that is faster do it.
- Don’t draw objects until you need them and don’t delete them till you need to.
- Consider using object caching (a pool of re-used display objects) for things like particles, or other shapes that don’t need to be modified significantly to re-use.
- …
- Minimize the cost of the work:
- As noted in the above, you should consider substitutions that are cheaper in terms of CPU cycles to execute.
- As an example. Let’s say you need to take some action if object A is within distance 10 of object B.
- Traditionally, you’d do a vector calculation and get the distance between A and B, then compare it to 10.
- Better would be to get the squared distance (skipping the square root calculation in vector lengths) and compare the distance to 100 (i.e. 10 * 10).
- Be aware of the fundamental costs of actions.
- A great example of this is that accessing fields on a display objects take up to 30X longer than accessing fields on tables: http://davebollinger.org/robot-sb-dev-blog-get-set-performance/
- In this case, you might find it valuable to have your world objects be Lua tables and when needed have those tables own and draw a display object.
- Then do all calculations on the Lua object as much as you can, only making the finial changes on the display object if needed.
Again, this discussion can go on and on and on. It is very technical, experience based, and requires a huge amount of effort to do right.
Best of luck on your game. Enjoy the journey.