Reworked Archive package for standard data types and fixed issue with Server package overrun

This commit is contained in:
Cekis
2021-11-13 02:22:37 -05:00
parent 6725ce7696
commit 26b6f8365f
19 changed files with 164 additions and 180 deletions
+2 -2
View File
@@ -77,13 +77,13 @@ elseif (UNIX)
endif ()
# don't put anything too crazy in debug...and any common flags go into CMAKE_CXX_FLAGS
set(CMAKE_CXX_FLAGS_DEBUG "-D_DEBUG -DDEBUG_LEVEL=2 -DPRODUCTION=0 -O0 -g3")
set(CMAKE_CXX_FLAGS_DEBUG "-D_DEBUG -DDEBUG_LEVEL=2 -DPRODUCTION=0 -O0 -ggdb")
# release specific cflags - optimizations beyond the default for both types is mostly just -O flags
set(CMAKE_CXX_FLAGS_RELEASE "-DDEBUG_LEVEL=0 -DPRODUCTION=1")
# we use fewer, if any, crazy optimizations for profile generation, and likewise release flags for the minsizerel
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} -ggdb")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_RELEASE}")
# Ofast doesn't work with gcc builds
@@ -79,7 +79,7 @@ void GameConnection::receive(const Archive::ByteStream & message)
{
if(! m_pid)
{
GenericValueTypeMessage<unsigned long> msg(r);
GenericValueTypeMessage<uint32_t> msg(r);
m_pid = msg.getValue();
#ifndef _WIN32
@@ -103,8 +103,8 @@ void ManagerConnection::onReceive(const Archive::ByteStream & message)
switch(messageType) {
case constcrc("SystemTimeCheck") :
{
long const currentTime = static_cast<long>(::time(nullptr));
GenericValueTypeMessage<std::pair<std::string, long > > msg(r);
int32_t const currentTime = static_cast<int32_t>(::time(nullptr));
GenericValueTypeMessage<std::pair<std::string, int32_t > > msg(r);
if (TaskManager::getNodeLabel() == "node0")
{
@@ -150,7 +150,7 @@ void ManagerConnection::onReceive(const Archive::ByteStream & message)
{
LOG("CustomerService", ("system_clock_mismatch:System clock mismatch (%d seconds) by more than %d seconds: master TaskManager epoch (%ld), remote TaskManager %s (%s) epoch (%ld). Telling remote TaskManager to terminate.", (std::max(currentTime, t.getCurrentEpochTime()) - std::min(currentTime, t.getCurrentEpochTime())), ConfigTaskManager::getMaximumClockDriftToleranceSeconds(), currentTime, t.getCommandLine().c_str(), getRemoteAddress().c_str(), t.getCurrentEpochTime()));
GenericValueTypeMessage<std::pair<std::string, std::pair<long, long> > > systemTimeMismatchMessage("SystemTimeMismatchMessage", std::make_pair(TaskManager::getNodeLabel(), std::make_pair(static_cast<long>(currentTime), t.getCurrentEpochTime())));
GenericValueTypeMessage<std::pair<std::string, std::pair<int32_t, int32_t> > > systemTimeMismatchMessage("SystemTimeMismatchMessage", std::make_pair(TaskManager::getNodeLabel(), std::make_pair(static_cast<int32_t>(currentTime), static_cast<int32_t> (t.getCurrentEpochTime()))));
send(systemTimeMismatchMessage);
}
}
@@ -166,7 +166,7 @@ void ManagerConnection::onReceive(const Archive::ByteStream & message)
}
case constcrc("SystemTimeMismatchMessage") :
{
GenericValueTypeMessage<std::pair<std::string, std::pair<long, long> > > msg(r);
GenericValueTypeMessage<std::pair<std::string, std::pair<int32_t, int32_t> > > msg(r);
FATAL((msg.getValue().first == "node0"), ("System clock mismatch (%d seconds) by more than %d seconds: master TaskManager epoch (%ld), self epoch (%ld)", (std::max(msg.getValue().second.first, msg.getValue().second.second) - std::min(msg.getValue().second.first, msg.getValue().second.second)), ConfigTaskManager::getMaximumClockDriftToleranceSeconds(), msg.getValue().second.first, msg.getValue().second.second));
break;
}
@@ -970,7 +970,7 @@ void TaskManager::update()
ManagerConnection * master = Locator::getServer("node0");
if (master)
{
GenericValueTypeMessage<std::pair<std::string, long > > msg("SystemTimeCheck", std::make_pair(getNodeLabel(), static_cast<long>(timeNow)));
GenericValueTypeMessage<std::pair<std::string, int32_t > > msg("SystemTimeCheck", std::make_pair(getNodeLabel(), static_cast<int32_t>(timeNow)));
master->send(msg);
}
}
@@ -115,9 +115,9 @@ namespace Archive
{
void get(ReadIterator & source, PopulationList & target)
{
size_t numEntries;
int32_t numEntries;
get(source,numEntries);
for (size_t count=0; count < numEntries; ++count)
for (int32_t count=0; count < numEntries; ++count)
{
std::string scene;
int x;
@@ -133,7 +133,7 @@ namespace Archive
void put(ByteStream & target, const PopulationList & source)
{
put(target,source.m_populationMap.size());
put(target, static_cast<int32_t> (source.m_populationMap.size()));
for (PopulationList::PopulationMapType::const_iterator i=source.m_populationMap.begin(); i!=source.m_populationMap.end(); ++i)
{
put(target,i->first.getScene());
@@ -122,7 +122,7 @@ std::string const &GameNetworkMessage::getCmdName() const
// ----------------------------------------------------------------------
std::string const &GameNetworkMessage::getCmdName(unsigned long cmdCrc) // static
std::string const &GameNetworkMessage::getCmdName(uint32_t cmdCrc) // static
{
std::string &val = s_messageTypes[cmdCrc];
if (val.empty())
@@ -39,7 +39,7 @@ public:
std::string const &getCmdName() const;
static std::vector<std::pair<std::string, int> > const getMessageCount();
static std::string const &getCmdName(unsigned long cmdCrc);
static std::string const &getCmdName(uint32_t cmdCrc);
private:
GameNetworkMessage();
+16 -44
View File
@@ -30,42 +30,28 @@ inline void get(ReadIterator & source, float & target)
//---------------------------------------------------------------------
inline void get(ReadIterator & source, unsigned long int & target)
inline void get(ReadIterator & source, uint32_t & target)
{
source.get(&target, 4);
}
//---------------------------------------------------------------------
inline void get(ReadIterator & source, signed long int & target)
inline void get(ReadIterator & source, int32_t & target)
{
source.get(&target, 4);
}
//---------------------------------------------------------------------
inline void get(ReadIterator & source, unsigned int & target)
{
source.get(&target, 4);
}
//---------------------------------------------------------------------
inline void get(ReadIterator & source, signed int & target)
{
source.get(&target, 4);
}
//---------------------------------------------------------------------
inline void get(ReadIterator & source, unsigned short int & target)
inline void get(ReadIterator & source, uint16_t & target)
{
source.get(&target, 2);
}
//---------------------------------------------------------------------
inline void get(ReadIterator & source, signed short int & target)
inline void get(ReadIterator & source, int16_t & target)
{
source.get(&target, 2);
}
@@ -190,9 +176,9 @@ template<typename A> inline void get_ptr(ReadIterator & source, std::vector<cons
template<typename Key, typename Value> inline void get(ReadIterator & source, std::map<Key, Value> & target)
{
size_t numKeys;
int32_t numKeys;
get(source, numKeys);
size_t i;
int32_t i;
for(i = 0; i < numKeys; ++i)
{
Key k;
@@ -229,42 +215,28 @@ inline void put(ByteStream & target, const float & source)
//---------------------------------------------------------------------
inline void put(ByteStream & target, const unsigned long int & source)
inline void put(ByteStream & target, const uint32_t & source)
{
target.put(&source, 4);
}
//---------------------------------------------------------------------
inline void put(ByteStream & target, const signed long int & source)
inline void put(ByteStream & target, const int32_t & source)
{
target.put(&source, 4);
}
//---------------------------------------------------------------------
inline void put(ByteStream & target, const unsigned int & source)
{
target.put(&source, 4);
}
//---------------------------------------------------------------------
inline void put(ByteStream & target, const signed int & source)
{
target.put(&source, 4);
}
//---------------------------------------------------------------------
inline void put(ByteStream & target, const unsigned short int & source)
inline void put(ByteStream & target, const uint16_t & source)
{
target.put(&source, 2);
}
//---------------------------------------------------------------------
inline void put(ByteStream & target, const signed short int & source)
inline void put(ByteStream & target, const int16_t & source)
{
target.put(&source, 2);
}
@@ -296,12 +268,12 @@ inline void put(ByteStream & target, const std::string & source)
{
if (source.size() < 65535)
{
unsigned short len = static_cast<unsigned short>(source.size());
unsigned short len = static_cast<uint16_t>(source.size());
put(target, len);
}
else
{
unsigned short len = static_cast<unsigned short>(65535);
unsigned short len = static_cast<uint16_t>(65535);
put(target, len);
unsigned int size = source.size();
put(target, size);
@@ -345,7 +317,7 @@ template<typename A, typename B> inline void put(ByteStream & target, const std:
template<typename A> inline void put(ByteStream & target, const std::vector<A> & source)
{
signed int length = source.size();
int32_t length = source.size();
target.put(&length, 4);
for(int i = 0; i < length; ++i)
{
@@ -357,7 +329,7 @@ template<typename A> inline void put(ByteStream & target, const std::vector<A> &
template<typename A> inline void put(ByteStream & target, const std::set<A> & source)
{
signed int length = source.size();
int32_t length = source.size();
target.put(&length, 4);
for (typename std::set<A>::const_iterator i = source.begin(); i != source.end(); ++i)
put(target, *i);
@@ -367,7 +339,7 @@ template<typename A> inline void put(ByteStream & target, const std::set<A> & so
template<typename A> inline void put(ByteStream & target, const std::deque<A> & source)
{
signed int length = source.size();
int32_t length = source.size();
target.put(&length, 4);
for(int i = 0; i < length; ++i)
{
@@ -379,7 +351,7 @@ template<typename A> inline void put(ByteStream & target, const std::deque<A> &
template<typename Key, typename Value> inline void put(ByteStream & target, const std::map<Key, Value> & source)
{
size_t numKeys = source.size();
int32_t numKeys = source.size();
put(target, numKeys);
for (typename std::map<Key, Value>::const_iterator i = source.begin(); i != source.end(); ++i)
{
@@ -726,7 +726,7 @@ public:
/** pure virtual */
virtual ~AutoDeltaContainer() = 0;
/** pure virtual */
virtual const size_t size() const = 0;
virtual const int32_t size() const = 0;
};
//-----------------------------------------------------------------------
+16 -16
View File
@@ -65,7 +65,7 @@ public: // methods
void pack(ByteStream & target) const;
void packDelta(ByteStream & target) const;
void set(const KeyType & key, const ValueType & value);
const size_t size() const;
const int32_t size() const;
void unpack(ReadIterator & source);
void unpackDelta(ReadIterator & source);
static void pack(ByteStream & target, const std::vector<Command> & data);
@@ -88,7 +88,7 @@ private:
void onSet(const KeyType &, const ValueType &, const ValueType &);
MapType container;
size_t baselineCommandCount;
int32_t baselineCommandCount;
mutable std::vector<Command> changes;
std::pair<ObjectType *, void (ObjectType::*)(const KeyType &, const ValueType &)> *onEraseCallback;
std::pair<ObjectType *, void (ObjectType::*)(const KeyType &, const ValueType &)> *onInsertCallback;
@@ -349,7 +349,7 @@ template<class KeyType, typename ValueType, typename ObjectType>
inline void AutoDeltaMap<KeyType, ValueType, ObjectType>::pack(ByteStream & target) const
{
typename std::map<KeyType, ValueType>::const_iterator i;
Archive::put(target, container.size());
Archive::put(target, static_cast<int32_t>(container.size()));
Archive::put(target, baselineCommandCount);
unsigned char cmd;
for(i = container.begin(); i != container.end(); ++i)
@@ -374,8 +374,8 @@ inline void AutoDeltaMap<KeyType, ValueType, ObjectType>::pack(ByteStream & targ
template<class KeyType, typename ValueType, typename ObjectType>
inline void AutoDeltaMap<KeyType, ValueType, ObjectType>::pack(ByteStream & target, const std::vector<Command> &data)
{
Archive::put(target, data.size());
Archive::put(target, static_cast<size_t>(0)); // baselineCommandCount
Archive::put(target, static_cast<int32_t>(data.size()));
Archive::put(target, static_cast<int32_t>(0)); // baselineCommandCount
for(typename std::vector<Command>::const_iterator c(data.begin()); c != data.end(); ++c)
{
assert(c->cmd == Command::ADD); // only add is valid in packing the whole container
@@ -403,7 +403,7 @@ inline void AutoDeltaMap<KeyType, ValueType, ObjectType>::pack(ByteStream & targ
template<class KeyType, typename ValueType, typename ObjectType>
inline void AutoDeltaMap<KeyType, ValueType, ObjectType>::packDelta(ByteStream & target) const
{
Archive::put(target, changes.size());
Archive::put(target, static_cast<int32_t>(changes.size()));
Archive::put(target, baselineCommandCount);
for (typename std::vector<Command>::iterator i = changes.begin(); i != changes.end(); ++i)
{
@@ -435,7 +435,7 @@ inline void AutoDeltaMap<KeyType, ValueType, ObjectType>::packDelta(ByteStream &
@return the number of elements in the map
*/
template<class KeyType, typename ValueType, typename ObjectType>
inline const size_t AutoDeltaMap<KeyType, ValueType, ObjectType>::size() const
inline const int32_t AutoDeltaMap<KeyType, ValueType, ObjectType>::size() const
{
return container.size();
}
@@ -514,12 +514,12 @@ inline void AutoDeltaMap<KeyType, ValueType, ObjectType>::unpack(ReadIterator &
clearDelta();
Command c;
size_t commandCount;
int32_t commandCount;
Archive::get(source, commandCount);
Archive::get(source, baselineCommandCount);
for (size_t i = 0; i < commandCount; ++i)
for (int32_t i = 0; i < commandCount; ++i)
{
Archive::get(source, c.cmd);
assert(c.cmd == Command::ADD); // only add is valid in unpack
@@ -548,13 +548,13 @@ inline void AutoDeltaMap<KeyType, ValueType, ObjectType>::unpack(ReadIterator &
// unpacking baseline data
Command c;
size_t commandCount;
size_t baselineCommandCount;
int32_t commandCount;
int32_t baselineCommandCount;
Archive::get(source, commandCount);
Archive::get(source, baselineCommandCount);
for (size_t i = 0; i < commandCount; ++i)
for (int32_t i = 0; i < commandCount; ++i)
{
Archive::get(source, c.cmd);
assert(c.cmd == Command::ADD); // only add is valid in unpack
@@ -572,7 +572,7 @@ template<class KeyType, typename ValueType, typename ObjectType>
inline void AutoDeltaMap<KeyType, ValueType, ObjectType>::unpackDelta(ReadIterator & source)
{
Command c;
size_t skipCount, commandCount, targetBaselineCommandCount;
int32_t skipCount, commandCount, targetBaselineCommandCount;
Archive::get(source, commandCount);
Archive::get(source, targetBaselineCommandCount);
@@ -593,7 +593,7 @@ inline void AutoDeltaMap<KeyType, ValueType, ObjectType>::unpackDelta(ReadIterat
if (skipCount > commandCount)
skipCount = commandCount;
size_t i;
int32_t i;
for (i = 0; i < skipCount; ++i)
{
Archive::get(source, c.cmd);
@@ -647,12 +647,12 @@ template<class KeyType, typename ValueType, typename ObjectType>
inline void AutoDeltaMap<KeyType, ValueType, ObjectType>::unpackDelta(ReadIterator & source, std::vector<Command> & data)
{
Command c;
size_t commandCount, targetBaselineCommandCount;
int32_t commandCount, targetBaselineCommandCount;
Archive::get(source, commandCount);
Archive::get(source, targetBaselineCommandCount);
for (size_t i=0 ; i < commandCount; ++i)
for (int32_t i=0 ; i < commandCount; ++i)
{
Archive::get(source, c.cmd);
switch(c.cmd)
+11 -34
View File
@@ -23,8 +23,8 @@ namespace Archive
void get(ReadIterator & source, unsigned __int64 & target);
void put(ByteStream & target, const unsigned __int64 & source);
#else
void get(ReadIterator & source, unsigned long long int & target);
void put(ByteStream & target, const unsigned long long int & source);
void get(ReadIterator & source, uint64_t & target);
void put(ByteStream & target, const uint64_t & source);
#endif
/**
* An AutoDeltaPackedMap is an AutoDeltaMap that will be packed into
@@ -100,7 +100,7 @@ namespace Archive
typename AutoDeltaMap<KeyType, ValueType, ObjectType>::Command c;
Archive::put(target, countCharacter(buffer,':'));
Archive::put(target, static_cast<size_t>(0)); // baselineCommandCount
Archive::put(target, static_cast<uint32_t>(0)); // baselineCommandCount
int tempPos = 0;
for (std::string::const_iterator i=buffer.begin(); i!=buffer.end(); ++i)
@@ -127,8 +127,8 @@ namespace Archive
char temp[200];
typename AutoDeltaMap<KeyType, ValueType, ObjectType>::Command c;
size_t commandCount;
size_t baselineCommandCount;
int32_t commandCount;
int32_t baselineCommandCount;
Archive::get(source, commandCount);
Archive::get(source, baselineCommandCount);
@@ -139,7 +139,7 @@ namespace Archive
}
else
{
for (size_t i = 0; i < commandCount; ++i)
for (int32_t i = 0; i < commandCount; ++i)
{
Archive::get(source, c.cmd);
Archive::get(source, c.key);
@@ -193,37 +193,25 @@ namespace Archive
}
template<>
inline void AutoDeltaPackedMap<int, int>::pack(ByteStream & target, const std::string & buffer)
inline void AutoDeltaPackedMap<int, int32_t>::pack(ByteStream & target, const std::string & buffer)
{
internal_pack(target, buffer, "%i %i");
}
template<>
inline void AutoDeltaPackedMap<int, int>::unpack(ReadIterator & source, std::string & buffer)
inline void AutoDeltaPackedMap<int, int32_t>::unpack(ReadIterator & source, std::string & buffer)
{
internal_unpack(source, buffer, "%i %i:");
}
template<>
inline void AutoDeltaPackedMap<int, uint32_t>::pack(ByteStream & target, const std::string & buffer)
{
internal_pack(target, buffer, "%i %i");
}
template<>
inline void AutoDeltaPackedMap<int, uint32_t>::unpack(ReadIterator & source, std::string & buffer)
{
internal_unpack(source, buffer, "%i %i:");
}
template<>
inline void AutoDeltaPackedMap<int, unsigned long>::pack(ByteStream & target, const std::string & buffer)
{
internal_pack(target, buffer, "%i %u");
}
template<>
inline void AutoDeltaPackedMap<int, unsigned long>::unpack(ReadIterator & source, std::string & buffer)
inline void AutoDeltaPackedMap<int, uint32_t>::unpack(ReadIterator & source, std::string & buffer)
{
internal_unpack(source, buffer, "%i %u:");
}
@@ -254,24 +242,13 @@ namespace Archive
#else
template<>
inline void AutoDeltaPackedMap<unsigned long, uint32_t>::pack(ByteStream & target, const std::string & buffer)
inline void AutoDeltaPackedMap<uint32_t, uint32_t>::pack(ByteStream & target, const std::string & buffer)
{
internal_pack(target, buffer, "%lu %llu");
}
template<>
inline void AutoDeltaPackedMap<unsigned long, uint32_t>::unpack(ReadIterator & source, std::string & buffer)
{
internal_unpack(source, buffer, "%lu %llu:");
}
template<>
inline void AutoDeltaPackedMap<unsigned long, uint64_t>::pack(ByteStream & target, const std::string & buffer)
{
internal_pack(target, buffer, "%lu %llu");
}
template<>
inline void AutoDeltaPackedMap<unsigned long, uint64_t>::unpack(ReadIterator & source, std::string & buffer)
inline void AutoDeltaPackedMap<uint32_t, uint32_t>::unpack(ReadIterator & source, std::string & buffer)
{
internal_unpack(source, buffer, "%lu %llu:");
}
+9 -9
View File
@@ -46,7 +46,7 @@ public: // methods
const bool isDirty() const;
void pack(ByteStream &target) const;
void packDelta(ByteStream &target) const;
const size_t size() const;
const int32_t size() const;
void unpack(ReadIterator &source);
void unpackDelta(ReadIterator &source);
@@ -72,7 +72,7 @@ private: // members
};
QueueType container;
size_t baselineCommandCount;
uint32_t baselineCommandCount;
mutable std::vector<ModifyCommand> changes;
AutoDeltaQueue &operator=(AutoDeltaQueue const &);
@@ -251,7 +251,7 @@ template<typename ValueType>
inline void AutoDeltaQueue<ValueType>::pack(ByteStream &target) const
{
const_iterator i;
Archive::put(target, container.size());
Archive::put(target, static_cast<int32_t> (container.size()));
Archive::put(target, baselineCommandCount);
unsigned char cmd;
for (i = container.begin(); i != container.end(); ++i)
@@ -267,7 +267,7 @@ inline void AutoDeltaQueue<ValueType>::pack(ByteStream &target) const
template<typename ValueType>
inline void AutoDeltaQueue<ValueType>::packDelta(ByteStream &target) const
{
Archive::put(target, changes.size());
Archive::put(target, static_cast<int32_t> (changes.size()));
Archive::put(target, baselineCommandCount);
for (typename std::vector<ModifyCommand>::iterator i = changes.begin(); i != changes.end(); ++i)
{
@@ -293,7 +293,7 @@ inline void AutoDeltaQueue<ValueType>::packDelta(ByteStream &target) const
//-----------------------------------------------------------------------
template<typename ValueType>
inline const size_t AutoDeltaQueue<ValueType>::size() const
inline const int32_t AutoDeltaQueue<ValueType>::size() const
{
return container.size();
}
@@ -324,12 +324,12 @@ inline void AutoDeltaQueue<ValueType>::unpack(ReadIterator &source)
clearDelta();
ModifyCommand c;
size_t commandCount;
int32_t commandCount;
Archive::get(source, commandCount);
Archive::get(source, baselineCommandCount);
for (size_t i = 0; i < commandCount; ++i)
for (int32_t i = 0; i < commandCount; ++i)
{
Archive::get(source, c.cmd);
assert(c.cmd == ModifyCommand::PUSH); // only push valid for pack/unpack
@@ -345,7 +345,7 @@ inline void AutoDeltaQueue<ValueType>::unpackDelta(ReadIterator &source)
{
using Archive::get;
ModifyCommand c;
size_t skipCount, commandCount, targetBaselineCommandCount;
int32_t skipCount, commandCount, targetBaselineCommandCount;
Archive::get(source, commandCount);
Archive::get(source, targetBaselineCommandCount);
@@ -359,7 +359,7 @@ inline void AutoDeltaQueue<ValueType>::unpackDelta(ReadIterator &source)
if (skipCount > commandCount)
skipCount = commandCount;
size_t i;
int32_t i;
for (i = 0; i < skipCount; ++i)
{
Archive::get(source, c.cmd);
+15 -15
View File
@@ -57,7 +57,7 @@ public:
void packDelta(ByteStream &target) const;
SetType const & get() const;
const size_t size() const;
const int32_t size() const;
bool empty() const;
bool contains(ValueType const &t) const;
const_iterator find(ValueType const &t) const;
@@ -84,7 +84,7 @@ private:
private:
SetType m_set;
size_t m_baselineCommandCount;
uint32_t m_baselineCommandCount;
mutable std::vector<Command> m_commands;
std::pair<ObjectType *, void (ObjectType::*)()> *m_onChangedCallback;
std::pair<ObjectType *, void (ObjectType::*)(ValueType const &)> *m_onEraseCallback;
@@ -301,7 +301,7 @@ inline void AutoDeltaSet<ValueType, ObjectType>::onInsert(ValueType const &value
template<typename ValueType, typename ObjectType>
inline void AutoDeltaSet<ValueType, ObjectType>::pack(ByteStream &target) const
{
Archive::put(target, m_set.size());
Archive::put(target, static_cast<int32_t> (m_set.size()));
Archive::put(target, m_baselineCommandCount);
for (typename SetType::const_iterator i = m_set.begin(); i != m_set.end(); ++i)
put(target, *i);
@@ -312,8 +312,8 @@ inline void AutoDeltaSet<ValueType, ObjectType>::pack(ByteStream &target) const
template<typename ValueType, typename ObjectType>
inline void AutoDeltaSet<ValueType, ObjectType>::pack(ByteStream &target, std::set<ValueType> const &data)
{
Archive::put(target, data.size());
Archive::put(target, static_cast<size_t>(0)); // baselineCommandCount
Archive::put(target, static_cast<int32_t> (data.size()));
Archive::put(target, static_cast<int32_t> (0)); // baselineCommandCount
for (typename std::set<ValueType>::const_iterator i = data.begin(); i != data.end(); ++i)
put(target, *i);
}
@@ -323,7 +323,7 @@ inline void AutoDeltaSet<ValueType, ObjectType>::pack(ByteStream &target, std::s
template<typename ValueType, typename ObjectType>
inline void AutoDeltaSet<ValueType, ObjectType>::packDelta(ByteStream &target) const
{
Archive::put(target, m_commands.size());
Archive::put(target, static_cast<int32_t> (m_commands.size()));
Archive::put(target, m_baselineCommandCount);
for (typename std::vector<Command>::iterator i = m_commands.begin(); i != m_commands.end(); ++i)
{
@@ -402,7 +402,7 @@ inline bool AutoDeltaSet<ValueType, ObjectType>::empty() const
//-----------------------------------------------------------------------
template<typename ValueType, typename ObjectType>
inline const size_t AutoDeltaSet<ValueType, ObjectType>::size() const
inline const int32_t AutoDeltaSet<ValueType, ObjectType>::size() const
{
return m_set.size();
}
@@ -415,13 +415,13 @@ inline void AutoDeltaSet<ValueType, ObjectType>::unpack(ReadIterator &source)
m_set.clear();
clearDelta();
size_t commandCount;
int32_t commandCount;
ValueType value;
Archive::get(source, commandCount);
Archive::get(source, m_baselineCommandCount);
using Archive::get;
for (size_t i = 0; i < commandCount; ++i)
for (int32_t i = 0; i < commandCount; ++i)
{
get(source, value);
m_set.insert(value);
@@ -436,13 +436,13 @@ template<typename ValueType, typename ObjectType>
inline void AutoDeltaSet<ValueType, ObjectType>::unpack(ReadIterator &source, std::vector<Command> &data)
{
Command c;
size_t commandCount, targetBaselineCommandCount;
int32_t commandCount, targetBaselineCommandCount;
Archive::get(source, commandCount);
Archive::get(source, targetBaselineCommandCount);
c.cmd = Command::INSERT;
for (size_t i = 0; i < commandCount; ++i)
for (int32_t i = 0; i < commandCount; ++i)
{
Archive::get(source,c.value);
data.push_back(c);
@@ -455,12 +455,12 @@ template<typename ValueType, typename ObjectType>
inline void AutoDeltaSet<ValueType, ObjectType>::unpackDelta(ReadIterator &source, std::vector<Command> &data)
{
Command c;
size_t commandCount, targetBaselineCommandCount;
int32_t commandCount, targetBaselineCommandCount;
Archive::get(source, commandCount);
Archive::get(source, targetBaselineCommandCount);
for (size_t i = 0 ; i < commandCount; ++i)
for (int32_t i = 0 ; i < commandCount; ++i)
{
Archive::get(source, c.cmd);
switch (c.cmd)
@@ -486,7 +486,7 @@ inline void AutoDeltaSet<ValueType, ObjectType>::unpackDelta(ReadIterator &sourc
{
using Archive::get;
Command c;
size_t skipCount, commandCount, targetBaselineCommandCount;
int32_t skipCount, commandCount, targetBaselineCommandCount;
Archive::get(source, commandCount);
Archive::get(source, targetBaselineCommandCount);
@@ -503,7 +503,7 @@ inline void AutoDeltaSet<ValueType, ObjectType>::unpackDelta(ReadIterator &sourc
if (skipCount > commandCount)
skipCount = commandCount;
size_t i = 0;
int32_t i = 0;
for ( ; i < skipCount; ++i)
{
Archive::get(source, c.cmd);
+20 -20
View File
@@ -39,7 +39,7 @@ public:
public:
AutoDeltaVector();
explicit AutoDeltaVector(size_t initialSize);
explicit AutoDeltaVector(int32_t initialSize);
~AutoDeltaVector();
const ValueType & back () const;
@@ -74,7 +74,7 @@ public:
void setOnInsert (ObjectType * owner, void (ObjectType::*onInsert)(const unsigned int, const ValueType &));
void setOnSet (ObjectType * owner, void (ObjectType::*onSet)(const unsigned int, const ValueType &, const ValueType &));
const size_t size () const;
const int32_t size () const;
bool empty () const;
const ValueType & operator[] (const unsigned int element) const;
@@ -91,7 +91,7 @@ private:
private:
std::vector<ValueType> v;
size_t baselineCommandCount;
int32_t baselineCommandCount;
mutable std::vector<Command> commands;
std::pair<ObjectType *, void (ObjectType::*)()> * onChangedCallback;
std::pair<ObjectType *, void (ObjectType::*)(const unsigned int, const ValueType &)> * onEraseCallback;
@@ -120,7 +120,7 @@ onSetCallback(0)
//-----------------------------------------------------------------------
template<typename ValueType, typename ObjectType>
inline AutoDeltaVector<ValueType, ObjectType>::AutoDeltaVector(size_t initialSize) :
inline AutoDeltaVector<ValueType, ObjectType>::AutoDeltaVector(int32_t initialSize) :
AutoDeltaContainer(),
v(initialSize),
baselineCommandCount(0),
@@ -366,7 +366,7 @@ inline void AutoDeltaVector<ValueType, ObjectType>::onSet(const unsigned int ele
template<typename ValueType, typename ObjectType>
inline void AutoDeltaVector<ValueType, ObjectType>::pack(ByteStream & target) const
{
Archive::put(target, v.size());
Archive::put(target, static_cast<int32_t> (v.size()));
Archive::put(target, baselineCommandCount);
typename std::vector<ValueType>::const_iterator i;
for (i = v.begin(); i != v.end(); ++i)
@@ -380,8 +380,8 @@ inline void AutoDeltaVector<ValueType, ObjectType>::pack(ByteStream & target) co
template<typename ValueType, typename ObjectType>
inline void AutoDeltaVector<ValueType, ObjectType>::pack(ByteStream & target, const std::vector<ValueType> & data)
{
Archive::put(target, data.size());
Archive::put(target, static_cast<size_t>(0)); // baselineCommandCount
Archive::put(target, static_cast<int32_t>(data.size()));
Archive::put(target, static_cast<int32_t>(0)); // baselineCommandCount
typename std::vector<ValueType>::const_iterator i;
for (i = data.begin(); i != data.end(); ++i)
{
@@ -394,7 +394,7 @@ inline void AutoDeltaVector<ValueType, ObjectType>::pack(ByteStream & target, co
template<typename ValueType, typename ObjectType>
inline void AutoDeltaVector<ValueType, ObjectType>::packDelta(ByteStream & target) const
{
Archive::put(target, commands.size());
Archive::put(target, static_cast<int32_t>(commands.size()));
Archive::put(target, baselineCommandCount);
typename std::vector<Command>::iterator i;
@@ -483,13 +483,13 @@ inline void AutoDeltaVector<ValueType, ObjectType>::resize(size_type n, ValueTyp
{
// expand the vector
v.resize(n);
for (size_t i = size; i < n; ++i)
for (int32_t i = size; i < n; ++i)
set(i, x);
}
else if (size > n)
{
// contract the vector
for (size_t i = size - 1; i >= n; --i)
for (int32_t i = size - 1; i >= n; --i)
{
erase(i);
@@ -607,7 +607,7 @@ inline bool AutoDeltaVector<ValueType, ObjectType>::empty() const
//-----------------------------------------------------------------------
template<typename ValueType, typename ObjectType>
inline const size_t AutoDeltaVector<ValueType, ObjectType>::size() const
inline const int32_t AutoDeltaVector<ValueType, ObjectType>::size() const
{
return v.size();
}
@@ -622,13 +622,13 @@ inline void AutoDeltaVector<ValueType, ObjectType>::unpack(ReadIterator & source
v.clear();
clearDelta();
size_t commandCount;
int32_t commandCount;
ValueType value;
Archive::get(source, commandCount);
Archive::get(source, baselineCommandCount);
for (size_t i = 0; i < commandCount; ++i)
for (int32_t i = 0; i < commandCount; ++i)
{
get(source, value);
v.push_back(value);
@@ -644,14 +644,14 @@ inline void AutoDeltaVector<ValueType, ObjectType>::unpack(ReadIterator & source
{
using Archive::get;
// unpacking the whole kazaba
size_t commandCount;
size_t bcc;
int32_t commandCount;
int32_t bcc;
Command c;
Archive::get(source, commandCount);
Archive::get(source, bcc);
for (size_t i = 0; i < commandCount; ++i)
for (int32_t i = 0; i < commandCount; ++i)
{
get(source,c.value);
c.index = static_cast<unsigned short int>(i);
@@ -668,12 +668,12 @@ inline void AutoDeltaVector<ValueType, ObjectType>::unpackDelta(ReadIterator & s
{
using Archive::get;
Command c;
size_t commandCount, targetBaselineCommandCount;
int32_t commandCount, targetBaselineCommandCount;
Archive::get(source, commandCount);
Archive::get(source, targetBaselineCommandCount);
for (size_t i=0 ; i < commandCount; ++i)
for (int32_t i=0 ; i < commandCount; ++i)
{
Archive::get(source, c.cmd);
switch (c.cmd)
@@ -708,7 +708,7 @@ inline void AutoDeltaVector<ValueType, ObjectType>::unpackDelta(ReadIterator & s
{
using Archive::get;
Command c;
size_t skipCount, commandCount, targetBaselineCommandCount;
int32_t skipCount, commandCount, targetBaselineCommandCount;
Archive::get(source, commandCount);
Archive::get(source, targetBaselineCommandCount);
@@ -719,7 +719,7 @@ inline void AutoDeltaVector<ValueType, ObjectType>::unpackDelta(ReadIterator & s
if (skipCount > commandCount)
skipCount = commandCount;
size_t i;
int32_t i;
for (i = 0; i < skipCount; ++i)
{
Archive::get(source, c.cmd);
+35
View File
@@ -5,6 +5,16 @@
#include <cassert>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/prctl.h>
// ======================================================================
//static volatile int s_dataFreeListLocked;
@@ -233,6 +243,31 @@ void ByteStream::get(void *target, ReadIterator &readIterator, const unsigned lo
else
{
static const char * const desc = "Archive::ByteStream - read beyond end of buffer";
std::cout << "read position: " << readIterator.getReadPosition() << " target size: " << targetSize << " allocated size: " << allocatedSize << std::endl;
std::cout << "I'm being called from: " << program_invocation_name;
std::cout << "======> BUFFER: " << std::endl;
std::stringstream ss;
ss << std::hex << std::setfill('0');
for (int i = 0; i < allocatedSize; ++i)
{
ss << std::setw(2) << static_cast<unsigned>(data->buffer[i]);
}
std::cout << ss.str() << std::endl;
char pid_buf[30];
sprintf(pid_buf, "%d", getpid());
char name_buf[512];
name_buf[readlink("/proc/self/exe", name_buf, 511)]=0;
prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0);
int child_pid = fork();
if (!child_pid) {
dup2(2,1); // redirect output to stderr - edit: unnecessary?
execl("/usr/bin/gdb", "gdb", "--batch", "-n", "-ex", "thread", "-ex", "bt", name_buf, pid_buf, NULL);
abort(); /* If gdb failed to start */
} else {
waitpid(child_pid,NULL,0);
}
ReadException ex(desc);
throw (ex);
}
+2 -2
View File
@@ -39,7 +39,7 @@ m_textIndex (0)
//----------------------------------------------------------------------
StringId::StringId (const std::string & table, unsigned long textIndex) :
StringId::StringId (const std::string & table, uint32_t textIndex) :
m_table (table),
m_text (),
m_textIndex (textIndex)
@@ -238,7 +238,7 @@ void StringId::setText (const std::string & text)
//----------------------------------------------------------------------
void StringId::setTextIndex (unsigned long textIndex) const
void StringId::setTextIndex (uint32_t textIndex) const
{
m_textIndex = textIndex;
}
+5 -5
View File
@@ -39,12 +39,12 @@ public:
StringId ();
StringId (const std::string & table, const std::string & text);
StringId (const std::string & table, unsigned long textIndex);
StringId (const std::string & table, uint32_t textIndex);
explicit StringId (const std::string & canonicalRepresentation);
const std::string & getTable () const;
const std::string & getText () const;
unsigned long getTextIndex () const;
uint32_t getTextIndex () const;
bool isInvalid () const;
bool isValid () const;
@@ -60,7 +60,7 @@ public:
//-- text index is a mutable property of the StringId
//-- it is set the first time a StringId is localized, to speed up future lookups
void setTextIndex (unsigned long textIndex) const;
void setTextIndex (uint32_t textIndex) const;
bool localize (LocUnicodeString & result, bool forceEnglish = false) const;
LocUnicodeString localize (bool forceEnglish = false) const;
@@ -79,7 +79,7 @@ private:
std::string m_table;
std::string m_text;
mutable unsigned long m_textIndex; //if this number is nonzero, assume it is valid
mutable uint32_t m_textIndex; //if this number is nonzero, assume it is valid
};
//----------------------------------------------------------------------
@@ -98,7 +98,7 @@ inline const std::string & StringId::getText() const
//----------------------------------------------------------------------
inline unsigned long StringId::getTextIndex() const
inline uint32_t StringId::getTextIndex() const
{
return m_textIndex;
}
@@ -23,7 +23,7 @@ namespace Archive
*/
void get(ReadIterator & source, StringId & target)
{
unsigned long index = 0;
int32_t index = 0;
std::string table;
std::string name;
@@ -331,21 +331,21 @@ void SwgSnapshot::encodeScriptObject(const NetworkId &objectId, Archive::ByteStr
void
SwgSnapshot::decodeAttributes(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline, int offset) {
if (isBaseline) {
size_t size, baselineCommandCount;
int32_t size, baselineCommandCount;
Archive::get(data, size);
Archive::get(data, baselineCommandCount);
Attributes::Value temp;
for (size_t i = 0; i < size; ++i) {
for (int32_t i = 0; i < size; ++i) {
Archive::get(data, temp);
m_creatureObjectBuffer.setAttribute(objectId, i + offset, temp);
}
} else {
typedef Archive::AutoDeltaVector <Attributes::Value> VectorType;
size_t numCommands, baselineCommandCount;
int32_t numCommands, baselineCommandCount;
Archive::get(data, numCommands);
Archive::get(data, baselineCommandCount);
for (size_t count = 0; count < numCommands; ++count) {
for (int32_t count = 0; count < numCommands; ++count) {
unsigned char cmd;// datatype?
uint16 index;
@@ -386,8 +386,8 @@ void SwgSnapshot::encodeAttributes(const NetworkId &objectId, Archive::ByteStrea
std::vector <Attributes::Value> values;
m_creatureObjectBuffer.getAttributesForObject(objectId, values, offset, Attributes::NumberOfAttributes);
Archive::put(data, Attributes::NumberOfAttributes);
Archive::put(data, static_cast<size_t>(0)); // baselineCommandCount
Archive::put(data, static_cast<int32_t> (Attributes::NumberOfAttributes));
Archive::put(data, static_cast<int32_t>(0)); // baselineCommandCount
if (values.size() < static_cast<size_t>(Attributes::NumberOfAttributes)) {
DEBUG_REPORT_LOG(true, ("Object %s did not have valid attribute data in the database. Missing attributes will be set to 100.\n", objectId.getValueString().c_str()));
values.resize(Attributes::NumberOfAttributes, 100);
@@ -754,21 +754,21 @@ void SwgSnapshot::ignorePersistedFlag(const NetworkId &objectId, Archive::ReadIt
void
SwgSnapshot::decodeLocationDataList(const NetworkId &objectId, size_t listId, Archive::ReadIterator &data, bool isBaseline) {
if (isBaseline) {
size_t size, baselineCommandCount;
int32_t size, baselineCommandCount;
Archive::get(data, size);
Archive::get(data, baselineCommandCount);
LocationData temp;
for (size_t i = 0; i < size; ++i) {
for (int32_t i = 0; i < size; ++i) {
Archive::get(data, temp);
m_locationBuffer.set(objectId, listId, i, temp);
}
} else {
typedef Archive::AutoDeltaVector <LocationData> VectorType;
size_t numCommands, baselineCommandCount;
int32_t numCommands, baselineCommandCount;
Archive::get(data, numCommands);
Archive::get(data, baselineCommandCount);
for (size_t count = 0; count < numCommands; ++count) {
for (int32_t count = 0; count < numCommands; ++count) {
unsigned char cmd;
uint16 index;
@@ -813,8 +813,8 @@ void SwgSnapshot::encodeLocationDataList(const NetworkId &objectId, size_t listI
std::vector <LocationData> values;
m_locationBuffer.getLocationList(objectId, listId, values);
Archive::put(data, values.size());
Archive::put(data, static_cast<size_t>(0));
Archive::put(data, static_cast<int32_t> (values.size()));
Archive::put(data, static_cast<int32_t>(0));
for (std::vector<LocationData>::iterator i = values.begin(); i != values.end(); ++i) {
Archive::put(data, *i);
}
@@ -855,8 +855,8 @@ void SwgSnapshot::encodeExperience(const NetworkId &objectId, Archive::ByteStrea
ValuesType values;
m_experienceBuffer.getExperienceForObject(objectId, values);
Archive::put(data, values.size());
Archive::put(data, static_cast<size_t>(0)); // baselineCommandCount
Archive::put(data, static_cast<int32_t> (values.size()));
Archive::put(data, static_cast<int32_t> (0)); // baselineCommandCount
for (ValuesType::const_iterator i = values.begin(); i != values.end(); ++i) {
const unsigned char command = 0; //ADD
Archive::put(data, command);
@@ -901,8 +901,8 @@ void SwgSnapshot::encodeBattlefieldParticipants(const NetworkId &objectId, Archi
ValuesType values;
m_battlefieldParticipantBuffer.getParticipantsForRegion(objectId, values);
Archive::put(data, values.size());
Archive::put(data, static_cast<size_t>(0)); // baselineCommandCount
Archive::put(data, static_cast<int32_t> (values.size()));
Archive::put(data, static_cast<int32_t> (0)); // baselineCommandCount
for (ValuesType::const_iterator i = values.begin(); i != values.end(); ++i) {
const unsigned char command = 0; //ADD
Archive::put(data, command);
@@ -945,8 +945,8 @@ void SwgSnapshot::encodeManufactureSchematicAttributes(const NetworkId &objectId
ValuesType values;
m_manufactureSchematicAttributeBuffer.getDataForObject(objectId, values);
Archive::put(data, values.size());
Archive::put(data, static_cast<size_t>(0)); // baselineCommandCount
Archive::put(data, static_cast<int32_t> (values.size()));
Archive::put(data, static_cast<int32_t> (0)); // baselineCommandCount
for (ValuesType::const_iterator i = values.begin(); i != values.end(); ++i) {
const unsigned char command = 0; //ADD
Archive::put(data, command);
@@ -1087,8 +1087,8 @@ void SwgSnapshot::encodeWaypoints(const NetworkId &objectId, Archive::ByteStream
ValuesType values;
m_waypointBuffer.getWaypointsForObject(objectId, values);
Archive::put(data, values.size());
Archive::put(data, static_cast<size_t>(0)); // baselineCommandCount
Archive::put(data, static_cast<int32_t> (values.size()));
Archive::put(data, static_cast<int32_t> (0)); // baselineCommandCount
for (ValuesType::const_iterator i = values.begin(); i != values.end(); ++i) {
const unsigned char command = 0; //ADD
Archive::put(data, command);