Fixes
"Allocator out of memory: couldn't allocate more memory from linear allocator."
error with TinyGL in GRIM in several places:
- at the beginning of Year 2, after Meche boards the boat (does not happen
when skipping cutscene)
- when loading set bi
And likely in other places.
The issue is that TinyGL queues draw calls in a fixed-size structure
(linear allocator used to quickly queue vertices), and it emits this error
when running out of space. This queue is not flushed for as long as
_flipEnable is false, and this value is controlled by game scripts.
The longer flipping is forbidden, and the more complex the scene is (more
vertices, like in bi), the more likely it is to run out of space and cause
residualvm to error out.
In set bi, missing one flip is enough to exceed buffer space.
In set lm (the one after meche boarding the boat), it takes 5 missed flips
to exceed buffer space (simpler scene), but it still happens in a split
second.
My initial thought was to empty the queue without drawing, but there is no
way to do this with OpenGL and I prefer to avoid TinyGL-only shortcuts.
It seems likely OpenGL to have larger draw operation buffers (maybe
dynamically extended ?), and/or to forcibly stall caller and execute draw
operations when running out of space. In any case, this would add
complexity to residualvm and use more CPU and GPU time for no purpose.
So instead just skip drawing until flipping is allowed again.
These were present to implement actor freezing in software rendering mode
in the way original engine was intended for performance reason.
In residualvm, software rendering will generalise the principle through
dirty-rectangles management, so off-screen buffers should not be needed.
Also, properly implementing them requires invasive changes (move previous
draw call list from global OpenGL context to individual off-screen buffers,
along with associated linear vertex allocator, adding a new draw call to
track requested buffer changes until final on-screen frame buffer
presentation).
So instead of such added complexity, lie to lua API about actor not being
in set but keep it in so it is part of normal redraw sequence.
Fixes disappearing actors in cn, bi.
Likely also fixes at, ly, sh, mn, dd which uses free/thaw lua API, but
which I did not check.
Pixel format does not seem to be stored in save game, so when loading a
save game produced in 32 bits mode it appears corrupted. So, to preserve
backward compatibility, convert to 16bits format before storing.
- this avoids the issue that _frameTime is set to 0 if a consecutive
luaUpdate() happens in the same millisecond and so getPerSecond()
would return 0 for any given rate
- this fixes the issue that Guybrush would walk erratically
when residualvm is built with optimization
This needs to be separate from the other videos, since the logo
is encoded as QuickTime. This solution replicates logic from
mainLoop to avoid adding any further special cases in engine code.