-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add dice rolling app #565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add dice rolling app #565
Conversation
Riksu9000
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A very nice looking app and well written code.
|
I might overlook something - but if you use |
I saw that another app was using |
|
@hubmartin I could use some help with the |
|
My guess is that constructors are run immediatelly after start and they are called cycle-perfect every time, so you seed the random, but it is same every time. You have to call srand somewhere where the called function is run based on user's input. It might be Then I would suggest to seed rather some milliseconds counter/timer. But your |
|
This is a cool idea |
|
With @hubmartin suggestion of using the screen constructor using the current time should be much more effective, |
|
@hubmartin @geekbozu I did a bit more looking at this -- I ended up using I believe the constructor is actually called every time the app is opened, rather than once every boot, though with this implementation (using current time rather than uptime) it shouldn't really matter either way. |
|
I gave this a try the other day and it worked really well I will try the new changes and see if it works out well. Never can go wrong with more features. Is there any plans to actually make apps configurable on compile time so we can remove stuff we don't want when we finally get to the point of running out of room. Not necessarily something you need to figure out just more of a curiosity. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code generates some tidy warnings and I copied them here. Other than that this PR looks good.
|
For the seed part for the random number generation, in an embedded software project I participate with we used ADC values on unused pins or very fluctuant voltage in order to have something different each time. I don't know if we have an ADC on the nrf but we can try to use something proportional to the battery voltage for example before filtering if possible. |
|
@toitoinou NRF52 has special and certified RNG peripheral exactly for this reason. I did some quick tests and had something wrong, the numbers did not come. If anyone could look into that it would be great to have system-wide random seed right after boot for the whole system. |
|
Using the RNG is pretty simple on the NRF52 https://devzone.nordicsemi.com/f/nordic-q-a/19429/random-number-without-softdevice. I suggest seeding using srand on boot-up. |
|
If we are going to use the hardware RNG maybe consider making an "RNG" driver so it can maintain portability between different platforms with more "ease".....aka just have it default to std::rand() when not on an NRF platform |
|
@geekbozu we don't need to use RNG for |
|
This is such a cool idea. Bump, to see this finished and included in the next build. |
Yeah this makes a ton of sense. Even more so for applications where randomness is only partially critical. |
Hey -- thanks for the support. I'd love to finish this up and get it included in the next build. Unfortunately life has gotten in the way a bit -- I hopefully should have some time in the next couple weeks to come back to it. |
|
A small recommendation. When the icon is pressed change the icon to the number that has been rolled , for other things long pressing it can open the full app. |
7c01742 to
cd03b1f
Compare
|
I just pushed new changes that make the dice app compatible with 1.6.0. I likely still have to revisit the The app itself runs fine otherwise. |
|
I would recommend removing the roll and adding it back later. There should be some changes coming down the pipeline on how the BMA interface is defined...one less thing to update with that PR would be nice ;) |
|
@stoehraj Hi, was working on other PR and discovered that Nimble is already using RNG peripheral and it has nice driver and wrapper for
It seems like Nimble has some buffer of pre-generated values so it seems like you can call |
|
@stoehraj Hi. Could you update this PR, so we can merge it hopefully? |
|
I think that in the case when n1, d2 the indicator also should write (heads) or (tails) for those who wishes to flip a coin, see #919 |
75c7e28 to
024a805
Compare
@Riksu9000 Hey -- apologies for the extremely late response and lack of activity. I see you've changed some stuff over the past few days. I just flashed the latest stuff onto my unit to play around with a bit. I do want to try out what @hubmartin suggested with using Also, if nothing else, I want to squash all of my prior commits to clean up the git history a bit before this gets merged in. |
|
@hubmartin -- the |
|
@Riksu9000 -- do you care if I squash your commits in with mine? Or would you prefer to keep yours separate? |
|
@stoehraj Nah I don't care. Do what you want. |
src/CMakeLists.txt: Added entry for Dice app. src/displayapp/Apps.h: Added Dice to list of apps. src/displayapp/DisplayApp.cpp: Added include for Dice.h. Added entry in switch case for creating the Dice screen. src/displayapp/fonts/README.md: Added dice symbol to range. src/displayapp/fonts/jetbrains_mono_bold_20.c: Added dice symbol. src/displayapp/screens/ApplicationList.cpp: Added third screen and added dice app to it. src/displayapp/screens/ApplicationList.h: Added third application screen. src/displayapp/screens/Dice.cpp: New file implementing an app for rolling dice. User can configure number of dice and size of dice. User can roll dice with the "Roll" button. The total of the dice roll is shown in an area at the top of the screen, and if multiple dice are rolled, the individual rolls are shown underneath the total. src/displayapp/screens/Dice.h: New header file for Dice.cpp. src/displayapp/screens/Symbols.h: Added dice symbol.
75f3385 to
2fe1f24
Compare
|
@Riksu9000 -- just took care of all of the squashing. Got everything into one nice commit and (hopefully) ready to merge in. |
|
It is a miniscule issue, but I think it might be a right thing to handle it: |
This commit modifies the roll logic in such a way to avoid modulo bias, based on an algorithm from the PCG family of random number generators.
@medeyko -- I just implemented this in the latest changes. |
|
Sorry for persisting, but I have a question again: are there any issues left with this app? Is it possible to do anything in order to help to include it in the firmware? |
|
@medeyko It's difficult to say, the amount of available RAM and storage is getting very very close. It's difficult to choose which new features should be merged first, if there's even space available. How to keep track of features that depend on additional resources, or do not change the memory footprint and could be instantly merged, is currently WIP. Hopefully we'll be able to more clearly communicate what's the status of each PR soon. |
|
@Avamander a bit off-topic to this PR but as a reply to your thoughts: maybe, just maybe, there need to be some straight-forward way of selecting which apps to include in the build or even have "editions/presets" |
This is something I have in mind : adding the possibility to select which apps will be installed at build time. This is something that is definitely possible to do. However, I think it'll be very difficult to maintain and test : we'll have to maintain and test multiple 'editions', and/or ensure that every combination of apps will work well, ensure that there's enough RAM memory available for all the apps,... |
|
Sorry for asking again, but could anyone please write what is the state of this app? |
|
Just a little neat addition: I think it would be cool if, when the user has set up the "dice" (that is, the dice number and such), they can shake the PineTime, and it "rolls" the dice. |
|
@Ertain hey, thanks for the comment -- if you look at the original description and some of the earlier comments, that actually is a feature I had initially, but we ended up pulling it out when there was some investigation on standardizing gestures a bit more across apps. I think it's a really cool idea, though! Makes the rolling a bit more tangible, especially combined with vibration. Either way, looks like there's a PR for a different dice app that seems more likely to get merged in than this one (#1326) so may be worth it to request that feature over there as well. |
|
closing in favor of merged #1326 |
Preview Video
dice_demo_vid.mp4
Description
This PR adds a new dice rolling app. I play D&D and thought it would be fun to be able to roll dice on my PineTime, so here we are. I thought others might enjoy it too.
This is what the basic UI looks like:
There are buttons to select the number and size of dice. The number of dice can be between 1 and 99, and the supported dice sizes are d2, d3, d4, d6, d8, d12, d20, and d100.
When the desired number and size of dice have been configured, the "Roll" button will, well, roll the dice. Rolls can also be made by slowly rolling the wrist, as shown below:
wrist_roll_demo.mp4
If the roll is made using the motion control, the watch will vibrate, giving feedback that the roll occurred.
After rolling, the first line of the output box at the top of the screens shows the total result, and, if multiple dice are rolled, the second line shows each individual die roll.