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

Pages: [1]
1
Window / Re: RenderWindow .display() seems to do nothing
« on: September 01, 2015, 11:01:55 pm »
Very interesting. Awesome, thanks guys!

Since my goal is not actually to publish an application, but instead to have a small playground to complement the texts I'm reading, I might tentatively go forward with this one extra thread. The resulting issues, challenges, and solutions are what I aim for. I'll ditch the threading if they become too much to bear.

Thanks again!

2
Window / Re: RenderWindow .display() seems to do nothing
« on: September 01, 2015, 10:10:06 pm »
Out of curiosity, why do you suggest that I avoid threads?
Threads bring a huge amount of complexity and requires a fair amount of experience with C++ to use correctly.
Try searching the forum. There have been many posts explaining the problems that threads can bring.

Here are a few:
 http://en.sfml-dev.org/forums/index.php?topic=17491.msg125858#msg125858
 
 http://en.sfml-dev.org/forums/index.php?topic=18539.msg133315#msg133315

 http://en.sfml-dev.org/forums/index.php?topic=15430.msg109640#msg109640

 http://en.sfml-dev.org/forums/index.php?topic=9949.msg68291#msg68291

 http://en.sfml-dev.org/forums/index.php?topic=17619.msg126675#msg126675

Thanks Jesper!

I just took some time to go through these posts. Very interesting. So far, the comments and warnings in them compare with those in the texts I'm reading.

One thing that's still a little obscure -- Without explicitly creating threads, the program will run entirely synchronously, right? There is no automatic or virtual threading that the VS compiler does?

I made a few simple programs in ObjectiveC a couple years ago, and for some reason I vaguely recall some automatic threading that XCode did. But maybe that was just a dream I had. Or maybe I misunderstood something I saw. Maybe I was drunk.

3
Window / Re: RenderWindow .display() seems to do nothing
« on: September 01, 2015, 07:52:07 am »
Thanks Verra!

It eases my mind to know that this was a limitation of a library and not something I did.

Out of curiosity, why do you suggest that I avoid threads? I honestly know very little in the game-dev world at this point. Is it that threading isn't necessary for the simple applications built out of SFML? Does the VS compiler do anything to incorporate threading automatically? Or do you say that mostly because the application is so rudimentary at this point?

4
Window / RenderWindow .display() seems to do nothing
« on: September 01, 2015, 06:08:47 am »
I'm new to SFML and C++ in general, reading a few texts while playing around with code to keep things fun. My first goal is to get some really basic code into an object oriented shape so that I can see a gameloop, keystrokes, and some simple draws all working together.

I started with the code from the setup tutorial, and it drew my little 200x200 window & green circle just fine. So I started moving stuff around to get that .draw() and .display() into its own thread under a block that fires off every-so-often.

I got to a state where the block executes, but for some reason the window.display() doesn't seem to do anything.

My OutputDebug lines all fire off, so I can see that the program is looping and executing on separate threads. In debugging mode, I can see it execute the .display() but it just leaves the window blank white. On the next line, I added a window.setTitle to make sure that the thread could talk to my window object--and that succeeds. If I take the window.display() back into main(), it draws successfully. So is the problem from the threading? From not using SFML's window.setFramerateLimit(60) with main()? I'm quite confused.

I know this code is probably ugly in a lot of ways. I just want to see the gears turning with each other for now.
(But with that said, I always appreciate free opinions & information)

// (some includes)
extern float posX = 0;
extern float posY = 0;
int keepGoing = 0;

sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);

auto gameStart = std::chrono::high_resolution_clock::now();
auto lastDraw = gameStart;
auto nextDraw = lastDraw;

void draw()
{
        if (GetKeyState('D') == true){ posX++; }
        if (GetKeyState('A') == true){ posX--; }
       
        shape.setPosition(posX, posY);
       
        window.clear();
        window.draw(shape);
        window.display(); //Here's the RenderWindow.display()

        window.setTitle("TITLE RESET");  //This succeeds, so I do have access to "window"
        OutputDebugString(L"\nDrawing!"); //I can see that this successfully executes, so I know the code is getting to here
}

//this runloop just calls my draw() every so often. My main() hands this loop the draw() function as *fp
void runloop(void (*fp)())
{
        while (keepGoing == 1)
        {
                OutputDebugString(L"\nLooping!");
               
                fp();

                lastDraw = std::chrono::high_resolution_clock::now();
                nextDraw += std::chrono::milliseconds(15);
               
                std::this_thread::sleep_until(nextDraw);
        }
}


int main()
{
        shape.setFillColor(sf::Color::Green);

        keepGoing = 1;

        void (*drawp)();
        drawp = draw;
        std::thread t1(runloop,drawp);
       
        while (window.isOpen())
        {
                sf::Event event;
                OutputDebugString(L"\nGotHere!");

               
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }
// Here's where the RenderWindow.display() is in the tutorial
        }
        return 0;
}
 

Pages: [1]
anything