arcade icon indicating copy to clipboard operation
arcade copied to clipboard

Documentation: Performance kludge page in programming guide

Open pushfoo opened this issue 2 years ago • 4 comments

Documentation request:

What documentation needs to be added?

A list of kludges to ensure performance during actual gameplay. This is distinct from actual optimizations as these will be platform or framework specific workarounds. Examples include:

  • "Throwing up a loading text, waiting a frame to actually load anything" - @DigiDuncan
  • Playing a sound once at inaudible volume to eliminate stutter later on

This will also double as a list of things we need to fix.

Where should it be located?

In the programming guide.

pushfoo avatar Feb 13 '23 23:02 pushfoo

If we add a proper section on performance, we may also want to mention multi-threaded loading and lazy SpriteLists.

pushfoo avatar Feb 24 '23 11:02 pushfoo

Related to the sound one, the same performance hack can be found for text; simply create and draw a dummy Text object (maybe using draw_text for simplicity, though that might be being deprecated) with a single space at 0, 0 at the start of your game. This forces the text to "warm up," and eliminates the "first-time stutter" issue.

DigiDuncan avatar Feb 28 '23 20:02 DigiDuncan

You can speed up the loading of OGG sounds ~3x by subclassing Sound and telling it to use the pyglet.media.codecs.pyogg.PyOGGDecoder decoder. That may be too technical for this guide, though.

DigiDuncan avatar Feb 28 '23 20:02 DigiDuncan

Documentation request:

What documentation needs to be added?

A list of kludges to ensure performance during actual gameplay. This is distinct from actual optimizations as these will be platform or framework specific workarounds. Examples include:

  • "Throwing up a loading text, waiting a frame to actually load anything" - @DigiDuncan

This is because the glyphs have to be loaded for each font. Loading a Label won't necessarily get rid of the issue unless you load most of the glyphs. You can preload the glyphs by getting all the default ones. For example:

def preload_font(ft):
    DEFAULT_CHARACTERS = ("0123456789"
                        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                        "abcdefghijklmnopqrstuvwxyz"
                         "{}()[]<>!?.,:;'\"*&%$@#\/|+=-_~` "
                        )

    for char in DEFAULT_CHARACTERS:
        ft.get_glyphs(char)
  • Playing a sound once at inaudible volume to eliminate stutter later on

This should be resolved here for first sound: https://github.com/pythonarcade/arcade/commit/10e48a0155b1bcc473c22a9fd40bb160f01dd0c7

For additional sound effect you should always preload them in your scene as long as they are a static source. (Not music)

caffeinepills avatar Mar 15 '23 15:03 caffeinepills