SpaghettiKart
Loading...
Searching...
No Matches
Engine.h
Go to the documentation of this file.
1#pragma once
2
3#include "port/audio/HMAS.h"
4
5static const char game_asset_file[] = "mk64.o2r";
6static const char engine_asset_file[] = "spaghetti.o2r";
7
8#define LOAD_ASSET(path) \
9(path == NULL ? NULL \
10 : (GameEngine_OTRSigCheck((const char*) path) ? ResourceGetDataByName((const char*) path) : path))
11#define LOAD_ASSET_RAW(path) ResourceGetDataByName((const char*) path)
12
13#ifdef __cplusplus
14#include <vector>
15#include <SDL2/SDL.h>
16#include <fast/Fast3dWindow.h>
17#include <fast/interpreter.h>
18#include "ship/Context.h"
19#include <unordered_map>
20
21#ifndef IDYES
22#define IDYES 6
23#endif
24#ifndef IDNO
25#define IDNO 7
26#endif
27
28#define SAMPLES_HIGH 448
29#define SAMPLES_LOW 432
30#define AUDIO_FRAMES_PER_UPDATE 2
31#define NUM_AUDIO_CHANNELS 2
32#define SAMPLES_PER_FRAME (SAMPLES_HIGH * NUM_AUDIO_CHANNELS * 2)
33
34Fast::Interpreter* GetInterpreter();
35
36struct CtlEntry;
37struct AudioBankSample;
39
40class GameEngine {
41 public:
42 static GameEngine* Instance;
43
44 std::shared_ptr<Ship::Context> context;
45 std::vector<CtlEntry*> banksTable;
46 std::vector<std::string> sequenceTable;
47 std::vector<AudioSequenceData*> audioSequenceTable;
48 std::vector<std::string> archiveFiles;
49
50 ImFont* fontStandard;
51 ImFont* fontStandardLarger;
52 ImFont* fontStandardLargest;
53 ImFont* fontMono;
54 ImFont* fontMonoLarger;
55 ImFont* fontMonoLargest;
56
57 HMAS* gHMAS;
58
59 std::unordered_map<std::string, uint8_t> bankMapTable;
60 GameEngine();
61 static bool GenAssetFile();
62 static void Create();
63
64 void AudioInit();
65 static void HandleAudioThread();
66 static void StartAudioFrame();
67 static void EndAudioFrame();
68 static void AudioExit();
69
70
71
72 static uint32_t GetInterpolationFPS();
73 static uint32_t GetInterpolationFrameCount();
74 void StartFrame() const;
75 static void RunCommands(Gfx* pool, const std::vector<std::unordered_map<Mtx*, MtxF>>& mtx_replacements);
76 void ProcessFrame(void (*run_one_game_iter)()) const;
77 static void Destroy();
78 static void ProcessGfxCommands(Gfx* pool);
79 static uint8_t GetBankIdByName(const std::string& name);
80 static int ShowYesNoBox(const char* title, const char* box);
81 static void ShowMessage(const char* title, const char* message, SDL_MessageBoxFlags type = SDL_MESSAGEBOX_ERROR);
82 float OTRGetAspectRatio(void);
83 float OTRGetDimensionFromLeftEdge(float v);
84 float OTRGetDimensionFromRightEdge(float v);
85 int16_t OTRGetRectDimensionFromLeftEdge(float v);
86 int16_t OTRGetRectDimensionFromRightEdge(float v);
87 uint32_t OTRGetGameRenderWidth();
88 uint32_t OTRGetGameRenderHeight();
89 uint32_t OTRGetGameViewportWidth();
90 uint32_t OTRGetGameViewportHeight();
91 uint32_t OTRCalculateCenterOfAreaFromRightEdge(int32_t center);
92 uint32_t OTRCalculateCenterOfAreaFromLeftEdge(int32_t center);
93 private:
94 ImFont* CreateFontWithSize(float size, std::string fontPath = "");
95};
96
97#endif
98
99#ifdef __cplusplus
100extern "C" {
101#endif
103uint32_t GameEngine_GetSampleRate();
106struct CtlEntry* GameEngine_LoadBank(uint8_t bankId);
107uint8_t GameEngine_IsBankLoaded(uint8_t bankId);
108void GameEngine_UnloadBank(uint8_t bankId);
109struct AudioSequenceData* GameEngine_LoadSequence(uint8_t seqId);
111uint8_t GameEngine_IsSequenceLoaded(uint8_t seqId);
112void GameEngine_UnloadSequence(uint8_t seqId);
113// bool GameEngine_OTRSigCheck(char* imgData); -> align_asset_macro.h
114float OTRGetAspectRatio(void);
115float OTRGetDimensionFromLeftEdge(float v);
116float OTRGetDimensionFromRightEdge(float v);
117int16_t OTRGetRectDimensionFromLeftEdge(float v);
118int16_t OTRGetRectDimensionFromRightEdge(float v);
119uint32_t OTRGetGameRenderWidth(void);
120uint32_t OTRGetGameRenderHeight(void);
121uint32_t OTRGetGameViewportWidth();
122uint32_t OTRGetGameViewportHeight();
123uint32_t OTRCalculateCenterOfAreaFromRightEdge(int32_t center);
124uint32_t OTRCalculateCenterOfAreaFromLeftEdge(int32_t center);
125int32_t GameEngine_ResourceGetTexTypeByName(const char* name);
126#ifdef __cplusplus
127}
128#endif
129
uint32_t OTRGetGameRenderWidth()
Definition Engine.cpp:805
float OTRGetAspectRatio()
Definition Engine.cpp:762
uint32_t OTRGetGameViewportWidth()
Definition Engine.cpp:814
float OTRGetDimensionFromRightEdge(float v)
Definition Engine.cpp:774
uint32_t OTRCalculateCenterOfAreaFromRightEdge(int32_t center)
Definition Engine.cpp:796
Fast::Interpreter * GetInterpreter()
Definition Engine.cpp:59
int16_t OTRGetRectDimensionFromRightEdge(float v)
Definition Engine.cpp:778
uint32_t OTRGetGameRenderHeight()
Definition Engine.cpp:810
uint32_t OTRGetGameViewportHeight()
Definition Engine.cpp:818
uint32_t OTRCalculateCenterOfAreaFromLeftEdge(int32_t center)
Definition Engine.cpp:800
int16_t OTRGetRectDimensionFromLeftEdge(float v)
Definition Engine.cpp:770
float OTRGetDimensionFromLeftEdge(float v)
Definition Engine.cpp:766
void GameEngine_UnloadSequence(uint8_t seqId)
Definition Engine.cpp:694
uint32_t OTRGetGameViewportWidth()
Definition Engine.cpp:814
float OTRGetDimensionFromRightEdge(float v)
Definition Engine.cpp:774
uint32_t OTRCalculateCenterOfAreaFromRightEdge(int32_t center)
Definition Engine.cpp:796
uint32_t GameEngine_GetSampleRate()
Definition Engine.cpp:620
void GameEngine_UnloadBank(uint8_t bankId)
Definition Engine.cpp:664
uint8_t GameEngine_IsBankLoaded(uint8_t bankId)
Definition Engine.cpp:658
uint32_t OTRGetGameRenderHeight(void)
Definition Engine.cpp:810
void GameEngine_ProcessGfxCommands(Gfx *commands)
uint32_t GameEngine_GetSequenceCount()
Definition Engine.cpp:685
int16_t OTRGetRectDimensionFromRightEdge(float v)
Definition Engine.cpp:778
struct CtlEntry * GameEngine_LoadBank(uint8_t bankId)
Definition Engine.cpp:637
int32_t GameEngine_ResourceGetTexTypeByName(const char *name)
Definition Engine.cpp:714
uint8_t GameEngine_IsSequenceLoaded(uint8_t seqId)
Definition Engine.cpp:690
uint32_t GameEngine_GetSamplesPerFrame()
Definition Engine.cpp:633
float OTRGetAspectRatio(void)
Definition Engine.cpp:762
float GameEngine_GetAspectRatio()
Definition Engine.cpp:699
struct AudioSequenceData * GameEngine_LoadSequence(uint8_t seqId)
Definition Engine.cpp:669
uint32_t OTRGetGameViewportHeight()
Definition Engine.cpp:818
uint32_t OTRCalculateCenterOfAreaFromLeftEdge(int32_t center)
Definition Engine.cpp:800
uint32_t OTRGetGameRenderWidth(void)
Definition Engine.cpp:805
static const char engine_asset_file[]
Definition Engine.h:6
int16_t OTRGetRectDimensionFromLeftEdge(float v)
Definition Engine.cpp:770
float OTRGetDimensionFromLeftEdge(float v)
Definition Engine.cpp:766
static const char game_asset_file[]
Definition Engine.h:5
Definition internal.h:134
Definition AudioSequence.h:7
Definition internal.h:172
u8 bankId
Definition internal.h:173