Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Could Codea handle something like Topia?

in General Posts: 972

I recently bought Topia on the App Store (Topia World Builder by Crescent Moon Games
https://appsto.re/us/99h2F.i).

My capsule review is don't bother getting it, you understand everything it can do in the first ten minutes, and it's fairly limited.

But it does simulate life and terrain and predators and prey, and a ton of them at that.

A while back people were experimenting with life simulations here, and I found that at any significant population size, Codea slowed way way down, apparently from having to calculate every organism's behavior every frame.

So it occurred to me to ask the experts--could Codea pull off something like Topia? And if so, how?

Comments

  • IgnatzIgnatz Mod
    Posts: 5,396

    To run a large number of processing intensive functions every frame, you want your coding language to be as fast as possible, and I don't think Codea is well suited for it.

    You would have to experiment to see how much you could manage to include, I think.

  • Posts: 972

    @Ignatz I understand that as a principle, but did you look at the app? I suppose I wondered if you might see it and instantly realize how they're doing it--and how Codea might do it too.

  • IgnatzIgnatz Mod
    Posts: 5,396

    The app description and pics didn't give a clear picture of the quality or detail of graphics

  • edited June 2016 Posts: 2,020

    I played with Topia a bit when it came out. It seems a bit harsh to say "don't bother downloading it", especially since it's free, I thought it was fun to play with, not a game as such.

    The worlds are quite small, and I don't remember them exactly being teeming with life. With any simulation, it's a question of to what extent do we want to model it, how much is "good enough" that the user doesn't notice the corners you've cut etc. AFAIR, the creatures seemed to follow a flock algorithm. Or, if you want to cut corners, you could just have them follow a noise-generated flow field. Have you read the free ebook, the Nature of Code ? @Ignatz first told me about it, it's awesome, required reading. Have a look at their flow fields and flock algorithms, here:

    http://natureofcode.com/book/chapter-6-autonomous-agents/

    On an iPad Air or newer I'm sure Codea could handle a few hundred flocking creatures without breaking a sweat.

    The planet itself is certainly possible with a shader and a couple of noise maps (one for height, one for moisture). Inspiration here:

    http://www.redblobgames.com/maps/terrain-from-noise/

  • edited June 2016 Posts: 2,020

    What would be super awesome is if you could make the noise maps for the terrain generation also drive the ai flow-fields, so that the creatures flowed around mountains and lakes. Would be a very cheap way of making the ai aware of its environment.

    On shader frog there's a very very nice seamless noise shader. So it creates a perlin noise image which can be tiled with itself, so you can wrap it around a sphere without there being any join.

    I'd start by generating two of those as textures (for height and moisture), applying them to the sphere, using the interaction between them to generate various biomes, have the ai do a texture lookup of each of them and then use it as a flow-field, with different animals preferring different biomes.

    easy-peasy B)

    EDIT: I meant biomes, not genomes

  • Posts: 972
    @yojimbo2000 that sounds very like the behavior of Topia, that might be exactly what they're doing.

    Not having read the book yet, by your post I get the impression that this flocking stuff is a way of calculating the movements of large groups of things without having to calculate each one individually. Is that right?

    Topia wasn't free when I bought it, I don't think (as far as I can see you can't tell what App Store prices are after you've bought the thing). I don't mean to be harsh, and I think they did a really nice job with it, and I have a lot of sympathy for developers and how hard it is to make things and how hard it is to sell them. That said, I got about five minutes of play out of it before it seemed to run out of surprises. So I'd feel irresponsible recommending it to someone wholeheartedly.

    But back to flocking: animals definitely flock in Topia, but individual animals also seem to hunt and kill other individual animals. Now that you bring it up I'm not sure if that's totally true, though. I've seen some animals do hunting behavior when near prey, and seen prey die when predators are hunting, but I can't say for sure I've seen one specific predator catch and kill one specific prey. So maybe all that could be done with flocking too.

    At any rate, you seem to definitely think it's something Codea could do. Only on a later model machine, though? Topia itself runs very well on my iPad 3.
  • Posts: 2,020

    Oh, maybe it's not free, my bad. Now that it just says "get", that could be because I had it before, not cos it's free. Fair enough then, I agree it's quite limited. It's interesting that they didn't try to gamify it.

  • IgnatzIgnatz Mod
    Posts: 5,396

    Flocking still requires individual processing for each animal, but in its original form, the flocking rules were extremely simple, making it easier to handle large numbers of objects.

    I would expect the developers have tried to do the same in Topia, including more complex rules for things like hunting only when necessary, and those may not slow the game down if they are only used for a few animals and only when the user is watching those animals. For situations where the user isn't watching, the game might just use a random number to decide if animals live or die. That's is what I would do, ie cheat wherever possible.

  • Posts: 196

    FYI, the terrain is actually a simple heightmap with a sphere distortion vertex shader. I used it a long time ago for this project before you could used meshes and shaders in codea : https://codea.io/talk/discussion/658/3d-rendering-on-codea/p1
    You should be able to find the formulae in there somewhere...

    Glenn Corpes, the dev and awesome guy, kindly shared the trick

  • Posts: 2,020

    @Xavier that's amazing, and incredible that you did that before Codea even had vec3s. Does that mean that the Codea mesh API accepts anything with an x, y, z component for the vertices normals arrays, not just a vec3?

  • Posts: 2,020

    @Xavier Regarding displacement maps in the vertex shader, although it's quite easy to put a height map into the vertex shader and displace the vertex positions in the shader, what I'd like to know is, how does one handle the normals resulting from that displacement in the vertex shader? A normal depends on the relationship between a given vertex and its neighbours, but, because a vertex shader can't access the neighbouring vertices, it seems like it would be a poor candidate for generating normals. For that reason, when I've done terrain, I've always generated the displacement height map and normals outside of the shader, and then passed them in as regular position/ normal attributes. If there is some ingenious way of calculating the normals in the vertex shader though, I'd love to hear about it.

  • Posts: 972

    Now that craft has a full planet-creation project baked in, I wonder if this is a huge step closer to being easy to do.

    I don’t fully understand what they all were talking about up there with the “making the flocking follow the noise maps”, but would that be doable with the craft worlds? How hard would it be? Do they have noise maps?

  • dave1707dave1707 Mod
    Posts: 9,109

    If you want noise maps, look at the documentation under Craft, all the way down to Noise.

  • Posts: 972

    I don’t want them, I’m asking if the existing craft project has them.

    The smart folks above theorized that they would be an easy way to have critters run around a planet.

  • dave1707dave1707 Mod
    Posts: 9,109

    @UberGoober If you’re referring to the Craft example Planet 3D, it uses several noise commands. I haven’t looked close enough at the code to see if they use it to create maps or not.

  • Posts: 972

    From @yojimbo2000 above:

    What would be super awesome is if you could make the noise maps for the terrain generation also drive the ai flow-fields, so that the creatures flowed around mountains and lakes. Would be a very cheap way of making the ai aware of its environment. ....I'd start by generating two of those as textures (for height and moisture), applying them to the sphere, using the interaction between them to generate various biomes, have the ai do a texture lookup of each of them and then use it as a flow-field, with different animals preferring different biomes.

    easy-peasy B)

    I feel like I understand maybe 10% of that, namely most of the prepositions. But he says it’s easy, so I wonder how hard it would be to learn.

Sign In or Register to comment.