T O P
KingAggressive1498

Probably writing a single-threaded 3d scanline software rasterizer that rendered at 720p in C89 without using floats. In 2016. It was usable in real-time for simple stuff.


jabakkkk

Link?


KingAggressive1498

Unfortunately it was one of the Google Code projects that never got archived when they shut down. It's on one of my old machines so maybe I'll put it on GitHub sometime.


jabakkkk

Thanks. Would love to learn from it, sounds impressive.


KingAggressive1498

Most of it was pretty trivial tbh. I used 16.16 fixed point numbers for screen positions and used bitmasks and shifts to effectively vectorize operations on color channels. Here's my alpha blending code for a quick taste (I guess I must have started in 2014): https://stackoverflow.com/questions/1102692/how-to-alpha-blend-rgba-unsigned-byte-color-fast/27141669#27141669 This tended towards black because it effectively divided by 256 instead of 255. Acceptable inaccuracy in most cases but if everything had alpha blending... The real beast though was my bilinear filtering function. It used the same vectorization trick, but I actually covered for the case where fully transparent pixels with all black color channels get blended with opaque pixels that aren't black (this would normally lead to darkening of the borders of stretched textures - this was necessary for my project anyway because I also handled XRGB with a colorkey, so it was just a matter of another condition in my if statement).


mredding

I worked for a portfolio management company. They had a message object that embodied the FIX protocol, what stock exchanges the world around use. This object was massive, and grew organically from pre C++98. sizeof (message) == 48 KiB. Instantiating one came with a boat load of dynamic allocation before you even populated any fields. We would generate about 50 million messages a day, and keep them all in memory during the business day. We were starved for resources. We were looking at a huge data center upgrade to increase daily capacity. I got the whole thing down to 12 bytes. With dynamic allocation, the average message was about 150 bytes. Instead of marshalling the data from the wire protocol to the structure, I kept the data in the wire format. I did a linear search for fields, and when found, shuffled the buffer around to put that field in front. Most commonly accessed fields percolated to the front, archival fields fell to the bottom. Lookup was faster than a map, most of the time. Our capacity went through the roof, performance went up thousands of percent because now messages could fit on a couple cache lines. We had a press release about a new version of our server software. No, man, I just got the stupid out... In college, I had a test in assembly. It was an all or nothing pass or fail, and I was expected to be the first one done. And I would have been, except I forgot how to divide. I knew the instruction and the registers, but I kept getting out garbage. I was the last one out of the room. With 10 minutes to go, I wrote a division algorithm in assembly, instead. The program worked, and I passed. As I walked out my friends were wondering what was up. I explained the situation. Then my friend asked: > Did you remember to zero out the result register beforehand? FUCK!!!


MountainAlps582

I had experiences like the last one. Thankfully it only has to happen once or twice to remember it


mredding

Yeah, in college, I never lived that one down. "Forgot how to divide" became my middle name.


camilo16

Making an engine from scratch, still in progress


the_Demongod

Same here, on my second one...


camilo16

which API?


the_Demongod

OpenGL


aaaaaaaaargghh

Compiling Boost libs on a Windows machine.


MountainAlps582

/thread


Narase33

Writing a small language similar to Java that no one ever will use


MountainAlps582

I don't ever plan on touching that stuff. Are you doing some kind of proof of concept for anything? and why "similar to java"?


Narase33

Its just a project for fun, I wanted to know how compilers work internally so I just wrote one. Biggest conclusion so far: C syntax looks like it looks because its incredible easy to parse. If youre writing a language/compiler and youre looking for a syntax thats easy to parse you tend to rebuild C. Its "similar to Java" because I wanted C'ish syntax without manual memory management. [Repo](https://github.com/Narase33/StackMachine) if youre interested, latest feature was function calls. Im kinda in a writers blockade right now as I dont know where I want to go with that language (easy to use? fast? teaching language for students?)


MountainAlps582

Why did you write it in C++? I don't know much but I know especially for toy projects C isn't a good choice. I heard functional languages are good for writing compilers. I tend to never use C++ unless I need it to be fast and I usually prototype in a gc language


Narase33

First and biggest point: I love C++ and tend to use it whenever I can Second point: C++ is blazing fast and you need speed for compilers, especially as I dont compile to native ASM but use an interpreter to execute the code in a second step. I also never wrote a single line in a functional language so learning a new language while writing one seems kinda overkill


MountainAlps582

haha, i see. I hear they're super hard to debug and I hate debugging in C++ so this is indeed crazy when you say you're doing it My last 'crazy' c++ related thing was rewriting a microservice at work that had 400ish global var. Went from a 400K like "small" project to my 50K rewrite


Narase33

>Went from a 400K like "small" project to my 50K rewrite thats impressive, not just the size reduction, but also refactoring \~400 globals with all their side effects


MountainAlps582

I might have actually increased the global variable count (technically they were thread local). Most of the globals have only 1 function that sets them (sometimes more than one if they're related). The other functions were read only. This made things easier because I wasn't 100% sure what the call graph would be and if I copied the original design I may have overwritten a global if the right set if statements were taken. Having more globals but forcing them to have a function owner made it way easier since I can start calling the function in any order I want and was able refactor without fear


UnicycleBloke

Not crazy, but kind of misdirected enthusiam... Writing a text <-> binary codec for a Byzantine game mod format that nobody asked for, almost nobody commented on and, I think, nobody has ever used. I don't even write mods for it myself.... Was fun in a sort of completionist way, trawling every detail of the badly written spec. I also wrote a ton of documentation that no-one will ever read...


luitzenh

This was pre covid at a work party for my girlfriend. Hotel and everything included. Loads and loads of alcohol, colleagues sleeping with each other, that kind of party. We both were very drunk and I had to lift my girlfriend in the bed as she was too drunk to get in bed by herself. I'm nicely sleeping when I start dreaming that I really need to pee, so in my dreams I desperately search for a toilet. It takes quite some time, but in the end I manage to find a toilet. I open my pants and start to pee. It takes a good while, but I'm enjoying as it's a great relief. The moment I finish peeing in my dream I'm suddenly wide awake and alert. I was absolutely hammered only a few hours before, but now I'm not even a little bit tipsy. I stare at a puddle on the carpet and immediately I realise I'm only wearing boxers, that I just peed in a corner of a hotel corridor and that I don't have the keycard for the hotel room on me. So there goes my walk of shame to reception where I explain I was sleepwalking and didn't have a keycard for the room on me. Luckily reception is quite cooperative and give me another keycard. Next morning when I tell my girlfriend about my nightly adventure she's absolutely shocked. Not saying it's the craziest thing I've ever done, but it's definitely somewhere in the top 50.


MountainAlps582

Funny sorry 1) don't delete this 2) Were you aware of what sub you were posting in?


luitzenh

I did think it was a weird question for this sub.