-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
192 lines (168 loc) · 4.92 KB
/
Copy pathmain.cpp
File metadata and controls
192 lines (168 loc) · 4.92 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include <cstdlib>
#include <gfd.h>
#include <stdio.h>
#include <string.h>
#include <whb/file.h>
#include <whb/gfx.h>
#include <whb/log.h>
#include <whb/log_cafe.h>
#include <whb/log_udp.h>
#include <whb/proc.h>
#include <whb/sdcard.h>
#include <sysapp/launch.h>
#include <coreinit/filesystem.h>
#include <coreinit/memblockheap.h>
#include <coreinit/memexpheap.h>
#include <coreinit/systeminfo.h>
#include <coreinit/thread.h>
#include <coreinit/time.h>
#include <sndcore2/core.h>
#include "renderer/Renderer.h"
#include "renderer/ShaderManager.h"
#include "renderer/RenderBuffer.h"
#include "immaterial/Assets.h"
#include "immaterial/Scenes.h"
#include "sound/Music.h"
#include "sync/Sync.h"
#include "util/ourmalloc.h"
// Non-default heap
#ifdef USE_OURMALLOC
#ifdef USE_OURMALLOC_BLOCKHEAP
MEMHeapHandle ourHeap;
MEMBlockHeap ourHeapStorage;
#else
MEMHeapHandle ourHeap;
#endif
#endif
#define BENCHMARK 1
#include "util/wuhbsupport.h"
int main(int argc, char **argv) {
// wiiu homebrew bug workaround (which unfortunately doesn't seem to actually
// work)
fprintf(stdout, "hi\n");
fprintf(stderr, "hello\n");
#ifndef WUHB_BUILD
WHBLogCafeInit();
WHBLogUdpInit();
#endif
#ifndef SHADER_BUILD
WHBProcInit();
#endif
WHBGfxInit();
#ifndef WUHB_BUILD
WHBMountSdCard();
#endif
// Preheat shader cache
getShaderManager();
#if SHADER_BUILD
// if we're in "build shader cache" mode, quit here
WHBGfxShutdown();
WHBUnmountSdCard();
WHBLogCafeDeinit();
WHBLogUdpDeinit();
return 0;
#endif
// Init the heap, 750mb, more than enough to store all assets
// this is explicitly and intentionally NOT used as the default heap, to
// isolate us from the base wiiu memory management that WHB uses, because it
// gets fucked up somehow at some point (maybe due to glsl compiler)
uint32_t heapSize = int(1024 * 1024 * 1025 * 0.75);
uint8_t *heapBaseAddr = (uint8_t *)MEMAllocFromDefaultHeapEx(heapSize, 4);
WHBLogPrintf("Allocated heap at %p", heapBaseAddr);
#ifdef USE_OURMALLOC_BLOCKHEAP
size_t trackSize = heapSize / 1024;
uint8_t *heapEndAddr = heapBaseAddr + heapSize;
MEMBlockHeapTracking *blockTrack =
(MEMBlockHeapTracking *)MEMAllocFromDefaultHeapEx(trackSize, 4);
WHBLogPrintf("Block track at %p, end at %p", blockTrack, heapEndAddr);
ourHeap = MEMInitBlockHeap(&ourHeapStorage, heapBaseAddr,
heapBaseAddr + heapSize, blockTrack, trackSize, 0);
#else
ourHeap = MEMCreateExpHeapEx(heapBaseAddr, heapSize, 0);
#endif
// Current scene
int currentScene = -1000;
WHBLogPrint("Hello World! Logging initialised.");
{
auto music = MusicPlayer(WIIU_PATH_PREFIX "assets/immaterial.ogg", 0.0f);
// Create the assets repository
auto assets = Assets();
auto renderer = Renderer();
auto renderBuffer = RenderBuffer(false, 1280, 720);
renderer.reserve(80);
// Populate the renderer with the models
renderer.addModels(assets.createModels());
std::unique_ptr<SceneBase> scene;
WHBLogPrintf("Begin updating...");
#ifdef SYNC_PLAYER
music.play();
#endif
createSyncHandler(
"sync_tracks/", SYNC_IP, music,
(60.0f / 100.0f) /
6.0f // 100 BPM, 8 rows per beat. unsure if FP math would cause
// drift by being not 100% accurate, should be fine tho
);
size_t frameCounter = 0;
float lastTime = 0.0f;
while (WHBProcIsRunning()) {
// Update rocket
getSyncHandler()->update();
// Scene switcher
int newScene = syncVal("Global:Scene");
if (currentScene != newScene) {
scene.reset(getScene(newScene));
if (scene) {
scene->setup();
}
currentScene = newScene;
}
// Update scene
if (scene) {
scene->update(music.currentTime());
renderer.renderFrame(*scene, renderBuffer);
}
#ifdef SYNC_PLAYER
if(music.isDone()) {
WHBLogPrintf("Music done, quitting...");
SYSLaunchMenu(); // this tells the proc loop to quit
}
#endif
#ifdef BENCHMARK
// if you're in synctool mode you can make the FPS go negative lol
frameCounter++;
if (frameCounter % 60 == 0) {
float currentTime = music.currentTime();
WHBLogPrintf("FPS: %f", 60.0f / (currentTime - lastTime));
lastTime = currentTime;
}
#endif
}
WHBLogPrintf("Done. Quitting...");
// Get rid of all of our stuff
destroySyncHandler();
}
destroyShaderManager();
// Clean up GX2 / AX stuff
WHBGfxShutdown();
AXQuit();
#ifndef WUHB_BUILD
// If not in WUHB mode: Deinit logging, unmount SD
WHBUnmountSdCard();
WHBLogCafeDeinit();
#endif
// Deinit WHBProc
WHBProcShutdown();
#ifdef USE_OURMALLOC
// Kill custom heap, if we were using that
WHBLogPrintf("Killing heap...");
MEMDestroyExpHeap(ourHeap);
MEMFreeToDefaultHeap(heapBaseAddr);
#endif
#ifndef WUHB_BUILD
// Deinit UDP log
WHBLogPrintf("Deinitialising UDP logging...");
WHBLogUdpDeinit();
#endif
return 0;
}