void free_unreachable_objects(bool report) { free_list_type free; { reachable_object_type m2; #ifdef BOOST_HAS_THREADS mutex_type::scoped_lock lock(get_mutex()); #endif arena_type const & m = get_map(); find_unreachable_objects_impl(m, m2, report); for(reachable_object_type::iterator j = m2.begin(); j != m2.end(); ++j) { arena_type::const_iterator i = m.find(j->first); BOOST_ASSERT(i != m.end()); if (i->second.first) scan_and_free(i->second.first, i->second.second, m2, free); } } if (report) std::cout << "... about to free " << free.size() << " objects.\n"; }
void display(void) { t_listd *lst; lst = get_map(0); map(lst); }
std::size_t find_unreachable_objects(bool report) { reachable_object_type m2; #ifdef BOOST_HAS_THREADS // This will work without the #ifdef, but some compilers warn // that lock is not referenced mutex_type::scoped_lock lock(get_mutex()); #endif arena_type const & m = get_map(); find_unreachable_objects_impl(m, m2, report); if(report) { for(reachable_object_type::iterator j = m2.begin(); j != m2.end(); ++j) { arena_type::const_iterator i = m.find(j->first); BOOST_ASSERT(i != m.end()); std::cout << "Unreachable object at " << i->second.first << ", " << i->second.second << " bytes long.\n"; } } return m2.size(); }
void editor_display::draw_sidebar() { config element; config::attribute_value &text = element.add_child("element")["text"]; // Fill in the terrain report if (get_map().on_board_with_border(mouseoverHex_)) { text = get_map().get_terrain_editor_string(mouseoverHex_); refresh_report("terrain", element); text = str_cast(mouseoverHex_); refresh_report("position", element); } text = int(get_map().villages().size()); refresh_report("villages", element); text = toolbar_hint_; refresh_report("editor_tool_hint", element); }
/** * \brief Gives the item to the player. */ void Pickable::try_give_item_to_player() { EquipmentItem& item = treasure.get_item(); if (!can_be_picked || given_to_player || get_game().is_dialog_enabled() || !get_hero().can_pick_treasure(item)) { return; } given_to_player = true; remove_from_map(); // play the sound const std::string& sound_id = item.get_sound_when_picked(); if (!sound_id.empty()) { Sound::play(sound_id); } // give the item if (item.get_brandish_when_picked()) { // The treasure is brandished. // on_obtained() will be called after the dialog. get_hero().start_treasure(treasure, LUA_REFNIL); } else { treasure.give_to_player(); // Call on_obtained() immediately since the treasure is not brandished. get_lua_context().item_on_obtained(item, treasure); get_lua_context().map_on_obtained_treasure(get_map(), treasure); } }
/** * \brief Draws the entity on the map. */ void Hookshot::draw_on_map() { static constexpr int nb_links = 7; static constexpr Point dxy[] = { { 16, -5 }, { 0, -13 }, { -16, -5 }, { 0, 7 } }; if (!is_drawn()) { return; } MapEntity::draw_on_map(); // also draw the links int direction = get_sprite().get_current_direction(); int x1 = get_hero().get_x() + dxy[direction].x; int y1 = get_hero().get_y() + dxy[direction].y; int x2 = get_x(); int y2 = get_y() - 5; Point link_xy; for (int i = 0; i < nb_links; i++) { link_xy.x = x1 + (x2 - x1) * i / nb_links; link_xy.y = y1 + (y2 - y1) * i / nb_links; get_map().draw_sprite(*link_sprite, link_xy); } }
/** * nm_setting_vlan_add_priority_str: * @setting: the #NMSettingVlan * @map: the type of priority map * @str: the string which contains a priority map, like "3:7" * * Adds a priority map entry into either the #NMSettingVlan:ingress_priority_map * or the #NMSettingVlan:egress_priority_map properties. The priority map maps * the Linux SKB priorities to 802.1p priorities. * * Returns: TRUE if the entry was successfully added to the list, or it * overwrote the old value, FALSE if error */ gboolean nm_setting_vlan_add_priority_str (NMSettingVlan *setting, NMVlanPriorityMap map, const char *str) { NMSettingVlanPrivate *priv = NULL; GSList *list = NULL, *iter = NULL; PriorityMap *item = NULL; g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), FALSE); g_return_val_if_fail (map == NM_VLAN_INGRESS_MAP || map == NM_VLAN_EGRESS_MAP, FALSE); g_return_val_if_fail (str && str[0], FALSE); priv = NM_SETTING_VLAN_GET_PRIVATE (setting); list = get_map (setting, map); item = priority_map_new_from_str (map, str); g_return_val_if_fail (item != NULL, FALSE); /* Duplicates get replaced */ for (iter = list; iter; iter = g_slist_next (iter)) { PriorityMap *p = iter->data; if (p->from == item->from) { p->to = item->to; g_free (item); return TRUE; } } set_map (setting, map, g_slist_append (list, item)); return TRUE; }
void _nm_setting_vlan_get_priorities (NMSettingVlan *setting, NMVlanPriorityMap map, NMVlanQosMapping **out_qos_map, guint *out_n_qos_map) { GSList *list; NMVlanQosMapping *qos_map = NULL; guint n_qos_map, i; list = get_map (setting, map); n_qos_map = g_slist_length (list); if (n_qos_map > 0) { qos_map = g_new (NMVlanQosMapping, n_qos_map); for (i = 0; list; i++, list = list->next) { nm_assert (i < n_qos_map); qos_map[i] = *((const NMVlanQosMapping *) list->data); } } *out_qos_map = qos_map; *out_n_qos_map = n_qos_map; }
/** * \brief Draws the tile on the map. */ void DynamicTile::draw_on_map() { if (!is_drawn()) { return; } const Rectangle& camera_position = get_map().get_camera_position(); Rectangle dst(0, 0); Rectangle dst_position(get_top_left_x() - camera_position.get_x(), get_top_left_y() - camera_position.get_y(), get_width(), get_height()); tile_pattern->fill_surface(get_map().get_visible_surface(), dst_position, get_map().get_tileset(), camera_position); }
/** * nm_setting_vlan_add_priority: * @setting: the #NMSettingVlan * @map: the type of priority map * @from: the priority to map to @to * @to: the priority to map @from to * * Adds a priority mapping to the #NMSettingVlan:ingress_priority_map or * #NMSettingVlan:egress_priority_map properties of the setting. If @from is * already in the given priority map, this function will overwrite the * existing entry with the new @to. * * If @map is #NM_VLAN_INGRESS_MAP then @from is the incoming 802.1q VLAN * Priority Code Point (PCP) value, and @to is the Linux SKB priority value. * * If @map is #NM_VLAN_EGRESS_MAP then @from is the Linux SKB priority value and * @to is the outgoing 802.1q VLAN Priority Code Point (PCP) value. * * Returns: %TRUE if the new priority mapping was successfully added to the * list, %FALSE if error */ gboolean nm_setting_vlan_add_priority (NMSettingVlan *setting, NMVlanPriorityMap map, guint32 from, guint32 to) { GSList *list = NULL; NMVlanQosMapping *item; g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), FALSE); g_return_val_if_fail (map == NM_VLAN_INGRESS_MAP || map == NM_VLAN_EGRESS_MAP, FALSE); list = get_map (setting, map); if (check_replace_duplicate_priority (list, from, to)) { if (map == NM_VLAN_INGRESS_MAP) g_object_notify (G_OBJECT (setting), NM_SETTING_VLAN_INGRESS_PRIORITY_MAP); else g_object_notify (G_OBJECT (setting), NM_SETTING_VLAN_EGRESS_PRIORITY_MAP); return TRUE; } item = g_malloc0 (sizeof (NMVlanQosMapping)); item->from = from; item->to = to; set_map (setting, map, g_slist_insert_sorted (list, item, prio_map_compare)); return TRUE; }
/** * \brief Returns control to the hero after its hookshot movement. * * This function is called when the hero has finished the hookshot movement. * It checks the validity of the destination position. */ void Hero::HookshotState::finish_movement() { Hero& hero = get_hero(); const Rectangle& hero_position = hero.get_bounding_box(); Layer layer = hero.get_layer(); Map& map = get_map(); MapEntities& entities = get_entities(); if (layer == LAYER_LOW || !map.has_empty_ground(layer, hero_position)) { // the hero is totally on the same layer: no problem hero.start_state_from_ground(); } else { // a part of the hero is on empty tiles: this is often illegal, especially // if there are jumpers; allow this only if tiles on // the lower layer are not obstacles, and go to this layer layer = Layer(layer - 1); if (!map.test_collision_with_obstacles(layer, hero_position, hero)) { Sound::play("hero_lands"); entities.set_entity_layer(hero, layer); hero.start_state_from_ground(); } else { // illegal position: get back to the start point // TODO: get back to the closest valid point from the destination instead Sound::play("hero_hurt"); hero.set_state(new BackToSolidGroundState(hero, false, 0, true)); } } }
/** * nm_setting_vlan_add_priority_str: * @setting: the #NMSettingVlan * @map: the type of priority map * @str: the string which contains a priority map, like "3:7" * * Adds a priority map entry into either the #NMSettingVlan:ingress_priority_map * or the #NMSettingVlan:egress_priority_map properties. The priority map maps * the Linux SKB priorities to 802.1p priorities. * * Returns: %TRUE if the entry was successfully added to the list, or it * overwrote the old value, %FALSE if error */ gboolean nm_setting_vlan_add_priority_str (NMSettingVlan *setting, NMVlanPriorityMap map, const char *str) { GSList *list = NULL; NMVlanQosMapping *item = NULL; g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), FALSE); g_return_val_if_fail (map == NM_VLAN_INGRESS_MAP || map == NM_VLAN_EGRESS_MAP, FALSE); g_return_val_if_fail (str && str[0], FALSE); list = get_map (setting, map); item = priority_map_new_from_str (map, str); if (!item) g_return_val_if_reached (FALSE); /* Duplicates get replaced */ if (check_replace_duplicate_priority (list, item->from, item->to)) { g_free (item); if (map == NM_VLAN_INGRESS_MAP) g_object_notify (G_OBJECT (setting), NM_SETTING_VLAN_INGRESS_PRIORITY_MAP); else g_object_notify (G_OBJECT (setting), NM_SETTING_VLAN_EGRESS_PRIORITY_MAP); return TRUE; } set_map (setting, map, g_slist_insert_sorted (list, item, prio_map_compare)); return TRUE; }
int main(void) { t_env env; int x; x = -1; init_env(&env); get_player(&env); while (1) { get_map(&env); get_piece(&env); if (contact_play(&env, 0, 0) != 1) { if (play(&env, 0, 0) != 1) { if (simple_play(&env) != 1) { ft_putstr("0 0\n"); break ; } } } free_all(&env); } return (0); }
/** * nm_setting_vlan_add_priority: * @setting: the #NMSettingVlan * @map: the type of priority map * @from: the priority to map to @to * @to: the priority to map @from to * * Adds a priority mapping to the #NMSettingVlan:ingress_priority_map or * #NMSettingVlan:egress_priority_map properties of the setting. If @from is * already in the given priority map, this function will overwrite the * existing entry with the new @to. * * If @map is #NM_VLAN_INGRESS_MAP then @from is the incoming 802.1q VLAN * Priority Code Point (PCP) value, and @to is the Linux SKB priority value. * * If @map is #NM_VLAN_EGRESS_MAP then @from is the Linux SKB priority value and * @to is the outgoing 802.1q VLAN Priority Code Point (PCP) value. * * Returns: TRUE if the new priority mapping was successfully added to the * list, FALSE if error */ gboolean nm_setting_vlan_add_priority (NMSettingVlan *setting, NMVlanPriorityMap map, guint32 from, guint32 to) { GSList *list = NULL, *iter = NULL; PriorityMap *item; g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), FALSE); g_return_val_if_fail (map == NM_VLAN_INGRESS_MAP || map == NM_VLAN_EGRESS_MAP, FALSE); list = get_map (setting, map); for (iter = list; iter; iter = g_slist_next (iter)) { item = iter->data; if (item->from == from) { item->to = to; return TRUE; } } item = g_malloc0 (sizeof (PriorityMap)); item->from = from; item->to = to; set_map (setting, map, g_slist_append (list, item)); return TRUE; }
/* * Add a new rule to the list. Copy the rule into a malloc'ed area, then * possibly create a rule number and add the rule to the list. * Update the rule_number in the input struct so the caller knows it as well. * XXX DO NOT USE FOR THE DEFAULT RULE. * Must be called without IPFW_UH held */ int ipfw_add_rule(struct ip_fw_chain *chain, struct ip_fw *input_rule) { struct ip_fw *rule; int i, l, insert_before; struct ip_fw **map; /* the new array of pointers */ if (chain->rules == NULL || input_rule->rulenum > IPFW_DEFAULT_RULE-1) return (EINVAL); l = RULESIZE(input_rule); rule = malloc(l, M_IPFW, M_WAITOK | M_ZERO); if (rule == NULL) return (ENOSPC); /* get_map returns with IPFW_UH_WLOCK if successful */ map = get_map(chain, 1, 0 /* not locked */); if (map == NULL) { free(rule, M_IPFW); return ENOSPC; } bcopy(input_rule, rule, l); /* clear fields not settable from userland */ rule->x_next = NULL; rule->next_rule = NULL; rule->pcnt = 0; rule->bcnt = 0; rule->timestamp = 0; if (V_autoinc_step < 1) V_autoinc_step = 1; else if (V_autoinc_step > 1000) V_autoinc_step = 1000; /* find the insertion point, we will insert before */ insert_before = rule->rulenum ? rule->rulenum + 1 : IPFW_DEFAULT_RULE; i = ipfw_find_rule(chain, insert_before, 0); /* duplicate first part */ if (i > 0) bcopy(chain->map, map, i * sizeof(struct ip_fw *)); map[i] = rule; /* duplicate remaining part, we always have the default rule */ bcopy(chain->map + i, map + i + 1, sizeof(struct ip_fw *) *(chain->n_rules - i)); if (rule->rulenum == 0) { /* write back the number */ rule->rulenum = i > 0 ? map[i-1]->rulenum : 0; if (rule->rulenum < IPFW_DEFAULT_RULE - V_autoinc_step) rule->rulenum += V_autoinc_step; input_rule->rulenum = rule->rulenum; } rule->id = chain->id + 1; map = swap_map(chain, map, chain->n_rules + 1); chain->static_len += l; IPFW_UH_WUNLOCK(chain); if (map) free(map, M_IPFW); return (0); }
void sp_scalar_constructor_hook(void * px, std::size_t size, void * pn) { #ifdef BOOST_HAS_THREADS mutex_type::scoped_lock lock(get_mutex()); #endif get_map()[pn] = std::make_pair(px, size); }
void sp_scalar_destructor_hook(void *, std::size_t, void * pn) { #ifdef BOOST_HAS_THREADS mutex_type::scoped_lock lock(get_mutex()); #endif get_map().erase(pn); }
/** * \copydoc Entity::notify_layer_changed */ void Detector::notify_layer_changed() { // Since this entity is a detector, all entities need to check // their collisions with it. get_map().check_collision_from_detector(*this); Entity::notify_layer_changed(); }
/** * \brief Draws the carried item on the map. * * This is a redefinition of Entity::draw_on_map() * to draw the shadow independently of the item movement. */ void CarriedItem::draw_on_map() { if (!is_drawn()) { return; } if (!is_throwing) { // draw the sprite normally Entity::draw_on_map(); } else { // when the item is being thrown, draw the shadow and the item separately // TODO: this could probably be simplified by using a JumpMovement get_map().draw_sprite(*shadow_sprite, get_xy()); get_map().draw_sprite(get_sprite(), get_x(), get_y() - item_height); } }
/* * Pick a random mapping, and perform some r/w op on it. * Called from child on child init, and also periodically * from periodic_work() */ void dirty_random_mapping(void) { struct map *map; map = get_map(); dirty_mapping(map); }
/** * \brief Returns whether the arrow has just hit the map border. * \return true if the arrow has just hit the map border */ bool Arrow::has_reached_map_border() const { if (get_sprite().get_current_animation() != "flying" || get_movement() == NULL) { return false; } return get_map().test_collision_with_border(get_movement()->get_last_collision_box_on_obstacle()); }
void MapEntity::display_on_map() { Map& map = get_map(); std::list<Sprite*>::iterator it; for(it = sprites.begin(); it != sprites.end(); it++) { Sprite& sprite = *(*it); map.display_sprite(sprite, get_displayed_xy()); } }
/** * nm_setting_vlan_get_num_priorities: * @map: the type of priority map * @setting: the #NMSettingVlan * * Returns the number of entires in the * #NMSettingVlan:ingress_priority_map or #NMSettingVlan:egress_priority_map * properties of this setting. * * Returns: return the number of ingress/egress priority entries, -1 if error **/ gint32 nm_setting_vlan_get_num_priorities (NMSettingVlan *setting, NMVlanPriorityMap map) { g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), -1); g_return_val_if_fail (map == NM_VLAN_INGRESS_MAP || map == NM_VLAN_EGRESS_MAP, -1); return g_slist_length (get_map (setting, map)); }
/** * @brief Displays the entity on the map. * * This is a redefinition of MapEntity::display_on_map() to also display the twinkling star * which has a special position. */ void CrystalSwitch::display_on_map() { // display the crystal switch MapEntity::display_on_map(); // display the star get_map().display_sprite(*star_sprite, get_top_left_x() + star_xy.get_x(), get_top_left_y() + star_xy.get_y()); }
void game_display::display_unit_hex(map_location hex) { unit_map::const_iterator u = find_visible_unit(units_, hex, get_map(), teams_, teams_[viewing_team()], !viewpoint_); if (u != units_.end()) { displayedUnitHex_ = hex; invalidate_unit(); } }
int get_user_num_in_ship_cmd(sprite_t* p, const uint8_t* body, int bodylen) { CHECK_VALID_ID(p->id); map_t* mp = get_map(72); response_proto_uint32(p, p->waitcmd, mp->sprite_num, 0); return 0; }
int get_map_value(void) { int rslt; int i; int j; rslt = 0; i = -1; while (++i < get_map()->height) { j = -1; while (++j < get_map()->width) { rslt += get_cell_value(i, j); } } return (rslt); }
/** * \brief Draws the tile on the specified surface. * \param dst_surface the destination surface * \param viewport coordinates of the top-left corner of dst_surface * relative to the map */ void Tile::draw(Surface& dst_surface, const Rectangle& viewport) { Rectangle dst_position(get_top_left_x() - viewport.get_x(), get_top_left_y() - viewport.get_y(), get_width(), get_height()); tile_pattern->fill_surface(dst_surface, dst_position, get_map().get_tileset(), viewport); }
/** * \brief Draws the tile on the map. */ void DynamicTile::draw_on_map() { const CameraPtr& camera = get_map().get_camera(); if (camera == nullptr) { return; } const Rectangle& camera_position = camera->get_bounding_box(); Rectangle dst_position(get_top_left_x() - camera_position.get_x(), get_top_left_y() - camera_position.get_y(), get_width(), get_height()); tile_pattern.fill_surface( get_map().get_camera_surface(), dst_position, get_map().get_tileset(), camera_position.get_xy() ); }
gboolean _nm_setting_vlan_set_priorities (NMSettingVlan *setting, NMVlanPriorityMap map, const NMVlanQosMapping *qos_map, guint n_qos_map) { gboolean has_changes = FALSE; GSList *map_prev, *map_new; guint i; gint64 from_last; map_prev = get_map (setting, map); if (n_qos_map != g_slist_length (map_prev)) has_changes = TRUE; else { const GSList *iter; iter = map_prev; for (i = 0; i < n_qos_map; i++, iter = iter->next) { const NMVlanQosMapping *m = iter->data; if ( m->from != qos_map[i].from || m->to != qos_map[i].to) { has_changes = TRUE; break; } } } if (!has_changes) return FALSE; map_new = NULL; from_last = G_MAXINT64; for (i = n_qos_map; i > 0;) { const NMVlanQosMapping *m = &qos_map[--i]; NMVlanQosMapping *item; /* We require the array to be presorted. */ if (m->from >= from_last) g_return_val_if_reached (FALSE); from_last = m->from; item = g_malloc0 (sizeof (NMVlanQosMapping)); item->from = m->from; item->to = m->to; map_new = g_slist_prepend (map_new, item); } g_slist_free_full (map_prev, g_free); set_map (setting, map, map_new); return TRUE; }