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.


Topics - Jungletoe

Pages: [1]
1
Network / Ubuntu TCP networking dropping/freezing packets
« on: July 28, 2014, 04:50:35 am »
About a year ago I had this exact same issue on Windows and we came to a resolution.
http://en.sfml-dev.org/forums/index.php?topic=11780.0

Now that I've ported and compiled the server on Linux, the exact same issue resurfaced. The server sends the packets to the client perfectly UNTIL it hits a large packet (nothing over 1000 bytes, though). At that point, the client stalls because it keeps waiting for the server to send the rest of the packet (a la the TCP protocol). The server never does and keeps moving on. The server then does not send ANY MORE packets to the client because I think the connector is frozen (or at least I assume).

Was that fix that was posted only apply to Windows?

2
Window / Are there still limitFramesPerSecond() isssues in 2.1?
« on: August 22, 2013, 08:37:00 pm »
I was experimenting a bit with SFML 2.1. Capping the framerate worked fine for a while, but it's noticeably starting to increase a lot at random times.

I can provide a minimal example, although I do not know how to reproduce it. I'm running Windows 7 with Intel Chipset Family graphics.


3
Window / LShift and RSHIFT causes choppy framerate?
« on: August 21, 2013, 04:50:27 pm »
When running my app, whenever I press LSHIFT or RSHIFT, regardless of whether I am processing it or not within my event loop, the framerate becomes choppy-- randomly freezing for tenths of seconds and then speeding back up.

I'm using SFML 2.1

int main ( int argc, char *argv[] )
{
        // Create a new render-window
        sf::RenderWindow window(sf::VideoMode(800, 600), "AAAA");
        window.setFramerateLimit(60);

        sf::Clock clock;
    float lastTime = 0;

        sf::Texture texture;
        texture.loadFromFile("dot.png");
        sf::Sprite sprite;
        sprite.setTexture(texture);
        sprite.setPosition(500, 400);

        sf::Int32 direction = rand()%4+1;

        // The main loop
        while (window.isOpen())
        {
                // Event handling
                sf::Event Event;
                while (window.pollEvent(Event))
                {
                        if (Event.type == sf::Event::Closed)
                                window.close();
                }

                //      Data
                if(direction == 1)
                        sprite.setPosition(sprite.getPosition().x+1, sprite.getPosition().y);
                if(direction == 2)
                        sprite.setPosition(sprite.getPosition().x, sprite.getPosition().y+1);
                if(direction == 3)
                        sprite.setPosition(sprite.getPosition().x-1, sprite.getPosition().y);
                if(direction == 4)
                        sprite.setPosition(sprite.getPosition().x, sprite.getPosition().y-1);

                if(sprite.getPosition().x < 0 || sprite.getPosition().y < 0 || sprite.getPosition().x + 50 > window.getSize().x || sprite.getPosition().y + 50> window.getSize().y)
                {
                        sf::Int32 origDir = direction;
                        while(origDir == direction)
                                direction = rand()%4+1;
                }

                //      Clear & Draw window
                window.clear();
                window.draw(sprite);
                window.display();

                //      FPS output
                float currentTime = clock.getElapsedTime().asSeconds();
        float fps = 1.f / (currentTime - lastTime);
        lastTime = currentTime;

                std::cout << fps << "\n";
        }

        return 0;
}


Is there any reason for this? Any fix?

Thanks!

4
Graphics / Extremely simple lighting techniques?
« on: June 23, 2013, 05:56:40 pm »
Hi,

At the moment, my lighting system is extremely basic. I simply lay a VertexArray over the whole screen and slowly modify its alpha channel to simulate a day/night system. However, I need to add campfires and torches, both which require a simple circular lighting radius where there is more transparency in the filter.

At the moment, I just put a yellow alpha image over where the campfire is. The only problem is that this can end up happening if there are too many fires in one area:



Is there any way to do a simple lighting system WITHOUT shadows and WITHOUT rendertextures? I want to support as many machines as possible (not to mention that my own computer can't handle rendertextures).

This is what I'm going for:


5
SFML projects / Dwell - A Retro Sandbox Survival MMO
« on: June 16, 2013, 09:28:45 pm »




What is Dwell?
A cross between creativity, horror, and adventure, Dwell aims to be an MORPG like no other. Settle, create a village, and defend your friends from the horrible creatures who lurk in the forests. You can change the landscape, farm, or hunt in order to survive the conditions-- it's all up to you.

How can I play?

Dwell is currently in its closed Alpha 1.0 stage. You can download alpha here (our temporary forum). Please register on the forums so we can track bugs and errors :)

http://www.youtube.com/watch?v=rkBnF3X-5Ig

What features are planned?
-An ever-changing world shaped purely by the players
-Villages created and governed by the players themselves
-Basic jobs, like farming, mining, fishing, woodworking, cloth working, and cooking
-Advanced building, allowing you to make a personalized home for your needs and profession
-A simplified stats system, reducing grind and improving players' experiences
-Skill-based combat (no more button bashing or complex combat systems!)
-Diplomacy amongst villages and villagers
-Children and Family NPCs (spawned based on your stats and living conditions)
-Pets and farm animals

What platforms will Dwell be available on?
At the moment, Dwell is only available on Windows (XP, Vista, Win7, and Win8 successfully tested). After our early testing phases, we aim to have a solid build out for everyone to enjoy, including those on MacOS and Linux. Please be patient-- we want everyone to play ASAP!

Who are the developers?
Jungletoe (Programming), ICT (Pixel Art), LegendWeaver (GUI Art), and Allen Calmes (Music). We're informally part of the development group Giraffes. Dwell is currently our main project.

Where can I find more info?
Website - http://playdwell.com
Youtube - http://www.youtube.com/user/MrJungletoe
Twitter - http://twitter.com/JungleTheDev

What libraries did you use?
SFML, libnoise, TGUI, and pugixml.










6
Network / Non-Blocking TCP Freeze [Fixed]
« on: April 22, 2013, 01:17:32 am »
Ok, so I've been posting my problems on this thread, which I previously believed were due to networking errors. After further investigation, I realized that the problem is rooted in the sound devices.

I've reinstalled openAL using the libraries provided with SFML, so it's not that.

Here is what Very Sleepy presents me:


If you look at the right hand side on the callstack, it appears that it freezes while playing sounds Here is another snapshot I took:


With this callstack freeze, it appears that it is trying to create a sound instead. Very odd.

Here is my SoundHandler.hpp

#ifndef __SOUNDHANDLER_HPP__
#define __SOUNDHANDLER_HPP__

#include "SFML/System.hpp"
#include "SFML/Audio.hpp"
#include <vector>

class SoundHandler
{
        private:
                sf::Clock timer;

                //////////////////////////
                //                Sounds                //
                //////////////////////////

                sf::SoundBuffer clickBuffer;
                sf::Sound clickSFX;

                sf::SoundBuffer chopBuffer;
                sf::Sound chopSFX;

                sf::SoundBuffer leavesBuffer;
                sf::Sound leavesSFX;

                sf::SoundBuffer windBuffer;
                sf::Sound windSFX;

                sf::SoundBuffer stormBuffer;
                sf::Sound stormSFX;

                sf::SoundBuffer rockBuffer;
                sf::Sound rockSFX;

                sf::Music deathSFX;

                sf::SoundBuffer blood1Buffer;
                sf::Sound blood1SFX;

                sf::Music birdSFX;

                sf::SoundBuffer killBuffer;
                sf::Sound killSFX;

                sf::SoundBuffer popBuffer;
                sf::Sound popSFX;

                sf::SoundBuffer splatBuffer;
                sf::Sound splatSFX;

                sf::SoundBuffer chargeBuffer;
                sf::Sound chargeSFX;

                sf::SoundBuffer splashBuffer;
                sf::Sound splashSFX;

                sf::SoundBuffer waterBuffer;
                sf::Sound waterSFX;

                sf::SoundBuffer fireBuffer;
                sf::Sound fireSFX;

                sf::Music cricketsSFX;

                sf::Music musicboxSFX;

                sf::Music combatSFX;

                sf::SoundBuffer typeBuffer;
                sf::Sound typeSFX;

                sf::Music feetSFX;

                sf::SoundBuffer puffBuffer;
                sf::Sound puffSFX;

                sf::SoundBuffer stabBuffer;
                sf::Sound stabSFX;

                //////////////////////////
                //                Music                 //
                //////////////////////////

                std::vector<sf::Int32> playlist;
                sf::Int32 playNumber;
                sf::Music ambient1;
                sf::Music ambient2;
                sf::Music ambient3;
                sf::Music ourHome;
                sf::Music fishing;
                sf::Music intro;
                sf::Music night;
                sf::Music main;
                bool firstPlayed;

                //      Other vars
                bool soundMuted;
                bool musicMuted;

        public:
                SoundHandler();
                void load();
                void handleMusic();
                void stopMusic();
                bool musicOn;
                void muteMusic();
                void muteSound();

                bool playClick();
                void stopClick();

                bool playWind();
                void stopWind();

                bool playChop();
                void stopChop();

                bool playLeaves();
                void stopLeaves();

                bool playStorm();
                void stopStorm();

                bool playRock();
                void stopRock();

                bool playDeath();
                void stopDeath();

                bool playBlood1();
                void stopBlood1();

                bool playBirds();
                void stopBirds();

                bool playKill();
                void stopKill();

                bool playPop();
                void stopPop();

                bool playSplat();
                void stopSplat();

                void playCharge();
                void resetCharge();

                void playFishing();
                void stopFishing();

                void playSplash();

                void playWater();

                void playCrickets();
                void stopCrickets();

                void playMain();

                void playNight();

                void playFire();

                void playMusicbox();
                void stopMusicbox();

                void playCombat();

                void playType();

                void playFeet();

                void playPuff();

                void playStab();
};

#endif
 


...and my SoundHandler.cpp

#include "stdafx.h"
#include <random>
#include <time.h>
#include "SoundHandler.hpp"
#include "Globals.hpp"

SoundHandler::SoundHandler()
{
        load();
        musicMuted = false;
        soundMuted = false;
}

void SoundHandler::load()
{
        //////////////////////////
        //                Sounds                //
        //////////////////////////

        clickBuffer.loadFromFile("rsc/SFX/click.ogg");
        clickSFX.setBuffer(clickBuffer);

        chopBuffer.loadFromFile("rsc/SFX/chop.ogg");
        chopSFX.setBuffer(chopBuffer);

        leavesBuffer.loadFromFile("rsc/SFX/leaves.ogg");
        leavesSFX.setBuffer(leavesBuffer);

        windBuffer.loadFromFile("rsc/SFX/wind.ogg");
        windSFX.setBuffer(windBuffer);
        windSFX.setLoop(true);

        stormBuffer.loadFromFile("rsc/SFX/storm.ogg");
        stormSFX.setBuffer(stormBuffer);

        rockBuffer.loadFromFile("rsc/SFX/rock.ogg");
        rockSFX.setBuffer(rockBuffer);

        deathSFX.openFromFile("rsc/SFX/death.ogg");

        blood1Buffer.loadFromFile("rsc/SFX/blood1.ogg");
        blood1SFX.setBuffer(blood1Buffer);

        birdSFX.openFromFile("rsc/SFX/birds.ogg");

        killBuffer.loadFromFile("rsc/SFX/kill.ogg");
        killSFX.setBuffer(killBuffer);

        popBuffer.loadFromFile("rsc/SFX/pop.ogg");
        popSFX.setBuffer(popBuffer);

        splatBuffer.loadFromFile("rsc/SFX/splat.ogg");
        splatSFX.setBuffer(splatBuffer);

        chargeBuffer.loadFromFile("rsc/SFX/charge.ogg");
        chargeSFX.setBuffer(chargeBuffer);
        resetCharge();

        splashBuffer.loadFromFile("rsc/SFX/splash.ogg");
        splashSFX.setBuffer(splashBuffer);

        waterBuffer.loadFromFile("rsc/SFX/water.ogg");
        waterSFX.setBuffer(waterBuffer);
        waterSFX.setVolume(25);

        cricketsSFX.openFromFile("rsc/SFX/crickets.ogg");

        fireBuffer.loadFromFile("rsc/SFX/fire.ogg");
        fireSFX.setBuffer(fireBuffer);

        musicboxSFX.openFromFile("rsc/SFX/musicbox.ogg");
        musicboxSFX.setLoop(true);

        combatSFX.openFromFile("rsc/SFX/combat.ogg");

        typeBuffer.loadFromFile("rsc/SFX/type.ogg");
        typeSFX.setBuffer(typeBuffer);

        feetSFX.openFromFile("rsc/SFX/feet.ogg");

        puffBuffer.loadFromFile("rsc/SFX/puff.ogg");
        puffSFX.setBuffer(puffBuffer);

        stabBuffer.loadFromFile("rsc/SFX/stab.ogg");
        stabSFX.setBuffer(stabBuffer);

        //////////////////////////
        //                Music                 //
        //////////////////////////

        //      Day Playlist
        ourHome.openFromFile("rsc/Music/ourHome.ogg");                  //      0
        playlist.push_back(0);
        ambient1.openFromFile("rsc/Music/ambience1.ogg");               //      1
        playlist.push_back(1);
        ambient2.openFromFile("rsc/Music/ambience2.ogg");               //      2
        playlist.push_back(2); 
        night.openFromFile("rsc/Music/night.ogg");                              //      3
        playlist.push_back(3);
        ambient3.openFromFile("rsc/Music/ambience3.ogg");               //      4
        playlist.push_back(4);

        musicOn = true;
        firstPlayed = false;
        srand(time(NULL));
        std::random_shuffle(playlist.begin(), playlist.end());
        playNumber = 0;

        //      Fishing
        fishing.openFromFile("rsc/Music/fishing.ogg");
        fishing.setLoop(true);

        //      Intro
        intro.openFromFile("rsc/Music/intro.ogg");
        intro.setLoop(true);

        //      Main
        main.openFromFile("rsc/Music/The Colony.ogg");
        main.setLoop(true);
}

void SoundHandler::handleMusic()
{
        if(((timer.getElapsedTime().asSeconds() >= 300) || ((!firstPlayed) && (timer.getElapsedTime().asSeconds() >= 60))) && musicOn && !musicMuted)
        {
                firstPlayed = true;
                sf::Int32 songNumber = playlist[playNumber];
                bool restartTimer = true;

                if(songNumber == 0)
                {
                        ourHome.play();
                }

                else if(songNumber == 1)
                {
                        ambient1.play();
                }

                else if(songNumber == 2)
                {
                        ambient2.play();
                }

                else if((songNumber == 3))
                {
                        if((gl::Vars::timeOfDay == NIGHT) || (gl::Vars::timeOfDay == DAWN) || (gl::Vars::timeOfDay == DAWN))
                                night.play();
                        else
                                restartTimer = false;
                }

                else if((songNumber == 4))
                {
                        ambient3.play();
                }

                if(restartTimer)
                        timer.restart();

                playNumber++;
                if(playNumber >= playlist.size())
                {
                        srand(time(NULL));
                        std::random_shuffle(playlist.begin(), playlist.end());
                        playNumber = 0;
                }
        }

        else if(timer.getElapsedTime().asSeconds() >= 300)
        {
                timer.restart();
        }
}

void SoundHandler::stopMusic()
{
        ourHome.stop();
        ambient1.stop();
        ambient2.stop();
        ambient3.stop();
        fishing.stop();
        intro.stop();
        night.stop();
        musicboxSFX.stop();
        main.stop();
}

void SoundHandler::muteMusic()
{
        musicMuted = !musicMuted;

        if(!musicMuted)
                stopMusic();
}

void SoundHandler::muteSound()
{
        soundMuted = !soundMuted;
        windSFX.stop();
        feetSFX.stop();
        cricketsSFX.stop();
        birdSFX.stop();
}

bool SoundHandler::playChop()
{
        if(!soundMuted)
                chopSFX.play();
        return true;
}

void SoundHandler::stopChop()
{
        chopSFX.stop();
}

bool SoundHandler::playClick()
{
        if(!soundMuted)
                clickSFX.play();
        return true;
}

void SoundHandler::stopClick()
{
        clickSFX.stop();
}

bool SoundHandler::playLeaves()
{
        if(!soundMuted)
                leavesSFX.play();
        return true;
}

void SoundHandler::stopLeaves()
{
        leavesSFX.stop();
}

bool SoundHandler::playWind()
{
        if(!soundMuted)
                windSFX.play();
        return true;
}

void SoundHandler::stopWind()
{
        windSFX.stop();
}

bool SoundHandler::playStorm()
{
        if(!soundMuted)
                stormSFX.play();
        return true;
}

void SoundHandler::stopStorm()
{
        stormSFX.stop();
}

bool SoundHandler::playRock()
{
        if(!soundMuted)
                rockSFX.play();
        return true;
}

void SoundHandler::stopRock()
{
        rockSFX.stop();
}

bool SoundHandler::playDeath()
{
        if(!musicMuted)
                deathSFX.play();
        return true;
}

void SoundHandler::stopDeath()
{
        deathSFX.stop();
}

bool SoundHandler::playBlood1()
{
        if(!soundMuted)
                blood1SFX.play();
        return true;
}

void SoundHandler::stopBlood1()
{
        blood1SFX.stop();
}

bool SoundHandler::playBirds()
{
        if(!soundMuted)
                birdSFX.play();
        return true;
}

void SoundHandler::stopBirds()
{
        birdSFX.stop();
}

bool SoundHandler::playKill()
{
        if(!soundMuted)
                killSFX.play();
        return true;
}

void SoundHandler::stopKill()
{
        killSFX.stop();
}

bool SoundHandler::playPop()
{
        if(!soundMuted)
                popSFX.play();
        return true;
}

void SoundHandler::stopPop()
{
        popSFX.stop();
}

bool SoundHandler::playSplat()
{
        if(!soundMuted)
                splatSFX.play();
        return true;
}

void SoundHandler::stopSplat()
{
        splatSFX.stop();
}

void SoundHandler::playCharge()
{
        if(!soundMuted)
                chargeSFX.play();
        chargeSFX.setPitch(chargeSFX.getPitch() + .1);
}

void SoundHandler::resetCharge()
{
        chargeSFX.setPitch(.1);
}

void SoundHandler::playFishing()
{
        if(!musicMuted)
                fishing.play();
}

void SoundHandler::stopFishing()
{
        fishing.stop();
}

void SoundHandler::playSplash()
{
        if(!soundMuted)
                splashSFX.play();
}

void SoundHandler::playWater()
{
        waterSFX.setPitch((rand() % 20) * .1 + .1);
        if(!soundMuted)
                waterSFX.play();
}

void SoundHandler::playCrickets()
{
        if(!soundMuted)
                cricketsSFX.play();
}

void SoundHandler::stopCrickets()
{
        if(!soundMuted)
                cricketsSFX.stop();
}

void SoundHandler::playMain()
{
        if(!musicMuted)
                main.play();
}

void SoundHandler::playNight()
{
        if(!soundMuted)
                night.play();
}

void SoundHandler::playFire()
{
        if(!soundMuted)
                fireSFX.play();
}

void SoundHandler::playMusicbox()
{
        musicOn = false;
        stopMusic();
        musicboxSFX.stop();
        if(!soundMuted && !musicMuted)
        {
                musicboxSFX.play();
                stabSFX.play();
        }
}

void SoundHandler::stopMusicbox()
{
        musicboxSFX.stop();
}

void SoundHandler::playCombat()
{
        if(!soundMuted)
                combatSFX.play();
}

void SoundHandler::playType()
{
        if(!soundMuted)
                typeSFX.play();
}

void SoundHandler::playFeet()
{
        if(!soundMuted)
                feetSFX.play();
}

void SoundHandler::playPuff()
{
        if(!soundMuted)
                puffSFX.play();
}

void SoundHandler::playStab()
{
        if(!soundMuted)
                stabSFX.play();
}
 

For the sake of "minimal and complete examples", here is an example main function:
#include "SoundHandler.hpp"

int main()
{
        SoundHandler soundHandler;
        soundHandler.load();
        soundHandler.handleMusic();
        soundHandler.playCombat();

        return 0;
}
 

Of course, this probably will not crash it since it crashes randomly when I play sounds. I haven't been able to solidly reproduce it yet repeatedly, so I apologize for lack of information.

My guess is that it may have to do with music being loaded at the same time as sounds? That's just a guess from my debugging, but I can't be sure.

All of the sounds are <1 second and the music is anywhere from 30 secs to 5 minutes.

Also, this occasionally gets output in my console and in other's:


Any ideas?

7
Network / Non-Blocking TCP Crashing Client?
« on: April 20, 2013, 02:58:59 am »
Overview
Ok, sorry to bug you guys and make a new thread, but I feel that the other one was titled wrongly for what I' now encountering.

The server is now stable thanks to Binary's help, but my client is very unstable. Again, I cannot replicate any of the crashes myself, which leads me to believe that people who live further away (with greater ping times) are corrupting the packets somehow. I don't know how this is possible, but it's crippling the stability of my playerbase and I have absolutely no way of testing it.

Details:
I am using unblocking TCP sockets, although I switch to blocking when I connect() from the client.

Code

Server send code:
void NetworkManager::sendPacket(sf::Packet* pack, sf::Int32 connectorID, bool delPacket)
{
        if(getConnectorWithID(connectorID) != NULL)
        {
                Connector* c = getConnectorWithID(connectorID);
                if(c != NULL)
                        c->sendPacket(pack);
        }

        if(delPacket)
        {
                //sf::Int32 packID;
                //*pack >> packID;
                //std::cout << "Sending :: " << packID << "\n";

                delete pack;
        }
}
 


Retry send if it fails or returns sf::Socket::NotReady:
void NetworkManager::retryDroppedPackets()
{
        for(sf::Int32 i = 0; i < ent::connectors.size(); i++)
        {
                if(ent::connectors[i]->packets.size() > 0)
                {
                        sf::Socket::Status status = ent::connectors[i]->socket.send(ent::connectors[i]->packets.front());

                        if(status != sf::Socket::NotReady && status != sf::Socket::Error)
                        {
                                ent::connectors[i]->packets.pop();

                                if(status == sf::Socket::Error)
                                {
                                        std::cout << "E1E\n";
                                }
                        }
                }
        }
}
 


Server receive code:
void NetworkManager::recPackets()
{
        Connector* newConnector = new Connector;
        newConnector->socket.setBlocking(false);
        newConnector->player = NULL;

        if(listener.accept(newConnector->socket) == sf::Socket::Done)
        {
                //      Adds a new client to client list
                maxConID += 1;
                newConnector->setID(maxConID);
                ent::connectors.push_back(newConnector);
        }

        else
        {
                //      Nothing we can do...
                delete newConnector;
        }


        //      The listener socket is not ready, test all other sockets
        for(sf::Int32 i = 0; i < ent::connectors.size(); i++)
        {
                sf::Packet packet;
                sf::Socket::Status status = ent::connectors[i]->socket.receive(packet);

                if(status == sf::Socket::Done)
                {
                        ent::connectors[i]->logClock.restart();

                        sf::Uint32 packetCode;
                        packet >> packetCode;

                        handlePacket(packetCode, packet, ent::connectors[i]->getID());
                }

                else if(status == sf::Socket::Disconnected)
                {
                        ent::playerHandler.handleDisconnect(ent::connectors[i]->getID());
                }

                else if(status == sf::Socket::Error)
                {
                        std::cout << "NetworkingError";
                }

                else if(status == sf::Socket::NotReady)
                {
                        //      Not ready
                        //std::cout << "not ready";
                }
        }
}
 


Client send code:
void NetworkManager::sendPacket(sf::Packet* pack)
{
        socket.setBlocking(false);
        if(droppedPackets.size() <= 0)
        {
                sf::Socket::Status status = socket.send(*pack);

                if(status == sf::Socket::Done)
                {
                        delete pack;
                }

                else if(status == sf::Socket::NotReady)
                {
                        droppedPackets.push(pack);
                }

                else if(status == sf::Socket::Error)
                {
                        std::cout << "ERROR";
                        droppedPackets.push(pack);
                }

                else if(status == sf::Socket::Disconnected)
                {
                        if(ent::game.isRunning())
                        {
                                ent::game.disconnect();
                                delete pack;
                        }
                }
        }

        else
        {
                droppedPackets.push(pack);
        }
}
 


Server send code if first time fails:
void NetworkManager::retryPackets()
{
        if(droppedPackets.size() > 0)
        {
                socket.setBlocking(false);
                sf::Socket::Status status = socket.send(*droppedPackets.front());

                if(status == sf::Socket::Done)
                {
                        delete droppedPackets.front();
                        droppedPackets.pop();
                }

                else if(status == sf::Socket::NotReady)
                {
                        //      Do nothing

                }

                else if(status == sf::Socket::Error)
                {
                        std::cout << "ERROR";
                        delete droppedPackets.front();
                        droppedPackets.pop();
                }

                else if(status == sf::Socket::Disconnected)
                {
                        if(ent::game.isRunning())
                        {
                                ent::game.disconnect();
                                delete droppedPackets.front();
                                droppedPackets.pop();
                        }
                }
        }
}
 


Client receive:
void NetworkManager::handle()
{
        retryPackets();

        socket.setBlocking(false);

        sf::Packet pack;
        sf::Socket::Status status = socket.receive(pack);

        if(status == sf::Socket::Done)
        {
                sf::Int32 packetType;           //      Determines what the packet contains, different packet types contain different info

                if(pack >> packetType)
                {
                        if(displayPacketID)
                                std::cout << "\nPacket Type :: " << packetType;
//
//
//                    Handle Packet
//
//

}

                else
                {
                        if(displayPacketID)
                                std::cout << "Junk Packet";
                }
        }

        else
        {
                //      not ready
        }
}
 


Client connect code (runs on its own thread):
bool NetworkManager::connect(std::string IP, sf::Int32 port)
{
        if(ip != NULL)
                delete ip;

        ip = new sf::IpAddress(IP);

        socket.setBlocking(true);
        sf::Socket::Status status = socket.connect(*ip, port, sf::milliseconds(250));
        socket.setBlocking(false);

        if(status == sf::Socket::Disconnected)
        {
                //std::cout << "disconnected";
                connected = false;
                gl::Vars::connected = false;
                return false;
        }

        else if(status == sf::Socket::Done)
        {

                //std::cout << "connected";
                gl::Vars::connected = true;
                connected = true;

                sf::Packet* spack = new sf::Packet;
                sf::Int32 packID = 0;
                *spack << packID << gl::Vars::versionNumber;
                ent::networkManager.sendPacket(spack);

                return true;
        }

        else if(status == sf::Socket::Error)
        {
                connected = false;
                gl::Vars::connected = false;

                return false;
        }

        else
        {
                std::cout << "not ready";
                connected = false;
                gl::Vars::connected = false;

                return false;
        }
}


Client Main:
ent::menu.Run();

        if(ent::menu.getSuccess())      //      If logged in
        {
                ent::loadingScreen.Run();
                if(ent::game.Run())             //      if dead
                {
                        ent::death.Run();
                }
        }


Game.Run()
Init();
        cleanClock.restart();
        while(running && !dead)
        {
                ent::networkManager.handle();
                Input();
                Data();
                Clear();
                Draw();
                if(cleanClock.getElapsedTime().asSeconds() >= 10.0f)
                {
                        cleanClock.restart();
                        Clean();
                }
        }
        cleanUp();

        return dead;


I'd love if one of you veterans could add me on Skype (brady.welch) so we can resolve this issue. I could send you the full source and client for you to test for my game.

8
Network / TCP Lag Reduction Techniques?
« on: March 30, 2013, 09:14:30 pm »
Hi, I'm developing an sandbox ORPG called Colonies.

As my game has progressed, we have gotten upwards of 20 players constantly on at once. With this new traffic, there is also a lot of lag that has followed. After optimizing everything except the networking backend, I came to the realization that the lag was coming from sending packets.

The game can suddenly freeze for 5-20 seconds at worst. I profiled the threads and noticed that it was getting held up at "zwwaitforsingleobject" inside of the send packet function.

-What are some common techniques to reduce the sending lag?
-Would breaking down the packets into smaller ones reduce the lag or have no effect since SFML does this anyways (I've noticed that larger packets take longer to send)?
-Does adding a timeout to the selector effect the timeout of the send? Do I need to have the selector in a different thread from the "sendPacket" functions in order for the timeout to work?

Thanks,
Jungle

9
Graphics / SFML rendering issues on different computers [SOLVED]
« on: December 23, 2012, 09:37:39 pm »
I've been having this issue (on all computers except my own) for months now. The graphics for my game render perfectly on my computer (specs below), but on some other people's computers, the graphics appear to be extremely distorted and the text skips characters.

This is what it looks like:


I'm using TGUI as well, although it seems that switching from TGUI's text to SFML's text still renders improperly. 

My specs: (It works fine on my computer, 450+ uncapped FPS)
Gateway DX4860
Intel(R) Core(TM) i5-2320 CPU @ 3.00GHz 3.00 GHz
6GB RAM
Windows 7 64-bit

Person 1's specs: (Rendering problems as seen above, 30 FPS)
4GB RAM
Has AMD/ATI Graphics Card (I'll ask him for specifics the next time he's online)

Person 2's specs: (Rendering problems as seen above, 450+ uncapped FPS)
32GB Ram
Windows 7 64-bit
Nvidia graphics card


Any ideas as to why this is happening? It's currently STATICALLY LINKED and I've tried switching around the way graphics are rendered to no avail. Is this a problem with SFML or am I doing something wrong?

And no, I cannot produce a minimal example because of the overwhelming amount of code I have atm.

10
The text above my sprites (or any small text around size 8 for that matter...) appears really blurred. I looked around and found this fix for 1.6, but couldn't find anything for 2.0 now that font.getImage() was removed. How do I set texts and fonts to not be smooth?


11
Window / Any way to make fullscreen stretch AND keep dimensions?
« on: August 12, 2012, 03:29:44 am »
Hello, I'm developing a game with tiles that are 16x16. I want my tiles to remain a square shape when I put the game in full screen mode. I'm trying to figure out how to do this with video modes.

If I draw a square in a full screen video mode set to my desktop's standards, there isn't any width stretching, but the tiles appear way too small. I want my tiles to be stretched, but equally. If I set the resolution to 800x600, the tiles are stretched to the size I want, but are too wide for my screen and appear as rectangles. I have a very wide HD monitor.

How can I make sure that all my users get a resolution without width stretching and without it being the desktop's default mode?

12
Graphics / Trying to boost FPS to a safe amount
« on: July 30, 2012, 04:07:54 am »
I'm constantly getting a good 90+ uncapped FPS in my tile-based game, but I really want to get that number higher to allow room for more things to get rendered besides just the tiles.

As of right now, I'm storing all of my tiles in a 2D vector of a tile struct, which contains 3 ints (X, Y, and ID). Each draw call, it goes through all the tiles in the 2D vector and draws the ones that are within the camera bounds. It draws each tile separately. Here is what it looks like:

if(loaded)
        {
                sf::Sprite sprite;

                for(int x = 0; x <= width - 1; x++)
                {
                        for(int y = 0; y <= height - 1; y++)
                        {
                               
                                if ( ((ent::camera.x) <= (x * getTileH()) + 32) && ((x * getTileH()) < (ent::camera.x + gl::Vars::screenW)) && (( (ent::camera.y) <= ( y * getTileW()) + 32) && (( y * getTileW()) < (ent::camera.y + gl::Vars::screenH))))
                                {
                                        sprite.setTexture(*textures.at(map[x][y]->ID));
                                        sprite.setPosition(x * tileW, y * tileH);
                                        gl::Win.draw(sprite);
                                }
                        }
                }
        }
 

Would it be faster to render all of my tiles and changes to a sprite and then render one huge sprite at once every loop instead of 50 individual renders? My games aims to be a HUGE world (nearly infinite) and be changeable. Tons of tiles will have a chance to be changed each loop due to people either digging or modifying them in some way related to the game (I hate to say this, but think of Terraria).

What's the best way to do this for my game? It's not a typical ORPG pre-made map. There are many changes to the map on the fly.

Also, do you guys have any other tips for boosting FPS? My aim is to get it over 400 uncapped.

Pages: [1]