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

Pages: [1]
1
Network / Re: Need clarification on sf::Packet << char * operator
« on: March 28, 2018, 03:40:14 pm »
On little endian machine:
Quote
(data >> 56) is the most significant byte, we put it in first position of the byte array so we get MSB-first which is big endian.
Since we're on little endian, it was originally at the end of the memory space used by "data", so we're actually swapping

On big endian machine:
Quote
(data >> 56) is the most significant byte, we put it in first position of the byte array so we get MSB-first which is big endian.
Since we're on big endian, it was originally at the beginning of the memory space used by "data", so we're actually not changing anything

What you missed is that it's the compiler which already interprets the byte order to give us the MSB when we do (data >> 56).

Ok this makes way more sense. Thanks. I was misinterpreting the code and assuming that the bytes were always being reversed.

2
Network / Re: Need clarification on sf::Packet << char * operator
« on: March 28, 2018, 01:29:42 am »
The easiest is to just check the source code, it's very simple to read and understand: https://github.com/SFML/SFML/blob/master/src/SFML/Network/Packet.cpp#L494

And yes it's about null-terminated strings.
Use the overload you mentioned for sending binary data.

Thank you this was very helpful. I wasn't sure if I should make a new thread or use this same thread, but I had a question regarding the source code.

In the following code, is it not problematic that the code assumes that the processor stores the integer in little endian format and needs to convert the integer from big endian (network byte order) to little endian (assumed machine byte order)?

Code: [Select]
Packet& Packet::operator >>(Uint64& data)
{
    if (checkSize(sizeof(data)))
    {
        // Since ntohll is not available everywhere, we have to convert
        // to network byte order (big endian) manually
        const Uint8* bytes = reinterpret_cast<const Uint8*>(&m_data[m_readPos]);
        data = (static_cast<Uint64>(bytes[0]) << 56) |
               (static_cast<Uint64>(bytes[1]) << 48) |
               (static_cast<Uint64>(bytes[2]) << 40) |
               (static_cast<Uint64>(bytes[3]) << 32) |
               (static_cast<Uint64>(bytes[4]) << 24) |
               (static_cast<Uint64>(bytes[5]) << 16) |
               (static_cast<Uint64>(bytes[6]) <<  8) |
               (static_cast<Uint64>(bytes[7])      );
        m_readPos += sizeof(data);
    }

    return *this;
}

Similarly, when appending an 8 byte integer, this same idea is applied. Is it not an issue that the code is just assuming that the machine stores integers in little endian format and will need to convert them to big endian or is there just something I am not understanding?

Code: [Select]
Packet& Packet::operator <<(Uint64 data)
{
    // Since htonll is not available everywhere, we have to convert
    // to network byte order (big endian) manually
    Uint8 toWrite[] =
    {
        static_cast<Uint8>((data >> 56) & 0xFF),
        static_cast<Uint8>((data >> 48) & 0xFF),
        static_cast<Uint8>((data >> 40) & 0xFF),
        static_cast<Uint8>((data >> 32) & 0xFF),
        static_cast<Uint8>((data >> 24) & 0xFF),
        static_cast<Uint8>((data >> 16) & 0xFF),
        static_cast<Uint8>((data >>  8) & 0xFF),
        static_cast<Uint8>((data      ) & 0xFF)
    };
    append(&toWrite, sizeof(toWrite));
    return *this;
}

Edited to fix errors in post.

3
Network / Need clarification on sf::Packet << char * operator
« on: March 27, 2018, 04:26:11 pm »
I am trying to understand how something works in the SFML library and replicate it outside of the library for learning purposes.

With this operator
Code: [Select]
Packet & operator<< (const char *data)
Does it assume that the data is a null terminated string or can this be used for a buffer of data from a binary file?

I was under the impression that the only way to append raw chunks of data would be to use something like
Code: [Select]
void append (const void *data, std::size_t sizeInBytes)
but I just wanted to get clarification. Thanks so much.


Edit: If the append function is meant to be used, how would a chunk of data be retrieved in the same manner for an incoming packet?

4
Thank you very much both of you for your replies! It makes more sense now.

5
Graphics / Getting strange Frames Per Second results (Pics included)
« on: April 03, 2016, 10:33:37 pm »
So, when I insert a Sleep(1) command in my loop that is polling/rendering for my window, I get about 100 fps as shown in this image.




However, when I remove the sleep command, I get about 8,300 FPS as shown in this image.



I am trying to understand why putting Sleep(1) takes my fps from 8300 down to 100. I would think that it would take it down to a bit under 1000 if it is normally 8,300 since there are 1,000 miliseconds in one second and Sleep(1) is only sleeping for 1 milisecond.

This is not a serious problem, but I am just curious as to why this happens if anybody knows. I included the Sleep there because I didn't want to put too much strain on the CPU. I didn't think it would reduce the fps by that much though.



Edit (4:56PM) - Well I just tried it again, and now i'm getting around 1000 fps with Sleep(1). It's just strange because after a few tries my fps will go back down to 100 for a few executions and then it will go back to 1000.


6
General / Weird Vector problem [Video/Source Included]
« on: April 20, 2015, 01:46:41 am »
Solved: I feel so stupid... I was debugging in release and that's why I was getting the unexpected behavior. Thanks for looking at it anyone who did sorry for wasting your time.  :-[

I am really dumbfounded on what is going on. The video explains the issue if you would like to see exactly what i'm encountering. Everything I have is encapsulated inside of my game class as far as rendering/sf objects such as rectangleshapes, texts, lines, etc. I added a
Code: [Select]
std::vector<int> IntegerVector; to my Game class, and the vector is constantly being modified/corrupted it seems. I don't know if it's a SFML thing or what, because I have done similar things using directx instead of SFML and never ran into this issue. (Having vectors inside of the game class randomly changing that is and also having the code randomly jump around)

Video highlighting issue:

You will probably have to select 1080p if it isn't on by default to be able to read the text.

Link to the source solution .rar: http://www.freewebs.com/smurf-job/SFML%20Template.rar

I would really appreciate it if anyone has a clue as to what is going on.

Thanks

7
Is this what you wanted me to upload?

8
I just upgraded to SFML 2.2, but I had this issue with other versions of SFML also. In the release executable, the exception doesn't pop up as it's just an exception message from debugging, but I didn't know if this was something I should be trying to avoid or not. If I don't use any Sound related classes, I get no exception issues.

9
Does anyone know if this is expected behavior or am I doing something wrong before leaving the scope?

Here is the code i'm using
Code: [Select]
#include <SFML/Audio.hpp>
#include "SFML/Config.hpp"
#include <Windows.h>
#include <iostream>
#include <string>

int main()
{
sf::SoundBuffer Example;
return 0;
}


Here's an image of the exception I get after the function returns once I exit the program. Is there something I should be doing to stop this from happening or is this expected behavior? Also note that I tested this with other objects such as the sf::Sound, sf::SoundBufferRecorder and even more and they all caused the same exception to occur once I exit the program. It is odd to me since I am under the assumption that it is not the destructor causing the issue since the following code does not cause an exception after the scope of the ExampleFunc() function is left. It only causes the exception once the program ends.
Code: [Select]
#include <SFML/Audio.hpp>
#include "SFML/Config.hpp"
#include <Windows.h>
#include <iostream>
#include <string>

void ExampleFunc()
{
sf::SoundBufferRecorder Example;
}

int main()
{
ExampleFunc(); //This executes fine
return 0; //After returning, once the program ends I get the exception
}

10
Audio / Re: Not able to get SoundRecorder Documented example to compile
« on: February 19, 2015, 12:41:34 pm »
Quote
sf::SoundRecorder::start() doesn't have the return tpye void but bool, as such you can certainly check whether it started or not.
Only in SFML 2.2, and the OP is using SFML 2.1. However the doc for 2.1 is correct and doesn't contain the line of code that tests the return value of recorder.start().

Ah this makes sense then.

Thanks a lot both of you! I appreciate your time and i'll upgrade to 2.2 and work through it that way.

11
Audio / Not able to get SoundRecorder Documented example to compile
« on: February 19, 2015, 11:45:11 am »
Just started looking into the audio buffer for SFML 2.1 to try to record from my microphone and play it back in a stream.

However, i'm having issues even getting the basics compiled before even getting to what i'm trying.

I don't have much experience with virtual void functions, but I basically copy/pasted the code from
http://www.sfml-dev.org/documentation/2.1/classsf_1_1SoundRecorder.php
and i'm not having any luck.

A few problems i'm having.
Code: [Select]
if (!recorder.start())start is a void function, so I can't check if it returns true or false since it returns nothing, but the code on the example used it

Code: [Select]
virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount)My compiler isn't recognizing Int16 as a data type. I tried to figure out which header this would be included in, and I wasn't having any luck. I just changed it to UINT16* for now in my code, but i'm not sure if these are the same.

Here is my code
Code: [Select]
#ifdef SFML_STATIC
#pragma comment(lib, "glew.lib")
#pragma comment(lib, "freetype.lib")
#pragma comment(lib, "jpeg.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "gdi32.lib")
#endif // SFML_STATIC

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Window.hpp>
#include <Windows.h>
#include <iostream>
#include <string>

using namespace std;

class CustomRecorder : public sf::SoundRecorder
{
virtual bool onStart() // optional
{
// Initialize whatever has to be done before the capture starts
// Return true to start playing
return true;
}
virtual bool onProcessSamples(const UINT16* samples, std::size_t sampleCount)
{
// Do something with the new chunk of samples (store them, send them, ...)
// Return true to continue playing
return true;
}
virtual void onStop() // optional
{
// Clean up whatever has to be done after the capture ends
}
};


int main()
{
if (CustomRecorder::isAvailable())
{
CustomRecorder recorder; //Error #1
if (!recorder.start()) //Error #2
return -1;
recorder.stop();
}
return 0;
}

Error #1
Quote
   1   IntelliSense: object of abstract class type "CustomRecorder" is not allowed:
            pure virtual function "sf::SoundRecorder::onProcessSamples" has no overrider   c:\Users\Jacob\Documents\Visual Studio 2013\Projects\SFMLGame\SFMLGame\Main.cpp   44   18   SFMLGame

Error #2
Quote
   2   IntelliSense: expression must have bool type (or be convertible to bool)   c:\Users\Jacob\Documents\Visual Studio 2013\Projects\SFMLGame\SFMLGame\Main.cpp   45   8   SFMLGame

Thanks for taking the time to read. Any input is appreciated. I just want to be able to get this compile so I can try to learn how to record and play to/from streamed audio buffers so that I can work on a basic voip later. Just really new to sound buffers and SFML.

Pages: [1]