1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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 DMS_PROPERTYACCESSORT_H
18 #define DMS_PROPERTYACCESSORT_H
20 #include "nel/misc/types_nl.h"
21 #include "game_share/object.h"
28 class CDynamicMapClient
;
31 class CPropertyAccessor
34 CPropertyAccessor(CDynamicMapClient
* client
, CObjectFactory
* factory
)
37 _Factory
= factory
; //client->getFactory
42 CObject
* getPropertyValue(CObject
* component
, const std::string
& attrName
);
44 // see if an object has a value in its base (e.g say if it redefines the default value)
45 bool hasValueInBase(CObject
* component
, const std::string
& attrName
);
47 //get The propertyValue as number or 0 if not found
48 double getValueAsNumber(CObject
* component
, const std::string
& attrName
) const;
49 sint64
getValueAsInteger(CObject
* component
, const std::string
& attrName
) const;
51 const CObject
* getPropertyValue(const CObject
* component
, const std::string
& attrName
) const;
53 void getPropertyList(CObject
* component
, std::list
<std::string
>& propertyList
);
56 /** Add a local value that prevails over the network value when read from this property accessor
57 * 'localValue' is a value supplied by the caller. When getPropertyValue will be called on 'shadowedValue', then
58 * 'localValue' will be returned instead, thus shadowing the original value.
59 * Any previous value that is shadowing the original value will be deleted when calling 'shadowValue'
61 * Intended usage is to modify a value locally on the client while it is being edited and before its value is commited
62 * Typically example is the slider in the client ui :
63 * While moving a slider the client wants to have instant feedback of the value on the screen.
64 * Update of screen content is usually done by implementing event handlers that are triggered when a property of an object
65 * changes. Unless the shadowing system is used, a property change can only occur when the corresponding network msg
66 * is received. So each time the slider move, we should send a requestSetNode or similar network message and wait for it to return back to our client (edition
67 * messages are repeated to all editing clients)
69 * This is not desirable in the case of sliders, because too many messages would be generated while the user move the mouse.
70 * Instead we only want to send a net message when the user release the mouse button
74 * - While a property is being edited, 'shadowValue' should be called. Posssibly notification of property change should be fired by the caller.
75 * any call to CPropertyAccessor::getPropertyValue will return the shadowed value instead of
76 * - If value is confirmed : 'commitValue' should be called, and the matching requestxxx method should be called to notify the server that the value has changed.
77 * current local value is copied into. Possibly, notification of property change should be fired.
78 * - If value is canceled : 'rollbackValue' should be called. Possibly, notification of property change should be fired.
82 void shadowValue(CObject
*shadowedValue
, CObject
*localValue
);
83 // Test if a value is shadowed, and returns the shadowing value
84 CObject
*getShadowingValue(CObject
*shadowedValue
);
85 /** stops value shadowing for the object 'shadowedValue', confirming the changes.
86 * The local value is copied into the shadowed value
88 void commitValue(CObject
*shadowedValue
);
89 /** stops value shadowing for the object 'shadowedValue', leaving the shadowed value unmodified.
91 void rollbackValue(CObject
*shadowedValue
);
94 CDynamicMapClient
* _Client
;
95 // remove dead references to shadowed value
96 void purgeShadowedValues();
101 CShadowedValue() : LocalValue(NULL
) {}
102 CObject::TRefPtr ShadowedValue
;
105 // usually there isn't more than a few shadowed value at a time.
107 std::vector
<CShadowedValue
> _ShadowedValues
;
108 CObjectFactory
* _Factory
;
113 #endif //DMS_PROPERTYACCESSORT_H