Merge remote-tracking branch 'origin/master' into hardware_skinning

This commit is contained in:
Benau 2016-12-10 10:09:30 +08:00
commit 8ca0c54bdc
137 changed files with 2042 additions and 1134 deletions

View File

@ -15,6 +15,7 @@ if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "STKRelease")
endif()
option(SERVER_ONLY "Create a server only (i.e. no graphics or sound)" OFF)
option(USE_FRIBIDI "Support for right-to-left languages" ON)
option(CHECK_ASSETS "Check if assets are installed in ../stk-assets" ON)
option(USE_SYSTEM_ANGELSCRIPT "Use system angelscript instead of built-in angelscript. If you enable this option, make sure to use a compatible version." OFF)
@ -34,7 +35,7 @@ else()
set(WIIUSE_BUILD ON)
endif()
if(MINGW OR CYGWIN)
if(MINGW OR CYGWIN OR SERVER_ONLY)
option(USE_WIIUSE "Support for wiimote input devices" OFF)
else()
option(USE_WIIUSE "Support for wiimote input devices" ON)
@ -68,6 +69,11 @@ if(USE_GLES2)
add_definitions(-DUSE_GLES2)
endif()
if(SERVER_ONLY)
add_definitions(-DSERVER_ONLY)
add_definitions(-DNO_IRR_COMPILE_WITH_X11_)
endif()
# Build the Bullet physics library
add_subdirectory("${PROJECT_SOURCE_DIR}/lib/bullet")
include_directories("${PROJECT_SOURCE_DIR}/lib/bullet/src")
@ -77,7 +83,7 @@ add_subdirectory("${PROJECT_SOURCE_DIR}/lib/enet")
include_directories("${PROJECT_SOURCE_DIR}/lib/enet/include")
# Build glew library
if(NOT USE_GLES2)
if(NOT USE_GLES2 AND NOT SERVER_ONLY)
add_definitions(-DGLEW_NO_GLU)
add_subdirectory("${PROJECT_SOURCE_DIR}/lib/glew")
include_directories("${PROJECT_SOURCE_DIR}/lib/glew/include")
@ -206,12 +212,13 @@ if (OPENMP_FOUND)
endif()
# OpenGL
if(NOT USE_GLES2)
if(NOT USE_GLES2 AND NOT SERVER_ONLY)
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
endif()
if(UNIX AND NOT APPLE)
if(UNIX AND NOT APPLE AND NOT SERVER_ONLY)
find_package(X11 REQUIRED)
include_directories(${X11_INCLUDE_DIR})
@ -370,10 +377,12 @@ target_link_libraries(supertuxkart
${FREETYPE_LIBRARIES}
)
if(NOT USE_GLES2)
target_link_libraries(supertuxkart ${OPENGL_LIBRARIES} glew)
else()
target_link_libraries(supertuxkart EGL GLESv2)
if(NOT SERVER_ONLY)
if(NOT USE_GLES2)
target_link_libraries(supertuxkart ${OPENGL_LIBRARIES} glew)
else()
target_link_libraries(supertuxkart EGL GLESv2)
endif()
endif()
if(UNIX AND NOT APPLE)

View File

@ -54,6 +54,7 @@ void main(void)
float scattering = mix(fPowEdotL, fLdotNBack, .5);
float specmap = texture(SpecMap, uv).g;
vec3 LightFactor = color.xyz * (scattering * 0.1) + getLightFactor(color.xyz, vec3(1.), specmap, 0.);
float emitmap = texture(SpecMap, uv).b;
vec3 LightFactor = color.xyz * (scattering * 0.1) + getLightFactor(color.xyz, vec3(1.), specmap, emitmap);
FragColor = vec4(LightFactor, 1.);
}

View File

@ -25,6 +25,7 @@ void main(void)
#ifdef Use_Bindless_Texture
vec4 color = texture(handle, uv);
float specmap = texture(secondhandle, uv).g;
float emitmap = texture(secondhandle, uv).b;
float mask = texture(thirdhandle, uv).a;
#ifdef SRGBBindlessFix
color.xyz = pow(color.xyz, vec3(2.2));
@ -32,6 +33,7 @@ void main(void)
#else
vec4 color = texture(Albedo, uv);
float specmap = texture(SpecMap, uv).g;
float emitmap = texture(SpecMap, uv).b;
float mask = texture(colorization_mask, uv).a;
#endif
if (color.a < 0.5) discard;
@ -59,7 +61,8 @@ void main(void)
float fLdotNBack = max(0., - dot(nor, L) * 0.6 + 0.4);
float scattering = mix(fPowEdotL, fLdotNBack, .5);
vec3 LightFactor = color.xyz * (scattering * 0.1) + getLightFactor(color.xyz, vec3(1.), specmap, emitmap);
vec3 LightFactor = color.xyz * (scattering * 0.1) + getLightFactor(color.xyz, vec3(1.), specmap, 0.);
FragColor = vec4(LightFactor, 1.);
}

View File

@ -1,5 +1,6 @@
# CMakeLists.txt - glew
if (NOT SERVER_ONLY)
include_directories("include")
if(APPLE)
@ -18,3 +19,5 @@ add_library(glew STATIC
)
target_link_libraries(glew ${OPENGL_LIBRARIES})
endif()

View File

@ -8,9 +8,14 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include/"
"${ZLIB_INCLUDE_DIR}"
"${CMAKE_CURRENT_BINARY_DIR}/../zlib/") # For zconf.h on WIN32
if(NOT USE_GLES2)
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
if (SERVER_ONLY)
add_definitions(-DNO_IRR_COMPILE_WITH_OPENGL_)
add_definitions(-DNO_IRR_COMPILE_WITH_X11_)
else()
if(NOT USE_GLES2)
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
endif()
endif()
if (UNIX AND NOT APPLE)

View File

@ -246,6 +246,10 @@ define out. */
#ifdef NO_IRR_LINUX_XCURSOR_
#undef _IRR_LINUX_XCURSOR_
#endif
#else
#undef _IRR_LINUX_X11_VIDMODE_
#undef _IRR_LINUX_X11_RANDR_
#endif

View File

@ -68,12 +68,14 @@ namespace irr
}
} // end namespace irr
#if defined(_IRR_COMPILE_WITH_X11_)
namespace
{
Atom X_ATOM_CLIPBOARD;
Atom X_ATOM_TARGETS;
Atom X_ATOM_UTF8_STRING;
};
#endif
namespace irr
{
@ -598,6 +600,7 @@ static GLXContext getMeAGLContext(Display *display, GLXFBConfig glxFBConfig, boo
Context = glXCreateNewContext(display, glxFBConfig, GLX_RGBA_TYPE, NULL, True);
return Context;
}
#endif
bool CIrrDeviceLinux::createWindow()

View File

@ -341,11 +341,25 @@ namespace video
delete BridgeCalls;
#if defined(EGL_VERSION_1_0)
// HACK : the following is commented because destroying the context crashes under Linux (Thibault 04-feb-10)
/*eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroyContext(EglDisplay, EglContext);
eglDestroySurface(EglDisplay, EglSurface);*/
eglTerminate(EglDisplay);
eglMakeCurrent(EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
if (EglContext != EGL_NO_CONTEXT)
{
eglDestroyContext(EglDisplay, EglContext);
EglContext = EGL_NO_CONTEXT;
}
if (EglSurface != EGL_NO_SURFACE)
{
eglDestroySurface(EglDisplay, EglSurface);
EglSurface = EGL_NO_SURFACE;
}
if (EglDisplay != EGL_NO_DISPLAY)
{
eglTerminate(EglDisplay);
EglDisplay = EGL_NO_DISPLAY;
}
#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
if (HDc)

View File

@ -1,5 +1,5 @@
# Modify this file to change the last-modified date when you add/remove a file.
# This will then trigger a new cmake run automatically.
# This will then trigger a new cmake run automatically.
file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*")

View File

@ -264,6 +264,9 @@ const std::string& getOSVersion()
*/
void reportHardwareStats()
{
#ifdef SERVER_ONLY
return;
#else
if(!UserConfigParams::m_hw_report_enable)
return;
@ -335,8 +338,10 @@ void reportHardwareStats()
if(nr_procs>0)
json.add("cpu_numprocs", nr_procs);
#ifndef SERVER_ONLY
json.add("GL_EXTENSIONS", getGLExtensions());
getGLLimits(&json);
#endif
json.finish();
// ------------------------------------------------------------------------
@ -391,7 +396,7 @@ void reportHardwareStats()
request->setURL((std::string)UserConfigParams::m_server_hw_report+"/upload/v1/");
//request->setURL("http://127.0.0.1:8000/upload/v1/");
request->queue();
#endif // !SERVER_ONLY
} // reportHardwareStats
} // namespace HardwareStats

View File

@ -527,6 +527,7 @@ void FontWithFace::render(const core::stringw& text,
FontSettings* font_settings,
FontCharCollector* char_collector)
{
#ifndef SERVER_ONLY
const bool black_border = font_settings ?
font_settings->useBlackBorder() : false;
const bool rtl = font_settings ? font_settings->isRTL() : false;
@ -778,4 +779,5 @@ void FontWithFace::render(const core::stringw& text,
}
}
}
#endif
} // render

View File

@ -15,6 +15,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/2dutils.hpp"
#include "graphics/central_settings.hpp"
@ -779,3 +780,6 @@ void GL32_draw2DRectangle(video::SColor color, const core::rect<s32>& position,
glGetError();
} // GL32_draw2DRectangle
#endif // !SERVER_ONLY

View File

@ -15,6 +15,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/central_settings.hpp"
#include "config/user_config.hpp"
@ -447,3 +448,4 @@ bool CentralVideoSettings::supportsHardwareSkinning() const
{
return isARBUniformBufferObjectUsable() && isARBExplicitAttribLocationUsable() && getGLSLVersion() >= 330;
}
#endif // !SERVER_ONLY

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/command_buffer.hpp"
#include "graphics/central_settings.hpp"
#include "utils/cpp2011.hpp"
@ -275,4 +277,6 @@ void GlowCommandBuffer::fill(OtherMeshMap *mesh_map)
glUnmapBuffer(GL_DRAW_INDIRECT_BUFFER);
} //GlowCommandBuffer::fill
#endif // !defined(USE_GLES2)
#endif // !defined(USE_GLES2)
#endif // !SERVER_ONLY

View File

@ -18,6 +18,8 @@
#ifndef HEADER_COMMAND_BUFFER_HPP
#define HEADER_COMMAND_BUFFER_HPP
#ifndef SERVER_ONLY
#include "graphics/draw_tools.hpp"
#include "graphics/gl_headers.hpp"
#include "graphics/material.hpp"
@ -653,5 +655,6 @@ public:
}
} // multidraw
};
#endif // !defined(USE_GLES2)
#endif //HEADER_COMMAND_BUFFER_HPP
#endif // !defined(USE_GLES2)
#endif // !SERVER_ONLY
#endif // HEADER_COMMAND_BUFFER_HPP

View File

@ -15,7 +15,9 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/draw_calls.hpp"
#include "config/user_config.hpp"
#include "graphics/draw_tools.hpp"
#include "graphics/gpu_particles.hpp"
@ -899,3 +901,4 @@ int32_t DrawCalls::getSkinningOffset() const
(const size_t previous, const STKAnimatedMesh* m)
{ return previous + m->getTotalJointSize(); });
} // getSkinningOffset
#endif // !SERVER_ONLY

View File

@ -18,6 +18,7 @@
#ifndef HEADER_DRAW_CALLS_HPP
#define HEADER_DRAW_CALLS_HPP
#ifndef SERVER_ONLY
#include "graphics/command_buffer.hpp"
#include <irrlicht.h>
#include <unordered_map>
@ -110,4 +111,5 @@ public:
int32_t getSkinningOffset() const;
};
#endif // !SERVER_ONLY
#endif //HEADER_DRAW_CALLS_HPP

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/draw_policies.hpp"
#include "graphics/draw_tools.hpp"
#include "graphics/materials.hpp"
@ -352,3 +354,5 @@ void MultidrawPolicy::drawReflectiveShadowMap(const DrawCalls& draw_calls,
draw_calls.multidrawReflectiveShadowMaps(rsm_matrix);
#endif //!defined(USE_GLES2)
}
#endif // !SERVER_ONLY

View File

@ -18,6 +18,8 @@
#ifndef HEADER_DRAW_POLICIES_HPP
#define HEADER_DRAW_POLICIES_HPP
#ifndef SERVER_ONLY
#include "graphics/draw_calls.hpp"
@ -91,5 +93,5 @@ public:
const core::matrix4 &rsm_matrix ) const;
};
#endif //HEADER_DRAW_POLICIES_HPP
#endif // !SERVER_ONLY
#endif // HEADER_DRAW_POLICIES_HPP

View File

@ -41,9 +41,11 @@ Explosion::Explosion(const Vec3& coord, const char* explosion_sound, const char
m_remaining_time = burst_time;
m_emission_frames = 0;
#ifndef SERVER_ONLY
ParticleKindManager* pkm = ParticleKindManager::get();
ParticleKind* particles = pkm->getParticles(particle_file);
m_emitter = new ParticleEmitter(particles, coord, NULL);
#endif
} // Explosion
//-----------------------------------------------------------------------------
@ -51,10 +53,12 @@ Explosion::Explosion(const Vec3& coord, const char* explosion_sound, const char
*/
Explosion::~Explosion()
{
#ifndef SERVER_ONLY
if(m_emitter)
{
delete m_emitter;
}
#endif
} // ~Explosion
//-----------------------------------------------------------------------------
@ -71,6 +75,7 @@ bool Explosion::updateAndDelete(float dt)
m_emission_frames++;
m_remaining_time -= dt;
#ifndef SERVER_ONLY
if (m_remaining_time < 0.0f && m_remaining_time >= -explosion_time)
{
scene::ISceneNode* node = m_emitter->getNode();
@ -88,7 +93,7 @@ bool Explosion::updateAndDelete(float dt)
node->getMaterial(0).DiffuseColor.setRed(intensity);
node->getMaterial(0).EmissiveColor.setRed(intensity);
}
#endif
// Do nothing more if the animation is still playing
if (m_remaining_time>0) return false;
@ -98,6 +103,7 @@ bool Explosion::updateAndDelete(float dt)
// object is removed.
if (m_remaining_time > -explosion_time)
{
#ifndef SERVER_ONLY
// if framerate is very low, emit for at least a few frames, in case
// burst time is lower than the time of 1 frame
if (m_emission_frames > 2)
@ -106,6 +112,7 @@ bool Explosion::updateAndDelete(float dt)
m_emitter->getNode()->getEmitter()->setMinParticlesPerSecond(0);
m_emitter->getNode()->getEmitter()->setMaxParticlesPerSecond(0);
}
#endif
}
else
{

View File

@ -15,6 +15,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/fixed_pipeline_renderer.hpp"
#include "config/user_config.hpp"
#include "graphics/camera.hpp"
@ -112,3 +113,4 @@ std::unique_ptr<RenderTarget> FixedPipelineRenderer::createRenderTarget(const ir
{
return std::unique_ptr<RenderTarget>(new GL1RenderTarget(dimension, name));
}
#endif

View File

@ -18,6 +18,7 @@
#ifndef HEADER_FIXED_PIPELINE_RENDERER_HPP
#define HEADER_FIXED_PIPELINE_RENDERER_HPP
#ifndef SERVER_ONLY
#include "graphics/abstract_renderer.hpp"
#include <map>
@ -37,4 +38,5 @@ public:
const std::string &name);
};
#endif // !SERVER_ONLY
#endif //HEADER_FIXED_PIPELINE_RENDERER_HPP

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/geometry_passes.hpp"
#include "graphics/callbacks.hpp"
#include "graphics/draw_tools.hpp"
@ -380,5 +382,4 @@ void AbstractGeometryPasses::renderTransparent(const DrawCalls& draw_calls,
} // renderTransparent
#endif // !SERVER_ONLY

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#ifndef HEADER_GEOMETRY_PASSES_HPP
#define HEADER_GEOMETRY_PASSES_HPP
@ -171,4 +173,5 @@ public:
};
#endif //HEADER_GEOMETRY_PASSES_HPP
#endif // !SERVER_ONLY
#endif // HEADER_GEOMETRY_PASSES_HPP

View File

@ -18,6 +18,8 @@
#ifndef GL_HEADER_HPP
#define GL_HEADER_HPP
#ifndef SERVER_ONLY
#define GLEW_STATIC
extern "C" {
@ -80,5 +82,12 @@ struct DrawElementsIndirectCommand{
GLuint baseVertex;
GLuint baseInstance;
};
#else
typedef unsigned int GLuint;
typedef unsigned int GLsync;
typedef unsigned int GLenum;
#endif // server only
#endif

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/glwrap.hpp"
#include "config/hardware_stats.hpp"
@ -758,3 +760,6 @@ else \
#endif // ifdef XX
} // getGLLimits
#endif // !SERVER_ONLY

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#ifndef GLWRAP_HEADER_H
#define GLWRAP_HEADER_H
@ -168,3 +170,6 @@ const std::string getGLExtensions();
void getGLLimits(HardwareStats::Json *json);
#endif
#endif // supertuxkart

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/gpu_particles.hpp"
#include "config/user_config.hpp"
@ -633,3 +635,5 @@ void ParticleSystemProxy::render() {
draw();
}
}
#endif // SERVER_ONLY

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#ifndef HEADER_GPU_PARTICLES_HPP
#define HEADER_GPU_PARTICLES_HPP
@ -109,3 +111,5 @@ public:
};
#endif // GPUPARTICLES_H
#endif // !SERVER_ONLY

View File

@ -70,11 +70,13 @@
* Should help prevent distros building against an incompatible library.
*/
#if (IRRLICHT_VERSION_MAJOR < 1 || IRRLICHT_VERSION_MINOR < 7 || \
_IRR_MATERIAL_MAX_TEXTURES_ < 8 || \
(!defined(_IRR_COMPILE_WITH_OPENGL_) && \
!defined(_IRR_COMPILE_WITH_OGLES2_)) || \
!defined(_IRR_COMPILE_WITH_B3D_LOADER_))
#if ( IRRLICHT_VERSION_MAJOR < 1 || \
IRRLICHT_VERSION_MINOR < 7 || \
_IRR_MATERIAL_MAX_TEXTURES_ < 8 || \
( !defined(_IRR_COMPILE_WITH_OPENGL_) && \
!defined(SERVER_ONLY) && \
!defined(_IRR_COMPILE_WITH_OGLES2_) ) || \
!defined(_IRR_COMPILE_WITH_B3D_LOADER_) )
#error "Building against an incompatible Irrlicht. Distros, \
please use the included version."
#endif
@ -97,8 +99,9 @@ struct android_app* global_android_app;
/** singleton */
IrrDriver *irr_driver = NULL;
#ifndef SERVER_ONLY
GPUTimer m_perf_query[Q_LAST];
#endif
const int MIN_SUPPORTED_HEIGHT = 768;
const int MIN_SUPPORTED_WIDTH = 1024;
@ -148,16 +151,19 @@ IrrDriver::IrrDriver()
IrrDriver::~IrrDriver()
{
assert(m_device != NULL);
#ifndef SERVER_ONLY
cleanUnicolorTextures();
#endif
m_device->drop();
m_device = NULL;
m_modes.clear();
#ifndef SERVER_ONLY
if (CVS->isGLSL())
{
Shaders::destroy();
}
#endif
delete m_wind;
delete m_renderer;
} // ~IrrDriver
@ -167,7 +173,9 @@ IrrDriver::~IrrDriver()
*/
void IrrDriver::reset()
{
#ifndef SERVER_ONLY
m_renderer->resetPostProcessing();
#endif
} // reset
// ----------------------------------------------------------------------------
@ -195,15 +203,17 @@ core::array<video::IRenderTarget> &IrrDriver::getMainSetup()
} // getMainSetup
// ----------------------------------------------------------------------------
#ifndef SERVER_ONLY
GPUTimer &IrrDriver::getGPUTimer(unsigned i)
{
return m_perf_query[i];
} // getGPUTimer
#endif
// ----------------------------------------------------------------------------
#ifndef SERVER_ONLY
std::unique_ptr<RenderTarget> IrrDriver::createRenderTarget(const irr::core::dimension2du &dimension,
const std::string &name)
{
@ -221,6 +231,7 @@ If window is the root window, returns window.
*/
Window get_toplevel_parent(Display* display, Window window)
{
#ifndef SERVER_ONLY
Window parent;
Window root;
Window * children;
@ -243,6 +254,9 @@ Window get_toplevel_parent(Display* display, Window window)
window = parent;
}
}
#else
return NULL;
#endif
}
#endif
@ -253,8 +267,9 @@ Window get_toplevel_parent(Display* display, Window window)
*/
void IrrDriver::updateConfigIfRelevant()
{
if (!UserConfigParams::m_fullscreen &&
UserConfigParams::m_remember_window_location)
#ifndef SERVER_ONLY
if (!UserConfigParams::m_fullscreen &&
UserConfigParams::m_remember_window_location)
{
#ifdef WIN32
const video::SExposedVideoData& videoData = m_device->getVideoDriver()
@ -306,6 +321,8 @@ void IrrDriver::updateConfigIfRelevant()
}
#endif
}
#endif // !SERVER_ONLY
} // updateConfigIfRelevant
// ----------------------------------------------------------------------------
@ -518,6 +535,7 @@ void IrrDriver::initDevice()
{
Log::fatal("irr_driver", "Couldn't initialise irrlicht device. Quitting.\n");
}
#ifndef SERVER_ONLY
CVS->init();
@ -536,12 +554,14 @@ void IrrDriver::initDevice()
params.ForceLegacyDevice = true;
recreate_device = true;
}
#endif
// This is the ugly hack for intel driver on linux, which doesn't
// use sRGB-capable visual, even if we request it. This causes
// the screen to be darker than expected. It affects mesa 10.6 and newer.
// Though we are able to force to use the proper format on mesa side by
// setting WithAlphaChannel parameter.
#ifndef SERVER_ONLY
else if (CVS->needsSRGBCapableVisualWorkaround())
{
Log::warn("irr_driver", "Created visual is not sRGB-capable. "
@ -567,17 +587,19 @@ void IrrDriver::initDevice()
CVS->init();
}
#endif
m_scene_manager = m_device->getSceneManager();
m_gui_env = m_device->getGUIEnvironment();
m_video_driver = m_device->getVideoDriver();
m_actual_screen_size = m_video_driver->getCurrentRenderTargetSize();
#ifndef SERVER_ONLY
if(CVS->isGLSL())
m_renderer = new ShaderBasedRenderer();
else
m_renderer = new FixedPipelineRenderer();
#endif
if (UserConfigParams::m_shadows_resolution != 0 &&
(UserConfigParams::m_shadows_resolution < 512 ||
@ -596,6 +618,7 @@ void IrrDriver::initDevice()
m_video_driver->beginScene(/*backBuffer clear*/true, /* Z */ false);
m_video_driver->endScene();
#ifndef SERVER_ONLY
if (CVS->isGLSL())
{
Log::info("irr_driver", "GLSL supported.");
@ -608,6 +631,7 @@ void IrrDriver::initDevice()
UserConfigParams::m_gi = false;
}*/
// m_glsl might be reset in rtt if an error occurs.
if (CVS->isGLSL())
{
@ -622,11 +646,12 @@ void IrrDriver::initDevice()
Log::warn("irr_driver", "Using the fixed pipeline (old GPU, or "
"shaders disabled in options)");
}
#endif
// Only change video driver settings if we are showing graphics
if (!ProfileWorld::isNoGraphics())
{
#if defined(__linux__) && !defined(ANDROID)
#if defined(__linux__) && !defined(ANDROID) && !defined(SERVER_ONLY)
// Set class hints on Linux, used by Window Managers.
const video::SExposedVideoData& videoData = m_video_driver
->getExposedVideoData();
@ -676,10 +701,12 @@ void IrrDriver::initDevice()
material2D.AntiAliasing=video::EAAM_FULL_BASIC;
//m_video_driver->enableMaterial2D();
#ifndef SERVER_ONLY
// set cursor visible by default (what's the default is not too clearly documented,
// so let's decide ourselves...)
m_device->getCursorControl()->setVisible(true);
m_pointer_shown = true;
#endif
} // initDevice
// ----------------------------------------------------------------------------
@ -703,6 +730,7 @@ void IrrDriver::cleanSunInterposer()
// ----------------------------------------------------------------------------
void IrrDriver::createSunInterposer()
{
#ifndef SERVER_ONLY
scene::IMesh * sphere = m_scene_manager->getGeometryCreator()
->createSphereMesh(1, 16, 16);
for (unsigned i = 0; i < sphere->getMeshBufferCount(); ++i)
@ -731,15 +759,18 @@ void IrrDriver::createSunInterposer()
m_sun_interposer->getMaterial(0).MaterialType = Shaders::getShader(ES_OBJECTPASS);
sphere->drop();
#endif
}
//-----------------------------------------------------------------------------
void IrrDriver::getOpenGLData(std::string *vendor, std::string *renderer,
std::string *version)
{
#ifndef SERVER_ONLY
*vendor = (char*)glGetString(GL_VENDOR );
*renderer = (char*)glGetString(GL_RENDERER);
*version = (char*)glGetString(GL_VERSION );
#endif
} // getOpenGLData
//-----------------------------------------------------------------------------
@ -783,6 +814,7 @@ core::position2di IrrDriver::getMouseLocation()
*/
bool IrrDriver::moveWindow(int x, int y)
{
#ifndef SERVER_ONLY
#ifdef WIN32
const video::SExposedVideoData& videoData =
m_video_driver->getExposedVideoData();
@ -821,6 +853,7 @@ bool IrrDriver::moveWindow(int x, int y)
// TODO: Actually handle possible failure
XMoveWindow(display, videoData.OpenGLLinux.X11Window, x, y);
#endif
#endif
return true;
}
@ -850,6 +883,7 @@ void IrrDriver::changeResolution(const int w, const int h,
void IrrDriver::applyResolutionSettings()
{
#ifndef SERVER_ONLY
// show black before resolution switch so we don't see OpenGL's buffer
// garbage during switch
m_video_driver->beginScene(true, true, video::SColor(255,100,101,140));
@ -939,6 +973,7 @@ void IrrDriver::applyResolutionSettings()
// above) - this happens dynamically when the tracks are loaded.
GUIEngine::reshowCurrentScreen();
MessageQueue::updatePosition();
#endif // !SERVER_ONLY
} // applyResolutionSettings
// ----------------------------------------------------------------------------
@ -1154,6 +1189,7 @@ scene::IMeshSceneNode *IrrDriver::addSphere(float radius,
m.EmissiveColor = color;
m.BackfaceCulling = false;
m.MaterialType = video::EMT_SOLID;
#ifndef SERVER_ONLY
//m.setTexture(0, getUnicolorTexture(video::SColor(128, 255, 105, 180)));
m.setTexture(0, getUnicolorTexture(color));
m.setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
@ -1167,6 +1203,7 @@ scene::IMeshSceneNode *IrrDriver::addSphere(float radius,
NULL, -1, "sphere");
return node;
}
#endif
scene::IMeshSceneNode *node = m_scene_manager->addMeshSceneNode(mesh);
return node;
@ -1192,6 +1229,9 @@ scene::IMeshSceneNode *IrrDriver::addMesh(scene::IMesh *mesh,
bool all_parts_colorized,
int frame_for_mesh)
{
#ifdef SERVER_ONLY
return m_scene_manager->addMeshSceneNode(mesh, parent);
#else
if (!CVS->isGLSL())
return m_scene_manager->addMeshSceneNode(mesh, parent);
@ -1210,6 +1250,7 @@ scene::IMeshSceneNode *IrrDriver::addMesh(scene::IMesh *mesh,
node->drop();
return node;
#endif
} // addMesh
// ----------------------------------------------------------------------------
@ -1233,6 +1274,7 @@ scene::ISceneNode *IrrDriver::addBillboard(const core::dimension2d< f32 > size,
bool alphaTesting)
{
scene::IBillboardSceneNode* node;
#ifndef SERVER_ONLY
if (CVS->isGLSL())
{
if (!parent)
@ -1243,13 +1285,14 @@ scene::ISceneNode *IrrDriver::addBillboard(const core::dimension2d< f32 > size,
node->drop();
}
else
#endif
node = m_scene_manager->addBillboardSceneNode(parent, size);
assert(node->getMaterialCount() > 0);
node->setMaterialTexture(0, texture);
if(alphaTesting)
node->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
return node;
} // addMesh
} // addBillboard
// ----------------------------------------------------------------------------
/** Creates a quad mesh with a given material.
@ -1391,13 +1434,16 @@ scene::IAnimatedMeshSceneNode *IrrDriver::addAnimatedMesh(scene::IAnimatedMesh *
const std::string& debug_name, scene::ISceneNode* parent,
RenderInfo* render_info, bool all_parts_colorized)
{
#ifndef SERVER_ONLY
if (!CVS->isGLSL())
{
#endif
return m_scene_manager->addAnimatedMeshSceneNode(mesh, parent, -1,
core::vector3df(0, 0, 0),
core::vector3df(0, 0, 0),
core::vector3df(1, 1, 1),
/*addIfMeshIsZero*/true);
#ifndef SERVER_ONLY
}
if (!parent)
@ -1408,6 +1454,7 @@ scene::IAnimatedMeshSceneNode *IrrDriver::addAnimatedMesh(scene::IAnimatedMesh *
core::vector3df(1, 1, 1), render_info, all_parts_colorized);
node->drop();
return node;
#endif
} // addAnimatedMesh
// ----------------------------------------------------------------------------
@ -1448,19 +1495,24 @@ scene::ISceneNode *IrrDriver::addSkyDome(video::ITexture *texture,
scene::ISceneNode *IrrDriver::addSkyBox(const std::vector<video::ITexture*> &texture,
const std::vector<video::ITexture*> &spherical_harmonics_textures)
{
#ifndef SERVER_ONLY
assert(texture.size() == 6);
m_renderer->addSkyBox(texture, spherical_harmonics_textures);
#endif
return m_scene_manager->addSkyBoxSceneNode(texture[0], texture[1],
texture[2], texture[3],
texture[4], texture[5]);
} // addSkyBox
// ----------------------------------------------------------------------------
void IrrDriver::suppressSkyBox()
{
#ifndef SERVER_ONLY
m_renderer->removeSkyBox();;
}
#endif
} // suppressSkyBox
// ----------------------------------------------------------------------------
/** Adds a camera to the scene.
@ -1811,13 +1863,17 @@ video::ITexture* IrrDriver::applyMask(video::ITexture* texture,
// ----------------------------------------------------------------------------
void IrrDriver::onLoadWorld()
{
#ifndef SERVER_ONLY
m_renderer->onLoadWorld();
}
// ----------------------------------------------------------------------------
#endif
} // onLoadWorld
// ----------------------------------------------------------------------------
void IrrDriver::onUnloadWorld()
{
m_renderer->onUnloadWorld();
}
} // onUnloadWorld
// ----------------------------------------------------------------------------
/** Sets the ambient light.
* \param light The colour of the light to set.
@ -1826,10 +1882,13 @@ void IrrDriver::onUnloadWorld()
*/
void IrrDriver::setAmbientLight(const video::SColorf &light, bool force_SH_computation)
{
#ifndef SERVER_ONLY
m_scene_manager->setAmbientLight(light);
m_renderer->setAmbientLight(light, force_SH_computation);
#endif
} // setAmbientLight
// ----------------------------------------------------------------------------
video::SColorf IrrDriver::getAmbientLight() const
{
return m_scene_manager->getAmbientLight();
@ -1840,6 +1899,7 @@ video::SColorf IrrDriver::getAmbientLight() const
*/
void IrrDriver::displayFPS()
{
#ifndef SERVER_ONLY
gui::IGUIFont* font = GUIEngine::getSmallFont();
core::rect<s32> position;
@ -1911,6 +1971,7 @@ void IrrDriver::displayFPS()
static video::SColor fpsColor = video::SColor(255, 0, 0, 0);
font->draw( fps_string.c_str(), position, fpsColor, false );
#endif
} // updateFPS
// ----------------------------------------------------------------------------
@ -2009,6 +2070,7 @@ void IrrDriver::update(float dt)
if (world)
{
#ifndef SERVER_ONLY
m_renderer->render(dt);
GUIEngine::Screen* current_screen = GUIEngine::getCurrentScreen();
@ -2025,6 +2087,7 @@ void IrrDriver::update(float dt)
debug_drawer->beginNextFrame();
}
}
#endif
}
else
{
@ -2094,10 +2157,16 @@ bool IrrDriver::OnEvent(const irr::SEvent &event)
// ----------------------------------------------------------------------------
bool IrrDriver::supportsSplatting()
{
#ifndef SERVER_ONLY
return CVS->isGLSL();
}
#else
return false;
#endif
} // supportsSplatting
// ----------------------------------------------------------------------------
#ifndef SERVER_ONLY
void IrrDriver::applyObjectPassShader(scene::ISceneNode * const node, bool rimlit)
{
if (!CVS->isGLSL())
@ -2175,6 +2244,8 @@ void IrrDriver::applyObjectPassShader()
applyObjectPassShader(m_scene_manager->getRootSceneNode());
}
#endif // !SERVER_ONLY
// ----------------------------------------------------------------------------
scene::ISceneNode *IrrDriver::addLight(const core::vector3df &pos,
@ -2182,6 +2253,7 @@ scene::ISceneNode *IrrDriver::addLight(const core::vector3df &pos,
float r, float g, float b,
bool sun, scene::ISceneNode* parent)
{
#ifndef SERVER_ONLY
if (CVS->isGLSL())
{
if (parent == NULL) parent = m_scene_manager->getRootSceneNode();
@ -2218,6 +2290,9 @@ scene::ISceneNode *IrrDriver::addLight(const core::vector3df &pos,
light->setRadius(radius);
return light;
}
#else
return NULL;
#endif
} // addLight
// ----------------------------------------------------------------------------

View File

@ -305,8 +305,10 @@ public:
void unsetTextureErrorMessage();
class GPUTimer &getGPUTimer(unsigned);
#ifndef SERVER_ONLY
std::unique_ptr<RenderTarget> createRenderTarget(const irr::core::dimension2du &dimension,
const std::string &name);
#endif
// ------------------------------------------------------------------------
/** Convenience function that loads a texture with default parameters

View File

@ -1,22 +1,24 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2015 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "graphics/lighting_passes.hpp"
#include "config/user_config.hpp"
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2015 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/lighting_passes.hpp"
#include "config/user_config.hpp"
#include "graphics/central_settings.hpp"
#include "graphics/glwrap.hpp"
#include "graphics/irr_driver.hpp"
@ -735,3 +737,4 @@ void LightingPasses::renderLightsScatter(GLuint depth_stencil_texture,
colors_framebuffer.getHeight());
} // renderLightsScatter
#endif

View File

@ -254,6 +254,7 @@ void LODNode::OnRegisterSceneNode()
m_previous_visibility = (shown ? WAS_SHOWN : WAS_HIDDEN);
m_last_tick = now;
#ifndef SERVER_ONLY
if (!CVS->isGLSL())
{
for (core::list<ISceneNode*>::Iterator it = Children.begin();
@ -262,7 +263,7 @@ void LODNode::OnRegisterSceneNode()
(*it)->updateAbsolutePosition();
}
}
#endif
scene::ISceneNode::OnRegisterSceneNode();
}
@ -296,5 +297,8 @@ void LODNode::add(int level, scene::ISceneNode* node, bool reparent)
node->drop();
node->updateAbsolutePosition();
#ifndef SERVER_ONLY
irr_driver->applyObjectPassShader(node);
#endif
}

View File

@ -716,6 +716,7 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
m_texname.c_str());
}
#ifndef SERVER_ONLY
// Backface culling
if(!m_backface_culling)
m->setFlag(video::EMF_BACK_FACE_CULLING, false);
@ -869,7 +870,7 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
}
m->setTexture(1, glossytex);
}
#endif
if (m_shader_type == SHADERTYPE_SOLID_UNLIT)
{
@ -1013,6 +1014,7 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
void Material::adjustForFog(scene::ISceneNode* parent, video::SMaterial *m,
bool use_fog) const
{
#ifndef SERVER_ONLY
if (CVS->isGLSL())
{
// to disable fog in the new pipeline, we slightly abuse the steps :
@ -1036,6 +1038,7 @@ void Material::adjustForFog(scene::ISceneNode* parent, video::SMaterial *m,
if (parent != NULL)
parent->setMaterialFlag(video::EMF_FOG_ENABLE, m_fog && use_fog);
}
#endif
} // adjustForFog
//-----------------------------------------------------------------------------
@ -1043,7 +1046,9 @@ void Material::adjustForFog(scene::ISceneNode* parent, video::SMaterial *m,
/** Callback from LOD nodes to create some effects */
void Material::onMadeVisible(scene::IMeshBuffer* who)
{
#ifndef SERVER_ONLY
if (!CVS->isGLSL()) return;
#endif
}
//-----------------------------------------------------------------------------
@ -1051,14 +1056,18 @@ void Material::onMadeVisible(scene::IMeshBuffer* who)
/** Callback from LOD nodes to create some effects */
void Material::onHidden(scene::IMeshBuffer* who)
{
#ifndef SERVER_ONLY
if (!CVS->isGLSL()) return;
#endif
}
//-----------------------------------------------------------------------------
void Material::isInitiallyHidden(scene::IMeshBuffer* who)
{
#ifndef SERVER_ONLY
if (!CVS->isGLSL()) return;
#endif
}
//-----------------------------------------------------------------------------

View File

@ -145,6 +145,7 @@ Material* MaterialManager::getDefaultMaterial(video::E_MATERIAL_TYPE shader_type
// Try to find a cleaner way
// If graphics are disabled, shaders should not be accessed (getShader
// asserts that shaders are initialised).
#ifndef SERVER_ONLY
if(!ProfileWorld::isNoGraphics() && CVS->isGLSL() &&
shader_type == Shaders::getShader(ShaderType::ES_OBJECT_UNLIT))
default_material->setShaderType(Material::SHADERTYPE_SOLID_UNLIT);
@ -156,7 +157,7 @@ Material* MaterialManager::getDefaultMaterial(video::E_MATERIAL_TYPE shader_type
// default_material->setShaderType(Material::SHADERTYPE_ALPHA_BLEND);
else
default_material->setShaderType(Material::SHADERTYPE_SOLID);
#endif
m_default_materials[shader_type] = default_material;
return default_material;
}

View File

@ -17,6 +17,8 @@
#include "graphics/materials.hpp"
#ifndef SERVER_ONLY
const STK::Tuple<size_t> DefaultMaterial::FirstPassTextures
= STK::Tuple<size_t>(1);
const STK::Tuple<size_t, size_t, size_t> DefaultMaterial::SecondPassTextures
@ -84,3 +86,5 @@ const STK::Tuple<size_t, size_t, size_t, size_t, size_t>
const STK::Tuple<> SplattingMat::ShadowTextures;
const STK::Tuple<size_t, size_t, size_t, size_t, size_t> SplattingMat::RSMTextures
= STK::Tuple<size_t, size_t, size_t, size_t, size_t>(1, 3, 4, 5, 6);
#endif

View File

@ -18,6 +18,8 @@
#ifndef HEADER_MATERIAL_TYPE_HPP
#define HEADER_MATERIAL_TYPE_HPP
#ifndef SERVER_ONLY
#include "graphics/shader.hpp"
#include "graphics/shaders.hpp"
#include "graphics/stk_mesh.hpp"
@ -871,4 +873,5 @@ struct SplattingMat
}; // SplattingMat
#endif //HEADER_MATERIAL_TYPE_HPP
#endif // !SERVER_ONLY
#endif // HEADER_MATERIAL_TYPE_HPP

View File

@ -328,6 +328,7 @@ void recalculateTangents(scene::IMesh* mesh, bool recalculate_normals, bool smoo
}
}
#ifndef SERVER_ONLY
bool MeshTools::isNormalMap(scene::IMeshBuffer* mb)
{
if (!CVS->isGLSL())
@ -335,6 +336,7 @@ bool MeshTools::isNormalMap(scene::IMeshBuffer* mb)
return (mb->getMaterial().MaterialType == Shaders::getShader(ES_NORMAL_MAP) &&
mb->getVertexType() != video::EVT_TANGENTS);
}
#endif
// Copied from irrlicht
scene::IMesh* MeshTools::createMeshWithTangents(scene::IMesh* mesh,

View File

@ -16,6 +16,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/particle_emitter.hpp"
#include "graphics/central_settings.hpp"
@ -764,3 +766,5 @@ void ParticleEmitter::resizeBox(float size)
}
#endif
}
#endif // !SERVER_ONLY

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
#ifndef SERVER_ONLY
#include "graphics/post_processing.hpp"
#include "config/user_config.hpp"
@ -1597,3 +1599,5 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode,
return out_fbo;
} // render
#endif // !SERVER_ONLY

View File

@ -147,7 +147,7 @@ Referee::Referee()
m_scene_node->setScale(m_st_scale.toIrrVector());
m_scene_node->setFrameLoop(m_st_first_start_frame,
m_st_last_start_frame);
#ifndef SERVER_ONLY
irr_driver->applyObjectPassShader(m_scene_node);
if (CVS->isGLSL() && CVS->isDefferedEnabled())
@ -156,6 +156,7 @@ Referee::Referee()
0.7f /* r */, 0.0 /* g */, 0.0f /* b */, false /* sun */, m_scene_node);
}
else
#endif
{
m_light = NULL;
}
@ -184,7 +185,9 @@ Referee::Referee(const AbstractKart &kart)
m_scene_node->setFrameLoop(m_st_first_rescue_frame,
m_st_last_rescue_frame);
#ifndef SERVER_ONLY
irr_driver->applyObjectPassShader(m_scene_node);
#endif
} // Referee
// ----------------------------------------------------------------------------

View File

@ -15,6 +15,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/render_target.hpp"
#include "graphics/2dutils.hpp"
@ -151,3 +152,5 @@ void GL3RenderTarget::draw2DImage(const irr::core::rect<s32>& dest_rect,
glDisable(GL_FRAMEBUFFER_SRGB);
} // draw2DImage
#endif // !SERVER_ONLY

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/rtts.hpp"
#include "config/user_config.hpp"
@ -58,14 +60,14 @@ RTT::RTT(size_t width, size_t height)
using namespace video;
using namespace core;
dimension2du res(width * UserConfigParams::m_scale_rtts_factor,
height * UserConfigParams::m_scale_rtts_factor);
dimension2du res(int(width * UserConfigParams::m_scale_rtts_factor),
int(height * UserConfigParams::m_scale_rtts_factor) );
const dimension2du half = res/2;
const dimension2du quarter = res/4;
const dimension2du eighth = res/8;
const u16 shadowside = 1024 * UserConfigParams::m_scale_rtts_factor;
const u16 shadowside = u16(1024 * UserConfigParams::m_scale_rtts_factor);
const dimension2du shadowsize0(shadowside, shadowside);
const dimension2du shadowsize1(shadowside / 2, shadowside / 2);
const dimension2du shadowsize2(shadowside / 4, shadowside / 4);
@ -350,3 +352,5 @@ RTT::~RTT()
}
}
#endif // !SERVER_ONLY

View File

@ -16,6 +16,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/shader.hpp"
#include "graphics/central_settings.hpp"
@ -362,3 +364,5 @@ GLuint ShaderBase::createVAO()
} // createVAO
// ============================================================================
#endif // !SERVER_ONLY

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#ifndef HEADER_SHADER_HPP
#define HEADER_SHADER_HPP
@ -383,3 +385,6 @@ public:
// ============================================================================
#endif
#endif // !SERVER_ONLY

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/shader_based_renderer.hpp"
#include "config/user_config.hpp"
@ -957,3 +959,5 @@ void ShaderBasedRenderer::renderToTexture(GL3RenderTarget *render_target,
irr_driver->getSceneManager()->setActiveCamera(NULL);
} //renderToTexture
#endif // !SERVER_ONLY

View File

@ -18,6 +18,8 @@
#ifndef HEADER_SHADER_BASED_RENDERER_HPP
#define HEADER_SHADER_BASED_RENDERER_HPP
#ifndef SERVER_ONLY
#include "graphics/abstract_renderer.hpp"
#include "graphics/draw_calls.hpp"
#include "graphics/lighting_passes.hpp"
@ -125,4 +127,5 @@ public:
};
#endif //HEADER_SHADER_BASED_RENDERER_HPP
#endif // !SERVER_ONLY
#endif // HEADER_SHADER_BASED_RENDERER_HPP

View File

@ -16,6 +16,8 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
/**
\page shaders_overview Shaders Overview
@ -421,3 +423,5 @@ Shaders::ColoredLine::ColoredLine()
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
} // Shaders::ColoredLine
#endif // !SERVER_ONLY

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#ifndef HEADER_SHADERS_HPP
#define HEADER_SHADERS_HPP
@ -176,3 +178,5 @@ public:
}; // class Shaders
#endif
#endif // SHADER_ONLY

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/shadow_matrices.hpp"
#include "config/user_config.hpp"
@ -523,3 +525,5 @@ void ShadowMatrices::renderShadowsDebug(const FrameBuffer &shadow_framebuffer,
renderWireFrameFrustrum(m_shadows_cam[3], 3);
glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height);
}
#endif // !SERVER_ONLY

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/shared_gpu_objects.hpp"
#include "graphics/central_settings.hpp"
@ -232,3 +234,6 @@ void SharedGPUObjects::reset()
{
m_has_been_initialised = false;
} // reset
#endif // !SERVER_ONLY

View File

@ -16,6 +16,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/show_curve.hpp"
#include "graphics/irr_driver.hpp"
@ -200,3 +202,6 @@ void ShowCurve::setPosition(const Vec3 &xyz)
m_scene_node->setPosition(xyz.toIrrVector());
} // setPosition
// ----------------------------------------------------------------------------
#endif // !SERVER_ONLY

View File

@ -131,12 +131,14 @@ void SkidMarks::update(float dt, bool force_skid_marks,
if (!is_skidding) // end skid marking
{
m_skid_marking = false;
#ifndef SERVER_ONLY
// The vertices and indices will not change anymore
// (till these skid mark quads are deleted)
m_left[m_current]->setHardwareMappingHint(scene::EHM_STATIC);
m_right[m_current]->setHardwareMappingHint(scene::EHM_STATIC);
if (STKMeshSceneNode* stkm = dynamic_cast<STKMeshSceneNode*>(m_nodes[m_current]))
stkm->setReloadEachFrame(false);
#endif
return;
}
@ -192,11 +194,13 @@ void SkidMarks::update(float dt, bool force_skid_marks,
custom_color);
new_mesh->addMeshBuffer(smq_right);
scene::IMeshSceneNode *new_node = irr_driver->addMesh(new_mesh, "skidmark");
#ifndef SERVER_ONLY
if (STKMeshSceneNode* stkm = dynamic_cast<STKMeshSceneNode*>(new_node))
stkm->setReloadEachFrame(true);
#ifdef DEBUG
std::string debug_name = m_kart.getIdent()+" (skid-mark)";
new_node->setName(debug_name.c_str());
#endif
#endif
// We don't keep a reference to the mesh here, so we have to decrement

View File

@ -15,6 +15,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/skybox.hpp"
#include "graphics/central_settings.hpp"
@ -375,4 +376,5 @@ void Skybox::render(const scene::ICameraSceneNode *camera) const
glBindVertexArray(0);
} // renderSkybox
#endif // !SERVER_ONLY

View File

@ -51,10 +51,12 @@ SlipStream::SlipStream(AbstractKart* kart) : MovingTexture(0, 0), m_kart(kart)
scene::IMeshBuffer* buffer = m_mesh->getMeshBuffer(0);
material->setMaterialProperties(&buffer->getMaterial(), buffer);
#ifndef SERVER_ONLY
STKMeshSceneNode* stk_node = dynamic_cast<STKMeshSceneNode*>(m_node);
if (stk_node != NULL)
stk_node->setReloadEachFrame(true);
m_mesh->drop();
#endif
#ifdef DEBUG
std::string debug_name = m_kart->getIdent()+" (slip-stream)";
@ -99,8 +101,10 @@ SlipStream::SlipStream(AbstractKart* kart) : MovingTexture(0, 0), m_kart(kart)
}
video::SMaterial &mat = buffer->getMaterial();
// Meshes need a texture, otherwise stk crashes.
#ifndef SERVER_ONLY
video::ITexture *red_texture = getUnicolorTexture(red);
mat.setTexture(0, red_texture);
#endif
buffer->recalculateBoundingBox();
m_mesh->setBoundingBox(buffer->getBoundingBox());
@ -231,7 +235,9 @@ void SlipStream::createMesh(Material* material)
} // for j<num_circles-1
material->setMaterialProperties(&buffer->getMaterial(), buffer);
#ifndef SERVER_ONLY
if (!CVS->isGLSL())
#endif
{
buffer->Material.setFlag(video::EMF_BACK_FACE_CULLING, false);
buffer->Material.setFlag(video::EMF_COLOR_MATERIAL, true);

View File

@ -15,6 +15,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/irr_driver.hpp"
#include "graphics/spherical_harmonics.hpp"
@ -528,3 +529,5 @@ void SphericalHarmonics::unprojectSH(size_t width, size_t height,
}
} // unprojectSH
#endif // !SERVER_ONLY

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/stk_animated_mesh.hpp"
#include "graphics/central_settings.hpp"
@ -344,3 +346,5 @@ void STKAnimatedMesh::resetSkinningState(scene::IAnimatedMesh* mesh)
m_skinned_mesh = NULL;
}
}
#endif // !SERVER_ONLY

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/stk_billboard.hpp"
#include "graphics/irr_driver.hpp"
@ -118,3 +120,6 @@ void STKBillboard::render()
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
} // render
#endif // !SERVER_ONLY

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/stk_mesh.hpp"
#include "graphics/callbacks.hpp"
@ -471,3 +473,6 @@ void initTexturesTransparent(GLMesh &mesh)
}
#endif
} // initTexturesTransparent
#endif // !SERVER_ONLY

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/stk_mesh_scene_node.hpp"
#include "graphics/central_settings.hpp"
@ -608,3 +610,6 @@ void STKMeshSceneNode::render()
}
}
}
#endif // !SERVER_ONLY

View File

@ -73,8 +73,10 @@ public:
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
if (!mb)
continue;
#ifndef SERVER_ONLY
if (isDisplacement)
mb->getMaterial().MaterialType = Shaders::getShader(ES_DISPLACE);
#endif
}
}
virtual bool glow() const { return isGlow; }

View File

@ -0,0 +1,67 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2014-2015 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/stk_scene_manager.hpp"
#include <SViewFrustum.h>
#include <vector>
using namespace irr;
// From irrlicht code
static
bool isBoxInFrontOfPlane(const core::plane3df &plane, const core::vector3df edges[8])
{
for (u32 j = 0; j<8; ++j)
if (plane.classifyPointRelation(edges[j]) != core::ISREL3D_FRONT)
return false;
return true;
}
std::vector<float> BoundingBoxes;
void addEdge(const core::vector3df &P0, const core::vector3df &P1)
{
BoundingBoxes.push_back(P0.X);
BoundingBoxes.push_back(P0.Y);
BoundingBoxes.push_back(P0.Z);
BoundingBoxes.push_back(P1.X);
BoundingBoxes.push_back(P1.Y);
BoundingBoxes.push_back(P1.Z);
}
bool isCulledPrecise(const scene::ICameraSceneNode *cam, const scene::ISceneNode *node)
{
if (!node->getAutomaticCulling())
return false;
const core::matrix4 &trans = node->getAbsoluteTransformation();
const scene::SViewFrustum &frust = *cam->getViewFrustum();
core::vector3df edges[8];
node->getBoundingBox().getEdges(edges);
for (unsigned i = 0; i < 8; i++)
trans.transformVect(edges[i]);
for (s32 i = 0; i < scene::SViewFrustum::VF_PLANE_COUNT; ++i)
if (isBoxInFrontOfPlane(frust.planes[i], edges))
return true;
return false;
}
#endif // !SERVER_ONLY

View File

@ -0,0 +1,37 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2014-2015 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// Not really a scene manager yet but hold algorithm that
// rework scene manager output
#ifndef SERVER_ONLY
#ifndef HEADER_STKSCENEMANAGER_HPP
#define HEADER_STKSCENEMANAGER_HPP
#include <ICameraSceneNode.h>
#include <ISceneNode.h>
#include <vector3d.h>
void addEdge(const irr::core::vector3df &P0, const irr::core::vector3df &P1);
bool isCulledPrecise(const irr::scene::ICameraSceneNode *cam, const irr::scene::ISceneNode *node);
#endif
#endif // supertuxkart

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/stk_text_billboard.hpp"
#include "graphics/shaders.hpp"
#include "graphics/irr_driver.hpp"
@ -190,3 +192,6 @@ void STKTextBillboard::collectChar(video::ITexture* texture,
{
m_chars.push_back(STKTextBillboardChar(texture, destRect, sourceRect, colors));
}
#endif // !SERVER_ONLY

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/texture_manager.hpp"
#include "graphics/central_settings.hpp"
@ -277,3 +279,6 @@ video::ITexture* getUnicolorTexture(const video::SColor &c)
return tex;
}
}
#endif // !SERVER_ONLY

View File

@ -16,6 +16,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/texture_shader.hpp"
#include "graphics/central_settings.hpp"
@ -366,3 +368,6 @@ GLuint TextureShaderBase::createSemiTrilinearSampler()
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#endif // !SERVER_ONLY

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SHADER_ONLY
#ifndef HEADER_TEXTURE_SHADER_HPP
#define HEADER_TEXTURE_SHADER_HPP
@ -259,3 +261,5 @@ public:
}; // class TextureShader
#endif
#endif // SHADER_ONLY

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/vao_manager.hpp"
#include "graphics/central_settings.hpp"
@ -367,3 +369,5 @@ std::pair<unsigned, unsigned> VAOManager::getBase(scene::IMeshBuffer *mb, Render
assert(It != mappedBaseIndex[tp].end());
return std::pair<unsigned, unsigned>(vtx, It->second);
}
#endif // !SERVER_ONLY

View File

@ -16,6 +16,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "graphics/water.hpp"
#include "graphics/callbacks.hpp"
@ -89,3 +91,6 @@ void WaterNode::OnRegisterSceneNode()
ISceneNode::OnRegisterSceneNode();
}
}
#endif // !SERVER_ONLY

View File

@ -174,6 +174,7 @@ void STKModifiedSpriteBank::draw2DSprite(u32 index,
const core::rect<s32>* clip, const video::SColor& color,
u32 starttime, u32 currenttime, bool loop, bool center)
{
#ifndef SERVER_ONLY
assert( m_magic_number == 0xCAFEC001 );
if (index >= Sprites.size() || Sprites[index].Frames.empty() )
return;
@ -221,7 +222,7 @@ void STKModifiedSpriteBank::draw2DSprite(u32 index,
*/
draw2DImage(tex, dest, r /* source rect */, clip,
NULL /* colors */, true);
#endif
} // draw2DSprite
// ----------------------------------------------------------------------------

View File

@ -664,7 +664,9 @@ namespace GUIEngine
#include "font/regular_face.hpp"
#include "input/input_manager.hpp"
#include "io/file_manager.hpp"
#ifndef SERVER_ONLY
#include "graphics/2dutils.hpp"
#endif
#include "graphics/irr_driver.hpp"
#include "guiengine/event_handler.hpp"
#include "guiengine/modaldialog.hpp"
@ -1121,6 +1123,7 @@ namespace GUIEngine
void render(float elapsed_time)
{
#ifndef SERVER_ONLY
GUIEngine::dt = elapsed_time;
// Not yet initialized, or already cleaned up
@ -1208,7 +1211,6 @@ namespace GUIEngine
y_from - count*text_height),
core::dimension2d<s32>(screen_size.Width,
text_height) );
GL32_draw2DRectangle(SColor(255,252,248,230),
msgRect);
Private::g_font->draw((*it).m_message.c_str(),
@ -1244,7 +1246,7 @@ namespace GUIEngine
DemoWorld::resetIdleTime();
}
#endif
} // render
// -----------------------------------------------------------------------
@ -1252,6 +1254,7 @@ namespace GUIEngine
void renderLoading(bool clearIcons)
{
#ifndef SERVER_ONLY
if (clearIcons) g_loading_icons.clear();
g_skin->drawBgImage();
@ -1315,7 +1318,7 @@ namespace GUIEngine
x = ICON_MARGIN;
}
}
#endif
} // renderLoading
// -----------------------------------------------------------------------

View File

@ -93,6 +93,8 @@ void ScalableFont::draw(const core::stringw& text,
const video::SColor& color, bool hcenter, bool vcenter,
const core::rect<s32>* clip, bool ignoreRTL)
{
#ifndef SERVER_ONLY
bool previousRTL = m_font_settings->isRTL();
if (ignoreRTL)
m_font_settings->setRTL(false);
@ -102,7 +104,7 @@ void ScalableFont::draw(const core::stringw& text,
if (ignoreRTL)
m_font_settings->setRTL(previousRTL);
#endif
} // draw
// ----------------------------------------------------------------------------

View File

@ -326,7 +326,7 @@ Skin::~Skin()
// ----------------------------------------------------------------------------
void Skin::drawBgImage()
{
#ifndef SERVER_ONLY
// ---- background image
// on one end, making these static is not too clean.
// on another end, these variables are really only used locally,
@ -370,6 +370,7 @@ void Skin::drawBgImage()
/* no clipping */0, /*color*/ 0,
/*alpha*/false);
irr_driver->getVideoDriver()->enableMaterial2D(false);
#endif
} // drawBgImage
// ----------------------------------------------------------------------------
@ -401,6 +402,7 @@ void Skin::drawBoxFromStretchableTexture(SkinWidgetContainer* w,
bool deactivated,
const core::recti* clipRect)
{
#ifndef SERVER_ONLY
// check if widget moved. if so, recalculate coords
if (w->m_skin_x != dest.UpperLeftCorner.X ||
w->m_skin_y != dest.UpperLeftCorner.Y ||
@ -701,7 +703,7 @@ X##_yflip.LowerRightCorner.Y = w->m_skin_dest_y + \
{
delete[] colorptr;
}
#endif
} // drawBoxFromStretchableTexture
// ----------------------------------------------------------------------------
@ -844,6 +846,7 @@ void Skin::drawProgress(Widget* w, const core::recti &rect,
void Skin::drawRatingBar(Widget *w, const core::recti &rect,
const bool pressed, const bool focused)
{
#ifndef SERVER_ONLY
RatingBarWidget *ratingBar = (RatingBarWidget*)w;
const ITexture *texture = SkinConfig::m_render_params["rating::neutral"].getImage();
@ -897,7 +900,7 @@ void Skin::drawRatingBar(Widget *w, const core::recti &rect,
(w->m_deactivated || ID_DEBUG) ? colors : 0,
true /* alpha */);
}
#endif
} // drawRatingBar
// ----------------------------------------------------------------------------
@ -921,6 +924,7 @@ void Skin::drawRibbon(const core::recti &rect, Widget* widget,
void Skin::drawRibbonChild(const core::recti &rect, Widget* widget,
const bool pressed, bool focused)
{
#ifndef SERVER_ONLY
// for now, when this kind of widget is disabled, just hide it. we can
// change that behaviour if we ever need to...
//if (widget->m_deactivated) return;
@ -1220,6 +1224,7 @@ void Skin::drawRibbonChild(const core::recti &rect, Widget* widget,
m_tooltips.push_back(widget);
}
}
#endif
} // drawRibbonChild
// ----------------------------------------------------------------------------
@ -1435,6 +1440,7 @@ void Skin::drawSpinnerChild(const core::recti &rect, Widget* widget,
void Skin::drawIconButton(const core::recti &rect, Widget* widget,
const bool pressed, bool focused)
{
#ifndef SERVER_ONLY
RibbonWidget* parentRibbon = dynamic_cast<RibbonWidget*>(widget->m_event_handler);
IGUIElement* focusedElem = NULL;
if (GUIEngine::getFocusForPlayer(PLAYER_ID_GAME_MASTER) != NULL)
@ -1543,6 +1549,7 @@ void Skin::drawIconButton(const core::recti &rect, Widget* widget,
{
irr_driver->getVideoDriver()->enableMaterial2D();
}
#endif
} // drawIconButton
// ----------------------------------------------------------------------------
@ -1662,6 +1669,7 @@ void Skin::drawListSelection(const core::recti &rect, Widget* widget,
void Skin::drawListHeader(const irr::core::rect< irr::s32 > &rect,
Widget* widget)
{
#ifndef SERVER_ONLY
bool isSelected =
(((ListWidget*)widget->m_event_handler)->m_selected_column == widget &&
((ListWidget*)widget->m_event_handler)->m_sort_default == false);
@ -1689,7 +1697,7 @@ void Skin::drawListHeader(const irr::core::rect< irr::s32 > &rect,
draw2DImage(img, destRect, srcRect,
NULL, NULL, /* alpha */true);
}
#endif
} // drawListHeader
// ----------------------------------------------------------------------------
@ -1698,6 +1706,7 @@ void Skin::drawListHeader(const irr::core::rect< irr::s32 > &rect,
*/
void Skin::renderSections(PtrVector<Widget>* within_vector)
{
#ifndef SERVER_ONLY
if (within_vector == NULL) within_vector = &getCurrentScreen()->m_widgets;
const unsigned short widgets_amount = within_vector->size();
@ -1770,12 +1779,13 @@ void Skin::renderSections(PtrVector<Widget>* within_vector)
}
}
} // next
#endif // !SERVER_ONLY
} // renderSections
// ----------------------------------------------------------------------------
void Skin::drawScrollbarBackground(const irr::core::rect< irr::s32 > &rect)
{
#ifndef SERVER_ONLY
// leave square space at both ends for up/down buttons (yeah, irrlicht
// doesn't handle that)
core::recti rect2 = rect;
@ -1789,12 +1799,13 @@ void Skin::drawScrollbarBackground(const irr::core::rect< irr::s32 > &rect)
p.m_source_area_center,
0 /* no clipping */, 0,
true /* alpha */);
#endif
} // drawScrollbarBackground
// ----------------------------------------------------------------------------
void Skin::drawScrollbarThumb(const irr::core::rect< irr::s32 > &rect)
{
#ifndef SERVER_ONLY
BoxRenderParams& p =
SkinConfig::m_render_params["scrollbar_thumb::neutral"];
@ -1802,7 +1813,7 @@ void Skin::drawScrollbarThumb(const irr::core::rect< irr::s32 > &rect)
p.m_source_area_center,
0 /* no clipping */, 0,
true /* alpha */);
#endif
} // drawScrollbarThumb
// ----------------------------------------------------------------------------
@ -1958,7 +1969,9 @@ void Skin::process3DPane(IGUIElement *element, const core::recti &rect,
else if (type == WTYPE_MODEL_VIEW)
{
ModelViewWidget* mvw = dynamic_cast<ModelViewWidget*>(widget);
#ifndef SERVER_ONLY
mvw->drawRTTScene(rect);
#endif
}
else if (type == WTYPE_ICON_BUTTON)
{
@ -2016,6 +2029,7 @@ void Skin::process3DPane(IGUIElement *element, const core::recti &rect,
void doDrawBadge(ITexture* texture, const core::recti& rect,
float max_icon_size, bool badge_at_left)
{
#ifndef SERVER_ONLY
// In case of a problem
if(!texture) return;
@ -2041,6 +2055,7 @@ void doDrawBadge(ITexture* texture, const core::recti& rect,
draw2DImage(texture, rect2, source_area,
0 /* no clipping */, 0,
true /* alpha */);
#endif
} // doDrawBadge
// ----------------------------------------------------------------------------
@ -2139,6 +2154,7 @@ void Skin::draw3DSunkenPane (IGUIElement *element, video::SColor bgcolor,
bool flat, bool fillBackGround,
const core::recti &rect, const core::recti *clip)
{
#ifndef SERVER_ONLY
const int id = element->getID();
Widget* widget = GUIEngine::getWidget(id);
@ -2257,18 +2273,21 @@ void Skin::draw3DSunkenPane (IGUIElement *element, video::SColor bgcolor,
return;
}
#endif
} // draw3DSunkenPane
// -----------------------------------------------------------------------------
void Skin::drawBGFadeColor()
{
#ifndef SERVER_ONLY
// fade out background
SColor color = SkinConfig::m_colors["dialog_background::neutral"];
if (m_dialog_size < 1.0f)
color.setAlpha( (unsigned int)(color.getAlpha()*m_dialog_size ));
GL32_draw2DRectangle(color, core::recti(position2d< s32 >(0,0),
irr_driver->getActualScreenSize()));
#endif
} // drawBGFadeColor
// -----------------------------------------------------------------------------
@ -2316,8 +2335,10 @@ core::recti Skin::draw3DWindowBackground(IGUIElement *element,
void Skin::draw3DMenuPane (IGUIElement *element, const core::recti &rect,
const core::recti *clip)
{
#ifndef SERVER_ONLY
SColor color = SColor(150, 96, 74, 196);
GL32_draw2DRectangle(color, rect);
#endif
} // draw3DMenuPane
// -----------------------------------------------------------------------------
@ -2376,7 +2397,9 @@ void Skin::draw2DImage(const video::ITexture* texture, const core::rect<s32>& de
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect,
const video::SColor* const colors, bool useAlphaChannelOfTexture)
{
#ifndef SERVER_ONLY
::draw2DImage(texture, destRect, sourceRect, clipRect, colors, useAlphaChannelOfTexture);
#endif
}
// -----------------------------------------------------------------------------

View File

@ -99,6 +99,7 @@ CGUIEditBox::CGUIEditBox(const wchar_t* text, bool border,
//! destructor
CGUIEditBox::~CGUIEditBox()
{
#ifndef SERVER_ONLY
if (OverrideFont)
OverrideFont->drop();
@ -108,6 +109,7 @@ CGUIEditBox::~CGUIEditBox()
CIrrDeviceLinux* dl = dynamic_cast<CIrrDeviceLinux*>(irr_driver->getDevice());
dl->setIMEEnable(false);
#endif
#endif
}
@ -235,6 +237,7 @@ void CGUIEditBox::setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT ver
//! called if an event happened.
bool CGUIEditBox::OnEvent(const SEvent& event)
{
#ifndef SERVER_ONLY
if (isEnabled())
{
@ -280,7 +283,7 @@ bool CGUIEditBox::OnEvent(const SEvent& event)
break;
}
}
#endif
return IGUIElement::OnEvent(event);
}
@ -903,6 +906,7 @@ core::position2di CGUIEditBox::calculateICPos()
//! draws the element and its children
void CGUIEditBox::draw()
{
#ifndef SERVER_ONLY
if (!IsVisible)
return;
@ -1104,6 +1108,7 @@ void CGUIEditBox::draw()
// draw children
IGUIElement::draw();
#endif
}
@ -1563,6 +1568,7 @@ void CGUIEditBox::inputChar(wchar_t c)
void CGUIEditBox::calculateScrollPos()
{
#ifndef SERVER_ONLY
if (!AutoScroll)
return;
@ -1616,6 +1622,7 @@ void CGUIEditBox::calculateScrollPos()
dl->setIMELocation(calculateICPos());
}
#endif
#endif // SERVER_ONLY
}
//! set text markers

View File

@ -52,13 +52,17 @@ IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO, false,
m_properties[PROP_ICON]="gui/main_help.png";
m_rtt_unsupported = false;
}
} // ModelViewWidget
// -----------------------------------------------------------------------------
ModelViewWidget::~ModelViewWidget()
{
GUIEngine::needsUpdate.remove(this);
#ifndef SERVER_ONLY
delete m_render_info;
}
#endif
} // ~ModelViewWidget
// -----------------------------------------------------------------------------
void ModelViewWidget::add()
{
@ -92,7 +96,7 @@ void ModelViewWidget::clearModels()
m_rtt_main_node = NULL;
m_camera = NULL;
m_light = NULL;
}
} // clearModels
// -----------------------------------------------------------------------------
@ -107,10 +111,11 @@ void ModelViewWidget::addModel(irr::scene::IMesh* mesh, const Vec3& location,
m_model_scale.push_back(scale);
m_model_frames.push_back(frame);
m_model_render_info_affected.push_back(all_parts_colorized);
#ifndef SERVER_ONLY
if (!CVS->isGLSL())
m_render_target = NULL;
}
#endif
} // addModel
// -----------------------------------------------------------------------------
void ModelViewWidget::update(float delta)
@ -161,7 +166,10 @@ void ModelViewWidget::update(float delta)
// stop rotating when target reached
if (fabsf(m_angle - m_rotation_target) < 2.0f) m_rotation_mode = ROTATE_OFF;
}
#ifdef SERVER_ONLY
return;
#else
if (m_render_target == NULL)
{
std::string name = "model view ";
@ -181,10 +189,13 @@ void ModelViewWidget::update(float delta)
m_render_target->renderToTexture(m_camera, GUIEngine::getLatestDt());
m_rtt_main_node->setVisible(false);
}
#endif
} // update
// ----------------------------------------------------------------------------
void ModelViewWidget::setupRTTScene()
{
#ifndef SERVER_ONLY
irr_driver->suppressSkyBox();
if (m_rtt_main_node != NULL) m_rtt_main_node->remove();
@ -297,42 +308,57 @@ void ModelViewWidget::setupRTTScene()
m_camera->setFOV(DEGREE_TO_RAD*50.0f);
m_camera->updateAbsolutePosition();
}
#endif
} // setupRTTScene
// ----------------------------------------------------------------------------
void ModelViewWidget::setRotateOff()
{
m_rotation_mode = ROTATE_OFF;
}
} // setRotateOff
// ----------------------------------------------------------------------------
void ModelViewWidget::setRotateContinuously(float speed)
{
m_rotation_mode = ROTATE_CONTINUOUSLY;
m_rotation_speed = speed;
}
} // setRotateContinuously
// ----------------------------------------------------------------------------
void ModelViewWidget::setRotateTo(float targetAngle, float speed)
{
m_rotation_mode = ROTATE_TO;
m_rotation_speed = speed;
m_rotation_target = targetAngle;
}
} // setRotateTo
// ----------------------------------------------------------------------------
bool ModelViewWidget::isRotating()
{
return m_rotation_mode != ROTATE_OFF ? true : false;
}
} // isRotating
// ----------------------------------------------------------------------------
void ModelViewWidget::elementRemoved()
{
#ifndef SERVER_ONLY
m_render_target = NULL;
IconButtonWidget::elementRemoved();
}
#endif
} // elementRemoved
// ----------------------------------------------------------------------------
void ModelViewWidget::clearRttProvider()
{
m_render_target = NULL;
}
} // clearRttProvider
// ----------------------------------------------------------------------------
void ModelViewWidget::drawRTTScene(const irr::core::rect<s32>& dest_rect) const
{
#ifndef SERVER_ONLY
if(m_render_target != NULL)
m_render_target->draw2DImage(dest_rect, NULL, video::SColor(255, 255, 255, 255), true);
}
#endif
} // drawRTTScene

View File

@ -182,7 +182,7 @@ void Attachment::set(AttachmentType type, float time,
}
}
m_node->setVisible(true);
#ifndef SERVER_ONLY
irr_driver->applyObjectPassShader(m_node);
// Save event about the new attachment
@ -193,6 +193,7 @@ void Attachment::set(AttachmentType type, float time,
saveState(buffer);
rwm->addEvent(this, buffer);
}
#endif
} // set
// -----------------------------------------------------------------------------

View File

@ -76,6 +76,7 @@ Flyable::Flyable(AbstractKart *kart, PowerupManager::PowerupType type,
m_max_lifespan = -1;
// Add the graphical model
#ifndef SERVER_ONLY
setNode(irr_driver->addMesh(m_st_model[type], StringUtils::insertValues("flyable_%i", (int)type)));
irr_driver->applyObjectPassShader(getNode());
#ifdef DEBUG
@ -83,7 +84,7 @@ Flyable::Flyable(AbstractKart *kart, PowerupManager::PowerupType type,
debug_name += type;
getNode()->setName(debug_name.c_str());
#endif
#endif
} // Flyable
// ----------------------------------------------------------------------------

View File

@ -185,6 +185,7 @@ void Item::switchTo(ItemType type, scene::IMesh *mesh, scene::IMesh *lowmesh)
scene::ISceneNode* node = m_node->getAllNodes()[0];
((scene::IMeshSceneNode*)node)->setMesh(mesh);
#ifndef SERVER_ONLY
if (lowmesh != NULL)
{
node = m_node->getAllNodes()[1];
@ -195,6 +196,7 @@ void Item::switchTo(ItemType type, scene::IMesh *mesh, scene::IMesh *lowmesh)
irr_driver->applyObjectPassShader(m_node->getAllNodes()[0]);
World::getWorld()->getTrack()->adjustForFog(m_node);
#endif
} // switchTo
//-----------------------------------------------------------------------------

View File

@ -68,14 +68,17 @@ RubberBand::RubberBand(Plunger *plunger, AbstractKart *kart)
verts[i].Color = color;
}
#ifndef SERVER_ONLY
// Color
mb->getMaterial().setTexture(0, getUnicolorTexture(video::SColor(255, 255, 255, 255)));
// Gloss
mb->getMaterial().setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
// Colorization mask
mb->getMaterial().setTexture(2, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
#endif
updatePosition();
m_node = irr_driver->addMesh(m_mesh, "rubberband");
#ifndef SERVER_ONLY
irr_driver->applyObjectPassShader(m_node);
if (STKMeshSceneNode *stkm = dynamic_cast<STKMeshSceneNode *>(m_node))
stkm->setReloadEachFrame(true);
@ -83,6 +86,7 @@ RubberBand::RubberBand(Plunger *plunger, AbstractKart *kart)
std::string debug_name = m_owner->getIdent()+" (rubber-band)";
m_node->setName(debug_name.c_str());
#endif
#endif
} // RubberBand

View File

@ -73,6 +73,7 @@ LocalPlayerController::LocalPlayerController(AbstractKart *kart,
// Attach Particle System
Track *track = World::getWorld()->getTrack();
#ifndef SERVER_ONLY
if (UserConfigParams::m_weather_effects &&
track->getSkyParticles() != NULL)
{
@ -88,7 +89,7 @@ LocalPlayerController::LocalPlayerController(AbstractKart *kart,
// of the heightmap being calculated and kept in memory
m_sky_particles_emitter->addHeightMapAffector(track);
}
#endif
} // LocalPlayerController
//-----------------------------------------------------------------------------
@ -191,6 +192,7 @@ void LocalPlayerController::update(float dt)
// look backward when the player requests or
// if automatic reverse camera is active
#ifndef SERVER_ONLY
Camera *camera = Camera::getCamera(m_camera_index);
if (camera->getType() != Camera::CM_TYPE_END)
{
@ -217,7 +219,7 @@ void LocalPlayerController::update(float dt)
}
}
}
#endif
if (m_kart->getKartAnimation() && m_sound_schedule == false &&
m_kart->getAttachment()->getType() != Attachment::ATTACH_TINYTUX)
{
@ -299,8 +301,11 @@ void LocalPlayerController::handleZipper(bool play_sound)
m_wee_sound->play();
}
#ifndef SERVER_ONLY
// Apply the motion blur according to the speed of the kart
irr_driver->giveBoost(m_camera_index);
#endif
} // handleZipper
//-----------------------------------------------------------------------------

View File

@ -212,7 +212,11 @@ void Kart::init(RaceManager::KartType type)
}
#ifdef SERVER_ONLY
bool animations = false; // server never animates
#else
bool animations = true;
#endif
const int anims = UserConfigParams::m_show_steering_animations;
if (anims == ANIMS_NONE)
{
@ -333,9 +337,10 @@ void Kart::reset()
m_kart_gfx->reset();
m_skidding->reset();
#ifndef SERVER_ONLY
if (m_collision_particles)
m_collision_particles->setCreationRateAbsolute(0.0f);
#endif
m_race_position = m_initial_position;
m_finished_race = false;
@ -2051,6 +2056,7 @@ void Kart::crashed(const Material *m, const Vec3 &normal)
if(m && m->getCollisionReaction() != Material::NORMAL &&
!getKartAnimation())
{
#ifndef SERVER_ONLY
std::string particles = m->getCrashResetParticles();
if (particles.size() > 0)
{
@ -2076,7 +2082,7 @@ void Kart::crashed(const Material *m, const Vec3 &normal)
"crash-reset properties\n", particles.c_str());
}
}
#endif
if (m->getCollisionReaction() == Material::RESCUE)
{
new RescueAnimation(this);
@ -2542,12 +2548,13 @@ void Kart::loadData(RaceManager::KartType type, bool is_animated_model)
track_manager->getTrack(race_manager->getTrackName())
->isFogEnabled() );
}
#ifndef SERVER_ONLY
if (!CVS->supportsShadows())
{
m_shadow = new Shadow(m_kart_properties.get(), m_node,
-m_kart_model->getLowestPoint());
}
#endif
World::getWorld()->kartAdded(this, m_node);
} // loadData
@ -2857,6 +2864,7 @@ btQuaternion Kart::getVisualRotation() const
*/
void Kart::setOnScreenText(const wchar_t *text)
{
#ifndef SERVER_ONLY
BoldFace* bold_face = font_manager->getFont<BoldFace>();
core::dimension2d<u32> textsize = bold_face->getDimension(text);
@ -2889,6 +2897,7 @@ void Kart::setOnScreenText(const wchar_t *text)
// No need to store the reference to the billboard scene node:
// It has one reference to the parent, and will get deleted
// when the parent is deleted.
#endif
} // setOnScreenText
// ------------------------------------------------------------------------

View File

@ -52,6 +52,7 @@ KartGFX::KartGFX(const AbstractKart *kart)
scene::ISceneNode *node = m_kart->getNode();
// Create nitro light
core::vector3df location(0.0f, 0.5f, -0.5f*length - 0.05f);
#ifndef SERVER_ONLY
m_nitro_light = irr_driver->addLight(location, /*force*/ 0.4f,
/*radius*/CVS->isGLSL() ? 5.0f : 1.0f,
0.0f, 0.4f, 1.0f,
@ -82,13 +83,16 @@ KartGFX::KartGFX(const AbstractKart *kart)
m_skidding_light_2->setVisible(false);
m_skidding_light_2->setName( ("skidding emitter 2 (" + m_kart->getIdent()
+ ")").c_str() );
#endif
#ifndef SERVER_ONLY
if (CVS->isGLSL())
{
m_nitro_light->grab();
m_skidding_light_1->grab();
m_skidding_light_2->grab();
}
#endif
// Create particle effects
Vec3 rear_left(kart->getWheelGraphicsPosition(3).getX(), 0.05f,
@ -131,13 +135,15 @@ KartGFX::~KartGFX()
if(m_all_emitters[i])
delete m_all_emitters[i];
} // for i < KGFX_COUNT
#ifndef SERVER_ONLY
if (CVS->isGLSL())
{
m_nitro_light->drop();
m_skidding_light_1->drop();
m_skidding_light_2->drop();
}
#endif
} // ~KartGFX
@ -151,6 +157,7 @@ KartGFX::~KartGFX()
void KartGFX::addEffect(KartGFXType type, const std::string &file_name,
const Vec3 &position, bool important)
{
#ifndef SERVER_ONLY
if (!UserConfigParams::m_graphical_effects &&
(!important || m_kart->getType() == RaceManager::KT_AI ||
m_kart->getType() == RaceManager::KT_SPARE_TIRE))
@ -196,6 +203,7 @@ void KartGFX::addEffect(KartGFXType type, const std::string &file_name,
m_skid_kind1 = kind;
else if (type==KGFX_SKID2L || type==KGFX_SKID2R)
m_skid_kind2 = kind;
#endif
} // addEffect
// ----------------------------------------------------------------------------
@ -204,6 +212,7 @@ void KartGFX::addEffect(KartGFXType type, const std::string &file_name,
void KartGFX::reset()
{
m_wheel_toggle = 1;
#ifndef SERVER_ONLY
for(unsigned int i=0; i<m_all_emitters.size(); i++)
{
if(m_all_emitters[i])
@ -212,6 +221,7 @@ void KartGFX::reset()
m_all_emitters[i]->clearParticles();
}
}
#endif
} // reset
// ----------------------------------------------------------------------------
@ -224,6 +234,7 @@ void KartGFX::setSkidLevel(const unsigned int level)
assert(level >= 1);
assert(level <= 2);
const ParticleKind *pk = level==1 ? m_skid_kind1 : m_skid_kind2;
#ifndef SERVER_ONLY
if(m_all_emitters[KGFX_SKID1L])
m_all_emitters[KGFX_SKID1L]->setParticleType(pk);
if(m_all_emitters[KGFX_SKID1R])
@ -232,6 +243,7 @@ void KartGFX::setSkidLevel(const unsigned int level)
// set to indicate that the bonus is now available.
setCreationRateRelative(KartGFX::KGFX_SKIDL, 0.0f);
setCreationRateRelative(KartGFX::KGFX_SKIDR, 0.0f);
#endif
} // setSkidLevel
// ----------------------------------------------------------------------------
@ -242,10 +254,12 @@ void KartGFX::setSkidLevel(const unsigned int level)
*/
void KartGFX::setParticleKind(const KartGFXType type, const ParticleKind *pk)
{
#ifndef SERVER_ONLY
ParticleEmitter *pe = m_all_emitters[KGFX_TERRAIN];
if(!pe) return;
pe->setParticleType(pk);
#endif
} // setParticleKind
// ----------------------------------------------------------------------------
@ -255,9 +269,11 @@ void KartGFX::setParticleKind(const KartGFXType type, const ParticleKind *pk)
*/
void KartGFX::setXYZ(const KartGFXType type, const Vec3 &xyz)
{
#ifndef SERVER_ONLY
ParticleEmitter *pe = m_all_emitters[KGFX_TERRAIN];
if(!pe) return;
pe->setPosition(xyz);
#endif
} // setXYZ
// ----------------------------------------------------------------------------
@ -268,8 +284,10 @@ void KartGFX::setXYZ(const KartGFXType type, const Vec3 &xyz)
*/
void KartGFX::setCreationRateAbsolute(KartGFXType type, float f)
{
#ifndef SERVER_ONLY
if(m_all_emitters[type])
m_all_emitters[type]->setCreationRateAbsolute(f);
#endif
} // setCreationRateAbsolute
// ----------------------------------------------------------------------------
@ -282,6 +300,7 @@ void KartGFX::setCreationRateAbsolute(KartGFXType type, float f)
*/
void KartGFX::setCreationRateRelative(KartGFXType type, float f)
{
#ifndef SERVER_ONLY
if(m_all_emitters[type])
{
if(f<0)
@ -289,6 +308,7 @@ void KartGFX::setCreationRateRelative(KartGFXType type, float f)
else
m_all_emitters[type]->setCreationRateRelative(f);
}
#endif
} // setCreationRateRelative
// ----------------------------------------------------------------------------
@ -301,8 +321,10 @@ void KartGFX::setCreationRateRelative(KartGFXType type, float f)
*/
void KartGFX::resizeBox(KartGFXType type, float new_size)
{
#ifndef SERVER_ONLY
if(m_all_emitters[type])
m_all_emitters[type]->resizeBox(std::max(0.25f, new_size));
#endif
} // resizeBox
// ----------------------------------------------------------------------------
@ -314,6 +336,7 @@ void KartGFX::resizeBox(KartGFXType type, float new_size)
*/
void KartGFX::updateTerrain(const ParticleKind *pk)
{
#ifndef SERVER_ONLY
ParticleEmitter *pe = m_all_emitters[KGFX_TERRAIN];
if(!pe) return;
@ -346,6 +369,7 @@ void KartGFX::updateTerrain(const ParticleKind *pk)
// m_skidding can be > 2, and speed > maxSpeed (if powerups are used).
if(rate>1.0f) rate = 1.0f;
pe->setCreationRateRelative(rate);
#endif
} // updateTerrain
// ----------------------------------------------------------------------------
@ -370,6 +394,7 @@ void KartGFX::update(float dt)
*/
void KartGFX::updateNitroGraphics(float nitro_frac)
{
#ifndef SERVER_ONLY
// Upate particle effects (creation rate, and emitter size
// depending on speed)
// --------------------------------------------------------
@ -389,7 +414,7 @@ void KartGFX::updateNitroGraphics(float nitro_frac)
setCreationRateAbsolute(KartGFX::KGFX_NITROSMOKE2, 0);
m_nitro_light->setVisible(false);
}
#endif
} // updateGraphics
// ----------------------------------------------------------------------------
@ -399,14 +424,17 @@ void KartGFX::updateNitroGraphics(float nitro_frac)
*/
void KartGFX::updateSkidLight(unsigned int level)
{
#ifndef SERVER_ONLY
m_skidding_light_1->setVisible(level == 1);
m_skidding_light_2->setVisible(level > 1);
#endif
} // updateSkidLight
// ----------------------------------------------------------------------------
void KartGFX::getGFXStatus(int* nitro, bool* zipper,
int* skidding, bool* red_skidding) const
{
#ifndef SERVER_ONLY
int n = 0;
bool z = false;
int s = 0;
@ -432,13 +460,14 @@ void KartGFX::getGFXStatus(int* nitro, bool* zipper,
*zipper = z;
*skidding = s;
*red_skidding = r;
#endif
} // getGFXStatus
// ----------------------------------------------------------------------------
void KartGFX::setGFXFromReplay(int nitro, bool zipper,
int skidding, bool red_skidding)
{
#ifndef SERVER_ONLY
if (nitro > 0)
{
setCreationRateAbsolute(KartGFX::KGFX_NITRO1, (float)nitro);
@ -492,12 +521,15 @@ void KartGFX::setGFXFromReplay(int nitro, bool zipper,
m_skidding_light_1->setVisible(false);
m_skidding_light_2->setVisible(false);
}
#endif
} // setGFXFromReplay
// ----------------------------------------------------------------------------
void KartGFX::setGFXInvisible()
{
#ifndef SERVER_ONLY
m_nitro_light->setVisible(false);
m_skidding_light_1->setVisible(false);
m_skidding_light_2->setVisible(false);
#endif
} // setGFXInvisible

View File

@ -357,6 +357,7 @@ scene::ISceneNode* KartModel::attachModel(bool animated_models, bool always_anim
irr_driver->getSceneManager()->getRootSceneNode(),
irr_driver->getSceneManager() );
#ifndef SERVER_ONLY
node = irr_driver->addAnimatedMesh(m_mesh, "kartmesh",
NULL/*parent*/, getRenderInfo());
@ -365,7 +366,7 @@ scene::ISceneNode* KartModel::attachModel(bool animated_models, bool always_anim
node->setAutomaticCulling(scene::EAC_OFF);
else
node->setAutomaticCulling(scene::EAC_FRUSTUM_BOX);
#endif
if (always_animated)
{
// give a huge LOD distance for the player's kart. the reason is that it should
@ -409,7 +410,7 @@ scene::ISceneNode* KartModel::attachModel(bool animated_models, bool always_anim
if(!m_speed_weighted_objects[i].m_node) continue;
m_speed_weighted_objects[i].m_node->setParent(lod_node);
}
#ifndef SERVER_ONLY
// Enable rim lighting for the kart
irr_driver->applyObjectPassShader(lod_node, true);
std::vector<scene::ISceneNode*> &lodnodes = lod_node->getAllNodes();
@ -418,6 +419,7 @@ scene::ISceneNode* KartModel::attachModel(bool animated_models, bool always_anim
{
irr_driver->applyObjectPassShader(lodnodes[i], true);
}
#endif
}
else
{
@ -428,12 +430,13 @@ scene::ISceneNode* KartModel::attachModel(bool animated_models, bool always_anim
: 0;
scene::IMesh* main_frame = m_mesh;
#ifndef SERVER_ONLY
if (!CVS->isGLSL())
{
main_frame = m_mesh->getMesh(straight_frame);
main_frame->setHardwareMappingHint(scene::EHM_STATIC);
}
#endif
std::string debug_name;
#ifdef DEBUG
@ -510,12 +513,13 @@ bool KartModel::loadModels(const KartProperties &kart_properties)
return false;
}
#ifndef SERVER_ONLY
scene::ISkinnedMesh* sm = dynamic_cast<scene::ISkinnedMesh*>(m_mesh);
if (sm)
{
MeshTools::createSkinnedMeshWithTangents(sm, &MeshTools::isNormalMap);
}
#endif
m_mesh->grab();
irr_driver->grabAllTextures(m_mesh);
@ -564,7 +568,7 @@ bool KartModel::loadModels(const KartProperties &kart_properties)
// Grab all textures. This is done for the master only, so
// the destructor will only free the textures if a master
// copy is freed.
#ifndef SERVER_ONLY
scene::ISkinnedMesh* sm =
dynamic_cast<scene::ISkinnedMesh*>(obj.m_model);
if (sm)
@ -573,7 +577,7 @@ bool KartModel::loadModels(const KartProperties &kart_properties)
&MeshTools::isNormalMap);
}
irr_driver->grabAllTextures(obj.m_model);
#endif
// Update min/max
Vec3 obj_min, obj_max;
MeshTools::minMax3D(obj.m_model, &obj_min, &obj_max);
@ -614,8 +618,10 @@ bool KartModel::loadModels(const KartProperties &kart_properties)
std::string full_wheel =
kart_properties.getKartDir()+m_wheel_filename[i];
m_wheel_model[i] = irr_driver->getMesh(full_wheel);
#ifndef SERVER_ONLY
m_wheel_model[i] = MeshTools::createMeshWithTangents(m_wheel_model[i],
&MeshTools::isNormalMap);
&MeshTools::isNormalMap);
#endif
// Grab all textures. This is done for the master only, so
// the destructor will only free the textures if a master
// copy is freed.

View File

@ -249,10 +249,12 @@ void KartProperties::load(const std::string &filename, const std::string &node)
else
m_minimap_icon = NULL;
#ifndef SERVER_ONLY
if (m_minimap_icon == NULL)
{
m_minimap_icon = getUnicolorTexture(m_color);
}
#endif
// Only load the model if the .kart file has the appropriate version,
// otherwise warnings are printed.

View File

@ -66,6 +66,7 @@ void Moveable::setNode(scene::ISceneNode *n)
void Moveable::updateGraphics(float dt, const Vec3& offset_xyz,
const btQuaternion& rotation)
{
#ifndef SERVER_ONLY
Vec3 xyz=getXYZ()+offset_xyz;
m_node->setPosition(xyz.toIrrVector());
btQuaternion r_all = getRotation()*rotation;
@ -75,6 +76,7 @@ void Moveable::updateGraphics(float dt, const Vec3& offset_xyz,
Vec3 hpr;
hpr.setHPR(r_all);
m_node->setRotation(hpr.toIrrHPR());
#endif
} // updateGraphics
//-----------------------------------------------------------------------------

View File

@ -60,8 +60,8 @@
physics -> audio
"translations\n(too many connections\nto draw)"
"configuration\n(too many connections\nto draw)"
# addons -> tracks
# addons -> karts
addons -> tracks
addons -> karts
guiengine -> addons
guiengine -> race
addons -> online_manager
@ -222,6 +222,7 @@
#include "replay/replay_play.hpp"
#include "replay/replay_recorder.hpp"
#include "states_screens/main_menu_screen.hpp"
#include "states_screens/networking_lobby.hpp"
#include "states_screens/register_screen.hpp"
#include "states_screens/state_manager.hpp"
#include "states_screens/user_screen.hpp"
@ -572,8 +573,10 @@ void cmdLineHelp()
// " (so n=1 means all Ais will be the test ai)\n"
// "
" --server=name Start a server (not a playing client).\n"
" --public-server Allow direct connection to the server (without stk server)\n"
" --lan-server=name Start a LAN server (not a playing client).\n"
" --server-password= Sets a password for a server (both client&server).\n"
" --connect-now=ip Connect to a server with IP known now (in format x.x.x.x:xxx(port)).\n"
" --login=s Automatically log in (set the login).\n"
" --password=s Automatically log in (set the password).\n"
" --port=n Port number to use.\n"
@ -978,6 +981,34 @@ int handleCmdLine()
// Networking command lines
NetworkConfig::get()->
setMaxPlayers(UserConfigParams::m_server_max_players);
if (CommandLine::has("--port", &n))
{
// We don't know if this instance is going to be a client
// or server, so just set both ports, only one will be used anyway
NetworkConfig::get()->setClientPort(n);
NetworkConfig::get()->setServerPort(n);
}
if (CommandLine::has("--public-server"))
{
NetworkConfig::get()->setIsPublicServer();
}
if (CommandLine::has("--connect-now", &s))
{
TransportAddress ip(s);
TransportAddress me(2130706433/*127.0.0.1*/,
NetworkConfig::get()->getServerDiscoveryPort() );
NetworkConfig::get()->setIsLAN();
NetworkConfig::get()->setIsServer(false);
NetworkConfig::get()->setMyAddress(me);
Log::info("main", "Try to connect to server '%s'.",
ip.toString().c_str() );
irr::core::stringw name = StringUtils::utf8ToWide(ip.toString());
ServersManager::get()->addServer(new Server(name, /*lan*/true,
16, 0, ip));
ServersManager::get()->setJoinedServer(0);
STKHost::create();
}
if(CommandLine::has("--server", &s))
{
NetworkConfig::get()->setServerName(core::stringw(s.c_str()));
@ -1613,6 +1644,7 @@ int main(int argc, char *argv[] )
}
Log::warn("OpenGL", "Driver is too old!");
}
#ifndef SERVER_ONLY
else if (!CVS->isGLSL())
{
if (UserConfigParams::m_old_driver_popup)
@ -1631,7 +1663,7 @@ int main(int argc, char *argv[] )
}
Log::warn("OpenGL", "OpenGL version is too old!");
}
#endif
// Note that on the very first run of STK internet status is set to
// "not asked", so the report will only be sent in the next run.
if(UserConfigParams::m_internet_status==Online::RequestManager::IPERM_ALLOWED)
@ -1639,7 +1671,13 @@ int main(int argc, char *argv[] )
HardwareStats::reportHardwareStats();
}
if(!UserConfigParams::m_no_start_screen)
// This can only be the case if --connect-now was used, which adds
// a server to the server list.
if (ServersManager::get()->getNumServers()==1)
{
NetworkingLobby::getInstance()->push();
}
else if (!UserConfigParams::m_no_start_screen)
{
// If there is a current player, it was saved in the config file,
// so we immediately start the main menu (unless it was requested
@ -1894,6 +1932,8 @@ void runUnitTests()
GraphicsRestrictions::unitTesting();
Log::info("UnitTest", "NetworkString");
NetworkString::unitTesting();
Log::info("UnitTest", "TransportAddress");
TransportAddress::unitTesting();
Log::info("UnitTest", "Easter detection");
// Test easter mode: in 2015 Easter is 5th of April - check with 0 days

View File

@ -320,6 +320,7 @@ void SoccerWorld::countdownReachedZero()
//-----------------------------------------------------------------------------
void SoccerWorld::initKartList()
{
#ifndef SERVER_ONLY
const unsigned int kart_amount = (unsigned int)m_karts.size();
//Loading the indicator textures
@ -340,13 +341,14 @@ void SoccerWorld::initKartList()
float arrow_pos_height = km->getHeight() + 0.5f;
SoccerTeam team = getKartTeam(i);
arrow_node = irr_driver->addBillboard(core::dimension2d<irr::f32>(0.3f,
0.3f), team == SOCCER_TEAM_BLUE ? blue : red, m_karts[i]
->getNode(), true);
arrow_node = irr_driver->addBillboard(
core::dimension2d<irr::f32>(0.3f,0.3f),
team == SOCCER_TEAM_BLUE ? blue : red,
m_karts[i]->getNode(), true);
arrow_node->setPosition(core::vector3df(0, arrow_pos_height, 0));
}
#endif
} // initKartList
//-----------------------------------------------------------------------------

View File

@ -224,8 +224,10 @@ void World::init()
// Load other custom models if needed
loadCustomModels();
#ifndef SERVER_ONLY
// Now that all models are loaded, apply the overrides
irr_driver->applyObjectPassShader();
#endif
// Must be called after all karts are created
m_race_gui->init();

View File

@ -28,6 +28,8 @@
#include "karts/abstract_kart.hpp"
#include "modes/world.hpp"
#include "network/network_config.hpp"
#include "network/protocols/client_lobby.hpp"
#include "network/protocols/server_lobby.hpp"
#include "network/race_event_manager.hpp"
#include "tracks/track.hpp"
@ -51,7 +53,6 @@ WorldStatus::WorldStatus()
if (device->getTimer()->isStopped())
device->getTimer()->start();
m_ready_to_race = false;
} // WorldStatus
//-----------------------------------------------------------------------------
@ -93,9 +94,9 @@ void WorldStatus::reset()
// Set the right music
World::getWorld()->getTrack()->startMusic();
// In case of a networked race the race can only start once
// all protocols are up. This flag waits for that, and is
// set by
m_ready_to_race = !NetworkConfig::get()->isNetworking();
// all protocols are up. This flag is used to wait for
// a confirmation before starting the actual race.
m_server_is_ready = false;
} // reset
//-----------------------------------------------------------------------------
@ -179,10 +180,6 @@ void WorldStatus::update(float dt)
*/
void WorldStatus::updateTime(const float dt)
{
// In case of a networked race wait till all necessary protocols are
// ready before progressing the timer
if (!m_ready_to_race) return;
switch (m_phase)
{
// Note: setup phase must be a separate phase, since the race_manager
@ -243,35 +240,34 @@ void WorldStatus::updateTime(const float dt)
m_prestart_sound->play();
// In a networked game the client needs to wait for a notification
// from the server that ready-set-go can start now. So client will go
// to the 'wait_for_server_phase', from which they will progress once
// the notification is received. In all other cases (no networking or
// server), immediately go to race start
if(!NetworkConfig::get()->isNetworking() ||
NetworkConfig::get()->isServer() )
{
// Notify the clients that they can start ready-set-go
if(NetworkConfig::get()->isServer())
RaceEventManager::getInstance()->startReadySetGo();
m_server_is_ready = true;
} // if not networked
m_phase = WAIT_FOR_SERVER_PHASE;
// from the server that all clients and the server are ready to
// start the game. The server will actually wait for all clients
// to confirm that they have started the race before starting
// itself. In a normal race, this phase is skipped and the race
// starts immediately.
m_phase = NetworkConfig::get()->isNetworking() ? WAIT_FOR_SERVER_PHASE
: READY_PHASE;
return; // Don't increase time
case WAIT_FOR_SERVER_PHASE:
// On a client this phase waits for the server to be ready. On a
// server or in case of non-networked game this phase is reached
// with m_server_is_ready set to true, so it will immediately
// start the engines and then the race
if(!m_server_is_ready) return;
{
// This stage is only reached in case of a networked game.
// A client waits for a message from the server that it can
// start the race (i.e. that all clients and the server have
// loaded the world). The server waits for a confirmation from
// each client that they have started (to guarantee that the
// server is running with a local time behind all clients).
if (!m_server_is_ready) return;
m_phase = READY_PHASE;
m_phase = READY_PHASE;
Protocol *p = LobbyProtocol::get();
ClientLobby *cl = dynamic_cast<ClientLobby*>(p);
if (cl)
cl->startingRaceNow();
return; // Don't increase time
}
case READY_PHASE:
startEngines();
// Receiving a 'startReadySetGo' message from the server triggers
// a call to startReadySetGo() here, which will change the phase
// (or state) of the finite state machine.
return; // Don't increase time
case READY_PHASE:
if (m_auxiliary_timer > 1.0)
{
if (m_play_ready_set_go_sounds)
@ -432,8 +428,11 @@ void WorldStatus::updateTime(const float dt)
//-----------------------------------------------------------------------------
/** Called on the client when it receives a notification from the server that
* the server is now starting its ready-set-go phase. This function changes
* the state of the finite state machine to be ready.
* all clients (and server) are ready to start the race. The server will
* then additionally wait for all clients to report back that they are
* starting, which guarantees that the server is running far enough behind
* clients time that at server time T all events from the clients at time
* T have arrived, minimising rollback impact.
*/
void WorldStatus::startReadySetGo()
{

View File

@ -94,9 +94,6 @@ protected:
/** If the start race should be played, disabled in cutscenes. */
bool m_play_racestart_sounds;
/** A flag that causes the world to wait in case of a networking race
* till all protocols are up and running. */
bool m_ready_to_race;
private:
/** Sound to play at the beginning of a race, during which a
* a camera intro of the track can be shown. */
@ -130,10 +127,10 @@ private:
bool m_engines_started;
void startEngines();
/** In networked game the client must wait for the server to start 'ready set go'
* (to guarantee that the client's time is not ahead of the server), This flag
* indicates that the notification from the server was received, and that the
* client can go to 'ready' phase. */
/** In networked game a client must wait for the server to start 'ready
* set go' to make sure all client are actually ready to start the game.
* A server on the other hand will run behind all clients, so it will
* wait for all clients to indicate that they have started the race. */
bool m_server_is_ready;
public:
@ -198,7 +195,7 @@ public:
/** Get the time since start regardless of which way the clock counts */
float getTimeSinceStart() const { return m_count_up_timer; }
// ------------------------------------------------------------------------
void setReadyToRace() { m_ready_to_race = true; }
void setReadyToRace() { m_server_is_ready = true; }
}; // WorldStatus

View File

@ -37,6 +37,7 @@ NetworkConfig::NetworkConfig()
{
m_network_type = NETWORK_NONE;
m_is_server = false;
m_is_public_server = false;
m_max_players = 4;
m_is_registered = false;
m_server_name = "";

View File

@ -34,11 +34,18 @@ private:
static NetworkConfig *m_network_config;
enum NetworkType
{ NETWORK_NONE, NETWORK_WAN, NETWORK_LAN };
{
NETWORK_NONE, NETWORK_WAN, NETWORK_LAN
};
/** Keeps the type of network connection: none (yet), LAN or WAN. */
NetworkType m_network_type;
/** If set it allows clients to connect directly to this server without
* using the stk server in between. It requires obviously that this
* server is accessible (through the firewall) from the outside. */
bool m_is_public_server;
/** True if this host is a server, false otherwise. */
bool m_is_server;
@ -79,7 +86,7 @@ public:
/** Singleton get, which creates this object if necessary. */
static NetworkConfig *get()
{
if(!m_network_config)
if (!m_network_config)
m_network_config = new NetworkConfig();
return m_network_config;
} // get
@ -102,19 +109,19 @@ public:
} // setServerDiscoveryPort
// ------------------------------------------------------------------------
/** Sets the port on which this server listens. */
void setServerPort(uint16_t port) { m_server_port = port; }
void setServerPort(uint16_t port) { m_server_port = port; }
// ------------------------------------------------------------------------
/** Sets the port on which a client listens for server connection. */
void setClientPort(uint16_t port) { m_client_port = port; }
void setClientPort(uint16_t port) { m_client_port = port; }
// ------------------------------------------------------------------------
/** Returns the port on which this server listenes. */
uint16_t getServerPort() const { return m_server_port; }
uint16_t getServerPort() const { return m_server_port; }
// ------------------------------------------------------------------------
/** Returns the port for LAN server discovery. */
uint16_t getServerDiscoveryPort() const { return m_server_discovery_port; }
// ------------------------------------------------------------------------
/** Returns the port on which a client listens for server connections. */
uint16_t getClientPort() const { return m_client_port; }
uint16_t getClientPort() const { return m_client_port; }
// ------------------------------------------------------------------------
/** Sets the password for a server. */
void setPassword(const std::string &password) { m_password = password; }
@ -122,6 +129,12 @@ public:
/** Returns the password. */
const std::string& getPassword() const { return m_password; }
// ------------------------------------------------------------------------
/** Sets that this server can be contacted directly. */
void setIsPublicServer() { m_is_public_server = true; }
// ------------------------------------------------------------------------
/** Returns if connections directly to the server are to be accepted. */
bool isPublicServer() const { return m_is_public_server; }
// ------------------------------------------------------------------------
/** Return if a network setting is happening. A network setting is active
* if a host (server or client) exists. */
bool isNetworking() const { return m_network_type!=NETWORK_NONE; }

View File

@ -21,10 +21,9 @@
#include "main_loop.hpp"
#include "network/network_config.hpp"
#include "network/network_player_profile.hpp"
#include "network/protocol_manager.hpp"
#include "network/stk_host.hpp"
#include "network/protocols/client_lobby_room_protocol.hpp"
#include "network/protocols/server_lobby_room_protocol.hpp"
#include "network/protocols/client_lobby.hpp"
#include "network/protocols/server_lobby.hpp"
#include "network/protocols/stop_server.hpp"
#include "network/stk_peer.hpp"
#include "utils/log.hpp"
@ -79,27 +78,23 @@ void* NetworkConsole::mainLoop(void* data)
}
else if (str == "start" && NetworkConfig::get()->isServer())
{
ServerLobbyRoomProtocol* protocol =
static_cast<ServerLobbyRoomProtocol*>
(ProtocolManager::getInstance()->getProtocol(PROTOCOL_LOBBY_ROOM));
assert(protocol);
protocol->startGame();
ServerLobby* protocol =
dynamic_cast<ServerLobby*>(LobbyProtocol::get());
protocol->signalRaceStartToClients();
}
else if (str == "selection" && NetworkConfig::get()->isServer())
{
ServerLobbyRoomProtocol* protocol =
static_cast<ServerLobbyRoomProtocol*>
(ProtocolManager::getInstance()->getProtocol(PROTOCOL_LOBBY_ROOM));
assert(protocol);
ServerLobby* protocol =
dynamic_cast<ServerLobby*>(LobbyProtocol::get());
protocol->startSelection();
}
else if (str == "select" && NetworkConfig::get()->isClient())
{
std::string str2;
getline(std::cin, str2);
Protocol* protocol =
ProtocolManager::getInstance()->getProtocol(PROTOCOL_LOBBY_ROOM);
ClientLobbyRoomProtocol* clrp = static_cast<ClientLobbyRoomProtocol*>(protocol);
ServerLobby* protocol =
dynamic_cast<ServerLobby*>(LobbyProtocol::get());
ClientLobby* clrp = dynamic_cast<ClientLobby*>(protocol);
std::vector<NetworkPlayerProfile*> players =
STKHost::get()->getMyPlayerProfiles();
// For now send a vote for each local player
@ -114,10 +109,9 @@ void* NetworkConsole::mainLoop(void* data)
std::cout << "Vote for ? (track/laps/reversed/major/minor/race#) :";
std::string str2;
getline(std::cin, str2);
Protocol* protocol = ProtocolManager::getInstance()
->getProtocol(PROTOCOL_LOBBY_ROOM);
ClientLobbyRoomProtocol* clrp =
static_cast<ClientLobbyRoomProtocol*>(protocol);
LobbyProtocol* protocol = LobbyProtocol::get();
ClientLobby* clrp =
dynamic_cast<ClientLobby*>(protocol);
std::vector<NetworkPlayerProfile*> players =
STKHost::get()->getMyPlayerProfiles();
if (str2 == "track")

View File

@ -118,8 +118,7 @@ void Protocol::findAndTerminateProtocol(ProtocolType type)
if (protocol)
protocol->requestTerminate();
else
Log::error("ClientLobbyRoomProtocol",
"No protocol %d registered.", type);
Log::error("Protocol", "No protocol %d registered.", type);
} // findAndTerminateProtocol
// ----------------------------------------------------------------------------

View File

@ -16,15 +16,15 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "network/protocols/client_lobby_room_protocol.hpp"
#include "network/protocols/client_lobby.hpp"
#include "config/player_manager.hpp"
#include "modes/world_with_rank.hpp"
#include "network/event.hpp"
#include "network/network_config.hpp"
#include "network/network_player_profile.hpp"
#include "network/protocols/start_game_protocol.hpp"
#include "network/protocol_manager.hpp"
#include "network/protocols/latency_protocol.hpp"
#include "network/race_event_manager.hpp"
#include "network/stk_host.hpp"
#include "network/stk_peer.hpp"
@ -35,26 +35,52 @@
#include "states_screens/state_manager.hpp"
#include "utils/log.hpp"
ClientLobbyRoomProtocol::
ClientLobbyRoomProtocol(const TransportAddress& server_address)
: LobbyRoomProtocol(NULL)
// ============================================================================
/** The protocol that manages starting a race with the server. It uses a
* finite state machine:
\dot
digraph interaction {
"NONE" -> "LINKED" [label="ENet connection with server established"]
"LINKED" -> "REQUESTING_CONNECTION" [label="Request connection from server"]
"REQUESTING_CONNECTION" -> CONNECTED [label="Connection accepted by server"]
"REQUESTING_CONNECTION" -> "?? TO BE DONE ??" [label="Connection refused by server"]
"CONNECTED" -> "KART_SELECTION" [label="Server tells us to start kart selection"]
"KART_SELECTION" -> "SELECTING_KARTS" [label="Show kart selection screen"]
"SELECTING_KARTS" -> "PLAYING" [label="Server sends start race message"]
}
\enddot
Note that some states are actually managed outside of the client lobby. For
example to select race details after selecting a kart is managed by the GUI
engine.
*/
ClientLobby::ClientLobby() : LobbyProtocol(NULL)
{
m_server_address.copy(server_address);
m_server_address.clear();
m_server = NULL;
setHandleDisconnections(true);
} // ClientLobbyRoomProtocol
} // ClientLobby
//-----------------------------------------------------------------------------
ClientLobbyRoomProtocol::~ClientLobbyRoomProtocol()
ClientLobby::~ClientLobby()
{
} // ClientLobbyRoomProtocol
} // ClientLobby
//-----------------------------------------------------------------------------
void ClientLobbyRoomProtocol::setup()
/** Sets the address of the server.
*/
void ClientLobby::setAddress(const TransportAddress &address)
{
m_setup = STKHost::get()->setupNewGame(); // create a new setup
m_server_address.copy(address);
} // setAddress
//-----------------------------------------------------------------------------
void ClientLobby::setup()
{
m_game_setup = STKHost::get()->setupNewGame(); // create a new game setup
m_state = NONE;
} // setup
@ -63,8 +89,8 @@ void ClientLobbyRoomProtocol::setup()
* \param player_id The global player id of the voting player.
* \param kart_name Name of the selected kart.
*/
void ClientLobbyRoomProtocol::requestKartSelection(uint8_t player_id,
const std::string &kart_name)
void ClientLobby::requestKartSelection(uint8_t player_id,
const std::string &kart_name)
{
NetworkString *request = getNetworkString(3+kart_name.size());
request->addUInt8(LE_KART_SELECTION).addUInt8(player_id)
@ -80,7 +106,7 @@ void ClientLobbyRoomProtocol::requestKartSelection(uint8_t player_id,
* \param player_id The global player id of the voting player.
* \param major Major mode voted for.
*/
void ClientLobbyRoomProtocol::voteMajor(uint8_t player_id, uint32_t major)
void ClientLobby::voteMajor(uint8_t player_id, uint32_t major)
{
NetworkString *request = getNetworkString(6);
request->addUInt8(LE_VOTE_MAJOR).addUInt8(player_id)
@ -96,7 +122,7 @@ void ClientLobbyRoomProtocol::voteMajor(uint8_t player_id, uint32_t major)
* \param player_id The global player id of the voting player.
* \param count NUmber of tracks to play.
*/
void ClientLobbyRoomProtocol::voteRaceCount(uint8_t player_id, uint8_t count)
void ClientLobby::voteRaceCount(uint8_t player_id, uint8_t count)
{
NetworkString *request = getNetworkString(3);
request->addUInt8(LE_VOTE_RACE_COUNT).addUInt8(player_id).addUInt8(count);
@ -111,7 +137,7 @@ void ClientLobbyRoomProtocol::voteRaceCount(uint8_t player_id, uint8_t count)
* \param player_id The global player id of the voting player.
* \param minor Voted minor mode.
*/
void ClientLobbyRoomProtocol::voteMinor(uint8_t player_id, uint32_t minor)
void ClientLobby::voteMinor(uint8_t player_id, uint32_t minor)
{
NetworkString *request = getNetworkString(6);
request->addUInt8(LE_VOTE_MINOR).addUInt8(player_id).addUInt32(minor);
@ -127,7 +153,7 @@ void ClientLobbyRoomProtocol::voteMinor(uint8_t player_id, uint32_t minor)
* \param track Name of the track.
* \param At which place in the list of tracks this track should be played.
*/
void ClientLobbyRoomProtocol::voteTrack(uint8_t player_id,
void ClientLobby::voteTrack(uint8_t player_id,
const std::string &track,
uint8_t track_nb)
{
@ -147,7 +173,7 @@ void ClientLobbyRoomProtocol::voteTrack(uint8_t player_id,
* \param track_nb Index for the track to be voted on in the list of all
* tracks.
*/
void ClientLobbyRoomProtocol::voteReversed(uint8_t player_id, bool reversed,
void ClientLobby::voteReversed(uint8_t player_id, bool reversed,
uint8_t track_nb)
{
NetworkString *request = getNetworkString(9);
@ -164,7 +190,7 @@ void ClientLobbyRoomProtocol::voteReversed(uint8_t player_id, bool reversed,
* \param laps Number of laps for the specified track.
* \param track_nb Index of the track in the list of all tracks.
*/
void ClientLobbyRoomProtocol::voteLaps(uint8_t player_id, uint8_t laps,
void ClientLobby::voteLaps(uint8_t player_id, uint8_t laps,
uint8_t track_nb)
{
NetworkString *request = getNetworkString(10);
@ -177,7 +203,7 @@ void ClientLobbyRoomProtocol::voteLaps(uint8_t player_id, uint8_t laps,
//-----------------------------------------------------------------------------
/** Called when a client selects to exit a server.
*/
void ClientLobbyRoomProtocol::leave()
void ClientLobby::leave()
{
m_server->disconnect();
STKHost::get()->removePeer(m_server);
@ -190,7 +216,7 @@ void ClientLobbyRoomProtocol::leave()
* screen. It notifies the server that this client has exited the screen and
* is back at the lobby.
*/
void ClientLobbyRoomProtocol::doneWithResults()
void ClientLobby::doneWithResults()
{
NetworkString *done = getNetworkString(1);
done->addUInt8(LE_RACE_FINISHED_ACK);
@ -200,18 +226,19 @@ void ClientLobbyRoomProtocol::doneWithResults()
//-----------------------------------------------------------------------------
bool ClientLobbyRoomProtocol::notifyEvent(Event* event)
bool ClientLobby::notifyEvent(Event* event)
{
assert(m_setup); // assert that the setup exists
assert(m_game_setup); // assert that the setup exists
NetworkString &data = event->data();
assert(data.size()); // assert that data isn't empty
uint8_t message_type = data.getUInt8();
Log::info("ClientLobbyRoomProtocol", "Synchronous message of type %d",
Log::info("ClientLobby", "Synchronous message of type %d",
message_type);
switch(message_type)
{
case LE_KART_SELECTION_UPDATE: kartSelectionUpdate(event); break;
case LE_LOAD_WORLD: loadWorld(); break;
case LE_RACE_FINISHED: raceFinished(event); break;
case LE_EXIT_RESULT: exitResultScreen(event); break;
default:
@ -223,16 +250,16 @@ bool ClientLobbyRoomProtocol::notifyEvent(Event* event)
//-----------------------------------------------------------------------------
bool ClientLobbyRoomProtocol::notifyEventAsynchronous(Event* event)
bool ClientLobby::notifyEventAsynchronous(Event* event)
{
assert(m_setup); // assert that the setup exists
assert(m_game_setup); // assert that the setup exists
if (event->getType() == EVENT_TYPE_MESSAGE)
{
NetworkString &data = event->data();
assert(data.size()); // assert that data isn't empty
uint8_t message_type = data.getUInt8();
Log::info("ClientLobbyRoomProtocol", "Asynchronous message of type %d",
Log::info("ClientLobby", "Asynchronous message of type %d",
message_type);
switch(message_type)
{
@ -269,7 +296,7 @@ bool ClientLobbyRoomProtocol::notifyEventAsynchronous(Event* event)
//-----------------------------------------------------------------------------
void ClientLobbyRoomProtocol::update(float dt)
void ClientLobby::update(float dt)
{
switch (m_state)
{
@ -309,6 +336,10 @@ void ClientLobbyRoomProtocol::update(float dt)
NetworkKartSelectionScreen::getInstance();
screen->push();
m_state = SELECTING_KARTS;
Protocol *p = new LatencyProtocol();
p->requestStart();
Log::info("LobbyProtocol", "LatencyProtocol started.");
}
break;
case SELECTING_KARTS:
@ -338,7 +369,7 @@ void ClientLobbyRoomProtocol::update(float dt)
* Data | player_id | hostid | player name |
* -------------------------------------
*/
void ClientLobbyRoomProtocol::newPlayer(Event* event)
void ClientLobby::newPlayer(Event* event)
{
if (!checkDataSize(event, 2)) return;
const NetworkString &data = event->data();
@ -350,21 +381,21 @@ void ClientLobbyRoomProtocol::newPlayer(Event* event)
// FIXME need adjusting when splitscreen is used/
if(STKHost::get()->getGameSetup()->isLocalMaster(player_id))
{
Log::error("ClientLobbyRoomProtocol",
Log::error("ClientLobby",
"The server notified me that I'm a new player in the "
"room (not normal).");
}
else if (m_setup->getProfile(player_id) == NULL)
else if (m_game_setup->getProfile(player_id) == NULL)
{
Log::verbose("ClientLobbyRoomProtocol", "New player connected.");
Log::verbose("ClientLobby", "New player connected.");
NetworkPlayerProfile* profile =
new NetworkPlayerProfile(name, player_id, host_id);
m_setup->addPlayer(profile);
m_game_setup->addPlayer(profile);
NetworkingLobby::getInstance()->addPlayer(profile);
}
else
{
Log::error("ClientLobbyRoomProtocol",
Log::error("ClientLobby",
"One of the player notified in the list is myself.");
}
} // newPlayer
@ -381,7 +412,7 @@ void ClientLobbyRoomProtocol::newPlayer(Event* event)
* Data | player id *|
* --------------
*/
void ClientLobbyRoomProtocol::disconnectedPlayer(Event* event)
void ClientLobby::disconnectedPlayer(Event* event)
{
if (!checkDataSize(event, 1)) return;
@ -389,16 +420,16 @@ void ClientLobbyRoomProtocol::disconnectedPlayer(Event* event)
while(data.size()>0)
{
const NetworkPlayerProfile *profile =
m_setup->getProfile(data.getUInt8());
if (m_setup->removePlayer(profile))
m_game_setup->getProfile(data.getUInt8());
if (m_game_setup->removePlayer(profile))
{
Log::info("ClientLobbyRoomProtocol",
Log::info("ClientLobby",
"Player %d removed successfully.",
profile->getGlobalPlayerId());
}
else
{
Log::error("ClientLobbyRoomProtocol",
Log::error("ClientLobby",
"The disconnected peer wasn't known.");
}
} // while
@ -418,7 +449,7 @@ void ClientLobbyRoomProtocol::disconnectedPlayer(Event* event)
* Data | player_id| hostid | authorised |playernames* |
* ---------------------------------------------------------
*/
void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
void ClientLobby::connectionAccepted(Event* event)
{
// At least 3 bytes should remain now
if(!checkDataSize(event, 3)) return;
@ -428,7 +459,7 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
// Accepted
// ========
Log::info("ClientLobbyRoomProtocol",
Log::info("ClientLobby",
"The server accepted the connection.");
// self profile
@ -448,7 +479,7 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
NetworkPlayerProfile* profile =
new NetworkPlayerProfile(name, my_player_id, my_host_id);
STKHost::get()->getGameSetup()->setLocalMaster(my_player_id);
m_setup->setNumLocalPlayers(1);
m_game_setup->setNumLocalPlayers(1);
// connection token
uint32_t token = data.getToken();
peer->setClientServerToken(token);
@ -464,7 +495,7 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
NetworkPlayerProfile* profile2 =
new NetworkPlayerProfile(name, player_id, host_id);
m_setup->addPlayer(profile2);
m_game_setup->addPlayer(profile2);
// Inform the network lobby of all players so that the GUI can
// show all currently connected players.
NetworkingLobby::getInstance()->addPlayer(profile2);
@ -472,7 +503,7 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
// Add self after other players so that player order is identical
// on server and all clients.
m_setup->addPlayer(profile);
m_game_setup->addPlayer(profile);
NetworkingLobby::getInstance()->addPlayer(profile);
m_server = event->getPeer();
m_state = CONNECTED;
@ -490,7 +521,7 @@ void ClientLobbyRoomProtocol::connectionAccepted(Event* event)
* Data | refusal code |
* ----------------
*/
void ClientLobbyRoomProtocol::connectionRefused(Event* event)
void ClientLobby::connectionRefused(Event* event)
{
if (!checkDataSize(event, 1)) return;
const NetworkString &data = event->data();
@ -498,17 +529,17 @@ void ClientLobbyRoomProtocol::connectionRefused(Event* event)
switch (data.getUInt8()) // the second byte
{
case 0:
Log::info("ClientLobbyRoomProtocol",
Log::info("ClientLobby",
"Connection refused : too many players.");
break;
case 1:
Log::info("ClientLobbyRoomProtocol", "Connection refused : banned.");
Log::info("ClientLobby", "Connection refused : banned.");
break;
case 2:
Log::info("ClientLobbyRoomProtocol", "Client busy.");
Log::info("ClientLobby", "Client busy.");
break;
default:
Log::info("ClientLobbyRoomProtocol", "Connection refused.");
Log::info("ClientLobby", "Connection refused.");
break;
}
} // connectionRefused
@ -525,7 +556,7 @@ void ClientLobbyRoomProtocol::connectionRefused(Event* event)
* Data | refusal code |
* ----------------
*/
void ClientLobbyRoomProtocol::kartSelectionRefused(Event* event)
void ClientLobby::kartSelectionRefused(Event* event)
{
if(!checkDataSize(event, 1)) return;
@ -534,15 +565,15 @@ void ClientLobbyRoomProtocol::kartSelectionRefused(Event* event)
switch (data.getUInt8()) // the error code
{
case 0:
Log::info("ClientLobbyRoomProtocol",
Log::info("ClientLobby",
"Kart selection refused : already taken.");
break;
case 1:
Log::info("ClientLobbyRoomProtocol",
Log::info("ClientLobby",
"Kart selection refused : not available.");
break;
default:
Log::info("ClientLobbyRoomProtocol", "Kart selection refused.");
Log::info("ClientLobby", "Kart selection refused.");
break;
}
} // kartSelectionRefused
@ -559,48 +590,64 @@ void ClientLobbyRoomProtocol::kartSelectionRefused(Event* event)
* Data | player id | N (kart name size) | kart name |
* --------------------------------------------------
*/
void ClientLobbyRoomProtocol::kartSelectionUpdate(Event* event)
void ClientLobby::kartSelectionUpdate(Event* event)
{
if(!checkDataSize(event, 3)) return;
const NetworkString &data = event->data();
uint8_t player_id = data.getUInt8();
std::string kart_name;
data.decodeString(&kart_name);
if (!m_setup->isKartAvailable(kart_name))
if (!m_game_setup->isKartAvailable(kart_name))
{
Log::error("ClientLobbyRoomProtocol",
Log::error("ClientLobby",
"The updated kart is taken already.");
}
m_setup->setPlayerKart(player_id, kart_name);
m_game_setup->setPlayerKart(player_id, kart_name);
NetworkKartSelectionScreen::getInstance()->playerSelected(player_id,
kart_name);
} // kartSelectionUpdate
//-----------------------------------------------------------------------------
/*! \brief Called when the race needs to be started.
/*! \brief Called when the server broadcasts to start the race.
race needs to be started.
* \param event : Event providing the information (no additional information
* in this case).
*/
void ClientLobbyRoomProtocol::startGame(Event* event)
void ClientLobby::startGame(Event* event)
{
const NetworkString &data = event->data();
m_state = PLAYING;
ProtocolManager::getInstance()
->requestStart(new StartGameProtocol(m_setup));
Log::info("ClientLobbyRoomProtocol", "Starting new game");
// Triggers the world finite state machine to go from WAIT_FOR_SERVER_PHASE
// to READY_PHASE.
World::getWorld()->setReadyToRace();
Log::info("ClientLobby", "Starting new game");
} // startGame
//-----------------------------------------------------------------------------
/** Called from WorldStatus when reaching the READY phase, i.e. when the race
* was started. It is going to inform the server of the race start. This
* allows the server to wait for all clients to start, so the server will
* be running behind the client with the biggest latency, which should
* make it likely that at local time T on the server all messages from
* all clients at their local time T have arrived.
*/
void ClientLobby::startingRaceNow()
{
NetworkString *ns = getNetworkString(2);
ns->addUInt8(LE_STARTED_RACE);
sendToServer(ns, /*reliable*/true);
terminateLatencyProtocol();
} // startingRaceNow
//-----------------------------------------------------------------------------
/*! \brief Called when the kart selection starts.
* \param event : Event providing the information (no additional information
* in this case).
*/
void ClientLobbyRoomProtocol::startSelection(Event* event)
void ClientLobby::startSelection(Event* event)
{
m_state = KART_SELECTION;
Log::info("ClientLobbyRoomProtocol", "Kart selection starts now");
Log::info("ClientLobby", "Kart selection starts now");
} // startSelection
//-----------------------------------------------------------------------------
@ -615,12 +662,12 @@ void ClientLobbyRoomProtocol::startSelection(Event* event)
* Data | Kart 1 ID | kart id 2 | ... |
* -------------------------------
*/
void ClientLobbyRoomProtocol::raceFinished(Event* event)
void ClientLobby::raceFinished(Event* event)
{
if(!checkDataSize(event, 1)) return;
NetworkString &data = event->data();
Log::error("ClientLobbyRoomProtocol",
Log::error("ClientLobby",
"Server notified that the race is finished.");
// stop race protocols
@ -629,7 +676,7 @@ void ClientLobbyRoomProtocol::raceFinished(Event* event)
if (protocol)
ProtocolManager::getInstance()->requestTerminate(protocol);
else
Log::error("ClientLobbyRoomProtocol",
Log::error("ClientLobby",
"No controller events protocol registered.");
protocol = ProtocolManager::getInstance()
@ -637,7 +684,7 @@ void ClientLobbyRoomProtocol::raceFinished(Event* event)
if (protocol)
ProtocolManager::getInstance()->requestTerminate(protocol);
else
Log::error("ClientLobbyRoomProtocol",
Log::error("ClientLobby",
"No kart update protocol registered.");
protocol = ProtocolManager::getInstance()
@ -645,7 +692,7 @@ void ClientLobbyRoomProtocol::raceFinished(Event* event)
if (protocol)
ProtocolManager::getInstance()->requestTerminate(protocol);
else
Log::error("ClientLobbyRoomProtocol",
Log::error("ClientLobby",
"No game events protocol registered.");
// finish the race
@ -657,7 +704,7 @@ void ClientLobbyRoomProtocol::raceFinished(Event* event)
{
uint8_t kart_id = data.getUInt8();
ranked_world->setKartPosition(kart_id,position);
Log::info("ClientLobbyRoomProtocol", "Kart %d has finished #%d",
Log::info("ClientLobby", "Kart %d has finished #%d",
kart_id, position);
position++;
}
@ -670,7 +717,7 @@ void ClientLobbyRoomProtocol::raceFinished(Event* event)
/** Called when the server informs the clients to exit the race result screen.
* It exits the race, and goes back to the lobby.
*/
void ClientLobbyRoomProtocol::exitResultScreen(Event *event)
void ClientLobby::exitResultScreen(Event *event)
{
RaceResultGUI::getInstance()->backToLobby();
} // exitResultScreen
@ -686,14 +733,14 @@ void ClientLobbyRoomProtocol::exitResultScreen(Event *event)
* Data |player id | major mode vote |
* ------------------------------
*/
void ClientLobbyRoomProtocol::playerMajorVote(Event* event)
void ClientLobby::playerMajorVote(Event* event)
{
const NetworkString &data = event->data();
if (!checkDataSize(event, 2))
return;
uint8_t player_id = data.getUInt8();
uint8_t mode = data.getUInt8();
m_setup->getRaceConfig()->setPlayerMajorVote(player_id, mode);
m_game_setup->getRaceConfig()->setPlayerMajorVote(player_id, mode);
} // playerMajorVote
//-----------------------------------------------------------------------------
@ -707,13 +754,13 @@ void ClientLobbyRoomProtocol::playerMajorVote(Event* event)
* Data | player id | races count |
* ---------------------------
*/
void ClientLobbyRoomProtocol::playerRaceCountVote(Event* event)
void ClientLobby::playerRaceCountVote(Event* event)
{
if (!checkDataSize(event, 2)) return;
const NetworkString &data = event->data();
uint8_t player_id = data.getUInt8();
uint8_t count = data.getUInt8();
m_setup->getRaceConfig()->setPlayerRaceCountVote(player_id, count);
m_game_setup->getRaceConfig()->setPlayerRaceCountVote(player_id, count);
} // playerRaceCountVote
//-----------------------------------------------------------------------------
@ -727,13 +774,13 @@ void ClientLobbyRoomProtocol::playerRaceCountVote(Event* event)
* Data | player id | minor mode vote |
* -------------------------------
*/
void ClientLobbyRoomProtocol::playerMinorVote(Event* event)
void ClientLobby::playerMinorVote(Event* event)
{
if (!checkDataSize(event, 2)) return;
const NetworkString &data = event->data();
uint8_t player_id = data.getUInt8();
uint8_t minor = data.getUInt8();
m_setup->getRaceConfig()->setPlayerMinorVote(player_id, minor);
m_game_setup->getRaceConfig()->setPlayerMinorVote(player_id, minor);
} // playerMinorVote
//-----------------------------------------------------------------------------
@ -748,7 +795,7 @@ void ClientLobbyRoomProtocol::playerMinorVote(Event* event)
* Data | player id | track number (gp) | N | track name |
* --------------------------------------------------
*/
void ClientLobbyRoomProtocol::playerTrackVote(Event* event)
void ClientLobby::playerTrackVote(Event* event)
{
if (!checkDataSize(event, 3)) return;
const NetworkString &data = event->data();
@ -756,7 +803,7 @@ void ClientLobbyRoomProtocol::playerTrackVote(Event* event)
uint8_t player_id = data.getUInt8();
uint8_t number = data.getUInt8();
int N = data.decodeString(&track_name);
m_setup->getRaceConfig()->setPlayerTrackVote(player_id, track_name,
m_game_setup->getRaceConfig()->setPlayerTrackVote(player_id, track_name,
number);
} // playerTrackVote
@ -772,14 +819,14 @@ void ClientLobbyRoomProtocol::playerTrackVote(Event* event)
* Data | player id |reversed | track number (gp) |
* -------------------------------------------
*/
void ClientLobbyRoomProtocol::playerReversedVote(Event* event)
void ClientLobby::playerReversedVote(Event* event)
{
if (!checkDataSize(event, 3)) return;
const NetworkString &data = event->data();
uint8_t player_id = data.getUInt8();
uint8_t reversed = data.getUInt8();
uint8_t number = data.getUInt8();
m_setup->getRaceConfig()->setPlayerReversedVote(player_id, reversed!=0,
m_game_setup->getRaceConfig()->setPlayerReversedVote(player_id, reversed!=0,
number);
} // playerReversedVote
@ -792,17 +839,39 @@ void ClientLobbyRoomProtocol::playerReversedVote(Event* event)
* Byte 0 1 2
* ----------------------------------------
* Size | 1 | 1 | 1 |
* Data | player id | laps | track number (gp) |
* Data | player id | laps | track number (gp) |
* ----------------------------------------
*/
void ClientLobbyRoomProtocol::playerLapsVote(Event* event)
void ClientLobby::playerLapsVote(Event* event)
{
if (!checkDataSize(event, 3)) return;
const NetworkString &data = event->data();
uint8_t player_id = data.getUInt8();
uint8_t laps = data.getUInt8();
uint8_t number = data.getUInt8();
m_setup->getRaceConfig()->setPlayerLapsVote(player_id, laps, number);
m_game_setup->getRaceConfig()->setPlayerLapsVote(player_id, laps, number);
} // playerLapsVote
//-----------------------------------------------------------------------------
/** Callback when the world is loaded. The client will inform the server
* that the players on this host are ready to start the race. It is called by
* the RaceManager after the world is loaded.
*/
void ClientLobby::finishedLoadingWorld()
{
assert(STKHost::get()->getPeerCount() == 1);
std::vector<NetworkPlayerProfile*> players =
STKHost::get()->getMyPlayerProfiles();
NetworkString *ns = getNetworkString(2);
ns->addUInt8(LE_CLIENT_LOADED_WORLD);
ns->addUInt8( uint8_t(players.size()) ) ;
for (unsigned int i = 0; i < players.size(); i++)
{
ns->addUInt8(players[i]->getGlobalPlayerId());
Log::info("ClientLobby",
"Player %d ready, notifying server.",
players[i]->getGlobalPlayerId());
} // for i < players.size()
sendToServer(ns, /*reliable*/true);
delete ns;
} // finishedLoadingWorld

View File

@ -1,13 +1,13 @@
#ifndef CLIENT_LOBBY_ROOM_PROTOCOL_HPP
#define CLIENT_LOBBY_ROOM_PROTOCOL_HPP
#ifndef CLIENT_LOBBY_HPP
#define CLIENT_LOBBY_HPP
#include "network/protocols/lobby_room_protocol.hpp"
#include "network/protocols/lobby_protocol.hpp"
#include "network/transport_address.hpp"
#include "utils/cpp2011.hpp"
class STKPeer;
class ClientLobbyRoomProtocol : public LobbyRoomProtocol
class ClientLobby : public LobbyProtocol
{
private:
void newPlayer(Event* event);
@ -50,11 +50,12 @@ private:
STATE m_state;
public:
ClientLobbyRoomProtocol(const TransportAddress& server_address);
virtual ~ClientLobbyRoomProtocol();
ClientLobby();
virtual ~ClientLobby();
void requestKartSelection(uint8_t player_id,
const std::string &kart_name);
virtual void requestKartSelection(uint8_t player_id,
const std::string &kart_name) OVERRIDE;
void setAddress(const TransportAddress &address);
void voteMajor(uint8_t player_id, uint32_t major);
void voteRaceCount(uint8_t player_id, uint8_t count);
void voteMinor(uint8_t player_id, uint32_t minor);
@ -63,14 +64,16 @@ public:
void voteReversed(uint8_t player_id, bool reversed, uint8_t track_nb = 0);
void voteLaps(uint8_t player_id, uint8_t laps, uint8_t track_nb = 0);
void doneWithResults();
void startingRaceNow();
void leave();
virtual bool notifyEvent(Event* event) OVERRIDE;
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE;
virtual void finishedLoadingWorld() OVERRIDE;
virtual void setup() OVERRIDE;
virtual void update(float dt) OVERRIDE;
virtual void asynchronousUpdate() OVERRIDE {}
};
#endif // CLIENT_LOBBY_ROOM_PROTOCOL_HPP
#endif // CLIENT_LOBBY_HPP

View File

@ -26,7 +26,7 @@
#include "network/protocols/hide_public_address.hpp"
#include "network/protocols/request_connection.hpp"
#include "network/protocols/ping_protocol.hpp"
#include "network/protocols/client_lobby_room_protocol.hpp"
#include "network/protocols/client_lobby.hpp"
#include "network/protocol_manager.hpp"
#include "network/servers_manager.hpp"
#include "network/stk_host.hpp"
@ -238,7 +238,9 @@ void ConnectToServer::asynchronousUpdate()
// lobby room protocol if we're connected only
if(STKHost::get()->getPeers()[0]->isConnected())
{
Protocol *p = new ClientLobbyRoomProtocol(m_server_address);
ClientLobby *p =
LobbyProtocol::create<ClientLobby>();
p->setAddress(m_server_address);
p->requestStart();
}
}

View File

@ -39,7 +39,7 @@ GameEventsProtocol::~GameEventsProtocol()
*/
void GameEventsProtocol::setup()
{
World::getWorld()->setReadyToRace();
m_count_ready_clients = 0;
} // setup
// ----------------------------------------------------------------------------
@ -63,16 +63,16 @@ bool GameEventsProtocol::notifyEvent(Event* event)
int8_t type = data.getUInt8();
switch (type)
{
case GE_ITEM_COLLECTED:
collectedItem(data); break;
case GE_KART_FINISHED_RACE:
kartFinishedRace(data); break;
case GE_START_READY_SET_GO:
receivedReadySetGo(); break;
case GE_CLIENT_STARTED_RSG:
receivedClientHasStarted(event); break;
case GE_ITEM_COLLECTED:
collectedItem(data); break;
case GE_KART_FINISHED_RACE:
kartFinishedRace(data); break;
default:
Log::warn("GameEventsProtocol", "Unkown message type.");
break;
default:
Log::warn("GameEventsProtocol", "Unkown message type.");
break;
}
return true;
} // notifyEvent
@ -164,26 +164,37 @@ void GameEventsProtocol::kartFinishedRace(const NetworkString &ns)
} // kartFinishedRace
// ----------------------------------------------------------------------------
/** This function is called on a server when the world starts the ready-set-go
* phase. It signals to all clients to do the same.
/** Called on a client when it has started its ready-set-go. The client will
* inform the server anout this. The server will wait for all clients to
* have started before it will start its own countdown.
*/
void GameEventsProtocol::startReadySetGo()
{
assert(NetworkConfig::get()->isServer());
NetworkString *ns = getNetworkString(1);
ns->setSynchronous(true);
ns->addUInt8(GE_START_READY_SET_GO);
sendMessageToPeersChangingToken(ns, /*reliable*/true);
delete ns;
} // startReadySetGo
// ----------------------------------------------------------------------------
/** Called on the client when it receives the message that the server has
* started its ready-set-go. Signal to world that it can go to the next
* phase (ready phase) now.
*/
void GameEventsProtocol::receivedReadySetGo()
void GameEventsProtocol::clientHasStarted()
{
assert(NetworkConfig::get()->isClient());
World::getWorld()->startReadySetGo();
} // receivedReadySetGo
NetworkString *ns = getNetworkString(1);
ns->setSynchronous(true);
ns->addUInt8(GE_CLIENT_STARTED_RSG);
sendToServer(ns, /*reliable*/true);
delete ns;
} // clientHasStarted
// ----------------------------------------------------------------------------
/** Called on the server when a client has signaled that it has started ready
* set go. The server waits for the last client before it starts its own
* ready set go. */
void GameEventsProtocol::receivedClientHasStarted(Event *event)
{
assert(NetworkConfig::get()->isServer());
m_count_ready_clients++;
Log::verbose("GameEvent",
"Host %d has started ready-set-go: %d out of %d done",
event->getPeer()->getHostId(), m_count_ready_clients,
STKHost::get()->getGameSetup()->getPlayerCount() );
if (m_count_ready_clients==STKHost::get()->getGameSetup()->getPlayerCount())
{
Log::verbose("GameEvent", "All %d clients have started.",
STKHost::get()->getGameSetup()->getPlayerCount());
// SIgnal the server to start now - since it is now behind the client
// times by the latency of the 'slowest' client.
World::getWorld()->startReadySetGo();
}
} // receivedClientHasStarted

View File

@ -11,11 +11,18 @@ class GameEventsProtocol : public Protocol
{
private:
enum GameEventType {
GE_START_READY_SET_GO = 0x01,
GE_CLIENT_STARTED_RSG = 0x01,
GE_ITEM_COLLECTED = 0x02,
GE_KART_FINISHED_RACE = 0x03
}; // GameEventType
/** Count how many clients have started 'ready'. The server
* will only go to its 'ready' phase if all client shave done so.
* This means the server time is far enough behind the clients
* that at time T all client messages for time T have been
* received (short of latency spikes). */
int m_count_ready_clients;
public:
GameEventsProtocol();
virtual ~GameEventsProtocol();
@ -24,9 +31,9 @@ public:
void collectedItem(Item* item, AbstractKart* kart);
void collectedItem(const NetworkString &ns);
void kartFinishedRace(AbstractKart *kart, float time);
void clientHasStarted();
void receivedClientHasStarted(Event *event);
void kartFinishedRace(const NetworkString &ns);
void startReadySetGo();
void receivedReadySetGo();
virtual void setup() OVERRIDE;
virtual void update(float dt) OVERRIDE {};
virtual void asynchronousUpdate() OVERRIDE{}

View File

@ -0,0 +1,140 @@
#include "network/protocols/latency_protocol.hpp"
#include "network/event.hpp"
#include "network/network_config.hpp"
#include "network/stk_host.hpp"
#include "network/stk_peer.hpp"
#include "utils/time.hpp"
//-----------------------------------------------------------------------------
/** This protocol tries to determine the average latency between client and
* server. While this information is not used atm, it might be useful for
* the server to determine how much behind the clients it should start.
* FIXME: ATM the main thread will load the world as part of an update
* of the ProtocolManager (which updates the protocols). Since all protocols
* are locked dusing this update, the synchronisation protocol is actually
* delayed from starting while world is loading (since finding the protocol
* for a message requires the protocol lock) - causing at least two frames
* of significanlty delayed pings :(
*/
LatencyProtocol::LatencyProtocol()
: Protocol(PROTOCOL_SYNCHRONIZATION)
{
unsigned int size = STKHost::get()->getPeerCount();
m_pings.resize(size, std::map<uint32_t,double>());
m_successed_pings.resize(size, 0);
m_total_diff.resize(size, 0);
m_average_ping.resize(size, 0);
m_pings_count = 0;
} // LatencyProtocol
//-----------------------------------------------------------------------------
LatencyProtocol::~LatencyProtocol()
{
} // ~LatencyProtocol
//-----------------------------------------------------------------------------
void LatencyProtocol::setup()
{
Log::info("LatencyProtocol", "Ready !");
} // setup
//-----------------------------------------------------------------------------
/** Called when receiving a message. On the client side the message is a ping
* from the server, which is answered back. On the server the received message
* is a reply to a previous ping request. The server will keep track of
* average latency.
*/
bool LatencyProtocol::notifyEventAsynchronous(Event* event)
{
if (event->getType() != EVENT_TYPE_MESSAGE)
return true;
if(!checkDataSize(event, 5)) return true;
const NetworkString &data = event->data();
uint32_t request = data.getUInt8();
uint32_t sequence = data.getUInt32();
const std::vector<STKPeer*> &peers = STKHost::get()->getPeers();
assert(peers.size() > 0);
// Find the right peer id. The host id (i.e. each host sendings its
// host id) can not be used here, since host ids can have gaps (if a
// host should disconnect)
uint8_t peer_id = -1;
for (unsigned int i = 0; i < peers.size(); i++)
{
if (peers[i]->isSamePeer(event->getPeer()))
{
peer_id = i;
break;
}
}
if (request)
{
// Only a client should receive a request for a ping response
assert(NetworkConfig::get()->isClient());
NetworkString *response = getNetworkString(5);
// The '0' indicates a response to a ping request
response->addUInt8(0).addUInt32(sequence);
event->getPeer()->sendPacket(response, false);
delete response;
}
else // receive response to a ping request
{
// Only a server should receive this kind of message
assert(NetworkConfig::get()->isServer());
if (sequence >= m_pings[peer_id].size())
{
Log::warn("LatencyProtocol",
"The sequence# %u isn't known.", sequence);
return true;
}
double current_time = StkTime::getRealTime();
m_total_diff[peer_id] += current_time - m_pings[peer_id][sequence];
m_successed_pings[peer_id]++;
m_average_ping[peer_id] =
(int)((m_total_diff[peer_id]/m_successed_pings[peer_id])*1000.0);
Log::debug("LatencyProtocol",
"Peer %d sequence %d ping %u average %u at %lf",
peer_id, sequence,
(unsigned int)((current_time - m_pings[peer_id][sequence])*1000),
m_average_ping[peer_id],
StkTime::getRealTime());
}
return true;
} // notifyEventAsynchronous
//-----------------------------------------------------------------------------
/** Waits for the countdown to be started. On the server the start of the
* countdown is triggered by ServerLobby::finishedLoadingWorld(),
* which is called once all clients have confirmed that they are ready to
* start. The server will send a ping request to each client once a second,
* and include the information if the countdown has started (and its current
* value). On the client the countdown is started in notifyEvenAsynchronous()
* when a server ping is received that indicates that the countdown has
* started. The measured times can be used later to estimate the latency
* between server and client.
*/
void LatencyProtocol::asynchronousUpdate()
{
float current_time = float(StkTime::getRealTime());
if (NetworkConfig::get()->isServer() && current_time > m_last_time+1)
{
const std::vector<STKPeer*> &peers = STKHost::get()->getPeers();
for (unsigned int i = 0; i < peers.size(); i++)
{
NetworkString *ping_request =
getNetworkString(5);
ping_request->addUInt8(1).addUInt32(m_pings[i].size());
m_pings[i] [ m_pings_count ] = current_time;
peers[i]->sendPacket(ping_request, false);
delete ping_request;
} // for i M peers
m_last_time = current_time;
m_pings_count++;
} // if current_time > m_last_time + 0.1
} // asynchronousUpdate

Some files were not shown because too many files have changed in this diff Show More