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

Pages: [1]
1
General / Transitioning from VS 2012 to VS Community 2013
« on: December 10, 2014, 08:48:03 am »
So I'm switching over to Visual Studio Community 2013, and I'm having some trouble setting it up. I downloaded the SFML 2.1 Binaries for VS 2013 from here. I got the template to work, but I'd like to know how to set it up myself as well. I'm following from what I usually do in VS 2012, but that doesn't seem to work. I'm comparing it to the template project settings, but I can't seem to find the issue. I'm getting the following error:

(click to show/hide)

2
General / Keeping mouse within window when dragging.
« on: March 15, 2014, 07:50:36 am »
I'm using borderless style for my window. I've set up an area where you can click and drag the window itself. My issue is keeping the mouse inside the window. I remember reading a reply in a thread about this too but still unsure of it.

int main (int argc, char **argv) {
    -- Snip --
    while (root.GetGameState() != Root::GameState::Quit) {
        switch (root.GetGameState()) {
            case Root::GameState::Menu:
                sf::Event currentEvent;
                while (root.GetRenderWindow()->pollEvent(currentEvent)) {
                    switch (currentEvent.type) {
                        case sf::Event::MouseButtonPressed:
                            Utilities::currentMouseButton = currentEvent.mouseButton.button;
                            Utilities::lastMousePosition = sf::Mouse::getPosition(*root.GetRenderWindow());
                            break;
                        case sf::Event::MouseButtonReleased:
                            Utilities::lastMousePosition = sf::Mouse::getPosition(*root.GetRenderWindow());
                            -- Snip --
                            break;
                        case sf::Event::MouseEntered:
                            Utilities::mouseWithinWindow = true;
                            break;
                        case sf::Event::MouseLeft:
                            Utilities::mouseWithinWindow = false;
                            break;
                        default:
                            break;
                    }
                    if (Utilities::IsMouseButtonHeld(sf::Mouse::Button::Left)) {
                        root.GetTitleBar()->HandleDrag(root.GetRenderWindow());
                    }
                }
                root.GetRenderWindow()->clear(sf::Color(48, 48, 48, 255));
                root.Update();
                root.GetRenderWindow()->display();
                break;
            case Root::GameState::Quit:
                root.GetRenderWindow()->close();
                break;
            default:
                break;
        }
    }
    return root.GetExitStatus();
}
 

3
General / Major lag when a C++ statement is removed
« on: March 04, 2014, 10:42:40 am »
I have the style of the window set to none, and this snippet allow the user to drag the window when the mouse is pressed.

void TitleBar::HandleDrag(sf::RenderWindow *renderWindow) {
    dragging = true;
    while (dragging) {
        lastMousePosition = sf::Vector2i(sf::Mouse::getPosition(*renderWindow).x, sf::Mouse::getPosition(*renderWindow).y);
        if (Utilities::AABBCollision(float(lastMousePosition.x), float(lastMousePosition.y), float(lastMousePosition.x), float(lastMousePosition.y),
                                     float(area.left), float(area.top), float(area.left + area.width), float(area.top + area.height)) && draggable) {
            //std::cout << "Within area" << std::endl;
            int offsetX = lastMousePosition.x - sf::Mouse::getPosition(*renderWindow).x;
            int offsetY = lastMousePosition.y - sf::Mouse::getPosition(*renderWindow).y;
            renderWindow->setPosition(sf::Vector2i(renderWindow->getPosition().x - offsetX, renderWindow->getPosition().y - offsetY));
            sf::Mouse::setPosition(lastMousePosition, *renderWindow);
            if (!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) {
                dragging = false;
            }
        }
    }
}

The code has CPU usage for the process spike up to the high 20's and the window stutters when dragging, but when I uncomment the console output statement the CPU usage for the process is about 6% and dragging works as intended. The length of the string that the console outputs also seems to impact performance. The shorter the length of the string the more lag there is.

I'll work on a minimal example tomorrow morning, but for now I hope someone can find a reason why.

4
General / Optimizing CPU usuage
« on: February 25, 2014, 10:17:29 am »
Alright so I had a thread earlier about calculating FPS after window.display() is called, but my while loop doesn't always call window.display() only when there is user input. CPU usage hits a peak of 20% for the program because of the while loop. I implemented the following to limit it:

void Root::CheckElapsedTime(sf::Clock &clock) {
    if (elapsedTime >= 1.0f / float(framesPerSecond)) {
        std::cout << "While Loop: " << 1.0f / elapsedTime << std::endl;
        elapsedTime = 0;
        return;
    }
    sf::sleep(sf::seconds(1.0f / float(framesPerSecond) - elapsedTime));
    elapsedTime += clock.restart().asSeconds();
    CheckElapsedTime(clock);
}

I have the frame-limit set to 30, and FPS is just shy of 30 which is good. CPU usage drops to a peak of 3%. Is this implementation correct, and is there a better way to optimize it?

5
General / [SOLVED]What's up with my FPS?
« on: February 24, 2014, 09:28:31 am »
For the life of me I can't figure out what the issue is. I've done plenty of searches, but I think I might be missing something since I now have tunnel vision. I'm using SFML 2.1 for this.

Here's the minimal example with code from a search:
int main() {
    sf::RenderWindow Window(sf::VideoMode(100, 100, 32), "Test");
    Window.setFrameLimit(60);

    sf::Clock clock;
    float lastTime = 0;
    while (Window.isOpen()) {
        float currentTime = clock.restart().asSeconds();
        float fps = 1.f / (currentTime - lastTime);
        lastTime = currentTime;
        std::cout << fps << std::endl;
    }

    return 0;
}

Console:
-327.225
32258.1
23255.8
-1002
 
And so on with various numbers

6
General / Compiling program on Linux
« on: August 09, 2013, 09:38:33 am »
I'm following the SFML 2.0 tutorial for testing a program on Linux, but I'm getting the following error. I downloaded the precompiled SFML 2.1 32bit for Linux.

command:
g++ test.o -o test -L/home/crumb/sfml2.1-dev/lib -lsfml-network
 

result:
/usr/bin/ld:/home/crumb/sfml2.1-dev/lib/libsfml-network.so: file format not recognized; treating as linker script
/usr/bin/ld:/home/crumb/sfml2.1-dev/lib/libsfml-network.so:1: syntax error
collect2: ld returned 1 exit status
 

7
Window / [Solved] Issue with sf::Keyboard::isPressed
« on: August 03, 2013, 09:03:38 am »
Hello I've recently been learning to use multiple threads and using sf::Keyboard for unbuffered input. The issue I'm running into is that when I press A with the following code it doesn't run the what's within the if block.
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) { // Returns false
        message_out += "a";
        std::cout << "WORKED";
}
 

But when trying this it works properly and prints "WORKED"
bool test = sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A); // Returns true
    if (test == true) {
        message_out += "a";
                std::cout << "WORKED";
    }
 

Is this an issue with threads or a bug?

8
General / Issues with linking SFML statically?
« on: June 30, 2013, 08:30:52 am »
I have SFML linked statically, and I've done some googling on my issue. I believe it has to do with global variables, but if that's the issue how can I avoid it when the variable is a static member of the class? Any way to guarantee that it is initialized after all the linking is done?

Root.hpp
#include <SFML/Graphics.hpp>

class Root {
private:
    static sf::RenderWindow render_window;
};
 

Root.cpp
#include "Root.hpp"

sf::RenderWindow Root::render_window;

int main(int argc, char **argv) {
        //sf::RenderWindow test(sf::VideoMode(200, 200), "TEST");
        return 0;
}

9
Graphics / [Solved] Reading pixel color issue
« on: June 01, 2013, 08:58:35 am »
I'm using SFML 2.0 and the getPixel() fuction of the Image class. The function returns 2,0,1 for what I drew to be 0, 0, 0 in Photoshop. http://stackoverflow.com/questions/16601839/reading-wrong-pixel-color.

Pages: [1]