Skip to content

Commit

Permalink
Merge branch 'master' into dialog-camera
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterwolfAT committed Jun 24, 2018
2 parents 19cb4af + 778a5cf commit bdbc03c
Show file tree
Hide file tree
Showing 14 changed files with 318 additions and 62 deletions.
Binary file modified content/shaders/essl/fs_particle_textured.bin
Binary file not shown.
6 changes: 1 addition & 5 deletions content/shaders/essl/fs_particle_textured.bin.disasm
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ varying highp vec4 v_color;
varying highp vec2 v_texcoord0;
varying highp vec3 v_view_pos;
uniform sampler2D s_texColor;
uniform highp vec4 u_FogColor;
uniform highp vec4 u_FogNearFar;
void main ()
{
lowp vec4 color_1;
lowp vec4 tmpvar_2;
tmpvar_2 = (texture2D (s_texColor, v_texcoord0) * v_color);
color_1.w = tmpvar_2.w;
color_1.xyz = mix (tmpvar_2.xyz, u_FogColor.xyz, clamp ((
color_1 = ((texture2D (s_texColor, v_texcoord0) * v_color) * clamp ((
(sqrt(dot (v_view_pos, v_view_pos)) - u_FogNearFar.x)
/
(u_FogNearFar.y - u_FogNearFar.x)
Expand Down
Binary file modified content/shaders/glsl/fs_particle_textured.bin
Binary file not shown.
14 changes: 3 additions & 11 deletions content/shaders/glsl/fs_particle_textured.bin.disasm
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,11 @@ varying vec4 v_color;
varying vec2 v_texcoord0;
varying vec3 v_view_pos;
uniform sampler2D s_texColor;
uniform vec4 u_FogColor;
uniform vec4 u_FogNearFar;
void main ()
{
vec4 color_1;
vec4 tmpvar_2;
tmpvar_2 = (texture2D (s_texColor, v_texcoord0) * v_color);
color_1.w = tmpvar_2.w;
color_1.xyz = mix (tmpvar_2.xyz, u_FogColor.xyz, clamp ((
(sqrt(dot (v_view_pos, v_view_pos)) - u_FogNearFar.x)
/
(u_FogNearFar.y - u_FogNearFar.x)
), 0.0, 1.0));
gl_FragColor = color_1;
gl_FragColor = ((texture2D (s_texColor, v_texcoord0) * v_color) * (1.0 - clamp (
((sqrt(dot (v_view_pos, v_view_pos)) - u_FogNearFar.x) / (u_FogNearFar.y - u_FogNearFar.x))
, 0.0, 1.0)));
}

18 changes: 18 additions & 0 deletions src/logic/scriptExternals/Externals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include <engine/GameEngine.h>
#include <logic/PlayerController.h>
#include <logic/visuals/ModelVisual.h>
#include <ui/Hud.h>
#include <ui/PrintScreenMessages.h>
#include <ui/IntroduceChapterView.h>
#include <utils/logger.h>
#include <logic/ScriptEngine.h>
#include <logic/DialogManager.h>
Expand Down Expand Up @@ -1503,4 +1505,20 @@ void ::Logic::ScriptExternals::registerEngineExternals(World::WorldInstance& wor
npc.playerController->drawWeaponMelee(true);
}
});

vm->registerExternalFunction("introducechapter", [=](Daedalus::DaedalusVM& vm) {

double waittime = vm.popDataValue();
std::string sound = vm.popString();
std::string texture = vm.popString();
std::string subtitle = vm.popString();
std::string title = vm.popString();

LogInfo() << "Queued up chapter introduction " << title;

engine->getJobManager().executeInMainThread<void>([=](Engine::BaseEngine* pEngine) {
engine->getHud().getIntroduceChapterView().enqueueChapterIntroduction(title, subtitle, texture, sound, waittime);
});

});
}
28 changes: 6 additions & 22 deletions src/logic/scriptExternals/Stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1932,32 +1932,16 @@ void ::Logic::ScriptExternals::registerStubs(Daedalus::DaedalusVM& vm, bool verb

vm.registerExternalFunction("introducechapter", [=](Daedalus::DaedalusVM& vm) {
if (verbose) LogInfo() << "introducechapter";
int i4 = vm.popDataValue();
if (verbose) LogInfo() << "i4: " << i4;
std::string s3 = vm.popString();
if (verbose) LogInfo() << "s3: " << s3;
std::string s2 = vm.popString();
if (verbose) LogInfo() << "s2: " << s2;
std::string s1 = vm.popString();
if (verbose) LogInfo() << "s1: " << s1;
std::string s0 = vm.popString();
if (verbose) LogInfo() << "s0: " << s0;

});

vm.registerExternalFunction("introducechapter", [=](Daedalus::DaedalusVM& vm) {
if (verbose) LogInfo() << "introducechapter";
int waittime = vm.popDataValue();
double waittime = vm.popDataValue();
if (verbose) LogInfo() << "waittime: " << waittime;
std::string sound = vm.popString();
if (verbose) LogInfo() << "sound: " << sound;
std::string texture = vm.popString();
if (verbose) LogInfo() << "texture: " << texture;
std::string untertitel = vm.popString();
if (verbose) LogInfo() << "untertitel: " << untertitel;
std::string titel = vm.popString();
if (verbose) LogInfo() << "titel: " << titel;

std::string subtitle = vm.popString();
if (verbose) LogInfo() << "subtitle: " << subtitle;
std::string title = vm.popString();
if (verbose) LogInfo() << "title: " << title;
});

vm.registerExternalFunction("log_addentry", [=](Daedalus::DaedalusVM& vm) {
Expand Down Expand Up @@ -2729,4 +2713,4 @@ void ::Logic::ScriptExternals::registerStubs(Daedalus::DaedalusVM& vm, bool verb
if (verbose) LogInfo() << "s0: " << s0;

});
}
}
37 changes: 18 additions & 19 deletions src/logic/visuals/PfxVisual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool Logic::PfxVisual::load(const std::string& visual)

// Need that one. Or should give a default value of 1?
//assert(!m_Emitter.ppsScaleKeys.empty());
if(m_Emitter.ppsScaleKeys.empty())
if (m_Emitter.ppsScaleKeys.empty())
m_Emitter.ppsScaleKeys.push_back(1.0f);

// Init particle-systems dynamic vertex-buffer
Expand Down Expand Up @@ -102,7 +102,7 @@ Components::PfxComponent& Logic::PfxVisual::getPfxComponent()

void Logic::PfxVisual::onUpdate(float deltaTime)
{
Components::PfxComponent &pfx = getPfxComponent();
Components::PfxComponent& pfx = getPfxComponent();
Controller::onUpdate(deltaTime);

// Spawn new particles. Need to accumulate deltaTime so the floor doesn't keep us from spawning any particles
Expand All @@ -115,15 +115,15 @@ void Logic::PfxVisual::onUpdate(float deltaTime)

// Loop ppsScaleKeys if wanted
if (Math::ifloor(m_ppsScaleKey) >= static_cast<int>(m_Emitter.ppsScaleKeys.size()))
{ //&& !m_Emitter.ppsIsLooping) {
{ //&& !m_Emitter.ppsIsLooping) {
m_ppsScaleKey = 0.0f;
if (!m_Emitter.ppsIsLooping)
{
m_dead = true;
}
}
if (Math::ifloor(m_shpScaleKey) >= static_cast<int>(m_Emitter.shpScaleKeys.size()))
{ //&& !m_Emitter.shpScaleIsLooping){
{ //&& !m_Emitter.shpScaleIsLooping){
m_shpScaleKey = 0.0f;
if (!m_Emitter.shpScaleIsLooping)
{
Expand Down Expand Up @@ -152,27 +152,27 @@ void Logic::PfxVisual::onUpdate(float deltaTime)
m_BBox.max = {-FLT_MAX, -FLT_MAX, -FLT_MAX};

// Update particle values
for (Components::PfxComponent::Particle &p : pfx.m_Particles)
for (Components::PfxComponent::Particle& p : pfx.m_Particles)
updateParticle(p, deltaTime);

//Notice that iterator is not incremented in for loop
for (size_t i = 0; i < pfx.m_Particles.size(); )
for (size_t i = 0; i < pfx.m_Particles.size();)
{
auto p = pfx.m_Particles.at(i);
auto& particle = pfx.m_Particles[i];

if (p.lifetime <= 0)
if (particle.lifetime <= 0)
{
// Kill particle. Move the last one into the free slot and reduce the vector size
// to keep the memory continuous
pfx.m_Particles[i] = pfx.m_Particles.back();
// Efficient erasing: Copy the last particle into the free slot and remove it
particle = pfx.m_Particles.back();
pfx.m_Particles.pop_back();
// No need to increase iterator, since we have a new particle in this slot now
}else
// No need to increase the index, since we have a new particle in this slot now
}
else
{
++i;
}
}
if(pfx.m_Particles.size() == 0 && m_dead)
if (pfx.m_Particles.size() == 0 && m_dead)
{
m_canBeRemoved = true;
}
Expand Down Expand Up @@ -316,17 +316,16 @@ void Logic::PfxVisual::updateParticle(Components::PfxComponent::Particle& p, flo
p.size += p.sizeVel * deltaTime;
p.alpha += p.alphaVel * deltaTime;


float alphaFinal;

if(m_Emitter.visSoftAlpha)
if (m_Emitter.visSoftAlpha)
{
float alphaRatio = (p.alpha - m_Emitter.visAlphaStart) / (m_Emitter.visAlphaEnd - m_Emitter.visAlphaStart);
alphaFinal = Math::sinusSmooth(alphaRatio) * p.alpha;
float alphaRatio = (p.alpha - m_Emitter.visAlphaStart) / (m_Emitter.visAlphaEnd - m_Emitter.visAlphaStart);
alphaFinal = Math::sinusSmooth(alphaRatio) * p.alpha;
}
else
{
alphaFinal = p.alpha;
alphaFinal = p.alpha;
}

// Compute actual color for this frame
Expand Down
41 changes: 39 additions & 2 deletions src/math/mathlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/norm.hpp>
#include <ZenLib/utils/mathlib.h>

namespace Math
{
Expand Down Expand Up @@ -105,6 +106,16 @@ namespace Math
this->x = x;
this->y = y;
}
t_float2(const ZMath::float2& v)
{
this->x = v.x;
this->y = v.y;
}
t_float2(float v)
{
this->x = v;
this->y = v;
}

union {
struct
Expand Down Expand Up @@ -139,6 +150,18 @@ namespace Math
this->y = y;
this->z = z;
}
t_float3(const ZMath::float3& v)
{
this->x = v.x;
this->y = v.y;
this->z = v.z;
}
t_float3(float v)
{
this->x = v;
this->y = v;
this->z = v;
}

union {
struct
Expand Down Expand Up @@ -175,6 +198,20 @@ namespace Math
this->z = z;
this->w = w;
}
t_float4(const ZMath::float4& v)
{
this->x = v.x;
this->y = v.y;
this->z = v.z;
this->w = v.w;
}
t_float4(float v)
{
this->x = v;
this->y = v;
this->z = v;
this->w = w;
}

union {
struct
Expand Down Expand Up @@ -289,7 +326,7 @@ namespace Math
t_vector() {}
t_vector(const void* v)
{
memcpy(this, v, sizeof(T));
memcpy(T::v, v, sizeof(T));
}

t_vector(const T& v)
Expand Down Expand Up @@ -470,7 +507,7 @@ namespace Math
// Assignment operators
Matrix& operator=(const Matrix& M)
{
memcpy(this, &M, sizeof(float) * 16);
memcpy(m, &M, sizeof(mv));
return *this;
}
Matrix& operator+=(const Matrix& M)
Expand Down
3 changes: 2 additions & 1 deletion src/shaders/fs_particle_textured.sc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ void main()
vec4 color = diffuse * v_color;

// Apply linear fog
color.rgb = computeLinearFog(length(v_view_pos), u_FogNearFar.x, u_FogNearFar.y, color.rgb, u_FogColor.xyz);
// color.rgb = computeLinearFog(length(v_view_pos), u_FogNearFar.x, u_FogNearFar.y, color.rgb, u_FogColor.xyz);
color *= computeLinearFogFactor(length(v_view_pos), u_FogNearFar.x, u_FogNearFar.y);

gl_FragColor = color;
}
Expand Down
4 changes: 4 additions & 0 deletions src/shaders/tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ vec3 computeLinearFog(float distance, float fogNear, float fogFar, vec3 color, v
return mix(color.rgb, fogColor, l);
}

float computeLinearFogFactor(float distance, float fogNear, float fogFar) {
return 1.0 - saturate((distance - fogNear)/(fogFar - fogNear));
}

vec4 applySkyColor(float intensity)
{
return mix(u_SkyColors[0], u_SkyColors[1], intensity);
Expand Down
14 changes: 13 additions & 1 deletion src/ui/Hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Menu_Status.h"
#include "PrintScreenMessages.h"
#include "TextView.h"
#include "IntroduceChapterView.h"
#include <components/VobClasses.h>
#include <logic/PlayerController.h>
#include <logic/CameraController.h>
Expand All @@ -39,6 +40,8 @@ UI::Hud::Hud(Engine::BaseEngine& e)
m_pMenuBackground = new ImageView(m_Engine);
m_pMenuBackground->setHidden(true);
m_pMenuBackground->setRelativeSize(false);
m_pIntroduceChapterView = new IntroduceChapterView(m_Engine);
m_pIntroduceChapterView->setHidden(true);

addChild(m_pHealthBar);
addChild(m_pManaBar);
Expand All @@ -49,6 +52,7 @@ UI::Hud::Hud(Engine::BaseEngine& e)
addChild(m_pLoadingScreen);
addChild(m_pMenuBackground);
addChild(m_pConsoleBox);
addChild(m_pIntroduceChapterView);

// Initialize status bars
{
Expand Down Expand Up @@ -119,6 +123,7 @@ UI::Hud::~Hud()
removeChild(m_pLoadingScreen);
removeChild(m_pConsoleBox);
removeChild(m_pMenuBackground);
removeChild(m_pIntroduceChapterView);

popAllMenus();

Expand All @@ -130,6 +135,7 @@ UI::Hud::~Hud()
delete m_pClock;
delete m_pLoadingScreen;
delete m_pConsoleBox;
delete m_pIntroduceChapterView;
}

void UI::Hud::update(double dt, Engine::Input::MouseState& mstate, Render::RenderConfig& config)
Expand Down Expand Up @@ -254,6 +260,12 @@ void UI::Hud::onInputAction(Engine::ActionType action)
if (!m_pLoadingScreen->isHidden())
return;

if (!m_pIntroduceChapterView->isHidden() && action == ActionType::UI_ToggleMainMenu)
{
m_pIntroduceChapterView->close();
return;
}

if (m_Engine.getConsole().isOpen())
{
if (action == ActionType::UI_Close || action == ActionType::UI_ToggleConsole)
Expand Down Expand Up @@ -341,4 +353,4 @@ void UI::Hud::popAllMenus()
{
while (!m_MenuChain.empty())
popMenu();
}
}
Loading

0 comments on commit bdbc03c

Please sign in to comment.