PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

When or why to lock

Hi!

After my first tries with PocketFrog and considering the poor documentation, I have some questions:

    Should I "Lock" a surface before writing to it? This was not clear to me, there doesn't seem to be a big difference or does it prevent other parts of (multi-threading?!) code to write to the same surface?

    Is it necessary or recommended to make a copy of the buffer to speed up some code? Let's consider I have a somehow static background consisting of several elements. In the game, I create additional elements on top of it (sprites, UIs, ...). Would it make sense to save a copy once the background has been constructed, or is it not worth thinking about such optimization strategies?

    For clarification: no matter on which device the code actually runs, the width and height for the display are the default 240x320 unless I specify something different?


Thank you for your patience. Just for your information, I am planning to write a game similar to Master of Orion.

Sullivan
Lock is used to get direct access to the pixel data. You don't need to use it with the built-in blits, etc. Only if you wanted to use some custom code.

If your background image doesn't change each frame, you would probably want to do as you say. Use a rasterizer to draw to a surface instead of the display.

The display is always fullscreen, so the size depends what device you're running on. Use display->getWidth to make code that is smart enough to support the various devices (320x240, 640x480, and the newer 240x240).

I suggest you register with pocketmatrix as well.
Thanks, fast_rx! Now I understand the code comments and the Lockinfo structure.

Okay, so I will create a new surface specifying the desired size, attach it to the Rasterizer, draw my stuff and blit it into the backbuffer.

What would you usally do to support different screen sizes / resolutions? Resize the gfx? Set some kind of logical viewpoint?

Sullivan
Sullivan wrote:
What would you usally do to support different screen sizes / resolutions? Resize the gfx? Set some kind of logical viewpoint?


It depends on the game. My games aren't affected by losing the bottom edge of the playfield - as long as button and UI stay on the screen. So I just resize the playfield and move the interface up a bit for 240x240.

I don't bother with 640x480 screens because of performance issues.