Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Complex Map Generation & Rendering  (Read 2766 times)

0 Members and 1 Guest are viewing this topic.

SamuelMS

  • Newbie
  • *
  • Posts: 1
    • View Profile
Complex Map Generation & Rendering
« on: June 24, 2013, 07:15:33 pm »
Dear SFML gurus,

I only learned of your incredible library a few days ago, but I was so impressed by its feature list that I immediately began developing in it.

While I've been able to piece together a lot of elements from the documentation and the various posts across this board, I have a couple of questions that I haven't quite been able to resolve on my own. Since you guys know SFML inside and out, I figured the time to drop by these parts was nigh.

The first project I've set out to create is a fairly straightforward 2D space-based game, in which the player flies around a starship and impresses the locals. I'm currently at the world-building stage: I intend to generate a series of fairly complicated star maps for the player to traverse. These maps will be generated on the user's machine prior to gameplay (and then loaded from file each subsequent run), not pre-packaged into the game itself, and each map represents a given region of space.

For the sake of example, let us say each map is approximately 10000 square pixels, with its details (stars of various sizes and colors, nebulas, etc.) determined procedurally given one or more seed values. For the sake of added realism, let us also assume that parallax movement will be implemented, with each layer of detail (stars of various sizes, indicating distance; nebula layers) moving at unique speeds.

For proof of concept, I initially rendered these starmap details directly onto a single Renderwindow, which then could be navigated by moving a view. However, this method struck me as inefficient and limiting, as I'd have to update positions for thousands of elements every cycle. Instead, I thought I could render each layer to its own texture, which I could then "pan" at varying speeds as necessary.

Before I get started, though, I wanted to get some input from you folks, in case there's a better way of going about things. So, in summary, I need to generate several large layers of moderate complexity, which would then be rendered and moved as needed (likely in slices, for sake of memory).

What do you all think?

Thanks for your time and consideration.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11029
    • View Profile
    • development blog
    • Email
AW: Complex Map Generation & Rendering
« Reply #1 on: June 24, 2013, 09:03:36 pm »
You've only mentioned the documentation, have you also looked at the tutorials? Those are a great resource. ;)

Although you should be fine updating and rendering a few hundred objects each frane, you could also render everything onto a sf::RenderTexture, given the content is static.

But keep in mind that texture sizes have limits that vary from GPU to GPU. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Polyfructol

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Complex Map Generation & Rendering
« Reply #2 on: June 24, 2013, 09:32:25 pm »
A nice way to do that is by using a parent/child hierarchy Drawable. You can search for "node" or "scene graph" to find more about it. Here a nice example with code: http://en.sfml-dev.org/forums/index.php?topic=7487.msg49403#msg49403

So you'll just have to move your few layers in order to move everything contained inside.

raycrasher

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Complex Map Generation & Rendering
« Reply #3 on: July 08, 2013, 10:48:47 am »
Just use a parallax value for each game object, and use it to calculate that object's final transform to be passed in a RenderState.

Here's a snippet from a C# project of mine. Position and Zoom are camera position and zoom. xform is the transform adjusted for parallax. Multiply your object's world transform by it and you get your object's final transform, adjusted for both position and zoom parallax.

            Transform xform = Transform.Identity;
            float scaleFactor = 1/(1 + parallax*Zoom)*2;

            xform.Scale(scaleFactor, scaleFactor);
            xform.Translate(-Position*parallax);
 

« Last Edit: July 08, 2013, 10:57:47 am by raycrasher »