3 using Microsoft.Xna.Framework;
4 using Microsoft.Xna.Framework.Graphics;
6 using System.Diagnostics;
11 partial class GameScreen : Screen
13 private RenderTarget2D renderTargetBackground;
14 private RenderTarget2D renderTarget;
15 private RenderTarget2D renderTargetWater;
16 private RenderTarget2D renderTargetFinal;
19 private readonly Texture2D damageStencil;
20 private readonly Texture2D distortTexture;
22 private float fadeToBlackState;
33 cam.
Translate(
new Vector2(-10.0f, 50.0f));
35 CreateRenderTargets(graphics);
38 CreateRenderTargets(graphics);
42 DamageEffect = EffectLoader.Load(
"Effects/damageshader");
45 GrainEffect = EffectLoader.Load(
"Effects/grainshader");
49 damageStencil = TextureLoader.FromFile(
"Content/Map/walldamage.png");
50 DamageEffect.Parameters[
"xStencil"].SetValue(damageStencil);
54 distortTexture = TextureLoader.FromFile(
"Content/Effects/distortnormals.png");
58 private void CreateRenderTargets(GraphicsDevice graphics)
60 renderTarget?.Dispose();
61 renderTargetBackground?.Dispose();
62 renderTargetWater?.Dispose();
63 renderTargetFinal?.Dispose();
76 selectedItem.AddToGUIUpdateList();
80 selectedSecondaryItem.AddToGUIUpdateList();
95 base.AddToGUIUpdateList();
98 public override void Draw(
double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
120 Stopwatch sw =
new Stopwatch();
123 DrawMap(graphics, spriteBatch, deltaTime);
144 Color indicatorColor = i == 0 ? Color.LightBlue * 0.5f : GUIStyle.Red * 0.5f;
146 spriteBatch, position, cam,
148 GUIStyle.SubmarineLocationIcon.Value.Sprite, indicatorColor);
160 GUI.Draw(cam, spriteBatch);
169 public void DrawMap(GraphicsDevice graphics, SpriteBatch spriteBatch,
double deltaTime)
178 Stopwatch sw =
new Stopwatch();
198 static bool IsFromOutpostDrawnBehindSubs(
Entity e)
199 => e.
Submarine is { Info.OutpostGenerationParams.DrawBehindSubs:
true };
202 graphics.SetRenderTarget(renderTarget);
203 graphics.Clear(Color.Transparent);
207 spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.NonPremultiplied,
null, DepthStencilState.None,
null,
null, cam.
Transform);
208 Submarine.
DrawBack(spriteBatch,
false, e => e is
Structure s && (e.SpriteDepth >= 0.9f || s.Prefab.BackgroundSprite !=
null) && !IsFromOutpostDrawnBehindSubs(e));
216 graphics.SetRenderTarget(
null);
224 graphics.SetRenderTarget(renderTargetBackground);
227 graphics.Clear(
new Color(11, 18, 26, 255));
235 spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.NonPremultiplied,
null, DepthStencilState.None,
null,
null, cam.
Transform);
236 Submarine.
DrawBack(spriteBatch,
false, e => e is
Structure s && (e.SpriteDepth >= 0.9f || s.Prefab.BackgroundSprite !=
null) && IsFromOutpostDrawnBehindSubs(e));
241 spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied,
null, DepthStencilState.None,
null,
null, cam.
Transform);
243 spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied,
null, DepthStencilState.None,
null,
null, cam.
Transform);
249 spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive,
null, DepthStencilState.None,
null,
null, cam.
Transform);
252 spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied,
null, DepthStencilState.None);
263 graphics.SetRenderTarget(renderTarget);
265 graphics.BlendState = BlendState.NonPremultiplied;
266 graphics.SamplerStates[0] = SamplerState.LinearWrap;
267 GraphicsQuad.UseBasicEffect(renderTargetBackground);
268 GraphicsQuad.Render();
271 spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.NonPremultiplied,
null, DepthStencilState.None,
null,
null, cam.
Transform);
273 DrawCharacters(deformed:
false, firstPass:
true);
280 spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied,
null, DepthStencilState.None,
null,
null, cam.
Transform);
281 DrawCharacters(deformed:
true, firstPass:
true);
282 DrawCharacters(deformed:
true, firstPass:
false);
283 DrawCharacters(deformed:
false, firstPass:
false);
286 void DrawCharacters(
bool deformed,
bool firstPass)
317 graphics.SetRenderTarget(renderTargetWater);
319 graphics.BlendState = BlendState.Opaque;
320 graphics.SamplerStates[0] = SamplerState.LinearWrap;
321 GraphicsQuad.UseBasicEffect(renderTarget);
322 GraphicsQuad.Render();
325 spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied,
null, DepthStencilState.DepthRead,
null,
null, cam.
Transform);
329 graphics.SetRenderTarget(renderTarget);
332 spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied,
null, DepthStencilState.DepthRead,
null,
null, cam.
Transform);
337 spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive,
null, DepthStencilState.None,
null,
null, cam.
Transform);
341 graphics.DepthStencilState = DepthStencilState.DepthRead;
342 graphics.SetRenderTarget(renderTargetFinal);
348 graphics.DepthStencilState = DepthStencilState.None;
355 spriteBatch.Begin(SpriteSortMode.Immediate,
356 BlendState.NonPremultiplied, SamplerState.LinearWrap,
367 spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.NonPremultiplied,
null, DepthStencilState.None,
null,
null, cam.
Transform);
376 spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive,
null, DepthStencilState.Default,
null,
null, cam.
Transform);
378 foreach (var discharger
in Items.Components.ElectricalDischarger.List)
380 discharger.DrawElectricity(spriteBatch);
385 graphics.DepthStencilState = DepthStencilState.None;
386 graphics.SamplerStates[0] = SamplerState.LinearWrap;
389 GraphicsQuad.Render();
392 spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.LinearWrap, DepthStencilState.None,
null,
null, cam.
Transform);
434 losColorHls.Y = ambientLightHls.Y;
435 losColor = ToolBox.HLSToRGB(losColorHls);
439 losColor = Color.Black;
444 graphics.BlendState = BlendState.NonPremultiplied;
445 graphics.SamplerStates[0] = SamplerState.PointClamp;
446 graphics.SamplerStates[1] = SamplerState.PointClamp;
448 GraphicsQuad.Render();
449 graphics.SamplerStates[0] = SamplerState.LinearWrap;
450 graphics.SamplerStates[1] = SamplerState.LinearWrap;
455 float grainStrength = character.GrainStrength;
457 spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, effect:
GrainEffect);
458 GUI.DrawRectangle(spriteBatch, screenRect, Color.White, isFilled:
true);
459 GrainEffect.Parameters[
"seed"].SetValue(Rand.Range(0f, 1f, Rand.RandSync.Unsynced));
460 GrainEffect.Parameters[
"intensity"].SetValue(grainStrength);
461 GrainEffect.Parameters[
"grainColor"].SetValue(character.GrainColor.ToVector4());
465 graphics.SetRenderTarget(
null);
467 float BlurStrength = 0.0f;
468 float DistortStrength = 0.0f;
469 Vector3 chromaticAberrationStrength = GameSettings.CurrentConfig.Graphics.ChromaticAberration ?
470 new Vector3(-0.02f, -0.01f, 0.0f) : Vector3.Zero;
481 if (GameSettings.CurrentConfig.Graphics.RadialDistortion)
490 DistortStrength = 0.0f;
493 string postProcessTechnique =
"";
494 if (BlurStrength > 0.0f)
496 postProcessTechnique +=
"Blur";
499 if (chromaticAberrationStrength != Vector3.Zero)
501 postProcessTechnique +=
"ChromaticAberration";
502 PostProcessEffect.Parameters[
"chromaticAberrationStrength"].SetValue(chromaticAberrationStrength);
504 if (DistortStrength > 0.0f)
506 postProcessTechnique +=
"Distort";
507 PostProcessEffect.Parameters[
"distortScale"].SetValue(Vector2.One * DistortStrength);
511 graphics.BlendState = BlendState.Opaque;
512 graphics.SamplerStates[0] = SamplerState.LinearClamp;
513 graphics.DepthStencilState = DepthStencilState.None;
514 if (
string.IsNullOrEmpty(postProcessTechnique))
516 GraphicsQuad.UseBasicEffect(renderTargetFinal);
525 GraphicsQuad.Render();
529 if (fadeToBlackState > 0.0f)
531 spriteBatch.Begin(SpriteSortMode.Deferred);
546 partial
void UpdateProjSpecific(
double deltaTime)
550 fadeToBlackState = Math.Min(fadeToBlackState + (
float)deltaTime, 1.0f);
554 fadeToBlackState = Math.Max(fadeToBlackState - (
float)deltaTime, 0.0f);
557 if (!PlayerInput.PrimaryMouseButtonHeld())
559 Inventory.DraggingSlot =
null;
560 Inventory.DraggingItems.Clear();
void Draw(SpriteBatch spriteBatch)
void UpdateTransform(bool interpolate=true, bool updateListener=true)
void Translate(Vector2 amount)
readonly CharacterParams Params
static void DrawSpeechBubbles(SpriteBatch spriteBatch, Camera cam)
CharacterHealth CharacterHealth
bool CanInteractWith(Character c, float maxDist=200.0f, bool checkVisibility=true, bool skipDistanceCheck=false)
void DoVisibilityCheck(Camera cam)
Vector2? CursorWorldPosition
bool HasEquippedItem(Item item, InvSlotType? slotType=null, Func< InvSlotType, bool > predicate=null)
Item????????? SelectedItem
The primary selected item. It can be any device that character interacts with. This excludes items li...
static readonly List< Character > CharacterList
CharacterInventory Inventory
float ChromaticAberrationStrength
float ObstructVisionAmount
static Character? Controlled
Item SelectedSecondaryItem
The secondary selected item. It's an item other than a device (see SelectedItem), e....
static void AddAllToGUIUpdateList()
bool IsVisible
Is the character currently visible on the camera. Refresh the value by calling DoVisibilityCheck.
virtual void DrawFront(SpriteBatch spriteBatch, Camera cam)
void DrawGUIMessages(SpriteBatch spriteBatch, Camera cam)
void Draw(SpriteBatch spriteBatch, Camera cam)
readonly AnimController AnimController
float RadialDistortStrength
void DrawHUD(SpriteBatch spriteBatch, Camera cam, bool drawHealth=true)
Triggers a "conversation popup" with text and support for different branching options.
static bool FadeScreenToBlack
void DebugDraw(SpriteBatch spriteBatch)
static GameSession?? GameSession
static RasterizerState ScissorTestEnable
static PerformanceCounter PerformanceCounter
static int GraphicsHeight
static Lights.LightManager LightManager
Action ResolutionChanged
NOTE: Use very carefully. You need to ensure that you ALWAYS unsubscribe from this when you no longer...
static ParticleManager ParticleManager
void DrawMap(GraphicsDevice graphics, SpriteBatch spriteBatch, double deltaTime)
GameScreen(GraphicsDevice graphics)
Effect ThresholdTintEffect
override void AddToGUIUpdateList()
By default, submits the screen's main GUIFrame and, if requested upon construction,...
override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
readonly Effect DamageEffect
void AddToGUIUpdateList()
readonly EventManager EventManager
void Draw(SpriteBatch spriteBatch)
static void UpdateVertices(Camera cam, WaterRenderer renderer)
virtual IEnumerable< Item > AllItems
All items contained in the inventory. Stacked items are returned as individual instances....
override void AddToGUIUpdateList(int order=0)
void DrawBack(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam)
void DrawDebugOverlay(SpriteBatch spriteBatch, Camera cam)
void DrawFront(SpriteBatch spriteBatch, Camera cam)
float ChromaticAberrationStrength
static BlendState Multiplicative
void DebugDrawLos(SpriteBatch spriteBatch, Camera cam)
float ObstructVisionAmount
RenderTarget2D LosTexture
void DebugDrawVertices(SpriteBatch spriteBatch)
void RenderLightMap(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam, RenderTarget2D backgroundObstructor=null)
void UpdateObstructVision(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam, Vector2 lookAtPosition)
static readonly List< MapEntity > MapEntityList
static void DrawFront(SpriteBatch spriteBatch, bool editing=false, Predicate< MapEntity > predicate=null)
static void DrawPaintedColors(SpriteBatch spriteBatch, bool editing=false, Predicate< MapEntity > predicate=null)
static void DrawDamageable(SpriteBatch spriteBatch, Effect damageEffect, bool editing=false, Predicate< MapEntity > predicate=null)
static readonly Submarine[] MainSubs
override Vector2? WorldPosition
static void CullEntities(Camera cam)
static List< Submarine > Loaded
Vector2 HiddenSubPosition
static void DrawBack(SpriteBatch spriteBatch, bool editing=false, Predicate< MapEntity > predicate=null)
void UpdateTransform(bool interpolate=true)
Rectangle? Borders
Extents of the solid items/structures (ones with a physics body) and hulls
void RenderAir(GraphicsDevice graphicsDevice, Camera cam, RenderTarget2D texture, Matrix transform)
void RenderWater(SpriteBatch spriteBatch, RenderTarget2D texture, Camera cam)
static WaterRenderer Instance