예제 #1
0
inline void TrivialReplication::internal_transact_log_reserve(size_t n, char** new_begin, char** new_end)
{
    char* data = m_transact_log_buffer.data();
    size_t size = write_position() - data;
    m_transact_log_buffer.reserve_extra(size, n);
    data = m_transact_log_buffer.data(); // May have changed
    *new_begin = data + size;
    *new_end = data + m_transact_log_buffer.size();
}
예제 #2
0
	int Write(lua_State* L)
	{
		//takes a pts data table, returns a .eqg directory entry table
		Util::PrepareWrite(L, ".pts");

		//write .pts data
		Header header;
		header.magic[0] = 'E';
		header.magic[1] = 'Q';
		header.magic[2] = 'P';
		header.magic[3] = 'T';
		header.version = 1;
		header.data_count = lua_objlen(L, 1);

		Util::Buffer buf;
		buf.Add(&header, Header::SIZE);

		for (uint32 i = 1; i <= header.data_count; ++i)
		{
			lua_pushinteger(L, i);
			lua_gettable(L, 1);

			Data d;
			snprintf(d.particle_name, 64, "%s", Util::GetString(L, -1, "particle_name"));
			snprintf(d.attach_name, 64, "%s", Util::GetString(L, -1, "attach_name"));

			lua_getfield(L, -1, "translation");
			d.translation[0] = Util::GetFloat(L, -1, "z");
			d.translation[1] = Util::GetFloat(L, -1, "y");
			d.translation[2] = Util::GetFloat(L, -1, "x");
			lua_pop(L, 1);

			lua_getfield(L, -1, "rotation");
			d.rotation[0] = Util::GetFloat(L, -1, "z");
			d.rotation[1] = Util::GetFloat(L, -1, "y");
			d.rotation[2] = Util::GetFloat(L, -1, "x");
			lua_pop(L, 1);

			lua_getfield(L, -1, "scale");
			d.scale[0] = Util::GetFloat(L, -1, "z");
			d.scale[1] = Util::GetFloat(L, -1, "y");
			d.scale[2] = Util::GetFloat(L, -1, "x");
			lua_pop(L, 1);

			buf.Add(&d, Data::SIZE);

			lua_pop(L, 1);
		}

		return Util::FinishWrite(L, buf);
	}
예제 #3
0
파일: connector.cpp 프로젝트: Gingar/port
void Connector::assembleMessage( const util::Buffer &b ) {
	int offset  = 0;
	int msgSize, need;
	int rcvLen=b.length();

	while (offset < rcvLen) {
		int sLen=_msg.length();
		
		//	How many bytes need for complete message?
		if (sLen > MESSAGE_HEADER) {
			//	Stored bytes already have header
			msgSize = MSG_SIZE(_msg.buffer());
			need    = msgSize - sLen;
		}
		else if (MESSAGE_HEADER-sLen <= (rcvLen-offset)) {
			//	Stored bytes don't have the header, but with bytes received complete header!
			_msg.append( b.buffer()+offset, MESSAGE_HEADER-sLen );
			offset += MESSAGE_HEADER-sLen;
			sLen    = MESSAGE_HEADER;
			msgSize = MSG_SIZE(_msg.buffer());
			need    = msgSize-MESSAGE_HEADER;
		}
		else {
			//	Can't complete the header
			_msg.append( b.buffer()+offset, rcvLen-offset );
			offset = rcvLen;
			continue;
		}

		assert( need >= 0 );

		//	Copy bytes
		int rest = (rcvLen-offset);
		int copy = (rest > need) ? need : rest;

		// printf( "[Connector (%p)] rcvLen=%d, sLen=%d, msgSize=%d, need=%d, rest=%d, copy=%d\n",
		// 	this, rcvLen, sLen, msgSize, need, rest, copy );
		
		_msg.append( b.buffer()+offset, copy );
		offset += copy;

		// printf( "[Connector (%p)] msgLen=%d\n", this, _msg.length() );

		//	Is message complete?
		if (msgSize == _msg.length()) {
			messageReceived(&_msg);
			_msg.resize(0);
		}
	}
}
예제 #4
0
	int Write(lua_State* L)
	{
		//takes a prt data table, returns a .eqg directory entry table
		Util::PrepareWrite(L, ".prt");

		Header header;
		header.magic[0] = 'P';
		header.magic[1] = 'T';
		header.magic[2] = 'C';
		header.magic[3] = 'L';
		header.version = 4;
		header.particle_count = lua_objlen(L, 1);

		Util::Buffer buf;
		buf.Add(&header, sizeof(Header));

		for (uint32 i = 1; i <= header.particle_count; ++i)
		{
			lua_pushinteger(L, i);
			lua_gettable(L, 1);

			DataV4 d;
			d.particle_id = Util::GetInt(L, -1, "particle_id");
			snprintf(d.particle_name, 64, "%s", Util::GetString(L, -1, "particle_name"));
			d.duration = Util::GetInt(L, -1, "duration");

			lua_getfield(L, -1, "unknown");
			for (int j = 1; j <= 5; ++j)
			{
				d.unknownA[j - 1] = Util::GetInt(L, -2, j);
			}
			d.unknownB = Util::GetInt(L, -2, 6);
			lua_pushinteger(L, 7);
			lua_gettable(L, -2);
			double u = lua_tonumber(L, -1);
			uint32 a = static_cast<uint32>(u);
			d.unknownFFFFFFFF = 0;
			d.unknownFFFFFFFF |= a;
			lua_pop(L, 1);
			d.unknownC = Util::GetInt(L, -2, 8);
			lua_pop(L, 1);

			buf.Add(&d, sizeof(DataV4));

			lua_pop(L, 1);
		}

		return Util::FinishWrite(L, buf);
	}
예제 #5
0
inline size_t TrivialReplication::transact_log_size()
{
    return write_position() - m_transact_log_buffer.data();
}
예제 #6
0
inline BinaryData TrivialReplication::get_uncommitted_changes() const noexcept
{
    const char* data = m_transact_log_buffer.data();
    size_t size = write_position() - data;
    return BinaryData(data, size);
}
예제 #7
0
void parseDescriptors( const util::Buffer &info, desc::MapOfDescriptors &descriptors ) {
	SIZE_T len = info.length();
	BYTE *data = (BYTE *)info.buffer();
	SSIZE_T offset = 0;

	while (offset < len) {
		BYTE dTag = RB(data,offset);
		BYTE dLen = RB(data,offset);
		SSIZE_T parsed = offset;

		printf( "[dsmcc::module] Parse tag descriptor: tag=%x, len=%d\n", dTag, dLen );

		switch (dTag) {
			case MODULE_DESC_TYPE:	//	Type descriptor
			{
				std::string type( (char *)(data+parsed), dLen );
				descriptors[dTag] = type;
				parsed += dLen;
				break;
			}
			case MODULE_DESC_NAME:	//	Name descriptor
			{
				std::string name( (char *)(data+parsed), dLen );
				descriptors[dTag] = name;
				parsed += dLen;
				break;
			}
			case MODULE_DESC_INFO:	//	Info descriptor
			{
				module::InfoDescriptor desc;
				desc.language = std::string( (char *)(data+parsed), 3 );
				desc.text     = std::string( (char *)(data+parsed+3), dLen-3 );
				descriptors[dTag] = desc;
				parsed += dLen;
				break;
			}
			case MODULE_DESC_LINK:	//	Module link descriptor
			{
				module::LinkDescriptor desc;
				desc.position = RB(data,parsed);
				desc.moduleID = RW(data,parsed);
				descriptors[dTag] = desc;
				break;
			}
			case MODULE_DESC_CRC32:	//	CRC32 descriptor
			{
				DWORD crc = RDW(data,parsed);
				descriptors[dTag] = crc;				
				break;
			}
			case MODULE_DESC_LOCATION:	//	Location descriptor
			{
				BYTE location = RB(data,parsed);
				descriptors[dTag] = location;				
				break;
			}
			case MODULE_DESC_EST_DOWNLOAD:	//	Estimated download time descriptor
			{
				DWORD est = RDW(data,parsed);
				descriptors[dTag] = est;				
				break;
			}
			case MODULE_DESC_COMPRESSION:	//	Compression type descriptor
			case MODULE_DESC_COMPRESSED:
			{
				module::CompressionTypeDescriptor desc;
				desc.type = RB(data,parsed);
				desc.originalSize = RDW(data,parsed);
				descriptors[dTag] = desc;								
				break;
			}
		};

		offset += dLen;
		if (offset != parsed) {
			printf( "[dsmcc::module] Descriptor not parsed or parsed was incomplete: dTag=%x, len=%d, parsed=%ld\n",
				dTag, dLen, parsed );
		}		
	}

	//printf( "[dsmcc::module] Descriptors parsed: %d\n", descriptors.size() );
}