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

Pages: [1]
1
Graphics / Re: Freeing GPU memory.
« on: May 16, 2013, 02:08:48 pm »
Ok guys, fixed it, thanks for the help.

Turns out i made a pretty big mistake of not making a destructor of my base level class virtual. Polymorphism will get ya;)

2
Graphics / Re: Freeing GPU memory.
« on: May 16, 2013, 01:34:04 pm »
Hmm, maybe gpu-z i showing false readings, i'll try something else. But i am quite sure there is some problem with loading and deleting either way, because of this:
I have a fireplace sound set at some specific location( say, x = 1000). SoundBuffer and Sound are also members of that level class. Strange thing is, that when i load a new map and go to the same location ( x =1000), sound still plays.

I am fairly sure i screwed something up, but i have no idea what. If anyone has any idea where to look, that'd be greatly appreciated, cause tbh i'm not sure which snippets would be relevant, cause the whole new/delete routine seems fairly straightforward.

Edit: Music member actually gets destroyed and stops. Sound does not. It really boggles my mind.

3
Graphics / Re: Freeing GPU memory.
« on: May 16, 2013, 01:09:55 pm »
I downloaded gpu-z, which shows how much of gpu memory is in use. I checked memory load when each map is created in separate runtimes and when one is created after deletion of another. whenn i load map2 after map 1 during one runtime i see more memory used.

Anyway i might have screwed something with new/delete routine, i'll admit i don't have much experience with that. I'll paste few snippets regarding loading/reloading a map.

Controler.cpp:
void TestControler::level_selector()
{
switch ( selector )
        {
        case 2:

                std::cout << "loading Mine level..." << std::endl;
                currentLevel = new MineLevel(world, window, rayCallback);

                break;

        case 3:

                std::cout << "loading City level..." << std::endl;
                currentLevel = new CityLevel(world, window, rayCallback);
               
                break;
///etc...
}
}
//and when i want to switch level:

void TestControler::check_for_destructors()
{
        if (switchLevel)
        {
                delete currentLevel;
                currentLevel = new AnotherLevel(world, window, rayCallback);
                switchLevel = false;
        }
}

 

And constructor and destructor for one of the levels.

CaveLevel::CaveLevel(b2World *aWorld, sf::RenderWindow * aWindow,RayCastListener * rayCast) : world(aWorld), window(aWindow)

{
        load_resources();
        set_layers();
        set_chains();
        ls = new ltbl::LightSystem(AABB(Vec2f(0.0f, 0.0f), Vec2f(1680.0f,1050.0f)), window, "data/lightFin.png",   "data/shaders/lightAttenuationShader.frag");
        rayCallback = rayCast;
        hero = new Hero(world, ls,1100, 735, sitting, rayCallback);
        camera = new Camera(hero);
        setup_lights();
        setup_audio();


}

CaveLevel::~CaveLevel()
{
        delete hero;
        delete camera;
        delete ls;

}

 

All the textures are private members of level class, and they are loaded in load_resources() function.

4
Graphics / Freeing GPU memory.
« on: May 16, 2013, 12:21:33 pm »
Hi.

I have a problem with handling the textures. Simply put i have a level class, which has Texture and Sprite members in it. I load textures from files, set sprites, all is well. But now i want to switch to next level when this one is done. So i call delete from outside and create a new level. But the old textures stay in GPU memory.

So my question is, how can i destroy unused textures properly?

5
Graphics / Re: Optimizing Texture and Sprite management
« on: November 08, 2012, 02:43:22 pm »
Ok, thanks.

Since this game won't be a resource hog, i guess it won't be a problem to load 20% of the map, and load rest on the fly.

6
Graphics / Optimizing Texture and Sprite management
« on: November 08, 2012, 01:59:09 pm »
Hi!

I have a multi-part question regarding the proper way of loading, storing and accessing textures and sprites.

Currently i am working on a 2d side-scrolling brawler. Three major game elements, which use textures and sprites are hero, enemies and background/map. I'd like to implement parallax scrolling later on.

Anyway, i wanted to ask about a proper way to load and store gfx elements for each of those instances.

For hero class, i keep all textures and sprites as members, and load textures in the constructor. Since there is only one hero, and he is loaded with the map, it should just work fine. Here's relevant parts:


Hero::Hero (b2World *aWorld, float posX, float posY) : world(aWorld)
        {
                hero_run.loadFromFile("HeroTextures/run.png");
                hero_turn.loadFromFile("HeroTextures/turn.png");
                hero_jump.loadFromFile("HeroTextures/jump.png");
                hero_crouch.loadFromFile("HeroTextures/crouch.png");
                hero_roll.loadFromFile("HeroTextures/roll.png");
                hero_stop.loadFromFile("HeroTextures/stop.png");
                hero_stand.loadFromFile("HeroTextures/stand.png");
                hero_attack.loadFromFile("HeroTextures/attack.png");
                m_sprite.setPosition(posX, posY);
                m_sprite.setOrigin(250,250);
                frame = 0;
                set_b2_body(); // Box2d stuff
               
 }

void Hero::display(State state)
{
        switch(state)
        {
        case running:
                if( direction == right)
                m_sprite.setScale(1.0f,1.0f);
                else
                m_sprite.setScale(-1.0f,1.0f);

                m_sprite.setTexture(hero_run);
                m_sprite.setTextureRect(hero_run_clips[frame]);
                frame++;
                if (frame > 20 )
                        frame = 0;
                break;
}

 

That's the gist of it. I imagine, for enemy class, i'll have to load textures somewhere else, because there will be mutliple enemies constructed from the same texture. Other than that, setTexture seems the way to go.

So regarding this part, my question is: is this the optimal way of handling graphics for animated entities, or could i store it, or access it in more optimized way?


Second part of my post pertains to the background. After preparing elements of the map i just set em the standard way:


TestLevel::TestLevel(b2World *aWorld) : world(aWorld)

{
        backgTexture1.loadFromFile("background/testlevel1.jpg");
        backgTexture2.loadFromFile("background/testlevel2.jpg");
        backgTexture3.loadFromFile("background/testlevel3.jpg");
        background1.setTexture(backgTexture1);
        background2.setTexture(backgTexture2);
        background3.setTexture(backgTexture3);
        background1.setPosition(0,0);
        background2.setPosition(5000,0);
        background3.setPosition(10000,0);
        set_ground_bodies(); // box2d stuff
}

 

It runs nice and all, but loading time is now good couple seconds, and it's only a small part of an actual planned level. Those textures are pretty big though (5000x5000).

So my last question is: how to improve loading time?

Edit: only part of my post showed the 1st time, edited for full version.

7
General / Re: Creating a Hero class
« on: September 19, 2012, 03:26:13 pm »
@Hiura:

Yeah, that seems like best option;)

Thanks.

8
General / Re: Creating a Hero class
« on: September 19, 2012, 11:10:45 am »
Thanks for the reply.

I went with option 2 as planned, it seemed straightforward, but i quickly ran into a problem.

So here's my hero class:

class Hero
{
public:
        Hero (const sf::Texture & texture, float posX, float posY, int state );
        Hero::~Hero();
        void draw (sf::RenderWindow* window);
        void move (int state);
        void display(int state);
        int getFrame();
        void resetFrame();
        void set();
        int state;

private:

        sf::Sprite m_sprite;
        int position;
        int frame;

};
 

ATM i'm doing the animation the standard way: using Rect on each frame, and drawing that frame in the loop.

It works nicely when there's only a few moves. But the problem is, main character's sprite sheet is pretty large. There are lot moves, and they are quite detailed, up to 20 frames per move. This means, they can't fit into one spritesheet.

So while this way of doing things is perfectly fine for background elements, or enemies with smaller pattern of moves, the hero class would need some changes.

I was wondering what the best course of action would be. Should i add more member sprites to the class, and switch them, depending on state ( running, attacking etc. )? That seems kinda clunky, since i would need to change which sprite gets drawn in main loop of the game.

Or should i just remove the member sprites, and just move on to option 3, leaving hero class with just data regarding positions and status, etc.?

9
General / Creating a Hero class
« on: September 14, 2012, 12:31:19 pm »
Hi guys!

I am a beginner when it comes to SFML, and since SFML2 does not have many tutorials i ran into some problems when designing my 2d game.

My question is this:

What is the best way to create a Hero class, considering the need of using sf::Sprite?

The hero would be animated based on a spritesheet, and would need to store data including states, frames, positions, hitpoints etc.

I came up with 3 possible solutions and i wonder which one would fit best with SFML design philosophy.

1) Hero inherits from sf::Sprite
2) Aggregation, so sf::Sprite is a member of Hero
3) Keeping sf::Sprite and Hero separate - use Hero class to store all the date and pass it to sf::Sprite

I would appreciate any answer, especially with some explanation, why any of those options might be the best.

Pages: [1]
anything