Magic_Game/src/kiwano/platform/Application.h

125 lines
2.7 KiB
C
Raw Normal View History

2019-04-11 14:40:54 +08:00
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
2019-08-13 21:16:38 +08:00
#include "../core/core.h"
#include "../base/time.h"
#include "../base/Component.h"
#include "../base/Event.hpp"
2019-08-16 10:12:34 +08:00
#include "../renderer/Color.h"
2019-04-11 14:40:54 +08:00
namespace kiwano
{
struct Options
{
String title; // <20><><EFBFBD><EFBFBD>
int width; // <20><><EFBFBD><EFBFBD>
int height; // <20>߶<EFBFBD>
LPCWSTR icon; // ͼ<><CDBC>
Color clear_color; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
bool vsync; // <20><>ֱͬ<D6B1><CDAC>
bool fullscreen; // ȫ<><C8AB>ģʽ
2019-08-12 14:51:54 +08:00
bool debug; // <20><><EFBFBD><EFBFBD>ģʽ
Options(
2019-04-11 14:40:54 +08:00
String const& title = L"Kiwano Game",
int width = 640,
int height = 480,
LPCWSTR icon = nullptr,
Color clear_color = Color::Black,
bool vsync = true,
2019-08-12 14:51:54 +08:00
bool fullscreen = false,
bool debug = false
);
};
2019-08-12 14:51:54 +08:00
// Ӧ<><D3A6>
2019-04-11 14:40:54 +08:00
class KGE_API Application
2019-08-13 21:16:38 +08:00
: protected noncopyable
{
public:
Application();
virtual ~Application();
// <20><>ʼ<EFBFBD><CABC>
void Init(
2019-08-12 14:51:54 +08:00
Options const& options = Options{}
);
2019-08-12 14:51:54 +08:00
// <20><>ʼ<EFBFBD><CABC><EFBFBD>ɹ<EFBFBD>ʱ
virtual void OnReady() {}
2019-08-12 14:51:54 +08:00
// <20><><EFBFBD>ڹر<DAB9>ʱ
virtual bool OnClosing() { return true; }
// <20><><EFBFBD><EFBFBD>ʱ
virtual void OnDestroy() {}
// <20><><EFBFBD><EFBFBD>
void Run();
// <20><><EFBFBD><EFBFBD>
void Quit();
// <20><><EFBFBD><EFBFBD>
void Destroy();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void Use(
Component* component
);
// ж<><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void Remove(
Component* component
);
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void SetTimeScale(
float scale_factor
);
// <20>ַ<EFBFBD><D6B7>¼<EFBFBD>
2019-08-12 14:51:54 +08:00
void DispatchEvent(Event& evt);
2019-04-11 14:40:54 +08:00
// <20><> Kiwano <20><><EFBFBD>߳<EFBFBD><DFB3><EFBFBD>ִ<EFBFBD>к<EFBFBD><D0BA><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵߳<DFB3><CCB5><EFBFBD> Kiwano <20><><EFBFBD><EFBFBD>ʱʹ<CAB1><CAB9>
2019-04-24 13:33:19 +08:00
static void PreformInMainThread(
2019-08-13 21:16:38 +08:00
Function<void()> Function
);
protected:
void Render();
void Update();
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
protected:
2019-08-12 14:51:54 +08:00
bool end_;
bool inited_;
float time_scale_;
2019-08-13 21:16:38 +08:00
Vector<Component*> components_;
};
}