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

Pages: [1] 2
1
Here is the log:
http://pastebin.com/raw.php?i=UMB8UhdE

I googled around a bit, and found that you can define a macro that makes the compiler stop giving an error: _CRT_SECURE_NO_WARNINGS, but even after putting this in the preprocessor defines, it still gives the same error.
Similar errors for the audio module as well.

Edit: maybe I should have read the forums with more attention before posting  ;D
For anyone else wondering, I decided to use the nightly builds at http://www.nightlybuilds.ch/

2
General / Re: View frustum culling with a vertex array of tiles?
« on: April 07, 2015, 03:42:54 pm »
Damn, this is good news! Thanks for the fast reply and sorry for being stupid :(

3
General / View frustum culling with a vertex array of tiles?
« on: April 07, 2015, 03:16:52 pm »
I googled around a bit, but I couldn't find anything.

Any idea if this is possible? (Drawing just a part of a vertex array?)

4
Network / Re: selector.isReady(client) returns false every time
« on: November 23, 2014, 04:27:07 pm »
Thanks! I added selector.wait(), and now it works. But there's a problem!
I call this code every frame, and now it's blocking input. What can I do?

edit:
I removed selector.wait() and the check for selector.isReady() completely, and then set the client as non-blocking, and it seems to work!
Please tell me if what I'm doing is bad, lol

5
Network / selector.isReady(client) returns false every time
« on: November 23, 2014, 03:38:50 pm »
Hi there! I followed the usage example from here: http://sfml-dev.org/documentation/2.0/classsf_1_1SocketSelector.php

Here is the server-side code:
(click to show/hide)

And the client-side code:
(click to show/hide)

I run the server, then run the client, it connects successfully, but when I try to send the packet from the client to the server, it gets sent but not received by the server, which means getting bombarded with "selector no worko", signifying that selector.isReady(client) is always false, even when data is sent to one of the clients.

Any ideas?

PS: Tell me if i forgot to provide anything essential!

6
Audio / Re: sf::Music setPlayingOffset() - big latency?
« on: November 03, 2014, 05:14:08 pm »
No, I am using the copy from the main page. Should I grab the latest version?

7
Audio / sf::Music setPlayingOffset() - big latency?
« on: November 03, 2014, 03:59:55 pm »
Using setPlayingOffset() to seek through a short song (1 min) works with no noticeable latency, however when I try a longer (5.5 min) song it lags for about 2 seconds before resuming playback. Should this be happening? Can it be fixed, should I use sf::Sound, or what?

Not sure if it helps much, but here's the code where I call the function:
...
sf::Time t = sf::seconds(music.getDuration().asSeconds() * barPerc);
music.setPlayingOffset(t);
...
 

Please do tell if you need anything else!

8
I managed to fix it. To anyone else that might be wondering about this, here's the issue:
I took a look at the SFML socket example in more detail, and noticed that you have to alternate the sending and receiving for server and client:
Example:
server:
 - first sends, then receives
client:
 - first receives, then sends
This fixed the issue, and now it's no longer laggy AT all.
Here's a pastebin of the fixed code if anyone needs it:
http://pastebin.com/GHTif2Xj

9
I'll change it to non-blocking later, I think, after I get these working... :)
added an error message for when connect() fails.
unfortunately, nothing at all gets printed when i run both the server and the client. it's still waiting for a connection i presume (from the blocking aspect of the socket) but no error messages are displayed

10
Network / Server and client can't both send and receive at the same time?
« on: October 24, 2014, 07:35:55 pm »
The code in its current form works, (with the server that ONLY receives data, and the client only SENDING data) but if you uncomment the currently commented blocks (server receives data and sends it back, and the client the same), it doesn't send or receive anything anymore...

#include <iostream>
#include <SFML/Network.hpp>
#include <SFML/Graphics.hpp>
#include <winsock2.h>

using std::cout;
using std::cin;

class Player
{
public:
    Player();

    int x, y;
    sf::RectangleShape shape;
};

Player::Player()
{
    x = y = 0;
    shape.setFillColor(sf::Color::White);
    shape.setSize(sf::Vector2f(50, 100));
}

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
    window.setVerticalSyncEnabled(true);
    bool isServer = false;
    cout << "Server/Client ? 1/0\n";
    cin >> isServer;

    if (!isServer)
    {
        sf::Int32 datax;
        sf::Int32 datay;
        Player player1, player2;
        player2.shape.setFillColor(sf::Color::Red);

        sf::TcpSocket socket;
        sf::Socket::Status status = socket.connect("localhost", 53000);
        if (status != sf::Socket::Done)
        {
            // error...
        }

        while (window.isOpen())
        {
            sf::Event event;
            while (window.pollEvent(event))
            {
                // Close window : exit
                if (event.type == sf::Event::Closed)
                    window.close();
                if (event.type == sf::Event::KeyPressed)
                {
                    if (event.key.code == sf::Keyboard::W)
                    {
                        player1.y--;
                    }
                    if (event.key.code == sf::Keyboard::S)
                    {
                        player1.y++;
                    }
                    if (event.key.code == sf::Keyboard::A)
                    {
                        player1.x--;
                    }
                    if (event.key.code == sf::Keyboard::D)
                    {
                        player1.x++;
                    }
                }
            }

            sf::Packet packet2;
//            if (socket.receive(packet2) != sf::Socket::Done)
//            {
//                cout << "Couldn't recieve data from server.\n";
//            }
//            else
//            {
//                cout << "Recieved data from server.\n";
//            }

            sf::Int32 enemydatax, enemydatay;
            packet2 >> enemydatax, enemydatay;
            player2.x = enemydatax;
            player2.y = enemydatay;
            player2.shape.setPosition(player2.x, player2.y);
            player1.shape.setPosition(player1.x, player1.y);
            window.clear(sf::Color::Black);

            window.draw(player2.shape);
            window.draw(player1.shape);
            window.display();

            //Send our clients position to the server
            sf::Packet packet1;
            datax = player1.x;
            datay = player1.y;
            packet1 << datax << datay;

            // TCP socket:
            if (socket.send(packet1) != sf::Socket::Done)
            {
                cout << "Couldn't send data to server.\n";
            }
            else
            {
                cout << "Sent data to server.\n";
            }
        }
    }
    else
    {
        sf::TcpListener listener;
        sf::Int32 datax;
        sf::Int32 datay;
        Player player1, player2;
        player2.shape.setFillColor(sf::Color::Red);

        // bind the listener to a port
        if (listener.listen(53000) != sf::Socket::Done)
        {
            cout << "Error: No connections.\n";
        }

        // accept a new connection
        sf::TcpSocket client;
        if (listener.accept(client) != sf::Socket::Done)
        {
            cout << "error client\n";
        }


        while (window.isOpen())
        {
            sf::Event event;
            while (window.pollEvent(event))
            {
                // Close window : exit
                if (event.type == sf::Event::Closed)
                    window.close();
                if (event.type == sf::Event::KeyPressed)
                {
                    if (event.key.code == sf::Keyboard::W)
                    {
                        player1.y--;
                    }
                    if (event.key.code == sf::Keyboard::S)
                    {
                        player1.y++;
                    }
                    if (event.key.code == sf::Keyboard::A)
                    {
                        player1.x--;
                    }
                    if (event.key.code == sf::Keyboard::D)
                    {
                        player1.x++;
                    }
                }
            }
            sf::Packet packet2;
            if (client.receive(packet2) != sf::Socket::Done)
            {
                cout << "Couldn't recieve data from client.\n";
            }
            else
            {
                cout << "Recieved data from client.\n";
            }

            sf::Int32 enemydatax, enemydatay;
            packet2 >> enemydatax;
            packet2 >> enemydatay;
            cout << "enemy x: " << enemydatax << std::endl;
            cout << "enemy y: " << enemydatay << std::endl;
            player2.x = enemydatax;
            player2.y = enemydatay;
            player2.shape.setPosition(player2.x, player2.y);
            player1.shape.setPosition(player1.x, player1.y);
            window.clear(sf::Color::Black);

            window.draw(player2.shape);
            window.draw(player1.shape);
            window.display();

            //Send our clients position to the server
            sf::Packet packet1;
            datax = player1.x;
            datay = player1.y;
            packet1 << datax << datay;


//            if (client.send(packet1) != sf::Socket::Done)
//            {
//                cout << "Couldn't send data to client.\n";
//            }
//            else
//            {
//                cout << "Data sent to client.\n";
//            }

        }
        // use "client" to communicate with the connected client,
        // and continue to accept new connections with the listener
    }
}

11
General / Generating cmake config files from a codeblocks project?
« on: September 22, 2014, 03:55:22 pm »
This may be a stupid question, but is something like this possible?

12
Graphics / Re: Dynamic Tile Map
« on: June 30, 2014, 11:57:09 am »
Maybe I'm misunderstanding this VertexArray, but I reconstruct it each loop because it changes in the meantime...?
If any of the tiles change (or the player moves), the vertex array has to be reconstructed, right?

Oh, that's a leftover from when the if did have code to execute... it doesn't make any difference so I just left it like that for now

13
Graphics / Re: Dynamic Tile Map
« on: June 30, 2014, 10:52:58 am »
Here's the tutorial in question from the SFML wiki : http://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php#example-tile-map

Here's the load() function that I modified (this gets called every game loop):

http://pastebin.com/GHrVmttD

As you can see I've moved the tileset loading and vertex array resizing to outside this for better performance.

And here's the main render function:

http://pastebin.com/1VTx3vkS

14
Graphics / Dynamic Tile Map
« on: June 30, 2014, 09:31:14 am »
The tile map in the tutorial is static, right? I was wondering, for a dynamic map, what changes would you need to make to the load() function to further optimize it? So far i've put the function that loads the tileset into a constructor, so it doesn't get loaded every cycle, but the performance is still pretty poor (around 40-50 fps on a 10x10 map, but also 40-50fps on a 100x100 map).

Is there anything else you'd recommend?

Also, is this a bad approach? What's the best way to render a map of dynamic NPCs?
is there a way to only redraw the tiles that have been modified in the vertex array? and leave everything else static?

15
Graphics / Joystick (?) functions slowing down program
« on: June 28, 2014, 06:47:02 pm »
My tile-based game was abnormally slow, so I decided to profile it a bit to see where the slowness comes from. I commented out everything in the render loop (only clear() and display() left), so just the event processing is in use... It only gets about 150 fps.
Here is the profiler information. Any idea what's up with the joystick functions?
http://pastebin.com/Hp5QJfBk

edit:
I've commented out the event processing as well and it's still 150 fps. What gives?

edit 2:
alright mates i tested it on a more powerful computer and the performance is way better (5100 fps) so it looks like my laptop is just very bad.

Pages: [1] 2
anything