本文整理汇总了C++中const_entity_handle类的典型用法代码示例。如果您正苦于以下问题:C++ const_entity_handle类的具体用法?C++ const_entity_handle怎么用?C++ const_entity_handle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了const_entity_handle类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: interpolation
std::optional<transformr> interpolation_system::find_interpolated(const const_entity_handle handle) const {
const auto id = handle.get_id();
auto result = [&]() -> std::optional<transformr> {
if (enabled) {
if (const auto cache = mapped_or_nullptr(per_entity_cache, id)) {
return cache->interpolated_transform;
}
}
return handle.find_logic_transform();
}();
/*
Here, we integerize the transform of the viewed entity, (and later possibly of the vehicle that it drives)
so that the rendered player does not shake when exactly followed by the camera,
which is also integerized for pixel-perfect rendering.
Ideally we shouldn't do it here because it introduces more state, but that's about the simplest solution
that doesn't make a mess out of rendering scripts for this special case.
Additionally, if someone does not use interpolation (there should be no need to disable it, really)
they will still suffer from the problem of shaky controlled player. We don't have time for now to handle it better.
*/
if (id == id_to_integerize) {
if (result) {
result->pos.discard_fract();
}
}
return result;
}
开发者ID:TeamHypersomnia,项目名称:Augmentations,代码行数:33,代码来源:interpolation_system.cpp
示例2: drag_mispredictions_into_past
void simulation_receiver::drag_mispredictions_into_past(interpolation_system& interp, past_infection_system& past, const cosmos& predicted_cosmos, const std::vector<misprediction_candidate_entry>& mispredictions) const {
for (const auto e : mispredictions) {
const const_entity_handle reconciliated_entity = predicted_cosmos[e.id];
const bool identity_matches = reconciliated_entity.alive() && reconciliated_entity.has_logic_transform();
if (!identity_matches)
continue;
const auto& reconciliated_transform = reconciliated_entity.logic_transform();
const bool is_contagious_agent = reconciliated_entity.get_flag(entity_flag::IS_PAST_CONTAGIOUS);
const bool should_smooth_rotation = !is_contagious_agent || predicted_cosmos[reconciliated_entity.get<components::driver>().owned_vehicle].alive();
auto& interp_data = interp.get_data(reconciliated_entity);
const bool shouldnt_smooth = reconciliated_entity.has<components::crosshair>();
bool misprediction_detected = false;
const float num_predicted_steps = static_cast<float>(predicted_steps.size());
if (!shouldnt_smooth && (reconciliated_transform.pos - e.transform.pos).length_sq() > 1.f) {
interp_data.positional_slowdown_multiplier = std::max(1.f, misprediction_smoothing_multiplier * num_predicted_steps);
misprediction_detected = true;
}
if (should_smooth_rotation && std::abs(reconciliated_transform.rotation - e.transform.rotation) > 1.f) {
interp_data.rotational_slowdown_multiplier = std::max(1.f, misprediction_smoothing_multiplier * num_predicted_steps);
misprediction_detected = true;
}
if (identity_matches || (!misprediction_detected && !is_contagious_agent)) {
past.uninfect(reconciliated_entity);
}
}
}
开发者ID:,项目名称:,代码行数:35,代码来源:
示例3: acquire_potential_misprediction
simulation_receiver::misprediction_candidate_entry simulation_receiver::acquire_potential_misprediction(const const_entity_handle& e) const {
misprediction_candidate_entry candidate;
if(e.has_logic_transform())
candidate.transform = e.logic_transform();
candidate.id = e.get_id();
return candidate;
}
开发者ID:,项目名称:,代码行数:10,代码来源:
示例4: assess_danger
identified_danger assess_danger(
const const_entity_handle& victim,
const const_entity_handle& danger
) {
identified_danger result;
const auto* const sentience = victim.find<components::sentience>();
if (!sentience) {
return result;
}
result.danger = danger;
const auto* const missile = danger.find<invariants::missile>();
const auto* const attitude = danger.find<components::attitude>();
if ((!missile && !attitude) || (missile && danger.get<components::sender>().is_sender_subject(victim))) {
return result;
}
const auto victim_pos = victim.get_logic_transform().pos;
const auto danger_pos = danger.get_logic_transform().pos;
const auto danger_vel = danger.get_owner_of_colliders().get_effective_velocity();
const auto danger_dir = (danger_pos - victim_pos);
const auto danger_distance = danger_dir.length();
result.recommended_evasion = augs::danger_avoidance(victim_pos, danger_pos, danger_vel);
result.recommended_evasion.normalize();
const auto& sentience_def = victim.get<invariants::sentience>();
const auto comfort_zone = sentience_def.comfort_zone;
const auto comfort_zone_disturbance_ratio = augs::disturbance(danger_distance, comfort_zone);
if (missile) {
result.amount += comfort_zone_disturbance_ratio * missile->damage.base*4;
}
if (attitude) {
const auto att = calc_attitude(danger, victim);
if (is_hostile(att)) {
result.amount += comfort_zone_disturbance_ratio * sentience_def.danger_amount_from_hostile_attitude;
}
}
return result;
}
开发者ID:TeamHypersomnia,项目名称:Augmentations,代码行数:48,代码来源:entity_scripts.cpp
示例5: destruct
void physics_system::destruct(const const_entity_handle handle) {
if (is_constructed_rigid_body(handle)) {
auto& cache = get_rigid_body_cache(handle);
for (const auto& colliders_cache_id : cache.correspondent_colliders_caches)
colliders_caches[colliders_cache_id] = colliders_cache();
b2world->DestroyBody(cache.body);
cache = rigid_body_cache();
}
if (is_constructed_colliders(handle)) {
const auto this_cache_id = handle.get_id().pool.indirection_index;
auto& cache = colliders_caches[this_cache_id];
ensure(cache.correspondent_rigid_body_cache != -1);
auto& owner_body_cache = rigid_body_caches[cache.correspondent_rigid_body_cache];
for (const auto& f_per_c : cache.fixtures_per_collider)
for (const auto f : f_per_c)
owner_body_cache.body->DestroyFixture(f);
remove_element(owner_body_cache.correspondent_colliders_caches, this_cache_id);
cache = colliders_cache();
}
}
开发者ID:,项目名称:,代码行数:28,代码来源:
示例6: spread_past_infection
void viewing_session::spread_past_infection(const const_logic_step step) {
const auto& cosm = step.cosm;
const auto& events = step.transient.messages.get_queue<messages::collision_message>();
for (const auto& it : events) {
const const_entity_handle subject_owner_body = cosm[it.subject].get_owner_body();
const const_entity_handle collider_owner_body = cosm[it.collider].get_owner_body();
auto& past_system = systems_audiovisual.get<past_infection_system>();
if (past_system.is_infected(subject_owner_body) && !collider_owner_body.get_flag(entity_flag::IS_IMMUNE_TO_PAST)) {
past_system.infect(collider_owner_body);
}
}
}
开发者ID:,项目名称:,代码行数:16,代码来源:
示例7: is_constructed_colliders
bool physics_system::is_constructed_colliders(const const_entity_handle handle) const {
return
handle.alive() // && is_constructed_rigid_body(handle.get<components::fixtures>().get_owner_body())
&&
get_colliders_cache(handle).fixtures_per_collider.size()> 0 &&
get_colliders_cache(handle).fixtures_per_collider[0].size() > 0;
}
开发者ID:,项目名称:,代码行数:7,代码来源:
示例8: set_updated_interpolated_transform
void interpolation_system::set_updated_interpolated_transform(
const const_entity_handle subject,
const transformr updated_value
) {
auto& cache = per_entity_cache[subject];
const auto& info = subject.get<components::interpolation>();
cache.recorded_place_of_birth = info.place_of_birth;
cache.interpolated_transform = updated_value;
cache.recorded_version = subject.get_id().raw.version;
}
开发者ID:TeamHypersomnia,项目名称:Augmentations,代码行数:11,代码来源:interpolation_system.cpp
示例9: assess_projectile_velocity_of_weapon
real32 assess_projectile_velocity_of_weapon(const const_entity_handle& weapon) {
if (weapon.dead()) {
return 0.f;
}
if (const auto* const gun_def = weapon.find<invariants::gun>()) {
// TODO: Take into consideration the missile invariant found in the chamber
return (gun_def->muzzle_velocity.first + gun_def->muzzle_velocity.second) / 2;
}
return 0.f;
}
开发者ID:TeamHypersomnia,项目名称:Augmentations,代码行数:12,代码来源:entity_scripts.cpp
示例10: assign_item_to_hotbar_button
void gui_element::assign_item_to_hotbar_button(
const size_t button_index,
const entity_handle element_entity,
const const_entity_handle item
) {
clear_hotbar_selection_for_item(element_entity, item);
ensure(item.get_owning_transfer_capability() == element_entity);
auto& element = element_entity.get<components::gui_element>();
element.hotbar_buttons[button_index].last_assigned_entity = item;
LOG_NVPS(button_index);
}
开发者ID:,项目名称:,代码行数:13,代码来源:
示例11: make_pair
std::pair<size_t, size_t> physics_system::map_fixture_pointer_to_indices(const b2Fixture* const f, const const_entity_handle& handle) {
const auto this_cache_id = handle.get_id().pool.indirection_index;
const auto& cache = colliders_caches[this_cache_id];
for (size_t collider_index = 0; collider_index < cache.fixtures_per_collider.size(); ++collider_index) {
for (size_t convex_index = 0; convex_index < cache.fixtures_per_collider[collider_index].size(); ++convex_index) {
if (cache.fixtures_per_collider[collider_index][convex_index] == f) {
return std::make_pair(collider_index, convex_index);
}
}
}
ensure(false);
return{};
}
开发者ID:,项目名称:,代码行数:15,代码来源:
示例12: calculate_space_occupied_with_children
unsigned calculate_space_occupied_with_children(const const_entity_handle item) {
auto space_occupied = item.get<components::item>().get_space_occupied();
if (item.find<components::container>()) {
ensure(item.get<components::item>().charges == 1);
for (auto& slot : item.get<components::container>().slots) {
for (auto& entity_in_slot : slot.second.items_inside) {
space_occupied += calculate_space_occupied_with_children(item.get_cosmos()[entity_in_slot]);
}
}
}
return space_occupied;
}
开发者ID:,项目名称:,代码行数:15,代码来源:
示例13: get_attachment_offset
components::transform get_attachment_offset(
const inventory_slot& slot,
const components::transform container_transform,
const const_entity_handle item
) {
ensure(slot.is_physical_attachment_slot);
components::transform total;
const auto sticking = slot.attachment_sticking_mode;
total = slot.attachment_offset;
total.pos += item.get_aabb(components::transform()).get_size().get_sticking_offset(sticking);
total.pos.rotate(container_transform.rotation, vec2(0, 0));
return total;
}
开发者ID:,项目名称:,代码行数:17,代码来源:
示例14: construct
void physics_system::construct(const const_entity_handle handle) {
//ensure(!is_constructed_rigid_body(handle));
if (is_constructed_rigid_body(handle))
return;
fixtures_construct(handle);
if (handle.has<components::physics>()) {
const auto& physics = handle.get<components::physics>();
const auto& fixture_entities = physics.get_fixture_entities();
if (physics.is_activated() && fixture_entities.size() > 0) {
const auto& physics_data = physics.get_data();
auto& cache = get_rigid_body_cache(handle);
b2BodyDef def;
switch (physics_data.body_type) {
case components::physics::type::DYNAMIC: def.type = b2BodyType::b2_dynamicBody; break;
case components::physics::type::STATIC: def.type = b2BodyType::b2_staticBody; break;
case components::physics::type::KINEMATIC: def.type = b2BodyType::b2_kinematicBody; break;
default:ensure(false) break;
}
def.userData = handle.get_id();
def.bullet = physics_data.bullet;
def.transform = physics_data.transform;
def.sweep = physics_data.sweep;
def.angularDamping = physics_data.angular_damping;
def.linearDamping = physics_data.linear_damping;
def.fixedRotation = physics_data.fixed_rotation;
def.gravityScale = physics_data.gravity_scale;
def.active = true;
def.linearVelocity = physics_data.velocity;
def.angularVelocity = physics_data.angular_velocity;
cache.body = b2world->CreateBody(&def);
cache.body->SetAngledDampingEnabled(physics_data.angled_damping);
/* notice that all fixtures must be unconstructed at this moment since we assert that the rigid body itself is not */
for (const auto& f : fixture_entities)
fixtures_construct(f);
}
}
}
开发者ID:,项目名称:,代码行数:45,代码来源:
示例15: calc_reloadable_ammo_info
ammunition_information calc_reloadable_ammo_info(const const_entity_handle item) {
ammunition_information out;
const auto maybe_magazine_slot = item[slot_function::GUN_DETACHABLE_MAGAZINE];
if (maybe_magazine_slot.alive() && maybe_magazine_slot.has_items()) {
const auto mag = item.get_cosmos()[maybe_magazine_slot.get_items_inside()[0]];
const auto ammo_depo = mag[slot_function::ITEM_DEPOSIT];
ensure(ammo_depo->has_limited_space());
out.total_charges += count_charges_in_deposit(mag);
out.total_ammo_space += ammo_depo->space_available;
out.available_ammo_space += ammo_depo.calc_local_space_available();
}
return out;
}
开发者ID:TeamHypersomnia,项目名称:Augmentations,代码行数:18,代码来源:entity_scripts.cpp
示例16: get_closest_hostile
entity_id get_closest_hostile(
const const_entity_handle subject,
const const_entity_handle subject_attitude,
const real32 radius,
const b2Filter filter
) {
const auto& cosm = subject.get_cosmos();
const auto si = cosm.get_si();
const auto& physics = cosm.get_solvable_inferred().physics;
const auto transform = subject.get_logic_transform();
entity_id closest_hostile;
auto min_distance = std::numeric_limits<real32>::max();
if (subject_attitude.alive()) {
const auto subject_attitude_transform = subject_attitude.get_logic_transform();
physics.for_each_in_aabb(
si,
transform.pos - vec2(radius, radius),
transform.pos + vec2(radius, radius),
filter,
[&](const b2Fixture& fix) {
const const_entity_handle s = cosm[get_body_entity_that_owns(fix)];
if (s != subject && s.has<components::attitude>() && !sentient_and_unconscious(s)) {
const auto calculated_attitude = calc_attitude(s, subject_attitude);
if (is_hostile(calculated_attitude)) {
const auto dist = (s.get_logic_transform().pos - subject_attitude_transform.pos).length_sq();
if (dist < min_distance) {
closest_hostile = s;
min_distance = dist;
}
}
}
return callback_result::CONTINUE;
}
);
}
return closest_hostile;
}
开发者ID:TeamHypersomnia,项目名称:Augmentations,代码行数:47,代码来源:entity_scripts.cpp
示例17: standard_confirm_go_to
void standard_confirm_go_to(const const_entity_handle match, const bool has_ctrl, editor_view& view, editor_view_ids& view_ids) {
/* Confirm selection with quick search */
if (match) {
if (has_ctrl) {
view_ids.selected_entities.emplace(match);
}
else {
view_ids.selected_entities = { match };
}
if (!view.panned_camera.has_value()) {
view.panned_camera = camera_eye();
}
if (const auto transform = match.find_logic_transform()) {
view.panned_camera->transform.pos = transform->pos;
}
else {
LOG("WARNING: transform of %x could not be found.", match);
}
}
}
开发者ID:TeamHypersomnia,项目名称:Augmentations,代码行数:23,代码来源:editor_go_to_gui.cpp
示例18: get_closest_hostiles
std::vector<entity_id> get_closest_hostiles(
const const_entity_handle subject,
const const_entity_handle subject_attitude,
const real32 radius,
const b2Filter filter
) {
const auto& cosm = subject.get_cosmos();
const auto si = cosm.get_si();
const auto& physics = cosm.get_solvable_inferred().physics;
const auto transform = subject.get_logic_transform();
struct hostile_entry {
entity_id s;
real32 dist = 0.f;
bool operator<(const hostile_entry& b) const {
return dist < b.dist;
}
bool operator==(const hostile_entry& b) const {
return s == b.s;
}
operator entity_id() const {
return s;
}
};
std::vector<hostile_entry> hostiles;
if (subject_attitude.alive()) {
const auto subject_attitude_transform = subject_attitude.get_logic_transform();
physics.for_each_in_aabb(
si,
transform.pos - vec2(radius, radius),
transform.pos + vec2(radius, radius),
filter,
[&](const b2Fixture& fix) {
const const_entity_handle s = cosm[get_body_entity_that_owns(fix)];
if (s != subject && s.has<components::attitude>()) {
const auto calculated_attitude = calc_attitude(s, subject_attitude);
if (is_hostile(calculated_attitude)) {
const auto dist = (s.get_logic_transform().pos - subject_attitude_transform.pos).length_sq();
hostile_entry new_entry;
new_entry.s = s;
new_entry.dist = dist;
hostiles.push_back(new_entry);
}
}
return callback_result::CONTINUE;
}
);
}
sort_range(hostiles);
remove_duplicates_from_sorted(hostiles);
return { hostiles.begin(), hostiles.end() };
}
开发者ID:TeamHypersomnia,项目名称:Augmentations,代码行数:66,代码来源:entity_scripts.cpp
示例19: get_interpolated
components::transform interpolation_system::get_interpolated(const const_entity_handle id) const {
return enabled ? per_entity_cache[make_cache_id(id)].interpolated_transform : id.logic_transform();
}
开发者ID:,项目名称:,代码行数:3,代码来源:
示例20: draw_crosshair_lines
void draw_crosshair_lines(
std::function<void(vec2, vec2, rgba)> callback,
std::function<void(vec2, vec2)> dashed_line_callback,
const interpolation_system& interp,
const const_entity_handle crosshair,
const const_entity_handle character) {
if (crosshair.alive()) {
const auto& cosmos = crosshair.get_cosmos();
const auto& physics = cosmos.systems_temporary.get<physics_system>();
vec2 line_from[2];
vec2 line_to[2];
const auto crosshair_pos = crosshair.viewing_transform(interp).pos;
const auto guns = character.guns_wielded();
auto calculate_color = [&](const const_entity_handle target) {
const auto att = calculate_attitude(character, target);
if (att == attitude_type::WANTS_TO_KILL || att == attitude_type::WANTS_TO_KNOCK_UNCONSCIOUS) {
return red;
}
else if (att == attitude_type::WANTS_TO_HEAL) {
return green;
}
else {
return cyan;
}
};
if (guns.size() >= 1) {
const auto subject_item = guns[0];
const auto& gun = subject_item.get<components::gun>();
const auto rifle_transform = subject_item.viewing_transform(interp);
const auto barrel_center = gun.calculate_barrel_center(rifle_transform);
const auto muzzle = gun.calculate_muzzle_position(rifle_transform);
line_from[0] = muzzle;
const auto proj = crosshair_pos.get_projection_multiplier(barrel_center, muzzle);
if (proj > 1.f) {
line_to[0] = barrel_center + (muzzle - barrel_center) * proj;
const auto raycast = physics.ray_cast_px(line_from[0], line_to[0], filters::bullet(), subject_item);
auto col = cyan;
if (raycast.hit) {
dashed_line_callback(raycast.intersection, line_to[0]);
line_to[0] = raycast.intersection;
col = calculate_color(cosmos[raycast.what_entity]);
}
callback(line_from[0], line_to[0], col);
}
}
if (guns.size() >= 2) {
const auto subject_item = guns[1];
const auto& gun = subject_item.get<components::gun>();
const auto rifle_transform = subject_item.viewing_transform(interp);
const auto barrel_center = gun.calculate_barrel_center(rifle_transform);
const auto muzzle = gun.calculate_muzzle_position(rifle_transform);
line_from[1] = muzzle;
const auto proj = crosshair_pos.get_projection_multiplier(barrel_center, muzzle);
if (proj > 1.f) {
line_to[1] = barrel_center + (muzzle - barrel_center) * proj;
const auto raycast = physics.ray_cast_px(line_from[1], line_to[1], filters::bullet(), subject_item);
auto col = cyan;
if (raycast.hit) {
dashed_line_callback(raycast.intersection, line_to[1]);
line_to[1] = raycast.intersection;
col = calculate_color(cosmos[raycast.what_entity]);
}
callback(line_from[1], line_to[1], col);
}
}
}
}
开发者ID:,项目名称:,代码行数:94,代码来源:
注:本文中的const_entity_handle类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论