GameLevelState::GameLevelState(StateManager* _stateManager) : State(_stateManager), playerPosition(0.0f, 4.0f), ballPosition(0.0f, 0.0f), ballVelocity(0.0f, 0.1f), ballSize(40.0f, 40.0f), playerSize(150, 35.0f) { map = new yam2d::TmxMap(); compFac = new CustomComponentFactory(); compFac->setCurrentMap(map); contactListener = new ContactListener(); compFac->getPhysicsWorld()->SetContactListener(contactListener); if (map->loadMapFile("Maps/test_map.tmx", compFac)) { map->getCamera()->setPosition(yam2d::vec2(map->getWidth() / 2.0f, map->getHeight() / 2.0f)); } else { msgstream("Error loading TmxMap!"); stateManager->setState(new MainMenuState(stateManager)); } tileSize = yam2d::vec2(map->getWidth(), map->getHeight()); yam2d::Map::LayerMap layers = map->getLayers(); yam2d::Layer::GameObjectList goList; for (unsigned i = 0; i < layers.size(); i++) { if (layers[i]) { goList = layers[i]->getGameObjects(); for (unsigned i = 0; i < goList.size(); i++) { tileObjects.push_back(goList[i]); } } } for (unsigned i = 0; i < tileObjects.size(); i++) { if (tileObjects[i]->getName() == "Player") { playerObject = tileObjects[i]; } else if (tileObjects[i]->getName() == "Ball") { ballObject = tileObjects[i]; } } tileAmount = tileObjects.size() - 3; //3 = ball, player, background textObject = createTextObject(); textObject->setPosition(tileSize.x - tileSize.x * 0.15f, tileSize.y - tileSize.y * 0.85f); map->getLayer("Tiles")->addGameObject(textObject); }
void dbg_draw_movement_areas::collect_visible_areas( std::vector< std::pair<vector3,vector3> > const& clip_planes, std::shared_ptr<netlab::network const> const network ) { if (!is_enabled()) return; m_batches.clear(); m_invalidated = false; std::vector< std::pair<vector3,qtgl::batch> >& batches = m_batches; std::vector<netlab::network_layer_props> const& layer_props = network->properties()->layer_props(); std::vector< std::vector< qtgl::batch > > area_batches; { area_batches.resize(layer_props.size()); for (netlab::layer_index_type layer_index = 0U; layer_index != layer_props.size(); ++layer_index) { area_batches.at(layer_index).resize(layer_props.size()); auto const& props = layer_props.at(layer_index); for (netlab::layer_index_type area_layer_index = 0U; area_layer_index != layer_props.size(); ++area_layer_index) area_batches.at(layer_index).at(area_layer_index) = qtgl::create_wireframe_box( -0.5f * props.size_of_ship_movement_area_in_meters(area_layer_index), +0.5f * props.size_of_ship_movement_area_in_meters(area_layer_index), vector4(0.5f, 0.5f, 0.5f, 1.0f), qtgl::FOG_TYPE::NONE, msgstream() << "netviewer/movement_area_of_layer_" << layer_index << "_to_layer_" << area_layer_index ); } } for (netlab::layer_index_type layer_index = 0U; layer_index != layer_props.size(); ++layer_index) { auto const& props = layer_props.at(layer_index); for (netlab::object_index_type spiker_index = 0ULL; spiker_index != props.num_spikers(); ++spiker_index) { auto const& props = layer_props.at(layer_index); vector3 const& area_center = network->get_layer_of_spikers(layer_index).get_movement_area_center(spiker_index); netlab::layer_index_type const area_layer_index = network->properties()->find_layer_index(area_center(2)); if (netview::is_bbox_behind_any_of_planes( area_center - 0.5f * props.size_of_ship_movement_area_in_meters(area_layer_index), area_center + 0.5f * props.size_of_ship_movement_area_in_meters(area_layer_index), clip_planes)) continue; batches.push_back({ area_center,area_batches.at(layer_index).at(area_layer_index) }); } } }
std::string draw_state::compute_generic_unique_id( bool const use_alpha_blending, natural_32_bit const alpha_blending_src_function, natural_32_bit const alpha_blending_dst_function, natural_32_bit const cull_face_mode ) { return msgstream() << "ALPHA_BLEND=" << use_alpha_blending << ", BLEND_SRC_FUNC=" << get_map_from_alpha_blending_functions_to_names().at(alpha_blending_src_function) << ", BLEND_DST_FUNC=" << get_map_from_alpha_blending_functions_to_names().at(alpha_blending_dst_function) << ", CULL=" << get_map_from_cull_modes_to_names().at(cull_face_mode) ; }
void NetworkClient::Handle_ClientCommsData ( char *buffer ) { std::istrstream msgstream ( buffer ); char msgtype [64]; msgstream >> msgtype; if ( strcmp ( msgtype, "CLIENTCOMMS" ) == 0 ) { // This is a list of IP's making up the players connection UplinkAssert ( screen ); UplinkAssert ( screen->ScreenID () == CLIENT_COMMS ); ((ClientCommsInterface *) screen)->connection.Empty (); int numrelays; msgstream >> numrelays; for ( int i = 0; i < numrelays; ++i ) { int x, y; char *ip = new char [64]; msgstream >> x >> y >> ip ; /* if ( ! ((ClientCommsInterface *) screen)->locations.LookupTree (ip) ) { // We don't have this IP yet VLocation *vl = new VLocation (); vl->SetPLocation ( x, y ); vl->SetIP ( ip ); vl->SetComputer ( "Accessing..." ); ((ClientCommsInterface *) screen)->locations.PutData ( ip, vl ); } */ UplinkAssert ( ((ClientCommsInterface *) screen)->locations.LookupTree (ip) ); ((ClientCommsInterface *) screen)->connection.PutData ( ip ); } }
draw_state_data::draw_state_data(async::finalise_load_on_destroy_ptr const finaliser) : m_use_alpha_blending(false) , m_alpha_blending_src_function(GL_SRC_ALPHA) , m_alpha_blending_dst_function(GL_ONE_MINUS_CONSTANT_ALPHA) , m_cull_face_mode(GL_BACK) { TMPROF_BLOCK(); boost::filesystem::path const pathname = finaliser->get_key().get_unique_id(); if (!boost::filesystem::exists(pathname)) throw std::runtime_error(msgstream() << "The passed file '" << pathname << "' does not exist."); boost::property_tree::ptree draw_state_ptree; boost::property_tree::read_info(pathname.string(), draw_state_ptree); m_use_alpha_blending = draw_state_ptree.get("use_alpha_blending", false); m_alpha_blending_src_function = read_property(draw_state_ptree, "alpha_blending_src_function", get_map_from_alpha_blending_function_names_to_gl_values()); m_alpha_blending_dst_function = read_property(draw_state_ptree, "alpha_blending_dst_function", get_map_from_alpha_blending_function_names_to_gl_values()); m_cull_face_mode = read_property(draw_state_ptree, "cull_face_mode", get_map_from_cull_mode_names_to_gl_values()); }
JaMessage CJabloDongle::ParseMessage(std::string msgstring) { JaMessage msg; std::stringstream msgstream(msgstring); std::string msgtok; int tokNum; bool singlePlaceTemp = false; if(msgstring == "\nOK\n") { msg.mtype = JMTYPE_OK; } else if(msgstring == "\nERROR\n") { msg.mtype = JMTYPE_ERR; } else if(!msgstring.compare(0, 16, "\nTURRIS DONGLE V") && (msgstring.length() > 17)) { msg.mtype = JMTYPE_VERSION; msg.version = std::string(msgstring.c_str() + 16); msg.version.erase(msg.version.size() - 1); } else if(!msgstring.compare(0, 6, "\nSLOT:")) { if(sscanf(msgstring.c_str(), "\nSLOT:%u [%u]\n", &msg.slot_num, &msg.slot_val) == 2) { msg.mtype = JMTYPE_SLOT; } else if(sscanf(msgstring.c_str(), "\nSLOT:%u [--------]\n", &msg.slot_num) == 1) { msg.mtype = JMTYPE_SLOT; msg.slot_val = 0; } } else { tokNum = 0; while(msgstream >> msgtok) { if(tokNum == 0) { if(sscanf(msgtok.c_str(), "[%u]", &msg.did) != 1) break; } #ifdef OLDFW else if(tokNum == 1) { if(sscanf(msgtok.c_str(), "ID:%u", &msg.mid) != 1) { msg.mid = -1; if(msgtok.compare("ID:---") != 0) break; } } #endif #ifdef OLDFW else if(tokNum == 2) { #else else if(tokNum == 1) { #endif msg.devmodel = msgtok; } #ifdef OLDFW else if(tokNum == 3) { #else else if(tokNum == 2) { #endif if(msgtok == "SENSOR") { msg.mtype = JMTYPE_SENSOR; } else if(msgtok == "TAMPER") { msg.mtype = JMTYPE_TAMPER; } else if(msgtok == "BEACON") { msg.mtype = JMTYPE_BEACON; } else if(msgtok == "BUTTON") { msg.mtype = JMTYPE_BUTTON; } else if(msgtok == "ARM:1") { msg.mtype = JMTYPE_ARM; } else if(msgtok == "ARM:0") { msg.mtype = JMTYPE_DISARM; } else if(sscanf(msgtok.c_str(), "SET:%f", &msg.temp) == 1) { msg.mtype = JMTYPE_SET; } else if(sscanf(msgtok.c_str(), "INT:%f", &msg.temp) == 1) { msg.mtype = JMTYPE_INT; } else if(msgtok == "SET:") { msg.mtype = JMTYPE_SET; singlePlaceTemp = true; } else if(msgtok == "INT:") { msg.mtype = JMTYPE_INT; singlePlaceTemp = true; } else { msg.mtype = JMTYPE_UNDEF; } } #ifdef OLDFW else if((tokNum == 4) && (singlePlaceTemp == true)) { #else else if((tokNum == 3) && (singlePlaceTemp == true)) { #endif if(sscanf(msgtok.c_str(), "%f", &msg.temp) != 1) { msg.temp = 0; msg.mtype = JMTYPE_UNDEF; } singlePlaceTemp = false; } else { if(sscanf(msgtok.c_str(), "LB:%d", &msg.lb) != 1) if(sscanf(msgtok.c_str(), "ACT:%d", &msg.act) != 1) sscanf(msgtok.c_str(), "BLACKOUT:%d", &msg.blackout); } tokNum++; } } return msg; } void CJabloDongle::ProcessMessage(JaMessage jmsg) { Ja_device *jdev; if((jmsg.mtype != JMTYPE_SLOT) && (jmsg.mtype != JMTYPE_VERSION) && (jmsg.mtype != JMTYPE_OK) && (jmsg.mtype != JMTYPE_ERR)) { _log.Log(LOG_STATUS, "Received message of type %s from device %d (%s)", jmsg.MtypeAsString().c_str(), jmsg.did, jmsg.devmodel.c_str()); } switch(jmsg.mtype) { case JMTYPE_SLOT: { SlotReadCallback(jmsg.slot_num, jmsg.slot_val); readSlotsCond.notify_one(); break; } case JMTYPE_VERSION: { ProbeCallback(jmsg.version); probeCond.notify_one(); break; } case JMTYPE_SENSOR: { std::stringstream dev_desc; dev_desc << jmsg.devmodel << "_" << std::setfill('0') << jmsg.did << "_SENSOR"; SendSwitch(jmsg.did, SUBSWITCH_SENSOR, (jmsg.lb == 1) ? 0 : 100, (jmsg.act == -1) ? 1 : jmsg.act, 0, dev_desc.str()); break; } case JMTYPE_TAMPER: { std::stringstream dev_desc; dev_desc << jmsg.devmodel << "_" << std::setfill('0') << jmsg.did << "_TAMPER"; SendSwitch(jmsg.did, SUBSWITCH_TAMPER, (jmsg.lb == 1) ? 0 : 100, (jmsg.act == -1) ? 1 : jmsg.act, 0, dev_desc.str()); break; } case JMTYPE_BUTTON: { std::stringstream dev_desc; dev_desc << jmsg.devmodel << "_" << std::setfill('0') << jmsg.did << "_BUTTON"; SendSwitch(jmsg.did, SUBSWITCH_BUTTON, (jmsg.lb == 1) ? 0 : 100, (jmsg.act == -1) ? 1 : jmsg.act, 0, dev_desc.str()); break; } case JMTYPE_ARM: case JMTYPE_DISARM: { std::stringstream dev_desc; dev_desc << jmsg.devmodel << "_" << std::setfill('0') << jmsg.did << "_ARM"; SendSwitch(jmsg.did, SUBSWITCH_ARM, (jmsg.lb == 1) ? 0 : 100, (jmsg.mtype == JMTYPE_ARM) ? 1 : 0, 0, dev_desc.str()); break; } case JMTYPE_SET: { std::stringstream dev_desc; dev_desc << jmsg.devmodel << "_" << std::setfill('0') << jmsg.did << "_SET"; SendSetPointSensor(jmsg.did, (jmsg.lb == 1) ? 0 : 100, jmsg.temp, dev_desc.str()); break; } case JMTYPE_INT: { std::stringstream dev_desc; dev_desc << jmsg.devmodel << "_" << std::setfill('0') << jmsg.did << "_INT"; SendTempSensor(jmsg.did, (jmsg.lb == 1) ? 0 : 100, jmsg.temp, dev_desc.str()); break; } } } void CJabloDongle::ReadCallback(const char *data, size_t len) { unsigned char *mf, *ml; unsigned char *bufptr; unsigned char msgline[128]; JaMessage jmsg; bool messagesInBuffer; boost::lock_guard<boost::mutex> l(readQueueMutex); if (!m_bIsStarted) return; if (!m_bEnableReceive) return; //receive data to buffer if((m_bufferpos + len) < sizeof(m_buffer)) { memcpy(m_buffer + m_bufferpos, data, len); m_bufferpos += len; } else { _log.Log(LOG_STATUS, "JabloDongle: Buffer Full"); } //m_buffer[m_bufferpos] = '\0'; //_log.Log(LOG_STATUS, "Pokus received: %s", m_buffer); do { messagesInBuffer = false; //find sync sequence \n[ bufptr = m_buffer; while((mf = (unsigned char*)strchr((const char*)bufptr, '\n')) != NULL) { //check if character after newline is printable character if((mf[1] > 32 && (mf[1] < 127))) break; bufptr = mf + 1; } //is there at least 1 whole msg in buffer? if((mf != NULL) && (strlen((char*)mf) > 2)) { ml = (unsigned char*)strchr((char*)mf + 2, '\n'); if(ml != NULL) messagesInBuffer = true; } if(messagesInBuffer) { //copy single message into separate buffer memcpy(msgline, mf, ml - mf + 1); msgline[ml - mf + 1] = '\0'; //shift message buffer and adjust end pointer memmove(m_buffer, ml + 1, m_bufferpos); m_bufferpos -= (ml - m_buffer) + 1; //process message //_log.Log(LOG_STATUS, "Received line %s", msgline); jmsg = ParseMessage(std::string((char*)msgline)); #ifdef OLDFW //quick and dirty hack for msg deduplication, will be removed in final version if((jmsg.mid == -1) && ((jmsg.mtype != last_mtype) || ((jmsg.mtype != JMTYPE_SET) && (jmsg.mtype != JMTYPE_INT)))) { ProcessMessage(jmsg); last_mtype = jmsg.mtype; } else if(jmsg.mid != last_mid) { ProcessMessage(jmsg); last_mid = jmsg.mid; } #else ProcessMessage(jmsg); #endif } }while(messagesInBuffer); } void CJabloDongle::SendTempSensor(int NodeID, const int BatteryLevel, const float temperature, const std::string &defaultname) { bool bDeviceExits = true; std::stringstream szQuery; std::vector<std::vector<std::string> > result; NodeID &= 0xFFFF; //TEMP packet has only 2 bytes for ID. char szTmp[30]; sprintf(szTmp, "%d", (unsigned int)NodeID); szQuery << "SELECT Name FROM DeviceStatus WHERE (HardwareID==" << m_HwdID << ") AND (DeviceID=='" << szTmp << "') AND (Type==" << int(pTypeTEMP) << ") AND (Subtype==" << int(sTypeTemperature) << ")"; result = m_sql.query(szQuery.str()); if (result.size() < 1) { bDeviceExits = false; } RBUF tsen; memset(&tsen, 0, sizeof(RBUF)); tsen.TEMP.packetlength = sizeof(tsen.TEMP) - 1; tsen.TEMP.packettype = pTypeTEMP; tsen.TEMP.subtype = sTypeTemperature; tsen.TEMP.battery_level = BatteryLevel; tsen.TEMP.rssi = 12; tsen.TEMP.id1 = (NodeID & 0xFF00) >> 8; tsen.TEMP.id2 = NodeID & 0xFF; tsen.TEMP.tempsign = (temperature >= 0) ? 0 : 1; int at10 = round(temperature*10.0f); tsen.TEMP.temperatureh = (BYTE)(at10 / 256); at10 -= (tsen.TEMP.temperatureh * 256); tsen.TEMP.temperaturel = (BYTE)(at10); sDecodeRXMessage(this, (const unsigned char *)&tsen.TEMP); if (!bDeviceExits) { //Assign default name for device szQuery.clear(); szQuery.str(""); szQuery << "UPDATE DeviceStatus SET Name='" << defaultname << "' WHERE (HardwareID==" << m_HwdID << ") AND (DeviceID=='" << szTmp << "') AND (Type==" << int(pTypeTEMP) << ") AND (Subtype==" << int(sTypeTemperature) << ")"; m_sql.query(szQuery.str()); } }