Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BulletEngine #579

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
7dde0f5
added bulletengine-skeleton
Apr 5, 2014
84fe57d
intermediate
Apr 5, 2014
fd9e8c7
stripped projectile of WorldObject inheritance
Apr 5, 2014
04cdfaa
Merge branch 'master' of github.com:voxelinc/voxellancer into bullete…
Apr 5, 2014
0eba1e9
move Bullet::passiveForCollisionDetection to WorldObjectBullet
Apr 5, 2014
5d6da02
mv genericbullet.* -> genericworldobjectbullet.*
Apr 5, 2014
39856fb
WorldObjectBuilder -> WorldElementBuilder
Apr 5, 2014
32feb48
Make WorldElementBuilder decide based on .ini whether a bullet is ins…
Apr 5, 2014
d559196
intermediate
Apr 5, 2014
b351273
Established skeleton pipeline for rendering InstancedBullets via Inst…
Apr 5, 2014
03ef757
intermediate
Apr 5, 2014
c97abd7
intermediate
Apr 6, 2014
9f24f02
intermediate
Apr 6, 2014
e521280
intermediate on bulletengine
Apr 6, 2014
830a586
something related to bulletengine
Apr 6, 2014
1008a70
merge with master
Apr 8, 2014
9275ac1
implemented instancedbullet
Apr 8, 2014
d453d67
continue bulletengine
Apr 9, 2014
7c78172
merge with origin
Apr 9, 2014
671d34a
intermediate
Apr 10, 2014
0436069
initial somehow working version of bulletengine
Apr 10, 2014
5fe8c51
Merge branch 'handle_improvements' of github.com:voxelinc/voxellancer…
Apr 10, 2014
0c58138
bulletengine working without collision and continuous rotation
Apr 10, 2014
fd860a2
Merge branch 'worldtreenoderef' of github.com:voxelinc/voxellancer in…
Apr 10, 2014
57b2e2e
bulletengine continues
Apr 10, 2014
2775f4b
bulletengine improvements
Apr 11, 2014
75a7a90
continue bulletengine
Apr 11, 2014
cb7746d
BulletEngine: Better removal strategy of InstancedBullets
Apr 11, 2014
bf2e214
continue bulletengine
Apr 11, 2014
adf8449
Fixed crah on contextreplace
Apr 11, 2014
dc572e8
enable hitSound and emissiveness on instancedbullets
Apr 12, 2014
bfd7c96
add docu to bulletengine/
Apr 12, 2014
5f68045
merge with master
Apr 13, 2014
7293f7d
fix Windows compile
gersseba Apr 17, 2014
203ea81
compiling again
Apr 19, 2014
f5d9bdf
add drawable
Apr 19, 2014
a4f1bc4
Merge branch 'bulletengine' of github.com:voxelinc/voxellancer into b…
Apr 19, 2014
22c3c10
trying to fix it
Apr 19, 2014
68f8e14
bulletengine working again. glowsquad, you better not cross my path t…
Apr 19, 2014
6a41261
remove drawable again
Apr 19, 2014
1639a8a
merge with master
May 11, 2014
eeaf6a9
Splitrockets also split if target is dead; Bullet::extent
May 11, 2014
832d9eb
remove outcommented logging
May 11, 2014
5a250cf
replaced voxelparticleengine::time with UWT ;)
May 18, 2014
b5e6552
merge with master
May 31, 2014
825025a
Renamed WorldElementBuilder to VoxelObjectBuilder
May 31, 2014
68ac315
merge with master
Jun 6, 2014
eb070fd
add virtual to VoxelParticleEngine-destructor decl.
Jun 8, 2014
472f591
Merge branch 'master' of github.com:voxelinc/voxellancer into bullete…
Aug 18, 2014
bb21df7
fixed indentation in src/geometry/line.inl
Aug 18, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion data/equipment/projectiles/gunbullet.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[general]
type=bullet
voxelcluster=gunbullet.csv
instanced=true
lifetime=1.5
speed=350.0
spinning=10.0
Expand All @@ -9,4 +10,4 @@ emissiveness=0.4
collisionFieldOfDamage=7.2

[hitsound]
name=data/sound/hit2.ogg
name=data/sound/hit2.ogg
3 changes: 2 additions & 1 deletion data/equipment/projectiles/hornet.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[general]
type=rocket
voxelcluster=hornet.csv
instanced=false
lifetime=60
scale=0.5
collisionFieldOfDamage=inf
Expand All @@ -11,4 +12,4 @@ direction=0.0,0.0,1.0

[explosionsound]
name=data/sound/102733__sarge4267__explosion3.ogg
attenuation=0.3
attenuation=0.3
3 changes: 2 additions & 1 deletion data/equipment/projectiles/ionbullet.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[general]
type=bullet
voxelcluster=ionbullet.csv
instanced=true
lifetime=10
speed=1000.0
spinning=1000.0
Expand All @@ -9,4 +10,4 @@ emissiveness=1.0
collisionFieldOfDamage=inf

[hitsound]
name=data/sound/hit2.ogg
name=data/sound/hit2.ogg
3 changes: 2 additions & 1 deletion data/equipment/projectiles/pulselaser_bullet.ini
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[general]
type=bullet
instanced=true
voxelcluster=pulselaser_bullet.csv
lifetime=1
speed=500.0
spinning=0.0
scale=0.4
emissiveness=0.4
emissiveness=40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afaik emissiveness should be 0.0 - 1.0, has something changed?

collisionFieldOfDamage=7.2

[hitsound]
Expand Down
3 changes: 2 additions & 1 deletion data/equipment/projectiles/railgunbullet.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[general]
type=bullet
voxelcluster=railgunbullet.csv
instanced=true
lifetime=1.5
speed=350.0
spinning=10.0
Expand All @@ -10,4 +11,4 @@ collisionFieldOfDamage=7.2

[hitsound]
name=data/sound/hit2.ogg
volume=0.5
volume=0.5
1 change: 1 addition & 0 deletions data/equipment/projectiles/snowball.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[general]
type=bullet
voxelcluster=snowball.csv
instanced=true
lifetime=2
speed=100.0
spinning=10.0
Expand Down
31 changes: 31 additions & 0 deletions data/shader/bulletengine/bullet.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#version 330

uniform float time;
uniform float withBorder;

layout(location = 0) out vec4 fragColor;
layout(location = 1) out vec4 normalz;
layout(location = 2) out vec4 emissiveness;

in vec4 f_color;
flat in vec3 f_normal;
in float f_emissiveness;
in vec3 f_modelposition;
flat in float f_active;
flat in float f_deathTime;

vec4 voxelFragmentColor(vec3 color, float emissiveness, vec3 normal, vec3 positionInVoxel);
vec4 voxelFragmentEmissiveness(vec3 color, float emissiveness);
vec4 voxelFragmenNormalZ(vec3 normal);


void main() {
if (f_active < 0.5 || f_deathTime <= time) {
discard;
}

fragColor = voxelFragmentColor(f_color.xyz, f_emissiveness, f_normal, f_modelposition);
emissiveness = voxelFragmentEmissiveness(f_color.xyz, f_emissiveness);
normalz = voxelFragmenNormalZ(f_normal);
}

57 changes: 57 additions & 0 deletions data/shader/bulletengine/bullet.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#version 330

// Input
layout(location = 0) in vec3 v_vertex;
layout(location = 1) in vec3 v_normal;

layout(location = 2) in vec3 v_gridCell;
layout(location = 3) in vec4 v_color;
layout(location = 4) in float v_emissiveness;

layout(location = 5) in vec3 v_originPosition;
layout(location = 6) in vec3 v_originEulers;
layout(location = 7) in vec3 v_directionalSpeed;
layout(location = 8) in vec3 v_angularSpeed;
layout(location = 9) in vec3 v_center;
layout(location = 10) in float v_originTime;
layout(location = 11) in float v_deathTime;
layout(location = 12) in float v_active;


// Output
out vec4 f_color;
flat out vec3 f_normal;
out float f_emissiveness;
out vec3 f_modelposition;
flat out float f_active;
flat out float f_deathTime;

// Uniforms
uniform mat4 viewProjection;
uniform float time;
uniform float scale;
uniform float emissiveness;


vec3 qtransform(vec4 q, vec3 v);
vec4 quat(vec3 euler);

void main() {
f_active = v_active;
f_deathTime = v_deathTime;

float deltaTime = time - v_originTime;

f_color = v_color;
f_normal = v_normal;
f_emissiveness = clamp(emissiveness + v_emissiveness, 0, 1);
f_modelposition = v_vertex;

vec3 bulletEulers = v_originEulers + v_angularSpeed * deltaTime * 0.01;
vec4 bulletOrientation = quat(bulletEulers);

vec3 bulletPosition = v_originPosition + v_directionalSpeed * deltaTime;

gl_Position = viewProjection * vec4(qtransform(bulletOrientation, v_vertex + v_gridCell - v_center) * scale + bulletPosition, 1.0f);
}

2 changes: 1 addition & 1 deletion data/worldobjects/banner.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[general]
type=worldobject
type=other
voxelcluster=banner.csv
2 changes: 1 addition & 1 deletion data/worldobjects/cake.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[general]
type=worldobject
type=other
voxelcluster=cake.csv
scale=3

Expand Down
2 changes: 1 addition & 1 deletion data/worldobjects/idareyou.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[general]
type=worldobject
type=other
voxelcluster=idareyou.csv
2 changes: 1 addition & 1 deletion data/worldobjects/missionstart.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[general]
type=worldobject
type=other
voxelcluster=missionstart.csv
2 changes: 1 addition & 1 deletion src/ai/basictasks/directsuicidetask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void DirectSuicideTask::update(float deltaSec) {
WorldObject* worldObject = boardComputer()->worldObject();

if (m_target.valid()) {
glm::vec3 targetPoint = m_target->physics().projectedTransformIn(0.1f).position();
glm::vec3 targetPoint = m_target->physics().speed().moved(m_target->transform(), 0.1f).position();
boardComputer()->rotateTo(targetPoint);
glm::vec3 targetDirection = glm::inverse(worldObject->transform().orientation()) * (targetPoint - worldObject->transform().position());
float angle = GeometryHelper::angleBetween(glm::vec3(0, 0, -1), targetDirection);
Expand Down
4 changes: 2 additions & 2 deletions src/ai/boardcomputer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const EngineState& BoardComputer::engineState() const {
}

void BoardComputer::moveTo(const glm::vec3& position, bool decelerate) {
glm::vec3 projectedPosition = m_worldObject->physics().projectedTransformIn(1.0f).position();
glm::vec3 projectedPosition = m_worldObject->physics().speed().moved(m_worldObject->transform(), 1.0f).position();
glm::vec3 delta = position - projectedPosition;
float distance = glm::length(delta);

Expand Down Expand Up @@ -68,7 +68,7 @@ void BoardComputer::rotateTo(const glm::vec3& position, const glm::vec3& up) {
glm::vec3 accumulatedEuler;

// A guess (hack) where the WorldObject will point to in one second, in the local coordinate-sys
glm::quat projectedOrientation = glm::inverse(m_worldObject->transform().orientation()) * m_worldObject->physics().projectedTransformIn(0.1f).orientation();
glm::quat projectedOrientation = glm::inverse(m_worldObject->transform().orientation()) * m_worldObject->physics().speed().moved(m_worldObject->transform(), 0.1f).orientation();
glm::vec3 projectedDirection = projectedOrientation * glm::vec3(0, 0, -1);

// Direction to the target, in the local coordinate-sys
Expand Down
63 changes: 63 additions & 0 deletions src/bulletengine/bulletengine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "bulletengine.h"

#include <iostream>

#include "equipment/weapons/worldobjectbullet.h"

#include "bulletenginerenderer.h"
#include "instancedbullet.h"
#include "instancedbulletcontainer.h"
#include "instancedbulletcontainerrenderer.h"


BulletEngine::BulletEngine():
m_renderer(new BulletEngineRenderer())
{
}

BulletEngine::~BulletEngine() = default;

BulletEngineRenderer& BulletEngine::renderer() {
return *m_renderer;
}

void BulletEngine::add(InstancedBullet* bullet) {
container(bullet->name())->add(bullet);
m_bullets.insert(std::unique_ptr<InstancedBullet>(bullet));
}

InstancedBulletContainer* BulletEngine::container(const std::string& name) {
auto iter = m_containers.find(name);
if (iter == m_containers.end()) {
iter = m_containers.emplace(name, std::unique_ptr<InstancedBulletContainer>(new InstancedBulletContainer(*this, name))).first;
m_renderer->add(iter->second.get());
}
return iter->second.get();
}

InstancedBullet* BulletEngine::createBullet(const std::string& name) {
return new InstancedBullet(container(name)->handle<InstancedBulletContainer>(), name);
}

void BulletEngine::update(float deltaSec) {
for (auto iter = m_bullets.begin(); iter != m_bullets.end();) {
InstancedBullet* bullet = iter->get();

bullet->update(deltaSec);
if (bullet->alive()) {
++iter;
} else {
bullet->container()->remove(bullet);
iter = m_bullets.erase(iter);
}
}

for (auto& pair : m_containers) {
pair.second->update(deltaSec);
}
}

void BulletEngine::draw(const Camera& camera) {
m_renderer->draw(camera);
}

48 changes: 48 additions & 0 deletions src/bulletengine/bulletengine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once

#include <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>


class BulletEngineRenderer;
class Camera;
class InstancedBullet;
class InstancedBulletContainer;

/**
* Responsible for much more performant handling of bullets instead of simulating them
* like full WorldObjects
* Holds the InstancedBullets of a World and their respective InstancedBulletContainers
*/
class BulletEngine {
public:
BulletEngine();
~BulletEngine();

BulletEngineRenderer& renderer();

void add(InstancedBullet* bullet);

/**
* Retrieve or create the InstancedBulletContainer of the given name
*/
InstancedBulletContainer* container(const std::string& name);

/**
* Create the InstancedBullet with the given name and connect it with its
* respective InstancedBulletContainer
*/
InstancedBullet* createBullet(const std::string& name);

void update(float deltaSec);
void draw(const Camera& camera);


protected:
std::unordered_map<std::string, std::unique_ptr<InstancedBulletContainer>> m_containers;
std::unordered_set<std::unique_ptr<InstancedBullet>> m_bullets;
std::unique_ptr<BulletEngineRenderer> m_renderer;
};

Loading