The MMO Project Part 9: GDNative, where's your docs?

The MMO Project Part 9: GDNative, where's your docs?
GDNative — Godot Engine (stable) documentation in English

So there's not much here at time of writing. I think what I will have to do is just create the applications for the account server interaction and call them from gdscript. I can not for the life of me get GDNative to recognize libpqxx which is what I use for a DB driver. I tried all kinds of things. I recompiled pqxx to be able to work in shared libs, copied that over to the dir with the lib I wrote, made sure it was all linked up in SCons and made sure it was listed as a dependency in the gdnlib file. It acts like the file does not exist. Google has been no help and I have spent entirely too much time on trying ot make this as it is.

Plus from what I understand they are undergoing a major refactor for GDNative for 4.0 so I might as well just ignore it for now given the lack of documentation and amount of frustration it is causing. The simpler way is the better way in the situation. No need to use GDNative just because I wanted to. There is something I will be redoing in GDNative soon anyway and I can mess around with it there. No more foolishness, on to linking up the DB with the servers.

And now libpqxx is broken. Joy. Recompiling it seems to do nothing. This is just... mmm.

./char: error while loading shared libraries: libpqxx-7.2.so: cannot open shared object file: No such file or directory

In recompiling it in an attempt to get it working with GDNative I have somehow broken it. I reconfigured, make clean && make && sudo make install to no avail. Shit's busted, yo. The .so file is right where it is supposed to be it's just... knackered. Looked at my bash files and profile and can't find any reason for any of it. Seems like this one was doomed from the start. Sometimes it feels like some otherworldly force is trying to just say "Nope" and slap the ball out of my hands. Tried -I/usr/local/include (Which is where it lives) to no avail. But the implication is that it is linking fine, but when trying to run and it looks for the file it can not see it.

Oh damn it, lunch... it's 12:20.

Yeah, cloned the repo again, reconfigured, recompiled and reinstalled. No dice. Also seems to break my usb hard drive connection somehow whenever I install it. Damn it. Just one of those days.

Yeah, nope. Done all I could think to try. Really wish I was getting enough sleep, maybe this wouldn't be so bad. This is really frustrating. I will try to change the cmake options and compile it one last time, then I will have wasted too much time on this. I'll also copy the damn .so file into the directory and see if it might be trying to dynamically link somehow in the local dir. If that fails I am skipping this for now and doing something else. I will have to come back to it.

Tried with 7.1 and 7.2, copied the files into the directory. Something I compiled yesterday still works but anything I compile since trying to get it working with GDNative is borked. Damn it, why did I have to make it GDNative? What a fool I was. Let's try a symlink, maybe somehow that's broken. Yeah nope, wasn't anything weird there. Now I will just try and install it from AUR and hope somehow that fixes it. If not I will just move on for now.

The last ditch attempt at using AUR worked... somehow? What is this sorcery?

Well, whatever. I'll take it. Back on track.

./char 0
0
48
Checking Args.
Insert.
Opened database successfully: godot_orm
Inserted Character.

Finally.

Now comes the part where I add a buttload more args and make sure they all work. All 27 of them... yay. Alright, now I can generate a character via a command to ./char It's a long one but it's not like anyone is going to be doing this by hand.

./char 0 1 borfmanz 2 10 TestMap 2.1 2.3 0 0 2 1 3 2 1 3 2 1 15 15 13 13 1 200 120 0 0

Generates the following in the DB.

a8724af2ae98",borfmanz,TestMap,2.1,2.3,10,2,0,0,2,1,3,2,1,3,2,1,15,15,13,13,1,200,120,0,0,1

the 1 on the end is the account_id. It's the second value into the command though. Confusing, yes but I know how it works and hopefully with Godot 4.0 the GDNative docs are better and I can port this over and just pass whatever needs to be changed. I could write this to take args like --name Blah --level 2 and all that, then have a bunch of code to route it all to the right SQL statement but I think for now... just for my sanity I will keep it as is and just parse a long list of args with every call. It is C++ so it should be fast enough, though constructing the string in Godot might be a little slow. We'll just have to try it and see.

Now the update function seems to be working. Just need a lookup function by account.

Tedious though, I mean... really. I could have written this so much better if I wasn't already too frustrated to try anything else.

C.prepare("update_char","UPDATE characters_character SET ID = $1, name = $2, level=$3, experience_points=$4, account_id=$5 ,map=$6 ,pos_x=$7, pos_y=$8, stat_points_available=$9, total_stat_points=$10, strength = $11, agility=$12, dexterity=$13, constitution=$14, intellect=$15, wisdom=$16, spirit=$17, luck=$18, health=$19, max_health=$20, mana=$21, max_mana=$22, survival_craft=$23, gold=$24, inventory_space=$25, skill_points_available=$26, total_skill_points=$27 WHERE id=$1;");

Opened database successfully: godot_orm
ID = 708ff795-bf6e-4f20-89e9-73b3ad46015f
Name = Noname
ID = 0e000000-cb55-0000-0076-4f3d08e628b1
Name = Cake
ID = 0e000000-0256-0000-00bc-99d1868750c1
Name = Crapskat
ID = 0e000000-d855-0000-00a6-b539d4f88310
Name = 0
ID = 0e000000-0000-0000-0060-8eafb2d49331
Name = borfman
ID = 0e000000-0000-0000-0020-a8724af2ae98
Name = borfmanz
ID = 0e000000-0000-0000-00c9-0aef862ed8f6
Name = WHOAMI
Fetched characters.

Now we just need to format it into a json string and print it to console for godot to consume. Easier said than done. Also you can see a clear difference in the UUIDs generated by Django and by the Boost UUID lib here. Different randomization algos I guess. Though the thought crossed my mind that maybe it's just because python is slow and that might do something to the time element of the randomization but I don't know.

Do I dare use a third party library? https://github.com/jorgen/json_struct Hmmmmmm

Seems to be actively maintained, let's give it a shot.

I am really looking forward to tomorrow where the project is a hardware project. The last 2 days have made me want to eat my keyboard and me forgetting how structs work because I got too used to python has blown up in my face. Treated it like a dict. What a foolish man.

So I am going to be fixing that now... all 27 fields of it.

Well, Hop to it, dumbdumb. Gotta clean up this mess.

Of course it doesn't work. Why would it? Why do I keep trying to be fancy? CSV!

708ff795-bf6e-4f20-89e9-73b3ad46015f,Noname,TestMap,0,0,0,1,0,0,1,1,1,1,1,1,1,1,10,10,10,10,1,100,100,0,0
0e000000-cb55-0000-0076-4f3d08e628b1,Cake,TestMap,1,1,1,1,0,0,1,1,1,1,1,1,1,1,10,10,10,10,10,100,100,0,0
0e000000-0256-0000-00bc-99d1868750c1,Crapskat,TestMap,1,1,1,1,0,0,1,1,1,1,1,1,1,1,10,10,10,10,10,100,100,0,0
0e000000-d855-0000-00a6-b539d4f88310,0,TestMap,1,1,1,1,0,0,1,1,1,1,1,1,1,1,10,10,10,10,10,100,100,0,0
0e000000-0000-0000-0060-8eafb2d49331,borfman,TestMap,0,2.1,10,2,2,0,0,2,1,3,2,1,3,2,1,15,15,13,13,1,200,120,0
0e000000-0000-0000-0020-a8724af2ae98,borfmanz,TestMap,2.1,2.3,10,2,0,0,2,1,3,2,1,3,2,1,15,15,13,13,1,200,120,0,0
0e000000-0000-0000-00c9-0aef862ed8f6,WHOAMI,TestMap,212.1,123.4,10,2,0,0,2,1,3,2,1,3,2,1,15,15,13,13,1,200,120,0,0

There! FUCKIN' DONE! It can create read and update characters. THERE IS NO DELETE!

I still have to integrate it with Godot and also build the Account lookup one but that one will be way easier, all it has to do is return account id by way of username.

Not sure why I kept trying to do things in "clever" ways. Yeah parsing the csv in godot into a dict will take time but not as much as GDScript POST requests and GET requests then parsing the json. At least that's what I am telling myself whether or not it's true. I very likely could have gotten away with writing this in python. Very... very likely. But "NO! Python is slow! We need SPEEEEEED!" said my brain, "These operations will happen VERY often so we need to make sure we squeeze as much performance out of them as we can with the power of C++!" it added like some kind of asshole.

I probably should have written this in python and then later on when I needed it to be more performant rewrote it in C or C++. Nothing wastes time like trying to save time.

It's almost time to clock out now and I feel like I got nothing done because of all my dawdling with overengineered ideas. Hopefully I learn my lesson here but I wont, I am a computer scientist. It'll have to recurse a few hundred more iterations before the process finishes. It's quadratic recursion unfortunately and I can't refactor my headmeat.

How I solve some problems.

Anyway, tomorrow is a hardware project I have had in planning just waiting on materials for a while now. That should be a good change of pace at least. Then back to this Friday and I SHOULD have it implemented into the servers and be ready to move on.

Time to go make some food, Cheers.