Magic_Game/src/core/Application.h

110 lines
2.5 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 "include-forwards.h"
#include "time.h"
2018-11-21 19:24:18 +08:00
#include "window.h"
2018-11-21 16:26:52 +08:00
#include "render.h"
2018-11-21 19:24:18 +08:00
#include "input.h"
#include "audio.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-01-25 01:45:03 +08:00
String title; // <20><><EFBFBD><EFBFBD>
int width; // <20><><EFBFBD><EFBFBD>
int height; // <20>߶<EFBFBD>
LPCWSTR icon; // ͼ<><CDBC>
bool vsync; // <20><>ֱͬ<D6B1><CDAC>
bool fullscreen; // ȫ<><C8AB>ģʽ
bool debug; // <20><><EFBFBD><EFBFBD>ģʽ
2018-11-21 16:26:52 +08:00
2018-11-12 20:46:54 +08:00
Options()
: title(L"Easy2D Game")
, width(640)
, height(480)
, icon(nullptr)
2018-11-21 19:24:18 +08:00
, vsync(true)
2019-01-25 01:45:03 +08:00
, fullscreen(false)
2018-11-12 20:46:54 +08:00
, debug(false)
{}
};
2019-01-24 12:21:01 +08:00
class Application
2018-11-17 23:24:16 +08:00
: protected Noncopyable
2018-11-08 00:21:59 +08:00
{
public:
2019-01-24 12:21:01 +08:00
Application(
String const& app_name = L"Easy2dGame"
);
2019-01-24 12:21:01 +08:00
virtual ~Application();
2019-01-24 12:21:01 +08:00
// <20><><EFBFBD><EFBFBD>
virtual void Setup() {}
// <20><>ʼ<EFBFBD><CABC>
void Init(
Options const& options
2018-11-08 00:21:59 +08:00
);
2018-09-02 14:30:48 +08:00
// <20><><EFBFBD><EFBFBD>
void Run();
// <20><><EFBFBD><EFBFBD>
void Quit();
// <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();
2018-11-21 19:24:18 +08:00
// <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>
void SetTimeScale(float scale);
private:
2018-11-22 19:31:44 +08:00
void Render(HWND);
2018-09-04 22:42:34 +08:00
void Update();
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
private:
2018-11-22 19:31:44 +08:00
bool debug_;
2018-11-21 19:24:18 +08:00
float time_scale_;
2019-01-24 12:21:01 +08:00
String app_name_;
ScenePtr curr_scene_;
ScenePtr next_scene_;
TransitionPtr transition_;
};
}