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

Pages: [1] 2
1
General / Re: How to flip sprite horizontal?
« on: May 12, 2013, 05:05:52 pm »
probably rotating sprite would be easiest

edit: nvm scaling is even easier then rotating :P

2
General / Re: window event Pulling - draw relation (2 threads)
« on: May 12, 2013, 03:16:57 pm »
Yes that's the conclusion I got from observation, but why would that affect other thread? shouldn't it be executed independently on other core?
It got to have something to do with event pulling, if I remove everything from //GameLoop and leave it empty or almost empty(adding int to 10k then 0 it), drawing thread will not slow down, even without sleep

Update:

turns out, without sleep drawing thread will work at ~70% of its original speed, if I click on desktop then back on my windows title bar (clicking on drawing area has no effect)


3
Graphics / Re: LoadFromFile issues in VS2012
« on: May 12, 2013, 04:04:13 am »
"C:\Users\Username\Documents\Visual Studio 2012\Projects\SFML Game1\Debug\ball.jpg"
probably wouldn't work because \ is escape character that should be escaped in path string...

in Visual Studio 2012 they've changed search directories, for example if you have something like this:

[solution catalog]
{
   [Debug]
   {
          (debug Dll Files and Exe outputs)
   }
   [Release]
   {
          (release Dll Files and Exe outputs)
   }
   [Project catalog]
   {
          (headers)
          (cpp)
          (resources loaded by your programs - images, fonts)
    }
    (Solution files)
}


Legend:
[catalog name]
{
    catalog content
}

(file/files)

4
General / window event Pulling - draw relation (2 threads)
« on: May 12, 2013, 02:10:02 am »
Hello
Settings:
I've dug out my old code and decided to give multithreaded game engine approach a shot.
The idea is to run drawing loop and update+event loop in separate threads.

drawing is done in "new thread" while event pulling and updating is supposed to run in main thread.

Problem:
Why does my drawing loop slow down aprox. 50 times if I don't put update/event loop to sleep for a short duration?
Since the two should run independently of each other (no communication is done yet, no synchronization, nothing) ran on multi-core cpu, the only connection between these loops is that I draw to same RenderWindow as I pull events from.

In the end of the day I do plan to limit how many times a sec each of these loops executes, but that doesn't change fact that I wonder how they influence each other or if my though flow is flawed :P


Fairly minimal example
#include <SFML/Graphics.hpp>
#include <iostream>
#include <sstream>

sf::RenderWindow window;
sf::View Camera;

void Draw()
{
        //time and fps variables
        int counter = 0;
        int fps = 0;
        sf::Text fpsText;
        sf::Clock clk;
        sf::Font font;
        sf::Time fpsTime = sf::Time::Zero;
        std::stringstream ss;

        font.loadFromFile("corbel.ttf");
        fpsText.setFont(font);

        //samething to draw
        sf::VertexArray va;
        va.setPrimitiveType(sf::Triangles);
        va.append(sf::Vector2f(10, 10));
        va.append(sf::Vector2f(100, 10));
        va.append(sf::Vector2f(100, 100));
        va[0].color = sf::Color::Red;
        va[1].color = sf::Color::Blue;
        va[2].color = sf::Color::Green;

        window.setActive(true);

        while(window.isOpen())
        {                              
                window.setView(Camera);

                window.clear();
                window.draw(va); //drawing of everything here

                window.setView(window.getDefaultView());

                //fps
                counter++;             
                fpsTime+=clk.restart();;
                if(fpsTime.asSeconds()>=1)
                {
                        fps = (int)(counter/fpsTime.asSeconds());
                        counter=0;
                        fpsTime = sf::Time::Zero;
                        ss.str(std::string());
                        ss.clear();
                        ss<<fps;
                        fpsText.setString(ss.str());
                }
                window.draw(fpsText);
                window.display();
        }
};


int main()
{      
        window.create(sf::VideoMode(1680, 1050),"");
        window.setVerticalSyncEnabled(false);
        window.setActive(false);

        //drawing thread start
        sf::Thread RenderThread(Draw);
        RenderThread.launch();

        //GameLoop
        while(window.isOpen())
        {
                //Event Handling
                sf::Event event;
                while(window.pollEvent(event))
                {
                        switch (event.type)
                        {
                                case sf::Event::Closed:
                                        window.close();
                                        RenderThread.wait();
                                        break;
                                case sf::Event::KeyPressed:    
                                {
                                        switch (event.key.code)
                                        {
                                                case sf::Keyboard::Escape:
                                                        window.close();
                                                        RenderThread.wait();
                                                        break;
                                                //more key events here
                                        default:
                                                break;
                                        }
                                        break;
                                }
                                default:
                                        break;
                        }
                }

                //update here

                //sleep to allow other thread to work
                sf::sleep(sf::milliseconds(3));
        }
}
 

5
General / Re: Differences between Image, Texture, Sprite and RenderTarget?
« on: September 13, 2012, 10:57:54 pm »
n sf::Image is class that holds image information on the memory of your CPU....
Wouldn't that be cache?
My description was very rough and I've actually not much knowledge of how SFML itself is implemented, I also used the term 'memory of your CPU' to make the difference clear between CPU and GPU.
As for the cache, one can not fully predict what the architecture the application will run on do with the information, but the cache has other functionality than to store information for a longer time and with its limited size, it wouldn't make sense.

Sorry, I just felt it could be misleading for someone with little knowledge as your description indicated cache, which we know is not used as user accessible  storage memory, but somebody else could not know that.

6
General / Re: Differences between Image, Texture, Sprite and RenderTarget?
« on: September 13, 2012, 10:34:45 pm »
n sf::Image is class that holds image information on the memory of your CPU....

Wouldn't that be cache?

7
General / Re: [OpenGL/SFML] A sample room..
« on: August 15, 2012, 07:43:08 pm »
I'd suggest you reading some OpenGL tutorials that are NOT NeHes :) As far as I know NeHe is so out of date, it's not even funny. The ones I did look at (alhough never really got into it) are:
All systems, OpenGl 3.3+
Linux, OpenGl 3.3+ altough since its OpenGl it doesn't really make difference, just how you create window/build/prepare project

They cover slightly different material after basics

8
General / Re: Linking SFML 2.0 to MS Visual Studio 2012
« on: August 15, 2012, 07:12:56 pm »
I am using VS2012 for a while now, and am very pleased with it. There are no additional steps you have to take in order to use it. It it exactly the same as VS2010, although you will have to build libs yourself, fortunatly CMake already supports least VS. Remember to put all libs and includes in relatively simple directory, w/o "-,.'" spaces and such, that makes it easier to spot any error there.

There is one Major change you need to keep in mind when using VS11. All dlls have to be put to your executable directory. example: for Project named  "Proj"

put according dlls into "Proj/Debug" and "Proj/Release".
All resources like fonts and images goes into "Proj/Proj" folder (the one where source code is)

It is a bit strange but that's how its done now. And it makes sense, you separate release and debug dlls by default now :)

Hope that helps :)


9
General / Re: Can't get even an example program to run
« on: August 14, 2012, 11:17:21 pm »
isn't that wrong linking order btw? I believe it should be:
-graphics
-network
-window
-system

Correct me if I'm wrong

10
Network / Re: Networking tutorial?
« on: August 11, 2012, 10:42:06 pm »
I can't stomach a lot of theory without practice in between, that's goes for everything I do. So I guess I will read a bit then start with sfml, and eventually move to boost should I need more features.

Thanks for responds

11
Network / Networking tutorial?
« on: August 11, 2012, 06:33:37 am »
Hello,

I want to take brief break from all that tiles I've been drawing past days and learn some basics about network programming. I threw topic into google and found people recommending to skip Winsock and move straight away to some other api, They actually mentioned SFML as first choice for beginners. But there not being any up to date tutorial, I have to wonder, if there are few enough changes to go with 1.6 tutorial and adapt it to 2.0 on fly or go hardcore to boost asio or yet something else? What do you think?

12
General / Re: Text drawn to renderTexture looks broken (see example)
« on: August 07, 2012, 06:36:44 am »
Possibly this bug
But to confirm you'll have to wait for someone who actually knows stuff :)

13
General / Re: State Machine and Engine problem
« on: August 06, 2012, 06:44:22 am »
by using std::vector he can push a state on top of other... imagine a "mini menu" that appears when you press Escape on the Play state... then he can easily pop the last state and back to the prior .. so he has 1 paused state in the background and another one active on top...

can you do that with std::stack?

Stack by definition is data structure following principle "first in last out" meaning that you can only add and remove things only from one, the same end. It's exactly the same as your real life stack of books, you can't pick book on bottom, without destroying stack, unless you remove all books from top first. I am not sure if that's how std::stack works since I've never used it myself, but I don't think they would name "stack" something that works differently then stack generally known in computer science :)

Correct me if I'm wrong

14
General / Re: threads, events and windows
« on: August 05, 2012, 07:36:48 pm »
none of that would make a difference, if it worked for him before on an older version of SFML2 then somethings changed since then to cause it.
Well eXpl0it3r reasoning is good, and putting sf::sleep(sf::milliseconds(10)); after event pulling does resolve the issue.
But that't only half of problme :) I made this post because I'm concerned if that's not some kind of bug, since it used to work.

@eXpl0it3r
I'm running on first gen i7 920 cpu therefore I have 4 cores and 8 threads.

It doesn't have to be setup that way, but from my previous tests with older build (which worked fine) it seemed like separating them actually increased fps by far(forgot number but it was noticeable). Which I figured was due to event pulling taking too much time, that's why I've put it into separate thread.
I am probably using threads wrong, since it is first time me ever attempting to use them, but still it is strange that something that worked stopped with new release.

@Laurent
SFML is the only thing that changed. My drivers are the same that used to be, just checked to confirm they are not outdated -  which they were not so I didn't install new/beta ones.
edit@Laurent I don't know where to put that window.waitEvent(event); where ever I put them they stop my events to be read correctly - I have to spam esc to exit and so on

Thanks for replies :)

15
General / threads, events and windows
« on: August 05, 2012, 06:56:55 pm »
Hello
Again toying with fresh built sfml2rc I've encountered strange problem that was non existing in previous built(RC built on April 12th).
It might not be best practice but nonetheless this is what I am using at the moment:
Thread one - event pulling;
Thread two - drawing and calculating;
with old build of sfml everything ran smooth and fast. However with fresh one it seems like window is not "in focus" by default or something of sort and I have to click/hold on Title bar which will boost fps. After that clicking back and forth on different windows(chrome/VS) causes similar thing, although clinking away from window boosts fps and clicking into Drawing area of render window slaps it down.
this happens in "SFML-2.0-rc-69-ge4ea686" build on W7x64, in both VS10 and VS11 each with their own built ddls, most recent nVidia WHQL drivers. I can not confirm which release is the one that works fine, only date it was build on(and downloaded) - April 12th.

This does not happen if i put drawing in same thread as event pulling

Problem occurs with this code
#include <SFML/Graphics.hpp>

void Draw();

sf::RenderWindow window;

int main()
{      

        //Initialize window
        window.create(sf::VideoMode(1680, 1050),"");
        window.setActive(false);

        //thread for draw function
        sf::Thread RenderThread(&Draw);
        RenderThread.launch();

        //GameLoop
        while(window.isOpen())
        {
                //Event Handling
                sf::Event event;
                while(window.pollEvent(event))
                {
                        if(event.type == sf::Event::Closed)
                                window.close();
                        if(event.type == sf::Event::KeyPressed)
                        {
                                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
                                        window.close();
                        }
                }
        }
        return 0;
}

void Draw()
{
        int counter = 0;
        int fps = 0;
        sf::Text fpsText;
        sf::Clock clk;
        sf::Font font;
        font.loadFromFile("corbel.ttf");
        fpsText.setFont(font);

        window.setActive(true);
        window.setVerticalSyncEnabled(false);
       
        while(window.isOpen())
        {
                counter++;
                if(clk.getElapsedTime().asSeconds()>=1)
                {
                        fps = counter/clk.getElapsedTime().asSeconds();
                        counter=0;
                        clk.restart();
                        std::string sss;
                        char tempB[20];
                        sprintf(tempB, "%d", fps);
                        sss = tempB;
                        fpsText.setString(sss);
                }
               
                window.clear();
                window.draw(fpsText);
                window.display();
        }
};
 

I know I am asking a lot of questions, but this really does bother me.

Pages: [1] 2