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

Pages: [1] 2
1
Network / Re: Bytes sent is greater than MaxDatagramSize
« on: March 11, 2017, 04:02:59 am »
Ignore this, I figured out my issue... I mistyped and was writing to p instead of p2. 

2
Network / Bytes sent is greater than MaxDatagramSize
« on: March 11, 2017, 03:57:08 am »
I am trying to set up a simple packet communication between a server and client.  However, I keep getting this printing from the client console:

Cannot send data over the network (the number of bytes to send is greater than sf::UdpSocket::MaxDatagramSize)

This seems suspicious as I am sending very little data through these packets.  Below is what I am using for network handling (for now):

Code: [Select]
NetworkHandler::NetworkHandler(IpAddress server, int serverPort, int myPort) : mThread(&NetworkHandler::handleNetworking, this)
{
mServerIp = server;
mServerPort = serverPort;
mMyPort = myPort;

mSocket.bind(myPort);
mThread.launch();
}

void NetworkHandler::handleNetworking()
{
cout << sf::UdpSocket::MaxDatagramSize << endl;
Packet p;
p << "newclient" << "charsmud";

Socket::Status s = mSocket.send(p, mServerIp, mServerPort);

while (true)
{
for (int i = 0; i < 10; i++)
{
if (i == 9)
{
Packet p2;
p << "pinger";
Socket::Status l = mSocket.send(p, mServerIp, mServerPort);
}
}
}
}

Both s and l both give back Done.  I haven't run the for loop too many iterations, but l is giving me Done every time.

3
Graphics / Drawing text over a period of time
« on: December 22, 2014, 03:34:02 am »
I am trying to get text to draw one character at a time over an indeterminate period of time.  However, it seems there isn't a way to append strings using sf::Text;  any suggestions of how to do this?

4
Graphics / Re: Drawing using RenderTarget not Drawing to Window
« on: December 03, 2014, 01:50:10 am »
Seems like the mText(text, font, textSize) was causing the problem.  Setting the constructor to mText() and filling in with the methods fixed the problem.  :)

5
Graphics / Re: Drawing using RenderTarget not Drawing to Window
« on: December 03, 2014, 12:34:30 am »
Hm... When I switched over the target.draw(mSprite, states) to target.draw(mText, states), I get an Access violation reading location error.  Here is the stack call:

    sfml-graphics-d-2.dll!0f8ad316()    
    [Frames below may be incorrect and/or missing, no symbols loaded for sfml-graphics-d-2.dll]   
    sfml-graphics-d-2.dll!0f8ab16e()    
    sfml-graphics-d-2.dll!0f8a8c5a()    
    sfml-graphics-d-2.dll!0f8a5f6d()    
    sfml-graphics-d-2.dll!0f8f76a6()    
    sfml-graphics-d-2.dll!0f8d4cc3()    
>   Byte.exe!TextElement::drawCurrent(sf::RenderTarget & target, sf::RenderStates states)  Line 22 + 0x19 bytes   C++
    Byte.exe!TextWindow::drawCurrent(sf::RenderTarget & target, sf::RenderStates states)  Line 29 + 0x3c bytes   C++
    Byte.exe!SceneNode::draw(sf::RenderTarget & target, sf::RenderStates states)  Line 55 + 0x2c bytes   C++
    Byte.exe!SceneNode::drawChildren(sf::RenderTarget & target, sf::RenderStates states)  Line 67 + 0x3b bytes   C++
    Byte.exe!SceneNode::draw(sf::RenderTarget & target, sf::RenderStates states)  Line 57   C++
    Byte.exe!SceneNode::drawChildren(sf::RenderTarget & target, sf::RenderStates states)  Line 67 + 0x3b bytes   C++
    Byte.exe!SceneNode::draw(sf::RenderTarget & target, sf::RenderStates states)  Line 57   C++
    sfml-graphics-d-2.dll!0f8d4cc3()    
    Byte.exe!World::draw()  Line 51 + 0x43 bytes   C++
    Byte.exe!GameState::draw()  Line 14   C++
    Byte.exe!StateStack::draw()  Line 33 + 0x23 bytes   C++
    Byte.exe!Application::render()  Line 100   C++
    Byte.exe!Application::run()  Line 73   C++
    Byte.exe!main()  Line 16   C++
    Byte.exe!__tmainCRTStartup()  Line 555 + 0x19 bytes   C
    Byte.exe!mainCRTStartup()  Line 371   C
    kernel32.dll!74c6338a()    
    ntdll.dll!77299f72()    
    ntdll.dll!77299f45()    

6
Graphics / Re: Drawing using RenderTarget not Drawing to Window
« on: December 03, 2014, 12:08:19 am »
void Application::render()
{
        mWindow.clear();

        mStateStack.draw();

        mWindow.setView(mWindow.getDefaultView());
        mWindow.draw(mStatisticsText);

        mGui.draw();

        mWindow.display();
}

I am able to draw other things to the screen except the TextElement inside of TextWindow.  Rendering sprites text, etc. work.

7
Graphics / Drawing using RenderTarget not Drawing to Window [SOLVED]
« on: December 02, 2014, 03:57:22 am »
I am attempting to store a variable amounts of objects inside of another and iterate through the list, drawing each as I go.  Currently, the objects do iterate through and the drawCurrent method does indeed run, but nothing is rendered besides the base that the other objects (called Elements) should be rendering on.  Here are related files:

#pragma once

#include "Element.hpp"
#include <SFML/Graphics/Text.hpp>
class TextElement : public Element
{
        public:
                TextElement(sf::String text, sf::Font font, int charSize, int xOrig, int yOrig, int xPos, int yPos);
                virtual void drawCurrent(sf::RenderTarget& target, sf::RenderStates states) const;
                virtual void updateCurrent(sf::Time dt);

private:
        sf::Texture mTexture;
        sf::Sprite mSprite;
        sf::Text mText;
        int xpos, ypos;
};
#include "TextElement.hpp"
#include "ResourceIdentifiers.hpp"
#include <iostream>

TextElement::TextElement(sf::String text, sf::Font font, int textSize, int xOrig, int yOrig, int xPos, int yPos)
: mText(text, font, textSize)
, xpos(xPos)
, ypos(yPos)
, mSprite(mTexture)
{

        mTexture.loadFromFile("Media/Textures/Raptor.png");
        mSprite.setTexture(mTexture);
        mSprite.setOrigin(100, 100);
        mText.setOrigin(xOrig, yOrig);
        mText.setColor(sf::Color::Green);
}

void TextElement::drawCurrent(sf::RenderTarget& target, sf::RenderStates states) const
{
        std::cout << "TEXTELEMENT" << std::endl;
        target.draw(mSprite, states);
        std::cout << "DONE " << std::endl;
}
void TextElement::updateCurrent(sf::Time dt)
{
        //Do nothing, text doesn't need to update!
}
 

#include <SFML\Graphics\Sprite.hpp>
#include <SFML\Graphics\RenderStates.hpp>
#include <SFML\Graphics\RenderTarget.hpp>
#include <SFML\Graphics\Text.hpp>
#include <SFML\System\Time.hpp>
#include <SFML\Window\Window.hpp>

#include <list>

#include "Element.hpp"
#include "Entity.hpp"
#include "ResourceIdentifiers.hpp"
#include "TextElement.hpp"
class TextWindow : public Entity
{
        public:
                TextWindow(const TextureHolder& textures, const FontHolder& fonts, sf::Window& window, Fonts::ID fontID, sf::String text);

                void drawCurrent(sf::RenderTarget& target, sf::RenderStates states) const;
                void updateCurrent(sf::Time dt);
                void addElements(sf::String text, sf::Font font);

        private:
                sf::Sprite mSprite;
                int mHitpoints;
                sf::Window& mWindow;
                float xPos, yPos;
                std::list<std::unique_ptr<Element>> mElements;
};
 
#include "TextWindow.hpp"
#include "TextElement.hpp"

#include <iostream>

TextWindow::TextWindow(const TextureHolder& textures, const FontHolder& fonts, sf::Window& windows, Fonts::ID fontID, sf::String text)
: mSprite(textures.get(Textures::WindowDefault))
, mHitpoints(10)
, mWindow(windows)
{
        sf::FloatRect bounds = mSprite.getLocalBounds();
        mSprite.setOrigin(bounds.width / 2.f, bounds.height / 2.f);
        addElements(text, fonts.get(fontID));
}

void TextWindow::addElements(sf::String text, sf::Font font)
{
        std::unique_ptr<TextElement> e(new TextElement(text, font, 10, xPos, yPos, 10, 10));
        mElements.push_back(std::move(e));
}

void TextWindow::drawCurrent(sf::RenderTarget& target, sf::RenderStates states) const
{
        target.draw(mSprite, states);
        for(std::list<std::unique_ptr<Element>>::const_iterator iterator = mElements.begin(); iterator != mElements.end(); ++iterator)
        {
                //std::cout << "IN TEXTWINDOW PRINT ITERATOR" << std::endl;
                (*iterator).get()->drawCurrent(target, states);
        }

}

void TextWindow::updateCurrent(sf::Time dt)
{
}

8
General discussions / Networking Library
« on: August 20, 2014, 06:50:34 am »
I'm planning on adding networking support to my game in the form of one main server with each user receiving the client (Think League of Legends style client-server).  Will the SFML Networking be fine for this, or should I go for some other networking library? 

9
Network / Re: Managing multiple connections to the same port
« on: June 24, 2014, 08:46:42 pm »
Ok, I think I'm grasping this a bit better.  So, this pseudo-code seems like it would work?

sf::UdpSocket accept(sf::Packet packet)

//Takes data from the packet (the client IP, client port, server IP)
//finds an open port on the server
//creates a new socket


10
Network / Re: Server does not receive packets
« on: June 24, 2014, 08:36:14 pm »
You're not sending a packet, you're sending a string:

                std::string message = "Hi, I am a client";
                socket.send(message.c_str(), message.size() + 1);
 

Instead, send a Packet. 

sf::Packet packet;
packet << message;
socket.send(packet, sizeofpacket);
 

Of course, that's only pseudo code, but that's the jist of how it would work.

11
Network / Re: Managing multiple connections to the same port
« on: June 24, 2014, 08:32:08 pm »
Thanks!  I'm a little confused by the listening socket though, and how hat interacts with the unique sockets....  So, from what I understand, one socket listens for connections on the port (1234).  However, I'm a bit confused on what occurs when a client connects, and how I would create the unique socket for the client... It might also be good to note that I'm using UDP.  Should I use TCP for my heartbeats and UDP for the actual game?

12
Network / Managing multiple connections to the same port
« on: June 24, 2014, 08:14:36 pm »
I am implementing a heartbeat interface for my server, and have run across the following problem.  I am managing the heartbeat on a specific port number.  When a user connects, the server establishes a heartbeat object for that client, and in that class a "connection" is established with the client.  However, because I am handling it on one specific port, if another user trys to connect, the heartbeat cannot be created and tells me that the port is in use, as it should.  I'm stuck on trying to figure out if there is a way to allow for multiple sockets to connect to the same port.  If this is simply not possible, how else could I implement the heartbeat?

13
System / Re: Thread Overriding Main (?)
« on: June 22, 2014, 10:01:40 pm »
That line should create the heartbeat object
But it does not store it in the unique pointer. I wonder why this even compiles, maybe an overloaded operator() in the standard library?

The container will not accept the unique pointer,  so could I pass a memory address to it?
No... But you have to tell me what you want to do (semantically), not vice versa. Either you want to store it in the container, and then you make it work, or you don't...

The thread creation code is in the constructor of Heartbeat. I need the array to hold the unique pointer for use later.

14
System / Re: Thread Overriding Main (?)
« on: June 22, 2014, 09:06:03 pm »
mBeat(new Heartbeat(player.getIp()));
What should this line do? Did you mean to call reset()?

And I thought you want to add the heartbeat object to a container, not store it as single member, don't you?
That line should create the heartbeat object and the object initialization should start the thread.  The container will not accept the unique pointer,  so could I pass a memory address to it?

15
System / Re: Thread Overriding Main (?)
« on: June 22, 2014, 08:22:51 pm »
It would create a new instance every time, and lead to a memory leak.

Avoid raw new and delete and use RAII (here std::unique_ptr) instead. Or consider the alternative in my last post: move semantics.

Thanks for the link, very interesting!  I might be missing something though, because my implementation does not seem to work; it still follows the problem of the original post.  Here is the updated block:

void ClientHandler::addConnection(PlayerSession player)
{
        mUsers.push_back(player);
        mBeat(new Heartbeat(player.getIp()));
        //mHeartbeat.push_back(mBeat);
        std::cout << "Finished adding connection + started heartbeat!" << std::endl;
}
private:
        std::unique_ptr<Heartbeat> mBeat;

Pages: [1] 2