Jump to content

  • Log In with Google      Sign In   
  • Create Account


Sunsharior

Member Since 14 Dec 2013
Offline Last Active Today, 08:46 AM
-----

Topics I've Started

My physic engine is done, but i'm still not satisfied. Physic book related.

02 June 2014 - 11:21 AM

Hello everyone.

 

On and off for the last 6 month, i've worked on my 2D physic engin directly integrated in the game i'm working on.
I have gone through several iteration, each one being better and better than the last one.

 

The current build is "acceptable", which mean it have every features that will be in my final game, like polygonal collision detection and resolution, slopes, rotating bounding boxes, skeletal anchors and more. It is by no means perfect. I am aware of a couple bugs here and there.

 

But i feel i can do better, more optimized or just more robust. I've read a lot of tutorial on the web to achieve everything so far, but i think i've come to a point where i need to read a good 2d physic book to make my engin better and better.

 

I have done some research to find good books, but everything i find so far have 3d physic as the main focus. The few 2d book i have found don't have a lot of reviews or have somes bogus reviews.

 

Would you recommend a good 2d physic book?
I am looking for an advanced book.

 

Thank you very much for your time.


Is this commenting macro safe to use?

22 May 2014 - 10:18 PM

Hello everyone.

 

I'm using a simple macro to comment out part of my code in release build, but i'm wondering if this could lead to some sort of problem, as i'm trying to cheat the precompiller into adding comments against the rule.

 

I use this to avoid writing duplicated code.

 

Basically, here is the macro

#if defined DEBUG
#define MACRO 
#else
#define MACRO );/ ## /
#endif

What it does is: If i'm in debug build, it does nothing. If i'm in release build, it close a function and comment the rest of the line.

The "/ ## /" part is needed to trick the compiler into thinking comment dont exist. But they do.

 

This is how i use the macro. (The code is simplified)

//Initialize a long list of interfaced classes into a map, allowing easy Factory access.
void Bar()
{
    //Assume each different letters is an interfaced class
    Foo(A0, A1 MACRO, A2, A3, A4);
    Foo(B0, B1 MACRO, B2, B3, B4);
    // Many Foo later...
    Foo(Z0, Z1 MACRO, Z2, Z3, Z4);
}

#if defined DEBUG
//Types don't really matter. Just the number of parameters is interesting.
void Foo(Type0, Type1, Type2, Type3, Type4)
{
    // Do something, in debug
}
#else
void Foo(Type0, Type1)
{
    // Do something, in release
}
#endif



As you can see, in release build, the compiler will see "Foo(A0, A1 );" as the comment will clear the rest of the line.
This way, i avoid writing this code:

#if defined DEBUG
Foo(A0, A1, A2, A3, A4);
Foo(B0, B1, B2, B3, B4);
// Many Foo later...
Foo(Z0, Z1, Z2, Z3, Z4);
#else
Foo(A0, A1);
Foo(B0, B1);
// Many Foo later...
Foo(Z0, Z1);
#endif

The reason i use it is to avoir writing duplicate code to avoid possible Copy/Paste errors.

As of writing this post, the macro work fine in either build, but i have this strange feeling i'm doing something cringe-worthy.

 

Am i really going overboard just to avoid writing duplicated code?

If so, is there other options?


Create new white texture from existing SDL_Texture.

05 April 2014 - 04:28 PM

Hello everyone,

 

I'm trying to accomplish something in SDL and i'm wondering if it can be done easily.

 

What i want to do it this:

 

First i create a new texture from a PNG file with this code. No problem so far.

bool CTextureInfo::Unserialize(std::ifstream &_inputfilestream)
{
    //png
    int pngsize = 0;
    _inputfilestream.read(reinterpret_cast<char *>(&pngsize), sizeof(int) );
    char *textureBinaries = new char[pngsize];
    _inputfilestream.read(reinterpret_cast<char *>(textureBinaries), pngsize);
	
    // Create texture
    SDL_RWops *img = SDL_RWFromConstMem(textureBinaries, pngsize);
	
    // This part is building the texture through SDL_image
    SDL_Texture *texture = IMG_LoadTexture_RW(CSDL_Setup::GetInstance()->GetRenderer(), img, 0);
}

After this i want to create another texture that will be a copy of the first one, but instead all pixels that are not transparent become white.

See attached image for example of what texture 1 and texture 2 should look like.

 

However, i am failing really hard to figure how to do this.

I thank you in advance.

 

 


There got to be a better way to manage animations.

23 March 2014 - 09:29 PM

Somes weeks ago, i've started pouring more hours on the animation part of my game, which was pretty bare up to this point. After sucessfully creating a tool to easily create and modify my 2d animations from a sprite sheet (setting things like sprite rect, crop, hitboxes, weapon mounting point and angle, etc...), i now have to actually do the logic of switching all of the animation the actors have in the game.

 

The code below is my function to change the actor's animation based on his state.

While, i've not actually come to a dead end, i feel what my code is starting to feel tangled and harder to debug.

As you will notice a little bit further down, it'll only get more complicated, as the number of possible animation is very wide.

 

So my question is this: Is there a better way of doing this? Or should i just continue doing all thoses else-if?

I really do not want all the hours i'm doing to go to waste if i have to redo everything, especially all the time spent doing my own animation tool (which is very specific to my game).

//////////////////////////////////////////////////////////////////////////
//
void IActor::ManageAnimation()
{
    Animations id = ANIMATION_IDLE_OOC;
    //If out of combat
    if(!IsState(STATE_INCOMBAT) )
    {
        if(IsState(STATE_JUMPING))
            id = ANIMATION_JUMP_OOC;

        else if(IsState(STATE_FALLING))
            id = ANIMATION_FALL_OOC;

        else if(IsIdle(MAX_IDLE_TIME))
            id = ANIMATION_SLEEP_OOC;

        //Sliding show be shown over moving
        else if(IsState(STATE_SLIDING))
            id = ANIMATION_SLIDE_OOC;

        else if(IsState(STATE_MOVING))
            id = ANIMATION_MOVE_OOC;
    }
    else
    {
        //...
    }

    SetAnimation(id);
}
enum Animations
{
    //////////////////////////////////////////////////////////////////////////
    //Generic animation. Everyone should have theses. It's the job of this class to set them.
    //Out of combat
    ANIMATION_IDLE_OOC,            //Basic idle animation out of combat.
    ANIMATION_SLEEP_OOC,        //Animation for idling too long... Player yawn, wolf lay down and sleep, etc...
    ANIMATION_MOVE_OOC,            //Moving
    ANIMATION_LOOK_UP_OOC,        //Look up
    ANIMATION_LOOK_DOWN_OOC,    //Look down
    ANIMATION_TREATHENED_OOC,    //Transition between out of combat and in combat.
    ANIMATION_JUMP_OOC,            //Jump
    ANIMATION_FALL_OOC,            //Falling
    ANIMATION_SLIDE_OOC,        //When the actor is changing direction or sliding down a slope.

    //In combat
    ANIMATION_IDLE_IC,            //Basic idle animation in combat.
    ANIMATION_MOVE_IC,            //Moving
    ANIMATION_LOOK_UP_IC,        //Look up
    ANIMATION_LOOK_DOWN_IC,        //Look down
    ANIMATION_TREATHENED_IC,    //Transition between in combat and out of combat.
    ANIMATION_JUMP_IC,            //Jump
    ANIMATION_FALL_IC,            //Falling
    ANIMATION_SLIDE_IC,            //When the actor is changing direction or sliding down a slope.

    //generic
    ANIMATION_HURT,
    ANIMATION_CRITITAL_HURT,
    ANIMATION_DIE,
    ANIMATION_DEAD,
    //End of generic animation
    //////////////////////////////////////////////////////////////////////////

    //////////////////////////////////////////////////////////////////////////
    //Specific animation. Not everyone have them. It's the job of the Actor's interface to set them. thoses animation can all be canceled by us.
    //Reserve for physical attack with a weapon or unarmed.
    ANIMATION_ATTACK_1,
    ANIMATION_ATTACK_2,
    ANIMATION_ATTACK_3,
    ANIMATION_ATTACK_4,
    ANIMATION_ATTACK_5,

    //Reserved for Spell animations
    ANIMATION_SPECIAL_1,
    ANIMATION_SPECIAL_2,
    ANIMATION_SPECIAL_3,
    ANIMATION_SPECIAL_4,
    ANIAMTION_SPECIAL_5,

    //Reserved for social animations. could be laugh, cry, angry, yell, etc...
    ANIMATION_SOCIAL_1,
    ANIMATION_SOCIAL_2,
    ANIMATION_SOCIAL_3,
    ANIMATION_SOCIAL_4,
    ANIMATION_SOCIAL_5,
    //End specific animation
    //////////////////////////////////////////////////////////////////////////
};

Advice about "Camera Zone".

04 February 2014 - 12:54 PM

Hello.

 

In this game engine i am working on, i have a camera problem that i will explain in a moment.

Before i continue thought, i must state that i aleredy have a few idea on how to resolve it, but i feel all of them are "awkward". So i come here to hear about yours opinions.

 

The problem is kind of hard to explain, i will try my best to be as precise as possible.

 

I have a 2D sidescroller game. In this game is a Camera Class that can move around dynamically, that means it will try it best to keep up with whatever it's bound to.

The camera follow a simple rules: Don't go out of the Level. This mean in a 100x100 Map, the camera won't go left of tile 0 or right of tile 100.

 

With this come 2 major problem

1. If i wants to make a "secret" area where i do not wants the camera to enter before the player do.

2. If i wants to stop the camera right at the floor level, even if the level go below the floor eventually.

 

if i am not clear enought, i have attached an image to show the problem.

 

In picture one, you can see the level Editor. I made a corridor leading to a pit. Picture 2 is zoomed it with the player spawned. You can see in picture 2 the problem. I wants the camera to stop at the floor and not go under the floor until the actor is nearby the pit.

 

So i got somes idea on how to solve it, but like i said earlier, neither are spectacular.

1. Flag somes tiles as "Don't go in here yet". If the camera is about to show them, stop the movement.

2. In the map header, tell the camera where it can go and where it can't go.

3. Disallow the camera to enter "empty space" or tile flagged as "secret space" (a trigger would unflag such area as soon as the player touch it).

4. Put trigger everywhere in the level to tell how the camera should behave.

 

Personnaly i would go with option 3 but i wants to hear what everyone is thinking. Maybe there is a better solution i am not thinking of.

 

Ps: Graphics are just placeholder.


PARTNERS