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

Pages: [1]
1
General / Issues with Audio module
« on: May 26, 2017, 10:54:38 am »
For reference, I used this tutorial: https://en.sfml-dev.org/forums/index.php?topic=17683.0

I've been using other SFML modules like System and Graphics with no issue. However, whenever I try to use something from the Audio module I get a bunch of undefined reference errors on building, e.g. ;

Quote
D:/sfml-release/_Sources/SFML/src/SFML/Audio/SoundFileReaderFlac.cpp:189: undefined reference to `FLAC__stream_decoder_new'
D:/sfml-release/_Sources/SFML/src/SFML/Audio/SoundFileReaderFlac.cpp:197: undefined reference to `FLAC__stream_decoder_init_stream'
D:/sfml-release/_Sources/SFML/src/SFML/Audio/SoundFileReaderFlac.cpp:200: undefined reference to `FLAC__stream_decoder_process_until_end_of_metadata'
D:/sfml-release/_Sources/SFML/src/SFML/Audio/SoundFileReaderFlac.cpp:203: undefined reference to `FLAC__stream_decoder_finish'
D:/sfml-release/_Sources/SFML/src/SFML/Audio/SoundFileReaderFlac.cpp:204: undefined reference to `FLAC__stream_decoder_delete'
C:\Users\Admin\Documents\SFML-2.4.2\lib/libsfml-audio-s-d.a(SoundFileReaderFlac.cpp.obj): In function `sf::priv::SoundFileReaderFlac::open(sf::InputStream&, sf::SoundFileReader::Info&)':
D:/sfml-release/_Sources/SFML/src/SFML/Audio/SoundFileReaderFlac.cpp:230: undefined reference to `FLAC__stream_decoder_new'
D:/sfml-release/_Sources/SFML/src/SFML/Audio/SoundFileReaderFlac.cpp:239: undefined reference to `FLAC__stream_decoder_init_stream'
D:/sfml-release/_Sources/SFML/src/SFML/Audio/SoundFileReaderFlac.cpp:242: undefined reference to `FLAC__stream_decoder_process_until_end_of_metadata'
C:\Users\Admin\Documents\SFML-2.4.2\lib/libsfml-audio-s-d.a(SoundFileReaderFlac.cpp.obj): In function `sf::priv::SoundFileReaderFlac::seek(unsigned long long)':
D:/sfml-release/_Sources/SFML/src/SFML/Audio/SoundFileReaderFlac.cpp:270: undefined reference to `FLAC__stream_decoder_seek_absolute'
C:\Users\Admin\Documents\SFML-2.4.2\lib/libsfml-audio-s-d.a(SoundFileReaderFlac.cpp.obj): In function `sf::priv::SoundFileReaderFlac::read(short*, unsigned long long)':
D:/sfml-release/_Sources/SFML/src/SFML/Audio/SoundFileReaderFlac.cpp:308: undefined reference to `FLAC__stream_decoder_process_single'
D:/sfml-release/_Sources/SFML/src/SFML/Audio/SoundFileReaderFlac.cpp:312: undefined reference to `FLAC__stream_decoder_get_state'
C:\Users\Admin\Documents\SFML-2.4.2\lib/libsfml-audio-s-d.a(SoundFileReaderFlac.cpp.obj): In function `sf::priv::SoundFileReaderFlac::close()':
D:/sfml-release/_Sources/SFML/src/SFML/Audio/SoundFileReaderFlac.cpp:325: undefined reference to `FLAC__stream_decoder_finish'
D:/sfml-release/_Sources/SFML/src/SFML/Audio/SoundFileReaderFlac.cpp:326: undefined reference to `FLAC__stream_decoder_delete'
C:\Users\Admin\Documents\SFML-2.4.2\lib/libsfml-audio-s-d.a(SoundFileReaderOgg.cpp.obj): In function `sf::priv::SoundFileReaderOgg::check(sf::InputStream&)':
D:/sfml-release/_Sources/SFML/src/SFML/Audio/SoundFileReaderOgg.cpp:77: undefined reference to `ov_test_callbacks'
D:/sfml-release/_Sources/SFML/src/SFML/Audio/SoundFileReaderOgg.cpp:79: undefined reference to `ov_clear'
C:\Users\Admin\Documents\SFML-2.4.2\lib/libsfml-audio-s-d.a(SoundFileReaderOgg.cpp.obj): In function `sf::priv::SoundFileReaderOgg::open(sf::InputStream&, sf::SoundFileReader::Info&)':
D:/sfml-release/_Sources/SFML/src/SFML/Audio/SoundFileReaderOgg.cpp:109: undefined reference to `ov_open_callbacks'
D:/sfml-release/_Sources/SFML/src/SFML/Audio/SoundFileReaderOgg.cpp:117: undefined reference to `ov_info'
D:/sfml-release/_Sources/SFML/src/SFML/Audio/SoundFileReaderOgg.cpp:120: undefined reference to `ov_pcm_total'

I'm using Eclipse Neon on Windows, I've included all the SFML modules in the Eclipse GCC C++ COmpiler and MinGW C++ linker settings the same way. Haven't had any issues with the library modules until this issue popped up.

Why is the undefined reference pointing to the D drive? Why doesn't the Audio module import work when all the other SFML modules worked?

2
General / Swept AABB collision
« on: May 20, 2017, 03:49:18 am »
I'm making a platformer and trying to implement swept AABB collision so that an entity's velocity doesn't cause it to skip over something it should collide with from one frame to the next. I'm using this tutorial: https://www.gamedev.net/resources/_/technical/game-programming/swept-aabb-collision-detection-and-response-r3084

I've modified the code from that for SFML usage. It works in the vertical axis, but it doesn't in the horizontal axis. It just doesn't trigger a collision (it doesn't return a value between 0 and 1, which is how a collision is indicated). The code for the function is like so:
float sweptAABB(Character* character, sf::Sprite* world, float& normalx, float& normaly) {
            float xInvEntry, yInvEntry;
            float xInvExit, yInvExit;
                sf::FloatRect worldBox = world->getGlobalBounds();
                sf::FloatRect charBox = character->getSprite()->getGlobalBounds();

            // find the distance between the objects on the near and far sides for both x and y
            if (character->getXVelocity() > 0.0f) {
                xInvEntry = worldBox.left - (charBox.left + charBox.width);
                xInvExit = (worldBox.left + worldBox.width) - charBox.left;
            }
            else {
                xInvEntry = (worldBox.left + worldBox.width) - charBox.left;
                xInvExit = worldBox.left - (charBox.left + charBox.width);
            }
            if (character->getYVelocity() > 0.0f) {
                yInvEntry = worldBox.top - (charBox.top + charBox.height);
                yInvExit = (worldBox.top + worldBox.height) - charBox.top;
            }
            else {
                yInvEntry = (worldBox.top + worldBox.height) - charBox.top;
                yInvExit = worldBox.top - (charBox.top + charBox.height);
            }

            // find time of collision and time of leaving for each axis (if statement is to prevent divide by zero)
            float xEntry, yEntry;
            float xExit, yExit;

            if (character->getXVelocity() == 0.0f) {
                xEntry = -std::numeric_limits<float>::infinity();
                xExit = std::numeric_limits<float>::infinity();
            }
            else  {
                xEntry = xInvEntry / character->getXVelocity();
                xExit = xInvExit / character->getXVelocity();
            }

            if (character->getYVelocity() == 0.0f) {
                yEntry = -std::numeric_limits<float>::infinity();
                yExit = std::numeric_limits<float>::infinity();
            }
            else {
                yEntry = yInvEntry / character->getYVelocity();
                yExit = yInvExit / character->getYVelocity();
            }

            // find the earliest/latest times of collision
            float entryTime = std::max(xEntry, yEntry);
            float exitTime = std::min(xExit, yExit);

            // if there was no collision
            if (entryTime > exitTime || (xEntry < 0.0f && yEntry < 0.0f) || xEntry > 1.0f || yEntry > 1.0f) {
                normalx = 0.0f;
                normaly = 0.0f;
                return 1.0f;
            }
            // if there was a collision
            else{
                // calculate normal of collided surface
                if (xEntry > yEntry) {
                    if (xInvEntry < 0.0f) {
                        normalx = 1.0f;
                        normaly = 0.0f;
                    }
                        else {
                        normalx = -1.0f;
                        normaly = 0.0f;
                    }
                }
                else {
                    if (yInvEntry < 0.0f) {
                        normalx = 0.0f;
                        normaly = 1.0f;
                    }
                        else {
                        normalx = 0.0f;
                                normaly = -1.0f;
                    }
                }

                // return the time of collision
                return entryTime;
            }
        }
 

Originally it was detecting collision on the horizontal axis, but it was doing so even when there was no collision on the y axis (i.e. the block could be well above the character and it would still stop it as if it was in front of the character) but after implementing the broadphase check (in that article tutorial I linked) that fixed that problem, but now it doesn't detect horizontal collision at all.

Been tinkering for past few days and can't figure out why this is  :( if needed I can post code from other sections but I get the feeling that this function is the one not working as it triggers in y axis but not x axis. Any insight would be greatly appreciated!

3
General / Jump height varies slightly
« on: May 13, 2017, 08:18:05 am »
I'm making a platform game and I have jumping and collision working. However, I've noticed that when I jump, the actual height my character reaches varies each time, by almost 10-15 pixels sometimes. It's quite noticeable

Originally I thought it's because I wasn't updating their position using a fixed frame time, but I have verified that I am. This is the relevant section of my main game loop:


        while (window.isOpen()) {
                ...
                if (gameIsClosing == false) {
                        if (accumulatedTime >= frameRate) {
                                game.draw(&window);
                                game.update(&window, accumulatedTime);
                                accumulatedTime -= frameRate;
                        }
                }
        }
 

In the game.update() function I call each character's update method, which in turn calls their move method:

        void move() {
                this->sprite->move(this->xVelocity, this->yVelocity);
        }
 

To try and see if this move function was being called at regular intervals and Y velocity was being updated by a regular amount I passed that interval down from the loop to the character and printed it out in the character's update function. This is the output:

Quote
Y velocity: 0.09600189
Time: 0.01000087

Y velocity: 0.19400188
Time: 0.01000049

Y velocity: 0.29200187
Time: 0.01000015

Y velocity: 0.39000186
Time: 0.01000078

Y velocity: 0.48800185
Time: 0.01000945

Y velocity: 0.58600187
Time: 0.01000008

Y velocity: 0.68400186
Time: 0.01000076

Y velocity: 0.78200185
Time: 0.01005336

It looks like the time interval is pretty constant @0.01 and the Y velocity is getting updated pretty much constantly @0.1

So why is the jump height varying so much each time?

4
General / Firing is inconsistent despite using time
« on: May 01, 2017, 12:14:25 pm »
I'm using the Clock class to get elapsed time and using that to try and standardise everything in my game based on time so it's consistent. However I'm having an issue with a gun Class (specifically cooldown for its firing)

This is the time code:

Quote
sf::Time elapsed = clock.getElapsedTime();

Then in my gun class:

Quote
void fire(float angle, Vector2f playerPos) {
        if (this->gunReady == true) {
            this->gunReady = false;
            // Play fire sound, create bullet, set position, etc.
        }
    }

    void updateBullets(float elapsed) {
        this->cooldownTime += elapsed;
        if (this->cooldownTime >= SHOT_COOLDOWN) {
            this->cooldownTime = 0.0f;
            this->gunReady = true;
        }
        for (auto &bullet : this->sprites) {
            // Move all the bullets
        }
    }

then in my firing function, i just check to see if this->gunReady is true before doing anything. There are two problems:

  • There is a noticeable inconsistency between shots (looks like it's changing based on FPS or some other non-static variable). sometimes it's the full cooldown time, other times it feels like two thirds the value, or longer
  • Secondly (and less importantly) the very first time I start spamming the mouse button, it fires a double shot (i.e. two shots within like 200ms of each other), then after that it starts the above behaviour, where the cooldown is only roughly the value I sent and is constantly undulating

Am I using the time functionality the wrong way?

Thanks  :)

5
General / Issue instantiating/using Text
« on: April 28, 2017, 07:04:35 pm »
Hey guys,

I'm having a mega headache using the Text class. Whenever I give this class a private Text member, it crashes when I try to run it:

Quote
class Score {
private:
    int score;
    Font* font;
    Text text;      <-------------- giving it a Text member
public:
    Score() {
        this->score = 0;
        this->font = new Font;
        this->font->loadFromFile("./sixty.tff");
    }
    string getScore() {
        return to_string(this->score);
    }
    void increaseScore() {
        this->score += 1;
    }
    void increaseScore(int n) {
        this->score += n;
    }
    Font getFont() {
        return *(this->font);
    }
};

It gives this error message:

Quote
*** Error in `./sfml-app': malloc(): memory corruption: 0x000000000108ac50 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f4c0516a7e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x8181e)[0x7f4c0517481e]
/lib/x86_64-linux-gnu/libc.so.6(__libc_malloc+0x54)[0x7f4c051765d4]
/usr/lib/x86_64-linux-gnu/libfreetype.so.6(ft_mem_qalloc+0xd)[0x7f4c0427cd7d]
/usr/lib/x86_64-linux-gnu/libfreetype.so.6(ft_mem_alloc+0x28)[0x7f4c0427cdd8]
/usr/lib/x86_64-linux-gnu/libfreetype.so.6(FT_New_Library+0x52)[0x7f4c0427d1d2]
/usr/lib/x86_64-linux-gnu/libfreetype.so.6(FT_Init_FreeType+0x24)[0x7f4c042783e4]
/home/ansah/Downloads/SFML-2.4.2/lib/libsfml-graphics.so.2.4(_ZN2sf4Font12loadFromFileERKSs+0x33)[0x7f4c05e96fe3]
./sfml-app[0x40357f]
./sfml-app[0x4036f8]
./sfml-app[0x402966]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f4c05113830]
./sfml-app[0x402619]
...
Aborted (core dumped)

But if I give other classes a Text member the program runs ok. Everything else in the program works, I;m compiling with these commands:

Quote
g++ -g -c -std=c++11 main.cpp
g++ main.o -o sfml-app -L/home/ansah/Downloads/SFML-2.4.2/lib -lsfml-graphics -lsfml-window -lsfml-system

I'm using Linux and I installed it via sudo apt-get command on the tutorial page. To run it I'm just using ./sudo-app and I;ve tried export LD_LIBRARY_PATH=/home/ansah/Downloads/SFML-2.4.2/lib && ./sfml-app with same results.

For context, I have a class called Game, and I can give that a Text member with no problems. That is also the class which contains a pointer member to a instance of the Score class above, i.e.

Quote
class Game {
private:
    ...
    Score* score;
    Text text;

public:
    Game(CircleShape* shapeInput) {
        ...
        this->score = new Score();
    }
...
}

That doesn't crash on running when I give it a Text member  :-\

I've followed the tutorial and tried the examples in that and looked at multiple forum posts, tried text pointers instead of members, but I can't figure out what's going wrong. Any suggestions welcome.

Pages: [1]