• R/O
  • SSH

dwaddle: Commit

Main Dwaddle repository


Commit MetaInfo

Revisione7f4a66264fc9730f5902a131fd93c4efe8bf0da (tree)
Time2021-05-22 07:13:35
AuthorRemilia Scarlet <remilia@post...>
CommiterRemilia Scarlet

Log Message

Remove references to the old ZUdmf* classes, and add #groupLines

Change Summary

Incremental Difference

diff -r 087a45079309 -r e7f4a66264fc src/level-data/level.cr
--- a/src/level-data/level.cr Wed May 12 00:58:07 2021 -0600
+++ b/src/level-data/level.cr Fri May 21 16:13:35 2021 -0600
@@ -44,12 +44,6 @@
4444 def initialize(vert : MapFormats::Udmf::UdmfVertex)
4545 @x = vert.x
4646 @y = vert.y
47- end
48-
49- # Creates a new `Vertex` by converting a `MapFormats::Udmf::ZUdmfVertex`.
50- def initialize(vert : MapFormats::Udmf::ZUdmfVertex)
51- @x = vert.x
52- @y = vert.y
5347 @floorHeight = vert.floorHeight
5448 @ceilingHeight = vert.ceilingHeight
5549 end
@@ -90,7 +84,7 @@
9084 property frontSidedef : Sidedef = Sidedef.new
9185
9286 # The sidedef for the back side of the linedef.
93- property backSidedef : Sidedef = Sidedef.new
87+ property backSidedef : Sidedef? = nil
9488
9589 # A textual comment.
9690 property comment = ""
@@ -128,82 +122,6 @@
128122 def initialize(line : MapFormats::Udmf::UdmfLinedef, vertices : Array(Vertex)|Nil, sidedefs : Array(Sidedef)|Nil)
129123 @tag = line.id == -1 ? 0 : line.id
130124 @special = line.special
131- [line.arg0, line.arg1, line.arg2, line.arg3, line.arg4].each { |x| @args << x }
132- @comment = line.comment
133-
134- if vertices
135- @startVertex = if line.startVertex < vertices.size
136- vertices[line.startVertex]
137- else
138- raise DwaddleError.new("Cannot assign a vertex to a Linedef: old index out of range")
139- end
140-
141- @endVertex = if line.endVertex < vertices.size
142- vertices[line.endVertex]
143- else
144- raise DwaddleError.new("Cannot assign a vertex to a Linedef: old index out of range")
145- end
146- end
147-
148- if sidedefs
149- @frontSidedef = if line.frontSidedef < sidedefs.size
150- sidedefs[line.frontSidedef]
151- else
152- raise DwaddleError.new("Cannot assign a sidedef to a Linedef: old index out of range")
153- end
154-
155- @backSidedef = if line.backSidedef < sidedefs.size
156- sidedefs[line.backSidedef]
157- else
158- raise DwaddleError.new("Cannot assign a sidedef to a Linedef: old index out of range")
159- end
160- end
161-
162- @flags = @flags | Flags::Impassable if line.impassable
163- @flags = @flags | Flags::BlocksMonsters if line.blocksMonsters
164- @flags = @flags | Flags::BlocksFloatingMonsters if line.blocksFloatingMonsters
165- @flags = @flags | Flags::TwoSided if line.twoSided
166- @flags = @flags | Flags::UpperUnpegged if line.upperUnpegged
167- @flags = @flags | Flags::LowerUnpegged if line.lowerUnpegged
168- @flags = @flags | Flags::ShownAsOneSided if line.shownAsOneSided
169- @flags = @flags | Flags::BlocksSound if line.blocksSound
170- @flags = @flags | Flags::NotShownOnMap if line.notShownOnMap
171- @flags = @flags | Flags::AlwaysOnMap if line.alwaysOnMap
172- @flags = @flags | Flags::PassUseThrough if line.passUseThrough
173- @flags = @flags | Flags::StrifeTranslucent if line.translucent
174- @flags = @flags | Flags::StrifeRailing if line.strifeRailing
175-
176- @activationFlags = @activationFlags | ActivationFlags::PlayerCross if line.onPlayerCross
177- @activationFlags = @activationFlags | ActivationFlags::PlayerUse if line.onPlayerUse
178- @activationFlags = @activationFlags | ActivationFlags::PlayerPush if line.onPlayerPush
179- @activationFlags = @activationFlags | ActivationFlags::MonsterCross if line.onMonsterCross
180- @activationFlags = @activationFlags | ActivationFlags::MonsterUse if line.onMonsterUse
181- @activationFlags = @activationFlags | ActivationFlags::MonsterPush if line.onMonsterPush
182- @activationFlags = @activationFlags | ActivationFlags::Impact if line.onImpact
183- @activationFlags = @activationFlags | ActivationFlags::ProjectileCross if line.onProjectileCross
184- @activationFlags = @activationFlags | ActivationFlags::Repeatable if line.repeatable
185- end
186-
187- # Creates a new `Linedef` by converting a `MapFormats::Udmf::ZUdmfLinedef`.
188- #
189- # If `vertices` is non-nil, then the
190- # `MapFormats::Udmf::ZUdmfLinedef#startVertex` and
191- # `MapFormats::Udmf::ZUdmfLinedef#endVertex` of `line` will be looked up in
192- # `vertices`. If this fails, a `DwaddleError` is raised.
193- #
194- # If `vertices` is nil, the new `Linedef` will have two completely new
195- # vertices.
196- #
197- # If `sidedefs` is non-nil, then the
198- # `MapFormats::Udmf::ZUdmfLinedef#frontSidedef` and
199- # `MapFormats::Udmf::ZUdmfLinedef#backSidedef` of `line` will be looked up in
200- # `sidedefs`. If this fails, a `DwaddleError` is raised.
201- #
202- # If `sidedefs` is nil, the new `Linedef` will have two completely new
203- # sidedefs.
204- def initialize(line : MapFormats::Udmf::ZUdmfLinedef, vertices : Array(Vertex)|Nil, sidedefs : Array(Sidedef)|Nil)
205- @tag = line.id == -1 ? 0 : line.id
206- @special = line.special
207125 @lockNumber = line.lockNumber
208126 @comment = line.comment
209127
@@ -234,10 +152,14 @@
234152 raise DwaddleError.new("Cannot assign a sidedef to a Linedef: old index out of range")
235153 end
236154
237- @backSidedef = if line.backSidedef < sidedefs.size
238- sidedefs[line.backSidedef]
155+ @backSidedef = if line.backSidedef != 0
156+ if line.backSidedef < sidedefs.size
157+ sidedefs[line.backSidedef]
158+ else
159+ raise DwaddleError.new("Cannot assign a sidedef to a Linedef: old index out of range")
160+ end
239161 else
240- raise DwaddleError.new("Cannot assign a sidedef to a Linedef: old index out of range")
162+ nil
241163 end
242164 end
243165
@@ -341,10 +263,14 @@
341263 raise DwaddleError.new("Cannot assign a sidedef to a Linedef: old index out of range")
342264 end
343265
344- @backSidedef = if line.backSidedef < sidedefs.size
345- sidedefs[line.backSidedef]
266+ @backSidedef = if line.backSidedef >= 0
267+ if line.backSidedef < sidedefs.size
268+ sidedefs[line.backSidedef]
269+ else
270+ raise DwaddleError.new("Cannot assign a sidedef to a Linedef: old index out of range")
271+ end
346272 else
347- raise DwaddleError.new("Cannot assign a sidedef to a Linedef: old index out of range")
273+ nil
348274 end
349275 end
350276
@@ -434,34 +360,6 @@
434360 #
435361 # If `sectors` is nil, the new `Sidedef` will have a completely new sector.
436362 def initialize(side : MapFormats::Udmf::UdmfSidedef, sectors : Array(Sector)|Nil)
437- @upperOffsetX = side.xOffset.to_f64!
438- @middleOffsetX = side.xOffset.to_f64!
439- @lowerOffsetX = side.xOffset.to_f64!
440- @upperOffsetY = side.yOffset.to_f64!
441- @middleOffsetY = side.yOffset.to_f64!
442- @lowerOffsetY = side.yOffset.to_f64!
443- @upperTexture = side.upperTexture
444- @middleTexture = side.middleTexture
445- @lowerTexture = side.lowerTexture
446- @comment = side.comment
447-
448- if sectors
449- @sector = if side.sector < sectors.size
450- sectors[side.sector]
451- else
452- raise DwaddleError.new("Cannot assign a sector to a Sidedef: old index out of range")
453- end
454- end
455- end
456-
457- # Creates a new `Sidedef` by converting a `MapFormats::Udmf::ZUdmfSidedef`.
458- #
459- # If `sectors` is non-nil, then the `MapFormats::Udmf::ZUdmfSidedef#sector`
460- # of `side` will be looked up in `sectors`. If this fails, a `DwaddleError`
461- # is raised.
462- #
463- # If `sectors` is nil, the new `Sidedef` will have a completely new sector.
464- def initialize(side : MapFormats::Udmf::ZUdmfSidedef, sectors : Array(Sector)|Nil)
465363 @upperOffsetX = side.upperOffsetX
466364 @middleOffsetX = side.middleOffsetX
467365 @lowerOffsetX = side.lowerOffsetX
@@ -661,6 +559,8 @@
661559 # The rendering style for the ceiling portal.
662560 getter ceilingPortalRenderStyle : RenderStyle = RenderStyle::Translucent
663561
562+ property lines : Array(Linedef) = [] of Linedef
563+
664564 # Creates a new `Sector`.
665565 def initialize
666566 end
@@ -670,24 +570,6 @@
670570 @tag = sect.id
671571 @floorHeight = sect.floorHeight
672572 @ceilingHeight = sect.ceilingHeight
673- @floorTexture = sect.floorTexture
674- @ceilingTexture = sect.ceilingTexture
675- @light = if sect.light < 0
676- 0u8
677- elsif sect.light > 255
678- 255u8
679- else
680- sect.light.to_u8
681- end
682- @special = sect.special
683- @comment = sect.comment
684- end
685-
686- # Creates a new `Sidedef` by converting a `MapFormats::Udmf::ZUdmfSector`.
687- def initialize(sect : MapFormats::Udmf::ZUdmfSector)
688- @tag = sect.id
689- @floorHeight = sect.floorHeight
690- @ceilingHeight = sect.ceilingHeight
691573 @floorPanningX = sect.floorPanningX
692574 @floorPanningY = sect.floorPanningY
693575 @ceilingPanningX = sect.ceilingPanningX
@@ -884,39 +766,6 @@
884766 @angle = thing.angle
885767 @type = thing.type
886768 @special = thing.special
887- [thing.arg0, thing.arg1, thing.arg2, thing.arg3, thing.arg4].each { |x| @args << x }
888-
889- @flags = @flags | Flags::Ambush if thing.ambush
890- @flags = @flags | Flags::InSinglePlayer if thing.inSinglePlayer
891- @flags = @flags | Flags::InDM if thing.inDM
892- @flags = @flags | Flags::InCoop if thing.inCoop
893- @flags = @flags | Flags::Friendly if thing.friendly
894- @flags = @flags | Flags::Dormant if thing.dormant
895- @flags = @flags | Flags::StrifeNPC if thing.npc
896- @flags = @flags | Flags::StrifeAlly if thing.ally
897- @flags = @flags | Flags::StrifeTranslucent if thing.translucent
898- @flags = @flags | Flags::StrifeInvisible if thing.invisible
899-
900- @skills = @skills | SkillLevels::Skill1 if thing.inVeryEasy
901- @skills = @skills | SkillLevels::Skill2 if thing.inEasy
902- @skills = @skills | SkillLevels::Skill3 if thing.inNormal
903- @skills = @skills | SkillLevels::Skill4 if thing.inHard
904- @skills = @skills | SkillLevels::Skill5 if thing.inVeryHard
905-
906- @classes = @classes | Classes::Class1 if thing.class1
907- @classes = @classes | Classes::Class2 if thing.class2
908- @classes = @classes | Classes::Class3 if thing.class3
909- end
910-
911- # Creates a new `Sidedef` by converting a `MapFormats::Udmf::ZUdmfThing`.
912- def initialize(thing : MapFormats::Udmf::ZUdmfThing)
913- @tag = thing.id
914- @x = thing.x
915- @y = thing.y
916- @z = thing.z
917- @angle = thing.angle
918- @type = thing.type
919- @special = thing.special
920769 @conversation = thing.conversation
921770 @gravity = thing.gravity
922771 @health = thing.health
@@ -1066,6 +915,35 @@
1066915 def initialize
1067916 end
1068917
918+ # Groups all of linedefs in this `Level` by sector, then stores this list of
919+ # linedefs in each sector's `Sector#lines`.
920+ #
921+ # If linedefs or sectors are added/removed, this should be re-run to regroup
922+ # them.
923+ def groupLines : Nil
924+ mappings = {} of Sector => Array(Linedef)
925+ @linedefs.each do |line|
926+ frontSect = line.frontSidedef.sector
927+ backSect = line.backSidedef.try &.sector
928+
929+ if mappings.has_key?(frontSect)
930+ mappings[frontSect] << line
931+ else
932+ mappings[frontSect] = [line]
933+ end
934+
935+ if backSect
936+ if mappings.has_key?(backSect)
937+ mappings[backSect] << line
938+ else
939+ mappings[backSect] = [line]
940+ end
941+ end
942+ end
943+
944+ mappings.each { |sect, lines| sect.lines = lines }
945+ end
946+
1069947 # Converts a `Dwaddle::MapFormats::Udmf::UdmfMap` to a `Level`.
1070948 def initialize(map : MapFormats::Udmf::UdmfMap)
1071949 map.vertices.each { |obj| @vertices << Vertex.new(obj) }
@@ -1074,6 +952,7 @@
1074952 map.linedefs.each { |obj| @linedefs << Linedef.new(obj, @vertices, @sidedefs) }
1075953 map.things.each { |obj| @things << Thing.new(obj) }
1076954 @origFormat = Format::UDMF
955+ groupLines
1077956 end
1078957
1079958 # Converts a `Dwaddle::MapFormats::Vanilla::Map` to a `Level`.
@@ -1084,6 +963,7 @@
1084963 map.linedefs.each { |obj| @linedefs << Linedef.new(obj, @vertices, @sidedefs) }
1085964 map.things.each { |obj| @things << Thing.new(obj) }
1086965 @origFormat = Format::Vanilla
966+ groupLines
1087967 end
1088968
1089969 # Loads a level from the given filename. Returns these values in this order:
Show on old repository browser