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