1
Network / Re: Send sf::Texture using sf::Packet
« on: April 13, 2015, 10:07:40 am »
Thank you for the answers. I managed to solve the problem by changing the code to the following:
Somehow removing the "put the Uint8* in a vector" part made it work the way I wanted it to work... even though I don't understand why, because before removing it, the loop to put all sf::Uint8s in the packet took as long as the conversion.
In my case the server side DOES require a texture because it is like another part of the game. Like a GM in classic P&P Games/Tabletop games (basically the player who is running the server is also able to play at the same time and just has more "possibilities")
sf::Packet& operator << (sf::Packet& packet, Tileset& tileset)
{
size_t sizeX, sizeY;
sizeX = tileset.getSpriteTexture().getSize().x;
sizeY = tileset.getSpriteTexture().getSize().y;
int size = sizeX * sizeY * 4;
packet << tileset.tileSize;
packet << sizeX << sizeY;
sf::Image tmpImg = tileset.getSprite()->getTexture()->copyToImage();
const sf::Uint8* tmpUint = tmpImg.getPixelsPtr();
for (int i = 0; i < size; ++i)
{
packet << tmpUint[i];
}
return packet;
}
{
size_t sizeX, sizeY;
sizeX = tileset.getSpriteTexture().getSize().x;
sizeY = tileset.getSpriteTexture().getSize().y;
int size = sizeX * sizeY * 4;
packet << tileset.tileSize;
packet << sizeX << sizeY;
sf::Image tmpImg = tileset.getSprite()->getTexture()->copyToImage();
const sf::Uint8* tmpUint = tmpImg.getPixelsPtr();
for (int i = 0; i < size; ++i)
{
packet << tmpUint[i];
}
return packet;
}
Somehow removing the "put the Uint8* in a vector" part made it work the way I wanted it to work... even though I don't understand why, because before removing it, the loop to put all sf::Uint8s in the packet took as long as the conversion.
In my case the server side DOES require a texture because it is like another part of the game. Like a GM in classic P&P Games/Tabletop games (basically the player who is running the server is also able to play at the same time and just has more "possibilities")