当前位置: 首页>>代码示例>>C++>>正文


C++ logic_step::get_delta方法代码示例

本文整理汇总了C++中logic_step::get_delta方法的典型用法代码示例。如果您正苦于以下问题:C++ logic_step::get_delta方法的具体用法?C++ logic_step::get_delta怎么用?C++ logic_step::get_delta使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在logic_step的用法示例。


在下文中一共展示了logic_step::get_delta方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: consume_melee_intents

void melee_system::consume_melee_intents(const logic_step step) {
	auto& cosmos = step.cosm;
	const auto& delta = step.get_delta();
	const auto& events = step.transient.messages.get_queue<messages::intent_message>();


	for (const auto& it : events) {
		/* 
			we search the whole intent message queue for events of interest;
			here we can even find gunshot requests for some distant enemy AI,
			therefore we need to filter out events we're interested in, and that would be
			melee-related intents and only these applied to an entity with a melee component
		*/
		auto* const maybe_melee = cosmos[it.subject].find<components::melee>();
		
		if (maybe_melee == nullptr) 
			continue;

		auto& melee = *maybe_melee;

		if (it.intent == intent_type::MELEE_PRIMARY_MOVE) {
			melee.primary_move_flag = it.is_pressed;
		}

		if (it.intent == intent_type::MELEE_SECONDARY_MOVE) {
			melee.secondary_move_flag = it.is_pressed;
		}
		
		if (it.intent == intent_type::MELEE_TERTIARY_MOVE) {
			melee.tertiary_move_flag = it.is_pressed;
		}
	}
}
开发者ID:,项目名称:,代码行数:33,代码来源:

示例2: lengthen_sprites_of_traces

void trace_system::lengthen_sprites_of_traces(logic_step& step) const {
	auto& cosmos = step.cosm;
	const auto delta = step.get_delta();

	for (const auto t : cosmos.get(processing_subjects::WITH_TRACE)) {
		auto& trace = t.get<components::trace>();
		auto& sprite = t.get<components::sprite>();

		if (trace.chosen_lengthening_duration_ms < 0.f) {
			trace.reset(cosmos.get_rng_for(t));
		}

		vec2 surplus_multiplier;
		
		if (!trace.is_it_finishing_trace) {
			surplus_multiplier = trace.chosen_multiplier * trace.lengthening_time_passed_ms / trace.chosen_lengthening_duration_ms;
		}
		else {
			surplus_multiplier = (trace.chosen_multiplier + vec2(1, 1)) * (1.f - (trace.lengthening_time_passed_ms / trace.chosen_lengthening_duration_ms)) - vec2(1, 1);
		}

		sprite.size_multiplier = vec2(1, 1) + surplus_multiplier;

		sprite.center_offset = sprite.size * (surplus_multiplier / 2.f);

		trace.lengthening_time_passed_ms += static_cast<float>(delta.in_milliseconds());
	}
}
开发者ID:,项目名称:,代码行数:28,代码来源:

示例3: step_and_set_new_transforms

void physics_system::step_and_set_new_transforms(logic_step& step) {
	auto& cosmos = step.cosm;
	const auto delta = step.get_delta();

	int32 velocityIterations = 8;
	int32 positionIterations = 3;

	ray_casts_since_last_step = 0;

	b2world->Step(static_cast<float32>(delta.in_seconds()), velocityIterations, positionIterations);

	post_and_clear_accumulated_collision_messages(step);

	for (b2Body* b = b2world->GetBodyList(); b != nullptr; b = b->GetNext()) {
		if (b->GetType() == b2_staticBody) continue;
		entity_handle entity = cosmos[b->GetUserData()];
		auto& physics = entity.get<components::physics>();

		recurential_friction_handler(step, b, b->m_ownerFrictionGround);

		physics.component.transform = b->m_xf;
		physics.component.sweep = b->m_sweep;
		physics.component.velocity = b->GetLinearVelocity();
		physics.component.angular_velocity = b->GetAngularVelocity();
	}
}
开发者ID:,项目名称:,代码行数:26,代码来源:

示例4: generate_movement_responses

void movement_system::generate_movement_responses(const logic_step step) {
	auto& cosmos = step.cosm;
	const auto& delta = step.get_delta();
	step.transient.messages.get_queue<messages::movement_response>().clear();

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

		float32 speed = 0.0f;

		if (movement.enable_animation) {
			if (it.has<components::physics>()) {
				speed = it.get<components::physics>().velocity().length();
			}
		}

		messages::movement_response msg;

		if (movement.max_speed_for_movement_response == 0.f) msg.speed = 0.f;
		else msg.speed = speed / movement.max_speed_for_movement_response;
		
		for (const auto receiver : movement.response_receivers) {
			messages::movement_response copy(msg);
			copy.stop_response_at_zero_speed = receiver.stop_response_at_zero_speed;
			copy.subject = receiver.target;
			step.transient.messages.post(copy);
		}
	}
}
开发者ID:,项目名称:,代码行数:29,代码来源:

示例5: handle_trigger_confirmations_as_pick_requests

void item_system::handle_trigger_confirmations_as_pick_requests(const logic_step step) {
	auto& cosmos = step.cosm;
	const auto& delta = step.get_delta();
	const auto& confirmations = step.transient.messages.get_queue<messages::trigger_hit_confirmation_message>();

	for (const auto& e : confirmations) {
		const auto detector = cosmos[e.detector_body];

		auto* const item_slot_transfers = detector.find<components::item_slot_transfers>();
		const auto item_entity = cosmos[e.trigger].get_owner_body();

		const auto* const item = item_entity.find<components::item>();

		if (item_slot_transfers && item && item_entity.get_owning_transfer_capability().dead()) {
			const auto& pick_list = item_slot_transfers->only_pick_these_items;
			const bool found_on_subscription_list = found_in(pick_list, item_entity);

			const bool item_subscribed = (pick_list.empty() && item_slot_transfers->pick_all_touched_items_if_list_to_pick_empty)
				|| found_in(item_slot_transfers->only_pick_these_items, item_entity);
			
			if (item_subscribed) {
				const auto pickup_slot = detector.determine_pickup_target_slot_for(item_entity);
				const bool can_pick_already = item_slot_transfers->pickup_timeout.try_to_fire_and_reset(cosmos.get_timestamp(), delta);

				if (pickup_slot.alive() && can_pick_already) {
					const item_slot_transfer_request request(item_entity, pickup_slot);
					perform_transfer(request, step);
				}
				else {
					// TODO: post gui message
				}
			}
		}
	}
}
开发者ID:,项目名称:,代码行数:35,代码来源:

示例6: apply_damages_and_split_fixtures

void destruction_system::apply_damages_and_split_fixtures(const logic_step step) const {
	auto& cosmos = step.cosm;
	const auto delta = step.get_delta();
	const auto& damages = step.transient.messages.get_queue<messages::damage_message>();

	for (const auto& d : damages) {
		const auto subject = cosmos[d.subject];
		
		if (subject.has<components::fixtures>()) {
			auto& fixtures = subject.get<components::fixtures>();
			
			const auto& data_indices = d.subject_collider_and_convex_indices;

			const auto& coll = fixtures.get_collider_data(data_indices.first);

			if (coll.destructible) {
				auto& dest_data = fixtures.get_modifiable_destruction_data(data_indices);
				dest_data.scars.resize(1);
				dest_data.scars[0].first_impact = d.point_of_impact;
				dest_data.scars[0].depth_point = d.point_of_impact + d.impact_velocity;

				//LOG("Destructible fixture has been applied damage to with direction: %x", d.impact_velocity);
			}
		}
	}
}
开发者ID:,项目名称:,代码行数:26,代码来源:

示例7: set_movement_flags_from_input

void movement_system::set_movement_flags_from_input(const logic_step step) {
	auto& cosmos = step.cosm;
	const auto& delta = step.get_delta();
	const auto& events = step.transient.messages.get_queue<messages::intent_message>();

	for (const auto& it : events) {
		auto* const movement = cosmos[it.subject].find<components::movement>();
		
		if (movement == nullptr) {
			continue;
		}

		switch (it.intent) {
		case intent_type::MOVE_FORWARD:
			movement->moving_forward = it.is_pressed;
			break;
		case intent_type::MOVE_BACKWARD:
			movement->moving_backward = it.is_pressed;
			break;
		case intent_type::MOVE_LEFT:
			movement->moving_left = it.is_pressed;
			break;
		case intent_type::MOVE_RIGHT:
			movement->moving_right = it.is_pressed;
			break;
		case intent_type::WALK:
			movement->walking_enabled = it.is_pressed;
			break;
		case intent_type::SPRINT:
			movement->sprint_enabled = it.is_pressed;
			break;
		default: break;
		}
	}
}
开发者ID:,项目名称:,代码行数:35,代码来源:

示例8: contextualize_crosshair_action_intents

void intent_contextualization_system::contextualize_crosshair_action_intents(const logic_step step) {
	auto& cosmos = step.cosm;
	const auto& delta = step.get_delta();
	auto& events = step.transient.messages.get_queue<messages::intent_message>();

	for (auto& it : events) {
		entity_id callee;

		const auto subject = cosmos[it.subject];

		const auto maybe_crosshair = subject[sub_entity_name::CHARACTER_CROSSHAIR];

		if (it.intent == intent_type::MOVE_CROSSHAIR && maybe_crosshair.alive()) {
			it.subject = maybe_crosshair;
			continue;
		}

		if (subject.has<components::container>()) {
			if (it.intent == intent_type::CROSSHAIR_PRIMARY_ACTION) {
				const auto hand = subject[slot_function::PRIMARY_HAND];

				if (hand.alive() && hand->items_inside.size() > 0)
					callee = hand.get_items_inside()[0];
			}

			if (it.intent == intent_type::CROSSHAIR_SECONDARY_ACTION) {
				const auto hand = subject[slot_function::SECONDARY_HAND];

				if (hand.alive() && hand->items_inside.size() > 0)
					callee = hand.get_items_inside()[0];
				else {
					const auto prim_hand = subject[slot_function::PRIMARY_HAND];

					if (prim_hand.alive() && prim_hand->items_inside.size() > 0)
						callee = prim_hand.get_items_inside()[0];
				}
			}
		}

		const auto callee_handle = cosmos[callee];

		if (callee_handle.alive()) {
			if (callee_handle.find<components::gun>()) {
				it.intent = intent_type::PRESS_GUN_TRIGGER;
				it.subject = callee;
				continue;
			}
			if (callee_handle.find<components::melee>()) {
				if (it.intent == intent_type::CROSSHAIR_PRIMARY_ACTION)
					it.intent = intent_type::MELEE_PRIMARY_MOVE;
				else if (it.intent == intent_type::CROSSHAIR_SECONDARY_ACTION)
					it.intent = intent_type::MELEE_SECONDARY_MOVE;

				it.subject = callee;
				continue;
			}
		}
	}
}
开发者ID:,项目名称:,代码行数:59,代码来源:

示例9: release_drivers_due_to_requests

void driver_system::release_drivers_due_to_requests(const logic_step step) {
	auto& cosmos = step.cosm;
	const auto& delta = step.get_delta();
	const auto& intents = step.transient.messages.get_queue<messages::intent_message>();

	for (const auto& e : intents) {
		if (e.intent == intent_type::RELEASE_CAR && e.is_pressed) {
			release_car_ownership(cosmos[e.subject]);
		}
	}
}
开发者ID:,项目名称:,代码行数:11,代码来源:

示例10: contextualize_movement_intents

void intent_contextualization_system::contextualize_movement_intents(const logic_step step) {
	auto& cosmos = step.cosm;
	const auto& delta = step.get_delta();
	auto& intents = step.transient.messages.get_queue<messages::intent_message>();

	for (auto& e : intents) {
		entity_id callee;
		bool callee_resolved = false;

		const auto subject = cosmos[e.subject];

		const auto* const maybe_driver = subject.find<components::driver>();
		const auto* const maybe_container = subject.find<components::container>();

		if (maybe_driver && cosmos[maybe_driver->owned_vehicle].alive()) {
			if (e.intent == intent_type::MOVE_FORWARD
				|| e.intent == intent_type::MOVE_BACKWARD
				|| e.intent == intent_type::MOVE_LEFT
				|| e.intent == intent_type::MOVE_RIGHT
				|| e.intent == intent_type::WALK
				|| e.intent == intent_type::SPRINT
				) {
				callee = maybe_driver->owned_vehicle;
				callee_resolved = true;
			}
			else if (e.intent == intent_type::SPACE_BUTTON) {
				callee = maybe_driver->owned_vehicle;
				callee_resolved = true;
				e.intent = intent_type::HAND_BRAKE;
			}
		}
		
		if (!callee_resolved) {
			if (maybe_container) {
				if (e.intent == intent_type::SPACE_BUTTON) {
					const auto hand = subject[slot_function::PRIMARY_HAND];

					if (hand.alive() && hand->items_inside.size() > 0) {
						e.intent = intent_type::MELEE_TERTIARY_MOVE;
						callee = hand.get_items_inside()[0];
						callee_resolved = true;
					}
				}
			}
		}

		if (callee_resolved) {
			e.subject = callee;
		}
	}
}
开发者ID:,项目名称:,代码行数:51,代码来源:

示例11: initiate_and_update_moves

void melee_system::initiate_and_update_moves(const logic_step step) {
	auto& cosmos = step.cosm;
	const auto& delta = step.get_delta();
	/* 
	- fixed delta timestep if it's a logic procedure 
	- variable frame time if it is a rendering-time procedure 
	*/
	const auto dt = static_cast<float>(delta.in_milliseconds());

	/* clear melee swing response queue because this is the only place where we send them */
	step.transient.messages.get_queue<messages::melee_swing_response>().clear();

	/* all entities in the "targets" vector are guaranteed to have both melee and damage components
		therefore we use get instead of find
	*/

	const auto targets_copy = cosmos.get(processing_subjects::WITH_MELEE);

	for (const auto& t : targets_copy) {
		auto& melee = t.get<components::melee>();
		auto& damage = t.get<components::damage>();

		//		 LOG("P: %x, S: %x, T: %x CDT: %x MVT: %x STATE: %x", melee.primary_move_flag, melee.secondary_move_flag, melee.tertiary_move_flag,melee.swing_current_cooldown_time,melee.swing_current_time,melee.state);

		switch (melee.current_state) {
		case melee_state::FREE:
			if (melee.primary_move_flag) {
				melee.current_state = primary_action(step, dt, t, melee, damage);
			}
			/* send a response message so that the rest of the game knows that a swing has occured;
			the message could be read by particles system, audio system and possibly animation system
			to apply each their own effects.
			*/
			break;
		case melee_state::ONCOOLDOWN:
			melee.swing_current_cooldown_time += dt;
			if (melee.swing_current_cooldown_time >= melee.swings[0].cooldown_ms) {
				melee.swing_current_cooldown_time = 0;
				melee.current_state = melee_state::FREE;
			}
			break;
		case melee_state::PRIMARY:
			melee.current_state = primary_action(step,dt,t,melee,damage);
			break;
		 default:
			LOG("Uknown action in melee_system.cpp");
		}
	}
}
开发者ID:,项目名称:,代码行数:49,代码来源:

示例12: post_trigger_requests_from_continuous_detectors

void trigger_detector_system::post_trigger_requests_from_continuous_detectors(const logic_step step) const {
	auto& cosmos = step.cosm;
	const auto delta = step.get_delta();
	auto targets_copy = cosmos.get(processing_subjects::WITH_TRIGGER_QUERY_DETECTOR);

	for (auto& t : targets_copy) {
		if (!t.get<components::trigger_query_detector>().detection_intent_enabled) {
			t.get<components::processing>().disable_in(processing_subjects::WITH_TRIGGER_QUERY_DETECTOR);
		}
		else {
			messages::trigger_hit_request_message request;
			request.detector = t;
			step.transient.messages.post(request);
		}
	}
}
开发者ID:,项目名称:,代码行数:16,代码来源:

示例13: assign_drivers_from_successful_trigger_hits

void driver_system::assign_drivers_from_successful_trigger_hits(const logic_step step) {
	auto& cosmos = step.cosm;
	const auto& delta = step.get_delta();
	const auto& confirmations = step.transient.messages.get_queue<messages::trigger_hit_confirmation_message>();

	for (const auto& e : confirmations) {
		const auto& subject_car = cosmos[cosmos[e.trigger].get<components::trigger>().entity_to_be_notified];

		if (subject_car.dead()) {
			continue;
		}

		const auto* const maybe_car = subject_car.find<components::car>();

		if (maybe_car && e.trigger == maybe_car->left_wheel_trigger) {
			assign_car_ownership(cosmos[e.detector_body], subject_car);
		}
	}
}
开发者ID:,项目名称:,代码行数:19,代码来源:

示例14: handle_holster_item_intents

void item_system::handle_holster_item_intents(const logic_step step) {
	auto& cosmos = step.cosm;
	const auto& delta = step.get_delta();
	const auto& requests = step.transient.messages.get_queue<messages::intent_message>();

	for (const auto& r : requests) {
		if (r.is_pressed &&
			(r.intent == intent_type::HOLSTER_PRIMARY_ITEM
				|| r.intent == intent_type::HOLSTER_SECONDARY_ITEM)
			) {
			const auto subject = cosmos[r.subject];

			if (subject.has<components::gui_element>() && subject.find<components::item_slot_transfers>()) {
				const auto hand_type = subject.map_primary_action_to_secondary_hand_if_primary_empty(intent_type::HOLSTER_SECONDARY_ITEM == r.intent).get_id().type;

				auto new_setup = components::gui_element::get_actual_selection_setup(subject);

				if (hand_type == slot_function::PRIMARY_HAND) {
					new_setup.primary_selection.unset();
				}
				else if (hand_type == slot_function::SECONDARY_HAND) {
					new_setup.secondary_selection.unset();
				}

				components::gui_element::apply_and_save_hotbar_selection_setup(step, new_setup, subject);
			}
			else if (subject.has<components::item_slot_transfers>()) {
				const auto hand = subject.map_primary_action_to_secondary_hand_if_primary_empty(intent_type::HOLSTER_SECONDARY_ITEM == r.intent);
				const auto item_inside = hand.get_item_if_any();

				if (item_inside.alive()) {
					const auto holstering_slot = subject.determine_hand_holstering_slot_for(item_inside);

					if (holstering_slot.alive()) {
						const item_slot_transfer_request request(item_inside, holstering_slot);
						perform_transfer(request, step);
					}
				}
			}
		}
	}
}
开发者ID:,项目名称:,代码行数:42,代码来源:

示例15: game_responses_to_animation_messages

void animation_system::game_responses_to_animation_messages(const logic_step step) {
	auto& cosmos = step.cosm;
	const auto& delta = step.get_delta();
	const auto& movements = step.transient.messages.get_queue<movement_response>();
	const auto& gunshots = step.transient.messages.get_queue<gunshot_response>();

	for (auto it : movements) {
		animation_message msg;

		msg.subject = it.subject;
		msg.change_speed = true;

		msg.change_animation = true;
		msg.preserve_state_if_animation_changes = false;
		msg.action = ((it.speed <= 1.f) ? animation_message::STOP : animation_message::CONTINUE);

		if (!it.stop_response_at_zero_speed)
			msg.action = animation_message::CONTINUE;

		msg.animation_priority = 0;

		msg.set_animation = (*(cosmos[it.subject].get<components::animation_response>().response))[animation_response_type::MOVE];
		msg.speed_factor = it.speed;

		step.transient.messages.post(msg);
	}

	for (auto it : gunshots) {
		// animation_message msg;
		// msg.preserve_state_if_animation_changes = false;
		// msg.change_animation = true;
		// msg.change_speed = true;
		// msg.speed_factor = 1.f;
		// msg.subject = it.subject;
		// msg.action = messages::animation_message::START;
		// msg.animation_priority = 1;
		// msg.set_animation = (*(it.subject.get<components::animation_response>().response))[animation_response_type::SHOT];
		// 
		// step.transient.messages.post(msg);
	}
}
开发者ID:,项目名称:,代码行数:41,代码来源:


注:本文中的logic_step::get_delta方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。