mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
final, but buuugs
This commit is contained in:
parent
82562300ff
commit
5e19c6807c
5 changed files with 13 additions and 27 deletions
|
|
@ -89,6 +89,7 @@ void input_sdl::pollEvents() {
|
|||
cursor = {event.motion.x, event.motion.y};
|
||||
break;
|
||||
case SDL_EVENT_WINDOW_RESIZED:
|
||||
window.setSize({event.window.data1, event.window.data2});
|
||||
break;
|
||||
case SDL_EVENT_TEXT_INPUT:
|
||||
std::vector<char> vec(
|
||||
|
|
|
|||
|
|
@ -344,12 +344,12 @@ void window_sdl::resetScissor() {
|
|||
}
|
||||
|
||||
double window_sdl::time() {
|
||||
return static_cast<double>(SDL_GetTicks()) / 1000;
|
||||
return static_cast<double>(SDL_GetTicksNS()) / 1'000'000'000;
|
||||
}
|
||||
|
||||
void window_sdl::setFramerate(int framerate) {
|
||||
/*todo*/
|
||||
if (!SDL_GL_SetSwapInterval(1)) {
|
||||
if (!SDL_GL_SetSwapInterval(framerate)) {
|
||||
logger.error() << "Failed to set framerate: " << SDL_GetError();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
debug::Logger logger("input");
|
||||
|
||||
static std::unordered_map<int, std::string> keynames {};
|
||||
static std::unordered_map<int, std::string> buttonsnames {};
|
||||
|
||||
static std::unordered_map<std::string, int> mousecodes {
|
||||
|
|
@ -19,22 +18,6 @@ static std::unordered_map<std::string, int> mousecodes {
|
|||
{"side2", SDL_BUTTON_X2},
|
||||
};
|
||||
|
||||
std::string input_util::get_name(Mousecode code) {
|
||||
const auto found = buttonsnames.find(static_cast<int>(code));
|
||||
if (found == buttonsnames.end()) {
|
||||
return "unknown";
|
||||
}
|
||||
return found->second;
|
||||
}
|
||||
|
||||
std::string input_util::get_name(Keycode code) {
|
||||
const auto found = keynames.find(static_cast<int>(code));
|
||||
if (found == keynames.end()) {
|
||||
return "unknown";
|
||||
}
|
||||
return found->second;
|
||||
}
|
||||
|
||||
void Binding::reset(InputType type, int code) {
|
||||
this->type = type;
|
||||
this->code = code;
|
||||
|
|
@ -49,7 +32,11 @@ void Binding::reset(Mousecode code) {
|
|||
}
|
||||
|
||||
Mousecode input_util::mousecode_from(const std::string& name) {
|
||||
return {};
|
||||
const auto& found = mousecodes.find(name);
|
||||
if (found == mousecodes.end()) {
|
||||
return Mousecode::UNKNOWN;
|
||||
}
|
||||
return static_cast<Mousecode>(found->second);
|
||||
}
|
||||
|
||||
void input_util::initialize() {
|
||||
|
|
@ -139,12 +126,12 @@ std::string Bindings::write() const {
|
|||
case InputType::KEYBOARD:
|
||||
value =
|
||||
"key:" +
|
||||
input_util::get_name(static_cast<Keycode>(binding.code));
|
||||
input_util::to_string(static_cast<Keycode>(binding.code));
|
||||
break;
|
||||
case InputType::MOUSE:
|
||||
value =
|
||||
"mouse:" +
|
||||
input_util::get_name(static_cast<Mousecode>(binding.code));
|
||||
input_util::to_string(static_cast<Mousecode>(binding.code));
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("unsupported control type");
|
||||
|
|
|
|||
|
|
@ -133,11 +133,6 @@ namespace input_util {
|
|||
std::string to_string(Keycode code);
|
||||
/// @return Mouse button label by keycode
|
||||
std::string to_string(Mousecode code);
|
||||
|
||||
/// @return Key name by keycode
|
||||
std::string get_name(Keycode code);
|
||||
/// @return Mouse button name by keycode
|
||||
std::string get_name(Mousecode code);
|
||||
}
|
||||
|
||||
enum class InputType {
|
||||
|
|
|
|||
|
|
@ -43,6 +43,9 @@ public:
|
|||
virtual const glm::ivec2& getSize() const {
|
||||
return size;
|
||||
}
|
||||
virtual void setSize(const glm::ivec2& s) {
|
||||
size = std::move(s);
|
||||
}
|
||||
|
||||
static std::tuple<std::unique_ptr<Window>, std::unique_ptr<Input>>
|
||||
initialize(DisplaySettings* settings, std::string title);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue