Animation Overview

This topic provides an overview of the Animation API, which third-parties can use to create Window Server plug-in DLLs to perform animations.

Introduction

An animation DLL performs drawing from within the Window Server thread. This makes the continuous updating of graphics possible, because the Window Server thread has high priority and is unlikely to be pre-empted by other threads. Animation DLLs can be used to create animation effects that rely on continual and fast graphic updates—for example, to make a clock second hand sweep smoothly. This approach might even be exploited for video-style animations although its intended use is for drawn rather than bitmap graphics.

A distinction between animated graphics and animated bitmaps is worth making. The animation classes are intended primarily for line drawing based animation. Bitmaps can be animated using either the animation classes or sprites, but sprites are usually preferred. Sprites animate arbitrary bitmaps. Typical uses are for cursors, PacMan style games, and so on. Because the Window Server handles much of the complexity, sprites can be thought of as bulletproof. The animation classes on the other hand provide server side speed and great flexibility, but are more complex to use.

It is possible to create animation effects using ordinary Window Server clients, for example using active objects on the client side to schedule graphics updates. However, these suffer from the (relatively) lower priority of the client thread and from the fact that active objects are non-preemptively scheduled, which means that the window update can be delayed by other client-side active objects.

An animation DLL also provides accurate clock ticks. Suppose you require a one second timer to move the second hand on a clock. If you work on the client side, then drift occurs with the clock losing time very gradually. The animation DLL provides access to timers that do not suffer from this problem.

The Animation classes form two pairs across the client/server boundary. One pair provides functions at DLL level and the other at the level of individual animation classes. To create an animation requires a DLL class and a class for each animated object. More accurately, a pair of classes is required for each, with each pair comprising one server side class and one client side class.

This general mechanism allows client/server separation while also allowing client side classes to benefit from server side privilege—fast graphical updates made possible by the high priority of the server thread.

For efficiency reasons, it makes sense to collect multiple animation classes into a single DLL, even if they are otherwise logically quite separate classes.

Architectural relationships

This API defines a framework for polymorphic DLLs that perform animations. These animation DLLs plug in to the Window Server, and so are run in the Window Server's high-priority thread, rather than the application thread.

The Window Server Client-Side API defines base classes for client interfaces that applications use to control animation DLLs. Providers of animation DLLs specialize these client interfaces appropriately.

Description

The API has four key concepts: animation factory, animation base class, window animation base class, and sprite animation base class.

Animation factory

Each animation DLL must define a factory for the animations it provides. The DLL must export at ordinal 1 a function to create an instance of this factory class.

The base class for such factories is CAnimDll .

Animation base class

Every animation implements an interface that is called by the Window Server to:

  • pass commands from clients

  • perform a step in the animation

  • pass Window Server events (if required), so that the animation can handle them before the application

This interface is CAnim , with its base class MEventHandler . The operation to perform an animation step is called by the Window Server on a timer. The animation is informed if for any reason timer events are missed or become out of sync. The timing properties are set through an MAnimGeneralFunctions member (an abstract interface that is implemented by the Window Server). This also provides other utility functions.

Window animation base class

For animations other than sprites, animation providers derive classes from the window animation base class, CWindowAnim , based on CAnim . This adds access to an interface for querying and manipulating the window in which the animation takes place, MAnimWindowFunctions .

A further specialized base class allows animations to be provided that implement their own animation timers. This is CFreeTimerWindowAnim , based on CWindowAnim , with related utility functions provided by MAnimFreeTimerWindowFunctions .

Sprite animation base class

Sprites are bitmaps that can overlay a window. A sprite animation can be provided by deriving a class from CSpriteAnim , based on CAnim . This adds access to an interface for querying and manipulating a sprite, MAnimSpriteFunctions .

Related concepts
Animations