diff --git a/game/graphics.cc b/game/graphics.cc index a773c01..a4b6636 100644 --- a/game/graphics.cc +++ b/game/graphics.cc @@ -35,6 +35,228 @@ Graphics::Graphics(glm::uvec2 windowSize, float nearPlane, Graphics::Graphics() { } +Graphics::Graphics(const Graphics &other) { + std::lock_guard lock(other.init_mutex); + lastLightUpdate = other.lastLightUpdate; + lastWindUpdate = other.lastWindUpdate; + windTarget = other.windTarget; + wind = other.wind; + windDirection = other.windDirection; + windDirectionTarget = other.windDirectionTarget; + textureMovementPosition = other.textureMovementPosition; + windowSize = other.windowSize; + nearPlane = other.nearPlane; + farPlane = other.farPlane; + loadingScreenPath = other.loadingScreenPath; + loadingScreenContinuePath = other.loadingScreenContinuePath; + loadingScreen = other.loadingScreen; + loadingContinueScreen = other.loadingContinueScreen; + closestLights = other.closestLights; + closestFlames = other.closestFlames; + loadingShader = other.loadingShader; + lightingShader = other.lightingShader; + skydomeShader = other.skydomeShader; + depthCubeShader = other.depthCubeShader; + depthShader = other.depthShader; + flameShader = other.flameShader; + flamePostShader = other.flamePostShader; + depth_directionalMaps = other.depth_directionalMaps; + framebuffer_directional = other.framebuffer_directional; + depth_cubeMaps = other.depth_cubeMaps; + framebuffer_cube = other.framebuffer_cube; + framebuffer_light = other.framebuffer_light; + light_fbo_color_texture = other.light_fbo_color_texture; + light_fbo_depth_texture = other.light_fbo_depth_texture; + fullscreen_quad = other.fullscreen_quad; + fullscreen_quad_ab = other.fullscreen_quad_ab; + fullscreen_quad_loading = other.fullscreen_quad_loading; + fullscreen_quad_ab_loading = other.fullscreen_quad_ab_loading; + cube_size = other.cube_size; + maxShadowRenderCount = other.maxShadowRenderCount; + level = other.level; + number_of_texture_units = other.number_of_texture_units; + gameStart = other.gameStart; + loadingScreenWidth = other.loadingScreenWidth; + loadingScreenHeight = other.loadingScreenHeight; + renderShadows = other.renderShadows; + renderFlames = other.renderFlames; + renderDebug = other.renderDebug; + renderWorld = other.renderWorld; + debugDrawer = other.debugDrawer; + debug_ab = other.debug_ab; + debug_vao = other.debug_vao; + debugShader = other.debugShader; + renderQueue = other.renderQueue; +} + +Graphics::Graphics(Graphics &&other) { + std::lock_guard lock(other.init_mutex); + lastLightUpdate = std::move(other.lastLightUpdate); + lastWindUpdate = std::move(other.lastWindUpdate); + windTarget = std::move(other.windTarget); + wind = std::move(other.wind); + windDirection = std::move(other.windDirection); + windDirectionTarget = std::move(other.windDirectionTarget); + textureMovementPosition = std::move(other.textureMovementPosition); + windowSize = std::move(other.windowSize); + nearPlane = std::move(other.nearPlane); + farPlane = std::move(other.farPlane); + loadingScreenPath = std::move(other.loadingScreenPath); + loadingScreenContinuePath = std::move(other.loadingScreenContinuePath); + loadingScreen = std::move(other.loadingScreen); + loadingContinueScreen = std::move(other.loadingContinueScreen); + closestLights = std::move(other.closestLights); + closestFlames = std::move(other.closestFlames); + loadingShader = std::move(other.loadingShader); + lightingShader = std::move(other.lightingShader); + skydomeShader = std::move(other.skydomeShader); + depthCubeShader = std::move(other.depthCubeShader); + depthShader = std::move(other.depthShader); + flameShader = std::move(other.flameShader); + flamePostShader = std::move(other.flamePostShader); + depth_directionalMaps = std::move(other.depth_directionalMaps); + framebuffer_directional = std::move(other.framebuffer_directional); + depth_cubeMaps = std::move(other.depth_cubeMaps); + framebuffer_cube = std::move(other.framebuffer_cube); + framebuffer_light = std::move(other.framebuffer_light); + light_fbo_color_texture = std::move(other.light_fbo_color_texture); + light_fbo_depth_texture = std::move(other.light_fbo_depth_texture); + fullscreen_quad = std::move(other.fullscreen_quad); + fullscreen_quad_ab = std::move(other.fullscreen_quad_ab); + fullscreen_quad_loading = std::move(other.fullscreen_quad_loading); + fullscreen_quad_ab_loading = std::move(other.fullscreen_quad_ab_loading); + cube_size = std::move(other.cube_size); + maxShadowRenderCount = std::move(other.maxShadowRenderCount); + level = std::move(other.level); + number_of_texture_units = std::move(other.number_of_texture_units); + gameStart = std::move(other.gameStart); + loadingScreenWidth = std::move(other.loadingScreenWidth); + loadingScreenHeight = std::move(other.loadingScreenHeight); + renderShadows = std::move(other.renderShadows); + renderFlames = std::move(other.renderFlames); + renderDebug = std::move(other.renderDebug); + renderWorld = std::move(other.renderWorld); + debugDrawer = std::move(other.debugDrawer); + debug_ab = std::move(other.debug_ab); + debug_vao = std::move(other.debug_vao); + debugShader = std::move(other.debugShader); + renderQueue = std::move(other.renderQueue); +} + +Graphics& Graphics::operator= (const Graphics &other) { + std::lock(init_mutex, other.init_mutex); + std::lock_guard self_lock(init_mutex, std::adopt_lock); + std::lock_guard other_lock(other.init_mutex, std::adopt_lock); + lastLightUpdate = other.lastLightUpdate; + lastWindUpdate = other.lastWindUpdate; + windTarget = other.windTarget; + wind = other.wind; + windDirection = other.windDirection; + windDirectionTarget = other.windDirectionTarget; + textureMovementPosition = other.textureMovementPosition; + windowSize = other.windowSize; + nearPlane = other.nearPlane; + farPlane = other.farPlane; + loadingScreenPath = other.loadingScreenPath; + loadingScreenContinuePath = other.loadingScreenContinuePath; + loadingScreen = other.loadingScreen; + loadingContinueScreen = other.loadingContinueScreen; + closestLights = other.closestLights; + closestFlames = other.closestFlames; + loadingShader = other.loadingShader; + lightingShader = other.lightingShader; + skydomeShader = other.skydomeShader; + depthCubeShader = other.depthCubeShader; + depthShader = other.depthShader; + flameShader = other.flameShader; + flamePostShader = other.flamePostShader; + depth_directionalMaps = other.depth_directionalMaps; + framebuffer_directional = other.framebuffer_directional; + depth_cubeMaps = other.depth_cubeMaps; + framebuffer_cube = other.framebuffer_cube; + framebuffer_light = other.framebuffer_light; + light_fbo_color_texture = other.light_fbo_color_texture; + light_fbo_depth_texture = other.light_fbo_depth_texture; + fullscreen_quad = other.fullscreen_quad; + fullscreen_quad_ab = other.fullscreen_quad_ab; + fullscreen_quad_loading = other.fullscreen_quad_loading; + fullscreen_quad_ab_loading = other.fullscreen_quad_ab_loading; + cube_size = other.cube_size; + maxShadowRenderCount = other.maxShadowRenderCount; + level = other.level; + number_of_texture_units = other.number_of_texture_units; + gameStart = other.gameStart; + loadingScreenWidth = other.loadingScreenWidth; + loadingScreenHeight = other.loadingScreenHeight; + renderShadows = other.renderShadows; + renderFlames = other.renderFlames; + renderDebug = other.renderDebug; + renderWorld = other.renderWorld; + debugDrawer = other.debugDrawer; + debug_ab = other.debug_ab; + debug_vao = other.debug_vao; + debugShader = other.debugShader; + renderQueue = other.renderQueue; + return *this; +} + +Graphics& Graphics::operator= (Graphics &&other) { + std::lock(init_mutex, other.init_mutex); + std::lock_guard self_lock(init_mutex, std::adopt_lock); + std::lock_guard other_lock(other.init_mutex, std::adopt_lock); + lastLightUpdate = std::move(other.lastLightUpdate); + lastWindUpdate = std::move(other.lastWindUpdate); + windTarget = std::move(other.windTarget); + wind = std::move(other.wind); + windDirection = std::move(other.windDirection); + windDirectionTarget = std::move(other.windDirectionTarget); + textureMovementPosition = std::move(other.textureMovementPosition); + windowSize = std::move(other.windowSize); + nearPlane = std::move(other.nearPlane); + farPlane = std::move(other.farPlane); + loadingScreenPath = std::move(other.loadingScreenPath); + loadingScreenContinuePath = std::move(other.loadingScreenContinuePath); + loadingScreen = std::move(other.loadingScreen); + loadingContinueScreen = std::move(other.loadingContinueScreen); + closestLights = std::move(other.closestLights); + closestFlames = std::move(other.closestFlames); + loadingShader = std::move(other.loadingShader); + lightingShader = std::move(other.lightingShader); + skydomeShader = std::move(other.skydomeShader); + depthCubeShader = std::move(other.depthCubeShader); + depthShader = std::move(other.depthShader); + flameShader = std::move(other.flameShader); + flamePostShader = std::move(other.flamePostShader); + depth_directionalMaps = std::move(other.depth_directionalMaps); + framebuffer_directional = std::move(other.framebuffer_directional); + depth_cubeMaps = std::move(other.depth_cubeMaps); + framebuffer_cube = std::move(other.framebuffer_cube); + framebuffer_light = std::move(other.framebuffer_light); + light_fbo_color_texture = std::move(other.light_fbo_color_texture); + light_fbo_depth_texture = std::move(other.light_fbo_depth_texture); + fullscreen_quad = std::move(other.fullscreen_quad); + fullscreen_quad_ab = std::move(other.fullscreen_quad_ab); + fullscreen_quad_loading = std::move(other.fullscreen_quad_loading); + fullscreen_quad_ab_loading = std::move(other.fullscreen_quad_ab_loading); + cube_size = std::move(other.cube_size); + maxShadowRenderCount = std::move(other.maxShadowRenderCount); + level = std::move(other.level); + number_of_texture_units = std::move(other.number_of_texture_units); + gameStart = std::move(other.gameStart); + loadingScreenWidth = std::move(other.loadingScreenWidth); + loadingScreenHeight = std::move(other.loadingScreenHeight); + renderShadows = std::move(other.renderShadows); + renderFlames = std::move(other.renderFlames); + renderDebug = std::move(other.renderDebug); + renderWorld = std::move(other.renderWorld); + debugDrawer = std::move(other.debugDrawer); + debug_ab = std::move(other.debug_ab); + debug_vao = std::move(other.debug_vao); + debugShader = std::move(other.debugShader); + renderQueue = std::move(other.renderQueue); + return *this; +} + void Graphics::init(Level* level) { // save Level diff --git a/game/graphics.hh b/game/graphics.hh index 3808657..cdfc5f3 100644 --- a/game/graphics.hh +++ b/game/graphics.hh @@ -16,6 +16,10 @@ class Graphics { Graphics(glm::uvec2 windowSize, float nearPlane, float farPlane, int cube_size, unsigned int maxShadowRenderCount, std::string screenPath, std::string screenContinuePath); + Graphics(const Graphics &other); + Graphics(Graphics &&other); + Graphics& operator= (const Graphics &other); + Graphics& operator= (Graphics &&other); Graphics(); void init(Level* level); void render(double time); @@ -88,6 +92,7 @@ class Graphics { SharedVertexArrayObject debug_vao; SharedShaderProgram debugShader; std::vector>*> renderQueue; + mutable std::mutex init_mutex; }; #endif