Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / ryzom / common / src / game_share / action.h
bloba9eac5dae3e522cbb4cb8d5d18b29440f36d7cf8
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef NL_ACTION_H
18 #define NL_ACTION_H
21 // Includes
24 #include <nel/misc/types_nl.h>
25 #include <nel/misc/bit_mem_stream.h>
26 #include <nel/misc/vector.h>
28 #include "entity_types.h"
29 #include "ryzom_entity_id.h"
32 namespace CLFECOMMON {
35 // Action code type
38 typedef uint8 TActionCode;
41 // Action codes
44 // 0->3 are special action coded in few bits
46 const TActionCode ACTION_POSITION_CODE = 0;
47 const TActionCode ACTION_GENERIC_CODE = 1;
48 const TActionCode ACTION_GENERIC_MULTI_PART_CODE = 2;
49 const TActionCode ACTION_SINT64 = 3;
51 const TActionCode ACTION_SYNC_CODE = 10;
52 const TActionCode ACTION_DISCONNECTION_CODE = 11;
53 const TActionCode ACTION_ASSOCIATION_CODE = 12;
54 const TActionCode ACTION_LOGIN_CODE = 13;
56 const TActionCode ACTION_TARGET_SLOT_CODE = 40;
58 const TActionCode ACTION_DUMMY_CODE = 99;
61 #undef TEST_POSITION_CORRECTNESS
65 // Classes
68 class CAction
70 public:
72 union TValue
74 public:
75 TValue() {}
76 // TValue(double d) : Double(d) {}
77 // TValue(float f) : Float(f) {}
78 TValue(sint32 i) : Int(i) {}
79 TValue(uint64 u) : UInt64(u) {}
80 TValue(sint64 s) : SInt64(s) {}
81 // TValue(float x, float y, float z) { Vector.x = x; Vector.y = y; Vector.z = z; }
82 // TValue(const NLMISC::CVector& v ) { Vector.x = v.x; Vector.y = v.y; Vector.z = v.z; }
83 public:
84 // NLMISC::CVector getVector() const { return NLMISC::CVector(Vector.x, Vector.y, Vector.z); }
85 // float getFloat() const { return Float; }
86 // double getDouble() const { return Double; }
87 sint32 getInt() const { return Int; }
88 uint64 getUInt64() const { return UInt64; }
89 sint64 getInt64() const { return SInt64; }
90 public:
91 // struct { float x, y, z; } Vector;
92 // float Float;
93 // double Double;
94 sint32 Int;
95 uint64 UInt64;
96 sint64 SInt64;
100 typedef sint64 TValue;
102 public:
104 virtual ~CAction() {}
106 /** This function creates initializes its fields using the buffer.
107 * \param buffer pointer to the buffer where the data are
108 * \size size of the buffer
110 virtual void unpack (NLMISC::CBitMemStream &/* message */) { }
112 /// This functions is used when you want to transform an action into an IStream.
113 virtual void serial (NLMISC::IStream &/* f */) { }
115 /** Returns the size of this action when it will be send to the UDP connection:
116 * the size is *IN BITS*, not in bytes (the actual size is this one plus the header size)
118 virtual uint32 size () { return 0; }
120 /// Returns the priority of this action, it can changed dynamically if you want (1 is very urgent)
121 uint32 priority () { return _Priority; }
123 /// Sets the priority
124 void setPriority( uint32 prio ) { _Priority = prio; }
126 /// Sets the value of the action
127 virtual void setValue(const TValue &/* value */) { }
129 /// Sets the value of the action
130 virtual TValue getValue() const { return (CAction::TValue)0; }
132 /// Returns true if the property is continuous
133 virtual bool isContinuous() const { return false; }
135 /// This value must be set (in ms) in the ctor of your action to know when this action must be resent to the other side.
136 uint32 Timeout; // TODO: remove?
137 /// Gamecycle to measure time between sending and ack (impulsions only)
138 NLMISC::TGameCycle GameCycle; // TEMP?
140 TActionCode Code;
141 TPropIndex PropertyCode;
142 TCLEntityId Slot;
144 protected:
146 /// Default ctor that initialize Timeout value
147 CAction ();
149 /** This function transform the internal field and transform them into a buffer for the UDP connection.
150 * \param buffer pointer to the buffer where the data will be written
151 * \size size of the buffer
153 virtual void pack (NLMISC::CBitMemStream &/* message */) { }
155 /** This method intialises the action with a default state */
156 virtual void reset() { }
158 friend class CActionFactory;
160 private:
162 uint32 _Priority;
166 class CActionImpulsion : public CAction
168 public:
169 virtual ~CActionImpulsion() {}
170 bool AllowExceedingMaxSize;
174 extern const CAction::TValue NullValue;
178 #endif // NL_ACTION_H
180 /* End of action.h */