Oh God so many tiles!
Moderator: PC Supremacists
- spirit bomb!
- Chaos Rift Newbie
- Posts: 17
- Joined: Wed Jan 06, 2010 11:28 pm
Oh God so many tiles!
This is a subject that I believe many people on these forums have experience with...
Suppose I have a tile based game. And suppose the character can move, but he really stays in the same spot on the screen, as the entire world moves in the opposite direction he is running in (Kinda like the space ship in FUTURAMA). So the problem is... I am keeping track of every single tile, on and off screen. Every time the character moves, the (x,y) of every single tile needs to be adjusted. This is eating my frame-rate ferociously, because of the ridiculous amount of processes involved. Has anyone experienced this problem, or have any good solution?
Possible Solutions???
-Smaller World.
-Make every layer into one single bitmap. <- wouldn't have any idea how to implement this b.s. but it would be cool
Any halp is awesome, and well appriciated.
Suppose I have a tile based game. And suppose the character can move, but he really stays in the same spot on the screen, as the entire world moves in the opposite direction he is running in (Kinda like the space ship in FUTURAMA). So the problem is... I am keeping track of every single tile, on and off screen. Every time the character moves, the (x,y) of every single tile needs to be adjusted. This is eating my frame-rate ferociously, because of the ridiculous amount of processes involved. Has anyone experienced this problem, or have any good solution?
Possible Solutions???
-Smaller World.
-Make every layer into one single bitmap. <- wouldn't have any idea how to implement this b.s. but it would be cool
Any halp is awesome, and well appriciated.
circular reasoning works because circular reasoning works because circular reasoning works because circular reasoning works because
circular reasoning works because circular reasoning works because circular reasoning works because circular reasoning works because
circular reasoning works because circular reasoning works because circular reasoning works because circular reasoning works because
-
- Chaos Rift Demigod
- Posts: 991
- Joined: Thu Nov 13, 2008 3:16 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Amiga, PSOne, NDS
- Programming Language of Choice: C++
- Location: Sweden
Re: Oh God so many tiles!
I think a possible solution would be to have an offset for your tilemap, something like this.
And then when you render your tiles you just add them to the X and Y parameters of your draw function. Hope it works out.
Code: Select all
int tmOffsetX;
int tmOffsetY;
Re: Oh God so many tiles!
and if your tiles aren't on screen, don't draw them :D
Re: Oh God so many tiles!
The other calculations barely cost anything compared to the cost of rendering. Always try and draw as little as possible.if your tiles aren't on screen, don't draw them :D
If you want to get crazy with optimisation you could consider grouping the tiles in a quad-tree like fashion.
- cypher1554R
- Chaos Rift Demigod
- Posts: 1124
- Joined: Sun Jun 22, 2008 5:06 pm
Re: Oh God so many tiles!
Also, instead of doing user defined per frame calculations for every tile, just move the moving sprite and follow it with camera (change view matrix accordingly).
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Oh God so many tiles!
What? Dude, when a scene is rendered, hundreds to thousands of render calls are made. The only difference between a scrolling tile game and nonscrolling is an integer offset. The calculation amounts to a simple difference in the x and y. So that's two subtractions per render call...spirit bomb! wrote:This is a subject that I believe many people on these forums have experience with...
Suppose I have a tile based game. And suppose the character can move, but he really stays in the same spot on the screen, as the entire world moves in the opposite direction he is running in (Kinda like the space ship in FUTURAMA). So the problem is... I am keeping track of every single tile, on and off screen. Every time the character moves, the (x,y) of every single tile needs to be adjusted. This is eating my frame-rate ferociously, because of the ridiculous amount of processes involved. Has anyone experienced this problem, or have any good solution?
Possible Solutions???
-Smaller World.
-Make every layer into one single bitmap. <- wouldn't have any idea how to implement this b.s. but it would be cool
Any halp is awesome, and well appriciated.
It sounds to me like your bottleneck is RENDERING not CALCULATING. If you are RENDERING a million tiles that aren't even on the screen (especially with SDL or software rendering) then yeah--shit can get hella slow. I'm sure that you're rendering your tiles with something like:
Code: Select all
for(y = 0; y < map_height; ++y)
for(int x = 0; x < map_width; ++x)
DrawSprite(map[y][x]);
Re: Oh God so many tiles!
so basically what falco is saying is, make it so if your tile's x < 0 && y < 0, or x > screenwidth && y > screenheight, don't draw the tile :D
- mv2112
- Chaos Rift Junior
- Posts: 240
- Joined: Sat Feb 20, 2010 4:15 am
- Current Project: Java Tower Defence Game
- Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
- Programming Language of Choice: C/++, Java
- Location: /usr/home/mv2112
- Contact:
Re: Oh God so many tiles!
I draw all the tiles under the character onto a bitmap and only manually render tiles above the player, and i only blit a clip of the map bitmap to the screen. I also use a camera that tells the engine where to clip the map so i don't render the whole thing.
Re: Oh God so many tiles!
yet he manually called a destructor...
- mv2112
- Chaos Rift Junior
- Posts: 240
- Joined: Sat Feb 20, 2010 4:15 am
- Current Project: Java Tower Defence Game
- Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
- Programming Language of Choice: C/++, Java
- Location: /usr/home/mv2112
- Contact:
Re: Oh God so many tiles!
Why the hell is it such bad practice to call destructors? Who says it is bad practice? Why does it matter?eatcomics wrote:yet he manually called a destructor...
Ahh, i feel better now...
Re: Oh God so many tiles!
Erm, I'd say Bjarne Stroustrup would say so...mv2112 wrote:Why the hell is it such bad practice to call destructors? Who says it is bad practice? Why does it matter?eatcomics wrote:yet he manually called a destructor...
Ahh, i feel better now...
Destructors are automatically called. So when you manually call it, it will actually be called twice most likely. So let's say you had this:
Code: Select all
SomeDestructorExample::~SomeDestructorExample()
{
delete pSomeDynamicallyAllocatedMemory;
}
That's probably why it's a bad practice... It's also just plain out unnecessary...
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: Oh God so many tiles!
Not if you have good coding habits.XianForce wrote: Destructors are automatically called. So when you manually call it, it will actually be called twice most likely. So let's say you had this:
And later the destructor is also automatically called... Then you run into things like segfaults and access violations...Code: Select all
SomeDestructorExample::~SomeDestructorExample() { delete pSomeDynamicallyAllocatedMemory; }
Code: Select all
SomeDestructorExample::~SomeDestructorExample()
{
delete pSomeDynamicallyAllocatedMemory;
pSomeDynamicallyAllocatedMemory = NULL;
}
This.XianForce wrote: It's also just plain out unnecessary...
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: Oh God so many tiles!
It would have to be more like this:dandymcgee wrote:Not if you have good coding habits.Code: Select all
SomeDestructorExample::~SomeDestructorExample() { delete pSomeDynamicallyAllocatedMemory; pSomeDynamicallyAllocatedMemory = NULL; }
Code: Select all
SomeDestructorExample::~SomeDestructorExample()
{
if(pSomeDynamicallyAllocatedMemory) {
delete pSomeDynamicallyAllocatedMemory;
pSomeDynamicallyAllocatedMemory = NULL;
}
}
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: Oh God so many tiles!
Actually, that's redundant.Ginto8 wrote:It would have to be more like this:dandymcgee wrote:Not if you have good coding habits.Code: Select all
SomeDestructorExample::~SomeDestructorExample() { delete pSomeDynamicallyAllocatedMemory; pSomeDynamicallyAllocatedMemory = NULL; }
Code: Select all
SomeDestructorExample::~SomeDestructorExample() { if(pSomeDynamicallyAllocatedMemory) { delete pSomeDynamicallyAllocatedMemory; pSomeDynamicallyAllocatedMemory = NULL; } }
http://opensource.devx.com/tips/Tip/14443
Null Pointers and Delete
C++ guarantees that operator delete checks its argument for null-ness. If the argument is 0, the delete expression has no effect. In other words, deleting a null pointer is a safe (yet useless) operation. There is no need to check the pointer for null-ness before passing it to delete:
if (p) // useless; delete already checks for a null value
delete(p);
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
Re: Oh God so many tiles!
But what Ginto posted is still good practice. Because what if it ISN'T NULL? I use that practice all the time =p