Magic_Game/easy2d/platform/Application.h

157 lines
3.3 KiB
C
Raw Normal View History

2018-10-03 22:02:46 +08:00
// Copyright (c) 2016-2018 Easy2D - 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"
2018-09-02 14:30:48 +08:00
2018-11-08 00:21:59 +08:00
namespace easy2d
2018-09-02 14:30:48 +08:00
{
2018-11-12 20:46:54 +08:00
struct Options
{
2019-03-10 13:44:02 +08:00
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>ģʽ
2018-11-21 16:26:52 +08:00
2019-03-11 17:24:11 +08:00
Options(
String const& title = L"Easy2D Game",
int width = 640,
int height = 480,
2019-03-11 17:24:11 +08:00
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)
{}
2018-11-12 20:46:54 +08:00
};
class E2D_API Application
2018-11-17 23:24:16 +08:00
: protected Noncopyable
2018-11-08 00:21:59 +08:00
{
public:
Application();
2019-01-24 12:21:01 +08:00
virtual ~Application();
// <20><>ʼ<EFBFBD><CABC>
void Init(
2019-03-11 17:24:11 +08:00
Options const& options
2018-11-08 00:21:59 +08:00
);
2018-09-02 14:30:48 +08:00
// <20><><EFBFBD><EFBFBD>ʱ
virtual void OnStart() {}
// <20>ر<EFBFBD>ʱ
virtual bool OnClosing() { return true; }
// <20><><EFBFBD><EFBFBD>ʱ
virtual void OnDestroy() {}
2019-03-11 11:11:39 +08:00
// <20><>Ⱦʱ
virtual void OnRender() {}
2019-02-03 21:45:56 +08:00
// <20><><EFBFBD><EFBFBD>ʱ
virtual void OnUpdate(Duration dt) { E2D_NOT_USED(dt); }
// <20><><EFBFBD><EFBFBD>
void Run();
// <20><><EFBFBD><EFBFBD>
void Quit();
2019-02-03 21:45:56 +08:00
// <20><><EFBFBD><EFBFBD>
void Destroy();
2019-03-11 17:24:11 +08:00
// <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>
2018-11-22 19:31:44 +08:00
void EnterScene(
ScenePtr const& scene /* <20><><EFBFBD><EFBFBD> */
);
// <20>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
2018-11-22 19:31:44 +08:00
void EnterScene(
ScenePtr const& scene, /* <20><><EFBFBD><EFBFBD> */
TransitionPtr const& transition /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
2018-11-08 00:21:59 +08:00
);
2018-09-02 14:30:48 +08:00
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
ScenePtr const& 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
);
2018-11-21 19:24:18 +08:00
2019-03-11 11:11:39 +08:00
// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
void ShowDebugInfo(
bool show = true
);
// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>̨
static void ShowConsole();
2019-03-10 13:44:02 +08:00
2019-03-11 11:11:39 +08:00
protected:
void Render();
2018-09-04 22:42:34 +08:00
void Update();
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
2019-03-11 11:11:39 +08:00
protected:
bool end_;
bool inited_;
2018-11-21 19:24:18 +08:00
float time_scale_;
2019-01-24 12:21:01 +08:00
ScenePtr curr_scene_;
ScenePtr next_scene_;
2019-03-11 11:11:39 +08:00
NodePtr debug_node_;
TransitionPtr transition_;
2019-03-11 17:24:11 +08:00
Window* main_window_;
Array<Component*> components_;
};
}