Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (775)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Drawing a Minimap  (Read 2880 times)
0 Members and 1 Guest are viewing this topic.
Offline Gibbo3771

JGO Kernel


Medals: 128
Projects: 5
Exp: 1 year


Currently inactive on forums :(


« Posted 2015-02-25 18:57:27 »

Heads-up - This is a C# game using XNA for a college project, hence the subforum

tl'dr at bottom

So I am having a little trouble at the moment with my minimap, not so much it working but it causing frame rate issues. The issues with the frame rate is already apparent as we are rendering everything at once.

We have a tile system for our map and the size starts at 160x90 tiles, with 2 layers so that is 28,800 tiles being rendered. Like I have said, it's not optimized yet and culling and chunk system will be added with the next update.

Now if I go onto the medium map, which is 320x180 (115,200 tiles) the frame rate drops. If I render the mini-map it REALLY drops.

The way the mini-map is created is simply give it a new camera and spritebatch, the camera is basically just a tiny little version of the world camera with the render holding all the same data.

This means the mini-map is rendering 115,200 tiles and the world is as well.

The whole "just use a small camera and render your map in it" approach seemed logical but I could see it going tits up when big maps are loaded.

Now I can see that if we culled and drew only the tiles visible inside the camera bounds, we would be rendering (with default zoom) 40x23 tiles which is only 920 tiles, which is fine. However that mini-map is still drawing a whopping 57,600 tiles.

What other way could I do this?

A few requirements for the mini-map:

  • Must show the whole map
  • Must show stationary entities (buildings, walls)

These 2 requirements literally throw the entire "just use a shader and color each pixel to that of the terrain type (grass green, blue water etc)".

What other methods can I do? Should I just forget those requirements and re-discuss the approach with the group?

tl;dr My mini-map lags my game as it is drawing everything over again, what do?

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline KevinWorkman

« JGO Plugged Duke »


Medals: 287
Projects: 12
Exp: 12 years


HappyCoding.io - Coding Tutorials!


« Reply #1 - Posted 2015-02-25 19:00:28 »

Why don't you just create another view?

Presumably, currently every tile Object contains an image to be drawn. You then draw that image twice- once at full size, and once at tiny size.

Why not have each tile Object contain another tiny image (or color) that you then draw to the minimap?

Alternatively: base the tiny image off of the full image, but cache the result instead of redrawing it every single frame.

HappyCoding.io - Coding Tutorials!
Happy Coding forum - Come say hello!
Offline Gibbo3771

JGO Kernel


Medals: 128
Projects: 5
Exp: 1 year


Currently inactive on forums :(


« Reply #2 - Posted 2015-02-25 19:06:30 »

Why don't you just create another view?

Do you mean another camera with a different projection? That is what I am already doing unless you mean something different.

Why not have each tile Object contain another tiny image (or color) that you then draw to the minimap?

I know the tiny image way would really increase performance but that means we start diluting the classes with extra data that imo, should not be necessary.

The color option is what I thought would be the next step but then I thought, it would look a bit weird having 1 pixel represent a building that takes up an entire cell and then a unit sitting next to it that also takes up an entire cell, then if we have a group of say 100 units all around each other it would populate the map to the point it looks a little eh, weird.

Alternatively: base the tiny image off of the full image, but cache the result instead of redrawing it every single frame.

Do you mean essentially take the pixel information of the finished batch call and store it somehow? I have no idea how to do that lol.

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Sabomoth

Junior Devvie


Medals: 4
Exp: 3 years



« Reply #3 - Posted 2015-02-25 19:08:06 »

Do you really have to draw everything on the minimap all the time? Will the terrain be changed often? Draw the terrain on an image, used that as background, on that add the rest of the stuff. Only draw a new image of the terrain when the terrain has changed.
Offline KevinWorkman

« JGO Plugged Duke »


Medals: 287
Projects: 12
Exp: 12 years


HappyCoding.io - Coding Tutorials!


« Reply #4 - Posted 2015-02-25 19:10:30 »

Do you mean another camera with a different projection? That is what I am already doing unless you mean something different.

No, that's not what I mean. I'm talking about creating your mini-map without using your full-sized images directly.

I know the tiny image way would really increase performance but that means we start diluting the classes with extra data that imo, should not be necessary.

I would argue that this data is necessary, but you don't really need to add anything new. Just cache the resized images used for the mini-map instead of recalculating them every frame.

Do you mean essentially take the pixel information of the finished batch call and store it somehow? I have no idea how to do that lol.

It doesn't really have to be that fancy. Just store the small images to be used by the mini-map. Whether you do them by hand ahead of time or try to calculate them when you load the full-sized image is up to you.

HappyCoding.io - Coding Tutorials!
Happy Coding forum - Come say hello!
Offline craftm

JGO Coder


Medals: 15
Projects: 1


_Keep Trying


« Reply #5 - Posted 2015-02-25 21:16:25 »

This is a old wiki for libGDX, but maybe can help you with some ideas:
https://code.google.com/p/libgdx-users/wiki/Minimap

Basically is a new camera with a new batch with small size. You draw only the objects you want (such as player, some maze walls) but not the same sprite, you draw pixel points/shapes or any texture to simulate the real size.

_ Wink
Offline lcass
« Reply #6 - Posted 2015-02-25 22:08:49 »

Why not temporarily store the data you have from your map rendering spritebatch and just shrink it instead of making a new camera. Or come up with some convoluted algorithm that determines which tiles will even be visible as pixels of course that means iterating through either 118000 tiles or performing width*height in pixels of the minimap converting each pixel into a world coordinate based upon the current position of the player and then specifically selecting the data from those tiles and binding it to a new sprite batcher which you then render on top of the current view . *BREATHES*
Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (41 views)
2018-11-16 13:46:03

hadezbladez (44 views)
2018-11-16 13:41:33

hadezbladez (25 views)
2018-11-16 13:35:35

hadezbladez (18 views)
2018-11-16 13:32:03

EgonOlsen (1894 views)
2018-06-10 19:43:48

EgonOlsen (1930 views)
2018-06-10 19:43:44

EgonOlsen (1285 views)
2018-06-10 19:43:20

DesertCoockie (1716 views)
2018-05-13 18:23:11

nelsongames (1404 views)
2018-04-24 18:15:36

nelsongames (2036 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!