Jump to content

Small bugs and fixes with Game.cpp / GameMenu.cpp


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
Posted

You also have camera->ClearPostEffects() only being called only if the posteffect array has a size greater than 0. This will allow the user to only set the effect on but turn it off.

Change:

                    // Post Effects
                    auto peIt = videoSettings.find("posteffects");
                    if (videoSettings["posteffects"].is_array())
                    {
                        auto& posteffects = videoSettings["posteffects"];
                        camera->ClearPostEffects();
                        for (int n = 0; n < posteffects.size(); ++n)
                        {
                            if (not posteffects[n].is_string()) continue;
                            std::string path = posteffects[n];
                            auto fx = LoadPostEffect(path);
                            if (fx) camera->AddPostEffect(fx);
                        }
                    }

To:

            // Post Effects
            if (not videoSettings["posteffects"].is_null())
            {
                camera->ClearPostEffects();
                if (videoSettings["posteffects"].is_array())
                {
                    auto& posteffects = videoSettings["posteffects"];
                    for (int n = 0; n < posteffects.size(); ++n)
                    {
                        if (not posteffects[n].is_string()) continue;
                        std::string path = posteffects[n];
                        auto fx = LoadPostEffect(path);
                        if (fx) camera->AddPostEffect(fx);
                    }
                }
            }

 

  • Like 1

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

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

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...