aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/client.cpp5
-rw-r--r--src/client/game.cpp20
-rw-r--r--src/client/game.h3
-rw-r--r--src/client/gameui.cpp3
-rw-r--r--src/client/inputhandler.h22
-rw-r--r--src/defaultsettings.cpp4
-rw-r--r--src/network/clientpackethandler.cpp7
-rw-r--r--src/script/cpp_api/s_cheats.cpp2
-rw-r--r--src/script/lua_api/l_client.cpp22
-rw-r--r--src/script/lua_api/l_client.h3
-rw-r--r--src/script/lua_api/l_env.cpp7
-rw-r--r--src/script/lua_api/l_localplayer.cpp35
-rw-r--r--src/script/lua_api/l_localplayer.h11
13 files changed, 123 insertions, 21 deletions
diff --git a/src/client/client.cpp b/src/client/client.cpp
index 74e7b9b0d..db80beb9f 100644
--- a/src/client/client.cpp
+++ b/src/client/client.cpp
@@ -506,7 +506,7 @@ void Client::step(float dtime)
{
float &counter = m_playerpos_send_timer;
counter += dtime;
- if((m_state == LC_Ready) && (counter >= m_recommended_send_interval) && ! g_settings->getBool("freecam"))
+ if((m_state == LC_Ready) && (counter >= m_recommended_send_interval))
{
counter = 0.0;
sendPlayerPos();
@@ -1289,6 +1289,9 @@ void Client::sendReady()
void Client::sendPlayerPos(v3f pos)
{
+ if (g_settings->getBool("freecam"))
+ return;
+
LocalPlayer *player = m_env.getLocalPlayer();
if (!player)
return;
diff --git a/src/client/game.cpp b/src/client/game.cpp
index b9e7e4d9b..ba360a153 100644
--- a/src/client/game.cpp
+++ b/src/client/game.cpp
@@ -238,11 +238,9 @@ void Game::run()
{
ProfilerGraph graph;
RunStats stats = { 0 };
- CameraOrientation cam_view_target = { 0 };
- CameraOrientation cam_view = { 0 };
FpsControl draw_times = { 0 };
f32 dtime; // in seconds
-
+
/* Clear the profiler */
Profiler::GraphValues dummyvalues;
g_profiler->graphGet(dummyvalues);
@@ -309,9 +307,8 @@ void Game::run()
processClientEvents(&cam_view_target);
updateCamera(draw_times.busy_time, dtime);
updateSound(dtime);
- if (! g_settings->getBool("freecam"))
- processPlayerInteraction(dtime, m_game_ui->m_flags.show_hud,
- m_game_ui->m_flags.show_debug);
+ processPlayerInteraction(dtime, m_game_ui->m_flags.show_hud,
+ m_game_ui->m_flags.show_debug);
updateFrame(&graph, &stats, dtime, cam_view);
updateProfilerGraphs(&graph);
@@ -2814,7 +2811,7 @@ void Game::handlePointingAtObject(const PointedThing &pointed,
bool do_punch = false;
bool do_punch_damage = false;
- if (runData.object_hit_delay_timer <= 0.0) {
+ if (runData.object_hit_delay_timer <= 0.0 || g_settings->getBool("spamclick")) {
do_punch = true;
do_punch_damage = true;
runData.object_hit_delay_timer = object_hit_delay;
@@ -3338,10 +3335,15 @@ void Game::freecamChangedCallback(const std::string &setting_name, void *data)
Game *game = (Game *) data;
LocalPlayer *player = game->client->getEnv().getLocalPlayer();
static v3f player_pos = player->getPosition();
- if (g_settings->getBool("freecam"))
+ static v3f player_speed = player->getSpeed();
+ if (g_settings->getBool("freecam")) {
player_pos = player->getPosition();
- else
+ player_speed = player->getSpeed();
+ game->camera->setCameraMode(CAMERA_MODE_FIRST);
+ } else {
player->setPosition(player_pos);
+ player->setSpeed(player_speed);
+ }
game->updatePlayerCAOVisibility();
}
diff --git a/src/client/game.h b/src/client/game.h
index aac8f8f38..e5557ee18 100644
--- a/src/client/game.h
+++ b/src/client/game.h
@@ -927,6 +927,9 @@ public:
bool m_does_lost_focus_pause_game = false;
+ CameraOrientation cam_view_target = { 0 };
+ CameraOrientation cam_view = { 0 };
+
#ifdef __ANDROID__
bool m_cache_hold_aux1;
bool m_android_chat_open;
diff --git a/src/client/gameui.cpp b/src/client/gameui.cpp
index 8e6c82b11..a9057052e 100644
--- a/src/client/gameui.cpp
+++ b/src/client/gameui.cpp
@@ -210,8 +210,7 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_
m_guitext_status->enableOverrideColor(true);
}
- // Hide chat when console is visible
- //m_guitext_chat->setVisible(isChatVisible() && !chat_console->isVisible());
+ m_guitext_chat->setVisible(isChatVisible());
}
void GameUI::initFlags()
diff --git a/src/client/inputhandler.h b/src/client/inputhandler.h
index fc7998f20..e006affb2 100644
--- a/src/client/inputhandler.h
+++ b/src/client/inputhandler.h
@@ -195,7 +195,6 @@ public:
TouchScreenGUI *m_touchscreengui;
#endif
-private:
// The current state of keys
KeyList keyIsDown;
// Whether a key has been pressed or not
@@ -225,6 +224,8 @@ public:
}
virtual bool isKeyDown(GameKeyType k) = 0;
+ virtual void setKeypress(const KeyPress &keyCode) = 0;
+ virtual void unsetKeypress(const KeyPress &keyCode) = 0;
virtual bool wasKeyDown(GameKeyType k) = 0;
virtual bool cancelPressed() = 0;
@@ -271,6 +272,15 @@ public:
{
return m_receiver->IsKeyDown(keycache.key[k]) || joystick.isKeyDown(k);
}
+ virtual void setKeypress(const KeyPress &keyCode)
+ {
+ m_receiver->keyIsDown.set(keyCode);
+ m_receiver->keyWasDown.set(keyCode);
+ }
+ virtual void unsetKeypress(const KeyPress &keyCode)
+ {
+ m_receiver->keyIsDown.unset(keyCode);
+ }
virtual bool wasKeyDown(GameKeyType k)
{
return m_receiver->WasKeyDown(keycache.key[k]) || joystick.wasKeyDown(k);
@@ -367,7 +377,7 @@ public:
m_receiver->clearInput();
}
-private:
+ private:
MyEventReceiver *m_receiver = nullptr;
v2s32 m_mousepos;
};
@@ -383,6 +393,14 @@ public:
}
virtual bool isKeyDown(GameKeyType k) { return keydown[keycache.key[k]]; }
+ virtual void setKeypress(const KeyPress &keyCode)
+ {
+ keydown.set(keyCode);
+ }
+ virtual void unsetKeypress(const KeyPress &keyCode)
+ {
+ keydown.unset(keyCode);
+ }
virtual bool wasKeyDown(GameKeyType k) { return false; }
virtual bool cancelPressed() { return false; }
virtual v2s32 getMousePos() { return mousepos; }
diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp
index 17129e403..a22b6b851 100644
--- a/src/defaultsettings.cpp
+++ b/src/defaultsettings.cpp
@@ -88,6 +88,8 @@ void set_default_settings(Settings *settings)
settings->setDefault("no_night", "false");
settings->setDefault("coords", "false");
settings->setDefault("point_liquids", "false");
+ settings->setDefault("log_particles", "false");
+ settings->setDefault("spamclick", "false");
// Keymap
settings->setDefault("remote_port", "30000");
@@ -386,7 +388,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("max_simultaneous_block_sends_per_client", "40");
settings->setDefault("time_send_interval", "5");
- settings->setDefault("default_game", "minetest");
+ settings->setDefault("default_game", "mineclone2");
settings->setDefault("motd", "");
settings->setDefault("max_users", "15");
settings->setDefault("creative_mode", "false");
diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp
index 9e0b35f53..05ae91f06 100644
--- a/src/network/clientpackethandler.cpp
+++ b/src/network/clientpackethandler.cpp
@@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include <iostream>
#include "client/client.h"
#include "util/base64.h"
@@ -977,7 +978,11 @@ void Client::handleCommand_SpawnParticle(NetworkPacket* pkt)
ClientEvent *event = new ClientEvent();
event->type = CE_SPAWN_PARTICLE;
event->spawn_particle = new ParticleParameters(p);
-
+
+ if (g_settings->getBool("log_particles")) {
+ std::cout << p.pos.X << " " << p.pos.Y << " " << p.pos.Z << std::endl;
+ }
+
m_client_event_queue.push(event);
}
diff --git a/src/script/cpp_api/s_cheats.cpp b/src/script/cpp_api/s_cheats.cpp
index 73183c64e..8f3e4ef14 100644
--- a/src/script/cpp_api/s_cheats.cpp
+++ b/src/script/cpp_api/s_cheats.cpp
@@ -41,7 +41,7 @@ bool ScriptApiCheatsCheat::is_enabled()
{
try {
return ! m_function_ref && g_settings->getBool(m_setting);
- } catch (SettingNotFoundException) {
+ } catch (SettingNotFoundException &) {
return false;
}
}
diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp
index 5d0ccf2e0..b9a8f77a8 100644
--- a/src/script/lua_api/l_client.cpp
+++ b/src/script/lua_api/l_client.cpp
@@ -35,6 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "map.h"
#include "util/string.h"
#include "nodedef.h"
+#include "client/keycode.h"
#define checkCSMRestrictionFlag(flag) \
( getClient(L)->checkCSMRestrictionFlag(CSMRestrictionFlags::flag) )
@@ -470,13 +471,31 @@ int ModApiClient::l_get_inventory(lua_State *L)
inventory_location.deSerialize(location);
inventory = client->getInventory(inventory_location);
push_inventory(L, inventory);
- } catch (SerializationError) {
+ } catch (SerializationError &) {
lua_pushnil(L);
}
return 1;
}
+// set_keypress(key_setting, pressed) -> returns true on success
+int ModApiClient::l_set_keypress(lua_State *L)
+{
+ std::string setting_name = "keymap_" + readParam<std::string>(L, 1);
+ bool pressed = lua_isboolean(L, 2) && readParam<bool>(L, 2);
+ try {
+ KeyPress keyCode = getKeySetting(setting_name.c_str());
+ if (pressed)
+ g_game->input->setKeypress(keyCode);
+ else
+ g_game->input->unsetKeypress(keyCode);
+ lua_pushboolean(L, true);
+ } catch (SettingNotFoundException &) {
+ lua_pushboolean(L, false);
+ }
+ return 1;
+}
+
void ModApiClient::Initialize(lua_State *L, int top)
{
API_FCT(get_current_modname);
@@ -508,4 +527,5 @@ void ModApiClient::Initialize(lua_State *L, int top)
API_FCT(place_node);
API_FCT(dig_node);
API_FCT(get_inventory);
+ API_FCT(set_keypress);
}
diff --git a/src/script/lua_api/l_client.h b/src/script/lua_api/l_client.h
index 21a540f8f..1ea57f9ee 100644
--- a/src/script/lua_api/l_client.h
+++ b/src/script/lua_api/l_client.h
@@ -116,6 +116,9 @@ private:
// get_inventory(location)
static int l_get_inventory(lua_State *L);
+
+ // l_set_keypress(key_setting, pressed)
+ static int l_set_keypress(lua_State *L);
public:
static void Initialize(lua_State *L, int top);
};
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index 2ea3b08b9..ee384ad10 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -1365,7 +1365,7 @@ int ModApiEnvMod::l_delete_area(lua_State *L)
// max_jump, max_drop, algorithm) -> table containing path
int ModApiEnvMod::l_find_path(lua_State *L)
{
- GET_ENV_PTR;
+ Environment *env = getEnv(L);
v3s16 pos1 = read_v3s16(L, 1);
v3s16 pos2 = read_v3s16(L, 2);
@@ -1382,8 +1382,8 @@ int ModApiEnvMod::l_find_path(lua_State *L)
if (algorithm == "Dijkstra")
algo = PA_DIJKSTRA;
}
-
- std::vector<v3s16> path = get_path(&env->getServerMap(), env->getGameDef()->ndef(), pos1, pos2,
+
+ std::vector<v3s16> path = get_path(&env->getMap(), env->getGameDef()->ndef(), pos1, pos2,
searchdistance, max_jump, max_drop, algo);
if (!path.empty()) {
@@ -1568,6 +1568,7 @@ void ModApiEnvMod::InitializeClient(lua_State *L, int top)
API_FCT(find_nodes_near_under_air_except);
API_FCT(find_nodes_in_area);
API_FCT(find_nodes_in_area_under_air);
+ API_FCT(find_path);
API_FCT(line_of_sight);
API_FCT(raycast);
}
diff --git a/src/script/lua_api/l_localplayer.cpp b/src/script/lua_api/l_localplayer.cpp
index 9d7db41ce..8e743c3ab 100644
--- a/src/script/lua_api/l_localplayer.cpp
+++ b/src/script/lua_api/l_localplayer.cpp
@@ -62,6 +62,38 @@ int LuaLocalPlayer::l_get_velocity(lua_State *L)
return 1;
}
+int LuaLocalPlayer::l_set_velocity(lua_State *L)
+{
+ LocalPlayer *player = getobject(L, 1);
+
+ v3f pos = checkFloatPos(L, 2);
+ player->setSpeed(pos);
+
+ return 0;
+}
+
+int LuaLocalPlayer::l_get_yaw(lua_State *L)
+{
+ LocalPlayer *player = getobject(L, 1);
+
+ lua_pushinteger(L, player->getYaw());
+ return 1;
+}
+
+int LuaLocalPlayer::l_set_yaw(lua_State *L)
+{
+ LocalPlayer *player = getobject(L, 1);
+
+ if (lua_isnumber(L, 2)) {
+ int yaw = lua_tonumber(L, 2);
+ player->setYaw(yaw);
+ g_game->cam_view.camera_yaw = yaw;
+ g_game->cam_view_target.camera_yaw = yaw;
+ }
+
+ return 0;
+}
+
int LuaLocalPlayer::l_get_hp(lua_State *L)
{
LocalPlayer *player = getobject(L, 1);
@@ -480,6 +512,9 @@ void LuaLocalPlayer::Register(lua_State *L)
const char LuaLocalPlayer::className[] = "LocalPlayer";
const luaL_Reg LuaLocalPlayer::methods[] = {
luamethod(LuaLocalPlayer, get_velocity),
+ luamethod(LuaLocalPlayer, set_velocity),
+ luamethod(LuaLocalPlayer, get_yaw),
+ luamethod(LuaLocalPlayer, set_yaw),
luamethod(LuaLocalPlayer, get_hp),
luamethod(LuaLocalPlayer, get_name),
luamethod(LuaLocalPlayer, get_wield_index),
diff --git a/src/script/lua_api/l_localplayer.h b/src/script/lua_api/l_localplayer.h
index a5d1081c7..c59cef764 100644
--- a/src/script/lua_api/l_localplayer.h
+++ b/src/script/lua_api/l_localplayer.h
@@ -34,6 +34,15 @@ private:
// get_velocity(self)
static int l_get_velocity(lua_State *L);
+
+ // set_velocity(self, vel)
+ static int l_set_velocity(lua_State *L);
+
+ // get_yaw(self)
+ static int l_get_yaw(lua_State *L);
+
+ // set_yaw(self, yaw)
+ static int l_set_yaw(lua_State *L);
// get_hp(self)
static int l_get_hp(lua_State *L);
@@ -75,6 +84,8 @@ private:
// get_pos(self)
static int l_get_pos(lua_State *L);
+
+ // set_pos(self, pos)
static int l_set_pos(lua_State *L);
// get_movement_acceleration(self)