/
main.cpp
52 lines (45 loc) · 1.09 KB
/
main.cpp
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
/**
* This file is part of the Playdate CPP Extensions library, and covered under
* the license terms found in the LICENSE file at the root of the repository.
*
* Copyright (c) 2023 - Metaphase
*
* Created: 9/29/2023
* Original author: MrBZapp
*/
#include <memory>
#include <pd_api.h>
#include <pdcpp/pdnewlib.h>
#include <pdcpp/core/GlobalPlaydateAPI.h>
#include "HelloWorld.h"
std::unique_ptr<BinaryBuilderApp> game;
static int update(void* userdata)
{
return game->update();
};
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WINDLL
__declspec(dllexport)
#endif
int eventHandler(PlaydateAPI* pd, PDSystemEvent event, uint32_t arg)
{
eventHandler_pdnewlib(pd, event, arg);
if (event == kEventInit)
{
pdcpp::GlobalPlaydateAPI::initialize(pd);
game = std::make_unique<BinaryBuilderApp>();
pd->system->setUpdateCallback(update, pd);
}
// Destroy the global state to prevent memory leaks
if (event == kEventTerminate)
{
game = nullptr;
pdcpp::GlobalPlaydateAPI::destroyInstance();
}
return 0;
}
#ifdef __cplusplus
}
#endif