# Multi\_prop.h, I feel I am getting closer to something usable but

**URL:** <https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793>\
**Category:** Props\
**Created:** [September 5, 2024, 2:58am UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793 "2024-09-05T02:58:27Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![ryryog25](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/ryryog25/32/1812_2.png) [@ryryog25](https://crucible.hubbe.net/u/ryryog25)\
**Post date:** [September 12, 2024, 2:08am UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/41 "2024-09-12T02:08:33Z")

</div>

Definitely take a look at that article I linked about the C Preprocessor to understand `#if`

---

<div class="post-metadata">

**Author:** ![olivierflying747-8](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/olivierflying747-8/32/5228_2.png) [@olivierflying747-8](https://crucible.hubbe.net/u/olivierflying747-8)\
**Post date:** [September 13, 2024, 12:59am UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/42 "2024-09-13T00:59:20Z")

</div>

So if I understand the button mapping properly:

The SaberBlasterProp assumes that the Blaster prop  
needs key mapping to work properly.

So this code alternates at each Prop change.  
It is not suitable for multi\_prop.h

It needs to be re-written to suit the needs of each prop:

- Saber: “normal mapping”  
(If 3 buttons: POWER, AUX & AUX2)  
(If 2 buttons: POWER & AUX)
- Blaster: “alternate mapping”  
(If 3 buttons: POWER, FIRE, MODE\_SELECT)  
(IF 2 buttons: FIRE & MODE\_SELECT)
- Detonator: same as Saber (or is it ?)
- Jetpack: same as Saber (yes I am also attempting a jetpack prop)

Did I understand button mapping correctly ?

---

<div class="post-metadata">

**Author:** ![NoSloppy](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/nosloppy/32/3865_2.png) [@NoSloppy](https://crucible.hubbe.net/u/NoSloppy)\
**Post date:** [September 13, 2024, 1:34am UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/43 "2024-09-13T01:34:12Z")

</div>

It currently toggles, that is correct.  
Sounds like instead, maybe it’s a good candidate for a switch case for each prop?

enum?

---

<div class="post-metadata">

**Author:** ![olivierflying747-8](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/olivierflying747-8/32/5228_2.png) [@olivierflying747-8](https://crucible.hubbe.net/u/olivierflying747-8)\
**Post date:** [September 13, 2024, 2:06am UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/44 "2024-09-13T02:06:50Z")

</div>

I thought of switch & enum but since only the blaster need something different, I thought I would get a much shorter code with (please don’t mind the syntax, I’ll figure it out - just trying to get the idea correct first)

```auto
if (currentMode = =:: blaster:)
"change mapping"
else "set/reset standard mapping"

```

I already have 4 working props plus another 3 or 4 in the pipeline so a 7 or 8 switch case would be a lot longer, no ?

---

<div class="post-metadata">

**Author:** ![ryryog25](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/ryryog25/32/1812_2.png) [@ryryog25](https://crucible.hubbe.net/u/ryryog25)\
**Post date:** [September 13, 2024, 2:38am UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/45 "2024-09-13T02:38:21Z")

</div>

> [@olivierflying747-8](#):
>
> I already have 4 working props plus another 3 or 4 in the pipeline so a 7 or 8 switch case would be a lot longer, no ?

I would write a mapping function similar to what’s in dual prop:

```cpp
uint32_t mapButtonToBlaster(uint32_t button) {
    switch (button) {
# if NUM_BUTTONS == 3
        case BUTTON_FIRE: return BUTTON_AUX;
        case BUTTON_MODE_SELECT: return BUTTON_AUX2;
# else
        case BUTTON_FIRE: return BUTTON_POWER;
        case BUTTON_MODE_SELECT: return BUTTON_AUX;
# endif
        default: return button;
    }
}
uint32_t mapButtonToSaber(uint32_t button) {
    switch (button) {
# if NUM_BUTTONS == 3
        case BUTTON_AUX: return BUTTON_FIRE;
        case BUTTON_AUX2: return BUTTON_MODE_SELECT;
# else
        case BUTTON_POWER: return BUTTON_FIRE;
        case BUTTON_AUX: return BUTTON_MODE_SELECT;
# endif
        default: return button;
    }
}

/* in event2 after handling any of your own combos */
    switch (currentMode) {
        case BLASTER: return Blaster::Event2(mapButtonToBlaster(button), effect, modifiers);
        case SABER: return Saber::Event2(mapButtonToSaber(button), effect, modifiers);
        /* Would also do this for `DETONATOR`, though maybe that could also use `mapButtonToSaber` and wouldn't need its own */
    }

```

Basically, the goal is to make sure the prop the events are being forwarded to is getting the expected button (the ones it’s set up to handle). So by running the `button` arg from `Event2` through the `map...()` functions, the `button` will be switched to the appropriate one, or simply fed back out if it was already, for example `BUTTON_POWER` and the goal was to feed that event to the `Saber` prop.

---

<div class="post-metadata">

**Author:** ![profezzorn](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/profezzorn/32/8_2.png) [@profezzorn](https://crucible.hubbe.net/u/profezzorn)\
**Post date:** [September 13, 2024, 4:13am UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/46 "2024-09-13T04:13:40Z")

</div>

> [@olivierflying747-8](#):
>
> `"change mapping"`

There isn’t a “change mapping” thing going on.  
Re-mapping the events is a conditional process, and it’s either done or not. The decision whether to re-map is directly based on the current state of the prop, so there is no map to set or reset.

---

<div class="post-metadata">

**Author:** ![olivierflying747-8](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/olivierflying747-8/32/5228_2.png) [@olivierflying747-8](https://crucible.hubbe.net/u/olivierflying747-8)\
**Post date:** [September 13, 2024, 10:57am UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/47 "2024-09-13T10:57:19Z")

</div>

> [@ryryog25](#):
>
> I would write a mapping function similar to what’s in dual prop:

That is what I meant, only two “maps” to be written and each prop uses/calls/if’s… one or the other.

---

<div class="post-metadata">

**Author:** ![profezzorn](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/profezzorn/32/8_2.png) [@profezzorn](https://crucible.hubbe.net/u/profezzorn)\
**Post date:** [September 13, 2024, 4:16pm UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/48 "2024-09-13T16:16:28Z")

</div>

> [@olivierflying747-8](#):
>
> one or the other.

No, both functions are used only for blasters.  
The reason there are two functions is because there is a bit field of currently pressed buttons, and that bitfield gets mapped one way before the Event2 function is called, and then it gets mapped _back_ afterwards.

For the saber prop, no button mapping is done at all.

---

<div class="post-metadata">

**Author:** ![olivierflying747-8](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/olivierflying747-8/32/5228_2.png) [@olivierflying747-8](https://crucible.hubbe.net/u/olivierflying747-8)\
**Post date:** [September 13, 2024, 7:11pm UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/49 "2024-09-13T19:11:04Z")

</div>

Please find attached my latest version for multi\_prop.h

You can find the sound files (created by NoSloppy) on my dropbox here:  
[https://www.dropbox.com/scl/fi/p2pj9os5v4seel0wmzwcz/Multi\_prop\_sounds\_by\_NoSloppy.zip?rlkey=hi6589mexymnx4jmxhtwqjfu0&st=3klofs5m&dl=0](https://www.dropbox.com/scl/fi/p2pj9os5v4seel0wmzwcz/Multi_prop_sounds_by_NoSloppy.zip?rlkey=hi6589mexymnx4jmxhtwqjfu0&st=3klofs5m&dl=0)

I would appreciate your comments, suggestions or critiques (spelling mistakes).

Thank you for all who helped me and especially @ryryog25, @profezzorn & @NoSloppy

Edit: "appologies, previously posted versions had an unfinished comment at the end `/*`, this is the correct one:  
Edit2: "appologies a thousand times, deleted again, I got mixed up in the different revisions. I can’t find the working version, but I promise, it did work (compile). I will re-post once I find the correct version. I am really sorry.

Also for your enjoyment, comment, suggestions, critiques, … , here is an initial version of my vision of a jetpack\_prop.  
[jetpack\_prop.h](https://crucible.hubbe.net/uploads/short-url/254zEKYWdjKQpt54asS7k1PazSN.h) (7.2 KB)

---

<div class="post-metadata">

**Author:** ![profezzorn](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/profezzorn/32/8_2.png) [@profezzorn](https://crucible.hubbe.net/u/profezzorn)\
**Post date:** [September 13, 2024, 7:23pm UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/50 "2024-09-13T19:23:41Z")

</div>

> [@olivierflying747-8](#):
>
> Please find attached my latest version for multi\_prop.h

Does it work?

---

<div class="post-metadata">

**Author:** ![olivierflying747-8](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/olivierflying747-8/32/5228_2.png) [@olivierflying747-8](https://crucible.hubbe.net/u/olivierflying747-8)\
**Post date:** [September 13, 2024, 7:24pm UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/51 "2024-09-13T19:24:54Z")

</div>

They both compile but my chassis is not finished yet so I can’t test it.

---

<div class="post-metadata">

**Author:** ![profezzorn](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/profezzorn/32/8_2.png) [@profezzorn](https://crucible.hubbe.net/u/profezzorn)\
**Post date:** [September 13, 2024, 7:50pm UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/52 "2024-09-13T19:50:16Z")

</div>

> [@olivierflying747-8](#):
>
> I would appreciate your comments, suggestions or critiques (spelling mistakes).

Well, after a quick glance, I have two comments:

1. Your SB\_Effect() only checks the mode, not what type of request was requested, which means that every effect will play the mode change sound.
2. If you would like to get the code added to proffieOS eventually, you should stick to the same style as the rest of the code. For instance, do not put `}` after other stuff, and only one per line.

---

<div class="post-metadata">

**Author:** ![olivierflying747-8](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/olivierflying747-8/32/5228_2.png) [@olivierflying747-8](https://crucible.hubbe.net/u/olivierflying747-8)\
**Post date:** [September 13, 2024, 9:17pm UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/53 "2024-09-13T21:17:55Z")

</div>

Thank you for the feedback.

> [@profezzorn](#):
>
> If you would like to get the code added to proffieOS eventually, you should stick to the same style as the rest of the code. For instance, do not put `}` after other stuff, and only one per line.

That I can absolutely do.

> [@profezzorn](#):
>
> Your SB\_Effect() only checks the mode, not what type of request was requested,

I understand this is a problem but I will need a bit more explanations, or maybe a link or two where I can educate myself.

> [@profezzorn](#):
>
> every effect will play the mode change sound.

Obviously nobody wants that.

Does the buttons mapping function seems right to you ?

Maybe, you would like me to change the comments ?

---

<div class="post-metadata">

**Author:** ![profezzorn](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/profezzorn/32/8_2.png) [@profezzorn](https://crucible.hubbe.net/u/profezzorn)\
**Post date:** [September 13, 2024, 9:39pm UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/54 "2024-09-13T21:39:46Z")

</div>

> [@olivierflying747-8](#):
>
> Does the buttons mapping function seems right to you ?  
> Maybe, you would like me to change the comments ?

Didn’t read in that much detail yet.

> [@olivierflying747-8](#):
>
> I understand this is a problem but I will need a bit more explanations, or maybe a link or two where I can educate myself.

You can read how SB\_Effect works in the other props.  
Also, it might be helpful to know that all the SB\_\* functions are part of the event-distribution system in ProffieOS. All the objects that inherit from SaberBase get stored in a linked list, and when one of the Do\* functions is called (like DoEffect) that function is called in all the SaberBase implementations, which includes the prop, sound, blades and displays.

---

<div class="post-metadata">

**Author:** ![olivierflying747-8](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/olivierflying747-8/32/5228_2.png) [@olivierflying747-8](https://crucible.hubbe.net/u/olivierflying747-8)\
**Post date:** [September 13, 2024, 9:56pm UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/55 "2024-09-13T21:56:28Z")

</div>

> [@profezzorn](#):
>
> You can read how SB\_Effect works in the other props.

I will definitely do that.

I am guessing that SB stands for Sound Board ? But could you give me a “non-initiated” definition ?

> [@profezzorn](#):
>
> not what type of request was requested

So what “kind of type” of request “can be requested” ?

---

<div class="post-metadata">

**Author:** ![olivierflying747-8](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/olivierflying747-8/32/5228_2.png) [@olivierflying747-8](https://crucible.hubbe.net/u/olivierflying747-8)\
**Post date:** [September 13, 2024, 10:33pm UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/56 "2024-09-13T22:33:36Z")

</div>

Apologies, I posted the incorrect multi\_prop.h file above twice. Now I can’t find the working (compiling) one. I will re-post it when I find it. I swear on my children, it did work !

---

<div class="post-metadata">

**Author:** ![profezzorn](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/profezzorn/32/8_2.png) [@profezzorn](https://crucible.hubbe.net/u/profezzorn)\
**Post date:** [September 13, 2024, 10:48pm UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/57 "2024-09-13T22:48:57Z")

</div>

> [@olivierflying747-8](#):
>
> SB stands for Sound Board

No, it stands for SaberBase

> [@olivierflying747-8](#):
>
> But could you give me a “non-initiated” definition ?

I’m not sure what that means.

> [@olivierflying747-8](#):
>
> So what “kind of type” of request “can be requested” ?

Ops, I meant the type of _EFFECT_ that was requested.

---

<div class="post-metadata">

**Author:** ![olivierflying747-8](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/olivierflying747-8/32/5228_2.png) [@olivierflying747-8](https://crucible.hubbe.net/u/olivierflying747-8)\
**Post date:** [September 13, 2024, 11:00pm UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/58 "2024-09-13T23:00:48Z")

</div>

> [@profezzorn](#):
>
> Does it work?

@profezzorn , if I may ask, when you say: “Does it work?”  
Is it because you saw something that shouldn’t work or because you tested it (tried to compile) and it didn’t work/compile for you ?

If it is because you saw something, please tell me in which part ?

I know I saw them (multi\_prop & jetpack\_prop) compile with the other props.

But now multi\_prop doesn’t compile anymore and I can’t find the working version.

---

<div class="post-metadata">

**Author:** ![profezzorn](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/profezzorn/32/8_2.png) [@profezzorn](https://crucible.hubbe.net/u/profezzorn)\
**Post date:** [September 13, 2024, 11:08pm UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/59 "2024-09-13T23:08:49Z")

</div>

> [@olivierflying747-8](#):
>
> @profezzorn , if I may ask, when you say: “Does it work?”  
> Is it because you saw something that shouldn’t work or because you tested it (tried to compile) and it didn’t work/compile for you ?

I ask because the more effort _you_ put in to it, the more interesting it is for me (and possibly other people) to read, comment on and help with.

---

<div class="post-metadata">

**Author:** ![NoSloppy](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/nosloppy/32/3865_2.png) [@NoSloppy](https://crucible.hubbe.net/u/NoSloppy)\
**Post date:** [September 13, 2024, 11:09pm UTC](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793/60 "2024-09-13T23:09:30Z")

</div>

I think the question meant did YOU try it and it worked for you.

> [@olivierflying747-8](#):
>
> I can’t find the working version.

I suggest making a free Github account.  
It will have every change you ever made, and it’s off site so if your computer falls out a window, you’ll be fine.

[Previous page](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793.md?page=2)

[Next page](https://crucible.hubbe.net/t/multi-prop-h-i-feel-i-am-getting-closer-to-something-usable-but/5793.md?page=4)
