// The start of the Application int MikMod::start(const std::vector<std::string> &args) { // Initialize mikmod SetupMikMod setup_mikmod; clan::SoundOutput sound_output(44100, 192); clan::SoundBuffer boss = clan::SoundBuffer("Resources/boss.mod"); clan::SoundBuffer_Session session = boss.prepare(); session.play(); #ifdef WIN32 clan::Console::write_line("Press any key to exit"); #else clan::Console::write_line("CTRL-C to exit"); #endif while(session.is_playing()) { #ifdef WIN32 if (kbhit()) break; #endif clan::KeepAlive::process(100); } return 0; }
Win32_App::Win32_App() { SourceDLLName = "Game.dll"; //GameCode = Win32_LoadGameCode(SourceDLLName); #ifdef _DEBUG // Дебажная консоль FileLogger flogger("debug.log"); log_event("SYSTEM", "Logger initialized"); #endif try { // We support all display targets, in order listed here #ifdef WIN32 D3DTarget::enable(); #endif OpenGLTarget::enable(); } catch (Exception exception) { // Create a console window for text-output if not available ConsoleWindow console("Console", 80, 160); Console::write_line("Exception caught: " + exception.get_message_and_stack_trace()); console.display_close_message(); quit = true; } // TODO: сохранять настройки графики fullscreen = 0; // TODO: Масштабировать окно InitScreenSize = Sizef(1024.0f, 768.0f); ScreenSize = InitScreenSize; DisplayWindowDescription window_description; window_description.set_title("Robot Game"); window_description.set_size(ScreenSize, true); window_description.set_allow_resize(true); //window_description.set_type(WindowType::tool); window = DisplayWindow(window_description); canvas = Canvas(window); // Подключим коллбэки на слоты пользовательского ввода keyboard = window.get_ic().get_keyboard(); sc.connect(window.sig_window_close(), bind_member(this, &Win32_App::Win32_OnWindowClose)); sc.connect(window.get_ic().get_keyboard().sig_key_up(), bind_member(this, &Win32_App::Win32_OnKeyUp)); sc.connect(window.get_ic().get_keyboard().sig_key_down(), bind_member(this, &Win32_App::Win32_OnKeyDown)); sc.connect(window.get_ic().get_mouse().sig_key_down(), bind_member(this, &Win32_App::Win32_OnMouseDown)); // Sound SoundOutput sound_output(48000); /* SoundBuffer sbuffer("cheer1.ogg"); sbuffer.play(); */ // Game memory LPVOID BaseAddress = 0; GameMemory.PermanentStorageSize = Megabytes(256); GameMemory.TransientStorageSize = Megabytes(256); size_t TotalStorageSize = (size_t)(GameMemory.PermanentStorageSize + GameMemory.TransientStorageSize); GameMemory.PermanentStorage = VirtualAlloc(BaseAddress, TotalStorageSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); GameMemory.TransientStorage = ((uint8*)GameMemory.PermanentStorage + GameMemory.PermanentStorageSize); // Game state GameState = (game_state*)GameMemory.PermanentStorage; *GameState = {}; GameState->ScreenSize = ScreenSize; // Resources //OpenGLTarget::set_current(); GameState->game_resources = clan::XMLResourceManager::create(clan::XMLResourceDocument("sprites.xml")); GameState->LoadGameSpriteFromImage = &LoadGameSpriteFromImage; GameState->LoadGameSpriteFromResource = &LoadGameSpriteFromResource; GameState->AddGameSpriteFrameFromImage = &AddGameSpriteFrameFromImage; // Main display buffers //GameState->MainDisplayBuffer = PixelBuffer(1024, 768, TextureFormat::tf_rgba8, GameMemory.TransientStorage); // Win32 Timings CanSleepSafe = (timeBeginPeriod(1) == TIMERR_NOERROR); QueryPerformanceFrequency(&PerfCounterFrequencyQ); PerfCounterFrequency = PerfCounterFrequencyQ.QuadPart; QueryPerformanceCounter(&LastCounter); LastCycleCount = __rdtsc(); game_time.reset(); //console.display_close_message(); //timeEndPeriod(1); }