Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Ability to see user controlled flares in multiplayer #2664

Closed
willmichals opened this issue Feb 2, 2021 · 10 comments · Fixed by #2729
Closed

Ability to see user controlled flares in multiplayer #2664

willmichals opened this issue Feb 2, 2021 · 10 comments · Fixed by #2729

Comments

@willmichals
Copy link

I'm posting this here because it has been a good while since this issue has been addressed on the git.

Why limit the amount of user controlled flares on multiplayer? If my assumption is correct, multiplayer displays the first 2 user controlled flares defined, then nothing else. If the ability is already there, why not extend it out to be able to see x amount (a reasonable quantity) of user controlled flares? Why limit it to just 2? Performance?

@ohlidalp
Copy link
Member

ohlidalp commented Feb 17, 2021

Re-opening because I want to deal with this, it came up several times already and I see no reason to not implement this properly. I'm not aware of any "first 2 user controlled flares" limitation. Let's see (making notes as I go):

  • our input system recognizes 10 user lights:
    {"TRUCK_LIGHTTOGGLE1", EV_TRUCK_LIGHTTOGGLE01, "Keyboard EXPL+CTRL+1", _LC("InputEvent", "toggle custom light 1")},
    {"TRUCK_LIGHTTOGGLE2", EV_TRUCK_LIGHTTOGGLE02, "Keyboard EXPL+CTRL+2", _LC("InputEvent", "toggle custom light 2")},
    {"TRUCK_LIGHTTOGGLE3", EV_TRUCK_LIGHTTOGGLE03, "Keyboard EXPL+CTRL+3", _LC("InputEvent", "toggle custom light 3")},
    {"TRUCK_LIGHTTOGGLE4", EV_TRUCK_LIGHTTOGGLE04, "Keyboard EXPL+CTRL+4", _LC("InputEvent", "toggle custom light 4")},
    {"TRUCK_LIGHTTOGGLE5", EV_TRUCK_LIGHTTOGGLE05, "Keyboard EXPL+CTRL+5", _LC("InputEvent", "toggle custom light 5")},
    {"TRUCK_LIGHTTOGGLE6", EV_TRUCK_LIGHTTOGGLE06, "Keyboard EXPL+CTRL+6", _LC("InputEvent", "toggle custom light 6")},
    {"TRUCK_LIGHTTOGGLE7", EV_TRUCK_LIGHTTOGGLE07, "Keyboard EXPL+CTRL+7", _LC("InputEvent", "toggle custom light 7")},
    {"TRUCK_LIGHTTOGGLE8", EV_TRUCK_LIGHTTOGGLE08, "Keyboard EXPL+CTRL+8", _LC("InputEvent", "toggle custom light 8")},
    {"TRUCK_LIGHTTOGGLE9", EV_TRUCK_LIGHTTOGGLE09, "Keyboard EXPL+CTRL+9", _LC("InputEvent", "toggle custom light 9")},
    {"TRUCK_LIGHTTOGGLE10", EV_TRUCK_LIGHTTOGGLE10, "Keyboard EXPL+CTRL+0", _LC("InputEvent", "toggle custom light 10")},
    . This is OK.
  • input events are processed here:
    if (RoR::App::GetInputEngine()->getEventBoolValue(EV_TRUCK_LIGHTTOGGLE01 + (ar_flares[i].controlnumber - 1)) && m_custom_light_toggle_countdown <= 0)
    , using user-defined "control number" from truck file. This would be OK if the control number was limited to 1-10.
  • Documentation states the control number can be 1-500. https://docs.rigsofrods.org/vehicle-creation/fileformat-truck/#flares That's pure evil. Technically, numbers 10-44 would somewhat work but only by accidentally mapping to these fields (notice they're after the userflares):
    EV_TRUCK_LIGHTTOGGLE01, //!< toggle custom light 1
    EV_TRUCK_LIGHTTOGGLE02, //!< toggle custom light 2
    EV_TRUCK_LIGHTTOGGLE03, //!< toggle custom light 3
    EV_TRUCK_LIGHTTOGGLE04, //!< toggle custom light 4
    EV_TRUCK_LIGHTTOGGLE05, //!< toggle custom light 5
    EV_TRUCK_LIGHTTOGGLE06, //!< toggle custom light 6
    EV_TRUCK_LIGHTTOGGLE07, //!< toggle custom light 7
    EV_TRUCK_LIGHTTOGGLE08, //!< toggle custom light 8
    EV_TRUCK_LIGHTTOGGLE09, //!< toggle custom light 9
    EV_TRUCK_LIGHTTOGGLE10, //!< toggle custom light 10
    EV_TRUCK_MANUAL_CLUTCH, //!< manual clutch (for manual transmission)
    EV_TRUCK_PARKING_BRAKE, //!< toggle parking brake
    EV_TRUCK_TRAILER_PARKING_BRAKE, //!< toggle trailer parking brake
    EV_TRUCK_RIGHT_MIRROR_LEFT,
    EV_TRUCK_RIGHT_MIRROR_RIGHT,
    EV_TRUCK_SHIFT_DOWN, //!< shift one gear down in manual transmission mode
    EV_TRUCK_SHIFT_GEAR01, //!< shift directly into this gear
    EV_TRUCK_SHIFT_GEAR02, //!< shift directly into this gear
    EV_TRUCK_SHIFT_GEAR03, //!< shift directly into this gear
    EV_TRUCK_SHIFT_GEAR04, //!< shift directly into this gear
    EV_TRUCK_SHIFT_GEAR05, //!< shift directly into this gear
    EV_TRUCK_SHIFT_GEAR06, //!< shift directly into this gear
    EV_TRUCK_SHIFT_GEAR07, //!< shift directly into this gear
    EV_TRUCK_SHIFT_GEAR08, //!< shift directly into this gear
    EV_TRUCK_SHIFT_GEAR09, //!< shift directly into this gear
    EV_TRUCK_SHIFT_GEAR10, //!< shift directly into this gear
    EV_TRUCK_SHIFT_GEAR11, //!< shift directly into this gear
    EV_TRUCK_SHIFT_GEAR12, //!< shift directly into this gear
    EV_TRUCK_SHIFT_GEAR13, //!< shift directly into this gear
    EV_TRUCK_SHIFT_GEAR14, //!< shift directly into this gear
    EV_TRUCK_SHIFT_GEAR15, //!< shift directly into this gear
    EV_TRUCK_SHIFT_GEAR16, //!< shift directly into this gear
    EV_TRUCK_SHIFT_GEAR17, //!< shift directly into this gear
    EV_TRUCK_SHIFT_GEAR18, //!< shift directly into this gear
    EV_TRUCK_SHIFT_GEAR_REVERSE, //!< shift directly into this gear
    EV_TRUCK_SHIFT_HIGHRANGE, //!< select high range (13-18) for H-shaft
    EV_TRUCK_SHIFT_LOWRANGE, //!< select low range (1-6) for H-shaft
    EV_TRUCK_SHIFT_MIDRANGE, //!< select middle range (7-12) for H-shaft
    EV_TRUCK_SHIFT_NEUTRAL, //!< shift to neutral gear in manual transmission mode
    EV_TRUCK_SHIFT_UP, //!< shift one gear up in manual transmission mode
    EV_TRUCK_STARTER, //!< hold to start the engine
    EV_TRUCK_STEER_LEFT, //!< steer left
    EV_TRUCK_STEER_RIGHT, //!< steer right
    EV_TRUCK_SWITCH_SHIFT_MODES, //!< toggle between transmission modes
    EV_TRUCK_TOGGLE_CONTACT, //!< toggle ignition
    EV_TRUCK_TOGGLE_FORWARDCOMMANDS, //!< toggle forwardcommands
    EV_TRUCK_TOGGLE_IMPORTCOMMANDS, //!< toggle importcommands
    EV_TRUCK_TOGGLE_INTER_AXLE_DIFF, //!< toggle the inter axle differential mode
    EV_TRUCK_TOGGLE_INTER_WHEEL_DIFF, //!< toggle the inter wheel differential mode
    EV_TRUCK_TOGGLE_PHYSICS, //!< toggle physics simulation
    EV_TRUCK_TOGGLE_TCASE_4WD_MODE, //!< toggle the transfer case 4wd mode
    EV_TRUCK_TOGGLE_TCASE_GEAR_RATIO, //!< toggle the transfer case gear ratio
    EV_TRUCK_TOGGLE_VIDEOCAMERA, //!< toggle videocamera update
    EV_TRUCK_TRACTION_CONTROL, //!< toggle antilockbrake system
    . The order of the elements can change at developer's convenience.
  • RoRnet reserves 4 bits for custom flares:
    NETMASK_CLIGHT1 = BITMASK(9), //!< custom light 1 on
    NETMASK_CLIGHT2 = BITMASK(10), //!< custom light 2 on
    NETMASK_CLIGHT3 = BITMASK(11), //!< custom light 3 on
    NETMASK_CLIGHT4 = BITMASK(12), //!< custom light 4 on
    , it doesn't seem like a big deal to use more.
  • How sending net data works: The spawner records the flare-IDs of the first 4 custom lights in Actor::m_net_custom_lights, and Actor::sendStreamData(), uses getCustomLightVisible() to query 'm_net_custom_lights' and set the RoRnet's light bits accordingly.
    if (ar_lights)
    send_oob->flagmask += NETMASK_LIGHTS;
    if (getCustomLightVisible(0))
    send_oob->flagmask += NETMASK_CLIGHT1;
    if (getCustomLightVisible(1))
    send_oob->flagmask += NETMASK_CLIGHT2;
    if (getCustomLightVisible(2))
    send_oob->flagmask += NETMASK_CLIGHT3;
    if (getCustomLightVisible(3))
    send_oob->flagmask += NETMASK_CLIGHT4;
    The code is messy but looks valid.
  • How receiving net data works: Actor::CalcNetwork() does the inverse of the send process:
    setCustomLightVisible(0, ((flagmask & NETMASK_CLIGHT1) > 0));
    setCustomLightVisible(1, ((flagmask & NETMASK_CLIGHT2) > 0));
    setCustomLightVisible(2, ((flagmask & NETMASK_CLIGHT3) > 0));
    setCustomLightVisible(3, ((flagmask & NETMASK_CLIGHT4) > 0));
    . Looks OK.

CONCLUSION:
First 4 custom flares defined in truck file should work over the network. I don't know why just 4, the code was written before I joined the project, probably seemed enough at the time. It wouldn't be a big deal to extend RoRnet to send all 10.

CHECKLIST:

  • fix the doc and the Validator to only accept control numbers 1-10.
  • (future) improve truckfile so flares can be toggled/triggered by input event names. Those would be properly (and maintainably) translated to input events.

@tritonas00
Copy link
Collaborator

tritonas00 commented Feb 17, 2021

I don't know why just 4

probably to save bandwidth, but after ulteq's net rewrite should not be an issue

@willmichals
Copy link
Author

It wouldn't be a big deal to extend RoRnet to send all 10

The first 10 defined user flares, or the 10 flare control groups?

In other words, will there be an unlimited amount of flares displayed on each flare group, or 10 flares total?

@ohlidalp
Copy link
Member

@willmichals The first 10 defined user flares, or the 10 flare control groups?

Very good question. Currently it's the first 4 individual flares, actually. But for the future I'd like all 10 groups to be sent.

@willmichals
Copy link
Author

But for the future I'd like all 10 groups to be sent.

When you extend it, will you extend it to all 10 groups?
I only ask because looking at the pull request frm @tritonas00, it appears that instead of only 4 individual flares, only the first 10 custom individually defined flares are being sent, but I could be wrong.

@ohlidalp
Copy link
Member

@willmichals You're right, in it's current state it would only transmit first 10 individual flares. I already requested change: #2690 (comment)

@willmichals
Copy link
Author

Sounds and looks great. Thank you both

@DarthCainRor
Copy link

DarthCainRor commented Feb 23, 2021

CHECKLIST:

  • fix the doc and the Validator to only accept control numbers 1-10.

The Control numbers above 10 are for the "Custom Controlled" flares.
image

About which, Mike had asked for clarification about the other numbers and where their function could be found.
#2551

@ohlidalp
Copy link
Member

ohlidalp commented Mar 2, 2021

@DarthCainRor Thanks for the reminder, answered: #2551 (comment). The takeaway: Doc is broken, only 1-10 should be used, ever.

@tritonas00
Copy link
Collaborator

it seems we have already an issue for this #32

custom flares over network will be hopefully addressed soon

ohlidalp added a commit to ohlidalp/rigs-of-rods that referenced this issue Apr 6, 2021
The 'u' flares code was simplified and made similar to code for other flare types.

Control numbers clamped to range 1-10, see short explanation RigsOfRods#2551 (comment) or detailed explanation: RigsOfRods#2664 (comment)

CODECHANGES:
* m_custom_light_toggle_countdown removed, using classic `getEventBoolValueBounce()` - same effect, same delay
* disabled `controltoggle_status` in individual flares - replaced by `m_custom_lights`

fixes RigsOfRods#2664
see also #32
ohlidalp added a commit that referenced this issue Apr 7, 2021
The 'u' flares code was simplified and made similar to code for other flare types.

Control numbers clamped to range 1-10, see short explanation #2551 (comment) or detailed explanation: #2664 (comment)

CODECHANGES:
* m_custom_light_toggle_countdown removed, using classic `getEventBoolValueBounce()` - same effect, same delay
* disabled `controltoggle_status` in individual flares - replaced by `m_custom_lights`

fixes #2664
see also #32
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
5 participants