Пример #1
0
void weapon_update(Entity *ent) {
    cpBody *body = entity_body(ent);
    WeaponEntityData *data = entity_data(ent);

    if (data->owner && !data->player_joint) {
        cvar_setd_player(entity_owner(ent), "weapon_id", entity_id(ent));
        data->player_joint = cpSpaceAddConstraint(game.space, cpPivotJointNew2(
            body,
            entity_body(data->owner),
            cpv(0, -WEAPON_HEIGHT / 2), cpv(1, 0)
        ));
        cpConstraintSetErrorBias(data->player_joint, 0);
    }

    int mult = 0;
    if (keymap_is_held("mouse1")) mult++;
    if (keymap_is_held("mouse2")) mult--;

    if (mult) {
        cpVect force_pos = cpv(0, WEAPON_HEIGHT);
        cpVect weapon_pos = cpBodyGetPosition(body);
        cpVect world_force_pos = cpvadd(weapon_pos, cpvrotate(cpBodyGetRotation(body), force_pos));
        cpVect mouse_delta = cpvsub(keymap_mouse_world(), world_force_pos);
        cpVect force = cpvmult(cpvnormalize(mouse_delta), mult * WEAPON_SWING_FORCE);
        cpBodyApplyForceAtWorldPoint(body, force, world_force_pos);
    }
}
Пример #2
0
	entity_id gui_element::get_hovered_world_entity(const cosmos& cosm, const vec2 world_cursor_position) {
		const auto& physics = cosm.systems_temporary.get<physics_system>();
		const auto cursor_pointing_at = world_cursor_position;
		
		const std::vector<vec2> cursor_world_polygon = { cursor_pointing_at, cursor_pointing_at + vec2(1, 0), cursor_pointing_at + vec2(1, 1) , cursor_pointing_at + vec2(0, 1) };
		const auto hovered = physics.query_polygon(cursor_world_polygon, filters::renderable_query());

		if (hovered.entities.size() > 0) {
			std::vector<unversioned_entity_id> sorted_by_visibility(hovered.entities.begin(), hovered.entities.end());

			sorted_by_visibility.erase(std::remove_if(sorted_by_visibility.begin(), sorted_by_visibility.end(), [&](const unversioned_entity_id e) {
				return cosm[e].find<components::render>() == nullptr;
			}), sorted_by_visibility.end());

			std::sort(sorted_by_visibility.begin(), sorted_by_visibility.end(), [&](const unversioned_entity_id a, const unversioned_entity_id b) {
				return render_system::render_order_compare(cosm[a], cosm[b]);
			});

			for (const auto h : sorted_by_visibility) {
				const auto named = get_first_named_ancestor(cosm[h]);

				if (cosm[named].alive()) {
					return named;
				}
			}
		}

		return entity_id();
	}
Пример #3
0
std::ostream &
print_entity_key( std::ostream & os , const MetaData & meta_data ,
                  const EntityKey & key )
{
  const unsigned type   = entity_rank(key);
  const EntityId id = entity_id(key);
  return print_entity_id( os , meta_data , type , id );
}
Пример #4
0
Entity * EntityRepository::get_entity(const EntityKey &key) const
{
  ThrowErrorMsgIf( ! entity_key_valid( key ),
      "Invalid key: " << entity_rank(key) << " " << entity_id(key));

  const EntityMap::const_iterator i = m_entities.find( key );

  return i != m_entities.end() ? i->second : NULL ;
}
Пример #5
0
	entity_id networked_testbed_server::assign_new_character() {
		for (auto& c : characters) {
			if (!c.occupied) {
				c.occupied = true;
				return c.id;
			}
		}

		ensure(false);
		return entity_id();
	}
Пример #6
0
D basic_relations_mixin<C, D>::operator[](sub_entity_name child) const {
	auto& self = *static_cast<const D*>(this);
	const auto& subs = get_sub_entities_component().sub_entities_by_name;

	const auto found = subs.find(child);
	
	if (found == subs.end()) {
		return self.get_cosmos()[entity_id()];
	}

	return self.get_cosmos()[(*found).second];
}
Пример #7
0
void unpack_entity_info(
  CommBuffer       & buf,
  const BulkData   & mesh ,
  EntityKey        & key ,
  unsigned         & owner ,
  PartVector       & parts ,
  std::vector<Relation> & relations )
{
  unsigned nparts = 0 ;
  unsigned nrel = 0 ;

  buf.unpack<EntityKey>( key );
  buf.unpack<unsigned>( owner );
  buf.unpack<unsigned>( nparts );

  parts.resize( nparts );

  for ( unsigned i = 0 ; i < nparts ; ++i ) {
    unsigned part_ordinal = ~0u ;
    buf.unpack<unsigned>( part_ordinal );
    parts[i] = & MetaData::get(mesh).get_part( part_ordinal );
  }

  buf.unpack( nrel );

  relations.clear();
  relations.reserve( nrel );

  for ( unsigned i = 0 ; i < nrel ; ++i ) {
    EntityKey rel_key ;
    unsigned rel_id = 0 ;
    unsigned rel_attr = 0 ;
    buf.unpack<EntityKey>( rel_key );
    buf.unpack<unsigned>( rel_id );
    buf.unpack<unsigned>( rel_attr );
    Entity * const entity =
      mesh.get_entity( entity_rank(rel_key), entity_id(rel_key) );
    if ( entity && EntityLogDeleted != entity->log_query() ) {
      Relation rel( * entity, rel_id );
      rel.set_attribute(rel_attr);
      relations.push_back( rel );
    }
  }
}
Пример #8
0
void EntityRepository::internal_expunge_entity( EntityMap::iterator i )
{
  TraceIfWatching("stk::mesh::impl::EntityRepository::internal_expunge_entity", LOG_ENTITY, i->first);

  ThrowErrorMsgIf( i->second == NULL,
                   "For key " << entity_rank(i->first) << " " <<
                   entity_id(i->first) << ", value was NULL");

  ThrowErrorMsgIf( i->first != i->second->key(),
    "Key " << print_entity_key(MetaData::get( *i->second ), i->first) <<
    " != " << print_entity_key(i->second));

  Entity* deleted_entity = i->second;

#ifdef SIERRA_MIGRATION
  destroy_fmwk_attr(deleted_entity->m_fmwk_attrs, m_use_pool);
#endif
  destroy_entity(deleted_entity, m_use_pool);
  i->second = NULL;
  m_entities.erase( i );
}
Пример #9
0
inline
stk::diag::Writer &operator<<(stk::diag::Writer &dout, const EntityKey &entity_key)  {
    return dout << entity_rank(entity_key) << ":" << entity_id(entity_key);
}
int main(int argc, char* argv[])
{
	ROSE.quiet(1);	//Get rid of annoying ST-Dev output.
	stplib_init();	// initialize merged cad library
	FILE *out;
	out = fopen("log.txt", "w");
	ROSE.error_reporter()->error_file(out);
	RoseP21Writer::max_spec_version(PART21_ED3);	//We need to use Part21 Edition 3 otherwise references won't be handled properly.
	RoseP21Writer::preserve_eids=ROSE_TRUE;
	RoseDesign * testAnchorAndData = ROSE.newDesign("testAnchorAndData");
	stplib_put_schema(testAnchorAndData, stplib_schema_ap214);
	stp_cartesian_point *point =pnew stp_cartesian_point;
	point->entity_id(321);		//Make the entity ID something we can check later.
	point->name("TestPoint");
	point->coordinates()->add(1.01);
	point->coordinates()->add(2.01);
	point->coordinates()->add(3.01);
	testAnchorAndData->addName("TestAnchor", point);
	testAnchorAndData->save();
	RoseDesign * testRefAndAnchor = ROSE.newDesign("testRefAndAnchor");
	stplib_put_schema(testRefAndAnchor, stplib_schema_ap214);
	auto ref = rose_make_ref(testRefAndAnchor, "testAnchorAndData.stp#TestAnchor");		//Manually make the reference point to the other file.
	ref->entity_id(123);		//Just give it an entity id so we can check it later.
	testRefAndAnchor->addName("ParentAnchor", ref);	//Add an anchor which points to the reference.
	stp_circular_area *area = pnew stp_circular_area;	//Make something to test if the reference resolves properly
	area->name("testarea");
	area->radius(2.0);
	rose_put_ref(ref, area, "centre");
	testRefAndAnchor->save();
	//Okay, so now we have two files- one with an anchor pointing to a reference, and one with an anchor and the data the anchor points to. Lets see what the anchor in the higher file points to.
	std::cout << "Anchor " << testRefAndAnchor->nameTable()->listOfKeys()->get(0) <<" points to (should be 123): " <<testRefAndAnchor->nameTable()->listOfValues()->get(0)->entity_id() <<'\n';
	//That should output "Anchor ParentAnchor points to: 123"
	//Now lets merge. 
	//First things first, we close the child design just to be certain we are doing it EXACTLY LIKE MERGE.
	rose_move_to_trash(testAnchorAndData);  
	testRefAndAnchor->saveAs("testmerge.stp");
	rose_move_to_trash(testRefAndAnchor);
	rose_empty_trash();						//now all of this is out of memory.
	RoseDesign *parent = ROSE.findDesign("testmerge.stp");	//Open the new file. Don't mess with the files we created earlier.
	if (!parent)
	{
		std::cout << "Shit's f****d\n";
		return EXIT_FAILURE;
	}
	//Call the URI parser function.
	RoseCursor * cursor = new RoseCursor;
	cursor->traverse(parent->reference_section());
	cursor->domain(ROSE_DOMAIN(RoseReference));//Go through all the references in parent. All one of them.
	std::cout << "Cursor size (should be 1): " << cursor->size() <<'\n';
	RoseObject * obj = cursor->next();
	std::cout << "Reference ID (should be 123): " << obj->entity_id() << '\n';
	ref = ROSE_CAST(RoseReference, obj);	//Now we have the reference as an actual Reference object instead of a generic RoseObject.
	std::string file, anchor,dir="./";
	URIParse(ref->uri(), file, anchor,dir);
	std::cout << "file (should be testAnchorAndData.stp): " << file << "\nanchor (should be TestAnchor): " << anchor << "\ndir (should be ./): " << dir << '\n';
	std::cout << "Anchor " << parent->nameTable()->listOfKeys()->get(0) << " points to (should be 123): " << parent->nameTable()->listOfValues()->get(0)->entity_id() << '\n';
	RoseDesign *child = ROSE.findDesign(file.substr(0, file.find('.')).c_str());
	if (!child)
	{
		std::cout << "Shit's f****d\n";
		return EXIT_FAILURE;
	}
	std::cout << "Anchor " << parent->nameTable()->listOfKeys()->get(0) << " points to (should be 123): " << parent->nameTable()->listOfValues()->get(0)->entity_id() << '\n';
	obj = child->findObject(anchor.c_str());	//Get the object associated with the anchor
	std::cout << "Child Object Pointed to by Anchor Entity ID (should be 321): " << obj->entity_id() <<'\n';
	obj->move(parent);	//move object to parent so we have it in the right place, then resolve references.
	RoseRefUsage *rru = ref->usage();	//rru is a linked list of all the objects that use ref
	do
	{
		std::cout << "Resolving reference in entity ID: " << rru->user()->entity_id() <<'\n';
		int rrureturn = ResolveRRU(rru,obj);
		if (-1 == rrureturn) break;
	} while (rru = rru->next_for_ref());	//Do this for anything that uses the reference.
	//parent->save();
	//At this point, the data section references are resolved. You can check the output file if you want to be sure. Just uncomment that save.
	//Now resolve the reference in the anchor section.
	DictionaryOfRoseObject * anchors = parent->nameTable();
	for (unsigned i = 0, sz = anchors->size(); i < sz; i++)
	{
		if (anchors->listOfValues()->get(i) == ref)
		{
			std::cout << "anchor " << anchors->listOfKeys()->get(i) << " has an entity ID of (should be 123): " << anchors->listOfValues()->get(i)->entity_id() <<'\n';
			anchors->add(anchors->listOfKeys()->get(i), obj);
			std::cout << "anchor " << anchors->listOfKeys()->get(i) << " has an entity ID of (should be 321): " << anchors->listOfValues()->get(i)->entity_id() << '\n';
		}
	}
	parent->save();
	return EXIT_SUCCESS;
}
Пример #11
0
	void networked_testbed::populate(const logic_step step) {
		auto& world = step.cosm;

		const auto crate = prefabs::create_crate(world, vec2(200, 200 + 300), vec2i(100, 100) / 3);
		const auto crate2 = prefabs::create_crate(world, vec2(400, 200 + 400), vec2i(300, 300));
		const auto crate4 = prefabs::create_crate(world, vec2(500, 200 + 0), vec2i(100, 100));

		for (int x = -4; x < 4; ++x) {
			for (int y = -4; y < 4; ++y) {
				auto obstacle = prefabs::create_crate(world, vec2(2000.f + x * 300.f, -1000.f +2000.f + y * 300.f), vec2i(100, 100));
			}
		}

		const auto car = prefabs::create_car(world, components::transform(-300, -600, -90));
		const auto car2 = prefabs::create_car(world, components::transform(-800, -600, -90));
		const auto car3 = prefabs::create_car(world, components::transform(-1300, -600, -90));

		const auto motorcycle = prefabs::create_motorcycle(world, components::transform(0, -600, -90));
		prefabs::create_motorcycle(world, components::transform(100, -600, -90));

		const vec2 bg_size = assets::get_size(assets::texture_id::TEST_BACKGROUND);

		const int num_floors = 10 * 10;
		const int side = sqrt(num_floors) / 2;

		for (int x = -side; x < side; ++x)
			for (int y = -side; y < side; ++y)
			{
				//auto background = world.create_entity("bg[-]");
				//ingredients::sprite(background, vec2(-1000, 0) + vec2(x, y) * (bg_size + vec2(1500, 550)), assets::texture_id::TEST_BACKGROUND, white, render_layer::GROUND);
				//ingredients::standard_static_body(background);

				auto street = world.create_entity("street[-]");
				ingredients::sprite(street, { bg_size * vec2(x, y) },
					assets::texture_id::TEST_BACKGROUND, gray1, render_layer::GROUND);

				//background.add_standard_components();
				street.add_standard_components();
			}

		const int num_characters = 6;

		std::vector<entity_id> new_characters;
		new_characters.resize(num_characters);

		auto character = [&](const size_t i) {
			return i < new_characters.size() ? world[new_characters.at(i)] : world[entity_id()];
		};

		{
			{
				const auto l = world.create_entity("l");
				l += components::transform();
				auto& light = l += components::light();
				light.color = red;
				l.add_standard_components();
			}
			{
				const auto l = world.create_entity("l");
				l += components::transform(300, 0);
				auto& light = l += components::light();
				light.color = green;
				l.add_standard_components();
			}
			{
				const auto l = world.create_entity("l");
				l += components::transform(600, 0);
				auto& light = l += components::light();
				light.color = blue;
				l.add_standard_components();
			}
			{
				const auto l = world.create_entity("l");
				l += components::transform(900, 0);
				auto& light = l += components::light();
				light.color = cyan;
				l.add_standard_components();
			}
			{
				const auto l = world.create_entity("l");
				l += components::transform(1200, 0);
				auto& light = l += components::light();
				light.color = orange;
				l.add_standard_components();
			}
		}

		for (int i = 0; i < num_characters; ++i) {
			const auto new_character = prefabs::create_character(world, vec2(i * 300.f, 0), vec2(1200, 800), typesafe_sprintf("player%x", i));

			new_characters[i] = new_character;

			if (i == 0) {
				new_character.get<components::sentience>().health.value = 100;
				new_character.get<components::sentience>().health.maximum = 100;
			}
			if (i == 1) {
				new_character.get<components::attitude>().parties = party_category::RESISTANCE_CITIZEN;
				new_character.get<components::attitude>().hostile_parties = party_category::METROPOLIS_CITIZEN;
				new_character.get<components::attitude>().maximum_divergence_angle_before_shooting = 25;
				new_character.get<components::sentience>().minimum_danger_amount_to_evade = 20;
				new_character.get<components::sentience>().health.value = 300;
				new_character.get<components::sentience>().health.maximum = 300;
				//ingredients::standard_pathfinding_capability(new_character);
				//ingredients::soldier_intelligence(new_character);
				new_character.recalculate_basic_processing_categories();
			}
			if (i == 2) {
				new_character.get<components::sentience>().health.value = 38;
			}
			if (i == 5) {
				new_character.get<components::attitude>().parties = party_category::METROPOLIS_CITIZEN;
				new_character.get<components::attitude>().hostile_parties = party_category::RESISTANCE_CITIZEN;
				new_character.get<components::attitude>().maximum_divergence_angle_before_shooting = 25;
				new_character.get<components::sentience>().minimum_danger_amount_to_evade = 20;
				new_character.get<components::sentience>().health.value = 300;
				new_character.get<components::sentience>().health.maximum = 300;
				//ingredients::standard_pathfinding_capability(new_character);
				//ingredients::soldier_intelligence(new_character);
				new_character.recalculate_basic_processing_categories();
			}
		}

		if (character(0).alive()) {
			name_entity(character(0), entity_name::PERSON, L"Attacker");
		}

		prefabs::create_sample_suppressor(world, vec2(300, -500));

		const bool many_charges = false;

		const auto rifle = prefabs::create_sample_rifle(step, vec2(100, -500),
			prefabs::create_sample_magazine(step, vec2(100, -650), many_charges ? "10" : "0.3",
				prefabs::create_cyan_charge(world, vec2(0, 0), many_charges ? 1000 : 30)));

		const auto rifle2 = prefabs::create_sample_rifle(step, vec2(100, -500 + 50),
			prefabs::create_sample_magazine(step, vec2(100, -650), true ? "10" : "0.3",
				prefabs::create_cyan_charge(world, vec2(0, 0), true ? 1000 : 30)));

		prefabs::create_sample_rifle(step, vec2(100, -500 + 100));

		prefabs::create_pistol(step, vec2(300, -500 + 50));

		const auto pis2 = prefabs::create_pistol(step, vec2(300, 50),
			prefabs::create_sample_magazine(step, vec2(100, -650), "0.4",
				prefabs::create_green_charge(world, vec2(0, 0), 40)));

		const auto submachine = prefabs::create_submachine(step, vec2(500, -500 + 50),
			prefabs::create_sample_magazine(step, vec2(100 - 50, -650), many_charges ? "10" : "0.5", prefabs::create_pink_charge(world, vec2(0, 0), many_charges ? 500 : 50)));

		prefabs::create_submachine(step, vec2(0, -1000),
			prefabs::create_sample_magazine(step, vec2(100 - 50, -650), many_charges ? "10" : "0.5", prefabs::create_pink_charge(world, vec2(0, 0), many_charges ? 500 : 50)));

		prefabs::create_submachine(step, vec2(150, -1000 + 150),
			prefabs::create_sample_magazine(step, vec2(100 - 50, -650), many_charges ? "10" : "0.5", prefabs::create_pink_charge(world, vec2(0, 0), many_charges ? 500 : 50)));

		prefabs::create_submachine(step, vec2(300, -1000 + 300),
			prefabs::create_sample_magazine(step, vec2(100 - 50, -650), many_charges ? "10" : "0.5", prefabs::create_pink_charge(world, vec2(0, 0), many_charges ? 500 : 50)));

		prefabs::create_submachine(step, vec2(450, -1000 + 450),
			prefabs::create_sample_magazine(step, vec2(100 - 50, -650), many_charges ? "10" : "0.5", prefabs::create_pink_charge(world, vec2(0, 0), many_charges ? 500 : 50)));


		prefabs::create_sample_magazine(step, vec2(100 - 50, -650));
		prefabs::create_sample_magazine(step, vec2(100 - 100, -650), "0.30");
		//prefabs::create_pink_charge(world, vec2(100, 100));
		//prefabs::create_pink_charge(world, vec2(100, -400));
		//prefabs::create_pink_charge(world, vec2(150, -400));
		//prefabs::create_pink_charge(world, vec2(200, -400));
		prefabs::create_cyan_charge(world, vec2(150, -500));
		prefabs::create_cyan_charge(world, vec2(200, -500));

		prefabs::create_cyan_urban_machete(world, vec2(100, 100));
		const auto second_machete = prefabs::create_cyan_urban_machete(world, vec2(0, 0));

		const auto backpack = prefabs::create_sample_backpack(world, vec2(200, -650));
		prefabs::create_sample_backpack(world, vec2(200, -750));

		perform_transfer({ backpack, character(0)[slot_function::SHOULDER_SLOT] }, step);
		perform_transfer({ submachine, character(0)[slot_function::PRIMARY_HAND] }, step);
		perform_transfer({ rifle, character(0)[slot_function::SECONDARY_HAND] }, step);

		if (character(1).alive()) {
			name_entity(character(1), entity_name::PERSON, L"Enemy");
			perform_transfer({ rifle2, character(1)[slot_function::PRIMARY_HAND] }, step);
		}

		if (character(2).alive()) {
			name_entity(character(2), entity_name::PERSON, L"Swordsman");
			perform_transfer({ second_machete, character(2)[slot_function::PRIMARY_HAND] }, step);
		}

		if (character(3).alive()) {
			name_entity(character(3), entity_name::PERSON, L"Medic");
			perform_transfer({ pis2, character(3)[slot_function::PRIMARY_HAND] }, step);
		}

		if (character(5).alive()) {
			const auto new_item = prefabs::create_submachine(step, vec2(0, -1000),
				prefabs::create_sample_magazine(step, vec2(100 - 50, -650), true ? "10" : "0.5", prefabs::create_pink_charge(world, vec2(0, 0), true ? 500 : 50)));

			perform_transfer({ new_item, character(5)[slot_function::PRIMARY_HAND] }, step);
		}

		//draw_bodies.push_back(crate2);
		//draw_bodies.push_back(new_characters[0]);
		//draw_bodies.push_back(backpack);

		//world.significant.meta.settings.pathfinding.draw_memorised_walls = 1;
		//world.significant.meta.settings.pathfinding.draw_undiscovered = 1;

		characters.assign(new_characters.begin(), new_characters.end());
		// _controlfp(0, _EM_OVERFLOW | _EM_ZERODIVIDE | _EM_INVALID | _EM_DENORMAL);
	}
Пример #12
0
bool driver_system::release_car_ownership(const entity_handle driver) {
	return change_car_ownership(driver, driver.get_cosmos()[entity_id()], true);
}
Пример #13
0
 entity_property(entity_rank r = entity_rank(), entity_id id = entity_id(), int proc=0)
     : m_rank(r), m_id(id), m_proc(proc) {}