Skip to content
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 key shortcuts to toggle debug/UI #180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

satoshinm
Copy link
Contributor

A simple addition to allow the user to toggle all the user interface elements (F1 keybinding) and the debug info text (F3), useful for taking clutter-free screenshots etc.

@polyvertex
Copy link

polyvertex commented Apr 16, 2017

Hey, I'm just jumping in and don't mean to be pedantic but wouldn't it be wiser to merge those 2 new integers you added (show_info_text and show_ui) into a single one and use flags? I'm not fully familiar with Craft's code so I'm asking purely out of curiosity

@satoshinm
Copy link
Contributor Author

Bitfields you mean? I suppose it could be more compact, but more complicated (requiring bitmasks etc.). Maybe something like this? (works on my system, but not sure how portable it is):

--- a/src/main.c
+++ b/src/main.c
@@ -165,8 +165,10 @@ typedef struct {
     Block block1;
     Block copy0;
     Block copy1;
-    int show_info_text;
-    int show_ui;
+    struct {
+        int show_info_text : 1;
+        int show_ui : 1;
+    };
 } Model;
 
 static Model model;

and/or was also considering using stdbool.h, new in C99 (but the rest of the codebase doesn't use it, so I stuck with int for consistency)

@polyvertex
Copy link

polyvertex commented Apr 16, 2017

I was thinking about direct bitwise manipulation on a single integer. Admittedly it leads to more verbose tests but those 2 integers seemed so closely related that when I read your patch I wondered if there was a rational behind this choice I might have missed. Anyway, don't mind me I was just passing by! Thanks for answering

@satoshinm
Copy link
Contributor Author

Ah I see what you're saying, something like:

if (SHOW_WIREFRAME && (g->show_flags & 1)) {  // check
...
g->show_flags |= 1; // show ui
g->show_flags &= ~1; // hide ui

if (g->show_flags & 2) // show info text

I think it's simpler to have separate variables (maybe faster too? not benchmarked).

But for what it's worth, I did end up changing to use the C standard stdbool.h type where possible in my fork: satoshinm/NetCraft@e3ce375, including for these two flags. Since bool (or in actuality _Bool from C99) only stores non-zero values as 1, this may allow further optimization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants