This will throw a GotSplitPacketException when a full
split packet is constructed.
*/
-void IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
+SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
{
u32 headersize = BASE_HEADER_SIZE + 7;
assert(p.data.getSize() >= headersize);
// Set chunk data in buffer
sp->chunks[chunk_num] = chunkdata;
- // If not all chunks are received, return
+ // If not all chunks are received, return empty buffer
if(sp->allReceived() == false)
- return;
+ return SharedBuffer<u8>();
// Calculate total size
u32 totalsize = 0;
// Remove sp from buffer
m_buf.remove(seqnum);
delete sp;
-
- throw GotSplitPacketException(fulldata);
+
+ return fulldata;
}
void IncomingSplitBuffer::removeUnreliableTimedOuts(float dtime, float timeout)
{
con->GetProtocolID(),
peer_id,
channelnum);
- try{
- // Buffer the packet
- incoming_splits.insert(packet, reliable);
- }
- // This exception happens when all the pieces of a packet
- // are collected.
- catch(GotSplitPacketException &e)
+ // Buffer the packet
+ SharedBuffer<u8> data = incoming_splits.insert(packet, reliable);
+ if(data.getSize() != 0)
{
con->PrintInfo();
dout_con<<"RETURNING TYPE_SPLIT: Constructed full data, "
- <<"size="<<e.getData().getSize()<<std::endl;
- return e.getData();
+ <<"size="<<data.getSize()<<std::endl;
+ return data;
}
con->PrintInfo();
- dout_con<<"BUFFERING TYPE_SPLIT"<<std::endl;
+ dout_con<<"BUFFERED TYPE_SPLIT"<<std::endl;
throw ProcessedSilentlyException("Buffered a split packet chunk");
}
else if(type == TYPE_RELIABLE)
{}
};
-class GotSplitPacketException
-{
- SharedBuffer<u8> m_data;
-public:
- GotSplitPacketException(SharedBuffer<u8> data):
- m_data(data)
- {}
- SharedBuffer<u8> getData()
- {
- return m_data;
- }
-};
-
inline u16 readPeerId(u8 *packetdata)
{
return readU16(&packetdata[4]);
public:
~IncomingSplitBuffer();
/*
- This will throw a GotSplitPacketException when a full
- split packet is constructed.
+ Returns a reference counted buffer of length != 0 when a full split
+ packet is constructed. If not, returns one of length 0.
*/
- void insert(BufferedPacket &p, bool reliable);
+ SharedBuffer<u8> insert(BufferedPacket &p, bool reliable);
void removeUnreliableTimedOuts(float dtime, float timeout);
SUGG: Background music based on cellular automata?\r
http://www.earslap.com/projectslab/otomata\r
\r
+SUGG: Simple light color information to air\r
+\r
Gaming ideas:\r
-------------\r
\r
Networking and serialization:\r
-----------------------------\r
\r
-TODO: Get rid of GotSplitPacketException\r
-\r
User Interface:\r
---------------\r
\r
\r
TODO: Better control of draw_control.wanted_max_blocks\r
\r
-TODO: Get player texture (and some others) from the specified texture\r
- directory\r
-\r
-SUGG: Simple light color information to air\r
-\r
TODO: Block mesh generator to tile properly on smooth lighting\r
\r
Configuration:\r
class SharedBuffer
{
public:
+ SharedBuffer()
+ {
+ m_size = 0;
+ data = NULL;
+ refcount = new unsigned int;
+ (*refcount) = 1;
+ }
SharedBuffer(unsigned int size)
{
m_size = size;
- data = new T[size];
+ if(m_size != 0)
+ data = new T[m_size];
+ else
+ data = NULL;
refcount = new unsigned int;
(*refcount) = 1;
}
SharedBuffer(T *t, unsigned int size)
{
m_size = size;
- data = new T[size];
- memcpy(data, t, size);
+ if(m_size != 0)
+ {
+ data = new T[m_size];
+ memcpy(data, t, m_size);
+ }
+ else
+ data = NULL;
refcount = new unsigned int;
(*refcount) = 1;
}
*/
SharedBuffer(const Buffer<T> &buffer)
{
- m_size = buffer.m_size;
- data = new T[buffer.getSize()];
- memcpy(data, *buffer, buffer.getSize());
+ m_size = buffer.getSize();
+ if(m_size != 0)
+ {
+ data = new T[m_size];
+ memcpy(data, *buffer, buffer.getSize());
+ }
+ else
+ data = NULL;
refcount = new unsigned int;
(*refcount) = 1;
}
}
T & operator[](unsigned int i) const
{
+ //assert(i < m_size)
return data[i];
}
T * operator*() const
(*refcount)--;
if(*refcount == 0)
{
- delete[] data;
+ if(data)
+ delete[] data;
delete refcount;
}
}