void QuaternionProperty16::serialize(BufferPointer buffer) { buffer->writeInt((short)(value.q[0] * 32767), 16); buffer->writeInt((short)(value.q[1] * 32767), 16); buffer->writeInt((short)(value.q[2] * 32767), 16); buffer->writeInt((short)(value.q[3] * 32767), 16); }
void QuaternionProperty::serialize(BufferPointer buffer) { buffer->writeFloat(value.q[0]); buffer->writeFloat(value.q[1]); buffer->writeFloat(value.q[2]); buffer->writeFloat(value.q[3]); }
void Entity::getUpdate(int time, BufferPointer buffer, int client) { bool local = client == getOwner(); for (unsigned int i = 0; i < properties.size(); i++) { if (local && ((properties[i].getFlags() & EPF_OwnerUpdates) == 0)) { // Potential update ignored because of property flags. buffer->writeUnsignedInt(0, 1); continue; } if (properties[i].getChangeTime() > time) { // Bit set: Property changed. buffer->writeUnsignedInt(1, 1); // Write the property to the stream. properties[i].write(buffer); } else { // Bit not set: Property remained unchanged. buffer->writeUnsignedInt(0, 1); } } }
void ClientWorldComponent::setReady() { if (!connection) return; // Send ready signal BufferPointer msg = new Buffer(); msg->write8(EPT_Ready); connection->send(msg, true); }
void QuaternionProperty::deserialize(BufferPointer buffer) { Quaternion newvalue; newvalue.q[0] = buffer->readFloat(); newvalue.q[1] = buffer->readFloat(); newvalue.q[2] = buffer->readFloat(); newvalue.q[3] = buffer->readFloat(); if (newvalue == value) return; value = newvalue; setChanged(); }
void QuaternionProperty16::deserialize(BufferPointer buffer) { Quaternion newvalue; newvalue.q[0] = (float)buffer->readInt(16) / 32767; newvalue.q[1] = (float)buffer->readInt(16) / 32767; newvalue.q[2] = (float)buffer->readInt(16) / 32767; newvalue.q[3] = (float)buffer->readInt(16) / 32767; if (newvalue == value) return; value = newvalue; setChanged(); }
void Entity::setState(BufferPointer buffer) { if (buffer.isNull()) return; for (unsigned int i = 0; i < properties.size(); i++) { int changed = buffer->readUnsignedInt(1); if (changed) { properties[i].read(buffer); } } }
void GLBackend::do_setUniformBuffer(Batch& batch, size_t paramOffset) { GLuint slot = batch._params[paramOffset + 3]._uint; BufferPointer uniformBuffer = batch._buffers.get(batch._params[paramOffset + 2]._uint); GLintptr rangeStart = batch._params[paramOffset + 1]._uint; GLsizeiptr rangeSize = batch._params[paramOffset + 0]._uint; #if (GPU_FEATURE_PROFILE == GPU_CORE) if (!uniformBuffer) { releaseUniformBuffer(slot); return; } // check cache before thinking if (_uniform._buffers[slot] == uniformBuffer) { return; } // Sync BufferObject auto* object = GLBackend::syncGPUObject(*uniformBuffer); if (object) { glBindBufferRange(GL_UNIFORM_BUFFER, slot, object->_buffer, rangeStart, rangeSize); _uniform._buffers[slot] = uniformBuffer; (void) CHECK_GL_ERROR(); } else { releaseResourceTexture(slot); return; } #else // because we rely on the program uniform mechanism we need to have // the program bound, thank you MacOSX Legacy profile. updatePipeline(); GLfloat* data = (GLfloat*) (uniformBuffer->getData() + rangeStart); glUniform4fv(slot, rangeSize / sizeof(GLfloat[4]), data); // NOT working so we ll stick to the uniform float array until we move to core profile // GLuint bo = getBufferID(*uniformBuffer); //glUniformBufferEXT(_shader._program, slot, bo); (void) CHECK_GL_ERROR(); #endif }
void Entity::getState(BufferPointer buffer) { const std::vector<Property> &tplproperties = tpl->getProperties(); for (unsigned int i = 0; i < properties.size(); i++) { if (properties[i] != tplproperties[i]) { // Bit set: Property changed. buffer->writeUnsignedInt(1, 1); // Write the property to the stream. properties[i].write(buffer); } else { // Bit not set: Property remained unchanged. buffer->writeUnsignedInt(0, 1); } } }
void GLBackend::do_setUniformBuffer(Batch& batch, uint32 paramOffset) { GLuint slot = batch._params[paramOffset + 3]._uint; BufferPointer uniformBuffer = batch._buffers.get(batch._params[paramOffset + 2]._uint); GLintptr rangeStart = batch._params[paramOffset + 1]._uint; GLsizeiptr rangeSize = batch._params[paramOffset + 0]._uint; #if (GPU_FEATURE_PROFILE == GPU_CORE) GLuint bo = getBufferID(*uniformBuffer); glBindBufferRange(GL_UNIFORM_BUFFER, slot, bo, rangeStart, rangeSize); #else GLfloat* data = (GLfloat*) (uniformBuffer->getData() + rangeStart); glUniform4fv(slot, rangeSize / sizeof(GLfloat[4]), data); // NOT working so we ll stick to the uniform float array until we move to core profile // GLuint bo = getBufferID(*uniformBuffer); //glUniformBufferEXT(_shader._program, slot, bo); #endif (void) CHECK_GL_ERROR(); }
void Entity::applyUpdate(BufferPointer buffer) { for (unsigned int i = 0; i < properties.size(); i++) { int changed = buffer->readUnsignedInt(1); if (changed && (properties[i].getFlags() & EPF_Unlocked)) { properties[i].read(buffer); } } }
bool RunlineEncoder:: neighborFieldContinuityOK(const VoxelizedPartition & vp, const Vector3i & newHalfCell, const Paint* newPaint) const { if (mFieldContinuity == kNeighborFieldNone) return 1; BufferPointer neighbor; for (int side = 0; side < 6; side++) if (mUsedNeighborFields[side]) { if (newPaint->curlBuffer(side) != mFirstPaint->curlBuffer(side)) return 0; neighbor = vp.lattice().wrappedPointer(newHalfCell+cardinal(side)); if (newPaint->curlBuffer(side) != mFirstPaint->curlBuffer(side)) return 0; if (mFirstNeighborFields[side].offset() + mLength != neighbor.offset()) return 0; } return 1; }
bool ClientWorldComponent::init(std::string address, unsigned int port, unsigned int timeout) { // Create connection client = new NetworkClient(); if(!client->init()) { delete client; client = 0; return false; } connection = client->connect(address, port, timeout); if(!connection) { delete client; client = 0; return false; } // Receive server data // FIXME: Infinite loop if the server does not respond. BufferPointer initialdata; while (!initialdata) { client->update(); if (connection->hasData()) { initialdata = connection->receive(); PacketType type = (PacketType)initialdata->read8(); if (type != EPT_InitialData) { initialdata = 0; } } } serverdata = initialdata; return true; }
void ClientWorldComponent::onPostUpdate() { // Send update BufferPointer update = new Buffer(); update->write8(EPT_Update); update->write32(lastupdate); update->write32(getWorld()->getTime()); // Fill buffer with updates for (unsigned int i = 0; i < entities.size(); i++) { ClientEntityComponent *component = entities[i]; if (component->hasChanged(lastacked)) { update->write16(component->getID() - 1); component->getUpdate(update.get(), lastacked); } } connection->send(update); }
void ClientWorldComponent::onPreUpdate() { client->update(); // Receive data while (connection->hasData()) { BufferPointer data = connection->receive(); PacketType type = (PacketType)data->read8(); switch (type) { case EPT_EntityCreated: { unsigned int id = data->read16() + 1; std::string type = data->readString(); bool local = data->readUnsignedInt(1); // Create entity Game *game = getWorld()->getEngine()->getGame(); EntityFactory *factory = game->getEntityFactory(type); if (!factory) { std::cout << "Could not get entity factory " << type << std::endl; continue; } Entity *entity = factory->createEntity(getWorld()); ClientEntityComponent *component = (ClientEntityComponent*)entity->getComponent(EECT_Client); component->setID(id); component->setState(data.get()); addEntity(entity); getWorld()->addEntity(entity); break; } case EPT_EntityDeleted: { unsigned int id = data->read16() + 1; Entity *entity = getEntity(id); removeEntity(entity); delete entity; break; } case EPT_Update: { bool updatevalid = true; unsigned int updatetime = data->read32(); unsigned int updateclienttime = data->read32(); lastacked = data->read32(); // Adjust time if the latency has decreased // TODO: This might affect client prediction if (updatetime > getWorld()->getTime()) getWorld()->setTime(updatetime); // Apply the updates while (data->getPosition() + 16 <= data->getSize() * 8) { unsigned int id = data->read16() + 1; ClientEntityComponent *entity = getComponent(id); // Ignore invalid updates if (!entity) { updatevalid = false; break; } // Apply backup to remove any user changes if (entity->hasBackup()) entity->applyBackup(); // Apply update entity->applyUpdate(data.get(), updatetime); entity->onUpdate().trigger(updateclienttime); } // Only send the server that we have received this // update if it was valid if (updatevalid) lastupdate = updatetime; break; } case EPT_EntityMessage: { unsigned int id = data->read16() + 1; ClientEntityComponent *entity = getComponent(id); entity->onMessage().trigger(data.get()); break; } default: // TODO: Warn break; } } }
BufferView::BufferView(const BufferPointer& buffer, const Element& element) : BufferView(buffer, DEFAULT_OFFSET, buffer ? buffer->getSize() : 0, element.getSize(), element) {}
void Client::send(BufferPointer buffer, bool reliable) { ENetPacket *packet = enet_packet_create(buffer->getData(), buffer->getSize(), reliable?ENET_PACKET_FLAG_RELIABLE:0); enet_peer_send(peer, 0, packet); }