Hazel game engine (075) code maintenance and where to go next

If there are errors in the code, terminology, etc. in the text, please correct me

code maintenance

BUGfix

  • Explain the bug

    When the window is minimized , imgui's viewportsize will be a negative value passed to the framebuffer to reset the size

    But the size parameter of the frame buffer is unsigned , so it will be converted to a large unsigned integer

    The size of the framebuffer becomes too large, causing the camera projection to be distorted when the window is re-maximized (camera aspect ratio does not match the size of the framebuffer)

  • camera distortion

    After minimizing, open again

    Please add a picture description

  • try to fix this bug

    Judging that if it is less than 0 , do not reset the frame buffer size, and do not reset if the frame buffer size is too large , double-layer insurance

    // EditorLayer.cpp
    if (m_ViewportSize != *((glm::vec2*)&viewportPanelSize) &&
        viewportPanelSize.x > 0 && viewportPanelSize.y > 0) {
          
           // 改变了窗口大小
        // 调整帧缓冲区大小
        m_Framebuffer->Resize((uint32_t)viewportPanelSize.x, (uint32_t)viewportPanelSize.y);
        m_ViewportSize = {
          
           viewportPanelSize.x, viewportPanelSize.y };
        // 调整摄像机投影
        m_CameraController.OnResize(viewportPanelSize.x, viewportPanelSize.y);
    }
    // OpenGLFramebuffer.cpp
    void OpenGLFramebuffer::Resize(uint32_t width, uint32_t height)
    {
          
          
        if (width == 0 || height == 0 || width > s_MaxFramebufferSize || height > s_MaxFramebufferSize) {
          
          
            HZ_CORE_WARN("试图将frambuffer的大小设为{0} {1}", width, height);
            return;
        }
        m_Specification.Width = width;
        m_Specification.Height = height;
        Invalidate();// 重新生成
    }
    

But the result is: temporarily can not solve the problem that the camera projection will be deformed (window minimization event and window resize are not the same event)

discuss macro

  1. In Core.h, there is a macro to judge which platform to choose

  2. In this way, the project needs to add macros in the precompile option of the settings-properties

  3. In this way, each cpp file has this macro and is at the top (so the cpp file can directly use the macro added in step 2)

  4. Although the program will not crash, it is not very good, there are too many macros

    This is an explanation of the automatic translation of the video. I don’t know if I understand it wrong. . .

where to go next

  • Teaching someone to be an engine is hard

    It's like teaching someone to develop a car, and some functions have to be cut off

    Instead, develop some familiar and interesting functions (rendering, events)

    Other functions may take the approach of third-party libraries (entity components, physics, etc.)

  • An engine is something that's always being developed and maintained, unless people aren't continuing to develop games.

  • The next step is to build the entity component system first. With the entity, you can add components to it, and then use scripts to control it.

Guess you like

Origin blog.csdn.net/qq_34060370/article/details/132013457