2008-08-17 21:12:50 +00:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2008 Alistair Riddoch
|
|
|
|
|
//
|
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef SERVER_STORAGE_MANAGER_H
|
|
|
|
|
#define SERVER_STORAGE_MANAGER_H
|
|
|
|
|
|
2014-09-20 22:13:49 +02:00
|
|
|
#include "Persistence.h"
|
|
|
|
|
|
|
|
|
|
#include "common/OperationRouter.h"
|
|
|
|
|
#include "modules/EntityRef.h"
|
|
|
|
|
|
|
|
|
|
#include <sigc++/trackable.h>
|
2008-08-17 21:12:50 +00:00
|
|
|
|
|
|
|
|
#include <deque>
|
2008-08-27 15:46:14 +00:00
|
|
|
#include <string>
|
2013-04-06 18:26:38 +02:00
|
|
|
#include <map>
|
2013-08-21 20:56:09 +02:00
|
|
|
#include <set>
|
2008-08-17 21:12:50 +00:00
|
|
|
|
|
|
|
|
class Entity;
|
|
|
|
|
class WorldRouter;
|
2008-08-27 15:46:14 +00:00
|
|
|
class PropertyBase;
|
2013-08-21 20:56:09 +02:00
|
|
|
class MindInspector;
|
2008-08-17 21:12:50 +00:00
|
|
|
|
|
|
|
|
/// \brief StorageManager represents the subsystem which stores world storage
|
|
|
|
|
///
|
|
|
|
|
/// This class has one instance which is the core of the world's persistent
|
|
|
|
|
/// storage in whatever data store is being used.
|
2014-09-20 22:13:49 +02:00
|
|
|
class StorageManager : public sigc::trackable {
|
2008-08-17 21:12:50 +00:00
|
|
|
protected:
|
|
|
|
|
typedef std::deque<EntityRef> Entitystore;
|
2008-09-04 09:39:04 +00:00
|
|
|
typedef std::deque<long> Idstore;
|
2008-08-17 21:12:50 +00:00
|
|
|
|
|
|
|
|
/// \brief Queue of references to entities yet to be stored.
|
|
|
|
|
Entitystore m_unstoredEntities;
|
|
|
|
|
|
|
|
|
|
/// \brief Queue of references to entities with modifications.
|
|
|
|
|
Entitystore m_dirtyEntities;
|
|
|
|
|
|
2008-09-04 09:39:04 +00:00
|
|
|
/// \brief Queue of IDs of entities that are destroyed
|
|
|
|
|
Idstore m_destroyedEntities;
|
|
|
|
|
|
2014-09-20 22:13:49 +02:00
|
|
|
/// \brief Handles inspection of minds.
|
2013-08-21 20:56:09 +02:00
|
|
|
MindInspector* m_mindInspector;
|
|
|
|
|
|
|
|
|
|
/// \brief Keeps track of outstanding requests for thoughts.
|
|
|
|
|
///
|
|
|
|
|
/// Value stored is entity id.
|
|
|
|
|
std::set<std::string> m_outstandingThoughtRequests;
|
|
|
|
|
|
2014-09-20 22:13:49 +02:00
|
|
|
std::deque<Persistence::AddCharacterData> m_addedCharacters;
|
|
|
|
|
|
|
|
|
|
std::deque<std::string> m_deletedCharacters;
|
|
|
|
|
|
2008-09-01 17:45:59 +00:00
|
|
|
int m_insertEntityCount;
|
|
|
|
|
int m_updateEntityCount;
|
|
|
|
|
|
|
|
|
|
int m_insertPropertyCount;
|
|
|
|
|
int m_updatePropertyCount;
|
|
|
|
|
|
2008-11-03 01:13:36 +00:00
|
|
|
int m_insertQps;
|
|
|
|
|
int m_updateQps;
|
|
|
|
|
|
|
|
|
|
int m_insertQpsNow;
|
|
|
|
|
int m_updateQpsNow;
|
|
|
|
|
|
|
|
|
|
int m_insertQpsAvg;
|
|
|
|
|
int m_updateQpsAvg;
|
|
|
|
|
|
|
|
|
|
int m_insertQpsIndex;
|
|
|
|
|
int m_updateQpsIndex;
|
|
|
|
|
|
|
|
|
|
int m_insertQpsRing[32];
|
|
|
|
|
int m_updateQpsRing[32];
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
void entityInserted(LocatedEntity *);
|
|
|
|
|
void entityUpdated(LocatedEntity *);
|
2013-06-15 22:54:09 +02:00
|
|
|
void entityContainered(const LocatedEntity *oldLocation, LocatedEntity *entity);
|
2008-08-17 21:12:50 +00:00
|
|
|
|
2008-08-27 15:46:14 +00:00
|
|
|
void encodeProperty(PropertyBase *, std::string &);
|
2014-09-06 20:44:53 +02:00
|
|
|
void restorePropertiesRecursively(LocatedEntity *);
|
2008-08-27 15:46:14 +00:00
|
|
|
|
2013-04-06 18:26:38 +02:00
|
|
|
void restoreThoughts(LocatedEntity *);
|
2013-08-22 10:43:03 +02:00
|
|
|
/// \brief Requests thoughts from the entity, if it has a mind.
|
|
|
|
|
///
|
|
|
|
|
/// \return True if a thoughts query was sent.
|
|
|
|
|
bool storeThoughts(LocatedEntity *);
|
2013-04-06 18:26:38 +02:00
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
void insertEntity(LocatedEntity *);
|
|
|
|
|
void updateEntity(LocatedEntity *);
|
2015-05-26 22:27:39 +02:00
|
|
|
void updateEntityThoughts(LocatedEntity *);
|
2013-01-17 10:17:07 +00:00
|
|
|
void restoreChildren(LocatedEntity *);
|
2008-08-26 14:26:25 +00:00
|
|
|
|
2013-08-21 20:56:09 +02:00
|
|
|
/// \brief Callback for m_mindInspector when thoughts arrive.
|
|
|
|
|
void thoughtsReceived(const std::string& entityId, const Operation& thoughts);
|
|
|
|
|
|
2014-09-20 22:13:49 +02:00
|
|
|
bool persistance_characterAdded(const Persistence::AddCharacterData& data);
|
|
|
|
|
bool persistance_characterDeleted(const std::string& entityId);
|
|
|
|
|
|
2008-08-17 21:12:50 +00:00
|
|
|
public:
|
|
|
|
|
StorageManager(WorldRouter &);
|
2013-08-21 20:56:09 +02:00
|
|
|
virtual ~StorageManager();
|
2008-08-22 18:59:06 +00:00
|
|
|
|
|
|
|
|
void tick();
|
2008-08-25 15:47:11 +00:00
|
|
|
int initWorld();
|
2008-11-17 02:14:59 +00:00
|
|
|
int restoreWorld();
|
2013-04-06 18:26:38 +02:00
|
|
|
|
|
|
|
|
/// \brief Called when shutting down.
|
|
|
|
|
///
|
|
|
|
|
/// It's expected that the storage manager attempts to persist entity state.
|
2013-04-06 19:05:13 +02:00
|
|
|
int shutdown(bool& exit_flag, const std::map<long, LocatedEntity *>& entites);
|
2013-04-06 18:26:38 +02:00
|
|
|
|
2013-08-21 20:56:09 +02:00
|
|
|
/// \brief Request thoughts from the supplied entities.
|
|
|
|
|
///
|
|
|
|
|
/// The method will take care of only requesting thoughts from entities
|
|
|
|
|
/// with external minds.
|
|
|
|
|
/// \param entities A list of entities. Only those entities that have
|
|
|
|
|
/// external minds will be queried.
|
2013-08-22 10:43:03 +02:00
|
|
|
/// \return The number of requests sent.
|
|
|
|
|
size_t requestMinds(const std::map<long, LocatedEntity *>& entites);
|
2013-08-21 20:56:09 +02:00
|
|
|
|
|
|
|
|
/// \brief Gets the number of outstanding thought requests.
|
|
|
|
|
size_t numberOfOutstandingThoughtRequests() const;
|
|
|
|
|
|
2008-08-17 21:12:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // SERVER_STORAGE_MANAGER_H
|