wmww / BrainfuckIDE

A Brainfuck IDE/debugger designed to be intuitive, featureful and visually appealing
MIT License
92 stars 11 forks source link

[Feature request] Strict mode that uses unsigned, 8-bit integers for the memory cells #2

Closed Maxr1998 closed 6 years ago

Maxr1998 commented 6 years ago

I already digged through the source, but I couldn't really find where the datamanager.AddVal(-1) is implemented.. it should be pretty easy to just check if the cell value is < 0 and add 256 in that case.

wmww commented 6 years ago

[reading my code] This is... bad. Really bad. [realizes we're both interested in a brainfuck IDE]. Welp, I guess we can handle it.

wmww commented 6 years ago

Overview

This is the file you want to look at: Scripts/data_display.gd. data is the actual array of numbers, and elems is the array of visual elements that display the data. Both must be kept in sync.

Prof of concept

The way I would go about implementing this is have a max_value member variable in data_display.gd (var max_value = 255 at the top). everywhere where data is mutated in that file, you'll want to check the new value against max_value, and do wrapping if needed. This would be enough for you to use it for your own purposes.

Full implementation

Before I'd merge such a feature into master, it would have to be togglable at runtime.

We'll need a set_max_value() function. It will set the max value, and run through the data array and wrap elements if needed. It will also need to update the elems array by calling elems[i].changeVal(data[i], time) for each spot that's changed. We'll also need a set_max_value() function in controller.gd, which just calls dataManager.set_max_value(value). You'll see why we need this later.

We'll also need UI to turn strict mode on and off. I recommend building the internal code to support an arbitrary max value, but just exposing unlimited and 8-bit options in the UI. This involves adding an 8-bit checkbox or toggle to the options scene in the editor and connecting its signal to a new function in options.gd. That will call controller.set_max_value(value) (the function in controller.gd).

I know this sounds complicated, but its really just a dozen or so lines of simple code. If you get hung up on anything in particular, I can help. Feel free to do it another way. I'm happy to merge anything that adds functionality without changing the default behavior. Good luck!

[Note: If @Maxr1998 doesn't implement this, anyone else is welcome to. I probably won't do any significant work on this project unless I decide to rebuild with Godot 3]

Maxr1998 commented 6 years ago

@wmww Wow, thanks for the very detailed response! I've never done Godot coding yet, but with your detailed guide, I might manage it. I'm going to look at it over the weekend, and send you a PR if I get anything done. Really like the design of your app btw!