AccessClass::AccessClass(RubyValue className, RubyValue methodInfos, RubyValue signalInfos, RubyValue propertyInfos) { setClassName(className.to<QByteArray>()); protect([&] { rb_check_array_type(methodInfos); rb_check_array_type(signalInfos); rb_check_array_type(propertyInfos); }); for (int i = 0; i < RARRAY_LEN(VALUE(methodInfos)); ++i) { RubyValue info = RARRAY_AREF(VALUE(methodInfos), i); auto nameSym = info.send("name"); addMethod(nameSym.to<QByteArray>(), nameSym.toID(), info.send("params").to<QList<QByteArray>>()); } for (int i = 0; i < RARRAY_LEN(VALUE(signalInfos)); ++i) { RubyValue info = RARRAY_AREF(VALUE(signalInfos), i); auto nameSym = info.send("name"); addSignal(nameSym.to<QByteArray>(), nameSym.toID(), info.send("params").to<QList<QByteArray>>()); } for (int i = 0; i < RARRAY_LEN(VALUE(propertyInfos)); ++i) { RubyValue info = RARRAY_AREF(VALUE(propertyInfos), i); addProperty(info.send("name").to<QByteArray>(), info.send("getter").toID(), info.send("setter").toID(), Property::Flag::Readable | Property::Flag::Writable, true, info.send("notifier").toID()); } }
void MetaInfo::save( KConfig * conf ) { conf->writeEntry( "Bookmarks", bookmarks() ); conf->writeEntry( "Breakpoints", breakpoints() ); conf->writeEntry( "OutputMethod", toID(outputMethodInfo().method()) ); conf->writePathEntry( "OutputPath", outputMethodInfo().outputFile().prettyURL() ); conf->writeEntry( "OutputPicID", outputMethodInfo().picID() ); conf->writeEntry( "CursorLine", cursorLine() ); conf->writeEntry( "CursorColumn", cursorColumn() ); }
void UpdateAttribute(IAttribute * attr) { WinID fromID(m_dlgview.GetAttribute()->GetModuleQualifiedLabel(), m_dlgview.GetAttribute()->GetLabel()); WinID toID(attr->GetModuleQualifiedLabel(), attr->GetLabel()); m_dlgview.SetAttribute(attr); g_attr_window[toID] = g_attr_window[fromID]; //g_attr_window[toID] = this; g_attr_window[fromID] = std::make_pair<CChildAttributeFrm *, CAttributeFrame *>(NULL, NULL); UIUpdateTitle(); (*this)(attr, false, NULL, false); }
std::unordered_map<uint64_t, detail::InternalTile>::iterator findParent(const uint8_t z, const uint32_t x, const uint32_t y) { uint8_t z0 = z; uint32_t x0 = x; uint32_t y0 = y; const auto end = tiles.end(); auto parent = end; while ((parent == end) && (z0 != 0)) { z0--; x0 = x0 / 2; y0 = y0 / 2; parent = tiles.find(toID(z0, x0, y0)); } return parent; }
const Tile& getTile(const uint8_t z, const uint32_t x_, const uint32_t y) { if (z > options.maxZoom) throw std::runtime_error("Requested zoom higher than maxZoom: " + std::to_string(z)); const uint32_t z2 = std::pow(2, z); const uint32_t x = ((x_ % z2) + z2) % z2; // wrap tile x coordinate const uint64_t id = toID(z, x, y); auto it = tiles.find(id); if (it != tiles.end()) return it->second.tile; it = findParent(z, x, y); if (it == tiles.end()) throw std::runtime_error("Parent tile not found"); // if we found a parent tile containing the original geometry, we can drill down from it const auto& parent = it->second; // parent tile is a solid clipped square, return it instead since it's identical if (parent.is_solid) return parent.tile; // drill down parent tile up to the requested one splitTile(parent.source_features, parent.z, parent.x, parent.y, z, x, y); it = tiles.find(id); if (it != tiles.end()) return it->second.tile; it = findParent(z, x, y); if (it == tiles.end()) throw std::runtime_error("Parent tile not found"); // drilling stopped because parent was a solid square; return it instead if (it->second.is_solid) return it->second.tile; // otherwise it was an empty tile return empty_tile; }
void Game::renderFromJSON(const Json::Value &msgs) { invariant(msgs.isArray(), "json messages must be array"); invariant(msgs.size() > 0, "messges must be nonempty"); for (auto msg : msgs) { auto type = must_have_idx(msg, "type").asString(); if (type == "render") { handleRenderMessage(msg); } else if (type == "start") { Renderer::get()->setGameTime(0.f); Renderer::get()->setTimeMultiplier(1.f); } else if (type == "game_over") { // TODO(zack/connor): do more here auto winning_team = toID(must_have_idx(msg, "winning_team")); LOG(DEBUG) << "Winning team : " << winning_team << '\n'; running_ = false; } else { invariant_violation("unknown message type: " + type); } } }
GameEntity::UIInfo UIInfoFromJSON(const Json::Value &v) { GameEntity::UIInfo ret; if (v.isMember("minimap_icon")) { ret.minimap_icon = v["minimap_icon"].asString(); } if (v.isMember("mana")) { ret.mana = toVec2(v["mana"]); } if (v.isMember("retreat")) { ret.retreat = v["retreat"].asBool(); } if (v.isMember("capture")) { ret.capture = toVec2(v["capture"]); } if (v.isMember("capture_pid")) { ret.capture_pid = toID(v["capture_pid"]); } if (v.isMember("path")) { for (auto &&pt : v["path"]) { ret.path.push_back(glm::vec3(toVec2(pt), 0.)); } } if (v.isMember("parts")) { for (auto &&json_part : v["parts"]) { ret.parts.push_back(UIPartFromJSON(json_part)); } } if (v.isMember("hotkey")) { auto&& hotkeystr = v["hotkey"].asString(); ret.hotkey = hotkeystr.empty() ? '\0' : hotkeystr[0]; } if (v.isMember("extra")) { ret.extra = v["extra"]; } return ret; }
void LithneClass::setRecipient( uint8_t _id ) { toID( _id ); }
void Game::handleRenderMessage(const Json::Value &v) { auto entities = must_have_idx(v, "entities"); invariant(entities.isObject(), "should have entities array"); auto entity_keys = entities.getMemberNames(); for (auto &eid : entity_keys) { // find or create GameEntity corresponding to the auto it = game_to_render_id.find(eid); GameEntity *entity = nullptr; if (it == game_to_render_id.end()) { id_t new_id = Renderer::get()->newEntityID(); auto game_entity = new GameEntity(new_id); game_entity->setGameID(eid); Renderer::get()->spawnEntity(game_entity); game_to_render_id[eid] = new_id; entity = game_entity; } else { entity = GameEntity::cast(Renderer::get()->getEntity(it->second)); } renderEntityFromJSON(entity, entities[eid]); } auto events = must_have_idx(v, "events"); invariant(events.isArray(), "events must be array"); for (auto&& event : events) { add_effect( must_have_idx(event, "name").asString(), must_have_idx(event, "params")); } auto players = must_have_idx(v, "players"); invariant(players.isArray(), "players must be array"); for (int i = 0; i < players.size(); i++) { auto player = players[i]; id_t pid = toID(must_have_idx(player, "pid")); requisition_[pid] = must_have_idx(player, "req").asFloat(); power_[pid] = must_have_idx(player, "power").asFloat(); } auto teams = must_have_idx(v, "teams"); for (int i = 0; i < teams.size(); i++) { auto team = teams[i]; id_t tid = toID(must_have_idx(team, "tid")); victoryPoints_[tid] = must_have_idx(team, "vps").asFloat(); } auto chats = must_have_idx(v, "chats"); for (int i = 0; i < chats.size(); i++) { auto json_chat = chats[i]; auto chat = ChatMessage( toID(must_have_idx(json_chat, "pid")), must_have_idx(json_chat, "msg").asString(), Clock::now()); chatListener_(chat); } const float t = must_have_idx(v, "t").asFloat(); const float dt = must_have_idx(v, "dt").asFloat(); const float render_t = Renderer::get()->getGameTime(); if (render_t + dt > t) { LOG(WARNING) << "Renderer is ahead of game: " << render_t << " vs " << t << '\n'; Renderer::get()->setGameTime(t - dt); } if (render_t < t - 2 * dt) { LOG(WARNING) << "Renderer is behind server " << render_t << " vs " << t << '\n'; Renderer::get()->setGameTime(t - dt); } }
void renderEntityFromJSON(GameEntity *e, const Json::Value &v) { invariant(e, "must have entity to render to"); if (v.isMember("alive")) { for (auto &sample : v["alive"]) { e->setAlive(sample[0].asFloat(), sample[1].asBool()); } } if (v.isMember("model")) { for (auto &sample : v["model"]) { e->setModelName(sample[1].asString()); } } if (v.isMember("properties")) { for (auto &sample : v["properties"]) { for (auto &prop : sample[1]) { e->addProperty(prop.asInt()); } } } if (v.isMember("pid")) { for (auto &sample : v["pid"]) { e->setPlayerID(sample[0].asFloat(), toID(sample[1])); } } if (v.isMember("tid")) { for (auto &sample : v["tid"]) { e->setTeamID(sample[0].asFloat(), toID(sample[1])); } } if (v.isMember("pos")) { for (auto &sample : v["pos"]) { e->setPosition(sample[0].asFloat(), toVec2(sample[1])); } } if (v.isMember("size")) { for (auto &sample : v["size"]) { e->setSize(sample[0].asFloat(), toVec3(sample[1])); } } if (v.isMember("angle")) { for (auto &sample : v["angle"]) { e->setAngle(sample[0].asFloat(), sample[1].asFloat()); } } if (v.isMember("sight")) { for (auto &sample : v["sight"]) { e->setSight(sample[0].asFloat(), sample[1].asFloat()); } } if (v.isMember("visible")) { for (auto &sample : v["visible"]) { float t = sample[0].asFloat(); VisibilitySet set; for (auto pid : sample[1]) { set.insert(toID(pid)); } e->setVisibilitySet(t, set); } } if (v.isMember("actions")) { for (auto &sample : v["actions"]) { float t = sample[0].asFloat(); std::vector<UIAction> actions; for (auto &action_json : sample[1]) { auto uiaction = UIActionFromJSON(action_json); uiaction.owner_id = e->getGameID(); actions.push_back(uiaction); } if (!actions.empty()) { e->setActions(t, actions); } } } if (v.isMember("ui_info")) { for (auto &&sample : v["ui_info"]) { const float t = sample[0].asFloat(); GameEntity::UIInfo uiinfo = UIInfoFromJSON(sample[1]); e->setUIInfo(t, uiinfo); } } }
void splitTile(const detail::vt_features& features, const uint8_t z, const uint32_t x, const uint32_t y, const uint8_t cz = 0, const uint32_t cx = 0, const uint32_t cy = 0) { const double z2 = 1u << z; const uint64_t id = toID(z, x, y); auto it = tiles.find(id); if (it == tiles.end()) { const double tolerance = (z == options.maxZoom ? 0 : options.tolerance / (z2 * options.extent)); it = tiles .emplace(id, detail::InternalTile{ features, z, x, y, options.extent, options.buffer, tolerance }) .first; stats[z] = (stats.count(z) ? stats[z] + 1 : 1); total++; // printf("tile z%i-%i-%i\n", z, x, y); } auto& tile = it->second; if (features.empty()) return; // stop tiling if the tile is solid clipped square if (!options.solidChildren && tile.is_solid) return; // if it's the first-pass tiling if (cz == 0u) { // stop tiling if we reached max zoom, or if the tile is too simple if (z == options.indexMaxZoom || tile.tile.num_points <= options.indexMaxPoints) { tile.source_features = features; return; } } else { // drilldown to a specific tile; // stop tiling if we reached base zoom if (z == options.maxZoom) return; // stop tiling if it's our target tile zoom if (z == cz) { tile.source_features = features; return; } // stop tiling if it's not an ancestor of the target tile const double m = 1u << (cz - z); if (x != static_cast<uint32_t>(std::floor(cx / m)) || y != static_cast<uint32_t>(std::floor(cy / m))) { tile.source_features = features; return; } } const double p = 0.5 * options.buffer / options.extent; const auto& min = tile.bbox.min; const auto& max = tile.bbox.max; const auto left = detail::clip<0>(features, (x - p) / z2, (x + 0.5 + p) / z2, min.x, max.x); splitTile(detail::clip<1>(left, (y - p) / z2, (y + 0.5 + p) / z2, min.y, max.y), z + 1, x * 2, y * 2, cz, cx, cy); splitTile(detail::clip<1>(left, (y + 0.5 - p) / z2, (y + 1 + p) / z2, min.y, max.y), z + 1, x * 2, y * 2 + 1, cz, cx, cy); const auto right = detail::clip<0>(features, (x + 0.5 - p) / z2, (x + 1 + p) / z2, min.x, max.x); splitTile(detail::clip<1>(right, (y - p) / z2, (y + 0.5 + p) / z2, min.y, max.y), z + 1, x * 2 + 1, y * 2, cz, cx, cy); splitTile(detail::clip<1>(right, (y + 0.5 - p) / z2, (y + 1 + p) / z2, min.y, max.y), z + 1, x * 2 + 1, y * 2 + 1, cz, cx, cy); // if we sliced further down, no need to keep source geometry tile.source_features = {}; }