Free is Good

It was coffee Monday today but everyone else in the group was either away overseas, or sick, so it was coffee for two this morning. Since our last coffees were not so great we got free coffees today (yeehaw). The weather was also pretty nice today so we walked into town and went to a fee different places doing chores, it was nice πŸ™‚

This afternoon I worked on the cave generation code. I added a grow function which scales the caves up and a corresponding shrink function that scales caves down. My only concern right now is the amount of processing that takes place to create a cave. Currently the following operations take place..

  • Create an empty 2d plane.
  • Fill plane randomly with ones (solid cells).
  • Create a solid border around the edges of the pane.
  • Smooth the plane (multiple times) to create the basic cave structure.
  • Determine isolated regions and discard (fill) regions below a certain size.
  • Sort regions from largest to smallest.
  • Create edge tiles (x, y pairs) for each region.
  • Determine closest tiles between largest region and all other regions.
  • Create tunnels between largest and all other regions.
  • Calculate a new region that encompasses all regions (plus tunnels).
  • Create edge tiles for the new region.
  • Clear the plane and repopulate it with the new edges.

That’s as far as I have got so far. Next up is to cleanup the edges so they will remap without isolated tiles. Then the plane needs to be remapped for presentation as a tilemap. Decoration and population will come after that and those two last parts are quite big things to make work I think.

So it seems that the simple task of procedural cave generation is really not that simple. Once I have this working however I’ll probably get back to inventory code because I’ve been thinking about that a lot. Of course there’s still my book that’s gathering virtual dust in My Documents.

Advertisements

Bugz Abound

Today I was browsing the GitHub repo for the cave generation tutorials I have been watching on YouTube. After poking about for a bit it seems that there are issues with some regions that do not get joined. This issue was raised over a year ago and there has been no comment by the author or even a fix. Damn I love the internet *NOT*. If there is a possible bug that will create cave systems with isolated regions.. this just won’t do for production. With this in mind I have had to come up with another solution.

One thing that I noticed once I started thinking about the problem was that the guys algorithms use some serious brute force to calculate stuff like calculating distances between cave regions. In the original algorithm you check every edge tile of a room against every edge tile of EVERY other room to determine which edge tiles are the closest. This is great when you have unlimited processing power but on an average mobile device this will just not perform well (if at all).

My solution was rather simple. When creating the edge tiles I made a counter that counts from 1 to 4 and then resets to 1 again. Whenever the counter equals 4 I then store an edge tile so immediately when calculating distances between cave regions, there are 75% less tiles to check for each room, a GIGANTIC CPU saving measure. You can’t even notice the loss of fidelity and I’ll experiment with larger values tomorrow.

Then came the complicated algorithm to join up all of the cave regions. After many hours of messing about I decided to just determine which is the largest region, calculate the nearest tiles to every other region (from the main region) and then make tunnels between those points. This super simple method has again saved HUGE CPU time and the results are really pretty fantastic. One feature of this method is that on some maps the tunnels drill through other areas which isn’t overly desired but adds extra connectivity so it’s all good.

Check out this image. On the left you can see the sparseness of edge tiles compared with last evenings screenshot. On the right is the final cave system, all ready to be remapped, decorated, and populated with monsters and treasure!

cavegen_12_8_2018

This has been great learning for me and a good reminder that when looking at code written by some random internet inhabitant.. don’t expect it to work without falling apart! Always investigate thoroughly πŸ™‚

To end with this evening, let’s think about religion…

#atheism

Houston.. we have a problem

Well after all of my boasting last evening, my cave code isn’t working quite as it should. I now have all rooms being connected but some rooms are not being connected to their nearest neighbors as you can see in the following image..

cavegen_11_8_2018

I’ve gone over the videos several times but it looks like I have everything correct. I’m really beginning to understand how it all works now and I think I might fix it with some of my own code tomorrow πŸ˜‰

That’s it for today folks, we are off to watch a movie πŸ™‚

C# > Lua – No Problem!

It was a truly fantastic day here in Hawkes Bay New Zealand (for winter)! We went for a wee bicycle ride over to Havelock North this morning and purchased some items for a ‘Platter Dinner’. Yep, dinner this evening was a platter of nice food and a bottle of fine Chardonnay. My tummy feels a bit ‘eughhh’ right now because it is a very rich meal and we really need to make these things a little less piggy (but retaining the entire bottle of wine heheh);)

Besides this I watched a bunch of video tutorials on youtube.. Procedural Cave Generation in Unity by Sebastian Lague (check it out) and wow! These are very cool. All of my interesting questions about procedural generated caves are answered in these cool tutorials. I was really in the zone today and as I watched and listened to him explaining the issues and laying out his C# code, I coded along in ZeroBrane Studio (All hail ZeroBrane Studio!!!) and vomited out equivalent Lua code. I was very impressed that I could just type Lua as he typed C#!!

I got up to episode 6 and currently the code is very good, generating caves and identifying all separated regions which was what I was having trouble with for the last couple of days.

This makes me look about and there is just SO MUCH DAMN MATERIAL AVAILABLE FOR UNITY!!!! I’m seriously considering dumping Gideros in the not too distant future because the maintainers just won’t work on the important stuff like tutorials and documentation, or really.. even listen to what people actually need. A decent tutorial on how to make plugins? Nahhh.. let’s just ignore that and do a Monty Pyton like ‘And now for something completely different’! Oh well, we shall see how it all pans out. As it transpires I seem to understand C# without much trouble and Unity has some funky as auto code completion and syntax checking so the temptation is there. The other interesting thing about Unity is that it is GIANT and there are actually a lot of people willing to PAY YOU TO PROGRAM THEIR SHIT IDEAS πŸ˜€

Still.. I do so love LUA!!!!

For now however I just rediscovered (for the millionth time) how much I enjoy destroying my eardrums with ultra loud music. This evening I’m spazzing out to a load of chip tunes by various artists because chip tunes have to be one of the best genre of music ever.. apart from thrash metal πŸ˜‰

For the last couple of days I have been giving thought to how my ARPG will be presented. Since I really love the Diablo franchise (only 1 and 2 though.. 3 is goat puke and the sole reason why I will never give Blizzard another cent!) and Path of Exile. I want to mix the two games using mechanics from both (but mainly Path of Exile) and package it all up into a 2 dimensional pixel art extravaganza! Sounds pretty fancy eh? I also don’t want to over extend myself so whilst I have a whole load of advanced stuff I would like to implement in the future, I thought that the initial offering would be set in a giant game world but only a very small part of it would be initially available, namely a dungeon consisting of a set number of levels like Diablo1 and then I thought ‘why not just make it totally procedural generated and it can be an unlimited dungeon.. I certainly have the know how to make such games, so why not?! This way a free version could contain the first x number of levels and if you liked the game you could buy the full version to explore deeper πŸ™‚

Hows this for spooky… This morning I went to reddit/r/pathofexile and they announced their next league, Delve.. an endless procedural generated dungeon! hrmphhh, I feel thoroughly robbed πŸ˜€

This won’t deter me though, if they are heading in this direction it’s only a positive indicator that my feeble brain (that peanut rattling about in my empty wine barrel) is on thw right wavelength. In fact with each passing day I’m feeling more and more like this game will have a market because I have really searched far and wide and cannot find a 2d ARPG like Diablo2 or Path of Exile for Android, and.. I see so many people asking where they can find such a game. It truly amazes me that it might not have been created yet! Now, I just need to find a f**king artist!!!

Finally I apologize that this post is so large. I’m a bit like the Incredible Hulk, the more angry he gets, the stronger he gets.. except.. the more I drink.. the more I type πŸ˜‰

where there’s a will…

Today we went up town and signed went over the sale and purchase agreement for our house purchase. The lawyer said it all looked good so now we wait until September 11th when we settle and the house becomes ours. It just so happens that September 11th is also my birthday, aww, a house for my birthday present? πŸ˜€

We also checked and signed off on our wills because you know.. we are all going to croak at some stage right? I do have fond ideas of my consciousness being transferred into an immortal robotΒ  so I could spend eternity exploring the universe, but that’s another story πŸ˜‰

I sanded and painted my new computer monitor shelve thingies today and they look not too bad. There are a few little lumpy bits that need a quick buff because I was using the paint at the bottom of the can. It will take a few days to harden and then I’ll give my office a much needed cleanup and install the new shelves.

I also found some code today that will resolve my issues with region discovery in my procedural generated cave maps. The code of course uses a lot of stuff that I don’t need and it has different data structures. There is however enough for me to either modify or base my own version on. Looking forward to getting that completed and then hmm, maybe writing some more in my book πŸ˜‰

Stayin busy

Today was quite busy. I finished up the bathroom windows so they are finally finished! I need to start on the walls soon.. at least the walls that can be done. We are thinking early next year we will get the bathroom renovated and two walls will be modified so there’s no point painting them now. The ceiling will stay pretty much the same and that needs a good sand and a few coats of paint applied. I guess I’m the guy to get that done πŸ˜‰

In the lounge there was one length of skirting board (326mm wide) that was missing and there was just a hole into the framing of the wall (hehe). This was leftover from our kitchen renovation so today I repaired that. It was kind of tricky because the profile of the wood was very old style, 20mmx 160mm with a beveled top edge. Since this is nearly impossible to get (and expensive!) I made my own one using two smaller bits of wood and used my trusty plane to make the bevel. Once I get it painted you won’t even notice it’s not an original πŸ™‚

I did a bunch of weeding outside today as well and it was good to be in the fresh air, even if it wasn’t the nicest day.

I also made a new monitor stand for my computer desk. The current one is functional but it is made from grotty old plywood and some warped rough sawn timber that I had lying about. I have been looking at it for some time and thinking that it really has to go.. so it’s going! The new one is made from some spare 6mm MDF board and some nicely milled timber that I had lying under the house. I’ve constructed it and filled all the nail holes and drilled out cable holes in the back of each of the four compartments at the bottom. This is looking to be one of the best quality things I have constructed, I’m actually getting better at this! Tomorrow I’ll paint it up, gloss white I think πŸ˜‰

I also wasted a bunch of time trying to make a new cave generator class. The current class works and makes nice caves, but.. it makes isolated parts which is no good (what if the player is in an isolated part and the exit is in another part? uh oh!). I buggered about for hours and about ten minutes ago I found two typos where I calculate an x and y position that was causing the whole thing to not work for the entire day! ARGHHHH! So it still does not work (FFS) but I’m making progress πŸ™‚

And I have been reading a bunch of articles on procedural generation of caves and what not and found an article that describes a method of determining all regions in a cave system where there are isolated parts, yay!Β  I’ll have to try and make that happen because I do like the original cave generator better than the new one. Maybe I’ll just keep both? Maybe πŸ˜€

Shoulda Woulda

I should have been working on my book today but I did other things πŸ˜€

I began putting the finishing touches on the bathroom windows, removing the tape from the glass and touching up little things. I fully attached the hardware (previously it was screwed loosely to the windows) and tomorrow I’ll have that all finished. Things have been delayed in the bathroom because of rain but it was not too bad today and the next few days will be not sunny but at the same time, not raining.

I did a boatload of coding today also πŸ˜‰

Every map in my ARPG will be represented on a 2 dimensional grid and some maps will have multiple layers. With this in mind I have created a generic buffer class which manages multi layered 2 dimensional arrays. Layers can have rectangles drawn into them (filled and outlined), lines drawn into them, be randomized (filling a random percentage with solid cells) and also smoothed using a cellular automata algorithm which creates rather nice caves. It’s a pretty good class πŸ™‚

Currently I an thinking to move the cave generation code to another separate class which would make things tidier when it is used with other generation techniques. First I need to get the caves generating with all areas connected.