| 65 | } |
| 66 | |
| 67 | int InputSerialization::writeFrame(std::ostream& stream, const AllInputs& inputs) |
| 68 | { |
| 69 | /* Write only events if present */ |
| 70 | if (!inputs.events.empty()) { |
| 71 | for (const auto& event : inputs.events) { |
| 72 | stream.put('|'); |
| 73 | stream.put('E'); |
| 74 | stream << std::dec; |
| 75 | stream << event.type << ':' << event.which << ':' << event.value; |
| 76 | } |
| 77 | stream << '|' << std::endl; |
| 78 | return 1; |
| 79 | } |
| 80 | |
| 81 | /* Write keyboard inputs */ |
| 82 | if (inputs.keyboard[0]) { |
| 83 | stream.put('|'); |
| 84 | stream.put('K'); |
| 85 | stream << std::hex; |
| 86 | for (int k=0; k<AllInputs::MAXKEYS; k++) { |
| 87 | if (!inputs.keyboard[k]) break; |
| 88 | stream << (k>0?":":"") << inputs.keyboard[k]; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | /* Write mouse inputs */ |
| 93 | if (context->config.sc.mouse_support && inputs.pointer) { |
| 94 | stream.put('|'); |
| 95 | stream.put('M'); |
| 96 | stream << std::dec; |
| 97 | stream << inputs.pointer->x << ':' << inputs.pointer->y << ':'; |
| 98 | stream << ((inputs.pointer->mode == SingleInput::POINTER_MODE_RELATIVE)?"R:":"A:"); |
| 99 | stream.put((inputs.pointer->mask&(1<<SingleInput::POINTER_B1))?'1':'.'); |
| 100 | stream.put((inputs.pointer->mask&(1<<SingleInput::POINTER_B2))?'2':'.'); |
| 101 | stream.put((inputs.pointer->mask&(1<<SingleInput::POINTER_B3))?'3':'.'); |
| 102 | stream.put((inputs.pointer->mask&(1<<SingleInput::POINTER_B4))?'4':'.'); |
| 103 | stream.put((inputs.pointer->mask&(1<<SingleInput::POINTER_B5))?'5':'.'); |
| 104 | stream << ":" << inputs.pointer->wheel; |
| 105 | } |
| 106 | |
| 107 | /* Write controller inputs */ |
| 108 | for (int joy=0; joy<context->config.sc.nb_controllers; joy++) { |
| 109 | if (inputs.isDefaultController(joy)) |
| 110 | continue; |
| 111 | /* Previous test ensures that there is an allocated ControllerInputs object */ |
| 112 | stream.put('|'); |
| 113 | stream.put('C'); |
| 114 | stream.put('1'+joy); |
| 115 | stream << std::dec; |
| 116 | for (int axis=0; axis<ControllerInputs::MAXAXES; axis++) { |
| 117 | stream << inputs.controllers[joy]->axes[axis] << ':'; |
| 118 | } |
| 119 | stream.put((inputs.controllers[joy]->buttons&(1<<SingleInput::BUTTON_A))?'A':'.'); |
| 120 | stream.put((inputs.controllers[joy]->buttons&(1<<SingleInput::BUTTON_B))?'B':'.'); |
| 121 | stream.put((inputs.controllers[joy]->buttons&(1<<SingleInput::BUTTON_X))?'X':'.'); |
| 122 | stream.put((inputs.controllers[joy]->buttons&(1<<SingleInput::BUTTON_Y))?'Y':'.'); |
| 123 | stream.put((inputs.controllers[joy]->buttons&(1<<SingleInput::BUTTON_BACK))?'b':'.'); |
| 124 | stream.put((inputs.controllers[joy]->buttons&(1<<SingleInput::BUTTON_GUIDE))?'g':'.'); |
nothing calls this directly
no test coverage detected