Merge remote-tracking branch 'remotes/upstrem/master' into hd-textures-option

This commit is contained in:
Guillaume P 2014-05-02 19:18:58 +02:00
commit 14508bc2ac
31 changed files with 462 additions and 313 deletions

View File

@ -39,6 +39,6 @@ or collect any achievements while being online."
</box>
</div>
<icon-button id="back" x="0" y="0" height="15%" icon="gui/back.png"/>
<icon-button id="back" x="0" y="0" height="8%" icon="gui/back.png"/>
</stkgui>

View File

@ -6,27 +6,33 @@ uniform float endH;
uniform float start;
uniform float end;
uniform vec3 col;
uniform mat4 ipvmat;
#if __VERSION__ >= 130
in vec2 uv;
out vec4 FragColor;
#ifdef UBO_DISABLED
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 InverseViewMatrix;
uniform mat4 InverseProjectionMatrix;
#else
varying vec2 uv;
#define FragColor gl_FragColor
layout (std140) uniform MatrixesData
{
mat4 ViewMatrix;
mat4 ProjectionMatrix;
mat4 InverseViewMatrix;
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
#endif
in vec2 uv;
out vec4 FragColor;
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
void main()
{
float z = texture(tex, uv).x;
vec3 tmp = vec3(uv, z);
tmp = tmp * 2.0 - 1.0;
vec4 xpos = vec4(tmp, 1.0);
xpos = ipvmat * xpos;
xpos.xyz /= xpos.w;
vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix);
float dist = length(xpos.xyz);
float fog = smoothstep(start, end, dist);

View File

@ -1,3 +1,9 @@
#ifdef UBO_DISABLED
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 InverseViewMatrix;
uniform mat4 InverseProjectionMatrix;
#else
layout (std140) uniform MatrixesData
{
mat4 ViewMatrix;
@ -6,6 +12,7 @@ layout (std140) uniform MatrixesData
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
#endif
uniform samplerCube tex;
uniform vec2 screen;

View File

@ -1,10 +1,24 @@
uniform sampler2D ntex;
uniform sampler2D dtex;
uniform float spec;
uniform mat4 invproj;
uniform mat4 ViewMatrix;
uniform vec2 screen;
#ifdef UBO_DISABLED
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 InverseViewMatrix;
uniform mat4 InverseProjectionMatrix;
#else
layout (std140) uniform MatrixesData
{
mat4 ViewMatrix;
mat4 ProjectionMatrix;
mat4 InverseViewMatrix;
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
#endif
flat in vec3 center;
flat in float energy;
flat in vec3 col;
@ -14,6 +28,7 @@ out vec4 Specular;
vec3 DecodeNormal(vec2 n);
vec3 getSpecular(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness);
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
void main()
{
@ -22,9 +37,7 @@ void main()
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, texc).xy - 1.));
float roughness = texture(ntex, texc).z;
vec4 xpos = 2.0 * vec4(texc, z, 1.0) - 1.0f;
xpos = invproj * xpos;
xpos /= xpos.w;
vec4 xpos = getPosFromUVDepth(vec3(texc, z), InverseProjectionMatrix);
vec3 eyedir = -normalize(xpos.xyz);
vec4 pseudocenter = ViewMatrix * vec4(center.xyz, 1.0);

View File

@ -1,5 +1,18 @@
#ifdef UBO_DISABLED
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 InverseViewMatrix;
uniform mat4 InverseProjectionMatrix;
#else
layout (std140) uniform MatrixesData
{
mat4 ViewMatrix;
mat4 ProjectionMatrix;
mat4 InverseViewMatrix;
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
#endif
in vec3 Position;
in float Energy;

View File

@ -1,3 +1,9 @@
#ifdef UBO_DISABLED
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 InverseViewMatrix;
uniform mat4 InverseProjectionMatrix;
#else
layout (std140) uniform MatrixesData
{
mat4 ViewMatrix;
@ -6,6 +12,7 @@ layout (std140) uniform MatrixesData
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
#endif
uniform samplerCube tex;
uniform vec2 screen;

View File

@ -1,17 +1,26 @@
uniform sampler2D ntex;
uniform sampler2D dtex;
uniform sampler2D noise_texture;
uniform mat4 invprojm;
uniform mat4 projm;
uniform vec4 samplePoints[16];
#if __VERSION__ >= 130
#ifdef UBO_DISABLED
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 InverseViewMatrix;
uniform mat4 InverseProjectionMatrix;
#else
layout (std140) uniform MatrixesData
{
mat4 ViewMatrix;
mat4 ProjectionMatrix;
mat4 InverseViewMatrix;
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
#endif
in vec2 uv;
out float AO;
#else
varying vec2 uv;
#define AO gl_FragColor.x
#endif
const float strengh = 5.;
const float radius = 1.f;
@ -28,13 +37,13 @@ vec3 rand(vec2 co)
}
vec3 DecodeNormal(vec2 n);
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
void main(void)
{
vec4 cur = texture(ntex, uv);
float curdepth = texture(dtex, uv).x;
vec4 FragPos = invprojm * (2.0f * vec4(uv, curdepth, 1.0f) - 1.0f);
FragPos /= FragPos.w;
vec4 FragPos = getPosFromUVDepth(vec3(uv, curdepth), InverseProjectionMatrix);
// get the normal of current fragment
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
@ -52,15 +61,14 @@ void main(void)
vec3 sampleDir = samplePoints[i].x * tangent + samplePoints[i].y * bitangent + samplePoints[i].z * norm;
sampleDir *= samplePoints[i].w;
vec4 samplePos = FragPos + radius * vec4(sampleDir, 0.0);
vec4 sampleProj = projm * samplePos;
vec4 sampleProj = ProjectionMatrix * samplePos;
sampleProj /= sampleProj.w;
bool isInsideTexture = (sampleProj.x > -1.) && (sampleProj.x < 1.) && (sampleProj.y > -1.) && (sampleProj.y < 1.);
// get the depth of the occluder fragment
float occluderFragmentDepth = texture(dtex, (sampleProj.xy * 0.5) + 0.5).x;
// Position of the occluder fragment in worldSpace
vec4 occluderPos = invprojm * vec4(sampleProj.xy, 2.0 * occluderFragmentDepth - 1.0, 1.0f);
occluderPos /= occluderPos.w;
vec4 occluderPos = getPosFromUVDepth(vec3((sampleProj.xy * 0.5) + 0.5, occluderFragmentDepth), InverseProjectionMatrix);
bool isOccluded = isInsideTexture && (sampleProj.z > (2. * occluderFragmentDepth - 1.0)) && (distance(FragPos, occluderPos) < radius);
bl += isOccluded ? samplePoints[i].z * smoothstep(5 * radius, 0, distance(samplePos, FragPos)) : 0.;

View File

@ -8,6 +8,22 @@ uniform mat4 invproj;
//uniform int hasclouds;
//uniform vec2 wind;
#ifdef UBO_DISABLED
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 InverseViewMatrix;
uniform mat4 InverseProjectionMatrix;
#else
layout (std140) uniform MatrixesData
{
mat4 ViewMatrix;
mat4 ProjectionMatrix;
mat4 InverseViewMatrix;
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
#endif
#if __VERSION__ >= 130
in vec2 uv;
out vec4 Diff;
@ -21,12 +37,11 @@ varying vec2 uv;
vec3 DecodeNormal(vec2 n);
vec3 getSpecular(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness);
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
void main() {
float z = texture(dtex, uv).x;
vec4 xpos = 2.0 * vec4(uv, z, 1.0) - 1.0;
xpos = invproj * xpos;
xpos.xyz /= xpos.w;
vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix);
if (z < 0.03)
{

View File

@ -10,6 +10,12 @@ uniform vec3 col;
//uniform vec2 wind;
//uniform float shadowoffset;
#ifdef UBO_DISABLED
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 InverseViewMatrix;
uniform mat4 InverseProjectionMatrix;
#else
layout (std140) uniform MatrixesData
{
mat4 ViewMatrix;
@ -18,6 +24,7 @@ layout (std140) uniform MatrixesData
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
#endif
in vec2 uv;
out vec4 Diff;
@ -25,6 +32,7 @@ out vec4 Spec;
vec3 DecodeNormal(vec2 n);
vec3 getSpecular(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness);
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
float getShadowFactor(vec3 pos, float bias, int index)
{
@ -60,9 +68,7 @@ float getShadowFactor(vec3 pos, float bias, int index)
void main() {
float z = texture(dtex, uv).x;
vec4 xpos = 2.0 * vec4(uv, z, 1.0) - 1.0;
xpos = InverseProjectionMatrix * xpos;
xpos.xyz /= xpos.w;
vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix);
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
float roughness =texture(ntex, uv).z;

View File

@ -5,6 +5,12 @@ uniform sampler2DArrayShadow shadowtex;
uniform vec3 direction;
uniform vec3 col;
#ifdef UBO_DISABLED
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 InverseViewMatrix;
uniform mat4 InverseProjectionMatrix;
#else
layout (std140) uniform MatrixesData
{
mat4 ViewMatrix;
@ -13,6 +19,7 @@ layout (std140) uniform MatrixesData
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
#endif
in vec2 uv;

View File

@ -0,0 +1,8 @@
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix)
{
vec4 pos = 2.0 * vec4(uvDepth, 1.0) - 1.0f;
pos.xy *= vec2(InverseProjectionMatrix[0][0], InverseProjectionMatrix[1][1]);
pos.zw = vec2(pos.z * InverseProjectionMatrix[2][2] + pos.w, pos.z * InverseProjectionMatrix[2][3] + pos.w);
pos /= pos.w;
return pos;
}

View File

@ -81,6 +81,7 @@ MusicInformation::MusicInformation(const XMLNode *root,
m_normal_music = NULL;
m_fast_music = NULL;
m_enable_fast = false;
m_music_waiting = false;
m_faster_time = 1.0f;
m_max_pitch = 0.1f;
m_gain = 1.0f;

View File

@ -461,6 +461,9 @@ namespace UserConfigParams
PARAM_PREFIX BoolUserConfigParam m_dynamic_lights
PARAM_DEFAULT(BoolUserConfigParam(false, "enable_dynamic_lights",
&m_video_group, "Enable Dynamic Lights"));
PARAM_PREFIX BoolUserConfigParam m_dof
PARAM_DEFAULT(BoolUserConfigParam(false, "enable_dof",
&m_video_group, "Enable Depth of Field"));
// ---- Debug - not saved to config file
/** If gamepad debugging is enabled. */

View File

@ -308,7 +308,16 @@ void Camera::setInitialTransform()
*/
void Camera::smoothMoveCamera(float dt)
{
Kart *kart = dynamic_cast<Kart*>(m_kart);
if (kart->isFlying())
{
Vec3 vec3 = m_kart->getXYZ() + Vec3(sin(m_kart->getHeading()) * -4.0f, 0.5f, cos(m_kart->getHeading()) * -4.0f);
m_camera->setTarget(m_kart->getXYZ().toIrrVector());
m_camera->setPosition(vec3.toIrrVector());
return;
}
core::vector3df current_position = m_camera->getPosition();
// Smoothly interpolate towards the position and target
const KartProperties *kp = m_kart->getKartProperties();
@ -345,6 +354,7 @@ void Camera::smoothMoveCamera(float dt)
{
current_position += (wanted_position - current_position) * dt * 5;
}
if(m_mode!=CM_FALLING)
m_camera->setPosition(current_position);
m_camera->setTarget(current_target);//set new target

View File

@ -274,7 +274,7 @@ void PostProcessing::renderSunlight()
glBindVertexArray(FullScreenShader::SunLightShader::vao);
setTexture(0, irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), GL_NEAREST, GL_NEAREST);
setTexture(1, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST);
FullScreenShader::SunLightShader::setUniforms(cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1);
FullScreenShader::SunLightShader::setUniforms(cb->getPosition(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
}
@ -412,7 +412,7 @@ void PostProcessing::renderGlow(unsigned tex)
ITexture *noise_tex = 0;
void PostProcessing::renderSSAO(const core::matrix4 &invprojm, const core::matrix4 &projm)
void PostProcessing::renderSSAO()
{
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
@ -427,12 +427,12 @@ void PostProcessing::renderSSAO(const core::matrix4 &invprojm, const core::matri
setTexture(1, irr_driver->getDepthStencilTexture(), GL_LINEAR, GL_LINEAR);
setTexture(2, getTextureGLuint(noise_tex), GL_LINEAR, GL_LINEAR);
FullScreenShader::SSAOShader::setUniforms(projm, invprojm, 0, 1, 2);
FullScreenShader::SSAOShader::setUniforms(0, 1, 2);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
void PostProcessing::renderFog(const core::matrix4 &ipvmat)
void PostProcessing::renderFog()
{
const Track * const track = World::getWorld()->getTrack();
@ -457,7 +457,7 @@ void PostProcessing::renderFog(const core::matrix4 &ipvmat)
glBindVertexArray(FullScreenShader::FogShader::vao);
setTexture(0, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST);
FullScreenShader::FogShader::setUniforms(ipvmat, fogmax, startH, endH, start, end, col, 0);
FullScreenShader::FogShader::setUniforms(fogmax, startH, endH, start, end, col, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
@ -650,9 +650,12 @@ void PostProcessing::render()
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
renderDoF(out_fbo, in_rtt);
std::swap(in_rtt, out_rtt);
std::swap(in_fbo, out_fbo);
if (UserConfigParams::m_dof)
{
renderDoF(out_fbo, in_rtt);
std::swap(in_rtt, out_rtt);
std::swap(in_fbo, out_fbo);
}
PROFILER_PUSH_CPU_MARKER("- Godrays", 0xFF, 0x00, 0x00);
const bool hasgodrays = World::getWorld()->getTrack()->hasGodRays();

View File

@ -76,8 +76,8 @@ public:
void renderSunlight();
void renderShadowedSunlight(const std::vector<core::matrix4> &sun_ortho_matrix, unsigned depthtex);
void renderFog(const core::matrix4 &ipvmat);
void renderSSAO(const core::matrix4 &invprojm, const core::matrix4 &projm);
void renderFog();
void renderSSAO();
void renderDiffuseEnvMap(const float *bSHCoeff, const float *gSHCoeff, const float *rSHCoeff);
/** Blur the in texture */

View File

@ -215,7 +215,7 @@ void IrrDriver::renderGLSL(float dt)
if (UserConfigParams::m_dynamic_lights && World::getWorld()->getTrack()->isFogEnabled())
{
PROFILER_PUSH_CPU_MARKER("- Fog", 0xFF, 0x00, 0x00);
m_post_processing->renderFog(irr_driver->getInvProjMatrix());
m_post_processing->renderFog();
PROFILER_POP_CPU_MARKER();
}
@ -858,11 +858,9 @@ static void renderPointLights(unsigned count)
setTexture(0, irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), GL_NEAREST, GL_NEAREST);
setTexture(1, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST);
LightShader::PointLightShader
::setUniforms(irr_driver->getViewMatrix(), irr_driver->getProjMatrix(),
irr_driver->getInvProjMatrix(),
core::vector2df(float(UserConfigParams::m_width),
float(UserConfigParams::m_height) ),
200, 0, 1);
::setUniforms(core::vector2df(float(UserConfigParams::m_width),
float(UserConfigParams::m_height) ),
200, 0, 1);
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, count);
}
@ -968,7 +966,7 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox,
glClearColor(1., 1., 1., 1.);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, UserConfigParams::m_width / 2, UserConfigParams::m_height / 2);
m_post_processing->renderSSAO(irr_driver->getInvProjMatrix(), irr_driver->getProjMatrix());
m_post_processing->renderSSAO();
// Blur it to reduce noise.
m_post_processing->renderGaussian6Blur(irr_driver->getFBO(FBO_SSAO), irr_driver->getRenderTargetTexture(RTT_SSAO),
irr_driver->getFBO(FBO_HALF1), irr_driver->getRenderTargetTexture(RTT_HALF1), UserConfigParams::m_width / 2, UserConfigParams::m_height / 2);

View File

@ -1636,6 +1636,8 @@ namespace MeshShader
uniform_tex = glGetUniformLocation(Program, "tex");
attrib_color = glGetAttribLocation(Program, "Color");
uniform_windDir = glGetUniformLocation(Program, "windDir");
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
void GrassShadowShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector3df &windDirection, unsigned TU_tex)
@ -1756,9 +1758,6 @@ namespace LightShader
GLuint PointLightShader::uniform_dtex;
GLuint PointLightShader::uniform_spec;
GLuint PointLightShader::uniform_screen;
GLuint PointLightShader::uniform_invproj;
GLuint PointLightShader::uniform_VM;
GLuint PointLightShader::uniform_PM;
GLuint PointLightShader::vbo;
GLuint PointLightShader::vao;
@ -1768,6 +1767,7 @@ namespace LightShader
GL_VERTEX_SHADER, file_manager->getAsset("shaders/pointlight.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getSpecular.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/pointlight.frag").c_str());
attrib_Position = glGetAttribLocation(Program, "Position");
attrib_Color = glGetAttribLocation(Program, "Color");
@ -1776,10 +1776,7 @@ namespace LightShader
uniform_ntex = glGetUniformLocation(Program, "ntex");
uniform_dtex = glGetUniformLocation(Program, "dtex");
uniform_spec = glGetUniformLocation(Program, "spec");
uniform_invproj = glGetUniformLocation(Program, "invproj");
uniform_screen = glGetUniformLocation(Program, "screen");
uniform_VM = glGetUniformLocation(Program, "ViewMatrix");
uniform_PM = glGetUniformLocation(Program, "ProjectionMatrix");
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
@ -1804,13 +1801,12 @@ namespace LightShader
glVertexAttribDivisor(attrib_Color, 1);
}
void PointLightShader::setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 &InvProjMatrix, const core::vector2df &screen, unsigned spec, unsigned TU_ntex, unsigned TU_dtex)
void PointLightShader::setUniforms(const core::vector2df &screen, unsigned spec, unsigned TU_ntex, unsigned TU_dtex)
{
if (UserConfigParams::m_ubo_disabled)
bypassUBO(Program);
glUniform1f(uniform_spec, 200);
glUniform2f(uniform_screen, screen.X, screen.Y);
glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer());
glUniformMatrix4fv(uniform_VM, 1, GL_FALSE, ViewMatrix.pointer());
glUniformMatrix4fv(uniform_PM, 1, GL_FALSE, ProjMatrix.pointer());
glUniform1i(uniform_ntex, TU_ntex);
glUniform1i(uniform_dtex, TU_dtex);
@ -2149,7 +2145,6 @@ namespace FullScreenShader
GLuint SunLightShader::uniform_dtex;
GLuint SunLightShader::uniform_direction;
GLuint SunLightShader::uniform_col;
GLuint SunLightShader::uniform_invproj;
GLuint SunLightShader::vao;
void SunLightShader::init()
@ -2158,18 +2153,21 @@ namespace FullScreenShader
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getSpecular.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/sunlight.frag").c_str());
uniform_ntex = glGetUniformLocation(Program, "ntex");
uniform_dtex = glGetUniformLocation(Program, "dtex");
uniform_direction = glGetUniformLocation(Program, "direction");
uniform_col = glGetUniformLocation(Program, "col");
uniform_invproj = glGetUniformLocation(Program, "invproj");
vao = createVAO(Program);
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
void SunLightShader::setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex)
void SunLightShader::setUniforms(const core::vector3df &direction, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex)
{
glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer());
if (UserConfigParams::m_ubo_disabled)
bypassUBO(Program);
glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z);
glUniform3f(uniform_col, r, g, b);
glUniform1i(uniform_ntex, TU_ntex);
@ -2221,6 +2219,7 @@ namespace FullScreenShader
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getSpecular.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/sunlightshadow.frag").c_str());
uniform_ntex = glGetUniformLocation(Program, "ntex");
uniform_dtex = glGetUniformLocation(Program, "dtex");
@ -2234,6 +2233,8 @@ namespace FullScreenShader
void ShadowedSunLightShader::setUniforms(const core::vector3df &direction, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex)
{
if (UserConfigParams::m_ubo_disabled)
bypassUBO(Program);
glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z);
glUniform3f(uniform_col, r, g, b);
glUniform1i(uniform_ntex, TU_ntex);
@ -2268,6 +2269,8 @@ namespace FullScreenShader
void ShadowedSunLightDebugShader::setUniforms(const core::vector3df &direction, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex)
{
if (UserConfigParams::m_ubo_disabled)
bypassUBO(Program);
glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z);
glUniform3f(uniform_col, r, g, b);
glUniform1i(uniform_ntex, TU_ntex);
@ -2422,8 +2425,6 @@ namespace FullScreenShader
GLuint SSAOShader::uniform_ntex;
GLuint SSAOShader::uniform_dtex;
GLuint SSAOShader::uniform_noise_texture;
GLuint SSAOShader::uniform_invprojm;
GLuint SSAOShader::uniform_projm;
GLuint SSAOShader::uniform_samplePoints;
GLuint SSAOShader::vao;
float SSAOShader::SSAOSamples[64];
@ -2433,14 +2434,15 @@ namespace FullScreenShader
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/ssao.frag").c_str());
uniform_ntex = glGetUniformLocation(Program, "ntex");
uniform_dtex = glGetUniformLocation(Program, "dtex");
uniform_noise_texture = glGetUniformLocation(Program, "noise_texture");
uniform_invprojm = glGetUniformLocation(Program, "invprojm");
uniform_projm = glGetUniformLocation(Program, "projm");
uniform_samplePoints = glGetUniformLocation(Program, "samplePoints[0]");
vao = createVAO(Program);
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
// SSAOSamples[4 * i] and SSAOSamples[4 * i + 1] can be negative
@ -2556,10 +2558,10 @@ namespace FullScreenShader
}*/
}
void SSAOShader::setUniforms(const core::matrix4& projm, const core::matrix4 &invprojm, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_noise)
void SSAOShader::setUniforms(unsigned TU_ntex, unsigned TU_dtex, unsigned TU_noise)
{
glUniformMatrix4fv(FullScreenShader::SSAOShader::uniform_invprojm, 1, GL_FALSE, invprojm.pointer());
glUniformMatrix4fv(FullScreenShader::SSAOShader::uniform_projm, 1, GL_FALSE, projm.pointer());
if (UserConfigParams::m_ubo_disabled)
bypassUBO(Program);
glUniform4fv(FullScreenShader::SSAOShader::uniform_samplePoints, 16, FullScreenShader::SSAOShader::SSAOSamples);
glUniform1i(FullScreenShader::SSAOShader::uniform_ntex, TU_ntex);
@ -2575,13 +2577,13 @@ namespace FullScreenShader
GLuint FogShader::uniform_start;
GLuint FogShader::uniform_end;
GLuint FogShader::uniform_col;
GLuint FogShader::uniform_ipvmat;
GLuint FogShader::vao;
void FogShader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/fog.frag").c_str());
uniform_tex = glGetUniformLocation(Program, "tex");
uniform_fogmax = glGetUniformLocation(Program, "fogmax");
@ -2590,19 +2592,21 @@ namespace FullScreenShader
uniform_start = glGetUniformLocation(Program, "start");
uniform_end = glGetUniformLocation(Program, "end");
uniform_col = glGetUniformLocation(Program, "col");
uniform_ipvmat = glGetUniformLocation(Program, "ipvmat");
vao = createVAO(Program);
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
void FogShader::setUniforms(const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, unsigned TU_ntex)
void FogShader::setUniforms(float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, unsigned TU_ntex)
{
if (UserConfigParams::m_ubo_disabled)
bypassUBO(Program);
glUniform1f(uniform_fogmax, fogmax);
glUniform1f(uniform_startH, startH);
glUniform1f(uniform_endH, endH);
glUniform1f(uniform_start, start);
glUniform1f(uniform_end, end);
glUniform3f(uniform_col, col.X, col.Y, col.Z);
glUniformMatrix4fv(uniform_ipvmat, 1, GL_FALSE, ipvmat.pointer());
glUniform1i(uniform_tex, TU_ntex);
}

View File

@ -412,7 +412,7 @@ public:
}
#define MAXLIGHT 16
#define MAXLIGHT 32
namespace LightShader
{
@ -435,12 +435,12 @@ namespace LightShader
static GLuint Program;
static GLuint attrib_Position, attrib_Energy, attrib_Color;
static GLuint attrib_Corner;
static GLuint uniform_ntex, uniform_dtex, uniform_spec, uniform_screen, uniform_invproj, uniform_VM, uniform_PM;
static GLuint uniform_ntex, uniform_dtex, uniform_spec, uniform_screen;
static GLuint vbo;
static GLuint vao;
static void init();
static void setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 &InvProjMatrix, const core::vector2df &screen, unsigned spec, unsigned TU_ntex, unsigned TU_dtex);
static void setUniforms(const core::vector2df &screen, unsigned spec, unsigned TU_ntex, unsigned TU_dtex);
};
}
@ -556,11 +556,11 @@ class SunLightShader
{
public:
static GLuint Program;
static GLuint uniform_ntex, uniform_dtex, uniform_direction, uniform_col, uniform_invproj;
static GLuint uniform_ntex, uniform_dtex, uniform_direction, uniform_col;
static GLuint vao;
static void init();
static void setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex);
static void setUniforms(const core::vector3df &direction, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex);
};
class DiffuseEnvMapShader
@ -693,23 +693,23 @@ class SSAOShader
{
public:
static GLuint Program;
static GLuint uniform_ntex, uniform_dtex, uniform_noise_texture, uniform_invprojm, uniform_projm, uniform_samplePoints;
static GLuint uniform_ntex, uniform_dtex, uniform_noise_texture, uniform_samplePoints;
static GLuint vao;
static float SSAOSamples[64];
static void init();
static void setUniforms(const core::matrix4& projm, const core::matrix4 &invprojm, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_noise);
static void setUniforms(unsigned TU_ntex, unsigned TU_dtex, unsigned TU_noise);
};
class FogShader
{
public:
static GLuint Program;
static GLuint uniform_tex, uniform_fogmax, uniform_startH, uniform_endH, uniform_start, uniform_end, uniform_col, uniform_ipvmat;
static GLuint uniform_tex, uniform_fogmax, uniform_startH, uniform_endH, uniform_start, uniform_end, uniform_col;
static GLuint vao;
static void init();
static void setUniforms(const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, unsigned TU_ntex);
static void setUniforms(float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, unsigned TU_ntex);
};
class MotionBlurShader

View File

@ -2272,38 +2272,33 @@ void Kart::updateSliding()
*/
void Kart::updateFlying()
{
m_body->setLinearVelocity(m_body->getLinearVelocity() * 0.99f);
if (m_controls.m_accel)
{
float orientation = getHeading();
m_body->applyCentralImpulse(btVector3(60.0f*sin(orientation), 0.0,
60.0f*cos(orientation)));
btVector3 velocity = m_body->getLinearVelocity();
if (velocity.length() < 25)
{
float orientation = getHeading();
m_body->applyCentralImpulse(btVector3(100.0f*sin(orientation), 0.0,
100.0f*cos(orientation)));
}
}
else if (m_controls.m_brake)
{
btVector3 velocity = m_body->getLinearVelocity();
if (velocity.length() > -15)
{
float orientation = getHeading();
m_body->applyCentralImpulse(btVector3(-100.0f*sin(orientation), 0.0,
-100.0*cos(orientation)));
}
}
if (m_controls.m_steer != 0.0f)
{
m_body->applyTorque(btVector3(0.0, m_controls.m_steer * 3500.0f, 0.0));
}
if (m_controls.m_brake)
{
btVector3 velocity = m_body->getLinearVelocity();
const float x = velocity.x();
if (x > 0.2f) velocity.setX(x - 0.2f);
else if (x < -0.2f) velocity.setX(x + 0.2f);
else velocity.setX(0);
const float y = velocity.y();
if (y > 0.2f) velocity.setY(y - 0.2f);
else if (y < -0.2f) velocity.setY(y + 0.2f);
else velocity.setY(0);
const float z = velocity.z();
if (z > 0.2f) velocity.setZ(z - 0.2f);
else if (z < -0.2f) velocity.setZ(z + 0.2f);
else velocity.setZ(0);
m_body->setLinearVelocity(velocity);
} // if brake
// dampen any roll while flying, makes the kart hard to control
btVector3 velocity = m_body->getAngularVelocity();

View File

@ -469,7 +469,8 @@ void PhysicalObject::init()
btVector3(0,extend.getY()*0.5f, 0));
m_motion_state = new btDefaultMotionState(m_init_pos);
btVector3 inertia;
m_shape->calculateLocalInertia(m_mass, inertia);
if (m_body_type != MP_EXACT)
m_shape->calculateLocalInertia(m_mass, inertia);
btRigidBody::btRigidBodyConstructionInfo info(m_mass, m_motion_state,
m_shape, inertia);

View File

@ -35,10 +35,11 @@
// ----------------------------------------------------------------------------
GrandPrixData::GrandPrixData(const std::string& filename) throw(std::logic_error)
GrandPrixData::GrandPrixData(const std::string& filename)
{
m_filename = filename;
m_id = StringUtils::getBasename(StringUtils::removeExtension(filename));
m_id = StringUtils::getBasename(
StringUtils::removeExtension(filename));
m_editable = (filename.find(file_manager->getGPDir(), 0) == 0);
reload();
}
@ -77,85 +78,98 @@ void GrandPrixData::reload()
std::auto_ptr<XMLNode> root(file_manager->createXMLTree(m_filename));
if (root.get() == NULL)
{
Log::error("GrandPrixData","Error while trying to read grandprix file '%s'",
m_filename.c_str());
throw std::logic_error("File not found");
Log::error("GrandPrixData",
"Error while trying to read xml Grand Prix from file '%s'. "
"Is the file readable for supertuxkart?",
m_filename.c_str());
throw std::runtime_error("File couldn't be read");
}
bool foundName = false;
if (root->getName() == "supertuxkart_grand_prix")
if (root->getName() != "supertuxkart_grand_prix")
{
if (root->get("name", &m_name) == 0)
{
Log::error("GrandPrixData", "Error while trying to read grandprix file '%s' : "
"missing 'name' attribute\n", m_filename.c_str());
throw std::logic_error("File contents are incomplete or corrupt");
}
foundName = true;
Log::error("GrandPrixData",
"Error while trying to read Grand Prix file '%s': "
"Root node has the wrong name %s", m_filename.c_str(),
root->getName().c_str());
throw std::runtime_error("Wrong root node name");
}
else
if (!root->get("name", &m_name))
{
Log::error("GrandPrixData", "Error while trying to read grandprix file '%s' : "
"Root node has an unexpected name\n", m_filename.c_str());
throw std::logic_error("File contents are incomplete or corrupt");
Log::error("GrandPrixData",
"Error while trying to read grandprix file '%s': "
"missing 'name' attribute", m_filename.c_str());
throw std::runtime_error("Missing name attribute");
}
// Every iteration means parsing one track entry
const int amount = root->getNumNodes();
for (int i=0; i<amount; i++)
for (int i = 0; i < amount; i++)
{
const XMLNode* node = root->getNode(i);
// read a track entry
if (node->getName() == "track")
if (node->getName() != "track")
{
std::string trackID;
int numLaps;
bool reversed = false;
const int idFound = node->get("id", &trackID );
const int lapFound = node->get("laps", &numLaps );
// Will stay false if not found
node->get("reverse", &reversed );
if (!idFound || !lapFound)
{
Log::error("GrandPrixData", "Error while trying to read grandprix file '%s' : "
"<track> tag does not have idi and laps reverse attributes. \n",
m_filename.c_str());
throw std::logic_error("File contents are incomplete or corrupt");
}
// Make sure the track really is reversible
Track* t = track_manager->getTrack(trackID);
if (t != NULL && reversed)
{
reversed = t->reverseAvailable();
}
m_tracks.push_back(trackID);
m_laps.push_back(numLaps);
m_reversed.push_back(reversed);
assert(m_tracks.size() == m_laps.size() );
assert(m_laps.size() == m_reversed.size());
Log::error("GrandPrixData"
"Unknown node in Grand Prix XML file '%s': %s",
m_filename.c_str(), node->getName().c_str());
throw std::runtime_error("Unknown node in the XML file");
}
else
// 1. Parsing the id atttribute
std::string track_id;
if (!node->get("id", &track_id))
{
std::cerr << "Unknown node in Grand Prix XML file : " << node->getName().c_str() << std::endl;
throw std::runtime_error("Unknown node in sfx XML file");
Log::error("GrandPrixData",
"The id attribute is missing in the %d. track entry of "
"the Grand Prix file '%s'.", i, m_filename.c_str());
throw std::runtime_error("Missing track id");
}
}// nend for
// sanity checks
if (!foundName)
{
Log::error("GrandPrixData", "Error while trying to read grandprix file '%s' : "
"missing 'name' attribute\n", m_filename.c_str());
throw std::logic_error("File contents are incomplete or corrupt");
}
}
// 1.1 Checking if the track exists
Track* t = track_manager->getTrack(track_id);
if (t == NULL)
{
Log::error("GrandPrixData",
"The Grand Prix file '%s' contains a track '%s' that "
"does not exist", m_filename.c_str(), track_id.c_str());
throw std::runtime_error("Unknown track");
}
// 2. Parsing the number of laps
int number_of_laps;
if (!node->get("laps", &number_of_laps))
{
Log::error("GrandPrixData",
"The laps attribute is missing in the %d. track entry "
"of the Grand Prix file '%s'.", i, m_filename.c_str());
throw std::runtime_error("Missing track id");
}
if (number_of_laps < 1)
{
Log::error("GrandPrixData",
"Track '%s' in the Grand Prix file '%s' should be raced "
"with %d laps, which isn't possible.", track_id.c_str(),
m_filename.c_str());
throw std::runtime_error("Lap count lower than 1");
}
// 3. Parsing the reversed attribute
bool reversed = false; // Stays false if not found
node->get("reverse", &reversed );
if (!t->reverseAvailable())
reversed = false;
// Adding parsed data
m_tracks.push_back(track_id);
m_laps.push_back(number_of_laps);
m_reversed.push_back(reversed);
assert(m_tracks.size() == m_laps.size() );
assert(m_laps.size() == m_reversed.size());
} // end for all root nodes
} // reload()
// ----------------------------------------------------------------------------
bool GrandPrixData::writeToFile()
@ -165,14 +179,15 @@ bool GrandPrixData::writeToFile()
UTFWriter file(m_filename.c_str());
if (file.is_open())
{
file << L"\n<supertuxkart_grand_prix name=\"" << m_name << L"\">\n\n";
file << L"\n<supertuxkart_grand_prix name=\"" << m_name
<< L"\">\n\n";
for (unsigned int i = 0; i < m_tracks.size(); i++)
{
file <<
L"\t<track id=\"" << m_tracks[i] <<
L"\" laps=\"" << m_laps[i] <<
L"\" reverse=\"" << (m_reversed[i] ? L"true" : L"false") <<
L"\" />\n";
L"\t<track id=\"" << m_tracks[i] <<
L"\" laps=\"" << m_laps[i] <<
L"\" reverse=\"" << (m_reversed[i] ? L"true" : L"false")
<< L"\" />\n";
}
file << L"\n</supertuxkart_grand_prix>\n";
@ -185,33 +200,32 @@ bool GrandPrixData::writeToFile()
}
catch (std::runtime_error& e)
{
Log::error("GrandPrixData", "Failed to write '%s'; cause: %s\n",
m_filename.c_str(), e.what());
Log::error("GrandPrixData",
"Failed to write grand prix to '%s'; cause: %s",
m_filename.c_str(), e.what());
return false;
}
}
// ----------------------------------------------------------------------------
bool GrandPrixData::checkConsistency(bool chatty) const
bool GrandPrixData::checkConsistency(bool log_error) const
{
for (unsigned int i = 0; i<m_tracks.size(); i++)
for (unsigned int i = 0; i < m_tracks.size(); i++)
{
Track* t = track_manager->getTrack(m_tracks[i]);
if (t == NULL)
if (track_manager->getTrack(m_tracks[i]) == NULL)
{
if (chatty)
if (log_error)
{
Log::error("GrandPrixData", "Grand Prix '%ls': Track '%s' does not exist!\n",
m_name.c_str(), m_tracks[i].c_str());
Log::error("GrandPrixData", "This Grand Prix will not be available.\n");
Log::error("GrandPrixData",
"The grand prix '%ls' won't be available because "
"the track '%s' does not exist!", m_name.c_str(),
m_tracks[i].c_str());
}
return false;
}
} // for i
}
return true;
} // checkConsistency
}
// ----------------------------------------------------------------------------
@ -221,15 +235,17 @@ bool GrandPrixData::checkConsistency(bool chatty) const
* is unlocked). It also prevents people from using the grand prix editor as
* a way to play tracks that still haven't been unlocked
*/
bool GrandPrixData::isTrackAvailable(const std::string &id, bool includeLocked) const
bool GrandPrixData::isTrackAvailable(const std::string &id,
bool includeLocked ) const
{
if (includeLocked)
return true;
else if (id == "fortmagma")
return !PlayerManager::getCurrentPlayer()->isLocked("fortmagma");
else
return (!m_editable || !PlayerManager::get()->getCurrentPlayer()->isLocked(id));
} // isTrackAvailable
return (!m_editable ||
!PlayerManager::get()->getCurrentPlayer()->isLocked(id));
}
// ----------------------------------------------------------------------------
std::vector<std::string> GrandPrixData::getTrackNames(bool includeLocked) const
@ -239,9 +255,9 @@ std::vector<std::string> GrandPrixData::getTrackNames(bool includeLocked) const
{
if(isTrackAvailable(m_tracks[i], includeLocked))
names.push_back(m_tracks[i]);
} // for i
}
return names;
} // getTrackNames
}
// ----------------------------------------------------------------------------
std::vector<int> GrandPrixData::getLaps(bool includeLocked) const
@ -250,8 +266,9 @@ std::vector<int> GrandPrixData::getLaps(bool includeLocked) const
for (unsigned int i = 0; i< m_tracks.size(); i++)
if(isTrackAvailable(m_tracks[i], includeLocked))
laps.push_back(m_laps[i]);
return laps;
} // getLaps
}
// ----------------------------------------------------------------------------
std::vector<bool> GrandPrixData::getReverse(bool includeLocked) const
@ -260,14 +277,15 @@ std::vector<bool> GrandPrixData::getReverse(bool includeLocked) const
for (unsigned int i = 0; i< m_tracks.size(); i++)
if(isTrackAvailable(m_tracks[i], includeLocked))
reverse.push_back(m_reversed[i]);
return reverse;
} // getReverse
}
// ----------------------------------------------------------------------------
bool GrandPrixData::isEditable() const
{
return m_editable;
} // isEditable
}
// ----------------------------------------------------------------------------
unsigned int GrandPrixData::getNumberOfTracks(bool includeLocked) const
@ -334,49 +352,47 @@ void GrandPrixData::moveDown(const unsigned int track)
// ----------------------------------------------------------------------------
void GrandPrixData::addTrack(Track* track, unsigned int laps, bool reverse,
int position)
int position)
{
int n;
n = getNumberOfTracks(true);
int n = getNumberOfTracks(true);
assert (track != NULL);
assert (laps > 0);
assert (position >= -1 && position < n);
assert (-1 < position && position < n);
if (position < 0 || position == (n - 1) || m_tracks.empty())
{
//Append new track to the end of the list
// Append new track to the end of the list
m_tracks.push_back(track->getIdent());
m_laps.push_back(laps);
m_reversed.push_back(reverse);
}
else
{
//Insert new track right after the specified position. Caution:
//std::vector inserts elements _before_ the specified position
m_tracks.insert(m_tracks.begin() + position + 1, track->getIdent());
m_laps.insert(m_laps.begin() + position + 1, laps);
m_reversed.insert(m_reversed.begin() + position + 1, reverse);
// Insert new track right after the specified position. Caution:
// std::vector inserts elements _before_ the specified position
m_tracks. insert(m_tracks.begin() + position + 1, track->getIdent());
m_laps. insert(m_laps.begin() + position + 1, laps );
m_reversed.insert(m_reversed.begin() + position + 1, reverse );
}
}
// ----------------------------------------------------------------------------
void GrandPrixData::editTrack(unsigned int t, Track* track,
unsigned int laps, bool reverse)
void GrandPrixData::editTrack(unsigned int index, Track* track,
unsigned int laps, bool reverse)
{
assert (t < getNumberOfTracks(true));
assert (index < getNumberOfTracks(true));
assert (track != NULL);
assert (laps > 0);
m_tracks[t] = track->getIdent();
m_laps[t] = laps;
m_reversed[t] = reverse;
m_tracks[index] = track->getIdent();
m_laps[index] = laps;
m_reversed[index] = reverse;
}
// ----------------------------------------------------------------------------
void GrandPrixData::remove(const unsigned int track)
{
assert (track < getNumberOfTracks(true));
assert (0 < track && track < getNumberOfTracks(true));
m_tracks.erase(m_tracks.begin() + track);
m_laps.erase(m_laps.begin() + track);

View File

@ -51,7 +51,7 @@ private:
* (ie. 'volcano'). */
std::vector<std::string> m_tracks;
/** The number of laps that each track should be raced, in the right order */
/** The number of laps that each track will be raced, in the right order */
std::vector<int> m_laps;
/** Whether the track in question should be done in reverse mode */
@ -69,22 +69,25 @@ private:
bool isTrackAvailable(const std::string &id, bool includeLocked) const;
public:
/** Load the GrandPrixData from the given filename */
#if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
#pragma warning(disable:4290)
# pragma warning(disable:4290)
#endif
GrandPrixData (const std::string& filename) throw(std::logic_error);
GrandPrixData () {}; // empty for initialising
/** Load the GrandPrixData from the given filename */
GrandPrixData(const std::string& filename);
/** Needed for simple creation of an instance of GrandPrixData */
GrandPrixData() {};
// Methods for the GP editor
void setId(const std::string& id);
void setName(const irr::core::stringw& name);
void setFilename(const std::string& filename);
void setEditable(const bool editable);
/** Load the grand prix from the file set by the constructor or the grand
* prix editor */
void reload();
bool writeToFile();
bool checkConsistency(bool chatty=true) const;
bool checkConsistency(bool log_error=true) const;
std::vector<std::string> getTrackNames(const bool includeLocked=false) const;
std::vector<int> getLaps(const bool includeLocked=false) const;
std::vector<bool> getReverse(const bool includeLocked=false) const;
@ -98,22 +101,22 @@ public:
void moveDown(const unsigned int track);
void addTrack(Track* track, unsigned int laps,
bool reverse, int position=-1);
void editTrack(unsigned int t, Track* track,
void editTrack(unsigned int index, Track* track,
unsigned int laps, bool reverse);
void remove(const unsigned int track);
// ------------------------------------------------------------------------
/** @return the (potentially translated) user-visible name of the Grand
* Prix (apply fribidi as needed) */
irr::core::stringw getName() const { return _LTR(m_name.c_str()); }
irr::core::stringw getName() const { return _LTR(m_name.c_str()); }
// ------------------------------------------------------------------------
/** @return the internal name identifier of the Grand Prix (not translated) */
const std::string& getId() const { return m_id; }
/** @return the internal indentifier of the Grand Prix (not translated) */
const std::string& getId() const { return m_id; }
// ------------------------------------------------------------------------
/** Returns the filename of the grand prix xml file. */
const std::string& getFilename() const { return m_filename; }
const std::string& getFilename() const { return m_filename; }
}; // GrandPrixData

View File

@ -19,8 +19,8 @@
#include "race/grand_prix_manager.hpp"
#include "config/user_config.hpp"
#include "grand_prix_data.hpp"
#include "io/file_manager.hpp"
#include "race/grand_prix_data.hpp"
#include "utils/string_utils.hpp"
#include <algorithm>
@ -36,12 +36,13 @@ void GrandPrixManager::loadFiles()
{
std::set<std::string> dirs;
//Add all the directories to a set to avoid duplicates
// Add all the directories to a set to avoid duplicates
dirs.insert(file_manager->getAsset(FileManager::GRANDPRIX, ""));
dirs.insert(file_manager->getGPDir());
dirs.insert(UserConfigParams::m_additional_gp_directory);
for (std::set<std::string>::const_iterator it = dirs.begin(); it != dirs.end(); ++it)
for (std::set<std::string>::const_iterator it = dirs.begin();
it != dirs.end (); ++it)
{
std::string dir = *it;
if (!dir.empty() && dir[dir.size() - 1] == '/')
@ -52,35 +53,34 @@ void GrandPrixManager::loadFiles()
// ----------------------------------------------------------------------------
void GrandPrixManager::loadDir(const std::string& dir)
{
Log::info("GrandPrixManager", "Loading Grand Prix files from %s", dir.c_str());
Log::info("GrandPrixManager",
"Loading Grand Prix files from %s", dir.c_str());
assert(!dir.empty() && dir[dir.size() - 1] == '/');
// Findout which grand prixs are available and load them
// Findout which grand prix are available and load them
std::set<std::string> result;
file_manager->listFiles(result, dir);
for(std::set<std::string>::iterator i = result.begin(); i != result.end(); i++)
{
for(std::set<std::string>::iterator i = result.begin();
i != result.end(); i++)
if (StringUtils::hasSuffix(*i, SUFFIX))
load(dir + *i);
} // for i
} // loadDir
}
// ----------------------------------------------------------------------------
void GrandPrixManager::load(const std::string& filename)
{
GrandPrixData* gp;
try
{
gp = new GrandPrixData(filename);
GrandPrixData* gp = new GrandPrixData(filename);
m_gp_data.push_back(gp);
Log::debug("GrandPrixManager", "Grand Prix '%s' loaded from %s",
gp->getId().c_str(), filename.c_str());
Log::debug("GrandPrixManager",
"Grand Prix '%s' loaded from %s",
gp->getId().c_str(), filename.c_str());
}
catch (std::logic_error& er)
catch (std::runtime_error& e)
{
Log::error("GrandPrixManager", "Ignoring GP %s (%s)\n",
filename.c_str(), er.what());
Log::error("GrandPrixManager",
"Ignoring grand prix %s (%s)\n", filename.c_str(), e.what());
}
} // load
@ -99,44 +99,42 @@ std::string GrandPrixManager::generateId()
{
std::stringstream s;
do
bool unique = false;
while(!unique)
{
s.clear();
s << "usr_gp_" << ((rand() % 90000000) + 10000000);
} while (existsId(s.str()));
// Check if the id already exists
unique = true;
for (unsigned int i = 0; i < m_gp_data.size(); i++)
{
if (m_gp_data[i]->getId() == s.str())
{
unique = false;
break;
}
}
}
return s.str();
}
// ----------------------------------------------------------------------------
bool GrandPrixManager::existsId(const std::string& id) const
{
bool exists;
exists = false;
for (unsigned int i = 0; !exists && i < m_gp_data.size(); i++)
exists = (m_gp_data[i]->getId() == id);
return exists;
}
// ----------------------------------------------------------------------------
bool GrandPrixManager::existsName(const irr::core::stringw& name) const
{
bool exists;
for (unsigned int i = 0; i < m_gp_data.size(); i++)
if (m_gp_data[i]->getName() == name)
return true;
exists = false;
for (unsigned int i = 0; !exists && i < m_gp_data.size(); i++)
exists = (m_gp_data[i]->getName() == name);
return exists;
return false;
}
// ----------------------------------------------------------------------------
GrandPrixManager::GrandPrixManager()
{
loadFiles();
} // GrandPrixManager
}
// ----------------------------------------------------------------------------
GrandPrixManager::~GrandPrixManager()
@ -144,21 +142,24 @@ GrandPrixManager::~GrandPrixManager()
for(unsigned int i=0; i<m_gp_data.size(); i++)
{
delete m_gp_data[i];
} // for i
} // ~GrandPrixManager
}
}
// ----------------------------------------------------------------------------
const GrandPrixData* GrandPrixManager::getGrandPrix(const std::string& s) const
GrandPrixData* GrandPrixManager::getGrandPrix(const std::string& s) const
{
return editGrandPrix(s);
} // getGrandPrix
}
// ----------------------------------------------------------------------------
GrandPrixData* GrandPrixManager::editGrandPrix(const std::string& s) const
{
for(unsigned int i=0; i<m_gp_data.size(); i++)
if(m_gp_data[i]->getId()==s) return m_gp_data[i];
{
if(m_gp_data[i]->getId() == s)
return m_gp_data[i];
} // for i in m_gp_data
return NULL;
}
@ -177,7 +178,7 @@ void GrandPrixManager::checkConsistency()
} // checkConsistency
// ----------------------------------------------------------------------------
GrandPrixData* GrandPrixManager::createNew(const irr::core::stringw& newName)
GrandPrixData* GrandPrixManager::createNewGP(const irr::core::stringw& newName)
{
if (existsName(newName))
return NULL;
@ -197,7 +198,7 @@ GrandPrixData* GrandPrixManager::createNew(const irr::core::stringw& newName)
// ----------------------------------------------------------------------------
GrandPrixData* GrandPrixManager::copy(const std::string& id,
const irr::core::stringw& newName)
const irr::core::stringw& newName)
{
if (existsName(newName))
return NULL;
@ -228,6 +229,7 @@ void GrandPrixManager::remove(const std::string& id)
}
else
{
Log::warn("GrandPrixManager", "Grand Prix '%s' cannot be removed\n", gp->getId().c_str());
Log::warn("GrandPrixManager",
"Grand Prix '%s' can not be removed", gp->getId().c_str());
}
}

View File

@ -32,30 +32,37 @@ class GrandPrixManager
private:
static const char* SUFFIX;
std::vector<GrandPrixData*> m_gp_data;
/** Load all the grands prix from the 3 directories known */
void loadFiles();
/** Load all the grands prix in one directory */
void loadDir(const std::string& dir);
/** Load a grand prix and add it to m_gp_data*/
void load(const std::string &filename);
/** Generates a new unique indentifier for a user defined grand prix */
std::string generateId();
bool existsId(const std::string& id) const;
bool existsName(const irr::core::stringw& name) const;
std::vector<GrandPrixData*> m_gp_data;
public:
GrandPrixManager();
~GrandPrixManager();
void reload();
const GrandPrixData* getGrandPrix(const int i) const { return m_gp_data[i]; }
const GrandPrixData* getGrandPrix(const std::string& s) const;
GrandPrixData* editGrandPrix(const std::string& s) const;
unsigned int getNumberOfGrandPrix() const { return m_gp_data.size(); }
void checkConsistency();
GrandPrixManager();
~GrandPrixManager();
void reload();
GrandPrixData* getGrandPrix(const int i) const { return m_gp_data[i]; }
GrandPrixData* getGrandPrix(const std::string& s) const;
unsigned int getNumberOfGrandPrix() const { return m_gp_data.size(); }
void checkConsistency();
GrandPrixData* createNew(const irr::core::stringw& newName);
GrandPrixData* copy(const std::string& id, const irr::core::stringw& newName);
void remove(const std::string& id);
// Methods for the gp editor
GrandPrixData* editGrandPrix(const std::string& s) const;
GrandPrixData* createNewGP(const irr::core::stringw& newName);
GrandPrixData* copy(const std::string& id,
const irr::core::stringw& newName);
void remove(const std::string& id);
}; // GrandPrixManager
extern GrandPrixManager *grand_prix_manager;
#endif

View File

@ -272,10 +272,8 @@ void EditGPScreen::setModified(const bool modified)
// -----------------------------------------------------------------------------
void EditGPScreen::setSelected(const int selected)
{
IconButtonWidget* button_up = getWidget<IconButtonWidget>("up");
assert(button_up != NULL);
IconButtonWidget* button_down = getWidget<IconButtonWidget>("down");
assert(button_down != NULL);
assert(getWidget<IconButtonWidget>("up") != NULL);
assert(getWidget<IconButtonWidget>("down") != NULL);
m_selected = selected;
}
@ -307,14 +305,14 @@ bool EditGPScreen::save()
else
{
new MessageDialog(
_("An error occurred while trying to save your grand prix"),
_("An error occurred while trying to save your grand prix."),
MessageDialog::MESSAGE_DIALOG_OK, NULL, false);
return false;
}
}
// -----------------------------------------------------------------------------
void EditGPScreen::back ()
void EditGPScreen::back()
{
m_action.clear();
m_modified = false;
@ -324,11 +322,11 @@ void EditGPScreen::back ()
// -----------------------------------------------------------------------------
bool EditGPScreen::canMoveUp() const
{
return (m_selected > 0 && m_selected < m_list->getItemCount());
return (0 < m_selected && m_selected < m_list->getItemCount());
}
// -----------------------------------------------------------------------------
bool EditGPScreen::canMoveDown() const
{
return (m_selected >= 0 && m_selected < (m_list->getItemCount() - 1));
return (0 <= m_selected && m_selected < m_list->getItemCount() - 1);
}

View File

@ -264,7 +264,7 @@ void GrandPrixEditorScreen::onNewGPWithName(const stringw& newName)
}
else if (m_action == "new")
{
setSelection(grand_prix_manager->createNew(newName));
setSelection(grand_prix_manager->createNewGP(newName));
}
loadGPList();

View File

@ -68,6 +68,10 @@ void GuestLoginScreen::eventCallback(Widget* widget, const std::string& name,
else if(button=="cancel")
StateManager::get()->escapePressed();
}
else if (name == "back")
{
StateManager::get()->escapePressed();
}
} // eventCallback

View File

@ -179,6 +179,10 @@ void LoginScreen::eventCallback(Widget* widget, const std::string& name,
else if(button=="cancel")
StateManager::get()->escapePressed();
}
else if (name == "back")
{
StateManager::get()->escapePressed();
}
} // eventCallback

View File

@ -201,6 +201,10 @@ void RegisterScreen::eventCallback(Widget* widget, const std::string& name,
else if(button=="cancel")
StateManager::get()->escapePressed();
}
else if (name == "back")
{
StateManager::get()->escapePressed();
}
} // eventCallback

View File

@ -78,6 +78,7 @@ enum DebugMenuCommand
DEBUG_ATTACHMENT_BOMB,
DEBUG_ATTACHMENT_ANVIL,
DEBUG_TOGGLE_GUI,
DEBUG_HIDE_KARTS,
DEBUG_THROTTLE_FPS,
DEBUG_TWEAK_SHADER_EXPOSURE,
DEBUG_TWEAK_SHADER_LWHITE
@ -181,10 +182,10 @@ bool onEvent(const SEvent &event)
sub->addItem(L"Anvil", DEBUG_ATTACHMENT_ANVIL);
sub->addItem(L"Parachute", DEBUG_ATTACHMENT_PARACHUTE);
mnu->addItem(L"Adjust shaders >", -1, true, true);
sub = mnu->getSubMenu(3);
sub->addItem(L"Exposure", DEBUG_TWEAK_SHADER_EXPOSURE);
sub->addItem(L"LWhite", DEBUG_TWEAK_SHADER_LWHITE);
//mnu->addItem(L"Adjust shaders >", -1, true, true);
//sub = mnu->getSubMenu(3);
//sub->addItem(L"Exposure", DEBUG_TWEAK_SHADER_EXPOSURE);
//sub->addItem(L"LWhite", DEBUG_TWEAK_SHADER_LWHITE);
mnu->addItem(L"Profiler",DEBUG_PROFILER);
if (UserConfigParams::m_profiler_enabled)
@ -194,6 +195,7 @@ bool onEvent(const SEvent &event)
mnu->addItem(L"Save replay", DEBUG_SAVE_REPLAY);
mnu->addItem(L"Save history", DEBUG_SAVE_HISTORY);
mnu->addItem(L"Toggle GUI", DEBUG_TOGGLE_GUI);
mnu->addItem(L"Hide karts", DEBUG_HIDE_KARTS);
g_debug_menu_visible = true;
@ -393,13 +395,17 @@ bool onEvent(const SEvent &event)
if (world == NULL) return false;
RaceGUIBase* gui = world->getRaceGUI();
if (gui != NULL) gui->m_enabled = !gui->m_enabled;
}
else if (cmdID == DEBUG_HIDE_KARTS)
{
World* world = World::getWorld();
if (world == NULL) return false;
const int count = World::getWorld()->getNumKarts();
for (int n=0; n<count; n++)
for (int n = 0; n<count; n++)
{
AbstractKart* kart = world->getKart(n);
if (kart->getController()->isPlayerController())
kart->getNode()->setVisible(gui->m_enabled);
kart->getNode()->setVisible(false);
}
}
else if (cmdID == DEBUG_TWEAK_SHADER_EXPOSURE)