Loading...

Top
PFQ Banner

This is PokéFarm Q, a free online Pokémon collectables game.

Already a user? New to PFQ?

Single post in Dev Log 204

Forum Index > Core > Announcements > Dev Log 204 >

Niet [Adam]'s AvatarNiet [Adam]
Niet [Adam]'s Avatar

Starting over: a fresh angle

It's difficult to admit when you're wrong. It's difficult to tear yourself away from the sunk-cost fallacy. It's much easier to press on, to consider it "good enough" just because it's technically working. But it is important to take the correct path, not the easy one. So it goes with PFNew. I had already noticed that the code was getting messy. In my determination to "just get things done", I had neglected the important part of "get things done well". It's not enough just to go fast. Going fast early on might feel like progress is being made, but it leads to much slower progress later as the mess has to be waded through. Instead, it is far better to take things slow and steady, especially with the foundation of the system, as this will allow continued development to remain fast and effective. And so I find myself rewriting basically all of the work I've done on PFNew. Thankfully, a lot of it can just be copy-pasted into the new structure, with only minor adjustments, so it's not like I'm wasting anything. It's just getting rearranged and put away tidily. It's like arranging your books into a library rather than just keeping them scattered on the floor. With this rearranging, I'm actually able to make some changes and improvements that wouldn't have been possible otherwise, so that's good! Here's just a few examples of what I'm changing as part of this tidy-up:

More organised code

The thing that tipped me off to there being a problem is that I had a bunch of files with similar names. For example, Pokemon.class.php PokemonAlternate.class.php PokemonBusyState.class.php PokemonCouple.class.php PokemonExp.class.php PokemonGender.class.php PokemonHappiness.class.php PokemonReleasePreventionReason.class.php PokemonSource.class.php PokemonStage.class.php PokemonStats.class.php You know what would be tidier? Folders! And in PHP those are called "namespaces". Pokemon |- Alternate.class.php |- BusyState.class.php |- Couple.class.php |- Data.class.php |- Exp.class.php |- Gender.class.php |- Happiness.class.php |- Pokemon.class.php |- Source.class.php |- Stage.class.php \- Stats.class.php Okay so that might not look like much on its own, but now apply that to all "groups" of things, like Fields, Species, Items, Quests, Interactions and you get the idea. Having better organisation of code will make it much easier in future to find where to go when adding or updating features. Another thing this has done is helped me break the habit of putting more than one class into a class file. Sometimes this is okay, but usually it isn't. An example where I had done this inappropriately was the StrongType system, where each individual type was in the same single file. This was fine, except that it meant the auto-loader couldn't find them. I had to "fix" this by adding a call to StrongType::init(). Do you know what this function does? Absolutely nothing, it just causes the auto-loader to load the StrongType file and "accidentally" load the individual types in the process. That's a hack if ever I saw one, and it needed to be fixed. Now it is, each type is defined in its own file, inside the StrongType folder. Much better!

Better database handling

On PFQ - and on PFNew until I changed it - each "object" (be it a Pokémon, a Species, an Item...) is a row in the database. The code then loads up that row and puts it into a PHP object so it can be worked on. Objects are also stored in Memcache, which speeds things up because it avoids looking for it in the database if possible (database lookups are relatively slow). But there are problems with this system. - Consistency. If Memcache isn't properly informed of changes, the game can be inconsistent for up to an hour until Memcache automatically purges it. This is why you sometimes (rarely) get the Scour bug where a Pokémon shows as "returned" but trying to retrieve it says it's not on a mission... but it is... but it isn't. - Reliability. I can't reliably update items without a delay, such as when Tournaments end. Even now, if you happen to load the Tournament page while scores are "being calculated", you might be locked out of buying the Egg for up to an hour afterwards because of the lack of reliability. - Performance. Ever wonder why "Pokémon that can evolve" takes so long to load? It's because each individual object has to be loaded one by one. The database is queried for a list of IDs of Pokémon belonging to you, then the system goes through each one and loads its data, checks it for evolution conditions, and displays it if it is ready. This is the biggest reason why I can't reasonably implement any kind of type filtering. The QoL userscript "fixes" this by loading data from the PokéDex and caching it, but that suffers from all the same problems as mentioned above. This is sometimes why Vulpix Eggs don't get highlighted in the Shelter when you filter for Fire-types, it has cached (Alolan) Vulpix as an Ice-type Egg. So what does PFNew do now? It has loosened the coupling between a PHP object and the corresponding database row. This means that I can just load all of the data directly, rather than having to get the list of IDs and then looking up each ID one by one. This will be a massive performance improvement on things like Fields, that would otherwise involve up to 40 database lookups. It's amazing the things you can do when you have experience under your belt... PFQ, even the Recoded version that we're on now, was made 8-10 years ago. I have learned a lot since then, but have been unable to apply it to PFQ due to just how bad the foundation is.

Localisation/Internationalisation

On to something that you as players will actually get to see! With new and improved organisation, I have taken care to separate "content" from "behaviour". This means that PFNew will support translation into other languages! To start with, this will just be about localising number formats. For example, PFQ lists the max PokéRadar chain as a +3,996% boost, but this is confusing to our European players because they use the comma as the decimal separator, so to them it could be confused for just a +4% boost! Oops... Similarly, PFQ is locked in to a 24-hour clock for its Server Time. Players from the US may struggle with what they refer to as "military time", so PFNew's localisation system will allow them to have a 12-hour clock. Also they get to have "color", "flavor" and dates in their silly month-day-year format :p (love you guys, but you're weird sometimes XD) Down the road, the language files will be able to be translated into different languages, which I think will be an amazing thing to be able to do! Of course, that's quite a monumental project, but there are services out there like Crowdin that should allow us to provide this option.
There is of course much more than just these three benefits, but a lot of them are on the technical code-side of things and I'm not sure I'd be able to explain them properly! A lot of these improvements are thanks to the new features of PHP 8.1, so in a way it's a good thing I had a bit of a mental breakdown and had to take time off! Ahaha... Not really. But I'm definitely enjoying the progress I've been making on this rewrite. And, like I said, a lot of it is "just" moving code around to organise it better, so none of my previous work is going to waste. I have mentioned elsewhere, but the current optimistic hope for PFNew is to open in 2024. Time will tell if I'll be able to deliver on that date, but on the flip side it might be possible to have limited beta testing as early as 2023... We'll see! Thank you again for your patience and understanding as I work through personal, mental, and also technological problems. I find myself doubting my ability a lot, but still I press on, determined to deliver a game we can all enjoy together! Discuss!
Clip from Pokémon anime, re-lined by me
-- OMNOMNOM!
Featured story: Injustice Feedback welcome!
© PokéFarm 2009-2024 (Full details)Contact | Rules | Privacy | Reviews 4.6★Get shortlink for this page