From ca44bc4b3a144b1dd0439253cfc0d80e788196f0 Mon Sep 17 00:00:00 2001 From: Frank DeMarco Date: Sun, 11 Apr 2021 00:30:15 -0400 Subject: [PATCH] new parameters for Mix_OpenAudio --- src/Display.cpp | 26 +++++++++++++------------- src/Game.cpp | 27 +++++++++++---------------- src/Input.cpp | 2 +- src/Input.hpp | 2 +- src/Sprite.cpp | 8 ++++---- src/Sprite.hpp | 2 +- 6 files changed, 31 insertions(+), 36 deletions(-) diff --git a/src/Display.cpp b/src/Display.cpp index db4335f..c6b25eb 100644 --- a/src/Display.cpp +++ b/src/Display.cpp @@ -36,19 +36,19 @@ void Display::get_screen_pixels(unsigned char* pixels, int w, int h, int x, int { if (get_root()->is_gl_context) { - GLenum format; -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - format = GL_BGRA; -#else - format = GL_RGBA; -#endif - glReadBuffer(GL_FRONT); - glReadPixels(x, y, w, h, format, GL_UNSIGNED_BYTE, pixels); - // SDL_Log("(%i, %i, %i) (%i, %i, %i, %i)", - // glCheckFramebufferStatus(GL_FRAMEBUFFER), - // glCheckFramebufferStatus(GL_READ_FRAMEBUFFER), - // glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER), - // pixels[0], pixels[1], pixels[2], pixels[3]); +// GLenum format; +// #if SDL_BYTEORDER == SDL_BIG_ENDIAN +// format = GL_BGRA; +// #else +// format = GL_RGBA; +// #endif +// glReadBuffer(GL_FRONT); +// glReadPixels(x, y, w, h, format, GL_UNSIGNED_BYTE, pixels); +// // SDL_Log("(%i, %i, %i) (%i, %i, %i, %i)", +// // glCheckFramebufferStatus(GL_FRAMEBUFFER), +// // glCheckFramebufferStatus(GL_READ_FRAMEBUFFER), +// // glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER), +// // pixels[0], pixels[1], pixels[2], pixels[3]); } else { diff --git a/src/Game.cpp b/src/Game.cpp index 5c87b8e..72371ec 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -19,11 +19,6 @@ SDL_Surface* FramerateIndicator::get_surface() std::string padded = sfw::pad(get_root()->frame_count_this_second, 2); SDL_Surface* shaded = TTF_RenderText_Shaded( get_root()->bp_mono_font, padded.c_str(), {0, 0, 0, 255}, {255, 255, 255, 255}); - // SDL_Surface* converted = SDL_ConvertSurfaceFormat( - // shaded, SDL_PIXELFORMAT_ARGB8888, 0); - // SDL_Surface* flipped = zoomSurface(converted, 1, -1, SMOOTHING_OFF); - // SDL_FreeSurface(shaded); - // SDL_FreeSurface(converted); if (!shaded) { get_root()->print_sdl_error("Could not create text"); @@ -69,12 +64,13 @@ Game::Game() // SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); // SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); // SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); - // SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); - // SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - // SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); - // SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); - // SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); - // SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); SDL_Log("GLEW %s", glewGetString(GLEW_VERSION)); auto window_size = get_configuration()["display"]["dimensions"].get(); window = SDL_CreateWindow( @@ -124,8 +120,7 @@ Game::Game() { print_error("Could not load BPmono.ttf"); } -#if !defined(__EMSCRIPTEN__) - if (Mix_Init(MIX_INIT_FLAC) == 0) + if (Mix_Init(MIX_INIT_OGG) == 0) { print_sdl_error("Could not initialize SDL mixer"); flag_to_end(); @@ -135,9 +130,9 @@ Game::Game() SDL_Log("initialized SDL mixer %d.%d.%d", SDL_MIXER_MAJOR_VERSION, SDL_MIXER_MINOR_VERSION, SDL_MIXER_PATCHLEVEL); } -#endif - if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, - MIX_DEFAULT_CHANNELS, 1024) < 0) + // if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, + // MIX_DEFAULT_CHANNELS, 1024) < 0) + if (Mix_OpenAudio(11025, AUDIO_U8, MIX_DEFAULT_CHANNELS, 2048) < 0) { print_sdl_error("Could not set up audio"); } diff --git a/src/Input.cpp b/src/Input.cpp index b86ec0b..9a66642 100644 --- a/src/Input.cpp +++ b/src/Input.cpp @@ -114,7 +114,7 @@ void Input::respond(SDL_Event &event) } } -void Input::post_command(std::string& name, const bool& cancel) const +void Input::post_command(std::string& name, const bool& cancel) { SDL_Event relay; bool* cancel_pointer = new bool(cancel); diff --git a/src/Input.hpp b/src/Input.hpp index 8fe09fa..d316d30 100644 --- a/src/Input.hpp +++ b/src/Input.hpp @@ -56,7 +56,7 @@ struct Input : Node void add_to_key_map( std::string, SDL_Keycode, bool = false, bool = false, bool = false); void print_key_combination(const KeyCombination&) const; - void post_command(std::string&, const bool&) const; + static void post_command(std::string&, const bool&); void suppress(); void unsuppress(); bool is_suppressed(); diff --git a/src/Sprite.cpp b/src/Sprite.cpp index d33130e..b139760 100644 --- a/src/Sprite.cpp +++ b/src/Sprite.cpp @@ -635,9 +635,9 @@ bool Sprite::collide(const Box& box, bool precise, Box* overlap, bool all, SDL_T const_cast(get_renderer()), collision_check_frame, overlap->stamp(-get_nw(ii))); if (other_texture == nullptr) { - for (int x = 0; x < static_cast(overlap->get_w()); x++) + for (int x = 0; x < region_pixels.rect.w; x++) { - for (int y = 0; y < static_cast(overlap->get_h()); y++) + for (int y = 0; y < region_pixels.rect.h; y++) { if (region_pixels.get(x, y).a > 0) { @@ -651,9 +651,9 @@ bool Sprite::collide(const Box& box, bool precise, Box* overlap, bool all, SDL_T { Pixels other_region_pixels = Pixels( const_cast(get_renderer()), other_texture, overlap->stamp(-box.get_nw())); - for (int x = 0; x < static_cast(overlap->get_w()); x++) + for (int x = 0; x < region_pixels.rect.w && x < other_region_pixels.rect.w; x++) { - for (int y = 0; y < static_cast(overlap->get_h()); y++) + for (int y = 0; y < region_pixels.rect.h && y < other_region_pixels.rect.h; y++) { if (region_pixels.get(x, y).a > 0 && other_region_pixels.get(x, y).a > 0) { diff --git a/src/Sprite.hpp b/src/Sprite.hpp index 9d769d8..6517315 100644 --- a/src/Sprite.hpp +++ b/src/Sprite.hpp @@ -41,7 +41,7 @@ struct Sprite : Node glm::bvec2 wrap = {false, false}; int texture_access = SDL_TEXTUREACCESS_TARGET, wipe_index = 0, wipe_increment = -1; Box wrap_frame, unscaled_subsection; - bool leave_memory_allocated = false, hidden = false, draw_children_on_frame = true; + bool leave_memory_allocated = false, hidden = false, draw_children_on_frame = true, draw_floating = true; std::vector> wipe_blinds; SDL_Rect subsection_int_rect, subsection_destination; std::list children = {};