Magic_Game/Kiwano/platform/Application.h

160 lines
3.3 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
#include "../2d/include-forwards.h"
#include "../base/time.h"
#include "../base/window.h"
#include "../base/Component.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>ģʽ
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,
bool fullscreen = false
)
: title(title)
, width(width)
, height(height)
, icon(icon)
, clear_color(clear_color)
, vsync(vsync)
, fullscreen(fullscreen)
{}
};
2019-04-11 14:40:54 +08:00
class KGE_API Application
: protected Noncopyable
{
public:
Application();
virtual ~Application();
// <20><>ʼ<EFBFBD><CABC>
void Init(
Options const& options
);
// <20><><EFBFBD><EFBFBD>ʱ
virtual void OnStart() {}
// <20>ر<EFBFBD>ʱ
virtual bool OnClosing() { return true; }
// <20><><EFBFBD><EFBFBD>ʱ
virtual void OnDestroy() {}
// <20><>Ⱦʱ
virtual void OnRender() {}
// <20><><EFBFBD><EFBFBD>ʱ
2019-04-11 14:40:54 +08:00
virtual void OnUpdate(Duration dt) { KGE_NOT_USED(dt); }
// <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><D0BB><EFBFBD><EFBFBD><EFBFBD>
void EnterScene(
ScenePtr scene /* <20><><EFBFBD><EFBFBD> */
);
// <20>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
void EnterScene(
ScenePtr scene, /* <20><><EFBFBD><EFBFBD> */
TransitionPtr transition /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
);
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
ScenePtr GetCurrentScene();
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
inline Window* GetWindow() const { return main_window_; }
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void SetTimeScale(
float scale_factor
);
// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
void ShowDebugInfo(
bool show = true
);
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(
Closure<void()> function
);
protected:
void Render();
void Update();
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
protected:
bool end_;
bool inited_;
float time_scale_;
ScenePtr curr_scene_;
ScenePtr next_scene_;
NodePtr debug_node_;
TransitionPtr transition_;
Window* main_window_;
Array<Component*> components_;
};
}