3d游戏引擎的核心代码core

2.Main.cpp


/*
int main() 
{
    return 0;
}
*/


#if _WIN64
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN

#endif

#include <Windows.h>
#include <crtdbg.h>

#ifndef USE_WITH_EDITOR


extern bool engine_initialize();
extern void engine_update();
extern void engine_shutdown();


int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int) 
{
#if _DEBUG
    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
    if (engine_initialize())
    {
        MSG msg{};
        bool is_running{ true };
        while (is_running) 
        {
            while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
                is_running &= (msg.message != WM_QUIT);


            }

            engine_update();

        
        }
    
    }
    engine_shutdown();
    return 0;


}

#endif

#endif

2.Engine.cpp

#if !defined(SHIPPING)
#include "..\Content\ContentLoader.h"
#include "..\Components\Script.h"
#include "..\Platform\PlatformTypes.h"
#include "..\Platform\Platform.h"
#include "..\Graphics\Renderer.h"
#include <thread>

using namespace primal;

namespace {

    graphics::render_surface game_window{};

    LRESULT win_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
    {
        switch (msg)
        {
        case WM_DESTROY:
        {
            
            if (game_window.window.is_closed())
            {

                PostQuitMessage(0);
                return 0;


            }


        }
        break;

        case WM_SYSCHAR:
            if (wparam == VK_RETURN && (HIWORD(lparam) & KF_ALTDOWN))
            {
                game_window.window.set_fullscreen(!game_window.window.is_fullscreen());
                return 0;

            }


            break;


        }

        return DefWindowProc(hwnd, msg, wparam, lparam);

    }


};


bool engine_initialize() 
{
    if (primal::content::load_game()) return false;

    platform::window_init_info info{


        &win_proc,nullptr,L"Primal Game"


    };

    game_window.window = platform::create_window(&info);
    if (!game_window.window.is_valid()) return false;

    return true;
}

void engine_update() 
{
    primal::script::update(10.f);
    std::this_thread::sleep_for(std::chrono::milliseconds(10));

}

void engine_shutdown() 
{

    platform::remove_window(game_window.window.get_id());
    primal::content::unload_game();


}

#endif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Magnum Lehar

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值