Commit e67f92d4 authored by ottona's avatar ottona

added sounds and dispatcher wip working

parent e840fc25
......@@ -8,7 +8,7 @@ TEMPLATE = app
unix:INCLUDEPATH += /usr/include/irrlicht
win32:INCLUDEPATH += ../pharus/external/irrlicht
unix:LIBS += -lIrrlicht
unix:LIBS += -lIrrlicht -lcAudio
DESTDIR = ../bin
......@@ -16,11 +16,15 @@ HEADERS += \
../src/FlaSimApp.hpp \
../src/FireUnit.hpp \
../src/Globals.hpp \
../src/TurretCamAnimator.hpp
../src/TurretCamAnimator.hpp \
../src/Aircraft.hpp \
../src/Dispatcher.hpp
SOURCES += \
../src/FlaSimApp.cpp \
../src/main.cpp \
../src/FireUnit.cpp \
../src/Globals.cpp \
../src/TurretCamAnimator.cpp
../src/TurretCamAnimator.cpp \
../src/Aircraft.cpp \
../src/Dispatcher.cpp
No preview for this file type
# Blender MTL File: 'None'
# Blender MTL File: 'guns-scene.blend'
# Material Count: 1
newmtl None
Ns 0
Ka 0.000000 0.000000 0.000000
Kd 0.8 0.8 0.8
Ks 0.8 0.8 0.8
d 1
newmtl Material
Ns 150.980392
Ka 1.000000 1.000000 1.000000
Kd 0.032314 0.032314 0.032314
Ks 0.211098 0.211098 0.211098
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
This diff is collapsed.
#include "Aircraft.hpp"
#include <iostream>
#include "Globals.hpp"
using namespace irr;
using namespace irr::core;
Aircraft::Aircraft()
{
model = Globals::getSceneManager()->addMeshSceneNode(Globals::getSceneManager()->getMesh("../res/SU35S.obj"));
model->setPosition(vector3df(25.f, 0.f, 0.f));
a = Globals::getSceneManager()->createFlyStraightAnimator(vector3df(100.f, 100.f, -1000.f),
vector3df(100.f, 100.f, 1000.f),
32000,
false,
false);
model->addAnimator(a);
std::cout << "Aircraft" << std::endl;
}
Aircraft::~Aircraft()
{
Globals::getSceneManager()->addToDeletionQueue(model);
std::cout << "~Aircraft" << std::endl;
}
bool Aircraft::isGood() const
{
return healthy;
}
bool Aircraft::isTerminated() const
{
return a->hasFinished();
}
bool Aircraft::evalShot(const irr::core::line3df &shotline)
{
bool hit = model->getTransformedBoundingBox().intersectsWithLine(shotline);
if (hit)
{
if (healthy)
{
// got hit for the first time: do smokey?
auto pman = Globals::getSceneManager()->addParticleSystemSceneNode(true, model);
pman->getEmitter()->setDirection(vector3df(0.f, 0.f, 0.f));
}
healthy = false;
}
return hit;
}
#include <irrlicht.h>
class Aircraft
{
public:
Aircraft();
~Aircraft();
bool evalShot(const irr::core::line3df&);
bool isGood() const;
bool isTerminated() const;
private:
irr::scene::IMeshSceneNode *model;
irr::scene::ISceneNodeAnimator *a;
bool healthy;
};
#include "Dispatcher.hpp"
#include "Globals.hpp"
#include "Aircraft.hpp"
using namespace irr;
Dispatcher::Dispatcher()
: active(false)
{
}
Dispatcher::~Dispatcher()
{
aircrafts.clear();
}
void Dispatcher::start()
{
lastDispatchMS = Globals::getDevice()->getTimer()->getRealTime();
active = true;
}
void Dispatcher::execute()
{
u32 curTime = Globals::getDevice()->getTimer()->getRealTime();
if (active && (curTime - lastDispatchMS) > 10000)
{
auto a = std::make_shared<Aircraft>();
aircrafts.push_back(a);
lastDispatchMS = curTime;
}
//cleanup
auto a = aircrafts.begin();
while (a < aircrafts.end())
{
if ((*a)->isTerminated())
{
a = aircrafts.erase(a);
}
else
++a;
}
}
void Dispatcher::stop()
{
active = false;
}
const Dispatcher::Aircrafts &Dispatcher::getAircrafts() const
{
return aircrafts;
}
bool Dispatcher::evalShot(const core::line3df& l)
{
bool ret = false;
for (auto a : aircrafts)
{
if (a->evalShot(l))
{
ret = true;
}
}
return ret;
}
#include <vector>
#include <memory>
#include <irrlicht.h>
class Dispatcher
{
public:
typedef std::vector< std::shared_ptr<class Aircraft> > Aircrafts;
Dispatcher();
~Dispatcher();
void start();
void execute();
void stop();
const Aircrafts& getAircrafts() const;
bool evalShot(const irr::core::line3df&);
private:
irr::u32 lastDispatchMS;
Aircrafts aircrafts;
bool active;
};
#include "FireUnit.hpp"
#include <iostream>
#include <cAudio/cAudio.h>
#include "Globals.hpp"
#include "Dispatcher.hpp"
#include "TurretCamAnimator.hpp"
using namespace std;
using namespace irr;
using namespace irr::core;
FireUnit::FireUnit()
: aziTurnCoeffSmooth(0.f)
, elevTurnCoeffSmooth(0.f)
, flashCount(0)
, fireBtnPressed(false)
{
turretAzimuth = Globals::getSceneManager()->addEmptySceneNode();
turretElevation = Globals::getSceneManager()->addMeshSceneNode(Globals::getSceneManager()->getMesh("../res/guns.obj"), turretAzimuth);
......@@ -19,21 +26,21 @@ FireUnit::FireUnit()
cam->setFarValue(4000.f);
cam->addAnimator(turretCamAnimator);
auto jet = Globals::getSceneManager()->addMeshSceneNode(Globals::getSceneManager()->getMesh("../res/SU35S.obj"));
jet->setPosition(vector3df(25.f, 0.f, 0.f));
auto a = Globals::getSceneManager()->createFlyStraightAnimator(vector3df(100.f, 100.f, -1000.f),
vector3df(100.f, 100.f, 1000.f),
16000,
true,
false);
jet->addAnimator(a);
a->drop();
crosshair = Globals::getVideoDriver()->getTexture("../res/crosshair.png");
auto b = Globals::getSceneManager()->addBillboardSceneNode(turretElevation, dimension2df(1.f, 1.f), vector3df(.14f, 1.5f, 1.89f));
b->setMaterialTexture(0, Globals::getVideoDriver()->getTexture("../res/mflash.png"));
b->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
mflashR = Globals::getSceneManager()->addBillboardSceneNode(turretElevation, dimension2df(1.f, 1.f), vector3df(.14f, 1.5f, 1.89f));
mflashL = Globals::getSceneManager()->addBillboardSceneNode(turretElevation, dimension2df(1.f, 1.f), vector3df(-.14f, 1.5f, 1.89f));
mflashR->setMaterialTexture(0, Globals::getVideoDriver()->getTexture("../res/mflash.png"));
mflashR->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
mflashR->setMaterialFlag(video::EMF_LIGHTING, false);
mflashL->setMaterialTexture(0, Globals::getVideoDriver()->getTexture("../res/mflash.png"));
mflashL->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
mflashL->setMaterialFlag(video::EMF_LIGHTING, false);
mflashL->setVisible(false);
mflashR->setVisible(false);
fireSound = Globals::getAudioManager()->create("fireSound", "../res/gunburst.wav", false);
}
FireUnit::~FireUnit()
......@@ -60,13 +67,28 @@ bool FireUnit::OnEvent(const SEvent& e)
if (fabs(aziTurnCoeff) < DEAD_ZONE)
aziTurnCoeff = 0.f;
if (e.JoystickEvent.IsButtonPressed(1))
if (e.JoystickEvent.IsButtonPressed(0))
{
// fire trigger pressed
if (!fireBtnPressed)
{
shotline.start = cam->getAbsolutePosition();
shotline.end = cam->getTarget() - shotline.start;
shotline.end.normalize();
shotline.end *= 4000.f;
fireSound->play2d();
/*vector3df lineEnd = cam->getTarget();
lineEnd.normalize();
lineEnd += 4000.f;
shotline.end = shotline.start + lineEnd;*/
Globals::getDispatcher()->evalShot(shotline);
fireBtnPressed = true;
flashCount = 16;
}
}
else
{
// fire trigger released
fireBtnPressed = false;
}
if (e.JoystickEvent.IsButtonPressed(2))
......@@ -109,7 +131,33 @@ bool FireUnit::OnEvent(const SEvent& e)
void FireUnit::draw()
{
auto& res = Globals::getVideoDriver()->getScreenSize();
auto drv = Globals::getVideoDriver();
auto& res = drv->getScreenSize();
drv->draw2DImage(crosshair, position2di(res.Width / 2 - 128, res.Height / 2 - 128), recti(0, 0, 256, 256), nullptr, video::SColor(255,255,255,255), true );
video::SMaterial matA;
matA.AmbientColor = video::SColor(255, 255, 0, 0);
matA.DiffuseColor = video::SColor(255, 255, 0, 0);
matA.ColorMaterial = video::ECM_NONE;
matA.AntiAliasing = video::EAAM_FULL_BASIC;
matA.Lighting = false;
matA.Thickness = 1.5f;
matA.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
drv->setMaterial(matA);
if (flashCount > 0)
{
mflashL->setVisible(flashCount % 4 == 2);
mflashR->setVisible(flashCount % 4 == 0);
flashCount--;
}
else
{
mflashL->setVisible(false);
mflashR->setVisible(false);
}
Globals::getVideoDriver()->draw2DImage(crosshair, position2di(res.Width / 2 - 128, res.Height / 2 - 128), recti(0, 0, 256, 256), nullptr, video::SColor(255,255,255,255), true );
//drv->draw3DLine(shotline.start, shotline.end);
//cout << tgt.X << ' ' << tgt.Y << ' ' << tgt.Z << endl;
}
......@@ -3,6 +3,11 @@
#include <irrlicht.h>
namespace cAudio
{
class IAudioSource;
}
class FireUnit : public irr::IEventReceiver
{
public:
......@@ -18,6 +23,13 @@ private:
irr::scene::ISceneNodeAnimator *turretCamAnimator;
irr::f32 aziTurnCoeffSmooth, elevTurnCoeffSmooth;
irr::video::ITexture *crosshair;
irr::core::line3df shotline;
irr::scene::IBillboardSceneNode *mflashL, *mflashR;
irr::u32 flashCount;
bool fireBtnPressed;
class cAudio::IAudioSource* fireSound;
};
#endif // FIREUNIT_HPP
......@@ -3,6 +3,7 @@
#include <iostream>
#include "Globals.hpp"
#include "Dispatcher.hpp"
using namespace std;
using namespace irr;
......@@ -46,6 +47,7 @@ void FlaSimApp::execute()
{
while (dev->run())
{
Globals::getDispatcher()->execute();
drv->beginScene(true, true, SColor(255, 128, 128, 128));
sman->drawAll();
drawScreenSpace();
......@@ -56,6 +58,24 @@ void FlaSimApp::execute()
bool FlaSimApp::OnEvent(const irr::SEvent &e)
{
if (e.EventType == EET_KEY_INPUT_EVENT)
{
if (e.KeyInput.Key == KEY_F12)
{
dev->closeDevice();
return true;
}
if (e.KeyInput.Key == KEY_F9)
{
Globals::getDispatcher()->start();
return true;
}
if (e.KeyInput.Key == KEY_F10)
{
Globals::getDispatcher()->stop();
return true;
}
}
return fireUnit.OnEvent(e);
}
......
#include "Globals.hpp"
#include "Dispatcher.hpp"
#include <irrlicht.h>
#include <cAudio/cAudio.h>
using namespace irr;
......@@ -11,11 +13,14 @@ Globals::Globals()
dev = createDevice(video::EDT_OPENGL, core::dimension2du(1280, 800), 32, false, false, true);
drv = dev->getVideoDriver();
sman = dev->getSceneManager();
dispatcher = new Dispatcher();
audioManager = cAudio::createAudioManager(true);
}
Globals::~Globals()
{
dev->drop();
audioManager->shutDown();
instance = nullptr;
}
......@@ -48,3 +53,19 @@ scene::ISceneManager* Globals::getSceneManager()
return instance->sman;
}
cAudio::IAudioManager* Globals::getAudioManager()
{
if (!instance)
instance = new Globals();
return instance->audioManager;
}
Dispatcher* Globals::getDispatcher()
{
if (!instance)
instance = new Globals();
return instance->dispatcher;
}
#ifndef GLOBALS_HPP
#define GLOBALS_HPP
namespace cAudio
{
class IAudioManager;
}
namespace irr
{
class IrrlichtDevice;
......@@ -22,6 +27,8 @@ public:
static class irr::IrrlichtDevice* getDevice();
static class irr::scene::ISceneManager* getSceneManager();
static class irr::video::IVideoDriver* getVideoDriver();
static cAudio::IAudioManager* getAudioManager();
static class Dispatcher* getDispatcher();
static void shutdown();
......@@ -33,5 +40,7 @@ private:
class irr::IrrlichtDevice* dev;
class irr::scene::ISceneManager* sman;
class irr::video::IVideoDriver* drv;
class cAudio::IAudioManager *audioManager;
class Dispatcher *dispatcher;
};
#endif // GLOBALS_HPP
#include "FlaSimApp.hpp"
#include "Globals.hpp"
int main()
{
FlaSimApp a;
a.execute();
FlaSimApp *a = new FlaSimApp();
a->execute();
delete a;
Globals::shutdown();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment