#include "client.h"
#include "client/tile.h" // For TextureSource
#include "client/keys.h"
+#include "client/joystick_controller.h"
#include "clientmap.h"
#include "clouds.h"
#include "config.h"
void draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
gui::IGUIFont *font) const
{
+ // Do *not* use UNORDERED_MAP here as the order needs
+ // to be the same for each call to prevent flickering
std::map<std::string, Meta> m_meta;
for (std::deque<Piece>::const_iterator k = m_log.begin();
i != piece.values.end(); ++i) {
const std::string &id = i->first;
const float &value = i->second;
- std::map<std::string, Meta>::iterator j =
- m_meta.find(id);
+ std::map<std::string, Meta>::iterator j = m_meta.find(id);
if (j == m_meta.end()) {
m_meta[id] = Meta(value);
static inline void create_formspec_menu(GUIFormSpecMenu **cur_formspec,
InventoryManager *invmgr, IGameDef *gamedef,
IWritableTextureSource *tsrc, IrrlichtDevice *device,
+ JoystickController *joystick,
IFormSource *fs_src, TextDest *txt_dest, Client *client)
{
if (*cur_formspec == 0) {
- *cur_formspec = new GUIFormSpecMenu(device, guiroot, -1, &g_menumgr,
- invmgr, gamedef, tsrc, fs_src, txt_dest, client);
+ *cur_formspec = new GUIFormSpecMenu(device, joystick,
+ guiroot, -1, &g_menumgr, invmgr, gamedef, tsrc,
+ fs_src, txt_dest, client);
(*cur_formspec)->doPause = false;
/*
static void show_deathscreen(GUIFormSpecMenu **cur_formspec,
InventoryManager *invmgr, IGameDef *gamedef,
- IWritableTextureSource *tsrc, IrrlichtDevice *device, Client *client)
+ IWritableTextureSource *tsrc, IrrlichtDevice *device,
+ JoystickController *joystick, Client *client)
{
std::string formspec =
std::string(FORMSPEC_VERSION_STRING) +
FormspecFormSource *fs_src = new FormspecFormSource(formspec);
LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_DEATH_SCREEN", client);
- create_formspec_menu(cur_formspec, invmgr, gamedef, tsrc, device, fs_src, txt_dst, NULL);
+ create_formspec_menu(cur_formspec, invmgr, gamedef, tsrc, device,
+ joystick, fs_src, txt_dst, NULL);
}
/******************************************************************************/
static void show_pause_menu(GUIFormSpecMenu **cur_formspec,
InventoryManager *invmgr, IGameDef *gamedef,
IWritableTextureSource *tsrc, IrrlichtDevice *device,
- bool singleplayermode)
+ JoystickController *joystick, bool singleplayermode)
{
#ifdef __ANDROID__
std::string control_text = strgettext("Default Controls:\n"
FormspecFormSource *fs_src = new FormspecFormSource(os.str());
LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_PAUSE_MENU");
- create_formspec_menu(cur_formspec, invmgr, gamedef, tsrc, device, fs_src, txt_dst, NULL);
+ create_formspec_menu(cur_formspec, invmgr, gamedef, tsrc, device,
+ joystick, fs_src, txt_dst, NULL);
std::string con("btn_continue");
(*cur_formspec)->setFocus(con);
(*cur_formspec)->doPause = true;
setStaticText(guitext_chat, recent_chat);
// Update gui element size and position
- s32 chat_y = 5 + line_height;
+ s32 chat_y = 5;
if (show_debug)
- chat_y += line_height;
+ chat_y += 2 * line_height;
// first pass to calculate height of text to be set
s32 width = std::min(g_fontengine->getTextWidth(recent_chat.c_str()) + 10,
= getKeySetting("keymap_decrease_viewing_range_min");
key[KeyType::RANGESELECT]
= getKeySetting("keymap_rangeselect");
+ key[KeyType::ZOOM] = getKeySetting("keymap_zoom");
key[KeyType::QUICKTUNE_NEXT] = getKeySetting("keymap_quicktune_next");
key[KeyType::QUICKTUNE_PREV] = getKeySetting("keymap_quicktune_prev");
void decreaseViewRange(float *statustext_time);
void toggleFullViewRange(float *statustext_time);
- void updateCameraDirection(CameraOrientation *cam, VolatileRunFlags *flags);
+ void updateCameraDirection(CameraOrientation *cam, VolatileRunFlags *flags,
+ float dtime);
void updateCameraOrientation(CameraOrientation *cam,
- const VolatileRunFlags &flags);
+ const VolatileRunFlags &flags, float dtime);
void updatePlayerControl(const CameraOrientation &cam);
void step(f32 *dtime);
void processClientEvents(CameraOrientation *cam, float *damage_flash);
static void settingChangedCallback(const std::string &setting_name, void *data);
void readSettings();
- bool getLeftClicked()
+ inline bool getLeftClicked()
{
- return input->getLeftClicked();
+ return input->getLeftClicked() ||
+ input->joystick.getWasKeyDown(KeyType::MOUSE_L);
}
- bool getRightClicked()
+ inline bool getRightClicked()
{
- return input->getRightClicked();
+ return input->getRightClicked() ||
+ input->joystick.getWasKeyDown(KeyType::MOUSE_R);
}
- bool isLeftPressed()
+ inline bool isLeftPressed()
{
- return input->getLeftState();
+ return input->getLeftState() ||
+ input->joystick.isKeyDown(KeyType::MOUSE_L);
}
- bool isRightPressed()
+ inline bool isRightPressed()
{
- return input->getRightState();
+ return input->getRightState() ||
+ input->joystick.isKeyDown(KeyType::MOUSE_R);
}
- bool getLeftReleased()
+ inline bool getLeftReleased()
{
- return input->getLeftReleased();
+ return input->getLeftReleased() ||
+ input->joystick.wasKeyReleased(KeyType::MOUSE_L);
}
- bool isKeyDown(GameKeyType k)
+ inline bool isKeyDown(GameKeyType k)
{
- return input->isKeyDown(keycache.key[k]);
+ return input->isKeyDown(keycache.key[k]) || input->joystick.isKeyDown(k);
}
- bool wasKeyDown(GameKeyType k)
+ inline bool wasKeyDown(GameKeyType k)
{
- return input->wasKeyDown(keycache.key[k]);
+ return input->wasKeyDown(keycache.key[k]) || input->joystick.wasKeyDown(k);
}
#ifdef __ANDROID__
*/
bool m_cache_doubletap_jump;
bool m_cache_enable_clouds;
+ bool m_cache_enable_joysticks;
bool m_cache_enable_particles;
bool m_cache_enable_fog;
+ bool m_cache_enable_noclip;
+ bool m_cache_enable_free_move;
f32 m_cache_mouse_sensitivity;
+ f32 m_cache_joystick_frustum_sensitivity;
f32 m_repeat_right_click_time;
#ifdef __ANDROID__
&settingChangedCallback, this);
g_settings->registerChangedCallback("enable_clouds",
&settingChangedCallback, this);
+ g_settings->registerChangedCallback("doubletap_joysticks",
+ &settingChangedCallback, this);
g_settings->registerChangedCallback("enable_particles",
&settingChangedCallback, this);
g_settings->registerChangedCallback("enable_fog",
&settingChangedCallback, this);
g_settings->registerChangedCallback("mouse_sensitivity",
&settingChangedCallback, this);
+ g_settings->registerChangedCallback("joystick_frustum_sensitivity",
+ &settingChangedCallback, this);
g_settings->registerChangedCallback("repeat_rightclick_time",
&settingChangedCallback, this);
+ g_settings->registerChangedCallback("noclip",
+ &settingChangedCallback, this);
+ g_settings->registerChangedCallback("free_move",
+ &settingChangedCallback, this);
readSettings();
&settingChangedCallback, this);
g_settings->deregisterChangedCallback("repeat_rightclick_time",
&settingChangedCallback, this);
+ g_settings->deregisterChangedCallback("noclip",
+ &settingChangedCallback, this);
+ g_settings->deregisterChangedCallback("free_move",
+ &settingChangedCallback, this);
}
bool Game::startup(bool *kill,
updateProfilers(runData, stats, draw_times, dtime);
processUserInput(&flags, &runData, dtime);
// Update camera before player movement to avoid camera lag of one frame
- updateCameraDirection(&cam_view_target, &flags);
+ updateCameraDirection(&cam_view_target, &flags, dtime);
float cam_smoothing = 0;
if (g_settings->getBool("cinematic"))
cam_smoothing = 1 - g_settings->getFloat("cinematic_camera_smoothing");
/* Set window caption
*/
std::wstring str = utf8_to_wide(PROJECT_NAME_C);
+ str += L" ";
+ str += utf8_to_wide(g_version_hash);
str += L" [";
str += driver->getName();
str += L"]";
wait_time += dtime;
// Only time out if we aren't waiting for the server we started
if ((*address != "") && (wait_time > 10)) {
- *error_message = "Connection timed out.";
+ bool sent_old_init = g_settings->getFlag("send_pre_v25_init");
+ // If no pre v25 init was sent, and no answer was received,
+ // but the low level connection could be established
+ // (meaning that we have a peer id), then we probably wanted
+ // to connect to a legacy server. In this case, tell the user
+ // to enable the option to be able to connect.
+ if (!sent_old_init &&
+ (client->getProtoVersion() == 0) &&
+ client->connectedToServer()) {
+ *error_message = "Connection failure: init packet not "
+ "recognized by server.\n"
+ "Most likely the server uses an old protocol version (<v25).\n"
+ "Please ask the server owner to update to 0.4.13 or later.\n"
+ "To still connect to the server in the meantime,\n"
+ "you can enable the 'send_pre_v25_init' setting by editing minetest.conf,\n"
+ "or by enabling the 'Client -> Network -> Support older Servers'\n"
+ "entry in the advanced settings menu.";
+ } else {
+ *error_message = "Connection timed out.";
+ }
errorstream << *error_message << std::endl;
break;
}
if (g_gamecallback->changevolume_requested) {
(new GUIVolumeChange(guienv, guiroot, -1,
- &g_menumgr, client))->drop();
+ &g_menumgr))->drop();
g_gamecallback->changevolume_requested = false;
}
} else if (wasKeyDown(KeyType::ESC) || input->wasKeyDown(CancelKey)) {
if (!gui_chat_console->isOpenInhibited()) {
show_pause_menu(¤t_formspec, client, gamedef,
- texture_src, device, simple_singleplayer_mode);
+ texture_src, device, &input->joystick,
+ simple_singleplayer_mode);
}
} else if (wasKeyDown(KeyType::CHAT)) {
openConsole(0.2, L"");
s32 wheel = input->getMouseWheel();
u16 max_item = MYMIN(PLAYER_INVENTORY_SIZE - 1,
- player->hud_hotbar_itemcount - 1);
+ player->hud_hotbar_itemcount - 1);
+
+ s32 dir = wheel;
+
+ if (input->joystick.wasKeyDown(KeyType::SCROLL_DOWN)) {
+ dir = -1;
+ }
- if (wheel < 0)
+ if (input->joystick.wasKeyDown(KeyType::SCROLL_UP)) {
+ dir = 1;
+ }
+
+ if (dir < 0)
*new_playeritem = *new_playeritem < max_item ? *new_playeritem + 1 : 0;
- else if (wheel > 0)
+ else if (dir > 0)
*new_playeritem = *new_playeritem > 0 ? *new_playeritem - 1 : max_item;
- // else wheel == 0
-
+ // else dir == 0
/* Item selection using keyboard
*/
TextDest *txt_dst = new TextDestPlayerInventory(client);
create_formspec_menu(¤t_formspec, client, gamedef, texture_src,
- device, fs_src, txt_dst, client);
+ device, &input->joystick, fs_src, txt_dst, client);
InventoryLocation inventoryloc;
inventoryloc.setCurrentPlayer();
void Game::updateCameraDirection(CameraOrientation *cam,
- VolatileRunFlags *flags)
+ VolatileRunFlags *flags, float dtime)
{
if ((device->isWindowActive() && noMenuActive()) || random_input) {
if (flags->first_loop_after_window_activation)
flags->first_loop_after_window_activation = false;
else
- updateCameraOrientation(cam, *flags);
+ updateCameraOrientation(cam, *flags, dtime);
input->setMousePos((driver->getScreenSize().Width / 2),
(driver->getScreenSize().Height / 2));
}
}
-
void Game::updateCameraOrientation(CameraOrientation *cam,
- const VolatileRunFlags &flags)
+ const VolatileRunFlags &flags, float dtime)
{
#ifdef HAVE_TOUCHSCREENGUI
if (g_touchscreengui) {
cam->camera_pitch = g_touchscreengui->getPitch();
} else {
#endif
+
s32 dx = input->getMousePos().X - (driver->getScreenSize().Width / 2);
s32 dy = input->getMousePos().Y - (driver->getScreenSize().Height / 2);
}
#endif
+ if (m_cache_enable_joysticks) {
+ f32 c = m_cache_joystick_frustum_sensitivity * (1.f / 32767.f) * dtime;
+ cam->camera_yaw -= input->joystick.getAxisWithoutDead(JA_FRUSTUM_HORIZONTAL) *
+ c;
+ cam->camera_pitch += input->joystick.getAxisWithoutDead(JA_FRUSTUM_VERTICAL) *
+ c;
+ }
+
cam->camera_pitch = rangelim(cam->camera_pitch, -89.5, 89.5);
}
{
//TimeTaker tt("update player control", NULL, PRECISION_NANO);
+ // DO NOT use the isKeyDown method for the forward, backward, left, right
+ // buttons, as the code that uses the controls needs to be able to
+ // distinguish between the two in order to know when to use joysticks.
+
PlayerControl control(
input->isKeyDown(keycache.key[KeyType::FORWARD]),
input->isKeyDown(keycache.key[KeyType::BACKWARD]),
input->isKeyDown(keycache.key[KeyType::LEFT]),
input->isKeyDown(keycache.key[KeyType::RIGHT]),
- input->isKeyDown(keycache.key[KeyType::JUMP]),
- input->isKeyDown(keycache.key[KeyType::SPECIAL1]),
- input->isKeyDown(keycache.key[KeyType::SNEAK]),
- input->getLeftState(),
- input->getRightState(),
+ isKeyDown(KeyType::JUMP),
+ isKeyDown(KeyType::SPECIAL1),
+ isKeyDown(KeyType::SNEAK),
+ isKeyDown(KeyType::ZOOM),
+ isLeftPressed(),
+ isRightPressed(),
cam.camera_pitch,
- cam.camera_yaw
+ cam.camera_yaw,
+ input->joystick.getAxisWithoutDead(JA_SIDEWARD_MOVE),
+ input->joystick.getAxisWithoutDead(JA_FORWARD_MOVE)
);
u32 keypress_bits =
- ( (u32)(input->isKeyDown(keycache.key[KeyType::FORWARD]) & 0x1) << 0) |
- ( (u32)(input->isKeyDown(keycache.key[KeyType::BACKWARD]) & 0x1) << 1) |
- ( (u32)(input->isKeyDown(keycache.key[KeyType::LEFT]) & 0x1) << 2) |
- ( (u32)(input->isKeyDown(keycache.key[KeyType::RIGHT]) & 0x1) << 3) |
- ( (u32)(input->isKeyDown(keycache.key[KeyType::JUMP]) & 0x1) << 4) |
- ( (u32)(input->isKeyDown(keycache.key[KeyType::SPECIAL1]) & 0x1) << 5) |
- ( (u32)(input->isKeyDown(keycache.key[KeyType::SNEAK]) & 0x1) << 6) |
- ( (u32)(input->getLeftState() & 0x1) << 7) |
- ( (u32)(input->getRightState() & 0x1) << 8
+ ( (u32)(isKeyDown(KeyType::FORWARD) & 0x1) << 0) |
+ ( (u32)(isKeyDown(KeyType::BACKWARD) & 0x1) << 1) |
+ ( (u32)(isKeyDown(KeyType::LEFT) & 0x1) << 2) |
+ ( (u32)(isKeyDown(KeyType::RIGHT) & 0x1) << 3) |
+ ( (u32)(isKeyDown(KeyType::JUMP) & 0x1) << 4) |
+ ( (u32)(isKeyDown(KeyType::SPECIAL1) & 0x1) << 5) |
+ ( (u32)(isKeyDown(KeyType::SNEAK) & 0x1) << 6) |
+ ( (u32)(isLeftPressed() & 0x1) << 7) |
+ ( (u32)(isRightPressed() & 0x1) << 8
);
#ifdef ANDROID
//u16 damage = event.player_damage.amount;
//infostream<<"Player damage: "<<damage<<std::endl;
- *damage_flash += 100.0;
- *damage_flash += 8.0 * event.player_damage.amount;
+ *damage_flash += 95.0 + 3.2 * event.player_damage.amount;
+ *damage_flash = MYMIN(*damage_flash, 127.0);
player->hurt_tilt_timer = 1.5;
- player->hurt_tilt_strength = event.player_damage.amount / 4;
- player->hurt_tilt_strength = rangelim(player->hurt_tilt_strength, 1.0, 4.0);
+ player->hurt_tilt_strength =
+ rangelim(event.player_damage.amount / 4, 1.0, 4.0);
MtEvent *e = new SimpleTriggerEvent("PlayerDamage");
gamedef->event()->put(e);
cam->camera_pitch = event.player_force_move.pitch;
} else if (event.type == CE_DEATHSCREEN) {
show_deathscreen(¤t_formspec, client, gamedef, texture_src,
- device, client);
+ device, &input->joystick, client);
chat_backend->addMessage(L"", L"You died.");
new TextDestPlayerInventory(client, *(event.show_formspec.formname));
create_formspec_menu(¤t_formspec, client, gamedef,
- texture_src, device, fs_src, txt_dst, client);
+ texture_src, device, &input->joystick,
+ fs_src, txt_dst, client);
delete(event.show_formspec.formspec);
delete(event.show_formspec.formname);
input->resetLeftClicked();
input->resetRightClicked();
+ input->joystick.clearWasKeyDown(KeyType::MOUSE_L);
+ input->joystick.clearWasKeyDown(KeyType::MOUSE_R);
+
input->resetLeftReleased();
input->resetRightReleased();
+
+ input->joystick.clearWasKeyReleased(KeyType::MOUSE_L);
+ input->joystick.clearWasKeyReleased(KeyType::MOUSE_R);
}
TextDest *txt_dst = new TextDestNodeMetadata(nodepos, client);
create_formspec_menu(¤t_formspec, client, gamedef,
- texture_src, device, fs_src, txt_dst, client);
+ texture_src, device, &input->joystick, fs_src, txt_dst, client);
current_formspec->setFormSpec(meta->getString("formspec"), inventoryloc);
} else {
float direct_brightness;
bool sunlight_seen;
- if (g_settings->getBool("free_move")) {
+ if (m_cache_enable_noclip && m_cache_enable_free_move) {
direct_brightness = time_brightness;
sunlight_seen = true;
} else {
runData->fog_range * 1.0,
0.01,
false, // pixel fog
- false // range fog
+ true // range fog
);
} else {
driver->setFog(
Damage flash
*/
if (runData->damage_flash > 0.0) {
- video::SColor color(std::min(runData->damage_flash, 180.0f),
- 180,
- 0,
- 0);
+ video::SColor color(runData->damage_flash, 180, 0, 0);
driver->draw2DRectangle(color,
core::rect<s32>(0, 0, screensize.X, screensize.Y),
NULL);
inline static const char *yawToDirectionString(int yaw)
{
- // NOTE: TODO: This can be done mathematically without the else/else-if
- // cascade.
-
- const char *player_direction;
+ static const char *direction[4] = {"North [+Z]", "West [-X]", "South [-Z]", "East [+X]"};
yaw = wrapDegrees_0_360(yaw);
+ yaw = (yaw + 45) % 360 / 90;
- if (yaw >= 45 && yaw < 135)
- player_direction = "West [-X]";
- else if (yaw >= 135 && yaw < 225)
- player_direction = "South [-Z]";
- else if (yaw >= 225 && yaw < 315)
- player_direction = "East [+X]";
- else
- player_direction = "North [+Z]";
-
- return player_direction;
+ return direction[yaw];
}
<< ", RTT = " << client->getRTT();
setStaticText(guitext, utf8_to_wide(os.str()).c_str());
guitext->setVisible(true);
- } else if (flags.show_hud || flags.show_chat) {
- std::ostringstream os(std::ios_base::binary);
- os << PROJECT_NAME_C " " << g_version_hash;
- setStaticText(guitext, utf8_to_wide(os.str()).c_str());
- guitext->setVisible(true);
} else {
guitext->setVisible(false);
}
void Game::readSettings()
{
- m_cache_doubletap_jump = g_settings->getBool("doubletap_jump");
- m_cache_enable_clouds = g_settings->getBool("enable_clouds");
- m_cache_enable_particles = g_settings->getBool("enable_particles");
- m_cache_enable_fog = g_settings->getBool("enable_fog");
- m_cache_mouse_sensitivity = g_settings->getFloat("mouse_sensitivity");
- m_repeat_right_click_time = g_settings->getFloat("repeat_rightclick_time");
+ m_cache_doubletap_jump = g_settings->getBool("doubletap_jump");
+ m_cache_enable_clouds = g_settings->getBool("enable_clouds");
+ m_cache_enable_joysticks = g_settings->getBool("enable_joysticks");
+ m_cache_enable_particles = g_settings->getBool("enable_particles");
+ m_cache_enable_fog = g_settings->getBool("enable_fog");
+ m_cache_mouse_sensitivity = g_settings->getFloat("mouse_sensitivity");
+ m_cache_joystick_frustum_sensitivity = g_settings->getFloat("joystick_frustum_sensitivity");
+ m_repeat_right_click_time = g_settings->getFloat("repeat_rightclick_time");
+
+ m_cache_enable_noclip = g_settings->getBool("noclip");
+ m_cache_enable_free_move = g_settings->getBool("free_move");
m_cache_mouse_sensitivity = rangelim(m_cache_mouse_sensitivity, 0.001, 100.0);
}