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

Pages: [1]
1
Audio / Re: open AL unexpected message
« on: January 31, 2018, 08:17:13 pm »
I've had this problem for a while now. It needs to be fixed :^(

2
General / Re: Events in seperate thread
« on: January 01, 2017, 04:01:08 pm »
Ohhh, now i got why it doens't close and why it freezes.
The while(willUpdateEvents){} is blocking because it won't continue until the event loop in GameEvents::update() is done.
But if i put willUpdateEvents = false; before GameEvents::update();, the event bools are all false in the game loop..

3
General / Re: Events in seperate thread
« on: January 01, 2017, 03:31:40 pm »
Okay, isn't that what i'm doing?
btw, events like KeyPressed do work.
it's just really slow, the window doesn't close and it freezes when i'm dragging it.

4
General / Events in seperate thread
« on: December 31, 2016, 11:47:12 pm »
So, i want to have static bools like "key_left_wasPressed" in a class, update them in main and do the game stuff in another thread.
right now my code looks something like this:
RenderWindow window;
volatile bool willUpdateEvents = false;
void game(){
    //in a loop:
        willUpdateEvents = true;
        while(willUpdateEvents){}
        //(do game stuff)
        //(draw stuff)
}
int main(){
    //(setup window)
    window.setActive(false);    

    Thread gameThread(game);
    gameThread.launch();
    while(Game::gameState != Game::Exit){
        if(willUpdateEvents){
            GameEvents::update(window);
            willUpdateEvents = false;
        }
    }
    gameThread.wait();
}

//Update function in GameEvents class:
void update(RenderWindow &window){
    everything = false;
    while(window.pollEvent(event)){
        //(set the event bools)
    }
}
 

The problem is, it's super slow, i can't close the window and it still freezes when i'm dragging it.

And i can't just do the game stuff that should happen at events in the event loop because i have like 8 rooms in the game so far and i don't want to have half of the logic in an event loop.

5
Graphics / Re: sf::texture destroyed when in class
« on: August 21, 2016, 09:31:56 pm »
Thank you.

6
Graphics / Re: sf::texture destroyed when in class
« on: August 21, 2016, 08:13:23 pm »
Here's code that replicates the problem:

main.cpp:
(click to show/hide)

Map.h:
(click to show/hide)

Map.cpp:
(click to show/hide)

Slider.h
(click to show/hide)

Slider.cpp:
(click to show/hide)

7
Graphics / Re: sf::texture destroyed when in class
« on: August 21, 2016, 07:16:38 pm »
the class is inheriting another class and being used by another one(not the inherited one), should i post all of the code? it's not that long if i take away the unneeded parts

8
Graphics / Re: sf::texture destroyed when in class
« on: August 21, 2016, 07:08:14 pm »
just with a function similar to this
void draw(RenderWindow &window){
    window.draw(sprite);
}
 

9
Graphics / sf::texture destroyed when in class
« on: August 21, 2016, 02:41:48 pm »
hi! I wanted to have a texture in a class like this:

 
class Thing{
    private:
    sf::Texture texture;
    sf::Sprite sprite;

    public:
    Thing(){
        texture.loadFromFile("file");
        sprite.setTexture(texture);
    }

    void draw(){
        //draw
    }
}
 

but then, the texture is gone in the draw() function and the sprite is white.
When I do
std::cout << &texture << endl;
, nothing shows up.

I have read about how the texture is destroyed if you make it in a function, which is pretty obvious to me, but i'm just loading the texture in a function here, which i think should work?
Thanks

10
General discussions / Re: Gravity simulation
« on: August 06, 2016, 10:42:31 am »
Thank you! When i came up with this i did it for simulating orbits and that stuff, so my first thought was to seperate the "throw" velocity and the gravity velocity, because they affect each other. But this does the exact same thing and in less code, so thanks. I said 1-8 as an example.

12
General discussions / Gravity simulation
« on: August 02, 2016, 12:38:14 pm »
I just came up with a super easy way of simulating gravity:

vel.y = pushVel + gravityPull;
pushVel = vel.y;
rect.move(vel);

PushVel is the jump force when you want to jump(-50 for example) and gravityPull is something between 1-8, depending on how much gravity there should be. This concept works with both platformer gravity and if you want to simulate orbits and stuff!

Pages: [1]