Mythruna

Development => Blog => Topic started by: pspeed on April 24, 2012, 12:55:35 PM



Title: Rotation...
Post by: pspeed on April 24, 2012, 12:55:35 PM
Things have been a little quiet around here lately so I decided to do a slightly more technical blog post on what has been going on in Mythruna development.

Many of you have seen the sun pictures but really that was just a fun side-track to avoid some different, more tedious, coding.  The sun thing started out as a player insistence to "fix it" and my goofing around with the light scattering filter that jMonkeyEngine includes be default.  I got light scattering to look kind of neat from certain views but a) it was expensive and b) there was no good way to determine when to turn it off.  If you were deep in a mine and looked up toward where the sun should be then you still got this weird scattering effect.  Still, after turning it back off again, the plain yellow circle sun looked pretty boring.  So I fixed that a different way.

The real project that I've been working on since well before the last release was "autogenerated buildings".

Prior to the 0417 release, I spent some time writing the "block pack" API and converting many of the existing block types over to block scripts.  All of the new block shapes are done in block-script.  Many of the old groups have been completely converted (like Stone) or partially converted (like Wood).  In some future release, this block script support will be exposed more formally as pluggable block packs.  (A user could add new block types right now but the game has no good way to deconflict block type IDs when new versions of the game come out so it would mess up your worlds.)

I thought this change was going to be necessary to do what I really wanted to do: which was have an easy way to determine when one block is the rotation or reflection of another block.  Turns out that it mostly wasn't but it was still a useful conversion... especially since it let me quickly add over 100 new block types for the last release.

Last night, after much tedious coding, I got the block transformation thing working as far as I've tested.  This means that if I have a stone ramp that rises to the north, I know which blocks would be a 90 degree rotation, which blocks would be a "mirror" of it in the x or y plane, which a 180 degree rotation, etc..  This is not necessarily as simple as it sounds because the block types themselves have no idea.  Furthermore, a stone ramp is symmetrical along one axis... so a mirroing along one axis is the same ramp but a mirroring on the other is a 180 degree rotation.  The corners and pillars are not symmetrical at all so a mirroring is a 90 degree rotation right or left (depending on axis).

This sort of transformation is important for generated buildings because it lets me break building templates into sections and reuse the sections in various ways.  I can rotate and mirror whole assemblies of blocks.  This allows me to take one building corner and flip it or rotate it to use as another building corner, and so on.

Mirroring was necessary because some building sections will have a definite front and side.  So while it might be ok to use the left side of a peaked roof as the right side... it wouldn't look right rotated.  Where as some sections or corners could be freely rotated without issue.

There is still a LOT of work to do before I have real generated buildings... and even more to do for generated towns and cities... but the rest of the work is slightly more fun.  Things like creating building parts and testing them out in different building templates is a more creative process and even the mistakes are sometimes fun to explore.

If anything cool comes out of it over the next week or two then I will post pics.


Title: Re: Rotation...
Post by: ayoriceball on April 24, 2012, 03:16:42 PM
 8)

You make it sound so easy :P


Title: Re: Rotation...
Post by: pspeed on April 24, 2012, 03:36:41 PM
Last night to test I was using a building corner template I made... a first floor of a kitchen with a chimney.  When I had rotation working, I put four corners together to make one really odd looking house:

(http://i.imgur.com/Odtxl.jpg)

When the full templating is working, there will be routines to figure out how the second floor gets merged with the first that will leave that tall chimney intact.

It is a little surreal to walk around inside that, though.  Round the corner, there's a fireplace.  Round the corner, hey, deja vu, another fireplace... and on and on.


Title: Re: Rotation...
Post by: FutureB on April 24, 2012, 04:43:27 PM
hehe looking good paul :]


Title: Re: Rotation...
Post by: Moonkey on April 25, 2012, 07:26:31 AM
Knowing that you are still working hard gives hope to all that you are not slipping away from coding. Hehe


Title: Re: Rotation...
Post by: pspeed on April 28, 2012, 06:09:12 PM
Making a little progress on the "random buildings" stuff...  This may actually work. :)

Here are three dumbly random buildings using only two different building parts.
(http://i.imgur.com/RoXC2.jpg)

Even with just two parts, rotated and mirrored, with random (and stupid) part selection, it generates some interesting floor plans.

I have about 15 sample parts total for first floor, second floor, and roofs layouts that I will use as I continue.  I'm pretty optimistic right now just based on how well that two-part test turned out.

Still lots of work to do and some rules to put in place, etc. but it's kind of a promising start so far.


Title: Re: Rotation...
Post by: FutureB on April 28, 2012, 08:35:37 PM
i see some good develpoment happening :] keep working on the random generation :]


Title: Re: Rotation...
Post by: Ghelmaron on April 29, 2012, 12:07:03 AM
Looking good so far.


Title: Re: Rotation...
Post by: pspeed on April 29, 2012, 12:30:28 AM
Some more goodies.  The generation is still operating completely random... so it frequently makes buildings without doors and stairs... and I only have a small handful of random sections, only one roof style, etc... and still:

(http://i.imgur.com/SmVyE.jpg)
(http://i.imgur.com/LVkkr.jpg)
(http://i.imgur.com/oeiNf.jpg)

It inspires me to make more parts.  Maybe I'll take a pic of the separate parts that are randomized to make those just to show you have few of them there are.  And each new part adds a lot of variation because it can be used in a few different ways, rotated, flipped, etc.


Title: Re: Rotation...
Post by: FutureB on April 29, 2012, 12:36:15 AM
i cannot comprehend how you make those randomly generated XD


Title: Re: Rotation...
Post by: pspeed on April 29, 2012, 12:46:55 AM
i cannot comprehend how you make those randomly generated XD

Part of me would like to leave it magic but my plan is that modders end up making their own building templates and I've designed the whole system around that.  So I will open the kimono a little.

This is a simple building template that is put together from just four corners (other template types will have other configurations but this is simple).  It expects the pieces to be a certain size and as long as the follow certain conventions, they will generally fit together well.

These buildings are generated by making a first level randomly choosing from one of five corner pieces that look like this, front side:
(http://i.imgur.com/guvXI.jpg)

Back side:
(http://i.imgur.com/sNfAc.jpg)

In general, the lower level requires the most parts because it must have at least one door tile and at least one stairs tile.  Also, this is more likely where you have special parts like the kitchen (far left in the from the back pic).

Contrast that to the second floor which only has these three different tiles:
(http://i.imgur.com/n12Yn.jpg)

It will need more to have more complicate internal rooms but this works for now... especially since the algorithm is still stupid about how it joins up doors.

And finally, there are only two different roof pieces and that's only because the insides are different:
(http://i.imgur.com/IykSm.jpg)

The neat thing is that I just make these in the blueprints editor and export them using a special admin tool.  So then I can incorporate the raw blueprints into my building templates as part of the random sections.


Title: Re: Rotation...
Post by: pspeed on April 29, 2012, 12:48:35 AM
Also, while I only generated two levels and a roof these tiles would have supported generating one level on up to however many.  I may randomize the floor count next just to play.


Title: Re: Rotation...
Post by: pspeed on April 29, 2012, 12:50:00 AM
Also note: all of these buildings are oriented the same way, basically, just for testing.  They can be freely rotated to any one of the 90 degree variations.


Title: Re: Rotation...
Post by: pspeed on April 29, 2012, 01:00:07 AM
Exact same parts except this time I randomize the number of floors.
(http://i.imgur.com/Avoug.jpg)

It could randomly go one more level up but it just didn't happen in this particular set.

And because there are no second floor stair sections yet, it is guaranteed to be impossible to get to the upper levels without building some by hand.  Still it's neat.


Title: Re: Rotation...
Post by: FutureB on April 29, 2012, 01:20:19 AM
i still dont understand :P hehehe but i like how theres those difernt types of corner bits which all match up


Title: Re: Rotation...
Post by: pspeed on April 29, 2012, 01:36:59 AM
i still dont understand :P hehehe but i like how theres those difernt types of corner bits which all match up

I bet eventually you will make some of your own templates/sections. :)


Title: Re: Rotation...
Post by: pspeed on April 29, 2012, 01:47:16 AM
Put this up on facebook but I'll include it here too... I finally got a four story building to generate (the max height I have specified for this template):

(http://i.imgur.com/cJOhe.jpg)


Title: Re: Rotation...
Post by: FutureB on April 29, 2012, 02:30:56 AM
the chimney failed :P


Title: Re: Rotation...
Post by: Ghelmaron on April 29, 2012, 01:08:09 PM
When the buildings are placed into the world, what will happen to the terrain around the house? I mean, could you end up with a house that half sticks out over a ravine, or a 3 story house in which the first 2 floors are completed surrounded by dirt? Or will the house have a foundation of sorts as well?

Overall it is using a modular system, in which sections of the house are randomly selected from premade rooms. Once you can confirm that each section is somehow compatible with each other section, it should work flawlessly. The houses you have shown look good so far too because variety is what makes map building more realistic.  :)


Title: Re: Rotation...
Post by: pspeed on April 29, 2012, 01:42:01 PM
When the buildings are placed into the world, what will happen to the terrain around the house? I mean, could you end up with a house that half sticks out over a ravine, or a 3 story house in which the first 2 floors are completed surrounded by dirt? Or will the house have a foundation of sorts as well?

Yeah, when the "tiles" are put together for real they will have a leveling strategy.  So, for example, in the case of these buildings it will pick a level that doesn't submerge the building more than two blocks deep for where it wants to be placed (and with the doorway level to street at least).  It will then fill in the terrain with stacked rock (it's up to the template how this will be done) up to a certain point and cap that off with stone beyond a certain depth.  So if the building is placed on a cliffside the "sticking out" part will end up with a stone shelf sticking out of the cliff side with stacked rock a few layers deep.  Eventually I also want to have leveling templates set up to have cooler or more complicated looking supports in such cases.  So maybe it's not just a big stone shelf but some graceful sloped beams or whatever.

Overall it is using a modular system, in which sections of the house are randomly selected from premade rooms. Once you can confirm that each section is somehow compatible with each other section, it should work flawlessly. The houses you have shown look good so far too because variety is what makes map building more realistic.  :)

Yep.  And the benefit of this system is that you can make templates that are as specific or as random as you want.  So if you are some modder writing your own adventure and you need a house of a certain configuration then you can plan it out specifically or even add custom sections just for that house.  Or maybe only the first floor has to be specific so you let the rest generate.

The sky's the limit, really.