Where can I find...

  • Videogamer555
    11th Feb 2012 Member 0 Permalink
    ...these pieces of code?
    Code that controls what happens when TPT first starts up.
    Code that controls what happens on EVERY frame when the game is not paused.
    Code that controls what happens when you exit via the exit dialog (esc key on keyboard triggers it).
    Code that controls what buttons are on the preferences dialog box.
    Code that tells those preferences buttons what to do.
  • jacksonmj
    11th Feb 2012 Developer 0 Permalink
    All C/C++ programs run the main() function when you start them. In Powder Toy, main.c:
    int main(int argc, char *argv[]) //line 703
    {
    /* Stuff that happens when TPT first starts up. */
    while (!sdl_poll()) //the main loop //line 887
    {
    /* Stuff that happens on every frame */

    } // line 2726
    /* Stuff that happens when you exit */
    }


    Within the enormous loop in main(), there are a couple of if statements checking whether the game is paused and if it isn't, running a couple of functions like update_air() and update_particles().

    Searching for "esc" in main.c gives, on line 1204: if (sdl_key=='q' || sdl_key==SDLK_ESCAPE)
    {
    if (confirm_ui(vid_buf, "You are about to quit", "Are you sure you want to quit?", "Quit"))
    break;
    }

    i.e. if you click Quit on the exit dialog, it breaks out of the main loop and runs the stuff at the end of main().

    All the preferences dialog code is in simulation_ui(), at the bottom of interface.c.