Jump to content

Recommended Posts

Posted

I've been playing with the new Game.cpp / GameMenu.cpp code and I noticed some bugs with the code.

First, this wrong, video isn't a boolean and there can be an error if window size vector is missing.

On Line 33 of Game.cpp change:

        bool fullscreen = true;
        if (settings["video"].is_boolean() and settings["video"]["fullscreen"].is_boolean()) fullscreen = settings["video"]["fullscreen"];
        if (settings["video"].is_boolean() and settings["video"]["windowsize"].size() >= 2)
        {
            w = settings["video"]["windowsize"][0];
            h = settings["video"]["windowsize"][1];
        }

To:

        bool fullscreen = true;
        if (settings["video"].is_object() and settings["video"]["fullscreen"].is_boolean()) fullscreen = settings["video"]["fullscreen"];
        if (settings["video"].is_object() and settings["video"]["windowsize"].is_array())
        {
            if (settings["video"]["windowsize"].size() >= 2)
            {
                w = settings["video"]["windowsize"][0];
                h = settings["video"]["windowsize"][1];
            }
        }

 

There's a bug with the window size values not carrying over from one save to another. This is because the window size values only get saved if a new window was created.

Around Line 787 change:

    if (resolutionIndex > 0) {
        bool newFullscreenMode = (fullscreenbutton->GetState() == WIDGETSTATE_SELECTED);
        bool oldFullscreenMode = (Game::window->style & WINDOW_FULLSCREEN) != 0;
        auto& item = resolutionlist->items[resolutionIndex];
        auto s = item.text;
        auto sarr = s.Split(" x ");
        auto w = std::stoi(sarr[0]);
        auto h = std::stoi(sarr[1]);

        if (w != Game::window->size.x || h != Game::window->size.y || newFullscreenMode != oldFullscreenMode) {
            auto style = WINDOW_CENTER | WINDOW_TITLEBAR;
            if (fullscreenbutton->GetState() == WIDGETSTATE_SELECTED) style |= WINDOW_FULLSCREEN;

            auto newWindow = CreateWindow(Game::window->text, Game::window->position.x, Game::window->position.y, w, h, Game::window->display, style);

            if (newWindow) {
                Game::window->SetHidden(true);
                Game::window = newWindow;
                Game::framebuffer = CreateFramebuffer(Game::window);
                ui->SetSize(Game::framebuffer->size);
                Game::settings["video"]["windowsize"] = {};
                Game::settings["video"]["windowsize"][0] = Game::window->size.x;
                Game::settings["video"]["windowsize"][1] = Game::window->size.y;
                Game::settings["video"]["fullscreen"] = (Game::window->style & WINDOW_FULLSCREEN) != 0;
            }
        }
    }

To:

    if (resolutionIndex > 0) {
        bool newFullscreenMode = (fullscreenbutton->GetState() == WIDGETSTATE_SELECTED);
        bool oldFullscreenMode = (Game::window->style & WINDOW_FULLSCREEN) != 0;
        auto& item = resolutionlist->items[resolutionIndex];
        auto s = item.text;
        auto sarr = s.Split(" x ");
        auto w = std::stoi(sarr[0]);
        auto h = std::stoi(sarr[1]);

        if (w != Game::window->size.x || h != Game::window->size.y || newFullscreenMode != oldFullscreenMode) {
            auto style = WINDOW_CENTER | WINDOW_TITLEBAR;
            if (fullscreenbutton->GetState() == WIDGETSTATE_SELECTED) style |= WINDOW_FULLSCREEN;

            auto newWindow = CreateWindow(Game::window->text, Game::window->position.x, Game::window->position.y, w, h, Game::window->display, style);

            if (newWindow) {
                Game::window->SetHidden(true);
                Game::window = newWindow;
                Game::framebuffer = CreateFramebuffer(Game::window);
                ui->SetSize(Game::framebuffer->size);
            }
        }

        Game::settings["video"]["windowsize"] = {};
        Game::settings["video"]["windowsize"][0] = Game::window->size.x;
        Game::settings["video"]["windowsize"][1] = Game::window->size.y;
        Game::settings["video"]["fullscreen"] = (Game::window->style & WINDOW_FULLSCREEN) != 0;
    }

There's also a bug with Post Processing effects being applied when the map already has effects applied.

 

Bonus:

When the game un-pauses with the FPSPlayer, the camera will spin to where the mouse is currently is. This is because freelookstarted needs to be set back to false. 

I just added the function to have the listen to EVENT_WORLDPAUSE and added this to the ProcessEvent function

	case EVENT_WORLDPAUSE:
		freelookstarted = false;
		break;

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

  • reepblue changed the title to Small bugs and fixes with Game.cpp / GameMenu.cpp

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...