SGDK. Debug the game (Debug)

Preface.

With each article, the project becomes more complicated and complicated, and someday, it will grow into a full-fledged game. But imagine that in the huge code of the game for 1000 lines of code, there was a bug. And to fix it needs debugging, i.e. some message that will tell us which line of code is responsible for the bug. You can do without debugging, but, you know, debugging is easier.

Turn on debug.

To enable debugging, you need to open Gens KMod and select Option->Debug.

And turn on the box “Active Development Features

Debug is enabled, you can see debug messages in CPU->Debug->Messages. It’s empty for now, but we’ll fix it soon.

Also, your computer may start to lag because of the Gens KMod emulator, so close it immediately after use.

Writing debug messages.

Open the project from the SGDK. Move around the map.

In main.c replace the setCameraPosition function with this:

void setCameraPosition(s16 x, s16 y)
{
    if ((x != camPosX) || (y != camPosY))
    {
        camPosX = x;
        camPosY = y;
        MAP_scrollTo(bga, x, y);
		
KLog_F1("x: ", posX);
	KLog_F1("y: ", posY);
    }
}

All I did was added a debug message with x,y coordinates.

The function KLog_F1 takes a string and a fix32 number, and outputs them to the CPU->Debug->Messages of the Gens KMod emulator.

Now, start and move the camera (make sure debug is on)

Works like clockwork. But what if you want to derive the number u32 or f8?

If you have SGDK installed on drive C, then follow this link: file:///C:/SGDK/doc/html/tools_8h.html

You will find the best source of information on SGDK (analogue of ZDoom wiki for Doom). Which describes in detail all the functions.

Choose the function for your liking.

Getting a FPS counter.

To show FPS, put this line in your while loop.

VDP_showFPS(FALSE);  

FALSE – means that the number will be an integer, otherwise float.

Run.

The value of the FPS counter will scroll along with map, because the FPS counter and map are on the same plane (BG_A). So, you need to move map to the back layer (BG_B).

In this line, I replaced BG_A with BG_B.

bga = MAP_create(&bga_map, BG_B, TILE_ATTR_FULL(0, FALSE, FALSE, FALSE, TILE_USERINDEX));

Compile and run.

It’s better that way.

Conclusion.

In this article, I told minimum of information about debug, if it is not enough, I will expand this article. In any case, this material will be very useful for collision debugging.

Final result.

Пожалуйста отключи блокировщик рекламы, или внеси сайт в белый список!

Please disable your adblocker or whitelist this site!