void StateManager::Internals::addedToEntity() { StateManager* man = &mState; requestMessage("Get.Input", [man](Kunlaboro::Message& msg){ msg.payload = man->mInput; msg.handled = true; }); requestMessage("Get.Settings", [man](Kunlaboro::Message& msg){ msg.payload = man->mSettings; msg.handled = true; }); requestMessage("Get.Sounds", [man](Kunlaboro::Message& msg){ msg.payload = man->mSound; msg.handled = true; }); requestMessage("Get.Font", [man](Kunlaboro::Message& msg){ msg.payload = &man->mGlobalFont; msg.handled = true; }); requestMessage("Get.GameView", [man](Kunlaboro::Message& msg){ msg.payload = man->mGameView; msg.handled = true; }); requestMessage("Get.UiView", [man](Kunlaboro::Message& msg){ msg.payload = man->mUiView; msg.handled = true; }); requestMessage("Now Playing", [this](const Kunlaboro::Message& msg) { mCurrentSong = boost::any_cast<std::string>(msg.payload); mSongPopout = 0; mSongTimeout = 2; }); requestMessage("LD26.Update", [this](const Kunlaboro::Message& msg) { float dt = boost::any_cast<float>(msg.payload); if (mSongTimeout > 0) mSongTimeout = std::max(0.f, mSongTimeout - dt); if (!mCurrentSong.empty() && mSongTimeout > 0 && mSongPopout < 1) mSongPopout = std::min(1.f, mSongPopout + dt); else if (mSongTimeout == 0 && mSongPopout > 0) mSongPopout = std::max(0.f, mSongPopout - dt); else if (mSongTimeout == 0 && mSongPopout == 0 && !mCurrentSong.empty()) mCurrentSong.clear(); }); changeRequestPriority("LD26.Update", -11); requestMessage("LD26.DrawUi", [this](const Kunlaboro::Message& msg) { sf::RenderTarget& target = *boost::any_cast<sf::RenderTarget*>(msg.payload); sf::RectangleShape rect; rect.setSize(sf::Vector2f(512, 96)); rect.setOrigin(rect.getSize()/2.f); rect.setFillColor(sf::Color::Black); rect.setOutlineColor(sf::Color::White); rect.setOutlineThickness(6.f); rect.setPosition(target.getSize().x + 262 - (512 * mSongPopout), target.getSize().y - 100); target.draw(rect); sf::Text playing("Now Playing:", mState.mGlobalFont); sf::FloatRect bounds = playing.getLocalBounds(); playing.setPosition(rect.getPosition() - sf::Vector2f(350, 72) + sf::Vector2f(bounds.left + bounds.width/2, bounds.top + bounds.height/2)); target.draw(playing); playing.setString(mCurrentSong); playing.move(0, bounds.height + 16); playing.setCharacterSize(20U); target.draw(playing); }); }
void IState::addedToEntity() { requestMessage("LD26.Update", &IState::update); requestMessage("LD26.Draw", &IState::draw); requestMessage("LD26.DrawUi", &IState::drawUi); changeRequestPriority("LD26.Update", -10); changeRequestPriority("LD26.Draw", -10); changeRequestPriority("LD26.DrawUi", -10); setup(); }
void PostedItem::loadMessage(const uint32_t &token) { std::vector<RsPostedPost> posts; std::vector<RsGxsComment> cmts; if (!rsPosted->getPostData(token, posts, cmts)) { std::cerr << "GxsChannelPostItem::loadMessage() ERROR getting data"; std::cerr << std::endl; return; } if (posts.size() == 1) { setPost(posts[0]); } else if (cmts.size() == 1) { RsGxsComment cmt = cmts[0]; ui->newCommentLabel->show(); ui->commLabel->show(); ui->commLabel->setText(QString::fromUtf8(cmt.mComment.c_str())); //Change this item to be uploaded with thread element. setMessageId(cmt.mMeta.mThreadId); requestMessage(); } else { std::cerr << "GxsChannelPostItem::loadMessage() Wrong number of Items. Remove It."; std::cerr << std::endl; removeItem(); return; } }
PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate) : GxsFeedItem(feedHolder, feedId, groupId, messageId, isHome, rsPosted, autoUpdate) { setup(); requestGroup(); requestMessage(); }
void ProtoBufWebSocketRequestMessageTest::testConstructor() { std::string testVerb("hfhfhfh"); std::string testPath("feuhehefhd"); std::string testBody("body body body"); google::protobuf::uint64 testId(3745646212); textsecure::WebSocketRequestMessage tsRequestMessage; tsRequestMessage.set_verb(testVerb); tsRequestMessage.set_path(testPath); tsRequestMessage.set_body(testBody); tsRequestMessage.set_id(testId); ProtoBufWebSocketRequestMessage requestMessage(tsRequestMessage); QVERIFY2(requestMessage.verb() == QString::fromStdString(testVerb), "Verb wasn't set."); QVERIFY2(requestMessage.path() == QString::fromStdString(testPath), "Path wasn't set."); QVERIFY2(requestMessage.body() == QString::fromStdString(testBody), "Body wasn't set."); QVERIFY2(requestMessage.requestId() == testId, "Test id wasn't set."); }
void GxsFeedItem::fillDisplay(RsGxsUpdateBroadcastBase *updateBroadcastBase, bool complete) { GxsGroupFeedItem::fillDisplay(updateBroadcastBase, complete); std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgs; updateBroadcastBase->getAllMsgIds(msgs); if (!msgs.empty()) { std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::const_iterator mit = msgs.find(groupId()); if (mit != msgs.end()) { const std::vector<RsGxsMessageId> &msgIds = mit->second; if (std::find(msgIds.begin(), msgIds.end(), messageId()) != msgIds.end()) { requestMessage(); } } } }
CommandByte parse(uint8_t byte) { int8_t msg_size = 0; switch (m_state) { // Test for synchronization case FSM_STATE_NONE: m_togo = m_done = 0; msg_size = getCommandDataSize(byte); if (msg_size > 0) { m_togo = msg_size - 1; m_done = 1; m_data[0] = byte; // Store ID. m_state = FSM_STATE_MESSAGE; } break; // Parse message body. case FSM_STATE_MESSAGE: m_data[m_done] = byte; ++m_done; --m_togo; break; // Should never get here. default: debug("%s: 0x%02x", DTR("unexpected byte"), byte); break; } // Exit if we don't have a complete message. if (m_togo != 0 || m_state != FSM_STATE_MESSAGE) return MSG_NULL; m_state = FSM_STATE_NONE; if (!validateCheckSum(m_data, m_done)) { err("%s", DTR(Status::getString(Status::CODE_INVALID_CHECKSUM))); return MSG_NULL; } double tstamp = Clock::getSinceEpoch(); // Interpret parsed data. int16_t angle = 0; switch (m_data[0]) { case MSG_CONTMODE: return MSG_CONTMODE; case MSG_EEPROM: ByteCopy::fromBE(m_eeprom, m_data + 1); return MSG_EEPROM; case MSG_GS_EULER: m_euler.time = updateTimerCount(m_data + 7); ByteCopy::fromBE(angle, m_data + 1); m_euler.phi = Angles::radians((fp64_t)angle * c_euler_factor); ByteCopy::fromBE(angle, m_data + 3); m_euler.theta = Angles::radians((fp64_t)angle * c_euler_factor); ByteCopy::fromBE(angle, m_data + 5); m_euler.psi = Angles::radians((fp64_t)angle * c_euler_factor); m_euler.psi_magnetic = m_euler.psi; m_euler.setTimeStamp(tstamp); dispatch(m_euler, DF_KEEP_TIME); requestMessage(m_args.raw_ivecs ? MSG_RAW_IVECS : MSG_IVECS); return MSG_GS_EULER; case MSG_IVECS: // Acceleration. m_accel.time = updateTimerCount(m_data + 19); ByteCopy::fromBE(angle, m_data + 7); m_accel.x = (fp64_t)angle / m_accel_scale; ByteCopy::fromBE(angle, m_data + 9); m_accel.y = (fp64_t)angle / m_accel_scale; ByteCopy::fromBE(angle, m_data + 11); m_accel.z = (fp64_t)angle / m_accel_scale; m_accel.setTimeStamp(tstamp); // Angular velocity. ByteCopy::fromBE(angle, m_data + 13); m_agvel.x = (fp64_t)angle / m_gyro_scale; ByteCopy::fromBE(angle, m_data + 15); m_agvel.y = (fp64_t)angle / m_gyro_scale; ByteCopy::fromBE(angle, m_data + 17); m_agvel.z = (fp64_t)angle / m_gyro_scale; m_agvel.setTimeStamp(tstamp); dispatch(m_accel, DF_KEEP_TIME); dispatch(m_agvel, DF_KEEP_TIME); return MSG_IVECS; case MSG_RAW_IVECS: // Acceleration. m_accel.time = updateTimerCount(m_data + 19); ByteCopy::fromBE(angle, m_data + 7); m_accel.x = (fp64_t)angle / m_accel_scale; ByteCopy::fromBE(angle, m_data + 9); m_accel.y = (fp64_t)angle / m_accel_scale; ByteCopy::fromBE(angle, m_data + 11); m_accel.z = (fp64_t)angle / m_accel_scale; m_accel.setTimeStamp(tstamp); // Angular velocity. ByteCopy::fromBE(angle, m_data + 13); m_agvel.x = (fp64_t)angle / m_gyro_scale; ByteCopy::fromBE(angle, m_data + 15); m_agvel.y = (fp64_t)angle / m_gyro_scale; ByteCopy::fromBE(angle, m_data + 17); m_agvel.z = (fp64_t)angle / m_gyro_scale; m_agvel.setTimeStamp(tstamp); dispatch(m_accel, DF_KEEP_TIME); dispatch(m_agvel, DF_KEEP_TIME); return MSG_RAW_IVECS; } return MSG_NULL; }
void GxsFeedItem::updateItemStatic() { std::cerr << "GxsFeedItem::updateItemStatic()"; std::cerr << std::endl; requestMessage(); }
/* Configures server and loops, processing connections 1 by 1 until quit_signal is received */ void* server_thread(void* p){ //Server config implementation //get info regarding server config details from Main method server_info* info = (server_info*)p; int PORT_NUMBER = info->port_num; // structs to represent the server and client struct sockaddr_in server_addr,client_addr; int sock; // socket descriptor // 1. socket: creates a socket descriptor that you later use to make other system calls if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("Socket"); exit(1); } int temp; if (setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&temp,sizeof(int)) == -1) { perror("Setsockopt"); exit(1); } // configure the server server_addr.sin_port = htons(PORT_NUMBER); // specify port number server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = INADDR_ANY; bzero(&(server_addr.sin_zero),8); // 2. bind: use the socket and associate it with the port number if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) { perror("Unable to bind"); exit(1); } // 3. listen: indicates that we want to listen to the port to which we bound; second arg is number of allowed connections if (listen(sock, 1) == -1) { perror("Listen"); exit(1); } // once you get here, the server is set up and about to start listening printf("\nServer configured to listen on port %d\n", PORT_NUMBER); fflush(stdout); //Request Processing //loops, waiting for requests until quit_signal is activated while (quit_signal == 0){ // 4. accept: wait here until we get a connection on that port int sin_size = sizeof(struct sockaddr_in); int fd2 = accept(sock, (struct sockaddr *)&client_addr,(socklen_t *)&sin_size); printf("Server got a connection from (%s, %d)\n", inet_ntoa(client_addr.sin_addr),ntohs(client_addr.sin_port)); // buffer to read data into char request[1024]; // 5. recv: read incoming request message into buffer int bytes_received = recv(fd2,request,1024,0); request[bytes_received] = '\0'; printf("%s\n", request); //this is a request for the most recent temperature switch (request[5]){ case 'a': changeSign(fd2); break; case 'b': mostRecentTemp(fd2); break; case 'd': highLowAverage(fd2); break; case 'm': requestMessage(fd2); break; case 'r': resetAlarm(fd2); break; case 's': toggleStandby(fd2); break; case 't': checkTripped(fd2); printf("%s\n\n", "in t"); break; } close(fd2); } // 7. close: close the socket connection close(sock); printf("Server closed connection\n"); return 0; }
void World::addedToEntity() { { std::random_device dev; std::uniform_int_distribution<int> rand(0, 3); std::uniform_real_distribution<float> randAng(0, 360); sf::RenderTexture render; auto size = std::min(sf::Texture::getMaximumSize(), 1024U); render.create(size, size); sf::Sprite sprite(Resources::Texture_Ground); sprite.setTextureRect(mSheet.getRect(0, 0)); sprite.setOrigin(sprite.getTextureRect().width / 2, sprite.getTextureRect().height / 2); sprite.setPosition(sprite.getTextureRect().width / 2, sprite.getTextureRect().height / 2); sprite.rotate(90); for (int x = 0; x <= size;) { for (int y = 0; y <= size;) { sprite.setTextureRect(mSheet.getRect(rand(dev)%2, rand(dev) % 2)); sprite.setRotation(rand(dev) * 90); render.draw(sprite); if (randAng(dev) > 300) { sprite.setTextureRect(mSheet.getRect(2 + rand(dev) % 2, rand(dev) % 2)); sprite.setRotation(randAng(dev)); render.draw(sprite); } sprite.move(0, sprite.getTextureRect().height); y += sprite.getTextureRect().height; } sprite.setPosition(sprite.getPosition().x, 0); sprite.move(sprite.getTextureRect().width, 0); x += sprite.getTextureRect().width; } render.display(); mBigOne = render.getTexture(); } requestMessage("Event.Update", [this](const Kunlaboro::Message& msg) { static float timer = 0; float dt = boost::any_cast<float>(msg.payload); timer += dt; if (timer > 1) { timer = 0; std::list<Enemy*> list; sendGlobalMessage("Would the real slim shady please stand up?", &list); if (list.size() < 15) { auto& sys = *getEntitySystem(); auto ent = sys.createEntity(); sys.addComponent(ent, "Game.Enemy"); sys.addComponent(ent, "Game.Weapon"); } } }); requestMessage("Event.Draw", [this](const Kunlaboro::Message& msg) { auto& target = *std::get<0>(boost::any_cast<std::tuple<sf::RenderTarget*,float>>(msg.payload)); sf::Vector2f vC = target.getView().getCenter(), vS = (sf::Vector2f)mBigOne.getSize(), vS2 = target.getView().getSize(); //vC += vS/2.f; sf::Vector2i centerPos = sf::Vector2i(vC.x / vS.x, vC.y / vS.x); sf::Sprite sprite(mBigOne); sprite.setOrigin((sf::Vector2f)mBigOne.getSize() / 2.f); sprite.setPosition(centerPos.x * vS.x, centerPos.y * vS.y); int xRes = vS2.x / vS.x + 1; int yRes = vS2.y / vS.y + 1; for (int x = -xRes; x <= xRes; ++x) { for (int y = -yRes; y <= yRes; ++y) { sprite.setPosition((centerPos.x + x) * vS.x, (centerPos.y + y) * vS.y); target.draw(sprite); } } }); changeRequestPriority("Event.Draw", -9001); requestMessage("I'm ending this!", [this](const Kunlaboro::Message& msg) { getEntitySystem()->destroyEntity(getOwnerId()); }); requestMessage("Did I accidentally all the stats?", [this](Kunlaboro::Message& msg) { msg.handled = true; msg.payload = mStats; }); ///< No, no you didn't. requestMessage("I am bullet!", [this](const Kunlaboro::Message&) { mStats.ShotsFired++; }); requestMessage("I am bullethole!", [this](const Kunlaboro::Message&) { mStats.ShotsHit++; }); requestMessage("Is dead now", [this](const Kunlaboro::Message& msg) { if (boost::any_cast<bool>(msg.payload)) mStats.EnemiesDeadByPlayer++; else mStats.EnemiesDead++; }); requestMessage("Demon Speeding", [this](const Kunlaboro::Message& msg) { float s = boost::any_cast<float>(msg.payload); mStats.MaxSpeed = std::max(mStats.MaxSpeed, s); }); requestMessage("Road to Rouen", [this](const Kunlaboro::Message& msg) { float s = boost::any_cast<float>(msg.payload); mStats.DistanceTraveled += s; }); }