diff options
-rw-r--r-- | .build.yml | 1 | ||||
-rw-r--r-- | build.zig | 4 | ||||
-rw-r--r-- | src/Game.cc | 28 | ||||
-rw-r--r-- | src/Game.h | 15 | ||||
-rw-r--r-- | src/GameInitDispose.cpp | 18 | ||||
-rw-r--r-- | src/main.zig | 46 |
6 files changed, 69 insertions, 43 deletions
diff --git a/.build.yml b/.build.yml index eb68c02..9216c2f 100644 --- a/.build.yml +++ b/.build.yml @@ -1,6 +1,5 @@ image: archlinux packages: - - freealut - glu - libvorbis - openal diff --git a/build.zig b/build.zig index bd2a063..cd8f246 100644 --- a/build.zig +++ b/build.zig @@ -2,8 +2,9 @@ const std = @import("std"); pub fn build(b: *std.build.Builder) void { const exe = b.addExecutable("blackshades", "src/main.zig"); + exe.addIncludeDir("src"); + const cxxflags = [_][]const u8{ "--std=c++17" }; - exe.addCSourceFile("src/Game.cc", &cxxflags); exe.addCSourceFile("src/Camera.cpp", &cxxflags); exe.addCSourceFile("src/Decals.cpp", &cxxflags); exe.addCSourceFile("src/Fog.cpp", &cxxflags); @@ -28,7 +29,6 @@ pub fn build(b: *std.build.Builder) void { exe.linkSystemLibrary("GL"); exe.linkSystemLibrary("GLU"); exe.linkSystemLibrary("SDL"); - exe.linkSystemLibrary("alut"); exe.linkSystemLibrary("c++"); exe.linkSystemLibrary("openal"); exe.linkSystemLibrary("vorbisfile"); diff --git a/src/Game.cc b/src/Game.cc deleted file mode 100644 index 31afe2a..0000000 --- a/src/Game.cc +++ /dev/null @@ -1,28 +0,0 @@ -// Main function -// Copyright (C) 2002 David Rosen -// Copyright (C) 2021 Nguyễn Gia Phong -// -// This file is part of Black Shades. -// -// Black Shades is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Black Shades is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Black Shades. If not, see <https://www.gnu.org/licenses/>. - -#include "Game.h" - -void run() -{ - Game game {}; - initGl(&game); - initGame(&game); - eventLoop(&game); -} diff --git a/src/Game.h b/src/Game.h index 0946e10..b4dbcc5 100644 --- a/src/Game.h +++ b/src/Game.h @@ -22,6 +22,7 @@ #ifndef BLACKSHADES_GAME_H #define BLACKSHADES_GAME_H +#ifdef __cplusplus #include <GL/gl.h> #include <GL/glu.h> #include <stdlib.h> @@ -196,13 +197,21 @@ public: void HandleKeyDown(char theChar); void Tick(); void Splat(int k); - ~Game(); }; +#else // __cplusplus +typedef struct Game Game; +#endif // __cplusplus +#ifdef __cplusplus extern "C" { - void run(); +#endif // __cplusplus + Game* makeGame(); void initGl(Game*); void initGame(Game*); void eventLoop(Game*); -} + void closeGame(Game*); +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + #endif // BLACKSHADES_GAME_H diff --git a/src/GameInitDispose.cpp b/src/GameInitDispose.cpp index 9877f93..782cf6a 100644 --- a/src/GameInitDispose.cpp +++ b/src/GameInitDispose.cpp @@ -20,7 +20,7 @@ // You should have received a copy of the GNU General Public License // along with Black Shades. If not, see <https://www.gnu.org/licenses/>. -#include <AL/alut.h> +#include <AL/alc.h> #include "Textures.h" #include "Game.h" @@ -57,10 +57,14 @@ extern int aimkey; extern int psychicaimkey; extern int psychickey; +Game* makeGame() +{ + return new Game(); +} + void LoadSounds(bool musictoggle) { // generate ten OpenAL sample sets and two sources - alutInit(NULL, 0); alGenBuffers(37, gSampleSet); alGenSources(37, gSourceID); @@ -1903,13 +1907,13 @@ GLvoid Game::ReSizeGLScene(float fov, float near) glLoadIdentity(); } -Game::~Game() +void closeGame(Game* game) { const GLuint textures[] { - personspritetextureptr, - deadpersonspritetextureptr, - scopetextureptr, - flaretextureptr, + game->personspritetextureptr, + game->deadpersonspritetextureptr, + game->scopetextureptr, + game->flaretextureptr, }; glDeleteTextures(4, textures); alDeleteSources(100, gSourceID); // delete sound sources diff --git a/src/main.zig b/src/main.zig index 10f6b75..98e8d84 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,5 +1,47 @@ -extern fn run() void; +// Main function +// Copyright (C) 2021 Nguyễn Gia Phong +// +// This file is part of Black Shades. +// +// Black Shades is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Black Shades is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Black Shades. If not, see <https://www.gnu.org/licenses/>. + +const legacy = @cImport({ @cInclude("Game.h"); }); +const alc = @cImport({ @cInclude("AL/alc.h"); }); + +fn initAl() void { + // FIXME: check for errors + const device = alc.alcOpenDevice(null); + const context = alc.alcCreateContext(device, null); + _ = alc.alcMakeContextCurrent(context); +} + +fn closeAl() void { + const context = alc.alcGetCurrentContext().?; + const device = alc.alcGetContextsDevice(context); + + _ = alc.alcMakeContextCurrent(null); + alc.alcDestroyContext(context); + _ = alc.alcCloseDevice(device); +} pub fn main() void { - run(); + initAl(); + defer closeAl(); + + const game = legacy.makeGame(); + legacy.initGl(game); + legacy.initGame(game); + defer legacy.closeGame(game); + legacy.eventLoop(game); } |