2020-10-04 08:28:38 +02:00
|
|
|
// Tips for Getting Started:
|
|
|
|
// 1. Use the Solution Explorer window to add/manage files
|
|
|
|
// 2. Use the Team Explorer window to connect to source control
|
|
|
|
// 3. Use the Output window to see build output and other messages
|
|
|
|
// 4. Use the Error List window to view errors
|
|
|
|
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
|
|
|
|
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
|
|
|
|
|
|
|
|
#ifndef PCH_H
|
|
|
|
#define PCH_H
|
|
|
|
|
2021-09-09 10:40:54 +02:00
|
|
|
|
|
|
|
// GCC does not have *_s functions
|
|
|
|
#define _CRT_SECURE_NO_WARNINGS
|
|
|
|
|
2020-10-04 08:28:38 +02:00
|
|
|
// TODO: add headers that you want to pre-compile here
|
2020-10-18 17:08:41 +02:00
|
|
|
#include <cstdio>
|
2020-10-25 15:17:26 +01:00
|
|
|
#include <cassert>
|
|
|
|
#include <cmath>
|
2021-02-16 17:03:45 +01:00
|
|
|
#include <cstdint>
|
2021-01-22 10:53:16 +01:00
|
|
|
#include <type_traits> /*For control template*/
|
2021-08-27 12:29:41 +02:00
|
|
|
#include <chrono>
|
2021-09-09 10:40:54 +02:00
|
|
|
#include <iostream>
|
2021-09-06 15:27:58 +02:00
|
|
|
//#include <iomanip>
|
2020-11-01 16:45:29 +01:00
|
|
|
//#include <cstdlib>
|
2021-09-06 15:27:58 +02:00
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
2021-09-09 10:40:54 +02:00
|
|
|
#include <cstring>
|
|
|
|
#include <string>
|
2021-09-28 07:14:18 +02:00
|
|
|
#include <thread>
|
2021-10-02 16:45:31 +02:00
|
|
|
#include <map>
|
2023-01-27 14:25:47 +01:00
|
|
|
#include <unordered_map>
|
2022-08-31 06:58:03 +02:00
|
|
|
#include <initializer_list>
|
2021-12-08 13:55:49 +01:00
|
|
|
//#include <array>
|
2020-10-18 17:08:41 +02:00
|
|
|
|
2021-08-27 12:29:41 +02:00
|
|
|
#define SDL_MAIN_HANDLED
|
|
|
|
#include "SDL.h"
|
|
|
|
#include <SDL_mixer.h>
|
|
|
|
|
2021-10-17 11:00:30 +02:00
|
|
|
// MIX_INIT_FLUIDSYNTH was renamed to MIX_INIT_MID in SDL_mixer v2.0.2
|
2022-07-18 08:45:46 +02:00
|
|
|
// Older versions of SDL_mixer did not have SDL_MIXER_VERSION_ATLEAST
|
2021-10-17 11:00:30 +02:00
|
|
|
constexpr int MIX_INIT_MID_Proxy =
|
2022-07-18 08:45:46 +02:00
|
|
|
#if SDL_VERSIONNUM(SDL_MIXER_MAJOR_VERSION, SDL_MIXER_MINOR_VERSION, SDL_MIXER_PATCHLEVEL) >= SDL_VERSIONNUM(2, 0, 2)
|
2021-10-17 11:00:30 +02:00
|
|
|
MIX_INIT_MID;
|
|
|
|
#else
|
|
|
|
MIX_INIT_FLUIDSYNTH;
|
|
|
|
#endif
|
|
|
|
|
2022-12-11 05:57:49 +01:00
|
|
|
//https://github.com/ocornut/imgui 59b63defe5421642fb0cdcfd1fa850fc85a13791 + patches
|
2021-09-05 09:47:05 +02:00
|
|
|
#include "imgui.h"
|
2021-09-16 09:57:46 +02:00
|
|
|
#include "imgui_internal.h"
|
2021-09-05 09:47:05 +02:00
|
|
|
#include "imgui_impl_sdl.h"
|
2022-12-11 07:32:40 +01:00
|
|
|
|
|
|
|
// imgui_impl_sdlrenderer is faster and more accurate, but it requires newer SDL.
|
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 17)
|
|
|
|
#include "imgui_impl_sdlrenderer.h"
|
|
|
|
constexpr const char* ImGuiRender = "HW";
|
|
|
|
inline void ImGui_Render_Init(SDL_Renderer* renderer) { ImGui_ImplSDLRenderer_Init(renderer); }
|
|
|
|
inline void ImGui_Render_Shutdown() { ImGui_ImplSDLRenderer_Shutdown(); }
|
|
|
|
inline void ImGui_Render_NewFrame() { ImGui_ImplSDLRenderer_NewFrame(); }
|
|
|
|
inline void ImGui_Render_RenderDrawData(ImDrawData* draw_data) { ImGui_ImplSDLRenderer_RenderDrawData(draw_data); }
|
|
|
|
#else
|
2022-12-11 05:57:49 +01:00
|
|
|
//https://github.com/Tyyppi77/imgui_sdl 01deb04b102b6a1c15c7fdec1977a2c96a885e6f + patches
|
2021-09-05 09:47:05 +02:00
|
|
|
#include "imgui_sdl.h"
|
2022-12-11 07:32:40 +01:00
|
|
|
constexpr const char* ImGuiRender = "SW";
|
|
|
|
inline void ImGui_Render_Init(SDL_Renderer* renderer) { ImGuiSDL::Initialize(renderer, 0, 0); }
|
|
|
|
inline void ImGui_Render_Shutdown() { ImGuiSDL::Deinitialize(); }
|
|
|
|
inline void ImGui_Render_NewFrame() { }
|
|
|
|
inline void ImGui_Render_RenderDrawData(ImDrawData* draw_data) { ImGuiSDL::Render(draw_data); }
|
|
|
|
#endif
|
|
|
|
|
2021-09-05 09:47:05 +02:00
|
|
|
|
2021-09-06 15:27:58 +02:00
|
|
|
typedef char* LPSTR;
|
|
|
|
typedef const char* LPCSTR;
|
|
|
|
|
2021-09-09 10:40:54 +02:00
|
|
|
constexpr char PathSeparator =
|
|
|
|
#ifdef _WIN32
|
|
|
|
'\\';
|
|
|
|
#else
|
|
|
|
'/';
|
|
|
|
#endif
|
|
|
|
|
2021-09-01 10:02:57 +02:00
|
|
|
|
2021-01-23 17:28:29 +01:00
|
|
|
/*Use (void) to silent unused warnings.*/
|
2020-11-05 16:44:34 +01:00
|
|
|
#define assertm(exp, msg) assert(((void)msg, exp))
|
2020-10-04 08:28:38 +02:00
|
|
|
|
2021-01-31 15:29:53 +01:00
|
|
|
|
|
|
|
inline size_t pgm_save(int width, int height, char* data, FILE* outfile)
|
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
n += fprintf(outfile, "P5\n%d %d\n%d\n", width, height, 0xFF);
|
|
|
|
n += fwrite(data, 1, width * height, outfile);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2021-09-09 10:40:54 +02:00
|
|
|
inline float RandFloat()
|
|
|
|
{
|
2021-09-14 14:33:18 +02:00
|
|
|
return static_cast<float>(std::rand() / static_cast<double>(RAND_MAX));
|
2021-09-09 10:40:54 +02:00
|
|
|
}
|
|
|
|
|
2022-01-12 15:17:38 +01:00
|
|
|
template <typename T>
|
|
|
|
constexpr int Sign(T val)
|
2021-10-25 07:03:30 +02:00
|
|
|
{
|
|
|
|
return (T(0) < val) - (val < T(0));
|
|
|
|
}
|
|
|
|
|
2022-01-12 15:17:38 +01:00
|
|
|
template <typename T>
|
|
|
|
const T& Clamp(const T& n, const T& lower, const T& upper)
|
|
|
|
{
|
|
|
|
return std::max(lower, std::min(n, upper));
|
|
|
|
}
|
|
|
|
|
2021-11-06 17:22:56 +01:00
|
|
|
// UTF-8 path adapter for fopen on Windows, implemented in SpaceCadetPinball.cpp
|
|
|
|
#ifdef _WIN32
|
|
|
|
extern FILE* fopenu(const char* path, const char* opt);
|
|
|
|
#else
|
|
|
|
inline FILE* fopenu(const char* path, const char* opt)
|
|
|
|
{
|
|
|
|
return fopen(path, opt);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-12-08 13:55:49 +01:00
|
|
|
// Platform specific data paths not found in SDL
|
|
|
|
constexpr const char* PlatformDataPaths[2] =
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
nullptr
|
|
|
|
#else
|
|
|
|
"/usr/local/share/SpaceCadetPinball/",
|
|
|
|
"/usr/share/SpaceCadetPinball/"
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2022-06-01 15:19:27 +02:00
|
|
|
constexpr float Pi = 3.14159265358979323846f;
|
|
|
|
|
2020-10-04 08:28:38 +02:00
|
|
|
#endif //PCH_H
|