/*- * Copyright (c) 2003 Qube Software, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * 1. Redistributions of the source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Any redistribution solely in binary form must conspicuously * reproduce the following disclaimer in documentation provided with the * binary redistribution. * * THIS SOFTWARE IS PROVIDED ``AS IS'', WITHOUT ANY WARRANTIES, EXPRESS * OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. LICENSOR SHALL * NOT BE LIABLE FOR ANY LOSS OR DAMAGES RESULTING FROM THE USE OF THIS * SOFTWARE, EITHER ALONE OR IN COMBINATION WITH ANY OTHER SOFTWARE. * * $Qube: Q/doc/tutorial/programmers/ptut81/maniccube.h,v 1.3 2003/02/14 20:54:51 nps Exp $ */ #include #include #include #include #include #include /** * @file maniccube.h */ /** * The ManicCube class holds the guts of the Entity that we will create. * It will be used to place a 3D star mesh in the scene (the placement was * authored using QStudio) when the placed EntityInstance comes into scope. * * The methods spin(), bounce(), idle(), toggleLooping() are called externally * as a result of keyboard events. They cause a spin or bounce animation to * be played, in a loop or a single time. The idle() method will stop the * current animation when it has completed its cycle. * * The Q::PlaybackListener inheritance and registration (see the embody/ * disembody methods for registration details) and its overridden onEnd() * method are used to loop the animation by restarting it when it has * completed. * * Refer to the GameDev tutorial information about the Entity APIs for further * detail. */ struct ManicCube: public Q::EntityBase, public Q::PlaybackListener { typedef Com::Ptr PTR; ManicCube(); ~ManicCube() {} // Interface EntityBase virtual bool embody(Q::EntityInstance*); virtual void disembody(bool destroyed); virtual void entered(unsigned int yourType, Q::EntityInstance* them, unsigned int theirType) {} virtual void exited(unsigned int yourType, Q::EntityInstance* them, unsigned int theirType) {} virtual void receive(Q::MessagePeer* from, Q::Message*, Q::MessageResult*) {} virtual void tick(float dt) {} // Q::PlaybackListener compliance // we use the PlaybackListener onEnd() method to loop the animation // if required virtual void onStart(Q::Playback& pb, Q::Animation& anim, float start, float end) {} virtual void onEnd(Q::Playback& pb, Q::Animation& anim, float start, float end); // Features - these change the state of the animation void spin(); void bounce(); void idle(); void toggleLooping(); private: void playAnim(const char* segName); static Q::Animation anim_; static Q::Mesh mesh_; // instance of the mesh. This is lightweight, so we need to store // its handle. Q::Instance inst_; // used to play the animation on the Group Q::Playback playback_; // set to true to loop the animation. bool looping_; // cache the currently playing segment name so that we can easily loop it. // this is used for clarity, a more performant solution would be to // cache the start/end times instead of looking them up from the name // of the segment each time. Utils::String segName_; };