Exemple #1
0
// Entry point
int main(int argc, char* argv[])  // <- this must match exactly, since SDL rewrites it
{
	SetStdOutToNewConsole();

	MainEngine Engine;

	printf("Loading...\n");
	Engine.Init();

	printf("SDL Testing!\n");
	Engine.Start();

	printf("Quitting...\n");

	return 0;
}
//-----------------------------------WinMain-----------------------------------------
//	Entry point for our windows application
//-----------------------------------------------------------------------------------
int WINAPI WinMain(	HINSTANCE hinstance,
					          HINSTANCE hprevinstance,
					          LPSTR lpcmdline,
					          int ncmdshow)
{
	SetStdOutToNewConsole();
	WNDCLASSEX winclass; 
	HWND	   hwnd;	 
	MSG		   msg;		 

	// first fill in the window class stucture
	winclass.cbSize       = sizeof(WNDCLASSEX);
	winclass.style			  = CS_HREDRAW | CS_VREDRAW;
	winclass.lpfnWndProc	= WindowProc<PRAC_ALGORITHM>;
	winclass.cbClsExtra		= 0;
	winclass.cbWndExtra		= 0;
	winclass.hInstance		= hinstance;
	winclass.hIcon			  = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_ICON1));
	winclass.hCursor		  = LoadCursor(NULL, IDC_ARROW); 
	winclass.hbrBackground= NULL; 
	winclass.lpszMenuName	= NULL;
	winclass.lpszClassName= szWindowClassName;
	winclass.hIconSm      = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_ICON1));


	// register the window class
	if (!RegisterClassEx(&winclass))
	{
		MessageBox(NULL, "Error Registering Class!", "Error", 0);
    return 0;
	}

	// create the window (one that cannot be resized)
	if (!(hwnd = CreateWindowEx(NULL,									
								              szWindowClassName,						
								              szApplicationName,						
								              WS_OVERLAPPED | WS_VISIBLE | WS_CAPTION | WS_SYSMENU,
                              GetSystemMetrics(SM_CXSCREEN)/2 - CParams::WindowWidth/2,
                              GetSystemMetrics(SM_CYSCREEN)/2 - CParams::WindowHeight/2,									
								              CParams::WindowWidth,
                              CParams::WindowHeight,				
								              NULL,									
								              NULL,								
								              hinstance,								
								              NULL)))	
	{
    MessageBox(NULL, "Error Creating Window!", "Error", 0);
		return 0;
	}
	
	//Show the window
	ShowWindow(hwnd, SW_SHOWDEFAULT );
	UpdateWindow(hwnd);

	//create a timer
	CTimer timer(CParams::iFramesPerSecond);

	//start the timer
	timer.Start();

	// Enter the message loop
	bool bDone = FALSE;

	while(!bDone)
	{
					
		while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) 
		{
			if( msg.message == WM_QUIT ) 
			{
				//Stop loop if it's a quit message
				bDone = TRUE;
			} 

			else 
			{
				TranslateMessage( &msg );
				DispatchMessage( &msg );
			}
		}
							
		if (timer.ReadyForNextFrame() || g_pController->FastRender())
		{
		  if (g_pController != nullptr)
			if(!g_pController->Update())
				{
					//we have a problem, end app
					bDone = TRUE;
				}

				//this will call WM_PAINT which will render our scene
				InvalidateRect(hwnd, NULL, TRUE);
				UpdateWindow(hwnd);
		}								
	}//end while
	

    // Clean up everything and exit the app
    Cleanup();
    UnregisterClass( szWindowClassName, winclass.hInstance );
	
	return 0;

} // end WinMain
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	MSG msg;
	HACCEL hAccelTable;
	HWND hWnd;

	HWAVEOUT shwd;
	WAVEFORMATEX pwfx;
	WAVEHDR pwhOut1;
	WAVEHDR pwhOut2;
	NOTIFYICONDATA notificon;

	fg = 0;
	if(strstr(lpCmdLine,"avi:"))
	{
		SetStdOutToNewConsole();
		printf("Command line %s\n",lpCmdLine);

		generateModAVI(10, strstr(lpCmdLine,"avi:")+4, "out",640,480,1);
		return 0;
	}

	hWnd = InitInstance(hInstance, nCmdShow);

	if(hWnd)
	{
		hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDI_MAINICON);

		if(waveOutGetNumDevs())
		{

			fg = init_fg(FRAMEXRES,FRAMEYRES);

			nb_wr_block = 0;
			modfile = 0;

			pwfx.wFormatTag = 1;
			pwfx.nChannels = 2;
			pwfx.nSamplesPerSec = SAMPLERATE;
			pwfx.nAvgBytesPerSec = pwfx.nSamplesPerSec*4;
			pwfx.nBlockAlign = 4;
			pwfx.wBitsPerSample = 16;
			pwfx.cbSize = 0;

			memset(&trackbuf_state1,0,sizeof(tracker_buffer_state));
			trackbuf_state1.nb_max_of_state = 100;
			trackbuf_state1.track_state_buf = malloc(sizeof(tracker_state) * trackbuf_state1.nb_max_of_state);
			memset(trackbuf_state1.track_state_buf,0,sizeof(tracker_state) * trackbuf_state1.nb_max_of_state);
			trackbuf_state1.sample_step = ( sizeof(sndbuffer1) / (sizeof(unsigned short)*2) ) / trackbuf_state1.nb_max_of_state;

			memset(&trackbuf_state2,0,sizeof(tracker_buffer_state));
			trackbuf_state2.nb_max_of_state = 100;
			trackbuf_state2.track_state_buf = malloc(sizeof(tracker_state) * trackbuf_state2.nb_max_of_state);
			memset(trackbuf_state2.track_state_buf,0,sizeof(tracker_state) * trackbuf_state2.nb_max_of_state);
			trackbuf_state2.sample_step = ( sizeof(sndbuffer2) / (sizeof(unsigned short)*2) ) / trackbuf_state2.nb_max_of_state;

			waveOutOpen(&shwd,WAVE_MAPPER,&pwfx,(unsigned long)hWnd,0,CALLBACK_WINDOW);
			wout = shwd;
			if(shwd)
			{
				pwhOut1.lpData=(char*)sndbuffer1;
				pwhOut1.dwBufferLength=sizeof(sndbuffer1);
				pwhOut1.dwFlags=0;
				pwhOut1.dwLoops=0;

				pwhOut2.lpData=(char*)sndbuffer2;
				pwhOut2.dwBufferLength=sizeof(sndbuffer2);
				pwhOut2.dwFlags=0;
				pwhOut2.dwLoops=0;

				waveOutPrepareHeader(shwd, &pwhOut1, sizeof(pwhOut1));
				waveOutPrepareHeader(shwd, &pwhOut2, sizeof(pwhOut2));

				waveOutWrite(shwd,&pwhOut1,sizeof(pwhOut1));
				nb_wr_block++;
				waveOutWrite(shwd,&pwhOut2,sizeof(pwhOut2));
				nb_wr_block++;

				notificon.cbSize = sizeof(NOTIFYICONDATA);
				notificon.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_APPLIICON);
				notificon.hWnd = hWnd;
				notificon.szTip[0] = 0;
				notificon.uID = 0;
				notificon.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
				notificon.uCallbackMessage = WM_USER;

				Shell_NotifyIcon(NIM_ADD,&notificon);

				hxcmod_init(&modloaded);

				hxcmod_setcfg(&modloaded, SAMPLERATE, 16, 1, 0, 0);

				modfile = unpack(data_cartoon_dreams_n_fantasies_mod->data,data_cartoon_dreams_n_fantasies_mod->csize ,data_cartoon_dreams_n_fantasies_mod->data, data_cartoon_dreams_n_fantasies_mod->size);
				hxcmod_load(&modloaded,(void*)modfile,data_cartoon_dreams_n_fantasies_mod->size);

				///////////////////////////////////////
				// Main message loop:
				while (GetMessage(&msg, NULL, 0, 0))
				{
					if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
					{
						TranslateMessage(&msg);
						DispatchMessage(&msg);
					}
				}

				Shell_NotifyIcon(NIM_DELETE,&notificon);

				deinit_fg(fg);

				return msg.wParam;
			}

		}
		else
		{
			MessageBox(NULL,"ERROR : Sound System Failure!!!",NOMFENETRE,MB_ICONHAND|MB_OK);
		}

	}

	return FALSE;
}