Tumgik
#what the fuck is a mutex
kawaoneechan · 1 month
Text
Okay so in a game like Animal Crossing, there's a bunch of things all happening at once. You can have a screen full of villagers walking around doing their thing, balloons flying, bugs bugging, a system in the background to handle hourly background music with chimes in between, all that good stuff, while you're doing your own things.
When you talk to a villager, you and the villager both stop on the spot, and a script takes over. That script then makes the villager turn to the player and a dialogue window appears. There may be a multiple choice thing now — "talk", "gift", or "leave" — and the script won't stop, releasing control to both, until what you've selected plays out.
So you have a villager with an attached script. The villager waits for the script to finish before continuing on their merry way, while the script waits for the villager to finish turning to the player. Once that's done, it picks something to say and eventually ends up opening the dialogue window. The script now has to wait for the message to finish writing, and the very next command is an "if" involving the result of a multiple choice question, so now the script has to wait for that to return.
I was thinking for Project Special K I might implement all that as several Tickable objects. Not unlike in SCI, you'd have a big list of things in the game that all implement a Tick method. In SCI, that'd be the cast, and its members have doit methods. It's the same deal, but Tick also gets a delta-time argument. So the dialogue box gets to be its own thing that implements Tickable, the multiple choice box is as well. Inventory window? Yes.
Also the script interpreter.
But all that wouldn't let the villager wait for the script interpreter, which waits for the dialogue box, right? Script execution should be halted until the dialogue box is dismissed. That one villager's AI should be halted until the interpreter finishes, only moving (or rather, emoting) because of embedded commands in the dialogue box's text stream.
So I figured, what if I gave them something like a mutex variable? The villager would have a bool waiting or whatever, and passes a pointer to that bool to the script interpreter they spawn when the player interacts with them. The interpreter is added to the cast list and starts running the code it was given. When it's done, it not only removes itself from the cast but sets the bool pointer so the villager can tell it's over and done with.
Now every time through the loop, the villager's Tick is called and they can tell "oh, I'm waiting for a script to finish" because their bool isn't set yet. The script interpreter likewise can spawn a dialogue box into the cast and have its own "waiting for that darn dialogue box" bool, in exactly the same way the villager can wait for the script interpreter.
Next trick, the dialogue box should remain on screen even when things are done, so multiple choice answers can have the question remain visible. It should only close when a different style of box is called for, or when the script ends. My idea is to always have a dialogue box object in the cast, idling until called for. When the villager realizes the script has ended, they can simply poke the dialogue box and have it close, if nothing else already did.
96 notes · View notes
shieldfoss · 1 year
Note
What's the most typed type you remember using in C++? I'm just finishing up the official introductory Rust book and I'm at Arc<Mutex<Receiver<Box<dyn FnOnce() + Send + 'static>>>>, which I think is a personal record for type parameter nesting depth.
I don't think I've ever been deeper than that myself - the thing is, once you've got just so little as "a vector of pairs," you've already done fucked up - those pairs represent something, give 'em a name.
11 notes · View notes
wunkolo · 7 years
Note
this is a candid ask, but since ive started following you i see many people send you messages about how good you are at programming, modeling, art, etc. and they want to know WHY. you say it's because you keep up a healthy "mix" of your hobbies but, tbh, i dont think that's it. you're smart. like. really fucking smart. probably near genius. most people aren't on your level. do you know that, somewhere, subconsciously? you really think just ANYONE can do what you do? it's not realistic.
People message me usually asking specific questions about stuff. “Where do I start” is one I get a lot and I usually refer them to python since it is a very welcoming language and when people ask about 3d art I show them blender and 3ds max stuff and blah blah.
When it comes to me as a person and what drives me I say what works for me in which one interest will touch another and touch another and “mix” and such and that’s what drives me as a person. Of course though theres drive and passion and interest but there is also circumstance and background and “where you’re coming from”. I had the chance to start when I was very very young (like 11). Not a lot of people are going to get that chance. Someone might not be able to give self-teaching the time they wish they could because of work or family or location or access to resources and all that stuff that can get in the way that is totally out of their control so it’s some percentage “passion/drive/etc” and another percentage “circumstance/proximity/etc” and lots of other percentages that factor into a healthy and secured environment to grow and keep on growing’ at a particular task. A lot of people have given up on their interests simply because the fight to secure such interests was too much or out of the question due to circumstance and so on. 
I’m too humble to have narcissistic thoughts involving being near-genius or thinking about how a lot of people are not “at my level” as that would serve more harm than good(probably related to some validation issues as I’ve seen before) and just make someone feel super lonely in the end. People have done stuff like what I do. Plenty of people have surpassed me and those are the people I learn from and I’m honestly not that special out there. I don’t look out to make clones of myself either. It’s unrealistic like you said and there isn’t really any benefit to the world to craft myself into another person so harshly(At a certain point in your education you might have ran into those professors that basically want to make clones of themselves out of a classroom rather than truly educate or those parents that force their children to be like them). In fact I don’t think I would ever want to answer a “how can I be more like you” type of question compared to the more insightful “how do I start” types or specific informational posts like “difference between a mutex and a semaphore” or “hand topology” and such and idk.
You seem upset about something more intricate beyond this ask but yo I am not expecting myself in anybody here
44 notes · View notes