Exemple #1
0
void SpringArm::process_spring() {
	// From
	real_t motion_delta(1);
	real_t motion_delta_unsafe(1);

	Vector3 motion;
	const Vector3 cast_direction(get_global_transform().basis.xform(Vector3(0, 0, 1)));

	if (shape.is_null()) {
		motion = Vector3(cast_direction * (spring_length));
		PhysicsDirectSpaceState::RayResult r;
		bool intersected = get_world()->get_direct_space_state()->intersect_ray(get_global_transform().origin, get_global_transform().origin + motion, r, excluded_objects, mask);
		if (intersected) {
			float dist = get_global_transform().origin.distance_to(r.position);
			dist -= margin;
			motion_delta = dist / (spring_length);
		}
	} else {
		motion = Vector3(cast_direction * spring_length);
		get_world()->get_direct_space_state()->cast_motion(shape->get_rid(), get_global_transform(), motion, 0, motion_delta, motion_delta_unsafe, excluded_objects, mask);
	}

	current_spring_length = spring_length * motion_delta;
	Transform childs_transform;
	childs_transform.origin = get_global_transform().origin + cast_direction * (spring_length * motion_delta);

	for (int i = get_child_count() - 1; 0 <= i; --i) {

		Spatial *child = Object::cast_to<Spatial>(get_child(i));
		if (child) {
			childs_transform.basis = child->get_global_transform().basis;
			child->set_global_transform(childs_transform);
		}
	}
}
Exemple #2
0
bool Player::unmount() {
    if (!mount) {
        return true;
    }
    printf_fvec3(get_world_pos());
    printf("\n");
    mount->remove_entity(this);
    // try setting pos to about 2 blocks above current position
    set_pos(fvec3(pos.x, pos.y + 2.0f, pos.z));
    if (get_world()->will_collide_with_anything(this)) {
        // return false if we can't unmount...because not room for player
        set_pos(fvec3(pos.x, pos.y - 2.0f, pos.z));
        mount->add_entity(this);
        return false;
    }
    velocity = mount->velocity;
    mount = 0;
    can_collide = true;
    printf_fvec3(get_world_pos());
    get_world()->add_entity(this);
    
    toggle_mount(false);

    return true;
}
Exemple #3
0
void GridMap::_octant_enter_world(const OctantKey &p_key) {

	ERR_FAIL_COND(!octant_map.has(p_key));
	Octant &g = *octant_map[p_key];
	PhysicsServer::get_singleton()->body_set_state(g.static_body, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform());
	PhysicsServer::get_singleton()->body_set_space(g.static_body, get_world()->get_space());
	//print_line("BODYPOS: "+get_global_transform());

	if (g.collision_debug_instance.is_valid()) {
		VS::get_singleton()->instance_set_scenario(g.collision_debug_instance, get_world()->get_scenario());
		VS::get_singleton()->instance_set_transform(g.collision_debug_instance, get_global_transform());
		if (area_map.has(p_key.area)) {
			VS::get_singleton()->instance_set_room(g.collision_debug_instance, area_map[p_key.area]->instance);
		}
	}
	for (Map<int, Octant::ItemInstances>::Element *E = g.items.front(); E; E = E->next()) {

		VS::get_singleton()->instance_set_scenario(E->get().multimesh_instance, get_world()->get_scenario());
		VS::get_singleton()->instance_set_transform(E->get().multimesh_instance, get_global_transform());
		//print_line("INSTANCEPOS: "+get_global_transform());

		if (area_map.has(p_key.area)) {
			VS::get_singleton()->instance_set_room(E->get().multimesh_instance, area_map[p_key.area]->instance);
		}
	}
}
Exemple #4
0
void GridMap::_octant_enter_world(const OctantKey &p_key) {

	ERR_FAIL_COND(!octant_map.has(p_key));
	Octant &g = *octant_map[p_key];
	PhysicsServer::get_singleton()->body_set_state(g.static_body, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform());
	PhysicsServer::get_singleton()->body_set_space(g.static_body, get_world()->get_space());
	//print_line("BODYPOS: "+get_global_transform());

	if (g.collision_debug_instance.is_valid()) {
		VS::get_singleton()->instance_set_scenario(g.collision_debug_instance, get_world()->get_scenario());
		VS::get_singleton()->instance_set_transform(g.collision_debug_instance, get_global_transform());
	}

	for (int i = 0; i < g.multimesh_instances.size(); i++) {
		VS::get_singleton()->instance_set_scenario(g.multimesh_instances[i].instance, get_world()->get_scenario());
		VS::get_singleton()->instance_set_transform(g.multimesh_instances[i].instance, get_global_transform());
	}

	if (navigation && theme.is_valid()) {
		for (Map<IndexKey, Octant::NavMesh>::Element *F = g.navmesh_ids.front(); F; F = F->next()) {

			if (cell_map.has(F->key()) && F->get().id < 0) {
				Ref<NavigationMesh> nm = theme->get_item_navmesh(cell_map[F->key()].item);
				if (nm.is_valid()) {
					F->get().id = navigation->navmesh_create(nm, F->get().xform, this);
				}
			}
		}
	}
}
Exemple #5
0
void Camera::_notification(int p_what) {

	switch(p_what) {
	
		case NOTIFICATION_ENTER_WORLD: {


			bool first_camera = get_viewport()->_camera_add(this);
			if (!get_tree()->is_node_being_edited(this) && (current || first_camera))
				make_current();


		} break;			
		case NOTIFICATION_TRANSFORM_CHANGED: {
		
			_request_camera_update();
		} break;
		case NOTIFICATION_EXIT_WORLD: {
		
			if (!get_tree()->is_node_being_edited(this)) {
				if (is_current()) {
					clear_current();
					current=true; //keep it true

				} else {
					current=false;
				}
			}

			get_viewport()->_camera_remove(this);


		} break;
		case NOTIFICATION_BECAME_CURRENT: {
			if (get_world().is_valid()) {
				get_world()->_register_camera(this);
			}
		} break;
		case NOTIFICATION_LOST_CURRENT: {
			if (get_world().is_valid()) {
				get_world()->_remove_camera(this);
			}
		} break;

	
	}

}
Exemple #6
0
/**
 * \copydoc LuaData::export_to_lua
 */
bool MapData::export_to_lua(std::ostream& out) const {

  // Write map properties.
  out << "properties{\n"
      << "  x = " << get_location().x << ",\n"
      << "  y = " << get_location().y << ",\n"
      << "  width = " << get_size().width << ",\n"
      << "  height = " << get_size().height << ",\n";
  if (has_world()) {
    out << "  world = \"" << get_world() << "\",\n";
  }
  if (has_floor()) {
    out << "  floor = " << get_floor() << ",\n";
  }
  out << "  tileset = \"" << get_tileset_id() << "\",\n";
  if (has_music()) {
    out << "  music = \"" << get_music_id() << "\",\n";
  }
  out << "}\n\n";

  for (const EntityList& layer_entities : entities) {
    for (const EntityData& entity_data : layer_entities.entities) {
      bool success = entity_data.export_to_lua(out);
      Debug::check_assertion(success, "Entity export failed");
    }
  }

  return true;
}
Exemple #7
0
void SpatialPlayer::_notification(int p_what) {


	switch(p_what) {

		case NOTIFICATION_ENTER_WORLD: {
			//find the sound space

			source_rid = SpatialSoundServer::get_singleton()->source_create(get_world()->get_sound_space());
			for(int i=0;i<PARAM_MAX;i++)
				set_param(Param(i),params[i]);


		} break;
		case NOTIFICATION_TRANSFORM_CHANGED: {

			SpatialSoundServer::get_singleton()->source_set_transform(source_rid,get_global_transform());

		} break;
		case NOTIFICATION_EXIT_WORLD: {

			if (source_rid.is_valid())
				SpatialSoundServer::get_singleton()->free(source_rid);

		} break;
	}

}
Exemple #8
0
void WorldEnvironment::set_environment(const Ref<Environment>& p_environment) {

    if (is_inside_world() && environment.is_valid() && get_world()->get_environment()==environment) {
        get_world()->set_environment(Ref<Environment>());
        //clean up
    }


    environment=p_environment;
    if (is_inside_world() && environment.is_valid()) {
        if (get_world()->get_environment().is_valid()) {
            WARN_PRINT("World already has an environment (Another WorldEnvironment?), overriding.");
        }
        get_world()->set_environment(environment);
    }
}
Exemple #9
0
void Client::check_need_update() {
    fvec3 player_pos = get_player()->get_viewpoint();
    if (get_fvec3_distance(last_player_pos - player_pos) >= CHUNK_UPDATE_TRIGGER_DISTANCE) {
        get_world()->update_render(&player_pos);
        last_player_pos = player_pos;
    }
}
Exemple #10
0
void CollisionObject::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_ENTER_WORLD: {

			RID space = get_world()->get_space();
			if (area) {
				PhysicsServer::get_singleton()->area_set_space(rid,space);
			} else
				PhysicsServer::get_singleton()->body_set_space(rid,space);

		//get space
		}

		case NOTIFICATION_TRANSFORM_CHANGED: {

			if (area)
				PhysicsServer::get_singleton()->area_set_transform(rid,get_global_transform());
			else
				PhysicsServer::get_singleton()->body_set_state(rid,PhysicsServer::BODY_STATE_TRANSFORM,get_global_transform());

		} break;
		case NOTIFICATION_EXIT_WORLD: {

			if (area) {
				PhysicsServer::get_singleton()->area_set_space(rid,RID());
			} else
				PhysicsServer::get_singleton()->body_set_space(rid,RID());

		} break;
	}
}
Exemple #11
0
void RayCast::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_ENTER_TREE: {

			if (enabled && !get_tree()->is_editor_hint()) {
				set_fixed_process(true);
			} else
				set_fixed_process(false);



		} break;
		case NOTIFICATION_EXIT_TREE: {

			if (enabled) {
				set_fixed_process(false);
			}


		} break;
		case NOTIFICATION_FIXED_PROCESS: {

			if (!enabled)
				break;



			Ref<World> w3d = get_world();
			ERR_BREAK( w3d.is_null() );

			PhysicsDirectSpaceState *dss = PhysicsServer::get_singleton()->space_get_direct_state(w3d->get_space());
			ERR_BREAK( !dss );

			Transform gt = get_global_transform();

			Vector3 to = cast_to;
			if (to==Vector3())
				to=Vector3(0,0.01,0);

			PhysicsDirectSpaceState::RayResult rr;

			if (dss->intersect_ray(gt.get_origin(),gt.xform(to),rr,exclude)) {

				collided=true;
				against=rr.collider_id;
				collision_point=rr.position;
				collision_normal=rr.normal;
				against_shape=rr.shape;
			} else {
				collided=false;
			}



		} break;
	}
}
/**
 * \brief Check if all players_detector of category are dead.
 */
bool ptb::bonus_all_dead_by_category::check_all_dead()
{
  bear::engine::world::const_item_iterator it;
  bool result(true);

  for ( it=get_world().living_items_begin();
        it!=get_world().living_items_end() && result; ++it )
    {
      const players_detector* item =
        dynamic_cast<const players_detector*>(&(*it));

      if ( item != NULL )
        result = ( item->get_category() != m_category );
    }

  return result ;
} // bonus_all_dead_by_category::check_all_dead()
void physics_world_update_settings(int index, double timeStep, int velocityIterations, int positionIterations)
{
  // extra function to control your world update settings
  get_world(sb2dworld, index);
  worlds[index]->timeStep = timeStep;
  worlds[index]->velocityIterations = velocityIterations;
  worlds[index]->positionIterations = positionIterations;
}
void VisibilityNotifier::_notification(int p_what) {

	switch (p_what) {
		case NOTIFICATION_ENTER_WORLD: {

			get_world()->_register_notifier(this, get_global_transform().xform(aabb));
		} break;
		case NOTIFICATION_TRANSFORM_CHANGED: {

			get_world()->_update_notifier(this, get_global_transform().xform(aabb));
		} break;
		case NOTIFICATION_EXIT_WORLD: {

			get_world()->_remove_notifier(this);
		} break;
	}
}
Exemple #15
0
void Client::render_shadows() {
    // get transform from light's perspective
    get_world()->set_light_camera(get_player());
    // only render geometry of world
    render_geometry();
    //fmat4 transform(1);
    //world->render_background(&transform, player);
}
Exemple #16
0
void SoftBody::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_ENTER_WORLD: {

			if (Engine::get_singleton()->is_editor_hint())
				add_change_receptor(this);

			RID space = get_world()->get_space();
			PhysicsServer::get_singleton()->soft_body_set_space(physics_rid, space);
			PhysicsServer::get_singleton()->soft_body_set_transform(physics_rid, get_global_transform());
			update_physics_server();
		} break;
		case NOTIFICATION_READY: {
			if (!parent_collision_ignore.is_empty())
				add_collision_exception_with(get_node(parent_collision_ignore));

		} break;
		case NOTIFICATION_TRANSFORM_CHANGED: {

			if (!simulation_started) {
				PhysicsServer::get_singleton()->soft_body_set_transform(physics_rid, get_global_transform());

				_update_cache_pin_points_datas();
				// Submit bone attachment
				const int pinned_points_indices_size = pinned_points_indices.size();
				PoolVector<PinnedPoint>::Read r = pinned_points_indices.read();
				for (int i = 0; i < pinned_points_indices_size; ++i) {
					if (!r[i].spatial_attachment) {
						// Use soft body position to update the point position
						PhysicsServer::get_singleton()->soft_body_move_point(physics_rid, r[i].point_index, (get_global_transform() * r[i].vertex_offset_transform).origin);
					} else {
						PhysicsServer::get_singleton()->soft_body_move_point(physics_rid, r[i].point_index, (r[i].spatial_attachment->get_global_transform() * r[i].vertex_offset_transform).origin);
					}
				}
			}
		} break;
		case NOTIFICATION_VISIBILITY_CHANGED: {

			_update_pickable();

		} break;
		case NOTIFICATION_EXIT_WORLD: {

			PhysicsServer::get_singleton()->soft_body_set_space(physics_rid, RID());

		} break;
	}

#ifdef TOOLS_ENABLED

	if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) {
		if (Engine::get_singleton()->is_editor_hint()) {
			update_configuration_warning();
		}
	}

#endif
}
Exemple #17
0
void WorldEnvironment::_notification(int p_what) {


    if (p_what==NOTIFICATION_ENTER_WORLD) {

        if (environment.is_valid()) {
            if (get_world()->get_environment().is_valid()) {
                WARN_PRINT("World already has an environment (Another WorldEnvironment?), overriding.");
            }
            get_world()->set_environment(environment);
        }

    } else if (p_what==NOTIFICATION_EXIT_WORLD) {

        if (environment.is_valid() && get_world()->get_environment()==environment)
            get_world()->set_environment(Ref<Environment>());
    }
}
Exemple #18
0
void update_loc(struct plyr *p, int newx, int newy)
{
  p->location = (struct loc *)get_world(p, newx, newy);
  p->worldx = newx;
  p->worldy = newy;
  p->lastdump = 0;
  printf("UPDATE LOCATION to %p @ %d,%d\n", p->location,newx,newy);
  dump_world(p);
}
Exemple #19
0
void VisualInstance::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_ENTER_WORLD: {

			// CHECK ROOM
			Spatial * parent = get_parent_spatial();
			Room *room=NULL;
			bool is_geom = cast_to<GeometryInstance>();

			while(parent) {

				room = parent->cast_to<Room>();
				if (room)
					break;

				if (is_geom && parent->cast_to<BakedLightSampler>()) {
					VS::get_singleton()->instance_geometry_set_baked_light_sampler(get_instance(),parent->cast_to<BakedLightSampler>()->get_instance());
					break;
				}

				parent=parent->get_parent_spatial();
			}



			if (room) {

				VisualServer::get_singleton()->instance_set_room(instance,room->get_instance());
			}
			// CHECK SKELETON => moving skeleton attaching logic to MeshInstance
			/*
			Skeleton *skeleton=get_parent()?get_parent()->cast_to<Skeleton>():NULL;
			if (skeleton)
				VisualServer::get_singleton()->instance_attach_skeleton( instance, skeleton->get_skeleton() );
			*/

			VisualServer::get_singleton()->instance_set_scenario( instance, get_world()->get_scenario() );

		} break;
		case NOTIFICATION_TRANSFORM_CHANGED: {

			Transform gt = get_global_transform();
			VisualServer::get_singleton()->instance_set_transform(instance,gt);
		} break;
		case NOTIFICATION_EXIT_WORLD: {

			VisualServer::get_singleton()->instance_set_scenario( instance, RID() );
			VisualServer::get_singleton()->instance_set_room(instance,RID());
			VisualServer::get_singleton()->instance_attach_skeleton( instance, RID() );
			VS::get_singleton()->instance_geometry_set_baked_light_sampler(instance, RID() );


		} break;
	}
}
Exemple #20
0
// runs one frame of the game
void Client::frame(int ms) {
    check_need_update();
    
    // get depth coordinates
    get_player()->query_depth(get_world());
    sprite_manager.step(ms);
    if (get_item_bar()->get_current()) {
        get_item_bar()->get_current()->step(ms);
    }
}
Exemple #21
0
void Camera::_update_camera() {

	Transform tr = get_camera_transform();
	tr.origin += tr.basis.get_axis(1) * v_offset;
	tr.origin += tr.basis.get_axis(0) * h_offset;
	VisualServer::get_singleton()->camera_set_transform(camera, tr);

	// here goes listener stuff
	//	if (viewport_ptr && is_inside_scene() && is_current())
	//		get_viewport()->_camera_transform_changed_notify();

	if (is_inside_tree() && is_current()) {
		get_viewport()->_camera_transform_changed_notify();
	}

	if (is_current() && get_world().is_valid()) {
		get_world()->_update_camera(this);
	}
}
Exemple #22
0
void Client::render() {
    // get transform from player's perspective
    get_player()->set_camera();
    OGLAttr::current_shader->set_enable_shadows(true);
    render_geometry();
    OGLAttr::current_shader->set_enable_shadows(false);
    fmat4 transform(1);
    get_world()->render_background(&transform);
    sprite_manager.render(&transform);
    render_ui();
}
void BlockGibEntity::tick()
{
	PhysicsEntity::tick();

	auto world = get_world();
	if (world) {
		const auto collision_info = world->blocks_test_rectangle_collision(get_rectangle());
		if (collision_info.first || get_position().y > static_cast<float>(Constants::VIDEO_HEIGHT))
			mark_for_deletion();
	}
}
Exemple #24
0
void Camera::_update_camera() {

	Transform tr = get_camera_transform();
	VisualServer::get_singleton()->camera_set_transform( camera, tr );

// here goes listener stuff
//	if (viewport_ptr && is_inside_scene() && is_current())
//		viewport_ptr->_camera_transform_changed_notify();

	if (is_inside_scene() && is_current()) {
		if (viewport_ptr) {
			viewport_ptr->_camera_transform_changed_notify();
		}
	}

	if (is_current() && get_world().is_valid()) {
		get_world()->_update_camera(this);
	}


}
Exemple #25
0
			void remove_constraint(BulletConstraint* constraint)
			{
				get_world()->removeConstraint(constraint->constraint);
				for (std::vector<BulletConstraint*>::iterator it = constraints.begin(); it != constraints.end(); ++it)
				{
					if (*it == constraint)
					{
						constraints.erase(it);
						break;
					}
				}
			}
void VisibilityNotifier::set_aabb(const AABB& p_aabb){

	if (aabb==p_aabb)
		return;
	aabb=p_aabb;

	if (is_inside_world()) {
		get_world()->_update_notifier(this,get_global_transform().xform(aabb));
	}

	_change_notify("aabb");
	update_gizmo();
}
Exemple #27
0
// Called in the main render loop. Pass the rendering to the appropriate entries
void Client::render_geometry() {
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_POLYGON_OFFSET_FILL);
    glEnable(GL_CULL_FACE);
    // render world in player's perspective
    OGLAttr::current_shader->set_shader_intensity(1.0f);
    
    fmat4 transform(1);
    get_world()->render(&transform);
    if (get_item_bar()->get_current()) {
        get_item_bar()->get_current()->render_in_world(&transform);
    }
}
Exemple #28
0
void Client::render_lights() {
    
    // --- AMBIENT LIGHTING ---
    // drawing ambient lighting here
    set_lighting_block_draw_mode(LightDrawMode::BASE);
    float vertex[6][3] = {
        {-1, -1, 0},
        {1, -1, 0},
        {-1, 1, 0},
        {-1, 1, 0},
        {1, -1, 0},
        {1, 1, 0},
    };
    set_ambient_lighting_properties(1.0f);
    set_unitary_lighting_transform_matrix();
    get_world()->set_light_camera_for_lighting(get_player());
    
    glBindBuffer(GL_ARRAY_BUFFER, OGLAttr::common_vertex_vbo);
    glBufferData(GL_ARRAY_BUFFER, sizeof vertex, vertex, GL_DYNAMIC_DRAW);
    glVertexAttribPointer(OGLAttr::lighting_shader.coord, 3, GL_FLOAT, GL_FALSE, 0, 0);
    
    glDrawArrays(GL_TRIANGLES, 0, 6);
    
    
    // --- OTHER LIGHTING ---
    // render a light around the player for now
    get_player()->set_camera();
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    
    fvec3 player_viewpoint_pos = get_player()->get_viewpoint();
    
    fmat4 transform(1);
    get_world()->render_lights(&transform, player_viewpoint_pos);
    sprite_manager.render_lights(&transform, player_viewpoint_pos);
    if (get_item_bar()->get_current()) {
        get_item_bar()->get_current()->render_light_in_world(&transform, player_viewpoint_pos);
    }
}
void
Material_test::on_think()
{
  /*
    After a time, change the materials randomly.
  */
  {
    m_timer += get_world().get_delta_time();
    
    if(m_timer > scene_material_switch)
    {
      m_timer = 0.f;
      
      Core::Material_renderer cube_renderer = Core::Entity_component::get_renderer(m_cube_entity);
      cube_renderer.set_material(m_materials[rand() % Material_test_utils::max_materials()]);
      Core::Entity_component::set_renderer(m_cube_entity, cube_renderer);

      Core::Material_renderer plane_renderer = Core::Entity_component::get_renderer(m_plane_entity);
      plane_renderer.set_material(m_materials[rand() % Material_test_utils::max_materials()]);
      Core::Entity_component::set_renderer(m_plane_entity, plane_renderer);
    }
  }

  /*
    Orbits camera based on time.
  */
  Core::Entity_component::set_transform(
    m_camera_entity,
    Common::Orbit_transform(get_world().get_time_running() * scene_delta_time_mod,
                            camera_tilt,
                            camera_distance,
                            camera_height)
  );

  /*
    Allow the world to render.
  */
  get_world().think();
}
Exemple #30
0
void handle_player(int sock) {
  int z, prevx, prevy;
  struct plyr *p = malloc(sizeof(struct plyr));
  
  p->fd = sock;
  p->x = p->y = p->lastdump = 0;
  p->worldx = p->worldy = 0;
  p->location = NULL;
  p->location = (struct loc *) get_world(p, 0,0);

  if(p->location == NULL)
  {
    printf("FAILED TO GET WORLD!\n");
    close(p->fd);
    return;
  }

  startmsg(p->fd);
  
  while( read_byte(p->fd) == 0);
  dump_world(p);
  
  while(1){
    prevx = p->x;
    prevy = p->y;   
  
    //handle input
    if(handle_input(p)){
     printf("disconnecting client\n");
     break;   
    }

    //display
    if(p->x != prevx || p->y != prevy)
    {
      //printf("trying to display @ %d, %d: %d\n", prevx, prevy, CHARAT(p,prevx, prevy));
      write_byte(p->fd, CHARAT(p,prevx, prevy));
    
      move_cursor(p->fd, p->x, p->y);
      //printf("now at %d,%d: %d\n",p->x,p->y, CHARAT(p,p->x,p->y));
      
    }
    
    check_updates(p);
    
  } 
 
  send(p->fd, "Goodbye\n", 8, 0);
  close(p->fd); 
}