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

Pages: [1]
1
System / [2.0] Using a thread to load game resources
« on: January 20, 2013, 03:03:26 am »
I'm making a loading screend and I thought I needed a second thread to load the game resources in. In the meantime the main thread would keep running main game loop, handling events, showing "loading" image and keeping window responsive. So the second thread only loads the resources and then ends.

For simplicity's sake (if I simplify my problem too much and you won't be able to help me then I'll go into more detail and paste some code but I'd like to avoid that) let's say a have this big Game class which has all resources as fields and and auxiliary private Load() method (which only loads these resources, nothing else). My game is very small so one big class is enough, actually. Anyway, in the main thread I call a Game's method (let's call it PublicLoad()) which starts a new thread giving it its Load() method and "this" pointer, then I keep running the main loop until the data are loaded (I have a boolean variable "loaded" which is set to "true" by the 2nd thread when the loading is done and the main thread keeps checking this variable).

After all that, the Game class should start "playing" the game using the loaded resources. But this doesn't work as inteded, as I can see some of the resources loaded and used, and others not (I can hear the music and sounds, I can see some images but not others). Although, after checking the resources with debugger everything seems loaded and fine). Just nothing shows up on the screen.

Also actually the only things that I can't see on my screen are classes using sf::RenderTexture, I don't know if it's related to using threads in anyway.

Oh yeah, and the same Game class works fine when I'm loading using only the main thread.

Edit: Ok, it's definitely something with sf::RenderTexture, because if I draw directly into sf::RenderWindow instead of sf::RenderTarget (and then from it to the window) everything works fine.

Any idea? Should I post some code (what code would be helpful here)?

2
Graphics / Parallax background with a couple of images
« on: January 18, 2013, 02:17:27 pm »
I've implemented parallax background which arbitrary number of images that slide at different speeds and loop. I'm using setTextureRect() for that of course and since when the images loop I have to draw 2 parts of the same image I also use setPosition().

Everything works great but I thought it'd be nice to be able to rotate and scale my parallax. When I do this right now everything breaks and gets put apart. Of course, I could implement calculating new positions for different angles and scales but it would be much simpler and cleaner if I could create the parallax frame (with scale 1.0 and no rotation), copy it to a new image and then rotate and scale that image.

My 2 questions - would it be fast (pixel operations like to be very slow) and how to do that (although I might probably google that so I'm most interested in the first question)?

3
Audio / Multiple sounds don't work
« on: January 18, 2013, 02:08:19 am »
SFML 2.0 (although had the same issue with 1.6). I use sounds like this:
class Sound
{
    private:
    sf::SoundBuffer soundBuffer;
    std::vector<sf::Sound> soundInstances;

    public:
    void Load(std::string filename);
    void Update(void);
    void Play(void);
};
void Sound::Load(std::string filename)
{
    bool result = soundBuffer.loadFromFile(filename);
    assert(result);
}

void Sound::Update(void)
{
    for (int i = 0 ; i < soundInstances.size() ; ++i)
    {
        if (soundInstances[i].getStatus() == sf::Sound::Stopped)
        {
            soundInstances.erase(soundInstances.begin() + i);
            --i;
        }
    }
}

void Sound::Play(void)
{
    soundInstances.push_back(sf::Sound(soundBuffer));
    soundInstances.back().play();
}

I've attached Sound::Play() to mouse clicks (just for debugging reasons). When I click once (i.e. create one sf::Sound and play it) everything's fine. However, when I click a couple of times (fast, so one sound won't finish before another starts) I get random results - either every consecutive sounds stops the previous one and only the last one plays till the end, or a couple of them start and play simultaneously but then all stop (sooner than they should), or very rarely they all play simultaneously and finish properly.

Why is that? Am I doing something wrong?

4
Graphics / Linker warning, linker error :P
« on: January 18, 2013, 12:41:24 am »
I'm using SFML 2.0, downloaded compiled version from website but when I compiled my project (VS 2010) I got this warning (I've shortened the paths):
Warning 1       warning LNK4099: PDB 'sfml-main-d.pdb' was not found with 'sfml-main-d.lib(SFML_Main.cpp.obj)' or at 'C:\...\Debug\sfml-main-d.pdb'; linking object as if no debug info C:\...\sfml-main-d.lib(SFML_Main.cpp.obj)
I know what it means, I've read on this forum that it's harmless yet I'm just the kind of guy that hates warnings and likes his project compile with none. So I've tried compiling SFML myself and replacing *.lib files (debug version). This rid me of the linker warning but later when I used this:
sf::Font::getDefaultFont()
I got following linker error:
Error   1       error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class sf::Font const & __cdecl sf::Font::getDefaultFont(void)" (__imp_?getDefaultFont@Font@sf@@SAABV12@XZ) referenced in function "public: __thiscall PopupText::PopupText(void)" (??0PopupText@@QAE@XZ)        C:\...\PopupText.obj
which doesn't occur with the *.lib files downloaded from the website (already compiled).

Am I doing something wrong?

5
Graphics / Can't get different font
« on: January 16, 2013, 09:39:44 pm »
I'm loading a font with Font::LoadFromFile() and it returns true but when i Draw it on the screen, the font is always the same (the default one, I guess). What's wrong?

Pages: [1]
anything