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

Pages: [1] 2
1
General / Re: Issues with Audio module
« on: May 26, 2017, 01:32:25 pm »
Wiki, forum and youtube "tutorials" are not tutorials. They may help at some point, but they are also possibly wrong, and most likely outdated. The only reference is the official set of tutorials and API documentation on the official website.

Yes, very true. The only reason I used that tutorial is because I hadn't used Eclipse in a while and Windows was being an ass pain (I usually develop in Linux). So I went to a tute that was specific for my IDE to help move things along. Was my mistake.

2
General / Re: Issues with Audio module
« on: May 26, 2017, 01:24:48 pm »
The tutorial you followed is outdated. Look at the dependencies mentioned in the getting started tutorial instead (the tutorial is not for eclipse, but the dependencies are the same).

Thanks, that tutorial was outdated and I wasn't including all the FLAC and vorbis dependencies required (as per the your link). Cheers guys!

3
General / Re: Issues with Audio module
« on: May 26, 2017, 12:08:06 pm »
Can you show your linker settings?

these are my Eclipse includes (attached)

4
General / Re: Issues with Audio module
« on: May 26, 2017, 11:15:00 am »
You probably forgot to link to FLAC libraries. Look at the list of dependencies (in the getting started tutorial) to link when you use SFML statically.

I've linked every library that's in that tutorial (and from the SFML documentation, it says everything you need for development in a Windows environment is included in the SFML library, so do I need to include something that's not in that list?)

5
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?

6
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!

7
General / Re: Jump height varies slightly
« on: May 14, 2017, 06:36:26 am »
Most monitors have a 60 fps refresh rate, and given that you have a linear velocity speed, then the highest point of the jump will be quite sharp and happening in single distinct frame, so at fps more than 60, that frame could be in one of the frames skipped by your monitor, so you won't see it and think the jump was shorter than the other times you see it when it is aligned with the 60 refresh rate.

Yeah I think that's it. I'll just stick to 60 for now.

I don't know if it's related to the problem or not, but this caught my attention:

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

You are passing "accumulatedTime" to your update function. Shouldn't you pass "frameRate" instead?

That was just for debugging so I could print out the time each update to make sure it was consistent. I've removed that now.

8
General / Re: Jump height varies slightly
« on: May 13, 2017, 11:16:45 am »
I can fix it by decreasing the FPS slightly. I had it at 100 FPS originally (0.01). Decreasing it to around 75 fixes it. Guess that from 75+ it starts to get a bit too intense to keep track of (which is weird, since there's hardly anything happening in the game, I have a high end computer and the numbers seemed to be within reason) but oh well. Guess I'll just stick to 60

9
General / Re: Jump height varies slightly
« on: May 13, 2017, 09:57:43 am »
But I do. If you look in the last code sample (the collision one) I set the position of the character using the world sprite they collide with as a reference. Plus I can see from the character sprite that it's always in the same spot when I land/jump.

10
General / Re: Jump height varies slightly
« on: May 13, 2017, 09:10:58 am »
Yeah since it gets called dozens of a time a second I could only give a small snippet of the output. That's from when it was descending back down.

For activating the jump, there is this in the main loop:
        while (window.pollEvent(event)) {
                ...
                // Parse user input
                game.parseEvent(event);
       
        }

 

The parseEvent() function is thus:
void parseEvent(sf::Event event){
        this->inputTracker->handleInput(event);
        if (this->characterManager->getPlayer()->getIsJumping() == false && this->inputTracker->didPlayerJump() == true) {
                this->characterManager->getPlayer()->setYVelocity(this->characterManager->getPlayer()->getJumpHeight());
                this->characterManager->getPlayer()->setIsJumping(true);
        }
};
 

  • handleInput(event) just records which key was pressed and stores it in a boolean in the inputTracker
  • The if statement condition checks for if they're jumping and whether they pressed up.
  • If they did jump and they aren't already jumping, it sets the character's Y velocity to the jump height and records that they're jumping in a boolean

There's no real calculation for Y velocity, it's linear. As you can see in my original post, on every update if they aren't on the ground it just increments it by a variable called 'gravity' (which in this case is a float equal to 0.98f). In the character's update function I call applyGravity():
void applyGravity() {
        if (this->yVelocity < this->terminalVelocity && this->touchingBottom == false) {
                this->yVelocity += this->gravity;
        }
}
 



For collision with the ground, it's a bit hard to put the code as it's quite mostly just a bunch of maths related if statements, but essentially if the two objects are colliding and I calculate that it must be a collision on the bottom of the character, I execute this code:
// Below
touchingBottom = true;
if (allChars[i]->getYVelocity() > 0) {
        allChars[i]->setYVelocity(0);
}
allChars[i]->setPosition(
        /* X */ allChars[i]->getSprite()->getPosition().x,
        /* Y */ allWorldSprites[j]->getPosition().y-allChars[i]->getSprite()->getGlobalBounds().height/2 + 1
);
allChars[i]->setIsJumping(false);

...

allChars[i]->setTouchingBottom(touchingBottom);
 

 that's just the code for bottom collision

11
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?

12
General / Re: Firing is inconsistent despite using time
« on: May 02, 2017, 02:18:51 am »
Woops, look like I copied my gun code wrong, sorry:

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

I've fixed it in the post

13
General / Re: Firing is inconsistent despite using time
« on: May 01, 2017, 07:47:40 pm »
Well if the gun is ready I want to fire, else I don't want to do anything. So what does inverting the boolean condition achieve?

14
General / Re: Firing is inconsistent despite using time
« on: May 01, 2017, 01:53:13 pm »
Thanks for your feedback/

Well my code isn't very well structured since I'm just practicing with each different module rather than trying to actually build something properly. So my main loop has this:

Quote
while (window.isOpen()) {
        Event event;
        while (window.pollEvent(event)) {
            if (event.type == Event::Closed) {
                window.close();
                game.exit(&window);
            }
            game.parseEvent(event, &window);
        }

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

        game.update(&window, elapsed.asSeconds());
    }

game.parseEvent() checks if the keyboard/mouse buttons are being pressed (and set booleans accordingly). Then in game.update() I do all the logic, like moving the player, firing a bullet, checking collision between player and other objects, and finally moving the existing bullets (stored in a vector).

In this case I do the event processing (assuming some event has happened), THEN run the update code. So you're saying I should separate event processing and game updating? How would this be done?

15
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  :)

Pages: [1] 2