Startup Interface

Describes everything about the startup of the Renderer and the Resources.  Setups the display mode and controls display mode shifts and loss of window focus.  Some functionality is in the main Source1.cpp, however most logic is in this interface.

Summary
Startup InterfaceDescribes everything about the startup of the Renderer and the Resources.
startup.cpp
Enumerations
MODE_TYPSpecifies what mode the program is running in
STATE_TYPDescribes the current running mode.
Macros
RGB10BIT_STRINGUsed to force the compiler to write out the words RGB10BIT
Types
SETTINGSAlias for SETTINGS_TYP
SETTINGS_PTRAlias for a pointer to SETTINGS_TYP
SETTINGS_TYPThis structure is more or less obsolete.
Variables
WidthUINT The width of the display surface
HeightUINT The height of the display surface
IsWindowedUINT Specifies whether the program is windowed or not
IsActiveUINT Specifies wether the program is still active or not
BackBufferFormatUINT Specifies the exact type of the back buffer for D3D objects to know
IsLogWindowUINT Specifies wether a log window exists or not
IsDebugWindowUINT Specifies wether a debug control panel window exists or not
dwD3DInitModeDWORD Some options for the D3DInterface to use.
VSyncUINT Determines wether VSync should be attempted or not
bppUINT The Bits per Pixel of the display
hzUINT The Hertz the screen updates at.
ModeMODE_TYP The rendering mode requested
hwndMainHWND The main window
CStartupInterface to control and query the running state of the program.
Constructors
CStartupSimply increases the internal reference count
~CStartupSimply decreases the internal reference count
Functions
ShowStartupDialogShow the main startup dialog and save the results into the class.
InitDevicesInitializes devices for the desired running mode.
ShutdownShutdown all the interfaces.
TestStateTests the state of the devices for any changes.
ProcessStateProcesses the current state of the interface.
TriggerTestStateIf possible, puts the interface into STATE_TEST.
DisplayModeShiftPuts the startup into a state to change the display mode from Fullscreen or Windowed.
ResizeWindowResizes the back buffer to match a resized window.
Access Functions
getStateRetrieves the state of the interface
getModeThe current MODE_TYP
getWidthThe current width of the window or back buffer
getHeightThe current height of the window or back buffer
getFSWidthThe stored fullscreen width of the backbuffer
getFSHeightThe stored fullscreen height of the backbuffer
getBppThe bits per pixel for the current display mode.
getHzThe current HZ the monitor is sync at.
getBackBufferFormatSpecifies the exact type of the pixel format of the back buffer.
getVSyncTrue if the display refresh rate is in sync with the monitor.

startup.cpp

DFLT_SCREEN_WIDTHDefaults to 800.  Determines the highlighted screen size in the startup dialog
DFLT_SCREEN_HEIGHTDefaults to 600.  Determines the highlighted screen size in the startup dialog
RGB10BITDefaults to 40.  Used to identify a 10bit per channel RGB BitsPerPixel.
STARTUP_EXITDefaults to 100.  This is the return value when EXIT is pressed in the Startup dialog

Enumerations

MODE_TYP

Specifies what mode the program is running in

MODE_NONEUninitialized and not ready for startup
MODE_D3DInitialized in Direct3D Mode
MODE_DDRAWInitialized in DirectDraw Mode
MODE_GDIInitialized in GDI Mode

STATE_TYP

Describes the current running mode.  This is used in a finite state routine in the main program to keep the running mode valid and respond to changing in the environment.

STATE_SHUTDOWNSignals that the program is shutting down
STATE_ERRORStartup assumed all was well, but interfaces are not ready for unknown reasons
STATE_CLEANNothing initialized or setup.  Can start in any mode at this point
STATE_DISPLAY_REINIT_TOTALReinitialization requested for a total reset
STATE_DISPLAY_REINIT_WINDOWEDReinitialization requested for a display mode shift to Windowed mode
STATE_DISPLAY_REINIT_FULLSCREENReinitialization requested for a display mode shift to Fullscreen mode
STATE_DISPLAY_REINIT_RESIZEReinitialization requested for a resize in the window
STATE_DISPLAY_REINIT_PENDINGDisplay and Resources must be re initialized and can be at any time
STATE_DISPLAY_INIT_OKDisplay is initialized and ok
STATE_RESOURCES_INIT_OKResource class is initialized with the mode and is ok
STATE_RENDERER_INIT_OKRenderer initialization completed
STATE_WAITDisplay and Resources must be re initialized, but unable to yet
STATE_TESTRequest for testing the interfaces for ready status
STATE_RUNStartup is in run mode and all is ready to go

Macros

RGB10BIT_STRING

Used to force the compiler to write out the words RGB10BIT

#define RGB10BIT_STRING     STRINGIZE(RGB10BIT)

Types

SETTINGS

Alias for SETTINGS_TYP

SETTINGS_PTR

Alias for a pointer to SETTINGS_TYP

SETTINGS_TYP

typedef struct SETTINGS_TYP

This structure is more or less obsolete.  It has not been removed out of the initial startup procedures.  All of the functions have been moved into CStartupCStartup uses this structure to setup defaults.

Summary
Variables
WidthUINT The width of the display surface
HeightUINT The height of the display surface
IsWindowedUINT Specifies whether the program is windowed or not
IsActiveUINT Specifies wether the program is still active or not
BackBufferFormatUINT Specifies the exact type of the back buffer for D3D objects to know
IsLogWindowUINT Specifies wether a log window exists or not
IsDebugWindowUINT Specifies wether a debug control panel window exists or not
dwD3DInitModeDWORD Some options for the D3DInterface to use.
VSyncUINT Determines wether VSync should be attempted or not
bppUINT The Bits per Pixel of the display
hzUINT The Hertz the screen updates at.
ModeMODE_TYP The rendering mode requested
hwndMainHWND The main window

Variables

Width

UINT Width

UINT The width of the display surface

Height

UINT Height

UINT The height of the display surface

IsWindowed

UINT IsWindowed

UINT Specifies whether the program is windowed or not

IsActive

UINT IsActive

UINT Specifies wether the program is still active or not

BackBufferFormat

UINT BackBufferFormat

UINT Specifies the exact type of the back buffer for D3D objects to know

IsLogWindow

UINT IsLogWindow

UINT Specifies wether a log window exists or not

IsDebugWindow

UINT IsDebugWindow

UINT Specifies wether a debug control panel window exists or not

dwD3DInitMode

DWORD dwD3DInitMode

DWORD Some options for the D3DInterface to use.

VSync

UINT VSync

UINT Determines wether VSync should be attempted or not

bpp

UINT bpp

UINT The Bits per Pixel of the display

hz

UINT hz

UINT The Hertz the screen updates at.  May not be able to determine

Mode

MODE_TYP Mode

MODE_TYP The rendering mode requested

hwndMain

HWND hwndMain

HWND The main window

CStartup

class CStartup

Interface to control and query the running state of the program.  Contains all information from the options dialog and allows the display to respond to windows environment changes.

The follow code controls the state.  This should be in your main program.

STATE_TYP   StartupState;

switch( StartupState = Startup.getState() )
{
case STATE_RUN:
    break;
case STATE_WAIT:
case STATE_TEST:
    // Validate the running state
    if( ( StartupState = Startup.TestState() ) != STATE_RUN )
    {
        if(bMainGate)
            LOG_INFO("Closing main gate because of state change");

        bMainGate=false;
    } else
    {
        if(!bMainGate)
            LOG_INFO("Opening main gate because of successful state change");

        bMainGate=true;
    }
    break;
case STATE_ERROR:
case STATE_SHUTDOWN:
    break;
default:
    // Let startup process the problem
    if( ( StartupState = Startup.ProcessState() ) == STATE_RUN )
    {
        if(!bMainGate)
            LOG_INFO("Opening main gate because of successful state change");

        bMainGate=true;
    }

    break;
}
Summary
Constructors
CStartupSimply increases the internal reference count
~CStartupSimply decreases the internal reference count
Functions
ShowStartupDialogShow the main startup dialog and save the results into the class.
InitDevicesInitializes devices for the desired running mode.
ShutdownShutdown all the interfaces.
TestStateTests the state of the devices for any changes.
ProcessStateProcesses the current state of the interface.
TriggerTestStateIf possible, puts the interface into STATE_TEST.
DisplayModeShiftPuts the startup into a state to change the display mode from Fullscreen or Windowed.
ResizeWindowResizes the back buffer to match a resized window.
Access Functions
getStateRetrieves the state of the interface
getModeThe current MODE_TYP
getWidthThe current width of the window or back buffer
getHeightThe current height of the window or back buffer
getFSWidthThe stored fullscreen width of the backbuffer
getFSHeightThe stored fullscreen height of the backbuffer
getBppThe bits per pixel for the current display mode.
getHzThe current HZ the monitor is sync at.
getBackBufferFormatSpecifies the exact type of the pixel format of the back buffer.
getVSyncTrue if the display refresh rate is in sync with the monitor.

Constructors

CStartup

CStartup()

Simply increases the internal reference count

~CStartup

~CStartup()

Simply decreases the internal reference count

Functions

ShowStartupDialog

int ShowStartupDialog(HINSTANCE hinstance)

Show the main startup dialog and save the results into the class.

Parameters

hinstanceHINSTANCE the application instance to attach the window to

Returns

False if successful.  Error code otherwise.

InitDevices

int InitDevices()

Initializes devices for the desired running mode.  Handles the initalization of both the Renderer and the Resource Interfaces.  It will catch exceptions thrown by the D3DInterface, DDrawInterface and the GDIInterface.

Returns

False if successful.  Error code otherwise.

Shutdown

static void Shutdown()

Shutdown all the interfaces.  Calls D3DInterface::ShutdownDevice, DDrawInterface::ShutdownInterface, GDIInterface::Shutdown, RSRC::Shutdown, and <RNDR::Shutdown>.  Puts the class into mode STATE_SHUTDOWN.

TestState

STATE_TYP TestState()

Tests the state of the devices for any changes.  If the STATE_TYP of the class is smaller than STATE_TEST it simply returns the state for later processing.  Otherwise it changes the STATE_TYP to STATE_DISPLAY_REINIT_PENDING.

Returns

STATE_TYP Is the current state of the Startup Interface.

ProcessState

STATE_TYP ProcessState()

Processes the current state of the interface.  It will run any required procedures to put the state back into STATE_RUN.  However it may place the mode into a different mode, even STATE_ERROR depending on the needs.

Returns

STATE_TYP with the current mode after processing.

TriggerTestState

static STATE_TYP TriggerTestState()

If possible, puts the interface into STATE_TEST.  If the STATE_TYP is already in a state below STATE_TEST, then it simple returns it.

Returns

STATE_TYP with the current mode after atempting to set STATE_TEST.

DisplayModeShift

STATE_TYP DisplayModeShift(HWND LogWindow)

Puts the startup into a state to change the display mode from Fullscreen or Windowed.  Also handles hiding and showing the log window if one exists.

Parameters

LogWindowThe log window that should be hidden or shown, depending on options

Returns

STATE_TYP of the current state of the startup interface.

ResizeWindow

static STATE_TYP ResizeWindow(int width,
int height)

Resizes the back buffer to match a resized window.  Puts the interface into a STATE_DISPLAY_REINIT_RESIZE.

Parameters

widthThe new width of the window
heightThe new height of the window

Returns

STATE_TYP of the current state of the interface.

Access Functions

getState

static STATE_TYP getState()

Retrieves the state of the interface

Returns

STATE_TYP with current state of the interface

getMode

MODE_TYP getMode() const

The current MODE_TYP

Returns

MODE_TYP of the interface

getWidth

UINT getWidth() const

The current width of the window or back buffer

Returns

UINT with the width

getHeight

UINT getHeight() const

The current height of the window or back buffer

Returns

UINT with the height

getFSWidth

UINT getFSWidth() const

The stored fullscreen width of the backbuffer

Returns

UINT with the width

getFSHeight

UINT getFSHeight() const

The stored fullscreen height of the backbuffer

Returns

UINT with the height

getBpp

UINT getBpp() const // Stores the bits per pixel

The bits per pixel for the current display mode.  Could be 15,16,32, or RGB10BIT.

Returns

UINT with the bpp of the pixel format

getHz

UINT getHz() const // The hz the screen updates at

The current HZ the monitor is sync at.  May be zero if unable to determine

Returns

UINT with the Hz of the monitor

getBackBufferFormat

UINT getBackBufferFormat() const // Specifies the exact type of the back buffer

Specifies the exact type of the pixel format of the back buffer.  Specific to D3D types.

Returns

UINT with the D3DFORMAT.

getVSync

UINT getVSync() const // May not even be an option, but will include anyway

True if the display refresh rate is in sync with the monitor.  Vertical Sync.

Returns

UINT True if on, false if not

typedef struct SETTINGS_TYP
This structure is more or less obsolete.
UINT Width
UINT The width of the display surface
UINT Height
UINT The height of the display surface
UINT IsWindowed
UINT Specifies whether the program is windowed or not
UINT IsActive
UINT Specifies wether the program is still active or not
UINT BackBufferFormat
UINT Specifies the exact type of the back buffer for D3D objects to know
UINT IsLogWindow
UINT Specifies wether a log window exists or not
UINT IsDebugWindow
UINT Specifies wether a debug control panel window exists or not
DWORD dwD3DInitMode
DWORD Some options for the D3DInterface to use.
class D3DInterface
This is the main interface into Direct3D.
UINT VSync
UINT Determines wether VSync should be attempted or not
UINT bpp
UINT The Bits per Pixel of the display
UINT hz
UINT The Hertz the screen updates at.
MODE_TYP Mode
MODE_TYP The rendering mode requested
Specifies what mode the program is running in
HWND hwndMain
HWND The main window
class CStartup
Interface to control and query the running state of the program.
CStartup()
Simply increases the internal reference count
~CStartup()
Simply decreases the internal reference count
int ShowStartupDialog(HINSTANCE hinstance)
Show the main startup dialog and save the results into the class.
int InitDevices()
Initializes devices for the desired running mode.
static void Shutdown()
Shutdown all the interfaces.
STATE_TYP TestState()
Tests the state of the devices for any changes.
STATE_TYP ProcessState()
Processes the current state of the interface.
static STATE_TYP TriggerTestState()
If possible, puts the interface into STATE_TEST.
Request for testing the interfaces for ready status
STATE_TYP DisplayModeShift(HWND LogWindow)
Puts the startup into a state to change the display mode from Fullscreen or Windowed.
static STATE_TYP ResizeWindow(int width,
int height)
Resizes the back buffer to match a resized window.
static STATE_TYP getState()
Retrieves the state of the interface
MODE_TYP getMode() const
The current MODE_TYP
UINT getWidth() const
The current width of the window or back buffer
UINT getHeight() const
The current height of the window or back buffer
UINT getFSWidth() const
The stored fullscreen width of the backbuffer
UINT getFSHeight() const
The stored fullscreen height of the backbuffer
UINT getBpp() const // Stores the bits per pixel
The bits per pixel for the current display mode.
UINT getHz() const // The hz the screen updates at
The current HZ the monitor is sync at.
UINT getBackBufferFormat() const // Specifies the exact type of the back buffer
Specifies the exact type of the pixel format of the back buffer.
UINT getVSync() const // May not even be an option, but will include anyway
True if the display refresh rate is in sync with the monitor.
class DDrawInterface
Controls DirectDraw and provides a common interface to all of its functions.
class GDIInterface
Provides an interface to startup and shutdown the GDI+ Interface
static void ShutdownDevice()
Shutsdown all the D3D Interfaces.
static void ShutdownInterface()
Shutdown the interface.
static void Shutdown()
Shutsdown GDI+.
void Shutdown()
Shuts down the resource interface
Signals that the program is shutting down
Describes the current running mode.
Display and Resources must be re initialized and can be at any time
Startup is in run mode and all is ready to go
Startup assumed all was well, but interfaces are not ready for unknown reasons
Reinitialization requested for a resize in the window
Defaults to 40.
Close