Beispiel #1
0
void InputManager::bootstrap() {
    unsigned guid = 0;
    for(auto &emulator : program->emulator) {
        Configuration::Node emulatorNode;

        for(auto &port : emulator->port) {
            Configuration::Node portNode;

            for(auto &device : port.device) {
                Configuration::Node deviceNode;

                for(auto &number : device.order) {
                    auto &input = device.input[number];

                    AbstractInput *abstract = nullptr;
                    if(input.type == 0) abstract = new DigitalInput;
                    if(input.type == 1) abstract = new RelativeInput;
                    if(input.type == 2) abstract = new AbsoluteInput;
                    if(input.type >= 3) continue;

                    abstract->name = string{input.name} .replace(" ", "");
                    abstract->mapping = "None";
                    abstract->logic = 0;  //OR

                    input.guid = guid++;
                    inputMap.append(abstract);
                    deviceNode.append(abstract->mapping, abstract->name);
                }
                portNode.append(deviceNode, string{device.name} .replace(" ", ""));
            }
            emulatorNode.append(portNode, string{port.name} .replace(" ", ""));
        }
        config.append(emulatorNode, string{emulator->information.name} .replace(" ", ""));
    }

    appendHotkeys();

    string path = program->savePath("input.bml");

    if(!file::exists(path))
        if(auto defaults = program->getResource("User defaults/input.bml"))
            file::write(path, vectorstream(defaults()).text());

    config.load(path);
    config.save(path);
    bind();
}
Beispiel #2
0
void InputManager::bootstrap() {
  unsigned guid = 0;
  for(auto& emulator : program->emulator) {
    Configuration::Node emulatorNode;

    for(auto& port : emulator->port) {
      Configuration::Node portNode;

      for(auto& device : port.device) {
        Configuration::Node deviceNode;

        for(auto& number : device.order) {
          auto& input = device.input[number];

          AbstractInput* abstract = nullptr;
          if(input.type == 0) abstract = new DigitalInput;
          if(input.type == 1) abstract = new RelativeInput;
          if(input.type == 2) abstract = new RumbleInput;
          if(abstract == nullptr) continue;

          abstract->name = string{input.name}.replace(" ", "");
          abstract->mapping = "None";
          abstract->logic = 0;  //OR

          input.guid = guid++;
          inputMap.append(abstract);

          deviceNode.append(abstract->mapping, abstract->name);
        }

        portNode.append(deviceNode, string{device.name}.replace(" ", ""));
      }

      emulatorNode.append(portNode, string{port.name}.replace(" ", ""));
    }

    config.append(emulatorNode, string{emulator->information.name}.replace(" ", ""));
  }

  appendHotkeys();

  config.load(program->path("input.bml"));
  config.save(program->path("input.bml"));

  bind();
}
Beispiel #3
0
void InputManager::appendHotkeys() {
  {
    auto hotkey = new HotkeyInput;
    hotkey->name    = "Toggle Fullscreen Mode";
    hotkey->mapping = "KB0::F11";

    hotkey->press = [] {
      utility->toggleFullScreen();
    };
  }

  {
    auto hotkey = new HotkeyInput;
    hotkey->name    = "Toggle Mouse Capture";
    hotkey->mapping = "KB0::F12";

    hotkey->press = [] {
      input.acquired() ? input.unacquire() : input.acquire();
    };
  }

  {
    auto hotkey = new HotkeyInput;
    hotkey->name = "Pause Emulation";
    hotkey->mapping = "KB0::P";

    hotkey->press = [] {
      program->pause = !program->pause;
    };
  }

  {
    auto hotkey = new HotkeyInput;
    hotkey->name    = "Fast Forward";
    hotkey->mapping = "KB0::Tilde";

    hotkey->press = [] {
      video.set(Video::Synchronize, false);
      audio.set(Audio::Synchronize, false);
    };

    hotkey->release = [] {
      video.set(Video::Synchronize, ::config->video.synchronize);
      audio.set(Audio::Synchronize, ::config->audio.synchronize);
    };
  }

  {
    auto hotkey = new HotkeyInput;
    hotkey->name    = "Power Cycle";
    hotkey->mapping = "None";

    hotkey->press = [] {
      utility->power();
    };
  }

  {
    auto hotkey = new HotkeyInput;
    hotkey->name    = "Soft Reset";
    hotkey->mapping = "None";

    hotkey->press = [] {
      utility->reset();
    };
  }

  static unsigned activeSlot = 1;

  {
    auto hotkey = new HotkeyInput;
    hotkey->name    = "Save State";
    hotkey->mapping = "KB0::F5";

    hotkey->press = [&] {
      utility->saveState(activeSlot);
    };
  }

  {
    auto hotkey = new HotkeyInput;
    hotkey->name    = "Load State";
    hotkey->mapping = "KB0::F7";

    hotkey->press = [&] {
      utility->loadState(activeSlot);
    };
  }

  {
    auto hotkey = new HotkeyInput;
    hotkey->name    = "Decrement Slot";
    hotkey->mapping = "KB0::F6";

    hotkey->press = [&] {
      if(--activeSlot == 0) activeSlot = 5;
      utility->showMessage({"Selected slot ", activeSlot});
    };
  }

  {
    auto hotkey = new HotkeyInput;
    hotkey->name    = "Increment Slot";
    hotkey->mapping = "KB0::F8";

    hotkey->press = [&] {
      if(++activeSlot == 6) activeSlot = 1;
      utility->showMessage({"Selected slot ", activeSlot});
    };
  }

  {
    auto hotkey = new HotkeyInput;
    hotkey->name    = "Close Emulator";
    hotkey->mapping = "None";

    hotkey->press = [] {
      Application::quit();
    };
  }

  {
    auto hotkey = new HotkeyInput;
    hotkey->name    = "Toggle Tracer";
    hotkey->mapping = "None";

    hotkey->press = [&] {
      utility->tracerToggle();
    };
  }

  {
    auto hotkey = new HotkeyInput;
    hotkey->name    = "Export Memory";
    hotkey->mapping = "None";

    hotkey->press = [&] {
      if(program->active == nullptr) return;
      system().exportMemory();
      utility->showMessage("Memory exported");
    };
  }

  Configuration::Node node;
  for(auto& hotkey : hotkeyMap) {
    node.append(hotkey->mapping, string{hotkey->name}.replace(" ", ""));
  }
  config.append(node, "Hotkey");
}