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 - JacobHofer

Pages: [1]
1
General / Re: Issue with rendering textures to the screen
« on: December 01, 2018, 09:59:39 pm »
My tilemap only changes when a player places a new tile, which is not happening here, so in this instance, the tilemap is static. None of the tiles are animating or anything either. Here is the code that handles the rendering of the tiles.

sf::Vector2f v = handler->window->getView().getSize();
        //std::cout << v.x << " " << v.y << std::endl;
        std::vector<std::vector<sf::RectangleShape>> renderOrder(256,
                std::vector<sf::RectangleShape>(0));


        for (int x = 0; x < world->getWidth(); x++) {
                for (int y = 0; y < world->getHeight(); y++) {



                        if (!(x * tileSize + tileSize < xOffset + (handler->window->getSize().x / 2 - v.x / 2) ||
                                x * tileSize > handler->window->getSize().x + xOffset - (handler->window->getSize().x / 2 - v.x / 2) ||
                                y * tileSize + tileSize < yOffset + (handler->window->getSize().y / 2 - v.y / 2) ||
                                y * tileSize > handler->window->getSize().y + yOffset - (handler->window->getSize().y / 2 - v.y / 2))) {


                                sf::Uint8 tileId = world->getTile(x, y);

                                sf::RectangleShape tile(sf::Vector2f(tileSize, tileSize));
                                tile.setPosition((x * tileSize - xOffset), (y * tileSize - yOffset));

                                sf::Uint8 data = 0;

                                tile.setTexture(handler->assets->getBaseTexture(tileId));



                                renderOrder[0].push_back(tile); // We always want the base tiles to be drawn first

                                TileData currentTileData = world->getTileData(x, y);
                                std::map<sf::Uint8, sf::Uint8> adjInfo = currentTileData.getAdjacentInfo();
                                for (std::map<sf::Uint8, sf::Uint8>::iterator it = adjInfo.begin(); it != adjInfo.end(); it++) {

                                        sf::Uint8 key = it->first;
                                        sf::Uint8 value = it->second;

                                        sf::Texture* newT = handler->assets->getOuterTexture(key, value, x, y);
                                        if (newT == nullptr) continue;
                                        tile.setTexture(newT);
                                        renderOrder[handler->assets->getTilePriority(key)].push_back(tile);

                                }


                        }



                }
        }

        for (int i = 0; i < renderOrder.size(); i++) {
                for (int j = 0; j < renderOrder[i].size(); j++) {
                        handler->window->draw(renderOrder[i][j]);
                }
        }
 

BTW tileSize, xOffset, and yOffset are variables declared elsewhere. Tilesize is simply the size of a tile, and x and y offset is the offset from the camera

*EDIT* sorry that the code looks bad in the window. I think it messed up my formatting. Here is a better view of it https://pastebin.com/LNgzCb61

2
General / Issue with rendering textures to the screen
« on: November 29, 2018, 07:14:01 am »
So, I have a tile game that I am working on. This is a very odd bug, and I'm not sure if it is due to my own code, or something in SFML. I've looked all over my code, and don't think that's where it is originating from.
 
Anyways, the bug is a small visual glitch. Some of my tiles seem to be rendered as a solid color from time to time, but for only a frame. In addition, the color seems to match somewhat with the base texture of the tile. I have attached a short video showing the bug in it's entirety.

https://www.youtube.com/watch?v=93n_V0vjkHI&feature=youtu.be

If you need to see any code, ask and I'll be happy to provide it

3
Network / Re: Sending Game Info Over UDP Is Very Slow
« on: August 08, 2018, 09:16:29 pm »
After a few days of trying different things, I finally found a solution! Basically, the info was being sent as quickly as the computer could, which would leave my internet trying to play catch up with sending the info. So I basically ran 2 threads, 1 for receiving info (which was still on a loop as fast as possible to ensure no loss of data), and the other for sending data, which I sleep to make the data only send 20 times a second!

4
Network / Sending Game Info Over UDP Is Very Slow
« on: August 05, 2018, 10:01:28 pm »
Hey everyone! So, I am new to the networking side of SFML, so to practice, I created a simple game. Basically users join and each control a square that moves around the screen. So far, it works fine, but sending and receiving data is very slow. Inputs take 1-2 seconds to register from one computer to another. Any ideas as to how I could fix it? Code is available below:

CLIENT CODE: https://hastebin.com/oviqiwajev.php
SERVER CODE: https://hastebin.com/xomolokabi.cpp

Thanks!

Pages: [1]
anything