Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / client / src / cdb_synchronised.h
blobf4c6472949166d63a7587f03a7a2f304436f62c5
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
7 //
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef CDB_SYNCHRONISED_H
24 #define CDB_SYNCHRONISED_H
27 #include "nel/misc/cdb.h"
28 #include "nel/misc/cdb_branch.h"
29 #include "nel/misc/cdb_manager.h"
31 /**
32 * Class to manage a database of properties
33 * \author Stephane Coutelas
34 * \author Nevrax France
35 * \date 2002
37 class CCDBSynchronised : public NLMISC::CCDBManager
39 /// string associations
40 std::map<uint32,std::string> _Strings;
42 /// True while the first database packet has not been completely processed (including branch observers)
43 bool _InitInProgress;
45 /// The number of "init database packet" received
46 uint8 _InitDeltaReceived;
48 public:
50 /// exception thrown when database is not initialized
51 struct EDBNotInit : public NLMISC::Exception
53 EDBNotInit() : Exception ("Property Database not initialized") {}
56 /**
57 * Default constructor
59 CCDBSynchronised();
61 /**
62 * Return a ptr on the node
63 * \return ptr on the node
65 NLMISC::CCDBNodeBranch * getNodePtr() { return _Database; }
67 /**
68 * Build the structure of the database from a file
69 * \param fileName is the name of file containing the database structure
71 void init( const std::string &fileName, class NLMISC::IProgressCallback &progressCallBack );
73 /**
74 * Load a backup of the database
75 * \param fileName is the name of the backup file
77 void read( const std::string &fileName );
79 /**
80 * Save a backup of the database
81 * \param fileName is the name of the backup file
83 void write( const std::string &fileName );
85 /**
86 * Update the database from a stream coming from the FE
87 * \param f the stream
89 void readDelta( NLMISC::TGameCycle gc, NLMISC::CBitMemStream& s, uint bank );
91 /**
92 * Return the value of a property (the update flag is set to false)
93 * \param name is the name of the property
94 * \return the value of the property
96 sint64 getProp( const std::string &name );
98 /**
99 * Set the value of a property (the update flag is set to true)
100 * \param name is the name of the property
101 * \param value is the value of the property
102 * \return bool : 'true' if the property was found.
104 bool setProp(const std::string &name, sint64 value);
107 * Return the string associated with id
108 * \param id is the string id
109 * \return the string
111 std::string getString( uint32 id );
114 * Set a new string association
115 * \param id is the string id
116 * \param str is the new string
118 void setString( uint32 id, const std::string &);
121 * Clear the database
123 void clear();
126 * Destructor
128 ~CCDBSynchronised() { clear(); }
130 /// Return true while the first database packet has not been completely received
131 bool initInProgress() const { return _InitInProgress; }
133 /// tests
134 void test();
136 /// Reset the init state (if you relauch the game from scratch)
137 void resetInitState() { _InitDeltaReceived = 0; _InitInProgress = true; writeInitInProgressIntoUIDB(); }
139 /// Called after flushObserversCalls() as it calls the observers for branches
140 void setChangesProcessed()
142 if ( allInitPacketReceived() )
144 _InitInProgress = false;
145 writeInitInProgressIntoUIDB(); // replaced by DECLARE_INTERFACE_USER_FCT(isDBInitInProgress)
149 private:
151 friend void impulseDatabaseInitPlayer( NLMISC::CBitMemStream &impulse );
152 friend void impulseInitInventory( NLMISC::CBitMemStream &impulse );
154 void setInitPacketReceived() { ++_InitDeltaReceived; }
155 bool allInitPacketReceived() const { return _InitDeltaReceived == 2; } // Classic database + inventory
157 void writeInitInProgressIntoUIDB();
159 NLMISC::CRefPtr<NLMISC::CCDBNodeLeaf> m_CDBInitInProgressDB;
163 #endif // CDB_SYNCHRONISED_H