1 min read

handmade-hero

Table of Contents

Handmade Hero

Intro

This is my personal study notes of the awesome project Handmade Hero.

If you think writing a professional-quality game from scratch on your own (no engine no library) is interesting and challenging, I highly recommend this project.

In my opinion, it's the best I can find.

Showcase

Day 85

  • We can jump p
  • We can shoot p+
  • We can go upstair and downstair pb bo8
  • We have a big world and many rooms p:
  • We have a basic procedure generated ground p ?

Env

Windows 10 with Visual Studio 2019 community version and Sublime Text 3.

Build system for Sublime Text 3:

{
  "build_systems":
  [
    {
      "name": "HandmadeHero",
      "shell_cmd": "build",
      "file_regex":"^(.+?)\\((\\d+\\))(): (error)(.+)$"
    }
  ]
}

Setup

NOTE: This repo does not contain copyrighted HandmadeHero assets, to build this repo, please consider preorder HandmadeHero.

  • Create a w drive using subst: subst w: /c/whatever_directory_you_choose
  • Clone this repo into the root of w
  • Install Visual Studio 2019 community version
  • cd into w and init cl: .\handmade-hero\misc\shell.bat
  • Build and enjoy! build

Code Style

My preferred code style for C is different from Casey's.

  • snake_case for types, e.g. game_world
  • camelCase for variables, e.g. globalRunning
  • PascalCase for functions and macro functions, e.g. GameUpdateVideo
  • UPPER_SNAKE_CASE for macro constants, e.g. TILES_PER_CHUNK
  • Prefix an underscore to indicate that this function should only be called with a corresponding macro, e.g. _PushSize

Marks

  • NOTE: Something we need to pay attention to
  • PLAN: Something we plan to do it later
  • RESOURCE: External valuable resource
  • DIFF: Something I have done it differently from Casey
  • FUN: Something interesting to know, like Windows can't correctly handle file formats they invented
  • CASEY: Casey's opinion about programming

Game Programming

  • Every memory allocation should go through a macro, it will make the debugging much easier.
  • Premultiplied Alpha: check day 83 for more details.
  • Gamma Correction: check day 94 for more details.
  • Transform Normal: check day 102 for more details.

Windows Programming

Command Prompt

  • dir /s [keyword]: search files
  • findstr -s -n -i -l [keyword]: find strings

Win32 API

  • WS_EX_TOPMOST: make window in front of others
  • WS_EX_LAYERED and SetLayeredWindowAttributes : change window alpha

Visual Studio

  • Spy++: inspect windows and messages

Resources

Build and Debug

  • To build the application:
    cd handmade\code
    build.bat
  • To debug the application:
    devenv ..\..\build\win32_handmade.exe

This will open visual studio, once there remember to change "Executable" and "Working Directory" on exe properties. Example:

alt text

Then just hit f11 and start debugging!

Debugging Tools

  • Press P Key to Pause
  • Press L Key to start input loop and L key again to lock the loop
  • Press Alt + Enter Keys to go full screen

Troubleshoot

If when trying to build the application, you receive the error "The input line is too long. The syntax of the command is incorrect." make sure to put the project folder as close as possible to C: and if the error persists just restart your cmd.

Doubts / Learn

##Vectors