tiehuis / faststack

If you want to stack blocks kind of quick
https://tiehuis.github.io/faststack/
GNU General Public License v3.0
11 stars 1 forks source link

Add generic render hook independent of game state #24

Closed tiehuis closed 7 years ago

tiehuis commented 8 years ago

A generic rendering hook would be useful for rendering details which aren't tied to any particular game state or which have a period of action where they occur before stopping. Examples include line clear animations and displaying of high scoring or technical moves such as T-Spins or tetrises.

The proposed outline is currently as follows:

Define a single function interface fsiRenderEvent(FSPSView *v, FS_RENDER_EVENT event, int currentFrame, int totalFrames).

v

This is simply the current game state which allows the implementer to get any required data.

event

A render event specifies the type of event which the implementer must render. For example, an event FS_RENDER_EVENT_LINE_CLEAR could be utilized and the implementer can then perform their specific action, choosing via a switch statement.

fsiRenderEvent(FSPSView *v, FS_RENDER_EVENT event, int currentFrame, int totalFrames)
{
    switch (event) {
      case FS_RENDER_EVENT_LINE_CLEAR:
        // Perform the line clear animation
        break;
    }
}

currentFrame, totalFrames

An implementer must implement their event based on the current frame and the total frames that this event will be called for. This is done to allow for different length events and for the implementer to handle variable time steps by means of interpolation or otherwise.

When are these renderered?

Events are renderered during the fsiDraw phase. A game instance will have a set of slots with which can be filled with render events (say 10). During this phase these slots are walked and the current frame to render with the total frames is passed to the fsiRenderEvent function for the implementer to handle.

This requires keeping track of the following three items in each slot:

tiehuis commented 7 years ago

Now that frontends are much more flexible, the requirement for this generic type of event is less pronounced. The idea still makes sense for each however, but each frontend's implementation strategy will likely differ.