void RetrieveResources( void ) { OpeningProgress( 0, 10 ); InitSound( ); OpeningProgress( 1, 10 ); InitBackdrop( ); OpeningProgress( 2, 10 ); GetBlobGraphics( ); OpeningProgress( 3, 10 ); InitNext( ); OpeningProgress( 4, 10 ); InitScore( ); OpeningProgress( 5, 10 ); InitGrayMonitors( ); OpeningProgress( 6, 10 ); InitOpponent( ); OpeningProgress( 7, 10 ); InitStage( ); // must run after backdrop window is open InitGameTickCount( ); InitPlayers( ); // must run after backdrop window is open InitFont( ); InitZapStyle( );// must run after fonts are inited OpeningProgress( 8, 10 ); InitBlitter( ); // must run after player windows are open InitPlayerWorlds( ); OpeningProgress( 9, 10 ); InitVictory( ); // must run after fonts are inited InitTweak( ); OpeningProgress( 10, 10 ); }
void CUIManager::OnSystemEvent( ESystemEvent event, UINT_PTR wparam, UINT_PTR lparam ) { switch (event) { case ESYSTEM_EVENT_LEVEL_POST_UNLOAD: InitSound(); break; case ESYSTEM_EVENT_LEVEL_LOAD_PREPARE: ShutdownSound(); break; case ESYSTEM_EVENT_LEVEL_GAMEPLAY_START: case ESYSTEM_EVENT_EDITOR_GAME_MODE_CHANGED: { if (event == ESYSTEM_EVENT_LEVEL_GAMEPLAY_START || wparam == 1) { ILevel *pLevel = gEnv->pGame->GetIGameFramework()->GetILevelSystem()->GetCurrentLevel(); if(pLevel) { m_pMOSystem->LoadLevelObjectives(pLevel->GetLevelInfo()->GetPath(), true); } } } break; } }
void PlaySound(sf::Sound* sound, const std::string& name) { if (!sound->getBuffer()) InitSound(sound, name); if (sound->getStatus() != sf::SoundSource::Playing) sound->play(); }
void CUIManager::OnSystemEvent( ESystemEvent event, UINT_PTR wparam, UINT_PTR lparam ) { if (event == ESYSTEM_EVENT_LEVEL_POST_UNLOAD) { InitSound(); } }
int DriverInitialize(void) { if (soundo) soundo = InitSound(); SetVideoMode(fullscreen); InitInputStuff(); /* Initialize DInput interfaces. */ return 1; }
virtual void OnOption() { if(changed) { DoneSound(); InitSound(); } }
bool InitEverything(SDL_GLContext& g_Context, SDL_Window*& g_Window, std::unique_ptr<Scene>& pScene) { if (InitSDL()) if (InitGL(g_Context, g_Window)) if (InitSound()) if (InitPython()) if (InitScene(pScene)) return true; return false; }
void Application::Init() { InitAppPreServices(); InitPrimaryWindow(); InitGraphics(); InitInput(); InitSound(); InitExtraSubsystems(); InitAppPostServices(); }
VOID main() { EnableAllIntrs(); InitSound(TM_TMR1); SetVector(VC_INT1, Int0Isr); SetIntrPriority(VC_INT1, IP_LOW); EnableIntr(VC_INT1); for (;;) PlayTune(tune, 7); }
int LoadGame(const char *path) { MDFNGI *tmp; CloseGame(); pending_save_state = 0; pending_save_movie = 0; pending_snapshot = 0; #ifdef NEED_CDEMU if(loadcd) { if(!(tmp = MDFNI_LoadCD(loadcd, path))) return(0); } else #endif { if(!(tmp=MDFNI_LoadGame(path))) return 0; } CurGame = tmp; InitGameInput(tmp); RefreshThrottleFPS(1); SDL_mutexP(VTMutex); NeedVideoChange = -1; SDL_mutexV(VTMutex); if(SDL_ThreadID() != MainThreadID) while(NeedVideoChange) { SDL_Delay(1); } sound_active = 0; if(MDFN_GetSettingB("sound")) sound_active = InitSound(tmp); if(MDFN_GetSettingB("autosave")) MDFNI_LoadState(NULL, "ncq"); if(netconnect) MDFND_NetworkConnect(); GameThreadRun = 1; GameThread = SDL_CreateThread(GameLoop, NULL); ffnosound = MDFN_GetSettingB("ffnosound"); return 1; }
static void Init(const char* path) { const char* res = "/"; OpLastFile(res); // xIo::SetResourcePath(res); char buf[xIo::MAX_PATH_LEN]; strcpy(buf, path); strcat(buf, "/"); xIo::SetProfilePath(buf); Handler()->OnInit(); InitSound(); }
bool retro_load_game(const struct retro_game_info *info) { int i; static char ROMName_buffer[MAXCARTS][1024]; enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565; if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) { if (log_cb) log_cb(RETRO_LOG_INFO, "RGB565 is not supported.\n"); return false; } environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &ProgDir); check_variables(); set_input_descriptors(); Verbose=1; UPeriod=100; strcpy(ROMName_buffer[0], info->path); ROMName[0]=ROMName_buffer[0]; SETJOYTYPE(0,1); // ProgDir="."; static Image fMSX_image; fMSX_image.Cropped = 0; fMSX_image.D = 16; fMSX_image.Data = image_buffer; fMSX_image.W = image_buffer_width; fMSX_image.H = image_buffer_height; fMSX_image.L = image_buffer_width; GenericSetVideo(&fMSX_image,0,0,image_buffer_width,image_buffer_height); for(i = 0; i < 80; i++) SetColor(i, 0, 0, 0); for(i = 0; i < 256; i++) BPal[i]=PIXEL(((i>>2)&0x07)*255/7,((i>>5)&0x07)*255/7,(i&0x03)*255/3); memset((void *)XKeyState,0xFF,sizeof(XKeyState)); InitSound(SND_RATE, 0); SetChannels(255/MAXCHANNELS, (1<<MAXCHANNELS)-1); ExitNow = 1; StartMSX(Mode,RAMPages,VRAMPages); printf ("Mode %i, RAMPages %i, VRAMPages %i", Mode, RAMPages, VRAMPages); return true; }
//---------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------- int main() { g_manager = ::Effekseer::Manager::Create( 2000 ); #if __CULLING_TEST g_manager->CreateCullingWorld(200, 200, 200, 4); #endif #if _WIN32 InitGraphics(g_window_width, g_window_height); InitSound(); #else InitGraphics( g_window_width, g_window_height); InitSound(); #endif Init(); while(DoEvent()) { Loop(); g_manager->Update(); Rendering(); } g_manager->Destroy(); for (size_t i = 0; i < g_effects.size(); i++) { ES_SAFE_RELEASE(g_effects[i]); } TermSound(); TermGraphics(); return 0; }
void CUIManager::Init() { CHUDEventDispatcher::SetUpEventListener(); SHUDEvent::InitDataStack(); m_pWarningManager = new CWarningsManager(); m_pOptions = new CProfileOptions(); m_pScreenLayoutMan = new ScreenLayoutManager(); m_p2DRendUtils = new C2DRenderUtils(m_pScreenLayoutMan); m_pHudSilhouettes = new CHUDSilhouettes(); m_pCVars = new CUICVars(); m_pMOSystem = new CHUDMissionObjectiveSystem(); m_pCVars->RegisterConsoleCommandsAndVars(); IUIEventSystemFactory* pFactory = IUIEventSystemFactory::GetFirst(); while (pFactory) { TUIEventSystemPtr pGameEvent = pFactory->Create(); CRY_ASSERT_MESSAGE(pGameEvent != NULL, "Invalid IUIEventSystemFactory!"); const char* name = pGameEvent->GetTypeName(); TUIEventSystems::const_iterator it = m_EventSystems.find(name); if(it == m_EventSystems.end()) { m_EventSystems[name] = pGameEvent; } else { string str; str.Format("IUIGameEventSystem \"%s\" already exists!", name); CRY_ASSERT_MESSAGE(false, str.c_str()); } pFactory = pFactory->GetNext(); } TUIEventSystems::const_iterator it = m_EventSystems.begin(); TUIEventSystems::const_iterator end = m_EventSystems.end(); for (;it != end; ++it) { it->second->InitEventSystem(); } InitSound(); gEnv->pSystem->GetISystemEventDispatcher()->RegisterListener( this ); g_pGame->GetIGameFramework()->RegisterListener(this, "CUIManager", FRAMEWORKLISTENERPRIORITY_HUD); m_bRegistered = true; }
int osd_init_machine(void) { Log ("\n--[ INITIALISE MACHINE ]--------------------------\n"); if (SDL_Init(SDL_INIT_TIMER)) { Log("Could not initialise SDL : %s\n",SDL_GetError()); return 0; } atexit(SDL_Quit); printf (MESSAGE[language][init_allegro]); printf (MESSAGE[language][translated_by]); if (!(XBuf = (UChar*)malloc(XBUF_WIDTH * XBUF_HEIGHT))) { printf (MESSAGE[language][failed_init]); return (0); } printf (MESSAGE[language][clear_buffer]); bzero (XBuf, XBUF_WIDTH * XBUF_HEIGHT); Log ("Initiating sound\n"); printf (MESSAGE[language][init_sound]); InitSound(); #ifndef SDL /* Opening joypad number 0 */ (int)fd[0] = open ("/dev/js0", O_NONBLOCK); #endif osd_gfx_buffer = XBuf + 32 + 64 * XBUF_WIDTH; // We skip the left border of 32 pixels and the 64 first top lines timerId = SDL_AddTimer(1000 / 60, interrupt_60hz, NULL); if (timerId) Log("Timer initialised\n"); else Log("Timer non initialised\n"); Log ("End of initialisation of the machine\n"); return 1; }
//******************************************************************* // WinMain - sounder main // // paramaters: // hInstance - The instance of this instance of this // application. // hPrevInstance - The instance of the previous instance // of this application. This will be 0 // if this is the first instance. // lpszCmdLine - A long pointer to the command line that // started this application. // cmdShow - Indicates how the window is to be shown // initially. ie. SW_SHOWNORMAL, SW_HIDE, // SW_MIMIMIZE. // // returns: // wParam from last message. // //******************************************************************* int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int cmdShow) { MSG msg; // Go init this application. InitSound(hInstance, hPrevInstance, lpszCmdLine, cmdShow); // Get and dispatch messages for this applicaton. while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return(msg.wParam); }
MainWindow::MainWindow() { AddKey("Exit",sKEY_Escape|sKEYQ_Shift,sGuiMsg(this,&sWindow::CmdExit)); AddHelp(); // grid sGridFrame *g = new sGridFrame(); g->AddBorder(new sFocusBorder); g->AddScrolling(0,1); AddChild(g); sGridFrameHelper gh(g); gh.Label("Buttons"); gh.UpdatePool = 0; gh.Button(sGuiMsg(this,&MainWindow::CmdPlay,0),"A"); gh.Button(sGuiMsg(this,&MainWindow::CmdPlay,1),"B"); gh.Button(sGuiMsg(this,&MainWindow::CmdPlay,2),"C"); gh.Button(sGuiMsg(this,&MainWindow::CmdPlay,3),"D"); InitSound(); }
void LunaticInit(MGLDraw *mgl) { gamemgl = mgl; logFile = AppdataOpen("loonylog.txt", "wt"); InitCosSin(); InitDisplay(gamemgl); InitSound(); InitMonsters(); InitTiles(mgl); InitItems(); InitInterface(); LoadOptions(); MusicInit(); mgl->SetLastKey(0); MGL_srand(timeGetTime()); InitControls(); InitPlayer(INIT_GAME, 0, 0); msgFromOtherModules = 0; }
void GameHubObject::InitGame( const std::string& sceneHub, const ZoyaSoundDef& snd ) { rsk::gRand.Create(); rsk::gRand->InitRNG(); std::string zsc = sceneHub; if( zsc.length() == 0 ) zsc = ZOYASCENE_MODULE; rsk::gPython->Import( zsc.c_str() ); gControl.Create(); gControl->InitControlModules(); InitEntityCreator(); gGUI.Create(); gGUI->InitGUI(); InitSound( snd ); }
int CMPlugin::Load() { g_plugin.registerIcon(LPGEN("New Status Notify"), iconList, MODULE); //"Service" Hook, used when the DB settings change: we'll monitor the "status" setting. HookEvent(ME_DB_CONTACT_SETTINGCHANGED, ContactSettingChanged); //We create this Hook which will notify everyone when a contact changes his status. hHookContactStatusChanged = CreateHookableEvent(ME_STATUSCHANGE_CONTACTSTATUSCHANGED); HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded); HookEvent(ME_SYSTEM_PRESHUTDOWN, OnShutdown); //We add the option page and the user info page (it's needed because options are loaded after plugins) HookEvent(ME_OPT_INITIALISE, OptionsInitialize); //This is needed for "NoSound"-like routines. HookEvent(ME_CLIST_STATUSMODECHANGE, StatusModeChanged); HookEvent(ME_PROTO_ACK, ProtoAck); LoadOptions(); InitStatusList(); InitSound(); db_set_resident("MetaContacts", "LastOnline"); db_set_resident("NewStatusNotify", "LastPopupText"); // register special type of event // there's no need to declare the special service for getting text // because a blob contains only text DBEVENTTYPEDESCR evtype = { sizeof(evtype) }; evtype.module = MODULE; evtype.eventType = EVENTTYPE_STATUSCHANGE; evtype.descr = LPGEN("Status change"); evtype.eventIcon = iconList[3].hIcolib; evtype.flags = DETF_HISTORY | DETF_MSGWINDOW; DbEvent_RegisterType(&evtype); CreateServiceFunction(MS_STATUSCHANGE_MENUCOMMAND, EnableDisableMenuCommand); return 0; }
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////// CTor/DTor /////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// CUIManager::CUIManager() : m_bPickupMsgVisible(false) { IUIEventSystemFactory *pFactory = IUIEventSystemFactory::GetFirst(); while(pFactory) { IUIGameEventSystem *pGameEvent = pFactory->Create(); CRY_ASSERT_MESSAGE(pGameEvent, "Invalid IUIEventSystemFactory!"); const char *name = pGameEvent->GetTypeName(); TUIEventSystems::const_iterator it = m_EventSystems.find(name); if(it == m_EventSystems.end()) { m_EventSystems[name] = pGameEvent; } else { string str; str.Format("IUIGameEventSystem \"%s\" already exists!", name); CRY_ASSERT_MESSAGE(false, str.c_str()); SAFE_DELETE(pGameEvent); } pFactory = pFactory->GetNext(); } TUIEventSystems::const_iterator it = m_EventSystems.begin(); TUIEventSystems::const_iterator end = m_EventSystems.end(); for(; it != end; ++it) { it->second->InitEventSystem(); } m_soundListener = gEnv->pSoundSystem->CreateListener(); InitSound(); gEnv->pSystem->GetISystemEventDispatcher()->RegisterListener(this); LoadProfile(); }
/** * Initialize all of the subsystem drivers: video, audio, and joystick. */ static int DriverInitialize(FCEUGI *gi) { if(InitVideo(gi) < 0) return 0; inited|=4; if(InitSound()) inited|=1; if(InitJoysticks()) inited|=2; int fourscore=0; g_config->getOption("SDL.FourScore", &fourscore); eoptions &= ~EO_FOURSCORE; if(fourscore) eoptions |= EO_FOURSCORE; InitInputInterface(); return 1; }
bool MT_FromRemote_SoundSync(void) { bool ret = TRUE; GameThreadRun = 0; SDL_WaitThread(GameThread, NULL); KillSound(); sound_active = 0; if(MDFN_GetSettingB("sound")) { sound_active = InitSound(CurGame); if(!sound_active) ret = FALSE; } GameThreadRun = 1; GameThread = SDL_CreateThread(GameLoop, NULL); return(ret); }
int init_audio(int format) { int err; int version =-1; char *errstr; mutex_lock(&driver_lock); if((err = InitSound(&version)) !=0 ) { mutex_unlock(&driver_lock); errstr = "Sound service not installed\n\r"; goto exit_whith_error; }; mutex_unlock(&driver_lock); // printf("sound version 0x%x\n", version); if( (SOUND_VERSION>(version&0xFFFF)) || (SOUND_VERSION<(version >> 16))) { errstr = "Sound service version mismatch\n\r"; goto exit_whith_error; } snd_format = format; create_thread(audio_thread, 0, 163840); return 1; exit_whith_error: printf(errstr); return 0; };
/** ** The main program: initialise, parse options and arguments. ** ** @param argc Number of arguments. ** @param argv Vector of arguments. */ int main(int argc, char **argv) { #ifdef REDIRECT_OUTPUT RedirectOutput(); #endif #ifdef USE_BEOS // Parse arguments for BeOS beos_init(argc, argv); #endif // Setup some defaults. #ifndef MAC_BUNDLE StratagusLibPath = "."; #else freopen("/tmp/stdout.txt", "w", stdout); freopen("/tmp/stderr.txt", "w", stderr); // Look for the specified data set inside the application bundle // This should be a subdir of the Resources directory CFURLRef pluginRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR(MAC_BUNDLE_DATADIR), NULL, NULL); CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, kCFURLPOSIXPathStyle); const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); Assert(pathPtr); StratagusLibPath = pathPtr; #endif Parameters ¶meters = Parameters::Instance; parameters.SetDefaultValues(); parameters.LocalPlayerName = GetLocalPlayerNameFromEnv(); if (argc > 0) { parameters.applicationName = argv[0]; } // FIXME: Parse options before or after scripts? ParseCommandLine(argc, argv, parameters); // Init the random number generator. InitSyncRand(); makedir(parameters.GetUserDirectory().c_str(), 0777); // Init Lua and register lua functions! InitLua(); LuaRegisterModules(); // Initialise AI module InitAiModule(); LoadCcl(parameters.luaStartFilename); PrintHeader(); PrintLicense(); // Setup video display InitVideo(); // Setup sound card if (!InitSound()) { InitMusic(); } #ifndef DEBUG // For debug it's better not to have: srand(time(NULL)); // Random counter = random each start #endif // Show title screens. SetDefaultTextColors(FontYellow, FontWhite); LoadFonts(); SetClipping(0, 0, Video.Width - 1, Video.Height - 1); Video.ClearScreen(); ShowTitleScreens(); // Init player data ThisPlayer = NULL; //Don't clear the Players strucure as it would erase the allowed units. // memset(Players, 0, sizeof(Players)); NumPlayers = 0; UnitManager.Init(); // Units memory management PreMenuSetup(); // Load everything needed for menus MenuLoop(); Exit(0); return 0; }
int main(int argc, char ** argv) { int i; #ifdef WIN32 WSADATA wsaData; WSAStartup(0x202, &wsaData); strcpy( sound_source, "WIN" ); #else strcpy( sound_source, "PULSE" ); #endif gargc = argc; gargv = argv; InitialFile[0] = "default.conf"; ProcessArgs(); //Initialize Rawdraw int frames = 0; double ThisTime; double LastFPSTime = OGGetAbsoluteTime(); double LastFrameTime = OGGetAbsoluteTime(); double SecToWait; CNFGBGColor = 0x800000; CNFGDialogColor = 0x444444; char title[1024]; char * tp = title; memcpy( tp, "ColorChord ", strlen( "ColorChord " ) ); tp += strlen( "ColorChord " ); for( i = 1; i < argc; i++ ) { memcpy( tp, argv[i], strlen( argv[i] ) ); tp += strlen( argv[i] ); *tp = ' '; tp++; } *tp = 0; if( !headless ) CNFGSetup( title, set_screenx, set_screeny ); char * OutDriverNames = strdup( GetParameterS( "outdrivers", "null" ) ); char * ThisDriver = OutDriverNames; char * TDStart; for( i = 0; i < MAX_OUT_DRIVERS; i++ ) { while( *ThisDriver == ' ' || *ThisDriver == '\t' ) ThisDriver++; if( !*ThisDriver ) break; TDStart = ThisDriver; while( *ThisDriver != 0 && *ThisDriver != ',' ) { if( *ThisDriver == '\t' || *ThisDriver == ' ' ) *ThisDriver = 0; ThisDriver++; } if( *ThisDriver ) { *ThisDriver = 0; ThisDriver++; } printf( "Loading: %s\n", TDStart ); outdriver[i] = SetupOutDriver( TDStart ); } free(OutDriverNames); //Initialize Sound sd = InitSound( sound_source, &SoundCB ); if( !sd ) { fprintf( stderr, "ERROR: Failed to initialize sound output device\n" ); return -1; } nf = CreateNoteFinder( sd->spsRec ); while(1) { char stt[1024]; //Handle Rawdraw frame swappign if( !headless ) { CNFGHandleInput(); CNFGClearFrame(); CNFGColor( 0xFFFFFF ); CNFGGetDimensions( &screenx, &screeny ); } RunNoteFinder( nf, sound, (soundhead-1+SOUNDCBSIZE)%SOUNDCBSIZE, SOUNDCBSIZE ); //Done all ColorChord work. VisTimeStart = OGGetAbsoluteTime(); for( i = 0; i < MAX_OUT_DRIVERS; i++ ) { if( force_white ) { memset( OutLEDs, 0x7f, MAX_LEDS*3 ); } if( outdriver[i] ) outdriver[i]->Func( outdriver[i]->id, nf ); } VisTimeEnd = OGGetAbsoluteTime(); if( !headless ) { //Handle outputs. int freqbins = nf->freqbins; int note_peaks = freqbins/2; int freqs = freqbins * nf->octaves; //int maxdists = freqbins/2; //Do a bunch of debugging. if( show_debug_basic ) { for( i = 0; i < nf->dists; i++ ) { CNFGPenX = (nf->dist_means[i] + 0.5) / freqbins * screenx; //Move over 0.5 for visual purposes. The means is correct. CNFGPenY = 400-nf->dist_amps[i] * 150.0 / nf->dist_sigmas[i]; //printf( "%f %f\n", dist_means[i], dist_amps[i] ); sprintf( stt, "%f\n%f\n", nf->dist_means[i], nf->dist_amps[i] ); CNFGDrawText( stt, 2 ); } CNFGColor( 0xffffff ); //Draw the folded bins for( i = 0; i < freqbins; i++ ) { float x0 = i / (float)freqbins * (float)screenx; float x1 = (i+1) / (float)freqbins * (float)screenx; float amp = nf->folded_bins[i] * 250.0; CNFGDialogColor = CCtoHEX( ((float)(i+0.5) / freqbins), 1.0, 1.0 ); CNFGDrawBox( x0, 400-amp, x1, 400 ); } CNFGDialogColor = 0xf0f000; for( i = 0; i < note_peaks; i++ ) { //printf( "%f %f /", note_positions[i], note_amplitudes[i] ); if( nf->note_amplitudes_out[i] < 0 ) continue; CNFGDialogColor = CCtoHEX( (nf->note_positions[i] / freqbins), 1.0, 1.0 ); CNFGDrawBox( ((float)i / note_peaks) * screenx, 480 - nf->note_amplitudes_out[i] * 100, ((float)(i+1) / note_peaks) * screenx, 480 ); CNFGPenX = ((float)(i+.4) / note_peaks) * screenx; CNFGPenY = screeny - 30; sprintf( stt, "%d\n%0.0f", nf->enduring_note_id[i], nf->note_amplitudes2[i]*1000.0 ); CNFGDrawText( stt, 2 ); } //Let's draw the o-scope. int thissoundhead = soundhead; thissoundhead = (thissoundhead-1+SOUNDCBSIZE)%SOUNDCBSIZE; int lasty = sound[thissoundhead] * 128 + 128; thissoundhead = (thissoundhead-1+SOUNDCBSIZE)%SOUNDCBSIZE; int thisy = sound[thissoundhead] * 128 + 128; thissoundhead = (thissoundhead-1+SOUNDCBSIZE)%SOUNDCBSIZE; for( i = 0; i < screenx; i++ ) { if( thisy < 0 || thisy > 256 ) printf( "%d/%d\n", thisy,thissoundhead ); CNFGTackSegment( i, lasty, i+1, thisy ); lasty = thisy; thisy = sound[thissoundhead] * 128 + 128; thissoundhead = (thissoundhead-1+SOUNDCBSIZE)%SOUNDCBSIZE; } } //Extra debugging? if( show_debug ) { //Draw the histogram float lasthistval; CNFGColor( 0xffffff ); for( i = -1; i < screenx; i++ ) { float thishistval = CalcHistAt( (float)i/(float)screenx*freqbins-0.5, nf->freqbins, nf->dist_means, nf->dist_amps, nf->dist_sigmas, nf->dists ); if( i >= 0 ) CNFGTackSegment( i, 400-lasthistval * 250.0, i+1, 400-thishistval * 250.0 ); lasthistval = thishistval; } CNFGColor( 0xffffff ); //Draw the bins for( i = 0; i < freqs; i++ ) { float x0 = i / (float)freqs * (float)screenx; float x1 = (i+1) / (float)freqs * (float)screenx; float amp = nf->outbins[i] * 250.0; CNFGDialogColor = CCtoHEX( ((float)i / freqbins), 1.0, 1.0 ); CNFGDrawBox( x0, 0, x1, amp ); } CNFGDialogColor = 0x0f0f0f; char stdebug[1024]; sprintf( stdebug, "DFT:%8.2fms\nFLT:%8.2f\nDEC:%8.2f\nFNL:%8.2f\nDPY:%8.2f", (nf->DFTTime - nf->StartTime)*1000, (nf->FilterTime - nf->DFTTime)*1000, (nf->DecomposeTime - nf->FilterTime)*1000, (nf->FinalizeTime - nf->DecomposeTime)*1000, (VisTimeEnd - VisTimeStart)*1000 ); CNFGPenX = 50; CNFGPenY = 50; CNFGDrawText( stdebug, 2 ); } CNFGColor( show_debug?0xffffff:0x000000 ); CNFGPenX = 0; CNFGPenY = screeny-10; CNFGDrawText( "Extra Debug (D)", 2 ); CNFGColor( show_debug_basic?0xffffff:0x000000 ); CNFGPenX = 120; CNFGPenY = screeny-10; CNFGDrawText( "Basic Debug (E)", 2 ); CNFGColor( show_debug_basic?0xffffff:0x000000 ); CNFGPenX = 240; CNFGPenY = screeny-10; sprintf( stt, "[9] Key: %d [0] (%3.1f) [-]", gKey, nf->base_hz ); CNFGDrawText( stt, 2 ); CNFGColor( 0xffffff ); CNFGPenX = 440; CNFGPenY = screeny-10; sprintf( stt, "FPS: %d", lastfps ); CNFGDrawText( stt, 2 ); CNFGSwapBuffers(); } //Finish Rawdraw with FPS counter, and a nice delay loop. frames++; ThisTime = OGGetAbsoluteTime(); if( ThisTime > LastFPSTime + 1 ) { // printf( "FPS: %d\n", frames ); lastfps = frames; frames = 0; LastFPSTime+=1; } if( cpu_autolimit ) { SecToWait = .016 - ( ThisTime - LastFrameTime ); LastFrameTime += .016; if( SecToWait < -.1 ) LastFrameTime = ThisTime - .1; if( SecToWait > 0 ) OGUSleep( (int)( SecToWait * 1000000 ) ); } SetEnvValues(); } }
void Init_Sound(void) { char *sd; #if defined(sgi) int err; #else char buf[PATH_MAX]; #endif #ifdef DEBUG printf("Init_Sound\n"); #endif /* * If sound_init is on in the .xtrekrc file (set in defaults.c) * look for sounds in .xtrekrc sounddir parameter. If that fails * look for an environment variable called SOUNDDIR and if that * fails, try to open the hardcoded sound directory. */ if (sound_init) { if ((sounddir = getdefault("sounddir")) == NULL) { if ((sd=getenv("SOUNDDIR")) != NULL) sounddir = strdup(sd); else #if defined(sgi) sounddir = "/usr/local/games/netrek-sgi/sounds"; #else sounddir = "/usr/share/sounds/netrek-client-cow"; #endif } if (!isDirectory(sounddir)) { sounddir = "sounds"; if (!isDirectory(sounddir)) { (void) fprintf(stderr, "sound directory %s missing\n", sounddir); return; } } } #if defined(sgi) err = sfxInit(sounddir, 3); /* initialize up to three audio ports */ if (err == SFX_ERR_NO_PORTS_AVAIL) { (void) fprintf(stderr, "No audio ports available.\n"); sound_init = 0; sound_toggle = 0; return; } if (err == SFX_ERR_NO_SPROC) { (void) fprintf(stderr, "Unable to execute sound process.\n"); sound_init = 0; sound_toggle = 0; return; } if (err == SFX_ERR_NO_MEM) { (void) fprintf(stderr, "No memory available for sound data.\n"); sound_init = 0; sound_toggle = 0; return; } if (err > 0) { /* load mandatory sounds f we got at least one audio port */ sounds[FIRE_TORP_WAV] = sfxLoad("fire_torp.aiff"); sounds[PHASER_WAV] = sfxLoad("phaser.aiff"); sounds[FIRE_PLASMA_WAV] = sfxLoad("fire_plasma.aiff"); sounds[EXPLOSION_WAV] = sfxLoad("explosion.aiff"); sounds[FIRE_TORP_OTHER_WAV] = sfxLoad("fire_torp_other.aiff"); sounds[PHASER_OTHER_WAV] = sfxLoad("phaser_other.aiff"); sounds[FIRE_PLASMA_OTHER_WAV] = sfxLoad("fire_plasma_other.aiff"); sounds[EXPLOSION_OTHER_WAV] = sfxLoad("explosion_other.aiff"); sounds[PLASMA_HIT_WAV] = sfxLoad("plasma_hit.aiff"); sounds[TORP_HIT_WAV] = sfxLoad("torp_hit.aiff"); if (err > 1) { /* load optional sounds only if we got two audio ports */ sounds[CLOAK_WAV] = sfxLoad("cloak.aiff"); sounds[UNCLOAK_WAV] = sfxLoad("cloak.aiff"); sounds[SHIELD_DOWN_WAV] = sfxLoad("shield_down.aiff"); sounds[SHIELD_UP_WAV] = sfxLoad("shield_up.aiff"); sounds[REDALERT_WAV] = sfxLoad("klaxon.aiff"); sounds[INTRO_WAV] = sfxLoad("paradise.aiff"); sounds[MESSAGE_WAV] = sfxLoad("message.aiff"); /* load sound loops only if we got three audio ports */ if (err > 2) { sounds[THERMAL_WAV] = sfxLoad("thermal_warn.aiff"); sounds[ENTER_SHIP_WAV] = sfxLoad("enter_ship.aiff"); sounds[SELF_DESTRUCT_WAV] = sfxLoad("self_destruct.aiff"); if ((sounds[ENGINE_WAV] = sfxLoad("bridge.aiff")) != NULL) { sfxLoop(sounds[ENGINE_WAV]); sfxPitchBend(sounds[ENGINE_WAV], 0.0f, 1.0f, 1.0f, 2.0f, 1.1f, 20); } } } sfxPlay(sounds[INTRO_WAV]); } #elif defined(HAVE_SDL) #ifdef DEBUG printf("Init_Sound using SDL\n"); #endif /* Initialize the SDL library */ if (SDL_Init(SDL_INIT_AUDIO) < 0) { fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); } atexit(SDL_Quit); /* Open the audio device at 8000 Hz 8 bit Microsoft PCM */ if (Mix_OpenAudio(8000, AUDIO_U8, 1, 512) < 0) { fprintf(stderr,"Mix_OpenAudio: %s\n", Mix_GetError()); sound_init = 0; } Mix_AllocateChannels(16); /* If we successfully loaded the wav files, so shut-off sound_init and play the introduction */ if (loadSounds()) { if (sounds[INTRO_WAV]) if (Mix_PlayChannel(-1, sounds[INTRO_WAV], 0) < 0) { fprintf(stderr, "Mix_PlayChannel: %s\n", Mix_GetError()); } } #else if (InitSound() == -1) { sound_toggle = 0; sound_init = 0; } else { sound_init = 1; sound_toggle = 1; } strcpy(sound_prefix, sounddir); strcat(sound_prefix, "/"); if (sound_toggle) { strcpy(buf, sounddir); strcat(buf, "/nt_intro"); StartSound(buf); } #endif }
// This is winmain, the main entry point for Windows applications int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ) { MSG msg; HWND hWnd; //register the class RegWindow(hInstance); //set up the screen in windowed or fullscreen mode DWORD style; if(FULLSCREEN) style = WS_EX_TOPMOST | WS_VISIBLE | WS_POPUP; else style = WS_OVERLAPPED; // create the window hWnd = CreateWindow( APPTITLE, //window class APPTITLE, //title bar WS_OVERLAPPEDWINDOW, //window style CW_USEDEFAULT, //x position of window CW_USEDEFAULT, //y position of window SCREEN_WIDTH, //width of the window SCREEN_HEIGHT, //height of the window NULL, //parent window NULL, //menu hInstance, //application instance NULL); //window parameters if(!hWnd) return FALSE; // Display the window on the screen ShowWindow( hWnd, SW_SHOW); UpdateWindow(hWnd); // Initialize the Direct Input Device if (!InitDirectInput(hWnd)){return FALSE;} // Initialize the Direct3D object // if(!InitDirect3D(hWnd, SCREEN_WIDTH, SCREEN_HEIGHT, FULLSCREEN)){return FALSE;} // Initialize the DirectSound object if(InitSound(hWnd) != AUDIO_SUCCESS){return FALSE;} /* // Initialize the game if(!InitGame(hWnd)) { MessageBox(hWnd, L"Error initializing the game", L"Error", MB_OK); return 0; } */ //Initialize the game game = new Game(hWnd); // main message loop: int done = 0; while(!done) { if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { //look for quit message if(msg.message == WM_QUIT) done = 1; //decode and pass messages to WndProc TranslateMessage(&msg); DispatchMessage(&msg); } else //process game loop game->GameRun(); } return (int) msg.wParam; }
/** ** The main program: initialise, parse options and arguments. ** ** @param argc Number of arguments. ** @param argv Vector of arguments. */ int stratagusMain(int argc, char **argv) { #ifdef USE_BEOS // Parse arguments for BeOS beos_init(argc, argv); #endif #ifdef USE_WIN32 SetUnhandledExceptionFilter(CreateDumpFile); #endif #if defined(USE_WIN32) && ! defined(REDIRECT_OUTPUT) SetupConsole(); #endif // Setup some defaults. #ifndef MAC_BUNDLE StratagusLibPath = "."; #else freopen("/tmp/stdout.txt", "w", stdout); freopen("/tmp/stderr.txt", "w", stderr); // Look for the specified data set inside the application bundle // This should be a subdir of the Resources directory CFURLRef pluginRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR(MAC_BUNDLE_DATADIR), NULL, NULL); CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, kCFURLPOSIXPathStyle); const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); Assert(pathPtr); StratagusLibPath = pathPtr; #endif #ifdef USE_PHYSFS if (PHYSFS_init(argv[0])) { PHYSFS_mount(PHYSFS_DATAFILE, "/", 0); } #endif #ifdef USE_STACKTRACE try { #endif Parameters ¶meters = Parameters::Instance; parameters.SetDefaultValues(); parameters.SetLocalPlayerNameFromEnv(); #ifdef REDIRECT_OUTPUT RedirectOutput(); #endif if (argc > 0) { parameters.applicationName = argv[0]; } // FIXME: Parse options before or after scripts? ParseCommandLine(argc, argv, parameters); // Init the random number generator. InitSyncRand(); makedir(parameters.GetUserDirectory().c_str(), 0777); // Init Lua and register lua functions! InitLua(); LuaRegisterModules(); // Initialise AI module InitAiModule(); LoadCcl(parameters.luaStartFilename, parameters.luaScriptArguments); PrintHeader(); PrintLicense(); // Setup video display InitVideo(); // Setup sound card if (!InitSound()) { InitMusic(); } #ifndef DEBUG // For debug it's better not to have: srand(time(NULL)); // Random counter = random each start #endif // Show title screens. SetDefaultTextColors(FontYellow, FontWhite); LoadFonts(); SetClipping(0, 0, Video.Width - 1, Video.Height - 1); Video.ClearScreen(); ShowTitleScreens(); // Init player data ThisPlayer = NULL; //Don't clear the Players structure as it would erase the allowed units. // memset(Players, 0, sizeof(Players)); NumPlayers = 0; UnitManager.Init(); // Units memory management PreMenuSetup(); // Load everything needed for menus MenuLoop(); Exit(0); #ifdef USE_STACKTRACE } catch (const std::exception &e) { fprintf(stderr, "Stratagus crashed!\n"); //Wyrmgus start // fprintf(stderr, "Please send this call stack to our bug tracker: https://github.com/Wargus/stratagus/issues\n"); fprintf(stderr, "Please send this call stack to our bug tracker: https://github.com/Andrettin/Wyrmgus/issues\n"); //Wyrmgus end fprintf(stderr, "and tell us what caused this bug to occur.\n"); fprintf(stderr, " === exception state traceback === \n"); fprintf(stderr, "%s", e.what()); exit(1); } #endif return 0; }
/************************************************************************* * Main entrypoint for debug build *************************************************************************/ int WINAPI WinMain(HINSTANCE instance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; g_hInstance = GetModuleHandle(0); OutputDebugString("Starting...\n"); if (!WindowOpen()) { OutputDebugString("Failed to open window\n"); WindowClose(); return 0; } if (FAILED(InitDevice())) { CleanupDevice(); return 0; } IntroInit(); InitSound(); while (!g_done) { g_currentFrame++; g_lastTime = g_currentTime; g_currentPos = BASS_ChannelGetPosition(g_stream, BASS_POS_BYTE); g_currentTime = BASS_ChannelBytes2Seconds(g_stream, g_currentPos); if (g_pause) { Sleep(100); } while (PeekMessage(&msg,0,0,0,PM_REMOVE)) { if (msg.message == WM_QUIT) { g_done = true; } TranslateMessage(&msg); DispatchMessage(&msg); if (WM_KEYDOWN == msg.message && VK_SPACE == LOWORD(msg.wParam)) { if (!g_pause) { BASS_ChannelPause(g_stream); g_pause = true; } else { BASS_ChannelPlay(g_stream, false); g_pause = false; } } if (WM_KEYDOWN == msg.message && VK_LEFT == LOWORD(msg.wParam)) { if (g_pause) { BASS_ChannelSetPosition(g_stream, g_currentPos-44100, BASS_POS_BYTE); } else { BASS_ChannelSetPosition(g_stream, g_currentPos-44100*4, BASS_POS_BYTE); } } if (WM_KEYDOWN == msg.message && VK_RIGHT == LOWORD(msg.wParam)) { if (g_pause) { BASS_ChannelSetPosition(g_stream, g_currentPos+44100, BASS_POS_BYTE); } else { BASS_ChannelSetPosition(g_stream, g_currentPos+44100*4, BASS_POS_BYTE); } } if (WM_KEYDOWN == msg.message && VK_DOWN == LOWORD(msg.wParam)) { BASS_ChannelSetPosition(g_stream, g_currentPos-44100*20, BASS_POS_BYTE); } if (WM_KEYDOWN == msg.message && VK_UP == LOWORD(msg.wParam)) { BASS_ChannelSetPosition(g_stream, g_currentPos+44100*20, BASS_POS_BYTE); } if (WM_KEYDOWN == msg.message && VK_F1 == LOWORD(msg.wParam)) { g_repeatStart = g_currentPos; g_repeatEnd = LONG_MAX; } if (WM_KEYDOWN == msg.message && VK_F2 == LOWORD(msg.wParam)) { g_repeatEnd = g_currentPos; } if (WM_KEYDOWN == msg.message && VK_RETURN == LOWORD(msg.wParam)) { g_repeatStart = 0; g_repeatEnd = LONG_MAX; } } IntroLoop((long)(g_currentTime*44100.0)); UpdateTitle(); if (g_currentPos > g_repeatEnd) { BASS_ChannelSetPosition(g_stream, g_repeatStart, BASS_POS_BYTE); } BASS_Update(0); } BASS_StreamFree(g_stream); BASS_Free(); WindowClose(); return 0; }