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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - schizo-boy

Pages: [1]
1
General / Re: Vertex Array issue
« on: July 11, 2013, 10:56:49 pm »
I actually had much more entities so I went with the vertex array method as I thought it would be less resources consuming than drawing many sprites.

Thanks a lot  ;)

2
General / Re: Vertex Array issue
« on: July 08, 2013, 11:04:58 pm »
Thank I just realized as well that it would be pointless.
It would mean that I would have to call as many time the function draw as I would have done without using the vertex array  :(

Do you have any suggestion on how to handle multiple players on a window that are controlled by an AI and that could all move in any direction all together depending on the AI.

For understanding purpose here is the player tileset I am using



So any of those 8 players could be in any position of the map facing any direction and moving to any direction.

I was thinking on may be creating a map of players like it was explained on the vertex array tutorial and adapt it according to the AI changes and draw that map each time.

Would that be a good solution or is there a simpler, better, easier, or more efficient way of doing such things?

3
General / Re: Vertex Array issue
« on: July 08, 2013, 09:34:07 pm »
window.draw(vertex_ptr, vertex_count, primitive_type);
?

Not too sure how that would help me to draw only one vertice (I suppose that is the correct terminology ?)

Unless the vertex_count actually correspond to the vertice that you want to draw from the vertex_ptr?

4
General / Re: Vertex Array issue
« on: July 08, 2013, 08:00:39 pm »
I actually have an other question....

How could I do to get a certain tile from the array?

For example if I used that method to split a tileset containing tiles of "players" and I would like to draw them on the map but obviously not all of them...

What I'm looking for would be something like

windaw.draw( map[i ]);

5
General / Re: Vertex Array issue
« on: July 08, 2013, 01:33:07 pm »
Oups my mistake!

I just thought that each quad[i ] was the entire tile with its texture. ::)

I guess I really need some sleep  :)

Thanks for making me realize my obvious mistakes  :)

6
General / Re: Vertex Array issue
« on: July 08, 2013, 01:07:52 pm »
levelMap[i ] = rand() % 3 + 1;

rand() % 3 gives 0 1 or 2
rand() % 3 + 1 gives 1 2 or 3
You can't get 4 different tiles with only 3 different values.

Just try levelMap[i ] = rand() % 4; to get 0 1 2 or 3

Thanks a lot, that solved my issue  :)

Any ideas on how to adapt the code to split more than 4 tiles?

Let's say I want to split a tileset of 10 tiles of 32*32 for example.

7
General / [SOLVED]Vertex Array issue
« on: July 08, 2013, 12:53:37 pm »
Hello,

I am having trouble playing around with tile sets and vertex array.

I followed the tutorial:
http://www.sfml-dev.org/tutorials/2.0/graphics-vertex-array.php

And tried using the tile map example in my code but I can only see 3 tiles being drawn.

I believe that my problem comes from this part of the code:

// define its 4 corners
                quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
                quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
                quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y);
                quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);

                // define its 4 texture coordinates
                quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
                quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
                quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
                quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);

In my code I only create the map randomly like so:

void           GameWindow::designMap(int width, int height)
{
    int         levelMap[width * height];

    for (int i  = 0; i < width * height ; i++)
        levelMap[i] = rand() % 3 + 1;

    if (!map.load("ressources/tileset4.png", sf::Vector2u(blockWidth, blockHeight), levelMap, width, height))
        throw GlobExcep("Cannot load tile image!");
}

with map being an attribute of type TileMap in my class.

But when I draw the map I can only see 3 different tiles being drawn. Here is the tile set I used ( with tiles being 32*32 like in the example):



and here is the result I get from drawing in map of 20 * 20.



I first thought that it was the format of the tileset I was using that was causing this issue so I changed it to a tileset like so:



but I would still get the same output and never get to see tile 1 drawn even if I create a map of 100 000 * 100 000

So I believe that I'm misunderstanding something about how to split tileset into quads.

So if somebody could help me understanding what I am doing wrong or what do I need to do to adapt this code:
  for (unsigned int i = 0; i < width; ++i)
            for (unsigned int j = 0; j < height; ++j)
            {
                // get the current tile number
                int tileNumber = tiles[i + j * width];

                // find its position in the tileset texture
                int tu = tileNumber % (m_tileset.getSize().x / tileSize.x);
                int tv = tileNumber / (m_tileset.getSize().x / tileSize.x);

                // get a pointer to the current tile's quad
                sf::Vertex* quad = &m_vertices[(i + j * width) * 4];

                // define its 4 corners
                quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
                quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
                quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y);
                quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);

                // define its 4 texture coordinates
                quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
                quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
                quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
                quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);
            }

 to any other tileset format that would be great!

8
Window / Re: Zoom on view using too much ressources
« on: July 07, 2013, 03:18:15 pm »
Thanks for the help guys!

You were right we were not handling the views correctly.

Took me quite some time to wrap my mind around it but we've finally managed to handle them correctly and now everything works as expected  :)

Thanks for the tip about vertex arrays as well our code is much more efficient now  8)

9
General / Re: Listenning event within a thread
« on: July 07, 2013, 03:12:33 pm »
Thanks for the reply!

We've managed to find an alternative solution  :)

10
General / [SOLVED]Listenning event within a thread
« on: July 06, 2013, 02:52:18 pm »
Hello,

My colleague and I are developing an network based application but we did not manage to put the keyboard listening event into an SFML thread.

We would like the listening events to be non blocking:

Our application must have 2 infinite loops allowing us to :
1. Listen to the network requests. ( synchronized sockets)
2. Listen to the keyboard events.

All we've manage to do so fare when putting the listening events in a thread is either a segmentation fault or the application would simply ignore those events.

So our question is :

How can we create a non blocking keyboard listening event?

An other thing would be how could we avoid being in the pollEvent loop all the time :
while (renderWindow.isOpen())
    {
        sf::Event event;
        while (renderWindow.pollEvent(event))
        {
           //handle events
        }
    }
 

when we are trying to actions which are not related to events?

Thanks

PS: If a solution existe using the SFML network module we are not allowed to use it and we have to use the Posix sockets.

11
Window / [SOLVED]Zoom on view using too much ressources
« on: July 06, 2013, 02:32:21 pm »
Hello,
My colleague and I ran into an issue with views.
The following method

void    GameWindow::redrawMap(const int width, const int height, const bool recreateMap)
{
    sf::View view, view2;
    sf::RectangleShape rect;
    int altColor = 0;
    int posX = 0, posY = 0;
    int caseWidth = 32, caseHeight = 32;
    int sidePanelWidth = 200;
    sf::Sprite sidepanelImage;

    sidepanelImage.setTexture(sidePanel);
    screenWidth = caseWidth * 20 + sidePanelWidth;
    screenHeight = caseHeight * 20;
    if (recreateMap)
        renderWindow.create(sf::VideoMode(screenWidth, screenHeight), "UI", sf::Style::Titlebar | sf::Style::Close);
    renderWindow.clear(sf::Color(139, 115, 85));
    rect.setSize(sf::Vector2f(caseWidth, caseHeight));
    rect.setOutlineColor(sf::Color::Yellow);
    rect.setOutlineThickness(1);
    sidepanelImage.setPosition(screenWidth - sidePanelWidth, 0);
    rect.setPosition(posX, posY);
    view.reset(sf::FloatRect(0, 0, screenWidth, screenHeight));
    view.setViewport(sf::FloatRect(0, 0, 1.0f, 1.0f));
    view.zoom(curZoom);
    renderWindow.setView(view);
    while (posY <= caseHeight * height)
    {
        while (posX < caseWidth * width)
        {
            renderWindow.draw(rect);
            rect.setPosition(posX, posY);
            posX += caseWidth;
            rect.setFillColor(sf::Color(0, 123, 12));
            altColor++;
        }
        posX = 0;
        posY += caseHeight;
    }
    view2.reset(sf::FloatRect(0, 0, screenWidth, screenHeight));
    view2.setViewport(sf::FloatRect(0, 0, 1.0f, 1.0f));
    renderWindow.setView(view2);
    renderWindow.draw(sidepanelImage);
    renderWindow.display();
}
 

Allow us to redraw the content of the window each time we want to zoom in or zoom out on this view by modifying the curZoom variable before entering this method.

The problem is that we have to redraw the whole content of the window each time we want to modify the view.

Our window look like this:


The green squares are all we want to zoom into.

The problem we are facing is that because the views are passed by copy into our renderWindow we can not find a way to access it later or to keep a reference on it. So we are just redrawing the squares as well as the other view on the right ( the grey "box").

If there was a way to do it in a "cleaner" way or any help idea or solution on that problem would be greatly appreciated.

Thanks

Pages: [1]