Add some windows support.

This commit is contained in:
Fries 2024-03-16 23:44:14 -07:00
parent c651dcd038
commit 63565fc7f1
11 changed files with 87 additions and 33 deletions

22
i686-w64-mingw32.txt Normal file
View file

@ -0,0 +1,22 @@
[binaries]
c = 'i686-w64-mingw32-gcc'
cpp = 'i686-w64-mingw32-g++'
ar = 'i686-w64-mingw32-ar'
strip = 'i686-w64-mingw32-strip'
pkg-config = 'i686-w64-mingw32-pkg-config'
windres = 'i686-w64-mingw32-windres'
#exe_wrapper = 'wine'
ld = 'i686-w64-mingw32-ld'
[properties]
# Directory that contains 'bin', 'lib', etc
root = '/usr/i686-w64-mingw32'
# Directory that contains 'bin', 'lib', etc for the toolchain and system libraries
sys_root = '/usr/i686-w64-mingw32/sys-root/mingw'
[host_machine]
system = 'windows'
cpu_family = 'x86'
cpu = 'i686'
endian = 'little'

View file

@ -1,10 +1,10 @@
#include "linuxController.hh" #include "desktopController.hh"
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
bool LinuxController::InitializeController() { bool DesktopController::InitializeController() {
std::ifstream gameControllerDB; std::ifstream gameControllerDB;
gameControllerDB.open("./gamecontrollerdb.txt"); gameControllerDB.open("./gamecontrollerdb.txt");
if (gameControllerDB.is_open()) { if (gameControllerDB.is_open()) {
@ -20,23 +20,23 @@ bool LinuxController::InitializeController() {
return false; return false;
} }
void LinuxController::PollController() { void DesktopController::PollController() {
glfwGetGamepadState(GLFW_JOYSTICK_1, &controllerState); glfwGetGamepadState(GLFW_JOYSTICK_1, &controllerState);
} }
bool LinuxController::IsButtonPressed(Button button) { bool DesktopController::IsButtonPressed(Button button) {
return controllerState.buttons[GetButtonMask(button)]; return controllerState.buttons[GetButtonMask(button)];
} }
float LinuxController::GetLeftJoystickXAxis() { float DesktopController::GetLeftJoystickXAxis() {
return controllerState.axes[GLFW_GAMEPAD_AXIS_LEFT_X]; return controllerState.axes[GLFW_GAMEPAD_AXIS_LEFT_X];
} }
float LinuxController::GetLeftJoystickYAxis() { float DesktopController::GetLeftJoystickYAxis() {
return controllerState.axes[GLFW_GAMEPAD_AXIS_LEFT_Y]; return controllerState.axes[GLFW_GAMEPAD_AXIS_LEFT_Y];
} }
int LinuxController::GetButtonMask(Button button) { int DesktopController::GetButtonMask(Button button) {
switch (button) { switch (button) {
case Button::A: case Button::A:
return GLFW_GAMEPAD_BUTTON_A; return GLFW_GAMEPAD_BUTTON_A;

View file

@ -3,7 +3,7 @@
#include "controller.hh" #include "controller.hh"
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
class LinuxController : public Controller { class DesktopController : public Controller {
public: public:
bool InitializeController() override; bool InitializeController() override;
void PollController() override; void PollController() override;

View file

@ -4,8 +4,8 @@ if host_machine.system() == 'dreamcast'
sources += 'dreamcastController.cc' sources += 'dreamcastController.cc'
endif endif
if host_machine.system() == 'linux' if host_machine.system() != 'dreamcast'
sources += 'linuxController.cc' sources += 'desktopController.cc'
endif endif
controller = static_library('controller', sources) controller = static_library('controller', sources, dependencies: engine_deps)

View file

@ -1,13 +1,13 @@
#ifdef __linux__ #ifndef _arch_dreamcast
#include "linuxEngine.hh" #include "desktopEngine.hh"
#include <iostream> #include <iostream>
#include <stdexcept> #include <stdexcept>
#include "controller/linuxController.hh" #include "controller/desktopController.hh"
void LinuxEngine::initializeEngine() { void DesktopEngine::initializeEngine() {
glfwInit(); glfwInit();
// Set OpenGL version to 1.2. // Set OpenGL version to 1.2.
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
@ -28,8 +28,8 @@ void LinuxEngine::initializeEngine() {
// printSystemInformation(); // printSystemInformation();
} }
void LinuxEngine::initializeController() { void DesktopEngine::initializeController() {
LinuxController* linuxCont = new LinuxController; DesktopController* linuxCont = new DesktopController;
if (linuxCont->InitializeController()) { if (linuxCont->InitializeController()) {
controller = linuxCont; controller = linuxCont;
} else { } else {
@ -37,16 +37,16 @@ void LinuxEngine::initializeController() {
} }
} }
void LinuxEngine::SwapBuffers() { void DesktopEngine::SwapBuffers() {
glfwSwapBuffers(window); glfwSwapBuffers(window);
glfwPollEvents(); glfwPollEvents();
} }
bool LinuxEngine::ShouldWindowClose() { bool DesktopEngine::ShouldWindowClose() {
return glfwWindowShouldClose(this->window); return glfwWindowShouldClose(this->window);
} }
LinuxEngine::~LinuxEngine() { DesktopEngine::~DesktopEngine() {
delete controller; delete controller;
glfwDestroyWindow(window); glfwDestroyWindow(window);
glfwTerminate(); glfwTerminate();

View file

@ -3,12 +3,12 @@
#include "nativeEngine.hh" #include "nativeEngine.hh"
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
class LinuxEngine : public NativeEngine { class DesktopEngine : public NativeEngine {
void initializeController() override; void initializeController() override;
void initializeEngine() override; void initializeEngine() override;
void SwapBuffers() override; void SwapBuffers() override;
bool ShouldWindowClose() override; bool ShouldWindowClose() override;
~LinuxEngine() override; ~DesktopEngine() override;
GLFWwindow* window = nullptr; GLFWwindow* window = nullptr;
}; };
#endif #endif

View file

@ -7,7 +7,7 @@
#include "dreamcastEngine.hh" #include "dreamcastEngine.hh"
#else #else
#include "linuxEngine.hh" #include "desktopEngine.hh"
#endif #endif
#include <cstdio> #include <cstdio>
@ -18,7 +18,7 @@ void Engine::initializeEngine() {
#ifdef _arch_dreamcast #ifdef _arch_dreamcast
engine = new DreamcastEngine; engine = new DreamcastEngine;
#else #else
engine = new LinuxEngine; engine = new DesktopEngine;
#endif #endif
engine->initializeEngine(); engine->initializeEngine();
initScreen(); initScreen();

View file

@ -3,12 +3,12 @@ engine_deps = [
math, math,
] ]
if host_machine.system() == 'linux' if host_machine.system() != 'dreamcast'
engine_deps += dependency('glfw3') engine_deps += dependency('glfw3', fallback: ['glfw', 'glfw_dep'], required: true)
engine_deps += dependency('epoxy') engine_deps += dependency('epoxy', fallback: ['epoxy', 'libepoxy_dep'], required: true)
endif endif
subdir('controller') subdir('controller')
engine = static_library('engine', ['dreamcastEngine.cc', 'linuxEngine.cc', 'entity.cc', 'engine.cc'], dependencies: engine_deps, include_directories: incdirs) engine = static_library('engine', ['dreamcastEngine.cc', 'desktopEngine.cc', 'entity.cc', 'engine.cc'], dependencies: engine_deps, include_directories: incdirs)
engine_dep = declare_dependency(link_with: [engine, controller], include_directories: incdirs) engine_dep = declare_dependency(link_with: [engine, controller], include_directories: incdirs)

View file

@ -5,7 +5,11 @@ koskernelinc = include_directories('/opt/toolchains/dc/kos/kernel/arch/dreamcast
kosaddonsinc = include_directories('/opt/toolchains/dc/kos/addons/include') kosaddonsinc = include_directories('/opt/toolchains/dc/kos/addons/include')
kosportsinc = include_directories('/opt/toolchains/dc/kos-ports/include') kosportsinc = include_directories('/opt/toolchains/dc/kos-ports/include')
GL = cc.find_library('GL', required: true) if host_machine.system() == 'windows'
GL = cc.find_library('opengl32', required: true)
else
GL = cc.find_library('GL', required: true)
endif
math = cc.find_library('m', required: true) math = cc.find_library('m', required: true)
# pcx = cc.find_library('pcx', required: true) # pcx = cc.find_library('pcx', required: true)
# kosutils = cc.find_library('kosutils', required: true) # kosutils = cc.find_library('kosutils', required: true)
@ -32,9 +36,13 @@ if host_machine.system() == 'dreamcast'
] ]
endif endif
if host_machine.system() == 'linux' if host_machine.system() != 'dreamcast'
deps += dependency('glfw3') deps += dependency('glfw3', fallback: ['glfw', 'glfw_dep'], required: true)
deps += dependency('glu') if host_machine.system() == 'windows'
deps += cc.find_library('glu32', required: true)
elif
deps += dependency('glu', required: true)
endif
endif endif
subdir('engine') subdir('engine')
@ -58,5 +66,7 @@ subdir('flappyBird')
executable('hello.elf', ['hello.cc'], dependencies: [deps] + [hello_dep], include_directories: incdirs) executable('hello.elf', ['hello.cc'], dependencies: [deps] + [hello_dep], include_directories: incdirs)
executable('gl.elf', ['gl.cc'], dependencies: [deps] + [glcc_dep], include_directories: incdirs) executable('gl.elf', ['gl.cc'], dependencies: [deps] + [glcc_dep], include_directories: incdirs)
executable('cube.elf', cube_sources, dependencies: deps, include_directories: incdirs) if host_machine.system() != 'windows'
executable('cube.elf', cube_sources, dependencies: deps, include_directories: incdirs)
endif
executable('flappyBird.elf', ['flappyBird.cc'], dependencies: [deps] + [flappy_dep], include_directories: incdirs) executable('flappyBird.elf', ['flappyBird.cc'], dependencies: [deps] + [flappy_dep], include_directories: incdirs)

9
subprojects/epoxy.wrap Normal file
View file

@ -0,0 +1,9 @@
[wrap-file]
directory = libepoxy-1.5.10
source_url = https://github.com/anholt/libepoxy/archive/refs/tags/1.5.10.tar.gz
source_filename = libepoxy-1.5.10.tar.gz
source_hash = a7ced37f4102b745ac86d6a70a9da399cc139ff168ba6b8002b4d8d43c900c15
wrapdb_version = 1.5.10-2
[provide]
epoxy = libepoxy_dep

13
subprojects/glfw.wrap Normal file
View file

@ -0,0 +1,13 @@
[wrap-file]
directory = glfw-3.3.9
source_url = https://github.com/glfw/glfw/archive/refs/tags/3.3.9.tar.gz
source_filename = glfw-3.3.9.tar.gz
source_hash = a7e7faef424fcb5f83d8faecf9d697a338da7f7a906fc1afbc0e1879ef31bd53
patch_filename = glfw_3.3.9-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/glfw_3.3.9-1/get_patch
patch_hash = b4261ed4de479ea0496617feace62eec5b73f62bf3c88dd1537afcf5eebd5cab
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/glfw_3.3.9-1/glfw-3.3.9.tar.gz
wrapdb_version = 3.3.9-1
[provide]
glfw3 = glfw_dep