CZPlayer::~CZPlayer(void) { if(m_playerState.play || m_playerState.pause) Stop(); CleanupAudio(); //if(m_decoder) //{ // m_decoder->Close(); // delete m_decoder; //} free(m_audioState); }
INT WINAPI wWinMain( HINSTANCE, HINSTANCE, LPWSTR, int ) { HRESULT hr = S_OK; #if defined(DEBUG) | defined(_DEBUG) _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); #endif DXUTSetCallbackD3D9DeviceAcceptable( IsDeviceAcceptable ); DXUTSetCallbackD3D9DeviceCreated( OnCreateDevice ); DXUTSetCallbackD3D9FrameRender( OnFrameRender ); DXUTSetCallbackD3D9DeviceReset( OnResetDevice ); DXUTSetCallbackD3D9DeviceLost( OnLostDevice ); DXUTSetCallbackD3D9DeviceDestroyed( OnDestroyDevice ); DXUTSetCallbackMsgProc( MsgProc ); DXUTSetCallbackFrameMove( OnFrameMove ); DXUTSetCallbackKeyboard( KeyboardProc ); DXUTSetCallbackDeviceChanging( ModifyDeviceSettings ); DXUTSetCursorSettings( false, true ); DXUTInit( true, true ); DXUTSetHotkeyHandling( false, false, false ); InitApp(); hr = PrepareAudio(); if( FAILED( hr ) ) { OutputDebugString( L"PrepareAudio() failed. Disabling audio support\n" ); } DXUTCreateWindow( L"Buser Stima" ); DXUTCreateDevice( false, 0, 0 ); DXUTMainLoop(); CleanupAudio(); return DXUTGetExitCode(); }
int main(int argc, char *argv[]) { enum { GAME_COMPUTER, GAME_NETWORK, GAME_UNKNOWN } game_type = GAME_UNKNOWN; char *remote_address = NULL; int remote_port; int i; if (argc < 2) { printf("Penguin Warrior\n"); printf("Usage: pw [ mode ] [ option ... ]\n"); printf(" Game modes (choose one):\n"); printf(" --computer\n"); printf(" --client <remote ip address>\n"); printf(" --server <port number>\n"); printf(" Display options, for tweaking and experimenting:\n"); printf(" --fullscreen\n"); printf(" --hwsurface (use an SDL hardware surface if possible)\n"); printf(" --doublebuf (use SDL double buffering if possible)\n"); printf(" The display options default to a windowed, software buffer.\n"); exit(EXIT_FAILURE); } /* Process command line arguments. There are plenty of libraries for command line processing, but our needs are simple in this case. */ for (i = 0; i < argc; i++) { /* Networked or scripted opponent? */ if (!strcmp(argv[i], "--computer")) { game_type = GAME_COMPUTER; continue; } else if (!strcmp(argv[i], "--client")) { game_type = GAME_NETWORK; if (i + 2 >= argc) { printf("You must supply an IP address "\ "and port number for network games.\n"); exit(EXIT_FAILURE); } remote_address = argv[i+1]; remote_port = atoi(argv[i+2]); i++; continue; } else if (!strcmp(argv[i], "--server")) { game_type = GAME_NETWORK; if (++i >= argc) { printf("You must supply a port number "\ "for --server.\n"); exit(EXIT_FAILURE); } remote_port = atoi(argv[i]); continue; /* Display-related options */ } else if (!strcmp(argv[i], "--hwsurface")) { hwsurface = 1; } else if (!strcmp(argv[i], "--doublebuf")) { doublebuf = 1; } else if (!strcmp(argv[i], "--fullscreen")) { fullscreen = 1; } } /* If this is a network game, make a connection. */ if (game_type == GAME_NETWORK) { /* If there's no remote address, the user selected server mode. */ if (remote_address == NULL) { if (WaitNetgameConnection(remote_port, &netlink) != 0) { printf("Unable to receive connection.\n"); exit(EXIT_FAILURE); } } else { if (ConnectToNetgame(remote_address, remote_port, &netlink) != 0) { printf("Unable to connect.\n"); exit(EXIT_FAILURE); } } opponent_type = OPP_NETWORK; printf("Playing in network game against %s.\n", netlink.dotted_ip); } else if (game_type == GAME_COMPUTER) { opponent_type = OPP_COMPUTER; printf("Playing against the computer.\n"); } else { printf("No game type selected.\n"); exit(EXIT_FAILURE); } /* Initialize our random number generator. */ initrandom(); /* Create a mutex to protect the player data. */ player_mutex = SDL_CreateMutex(); if (player_mutex == NULL) { fprintf(stderr, "Unable to create mutex: %s\n", SDL_GetError()); } /* Start our scripting engine. */ InitScripting(); if (LoadGameScript("pw.tcl") != 0) { fprintf(stderr, "Exiting due to script error.\n"); exit(EXIT_FAILURE); } /* Fire up SDL. */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("Unable to initialize SDL: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } atexit(SDL_Quit); /* Set an appropriate 16-bit video mode. */ if (SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, (hwsurface ? SDL_HWSURFACE : SDL_SWSURFACE) | (doublebuf ? SDL_DOUBLEBUF : 0) | (fullscreen ? SDL_FULLSCREEN : 0)) == NULL) { printf("Unable to set video mode: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } /* Save the screen pointer for later use. */ screen = SDL_GetVideoSurface(); /* Set the window caption to the name of the game. */ SDL_WM_SetCaption("Penguin Warrior", "Penguin Warrior"); /* Hide the mouse pointer. */ SDL_ShowCursor(0); /* Initialize the status display. */ if (InitStatusDisplay() < 0) { printf("Unable to initialize status display.\n"); exit(EXIT_FAILURE); } /* Start the OpenAL-based audio system. */ InitAudio(); /* Initialize music and give the music system a file. */ InitMusic(); if (LoadMusic("reflux.ogg") < 0) { /* If that failed, don't worry about it. */ printf("Unable to load reflux.ogg.\n"); } /* Load the game's data into globals. */ LoadGameData(); /* Initialize the background starfield. */ InitBackground(); /* Start the network thread. */ if (game_type == GAME_NETWORK) { network_thread = SDL_CreateThread(NetworkThread, NULL); if (network_thread == NULL) { printf("Unable to start network thread: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } } /* Play! */ InitPlayer(&player); InitPlayer(&opponent); PlayGame(); /* Kill the network thread. */ if (game_type == GAME_NETWORK) { SDL_KillThread(network_thread); } /* Close the network connection. */ if (game_type == GAME_NETWORK) CloseNetgameLink(&netlink); /* Unhide the mouse pointer. */ SDL_ShowCursor(1); /* Clean up the status display. */ CleanupStatusDisplay(); /* Unload data. */ UnloadGameData(); /* Shut down our scripting engine. */ CleanupScripting(); /* Get rid of the mutex. */ SDL_DestroyMutex(player_mutex); /* Shut down audio. */ CleanupMusic(); CleanupAudio(); return 0; }
int main(int argc, char *argv[]) { enum { GAME_COMPUTER, GAME_NETWORK, GAME_UNKNOWN } game_type = GAME_UNKNOWN; char *remote_address; int i; if (argc < 2) { printf("Penguin Warrior\n"); printf("Usage: pw [ mode ] [ option ... ]\n"); printf(" Game modes (choose one):\n"); printf(" --computer\n"); printf(" --net <remote ip address>\n"); printf(" Display options, for tweaking and experimenting:\n"); printf(" --fullscreen\n"); printf(" --hwsurface (use an SDL hardware surface if possible)\n"); printf(" --doublebuf (use SDL double buffering if possible)\n"); printf(" The display options default to a windowed, software buffer.\n"); exit(EXIT_FAILURE); } /* Process command line arguments. There are plenty of libraries for command line processing, but our needs are simple in this case. */ for (i = 0; i < argc; i++) { /* Networked or scripted opponent? */ if (!strcmp(argv[i], "--computer")) { game_type = GAME_COMPUTER; continue; } else if (!strcmp(argv[i], "--net")) { game_type = GAME_NETWORK; if (++i >= argc) { printf("You must supply an IP address for --net.\n"); exit(EXIT_FAILURE); } remote_address = argv[i]; continue; /* Display-related options */ } else if (!strcmp(argv[i], "--hwsurface")) { hwsurface = 1; } else if (!strcmp(argv[i], "--doublebuf")) { doublebuf = 1; } else if (!strcmp(argv[i], "--fullscreen")) { fullscreen = 1; } } switch (game_type) { case GAME_COMPUTER: opponent_type = OPP_COMPUTER; printf("Playing against the computer.\n"); break; case GAME_NETWORK: printf("Sorry, network play is not implemented... yet!\n"); exit(EXIT_FAILURE); default: printf("You must select a game type.\n"); exit(EXIT_FAILURE); } /* Initialize our random number generator. */ initrandom(); /* Fire up SDL. */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("Unable to initialize SDL: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } atexit(SDL_Quit); /* Set an appropriate 16-bit double buffered video mode. */ if (SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, (hwsurface ? SDL_HWSURFACE : SDL_SWSURFACE) | (doublebuf ? SDL_DOUBLEBUF : 0) | (fullscreen ? SDL_FULLSCREEN : 0)) == NULL) { printf("Unable to set video mode: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } /* Save the screen pointer for later use. */ screen = SDL_GetVideoSurface(); /* Set the window caption to the name of the game. */ SDL_WM_SetCaption("Penguin Warrior", "Penguin Warrior"); /* Hide the mouse pointer. */ SDL_ShowCursor(0); /* Start the OpenAL-based audio system. */ InitAudio(); /* Initialize music and give the music system a file. */ InitMusic(); if (LoadMusic("reflux.ogg") != 0) { /* If that failed, don't worry about it. */ printf("Unable to load reflux.ogg.\n"); } /* Load the game's data into globals. We can only do this after the video and audio subsystems are ready for action, since the loading routines interact with SDL and OpenAL. */ LoadGameData(); /* Initialize the background starfield. */ InitBackground(); /* Play! */ InitPlayer(); InitOpponent(); PlayGame(); /* Unhide the mouse pointer. */ SDL_ShowCursor(1); /* Unload data. */ UnloadGameData(); /* Shut down audio. */ CleanupMusic(); CleanupAudio(); return 0; }