Jump to content

  • Log In with Google      Sign In   
  • Create Account

Sunsharior

Member Since 14 Dec 2013
Offline Last Active Today, 09:55 AM

Topics I've Started

How should i process about embedding a SDL2 game into QT to make a level editor.

28 November 2014 - 11:32 AM

Hello everyone.

 

The video game engine i'm working on is amost complete. Right now i'm working on refactoring part i don't like. One of the part i do not like is the current level editor.

It's currently a seperate window that have the basic fonctionality (see screenshot). So i wants to make everything nicer and do a level editor using QT.

 

I want to make a basic QT Dialog that have embedded inside the game engine. However, i'm very confused about how i should do it. Right now, i'm struggling to make SDL2 work within QT and i'm not even sure if it's the right approche i'm doing. I'm currently able to draw with SDL2 within QT, but i really don't know how to make my game work inside.

 

Some detail: i'm using QT 5.3.x via Vs2012 (not qteditor). My game engine is an executable that use SDL2 for graphic, sound and key inputs. I've heard i might have problem with graphic rendering and sound, so i'm hesitant on how to proceed. Should i make my game engine a DLL to run within QT or is a .Exe okay? If more information is needed, i will give it.

 

As always, thank you very much for your time.

ps. Sorry for my english.

 


Culling points from a polygon.

28 August 2014 - 10:01 PM

Hello everyone,

 

i am currently experiencing a problem figuring an algorithm to remove unneeded points from a polygon structure. Normally i wouldn't consider posting here, but this one got me stumped for quite a while.

 

So here is the problem:

 

I have a std::vector of a Point structure that form a convexe polygon.

Somes of the points in the vector may be not needed and could be removed without changing the shape of the polygon.

I need to figure out how to remove thoses unneeded points.
 

I have attached a picture representating this array of points.
As you can see, two point can be removed without changing the shape of the polygon (50,0 and 50,50)

 

Here is more informations:

The polygon will always be contained within a known range (xmin to xmax, ymin to ymax).

A point always have X or Y equals either known min-max value (can be both). So if xmin = 0, xmax = 100, ymin = 0, ymax = 50, the point (25,25) is impossible.

The polygon is not always a simple square or rectangle and can be anything convexe (Trapeze, triangle, losange, etc...).

The array will always be sorted clockwise but the first point is not always 0,0.

 

Here is what i already tried to solve this problem:

I tried looking for points in the middle of a side and removing them . I think the idea is good, but my logic is faulty, though.
This algorythm work for a simple rectange but fail with anything more complexe, like a trapeze.
 

//////////////////////////////////////////////////////////////////////////
//
void Cull( std::vector<CVector> &_vertices, float _xmin, float _ymin, float _xmax, float _ymax )
{
    // Work for a simple square or rectangle, but fail for anything else like a trapeze.
    if(_vertices.size())
    {
        CVector lastvalidx = _vertices[0];
        CVector lastvalidy = _vertices[0];

        for(unsigned i = 1; i < _vertices.size();)
        {
            int n = i + 1 < _vertices.size() ? i + 1 : 0; // next point

            //Remove any point that is in the middle of a plane
            if( ( (_vertices[i].x != lastvalidx.x && (_vertices[i].x != _xmin && _vertices[i].x != _xmax) ) ||
                (_vertices[i].y != lastvalidy.y && (_vertices[i].y != _ymin && _vertices[i].y != _ymax) ) ) )
            {
                //remove the point, since it is not needed.
                _vertices.erase(std::remove(_vertices.begin(), _vertices.end(), _vertices[i]), _vertices.end());
            }
            else
            {
               lastvalidx = _vertices[i];
               lastvalidy = _vertices[i++];
            }
        }
    }   
}

 

If you would take a look at my problem, i will be thankful. I will continue trying to solve it on my side in the meantime.
I really hope my problem is not too confusing to understand. If more information is needed, i will post it.
As always, thank you very much for your time.


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.

 

 


PARTNERS