From 6a85967ffff5c6e4bf42ba3e3d72f41b72e496c0 Mon Sep 17 00:00:00 2001 From: Otto Naderer Date: Thu, 5 Aug 2021 16:00:19 +0200 Subject: [PATCH] cAudio now submodule, some minifixes, updated readme --- .gitmodules | 3 +++ README.md | 18 +++++++++++++++--- ext/cAudio | 1 + prj/flasim.pro | 5 +++-- src/Aircraft.cpp | 2 +- src/Dispatcher.cpp | 4 ++-- src/Dispatcher.hpp | 2 +- src/FireUnit.cpp | 2 +- src/FlaSimApp.cpp | 22 +++++++++++++++++++++- src/FlaSimApp.hpp | 1 + src/Globals.cpp | 2 +- 11 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 .gitmodules create mode 160000 ext/cAudio diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..3bbb231 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "ext/cAudio"] + path = ext/cAudio + url = https://github.com/R4stl1n/cAudio.git diff --git a/README.md b/README.md index 2d3cb1a..163ec10 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # flasim -FlaSim is a mini game I did as a birthday party gag. It lets you manually control an anti-aircraft cannon with your joystick. Five jets are then randomly spawned (one after the other) as targets to be engaged by the player. +FlaSim is a mini game I did as a birthday party gag. It lets you manually control an anti-aircraft cannon with your joystick. Five jets are then randomly spawned (one after the other) as targets to be engaged by the player. There is a [blog post](https://polylux.eu/blog/4/) about the implementation aspects of the game. ## Controls @@ -15,7 +15,19 @@ About the visual content shown in the game: I did some parts myself (cannon mode ## Building flasim Currently only Linux works, should have a windows buildability in a couple of days. -The game is written in QtCreator and hence uses the qmake build system. You should have gcc, qmake, irrlicht and cAudio installed and handy. -cd to the 'prj' folder and run qmake to get a Makefile out of flasim.pro. Build the game using 'make'. Done. +The game is written in QtCreator and hence uses the qmake build system. You should have gcc, qmake, irrlicht and OpenAL installed and handy. + +### Prerequirements + +1. Fetch the submodules. +1. `cd` into `ext/cAudio` and issue `cmake -DCAUDIO_BUILD_EAX_PLUGIN=ON -DCAUDIO_BUILD_MP3DECODER_PLUGIN=OFF -DCAUDIO_ENABLE_OGG=OFF -DCAUDIO_BUILD_SAMPLES=OFF -DCAUDIO_DEPENDENCIES_DIR=Dependencies64 -DCAUDIO_STATIC=ON` +1. `make` cAudio + +### Build flasim + +`cd` to the `prj` folder and run qmake to get a Makefile out of `flasim.pro`. Build the game using `make`. Done. Questions? Reach me at otto@socialnerds.org + + + diff --git a/ext/cAudio b/ext/cAudio new file mode 160000 index 0000000..ce5d039 --- /dev/null +++ b/ext/cAudio @@ -0,0 +1 @@ +Subproject commit ce5d03905a01c89c8d64dea9c3aa1cf63647d794 diff --git a/prj/flasim.pro b/prj/flasim.pro index 4791ada..4d45bc0 100644 --- a/prj/flasim.pro +++ b/prj/flasim.pro @@ -6,9 +6,10 @@ Debug:TARGET = flasimD TEMPLATE = app unix:INCLUDEPATH += /usr/include/irrlicht -win32:INCLUDEPATH += ../pharus/external/irrlicht +INCLUDEPATH += ../ext/cAudio/cAudio/include ../ext/cAudio/include -unix:LIBS += -lIrrlicht -lcAudio +unix:LIBS += -L../ext/cAudio/cAudio +unix:LIBS += -lIrrlicht -lopenal -lcAudio DESTDIR = ../bin diff --git a/src/Aircraft.cpp b/src/Aircraft.cpp index da56105..fcccba5 100644 --- a/src/Aircraft.cpp +++ b/src/Aircraft.cpp @@ -1,7 +1,7 @@ #include "Aircraft.hpp" #include -#include +#include #include "Globals.hpp" diff --git a/src/Dispatcher.cpp b/src/Dispatcher.cpp index b114da4..b5d89f4 100644 --- a/src/Dispatcher.cpp +++ b/src/Dispatcher.cpp @@ -72,7 +72,7 @@ const Dispatcher::Aircrafts &Dispatcher::getAircrafts() const bool Dispatcher::evalShot(const core::line3df& l) { bool ret = false; - for (auto a : aircrafts) + for (auto& a : aircrafts) { if (a->isGood() && a->evalShot(l)) { @@ -112,5 +112,5 @@ void Dispatcher::dispatchAircraft() line3df l; l.start = vector3df(start.X, alt, start.Y); l.end = vector3df(end.X, alt, end.Y); - aircrafts.push_back(std::make_shared(l, 30000 + static_cast(rand->frand() * 15000.f))); + aircrafts.push_back(std::make_unique(l, 30000 + static_cast(rand->frand() * 15000.f))); } diff --git a/src/Dispatcher.hpp b/src/Dispatcher.hpp index d7691cf..1751bc0 100644 --- a/src/Dispatcher.hpp +++ b/src/Dispatcher.hpp @@ -7,7 +7,7 @@ class Dispatcher { public: - typedef std::vector< std::shared_ptr > Aircrafts; + typedef std::vector< std::unique_ptr > Aircrafts; Dispatcher(); ~Dispatcher(); diff --git a/src/FireUnit.cpp b/src/FireUnit.cpp index 5c50f97..083a427 100644 --- a/src/FireUnit.cpp +++ b/src/FireUnit.cpp @@ -1,7 +1,7 @@ #include "FireUnit.hpp" #include -#include +#include #include "Globals.hpp" #include "Dispatcher.hpp" diff --git a/src/FlaSimApp.cpp b/src/FlaSimApp.cpp index e8c61a8..ba7b7e6 100644 --- a/src/FlaSimApp.cpp +++ b/src/FlaSimApp.cpp @@ -64,7 +64,7 @@ void FlaSimApp::execute() bool FlaSimApp::OnEvent(const irr::SEvent &e) { - if (e.EventType == EET_KEY_INPUT_EVENT) + if (e.EventType == EET_KEY_INPUT_EVENT && e.KeyInput.PressedDown) { if (e.KeyInput.Key == KEY_F12) { @@ -81,7 +81,14 @@ bool FlaSimApp::OnEvent(const irr::SEvent &e) Globals::getDispatcher()->stop(); return true; } + if (e.KeyInput.Key == KEY_KEY_T) + { + saveScreenshot(); + return true; + } } + + // if we reach here, relay event to the fireunit return fireUnit.OnEvent(e); } @@ -112,3 +119,16 @@ void FlaSimApp::drawScreenSpace() info += L"\nPOINTS: "; info += Globals::getDispatcher()->getPoints(); Globals::getFont()->draw(info, core::recti(10, 10, 100, 100), video::SColor(255, 255, 255, 255)); } + +void FlaSimApp::saveScreenshot() +{ + video::IImage* scrn = nullptr; + core::stringc fname = ""; + fname += dev->getTimer()->getRealTime(); + io::path filename = fname.c_str(); + filename += ".png"; + + scrn = drv->createScreenShot(); + drv->writeImageToFile(scrn, filename); + scrn->drop(); +} diff --git a/src/FlaSimApp.hpp b/src/FlaSimApp.hpp index 8bd433f..3beaa69 100644 --- a/src/FlaSimApp.hpp +++ b/src/FlaSimApp.hpp @@ -13,6 +13,7 @@ public: private: void drawScreenSpace(); + void saveScreenshot(); irr::IrrlichtDevice *dev; irr::scene::ISceneManager *sman; diff --git a/src/Globals.cpp b/src/Globals.cpp index 099b5cc..122936c 100644 --- a/src/Globals.cpp +++ b/src/Globals.cpp @@ -2,7 +2,7 @@ #include "Dispatcher.hpp" #include -#include +#include using namespace irr;