// // 从数据流加载资源 // BOOL CSound::LoadFromStream(CStream *pStream) { // // 1. 数据流有效性检查 // if (pStream == NULL) { return FALSE; } if (pStream->IsValid() == FALSE) { return FALSE; } // // 2. 加载声音 // Free(); // // 3. 加载声音 // try { m_pFModSound = SoundSystem()->CreateSound((BYTE *)pStream->GetCurrentAddress(), pStream->GetFreeSize(), TRUE); if (m_pFModSound == NULL) throw "Create sound fail."; return TRUE; } catch (const CHAR *szError) { WriteLogE("Error CTexture::LoadFromStream: %s %s %d\n", szError, __FILE__, __LINE__); Free(); return FALSE; } }
// // 释放资源 // VOID CSound::Free(VOID) { SoundSystem()->ReleaseSound(m_pFModSound); CResource::Free(); }
int CALLBACK WinMain( _In_ HINSTANCE hInstance, _In_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) { int flags = 0; dfDeltaTime = 43.f; ScreenResolution.x = 800.f; ScreenResolution.y = 600.f; GameResolution.x = 640.f; GameResolution.y = 480.f; if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { printf( "Video initialization failed: %s\n", SDL_GetError( ) ); GameExit( 1 ); } if( SDL_Init( SDL_INIT_JOYSTICK ) < 0 ) { printf( "Input initialization failed: %s\n", SDL_GetError( ) ); GameExit( 1 ); } if( SDL_Init( SDL_INIT_GAMECONTROLLER ) < 0 ) { printf( "Input initialization failed: %s\n", SDL_GetError( ) ); GameExit( 1 ); } if( SDL_Init( SDL_INIT_AUDIO ) < 0 ) { printf( "Audio initialization failed: %s\n", SDL_GetError( ) ); GameExit( 1 ); } //Initialize SDL_mixer if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 ) { printf( "SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError() ); GameExit( 1 ); } SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); //flags = SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL; flags = SDL_WINDOW_OPENGL; RenderSystem::window = SDL_CreateWindow("Dufresne", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, ScreenResolution.x, ScreenResolution.y, flags); flags = IMG_INIT_JPG | IMG_INIT_PNG; int initted = IMG_Init(flags); if(initted & flags != flags) { printf("Failed to Init SDL Image\n"); printf("IMG_Init: %s\n", IMG_GetError()); GameExit( 1 ); // handle error } // init gl SDL_GLContext glcontext; glcontext = SDL_GL_CreateContext(RenderSystem::window); GLint GlewInitResult = glewInit(); if (GlewInitResult != GLEW_OK) { printf("ERROR: %s\n",glewGetErrorString(GlewInitResult)); GameExit( 1 ); } glEnable(GL_TEXTURE_2D); tinyjson_init(); InitEngine(); assMan = AssetManager(); std::wstring path = L"fart\\"; assMan.CalculateLoosePackageSize(path); assMan.LoadLoosePackage(path); assMan.DebugTestWritePoolToFile(); sfxMan = SoundSystem(); sfxMan.Init(); sceneMan.Init(); input = Input(); input.Init(); dfScene* scene1 = sceneMan.CreateScene("scene-left"); dfScene* scene2 = sceneMan.CreateScene("scene-right"); scene1->setupFunc = &SetupScene1; scene2->setupFunc = &SetupScene2; sceneMan.LoadScene(scene1); Uint32 previousMiliseconds = 0; while(true) { Uint32 currentMiliseconds = SDL_GetTicks(); dfRandomFloat = dfRand(); dfTotalTime = currentMiliseconds / 1000.f; dfDeltaTime = (currentMiliseconds / 1000.f) - (previousMiliseconds / 1000.f); if(testDude->tf.rectangle.left > GameResolution.x) { sceneMan.LoadScene(scene2); } if(testDude->tf.rectangle.right < 0) { sceneMan.LoadScene(scene1); } if(input.keyboard.n1.tapped) { sceneMan.renderer.UpdateResolution(640, 480); } if(input.keyboard.n2.tapped) { sceneMan.renderer.UpdateResolution(300, 300); } if(input.keyboard.n3.tapped) { sceneMan.renderer.UpdateResolution(450, 300); } input.Update(); sceneMan.Update(); SDL_GL_SwapWindow(RenderSystem::window); } return 0; }
// ----------------------------------------------------------------------------- // CAknPopupFormExt::DoSoundSystem // ----------------------------------------------------------------------------- // CAknKeySoundSystem* CAknPopupFormExt::DoSoundSystem() const { return SoundSystem(); }