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

Author Topic: Chop and Stutter; sprite-based tiled game  (Read 4016 times)

0 Members and 1 Guest are viewing this topic.

Hibchibbler

  • Newbie
  • *
  • Posts: 6
    • View Profile
Chop and Stutter; sprite-based tiled game
« on: February 01, 2013, 07:05:28 am »
Hi,

First, thank you for this wonderful software.
Overview
It runs fine on my computer, but runs very choppy on everyone else's computer; some of the computers are much more powerful then mine. we all have NVIDIA gfx cards of varying degrees of quality, mine not being the best.
all of us have win7, and i'm statically linking to a recent snapshot of SFML 2.0 (LaurentGomila-SFML-2.0-rc-95-g4c04a0c)
This problem exists in release mode. Although, I have not tried deploying a debug build on these other computers.

Narrowing it Down
I have a PNG file with an alpha channel. It is 512x512 pixels. It has several sprites on it(among a few others) that i use to create the floor in a game. Each floor sprite is 128x128 pixels.
The floor tiles are arranged in a 60x30 tile map. The tile map is static, but i pan around by use of a sf::View  that is centered on a player character. 

Specifically
In the initialization routine, that is only called once, i create a large render texture, and populate it with all the tiles:

arenaTexture.create(60*128,30*128);
for (int i = 0;i < 60*30;i++)
{
        Tile &tile = g.arenaMan.getTile(i);
        sf::Sprite s = g.assetMan.getSprite(tile.getId()+4);
        s.setPosition(tile.getPosition());
        arenaTexture.draw(s);
}
arenaTexture.display();
arenaSprite.setTexture(arenaTexture.getTexture());

Then, in the routine that is responsible for  rendering each frame, I have:

sf::FloatRect fr = sf::FloatRect(pos.x-(g.scrWidth/2.0f),pos.y-(g.scrHeight/2.0f),g.scrWidth,g.scrHeight);
arenaView.reset(fr);
window.setView(arenaView);
window.draw(arenaSprite);

So, for now, my question is; is the method i'm using above bad?

Thanks,
~Hibchibbler
« Last Edit: February 04, 2013, 12:15:23 am by Hibchibbler »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Tiling with sf::RenderTexture
« Reply #1 on: February 01, 2013, 08:16:57 am »
If it works then it *should* give you maximum performances. But it will fail on many computers, 7680 is a texture width that only good graphics card can support.

You should use vertex arrays instead.
Laurent Gomila - SFML developer

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Tiling with sf::RenderTexture
« Reply #2 on: February 01, 2013, 05:09:30 pm »
If you don't want to reinvent the wheel you can check the wiki, there's some tiled-map classes there.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Tiling with sf::RenderTexture
« Reply #3 on: February 01, 2013, 05:19:15 pm »
Scrap that and use http://en.sfml-dev.org/forums/index.php?topic=10249.msg70501#msg70501
I've also rewritten the example shader from projects forum to do tiling. It needs glsl 1.3 to be avaible and needs some testing on the .exe I posted(so far it works on 3 pcs, 2 nvidia and one ati and failed on one non-updated pc). If it's good I'll have to post the code because of the license of original.
Back to C++ gamedev with SFML in May 2023

Hibchibbler

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Tiling with sf::RenderTexture
« Reply #4 on: February 03, 2013, 10:54:10 am »
Chop, Stutter

I have moved from sf::RenderTexture to sf::VertexArray
Still having chop issues. But, only tested it on one of the problematic computers.
And the test was performed before i implemented rudimentary culling (fog of war =)). So I consider this test invalid. But still disheartening.

Here is specifically what I am working on.
http://imagebin.org/245312
This game is a multiplayer, team based dota/tower-defense style game.
I know for a fact that the chop is not network related.
have run empirical performance tests with and without server traffic involved...chop stays constant.

ContextSettings tells me Major 4, Minor 0 on my computer.
I will see what it says on problem computers next chance I get.

with a tile map of 30x60, where each tile is 128x128 pixels, would there be any limitations(as there is with sf::RenderTexture) on drawing the whole map?

The part of the story you are familiar with, is that I have a large, static map. It now uses a VertexArray, and is relatively constant. I only rebuild quad mesh every so often, not every frame.

The next piece of my story is that there are a ton of little sprites. Bullets, minions, explosions, other tanks. These things are always translating and rotating.

So, i digested, and followed advice given in this:
http://en.sfml-dev.org/forums/index.php?topic=9846.15

Hence all the little sprites are drawn using a VertexArray also.

We shall see what happens when my peoples come around and test my new build..

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Tiling with sf::RenderTexture
« Reply #5 on: February 03, 2013, 11:21:17 am »
Video, minimal working code with the stutter, count your fps?
Back to C++ gamedev with SFML in May 2023

Hibchibbler

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Tiling with sf::RenderTexture
« Reply #6 on: February 03, 2013, 10:58:38 pm »
Ok, so;
On one of the problematic computers; ContextSettings indicates OpenGL 4.3
And, again, i'm running 4.0.

Problematic computer has FPS that wildly swings between 40 and 6
My computer(which does NOT experience the chop) has a wildly swinging FPS  of between 250 and 130

I'm not using sleeps, i'm not enabling VSync, i'm not setting  FrameRateLimit
I have tried both fullscreen and windowed mode.

I have tried employing timeBeginPeriod/timeEndPeriod with unimproved results..
I cannot figure out why there are such wild timings...





FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Tiling with sf::RenderTexture
« Reply #7 on: February 03, 2013, 11:22:12 pm »
Why do you think tiling is the problem?
Back to C++ gamedev with SFML in May 2023

Hibchibbler

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Tiling with sf::RenderTexture
« Reply #8 on: February 04, 2013, 12:13:56 am »
Well, I suppose the topic of the original post is now obsolete (EDIT: I changed it).
When i originally wrote it, i thought that it was the tiling..
But, now that I've changed paradigms from sf::RenderTexture to sf::VertexArray, and am still experiencing the chop,  I am suspecting it is not the tiling...
But something else.
Unfortunately, I don't know what...
The wildly varying FPS makes me very concerned...

I am attempting to come up with minimal working code with stutter...

I appreciate your inquiries
« Last Edit: February 04, 2013, 02:27:40 am by Hibchibbler »

Hibchibbler

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Chop and Stutter; sprite-based tiled game
« Reply #9 on: February 04, 2013, 02:26:20 am »
Uh oh...
I think I have an unnecessary mutex.
I did the time based profiling in VS 2010...showed me the light....
I haven't ever been able to repro the problem on my computer, so i'm waiting on people to stop watching TV.
But,i'm pretty sure this may be the problem...if so, i'll come back here to report, redact and apologize..

Hibchibbler

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: It is not always what it seems
« Reply #10 on: February 04, 2013, 05:14:42 am »
Yup, It's not the Tiling, Sorry.
Was the Mutex, which means,Was the networking code.
Sorry.

But, thanks for making me feel not alone.

However, i'm glad I migrated to VertexArrays, so not all is lost.

 

anything