toddw123 / RotMG_Clientless

Compatible with version X16.0.0
MIT License
11 stars 4 forks source link

Linux support #44

Closed VoOoLoX closed 7 years ago

VoOoLoX commented 7 years ago

So since I moved to Linux few weeks ago I decided to try and get this working on Linux. I just got it semi-working. It connects to server and I can use "test" and "shoot" commands but character is not moving, could be platform based problem or it could be that I messed up the actual code, still not sure at this point (just got it working so I'm a bit excited and haven't really looked at the code).

EDIT: Here is the screenshot http://i.imgur.com/xZDkFzw.png

toddw123 commented 7 years ago

Awesome keep me updated. I only tried to compile it a few times in my linux VM because i was too lazy to drag it over to my other computer. I kept getting errors related to the unordered_map of functions in the client class (the packet handlers). I havent tried to get it working since, and that was probably a few weeks or maybe a month ago ha.

So yeah, im super interested to know if you get it compiling properly. Definitely keep me updated.

Zeroeh commented 7 years ago

No code? No explanations?

VoOoLoX commented 7 years ago

It compiles properly with no errors (just few warnings) but the thing is, on Linux pointers are 64 bit and that leads me to the question why are you casting void pointers to int? The way around that I use is to cast void pointer to long first and then cast it to int and yes I know that's not the best solution and that's probably the cause of seg faults which occur every now and then. Interesting thing is I got 0 errors related to unordered_map.Seems like there is the problem with either threads or timing, and most likely that same problem has something to do with bot not moving.And since @Zeroeh is looking for code maybe make a new branch so I can push the code there?

toddw123 commented 7 years ago

to the question why are you casting void pointers to int

Huh? Not really sure where you say im doing this? Unless you are talking about the path-finding. In which case, that is how the person that created the library for it designed it to be used.

And yeah if you are changing lots of stuff instead of setting it up in if/def compiler macros then i can make a new branch for it.

VoOoLoX commented 7 years ago

I tried to use a lot of preprocessors but I'm sure I missed some stuff and I kinda removed the whole EnumToString thing cause it was not working for me and I couldn't figure it out. And yes the only file that seems to have void pointers to int casts is the TileMap which is for the path finding I guess.

Also who used "\" instead of "/" in the include paths? Fucking annoying stuff, thankfully it was only in few files otherwise I'd quit this.

Still have no clue why moving isn't working but my guess is timing.I couldn't find function that does exactly what timeGetTime() or whatever it is called does since it is windows only.

And I made CMake file to make things easier and quicker (linux (my distro at least) came with all the libraries I needed but for the linking process I had to include few additional libraries namely "libcrypto" and "libpthread" it's all in the CMake file so shouldn't be a problem)

toddw123 commented 7 years ago

Still have no clue why moving isn't working but my guess is timing.I couldn't find function that does exactly what timeGetTime() or whatever it is called does since it is windows only.

That is to get the miliseconds since the program started. timeGetTime() is a windows only function and i used it because its the best option for someone on windows. For linux you would want to use something like gettimeofday() or some std::chrono function.

Not having a valid milisecond function could definitely explain why things dont work for you.

Also, you should be able to do a pull request and i can just turn that into a branch i believe. If not, i can create a branch and then complete the pull request if needed. But either way, thanks for working on it. I gave up pretty quickly on trying to get it to compile because i dont know too much about using CMake (thats what i tried but dont think i had my file set up right).

VoOoLoX commented 7 years ago

I fixed the timing so now moving works perfectly, believe it or not it's my first time using CMake I only had to dig through docs for 30-50 mins to find what I was looking for but once setup it makes everything so much easier.

toddw123 commented 7 years ago

@VoOoLoX since i closed the pull request lets keep linux based chat in this post for now i guess.

Just merged the linux and master branch. There were only a few conflicts that i was able to easily fix. So the rest is good to go! Tested on windows in visual studio, master branch compiled no problem. Then switched over to my arch linux VM and pulled down the master branch, compiled no problem as well. So fuck yeah!

Also wanted to go over the file i added called "defines.h". This should be where we try to put any non-cross-platform things. If you look at the file right now for instance you will see a few defines in there that are wrapped in an #if/#elif macro (also a small note, for me atleast, __WIN32__ was not a valid define. That is why i added multiple ones for both linux and windows, try to use this).

Im probably going to change the SLEEP() define i created because i want to try and stick to using either one or the other platform's function. So for example, look at the closesocket() define i created for linux. Now, on a normal windows computer the compiler will use closesocket() as normal. But on a linux machine, since there is no closesocket() by default, its now defined and that line doesnt have to change to be cross-compatible! See how that works? It cuts down on the #if/#elif macros a TON if we stick to that kind of formatting.

Same kind of thing for SOCKET and INVALID_SOCKET/SOCKET_ERROR. On windows these are all normal things in the winsock header. But obviously on linux they are not, on linux a SOCKET is just an int. So the easiest way to solve that problem is to just make a new typedef for an int on linux! I saw you did this for one file but not all of them, not sure why, but you get the point. By doing typedef int SOCKET;, now all the code can be left alone without having to throw an #if/#elfi wrapper around every instance of SOCKET. And same thing with the INVALID_SOCKET/SOCKET_ERROR defines. Its easier to just create those defines on linux then it is to change the code or wrap it.

I didnt follow me own advice for the SLEEP() macro i created, but that is another option if someone wants to set up a define that way too. The idea behind SLEEP() is that its now a completely new function, meaning the code has to be changed from what it originally was, but by setting up a SLEEP define for linux (SLEEP(x) usleep(x * 1000)) and a SLEEP define for windows (SLEEP(x) Sleep(x)) we can now call a sleep function without having to use the #if/#elif wrapper each time. Pretty basic stuff here.

So since this is all the master branch now, lets try our best to keep everything cross-compatible. And try to keep it as clean as possible. But yeah, super cool this is working on arch linux and windows now. Very very very cool.

VoOoLoX commented 7 years ago

Great. You mentioned me in that pull request asking me about the screenshot? Were you referring to the one I posted here?

toddw123 commented 7 years ago

Why would i be referring to the one posted here when i was in the other thread? that makes 0 sense hahah. So yeah i was referring to the one you posted in the pull request thread that showed the terminal with a few errors, so this comment: https://github.com/toddw123/RotMG_Clientless/pull/45#issuecomment-297418963

Are you getting those errors on arch linux? And was it from a fresh pull of the linux branch at that point that caused those or were they related to something you were working on?

edit: so after running it for about 20 minutes on arch linux (with 22 accounts) it eventually crashed with this error: terminate called after throwing an instance of 'std::bad_alloc'. I have noticed the last few weeks that it will eventually crash on my windows machine after like a few hours, but never took the time to figure out what was causing it. But this gives a pretty good clue at what the problem is, and i found this post in regards to it: http://stackoverflow.com/questions/23444844/c-error-terminate-called-after-throwing-an-instance-of-stdbad-alloc

VoOoLoX commented 7 years ago

Ummm I'm kinda confused now. That's posted by Zeroeh ( http://i.imgur.com/mTlvJmZ.png ) so why you mentioned me?Also you can see it's on mac not Linux.

toddw123 commented 7 years ago

Ummm I'm kinda confused now. That's posted by Zeroeh ( http://i.imgur.com/mTlvJmZ.png ) so why you mentioned me?Also you can see it's on mac not Linux.

Lol im an idiot. I originally saw the post in my email and didnt bother to check who it was. Lol

toddw123 commented 7 years ago

Guess im going to run this on windows with the visual studio debugger attached so i can finally figure out where its failing. Based on the link i posted in the edit of my previous comment, i have a few ideas of where the problem could be, so ill see what i can find. It seems the it crashes much quicker on linux then it does on windows though. Linux it tends to crash within about 15-25 minutes. Whereas on windows it can run almost all night before it crashes. Pretty interesting. If anyone else wants to look into this and figure it out, feel free to do so. Lol i wont stop ya.

Zeroeh commented 7 years ago

@toddw123 Thanks for the cross platform sorting and such, I was wondering if the clang compiler was having issues with the #ifdefs and it looks like it did. I'll try out the latest commit and see if it works ;)

Also, from the other topic, it's not arch or ubuntu, it's macOS.

toddw123 commented 7 years ago

yeah i was getting warnings for originally having it look like #ifdef __unix__ || __linux || __linux__. Turns out an #ifdef is only suppose to have 1 variable in the statement. So its better to use #if defined(__unix__) || defined(__linux) || defined(__linux__) instead. I also included all of them just to try and satisfy any compiler. Because on windows, my visual studios didnt recognize __WIN32__, only __WIN32 and WIN32 aparently.

But yeah let me know if you get the latest commit to work on mac. I dont have access to a mac and i dont really feel like downloading a mac os and creating another VM just to test that lol. Would be cool if it does work. Would mean this program is basically compatible with any OS. I do plan to try and get it working on my Xubuntu system (ubuntu alternative) as well, i assume its just my older version of cmake and gcc that is the problem.

edit: @VoOoLoX do you know how to reverse the fucking mouse scroll wheel in Apricity? Its really fucking annoying having to scroll the wheel up to go down and down to go up. I tried a few things i found online but they didnt seem to work. When i use the touchpad on my laptop, that scrolls normally. But the mouse scroll wheel does not. lol

VoOoLoX commented 7 years ago

Yeah that's the issue I had on a live boot after installing system it was fine. I'm pretty sure it's because of touchpad driver, if you remove it it should be ok but well you won't be able to use touchpad. I'm gonna look for solution and edit this if I find any.

toddw123 commented 7 years ago

im not on the live boot anymore. I didnt play around with the live boot long enough to see if the scroll thing was a problem there or not, but in the actual OS i have the problem. And like i said, my touchpad works fine and it scrolls correctly (down is down, up is up). Its only my freaking mouse scroll wheel that is fucked up. It wouldnt be that big a problem for me if i was using just Apricity, but its really really really annoying when i keep going from Apricity to Windows and get confused why my scrolling isnt working lol. Its just a constant fuckery of reversed scrolling. I start to get use to the up is down, down is up. Go to windows and get confused why scrolling doesnt work right. Then get back to normal from using windows, switch over to Apricity and get confused as fuck again because the scrolling isnt working. Lol got this is annoying.

VoOoLoX commented 7 years ago

Ok try this gsettings set org.gnome.desktop.peripherals.mouse natural-scroll false That should only change the way mouse scrolling behaves.

toddw123 commented 7 years ago

did that one already. didnt work :(

also tried doing various xinput stuff. The one i found on xinput said that the mouse values (i had 3 "mouse" inputs, not sure what the differences where) and each one had values of 1 2 3 4 5 6 7 8 9. The article i found say that values "4" and "5" are the scrolling input, so reverse the 4 and 5 to make it scroll normal. I tried each of the 3 inputs and set the values to 1 2 3 5 4 6 7 8 9. That didnt work either. And also tried one other way but forget what that was. It had something to do with xinput list-props <device> and set the natural-scroll from false to true, and true to false. I cant figure it out

VoOoLoX commented 7 years ago

Have you tried to disable natural scrolling on both touchpad and mouse? Also have you tried to restart your pc/laptop?

toddw123 commented 7 years ago

Yeah totally forgot to try restarting after making the changes. I assumed it would be like every other setting in linux where the change takes effect immediately.

But yeah, looks like after i restarted that it is working correctly now! Lol

toddw123 commented 7 years ago

Closing this issue as the linux support seems solid at this point. If anyone wants to open another issue that is more specific like "Ubuntu Support" or something, feel free to do that.