TS3Main.c

/*
 *  File:       TS3Main.c
 *
 *  Contents:   Main entry point, main loop, initialize and exit code
 *
 *  Copyright © 1996 Apple Computer, Inc.
 */
 
#include <Dialogs.h>
#include <Fonts.h>
#include <Memory.h>
#include <QuickDraw.h>
#include <Types.h>
#include <Windows.h>
 
#include <QD3D.h>
 
#include "TS3Events.h"
#include "TS3Main.h"
#include "TS3Menu.h"
#include "TS3Message.h"
#include "TS3Sound.h"
#include "TS3TestAPI.h"
#include "TS3TestHiLevel.h"
#include "TS3TestLoLevel.h"
#include "TS3Utils.h"
#include "TS3Window.h"
 
#ifdef APP_LOADS_SOUND_COMPONENT
    #include "S3Private.h"
#endif
 
void main(
    void);
 
static void Init(
    void);
 
static void Exit(
    void);
 
 
static Boolean gAlive = false;
 
 
 
/* =============================================================================
 *      main
 *
 *  Initializes, processes events, does the idle-time stuff, and exits.
 * ========================================================================== */
void main(
    void)
{
    Init();
    
    while (gAlive)
    {
        Events_Process();
    }
    
    Exit();
}
 
 
/* =============================================================================
 *      Main_LastRoundup (external)
 *
 *  Requests the main event loop to gracefully exit.
 * ========================================================================== */
void Main_LastRoundup(
    void)
{
    gAlive = false;
}
 
 
/* =============================================================================
 *      Init (internal)
 *
 *  Initialization of toolbox and our stuff.
 * ========================================================================== */
void Init(
    void)
{
    // Initialize the toolbox
    MaxApplZone();
    MoreMasters();
    
    InitGraf(&qd.thePort);
    InitFonts();
    InitWindows();
    InitDialogs(NULL);
    InitCursor();
    InitMenus();
    TEInit();
    
    // Should we load S3Localization?
    #ifdef APP_LOADS_SOUND_COMPONENT
    {
        ComponentDescription    filterDesc;
        Handle                  filterNameHdl;
        Handle                  infoHdl;
        
        // Register (or find) our components
#ifdef REAL_3D_INSTALL
        filterDesc.componentType            = kSoundEffectsType;
#else
        filterDesc.componentType            = 'sdec';
#endif
        filterDesc.componentSubType         = kSSpLocalizationSubType;
        filterDesc.componentManufacturer    = kAppleManufacturer;
        filterDesc.componentFlags           = 0L;
        filterDesc.componentFlagsMask       = 0L;
        
        filterNameHdl = NewHandle (sizeof (Str255));
        BlockMove ((Ptr)"\pS3Localization", (Ptr)(*filterNameHdl), sizeof (Str255));
 
        infoHdl = NewHandle (sizeof (Str255));
        BlockMove ((Ptr)"\pThis component provides 3D Audio.", (Ptr)(*infoHdl), sizeof (Str255));
        
        // Register the Filter component
        RegisterComponent (&filterDesc, NewComponentRoutineProc(SoundComponentProc), kRegisterGlobally,
            filterNameHdl, infoHdl, nil);
    }
    #endif
    
    // Initialize our modules
    Utils_Init();
    Message_Init();
    Menu_Init();
    Events_Init();
    Window_Init();
    TestHiLevel_Init();
    Sound_Init();
    TestLoLevel_Init();
    TestAPI_Init();
    
    // We're off...
    gAlive = true;
}
 
 
/* =============================================================================
 *      Exit (internal)
 *
 *  Cleans up before exit.
 * ========================================================================== */
void Exit(
    void)
{
    // Exit our modules
    TestLoLevel_Exit();
    TestHiLevel_Exit();
    TestAPI_Exit();
    Sound_Exit();
    Window_Exit();
    Events_Exit();
    Menu_Exit();
    Message_Exit();
    Utils_Exit();
}