Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    8
  • comments
    10
  • views
    7524

Cleanup

Sign in to follow this  
PixelOcean

378 views

So it's been a long time since I have made any updates, but I assure you this is not due to lack of progress on my part. In fact, I have finished both the asset and graphics management systems and have finally settled on my chosen method for propagating the objects about through the separate modules. I have also added a good deal of new functionality and established a framework that will allow me to implement even more (aka full alpha maps for each image, rather than a global alpha value per image).

Unfortunately, most of this progress has been behind-the-scenes stuff, so I don't really have any more to show for it than I did before - at least as far as pretty pictures go.

However, just to give you an idea of how vastly improved my code base is, here is a comparison of the asset instantiation and loading code (for only a single object), both before and after the asset system:

BEFORE:
// Here is just the initialization and loading for the Character object //
CImage* CharUp1 = NULL;
CImage* CharUp2 = NULL;
CImage* CharUp3 = NULL;
CImage* CharUp4 = NULL;
CImage* CharDown1 = NULL;
CImage* CharDown2 = NULL;
CImage* CharDown3 = NULL;
CImage* CharDown4 = NULL;
CImage* CharLeft1 = NULL;
CImage* CharLeft2 = NULL;
CImage* CharLeft3 = NULL;
CImage* CharLeft4 = NULL;
CImage* CharRight1 = NULL;
CImage* CharRight2 = NULL;
CImage* CharRight3 = NULL;
CImage* CharRight4 = NULL;

CSprite* CUpSprite = NULL;
CSprite* CDnSprite = NULL;
CSprite* CLfSprite = NULL;
CSprite* CRiSprite = NULL;

CObject* ChrObj = NULL;

CharUp1 = new CBitmap( "./Data/Images/Character/CharUp1.bmp" );
CharUp2 = new CBitmap( "./Data/Images/Character/CharUp2.bmp" );
CharUp3 = new CBitmap( "./Data/Images/Character/CharUp3.bmp" );
CharUp4 = new CBitmap( "./Data/Images/Character/CharUp4.bmp" );
CharDown1 = new CBitmap( "./Data/Images/Character/CharDown1.bmp" );
CharDown2 = new CBitmap( "./Data/Images/Character/CharDown2.bmp" );
CharDown3 = new CBitmap( "./Data/Images/Character/CharDown3.bmp" );
CharDown4 = new CBitmap( "./Data/Images/Character/CharDown4.bmp" );
CharLeft1 = new CBitmap( "./Data/Images/Character/CharLeft1.bmp" );
CharLeft2 = new CBitmap( "./Data/Images/Character/CharLeft2.bmp" );
CharLeft3 = new CBitmap( "./Data/Images/Character/CharLeft3.bmp" );
CharLeft4 = new CBitmap( "./Data/Images/Character/CharLeft4.bmp" );
CharRight1 = new CBitmap( "./Data/Images/Character/CharRight1.bmp" );
CharRight2 = new CBitmap( "./Data/Images/Character/CharRight2.bmp" );
CharRight3 = new CBitmap( "./Data/Images/Character/CharRight3.bmp" );
CharRight4 = new CBitmap( "./Data/Images/Character/CharRight4.bmp" );

CUpSprite = new CSprite( 0.175f );
CUpSprite->AddFrame( CharUp1 );
CUpSprite->AddFrame( CharUp2 );
CUpSprite->AddFrame( CharUp3 );
CUpSprite->AddFrame( CharUp4 );

CDnSprite = new CSprite( 0.175f );
CDnSprite->AddFrame( CharDown1 );
CDnSprite->AddFrame( CharDown2 );
CDnSprite->AddFrame( CharDown3 );
CDnSprite->AddFrame( CharDown4 );

CLfSprite = new CSprite( 0.175f );
CLfSprite->AddFrame( CharLeft1 );
CLfSprite->AddFrame( CharLeft2 );
CLfSprite->AddFrame( CharLeft3 );
CLfSprite->AddFrame( CharLeft4 );

CRiSprite = new CSprite( 0.175f );
CRiSprite->AddFrame( CharRight1 );
CRiSprite->AddFrame( CharRight2 );
CRiSprite->AddFrame( CharRight3 );
CRiSprite->AddFrame( CharRight4 );

ChrObj = new CObject( 400, 300, 0 );
ChrObj->AddSprite( CUpSprite, "CHAR_UP" );
ChrObj->AddSprite( CDnSprite, "CHAR_DOWN" );
ChrObj->AddSprite( CLfSprite, "CHAR_LEFT" );
ChrObj->AddSprite( CRiSprite, "CHAR_RIGHT" );
ChrObj->AddSprite( CDnSprite, "CHAR_DEFAULT", 0 );

// And here is the cleanup in the WndProc, which is the reason all
// of this fragmentation was necessary in the first place.
if( CharUp1 ) delete CharUp1;
if( CharUp2 ) delete CharUp2;
if( CharUp3 ) delete CharUp3;
if( CharUp4 ) delete CharUp4;
if( CharDown1 ) delete CharDown1;
if( CharDown2 ) delete CharDown2;
if( CharDown3 ) delete CharDown3;
if( CharDown4 ) delete CharDown4;
if( CharLeft1 ) delete CharLeft1;
if( CharLeft2 ) delete CharLeft2;
if( CharLeft3 ) delete CharLeft3;
if( CharLeft4 ) delete CharLeft4;
if( CharRight1 ) delete CharRight1;
if( CharRight2 ) delete CharRight2;
if( CharRight3 ) delete CharRight3;
if( CharRight4 ) delete CharRight4;

if( CUpSprite ) delete CUpSprite;
if( CDnSprite ) delete CDnSprite;
if( CLfSprite ) delete CLfSprite;
if( CRiSprite ) delete CRiSprite;

if( ChrObj ) delete ChrObj;







AFTER:

AssetSystem.SelectObject ( "CHARACTER" );
AssetSystem.SetPosition ( 368.0f, 268.0f, 20.0f );
AssetSystem.SelectGroup ( "IDLE" );
AssetSystem.SetFrameDelay( 0.2f );
AssetSystem.AddImage ( "./Data/Images/Character/CharDown1.bmp", 200 );
AssetSystem.AddImage ( "./Data/Images/Character/CharDown2.bmp", 175 );
AssetSystem.AddImage ( "./Data/Images/Character/CharDown3.bmp", 150 );
AssetSystem.AddImage ( "./Data/Images/Character/CharDown4.bmp", 175 );
AssetSystem.SelectGroup ( "UP" );
AssetSystem.SetFrameDelay( 0.2f );
AssetSystem.AddImage ( "./Data/Images/Character/CharUp1.bmp", 200 );
AssetSystem.AddImage ( "./Data/Images/Character/CharUp2.bmp", 175 );
AssetSystem.AddImage ( "./Data/Images/Character/CharUp3.bmp", 150 );
AssetSystem.AddImage ( "./Data/Images/Character/CharUp4.bmp", 175 );
AssetSystem.SelectGroup ( "DOWN" );
AssetSystem.SetFrameDelay( 0.2f );
AssetSystem.AddImage ( "./Data/Images/Character/CharDown1.bmp", 200 );
AssetSystem.AddImage ( "./Data/Images/Character/CharDown2.bmp", 175 );
AssetSystem.AddImage ( "./Data/Images/Character/CharDown3.bmp", 150 );
AssetSystem.AddImage ( "./Data/Images/Character/CharDown4.bmp", 175 );
AssetSystem.SelectGroup ( "LEFT" );
AssetSystem.SetFrameDelay( 0.2f );
AssetSystem.AddImage ( "./Data/Images/Character/CharLeft1.bmp", 200 );
AssetSystem.AddImage ( "./Data/Images/Character/CharLeft2.bmp", 175 );
AssetSystem.AddImage ( "./Data/Images/Character/CharLeft3.bmp", 150 );
AssetSystem.AddImage ( "./Data/Images/Character/CharLeft4.bmp", 175 );
AssetSystem.SelectGroup ( "RIGHT" );
AssetSystem.SetFrameDelay( 0.2f );
AssetSystem.AddImage ( "./Data/Images/Character/CharRight1.bmp", 200 );
AssetSystem.AddImage ( "./Data/Images/Character/CharRight2.bmp", 175 );
AssetSystem.AddImage ( "./Data/Images/Character/CharRight3.bmp", 150 );
AssetSystem.AddImage ( "./Data/Images/Character/CharRight4.bmp", 175 );







As you can see, the second sample, though still somewhat lengthy, is MUCH better than the first. Keep in mind that this is only for a single object - there's no telling how many objects will need to be loaded for a real scene. The initial approach would be impossible to use for anything larger than four or five objects.

On a similar note, creating the graphics system forced me to rearrange some functions, and the decrease in function calls actually improved my framerate by a small margin. A nice bonus indeed.

So the engine is far more manageable now, and I am putting the finishing touches on the graphics system as we speak. Or as I type, rather.

Next up are the physics and input systems.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!