Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BYOND Parity Renderer #1043

Merged
merged 164 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 158 commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
e6eb295
start
amylizzle Jan 8, 2023
c0cb2ea
going to bed, stupid confusing coordinate system
amylizzle Jan 8, 2023
e5806a3
Merge remote-tracking branch 'upstream/master' into renderer
amylizzle Jan 21, 2023
f1ab3ff
now we're getting somewhere
amylizzle Jan 21, 2023
1634052
move map tiles into the normal rendering queue
amylizzle Jan 21, 2023
4bbe856
add some map objects to test with
amylizzle Jan 21, 2023
c3edf22
my brain hurts
amylizzle Jan 21, 2023
7a61b3e
go faster
amylizzle Jan 21, 2023
2502cb3
default plane value should be 0
amylizzle Jan 21, 2023
9844564
fold screen objects into the normal rendering
amylizzle Jan 22, 2023
d92cb38
subplane
amylizzle Jan 22, 2023
7e69604
Correct for coordinate systems and render offsets
amylizzle Jan 22, 2023
7dd4cbe
appearance flags part 1 - TODO redo mouse stuff
amylizzle Jan 25, 2023
c645da4
some todo messages so I don't forget
amylizzle Jan 25, 2023
8753871
KT group rendering
amylizzle Jan 26, 2023
348a6d3
implement alpha and colour
amylizzle Jan 26, 2023
64fdd57
Planemaster begin
amylizzle Jan 26, 2023
5114d11
fix broken overlays
amylizzle Jan 26, 2023
c3950e7
start of mouse map
amylizzle Jan 26, 2023
b9b447e
honestly I'm amazed this works
amylizzle Jan 26, 2023
1c9d6ef
correct
amylizzle Jan 26, 2023
cf3e5f1
clean up a bit, memory leak though?
amylizzle Jan 26, 2023
15a4d1c
fixed the memory leak
amylizzle Jan 27, 2023
ee4bbe0
this would work if getpixel didn't return garbage
amylizzle Jan 27, 2023
9061800
click detection works if the RT thing is merged
amylizzle Jan 27, 2023
8784156
fix a couple things, add a debug overlay command
amylizzle Jan 27, 2023
f892722
toggle screen overlay
amylizzle Jan 27, 2023
287caaa
blendmodes start
amylizzle Jan 28, 2023
a14e8b2
probably break plane masters
amylizzle Jan 28, 2023
e2554c7
move to pc
amylizzle Jan 28, 2023
5b01462
good news, all non-default blend modes now fail to render!
amylizzle Jan 28, 2023
42d751c
fix blendmode shaders
amylizzle Jan 28, 2023
0efc000
Merge remote-tracking branch 'upstream/master' into renderer
amylizzle Jan 29, 2023
0e8444c
correct light_mode on shaders
amylizzle Jan 30, 2023
3000af8
transforms
amylizzle Jan 30, 2023
8ac106e
plane transform correction
amylizzle Jan 30, 2023
5e702f5
render source and target, first draft, broken
amylizzle Jan 30, 2023
0299477
less broken, still broken
amylizzle Jan 30, 2023
15bec9d
remove paradise code, add some render tests to testgame
amylizzle Feb 1, 2023
a80f3a7
keeptogether tests
amylizzle Feb 1, 2023
d1a0e6f
tiny bugfix for null mousemap
amylizzle Feb 1, 2023
bdd9c70
fix some things
amylizzle Feb 2, 2023
0470f45
fix overlays from my stupid mistak
amylizzle Feb 3, 2023
dee342b
mostly fix kt groups, transform issue?
amylizzle Feb 3, 2023
55aeda7
Merge remote-tracking branch 'upstream/master' into renderer
amylizzle Feb 4, 2023
509fa5e
Fix reveresd rotation transform
amylizzle Feb 4, 2023
a541dea
comment
amylizzle Feb 4, 2023
aacb640
something wrong with my transforms?
amylizzle Feb 5, 2023
1351202
I think that's got it
amylizzle Feb 6, 2023
20993dc
fix color application
amylizzle Feb 6, 2023
aabb232
render source test
amylizzle Feb 6, 2023
de9d482
partial fix for render source
amylizzle Feb 6, 2023
13f1f37
fix render targets
amylizzle Feb 7, 2023
762a74b
translate test
amylizzle Feb 7, 2023
8651d01
make render source only apply after button push
amylizzle Feb 7, 2023
7165e63
fix minor bug in kt groups
amylizzle Feb 9, 2023
1db28fb
background image test
amylizzle Feb 10, 2023
0088591
better sprite
amylizzle Feb 10, 2023
d3331e4
planemaster lighting test
amylizzle Feb 10, 2023
204e407
clean up a comment
amylizzle Feb 10, 2023
0e5c397
Plane masters
amylizzle Feb 10, 2023
f611b4e
set up for coordinate correction + shader application
amylizzle Feb 11, 2023
c6b4d0f
byond-matching behaviour - we need color matrices
amylizzle Feb 11, 2023
65f1b51
fix ordering
amylizzle Feb 11, 2023
1a0c843
well that's a lot better way of doing it
amylizzle Feb 11, 2023
2819fab
correct plane master rendering, and use the same system for render ta…
amylizzle Feb 11, 2023
06af7b3
alpha test
amylizzle Feb 11, 2023
134efba
Alpha filter, broken
amylizzle Feb 11, 2023
3f78142
oops
amylizzle Feb 11, 2023
a4fd1c0
I'm an idiot
amylizzle Feb 11, 2023
f0f2329
oops again
amylizzle Feb 11, 2023
cea3d8b
oops some more
amylizzle Feb 11, 2023
c2325a4
add verbs to atoms for click behaviour
amylizzle Feb 12, 2023
dcd8e75
wait its simpler than that
amylizzle Feb 12, 2023
1fd7cf8
add TODO for mouse input popup menus
amylizzle Feb 12, 2023
28f37e4
render order test start
amylizzle Feb 12, 2023
84aaa4d
layer and plane master tests
amylizzle Feb 12, 2023
7be1909
fix a couple render order bugs
amylizzle Feb 12, 2023
5db8eea
rendersource/target test
amylizzle Feb 12, 2023
8f70ba3
Fix render target positioning again
amylizzle Feb 12, 2023
e537547
pretty sure this is correct behaviour. TODO planemaster rendersource
amylizzle Feb 12, 2023
4de0953
alpha filter rendersource test
amylizzle Feb 12, 2023
36c4da4
slightly broken alpha filter
amylizzle Feb 13, 2023
2836fa7
replace checker iconstate
amylizzle Feb 13, 2023
79b176c
fixed alpha filter working with render sources
amylizzle Feb 13, 2023
78b9dff
prevent filters from applying twice in render targets
amylizzle Feb 13, 2023
35fa010
image test
amylizzle Feb 13, 2023
ebfe41c
enable the various image features
amylizzle Feb 13, 2023
ece9a7d
Merge remote-tracking branch 'upstream/master' into renderer
amylizzle Feb 13, 2023
d4328d4
apply transforms from def
amylizzle Feb 13, 2023
9c000a0
minor mistake in transforms
amylizzle Feb 13, 2023
b8d889e
rendersource+plane_master+alpha flags
amylizzle Feb 15, 2023
2ea643a
fully implement flags for alpha, minor scaling issue
amylizzle Feb 15, 2023
337a8c0
the third or forth, maybe fifth time is the charm
amylizzle Feb 15, 2023
c096df2
Fix mouse map
amylizzle Feb 15, 2023
79dd39d
couple code cleanup bits
amylizzle Feb 15, 2023
1d3b31f
fix bug
amylizzle Feb 15, 2023
61004c9
fix another bug
amylizzle Feb 16, 2023
14f0779
fix tiny bug with /image
amylizzle Feb 16, 2023
e4b52bd
tiny bug in contextmenu item icons
amylizzle Feb 16, 2023
1d1a435
I swear this is the last time I rewrite the render pipleine
amylizzle Feb 17, 2023
9d5452c
Merge remote-tracking branch 'upstream/master' into renderer
amylizzle Feb 27, 2023
5773823
adjust world view value to be right
amylizzle Mar 1, 2023
410979f
Merge remote-tracking branch 'upstream/master' into renderer
amylizzle Mar 9, 2023
e9f387e
render meta rental
amylizzle Mar 9, 2023
91d0b23
does this fix it?
amylizzle Mar 19, 2023
b46ea3c
go faster
amylizzle Mar 19, 2023
c1701fe
go faster?
amylizzle Mar 19, 2023
f4ec0c3
don't allocate KT list unless you need to
amylizzle Mar 19, 2023
c418469
oops
amylizzle Mar 19, 2023
46c27fe
Merge remote-tracking branch 'upstream/master' into renderer
amylizzle Mar 19, 2023
2dde48d
rename the rental functions
amylizzle Mar 19, 2023
75c540e
okay, *this* is the last time I rewrite the renderer pipeline
amylizzle Mar 21, 2023
07eec3d
it was dangerous
amylizzle Mar 21, 2023
7a3e161
how many times must I teach you this lesson old man?
amylizzle Mar 21, 2023
f95688d
Merge remote-tracking branch 'upstream/master' into renderer
amylizzle Mar 21, 2023
9b107d7
null ref fix
amylizzle Mar 22, 2023
54c8709
hey altoids look at this
amylizzle Mar 23, 2023
f95102c
this works really well for how jank it is
amylizzle Mar 23, 2023
907a1e5
work good, go fast
amylizzle Mar 23, 2023
950b3fe
Merge remote-tracking branch 'upstream/master' into renderer
amylizzle Apr 1, 2023
030c9af
todo: fix color to use the blendmode shaders
amylizzle Apr 1, 2023
0d8f569
some minor test changes
amylizzle Apr 2, 2023
29dfa33
test buttons
amylizzle Apr 2, 2023
1cfa04d
buttery smooth
amylizzle Apr 2, 2023
9e25a83
broke it
amylizzle Apr 2, 2023
f708118
I might be an idiot
amylizzle Apr 4, 2023
757349f
Merge remote-tracking branch 'upstream/master' into renderer
amylizzle Apr 4, 2023
9a4dac9
mousemap too
amylizzle Apr 4, 2023
bd7be6e
see_invisible
amylizzle Apr 4, 2023
747633d
little tweak
amylizzle Apr 4, 2023
9d9d88e
fixed it
amylizzle Apr 4, 2023
3833d2b
cull one extra draw
amylizzle Apr 4, 2023
21fe985
ghosty
amylizzle Apr 4, 2023
18dc736
color filter go fast
amylizzle Apr 5, 2023
4eccd83
fix mouse overlay bug
amylizzle Apr 5, 2023
0f62897
Apply suggestions from code review
amylizzle Apr 8, 2023
42fbb4d
style changes
amylizzle Apr 8, 2023
1886c5e
remove z fighting check since it obviously doesn't work
amylizzle Apr 8, 2023
05c0f82
blendmode enum
amylizzle Apr 8, 2023
f56d268
More blendmode enum stuff
amylizzle Apr 8, 2023
9b6650e
AppearanceFlags
amylizzle Apr 8, 2023
fa6f06d
clientAppearanceComponent (broken)
amylizzle Apr 9, 2023
4b4be2f
fixed
amylizzle Apr 9, 2023
10842ad
Make it mobsight component instead
amylizzle Apr 9, 2023
e091b4c
comments and a client images test
amylizzle Apr 9, 2023
d13cd9e
rename a var
amylizzle Apr 9, 2023
7ca85e4
tiny fix
amylizzle Apr 9, 2023
59dd5bd
well that's weird
amylizzle Apr 9, 2023
3758423
plane is an int
amylizzle Apr 9, 2023
3bb9b3f
speeelin
amylizzle Apr 9, 2023
0711cd8
I fucking hate byond
amylizzle Apr 10, 2023
e044101
position matters too
amylizzle Apr 10, 2023
c7005f7
partially fixed lighting
amylizzle Apr 10, 2023
9edd8e3
still not right, but I'm tired
amylizzle Apr 10, 2023
9a6b24d
Fixed paradise lighting (holy shit finally)
amylizzle Apr 11, 2023
8e12899
Merge remote-tracking branch 'upstream/master' into renderer
amylizzle Apr 11, 2023
252ccb7
fixed render sources, alpha, and overlay blend mode
amylizzle Apr 11, 2023
4c7fa6e
Update Resources/Shaders/alpha.swsl
amylizzle Apr 11, 2023
62dbb78
Update Resources/Shaders/alpha.swsl
amylizzle Apr 11, 2023
5230a21
Update OpenDreamShared/Rendering/DreamMobSightComponent.cs
amylizzle Apr 11, 2023
d6bd739
Update OpenDreamRuntime/Objects/MetaObjects/DreamMetaObjectMob.cs
amylizzle Apr 11, 2023
4acaba8
codereview
amylizzle Apr 11, 2023
254ac89
Merge remote-tracking branch 'upstream/master' into renderer
amylizzle Apr 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Content.Tests/DMProject/Tests/Stdlib/newmob.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/proc/RunTest()
var/mob/testmob = new
2 changes: 2 additions & 0 deletions Content.Tests/DMTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using OpenDreamRuntime.Objects;
using OpenDreamRuntime.Procs;
using OpenDreamRuntime.Rendering;
using OpenDreamShared.Rendering;
using Robust.Shared.Asynchronous;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
Expand Down Expand Up @@ -47,6 +48,7 @@ public void OneTimeSetup() {
_taskManager.Initialize();
IComponentFactory componentFactory = IoCManager.Resolve<IComponentFactory>();
componentFactory.RegisterClass<DMISpriteComponent>();
componentFactory.RegisterClass<DreamMobSightComponent>(); //wow this is terrible TODO figure out why this is necessary
componentFactory.GenerateNetIds();
Compile(InitializeEnvironment);
_dreamMan.PreInitialize(Path.ChangeExtension(InitializeEnvironment, "json"));
Expand Down
2 changes: 1 addition & 1 deletion DMCompiler/DMStandard/Defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define OBJ_LAYER 3
#define MOB_LAYER 4
#define FLY_LAYER 5
#define EFFECTS_LAYER 19999
#define EFFECTS_LAYER 5000
#define BACKGROUND_LAYER 20000

#define FLOAT_PLANE -32767
Expand Down
10 changes: 5 additions & 5 deletions DMCompiler/DMStandard/Types/Atoms/_Atom.dm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
var/icon = null
var/icon_state = ""
var/layer = 2.0
var/plane = FLOAT_PLANE as opendream_unimplemented
var/plane = 0
var/alpha = 255
var/color = "#FFFFFF"
var/invisibility = 0
Expand All @@ -36,7 +36,7 @@
var/luminosity = 0 as opendream_unimplemented
var/opacity = 0 as opendream_unimplemented
var/matrix/transform
var/blend_mode = 0 as opendream_unimplemented
var/blend_mode = 0

var/gender = NEUTER
var/density = FALSE
Expand All @@ -45,18 +45,18 @@

var/list/filters = null
var/appearance as opendream_unimplemented
var/appearance_flags as opendream_unimplemented
var/appearance_flags = 0
var/maptext_width as opendream_unimplemented
var/maptext_height as opendream_unimplemented
var/maptext_x = 32 as opendream_unimplemented
var/maptext_y = 32 as opendream_unimplemented
var/step_x as opendream_unimplemented
var/step_y as opendream_unimplemented
var/render_source as opendream_unimplemented
var/render_source
var/mouse_drag_pointer as opendream_unimplemented
var/mouse_drop_pointer as opendream_unimplemented
var/mouse_over_pointer as opendream_unimplemented
var/render_target as opendream_unimplemented
var/render_target
var/vis_flags as opendream_unimplemented

proc/Click(location, control, params)
Expand Down
12 changes: 6 additions & 6 deletions DMCompiler/DMStandard/Types/Image.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

var/alpha = 255
var/appearance as opendream_unimplemented
var/appearance_flags = 0 as opendream_unimplemented
var/blend_mode = 0 as opendream_unimplemented
var/appearance_flags = 0
var/blend_mode = 0
var/color = "#FFFFFF"
var/desc = null
var/gender = "neuter" as opendream_unimplemented
Expand All @@ -31,9 +31,9 @@
var/pixel_y = 0
var/pixel_w = 0 as opendream_unimplemented
var/pixel_z = 0 as opendream_unimplemented
var/plane = FLOAT_PLANE as opendream_unimplemented
var/render_source as opendream_unimplemented
var/render_target as opendream_unimplemented
var/plane = FLOAT_PLANE
var/render_source
var/render_target
var/suffix as opendream_unimplemented
var/text = "i" as opendream_unimplemented
var/matrix/transform
Expand All @@ -55,7 +55,7 @@

// The ref does not mention the pixel_x and pixel_y args...
New(icon, loc, icon_state, layer, dir, pixel_x, pixel_y)
src.icon = icon
if (icon != null) src.icon = icon
if (!istext(loc))
if (loc != null) src.loc = loc
if (icon_state != null) src.icon_state = icon_state
Expand Down
2 changes: 1 addition & 1 deletion DMCompiler/DMStandard/Types/World.dm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
var/maxy = 0
var/maxz = 0
var/icon_size = 32
var/view = 7 // The default is actually 5, but we hardcode a 15x15 view for now
var/view = 5
var/movement_mode = LEGACY_MOVEMENT_MODE as opendream_unimplemented

var/byond_version = DM_VERSION
Expand Down
1 change: 0 additions & 1 deletion OpenDreamClient/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public override void PostInit() {
lightManager.DrawShadows = true;

_overlayManager.AddOverlay(new DreamViewOverlay());
_overlayManager.AddOverlay(new DreamScreenOverlay());

_dreamInterface.Initialize();
IoCManager.Resolve<IDreamSoundEngine>().Initialize();
Expand Down
93 changes: 33 additions & 60 deletions OpenDreamClient/Input/MouseInputSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ sealed class MouseInputSystem : SharedMouseInputSystem {
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IOverlayManager _overlayManager = default!;
[Dependency] private readonly EntityLookupSystem _lookupSystem = default!;

private DreamViewOverlay _dreamViewOverlay;
private ContextMenuPopup _contextMenu;

public override void Initialize() {
Expand All @@ -40,89 +42,60 @@ public bool HandleViewportClick(ScalingViewport viewport, GUIBoundKeyEventArgs a
bool ctrl = _inputManager.IsKeyDown(Keyboard.Key.Control);
bool alt = _inputManager.IsKeyDown(Keyboard.Key.Alt);

Vector2 screenLocPos = (args.RelativePixelPosition - viewportBox.TopLeft) / viewportBox.Size;
screenLocPos *= viewport.ViewportSize;
screenLocPos.Y = viewport.ViewportSize.Y - screenLocPos.Y; // Flip the Y
ScreenLocation screenLoc = new ScreenLocation((int) screenLocPos.X, (int) screenLocPos.Y, 32); // TODO: icon_size other than 32

MapCoordinates mapCoords = viewport.ScreenToMap(args.PointerLocation.Position);
EntityUid entity = GetEntityUnderMouse(viewport, args.PointerLocation.Position, mapCoords);
EntityUid entity = GetEntityUnderMouse(viewport, screenLocPos, mapCoords);

if (args.Function == EngineKeyFunctions.UIRightClick) {
if (entity == EntityUid.Invalid)
return false;
if (entity == EntityUid.Invalid && args.Function != EngineKeyFunctions.UIRightClick) { // Turf was clicked and not a right-click
if (_mapManager.TryFindGridAt(mapCoords, out var grid)){
Vector2i position = grid.CoordinatesToTile(mapCoords);
MapCoordinates worldPosition = grid.GridTileToWorld(position);
RaiseNetworkEvent(new TurfClickedEvent(position, (int)worldPosition.MapId, screenLoc, shift, ctrl, alt));
}
return true;
}

_contextMenu.RepopulateEntities(_lookupSystem.GetEntitiesInRange(mapCoords, 0.01f));
if (args.Function == EngineKeyFunctions.UIRightClick) { //either turf or atom was clicked, and it was a right-click
var entities = _lookupSystem.GetEntitiesInRange(mapCoords, 0.01f);
//TODO filter entities by the valid verbs that exist on them
//they should only show up if there is a verb attached to usr which matches the filter in world syntax
//ie, obj|turf in world
//note that popup_menu = 0 overrides this behaviour, as does verb invisibility (urgh), and also hidden
//because BYOND sure loves redundancy
if(entities.Count == 0)
return true; //don't open a 1x1 empty context menu
_contextMenu.RepopulateEntities(entities);
_contextMenu.Measure(_userInterfaceManager.ModalRoot.Size);
Vector2 contextMenuLocation = args.PointerLocation.Position / _userInterfaceManager.ModalRoot.UIScale; // Take scaling into account
_contextMenu.Open(UIBox2.FromDimensions(contextMenuLocation, _contextMenu.DesiredSize));

return true;
}

Vector2 screenLocPos = (args.RelativePixelPosition - viewportBox.TopLeft) / viewportBox.Size;
screenLocPos *= viewport.ViewportSize;
screenLocPos.Y = viewport.ViewportSize.Y - screenLocPos.Y; // Flip the Y
ScreenLocation screenLoc = new ScreenLocation((int) screenLocPos.X, (int) screenLocPos.Y, 32); // TODO: icon_size other than 32

if (entity == EntityUid.Invalid) { // Turf was clicked
if (!_mapManager.TryFindGridAt(mapCoords, out var grid))
return false;

Vector2i position = grid.CoordinatesToTile(mapCoords);
MapCoordinates worldPosition = grid.GridTileToWorld(position);
RaiseNetworkEvent(new TurfClickedEvent(position, (int)worldPosition.MapId, screenLoc, shift, ctrl, alt));
return true;
}

RaiseNetworkEvent(new EntityClickedEvent(entity, screenLoc, shift, ctrl, alt));
if (entity != EntityUid.Invalid) //atom was clicked, and it wasn't a right click
RaiseNetworkEvent(new EntityClickedEvent(entity, screenLoc, shift, ctrl, alt));
return true;
}

private EntityUid GetEntityUnderMouse(ScalingViewport viewport, Vector2 mousePos, MapCoordinates coords) {
EntityUid? entity = GetEntityOnScreen(mousePos, viewport);
entity ??= GetEntityOnMap(coords);

return entity ?? EntityUid.Invalid;
}

private EntityUid? GetEntityOnScreen(Vector2 mousePos, ScalingViewport viewport) {
ClientScreenOverlaySystem screenOverlay = EntitySystem.Get<ClientScreenOverlaySystem>();
EntityUid? eye = _playerManager.LocalPlayer.Session.AttachedEntity;
if (eye == null || !_entityManager.TryGetComponent<TransformComponent>(eye.Value, out var eyeTransform)) {
_dreamViewOverlay ??= _overlayManager.GetOverlay<DreamViewOverlay>();
if(_dreamViewOverlay.MouseMap == null)
return null;
}

Vector2 viewOffset = eyeTransform.WorldPosition - 7.5f; //TODO: Don't hardcode a 15x15 view
MapCoordinates coords = viewport.ScreenToMap(mousePos);

var foundSprites = new List<DMISpriteComponent>();
foreach (DMISpriteComponent sprite in screenOverlay.EnumerateScreenObjects()) {
Vector2 position = sprite.ScreenLocation.GetViewPosition(viewOffset, EyeManager.PixelsPerMeter);

if (sprite.CheckClickScreen(position, coords.Position)) {
foundSprites.Add(sprite);
}
}

if (foundSprites.Count == 0)
Color lookupColor = _dreamViewOverlay.MouseMap.GetPixel((int)mousePos.X, (int)mousePos.Y);
if(!_dreamViewOverlay.MouseMapLookup.TryGetValue(lookupColor, out EntityUid result))
return null;

foundSprites.Sort(new RenderOrderComparer());
return foundSprites[^1].Owner;
return result;
}

private EntityUid? GetEntityOnMap(MapCoordinates coords) {
IEnumerable<EntityUid> entities = _lookupSystem.GetEntitiesIntersecting(coords.MapId, Box2.CenteredAround(coords.Position, (0.1f, 0.1f)));

var foundSprites = new List<DMISpriteComponent>();
foreach (EntityUid entity in entities) {
if (_entityManager.TryGetComponent<DMISpriteComponent>(entity, out var sprite)
&& sprite.CheckClickWorld(coords.Position)) {
foundSprites.Add(sprite);
}
}

if (foundSprites.Count == 0)
return null;

foundSprites.Sort(new RenderOrderComparer());
return foundSprites[^1].Owner;
}
}
}
29 changes: 19 additions & 10 deletions OpenDreamClient/Rendering/ClientAppearanceSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using SharedAppearanceSystem = OpenDreamShared.Rendering.SharedAppearanceSystem;
using Robust.Client.Graphics;
using Robust.Shared.Prototypes;
using OpenDreamClient.Resources;
using OpenDreamClient.Resources.ResourceTypes;

namespace OpenDreamClient.Rendering {
sealed class ClientAppearanceSystem : SharedAppearanceSystem {
Expand All @@ -19,6 +21,7 @@ sealed class ClientAppearanceSystem : SharedAppearanceSystem {

[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly OccluderSystem _occluderSystem = default!;
[Dependency] private readonly IDreamResourceManager _dreamResourceManager = default!;

public override void Initialize() {
SubscribeNetworkEvent<AllAppearancesEvent>(OnAllAppearances);
Expand Down Expand Up @@ -96,14 +99,27 @@ public void CleanUpUnusedFilters() {
}
}

public ShaderInstance GetFilterShader(DreamFilter filter) {
public ShaderInstance GetFilterShader(DreamFilter filter, Dictionary<string, IRenderTexture> renderSourceLookup) {
if (!_filterShaders.TryGetValue(filter, out var instance)) {
var protoManager = IoCManager.Resolve<IPrototypeManager>();

instance = protoManager.Index<ShaderPrototype>(filter.FilterType).InstanceUnique();

switch (filter) {
case DreamFilterAlpha alpha:
if(!String.IsNullOrEmpty(alpha.RenderSource) && renderSourceLookup.TryGetValue(alpha.RenderSource, out var renderSourceTexture))
instance.SetParameter("mask_texture", renderSourceTexture.Texture);
else if(alpha.Icon != 0){
_dreamResourceManager.LoadResourceAsync<DMIResource>(alpha.Icon, (DMIResource rsc) => {
instance.SetParameter("mask_texture", rsc.Texture);
});
}
else{
instance.SetParameter("mask_texture", Texture.Transparent);
}
instance.SetParameter("x",alpha.X);
instance.SetParameter("y",alpha.Y);
instance.SetParameter("flags",alpha.Flags);
break;
case DreamFilterAngularBlur angularBlur:
break;
Expand All @@ -114,15 +130,8 @@ public ShaderInstance GetFilterShader(DreamFilter filter) {
break;
case DreamFilterColor color: {
//Since SWSL doesn't support 4x5 matrices, we need to get a bit silly.
instance.SetParameter("colorMatrix", new Matrix4(
color.Color.c11, color.Color.c12, color.Color.c13, color.Color.c14,
color.Color.c21, color.Color.c22, color.Color.c23, color.Color.c24,
color.Color.c31, color.Color.c32, color.Color.c33, color.Color.c34,
color.Color.c41, color.Color.c42, color.Color.c43, color.Color.c44
));
instance.SetParameter("offsetVector", new Vector4(
color.Color.c51, color.Color.c52, color.Color.c53, color.Color.c54
));
instance.SetParameter("colorMatrix", color.Color.GetMatrix4());
instance.SetParameter("offsetVector", color.Color.GetOffsetVector());
//TODO: Support the alternative colour mappings.
break;
}
Expand Down
5 changes: 2 additions & 3 deletions OpenDreamClient/Rendering/DMISpriteComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ public Box2 GetAABB(Transform transform) {
return Icon.GetWorldAABB(transform.Position);
}

public bool IsVisible(bool checkWorld = true, [CanBeNull] IMapManager mapManager = null) {
if (Icon?.DMI == null) return false;
if (Icon.Appearance.Invisibility > 0) return false; //TODO: mob.see_invisibility
public bool IsVisible(bool checkWorld = true, [CanBeNull] IMapManager mapManager = null, int seeInvis = 0) {
if (Icon.Appearance?.Invisibility > seeInvis) return false;

if (checkWorld) {
//Only render movables not inside another movable's contents (parented to the grid)
Expand Down
2 changes: 1 addition & 1 deletion OpenDreamClient/Rendering/DreamIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void Draw(DrawingHandleWorld handle, Vector2 position) {

AtlasTexture frame = CurrentFrame;
if (frame != null) {
handle.DrawTexture(frame, position, Appearance.Color); // TODO: Does not consider SillyColorFilter
handle.DrawTexture(frame, position, Appearance.Color); // TODO: Does not consider ColorMatrix
}

foreach (DreamIcon overlay in Overlays) {
Expand Down
Loading