Compare commits

...

11 Commits

Author SHA1 Message Date
jachoo 082dd7e4e1 Fix variable names and comments in crawling and extended block selecting 2011-12-14 20:10:35 +01:00
jachoo 6347f4aeeb Merge branch 'master' of https://github.com/celeron55/minetest 2011-12-13 23:59:43 +01:00
jachoo 253481300b "Crouch" renaimed to "crawl" 2011-12-13 23:53:19 +01:00
jachoo 1324d39db9 Crouching & crawling 2011-12-13 23:35:20 +01:00
Perttu Ahola 69579306dd Extend load screen maximum time 2011-12-11 16:52:19 +02:00
jachoo b22c78301b Better 'torchlike' drawing 2011-12-04 20:00:29 +01:00
jachoo 61a7fb67fb a 2011-12-04 16:29:11 +01:00
jachoo e92ea680a9 Merge branch 'master' of git://github.com/celeron55/minetest 2011-12-04 16:12:01 +01:00
jachoo da398e01e6 Extended block selecting 2011-12-04 16:11:04 +01:00
jachoo d4bf0b6e99 Visual Studio - headers added to CMakeLists.txt 2011-12-04 14:29:51 +01:00
jachoo 93db635364 Crouching (Left Control key) 2011-12-04 14:29:49 +01:00
9 changed files with 274 additions and 38 deletions

View File

@ -38,6 +38,7 @@
#keymap_right = KEY_KEY_D
#keymap_jump = KEY_SPACE
#keymap_sneak = KEY_LSHIFT
#keymap_crouch = KEY_LCONTROL
#keymap_inventory = KEY_KEY_I
# Go down ladder / go down in fly mode / go fast in fast mode
#keymap_special1 = KEY_KEY_E
@ -104,6 +105,8 @@
#screenshot_path = .
# Amount of view bobbing (0 = no view bobbing, 1.0 = normal, 2.0 = double)
#view_bobbing_amount = 1.0
# Enables extended block selecting feature (you con now build everything without sneaking)
#extended_block_selecting = false
#
# Server stuff

View File

@ -187,6 +187,76 @@ set(minetestserver_SRCS
servermain.cpp
)
# Want to see header files in solution explorer
if(MSVC)
set(common_HDRS
log.h
content_sao.h
mapgen.h
content_nodemeta.h
content_mapnode.h
auth.h
collision.h
nodemetadata.h
serverobject.h
noise.h
mineral.h
porting.h
materials.h
defaultsettings.h
mapnode.h
voxel.h
inventory.h
debug.h
serialization.h
light.h
filesys.h
connection.h
environment.h
server.h
servercommand.h
socket.h
mapblock.h
mapsector.h
map.h
player.h
utility.h
test.h
sha1.h
base64.h
ban.h
)
set(minetest_HDRS
${common_HDRS}
content_mapblock.h
content_cao.h
mapblock_mesh.h
farmesh.h
keycode.h
camera.h
clouds.h
clientobject.h
guiMainMenu.h
guiKeyChangeMenu.h
guiMessageMenu.h
guiTextInputMenu.h
guiInventoryMenu.h
guiPauseMenu.h
guiPasswordChange.h
guiDeathScreen.h
client.h
tile.h
game.h
main.h
)
set(minetestserver_HDRS
${common_HDRS}
)
set(common_SRCS ${common_SRCS} ${common_HDRS})
set(minetest_SRCS ${minetest_SRCS} ${minetest_HDRS})
set(minetestserver_SRCS ${minetestserver_SRCS} ${minetestserver_HDRS})
endif()
include_directories(
${PROJECT_BINARY_DIR}
${IRRLICHT_INCLUDE_DIR}

View File

@ -680,27 +680,41 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
ap.x0(), ap.y0()),
};
video::S3DVertex vertices2[4];
for(s32 i=0; i<4; i++)
{
if(dir == v3s16(1,0,0))
vertices[i].Pos.rotateXZBy(0);
if(dir == v3s16(-1,0,0))
else if(dir == v3s16(-1,0,0))
vertices[i].Pos.rotateXZBy(180);
if(dir == v3s16(0,0,1))
else if(dir == v3s16(0,0,1))
vertices[i].Pos.rotateXZBy(90);
if(dir == v3s16(0,0,-1))
else if(dir == v3s16(0,0,-1))
vertices[i].Pos.rotateXZBy(-90);
if(dir == v3s16(0,-1,0))
else if(dir == v3s16(0,-1,0))
vertices[i].Pos.rotateXZBy(45);
if(dir == v3s16(0,1,0))
else if(dir == v3s16(0,1,0))
vertices[i].Pos.rotateXZBy(-45);
vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
vertices2[i] = vertices[i];
vertices2[i].Pos += intToFloat(p + blockpos_nodes, BS);
}
u16 indices[] = {0,1,2,2,3,0};
// Add to mesh collector
collector.append(material, vertices, 4, indices, 6);
collector.append(material, vertices2, 4, indices, 6);
if(dir.Y != 0) //floor or ceiling - add second mesh rotated by 90*
{
for(s32 i=0; i<4; i++)
{
vertices[i].Pos.rotateXZBy(-90);
vertices2[i].Pos = vertices[i].Pos + intToFloat(p + blockpos_nodes, BS);
}
collector.append(material, vertices2, 4, indices, 6);
}
break;}
case NDT_SIGNLIKE:
{

View File

@ -36,6 +36,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("keymap_jump", "KEY_SPACE");
settings->setDefault("keymap_sneak", "KEY_LSHIFT");
settings->setDefault("keymap_drop", "KEY_KEY_Q");
settings->setDefault("keymap_crawl", "KEY_LCONTROL");
settings->setDefault("keymap_inventory", "KEY_KEY_I");
settings->setDefault("keymap_special1", "KEY_KEY_E");
settings->setDefault("keymap_chat", "KEY_KEY_T");
@ -80,6 +81,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("view_bobbing_amount", "1.0");
settings->setDefault("enable_3d_clouds", "false");
settings->setDefault("opaque_water", "false");
settings->setDefault("extended_block_selecting", "false");
// Server stuff
// "map-dir" doesn't exist by default.

View File

@ -346,9 +346,17 @@ PointedThing getPointedThing(Client *client, v3f player_position,
// That didn't work, try to find a pointed at node
f32 mindistance = BS * 1001;
static const bool ext_block_sel = g_settings->getBool("extended_block_selecting");
bool free_node_found = false;
f32 mindistance = BS * 1001; //used for regular blocks
f32 maxdistance = -BS * 1001; //used for free blocks
v3s16 pos_i = floatToInt(player_position, BS);
v3s16 cam_i = floatToInt(camera_position, BS);
v3s16 camdir_i(camera_direction.X>=0?1:-1,
camera_direction.Y>=0?1:-1,
camera_direction.Z>=0?1:-1);
/*infostream<<"pos_i=("<<pos_i.X<<","<<pos_i.Y<<","<<pos_i.Z<<")"
<<std::endl;*/
@ -374,8 +382,8 @@ PointedThing getPointedThing(Client *client, v3f player_position,
{
continue;
}
if(!isPointableNode(n, client, liquids_pointable))
continue;
/*if(!isPointableNode(n, client, liquids_pointable))
continue;*/
v3s16 np(x,y,z);
v3f npf = intToFloat(np, BS);
@ -548,27 +556,96 @@ PointedThing getPointedThing(Client *client, v3f player_position,
if(facebox.intersectsWithLine(shootline))
{
result.type = POINTEDTHING_NODE;
result.node_undersurface = np;
result.node_abovesurface = np + dirs[i];
mindistance = distance;
if(isPointableNode(n, client, liquids_pointable))
{
result.type = POINTEDTHING_NODE;
result.node_undersurface = np;
result.node_abovesurface = np + dirs[i];
mindistance = distance;
//hilightbox = facebox;
//hilightbox = facebox;
const float d = 0.502;
core::aabbox3d<f32> nodebox
(-BS*d, -BS*d, -BS*d, BS*d, BS*d, BS*d);
v3f nodepos_f = intToFloat(np, BS);
nodebox.MinEdge += nodepos_f;
nodebox.MaxEdge += nodepos_f;
hilightbox = nodebox;
should_show_hilightbox = true;
const float d = 0.502;
core::aabbox3d<f32> nodebox
(-BS*d, -BS*d, -BS*d, BS*d, BS*d, BS*d);
v3f nodepos_f = intToFloat(np, BS);
nodebox.MinEdge += nodepos_f;
nodebox.MaxEdge += nodepos_f;
hilightbox = nodebox;
should_show_hilightbox = true;
//if no node has been found - we try to find 'fake' pointed node
}else if(ext_block_sel
&& result.type == POINTEDTHING_NOTHING
&& distance < (BS*6) //is this enough?
&& np != pos_i
&& np != v3s16(pos_i.X,pos_i.Y+1,pos_i.Z)
&& client->getNodeDefManager()->get(n).buildable_to)
{
bool can_build = false;
v3s16 neigh_pos;
for(int i=0; i<6; i++)
{
const v3s16& npos = dirs[i];
v3s16 ap = np + npos;
try{
MapNode an = client->getNode(ap);
//check if we can build onto this node
//FIXME: when it will be possible to build on torches, rails etc. then change .walkable to .pointable
if(!client->getNodeDefManager()->get(an).walkable)
continue;
//check if we can build onto this node by normally selecting it
if( npos.X==camdir_i.X //check if it's the same direction as camera
|| npos.Y==camdir_i.Y
|| npos.Z==camdir_i.Z
|| (npos.X != 0 && cam_i.X == np.X) //check if it's the same axis as camera
|| (npos.Y != 0 && cam_i.Y == np.Y)
|| (npos.Z != 0 && cam_i.Z == np.Z) )
{
can_build = false;
break;
}
//finally, we can build 'extended way' on this block
can_build = true;
neigh_pos = ap;
}catch(InvalidPositionException&){}
}
if(can_build && distance > maxdistance){
maxdistance = distance;
//result.type = POINTEDTHING_NODE; //we can't do this here
free_node_found = true; //instead, we set this and check at the end
result.node_undersurface = neigh_pos; //yes, these are swaped
result.node_abovesurface = np;
const float d = 0.502;
core::aabbox3d<f32> nodebox
(-BS*d, -BS*d, -BS*d, BS*d, BS*d, BS*d);
v3f nodepos_f = intToFloat(np, BS);
nodebox.MinEdge += nodepos_f;
nodebox.MaxEdge += nodepos_f;
hilightbox = nodebox;
//should_show_hilightbox = true; //we must do this at the end
}
}
}
} // if distance < mindistance
} // for dirs
} // regular block
} // for coords
if(ext_block_sel && result.type == POINTEDTHING_NOTHING && free_node_found){
result.is_fake = true;
result.type = POINTEDTHING_NODE;
should_show_hilightbox = true;
}
return result;
}
@ -824,7 +901,7 @@ void the_game(
bool got_content = false;
{
float frametime = 0.033;
const float timeout = 5.0;
const float timeout = 30.0;
float time_counter = 0.0;
for(;;)
{
@ -1561,7 +1638,8 @@ void the_game(
false,
false,
camera_pitch,
camera_yaw
camera_yaw,
false
);
client.setPlayerControl(control);
}
@ -1585,7 +1663,8 @@ void the_game(
input->isKeyDown(getKeySetting("keymap_special1")),
input->isKeyDown(getKeySetting("keymap_sneak")),
camera_pitch,
camera_yaw
camera_yaw,
input->isKeyDown(getKeySetting("keymap_crawl"))
);
client.setPlayerControl(control);
}
@ -1828,7 +1907,7 @@ void the_game(
*/
if(nodig_delay_timer <= 0.0 && input->getLeftState())
if(!pointed.is_fake && nodig_delay_timer <= 0.0 && input->getLeftState())
{
if(!digging)
{

View File

@ -31,6 +31,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "environment.h"
#include "gamedef.h"
#define EYE_OFFSET_MAX (BS+(5*BS)/8)
#define EYE_OFFSET_MIN (BS * 0.9f)
Player::Player(IGameDef *gamedef):
touching_ground(false),
in_water(false),
@ -47,7 +50,8 @@ Player::Player(IGameDef *gamedef):
m_pitch(0),
m_yaw(0),
m_speed(0,0,0),
m_position(0,0,0)
m_position(0,0,0),
m_eye_offset(0,EYE_OFFSET_MAX,0)
{
updateName("<not set>");
resetInventory();
@ -183,7 +187,8 @@ void Player::deSerialize(std::istream &is)
LocalPlayer::LocalPlayer(IGameDef *gamedef):
Player(gamedef),
m_sneak_node(32767,32767,32767),
m_sneak_node_exists(false)
m_sneak_node_exists(false),
m_must_crawl(false)
{
// Initialize hp to 0, so that no hearts will be shown if server
// doesn't support health points
@ -289,7 +294,8 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
assert(d > pos_max_d);
float player_radius = BS*0.35;
float player_height = BS*1.7;
float player_height = m_eye_offset.Y + BS*0.05f;
float player_maxheight = EYE_OFFSET_MAX + BS*0.05f;
// Maximum distance over border for sneaking
f32 sneak_max = BS*0.4;
@ -347,6 +353,14 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
position.Y + player_height,
position.Z + player_radius
);
core::aabbox3d<f32> playerbox_standing(
position.X - player_radius,
position.Y - 0.0,
position.Z - player_radius,
position.X + player_radius,
position.Y + player_maxheight,
position.Z + player_radius
);
core::aabbox3d<f32> playerbox_old(
oldpos.X - player_radius,
oldpos.Y - 0.0,
@ -371,11 +385,12 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
<<"):"<<std::endl;*/
bool standing_on_unloaded = false;
const s16 player_height_i = player_height/BS + 1;
/*
Go through every node around the player
*/
for(s16 y = oldpos_i.Y - 1; y <= oldpos_i.Y + 2; y++)
for(s16 y = oldpos_i.Y - 1; y <= oldpos_i.Y + player_height_i; y++)
for(s16 z = oldpos_i.Z - 1; z <= oldpos_i.Z + 1; z++)
for(s16 x = oldpos_i.X - 1; x <= oldpos_i.X + 1; x++)
{
@ -583,6 +598,32 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
if(sneak_node_found && control.sneak)
touching_ground = true;
}
/*
Check if player must crawl
*/
bool must_crawl = false;
v3s16 pos_head_i = floatToInt(v3f(position.X,position.Y+EYE_OFFSET_MAX+BS*0.05f,position.Z), BS);
for(s16 z = -1; z <= 1; z++)
for(s16 x = -1; x <= 1; x++)
{
try{
// Player collides into walkable nodes
v3s16 np(pos_head_i.X+x,pos_head_i.Y,pos_head_i.Z+z);
if(nodemgr->get(map.getNode(np)).walkable == false)
continue;
core::aabbox3d<f32> nodebox = getNodeBox(np, BS);
if( (m_must_crawl || control.crawl) //only if we were crawling before
&& playerbox_standing.intersectsWithBox(nodebox) //only when colliding with the node
)
{
must_crawl = true;
}
}
catch(InvalidPositionException &e)
{}
}
m_must_crawl = must_crawl;
/*
Set new position
@ -644,6 +685,9 @@ void LocalPlayer::applyControl(float dtime)
// If free movement and fast movement, always move fast
if(free_move && fast_move)
superspeed = true;
// If must crawl - then crawl ;)
if(m_must_crawl) control.crawl = true;
// Auxiliary button 1 (E)
if(control.aux1)
@ -737,7 +781,7 @@ void LocalPlayer::applyControl(float dtime)
// The speed of the player (Y is ignored)
if(superspeed)
speed = speed.normalize() * walkspeed_max * 5.0;
else if(control.sneak)
else if(control.sneak || control.crawl)
speed = speed.normalize() * walkspeed_max / 3.0;
else
speed = speed.normalize() * walkspeed_max;
@ -750,6 +794,19 @@ void LocalPlayer::applyControl(float dtime)
// Accelerate to target speed with maximum increment
accelerate(speed, inc);
static const f32 eyes_delta = 10.f;
if(control.crawl){
//crawling
if(m_eye_offset.Y > EYE_OFFSET_MIN + 0.01f)
m_eye_offset.Y += (EYE_OFFSET_MIN-m_eye_offset.Y) * eyes_delta * dtime;
else m_eye_offset.Y = EYE_OFFSET_MIN;
}else{
//standing
if(m_eye_offset.Y < EYE_OFFSET_MAX - 0.01f)
m_eye_offset.Y += (EYE_OFFSET_MAX-m_eye_offset.Y) * eyes_delta * dtime;
else m_eye_offset.Y = EYE_OFFSET_MAX;
}
}
#endif

View File

@ -69,7 +69,8 @@ public:
// This is at the height of the eyes of the current figure
// return v3f(0, BS+BS/2, 0);
// This is more like in minecraft
return v3f(0,BS+(5*BS)/8,0);
//return v3f(0,BS+(5*BS)/8,0);
return m_eye_offset;
}
v3f getEyePosition()
@ -169,6 +170,7 @@ protected:
f32 m_yaw;
v3f m_speed;
v3f m_position;
v3f m_eye_offset;
public:
@ -188,6 +190,7 @@ struct PlayerControl
sneak = false;
pitch = 0;
yaw = 0;
crawl = false;
}
PlayerControl(
bool a_up,
@ -198,7 +201,8 @@ struct PlayerControl
bool a_aux1,
bool a_sneak,
float a_pitch,
float a_yaw
float a_yaw,
bool a_crawl
)
{
up = a_up;
@ -210,6 +214,7 @@ struct PlayerControl
sneak = a_sneak;
pitch = a_pitch;
yaw = a_yaw;
crawl = a_crawl;
}
bool up;
bool down;
@ -220,6 +225,7 @@ struct PlayerControl
bool sneak;
float pitch;
float yaw;
bool crawl;
};
class LocalPlayer : public Player
@ -246,6 +252,8 @@ private:
v3s16 m_sneak_node;
// Whether the player is allowed to sneak
bool m_sneak_node_exists;
// Whether player can't stand
bool m_must_crawl;
};
#endif // !SERVER

View File

@ -259,7 +259,8 @@ PointedThing::PointedThing():
type(POINTEDTHING_NOTHING),
node_undersurface(0,0,0),
node_abovesurface(0,0,0),
object_id(-1)
object_id(-1),
is_fake(false)
{}
std::string PointedThing::dump() const
@ -273,8 +274,9 @@ std::string PointedThing::dump() const
{
const v3s16 &u = node_undersurface;
const v3s16 &a = node_abovesurface;
os<<"[node under="<<u.X<<","<<u.Y<<","<<u.Z
<< " above="<<a.X<<","<<a.Y<<","<<a.Z<<"]";
os << "[node under="<<u.X<<","<<u.Y<<","<<u.Z
<< " above="<<a.X<<","<<a.Y<<","<<a.Z
<< (is_fake?" fake]":"]");
}
else if(type == POINTEDTHING_OBJECT)
{

View File

@ -1766,6 +1766,7 @@ struct PointedThing
v3s16 node_undersurface;
v3s16 node_abovesurface;
s16 object_id;
bool is_fake; //if true, then disallow digging [not serialized!]
PointedThing();
std::string dump() const;