Archive

Posts Tagged ‘C++’

Early-outs for n00bs

November 26th, 2011 No comments

Sometimes I see people code something up like the following:

void AwesomeFunc( void )
{
    if( var == 3 )
    {
        if( var2 == 4 )
        {
            if( var4 == "napkin" )
            {
                if( var5 == 8495 )
                {
                    g_flag = true;
                }
                else
                {
                    Debug.Log( "var5 wasn't 8495" );
                }
            }
            else
            {
                Debug.Log( "var4 was not napkin" );
            }
        }
        else
        {
            Debug.Log( "var2 wasn't 4" );
        }
    }
    else
    {
        Debug.Log( "var wasn't 3" );
    }
}

Read more…

Categories: Blog, Tips 'n Tricks Tags: ,

Testing at Microsoft

November 26th, 2011 No comments

I was a contract employee at Microsoft, an SDET I. While I was there I learned quite a lot about testing, and I really believe it made me a much better programmer. Although my time there was short lived, I managed to retain some of my testing knowledge, and I hope to share that with you now. So I’ll quickly and briefly cover the basics of testing. I’m not talking about unit testing either. I’ll break down the types of tests you have into different categories. There may be more.

  • BVT (Base verification tests)
  • –Positive test cases
  • FVT (Functional verification tests)
  • –Positive Test CasesĀ (Tester tests for expected failures )
  • –Negative Test Cases (We catch unexpected failures during testing (hopefully) )

Read more…

Categories: Blog Tags: , , , , ,

Const qualifier reminder

November 7th, 2011 No comments

Just a reminder how const-ness works. If I remember correctly.

// These two lines are the same type
// const and int can be switched around and the result is the same.
const int i;
int const j;

// If the word "const" follows the "*", it affects the pointer
int* const k;

// Both the pointer and the int are const
const int* const m;

// Same as line above, it just looks weird
int const * const n;

// Does the const affect the pointer or the int? The int..
int const * p;
Categories: Blog, Miscellaneous, Tips 'n Tricks Tags: ,

Math trickery for 1D & 2D arrays

August 14th, 2011 No comments

Once upon a time, there was a language that didn’t have 2 dimensional arrays. This greatly upset the programmer. Fortunately, the programmer was swift in the art of arithmetic and overcame this obstacle easily.

Lets say for example, we only have access to a 1 dimensional array data structure and it has 50 elements in it.

int data[50];

Lets break this array up into 10 rows and 5 columns to make a grid. So how do we get access to a position say data[4][3]?
There are two things I’m going to teach you now:
1) Retrieve the column & row numbers from a linear index counter.
2) Retrieve the index from a row & column numbers.

Read more…

Categories: Articles, Blog, Miscellaneous Tags: , ,

What is the difference between aggregation and composition?

May 5th, 2011 No comments

This question has bothered me for some time and I always forget. So I wrote it down here and added an answer.

Composition : An object contains another object. When the container object dies, so does the composited objects.

Aggregation : An object pseudo-contains another object (contains a pointer to it). When the container object dies, the containees do not.

class Container
{
public:
    // Composition
    Containee _c[5];

    // Aggregation
    Containee* _pc[5];
}

Sometimes aggregation is called composition when the difference doesn’t matter.
Note: In UML, aggregation is an unfilled diamond, whereas composition is a filled diamond.

References:
http://en.wikipedia.org/wiki/Object_composition#Aggregation

Engine Update 001

September 28th, 2010 No comments

I’m in the process of redoing my “testing” engine. I hope to make it robust, scalable, modular, while supporting a lot of other different technologies. This is the start of it using D3D9, but don’t worry, I’ll eventually port it over to d3d11. I’m going to skip 10 though. I have lots of things in the works for it too!

As you can see here, I have a few simple cubes and a triangle grid. Most likely the grid will turn into terrain. I haven’t decided what I wanted to name the engine yet. I’m leaning towards “Tornado.” I remember looking into a physics engine a while ago named “Cyclone” and I thought the name was interesting.

C++ Casting

September 5th, 2010 No comments
Categories: Articles Tags:

The hidden default constructor in C++

February 19th, 2010 No comments

I think I’m going to start posting about general C++ stuff too and since C++ is my favorite language (aside from assembly) I thought it would be interesting to post obscure C++ things that I find. Today I’m going to talk about a blog post that I found a while ago regarding constructors.

The fellow (I forgot where I saw it) mentioned that there was a significant difference the two lines of code.

Class *pClass = new Class;
Class *pClass = new Class();

The first line will NOT initialize intrinsic data types. So they will be filled with whatever when the object is instantiated.
The second line, on the other hand, WILL initialize all intrinsic data types to zero.
There are a couple of issues to be aware of though:

1) There must NOT be a default constructor available.
2) This is very well compiler/implementation dependent. I haven’t actually checked the standard though but I don’t see why the standard would define such a thing since it could (theoretically) impose a performance risk.

Looking back at point 1, lets use an example:

Class{
int foo;
};

Note: No default constructor or destructor. In this case, the compiler will provide them for your automatically. At least Microsoft’s compiler will. In that case, it will be kind enough to also initialize foo to zero if you specify

new Class();

as opposed to

new Class;


Categories: Blog, Tips 'n Tricks Tags: ,

A Few Code Snippets

February 19th, 2010 No comments

Periodically I’ll stumble across a small but useful piece of code. I have a small list right now, but as I stumble across them, I’ll post them here. Note: I do not take credit for any of this code.

Pausing your application

__asm int 3;

or

__debugbreak();

Convert any data type to a std::string object

#include <sstream>
template <typename T>
std::string toString( const T &arg )
{
    std::stringstream ss;
    ss << arg;
    return ss.str();
}

Test if a float is zero or near zero

inline bool IsZero( float val )
{
    return( fabs( val ) < EPSILON);
}

EPSILON is a #define that is something small, like 0.002f
Note, I will repost, I just realized that serendipity can’t handle angle brackets…

Categories: Blog, Tips 'n Tricks Tags: , ,

Sundown Cerose

February 25th, 2009 No comments

Description: A fast-paced comic book style 3D isometric based action/adventure game where the player must battle hordes of minions in order to save the galaxy.


Gameplay video footage of Sundown Cerose.

Position: Technical Director

Date: 2008 – 2009

Accomplishments:

  • Designed and coded the input, using DirectInput, scene management system, using TinyXML, physics, collision detection, and the engine framework to allow for dynamic object interactivity.
  • Implemented all of the required features by utilizing C/C++, the Win32 API, DirectX, C/C++ Standard Libraries, and the STL to ensure a robust framework on the Windows PC platform.
  • Worked closely with the designer and the producer to successfully implement the game’s required features before the preceded milestones.
  • Engineered a component based design using Object Oriented Programming principles to allow for versatility in the engine framework.
  • Assisted in the core design of “Sundown Cerose” in order to plan the development of a dynamic and robust engine architecture that would meet the designs requirements.
  • Designed and Implemented the level editor

Platform: PC

Requirements: Windows XP, DirectX 9 compatible graphics card, 512 MB RAM, 1.6 GHz Processor, Vertex/Pixel shaders 2.0 or greater.

Controls: Move: W,A,S,D
Aim: Mouse
Shoot fireball:Left mouse button
Flame thrower: Right mouse button

Screen Shots:

The flame thrower in action.

The player was hit and is now running away.

The player shooting fireballs.

The player charging at the enemies.