1 /** @file clientmobjthinkerdata.h  Private client-side data for mobjs.
2  *
3  * @authors Copyright (c) 2014-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
4  *
5  * @par License
6  * GPL: http://www.gnu.org/licenses/gpl.html
7  *
8  * <small>This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by the
10  * Free Software Foundation; either version 2 of the License, or (at your
11  * option) any later version. This program is distributed in the hope that it
12  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14  * Public License for more details. You should have received a copy of the GNU
15  * General Public License along with this program; if not, see:
16  * http://www.gnu.org/licenses</small>
17  */
18 
19 #ifndef DENG_WORLD_CLIENTMOBJTHINKERDATA_H
20 #define DENG_WORLD_CLIENTMOBJTHINKERDATA_H
21 
22 #include <doomsday/world/mobjthinkerdata.h>
23 #include <de/timer.h>
24 #include <de/ModelDrawable>
25 #include <de/GLState>
26 
27 #include "render/modelrenderer.h"
28 
29 /**
30  * @defgroup clMobjFlags Client Mobj Flags
31  * @ingroup flags
32  */
33 ///@{
34 #define CLMF_HIDDEN         0x01 ///< Not officially created yet
35 #define CLMF_UNPREDICTABLE  0x02 ///< Temporarily hidden (until next delta)
36 #define CLMF_SOUND          0x04 ///< Sound is queued for playing on unhide.
37 #define CLMF_NULLED         0x08 ///< Once nulled, it can't be updated.
38 #define CLMF_STICK_FLOOR    0x10 ///< Mobj will stick to the floor.
39 #define CLMF_STICK_CEILING  0x20 ///< Mobj will stick to the ceiling.
40 #define CLMF_LOCAL_ACTIONS  0x40 ///< Allow local action execution.
41 ///@}
42 
43 // Clmobj knowledge flags. This keeps track of the information that has been
44 // received.
45 #define CLMF_KNOWN_X        0x10000
46 #define CLMF_KNOWN_Y        0x20000
47 #define CLMF_KNOWN_Z        0x40000
48 #define CLMF_KNOWN_STATE    0x80000
49 #define CLMF_KNOWN          0xf0000 ///< combination of all the KNOWN-flags
50 
51 // Magic number for client mobj information.
52 //#define CLM_MAGIC1          0xdecafed1
53 //#define CLM_MAGIC2          0xcafedeb8
54 
55 namespace render { class StateAnimator; }
56 
57 /**
58  * Private client-side data for mobjs. This includes any per-object state for rendering
59  * and client-side network state.
60  *
61  * @todo Lumobj objects (light source interfaces) should be moved into this class, so
62  * that they can exist across frames. -jk
63  */
64 class ClientMobjThinkerData : public MobjThinkerData
65 {
66 public:
67     struct RemoteSync
68     {
69         int flags;
70         uint time; ///< Time of last update.
71         int sound; ///< Queued sound ID.
72         float volume; ///< Volume for queued sound.
73 
RemoteSyncRemoteSync74         RemoteSync()
75             : flags(0)
76             , time(Timer_RealMilliseconds())
77             , sound(0)
78             , volume(0)
79         {}
80     };
81 
82 public:
83     ClientMobjThinkerData(de::Id const &id = de::Id::none());
84     ClientMobjThinkerData(ClientMobjThinkerData const &other);
85 
86     void think() override;
87     IData *duplicate() const override;
88 
89     void stateChanged(state_t const *previousState) override;
90     void damageReceived(int damage, mobj_t const *inflictor) override;
91 
92     int stateIndex() const;
93 
94     bool hasRemoteSync() const;
95 
96     /**
97      * Returns the network state of the mobj. This state is not allocated until this is
98      * called for the first time.
99      */
100     RemoteSync &remoteSync();
101 
102     /**
103      * If the object is represented by a model, returns the current state of the
104      * object's animation.
105      *
106      * @return Animation state, or @c NULL if not drawn as a model.
107      */
108     render::StateAnimator *animator();
109 
110     render::StateAnimator const *animator() const;
111 
112     de::Matrix4f const &modelTransformation() const;
113 
114     void operator << (de::Reader &from) override;
115     void operator >> (de::Writer &to) const override;
116 
117 private:
118     DENG2_PRIVATE(d)
119 };
120 
121 #endif // DENG_WORLD_CLIENTMOBJTHINKERDATA_H
122