Sign in to follow this  
BaneTrapper

Needing sugestions on drawing tiled map

Recommended Posts

BaneTrapper    1531

Hello.
I am currently trying to find a workaround for my problem with Code::Blocks vs Visual studio.
Am running these codes in IDEs and i get results:

Code::Blocks

void Map::DrawMap(Application& objApp)
{
    sf::RenderWindow& Screen = objApp.objWindow.Screen;

    int TilesetWidth = objApp.objTextures.TileSheet.getSize().x / TILESIZE;
    int Layer2Width = objApp.objTextures.Layer2.getSize().x / TILESIZE;
    int TileID = 0;

    for(int y = 0; y < MAPSIZE_Y; y++)
    {
        for(int x = 0; x < MAPSIZE_X; x++)
        {
            //Tile
            sprTile.setTextureRect(sf::IntRect(((TileList[TileID].Layer1 - 1) % TilesetWidth) * TILESIZE,
                                   ((TileList[TileID].Layer1 - 1) / TilesetWidth) * TILESIZE, 32 ,32));
            sprTile.setPosition(x * TILESIZE, y * TILESIZE);
            Screen.draw(sprTile);
            //Layer2
            if(TileList[TileID].Layer2 > 0) // There is something to be drawn
            {
                //-1 for Layer2 to grab correct Layer2 icon, so no space is wasted
                sprLayer2.setTextureRect(sf::IntRect(((TileList[TileID].Layer2 - 1) % Layer2Width) * TILESIZE,
                                                     ((TileList[TileID].Layer2 - 1) / Layer2Width) * TILESIZE, 32, 32));
                sprLayer2.setPosition(x * TILESIZE, y * TILESIZE);
                Screen.draw(sprLayer2);
            }
            TileID ++;
        }
    }
}

 

This is like 1/2 performance of whole program of my per loop for Code::Blocks and i get around 600FPS // when i don't call this function i get around 800-900 fps

Visual studio 2010

void Map::DrawMap(Textures& objTex, sf::RenderWindow& renWin, Camera& objCam)
{
	int TileID = 0;
	int TilesetWidth = objTex.Global_TileSheet1.getSize().x / TILE_SIZE;
	int Layer2Width = objTex.Global_TileSheet2.getSize().x / TILE_SIZE;
	int offsetX = objCam.cameraX % TILE_SIZE;
	int offsetY = objCam.cameraY % TILE_SIZE;
	
	sprTile.setTextureRect(sf::IntRect((TileList[TileID].Layer1 % TilesetWidth) * TILE_SIZE, (TileList[TileID].Layer1 / TilesetWidth) * TILE_SIZE, 32 ,32));

    sprTile.setPosition(32 * TILE_SIZE - offsetX, 364 * TILE_SIZE - offsetY);

	sprTile2.setTextureRect(sf::IntRect((TileList[TileID].Layer2 % Layer2Width) * TILE_SIZE, (TileList[TileID].Layer2 / Layer2Width) * TILE_SIZE, 32, 32));
    sprTile2.setPosition(32 * TILE_SIZE - offsetX, 64 * TILE_SIZE - offsetY);

	for(int y = 0; y < mapSizeY; y++)
	{
		for(int x = 0; x < mapSizeX; x++)
		{
            renWin.draw(sprTile);
			renWin.draw(sprTile2);
			TileID ++;
		}
	}
}

 

In this case i get like 1-2 fps, "mapSizeX = 32" "mapSizeY = 24" are in both cases, and i also thought maybe something else is causing problem... Well when i comment out the drawing in the "visual studio 2010" i get around 900 fps witch is my max considering side program.

Question number 1: In both cases i use same program design, any ideas what may be wrong with Visual studio 2010 code?
If you need any more details i will post them.

Edited by BaneTrapper

Share this post


Link to post
Share on other sites
BaneTrapper    1531
Sorry for double post, but if i edit, the code gets smashed intro one line...

I just did remove whole program in visual studio and just kept "Map drawing" and "Fps capping" the problem still persists... i will try replacing .dll

This is kinda weird problem that would require inspection of whole program, so if you experienced same issues please share your wisdom!

EDIT:: I would like to note i am using "sfml 2.0" library for this Edited by BaneTrapper

Share this post


Link to post
Share on other sites
SuperVGA    1132
Are you compiling with roughly the same parameters/flags?
Are you compiling and running in release mode with both IDE's(compilers)?
Cause debug modes can really slow some things down...

Share this post


Link to post
Share on other sites
BaneTrapper    1531
Are you compiling with roughly the same parameters/flags?
Are you compiling and running in release mode with both IDE's(compilers)?
Cause debug modes can really slow some things down...
On Visual studio 2010 i got FPS improved up to 80 from 1-11, but on Code::blocks i went from around 700 too around 800.

I downloaded .dll from official sfml site for codeblocks and i get a massive decrease in fps down to 300-330 with release. Also i noticed with site .dll the sound was tearing "stoping for 0.1 - 0.3 each 1 second, if that describes it.

I will try to build my own Visual studio 2010 .dll and i will give you info

EDIT 2::
Also when using Visual studio 2010 i have "Main menu" "Character creation" "Member edit" all these functions are collision and drawing heavy and i get 400-600 fps in visual studio and 400-600 in code::blocks.

EDIT 3::
After building my own .dll files with cmake for visual studio the program fps on debug increased to 130 and release up to 200...

Don't know why... know know how... its acceptable FPS now "Flips the table" Edited by BaneTrapper

Share this post


Link to post
Share on other sites
FalconDragoon    485

Are both of these on the same machine, and if not are they on the same OS, do they have the same hardware configuration?

 

If they are on the same machine, are they using different compilers? Far as I know, Code blocks requires you to set one up, and that one can be Visual C++'s compiler or a few others.

 

Finally, regardless of the two question sets above, the code between them seems to be pretty significantly different (e.g. what does renWin.draw do?). Without the full context, comparisons like these mean little.

 

We don't know under what context the draw call is being made, or in the VS case what the draw code is doing at all. Inspect that and see what you find. If you can provide more context on what your scenario is (and what your code is actually doing) we can probably help more.

Share this post


Link to post
Share on other sites
BaneTrapper    1531

It has to do something with my graphics card being derp, when i get good explanation am gonna post it someone googles this but there ain't much i can ask of people to do now.

Running same executable on my laptop provides allot better FPS then on my main machine witch is allot stronger in all components so... id state compatibility issues...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this