Return

Struggle to reach something 2024-01-09

I haven't accomplished much in the past several months. I've had this feeling for a long time now: I want to work on bigger projects, but every time I try, the progamming language is getting in the way.


Programming language rant

I've always had problems accepting things that are bad and unnecessary. Even back in middle school I struggled with classes like history because I just could not convince myself that the year Napoleon lived or died or whatever is worth remembering. This problem manifests itself today in programming, the more times I have to type -> instead of . to access a variable from a struct the more I start to hate programming. It seems like such a minor thing, but I have to do it probably 100s of times on a good day of programming, it requires 3 key presses - Shift < instead of 1, it makes the code look like disgusting vomit, and there's no actual purpose for it. The compiler already has to know that the variable is a pointer in order to give an error about it, you can't use . for anything when that's the case and you can't use -> when that isn't the case, so there's no reason to have that differentiation. C++ adds the ugly :: syntax on top, I can't stomach looking at that at all.

C is great when you're doing little things, but when I scale up beyond a certain point, it just always seems to devolve into a bunch of managerial crap that has nothing to do with the actual program that I want to work on. And when you're trying to keep a large and complex system in your head, all the little unnecessary and ugly things consume too much mental bandwidth.

I've looked into every alternative language that I can find but C is still the lesser evil of them all for me. C2 looked like an improvement until I found out that I would have to change all of my naming conventions because the author, like many other language authors, is a control freak and forces you to capitalize all of your variables and types in a specific way. There was another language that forced you to indent code with spaces instead of the dedicated indentation character (tab), and another that required you to use Visual Studio, I cannot wrap my head around what kind of brain damage would cause someone to add such requirements to their language.

As such, I've more and more started to consider making my own programming language. All I really need is C with several conveniences added on top. I tried making a lazy parser that just merges all the files in my program and re-organizes things so I don't need separate header files (the goal being that I can #include a .c file and it just works), but decided that the tradeoffs of what you gain and lose are not worth it.

I concluded that if I'm going to make and use a custom language, it has to be at least a semi-proper language that parses all the contents and does type checking and namespaces/scopes etc, which significantly increases the difficulty of making that language.

There's still a huge shortcut I can and want to take, which is compiling my language into C code and then using a C compiler to compile it. The biggest issue with that is that unless I validate everything perfectly, the C compiler may give an error about something and it's going to give a totally different location for that error which is hard to find from your own code. You can use #line to manipulate what location the compiler thinks it's at, but if I have to plaster that on every other line, I'm concerned that's going to slow things down a lot.

But anyway, I have the feeling that I can't continue programming unless I do this. The amount of time that I spend being burned out is increasing over time, and I attribute it to all the friction I have with the programming language.

My current plan is not to make XHACK as described on that page, but rather an alternate version of C. Many of the features will be similar, but the syntax will be similar to C and I'll ignore some of the more complex features.


Stalker Anomaly modding

I got into modding (as in making mods for) Stalker Anomaly. It's just simple things like rebalancing stats and crafting recipes and changing icons and such, I made them for myself so they're not anywhere. Anomaly is one of those games whose concept I find extremely appealing, but the more time I spend on it the more I hate it because it's full of issues and it's too difficult to fix them.

The modding for that game is infuriatingly broken. In order to replace some value, you have to replace the entire file which may have 100s of items or objects or scripts and thus will almost certainly conflict with any mod for a similar subject. There's "modded exes" which allow you to patch in variables without replacing the file, but the way it's implemented is absolutely retarded and doesn't even work half the time. If you're going to modify the executable of the game, you should just add a proper merger that takes files from mod folders, reads instructions from them, and replaces the original files with modified ones before the game even runs and reads them. Here's an example of what a mod file could look like:

!FILE "configs/items/items/medical.ltx"
!MODIFY bandage
cost = 600
eat_satiety = /
!DELETE medkit_scientic

!FILE "configs/ui/maingame.xml"
!MODIFY w speech_menu text
x = 213
y = 100
!MODIFY_TEXT w weapon_jammed_static texture
"ui_hud_icon_weapon"

The data itself is such a rat's nest of nonsense and bad formatting in so many levels that I don't even know how to describe it. The files, how the game reads them, how the files relate to each other, the file contents, the comments in the files, the data structures, the way things are named and organized, how the data affects the game, it seems like every aspect that could have a problem has problems. Even the indentation of the text is a completely randomized mixture of spaces and tabs that somehow aligns to the correct level anyway. To be fair these problems are probably in part inherited from the original Stalker games.

As for the logic scripts, I get very confused and don't understand how people can program like that. It just seems like lots and lots of managerial crap, it's a bunch of methods and callbacks passing objects to one another forever seemingly without ever doing anything themselves. I'm looking for "the thing" and can't find it, I can't find a single piece of data that represents something in the game that I could modify to do something. I did manage to increase how thirsty do you need to be before you start getting penalties and taking damage though.

It has become very routine for me to ask "why don't you just do the thing?" when I look at other people's code. People have this strange tendency to set up a bunch of managerial architecture to wrap things into instead of just doing the thing. In theory that makes sense for modding because then you could, in theory, replace each wrapper with another one, but I'm not convinced that that's what's happening in Anomaly because you have to replace the whole script to mod it. There's some way to kind-of replace functions in a script from a separate script, but it doesn't work very well because the scripts have local variables that need to work across multiple functions in that file and you can't edit or access those variables externally. Again, you could use instructions similar to what I mentioned above to patch parts of the scripts, but I guess that's too simple and useful of a solution.

On a tangentially related subject, apparently there's an open source rewrite of the whole Stalker engine. I'm hoping that it can eventually be used for a better and cleaner version of Anomaly, although I have no idea what that would entail. I looked at the source code and nope'd out of there when it started looking similar to the Anomaly scripts (can't find "the thing").

Anyway, what I wanted to make was a total overhaul of equipment stats. I just can't bring myself to care about all the equipment that have 1-2% differences in stats and very similar prices, so I wanted to make things more distinctive. It would be cool if there were several tiers and classes of equipment and each faction's armors had their own distinctive benefits (like bandit armors having slightly more carry capacity, monolith having extra psychic protection, etc). But the stats are too convoluted, I can't make sense of what kind of effect X % of a particular stat has, sometimes it seems like 5% protection against something has a massive effect. Balancing all the consumables was more easy because the meaning of restoring/removing some portion of your stats is much easier to understand.

My ultimate dream would be to overhaul the whole game, there's many aspects that would be a lot more cool with some tweaks. But it's just such a mess that it's never going to happen. Every time I get a burst of motivation and start tinkering with things, I am quickly reminded of how unworkable the data and code is and why I previously stopped.


Image viewer

You'd think there was a program that just shows you images and works correctly, but even that's somehow too much to expect. I started working on a program which does that: shows images (and isn't completely broken). I got the basics working and in some ways it's already better for viewing images than irfanview (my current image viewer).

The biggest problem that stopped me from finishing and using it are animated images, a substantial portion of my images are animated gifs. I can't play an animation from my program unless I can extract the frames and get their times/delays, and doing that is kind of complicated.

I started learning how to do rudimentary parsing for various file formats, mainly I wanted to extract the image dimensions very quickly so I can sort the files according to dimensions. I learned to hate JPG while doing that, in order to know the dimensions of a jpg image, you have to read through arbitrary amount of data chunks to find a chunk that has that information, the worst I found was a jpg where that information was 7000 bytes into the file data. The problem is that if I open a folder with 10000 images, the program may not be able to sort and browse through them until all those files are analyzed, I want to read the dimensions as quickly as possible so the program doesn't have to stay in any kind of temporary waiting stage for long. Having to stream in an arbitrary amount of jpg file data is going to make that a lot slower. Thankfully bmp/png/gif/ico files have that information right at the beginning (as they should), as long as you read 30 bytes from the beginning you can get the dimensions for all of those formats. I haven't looked into the newer image formats like avif yet.

My current format review (for the file structure, not the algorithms within) with my extremely limited undertanding: bmp is an abomination with like 20 different versions and alternate formats and weird hacks and exceptions in it but it gets a pass because it's relatively simple (it just has the data in it while all other formats have a series of chunks) and it can be extremely simple if you want it to be, gif is pretty good but it has some ugly extension stuff and weird obsolete/undefined features, ico/ani are just containers for other formats like bmp so they're not real image formats, png looks ok although I get concerned when I see how many different types of data blocks it has in it, jpg seems crap.

I made an almost-complete parser for gif files, partly out of curiosity, partly because gif animations are the most prevalent and I was hoping to open them as fast as possible, I can read all the information from a gif file except the pixel data. The pixel data is compressed with some third party algorithm and I can't be bothered to research that separately. I looked at a small gif library but I can't make any sense of it. Most C programmers have this strange habit of making the most obtuse unreadable code. Once again: just do the thing. Just name the variable according to what it's for OR add a comment to explain things, do AT LEAT ONE of them instead of neither. Stop abbreviating everything into an unreadable mess and adding 800 #ifdefs everywhere. Just... do... the thing. Normally. At least pretend to be a human when you write code.

The gif documentation was relatively pleasant to read because it just tells you the structure of the file and the rules. I tried to look for png documentation and couldn't find anything similar, I could only find what look like academic papers that have many, many words to give you but none of the words just tells you the thing that you actually need in order to read a png file. Nonetheless I was able to get the basics by reading various sources, I even managed to figure out how to detect apng animation frames.

Anyway, I eventually figured out how to make Imagemagick extract frames and frame delays from animations, but I'm not sure if it gets the delays correctly, I could be wrong but I think it rounds to the nearest 1/100 millisecond which I'm pretty sure is a gif-only limitation. A workaround (which I may prefer anyway) is to extract the frame delays manually (I can already do it for gif and apng). Imagemagick also doesn't support animated jxls, but support for that is very dodgy so I'm not sure what to do about it. The code required for decoding gif pixel data is fairly small so I hope I can at least do that fully manually for maximum speed.

Here's a design mockup of what the image viewer could look like if I ever finish it:

There's no image viewer that I know of which has a timeline for animated images. I plan to have 2, the top is relative to time, and the bottom one is relative to frames.

I don't know what to call it yet, "JIMG" just seemed nice on a whim.


I've thought about UI design for a long time, it has always bothered me when you can't tell buttons and toggles and background text apart. I've gone through many iterations of designs for several projects, and I think the mockup above may have the best ones so far. Especially toggle button (setting that can be turned on/off) designs are hard to come up with.

On the topic of design, I was always fascinated by that kind of window design where the border and the window contents are the same, it seems very minimal and effective. If I made an OS, I would try to standardize a window design like this, maybe the program tells the OS what background color to use and then tries to blend with it, or can draw anything under the border, or whatever. I absolutely LOATHE the "modern" window design where the border is 1 pixel wide and the resize handles are outside of the window edge.