From a634519a163e6bbf763fbc9f7491c20e01cae5b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sat, 14 Nov 2020 12:01:49 +0100 Subject: [PATCH] Fix visibility --- game.h | 15 +++++++++++++-- index.html | 3 ++- main_sdl.c | 8 +++++++- settings.h | 34 +++++++++++++++++++++++++++++++++- 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/game.h b/game.h index 06374df..81397d5 100755 --- a/game.h +++ b/game.h @@ -353,7 +353,8 @@ struct uint8_t soundsPlayedThisFrame; /**< Each bit says whether given sound was played this frame, prevents playing too many sounds at once. */ - RCL_RayConstraints rayConstraints; + RCL_RayConstraints rayConstraints; ///< Ray constraints for rendering. + RCL_RayConstraints visibilityRayConstraints; ///< Constraints for visibility. uint8_t keyStates[SFG_KEY_COUNT]; /**< Pressed states of keys, each value stores the number of frames for which the key has been held. */ @@ -1662,6 +1663,12 @@ void SFG_init() SFG_game.rayConstraints.maxHits = SFG_RAYCASTING_MAX_HITS; SFG_game.rayConstraints.maxSteps = SFG_RAYCASTING_MAX_STEPS; + RCL_initRayConstraints(&SFG_game.visibilityRayConstraints); + SFG_game.visibilityRayConstraints.maxHits = + SFG_RAYCASTING_VISIBILITY_MAX_HITS; + SFG_game.visibilityRayConstraints.maxSteps = + SFG_RAYCASTING_VISIBILITY_MAX_STEPS; + SFG_game.antiSpam = 0; SFG_LOG("computing average texture colors") @@ -1734,6 +1741,10 @@ void SFG_init() SFG_game.save[0] = SFG_NUMBER_OF_LEVELS - 1; // revealed all levels } +#if SFG_ALL_LEVELS + SFG_game.save[0] = SFG_NUMBER_OF_LEVELS - 1; +#endif + SFG_setMusic((SFG_game.settings & 0x02) ? SFG_MUSIC_TURN_ON : SFG_MUSIC_TURN_OFF); @@ -2868,7 +2879,7 @@ static inline uint8_t SFG_spriteIsVisible(RCL_Vector2D pos, RCL_Unit height, height, SFG_floorHeightAt, SFG_ceilingHeightAt, - SFG_game.rayConstraints + SFG_game.visibilityRayConstraints ) == RCL_UNITS_PER_SQUARE; } diff --git a/index.html b/index.html index bf5f3b8..adcd5d2 100644 --- a/index.html +++ b/index.html @@ -257,12 +257,13 @@

Explore

diff --git a/main_sdl.c b/main_sdl.c index 3afeb4d..bdd0fd3 100644 --- a/main_sdl.c +++ b/main_sdl.c @@ -26,11 +26,13 @@ // #define SFG_START_LEVEL 1 #define SFG_IMMORTAL 1 - #define SFG_UNLOCK_DOOR 1 + #define SFG_ALL_LEVELS 1 +// #define SFG_UNLOCK_DOOR 1 // #define SFG_REVEAL_MAP 1 // #define SFG_INFINITE_AMMO 1 // #define SFG_TIME_MULTIPLIER 512 // #define SFG_CPU_LOAD(percent) printf("CPU load: %d%\n",percent); +#define GAME_LQ #ifndef __EMSCRIPTEN__ #ifndef GAME_LQ @@ -53,6 +55,8 @@ #define SFG_DIMINISH_SPRITES 0 #define SFG_DITHERED_SHADOW 0 #define SFG_BACKGROUND_BLUR 0 + #define SFG_RAYCASTING_MAX_STEPS 20 + #define SFG_RAYCASTING_MAX_HITS 8 #endif #else // emscripten @@ -63,6 +67,8 @@ #define SFG_RESOLUTION_SCALEDOWN 2 #define SFG_DITHERED_SHADOW 1 #define SFG_BACKGROUND_BLUR 0 + #define SFG_RAYCASTING_MAX_STEPS 20 + #define SFG_RAYCASTING_MAX_HITS 8 #include #endif diff --git a/settings.h b/settings.h index fb63bec..ae75a6d 100644 --- a/settings.h +++ b/settings.h @@ -164,6 +164,30 @@ #define SFG_RAYCASTING_MAX_HITS 10 #endif +/** + Same as SFG_RAYCASTING_MAX_STEPS but for visibility rays that are used to + check whether sprites are visible etc. +*/ +#ifndef SFG_RAYCASTING_VISIBILITY_MAX_STEPS + #if SFG_RAYCASTING_MAX_STEPS < 15 + #define SFG_RAYCASTING_VISIBILITY_MAX_STEPS 15 + #else + #define SFG_RAYCASTING_VISIBILITY_MAX_STEPS SFG_RAYCASTING_MAX_STEPS + #endif +#endif + +/** + Same as SFG_RAYCASTING_MAX_HITS but for visibility rays that are used to check + whether sprites are visible etc. +*/ +#ifndef SFG_RAYCASTING_VISIBILITY_MAX_HITS + #if SFG_RAYCASTING_MAX_HITS < 6 + #define SFG_RAYCASTING_VISIBILITY_MAX_HITS 6 + #else + #define SFG_RAYCASTING_VISIBILITY_MAX_HITS SFG_RAYCASTING_MAX_HITS + #endif +#endif + /** How many times rendering should be subsampled horizontally. Bigger number can significantly improve performance (by casting fewer rays), but can look @@ -396,7 +420,8 @@ look weirdly scaled, so this option can be used to fix that. */ #ifndef SFG_SPRITE_MAX_SIZE - #define SFG_SPRITE_MAX_SIZE SFG_SCREEN_RESOLUTION_Y + #define SFG_SPRITE_MAX_SIZE \ + (SFG_SCREEN_RESOLUTION_Y / SFG_RESOLUTION_SCALEDOWN) #endif /** @@ -422,6 +447,13 @@ #define SFG_IMMORTAL 0 #endif +/** + Reveals all levels to be played. +*/ +#ifndef SFG_ALL_LEVELS + #define SFG_ALL_LEVELS 0 +#endif + /** Turn on for previes mode for map editing (flying, noclip, fast movement etc.). */