Ramblings about programming


Was my reaction when I conceived of and blocked in an economics simulator into my engine… I still can’t generate useful terrain but once I get around that hurdle and implement a city generator I’ll have a game with a sprawling dynamic economy as in real life where the AI and players can either make or break it (and fix it, no matter how severe a depression is ultimately temporary; mind the game could end up in a state of widespread famine where every NPC or the vast majority die from starvation, the player doesn’t need to eat except in hardcore mode because a lot of players, me included, find such things tedious and annoying).

Well, rather the blocked out system needs to be fleshed out, currently it’s just a bunch of void interfaces. I’ll determine the area of famine based on cities, with an area around that city. then I’ll poll trade-routes for that city to see if the city can get food, assuming the city is willing to help them if they can’t afford it or if they can somehow obtain it through other peaceful or non-peaceful means. if the city can’t it will attempt other solutions and eventually work it out or die out, thus leaving a ghost town that might then be inhabited by bandits, monsters, or other things. this can all be done on non-loaded cities, merely through how the simulation state machine works, when it’s not actively doing something useful it can simulate the state of cities further out.

Essentially this allows me to solve the issue of a player hanging around an area plagued by widespread famine and then walk into an area that’s sprawling with life just a couple chunks away, instead this system allows me to keep a vast array of important events that can be super-simulated as the player approaches and determine the state of the area long before it’s within player view. in short, a sophisticated economic and environmental simulation, and I still haven’t figured out how to simulate water yet… and somehow this simulation depends on water simulation as that influences famine and drought. Did I mention that I specialize in framework code and not necessarily interactive code?

This framework does of course still need to be called and actively running, currently it’s some empty classes, some semi-built classes and a bit of pseudo code to serve as a reminder, but the actual important details are already blocked out. I can imagine this game being a huge failure because people will invariably find it far too complex, especially when they end up crashing the economy 😛
But guess what?

I care not for the success of the game, nor how long it takes. I’m making a game I want to play.

The simulation is at a few levels, per region level (essentially country), city level, city block level (for things such as gang wars, police raids, fires etc), per building level, per individual level.
These levels base entirely on how far away the player is, any of these have some parameters stored and are super-simulated as the player gets within reasonable range. It’s all a beautifully intricate hack, as in it’s not a real simulation, it only appears to be at surface value but to be fair, it doesn’t need to be anything else. It needs to be interactive, seem like a living sprawling world, yet be able to run on modest systems.

For a true simulation you can only have two of those.
You can have a living sprawling world that runs on a modest system but good luck getting it interactive (if real simulation, that is) or you could have an interactive living and sprawling world but that shit won’t run on any consumer end system.
You could also have an interactive simulation that runs on modest systems but it’s not going to feature living, sprawling economies at a massive super-global scale.

Really though, the job of a video game designer is to craft an illusion that suspends disbelief, the model doesn’t have to accurately represent real life; it only has to seem like it actively represents real life. A beautifully intricate multi-layered illusion it is, but it is nonetheless an illusion. An illusion you cannot even see at this stage because the framework code isn’t done, the back-end isn’t done and the front-end is a bunch of disjointed voxels because simplex hurts my brain.

Essentially what I’m conveying is that I don’t understand prioritization, good software design (too much feature creep) or how to actually develop software in a way that doesn’t suck… except I do, I just apparently don’t consider such things while coding.
More importantly I just felt I had to ramble about something and this was the first thing at hand, it’s very likely that the paragraphs are entirely disjointed, I didn’t proof read it, only spell checked it and checked the grammar.
I err… suppose you enjoyed the read if you got this far, have a nice day or something; I’m going to do something else now.


Taking a break from simplex

so instead I worked on tweaking render performance, I wasn’t pushing acceptable framerates and the reason for why is of course that I was pushing almost 7,000 draw calls every frame.
Optimizing that down to 1 gave me these performance metrics:
10k tris (1 draw call) – 60 fps (vsync locked?) (before: 15 fps, 6,864 draw calls)
100k tris (10 draw calls) – 60 fps (before: sub 5 fps, 68,640 draw calls)
1M tris (100 draw calls)  – 60 fps (before: what a nice slideshow, could you perhaps move the frames a bit more often than onece a minute 686,400 draw calls)
5M tris (500 draw calls) – 60 FPS (before: never tried, closest was 3.14M tris @ pls kill me now FPS, 6,864,000 draw calls)

The drawback being that each chunk now takes 3.2 seconds to build instead of 50ms, this might not sound like an issue until you look at the fact that generating a 1km^3 (5,271,552 tris with the testing chunk spammed over and over) takes a bloody hour
oh well, you win some you lose some; at least this is in the realm of things I understand, things I can do math with, things I can plot on graphs, things I can optimize. (unlike simplex which just hurts my head and melts my brain)

another issue is that this slows down exponentially as chunks get larger, for 16^3 the time taken is 3.2 seconds.
for 32^3 it’s 5.34 minutes, orders of magnitude slower.
At least it also uses less memory as well.
I suppose you win some and you lose some, this took one huge weight off my shoulders and instead put another one on.

rant about simplex noise, incompetence and stuff.

2111111111111111221111111 … 1111122111111


That’s the output of the simplex noise I’m using… what does this mean? How does it work? Don’t ask me, I’m just as baffled. My scene generates with three block types visible (at least, since I use stone as the fallback material for non-grass/air blocks), the blocks I see in my scene are:
id 1: air
id 2: grass
id 3+: stone.
How is this when the simplex only generates values of 1 and 2? I take a plain integer as block id, that should reasonably cause it to only generate grass and air, given that this only contains id 1 and 2.
simplex is weird.

What happens if I clamp it to 1-32?

1614121110910101091011 … 51413121214

The chunk generated however does not have any similarity to the screenshot at all, reasonably one would expect more than an empty shell, no?


this thing is hollow btw, in case you’re wondering.

How am I printing these numbers?
std::ofstream f;
f.open(“Chunk_plaintext.txt”, std::ios::out | std::ios::ate | std::ios::app);

are they floating point? sure, we could print them as float but my blocks have index values and I have no useful way to cast them to int that doesn’t have data loss, this would be an issue with 2D simplex as well though, given that you have to put a roundoff point somewhere to get a sample at every pixel and a pixel can’t have a floating point value,
what happens if we multiply the float by 100, divide that result by 2 and then cast to int?
I don’t know, let’s try.

2 1.83933 1.73532 1.66185 1.60199 1.56883 1.59679 1.64369 1.59767 1.53981 1.5873 1.64683 1.67224 1.74292 1.79105 1.80853 2.19107 2.05502 1.92196 1.82605 1.7717 1.72561 … 1.80914 1.76124 1.75255 1.84197

This is the raw noise, added some space padding code, still don’t see how this (when implicitly cast to int, which truncates it) would generate three different blocks when it would only truncate to 1’s and 2’s, that only covers 2 block id’s.
I am confused, I don’t understand why this black magic doesn’t work as expected and I don’t even know where to begin looking.
I’d wager I’m just incompetent, maybe I should just quit; given that I can’t even get simplex noise to work right.

All examples truncated for brevity, I’d wager no one wants to read 2 lists of 4096 integers and one list of 4096 floating point values.

[insert witty title here]

Really more of a screenshot dump than a real post with a lot of text content.
That’s some fine programmer art right there, I got the noise function working (this being a 32^3 chunk of the world just ripped out and displayed on its own, the triangle count is ludicrous because I haven’t implemented greedy meshing yet (because I haven’t implemented texture atlas loading or shader parsing yet, both of which are required to do greedy meshing and more importantly texturing said meshes)

interestingly the scaled octave noise is not significantly slower than raw noise (I expected it to be, but it was surprisingly insignificant compared to the rest of the chunk building), a potential optimization to that would be to generate the noise once per chunk and then just sample it once per block instead of generating samples on the fly per block, although it would spike memory usage and only slightly improve speed since this process is really rather prone to be optimized by the compiler and branch prediction would work very well on it since the algorithm runs thousands of times per chunk.

Anywho, there was something else I wanted to ramble about but I’ve since forgotten what that was merely through the process of writing this post so I’ll just dump this here, apologize for the lack of incoherency and then go to sleep.

… on that matter, I don’t know how featured images work… will it insert the image twice into the post since I already attached it? will it only show on the front page? I don’t know, but I will soon enough (by the time you’re reading this I’ll already know… so this paragraph is rather pointless), either way I won’t bother editing it if the results aren’t as expected.

EDIT: it did what I expected, well you’ll just have to deal with the same image showing up twice.

Chocolate is the new gravel

As usual I don’t really have anything to write about so therefore I should write random inchoerent things instead, but I don’t really have anything incoherent to write either so I’ll instead just post a code snippet from my project.

chunk::chunk(int p)
cPosition = p;
//I don’t remember why I’m multiplying by 5 but it works so I’m not touching it.
poteto = core::vector3df( fieldIndexX.at(cPosition)*5, fieldIndexY.at(cPosition)*5, fieldIndexZ.at(cPosition)*5 );
t1 = steady_clock::now();
b_blocks = new block**[CHUNKSIZE];
for(int8_t i = 0; i < CHUNKSIZE; i++)
b_blocks[i] = new block*[CHUNKSIZE];
for(int8_t j = 0; j < CHUNKSIZE; j++)
b_blocks[i][j] = new block[CHUNKSIZE];
BlockType BT_T = BT_NULL;
int tst;
for(int x = 1; x < CHUNKSIZE-1; x++)
for(int y = 1; y < CHUNKSIZE-1; y++)
for(int z = 1; z < CHUNKSIZE-1; z++) { //loBound, hiBound, algo (0-3), octaves, persistence, x, y, z, scale b_blocks[x][y][z].setBlock(tGen->chunkGen(0.0f, 2.0f, 2, 6.0f, 10.0f, x, y, z, 1.0f));
// 0.0f, 2.0f, 2, 6.0f, 10.0f, x, y, z, 1.0f yields very weird straight pillars of solid matter with large airgaps.
t2 = steady_clock::now();
time_span = duration_cast<duration>(t2 – t1)*1000;
std::cout << “Time: ” << time_span.count() << “ms” << std::endl;

Whoever can tell me what that code does get’s a free letter ‘a’, mind I already know so no cheating 😉
oooh and that’s actually pretty incoherent and somewhat unprovoked so mission success?

Anyway, back to figuring out how to modulate simplex into something useful, infinite vertical columns is rather useless.
perhaps I should be using scaled octave noise instead of scaled raw noise… or maybe just octave noise? Anywho, here’s a screenshot.