interreality.org [VOS]
[Home] [About]
[Screenshots]
[Download]
[News]
[Community]
[Documentation] [Manual]
[Bugs & Requests] [Wiki]

/home/tetron/hack/vos/libs/vos/metaobjects/a3dl/actor.hh

Go to the documentation of this file.
00001 /*
00002     This file is part of the Virtual Object System of
00003     the Interreality project (http://interreality.org).
00004 
00005     Copyright (C) 2003 Peter Amstutz
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 
00021     Peter Amstutz <http://www.interreality.org>
00022 */
00023 
00024 #ifndef _ACTOR_HH_
00025 #define _ACTOR_HH_
00026 
00027 #include <vos/vos/vos.hh>
00028 
00029 #include "a3dldefs.hh"
00030 
00031 #ifndef A3DL_EXPORTS
00032 IMPORT_METAOBJECT_FACTORIES(A3DL_Actor)
00033 #endif
00034 
00035 namespace A3DL
00036 {
00037     class Actor;
00038     class ActionEvent;
00039 
00040     class A3DL_API ActionListener
00041     {
00042     public:
00043         virtual ~ActionListener() { }
00044         virtual void notifyActionChange(const ActionEvent& ae) = 0;
00045     };
00046 
00047     class A3DL_API ActionEvent : public VUtil::RefCounted
00048     {
00049     public:
00050         typedef enum { SetActionCycle, StartActionCycle, StopAction,
00051                        StopAllActions, DoActionOnce } EventType;
00052     private:
00053         EventType type;
00054         VUtil::vRef<Actor> actor;
00055         std::string action;
00056         float weight;
00057         float delayIn;
00058         float delayOut;
00059     public:
00060         ActionEvent(EventType et, Actor* actor,
00061                     const std::string& action = "",
00062                     float weight = 0.0,
00063                     float delayIn = 0.0,
00064                     float delayOut = 0.0);
00065         ~ActionEvent();
00066 
00067         EventType getEventType() const { return type; };
00068         const std::string& getAction() const { return action; };
00069         VUtil::vRef<Actor> getActor() const;
00070         float getWeight() const { return weight; }
00071         float getDelayIn() const { return delayIn; }
00072         float getDelayOut() const { return delayOut; }
00073 
00074         void deliverTo(ActionListener* al) { al->notifyActionChange(*this); }
00075     };
00076 
00077     class A3DL_API RemoteActionListener : public VOS::MetaObject, public ActionListener
00078     {
00079     public:
00080         RemoteActionListener(VOS::VobjectBase* superobject);
00081         virtual ~RemoteActionListener();
00082 
00083         virtual void notifyActionChange(const ActionEvent& ae);
00084     };
00085 
00086     class A3DL_API Actor : public VOS::MetaObject
00087     {
00088     protected:
00089         VUtil::ListenerBase<ActionListener, ActionEvent> actionListeners;
00090 
00091         std::map< std::string, VUtil::vRef<ActionEvent> > actions;
00092 
00093     public:
00094         Actor(VOS::VobjectBase* superobject);
00095         virtual ~Actor();
00096 
00097         virtual const std::string getVOSType();
00098 
00099         virtual void addActionListener(ActionListener* al);
00100         virtual void removeActionListener(ActionListener* al);
00101 
00102         virtual void setActionCycle(const std::string& action, float weight) = 0;
00103         virtual void startActionCycle(const std::string& action, float weight,
00104                                       float delay) = 0;
00105         virtual void stopAction(const std::string& action, float delay) = 0;
00106         virtual void stopAllActions() = 0;
00107         virtual void doActionOnce(const std::string& action, float delayIn,
00108                                   float delayOut) = 0;
00109         virtual bool isDoingAction(const std::string& action)
00110             { return actions.count(action) > 0; }
00111     };
00112 
00113     class A3DL_API LocalActor : public virtual Actor
00114     {
00115     public:
00116         LocalActor(VOS::VobjectBase* superobject);
00117         virtual ~LocalActor();
00118 
00119         static VOS::MetaObject* new_LocalActor(VOS::VobjectBase* superobject,
00120                                                const std::string& type);
00121 
00122         virtual void addActionListener(ActionListener* al);
00123         virtual void removeActionListener(ActionListener* al);
00124 
00125         virtual void setActionCycle(const std::string& action, float weight);
00126         virtual void startActionCycle(const std::string& action, float weight, float delay);
00127         virtual void stopAction(const std::string& action, float delay);
00128         virtual void stopAllActions();
00129         virtual void doActionOnce(const std::string& action, float delayIn, float delayOut);
00130 
00131         virtual void startListeningHandler(VOS::Message* m);
00132         virtual void stopListeningHandler(VOS::Message* m);
00133         virtual void actionChangeHandler(VOS::Message* m);
00134     };
00135 
00136     class A3DL_API RemoteActor : public virtual Actor
00137     {
00138     public:
00139         RemoteActor(VOS::VobjectBase* superobject);
00140         virtual ~RemoteActor();
00141 
00142         static VOS::MetaObject* new_RemoteActor(VOS::VobjectBase* superobject, const std::string& type);
00143 
00144         virtual void addActionListener(ActionListener* al);
00145         virtual void removeActionListener(ActionListener* al);
00146 
00147         virtual void setActionCycle(const std::string& action, float weight);
00148         virtual void startActionCycle(const std::string& action, float weight, float delay);
00149         virtual void stopAction(const std::string& action, float delay);
00150         virtual void stopAllActions();
00151         virtual void doActionOnce(const std::string& action, float delayIn, float delayOut);
00152 
00153         virtual void startListeningUpdateHandler(VOS::Message* m);
00154         virtual void stopListeningUpdateHandler(VOS::Message* m);
00155         virtual void actionChangeUpdateHandler(VOS::Message* m);
00156     };
00157 };
00158 
00159 #endif