Example #1
0
void interpolation_system::integrate_interpolated_transforms(const cosmos& cosm, const augs::delta variable_delta, const augs::delta fixed_delta_for_slowdowns) {
	if (!enabled) {
		return;
	}
	
	const auto seconds = variable_delta.in_seconds();
	const float slowdown_multipliers_decrease = seconds / fixed_delta_for_slowdowns.in_seconds();

	for (const auto e : cosm.get(processing_subjects::WITH_INTERPOLATION)) {
		const auto& actual = e.logic_transform();
		const auto& info = e.get<components::interpolation>();
		auto& integrated = get_interpolated(e);
		auto& cache = per_entity_cache[make_cache_id(e)];

		const float considered_positional_speed = interpolation_speed / (sqrt(cache.positional_slowdown_multiplier));
		const float considered_rotational_speed = interpolation_speed / (sqrt(cache.rotational_slowdown_multiplier));

		if (cache.positional_slowdown_multiplier > 1.f) {
			cache.positional_slowdown_multiplier -= slowdown_multipliers_decrease / 4;

			if (cache.positional_slowdown_multiplier < 1.f) {
				cache.positional_slowdown_multiplier = 1.f;
			}
		}

		if (cache.rotational_slowdown_multiplier > 1.f) {
			cache.rotational_slowdown_multiplier -= slowdown_multipliers_decrease / 4;

			if (cache.rotational_slowdown_multiplier < 1.f) {
				cache.rotational_slowdown_multiplier = 1.f;
			}
		}

		const float positional_averaging_constant = 1.0f - static_cast<float>(pow(info.base_exponent, considered_positional_speed * seconds));
		const float rotational_averaging_constant = 1.0f - static_cast<float>(pow(info.base_exponent, considered_rotational_speed * seconds));

		auto& recorded_pob = cache.recorded_place_of_birth;
		auto& recorded_ver = cache.recorded_version;
		const auto& pob = info.place_of_birth;
		const auto& ver = e.get_id().pool.version;

		if (recorded_pob == pob && recorded_ver == ver) {
			integrated = actual.interpolated_separate(integrated, positional_averaging_constant, rotational_averaging_constant);
		}
		else {
			integrated = actual;
			recorded_pob = pob;
			recorded_ver = ver;
		}
	}
}
Example #2
0
void simulation_receiver::remote_entropy_predictions(guid_mapped_entropy& adjusted_entropy, const entity_id& predictable_entity, const cosmos& predicted_cosmos) {
	entity_intent release_intent;
	release_intent.is_pressed = false;

	for (auto e : predicted_cosmos.get(processing_subjects::WITH_PAST_CONTAGIOUS)) {
		const bool is_locally_controlled_entity = e == predictable_entity;
		
		if (is_locally_controlled_entity)
			continue;

		for (const auto g : e.guns_wielded()) {
			if (g.get<components::gun>().trigger_pressed) {
				if (g.get_current_slot().raw_id.type == slot_function::PRIMARY_HAND) {
					release_intent.intent = intent_type::CROSSHAIR_PRIMARY_ACTION;
				}
				else {
					release_intent.intent = intent_type::CROSSHAIR_SECONDARY_ACTION;
				}

				adjusted_entropy.entropy_per_entity[e.get_guid()].push_back(release_intent);
			}
		}
	}
}
Example #3
0
void movement_system::apply_movement_forces(cosmos& cosmos) {
	auto& physics_sys = cosmos.systems_temporary.get<physics_system>();
	const auto& delta = cosmos.get_fixed_delta();

	for (const auto& it : cosmos.get(processing_subjects::WITH_MOVEMENT)) {
		auto& movement = it.get<components::movement>();

		if (!movement.apply_movement_forces) {
			continue;
		}

		vec2 resultant;

		resultant.x = movement.moving_right * movement.input_acceleration_axes.x - movement.moving_left * movement.input_acceleration_axes.x;
		resultant.y = movement.moving_backward * movement.input_acceleration_axes.y - movement.moving_forward * movement.input_acceleration_axes.y;

		if (!it.has<components::physics>()) {
			it.get<components::transform>().pos += resultant * delta.in_seconds();
			continue;
		}

		const auto& physics = it.get<components::physics>();
		
		if (!physics.is_constructed())
			continue;

		if (movement.make_inert_for_ms > 0.f) {
			movement.make_inert_for_ms -= static_cast<float>(delta.in_milliseconds());
			physics.set_linear_damping(2);
		}
		else {
			physics.set_linear_damping(movement.sprint_enabled ? (movement.standard_linear_damping / 4.f) : movement.standard_linear_damping);
		}

		if (resultant.non_zero()) {
			if (movement.acceleration_length > 0) {
				resultant.set_length(movement.acceleration_length);
			}
			
			if (movement.make_inert_for_ms > 0.f) {
				resultant /= 10.f;
			}

			if (movement.sprint_enabled) {
				resultant /= 2.f;
			}
			
			if (movement.walking_enabled) {
				resultant /= 2.f;
			}

			physics.apply_force(resultant * physics.get_mass(), movement.applied_force_offset, true);
		}

		/* the player feels less like a physical projectile if we brake per-axis */
		if (movement.enable_braking_damping && !(movement.make_inert_for_ms > 0.f)) {
			physics.set_linear_damping_vec(vec2(
				resultant.x_non_zero() ? 0.f : movement.braking_damping,
				resultant.y_non_zero() ? 0.f : movement.braking_damping));
		}
		else {
			physics.set_linear_damping_vec(vec2(0, 0));
		}
	}
}