void outsync (Protocol::Transaction& c, void* payload, size_t& size) { if (current_.status == Protocol::TS_COMMIT || current_.status == Protocol::TS_ABORT) { if (++voting_duration_ >= Protocol::VOTING_FRAME) { // end of voting frame if (current_.status == Protocol::TS_COMMIT) { { if (initiated_) { MessageQueueAutoLock lock (send_out_); send_out_.push (MessagePtr (new Commited)); } else // joined transaction { MessageQueueAutoLock lock (recv_out_); recv_out_.push (MessagePtr (recv_)); recv_ = RecvPtr (); } } current_.status = Protocol::TS_COMMITED; // if (trace_) cerr << "commited transaction with id " // << current_.id << endl; } else // TS_ABORT { if (initiated_) { MessageQueueAutoLock lock (send_out_); send_out_.push (MessagePtr (new Aborted)); } else { // free revc_ buffer if necessary // if (recv_.get ()) recv_ = RecvPtr (); } current_.status = Protocol::TS_ABORTED; // if (trace_) cerr << "aborted transaction with id " // << current_.id << endl; } // start transaction separation frame (counts down) // +1 because it will be decremented on this iteration separation_duration_ = Protocol::SEPARATION_FRAME + 1; } } // Set current outsync info c.id = current_.id; c.status = current_.status; // Do some post-processing switch (current_.status) { case Protocol::TS_COMMITED: case Protocol::TS_ABORTED: { if (separation_duration_ > 0) --separation_duration_; break; } case Protocol::TS_BEGIN: { // transfer payload size = send_->size (); ACE_OS::memcpy (payload, send_->payload (), size); send_ = SendPtr (); // get redy to vote for 'commit' current_.status = Protocol::TS_COMMIT; voting_duration_ = 0; } } }
void LocalRulesManager::update(const double& timeStep) { ENetEvent event; while(enet_host_service(m_server, &event, 0) > 0) { switch (event.type) { case ENET_EVENT_TYPE_CONNECT: std::cout<<"Client connected: "<< event.peer->address.host << " : " << event.peer->address.port<<std::endl; break; case ENET_EVENT_TYPE_RECEIVE: updateMessages(event.packet->data, event.packet->dataLength); for(auto msg : m_messageQueue) { switch(msg->getType()) { case C_HELLO: { sendMessage(MessagePtr(new Welcome("Server")), ENET_PACKET_FLAG_RELIABLE); m_isWaiting = false; } break; case G_UPDATE_POS: m_pongScene->updateOpponentPos(((UpdatePos*)msg.get())->getPosition()); break; case G_BALLEVENT: { //std::cout<<"Ball event: " << (int)((BallEvent*)msg.get())->getEventType() << " "<< (int)((BallEvent*)msg.get())->getPlayerId() << std::endl; BallEvent* evt = (BallEvent*)msg.get(); switch(evt->getEventType()) { case BallEvent::BALLEVENT_TABLE: m_gameRules->onBallHitTable(evt->getPlayerId()); break; case BallEvent::BALLEVENT_RACKET: m_gameRules->onBallHitRacket(evt->getPlayerId()); break; case BallEvent::BALLEVENT_OUTSIDE: m_gameRules->onBallOut(); break; } checkGameRules(); } break; case G_BALLSTATE: { BallState* ballState = (BallState*)msg.get(); m_pongScene->updateBallState( ballState->getPosition(), ballState->getVelocity(), ballState->getAngularVelocity(), ballState->getServe(), ballState->getHitMagnitude()); if(ballState->getServe() != 0) m_gameRules->onNewRound(); } break; } } m_messageQueue.clear(); //std::cout<<"Got data: "<< event.packet->dataLength << std::endl; break; case ENET_EVENT_TYPE_DISCONNECT: std::cout<<"Client disconnected: "<< event.peer->address.host << " : " << event.peer->address.port<<std::endl; break; } } }
bool Reader::loadLayers(ZipReader &zip, const QDomElement& stack, QPoint offset) { // TODO are layer coordinates relative to stack coordinates? // The spec, as of this writing, is not clear on this. offset += QPoint( stack.attribute("x", "0").toInt(), stack.attribute("y", "0").toInt() ); QDomNodeList nodes = stack.childNodes(); // Iterate backwards to get the layers in the right order (layers are always added to the top of the stack) for(int n=nodes.count()-1;n>=0;--n) { QDomElement e = nodes.at(n).toElement(); if(e.isNull()) continue; if(e.tagName()=="layer") { // Check for unknown attributes const char *layerattrs[] = { "x", "y", "name", "src", "opacity", "visibility", "composite-op", 0 }; if(!isKnown(e.attributes(), layerattrs)) _warnings |= ORA_EXTENDED; // Load content image from the file const QString src = e.attribute("src"); QImage content; { QByteArray image = zip.fileData(src); if(image.isNull()) { _error = QApplication::tr("Couldn't get layer %1").arg(src); return false; } if(content.loadFromData(image, "png")==false) { _error = QApplication::tr("Couldn't load layer %1").arg(src); return false; } } // Create layer QString name = e.attribute("name", QApplication::tr("Unnamed layer")); _commands.append(MessagePtr(new protocol::LayerCreate( 1, ++_layerid, 0, name ))); QPoint layerPos = offset + QPoint( e.attribute("x", "0").toInt(), e.attribute("y", "0").toInt() ); _commands.append(net::putQImage(_layerid, layerPos.x(), layerPos.y(), content, false)); QString compositeOp = e.attribute("composite-op", "src-over"); int blendmode = dpcore::blendModeSvg(compositeOp); if(blendmode<0) { _warnings |= ORA_EXTENDED; blendmode = 1; } _commands.append(MessagePtr(new protocol::LayerAttributes( _layerid, qRound(255 * e.attribute("opacity", "1.0").toDouble()), blendmode ))); // TODO visibility flag //layer->setHidden(e.attribute("visibility", "visible") != "visible"); } else if(e.tagName()=="stack") { // Nested stacks are not fully supported _warnings |= ORA_NESTED; if(loadLayers(zip, e, offset)==false) return false; } else if(e.namespaceURI()==DP_NAMESPACE && e.localName()=="annotations") { loadAnnotations(e); } else if(e.namespaceURI()==DP_NAMESPACE) { qWarning() << "Unhandled drawpile extension in stack:" << e.tagName(); _warnings |= ORA_EXTENDED; } else if(e.prefix()=="") { qWarning() << "Unhandled stack element:" << e.tagName(); _warnings |= ORA_EXTENDED; } } return true; }