#yup
1 messages · Page 1 of 1 (latest)
ooo I would really appreciate any tips or anything really, I'm trying to get better at coding so the more complex the better
first, i got custom code a custom data structure called a DropoutStack. A DropoutStack is a Stack, with a max size, and if you try to push something onto the DropoutStack when it is at max capacity, it erases the bottom of the stack.
This DropoutStack is the core of the structure
simple is always better. This is just mildly complex.
In my case, it was an Undo/Redo log for level editor, called a BuildHistory. Next, we make a simple Class for a BuildHistoryEvent. It is a single unit of (everything that happens within one click of undo/redo)
This is going to be like a command pattern. However you make a BuildHistoryEvent, it just needs to contain all the information to do a single undo/redo call.
Then, we have a 3rd class, called BuildHistory. BuildHistory’s job is to maintain a DropoutStack<BuildHistoryEvent> for undo history, and DropoutStack<BuildHistoryEvent> for redo history.
BuildHistory’s job is to basically manage that, tell is can we undo, can we redo, and when we undo/redo, it spits out a BuildHistoryEvent for us to do.
BuildHistory does not actually DO the Undo/Redo. It just keeps a log, to spit out the event that needs to happen.
Do you follow so far?
you’re typing a lot for a simple yes or no
I'm a bit confused on sort of the way it works, there's a stack which contains and lets us grab the "info", there's an event that lets us "send" info, and there's one that sends the "action" to be done?
the stack keeps the order of what to do
If we were to do separate actions for typing: L E F T.
Then the Undo log looks like:
Bottom - erase char 1, erase char 2, erase char 3, erase char 4 - Top
now I undo. I pop the top of the undo stack, which is a T, and spit out what happened. I then push the equivalent event to the redo stack.
Undo: Bottom - erase char 1, erase char 2, erase char 3 - Top
Redo: Bottom - add “T” - Top
Does this make sense?
One build history event contains the information for what we need to do to go backwards from one state to the previous
I could explain how it worked for my level editor, which writes to a tilemap
I think that I got the idea with the characters, the only thing I can't understand yet is the "spit" part, how do you redo it?
Whenever you undo, you also log to the redo
Yup, I mean how do you redo the action?
maybe I can explain
So like write the T character back in?
Is there like a way to do the "opposite" of the undo, or is it just a method like "if stack info = character: write character to console"?
in my case, i have a tilemap. I write tiles and erase tiles. My super low level functions, when they make an edit, they make a log “coordinate X contained tile Y” (and Y could be null). My BuildHistoryEvent is a list of every individual tile changed
yes, but we do this a bit differently
My BuildHistory has a few methods:
StartLoggingUndoEvent, StartLoggingRedoEvent, StopLoggingEvent, and LogPriorTile
BuildHistory keeps a current BuildHistoryEvent that is currently growing, if we are in the middle of writing an event.
Whenever my game starts a new drawing action, I call StartLoggingUndoEvent
All of my edit functions (for draw/erase) call LogPriorTile on BuildHistory before we actually make the edit.
So BuildHistory adds the old tile into the growing event.
When done drawing, we call StopLoggingEvent
which pushes the complete event onto the Undo DropoutStack.
Follow so far?
Yup
When we call Undo, we:
- Pop from the Undo DropoutStack
- Call StartLoggingRedoEvent
- Go do all the edit functions to draw whatever is in the BuildEvent we are undoing. Every edit function (when called) calls LogPriorTile (like before). So the growing BuildHistoryEvent gets populated with what the board was before we undo anything.
- Call StopLoggingEvent. Since BuildHistory was logging a redo event, it pushes this to the redo stack.
this effectively adds the reverse to the redo stack
i forget the details, since I can’t access my code rn, but that is the basic idea.
Also, fight any temptation for BuildHistory to actually DO any of the changes. That is shit design, and everything will spiral out of control if you do that
Unfortunately, my computer got fried last week, so I can’t just send you code for some of these data structures.
okay okay, I'll try to do something similar, if I have any issue would u be ok helping me out a bit?
yeah, just ping me
alr alr, tysm man smiley face
