aboutsummaryrefslogtreecommitdiffstats
path: root/yage/entity/engine.cpp
blob: 7377409367dea9385590428a3ea05f714a1ace57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/** ---------------------------------------------------------------------------
 * -*- c++ -*-
 * @file: engine.cpp
 *
 * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com>
 * MIT License, see LICENSE file for more details.
 * ----------------------------------------------------------------------------
 */

#include "engine.h"

#include "../core/core.h"

#include "space.h"

namespace yage
{

Engine::~Engine()
{
    quit();
}

Engine &Engine::init()
{
    yage::init();
    window_.create("Game Engine", 800, 640);
    return *this;
}

Engine &Engine::mainLoop()
{
    while (!window_.shouldClose()) {
        window_.pollEvents();
        window_.clearBuffer();

        update();

        window_.swapBuffer();
    }

    return *this;
}

void Engine::update()
{
    for (auto &space : spaces_) {
        space->update();
    }
}

Engine &Engine::addSpace(std::unique_ptr<Space> space)
{
    spaces_.push_back(std::move(space));
    return *this;
}

Engine &Engine::instance()
{
    static Engine engine_instance;

    return engine_instance;
}

} // namespace yage