random optimisations

This commit is contained in:
darkrose 2015-01-22 06:22:26 +10:00
parent 54cefb4499
commit 71de73b3fe
16 changed files with 376 additions and 426 deletions

View File

@ -68,6 +68,7 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control, Client
m_frametime_counter(0),
m_time_per_range(30. / 50), // a sane default of 30ms per 50 nodes of range
m_view_bobbing(true),
m_view_bobbing_anim(0),
m_view_bobbing_state(0),
m_view_bobbing_speed(0),
@ -75,8 +76,6 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control, Client
m_digging_anim(0),
m_digging_button(-1)
{
//dstream<<__FUNCTION_NAME<<std::endl;
// note: making the camera node a child of the player node
// would lead to unexpected behaviour, so we don't do that.
m_playernode = smgr->addEmptySceneNode(smgr->getRootSceneNode());
@ -89,6 +88,17 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control, Client
m_wieldmgr = smgr->createNewSceneManager();
m_wieldmgr->addCameraSceneNode();
m_wieldnode = new ExtrudedSpriteSceneNode(m_wieldmgr->getRootSceneNode(), m_wieldmgr);
// Get FOV setting
m_fov = g_settings->getFloat("fov");
m_fov = MYMAX(m_fov, 10.0);
m_fov = MYMIN(m_fov, 170.0);
m_view_bobbing_amount = g_settings->getFloat("view_bobbing_amount");
f32 wanted_fps = g_settings->getFloat("wanted_fps");
wanted_fps = MYMAX(wanted_fps, 1.0);
m_wanted_frametime = 1.0 / wanted_fps;
}
Camera::~Camera()
@ -99,28 +109,23 @@ Camera::~Camera()
bool Camera::successfullyCreated(std::wstring& error_message)
{
if (m_playernode == NULL)
{
if (m_playernode == NULL) {
error_message = L"Failed to create the player scene node";
return false;
}
if (m_headnode == NULL)
{
if (m_headnode == NULL) {
error_message = L"Failed to create the head scene node";
return false;
}
if (m_cameranode == NULL)
{
if (m_cameranode == NULL) {
error_message = L"Failed to create the camera scene node";
return false;
}
if (m_wieldmgr == NULL)
{
if (m_wieldmgr == NULL) {
error_message = L"Failed to create the wielded item scene manager";
return false;
}
if (m_wieldnode == NULL)
{
if (m_wieldnode == NULL) {
error_message = L"Failed to create the wielded item scene node";
return false;
}
@ -212,41 +217,20 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize)
{
f32 bobfrac = my_modf(m_view_bobbing_anim * 2);
f32 bobdir = (m_view_bobbing_anim < 0.5) ? 1.0 : -1.0;
#if 1
f32 bobknob = 1.2;
f32 bobtmp = sin(pow(bobfrac, bobknob) * PI);
//f32 bobtmp2 = cos(pow(bobfrac, bobknob) * PI);
v3f bobvec = v3f(
0.3 * bobdir * sin(bobfrac * PI),
-0.28 * bobtmp * bobtmp,
0.);
//rel_cam_pos += 0.2 * bobvec;
//rel_cam_target += 0.03 * bobvec;
//rel_cam_up.rotateXYBy(0.02 * bobdir * bobtmp * PI);
float f = 1.0;
f *= g_settings->getFloat("view_bobbing_amount");
f *= m_view_bobbing_amount;
rel_cam_pos += bobvec * f;
//rel_cam_target += 0.995 * bobvec * f;
rel_cam_target += bobvec * f;
rel_cam_target.Z -= 0.005 * bobvec.Z * f;
//rel_cam_target.X -= 0.005 * bobvec.X * f;
//rel_cam_target.Y -= 0.005 * bobvec.Y * f;
rel_cam_up.rotateXYBy(-0.03 * bobdir * bobtmp * PI * f);
#else
f32 angle_deg = 1 * bobdir * sin(bobfrac * PI);
f32 angle_rad = angle_deg * PI / 180;
f32 r = 0.05;
v3f off = v3f(
r * sin(angle_rad),
r * (cos(angle_rad) - 1),
0);
rel_cam_pos += off;
//rel_cam_target += off;
rel_cam_up.rotateXYBy(angle_deg);
#endif
}
@ -272,14 +256,9 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize)
// *100.0 helps in large map coordinates
m_cameranode->setTarget(m_camera_position-intToFloat(m_camera_offset, BS) + 100 * m_camera_direction);
// Get FOV setting
f32 fov_degrees = g_settings->getFloat("fov");
fov_degrees = MYMAX(fov_degrees, 10.0);
fov_degrees = MYMIN(fov_degrees, 170.0);
// FOV and aspect ratio
m_aspect = (f32)screensize.X / (f32) screensize.Y;
m_fov_y = fov_degrees * PI / 180.0;
m_fov_y = m_fov * PI / 180.0;
m_fov_x = 2 * atan(0.5 * m_aspect * tan(m_fov_y));
m_cameranode->setAspectRatio(m_aspect);
m_cameranode->setFOV(m_fov_y);
@ -322,17 +301,16 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize)
// view bobbing is enabled and free_move is off,
// start (or continue) the view bobbing animation.
v3f speed = player->getSpeed();
if ((hypot(speed.X, speed.Z) > BS) &&
(player->touching_ground) &&
(g_settings->getBool("view_bobbing") == true) &&
(g_settings->getBool("free_move") == false))
{
if (
(hypot(speed.X, speed.Z) > BS)
&& (player->touching_ground)
&& m_view_bobbing == true
&& player->control.free == false
) {
// Start animation
m_view_bobbing_state = 1;
m_view_bobbing_speed = MYMIN(speed.getLength(), 40);
}
else if (m_view_bobbing_state == 1)
{
}else if (m_view_bobbing_state == 1) {
// Stop animation
m_view_bobbing_state = 2;
m_view_bobbing_speed = 60;
@ -353,16 +331,6 @@ void Camera::updateViewingRange(f32 frametime_in)
return;
m_frametime_counter = 0.2;
/*dstream<<__FUNCTION_NAME
<<": Collected "<<m_added_frames<<" frames, total of "
<<m_added_frametime<<"s."<<std::endl;
dstream<<"m_draw_control.blocks_drawn="
<<m_draw_control.blocks_drawn
<<", m_draw_control.blocks_would_have_drawn="
<<m_draw_control.blocks_would_have_drawn
<<std::endl;*/
// Get current viewing range and FPS settings
f32 viewing_range_min = g_settings->getS16("viewing_range_nodes_min");
viewing_range_min = MYMAX(5.0, viewing_range_min);
@ -370,10 +338,6 @@ void Camera::updateViewingRange(f32 frametime_in)
f32 viewing_range_max = g_settings->getS16("viewing_range_nodes_max");
viewing_range_max = MYMAX(viewing_range_min, viewing_range_max);
f32 wanted_fps = g_settings->getFloat("wanted_fps");
wanted_fps = MYMAX(wanted_fps, 1.0);
f32 wanted_frametime = 1.0 / wanted_fps;
m_draw_control.wanted_min_range = viewing_range_min;
m_draw_control.wanted_max_blocks = (2.0*m_draw_control.blocks_would_have_drawn)+1;
if (m_draw_control.wanted_max_blocks < 10)
@ -381,10 +345,7 @@ void Camera::updateViewingRange(f32 frametime_in)
f32 block_draw_ratio = 1.0;
if (m_draw_control.blocks_would_have_drawn != 0)
{
block_draw_ratio = (f32)m_draw_control.blocks_drawn
/ (f32)m_draw_control.blocks_would_have_drawn;
}
block_draw_ratio = (f32)m_draw_control.blocks_drawn / (f32)m_draw_control.blocks_would_have_drawn;
// Calculate the average frametime in the case that all wanted
// blocks had been drawn
@ -393,17 +354,13 @@ void Camera::updateViewingRange(f32 frametime_in)
m_added_frametime = 0.0;
m_added_frames = 0;
f32 wanted_frametime_change = wanted_frametime - frametime;
//dstream<<"wanted_frametime_change="<<wanted_frametime_change<<std::endl;
f32 wanted_frametime_change = m_wanted_frametime - frametime;
// If needed frametime change is small, just return
// This value was 0.4 for many months until 2011-10-18 by c55;
// Let's see how this works out.
if (fabs(wanted_frametime_change) < wanted_frametime*0.33)
{
//dstream<<"ignoring small wanted_frametime_change"<<std::endl;
if (fabs(wanted_frametime_change) < m_wanted_frametime*0.33)
return;
}
f32 range = m_draw_control.wanted_range;
f32 new_range = range;
@ -411,9 +368,7 @@ void Camera::updateViewingRange(f32 frametime_in)
f32 d_range = range - m_range_old;
f32 d_frametime = frametime - m_frametime_old;
if (d_range != 0)
{
m_time_per_range = d_frametime / d_range;
}
// The minimum allowed calculated frametime-range derivative:
// Practically this sets the maximum speed of changing the range.
@ -422,40 +377,21 @@ void Camera::updateViewingRange(f32 frametime_in)
// A high value here results in slow changing range (0.0025)
// SUGG: This could be dynamically adjusted so that when
// the camera is turning, this is lower
//f32 min_time_per_range = 0.0015;
f32 min_time_per_range = 0.0010;
//f32 min_time_per_range = 0.05 / range;
if(m_time_per_range < min_time_per_range)
{
if (m_time_per_range < min_time_per_range)
m_time_per_range = min_time_per_range;
//dstream<<"m_time_per_range="<<m_time_per_range<<" (min)"<<std::endl;
}
else
{
//dstream<<"m_time_per_range="<<m_time_per_range<<std::endl;
}
f32 wanted_range_change = wanted_frametime_change / m_time_per_range;
// Dampen the change a bit to kill oscillations
//wanted_range_change *= 0.9;
//wanted_range_change *= 0.75;
wanted_range_change *= 0.5;
//dstream<<"wanted_range_change="<<wanted_range_change<<std::endl;
// If needed range change is very small, just return
if(fabs(wanted_range_change) < 0.001)
{
//dstream<<"ignoring small wanted_range_change"<<std::endl;
if (fabs(wanted_range_change) < 0.001)
return;
}
new_range += wanted_range_change;
//f32 new_range_unclamped = new_range;
new_range = MYMAX(new_range, viewing_range_min);
new_range = MYMIN(new_range, viewing_range_max);
/*dstream<<"new_range="<<new_range_unclamped
<<", clamped to "<<new_range<<std::endl;*/
m_draw_control.wanted_range = new_range;

View File

@ -160,11 +160,13 @@ private:
v3s16 m_camera_offset;
// Field of view and aspect ratio stuff
f32 m_fov;
f32 m_aspect;
f32 m_fov_x;
f32 m_fov_y;
// Stuff for viewing range calculations
f32 m_wanted_frametime;
f32 m_added_frametime;
s16 m_added_frames;
f32 m_range_old;
@ -172,6 +174,7 @@ private:
f32 m_frametime_counter;
f32 m_time_per_range;
bool m_view_bobbing;
// View bobbing animation frame (0 <= m_view_bobbing_anim < 1)
f32 m_view_bobbing_anim;
// If 0, view bobbing is off (e.g. player is standing).
@ -180,6 +183,7 @@ private:
s32 m_view_bobbing_state;
// Speed of view bobbing animation
f32 m_view_bobbing_speed;
f32 m_view_bobbing_amount;
// Digging animation frame (0 <= m_digging_anim < 1)
f32 m_digging_anim;

View File

@ -51,11 +51,12 @@ Clouds::Clouds(
m_material.setFlag(video::EMF_BACK_FACE_CULLING, false);
m_material.setFlag(video::EMF_BILINEAR_FILTER, false);
m_material.setFlag(video::EMF_FOG_ENABLE, false);
//m_material.setFlag(video::EMF_ANTI_ALIASING, true);
//m_material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
m_box = core::aabbox3d<f32>(-BS*1000000,cloud_y-BS,-BS*1000000,
BS*1000000,cloud_y+BS,BS*1000000);
m_box = core::aabbox3d<f32>(-BS*1000000,cloud_y-BS,-BS*1000000, BS*1000000,cloud_y+BS,BS*1000000);
m_face_count = 1;
if (g_settings->getBool("enable_3d_clouds"))
m_face_count = 6;
}
@ -66,11 +67,8 @@ Clouds::~Clouds()
void Clouds::OnRegisterSceneNode()
{
if(IsVisible)
{
//SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT);
if (IsVisible)
SceneManager->registerNodeForRendering(this, scene::ESNRP_SOLID);
}
ISceneNode::OnRegisterSceneNode();
}
@ -81,17 +79,11 @@ void Clouds::render()
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
/*if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_TRANSPARENT)
return;*/
if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_SOLID)
if (SceneManager->getSceneNodeRenderPass() != scene::ESNRP_SOLID)
return;
ScopeProfiler sp(g_profiler, "Rendering of clouds, avg", SPT_AVG);
int num_faces_to_draw = 1;
if(g_settings->getBool("enable_3d_clouds"))
num_faces_to_draw = 6;
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
driver->setMaterial(m_material);
@ -120,106 +112,94 @@ void Clouds::render()
center_of_drawing_in_noise_i.Y * cloud_size
) + world_cloud_origin_pos_f;
for(s16 zi=-cloud_radius_i; zi<cloud_radius_i; zi++)
for(s16 xi=-cloud_radius_i; xi<cloud_radius_i; xi++)
{
video::SColor c[6] = {
video::SColor(128,m_brightness*240,m_brightness*240,m_brightness*255),
video::SColor(128,m_brightness*230,m_brightness*230,m_brightness*255),
video::SColor(128,m_brightness*220,m_brightness*220,m_brightness*245),
video::SColor(128,m_brightness*230,m_brightness*230,m_brightness*255),
video::SColor(128,m_brightness*220,m_brightness*220,m_brightness*245),
video::SColor(128,m_brightness*205,m_brightness*205,m_brightness*230)
};
for (s16 zi=-cloud_radius_i; zi<cloud_radius_i; zi++)
for (s16 xi=-cloud_radius_i; xi<cloud_radius_i; xi++) {
v2s16 p_in_noise_i(
xi+center_of_drawing_in_noise_i.X,
zi+center_of_drawing_in_noise_i.Y
);
/*if((p_in_noise_i.X + p_in_noise_i.Y)%2==0)
continue;*/
/*if((p_in_noise_i.X/2 + p_in_noise_i.Y/2)%2==0)
continue;*/
v2f p0 = v2f(xi,zi)*cloud_size + world_center_of_drawing_in_noise_f;
double noise = noise2d_perlin_abs(
(float)p_in_noise_i.X*cloud_size/BS/200,
(float)p_in_noise_i.Y*cloud_size/BS/200,
m_seed, 3, 0.4);
if(noise < 0.95)
(float)p_in_noise_i.X*cloud_size/BS/200,
(float)p_in_noise_i.Y*cloud_size/BS/200,
m_seed,
3,
0.4
);
if (noise < 0.95)
continue;
float b = m_brightness;
video::SColor c_top(128,b*240,b*240,b*255);
video::SColor c_side_1(128,b*230,b*230,b*255);
video::SColor c_side_2(128,b*220,b*220,b*245);
video::SColor c_bottom(128,b*205,b*205,b*230);
video::S3DVertex v[4] =
{
video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 1),
video::S3DVertex(0,0,0, 0,0,0, c_top, 1, 1),
video::S3DVertex(0,0,0, 0,0,0, c_top, 1, 0),
video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 0)
video::S3DVertex v[4] = {
video::S3DVertex(0,0,0, 0,0,0, c[0], 0, 1),
video::S3DVertex(0,0,0, 0,0,0, c[0], 1, 1),
video::S3DVertex(0,0,0, 0,0,0, c[0], 1, 0),
video::S3DVertex(0,0,0, 0,0,0, c[0], 0, 0)
};
f32 rx = cloud_size;
f32 ry = 8*BS;
f32 rz = cloud_size;
for(int i=0; i<num_faces_to_draw; i++)
{
switch(i)
{
case 0: // top
v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
v[2].Pos.X= rx; v[2].Pos.Y= ry; v[2].Pos.Z= rz;
v[3].Pos.X= rx; v[3].Pos.Y= ry, v[3].Pos.Z=-rz;
break;
case 1: // back
for(int j=0;j<4;j++)
v[j].Color=c_side_1;
v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
v[1].Pos.X= rx; v[1].Pos.Y= ry; v[1].Pos.Z=-rz;
v[2].Pos.X= rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
v[3].Pos.X=-rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
break;
case 2: //right
for(int j=0;j<4;j++)
v[j].Color=c_side_2;
v[0].Pos.X= rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
v[1].Pos.X= rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
v[2].Pos.X= rx; v[2].Pos.Y=-ry; v[2].Pos.Z= rz;
v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
break;
case 3: // front
for(int j=0;j<4;j++)
v[j].Color=c_side_1;
v[0].Pos.X= rx; v[0].Pos.Y= ry; v[0].Pos.Z= rz;
v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z= rz;
v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z= rz;
break;
case 4: // left
for(int j=0;j<4;j++)
v[j].Color=c_side_2;
v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z= rz;
v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z=-rz;
v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
v[3].Pos.X=-rx; v[3].Pos.Y=-ry, v[3].Pos.Z= rz;
break;
case 5: // bottom
for(int j=0;j<4;j++)
v[j].Color=c_bottom;
v[0].Pos.X= rx; v[0].Pos.Y=-ry; v[0].Pos.Z= rz;
v[1].Pos.X=-rx; v[1].Pos.Y=-ry; v[1].Pos.Z= rz;
v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
break;
for (int i=0; i<m_face_count; i++) {
switch (i) {
case 0: // top
v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
v[2].Pos.X= rx; v[2].Pos.Y= ry; v[2].Pos.Z= rz;
v[3].Pos.X= rx; v[3].Pos.Y= ry, v[3].Pos.Z=-rz;
break;
case 1: // back
v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
v[1].Pos.X= rx; v[1].Pos.Y= ry; v[1].Pos.Z=-rz;
v[2].Pos.X= rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
v[3].Pos.X=-rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
break;
case 2: //right
v[0].Pos.X= rx; v[0].Pos.Y= ry; v[0].Pos.Z=-rz;
v[1].Pos.X= rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
v[2].Pos.X= rx; v[2].Pos.Y=-ry; v[2].Pos.Z= rz;
v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
break;
case 3: // front
v[0].Pos.X= rx; v[0].Pos.Y= ry; v[0].Pos.Z= rz;
v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z= rz;
v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z= rz;
v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z= rz;
break;
case 4: // left
v[0].Pos.X=-rx; v[0].Pos.Y= ry; v[0].Pos.Z= rz;
v[1].Pos.X=-rx; v[1].Pos.Y= ry; v[1].Pos.Z=-rz;
v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
v[3].Pos.X=-rx; v[3].Pos.Y=-ry, v[3].Pos.Z= rz;
break;
case 5: // bottom
v[0].Pos.X= rx; v[0].Pos.Y=-ry; v[0].Pos.Z= rz;
v[1].Pos.X=-rx; v[1].Pos.Y=-ry; v[1].Pos.Z= rz;
v[2].Pos.X=-rx; v[2].Pos.Y=-ry; v[2].Pos.Z=-rz;
v[3].Pos.X= rx; v[3].Pos.Y=-ry, v[3].Pos.Z=-rz;
break;
}
v3f pos = v3f(p0.X,m_cloud_y,p0.Y);
pos -= intToFloat(m_camera_offset, BS);
for(u16 i=0; i<4; i++)
v[i].Pos += pos;
for (u16 k=0; k<4; k++) {
v[k].Pos += pos;
v[k].Color= c[i];
}
u16 indices[] = {0,1,2,2,3,0};
driver->drawVertexPrimitiveList(v, 4, indices, 2,
video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
driver->drawVertexPrimitiveList(v, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
}
}

View File

@ -87,6 +87,7 @@ private:
v2f m_camera_pos;
v3s16 m_camera_offset;
float m_time;
u16 m_face_count;
};

View File

@ -3582,6 +3582,7 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
ClientEnvironment::ClientEnvironment(Client *client, ClientMap *map, scene::ISceneManager *smgr):
m_client(client),
m_map(map),
m_local_player(NULL),
m_smgr(smgr)
{
assert(m_map);
@ -3606,21 +3607,17 @@ void ClientEnvironment::addPlayer(Player *player)
It is a failure if player is local and there already is a local
player
*/
assert(!(player->isLocal() == true && getLocalPlayer() != NULL));
if (player->isLocal()) {
assert(m_local_player == NULL);
m_local_player = (LocalPlayer*)player;
}
Environment::addPlayer(player);
}
LocalPlayer * ClientEnvironment::getLocalPlayer()
{
for(core::list<Player*>::Iterator i = m_players.begin();
i != m_players.end(); i++)
{
Player *player = *i;
if(player->isLocal())
return (LocalPlayer*)player;
}
return NULL;
return m_local_player;
}
void ClientEnvironment::step(float dtime)
@ -3628,7 +3625,6 @@ void ClientEnvironment::step(float dtime)
DSTACK(__FUNCTION_NAME);
// Get some settings
bool free_move = g_settings->getBool("free_move");
bool footprints = g_settings->getBool("enable_footprints");
// Get local player
@ -3696,7 +3692,7 @@ void ClientEnvironment::step(float dtime)
v3f lplayerpos = lplayer->getPosition();
// Apply physics
if (free_move == false && is_climbing == false) {
if (lplayer->control.free == false && is_climbing == false) {
// Gravity
v3f speed = lplayer->getSpeed();
if (lplayer->swimming_up == false)

View File

@ -468,6 +468,7 @@ public:
private:
Client *m_client;
ClientMap *m_map;
LocalPlayer *m_local_player;
scene::ISceneManager *m_smgr;
std::map<u16, ClientActiveObject*> m_active_objects;
Queue<ClientEnvEvent> m_client_event_queue;

View File

@ -947,21 +947,16 @@ void the_game(
float cloud_height = BS*100;
Clouds *clouds = NULL;
if(g_settings->getBool("enable_clouds"))
{
clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1,
cloud_height, time(0));
}
if (g_settings->getBool("enable_clouds"))
clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1, cloud_height, time(0));
/*
FarMesh
*/
FarMesh *farmesh = NULL;
if(g_settings->getBool("enable_farmesh"))
{
if (g_settings->getBool("enable_farmesh"))
farmesh = new FarMesh(smgr->getRootSceneNode(), smgr, -1, client.getMapSeed(), client.getMapType(), &client);
}
/*
Move into game
@ -1051,6 +1046,17 @@ void the_game(
bool show_debug_frametime = false;
u32 show_profiler = 0;
u32 show_profiler_max = 3; // Number of pages
float fps_max = g_settings->getFloat("fps_max");
float profiler_print_interval = g_settings->getFloat("profiler_print_interval");
bool free_move = g_settings->getBool("free_move");
bool fast_move = g_settings->getBool("fast_move");
f32 mouse_sensitivity = g_settings->getFloat("mouse_sensitivity");
bool highlight_selected_node = true;
if (g_settings->exists("selected_node") && g_settings->get("selected_node") == "outline")
highlight_selected_node = false;
bool enable_particles = g_settings->getBool("enable_particles");
bool enable_fog = g_settings->getBool("enable_fog");
/*
Main loop
@ -1068,26 +1074,22 @@ void the_game(
u32 lasttime = device->getTimer()->getTime();
v3s16 lastpointed(0,0,0);
while(device->run() && kill == false)
{
while (device->run() && kill == false) {
//std::cerr<<"frame"<<std::endl;
if(client.accessDenied())
{
if (client.accessDenied()) {
error_message = wgettext("Access denied. Reason: ")
+client.accessDeniedReason();
errorstream<<wide_to_narrow(error_message)<<std::endl;
break;
}
if(g_gamecallback->disconnect_requested)
{
if (g_gamecallback->disconnect_requested) {
g_gamecallback->disconnect_requested = false;
break;
}
if(g_gamecallback->changepassword_requested)
{
if (g_gamecallback->changepassword_requested) {
(new GUIPasswordChange(guienv, guiroot, -1,
&g_menumgr, &client))->drop();
g_gamecallback->changepassword_requested = false;
@ -1106,12 +1108,13 @@ void the_game(
v2s32 displaycenter(screensize.X/2,screensize.Y/2);
// Resize hotbar
if(screensize.Y <= 800)
if (screensize.Y <= 800) {
hotbar_imagesize = 32;
else if(screensize.Y <= 1280)
}else if (screensize.Y <= 1280) {
hotbar_imagesize = 48;
else
}else{
hotbar_imagesize = 64;
}
// Hilight boxes collected during the loop and displayed
core::list< core::aabbox3d<f32> > hilightboxes;
@ -1125,10 +1128,11 @@ void the_game(
{
// not using getRealTime is necessary for wine
u32 time = device->getTimer()->getTime();
if(time > lasttime)
if (time > lasttime) {
busytime_u32 = time - lasttime;
else
}else{
busytime_u32 = 0;
}
busytime = busytime_u32 / 1000.0;
}
@ -1140,11 +1144,9 @@ void the_game(
*/
{
float fps_max = g_settings->getFloat("fps_max");
u32 frametime_min = 1000./fps_max;
if(busytime_u32 < frametime_min)
{
if (busytime_u32 < frametime_min) {
u32 sleeptime = frametime_min - busytime_u32;
device->sleep(sleeptime);
}
@ -1159,10 +1161,11 @@ void the_game(
f32 dtime; // in seconds
u32 time = device->getTimer()->getTime();
if(time > lasttime)
if (time > lasttime) {
dtime = (time - lasttime) / 1000.0;
else
}else{
dtime = 0;
}
lasttime = time;
/* Run timers */
@ -1176,8 +1179,7 @@ void the_game(
Log frametime for visualization
*/
frametime_log.push_back(dtime);
if(frametime_log.size() > 100)
{
if (frametime_log.size() > 100) {
core::list<float>::Iterator i = frametime_log.begin();
frametime_log.erase(i);
}
@ -1195,15 +1197,13 @@ void the_game(
{
static f32 jitter1_max = 0.0;
static f32 counter = 0.0;
if(dtime_jitter1 > jitter1_max)
if (dtime_jitter1 > jitter1_max)
jitter1_max = dtime_jitter1;
counter += dtime;
if(counter > 0.0)
{
if (counter > 0.0) {
counter -= 3.0;
dtime_jitter1_max_sample = jitter1_max;
dtime_jitter1_max_fraction
= dtime_jitter1_max_sample / (dtime_avg1+0.001);
dtime_jitter1_max_fraction = dtime_jitter1_max_sample / (dtime_avg1+0.001);
jitter1_max = 0.0;
}
}
@ -1222,12 +1222,12 @@ void the_game(
static f32 jitter1_max = 0.0;
static f32 jitter1_min = 0.0;
static f32 counter = 0.0;
if(busytime_jitter1 > jitter1_max)
if (busytime_jitter1 > jitter1_max)
jitter1_max = busytime_jitter1;
if(busytime_jitter1 < jitter1_min)
if (busytime_jitter1 < jitter1_min)
jitter1_min = busytime_jitter1;
counter += dtime;
if(counter > 0.0){
if (counter > 0.0) {
counter -= 3.0;
busytime_jitter1_max_sample = jitter1_max;
busytime_jitter1_min_sample = jitter1_min;
@ -1242,8 +1242,7 @@ void the_game(
{
static float counter = 0.0;
counter -= dtime;
if(counter < 0)
{
if (counter < 0) {
counter = 30.0;
client.printDebugInfo(infostream);
}
@ -1252,16 +1251,13 @@ void the_game(
/*
Profiler
*/
float profiler_print_interval =
g_settings->getFloat("profiler_print_interval");
bool print_to_log = true;
if(profiler_print_interval == 0){
if (profiler_print_interval == 0) {
print_to_log = false;
profiler_print_interval = 5;
}
if(m_profiler_interval.step(dtime, profiler_print_interval))
{
if(print_to_log){
if (m_profiler_interval.step(dtime, profiler_print_interval)) {
if (print_to_log) {
infostream<<"Profiler:"<<std::endl;
g_profiler->print(infostream);
}
@ -1277,10 +1273,8 @@ void the_game(
*/
// Reset input if window not active or some menu is active
if(device->isWindowActive() == false || noMenuActive() == false)
{
if (device->isWindowActive() == false || noMenuActive() == false)
input->clear();
}
// Input handler step() (used by the random input generator)
input->step(dtime);
@ -1288,15 +1282,10 @@ void the_game(
/*
Launch menus according to keys
*/
if(input->wasKeyDown(getKeySetting("keymap_inventory")))
{
infostream<<"the_game: "
<<"Launching inventory"<<std::endl;
if (input->wasKeyDown(getKeySetting(VLKC_INVENTORY))) {
infostream<<"the_game: Launching inventory"<<std::endl;
GUIFormSpecMenu *menu =
new GUIFormSpecMenu(guienv, guiroot, -1,
&g_menumgr,
&client);
GUIFormSpecMenu *menu = new GUIFormSpecMenu(guienv, guiroot, -1, &g_menumgr, &client);
InventoryLocation inventoryloc;
inventoryloc.setCurrentPlayer();
@ -1306,53 +1295,42 @@ void the_game(
menu->setFormSpec(fio->getForm(), inventoryloc);
menu->setFormIO(fio);
menu->drop();
}
else if(input->wasKeyDown(EscapeKey))
{
infostream<<"the_game: "
<<"Launching pause menu"<<std::endl;
}else if (input->wasKeyDown(EscapeKey)) {
infostream<<"the_game: Launching pause menu"<<std::endl;
// It will delete itself by itself
(new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
&g_menumgr))->drop();
(new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback, &g_menumgr))->drop();
// Move mouse cursor on top of the disconnect button
input->setMousePos(displaycenter.X, displaycenter.Y+25);
}
else if(input->wasKeyDown(getKeySetting("keymap_chat")))
{
}else if (input->wasKeyDown(getKeySetting(VLKC_CHAT))) {
FormIO *fio = new ChatFormIO(&client);
(new GUITextInputMenu(guienv, guiroot, -1, &g_menumgr, fio, L""))->drop();
}
else if(input->wasKeyDown(getKeySetting("keymap_cmd")))
{
}else if (input->wasKeyDown(getKeySetting(VLKC_COMMAND))) {
FormIO *fio = new ChatFormIO(&client);
(new GUITextInputMenu(guienv, guiroot, -1, &g_menumgr, fio, L"/"))->drop();
}
else if(input->wasKeyDown(getKeySetting("keymap_freemove"))) {
if (g_settings->getBool("free_move")) {
g_settings->set("free_move","false");
}else if(input->wasKeyDown(getKeySetting(VLKC_FREEMOVE))) {
if (free_move) {
free_move = false;
statustext = wgettext("free_move disabled");
statustext_time = 0;
}else{
g_settings->set("free_move","true");
free_move = true;
statustext = wgettext("free_move enabled");
statustext_time = 0;
}
}
else if(input->wasKeyDown(getKeySetting("keymap_fastmove"))) {
if (g_settings->getBool("fast_move")) {
g_settings->set("fast_move","false");
}else if(input->wasKeyDown(getKeySetting(VLKC_FASTMOVE))) {
if (fast_move) {
fast_move = false;
statustext = wgettext("fast_move disabled");
statustext_time = 0;
}else{
g_settings->set("fast_move","true");
fast_move = true;
statustext = wgettext("fast_move enabled");
statustext_time = 0;
}
}
else if(input->wasKeyDown(getKeySetting("keymap_screenshot"))) {
}else if(input->wasKeyDown(getKeySetting(VLKC_SCREENSHOT))) {
irr::video::IImage* const image = driver->createScreenShot();
if (image) {
irr::c8 filename[256];
@ -1370,8 +1348,7 @@ void the_game(
}
image->drop();
}
}
else if (input->wasKeyDown(getKeySetting("keymap_toggle_hud"))) {
}else if (input->wasKeyDown(getKeySetting(VLKC_TOGGLE_HUD))) {
show_hud = !show_hud;
if (show_hud) {
statustext = wgettext("HUD shown");
@ -1379,8 +1356,7 @@ void the_game(
statustext = wgettext("HUD hidden");
}
statustext_time = 0;
}
else if (input->wasKeyDown(getKeySetting("keymap_toggle_chat"))) {
}else if (input->wasKeyDown(getKeySetting(VLKC_TOGGLE_CHAT))) {
show_chat = !show_chat;
if (show_chat) {
statustext = wgettext("Chat shown");
@ -1388,8 +1364,7 @@ void the_game(
statustext = wgettext("Chat hidden");
}
statustext_time = 0;
}
else if (input->wasKeyDown(getKeySetting("keymap_toggle_force_fog_off"))) {
}else if (input->wasKeyDown(getKeySetting(VLKC_TOGGLE_FOG))) {
force_fog_off = !force_fog_off;
if (force_fog_off) {
statustext = wgettext("Fog disabled");
@ -1397,8 +1372,7 @@ void the_game(
statustext = wgettext("Fog enabled");
}
statustext_time = 0;
}
else if (input->wasKeyDown(getKeySetting("keymap_toggle_update_camera"))) {
}else if (input->wasKeyDown(getKeySetting(VLKC_TOGGLE_CAMERA))) {
disable_camera_update = !disable_camera_update;
if (disable_camera_update) {
statustext = wgettext("Camera update disabled");
@ -1406,8 +1380,7 @@ void the_game(
statustext = wgettext("Camera update enabled");
}
statustext_time = 0;
}
else if (input->wasKeyDown(getKeySetting("keymap_toggle_debug"))) {
}else if (input->wasKeyDown(getKeySetting(VLKC_TOGGLE_DEBUG))) {
// Initial / 3x toggle: Chat only
// 1x toggle: Debug text with chat
// 2x toggle: Debug text with frametime
@ -1416,8 +1389,7 @@ void the_game(
show_debug_frametime = false;
statustext = wgettext("Debug info shown");
statustext_time = 0;
}
else if (show_debug_frametime) {
}else if (show_debug_frametime) {
show_debug = false;
show_debug_frametime = false;
statustext = wgettext("Debug info and frametime graph hidden");
@ -1427,8 +1399,7 @@ void the_game(
statustext = wgettext("Frametime graph shown");
statustext_time = 0;
}
}
else if (input->wasKeyDown(getKeySetting("keymap_toggle_profiler"))) {
}else if (input->wasKeyDown(getKeySetting(VLKC_TOGGLE_PROFILER))) {
show_profiler = (show_profiler + 1) % (show_profiler_max + 1);
// FIXME: This updates the profiler with incomplete values
@ -1444,8 +1415,7 @@ void the_game(
statustext = wgettext("Profiler hidden");
statustext_time = 0;
}
}
else if (input->wasKeyDown(getKeySetting("keymap_increase_viewing_range_min"))) {
}else if (input->wasKeyDown(getKeySetting(VLKC_RANGE_PLUS))) {
s16 range = g_settings->getS16("viewing_range_nodes_min");
s16 range_new = range + 10;
g_settings->set("viewing_range_nodes_min", itos(range_new));
@ -1453,8 +1423,7 @@ void the_game(
swprintf(buff,512,wgettext("Minimum viewing range changed to %d"),range_new);
statustext = std::wstring(buff);
statustext_time = 0;
}
else if (input->wasKeyDown(getKeySetting("keymap_decrease_viewing_range_min"))) {
}else if (input->wasKeyDown(getKeySetting(VLKC_RANGE_MINUS))) {
s16 range = g_settings->getS16("viewing_range_nodes_min");
s16 range_new = range - 10;
if (range_new < 0)
@ -1501,7 +1470,7 @@ void the_game(
}
// Viewing range selection
if (input->wasKeyDown(getKeySetting("keymap_rangeselect"))) {
if (input->wasKeyDown(getKeySetting(VLKC_RANGE))) {
draw_control.range_all = !draw_control.range_all;
if (draw_control.range_all) {
infostream<<"Enabled full viewing range"<<std::endl;
@ -1515,7 +1484,7 @@ void the_game(
}
// Print debug stacks
if (input->wasKeyDown(getKeySetting("keymap_print_debug_stacks"))) {
if (input->wasKeyDown(getKeySetting(VLKC_PRINT_DEBUG))) {
dstream<<"-----------------------------------------"
<<std::endl;
dstream<<DTIME<<"Printing debug stacks:"<<std::endl;
@ -1545,8 +1514,7 @@ void the_game(
if (invert_mouse)
dy = -dy;
float d = g_settings->getFloat("mouse_sensitivity");
d = rangelim(d, 0.01, 100.0);
f32 d = rangelim(mouse_sensitivity, 0.01, 100.0);
camera_yaw -= dx*d;
camera_pitch += dy*d;
@ -1576,6 +1544,8 @@ void the_game(
false,
false,
false,
fast_move,
free_move,
camera_pitch,
camera_yaw
);
@ -1591,13 +1561,15 @@ void the_game(
float a_pitch,
float a_yaw*/
PlayerControl control(
input->isKeyDown(getKeySetting("keymap_forward")),
input->isKeyDown(getKeySetting("keymap_backward")),
input->isKeyDown(getKeySetting("keymap_left")),
input->isKeyDown(getKeySetting("keymap_right")),
input->isKeyDown(getKeySetting("keymap_jump")),
input->isKeyDown(getKeySetting("keymap_special1")),
input->isKeyDown(getKeySetting("keymap_sneak")),
input->isKeyDown(getKeySetting(VLKC_FORWARD)),
input->isKeyDown(getKeySetting(VLKC_BACKWARD)),
input->isKeyDown(getKeySetting(VLKC_LEFT)),
input->isKeyDown(getKeySetting(VLKC_RIGHT)),
input->isKeyDown(getKeySetting(VLKC_JUMP)),
input->isKeyDown(getKeySetting(VLKC_USE)),
input->isKeyDown(getKeySetting(VLKC_SNEAK)),
fast_move,
free_move,
camera_pitch,
camera_yaw
);
@ -1796,10 +1768,10 @@ void the_game(
Visualize selection
*/
if (g_settings->exists("selected_node") && g_settings->get("selected_node") == "outline") {
hilightboxes.push_back(nodehilightbox);
}else{
if (highlight_selected_node) {
client.setTempMod(nodepos, NodeMod(NODEMOD_SELECTION));
}else{
hilightboxes.push_back(nodehilightbox);
}
if (nodig_delay_counter > 0.0) {
@ -1847,7 +1819,7 @@ void the_game(
client.clearTempMod(nodepos);
}else{
dig_time_complete = prop.time;
if (g_settings->getBool("enable_particles"))
if (enable_particles)
addPunchingParticles(smgr, player, nodepos, content_features(n).tiles);
if (dig_time_complete >= 0.001) {
@ -1866,7 +1838,7 @@ void the_game(
client.clearTempMod(nodepos);
client.removeNode(nodepos);
if (g_settings->getBool("enable_particles"))
if (enable_particles)
addDiggingParticles(smgr, player, nodepos, content_features(n).tiles);
dig_time = 0;
@ -1947,10 +1919,11 @@ void the_game(
u32 daynight_ratio = client.getDayNightRatio();
u8 l = decode_light((daynight_ratio * LIGHT_SUN) / 1000);
video::SColor bgcolor = video::SColor(
255,
bgcolor_bright.getRed() * l / 255,
bgcolor_bright.getGreen() * l / 255,
bgcolor_bright.getBlue() * l / 255);
255,
bgcolor_bright.getRed() * l / 255,
bgcolor_bright.getGreen() * l / 255,
bgcolor_bright.getBlue() * l / 255
);
float brightness = (float)l/255.0;
@ -1995,7 +1968,7 @@ void the_game(
Fog
*/
if (g_settings->getBool("enable_fog") == true && !force_fog_off) {
if (enable_fog && !force_fog_off) {
f32 range;
if (farmesh) {
range = BS*farmesh_range;
@ -2355,6 +2328,18 @@ void the_game(
}
}
// save some settings
if (free_move) {
g_settings->set("free_move","true");
}else{
g_settings->set("free_move","false");
}
if (fast_move) {
g_settings->set("fast_move","true");
}else{
g_settings->set("fast_move","false");
}
/*
Drop stuff
*/

View File

@ -667,7 +667,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
{
if (event.EventType==EET_KEY_INPUT_EVENT) {
KeyPress kp(event.KeyInput);
if (event.KeyInput.PressedDown && (kp == EscapeKey || kp == getKeySetting("keymap_inventory"))) {
if (event.KeyInput.PressedDown && (kp == EscapeKey || kp == getKeySetting(VLKC_INVENTORY))) {
m_tooltip_element->setVisible(false);
quitMenu();
return true;

View File

@ -356,20 +356,20 @@ bool GUIKeyChangeMenu::acceptInput()
}
void GUIKeyChangeMenu::init_keys()
{
key_forward = getKeySetting("keymap_forward");
key_backward = getKeySetting("keymap_backward");
key_left = getKeySetting("keymap_left");
key_right = getKeySetting("keymap_right");
key_jump = getKeySetting("keymap_jump");
key_sneak = getKeySetting("keymap_sneak");
key_inventory = getKeySetting("keymap_inventory");
key_chat = getKeySetting("keymap_chat");
key_cmd = getKeySetting("keymap_cmd");
key_range = getKeySetting("keymap_rangeselect");
key_fly = getKeySetting("keymap_freemove");
key_fast = getKeySetting("keymap_fastmove");
key_use = getKeySetting("keymap_special1");
key_dump = getKeySetting("keymap_print_debug_stacks");
key_forward = getKeySetting(VLKC_FORWARD);
key_backward = getKeySetting(VLKC_BACKWARD);
key_left = getKeySetting(VLKC_LEFT);
key_right = getKeySetting(VLKC_RIGHT);
key_jump = getKeySetting(VLKC_JUMP);
key_sneak = getKeySetting(VLKC_SNEAK);
key_inventory = getKeySetting(VLKC_INVENTORY);
key_chat = getKeySetting(VLKC_CHAT);
key_cmd = getKeySetting(VLKC_COMMAND);
key_range = getKeySetting(VLKC_RANGE);
key_fly = getKeySetting(VLKC_FREEMOVE);
key_fast = getKeySetting(VLKC_FASTMOVE);
key_use = getKeySetting(VLKC_USE);
key_dump = getKeySetting(VLKC_PRINT_DEBUG);
}
bool GUIKeyChangeMenu::resetMenu()

View File

@ -351,20 +351,61 @@ const KeyPress NumberKey[] = {
Key config
*/
// A simple cache for quicker lookup
std::map<std::string, KeyPress> g_key_setting_cache;
static const char* keymap_strings[] = {
"keymap_forward",
"keymap_backward",
"keymap_left",
"keymap_right",
"keymap_jump",
"keymap_sneak",
"keymap_inventory",
"keymap_special1",
"keymap_chat",
"keymap_cmd",
"keymap_rangeselect",
"keymap_freemove",
"keymap_fastmove",
"keymap_screenshot",
"keymap_toggle_hud",
"keymap_toggle_chat",
"keymap_toggle_force_fog_off",
"keymap_toggle_update_camera",
"keymap_toggle_debug",
"keymap_toggle_profiler",
"keymap_increase_viewing_range_min",
"keymap_decrease_viewing_range_min",
"keymap_print_debug_stacks",
NULL
};
KeyPress getKeySetting(const char *settingname)
KeyPress *g_key_setting_cache[256];
static bool key_setting_cache_init = false;
KeyPress getKeySetting(KeyCode code)
{
std::map<std::string, KeyPress>::iterator n;
n = g_key_setting_cache.find(settingname);
if(n != g_key_setting_cache.end())
return n->second;
g_key_setting_cache[settingname] = g_settings->get(settingname).c_str();
return g_key_setting_cache.find(settingname)->second;
if (!key_setting_cache_init)
clearKeyCache();
if (g_key_setting_cache[code])
return *g_key_setting_cache[code];
g_key_setting_cache[code] = new KeyPress(g_settings->get(keymap_strings[code]).c_str());
return *g_key_setting_cache[code];
}
void clearKeyCache()
{
g_key_setting_cache.clear();
if (key_setting_cache_init) {
for (int i=0; i<VLKC_MAX; i++) {
if (g_key_setting_cache[i] == NULL)
continue;
delete g_key_setting_cache[i];
g_key_setting_cache[i] = NULL;
}
}else{
for (int i=0; i<VLKC_MAX; i++) {
g_key_setting_cache[i] = NULL;
}
}
key_setting_cache_init = true;
}

View File

@ -65,8 +65,36 @@ extern const KeyPress EscapeKey;
extern const KeyPress CancelKey;
extern const KeyPress NumberKey[10];
enum KeyCode {
VLKC_FORWARD = 0,
VLKC_BACKWARD,
VLKC_LEFT,
VLKC_RIGHT,
VLKC_JUMP,
VLKC_SNEAK,
VLKC_INVENTORY,
VLKC_USE,
VLKC_CHAT,
VLKC_COMMAND,
VLKC_RANGE,
VLKC_FREEMOVE,
VLKC_FASTMOVE,
VLKC_SCREENSHOT,
VLKC_TOGGLE_HUD,
VLKC_TOGGLE_CHAT,
VLKC_TOGGLE_FOG,
VLKC_TOGGLE_CAMERA,
VLKC_TOGGLE_DEBUG,
VLKC_TOGGLE_PROFILER,
VLKC_RANGE_PLUS,
VLKC_RANGE_MINUS,
VLKC_PRINT_DEBUG,
// put new codes above this
VLKC_MAX
};
// Key configuration getter
KeyPress getKeySetting(const char *settingname);
KeyPress getKeySetting(KeyCode code);
// Clear fast lookup cache
void clearKeyCache();

View File

@ -487,7 +487,7 @@ public:
if(counter1 < 0.0)
{
counter1 = 0.1*Rand(1, 40);
keydown.toggle(getKeySetting("keymap_jump"));
keydown.toggle(getKeySetting(VLKC_JUMP));
}
}
{
@ -496,7 +496,7 @@ public:
if(counter1 < 0.0)
{
counter1 = 0.1*Rand(1, 40);
keydown.toggle(getKeySetting("keymap_special1"));
keydown.toggle(getKeySetting(VLKC_USE));
}
}
{
@ -505,7 +505,7 @@ public:
if(counter1 < 0.0)
{
counter1 = 0.1*Rand(1, 40);
keydown.toggle(getKeySetting("keymap_forward"));
keydown.toggle(getKeySetting(VLKC_FORWARD));
}
}
{
@ -514,7 +514,7 @@ public:
if(counter1 < 0.0)
{
counter1 = 0.1*Rand(1, 40);
keydown.toggle(getKeySetting("keymap_left"));
keydown.toggle(getKeySetting(VLKC_LEFT));
}
}
{

View File

@ -3390,6 +3390,10 @@ ClientMap::ClientMap(
m_box = core::aabbox3d<f32>(-BS*1000000,-BS*1000000,-BS*1000000,
BS*1000000,BS*1000000,BS*1000000);
m_render_trilinear = g_settings->getBool("trilinear_filter");
m_render_bilinear = g_settings->getBool("bilinear_filter");
m_render_anisotropic = g_settings->getBool("anisotropic_filter");
}
ClientMap::~ClientMap()
@ -3501,22 +3505,17 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
bool is_transparent_pass = pass == scene::ESNRP_TRANSPARENT;
std::string prefix;
if(pass == scene::ESNRP_SOLID)
if (pass == scene::ESNRP_SOLID) {
prefix = "CM: solid: ";
else
}else{
prefix = "CM: transparent: ";
}
/*
This is called two times per frame, reset on the non-transparent one
*/
if(pass == scene::ESNRP_SOLID)
{
if (pass == scene::ESNRP_SOLID)
m_last_drawn_sectors.clear();
}
bool use_trilinear_filter = g_settings->getBool("trilinear_filter");
bool use_bilinear_filter = g_settings->getBool("bilinear_filter");
bool use_anisotropic_filter = g_settings->getBool("anisotropic_filter");
/*
Get time for measuring timeout.
@ -3819,9 +3818,9 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
if (buf == NULL)
continue;
buf->getMaterial().setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
buf->getMaterial().setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
buf->getMaterial().setFlag(video::EMF_TRILINEAR_FILTER, m_render_trilinear);
buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, m_render_bilinear);
buf->getMaterial().setFlag(video::EMF_ANISOTROPIC_FILTER, m_render_anisotropic);
const video::SMaterial& material = buf->getMaterial();
video::IMaterialRenderer* rnd =
@ -3893,12 +3892,10 @@ void ClientMap::renderPostFx()
// - If the player is in liquid, draw a semi-transparent overlay.
ContentFeatures& features = content_features(n);
video::SColor post_effect_color = features.post_effect_color;
if(features.solidness == 2 && g_settings->getBool("free_move") == false)
{
if (features.solidness == 2 && m_client->getLocalPlayer()->control.free == false) {
post_effect_color = video::SColor(255, 0, 0, 0);
}
if (post_effect_color.getAlpha() != 0)
{
if (post_effect_color.getAlpha() != 0) {
// Draw a full-screen rectangle
video::IVideoDriver* driver = SceneManager->getVideoDriver();
v2u32 ss = driver->getScreenSize();

View File

@ -625,6 +625,10 @@ private:
v3s16 m_camera_offset;
JMutex m_camera_mutex;
bool m_render_trilinear;
bool m_render_bilinear;
bool m_render_anisotropic;
core::map<v2s16, bool> m_last_drawn_sectors;
};

View File

@ -695,8 +695,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
*/
// Skip collision detection if a special movement mode is used
bool free_move = g_settings->getBool("free_move");
if (free_move) {
if (control.free) {
position += m_speed * dtime;
setPosition(position);
return;
@ -744,7 +743,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
v3s16 pp = floatToInt(position + v3f(0,0.5*BS,0), BS);
v3s16 pp2 = floatToInt(position + v3f(0,-0.2*BS,0), BS);
is_climbing = ((content_features(map.getNode(pp).getContent()).climbable ||
content_features(map.getNode(pp2).getContent()).climbable) && !free_move);
content_features(map.getNode(pp2).getContent()).climbable) && !control.free);
}catch(InvalidPositionException &e) {
is_climbing = false;
}
@ -921,12 +920,7 @@ void LocalPlayer::applyControl(float dtime)
v3f speed = v3f(0,0,0);
bool free_move = g_settings->getBool("free_move");
bool fast_move = g_settings->getBool("fast_move");
bool continuous_forward = g_settings->getBool("continuous_forward");
if(free_move || is_climbing)
{
if (control.free || is_climbing) {
v3f speed = getSpeed();
speed.Y = 0;
setSpeed(speed);
@ -936,72 +930,50 @@ void LocalPlayer::applyControl(float dtime)
bool superspeed = false;
// If free movement and fast movement, always move fast
if(free_move && fast_move)
if (control.free && control.fast)
superspeed = true;
// Auxiliary button 1 (E)
if(control.aux1)
{
if(free_move)
{
if (control.aux1) {
if (control.free) {
// In free movement mode, aux1 descends
v3f speed = getSpeed();
if(fast_move)
if (control.fast) {
speed.Y = -20*BS;
else
}else{
speed.Y = -walkspeed_max;
}
setSpeed(speed);
}
else if(is_climbing)
{
}else if (is_climbing) {
v3f speed = getSpeed();
speed.Y = -3*BS;
setSpeed(speed);
}
else
{
}else{
// If not free movement but fast is allowed, aux1 is
// "Turbo button"
if(fast_move)
if (control.fast)
superspeed = true;
}
}
if(continuous_forward)
if (control.up)
speed += move_direction;
if(control.up)
{
if(continuous_forward)
superspeed = true;
else
speed += move_direction;
}
if(control.down)
{
if (control.down)
speed -= move_direction;
}
if(control.left)
{
if (control.left)
speed += move_direction.crossProduct(v3f(0,1,0));
}
if(control.right)
{
if (control.right)
speed += move_direction.crossProduct(v3f(0,-1,0));
}
if(control.jump)
{
if(free_move)
{
if (control.jump) {
if (control.free) {
v3f speed = getSpeed();
if(fast_move)
if (control.fast) {
speed.Y = 20*BS;
else
}else{
speed.Y = walkspeed_max;
}
setSpeed(speed);
}
else if(touching_ground)
{
}else if (touching_ground) {
v3f speed = getSpeed();
/*
NOTE: The d value in move() affects jump height by
@ -1010,18 +982,14 @@ void LocalPlayer::applyControl(float dtime)
*/
speed.Y = 6.5*BS;
setSpeed(speed);
}
// Use the oscillating value for getting out of water
// (so that the player doesn't fly on the surface)
else if(in_water)
{
}else if (in_water) {
// Use the oscillating value for getting out of water
// (so that the player doesn't fly on the surface)
v3f speed = getSpeed();
speed.Y = 1.5*BS;
setSpeed(speed);
swimming_up = true;
}
else if(is_climbing)
{
} else if (is_climbing) {
v3f speed = getSpeed();
speed.Y = 3*BS;
setSpeed(speed);
@ -1029,17 +997,18 @@ void LocalPlayer::applyControl(float dtime)
}
// The speed of the player (Y is ignored)
if(superspeed)
if (superspeed) {
speed = speed.normalize() * walkspeed_max * 5.0;
else if(control.sneak)
}else if (control.sneak) {
speed = speed.normalize() * walkspeed_max / 3.0;
else
}else{
speed = speed.normalize() * walkspeed_max;
}
f32 inc = walk_acceleration * BS * dtime;
// Faster acceleration if fast and free movement
if(free_move && fast_move)
if (control.free && control.fast)
inc = walk_acceleration * BS * dtime * 10;
// Accelerate to target speed with maximum increment

View File

@ -444,6 +444,8 @@ struct PlayerControl
jump = false;
aux1 = false;
sneak = false;
fast = false;
free = false;
pitch = 0;
yaw = 0;
}
@ -455,6 +457,8 @@ struct PlayerControl
bool a_jump,
bool a_aux1,
bool a_sneak,
bool a_fast,
bool a_free,
float a_pitch,
float a_yaw
)
@ -466,6 +470,8 @@ struct PlayerControl
jump = a_jump;
aux1 = a_aux1;
sneak = a_sneak;
fast = a_fast;
free = a_free;
pitch = a_pitch;
yaw = a_yaw;
}
@ -476,6 +482,8 @@ struct PlayerControl
bool jump;
bool aux1;
bool sneak;
bool fast;
bool free;
float pitch;
float yaw;
};