Published on

Devlog #52 - Web Workers

SmartFoxServer websocket API has been successfully quarantined into a web worker.

https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers

Here's how web workers work. You create the worker and then communicate with it via postMessage and onmessage. It's the simplest and easiest to use API I've ever used to handle threads. I post a "connect" message to the websocket worker and then from there on out the web worker posts any and all messages received from the server to the main thread. When the player  does something like move an item in their bag or click on the map to move, the main thread then sends the data needed by the server to the worker thread and the worker sends it on to the server. Awesome.

JavaScript's garbage collector is single threaded. This means that the worker has it's own garbage collector. So all that garbage created from sending and receiving messages on a websocket is now handled by a separate thread thus greatly reducing garbage on the main thread. This is the reason movement got so smooth all of a sudden. Thank you web workers!

This web worker work took me about 3/4 of a week to finish. Not because it was hard to transition the code, but partly because of the headache that is CORS. CORS stands for Cross-origin resource sharing and it basically prohibits loading of resources from a domain other than the one it's hosted on. So when I tried to load the worker JS file from https://game.fantasyonline2.com/ on https://fantasyonline2.com/ it complained. It's not completely straightforward to fix as loading JavaScript isn't really CORS but another form of it. So to get around it ChatGPT 4 helped me figure out a work around.

If you load a JS file via fetch, then load it into a Blob, and then create the worker with the blob, the worker won't complain. And this is usually the kind of silly thing that takes up a lot of a game coder's time. Finding work arounds for something you need to do but which isn't directly supported. What a headache. But it was all worth it for the smoothness.

I was then going to go back to finishing up the party system when I got a bad flu like sickness. I'm almost recovered but it took me out for a good week. In that week I decided that parties aren't that important right now so I'm switching gears to getting the market up and running. Most of the market MySQL tables are in and working, so now it's time to implement the market window and all the functionality of it server side. Once I finish the market, I'll go back to parties.

I setup about 70% of the gem shop window. It now pops up if you try to buy something with gems and you don't have enough. I'll be working on hooking this up to the Steam microtransaction API in June as well. For Patreon it will just open the membership tab of our Patreon page.

I also recently had a couple of FO virgins play FO2 to give me some feedback. The #1 complaint was the lack of pathfinding. So I'll be looking at that as well. I've implemented pathfinding several times before, most recently in AO, so it's definitely doable. It just takes awhile to get feeling right.

Patch Notes #49 - Astronaut Exodus

The Astronaut Box Set has left the building until next year. Both sentry.io and Google Analytics were screwing up the main thread render loop so I ripped those out. Forgotten Wasteland map is in and looks really cool. There's a really big secret hiding in the top left corner of it. We'll open it up for people to run around in maybe this week.

Patch Notes #50 - More Mirabella

 Mirabella now has almost all of its quests in. MC is such a big zone content wise. All the T1 crafting, more quests than any other zone, lots of neat drops. It's a great zone.

Join annually and save!

Patreon enabled annual subscriptions for us out of the blue. I turned it on.

What items should be in the Summer Battle Pass?

The Summer Battle Pass is likely coming much sooner than at the end of Summer.

Patch Notes #51 - CoD Skills & Hotbars

 Multiple hotbars are here. Time to move all your teleports to hotbar 4 right?

Patch Notes #52 - Spring Battle Pass

The Spring Battle Pass is here. There are several great looking sets including Farmer, Chicken, Duckie, and Acorn Warrior. Summer Battle Pass work has already started so maybe we'll get it for the first day of Summer? We'll see.

I've been thinking about implementing the ability to transfer certain items between FO2<->Steam Inventory.

https://partner.steamgames.com/doc/features/inventory

https://partner.steamgames.com/doc/webapi/IInventoryService#AddItem

https://partner.steamgames.com/doc/webapi/IInventoryService#ConsumeItem

https://partner.steamgames.com/doc/features/inventory/schema

These are the things I'd need to implement. Essentially there'd be a window where you'd drag and drop your item in order to transfer it to your Steam Inventory. Then it would be possible to buy/sell/trade FO2 items on the Steam Community Marketplace. If you wanted it back in-game you'd then open another window in FO2 that would allow you to transfer it via "consuming" the Steam inventory version of it. Steam uses the same naming for their item definitions as FO2 does. Small world.

These two boolean flags on each Steam inventory item definition would be the only reason I'd implement this. So what do you think? Do you want to be able to buy/trade/sell items from FO2 on the Steam Community Marketplace? https://steamcommunity.com/market/

So in the next two weeks I'll be working on the market, finishing off MC quests, fixing bugs, and doing other random things that pop up. I always end up spending a lot of time on random quality of life things that people yell at me while in the game, so that too.

See you next patch notes!

Have Fun & Keep Gaming!