- /*
- * We have to open all possible player files in the players directory
- * and check their player names because some file systems are not
- * case-sensitive and player names are case-sensitive.
- */
-
- // A player to deserialize files into to check their names
- RemotePlayer testplayer(m_gamedef, "");
-
- savedir += DIR_DELIM;
- std::string path = savedir + m_name;
- for (u32 i = 0; i < PLAYER_FILE_ALTERNATE_TRIES; i++) {
- if (!fs::PathExists(path)) {
- // Open file and serialize
- std::ostringstream ss(std::ios_base::binary);
- serialize(ss);
- if (!fs::safeWriteToFile(path, ss.str())) {
- infostream << "Failed to write " << path << std::endl;
- }
- setModified(false);
- return;
- }
- // Open file and deserialize
- std::ifstream is(path.c_str(), std::ios_base::binary);
- if (!is.good()) {
- infostream << "Failed to open " << path << std::endl;
- return;
- }
- testplayer.deSerialize(is, path);
- is.close();
- if (strcmp(testplayer.getName(), m_name) == 0) {
- // Open file and serialize
- std::ostringstream ss(std::ios_base::binary);
- serialize(ss);
- if (!fs::safeWriteToFile(path, ss.str())) {
- infostream << "Failed to write " << path << std::endl;
- }
- setModified(false);
- return;
- }
- path = savedir + m_name + itos(i);
+ u32 keypress_bits =
+ ( (u32)(jump & 1) << 4) |
+ ( (u32)(aux1 & 1) << 5) |
+ ( (u32)(sneak & 1) << 6) |
+ ( (u32)(dig & 1) << 7) |
+ ( (u32)(place & 1) << 8) |
+ ( (u32)(zoom & 1) << 9)
+ ;
+
+ // If any direction keys are pressed pass those through
+ if (direction_keys != 0)
+ {
+ keypress_bits |= direction_keys;
+ }
+ // Otherwise set direction keys based on joystick movement (for mod compatibility)
+ else if (isMoving())
+ {
+ float abs_d;
+
+ // (absolute value indicates forward / backward)
+ abs_d = abs(movement_direction);
+ if (abs_d < 3.0f / 8.0f * M_PI)
+ keypress_bits |= (u32)1; // Forward
+ if (abs_d > 5.0f / 8.0f * M_PI)
+ keypress_bits |= (u32)1 << 1; // Backward
+
+ // rotate entire coordinate system by 90 degree
+ abs_d = movement_direction + M_PI_2;
+ if (abs_d >= M_PI)
+ abs_d -= 2 * M_PI;
+ abs_d = abs(abs_d);
+ // (value now indicates left / right)
+ if (abs_d < 3.0f / 8.0f * M_PI)
+ keypress_bits |= (u32)1 << 2; // Left
+ if (abs_d > 5.0f / 8.0f * M_PI)
+ keypress_bits |= (u32)1 << 3; // Right