mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-03 08:55:22 +01:00
5350d9ba6b
The command went over the network. flashlighttoggle was a simulation command, and those are sent to every machine of a network game: one player's key switched the flashlight of all of them. It is an entity command now, as the commands of the camera are; those stay on the machine they were given on (command_queue::is_network_target()). TCamera::OnCommand() takes it, simulation.cpp no longer does. The shadows took the budget of the scenery lamps. The flashlight is the light nearest to the camera, so it took the first of the gfx.lights.shadows.lamps slots, and as it moves with the player its map was drawn anew in nearly every frame, out of the scenery drawings a frame allows the lamps (one a frame at levels 1 and 2): the lamps kept waiting for their shadows. The flashlight now has a slot of its own past those of the lamps, made when it is first switched on, and its map is drawn when it needs it, not counted against the lamps. With gfx.lights.shadows.lamps 0 it has no shadows, as before. The key. Ctrl+Shift+L is motorconnectorsclose in the eu07_input-keyboard.ini the game ships with, and bind() gives a key two commands share to the later one in user_command, so the flashlight took it over. The default is Ctrl+Shift+F, which neither that file nor the defaults in the code use. For the files of the players that do use it: a default of the flashlight on a key their file binds to another command is dropped (keyboard_input::yield_default()), with a line in the log, so their binding keeps working; they bind the flashlight to a key of their choice.
125 lines
2.9 KiB
C++
125 lines
2.9 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <map>
|
|
#include <set>
|
|
#include <unordered_map>
|
|
#include <array>
|
|
#include "input/command.h"
|
|
|
|
namespace input {
|
|
|
|
extern std::array<char, GLFW_KEY_LAST + 1> keys;
|
|
extern bool key_alt;
|
|
extern bool key_ctrl;
|
|
extern bool key_shift;
|
|
|
|
}
|
|
|
|
namespace ui {
|
|
class keymapper_panel;
|
|
}
|
|
|
|
class keyboard_input {
|
|
friend class ui::keymapper_panel;
|
|
|
|
public:
|
|
// types
|
|
using bindingsetup_sequence = std::map<user_command, std::tuple<int, std::string>>;
|
|
|
|
enum keymodifier : int {
|
|
|
|
shift = 0x10000,
|
|
control = 0x20000
|
|
};
|
|
|
|
// constructors
|
|
keyboard_input() = default;
|
|
|
|
// destructor
|
|
virtual ~keyboard_input() = default;
|
|
|
|
// methods
|
|
virtual
|
|
bool
|
|
init() { return true; }
|
|
bool
|
|
key( int const Key, int const Action );
|
|
int
|
|
key( int const Key ) const;
|
|
void
|
|
poll();
|
|
inline
|
|
user_command
|
|
command() const {
|
|
return m_command; }
|
|
bindingsetup_sequence&
|
|
bindings() {
|
|
return m_bindingsetups; }
|
|
int
|
|
binding( user_command const Command ) const;
|
|
std::string
|
|
binding_hint( user_command const Command ) const;
|
|
void
|
|
dump_bindings() const;
|
|
|
|
// members
|
|
static std::unordered_map<int, std::string> keytonamemap;
|
|
|
|
protected:
|
|
// methods
|
|
virtual
|
|
void
|
|
default_bindings() = 0;
|
|
bool
|
|
recall_bindings();
|
|
// a command added after the players wrote their bindings: where their file doesn't list it and gives the key of its default
|
|
// to another command, the command is left without a key, so that the one of the file goes on working. bind() gives a key
|
|
// two commands share to the one later in user_command, which a new command always is
|
|
void
|
|
yield_default( user_command const Command );
|
|
void
|
|
bind();
|
|
|
|
// members
|
|
bindingsetup_sequence m_bindingsetups;
|
|
std::set<user_command> m_recalled; // the commands the file of the bindings lists
|
|
|
|
private:
|
|
// types
|
|
using usercommand_map = std::unordered_map<int, user_command>;
|
|
|
|
struct bindings_cache {
|
|
|
|
int forward { -1 };
|
|
int back { -1 };
|
|
int left { -1 };
|
|
int right { -1 };
|
|
int up { -1 };
|
|
int down { -1 };
|
|
};
|
|
|
|
// methods
|
|
bool
|
|
is_movement_key( int const Key ) const;
|
|
|
|
// members
|
|
user_command m_command { user_command::none }; // last, if any, issued command
|
|
usercommand_map m_bindings;
|
|
std::unordered_map<int, int> m_modsforkeys; // modifiers that were used with the active keys
|
|
command_relay m_relay;
|
|
bindings_cache m_bindingscache;
|
|
glm::vec2 m_movementhorizontal { 0.f };
|
|
float m_movementvertical { 0.f };
|
|
};
|
|
|
|
//---------------------------------------------------------------------------
|