本文整理汇总了C++中DataBuffer::copy方法的典型用法代码示例。如果您正苦于以下问题:C++ DataBuffer::copy方法的具体用法?C++ DataBuffer::copy怎么用?C++ DataBuffer::copy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataBuffer
的用法示例。
在下文中一共展示了DataBuffer::copy方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sendDatagram
int UDPManager::sendDatagram(DataBuffer * data, unsigned long ipAddress, unsigned long port, unsigned long frameCount) {
if (initErrors || data == NULL || port == 0) return -1;
sockaddr_in otherAddress;
otherAddress.sin_family = AF_INET;
otherAddress.sin_addr.s_addr = ipAddress;
otherAddress.sin_port = port;
int packetSize = data->getSize();
DataBuffer * sendBuffer = new DataBuffer(packetSize + 4);
//sendBuffer->copy(0, &packetSize, sizeof(int));
sendBuffer->copy(0, &frameCount, 4);
sendBuffer->copy(4, data->getData(), data->getSize());
if (sendto(sock, sendBuffer->getData(), sendBuffer->getSize(), 0, (struct sockaddr *)&otherAddress, sizeof(otherAddress)) < 0) {
perror("UDP sendto() failed\n");
delete sendBuffer;
return -1;
}
//printf("UDP Send:");
//Utilities::printfNetworkPacket(sendBuffer->getData(), sendBuffer->getSize());
delete sendBuffer;
return 0;
}
示例2: DataBuffer
DataBuffer * NetworkFunctions::createClearObjectsBuffer()
{
DataBuffer * tempBuffer = new DataBuffer(5);
int functionID = EVENT_CLEAR_OBJECTS;
tempBuffer->copy(0, &functionID, 4);
tempBuffer->copy(4, "\n", 1);
return tempBuffer;
}
示例3:
DataBuffer * NetworkFunctions::createUpdateObjectBuffer(unsigned long netID)
{
GameObject * tempObject = gameObjects->getValue(netID);
if (tempObject == NULL) return NULL;
DataBuffer * tempBuffer = tempObject->serialize();
int functionIndex = EVENT_UPDATE_GAME_OBJECT;
tempBuffer->copy(0, &functionIndex, 4);
tempBuffer->copy(4, &netID, 4);
return tempBuffer;
}
示例4: DataBuffer
DataBuffer * Spell::createDamageBuffer(int playerID, int targetID, int damage, int spellID)
{
if (spellID < 0 || spellID >= SPELLID_COUNT) return NULL;
DataBuffer * tempBuffer = new DataBuffer(21);
int functionIndex = EVENT_DAMAGE;
tempBuffer->copy(0, &functionIndex, 4);
tempBuffer->copy(4, &playerID, 4);
tempBuffer->copy(8, &targetID, 4);
tempBuffer->copy(12, &damage, 4);
tempBuffer->copy(16, &spellID, 4);
tempBuffer->copy(20, "\n", 1);
return tempBuffer;
}
示例5:
DataBuffer * Spell::createCentralForceBuffer(GameObject * g, glm::vec3 force, int spellID)
{
if (spellID < 0 || spellID >= SPELLID_COUNT) return NULL;
if (g == NULL) return NULL;
DataBuffer * tempBuffer = g->createSpellCentralForceBuffer(force, spellID);
tempBuffer->copy(8, &ownerID, 4);
return tempBuffer;
}
示例6: DataBuffer
DataBuffer * RigidObject::serialize()
{
if (!physInit) return NULL;
btVector3 pos = body->getCenterOfMassPosition();
btVector3 linVel = body->getLinearVelocity();
btQuaternion orient = body->getOrientation();
btVector3 angVel = body->getAngularVelocity();
DataBuffer * tempBuffer = new DataBuffer(getSerializedSize());
float test = 1.0f;
memcpy(&test, &pos.x(), 4);
int uninit = -1;
tempBuffer->copy(0, &uninit, 4); //function ID
unsigned long netID = getNetID();
tempBuffer->copy(4, &netID, 4);
tempBuffer->copy(8, &pos.x(), 4);
tempBuffer->copy(12, &pos.y(), 4);
tempBuffer->copy(16, &pos.z(), 4);
tempBuffer->copy(20, &linVel.x(), 4);
tempBuffer->copy(24, &linVel.y(), 4);
tempBuffer->copy(28, &linVel.z(), 4);
tempBuffer->copy(32, &orient.x(), 4);
tempBuffer->copy(36, &orient.y(), 4);
tempBuffer->copy(40, &orient.z(), 4);
tempBuffer->copy(44, &orient.w(), 4);
tempBuffer->copy(48, &angVel.x(), 4);
tempBuffer->copy(52, &angVel.y(), 4);
tempBuffer->copy(56, &angVel.z(), 4);
tempBuffer->copy(60, "\n", 1);
return tempBuffer;
}
示例7: DataBuffer
DataBuffer * Fireball::createCreateFireballBuffer()
{
if (owner == NULL) return NULL;
DataBuffer * tempBuffer = new DataBuffer(33);
int functionIndex = EVENT_CREATE_FIREBALL;
tempBuffer->copy(0, &functionIndex, 4);
tempBuffer->copy(4, &ownerID, 4);
tempBuffer->copy(8, &position.x, 4);
tempBuffer->copy(12, &position.y, 4);
tempBuffer->copy(16, &position.z, 4);
tempBuffer->copy(20, &direction.x, 4);
tempBuffer->copy(24, &direction.y, 4);
tempBuffer->copy(28, &direction.z, 4);
tempBuffer->copy(32, "\n", 1);
return tempBuffer;
}
示例8: translateReceivedEvents
int NetworkFunctions::translateReceivedEvents(Packet * serverEvents)
{
while (serverEvents->getReceiveBufferSize() > 0) {
DataBuffer * tempBuffer = new DataBuffer(MAX_PACKET_SIZE);
int charCount = 0;
int functionIndex = -1;
int bufferLength = -1;
for (int i = 0; i < serverEvents->getReceiveBufferSize(); i++) {
tempBuffer->copy(tempBuffer->getSize(), serverEvents->getReceiveBuffer() + i, 1);
if (charCount == 3) {
memcpy(&functionIndex, tempBuffer->getData(), 4);
if (functionIndex < 0 || functionIndex >= FUNCTION_COUNT || functionIndex == 10) {
while ((serverEvents->getReceiveBuffer()[i]) != '\n') i++;
tempBuffer->clear();
continue;
}
else {
bufferLength = bufferSizes[functionIndex];
}
}
if (charCount == 7 && functionIndex == EVENT_UPDATE_GAME_OBJECT) {
unsigned long netID = 0;
memcpy(&netID, tempBuffer->getData() + 4, 4);
GameObject * tempObject = gameObjects->getValue(netID);
if (tempObject == NULL) {
while ((serverEvents->getReceiveBuffer()[i]) != '\n') i++;
tempBuffer->clear();
continue;
}
/*int objectIndex = -1;
memcpy(&objectIndex, tempBuffer->getData() + 4, 4);
if (objectIndex < 0 || objectIndex >= gameObjects->size()) {
while ((serverEvents->getReceiveBuffer()[i]) != '\n') i++;
tempBuffer->clear();
continue;
}*/
else {
bufferLength = tempObject->getSerializedSize();
}
}
if (charCount == bufferLength-1) {
if (tempBuffer->getSize() == 0) {
tempBuffer->clear();
continue;
}
executeIndexedFunction(tempBuffer);
tempBuffer->clear();
charCount = 0;
continue;
}
/*if (serverEvents->getReceiveBuffer()[i] == '\n') {
if (tempBuffer->getSize() == 0) {
tempBuffer->clear();
continue;
}
executeIndexedFunction(tempBuffer);
tempBuffer->clear();
}*/
charCount++;
}
delete tempBuffer;
serverEvents->refillReceiveBuffer();
}
return 0;
}