Пример #1
0
//--------------------------------------------------------------------------
void EntityS::SyncToClient()
{
	if(m_pkAgent)
	{
		if(m_kSyncDirty.Size())
		{
			BitStream kStream;
			kStream.Reset();
			kStream << VeUInt8(ID_CLIENT_ENTITY_UPDATE);
			kStream << (const VeChar8*)m_kName;
			VE_ASSERT(m_kSyncDirty.Size() <= VE_UINT16_MAX);
			kStream << VeUInt16(m_kSyncDirty.Size());
			m_kSyncDirty.BeginIterator();
			while(!m_kSyncDirty.IsEnd())
			{
				PropertySValue* pkValue = m_kSyncDirty.GetIterNode()->m_tContent;
				m_kSyncDirty.Next();
				VE_ASSERT(pkValue);
				kStream << pkValue->GetField();
				VE_ASSERT(pkValue->GetSize() <= 0xff);
				kStream.WriteAlignedBytesSafe((const VeChar8*)pkValue->GetClientData(), pkValue->GetClientSize(), VE_UINT8_MAX);
			}
			m_kSyncDirty.Clear();
			m_pkAgent->SendPacket(kStream);
		}
	}
}
Пример #2
0
//--------------------------------------------------------------------------
void EntityS::SyncAllToClient()
{
	if(m_pkAgent)
	{
		BitStream kStream;
		kStream.Reset();
		kStream << VeUInt8(ID_CLIENT_ENTITY_UPDATE);
		kStream << (const VeChar8*)m_kName;
		VE_ASSERT(m_kSyncChildren.Size() <= VE_UINT16_MAX);
		kStream << VeUInt16(m_kSyncChildren.Size());
		for(VeUInt32 i(0); i < m_kSyncChildren.Size(); ++i)
		{
			PropertySValue* pkValue = m_kSyncChildren[i];
			kStream << pkValue->GetField();
			VE_ASSERT(pkValue->GetSize() <= 0xff);
			kStream.WriteAlignedBytesSafe((const VeChar8*)pkValue->GetClientData(), pkValue->GetClientSize(), VE_UINT8_MAX);
		}
		m_pkAgent->SendPacket(kStream);
	}
}
Пример #3
0
//--------------------------------------------------------------------------
void VePNGImage::From(VeBinaryIStream& kIn)
{
	png_structp pkPngPtr;
	png_infop pkInfoPtr;
	pkPngPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING,(void *)NULL,NULL,NULL);
	VE_ASSERT(pkPngPtr);
	pkInfoPtr = png_create_info_struct(pkPngPtr);
	VE_ASSERT(pkInfoPtr);
	VE_ASSERT_EQ(setjmp(png_jmpbuf(pkPngPtr)), VE_S_OK);
	png_set_read_fn(pkPngPtr, &kIn, VePngRead);
	png_read_png(pkPngPtr, pkInfoPtr, PNG_TRANSFORM_EXPAND, 0);
	m_u16Width = png_get_image_width(pkPngPtr, pkInfoPtr);
	m_u16Height = png_get_image_height(pkPngPtr, pkInfoPtr);
	VeByte byType = png_get_color_type(pkPngPtr, pkInfoPtr);
	VeByte byDepth = png_get_bit_depth(pkPngPtr, pkInfoPtr);
	VeByte byUnitSize(0), byPixelSize(0);
	VeRenderer::Format eFormat = VeRenderer::FMT_UNKNOWN;
	switch(byType)
	{
	case PNG_COLOR_TYPE_GRAY:
	case PNG_COLOR_TYPE_PALETTE:
		if(byDepth == 8)
		{
			eFormat = VeRenderer::FMT_R8_UNORM;
		}
		else if(byDepth == 16)
		{
			eFormat = VeRenderer::FMT_R16_UNORM;
		}
		byUnitSize = byDepth;
		byPixelSize = byDepth;
		break;
	case PNG_COLOR_TYPE_RGB:
		if(byDepth == 8)
		{
			eFormat = VeRenderer::FMT_R8G8B8A8_UNORM;
		}
		else if(byDepth == 16)
		{
			eFormat = VeRenderer::FMT_R16G16B16A16_UNORM;
		}
		byUnitSize = byDepth * 3;
		byPixelSize = byDepth * 4;
		break;
	case PNG_COLOR_TYPE_RGB_ALPHA:
		if(byDepth == 8)
		{
			eFormat = VeRenderer::FMT_R8G8B8A8_UNORM;
		}
		else if(byDepth == 16)
		{
			eFormat = VeRenderer::FMT_R16G16B16A16_UNORM;
		}
		byUnitSize = byDepth * 4;
		byPixelSize = byDepth * 4;
		break;
	case PNG_COLOR_TYPE_GRAY_ALPHA:
		if(byDepth == 8)
		{
			eFormat = VeRenderer::FMT_R8G8_UNORM;
		}
		else if(byDepth == 16)
		{
			eFormat = VeRenderer::FMT_R16G16_UNORM;
		}
		byUnitSize = byDepth * 2;
		byPixelSize = byDepth * 2;
		break;
	}
	VE_ASSERT(eFormat != VeRenderer::FMT_UNKNOWN);
	byPixelSize >>= 3;
	byUnitSize >>= 3;
	png_bytep* row_pointers = png_get_rows(pkPngPtr, pkInfoPtr);
	m_kStream.Reset();
	m_kStream << m_u16Width;
	m_kStream << m_u16Height;
	m_kStream << VeUInt16(1);
	m_kStream << VeUInt16(1);
	m_kStream << VeUInt8(eFormat);
	m_kStream << VeUInt8(1);
	m_kStream << VeUInt8(0);
	m_kStream << VeUInt8(VeRenderer::USAGE_DEFAULT);
	m_kStream << VeUInt8(VeRenderer::BIND_SHADER_RESOURCE);
	m_kStream << VeUInt8(0);
	m_kStream << VeUInt16(0);
	m_kStream << VeUInt16(1);
	m_kStream << VeUInt16(1);
	VeUInt32 u32PixelPitch = byPixelSize * m_u16Width;
	VeUInt32 u32PixelByteWidth = u32PixelPitch * m_u16Height;
	m_kStream << u32PixelPitch;
	m_kStream << u32PixelByteWidth;
	m_kStream << u32PixelByteWidth;
	if(byUnitSize == byPixelSize)
	{
		for(VeUInt32 i(0); i < m_u16Height; ++i)
		{
			m_kStream.Write(row_pointers[i], u32PixelPitch);
		}
	}
	else
	{
		for(VeUInt32 i(0); i < m_u16Height; ++i)
		{
			for(VeUInt32 j(0); j < m_u16Width; ++j)
			{
				m_kStream.Write(row_pointers[i] + (j * byUnitSize), byUnitSize);
				for(VeInt32 k(0); k < (byPixelSize - byUnitSize); ++k)
				{
					m_kStream << VeUInt8(0xff);
				}
			}
		}
	}
	png_destroy_read_struct(&pkPngPtr, &pkInfoPtr, NULL);
}