home *** CD-ROM | disk | FTP | other *** search
- // For Standart Windows Input Devices Via Message Loop
-
- #include <win32/windows.h>
-
- #include <AutoPtr.h>
- #include <String.hpp>
- #include <Converter.h>
- #include <Log/LogPtr.h>
-
- #include "Interface2D.h"
- #include "Hardware2DSoft.h"
-
- #include "Sequences.h"
- #include <safe_new.h>
- #include <InputForGameExe/InputManagerPtr.h>
- #include <InputForGameExe/InputCreatorWindows.h>
-
- static Hardware2D * hardware = 0;
- static InputCreatorWindows * input_creator_windows = 0;
- static Interface2D * inter = 0;
- static HWND MainHWnd = NULL;
- static bool pause = false;
-
- void display()
- {
- static int old_tick_count = GetTickCount();
-
- int dt = GetTickCount() - old_tick_count;
- old_tick_count = GetTickCount();
-
- if( !pause && inter )
- {
- if( !inter->life_cycle( dt < 500 ? dt/1000.0 : 0.5 ) )
- PostMessage( MainHWnd, WM_CLOSE, 0, 0 );
- inter->render();
- if( dt < 10 )
- Sleep( 10 - dt );
- }
- }
-
- static void do_deinit()
- {
- delete inter; inter = NULL;
- delete hardware; hardware = NULL;
- delete input_creator_windows; input_creator_windows = NULL;
- if( int cc = Sequences::cached_count() )
- {
- LogPtr()->warning( String("in WinMain() Sequences::cached_count() == ") + Converter::convert( cc ) );
- }
-
- InputManagerPtr::destroy();
- LogPtr::destroy();
- }
-
- static 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_ACTIVATE:
- {
- int active = LOWORD(wParam);
- int fMinimized = (BOOL) HIWORD(wParam); // minimized flag
- switch( active )
- {
- case WA_ACTIVE:
- case WA_CLICKACTIVE:
- pause = false;
- break;
- case WA_INACTIVE:
- pause = true;
- break;
- }
- }
- break;
- case WM_PAINT:
- {
- PAINTSTRUCT paint;
- HDC hdc = BeginPaint( hwnd, &paint );
-
- EndPaint( hwnd, &paint );
- }
- return 0;
- case WM_CLOSE:
- do_deinit();
- DestroyWindow( hwnd );
- break;
- case WM_DESTROY:
- PostQuitMessage(TRUE);
- break;
- case WM_KEYDOWN:
- input_creator_windows->key_down( wParam );
- break;
- case WM_KEYUP:
- input_creator_windows->key_up( wParam );
- break;
- case WM_CHAR:
- input_creator_windows->key_char( wParam );
- break;
- case WM_MOUSEMOVE:
- input_creator_windows->mouse_move( x_pos, y_pos );
- break;
- case WM_LBUTTONDOWN:
- input_creator_windows->mouse_down( 0 );
- break;
- case WM_LBUTTONUP:
- input_creator_windows->mouse_up( 0 );
- break;
- case WM_RBUTTONDOWN:
- input_creator_windows->mouse_down( 1 );
- break;
- case WM_RBUTTONUP:
- input_creator_windows->mouse_up( 1 );
- break;
- }
- return DefWindowProc( hwnd, msg, wParam, lParam);
- }
-
- static 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 = LoadCursor(NULL, IDC_ARROW);
- 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 )
- {
- LogPtr()->message("Starting game...\n");
- srand( GetTickCount() );
-
- MainHWnd = do_init( hInstance, nCmdShow );
- if( !MainHWnd )
- {
- LogPtr()->error("WinMain() Failed to create winfow");
- return 1;
- }
-
- hardware = new Hardware2DSoft( MainHWnd );
- // hardware = new Hardware2DDirect( MainHWnd );
- input_creator_windows = new InputCreatorWindows();
-
- ShowWindow( MainHWnd, true );
- UpdateWindow( MainHWnd );
-
- inter = create_game( hardware );
-
- SetWindowText( MainHWnd, inter->get_caption().c_str() );
-
- 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();
- }
- return 0;
- }
-
- int main(void) // ─δ Ωε∞∩Φδ ≥ε≡α BCC5.5
- {
- HINSTANCE h = GetModuleHandle(NULL);
- return WinMain( h, NULL, GetCommandLine(), SW_SHOWNORMAL );
- }