2024-03-24 20:17:41

so I've been trying a bit of things recently, I finally left rust after realizing that I'm going nowhere because I'm just too lame to understand how to do things the proper way, most people just give me a vague outline of what I should do and make it sound like it's obvious what I would need to do next, which it really isn't, some tell me just read rust code and you will learn how to do things the rust way, which is not really true because rust is possiblly the thing that I've read far too much code in, the language that I tried using the longest, so I just said ok this is not taking me anywhere, and then left it.
Ok, what then, go? Nope, I hate it, java? Don't exactly have anything against it but people have to hate it for a reason, dart? Far too immature, python? I hate dynamic languages, and not jus because static typing, it's because of how much a mess not having an official compiler can have for audiogames.
so, C#, seems like the perfect choice, and I love it, but.
C# is the worst modern language with documentation, and I really mean the worst there is no way of documentation, nothing, you're just expected to read file by file, even if a file is 2000 lines with mostly private definitions and you have no idea what you're looking at or where it is, which is sorta exosting, and there's just something that doesn't make me feel safe about the libraries, I now have to make a binding to openAL soft because yay no one made an actual good binding to it, which is really annoying I guess but not that much of a big deal, but the stuff added up and I'm not sure if I should continue there or not, I honestly really love rust, I think it's the perfect language, which is why I've been fighting it for 2 years, but I just can't go anywhere with it, I guess I'm just dumb? IF it's that obvious to everyone then it's probably me or something? Not sure at this point lol.
I know I think I said the same thing multiple times before, so lets go a step forward and give you the biggest issue with me and rust.
So imagine this. I'm making a server, no async, no threads, no parallel code what so ever, good old single threaded server, I have a collecton of players that I would eventually need to access at some point, when recieving packets, for example, I would get the player using the peer ID, then depending on the packet, maybe change the coordinates, or anything, basically, mutable access.
then I have maps, which are the same things, though I suppose maps will mostly be immutable except when an admin will update the map data?
ok, I have the server struct, lets say I somehow can pass it around to all the parts that needs it, even though that's impossible without doing bad global stuff that break because you shouldn't do it that way due to ownership rules and no surculars, here we come to the next issue, mutable accesses more than a time
I can't bring an exact example because I can't bring an exact code that makes this happen, but I will basically, after accessing the player, do something, maybe access a mutable server function, which will error because I'm borrowing player mutablly then I borrow the function mutablly again, I don't exactly remember if that causes it, but I'm pretty sure my issues go to something like that, I have something borrowed, like a player, then I borrow another player, or a player is borrowed and I call a mutable function from server, which is holding the player Vec, so it considers it mutiple borrowing of server, or I could be borrowing a player, then I need to for loop through all the players mutablly, then call a mutable server function, it goes on, I guess you'll probably tell me to seprate them instead of making them linked like that, but how? How would I make it accessible without global, and without making every function take 8 arguments, which will force me to change the arguments each time I add a new necessary collection or something like that?

2024-03-24 20:51:29

Hello.
Why not use a system of actors where instead of having one central entity you have multiple entities that pass data between them and act accordingly?
Rust supports this quite well through the use of channels. You could have an actor responsible for networking and an actor that would be responsible for updating the game world. Fundamentally, what's good about actors is that to communicate with them, you just need a public interface, that in this case could be std::sync::mpsc::Sender<T>.So you could just pass events around without the other systems having to worry about each other's state.  I could be missing something obvious here, so please do correct me if that is the case.

Paul

2024-03-25 00:59:47

Just go use an entity component system and do whatever you have to do to make that work.  People like Bevy.

But ultimately factoring in our conversations in private, at the end of the day, you're not going to be able to do an online game right in anything right now if you want to go beyond Contacts on all Sides. You need to get better first. C# for example is not particularly bad about docs, if you think it is that's you, not C#.  Note also in particular that you will have to either use multithreading or some form of async i/o for the server in the end even if you get that from a library.

But the Rust way of "player must access the server" is to pass subsets of the server via mutable reference to player's methods (not store it in the struct, actually pass it every time) or just lift those methods to the server and have them mutably access players. This isn't OOP, you can have impl blocks in more than one file for the server anyway, you can just do impl Server { stuff for the player } in player.rs or whatever.  Ultimately in Rust you can do like:

struct Server {
    shared_state: SharedState,
    players: HashMap<PlayerId, Player>,
}

struct Player;
struct SharedState { some: u32, fields: u32 }


impl Player {
    fn thing_needs_state(&mut self, &mut SharedState) { }
}


impl Server {
    fn do_stuff(&mut self) {
        let player: Player = // get a player somehow.
        player.thing_needs_state(&mut self.shared_state);
    }
}

In Rust, things which act on the server and more than one object just simply have to be methods on the server, though. No, the player struct cannot get direct access to the vec/map of players, that's just flat out not something one can do.  That violates the aliasing rules: the map's mutability is "bigger" than the player reference, so you can't let the player mutate the map since it could use that to get a second reference to itself.

However the thing is you need to work on your question asking.  I want to help you but your post here is somewhere between on weed and hyperactive but sad puppy.  I can't get enough out of it to provide you advice other than that you are frustrated and are doing the part where you try a bunch of languages because surely one of them is "right" and will make it easy, only to find out that programming is hard after all.

@2
You don't do that because channels implies threads and you can't have thousands of threads, or it implies async which is basically a meatgrinder for someone who is already having trouble with Rust.  Rust has tons of libraries like Bevy which solve the problem.  If he wants to stay in Rust he's going to need to take the time to understand something like that or how to handle mutable state the Rust way without falling back to thinking about this as OOP.

My Blog
Twitter: @ajhicks1992

2024-03-25 09:34:41

@3
By documentation I mean like at least something like `rust doc`, its just a bit disorienting to check file by file because of private vs public and all that, maybe my way of doing it is wrong, not sure, because I view with notepad just view stuff, not sure if vscode has an easy way to do something better?
also I mean third party library documentation, not C# language documentation, yes it's on the author but in rust regardless you can do rust doc to find all the functions, structs, enums etc even if without an explanation.
hmm, not sure how to clarify more? That's basically my issue.
I'm not exactly against threads and async except in rust, because yes, rust made me hate threads lol, I tried once or twice and found it to be way too much for what it is worth, and async in rust is... Interesting, it actually made me think of all async in all languages wrong because I assumed all languages do stuff the same way.
yeah I suppose I was trying not to make the server struct impl become 5000 lines because I really thought of it as messy? Is that a wrong way of looking at things?

2024-03-25 09:48:06

You want something like Xcode's documentation library in Visual Studio?

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2024-03-25 09:54:52

@5
yeah exactly, I want to see all public classes, functions, fields, properties, enums, anything, in a list, not for C# itself, while that will also be useful but that can be easily found in the internet from microsoft learn, but third party libraries.

2024-03-25 11:23:26

small remark about documentation, their is just enough of it out their to get you started, the rest is you have to figure out for whatever you're doing, especially games, you mite find articles detailing a few aspects   thrown here and their, usually tutorials, and they do cover a lot of the basics

And as anyone who's gone mountain climbing knows ,The serene snow-covered peaks that look so tranquil from a bdistance, Are the deadliest
sound is my vision
i rarely check my private messages on the forum, so if you want to contact me please use my email, or dm me  at oussama40121 on tw

2024-03-25 11:30:05

@7
No you misunderstand, I don't mean give me < long tutorial stepb y step for everything >, I mean, give me a list of public functions, classes, fields/properties, enums etc, with an optional explanation, that's just it, I don't need a huge tutorial or step by step guide or anything, and no, not for games, for libraries, for example, someone made an openAL binding? You have an API reference, Bass binding? API reference, JSON parser that is somehow really fast and has a lot of customization options? API reference, that's just about it.

2024-03-25 15:08:42

So you want Intellisense. Yes, vscode pretty much does that automatically if you have the proper extensions installed.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2024-03-25 15:25:25

@9
if I understand intelisense correctly it just, displays stuff when you write them? Like auto complete and stuff? I use that. But I mean like, a tree or web page or something, like docs.rs's system of displaying API documentation, is there a way to do that with vscode?

2024-03-25 16:52:59

Run your library through Doxygen
http://www.doxygen.org/

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2024-03-25 16:57:57

I'm sure C# has at least one documentation generator but I don't believe it is as standardized. Same problem with Python, JS, etc.  You are learning about how whoever makes the most recent language gets to solve packaging.  Rust was the last popular one, so they got a bunch of things right, and whatever comes next will get a bunch more things right and then we will be sad we are in Rust.  One of the things Rust got right is Rustdoc being standard and easy to use.  Python sort of tried, but sphinx is...special.

You don't know what you're doing, so if you stay in Rust thousands of lines for the server is better than trying to violate safety with global statics, and it at least works.  Note that you can split impl blocks between files, though.  It doesn't have to be a thousands-of-lines file, you can still organize the code well.  There are better ways to solve the problem that aren't tons of methods on a top-level object but they are hard to put into words and boil down to Rust being for the intermediate to advanced coder.

In general the insight is just figuring out how to split things the right way.  You're trying to move data "down", but in any good program in any language data should mostly move "up".  I don't have better words.  What makes a good module or whatever though is that you can look at it by itself and it doesn't really necessarily need you to know about the whole app or all the fields on the server or whatever.  Like for example maybe you make a PlayerManager, but that requires that players need a specific subset only, so you have to figure that out.  The difficulty with Rust is that the mutability rules indirectly enforce doing this well.

But seriously go read the bevy tutorial or something.  The entity component system libraries solve this for you.  They add complexity, but they're hard to use wrong and they don't run you into the mutable borrow meatgrinder.

As for Rust async, async in other languages is mostly the same save that Rust natively supports cancellation.  The issue with Rust async is that it takes your mutable borrows issues and multiplies them by 10 plus a side of understanding Pin and Unpin.  I have seen very experienced coders who have done C/C++ for a decade run into Pin and Unpin like crashing into a brick wall.  They got over it in a couple days because, you know, decade plus it was at work where you've got a whole workday to figure things out, but...well, if someone that experienced has trouble I hesitate to throw newbies at it for anything beyond  basic networking where all your questions can either be answered or end at "just throw Box around it".  Trying to figure out how to repurpose an async executor to let you use actors for everything is not worth it to me because you have to bend things until they break, and for you it means learning a whole lot and then bending things until they break.  But also I haven't seen anyone seriously use actors for anything since akka/scala a decade ago except maybe the occasional HTTP server and the Erlang ecosystem (Erlang is a niche programming language).

My Blog
Twitter: @ajhicks1992

2024-03-25 19:14:36

Most .Net devs I know use Doxygen. Is it the best? I don't know but it works well.

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com