Example #1
0
/**
 * \brief Adds an entity to the map.
 *
 * The entity will be added in front of other ones that are on the same layer.
 * Use insert_entity() if you want to insert it at a specific index.
 *
 * If the new entity has a name, it should be unique on the map.
 *
 * \param entity The information of an entity.
 * \return The index of this entity on the map.
 * Returns an invalid index in case of failure, that is,
 * if the name was already in use or if the entity type is illegal.
 */
EntityIndex MapData::add_entity(const EntityData& entity) {

  // Compute the appropriate index.
  Layer layer = entity.get_layer();
  int bound = entity.is_dynamic() ? get_num_entities(layer) : get_num_tiles(layer);
  EntityIndex index = { layer, bound };

  // Insert the entity there.
  if (!insert_entity(entity, index)) {
    // Failure.
    return EntityIndex();
  }
  return index;
}
Example #2
0
// lod_offset: how much above nominal LOD this node is. 
void load_node(oct_node node, game_data * game_data, int lod_offset){
  if(ht_lookup(game_data->loaded_nodes, &node))
    return;
  i64 hash = get_hash(node, game_data->hashed_node, game_data);
  srand(hash);
  logd("%p ", hash);
  logd("Loading node.. %i %p\n", node.ptr2, hash);
  int val = 0;
  ht_insert(game_data->loaded_nodes, &node, &val);
  int size = 1;
  for(int i = lod_offset; i> 0; i--){
    node = oct_get_sub(node, 0);
    size *= 2;
  }
  for(int i = 0; i < size; i++)
    for(int j = 0; j < size; j++){
      insert_tile(node, vec3i_make(i, 0, j), rand()&1);
      if(rand() % 16 == 0){
	insert_tile(node, vec3i_make(i, 1, j), GD_TREE_1);
	insert_tile(node, vec3i_make(i, 2, j), GD_TREE_2);
	insert_tile(node, vec3i_make(i, 3, j), GD_TREE_3);
	for(int k1 = -1; k1 <= 1; k1++)
	  for(int k2 = -1; k2 <= 1; k2++)
	    insert_tile(node, vec3i_make(i + k1, 4, j + k2), GD_FOILAGE);
	insert_tile(node, vec3i_make(i, 5, j), GD_FOILAGE);
      }else if(rand() % 4000 == 0){
	insert_entity(node, vec3mk(i, 1, j), vec3mk(1, 1, 1), GD_FIREPLACE);
      
      }else if(rand() % 2000 == 0){
	entity * n2 = insert_entity(node, vec3mk(i, 1, j), 
				    vec3mk(1, 1, 1), 
				    (rand() & 1) == 0 ? GD_BUG : GD_CAT);
	int unused_1;
	ht_insert(game_data->enemies, &n2, &unused_1);
      }
    }
}