Magic_Game/core/base/Game.h

125 lines
2.6 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-11-22 19:31:44 +08:00
#include "Event.hpp"
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
{
std::wstring title; // <20><><EFBFBD><EFBFBD>
2018-11-21 16:26:52 +08:00
int width; // <20><><EFBFBD><EFBFBD>
int height; // <20>߶<EFBFBD>
LPCWSTR icon; // ͼ<><CDBC>
2018-11-21 19:24:18 +08:00
bool vsync; // <20><>ֱͬ<D6B1><CDAC>
2018-11-21 16:26:52 +08:00
bool debug; // <20><><EFBFBD><EFBFBD>ģʽ
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)
2018-11-12 20:46:54 +08:00
, debug(false)
{}
};
class Game
2018-11-17 23:24:16 +08:00
: protected Noncopyable
2018-11-08 00:21:59 +08:00
{
public:
Game();
Game(
Options const& options
);
virtual ~Game();
2018-11-22 19:31:44 +08:00
// <20>˳<EFBFBD><CBB3><EFBFBD>Ϸ
virtual void OnExit() {}
2018-11-22 19:31:44 +08:00
// <20><><EFBFBD>ڹر<DAB9>
virtual bool OnClose() { return true; }
// <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(
spScene const& scene /* <20><><EFBFBD><EFBFBD> */
);
// <20>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
2018-11-22 19:31:44 +08:00
void EnterScene(
spScene const& scene, /* <20><><EFBFBD><EFBFBD> */
spTransition 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>
spScene 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();
2018-11-22 19:31:44 +08:00
bool HandleMessage(
HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam
);
void Dispatch(
2018-11-22 19:31:44 +08:00
Event* event
);
2018-10-03 18:04:04 +08:00
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
private:
2018-11-22 19:31:44 +08:00
bool debug_;
bool active_;
2018-11-21 19:24:18 +08:00
float time_scale_;
spScene curr_scene_;
spScene next_scene_;
spTransition transition_;
};
}