home *** CD-ROM | disk | FTP | other *** search
- #include <windows.h>
-
- #include "AutoPtr.h"
- #include "String.h"
- #include "Resource.h"
- #include "PictureFormat.h"
-
- #include "ResourceManagerPtr.h"
- #include "PictureFormatManagerPtr.h"
- #include "LogPtr.h"
-
- #include "Interface2D.h"
- #include "SoftwareHardware2D.h"
-
- #include "Sequences.h"
- #include "safe_new.h"
-
- static Hardware2D * hardware = 0;
- static Interface2D * inter = 0;
- static HWND MainHWnd = NULL;
-
- void CALLBACK display(void)
- {
- static int old_tick_count = GetTickCount();
-
- int dt = GetTickCount() - old_tick_count;
- old_tick_count = GetTickCount();
-
- if( inter )
- {
- if( !inter->life_cycle( dt < 500 ? dt : 500 ) )
- PostMessage( MainHWnd, WM_CLOSE, 0, 0 );
- inter->render();
- }
- if( dt < 10 )
- Sleep( 10 - dt );
- SetWindowText( MainHWnd, (const char *)inter->get_caption() );
- }
-
- bool is_mouse_down = false;
-
- LRESULT CALLBACK WindowProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
- {
- int x_pos = LOWORD( lParam );
- int y_pos = HIWORD( lParam );
- switch (msg)
- {
- case WM_PAINT:
- {
- PAINTSTRUCT paint;
- HDC hdc = BeginPaint( hwnd, &paint );
-
- EndPaint( hwnd, &paint );
- }
- return 0;
- case WM_CLOSE:
- delete inter; inter = NULL;
- delete hardware; hardware = NULL;
- DestroyWindow( hwnd );
- break;
- case WM_DESTROY:
- PostQuitMessage(TRUE);
- break;
- }
- return DefWindowProc( hwnd, msg, wParam, lParam);
- }
-
- HWND do_init( HINSTANCE hInstance, int nCmdShow )
- {
- WNDCLASS wc;
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = WindowProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon( hInstance, NULL);
- wc.hCursor = NULL;
- wc.hbrBackground = CreateSolidBrush( RGB( 88, 128, 192 ) );
- wc.lpszMenuName = 0;
- wc.lpszClassName = "Hrissan";
- RegisterClass( &wc );
-
- HWND wnd = CreateWindow(
- "Hrissan",
- "Hrissan",
- WS_OVERLAPPED | WS_SYSMENU,
- 0, 0,
- CW_USEDEFAULT, CW_USEDEFAULT,
- NULL, NULL, hInstance, NULL );
- return wnd;
- }
-
- int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPTSTR lpCmdLine, int nCmdShow )
- {
- srand( GetTickCount() );
-
- MainHWnd = do_init( hInstance, nCmdShow );
- if( !MainHWnd )
- {
- LogPtr()->error("WinMain() Failed to create winfow");
- return 1;
- }
-
- hardware = new SoftwareHardware2D( MainHWnd );
-
- ShowWindow( MainHWnd, true );
- UpdateWindow( MainHWnd );
-
- inter = create_game( hardware );
-
- unsigned frames_done = 0;
- while( 1 )
- {
- MSG msg;
- if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
- {
- if( !GetMessage( &msg, NULL, 0, 0 ) )
- {
- break ;
- }
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- else
- {
- display();
- ++frames_done;
- }
- }
-
- if( inter )
- {
- delete inter; inter = NULL;
- LogPtr()->warning( "After Main Loop Interface2D is still valid" );
- }
- if( hardware )
- {
- delete hardware; hardware = NULL;
- LogPtr()->warning( "After Main Loop Hardware2D is still valid" );
- }
-
- if( unsigned cc = Sequences::cached_count() )
- {
- LogPtr()->warning( String("in WinMain() Sequences::cached_count() == ") + String::convert( cc ) );
- }
-
- LogPtr::destroy();
- ResourceManagerPtr::destroy();
- PictureFormatManagerPtr::destroy();
- return 0;
- }
-
- int main(void) // ─δ Ωε∞∩Φδ ≥ε≡α BCC5.5
- {
- HINSTANCE h = GetModuleHandle(NULL);
- return WinMain( h, NULL, GetCommandLine(), SW_SHOWNORMAL );
- }