├── .gitattributes ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE.txt ├── PHILOSOPHY.md ├── README.md ├── VERSIONING.md ├── build-dependencies.xml ├── build-import.xml ├── build.xml ├── docs ├── AUTHORS.txt ├── CHANGELOG.md └── LICENSE-BlackRookBase.txt └── src ├── main └── java │ └── net │ └── mtrop │ └── doom │ ├── DoomPK3.java │ ├── Wad.java │ ├── WadBuffer.java │ ├── WadEntry.java │ ├── WadFile.java │ ├── WadMap.java │ ├── bsp │ ├── BSPTree.java │ ├── data │ │ ├── BSPNode.java │ │ ├── BSPSegment.java │ │ ├── BSPSubsector.java │ │ └── package-info.java │ └── package-info.java │ ├── demo │ ├── Demo.java │ └── package-info.java │ ├── exception │ ├── MapException.java │ ├── TextureException.java │ ├── WadException.java │ └── package-info.java │ ├── graphics │ ├── Colormap.java │ ├── EndDoom.java │ ├── Flat.java │ ├── IndexedGraphic.java │ ├── PNGPicture.java │ ├── Palette.java │ ├── Picture.java │ └── package-info.java │ ├── map │ ├── CommonMap.java │ ├── DoomMap.java │ ├── HexenMap.java │ ├── MapElementView.java │ ├── MapFormat.java │ ├── MapObjectConstants.java │ ├── MapView.java │ ├── UDMFMap.java │ ├── data │ │ ├── Blockmap.java │ │ ├── CommonLinedef.java │ │ ├── CommonThing.java │ │ ├── DoomLinedef.java │ │ ├── DoomSector.java │ │ ├── DoomSidedef.java │ │ ├── DoomThing.java │ │ ├── DoomVertex.java │ │ ├── HexenLinedef.java │ │ ├── HexenThing.java │ │ ├── Reject.java │ │ ├── flags │ │ │ ├── BoomLinedefFlags.java │ │ │ ├── BoomThingFlags.java │ │ │ ├── DoomLinedefFlags.java │ │ │ ├── DoomThingFlags.java │ │ │ ├── HexenLinedefFlags.java │ │ │ ├── HexenThingFlags.java │ │ │ ├── LinedefFlags.java │ │ │ ├── MBFThingFlags.java │ │ │ ├── StrifeLinedefFlags.java │ │ │ ├── StrifeThingFlags.java │ │ │ ├── ThingFlags.java │ │ │ ├── ZDoomLinedefFlags.java │ │ │ ├── ZDoomThingFlags.java │ │ │ └── package-info.java │ │ └── package-info.java │ ├── package-info.java │ └── udmf │ │ ├── UDMFObject.java │ │ ├── UDMFParseException.java │ │ ├── UDMFParser.java │ │ ├── UDMFParserListener.java │ │ ├── UDMFReader.java │ │ ├── UDMFScanner.java │ │ ├── UDMFTable.java │ │ ├── UDMFWriter.java │ │ ├── attributes │ │ ├── UDMFCommonAttributes.java │ │ ├── UDMFCommonLinedefAttributes.java │ │ ├── UDMFCommonSectorAttributes.java │ │ ├── UDMFCommonSidedefAttributes.java │ │ ├── UDMFCommonThingAttributes.java │ │ ├── UDMFCommonVertexAttributes.java │ │ ├── UDMFDoomLinedefAttributes.java │ │ ├── UDMFDoomSectorAttributes.java │ │ ├── UDMFDoomSidedefAttributes.java │ │ ├── UDMFDoomThingAttributes.java │ │ ├── UDMFDoomVertexAttributes.java │ │ ├── UDMFGlobalAttributes.java │ │ ├── UDMFHexenLinedefAttributes.java │ │ ├── UDMFHexenThingAttributes.java │ │ ├── UDMFMBFThingAttributes.java │ │ ├── UDMFObjectTypes.java │ │ ├── UDMFStrifeLinedefAttributes.java │ │ ├── UDMFStrifeThingAttributes.java │ │ ├── UDMFZDoomLinedefAttributes.java │ │ ├── UDMFZDoomSectorAttributes.java │ │ ├── UDMFZDoomSidedefAttributes.java │ │ ├── UDMFZDoomThingAttributes.java │ │ ├── UDMFZDoomVertexAttributes.java │ │ └── package-info.java │ │ ├── listener │ │ ├── UDMFFullTableListener.java │ │ ├── UDMFInlineTypeListener.java │ │ ├── UDMFTypeListener.java │ │ └── package-info.java │ │ └── package-info.java │ ├── object │ ├── BinaryObject.java │ ├── GraphicObject.java │ ├── TextObject.java │ └── package-info.java │ ├── package-info.java │ ├── sound │ ├── DMXSound.java │ ├── MUS.java │ └── package-info.java │ ├── struct │ ├── DataList.java │ ├── Lexer.java │ ├── Sizable.java │ ├── io │ │ ├── CRC32.java │ │ ├── IOUtils.java │ │ ├── JSPISoundHandle.java │ │ ├── PNGContainerReader.java │ │ ├── PNGContainerWriter.java │ │ ├── SerialReader.java │ │ ├── SerialWriter.java │ │ ├── SerializerUtils.java │ │ └── package-info.java │ ├── map │ │ ├── HashDequeMap.java │ │ ├── SparseGridIndex.java │ │ ├── SparseQueueGridIndex.java │ │ └── package-info.java │ ├── package-info.java │ ├── trie │ │ ├── AbstractTrie.java │ │ ├── AbstractTrieMap.java │ │ ├── CaseInsensitiveTrieMap.java │ │ ├── StringTrieMap.java │ │ └── package-info.java │ └── vector │ │ ├── AbstractArrayStorage.java │ │ ├── AbstractMappedVector.java │ │ ├── AbstractVector.java │ │ └── package-info.java │ ├── texture │ ├── Animated.java │ ├── CommonPatch.java │ ├── CommonTexture.java │ ├── CommonTextureList.java │ ├── DoomTextureList.java │ ├── PatchNames.java │ ├── StrifeTextureList.java │ ├── Switches.java │ ├── TextureSet.java │ └── package-info.java │ └── util │ ├── GraphicUtils.java │ ├── MapUtils.java │ ├── MathUtils.java │ ├── NameUtils.java │ ├── RangeUtils.java │ ├── SoundUtils.java │ ├── TextUtils.java │ ├── TextureUtils.java │ ├── WadUtils.java │ └── package-info.java └── test ├── java └── net │ └── mtrop │ └── doom │ ├── LoggingFactory.java │ ├── PK3Test.java │ ├── WadTest.java │ ├── demo │ └── DemoTest.java │ ├── graphics │ ├── AnimatedTest.java │ ├── ColormapTest.java │ ├── GraphicDirTest.java │ ├── GraphicTest.java │ ├── PaletteTest.java │ └── TallGraphicTest.java │ ├── map │ ├── MapTest.java │ ├── data │ │ ├── BlockmapTest.java │ │ ├── DoomLinedefTest.java │ │ ├── DoomSectorTest.java │ │ ├── DoomSidedefTest.java │ │ ├── DoomThingTest.java │ │ ├── DoomVertexTest.java │ │ ├── HexenLinedefTest.java │ │ ├── HexenThingTest.java │ │ └── RejectTest.java │ └── udmf │ │ ├── UDMFReaderTest.java │ │ └── UDMFScannerTest.java │ ├── sound │ ├── MUSTest.java │ └── SoundTest.java │ ├── test │ ├── TestSuite.java │ └── TestUtils.java │ ├── texture │ └── TextureTest.java │ └── util │ ├── MapUtilsTest.java │ ├── NameUtilsTest.java │ └── SoundUtilTest.java └── resources ├── doommap.wad ├── hexenmap.wad ├── udmfmap.wad └── viscerus.pk3 /.gitattributes: -------------------------------------------------------------------------------- 1 | *.wad binary 2 | *.pk3 binary 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bin 2 | /build 3 | /deps 4 | /target 5 | /.idea 6 | build.properties 7 | .settings 8 | .classpath 9 | .project 10 | *.ipr 11 | *.iml 12 | *.iws 13 | Thumbs.db 14 | desktop.ini 15 | .README.md.html 16 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | To contribute to this project, you must follow the Code of Conduct and Coding Standards, as well as observe the guidelines for Pull Requests. 4 | 5 | ### Code of Conduct 6 | 7 | 1. Keep your criticism constructive. Discussion over algorithms, implementations, and documentation/comment wording is constructive. Personal attacks are **not constructive.** 8 | 9 | 2. You may not harass other contributors in any way, nor other contributors of other projects, nor do anything that would promote a culture of hostility to prevent others from contributing. Contributing to this project makes you a tangential representative of it. Act accordingly. 10 | 11 | 12 | ### Coding Standards 13 | 14 | 1. The bracing style is [Allman](https://en.wikipedia.org/wiki/Indentation_style#Allman_style), for the most part. Some try/catches use [K&R](https://en.wikipedia.org/wiki/Indentation_style#K&R_style). The primary maintainer of this codebase prefers consistency within code over arguing the merits of each style. Discussions over a change of style will not be entertained. 15 | 16 | 2. Hard tabs in code. Again, the primary maintainer of this codebase prefers consistency within code over arguing the merits of each style. Discussions over a change of style will not be entertained. 17 | 18 | 3. You are contributing to a general library/API. As such, all **public** and **protected** fields and methods **must** have Javadoc comments. Private or default method/field Javadocs are optional (but may be encouraged if the method is very complex), but sometimes just a comment is fine, for elucidation. 19 | 20 | 4. Unless the variable is temporary or "throwaway," use descriptive names. We have IDEs, now. Autocomplete is a thing. 21 | 22 | 5. Methods must have purposeful names, but not excessively large, descriptive ones. That's what documentation is for. 23 | 24 | 6. You may not add additional dependencies to this project. Stay in the [java.desktop](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/module-summary.html) module (and its child dependencies). However, *removal* of dependencies, if any, are a welcome proposition. 25 | 26 | ### Pull Requests 27 | 28 | 1. All Pull Requests are subject to review before acceptance. If your feature or contribution is not accepted, understand that it may be due to it not aligning with the project's philosophy or purpose, coding standards aside. Don't worry - there's no shame in use using this library as a dependency for your toolset! 29 | 30 | 2. All Pull Requests must be made against `master` or a "master-derivative" branch. 31 | 32 | 3. You must specify what you are adding or fixing. Without context for the PR, it cannot be reviewed adequately, nor ultimately accepted. 33 | 34 | 4. Understand that not all contributions are worthy by default - any new features must fill a utilitarian deficit or fix a clear bug ("bug" is this case is defined as an unintended behavior). 35 | 36 | 5. Refactorings of existing classes/packages are at the discretion of the primary maintainer. Please ask if you are unsure whether or not a feature requires a new package, and accept direction if another or different package (or project) is necessary to accommodate your feature. 37 | 38 | 6. "Bikeshed" features/corrections will not be accepted without adequate justification. 39 | 40 | 7. The primary maintainer of this codebase is **not** a believer in "Good or readable code needs no comments." If you are asked to clarify sections of code with plain English, do so or you will risk the rejection of your request. 41 | 42 | 8. New public/protected methods/classes should contain a `@since [NOW]` descriptor in the Javadocs, so that when a new release is cut, the "NOW" can be replaced with the next release version. 43 | 44 | 9. Deprecated public/protected/default methods/classes should contain a `@deprecated Since [NOW]` entry in the javadoc comment, so that when a new release is cut, the new deprecations can be adequately documented, and the "NOW" can be replaced with the next release version. 45 | 46 | 10. Please amend the CHANGELOG - add a "Next Version" section if it doesn't exist. 47 | 48 | 11. Your code must be compatible with the license of this project, and be written with the understanding that it will be published under this project's license. 49 | 50 | -------------------------------------------------------------------------------- /PHILOSOPHY.md: -------------------------------------------------------------------------------- 1 | # Library Philosophy 2 | 3 | This file is for answering questions around some of this library's design. This can also 4 | serve as a reference point for why certain parts of the library are packaged a certain 5 | way, or explaining choices made during creation, so that it can guide future decisions. 6 | 7 | And if, down the line, a better approach is proposed, at least there's a paper trail for 8 | the decisions already made so that more *educated* decisions can be made. 9 | 10 | 11 | ### What is the primary goal of this project? 12 | 13 | To read Doom Engine data structures and allow the users of the library to use that data 14 | to create or manipulate other Doom-related data. Features that ease "map editing" or 15 | advanced graphics or sound manipulation or other decision-making logic layers are not considered 16 | to be within the scope of this project. 17 | 18 | 19 | ### Lots of things are somewhat "low-level." Why? 20 | 21 | Personal API philosophy. Assuming the intent of the user of an API will limit its design and 22 | its usefulness in application. Better to expose low level functionality and wrap in "smarter" 23 | structures, rather than ease-of-use first, then down to bits and bytes. Then, you can still have 24 | flexibility as well as convenience. 25 | 26 | 27 | ### Why are WadEntries immutable? 28 | 29 | WadEntries are immutable because they can be used by other Wads - changing an entry's values 30 | like offset, length, or name could pollute use of an entry whose reference is used in many places. 31 | 32 | 33 | ### Why Doom/Hexen/UDMF Linedef/Thing objects? Why not a single object for all things/linedefs? 34 | 35 | Those object types are first and foremost abstractions of data representation in Doom, 36 | and so all of the limitations of that data must be managed by them as well. Doing this 37 | ensures that user errors are caught sooner (at read and incidental modification) rather 38 | than later (when that data needs to be written back to a binary or textual format that 39 | Doom engines can understand). 40 | 41 | 42 | ### Why are bitflags a single field on Doom/Hexen things/linedefs and not broken out into significant is/set Getter/Setters? 43 | 44 | Again, those object types are first and foremost abstractions of data representation in Doom. 45 | The meaning placed on the bitflag section of these objects are *per game or source port* and not according 46 | to the data model itself. So, a mechanism for checking these flags is necessary, but not down to the class level, 47 | where it can mislead those unfamiliar with other engines or ports. 48 | 49 | 50 | ### In Wad, why are there no "entry name seeking" variant methods for replaceEntry() / renameEntry() / removeEntry() / deleteEntry()? 51 | 52 | These methods alter data, and require you to be more precise about what you are changing. Most of 53 | the other methods that do "seeking" are read-only - finding the wrong entry to read has no direct 54 | permanent impact. 55 | 56 | ### How come MapElementView takes *Ints* instead of Enums for enumerating field types? 57 | 58 | Java Enums cannot be extended. If a developer creates a class that is an extension of another MapElementView, the same 59 | values can be used for the enumerated fields instead of needing to potentially create another full Enum set that 60 | the new view class would accept. While this approach is a little more error-prone for end-users, this would still enable developers 61 | to add only what they would need to implement and call the parent implementation for handling an unknown field type. 62 | -------------------------------------------------------------------------------- /VERSIONING.md: -------------------------------------------------------------------------------- 1 | # Versioning 2 | 3 | This project makes use of Semantic Versioning as its guidelines for advancing versions. The version of this project is {Major}.{Minor}.{Patch} with an optional fourth digit ({Info}) for tiny changes that do not affect program logic (but possibly documentation/build). 4 | 5 | **Major** changes entail refactorings and removal of deprecated methods/classes/fields ("Will updating cause errors in dependent code?") 6 | 7 | **Minor** changes entail additions or deprecations of public/protected/default fields/methods/classes ("Will updating keep things working in dependent code?") 8 | 9 | **Patch** changes entail logic changes within methods and classes that are not visible to end users. 10 | 11 | **Info** changes are changes to comments or documentation - no logic changes (unless it's to the build scripts). 12 | 13 | The "highest" type of change dictates what number is advanced. The rest of the lower digits are set to 0 (or removed, if "info" change). 14 | 15 | -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | Doom Struct 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 50 | 51 | 52 | 53 | 54 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /docs/AUTHORS.txt: -------------------------------------------------------------------------------- 1 | Matt Tropiano 2 | - API and implementation 3 | - doommap.wad (CC3 MAP07) 4 | - hexenmap.wad (Scourge of Viscerus MAP01) 5 | - udmfmap.wad (SQUARE DM01) 6 | - viscerus.pk3 (Scourge of Viscerus) 7 | -------------------------------------------------------------------------------- /docs/LICENSE-BlackRookBase.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Black Rook Software 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/bsp/BSPTree.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.bsp; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | import net.mtrop.doom.bsp.data.BSPNode; 14 | import net.mtrop.doom.bsp.data.BSPSegment; 15 | import net.mtrop.doom.bsp.data.BSPSubsector; 16 | 17 | /** 18 | * BSP Tree Abstraction. 19 | * @author Matthew Tropiano 20 | */ 21 | public class BSPTree 22 | { 23 | /** Nodes: List of Segments. */ 24 | private List segments; 25 | /** Nodes: List of Subsectors. */ 26 | private List subsectors; 27 | /** Nodes: List of Nodes. */ 28 | private List nodes; 29 | 30 | public BSPTree() 31 | { 32 | segments = new ArrayList(1024); 33 | subsectors = new ArrayList(1024); 34 | nodes = new ArrayList(512); 35 | } 36 | 37 | /** 38 | * @return the underlying list of segments. 39 | */ 40 | public List getSegments() 41 | { 42 | return segments; 43 | } 44 | 45 | /** 46 | * Replaces the list of segments in the map. 47 | * Input objects are copied to the underlying list. 48 | * @param segments the new list of segments. 49 | */ 50 | public void setSegments(Iterable segments) 51 | { 52 | this.segments.clear(); 53 | for (BSPSegment obj : segments) 54 | this.segments.add(obj); 55 | } 56 | 57 | /** 58 | * Adds a segment to this map. 59 | * @param segment the segment to add. 60 | */ 61 | public void addSegment(BSPSegment segment) 62 | { 63 | segments.add(segment); 64 | } 65 | 66 | /** 67 | * @return the amount of segments in this map. 68 | */ 69 | public int getSegmentCount() 70 | { 71 | return segments.size(); 72 | } 73 | 74 | /** 75 | * Gets the segment at a specific index. 76 | * @param i the desired index. 77 | * @return the segment at the index, or null if the index is out of range. 78 | */ 79 | public BSPSegment getSegment(int i) 80 | { 81 | return segments.get(i); 82 | } 83 | 84 | /** 85 | * @return the underlying list of subsectors. 86 | */ 87 | public List getSubsectors() 88 | { 89 | return subsectors; 90 | } 91 | 92 | /** 93 | * Replaces the list of subsectors in the map. 94 | * Input objects are copied to the underlying list. 95 | * @param subsectors the new list of subsectors. 96 | */ 97 | public void setSubsectors(Iterable subsectors) 98 | { 99 | this.subsectors.clear(); 100 | for (BSPSubsector obj : subsectors) 101 | this.subsectors.add(obj); 102 | } 103 | 104 | /** 105 | * Adds a subsector to this map. 106 | * @param subsector the subsector to add. 107 | */ 108 | public void addSubsector(BSPSubsector subsector) 109 | { 110 | subsectors.add(subsector); 111 | } 112 | 113 | /** 114 | * @return the amount of subsectors in this map. 115 | */ 116 | public int getSubsectorCount() 117 | { 118 | return subsectors.size(); 119 | } 120 | 121 | /** 122 | * Gets the subsector at a specific index. 123 | * @param i the desired index. 124 | * @return the subsector at the index, or null if the index is out of range. 125 | */ 126 | public BSPSubsector getSubsector(int i) 127 | { 128 | return subsectors.get(i); 129 | } 130 | 131 | /** 132 | * @return the underlying list of nodes. 133 | */ 134 | public List getNodes() 135 | { 136 | return nodes; 137 | } 138 | 139 | /** 140 | * Replaces the list of nodes in the map. 141 | * Input objects are copied to the underlying list. 142 | * @param nodes the new list of nodes. 143 | */ 144 | public void setNodes(Iterable nodes) 145 | { 146 | this.nodes.clear(); 147 | for (BSPNode obj : nodes) 148 | this.nodes.add(obj); 149 | } 150 | 151 | /** 152 | * Adds a node to this map. 153 | * @param node the node to add. 154 | */ 155 | public void addNode(BSPNode node) 156 | { 157 | nodes.add(node); 158 | } 159 | 160 | /** 161 | * @return the amount of nodes in this map. 162 | */ 163 | public int getNodeCount() 164 | { 165 | return nodes.size(); 166 | } 167 | 168 | /** 169 | * Gets the node at a specific index. 170 | * @param i the desired index. 171 | * @return the node at the index, or null if the index is out of range. 172 | */ 173 | public BSPNode getNode(int i) 174 | { 175 | return nodes.get(i); 176 | } 177 | 178 | } 179 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/bsp/data/BSPSubsector.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.bsp.data; 9 | 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.io.OutputStream; 13 | 14 | import net.mtrop.doom.object.BinaryObject; 15 | import net.mtrop.doom.struct.io.SerialReader; 16 | import net.mtrop.doom.struct.io.SerialWriter; 17 | import net.mtrop.doom.util.RangeUtils; 18 | 19 | /** 20 | * 4-byte BSP Subsector information that lists all of the BSP segment indices for a sector. 21 | * These are essentially the mappings of Nodes to other nodes. 22 | * @author Matthew Tropiano 23 | */ 24 | public class BSPSubsector implements BinaryObject 25 | { 26 | /** Byte length of this object. */ 27 | public static final int LENGTH = 4; 28 | 29 | /** This Subsector's BSP Segment count. */ 30 | protected int segCount; 31 | /** This Subsector's starting segment index. */ 32 | protected int segStartIndex; 33 | 34 | /** 35 | * Creates a new BSP Subsector. 36 | */ 37 | public BSPSubsector() 38 | { 39 | segCount = 0; 40 | segStartIndex = -1; 41 | } 42 | 43 | /** 44 | * @return the amount of BSPSegments pointed to by this subsector. 45 | */ 46 | public int getSegCount() 47 | { 48 | return segCount; 49 | } 50 | 51 | /** 52 | * Sets the amount of BSPSegments pointed to by this subsector. 53 | * @param segCount the amount of segments. 54 | * @throws IllegalArgumentException if the provided value is outside the range 0 to 65535. 55 | */ 56 | public void setSegCount(int segCount) 57 | { 58 | RangeUtils.checkShortUnsigned("Segment Count", segCount); 59 | this.segCount = segCount; 60 | } 61 | 62 | /** 63 | * @return the starting offset index of this subsector's BSPSegments in the Segs lump. 64 | */ 65 | public int getSegStartIndex() 66 | { 67 | return segStartIndex; 68 | } 69 | 70 | /** 71 | * Sets the starting offset index of this subsector's BSPSegments in the Segs lump. 72 | * @param segStartIndex the starting index. 73 | * @throws IllegalArgumentException if the provided value is outside the range 0 to 65535. 74 | */ 75 | public void setSegStartIndex(int segStartIndex) 76 | { 77 | RangeUtils.checkShortUnsigned("Segment Start Index", segStartIndex); 78 | this.segStartIndex = segStartIndex; 79 | } 80 | 81 | @Override 82 | public void readBytes(InputStream in) throws IOException 83 | { 84 | SerialReader sr = new SerialReader(SerialReader.LITTLE_ENDIAN); 85 | segCount = sr.readUnsignedShort(in); 86 | segStartIndex = sr.readUnsignedShort(in); 87 | } 88 | 89 | @Override 90 | public void writeBytes(OutputStream out) throws IOException 91 | { 92 | SerialWriter sw = new SerialWriter(SerialWriter.LITTLE_ENDIAN); 93 | sw.writeUnsignedShort(out, segCount); 94 | sw.writeUnsignedShort(out, segStartIndex); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/bsp/data/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains data for BSP Trees. 3 | */ 4 | package net.mtrop.doom.bsp.data; -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/bsp/package-info.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Matt Tropiano 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Lesser Public License v2.1 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | /** 9 | * Contains binary space partitioning data structures. 10 | */ 11 | package net.mtrop.doom.bsp; 12 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/demo/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains classes related to Demos. 3 | */ 4 | package net.mtrop.doom.demo; -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/exception/MapException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.exception; 9 | 10 | /** 11 | * An exception thrown when Doom Map information is unavailable or malformed. 12 | * @author Matthew Tropiano 13 | */ 14 | public class MapException extends Exception 15 | { 16 | private static final long serialVersionUID = 4553734950678544532L; 17 | 18 | public MapException() 19 | { 20 | super(); 21 | } 22 | 23 | public MapException(String message, Throwable cause) 24 | { 25 | super(message, cause); 26 | } 27 | 28 | public MapException(String message) 29 | { 30 | super(message); 31 | } 32 | 33 | public MapException(Throwable cause) 34 | { 35 | super(cause); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/exception/TextureException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.exception; 9 | 10 | /** 11 | * An exception thrown when Doom texture information is unavailable or malformed. 12 | * @author Matthew Tropiano 13 | */ 14 | public class TextureException extends RuntimeException 15 | { 16 | private static final long serialVersionUID = 4553734950678544532L; 17 | 18 | public TextureException() 19 | { 20 | super(); 21 | } 22 | 23 | public TextureException(String message, Throwable cause) 24 | { 25 | super(message, cause); 26 | } 27 | 28 | public TextureException(String message) 29 | { 30 | super(message); 31 | } 32 | 33 | public TextureException(Throwable cause) 34 | { 35 | super(cause); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/exception/WadException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.exception; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * An exception thrown when an operation on a WAD file would violate its 14 | * structural integrity in some way. 15 | * @author Matthew Tropiano 16 | */ 17 | public class WadException extends IOException 18 | { 19 | private static final long serialVersionUID = 7393763909497049387L; 20 | 21 | public WadException() 22 | { 23 | super(); 24 | } 25 | 26 | public WadException(String message, Throwable cause) 27 | { 28 | super(message, cause); 29 | } 30 | 31 | public WadException(String message) 32 | { 33 | super(message); 34 | } 35 | 36 | public WadException(Throwable cause) 37 | { 38 | super(cause); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Matt Tropiano 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Lesser Public License v2.1 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | /** 9 | * All exceptions specific to this library are contained here. 10 | */ 11 | package net.mtrop.doom.exception; 12 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/graphics/IndexedGraphic.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.graphics; 9 | 10 | /** 11 | * Interface for graphic data with indexed palettes. 12 | * @author Matthew Tropiano 13 | * @since 2.2.0 14 | * @deprecated Since 2.13.0 - made superfluous. 15 | */ 16 | public interface IndexedGraphic 17 | { 18 | /** 19 | * @return the width of this graphic in pixels. 20 | */ 21 | public int getWidth(); 22 | 23 | /** 24 | * @return the height of this graphic in pixels. 25 | */ 26 | public int getHeight(); 27 | 28 | /** 29 | * Gets the pixel data at a location in the graphic. 30 | * May return -1 if this graphic has translucent pixels. 31 | * @param x graphic x-coordinate. 32 | * @param y graphic y-coordinate. 33 | * @return a palette index value from 0 to 255, or {@link Picture#PIXEL_TRANSLUCENT} if translucent. 34 | * @throws ArrayIndexOutOfBoundsException if the provided coordinates is outside the graphic. 35 | */ 36 | public int getPixel(int x, int y); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/graphics/package-info.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Matt Tropiano 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Lesser Public License v2.1 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | /** Contains abstracts and implementations of graphic types. */ 9 | package net.mtrop.doom.graphics; 10 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/DoomMap.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map; 9 | 10 | import net.mtrop.doom.map.data.DoomLinedef; 11 | import net.mtrop.doom.map.data.DoomSector; 12 | import net.mtrop.doom.map.data.DoomSidedef; 13 | import net.mtrop.doom.map.data.DoomThing; 14 | import net.mtrop.doom.map.data.DoomVertex; 15 | 16 | /** 17 | * Doom map in Doom Format. 18 | * @author Matthew Tropiano 19 | */ 20 | public class DoomMap extends CommonMap 21 | { 22 | /** 23 | * Creates a blank map. 24 | */ 25 | public DoomMap() 26 | { 27 | super(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/HexenMap.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map; 9 | 10 | import net.mtrop.doom.map.data.DoomSector; 11 | import net.mtrop.doom.map.data.DoomSidedef; 12 | import net.mtrop.doom.map.data.DoomVertex; 13 | import net.mtrop.doom.map.data.HexenLinedef; 14 | import net.mtrop.doom.map.data.HexenThing; 15 | 16 | /** 17 | * Hexen map in ZDoom/Hexen Format. 18 | * @author Matthew Tropiano 19 | */ 20 | public class HexenMap extends CommonMap 21 | { 22 | /** 23 | * Creates a blank map. 24 | */ 25 | public HexenMap() 26 | { 27 | super(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/MapFormat.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map; 9 | 10 | /** 11 | * Enumeration of internal map format types. 12 | * @author Matthew Tropiano 13 | */ 14 | public enum MapFormat 15 | { 16 | /** Format commonly used by Doom, Boom, and MBF/SMMU ports, plus Heretic and Strife. */ 17 | DOOM, 18 | /** Format commonly used by Hexen and ZDoom-derivative ports. */ 19 | HEXEN, 20 | /** Format commonly used by all extensible ports. */ 21 | UDMF; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/MapObjectConstants.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map; 9 | 10 | /** 11 | * Common elements of all map objects. 12 | * This provides a general interface for getting map object data. 13 | * @author Matthew Tropiano 14 | */ 15 | public interface MapObjectConstants 16 | { 17 | /** Value used for null references to other map objects. */ 18 | public static final int NULL_REFERENCE = -1; 19 | /** Value used for no special. */ 20 | public static final int SPECIAL_NONE = 0; 21 | /** Value used for blank texture. */ 22 | public static final String TEXTURE_BLANK = "-"; 23 | 24 | /** Degree Angle for EAST. */ 25 | public static final int ANGLE_EAST = 0; 26 | /** Degree Angle for NORTHEAST. */ 27 | public static final int ANGLE_NORTHEAST = 45; 28 | /** Degree Angle for NORTH. */ 29 | public static final int ANGLE_NORTH = 90; 30 | /** Degree Angle for NORTHWEST. */ 31 | public static final int ANGLE_NORTHWEST = 135; 32 | /** Degree Angle for WEST. */ 33 | public static final int ANGLE_WEST = 180; 34 | /** Degree Angle for SOUTHWEST. */ 35 | public static final int ANGLE_SOUTHWEST = 225; 36 | /** Degree Angle for SOUTH. */ 37 | public static final int ANGLE_SOUTH = 270; 38 | /** Degree Angle for SOUTHEAST. */ 39 | public static final int ANGLE_SOUTHEAST = 315; 40 | 41 | /** Byte Angle for EAST. */ 42 | public static final int BYTE_ANGLE_EAST = 0; 43 | /** Byte Angle for NORTHEAST. */ 44 | public static final int BYTE_ANGLE_NORTHEAST = 32; 45 | /** Byte Angle for NORTH. */ 46 | public static final int BYTE_ANGLE_NORTH = 64; 47 | /** Byte Angle for NORTHWEST. */ 48 | public static final int BYTE_ANGLE_NORTHWEST = 96; 49 | /** Byte Angle for WEST. */ 50 | public static final int BYTE_ANGLE_WEST = 128; 51 | /** Byte Angle for SOUTHWEST. */ 52 | public static final int BYTE_ANGLE_SOUTHWEST = 160; 53 | /** Byte Angle for SOUTH. */ 54 | public static final int BYTE_ANGLE_SOUTH = 192; 55 | /** Byte Angle for SOUTHEAST. */ 56 | public static final int BYTE_ANGLE_SOUTHEAST = 224; 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/MapView.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map; 9 | 10 | /** 11 | * Interface for looking into Doom maps. 12 | * @author Matthew Tropiano 13 | * @param the class type for vertices. 14 | * @param the class type for linedefs. 15 | * @param the class type for sidedefs. 16 | * @param the class type for sectors. 17 | * @param the class type for things. 18 | */ 19 | public interface MapView 20 | { 21 | /** 22 | * Gets the vertex at a specific index. 23 | * @param i the desired index. 24 | * @return the vertex at the index, or null if the index is out of range. 25 | */ 26 | public V getVertex(int i); 27 | 28 | /** 29 | * @return the amount of vertices in this map. 30 | */ 31 | public int getVertexCount(); 32 | 33 | /** 34 | * Gets the linedef at a specific index. 35 | * @param i the desired index. 36 | * @return the linedef at the index, or null if the index is out of range. 37 | */ 38 | public L getLinedef(int i); 39 | 40 | /** 41 | * @return the amount of linedefs in this map. 42 | */ 43 | public int getLinedefCount(); 44 | 45 | /** 46 | * Gets the sidedef at a specific index. 47 | * @param i the desired index. 48 | * @return the sidedef at the index, or null if the index is out of range. 49 | */ 50 | public S getSidedef(int i); 51 | 52 | /** 53 | * @return the amount of sidedefs in this map. 54 | */ 55 | public int getSidedefCount(); 56 | 57 | /** 58 | * Gets the sector at a specific index. 59 | * @param i the desired index. 60 | * @return the sector at the index, or null if the index is out of range. 61 | */ 62 | public E getSector(int i); 63 | 64 | /** 65 | * @return the amount of sectors in this map. 66 | */ 67 | public int getSectorCount(); 68 | 69 | /** 70 | * Gets the thing at a specific index. 71 | * @param i the desired index. 72 | * @return the thing at the index, or null if the index is out of range. 73 | */ 74 | public T getThing(int i); 75 | 76 | /** 77 | * @return the amount of things in this map. 78 | */ 79 | public int getThingCount(); 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/UDMFMap.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map; 9 | 10 | import java.io.IOException; 11 | import java.io.Reader; 12 | import java.io.Writer; 13 | 14 | import net.mtrop.doom.map.udmf.UDMFObject; 15 | import net.mtrop.doom.map.udmf.UDMFReader; 16 | import net.mtrop.doom.map.udmf.UDMFWriter; 17 | import net.mtrop.doom.map.udmf.attributes.UDMFGlobalAttributes; 18 | import net.mtrop.doom.map.udmf.listener.UDMFTypeListener; 19 | import net.mtrop.doom.object.TextObject; 20 | 21 | /** 22 | * A map that contains full UDMF map data. 23 | * @author Matthew Tropiano 24 | */ 25 | public class UDMFMap extends CommonMap implements TextObject 26 | { 27 | /** Type name: Vertex. */ 28 | public static final String VERTEX = "vertex"; 29 | /** Type name: Linedef. */ 30 | public static final String LINEDEF = "linedef"; 31 | /** Type name: Sidedef. */ 32 | public static final String SIDEDEF = "sidedef"; 33 | /** Type name: Sector. */ 34 | public static final String SECTOR = "sector"; 35 | /** Type name: Thing. */ 36 | public static final String THING = "thing"; 37 | 38 | /** The namespace for this UDMF map. */ 39 | private String namespace; 40 | 41 | /** 42 | * Creates a blank map. 43 | */ 44 | public UDMFMap() 45 | { 46 | super(); 47 | this.namespace = null; 48 | } 49 | 50 | @Override 51 | public void clear() 52 | { 53 | super.clear(); 54 | setNamespace(null); 55 | } 56 | 57 | /** 58 | * Gets this UDMF namespace. 59 | * @return the namespace for this UDMF map. 60 | */ 61 | public String getNamespace() 62 | { 63 | return namespace; 64 | } 65 | 66 | /** 67 | * Sets the UDMF namespace for this map. 68 | * @param namespace the new namespace. 69 | */ 70 | public void setNamespace(String namespace) 71 | { 72 | this.namespace = namespace; 73 | } 74 | 75 | @Override 76 | public void readText(Reader reader) throws IOException 77 | { 78 | clear(); 79 | final IOException[] exception = new IOException[1]; 80 | UDMFReader.readData(reader, new UDMFTypeListener(){ 81 | 82 | @Override 83 | public void onParseError(String error) 84 | { 85 | exception[0] = new IOException(error); 86 | } 87 | 88 | @Override 89 | public void onGlobalAttribute(String name, Object value) 90 | { 91 | if (name.equals(UDMFGlobalAttributes.ATTRIB_NAMESPACE)) 92 | setNamespace(String.valueOf(value)); 93 | } 94 | 95 | @Override 96 | public void onType(String type, UDMFObject object) 97 | { 98 | switch (type) 99 | { 100 | case UDMFMap.VERTEX: 101 | addVertex(object); 102 | break; 103 | case UDMFMap.LINEDEF: 104 | addLinedef(object); 105 | break; 106 | case UDMFMap.SIDEDEF: 107 | addSidedef(object); 108 | break; 109 | case UDMFMap.SECTOR: 110 | addSector(object); 111 | break; 112 | case UDMFMap.THING: 113 | addThing(object); 114 | break; 115 | } 116 | } 117 | }); 118 | 119 | if (exception[0] != null) 120 | throw exception[0]; 121 | } 122 | 123 | @Override 124 | public void writeText(Writer writer) throws IOException 125 | { 126 | writer.append("// Generated by Doom Struct").append('\n').append('\n'); 127 | UDMFWriter.writeField(UDMFGlobalAttributes.ATTRIB_NAMESPACE, namespace, writer, ""); 128 | for (int i = 0; i < getThingCount(); i++) 129 | UDMFWriter.writeObject(getThing(i), writer, THING, i); 130 | for (int i = 0; i < getVertexCount(); i++) 131 | UDMFWriter.writeObject(getVertex(i), writer, VERTEX, i); 132 | for (int i = 0; i < getLinedefCount(); i++) 133 | UDMFWriter.writeObject(getLinedef(i), writer, LINEDEF, i); 134 | for (int i = 0; i < getSidedefCount(); i++) 135 | UDMFWriter.writeObject(getSidedef(i), writer, SIDEDEF, i); 136 | for (int i = 0; i < getSectorCount(); i++) 137 | UDMFWriter.writeObject(getSector(i), writer, SECTOR, i); 138 | } 139 | 140 | } 141 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/CommonThing.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data; 9 | 10 | import net.mtrop.doom.map.data.flags.BoomThingFlags; 11 | import net.mtrop.doom.map.data.flags.DoomThingFlags; 12 | import net.mtrop.doom.map.data.flags.HexenThingFlags; 13 | import net.mtrop.doom.map.data.flags.MBFThingFlags; 14 | import net.mtrop.doom.map.data.flags.StrifeThingFlags; 15 | import net.mtrop.doom.map.data.flags.ZDoomThingFlags; 16 | import net.mtrop.doom.object.BinaryObject; 17 | import net.mtrop.doom.util.RangeUtils; 18 | 19 | /** 20 | * Contains common elements of all binary things. 21 | * @author Matthew Tropiano 22 | */ 23 | abstract class CommonThing implements BinaryObject 24 | { 25 | /** Thing X position. */ 26 | protected int x; 27 | /** Thing Y position. */ 28 | protected int y; 29 | /** Thing angle. */ 30 | protected int angle; 31 | /** Thing type (editor number). */ 32 | protected int type; 33 | 34 | /** Behavior bitflags. */ 35 | protected int flags; 36 | 37 | /** 38 | * Creates a new thing. 39 | */ 40 | public CommonThing() 41 | { 42 | this.x = 0; 43 | this.y = 0; 44 | this.angle = 0; 45 | this.type = 0; 46 | this.flags = 0; 47 | } 48 | 49 | /** 50 | * Sets the coordinates of this thing. 51 | * @param x the x-coordinate value. 52 | * @param y the y-coordinate value. 53 | */ 54 | public void set(int x, int y) 55 | { 56 | setX(x); 57 | setY(y); 58 | } 59 | 60 | /** 61 | * @return the position X-coordinate. 62 | */ 63 | public int getX() 64 | { 65 | return x; 66 | } 67 | 68 | /** 69 | * Sets the position X-coordinate. 70 | * @param x the new x-coordinate. 71 | * @throws IllegalArgumentException if x is outside of the range -32768 to 32767. 72 | */ 73 | public void setX(int x) 74 | { 75 | RangeUtils.checkShort("Position X", x); 76 | this.x = x; 77 | } 78 | 79 | /** 80 | * @return the position Y-coordinate. 81 | */ 82 | public int getY() 83 | { 84 | return y; 85 | } 86 | 87 | /** 88 | * Sets the position Y-coordinate. 89 | * @param y the new y-coordinate. 90 | * @throws IllegalArgumentException if y is outside of the range -32768 to 32767. 91 | */ 92 | public void setY(int y) 93 | { 94 | RangeUtils.checkShort("Position Y", y); 95 | this.y = y; 96 | } 97 | 98 | /** 99 | * @return the angle (in degrees). 100 | */ 101 | public int getAngle() 102 | { 103 | return angle; 104 | } 105 | 106 | /** 107 | * Sets the angle (in degrees). 108 | * @param angle the new angle in degrees. 109 | * @throws IllegalArgumentException if angle is outside of the range -32768 to 32767. 110 | */ 111 | public void setAngle(int angle) 112 | { 113 | RangeUtils.checkShort("Angle", angle); 114 | this.angle = angle; 115 | } 116 | 117 | /** 118 | * @return thing type (a.k.a. editor number). 119 | */ 120 | public int getType() 121 | { 122 | return type; 123 | } 124 | 125 | /** 126 | * Sets thing type (a.k.a. editor number). 127 | * @param type the new thing type. 128 | * @throws IllegalArgumentException if type is outside of the range 0 to 65535. 129 | */ 130 | public void setType(int type) 131 | { 132 | RangeUtils.checkShortUnsigned("Type", type); 133 | this.type = type; 134 | } 135 | 136 | /** 137 | * @return this linedef's full bitflags. 138 | */ 139 | public int getFlags() 140 | { 141 | return flags; 142 | } 143 | 144 | /** 145 | * Sets/replaces this linedef's full bitflags. 146 | * @param flags the flags to set 147 | */ 148 | public void setFlags(int flags) 149 | { 150 | this.flags = flags; 151 | } 152 | 153 | /** 154 | * Check's if a flag bit is set. 155 | * @param flagType the flag type (constant). 156 | * @return true if set, false if not. 157 | * @see DoomThingFlags 158 | * @see BoomThingFlags 159 | * @see MBFThingFlags 160 | * @see HexenThingFlags 161 | * @see StrifeThingFlags 162 | * @see ZDoomThingFlags 163 | */ 164 | public boolean isFlagSet(int flagType) 165 | { 166 | return (flags & (1 << flagType)) != 0; 167 | } 168 | 169 | /** 170 | * Sets/clears a bit flag. 171 | * @param flagType the flag type (constant). 172 | * @param set if true, set the bit. If false, clear it. 173 | * @see DoomThingFlags 174 | * @see BoomThingFlags 175 | * @see MBFThingFlags 176 | * @see HexenThingFlags 177 | * @see StrifeThingFlags 178 | * @see ZDoomThingFlags 179 | */ 180 | public void setFlag(int flagType, boolean set) 181 | { 182 | flags = set 183 | ? flags | (1 << flagType) 184 | : flags & ~(1 << flagType) 185 | ; 186 | } 187 | 188 | } 189 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/DoomLinedef.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data; 9 | 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.io.OutputStream; 13 | 14 | import net.mtrop.doom.object.BinaryObject; 15 | import net.mtrop.doom.struct.io.SerialReader; 16 | import net.mtrop.doom.struct.io.SerialWriter; 17 | import net.mtrop.doom.util.RangeUtils; 18 | 19 | /** 20 | * Doom/Boom 14-byte format implementation of Linedef. 21 | * @author Matthew Tropiano 22 | */ 23 | public class DoomLinedef extends CommonLinedef implements BinaryObject 24 | { 25 | /** Byte length of this object. */ 26 | public static final int LENGTH = 14; 27 | 28 | /** Linedef special tag. */ 29 | protected int tag; 30 | 31 | /** 32 | * Creates a new linedef. 33 | */ 34 | public DoomLinedef() 35 | { 36 | super(); 37 | this.tag = 0; 38 | } 39 | 40 | /** 41 | * Sets this linedef's special tag. 42 | * @param tag the new tag. 43 | */ 44 | public void setTag(int tag) 45 | { 46 | RangeUtils.checkShortUnsigned("Tag", tag); 47 | this.tag = tag; 48 | } 49 | 50 | /** 51 | * @return this linedef's special tag. 52 | */ 53 | public int getTag() 54 | { 55 | return tag; 56 | } 57 | 58 | @Override 59 | public void readBytes(InputStream in) throws IOException 60 | { 61 | SerialReader sr = new SerialReader(SerialReader.LITTLE_ENDIAN); 62 | vertexStartIndex = sr.readUnsignedShort(in); 63 | vertexEndIndex = sr.readUnsignedShort(in); 64 | flags = sr.readUnsignedShort(in); 65 | special = sr.readUnsignedShort(in); 66 | tag = sr.readUnsignedShort(in); 67 | sidedefFrontIndex = sr.readShort(in); 68 | sidedefBackIndex = sr.readShort(in); 69 | } 70 | 71 | @Override 72 | public void writeBytes(OutputStream out) throws IOException 73 | { 74 | SerialWriter sw = new SerialWriter(SerialWriter.LITTLE_ENDIAN); 75 | sw.writeUnsignedShort(out, vertexStartIndex); 76 | sw.writeUnsignedShort(out, vertexEndIndex); 77 | sw.writeUnsignedShort(out, flags & 0x0FFFF); 78 | sw.writeUnsignedShort(out, special); 79 | sw.writeUnsignedShort(out, tag); 80 | sw.writeShort(out, (short)sidedefFrontIndex); 81 | sw.writeShort(out, (short)sidedefBackIndex); 82 | } 83 | 84 | @Override 85 | public String toString() 86 | { 87 | StringBuilder sb = new StringBuilder(); 88 | sb.append("Linedef"); 89 | sb.append(' ').append(vertexStartIndex).append(" to ").append(vertexEndIndex); 90 | sb.append(' ').append("Front Sidedef ").append(sidedefFrontIndex); 91 | sb.append(' ').append("Back Sidedef ").append(sidedefBackIndex); 92 | sb.append(' ').append("Flags 0x").append(String.format("%016x", flags & 0x0FFFF)); 93 | sb.append(' ').append("Special ").append(special); 94 | sb.append(' ').append("Tag ").append(tag); 95 | return sb.toString(); 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/DoomThing.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data; 9 | 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.io.OutputStream; 13 | 14 | import net.mtrop.doom.object.BinaryObject; 15 | import net.mtrop.doom.struct.io.SerialReader; 16 | import net.mtrop.doom.struct.io.SerialWriter; 17 | 18 | /** 19 | * Doom/Boom/MBF 10-byte format implementation of Thing. 20 | * @author Matthew Tropiano 21 | */ 22 | public class DoomThing extends CommonThing implements BinaryObject 23 | { 24 | /** Byte length of this object. */ 25 | public static final int LENGTH = 10; 26 | 27 | /** 28 | * Creates a new thing. 29 | */ 30 | public DoomThing() 31 | { 32 | super(); 33 | } 34 | 35 | @Override 36 | public void readBytes(InputStream in) throws IOException 37 | { 38 | SerialReader sr = new SerialReader(SerialReader.LITTLE_ENDIAN); 39 | x = sr.readShort(in); 40 | y = sr.readShort(in); 41 | angle = sr.readUnsignedShort(in); 42 | type = sr.readUnsignedShort(in); 43 | flags = sr.readUnsignedShort(in); 44 | } 45 | 46 | @Override 47 | public void writeBytes(OutputStream out) throws IOException 48 | { 49 | SerialWriter sw = new SerialWriter(SerialWriter.LITTLE_ENDIAN); 50 | sw.writeShort(out, (short)x); 51 | sw.writeShort(out, (short)y); 52 | sw.writeShort(out, (short)angle); 53 | sw.writeShort(out, (short)type); 54 | sw.writeUnsignedShort(out, flags & 0x0FFFF); 55 | } 56 | 57 | @Override 58 | public String toString() 59 | { 60 | StringBuilder sb = new StringBuilder(); 61 | sb.append("Thing"); 62 | sb.append(" (").append(x).append(", ").append(y).append(")"); 63 | sb.append(" Type:").append(type); 64 | sb.append(" Angle:").append(angle); 65 | sb.append(' ').append("Flags 0x").append(String.format("%016x", flags & 0x0FFFF)); 66 | return sb.toString(); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/DoomVertex.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data; 9 | 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.io.OutputStream; 13 | 14 | import net.mtrop.doom.object.BinaryObject; 15 | import net.mtrop.doom.struct.io.SerialReader; 16 | import net.mtrop.doom.struct.io.SerialWriter; 17 | import net.mtrop.doom.util.RangeUtils; 18 | 19 | /** 20 | * The 4-byte representation of a vertex. 21 | * @author Matthew Tropiano 22 | */ 23 | public class DoomVertex implements BinaryObject 24 | { 25 | /** Byte length of this object. */ 26 | public static final int LENGTH = 4; 27 | 28 | /** Vertex: X-coordinate. */ 29 | private int x; 30 | /** Vertex: X-coordinate. */ 31 | private int y; 32 | 33 | /** 34 | * Creates a new vertex with default values set. 35 | */ 36 | public DoomVertex() 37 | { 38 | this.x = 0; 39 | this.y = 0; 40 | } 41 | 42 | /** 43 | * Sets the coordinates of this vertex. 44 | * @param x the new x-coordinate value. 45 | * @param y the new y-coordinate value. 46 | */ 47 | public void set(int x, int y) 48 | { 49 | setX(x); 50 | setY(y); 51 | } 52 | 53 | /** 54 | * @return the X-coordinate value of this vertex. 55 | */ 56 | public int getX() 57 | { 58 | return x; 59 | } 60 | 61 | /** 62 | * Sets the X-coordinate value of this vertex. 63 | * @param x the new x-coordinate value. 64 | * @throws IllegalArgumentException if x is outside of the range -32768 to 32767. 65 | */ 66 | public void setX(int x) 67 | { 68 | RangeUtils.checkShort("X-coordinate", x); 69 | this.x = x; 70 | } 71 | 72 | /** 73 | * @return the Y-coordinate value of this vertex. 74 | */ 75 | public int getY() 76 | { 77 | return y; 78 | } 79 | 80 | /** 81 | * Sets the Y-coordinate value of this vertex. 82 | * @param y the new y-coordinate value. 83 | * @throws IllegalArgumentException if y is outside of the range -32768 to 32767. 84 | */ 85 | public void setY(int y) 86 | { 87 | RangeUtils.checkShort("Y-coordinate", y); 88 | this.y = y; 89 | } 90 | 91 | @Override 92 | public void readBytes(InputStream in) throws IOException 93 | { 94 | SerialReader sr = new SerialReader(SerialReader.LITTLE_ENDIAN); 95 | x = sr.readShort(in); 96 | y = sr.readShort(in); 97 | } 98 | 99 | @Override 100 | public void writeBytes(OutputStream out) throws IOException 101 | { 102 | RangeUtils.checkShort("X-coordinate", x); 103 | RangeUtils.checkShort("Y-coordinate", y); 104 | 105 | SerialWriter sw = new SerialWriter(SerialWriter.LITTLE_ENDIAN); 106 | sw.writeShort(out, (short)x); 107 | sw.writeShort(out, (short)y); 108 | } 109 | 110 | @Override 111 | public String toString() 112 | { 113 | return "Vertex (" + x + ", " + y + ")"; 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/Reject.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data; 9 | 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.io.OutputStream; 13 | 14 | import net.mtrop.doom.object.BinaryObject; 15 | import net.mtrop.doom.struct.io.SerialReader; 16 | import net.mtrop.doom.struct.io.SerialWriter; 17 | 18 | /** 19 | * Represents the Reject lump. 20 | *

21 | * The reject lump is a lookup grid that hold information on what sectors can 22 | * "see" other sectors on the map used for thing sight algorithms. 23 | * @author Matthew Tropiano 24 | */ 25 | public class Reject implements BinaryObject 26 | { 27 | private static final byte[] BITMASK = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, (byte)0x80}; 28 | 29 | /** The reject grid itself. */ 30 | private boolean[][] grid; 31 | 32 | /** 33 | * Creates a new blank reject grid. 34 | * @param sectors the number of sectors. 35 | */ 36 | public Reject(int sectors) 37 | { 38 | grid = new boolean[sectors][sectors]; 39 | } 40 | 41 | /** 42 | * Checks whether a sector is visible from another. 43 | * @param sectorIndex the sector index viewing from. 44 | * @param targetSectorIndex the sector index viewing into. 45 | * @return true if so, false if not. 46 | */ 47 | public boolean getSectorIsVisibleTo(int sectorIndex, int targetSectorIndex) 48 | { 49 | return grid[targetSectorIndex][sectorIndex]; 50 | } 51 | 52 | /** 53 | * Sets whether a sector is visible from another. 54 | * @param sectorIndex the sector index viewing from. 55 | * @param targetSectorIndex the sector index viewing into. 56 | * @param flag true if visible, false if not. 57 | */ 58 | public void setSectorIsVisibleTo(int sectorIndex, int targetSectorIndex, boolean flag) 59 | { 60 | grid[targetSectorIndex][sectorIndex] = flag; 61 | } 62 | 63 | @Override 64 | public void readBytes(InputStream in) throws IOException 65 | { 66 | SerialReader sr = new SerialReader(SerialReader.LITTLE_ENDIAN); 67 | 68 | byte curByte = 0; 69 | int bit = 0; 70 | 71 | for (int i = 0; i < grid.length; i++) 72 | for (int j = 0; j < grid[i].length && in.available() > 0; j++) 73 | { 74 | if (bit == 8) 75 | { 76 | curByte = sr.readByte(in); 77 | bit = 0; 78 | } 79 | grid[i][j] = (curByte & BITMASK[bit]) != 0; 80 | bit++; 81 | } 82 | } 83 | 84 | @Override 85 | public void writeBytes(OutputStream out) throws IOException 86 | { 87 | SerialWriter sw = new SerialWriter(SerialWriter.LITTLE_ENDIAN); 88 | byte curByte = 0; 89 | int bit = 0; 90 | 91 | for (int i = 0; i < grid.length; i++) 92 | for (int j = 0; j < grid[i].length; j++) 93 | { 94 | if (grid[i][j]) 95 | curByte &= (byte)(0x01 << bit); 96 | bit++; 97 | if (bit == 8) 98 | { 99 | sw.writeByte(out, curByte); 100 | bit = 0; 101 | } 102 | } 103 | if (bit != 0) 104 | sw.writeByte(out, curByte); 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/flags/BoomLinedefFlags.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data.flags; 9 | 10 | /** 11 | * Linedef flag constants for Doom/Boom/MBF/SMMU. 12 | * The constant value is how many places to bit shift 1 to equal the flag bit. 13 | * @author Matthew Tropiano 14 | */ 15 | public interface BoomLinedefFlags extends DoomLinedefFlags 16 | { 17 | /** Linedef flag: Pass USE through this line. */ 18 | public static final int PASSTHRU = 9; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/flags/BoomThingFlags.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data.flags; 9 | 10 | /** 11 | * Thing flag constants for Boom things. 12 | * The constant value is how many places to bit shift 1 to equal the flag bit. 13 | * @author Matthew Tropiano 14 | */ 15 | public interface BoomThingFlags extends DoomThingFlags 16 | { 17 | /** Thing flag: Does not appear in cooperative. */ 18 | public static final int NOT_COOPERATIVE = 5; 19 | /** Thing flag: Does not appear in deathmatch. */ 20 | public static final int NOT_DEATHMATCH = 6; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/flags/DoomLinedefFlags.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data.flags; 9 | 10 | /** 11 | * Linedef flag constants for Doom/Heretic. 12 | * The constant value is how many places to bit shift 1 to equal the flag bit. 13 | * @author Matthew Tropiano 14 | */ 15 | public interface DoomLinedefFlags extends LinedefFlags 16 | { 17 | /** Linedef flag: Blocks players and monsters. */ 18 | public static final int IMPASSABLE = 0; 19 | /** Linedef flag: Blocks monsters. */ 20 | public static final int BLOCK_MONSTERS = 1; 21 | /** Linedef flag: Two-sided. */ 22 | public static final int TWO_SIDED = 2; 23 | /** 24 | * Linedef flag: Draw upper texture from top-down. 25 | * @since 2.9.0, naming convention change. 26 | */ 27 | public static final int UNPEG_TOP = 3; 28 | /** 29 | * Linedef flag: Draw lower texture from bottom-up. 30 | * @since 2.9.0, naming convention change. 31 | */ 32 | public static final int UNPEG_BOTTOM = 4; 33 | /** Linedef flag: Render as solid wall on automap. */ 34 | public static final int SECRET = 5; 35 | /** Linedef flag: Blocks sound propagation (needs two). */ 36 | public static final int BLOCK_SOUND = 6; 37 | /** Linedef flag: Never drawn on automap. */ 38 | public static final int NOT_DRAWN = 7; 39 | /** Linedef flag: Immediately shown on automap. */ 40 | public static final int MAPPED = 8; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/flags/DoomThingFlags.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data.flags; 9 | 10 | /** 11 | * Thing flag constants for Doom/Heretic. 12 | * The constant value is how many places to bit shift 1 to equal the flag bit. 13 | * @author Matthew Tropiano 14 | */ 15 | public interface DoomThingFlags extends ThingFlags 16 | { 17 | /** Thing flag: Ambushes players. */ 18 | public static final int AMBUSH = 3; 19 | /** Thing flag: Does not appear in single player. */ 20 | public static final int NOT_SINGLEPLAYER = 4; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/flags/HexenLinedefFlags.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data.flags; 9 | 10 | /** 11 | * Linedef flag constants for Hexen. 12 | * The constant value is how many places to bit shift 1 to equal the flag bit. 13 | * @author Matthew Tropiano 14 | */ 15 | public interface HexenLinedefFlags extends DoomLinedefFlags 16 | { 17 | /** Linedef flag: Line's special is repeatable (special is not cleared). */ 18 | public static final int REPEATABLE = 9; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/flags/HexenThingFlags.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data.flags; 9 | 10 | /** 11 | * Thing flag constants for Hexen things. 12 | * The constant value is how many places to bit shift 1 to equal the flag bit. 13 | * @author Matthew Tropiano 14 | */ 15 | public interface HexenThingFlags extends ThingFlags 16 | { 17 | /** Thing flag: Appears on ambush difficulty. */ 18 | public static final int AMBUSH = 3; 19 | /** Thing flag: Starts dormant. */ 20 | public static final int DORMANT = 4; 21 | /** Thing flag: Appears for fighter. */ 22 | public static final int FIGHTER = 5; 23 | /** Thing flag: Appears for cleric. */ 24 | public static final int CLERIC = 6; 25 | /** Thing flag: Appears for mage. */ 26 | public static final int MAGE = 7; 27 | /** Thing flag: Appears in Single Player. */ 28 | public static final int SINGLEPLAYER = 8; 29 | /** Thing flag: Appears in Cooperative. */ 30 | public static final int COOPERATIVE = 9; 31 | /** Thing flag: Appears in DeathMatch. */ 32 | public static final int DEATHMATCH = 10; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/flags/LinedefFlags.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data.flags; 9 | 10 | /** 11 | * Linedef flag constants. 12 | * The constant value is how many places to bit shift 1 to equal the flag bit. 13 | * @author Matthew Tropiano 14 | */ 15 | interface LinedefFlags 16 | { 17 | /** 18 | * Gets the bit value of the flag (shifted). 19 | * @param flag the input flag constant. 20 | * @return the resultant value. 21 | */ 22 | default int value(int flag) 23 | { 24 | return 1 << flag; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/flags/MBFThingFlags.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data.flags; 9 | 10 | /** 11 | * Thing flag constants for MBF/SMMU. 12 | * The constant value is how many places to bit shift 1 to equal the flag bit. 13 | * @author Matthew Tropiano 14 | */ 15 | public interface MBFThingFlags extends BoomThingFlags 16 | { 17 | /** Thing flag: Thing is friendly. */ 18 | public static final int FRIENDLY = 7; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/flags/StrifeLinedefFlags.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data.flags; 9 | 10 | /** 11 | * Linedef flag constants for Strife. 12 | * The constant value is how many places to bit shift 1 to equal the flag bit. 13 | * @author Matthew Tropiano 14 | */ 15 | public interface StrifeLinedefFlags extends DoomLinedefFlags 16 | { 17 | /** Linedef flag: Line is a jump-over railing. */ 18 | public static final int RAILING = 9; 19 | /** Linedef flag: Line blocks floating actors. */ 20 | public static final int BLOCK_FLOATERS = 10; 21 | /** 22 | * Linedef flag: Line is translucent. 23 | * @since 2.8.1 24 | */ 25 | public static final int TRANSLUCENT = 12; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/flags/StrifeThingFlags.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data.flags; 9 | 10 | /** 11 | * Thing flag constants for Strife things. 12 | * The constant value is how many places to bit shift 1 to equal the flag bit. 13 | * @author Matthew Tropiano 14 | */ 15 | public interface StrifeThingFlags extends ThingFlags 16 | { 17 | /** Thing flag: Thing starts in standing mode. */ 18 | public static final int STANDING = 3; 19 | /** Thing flag: Appears in multiplayer only. */ 20 | public static final int MULTIPLAYER = 4; 21 | /** Thing flag: Ambushes players. */ 22 | public static final int AMBUSH = 5; 23 | /** Thing flag: Thing starts friendly to players. */ 24 | public static final int ALLY = 6; 25 | /** Thing flag: Appears at 25% translucency. */ 26 | public static final int TRANSLUCENT_25 = 7; 27 | /** Thing flag: Is invisible. */ 28 | public static final int INVISIBLE = 8; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/flags/ThingFlags.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data.flags; 9 | 10 | /** 11 | * Thing flag constants. 12 | * The constant value is how many places to bit shift 1 to equal the flag bit. 13 | * @author Matthew Tropiano 14 | */ 15 | interface ThingFlags 16 | { 17 | /** Thing flag: Appears on easy difficulty. */ 18 | public static final int EASY = 0; 19 | /** Thing flag: Appears on medium difficulty. */ 20 | public static final int MEDIUM = 1; 21 | /** Thing flag: Appears on hard difficulty. */ 22 | public static final int HARD = 2; 23 | 24 | /** 25 | * Gets the bit value of the flag (shifted). 26 | * @param flag the input flag constant. 27 | * @return the resultant value. 28 | */ 29 | default int value(int flag) 30 | { 31 | return 1 << flag; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/flags/ZDoomLinedefFlags.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data.flags; 9 | 10 | /** 11 | * Linedef flag constants for ZDoom (Hexen format). 12 | * The constant value is how many places to bit shift 1 to equal the flag bit. 13 | * @author Matthew Tropiano 14 | */ 15 | public interface ZDoomLinedefFlags extends HexenLinedefFlags 16 | { 17 | /** Linedef flag: Special can be activated by players and monsters. */ 18 | public static final int ACTIVATED_BY_MONSTERS = 13; 19 | /** Linedef flag: Blocks players. */ 20 | public static final int BLOCK_PLAYERS = 14; 21 | /** Linedef flag: Blocks everything (like a one-sided line). */ 22 | public static final int BLOCK_EVERYTHING = 15; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/flags/ZDoomThingFlags.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data.flags; 9 | 10 | /** 11 | * Thing flag constants for ZDoom things. 12 | * The constant value is how many places to bit shift 1 to equal the flag bit. 13 | * @author Matthew Tropiano 14 | */ 15 | public interface ZDoomThingFlags extends HexenThingFlags 16 | { 17 | /** Thing flag: Thing starts in standing mode. */ 18 | public static final int STANDING = 11; 19 | /** Thing flag: Appears translucent. */ 20 | public static final int TRANSLUCENT = 12; 21 | /** Thing flag: Appears invisible. */ 22 | public static final int INVISIBLE = 13; 23 | /** Thing flag: Thing starts friendly to players. */ 24 | public static final int FRIENDLY = 14; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/flags/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains flag constant classes for binary-based map structures. 3 | */ 4 | package net.mtrop.doom.map.data.flags; -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/data/package-info.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Matt Tropiano 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Lesser Public License v2.1 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | /** 9 | * Map object implementations that are read from bytes. 10 | */ 11 | package net.mtrop.doom.map.data; 12 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/package-info.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Matt Tropiano 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Lesser Public License v2.1 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | /** Contains abstracts and implementations of map object types. */ 9 | package net.mtrop.doom.map; 10 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/UDMFParseException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf; 9 | 10 | /** 11 | * An exception thrown on UDMF parse errors. 12 | * @author Matthew Tropiano 13 | */ 14 | public class UDMFParseException extends RuntimeException 15 | { 16 | private static final long serialVersionUID = 1102498826055072221L; 17 | 18 | public UDMFParseException() 19 | { 20 | super(); 21 | } 22 | 23 | public UDMFParseException(String message) 24 | { 25 | super(message); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/UDMFParserListener.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf; 9 | 10 | /** 11 | * A listener for each new parsed entry or field that gets parsed in a UDMF structure. 12 | * @author Matthew Tropiano 13 | */ 14 | public interface UDMFParserListener 15 | { 16 | /** 17 | * Called when reading a UDMF document starts. 18 | */ 19 | void onStart(); 20 | 21 | /** 22 | * Called when reading a UDMF document ends. 23 | */ 24 | void onEnd(); 25 | 26 | /** 27 | * Called when an attribute is read from a UDMF structure. 28 | * @param name the name of the field. 29 | * @param value the parsed value. 30 | */ 31 | void onAttribute(String name, Object value); 32 | 33 | /** 34 | * Called when the start of an object is read from a UDMF structure. 35 | * @param name the name (type) of the structure. 36 | */ 37 | void onObjectStart(String name); 38 | 39 | /** 40 | * Called when an object is ended in a UDMF structure. 41 | * @param name the name (type) of the structure. 42 | */ 43 | void onObjectEnd(String name); 44 | 45 | /** 46 | * Called when a parsing error occurs. 47 | * @param error the error message. 48 | */ 49 | void onParseError(String error); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/UDMFReader.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf; 9 | 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.io.InputStreamReader; 13 | import java.io.Reader; 14 | import java.io.StringReader; 15 | 16 | import net.mtrop.doom.map.udmf.listener.UDMFFullTableListener; 17 | 18 | /** 19 | * A method for reading UDMF data, element by element, in a push-oriented way, 20 | * pushing events to a listener. Compare this to {@link UDMFScanner}, which is pull-oriented. 21 | * @author Matthew Tropiano 22 | */ 23 | public final class UDMFReader 24 | { 25 | /** 26 | * Reads UDMF-formatted data into a UDMFTable from an {@link InputStream}. 27 | * This will read until the end of the stream is reached. 28 | * Does not close the InputStream at the end of the read. 29 | * @param in the InputStream to read from. 30 | * @return a UDMFTable containing the structures. 31 | * @throws UDMFParseException if a parsing error occurs. 32 | * @throws IOException if the data can't be read. 33 | */ 34 | public static UDMFTable readData(InputStream in) throws IOException 35 | { 36 | return readData(new InputStreamReader(in, "UTF8")); 37 | } 38 | 39 | /** 40 | * Reads UDMF-formatted data into a UDMFTable from a String. 41 | * This will read until the end of the stream is reached. 42 | * @param data the String to read from. 43 | * @return a UDMFTable containing the structures. 44 | * @throws UDMFParseException if a parsing error occurs. 45 | * @throws IOException if the data can't be read. 46 | */ 47 | public static UDMFTable readData(String data) throws IOException 48 | { 49 | return readData(new StringReader(data)); 50 | } 51 | 52 | /** 53 | * Reads UDMF-formatted data into a UDMFTable from a {@link Reader}. 54 | * This will read until the end of the stream is reached. 55 | * Does not close the Reader at the end of the read. 56 | * @param reader the reader to read from. 57 | * @return a UDMFTable containing the parsed structures. 58 | * @throws UDMFParseException if a parsing error occurs. 59 | * @throws IOException if the data can't be read. 60 | */ 61 | public static UDMFTable readData(Reader reader) throws IOException 62 | { 63 | UDMFFullTableListener listener = new UDMFFullTableListener(); 64 | readData(reader, listener); 65 | String[] errors = listener.getErrorMessages(); 66 | if (errors.length > 0) 67 | { 68 | StringBuilder sb = new StringBuilder(); 69 | for (int i = 0; i < errors.length; i++) 70 | { 71 | sb.append(errors[i]); 72 | if (i < errors.length-1) 73 | sb.append('\n'); 74 | } 75 | throw new UDMFParseException(sb.toString()); 76 | } 77 | return listener.getTable(); 78 | } 79 | 80 | /** 81 | * Reads UDMF-formatted data into a UDMFTable from an {@link InputStream}. 82 | * This will read until the end of the stream is reached. 83 | * Does not close the InputStream at the end of the read. 84 | * @param in the InputStream to read from. 85 | * @param listener the listener to use for listening to parsed structure events. 86 | * @throws IOException if the data can't be read. 87 | */ 88 | public static void readData(InputStream in, UDMFParserListener listener) throws IOException 89 | { 90 | readData(new InputStreamReader(in, "UTF8"), listener); 91 | } 92 | 93 | /** 94 | * Reads UDMF-formatted data into a UDMFTable from a String. 95 | * This will read until the end of the stream is reached. 96 | * @param data the String to read from. 97 | * @param listener the listener to use for listening to parsed structure events. 98 | * @throws IOException if the data can't be read. 99 | */ 100 | public static void readData(String data, UDMFParserListener listener) throws IOException 101 | { 102 | readData(new StringReader(data), listener); 103 | } 104 | 105 | /** 106 | * Reads UDMF-formatted data into a UDMFTable from a {@link Reader}. 107 | * This will read until the end of the stream is reached. 108 | * Does not close the InputStream at the end of the read. 109 | * @param reader the reader to read from. 110 | * @param listener the listener to use for listening to parsed structure events. 111 | * @throws IOException if the data can't be read. 112 | */ 113 | public static void readData(Reader reader, UDMFParserListener listener) throws IOException 114 | { 115 | (new UDMFParser(reader)).readFull(listener); 116 | } 117 | 118 | private UDMFReader() {} 119 | 120 | } 121 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/UDMFTable.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf; 9 | 10 | import java.util.Deque; 11 | import java.util.Map; 12 | 13 | import net.mtrop.doom.struct.map.HashDequeMap; 14 | 15 | /** 16 | * This holds a bunch of {@link UDMFObject}s for reading Doom information. 17 | * Also contains a structure for "global" fields in the UDMF, like "namespace". 18 | * @author Matthew Tropiano 19 | */ 20 | public class UDMFTable 21 | { 22 | private static final UDMFObject[] EMPTY_OBJECT_LIST = new UDMFObject[0]; 23 | 24 | /** Root fields table. */ 25 | private UDMFObject globalFields; 26 | /** UDMF tables. */ 27 | private HashDequeMap innerTable; 28 | 29 | /** 30 | * Creates a new UDMFTable. 31 | */ 32 | public UDMFTable() 33 | { 34 | super(); 35 | this.globalFields = new UDMFObject(); 36 | this.innerTable = new HashDequeMap<>(); 37 | } 38 | 39 | /** 40 | * @return the root global fields structure. 41 | */ 42 | public UDMFObject getGlobalFields() 43 | { 44 | return globalFields; 45 | } 46 | 47 | /** 48 | * Returns all objects of a specific type into an array. 49 | * The names are case-insensitive. 50 | * @param name the name of the structures to retrieve. 51 | * @return the queue of structures with the matching name in the order that 52 | * they were added to the structure. If there are none, an empty array 53 | * is returned. 54 | */ 55 | public UDMFObject[] getObjects(String name) 56 | { 57 | Deque list = innerTable.get(name); 58 | if (list == null) 59 | return EMPTY_OBJECT_LIST; 60 | UDMFObject[] out = new UDMFObject[list.size()]; 61 | list.toArray(out); 62 | return out; 63 | } 64 | 65 | /** 66 | * Adds an object of a particular type to this table. 67 | * Keep in mind that the order in which these are added is important. 68 | * @param name the name of this type of structure. 69 | * @return a reference to the new structure created. 70 | */ 71 | public UDMFObject addObject(String name) 72 | { 73 | return addObject(name, new UDMFObject()); 74 | } 75 | 76 | /** 77 | * Adds an object of a particular type name to this table. 78 | * Keep in mind that the order in which these are added is important. 79 | * @param name the name of this type of structure. 80 | * @param object the object to add. 81 | * @return a reference to the added structure. 82 | */ 83 | public UDMFObject addObject(String name, UDMFObject object) 84 | { 85 | innerTable.add(name, object); 86 | return object; 87 | } 88 | 89 | /** 90 | * @return a list of all of the object type names in the table. 91 | */ 92 | public String[] getAllObjectNames() 93 | { 94 | String[] out = new String[innerTable.size()]; 95 | int i = 0; 96 | for (Map.Entry> entry : innerTable.entrySet()) 97 | out[i++] = entry.getKey(); 98 | return out; 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFCommonAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains common linedef attributes on some UDMF structures. 12 | * @author Matthew Tropiano 13 | */ 14 | interface UDMFCommonAttributes 15 | { 16 | /** Object comment. */ 17 | public static final String ATTRIB_COMMENT = "comment"; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFCommonLinedefAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains common linedef attributes on some UDMF structures. 12 | * @author Matthew Tropiano 13 | */ 14 | interface UDMFCommonLinedefAttributes extends UDMFCommonAttributes 15 | { 16 | /** Linedef flag: blocks creatures (players/monsters) a.k.a. "Impassable". */ 17 | public static final String ATTRIB_FLAG_BLOCKING = "blocking"; 18 | /** Linedef flag: blocks monsters. */ 19 | public static final String ATTRIB_FLAG_BLOCK_MONSTERS = "blockmonsters"; 20 | /** Linedef flag: two sided. */ 21 | public static final String ATTRIB_FLAG_TWO_SIDED = "twosided"; 22 | /** Linedef flag: top texture unpegged. */ 23 | public static final String ATTRIB_FLAG_UNPEG_TOP = "dontpegtop"; 24 | /** 25 | * Linedef flag: bottom texture unpegged. 26 | * @since 2.9.0, naming convention change. 27 | */ 28 | public static final String ATTRIB_FLAG_UNPEG_BOTTOM = "dontpegbottom"; 29 | /** Linedef flag: Secret (shows up as 1-sided, blocking on automap). */ 30 | public static final String ATTRIB_FLAG_SECRET = "secret"; 31 | /** Linedef flag: Block sound propagation. */ 32 | public static final String ATTRIB_FLAG_BLOCK_SOUND = "blocksound"; 33 | /** Linedef flag: Don't draw on automap. */ 34 | public static final String ATTRIB_FLAG_DONT_DRAW = "dontdraw"; 35 | /** Linedef flag: Already revealed on automap. */ 36 | public static final String ATTRIB_FLAG_MAPPED = "mapped"; 37 | 38 | /** Linedef id. */ 39 | public static final String ATTRIB_ID = "id"; 40 | /** Linedef Special type. */ 41 | public static final String ATTRIB_SPECIAL = "special"; 42 | /** Linedef first vertex. */ 43 | public static final String ATTRIB_VERTEX_START = "v1"; 44 | /** Linedef second vertex. */ 45 | public static final String ATTRIB_VERTEX_END = "v2"; 46 | /** Linedef Front Sidedef Reference. */ 47 | public static final String ATTRIB_SIDEDEF_FRONT = "sidefront"; 48 | /** Linedef Back Sidedef Reference. */ 49 | public static final String ATTRIB_SIDEDEF_BACK = "sideback"; 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFCommonSectorAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains common sector attributes on some UDMF structures. 12 | * @author Matthew Tropiano 13 | */ 14 | interface UDMFCommonSectorAttributes extends UDMFCommonAttributes 15 | { 16 | /** Sector floor height. */ 17 | public static final String ATTRIB_HEIGHT_FLOOR = "heightfloor"; 18 | /** Sector ceiling height. */ 19 | public static final String ATTRIB_HEIGHT_CEILING = "heightceiling"; 20 | /** Sector floor texture. */ 21 | public static final String ATTRIB_TEXTURE_FLOOR = "texturefloor"; 22 | /** Sector ceiling texture. */ 23 | public static final String ATTRIB_TEXTURE_CEILING = "textureceiling"; 24 | /** Sector light level. */ 25 | public static final String ATTRIB_LIGHT_LEVEL = "lightlevel"; 26 | /** Sector special. */ 27 | public static final String ATTRIB_SPECIAL = "special"; 28 | /** 29 | * Sector tag/id. 30 | * @since 2.9.0 31 | */ 32 | public static final String ATTRIB_ID = "id"; 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFCommonSidedefAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains common sidedef attributes on some UDMF structures. 12 | * @author Matthew Tropiano 13 | */ 14 | interface UDMFCommonSidedefAttributes extends UDMFCommonAttributes 15 | { 16 | /** Sidedef base texture offset X. */ 17 | public static final String ATTRIB_OFFSET_X = "offsetx"; 18 | /** Sidedef base texture offset Y. */ 19 | public static final String ATTRIB_OFFSET_Y = "offsety"; 20 | /** Sidedef top texture. */ 21 | public static final String ATTRIB_TEXTURE_TOP = "texturetop"; 22 | /** Sidedef bottom texture. */ 23 | public static final String ATTRIB_TEXTURE_BOTTOM = "texturebottom"; 24 | /** Sidedef middle texture. */ 25 | public static final String ATTRIB_TEXTURE_MIDDLE = "texturemiddle"; 26 | /** Sidedef sector reference. */ 27 | public static final String ATTRIB_SECTOR_INDEX = "sector"; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFCommonThingAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains common thing attributes on some UDMF structures. 12 | * @author Matthew Tropiano 13 | */ 14 | interface UDMFCommonThingAttributes extends UDMFCommonAttributes 15 | { 16 | /** Thing position: x-coordinate. */ 17 | public static final String ATTRIB_POSITION_X = "x"; 18 | /** Thing position: y-coordinate. */ 19 | public static final String ATTRIB_POSITION_Y = "y"; 20 | /** Thing angle in degrees. */ 21 | public static final String ATTRIB_ANGLE = "angle"; 22 | /** Thing type. */ 23 | public static final String ATTRIB_TYPE = "type"; 24 | 25 | /** Thing flag: Appears on skill 1. */ 26 | public static final String ATTRIB_FLAG_SKILL1 = "skill1"; 27 | /** Thing flag: Appears on skill 2. */ 28 | public static final String ATTRIB_FLAG_SKILL2 = "skill2"; 29 | /** Thing flag: Appears on skill 3. */ 30 | public static final String ATTRIB_FLAG_SKILL3 = "skill3"; 31 | /** Thing flag: Appears on skill 4. */ 32 | public static final String ATTRIB_FLAG_SKILL4 = "skill4"; 33 | /** Thing flag: Appears on skill 5. */ 34 | public static final String ATTRIB_FLAG_SKILL5 = "skill5"; 35 | /** Thing flag: Ambushes players ("deaf" flag). */ 36 | public static final String ATTRIB_FLAG_AMBUSH = "ambush"; 37 | /** Thing flag: Single player. */ 38 | public static final String ATTRIB_FLAG_SINGLE_PLAYER = "single"; 39 | /** Thing flag: Co-operative. */ 40 | public static final String ATTRIB_FLAG_COOPERATIVE = "coop"; 41 | /** Thing flag: Deathmatch. */ 42 | public static final String ATTRIB_FLAG_DEATHMATCH = "dm"; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFCommonVertexAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains common vertex attributes on some UDMF structures. 12 | * @author Matthew Tropiano 13 | */ 14 | interface UDMFCommonVertexAttributes extends UDMFCommonAttributes 15 | { 16 | /** Vertex position: x-coordinate. */ 17 | public static final String ATTRIB_POSITION_X = "x"; 18 | /** Vertex position: y-coordinate. */ 19 | public static final String ATTRIB_POSITION_Y = "y"; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFDoomLinedefAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains linedef attributes for Doom namespaces. 12 | * @author Matthew Tropiano 13 | */ 14 | public interface UDMFDoomLinedefAttributes extends UDMFCommonLinedefAttributes 15 | { 16 | /** Linedef flag: Linedef passes its activation through to another line. */ 17 | public static final String ATTRIB_FLAG_PASSTHRU = "passuse"; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFDoomSectorAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains sector attributes for Doom namespaces. 12 | * @author Matthew Tropiano 13 | * @since 2.9.0 14 | */ 15 | public interface UDMFDoomSectorAttributes extends UDMFCommonSectorAttributes 16 | { 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFDoomSidedefAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains sidedef attributes for Doom namespaces. 12 | * @author Matthew Tropiano 13 | * @since 2.9.0 14 | */ 15 | public interface UDMFDoomSidedefAttributes extends UDMFCommonSidedefAttributes 16 | { 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFDoomThingAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains thing attributes for Doom namespaces. 12 | * @author Matthew Tropiano 13 | * @since 2.9.0 14 | */ 15 | public interface UDMFDoomThingAttributes extends UDMFCommonThingAttributes 16 | { 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFDoomVertexAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains vertex attributes for Doom namespaces. 12 | * @author Matthew Tropiano 13 | * @since 2.9.0 14 | */ 15 | public interface UDMFDoomVertexAttributes extends UDMFCommonVertexAttributes 16 | { 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFGlobalAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains known global attributes. 12 | * @author Matthew Tropiano 13 | */ 14 | public interface UDMFGlobalAttributes 15 | { 16 | /** Global attribute: UDMF namespace. */ 17 | public static final String ATTRIB_NAMESPACE = "namespace"; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFHexenLinedefAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains linedef attributes for Hexen namespaces. 12 | * @author Matthew Tropiano 13 | * @since 2.8.0 14 | */ 15 | public interface UDMFHexenLinedefAttributes extends UDMFDoomLinedefAttributes 16 | { 17 | /** Linedef activation: Player Crosses. */ 18 | public static final String ATTRIB_ACTIVATE_PLAYER_CROSS = "playercross"; 19 | /** Linedef activation: Player Uses. */ 20 | public static final String ATTRIB_ACTIVATE_PLAYER_USE = "playeruse"; 21 | /** Linedef activation: Monster Crosses. */ 22 | public static final String ATTRIB_ACTIVATE_MONSTER_CROSS = "monstercross"; 23 | /** Linedef activation: Monster Crosses. */ 24 | public static final String ATTRIB_ACTIVATE_MONSTER_USE = "monsteruse"; 25 | /** Linedef activation: Projectile Impact. */ 26 | public static final String ATTRIB_ACTIVATE_IMPACT = "impact"; 27 | /** Linedef activation: Player Pushes (collide). */ 28 | public static final String ATTRIB_ACTIVATE_PLAYER_PUSH = "playerpush"; 29 | /** Linedef activation: Monster Pushes (collide). */ 30 | public static final String ATTRIB_ACTIVATE_MONSTER_PUSH = "monsterpush"; 31 | /** Linedef activation: Projectile Crosses. */ 32 | public static final String ATTRIB_ACTIVATE_PROJECTILE_CROSS = "missilecross"; 33 | 34 | /** Linedef flag: Special is repeatable. */ 35 | public static final String ATTRIB_FLAG_REPEATABLE = "repeatspecial"; 36 | 37 | /** Linedef special argument 0. */ 38 | public static final String ATTRIB_ARG0 = "arg0"; 39 | /** Linedef special argument 1. */ 40 | public static final String ATTRIB_ARG1 = "arg1"; 41 | /** Linedef special argument 2. */ 42 | public static final String ATTRIB_ARG2 = "arg2"; 43 | /** Linedef special argument 3. */ 44 | public static final String ATTRIB_ARG3 = "arg3"; 45 | /** Linedef special argument 4. */ 46 | public static final String ATTRIB_ARG4 = "arg4"; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFHexenThingAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains Hexen thing attributes on some UDMF structures. 12 | * @author Matthew Tropiano 13 | * @since 2.8.0 14 | */ 15 | public interface UDMFHexenThingAttributes extends UDMFDoomThingAttributes 16 | { 17 | /** Thing position: height. */ 18 | public static final String ATTRIB_HEIGHT = "height"; 19 | 20 | /** 21 | * Thing flag: Dormant. 22 | * @since 2.9.1 23 | */ 24 | public static final String ATTRIB_FLAG_DORMANT = "dormant"; 25 | /** Thing flag: Appears for class 1. */ 26 | public static final String ATTRIB_FLAG_CLASS1 = "class1"; 27 | /** Thing flag: Appears for class 2. */ 28 | public static final String ATTRIB_FLAG_CLASS2 = "class2"; 29 | /** Thing flag: Appears for class 3. */ 30 | public static final String ATTRIB_FLAG_CLASS3 = "class3"; 31 | 32 | /** 33 | * Thing id. 34 | * @since 2.8.1 35 | */ 36 | public static final String ATTRIB_ID = "id"; 37 | /** 38 | * Thing Special type. 39 | * @since 2.8.1 40 | */ 41 | public static final String ATTRIB_SPECIAL = "special"; 42 | 43 | /** 44 | * Thing special argument 0. 45 | * @since 2.8.1 46 | */ 47 | public static final String ATTRIB_ARG0 = "arg0"; 48 | /** 49 | * Thing special argument 1. 50 | * @since 2.8.1 51 | */ 52 | public static final String ATTRIB_ARG1 = "arg1"; 53 | /** 54 | * Thing special argument 2. 55 | * @since 2.8.1 56 | */ 57 | public static final String ATTRIB_ARG2 = "arg2"; 58 | /** 59 | * Thing special argument 3. 60 | * @since 2.8.1 61 | */ 62 | public static final String ATTRIB_ARG3 = "arg3"; 63 | /** 64 | * Thing special argument 4. 65 | * @since 2.8.1 66 | */ 67 | public static final String ATTRIB_ARG4 = "arg4"; 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFMBFThingAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains MBF thing attributes on some UDMF structures. 12 | * @author Matthew Tropiano 13 | * @since 2.8.0 14 | */ 15 | public interface UDMFMBFThingAttributes extends UDMFDoomThingAttributes 16 | { 17 | /** Thing flag: Friendly (Marine's Best Friend-style). */ 18 | public static final String ATTRIB_FLAG_FRIENDLY = "friend"; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFObjectTypes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains common UDMF structure type names. 12 | * @author Matthew Tropiano 13 | * @since 2.4.0 14 | */ 15 | public interface UDMFObjectTypes 16 | { 17 | /** Object type: Vertex. */ 18 | public static final String TYPE_VERTEX = "vertex"; 19 | /** Object type: Linedef. */ 20 | public static final String TYPE_LINEDEF = "linedef"; 21 | /** Object type: Vertex. */ 22 | public static final String TYPE_SIDEDEF = "sidedef"; 23 | /** Object type: Sector. */ 24 | public static final String TYPE_SECTOR = "sector"; 25 | /** Object type: Thing. */ 26 | public static final String TYPE_THING = "thing"; 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFStrifeLinedefAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains linedef attributes for Strife namespaces. 12 | * @author Matthew Tropiano 13 | */ 14 | public interface UDMFStrifeLinedefAttributes extends UDMFDoomLinedefAttributes 15 | { 16 | /** Linedef flag: Linedef is translucent (75% opaque). */ 17 | public static final String ATTRIB_FLAG_TRANSLUCENT = "translucent"; 18 | /** Linedef flag: Linedef is a railing that can be jumped over. */ 19 | public static final String ATTRIB_FLAG_JUMPOVER = "jumpover"; 20 | /** Linedef flag: Linedef blocks floating enemies. */ 21 | public static final String ATTRIB_FLAG_BLOCK_FLOAT = "blockfloaters"; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFStrifeThingAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains thing attributes for Strife namespaces. 12 | * @author Matthew Tropiano 13 | * @since 2.8.0 14 | */ 15 | public interface UDMFStrifeThingAttributes extends UDMFDoomThingAttributes 16 | { 17 | /** Thing flag: Thing is in a standing mode. */ 18 | public static final String ATTRIB_FLAG_STANDING = "standing"; 19 | /** Thing flag: Thing is an ally. */ 20 | public static final String ATTRIB_FLAG_ALLY = "strifeally"; 21 | /** Thing flag: Thing is translucent. */ 22 | public static final String ATTRIB_FLAG_TRANSLUCENT = "translucent"; 23 | /** Thing flag: Thing is invisible. */ 24 | public static final String ATTRIB_FLAG_INVISIBLE = "invisible"; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFZDoomLinedefAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains linedef attributes for ZDoom namespaces. 12 | * @author Matthew Tropiano 13 | */ 14 | public interface UDMFZDoomLinedefAttributes extends UDMFHexenLinedefAttributes, UDMFStrifeLinedefAttributes 15 | { 16 | /** Linedef activation: Anything Crosses. */ 17 | public static final String ATTRIB_ACTIVATE_ANY_CROSS = "anycross"; 18 | 19 | /** Linedef flag: Player can use the back of the linedef for specials. */ 20 | public static final String ATTRIB_FLAG_USEBACK = "playeruseback"; 21 | /** Linedef flag: Activates front-side only. */ 22 | public static final String ATTRIB_FLAG_FIRST_SIDE_ONLY = "firstsideonly"; 23 | /** Linedef flag: Blocks players. */ 24 | public static final String ATTRIB_FLAG_BLOCK_PLAYERS = "blockplayers"; 25 | /** Linedef flag: Blocks everything. */ 26 | public static final String ATTRIB_FLAG_BLOCK_EVERYTHING = "blockeverything"; 27 | /** Linedef flag: Blocks sound environment propagation. */ 28 | public static final String ATTRIB_FLAG_ZONE_BOUNDARY = "zoneboundary"; 29 | /** Linedef flag: Blocks projectiles. */ 30 | public static final String ATTRIB_FLAG_BLOCK_PROJECTILES = "blockprojectiles"; 31 | /** Linedef flag: Blocks line use. */ 32 | public static final String ATTRIB_FLAG_BLOCK_USE = "blockuse"; 33 | /** Linedef flag: Blocks monster sight. */ 34 | public static final String ATTRIB_FLAG_BLOCK_SIGHT = "blocksight"; 35 | /** Linedef flag: Blocks hitscan. */ 36 | public static final String ATTRIB_FLAG_BLOCK_HITSCAN = "blockhitscan"; 37 | /** Linedef flag: Clips the rendering of the middle texture. */ 38 | public static final String ATTRIB_FLAG_MIDTEX_CLIP = "clipmidtex"; 39 | /** Linedef flag: Wraps/tiles the rendering of the middle texture. */ 40 | public static final String ATTRIB_FLAG_MIDTEX_WRAP = "wrapmidtex"; 41 | /** Linedef flag: 3D middle texture collision. */ 42 | public static final String ATTRIB_FLAG_MIDTEX_3D = "midtex3d"; 43 | /** Linedef flag: 3D middle texture collision acts only blocks creatures. */ 44 | public static final String ATTRIB_FLAG_MIDTEX_3D_IMPASSABLE = "midtex3dimpassable"; 45 | /** Linedef flag: Switch activation checks activator height. */ 46 | public static final String ATTRIB_FLAG_CHECK_SWITCH_RANGE = "checkswitchrange"; 47 | /** Linedef flag: Strife Transparent (25% opaque) */ 48 | public static final String ATTRIB_TRANSPARENT = "transparent"; 49 | 50 | /** Linedef special argument 0, string type. */ 51 | public static final String ATTRIB_ARG0STR = "arg0str"; 52 | 53 | /** Linedef alpha component value. */ 54 | public static final String ATTRIB_ALPHA = "alpha"; 55 | /** Linedef rendering style. */ 56 | public static final String ATTRIB_RENDERSTYLE = "renderstyle"; 57 | /** Linedef special lock type. */ 58 | public static final String ATTRIB_LOCKNUMBER = "locknumber"; 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFZDoomSidedefAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains sidedef attributes for ZDoom namespaces. 12 | * @author Matthew Tropiano 13 | * @since 2.9.0 14 | */ 15 | public interface UDMFZDoomSidedefAttributes extends UDMFDoomSidedefAttributes 16 | { 17 | /** Sidedef flag: Relative sidedef light level is instead absolute. */ 18 | public static final String ATTRIB_FLAG_LIGHT_ABSOLUTE = "lightabsolute"; 19 | /** Sidedef flag: Use light level in fog. */ 20 | public static final String ATTRIB_FLAG_LIGHT_FOG = "lightfog"; 21 | /** Sidedef flag: Disable the "fake contrast" on angled walls. */ 22 | public static final String ATTRIB_FLAG_NO_FAKE_CONTRAST = "nofakecontrast"; 23 | /** Sidedef flag: Disable the "fake contrast" on angled walls. */ 24 | public static final String ATTRIB_FLAG_SMOOTH_LIGHTING = "smoothlighting"; 25 | /** Sidedef flag: This side's middle texture is clipped by the floor. */ 26 | public static final String ATTRIB_FLAG_CLIP_MIDTEX = "clipmidtex"; 27 | /** Sidedef flag: This side's middle texture is wrapped vertically if there is more to draw. */ 28 | public static final String ATTRIB_FLAG_WRAP_MIDTEX = "wrapmidtex"; 29 | /** Sidedef flag: Disable decals on this wall. */ 30 | public static final String ATTRIB_FLAG_NO_DECALS = "nodecals"; 31 | 32 | /** Sidedef upper texture scaling, X. */ 33 | public static final String ATTRIB_SCALE_TOP_X = "scalex_top"; 34 | /** Sidedef upper texture scaling, Y. */ 35 | public static final String ATTRIB_SCALE_TOP_Y = "scaley_top"; 36 | /** Sidedef middle texture scaling, X. */ 37 | public static final String ATTRIB_SCALE_MIDDLE_X = "scalex_mid"; 38 | /** Sidedef middle texture scaling, Y. */ 39 | public static final String ATTRIB_SCALE_MIDDLE_Y = "scaley_mid"; 40 | /** Sidedef bottom texture scaling, X. */ 41 | public static final String ATTRIB_SCALE_BOTTOM_X = "scalex_bottom"; 42 | /** Sidedef bottom texture scaling, Y. */ 43 | public static final String ATTRIB_SCALE_BOTTOM_Y = "scaley_bottom"; 44 | 45 | /** Sidedef upper texture offset, X. */ 46 | public static final String ATTRIB_OFFSET_TOP_X = "offsetx_top"; 47 | /** Sidedef upper texture offset, Y. */ 48 | public static final String ATTRIB_OFFSET_TOP_Y = "offsety_top"; 49 | /** Sidedef middle texture offset, X. */ 50 | public static final String ATTRIB_OFFSET_MIDDLE_X = "offsetx_mid"; 51 | /** Sidedef middle texture offset, Y. */ 52 | public static final String ATTRIB_OFFSET_MIDDLE_Y = "offsety_mid"; 53 | /** Sidedef bottom texture offset, X. */ 54 | public static final String ATTRIB_OFFSET_BOTTOM_X = "offsetx_bottom"; 55 | /** Sidedef bottom texture offset, Y. */ 56 | public static final String ATTRIB_OFFSET_BOTTOM_Y = "offsety_bottom"; 57 | 58 | /** Sidedef relative light level. */ 59 | public static final String ATTRIB_LIGHT = "light"; 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFZDoomThingAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains thing attributes for ZDoom namespaces. 12 | * @author Matthew Tropiano 13 | * @since 2.9.0 14 | */ 15 | public interface UDMFZDoomThingAttributes extends UDMFHexenThingAttributes 16 | { 17 | /** Thing flag: Appears on skill 6. */ 18 | public static final String ATTRIB_FLAG_SKILL6 = "skill6"; 19 | /** Thing flag: Appears on skill 7. */ 20 | public static final String ATTRIB_FLAG_SKILL7 = "skill7"; 21 | /** Thing flag: Appears on skill 8. */ 22 | public static final String ATTRIB_FLAG_SKILL8 = "skill8"; 23 | /** Thing flag: Appears on skill 9. */ 24 | public static final String ATTRIB_FLAG_SKILL9 = "skill9"; 25 | /** Thing flag: Appears on skill 10. */ 26 | public static final String ATTRIB_FLAG_SKILL10 = "skill10"; 27 | /** Thing flag: Appears on skill 11. */ 28 | public static final String ATTRIB_FLAG_SKILL11 = "skill11"; 29 | /** Thing flag: Appears on skill 12. */ 30 | public static final String ATTRIB_FLAG_SKILL12 = "skill12"; 31 | /** Thing flag: Appears on skill 13. */ 32 | public static final String ATTRIB_FLAG_SKILL13 = "skill13"; 33 | /** Thing flag: Appears on skill 14. */ 34 | public static final String ATTRIB_FLAG_SKILL14 = "skill14"; 35 | /** Thing flag: Appears on skill 15. */ 36 | public static final String ATTRIB_FLAG_SKILL15 = "skill15"; 37 | /** Thing flag: Appears on skill 16. */ 38 | public static final String ATTRIB_FLAG_SKILL16 = "skill16"; 39 | 40 | /** Thing flag: Appears for class 4. */ 41 | public static final String ATTRIB_FLAG_CLASS4 = "skill4"; 42 | /** Thing flag: Appears for class 5. */ 43 | public static final String ATTRIB_FLAG_CLASS5 = "skill5"; 44 | /** Thing flag: Appears for class 6. */ 45 | public static final String ATTRIB_FLAG_CLASS6 = "skill6"; 46 | /** Thing flag: Appears for class 7. */ 47 | public static final String ATTRIB_FLAG_CLASS7 = "skill7"; 48 | /** Thing flag: Appears for class 8. */ 49 | public static final String ATTRIB_FLAG_CLASS8 = "skill8"; 50 | /** Thing flag: Appears for class 9. */ 51 | public static final String ATTRIB_FLAG_CLASS9 = "skill9"; 52 | /** Thing flag: Appears for class 10. */ 53 | public static final String ATTRIB_FLAG_CLASS10 = "skill10"; 54 | /** Thing flag: Appears for class 11. */ 55 | public static final String ATTRIB_FLAG_CLASS11 = "skill11"; 56 | /** Thing flag: Appears for class 12. */ 57 | public static final String ATTRIB_FLAG_CLASS12 = "skill12"; 58 | /** Thing flag: Appears for class 13. */ 59 | public static final String ATTRIB_FLAG_CLASS13 = "skill13"; 60 | /** Thing flag: Appears for class 14. */ 61 | public static final String ATTRIB_FLAG_CLASS14 = "skill14"; 62 | /** Thing flag: Appears for class 15. */ 63 | public static final String ATTRIB_FLAG_CLASS15 = "skill15"; 64 | /** Thing flag: Appears for class 16. */ 65 | public static final String ATTRIB_FLAG_CLASS16 = "skill16"; 66 | /** Thing flag: Count as secret. */ 67 | public static final String ATTRIB_FLAG_SECRET = "countsecret"; 68 | 69 | /** Thing uses a Conversation ID. */ 70 | public static final String ATTRIB_CONVERSATION = "conversation"; 71 | 72 | /** Thing special argument 0, string type. */ 73 | public static final String ATTRIB_ARG0STR = "arg0str"; 74 | 75 | /** Thing gravity scalar. */ 76 | public static final String ATTRIB_GRAVITY = "gravity"; 77 | /** Thing health (multiplicative). */ 78 | public static final String ATTRIB_HEALTH = "health"; 79 | /** Thing renderstyle. */ 80 | public static final String ATTRIB_RENDERSTYLE = "renderstyle"; 81 | /** Thing fill color for stencil renderstyle. */ 82 | public static final String ATTRIB_FILLCOLOR = "fillcolor"; 83 | /** Thing alpha component scalar for supported renderstyles. */ 84 | public static final String ATTRIB_ALPHA = "alpha"; 85 | /** Thing score value. */ 86 | public static final String ATTRIB_SCORE = "score"; 87 | /** Thing pitch (in degrees). */ 88 | public static final String ATTRIB_PITCH = "pitch"; 89 | /** Thing roll (in degrees). */ 90 | public static final String ATTRIB_ROLL = "roll"; 91 | /** Thing size scalar (both axes). */ 92 | public static final String ATTRIB_SCALE = "scale"; 93 | /** Thing size scalar, X. */ 94 | public static final String ATTRIB_SCALE_X = "scalex"; 95 | /** Thing size scalar, Y. */ 96 | public static final String ATTRIB_SCALE_Y = "scaley"; 97 | /** Thing float bob phase offset (for bobbing things). */ 98 | public static final String ATTRIB_PHASE_FLOATBOB = "floatbobphase"; 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/UDMFZDoomVertexAttributes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.attributes; 9 | 10 | /** 11 | * Contains vertex attributes for ZDoom namespaces. 12 | * @author Matthew Tropiano 13 | */ 14 | public interface UDMFZDoomVertexAttributes extends UDMFDoomVertexAttributes 15 | { 16 | /** Vertex Z position (floor height). */ 17 | public static final String ATTRIB_POSITION_Z_FLOOR = "zfloor"; 18 | /** Vertex Z position (ceiling height). */ 19 | public static final String ATTRIB_POSITION_Z_CEILING = "zceiling"; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/attributes/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains interfaces for common UDMF namespace attributes. 3 | */ 4 | package net.mtrop.doom.map.udmf.attributes; -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/listener/UDMFFullTableListener.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.listener; 9 | 10 | import java.util.LinkedList; 11 | 12 | import net.mtrop.doom.map.udmf.UDMFObject; 13 | import net.mtrop.doom.map.udmf.UDMFParserListener; 14 | import net.mtrop.doom.map.udmf.UDMFTable; 15 | 16 | /** 17 | * A parser listener that generates full UDMF tables. 18 | * Can be fairly memory-intensive. Can be re-used. 19 | * @author Matthew Tropiano 20 | */ 21 | public class UDMFFullTableListener implements UDMFParserListener 22 | { 23 | /** Struct table. */ 24 | private UDMFTable table; 25 | /** Struct stack. */ 26 | private LinkedList stack; 27 | /** Error list. */ 28 | private LinkedList errors; 29 | 30 | @Override 31 | public void onStart() 32 | { 33 | this.table = new UDMFTable(); 34 | this.stack = new LinkedList<>(); 35 | this.stack.push(table.getGlobalFields()); 36 | this.errors = new LinkedList<>(); 37 | } 38 | 39 | /** 40 | * @return the parsed table. 41 | */ 42 | public UDMFTable getTable() 43 | { 44 | return table; 45 | } 46 | 47 | /** 48 | * @return the list of error messages during parse. 49 | */ 50 | public String[] getErrorMessages() 51 | { 52 | String[] out = new String[errors.size()]; 53 | errors.toArray(out); 54 | return out; 55 | } 56 | 57 | @Override 58 | public void onObjectStart(String name) 59 | { 60 | stack.push(table.addObject(name)); 61 | } 62 | 63 | @Override 64 | public void onObjectEnd(String name) 65 | { 66 | stack.pop(); 67 | } 68 | 69 | @Override 70 | public void onAttribute(String name, Object value) 71 | { 72 | stack.peek().set(name, value); 73 | } 74 | 75 | @Override 76 | public void onParseError(String error) 77 | { 78 | errors.add(error); 79 | } 80 | 81 | @Override 82 | public void onEnd() 83 | { 84 | stack.pop(); 85 | } 86 | 87 | }; 88 | 89 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/listener/UDMFInlineTypeListener.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.listener; 9 | 10 | import net.mtrop.doom.map.udmf.UDMFObject; 11 | import net.mtrop.doom.map.udmf.UDMFParserListener; 12 | 13 | /** 14 | * A parser listener that listens for specific structure/object types, however, 15 | * unlike {@link UDMFTypeListener}, this reuses the same UDMFObject per read. 16 | * Do not store the reference to the read object anywhere because the next read will overwrite its contents! 17 | * @author Matthew Tropiano 18 | */ 19 | public abstract class UDMFInlineTypeListener implements UDMFParserListener 20 | { 21 | /** Current object being read. */ 22 | private UDMFObject current; 23 | 24 | @Override 25 | public void onStart() 26 | { 27 | this.current = null; 28 | } 29 | 30 | @Override 31 | public void onEnd() 32 | { 33 | this.current = null; 34 | } 35 | 36 | @Override 37 | public void onAttribute(String name, Object value) 38 | { 39 | if (current != null) 40 | current.set(name, value); 41 | else 42 | onGlobalAttribute(name, value); 43 | } 44 | 45 | @Override 46 | public void onObjectStart(String name) 47 | { 48 | if (current == null) 49 | current = new UDMFObject(); 50 | else 51 | current.clear(); 52 | } 53 | 54 | @Override 55 | public void onObjectEnd(String name) 56 | { 57 | onType(name, current); 58 | } 59 | 60 | @Override 61 | public abstract void onParseError(String error); 62 | 63 | /** 64 | * Called when a global attribute is encountered. 65 | * @param name the name of the attribute. 66 | * @param value the parsed value. 67 | */ 68 | public abstract void onGlobalAttribute(String name, Object value); 69 | 70 | /** 71 | * Called when the parser has finished reading an object. 72 | * @param type the object type. 73 | * @param object the object itself. 74 | */ 75 | public abstract void onType(String type, UDMFObject object); 76 | 77 | } 78 | 79 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/listener/UDMFTypeListener.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf.listener; 9 | 10 | import net.mtrop.doom.map.udmf.UDMFObject; 11 | import net.mtrop.doom.map.udmf.UDMFParserListener; 12 | 13 | /** 14 | * A parser listener that listens for specific structure/object types. 15 | * @author Matthew Tropiano 16 | */ 17 | public abstract class UDMFTypeListener implements UDMFParserListener 18 | { 19 | /** Current object being read. */ 20 | private UDMFObject current; 21 | 22 | @Override 23 | public void onStart() 24 | { 25 | this.current = null; 26 | } 27 | 28 | @Override 29 | public void onEnd() 30 | { 31 | this.current = null; 32 | } 33 | 34 | @Override 35 | public void onAttribute(String name, Object value) 36 | { 37 | if (current != null) 38 | current.set(name, value); 39 | else 40 | onGlobalAttribute(name, value); 41 | } 42 | 43 | @Override 44 | public void onObjectStart(String name) 45 | { 46 | current = new UDMFObject(); 47 | } 48 | 49 | @Override 50 | public void onObjectEnd(String name) 51 | { 52 | onType(name, current); 53 | current = null; 54 | } 55 | 56 | @Override 57 | public abstract void onParseError(String error); 58 | 59 | /** 60 | * Called when a global attribute is encountered. 61 | * @param name the name of the attribute. 62 | * @param value the parsed value. 63 | */ 64 | public abstract void onGlobalAttribute(String name, Object value); 65 | 66 | /** 67 | * Called when the parser has finished reading an object. 68 | * @param type the object type. 69 | * @param object the object itself. 70 | */ 71 | public abstract void onType(String type, UDMFObject object); 72 | 73 | } 74 | 75 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/listener/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains UDMF listeners. 3 | */ 4 | package net.mtrop.doom.map.udmf.listener; -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/map/udmf/package-info.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Matt Tropiano 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Lesser Public License v2.1 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | /** 9 | * Map object implementations that are read from UDMF. 10 | */ 11 | package net.mtrop.doom.map.udmf; 12 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/object/GraphicObject.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.object; 9 | 10 | import net.mtrop.doom.graphics.Flat; 11 | import net.mtrop.doom.graphics.Picture; 12 | 13 | /** 14 | * Interface for graphic data. 15 | * @author Matthew Tropiano 16 | */ 17 | public interface GraphicObject 18 | { 19 | 20 | /** 21 | * @return the offset from the center, horizontally, in pixels. 22 | */ 23 | public int getOffsetX(); 24 | 25 | /** 26 | * @return the offset from the center, vertically, in pixels. 27 | */ 28 | public int getOffsetY(); 29 | 30 | /** 31 | * @return the width of this graphic in pixels. 32 | */ 33 | public int getWidth(); 34 | 35 | /** 36 | * @return the height of this graphic in pixels. 37 | */ 38 | public int getHeight(); 39 | 40 | /** 41 | * Gets the pixel data at a location in the graphic. 42 | *

If this graphic is an indexed color graphic (i.e. {@link Flat} or {@link Picture}), this 43 | * will return a palette index value from 0 to 255, or {@link Picture#PIXEL_TRANSLUCENT} if this graphic has translucent pixels. 44 | *

For full-color graphics, this returns an ARGB integer value representing the pixel color in RGB space (with Alpha). 45 | * @param x graphic x-coordinate. 46 | * @param y graphic y-coordinate. 47 | * @return a palette index value from 0 to 255, {@link Picture#PIXEL_TRANSLUCENT} if translucent, or an ARGB value. 48 | * @throws ArrayIndexOutOfBoundsException if the provided coordinates is outside the graphic. 49 | */ 50 | public int getPixel(int x, int y); 51 | 52 | /** 53 | * Sets the pixel data at a location in the graphic. 54 | *

For indexed color graphics, valid values are in the range of -1 to 255, 55 | * with 0 to 254 being palette indexes and {@link Picture#PIXEL_TRANSLUCENT} / 255 being translucent pixels (if supported). 56 | *

For full-color graphics, the value is an ARGB integer value representing the pixel color in RGB space (with Alpha). 57 | * @param x picture x-coordinate. 58 | * @param y picture y-coordinate. 59 | * @param value the value to set. 60 | * @throws IllegalArgumentException if the value is outside a valid range. 61 | * @throws ArrayIndexOutOfBoundsException if the provided coordinates is outside the graphic. 62 | */ 63 | public void setPixel(int x, int y, int value); 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/object/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains object interfaces for most data. 3 | */ 4 | package net.mtrop.doom.object; -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/package-info.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Matt Tropiano 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Lesser Public License v2.1 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | /** Contains the base structural abstracts for this library. */ 9 | package net.mtrop.doom; 10 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/sound/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains classes relevant to sound information. 3 | */ 4 | package net.mtrop.doom.sound; -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/struct/Sizable.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.struct; 9 | 10 | /** 11 | * Describes a class that contains an amount of discrete objects. 12 | * @author Matthew Tropiano 13 | */ 14 | public interface Sizable 15 | { 16 | /** 17 | * @return the amount of individual objects that this object contains. 18 | */ 19 | public int size(); 20 | 21 | /** 22 | * Returns if this object contains no objects. 23 | * The general policy of this method is that this returns true if 24 | * and only if {@link #size()} returns 0. 25 | * @return true if so, false otherwise. 26 | */ 27 | public boolean isEmpty(); 28 | 29 | } -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/struct/io/CRC32.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.struct.io; 9 | 10 | /** 11 | * This is an implementation of the CRC32 algorithm, 12 | * used for CRC checksumming of byte arrays and streams. 13 | * @author Matthew Tropiano 14 | */ 15 | public class CRC32 16 | { 17 | /** Default often-used CRC polynomial. */ 18 | public static final int POLYNOMIAL_DEFAULT = 0x04C11DB7; 19 | /** Known polynomials: IEEE CRC polynomial (used in Ethernet and PNG and a bunch of other things). */ 20 | public static final int POLYNOMIAL_IEEE = 0xEDB88320; 21 | /** Known polynomials: Castagnioli (iSCSI). */ 22 | public static final int POLYNOMIAL_CASTAGNIOLI = 0x82F63B78; 23 | /** Known polynomials: Koopman. */ 24 | public static final int POLYNOMIAL_KOOPMAN = 0xEB31D82E; 25 | 26 | /** The CRC polynomial used. */ 27 | private int polynomial; 28 | /** The cached array for CRC32 calculation. */ 29 | private int[] crcCache; 30 | 31 | /** 32 | * Creates a new CRC32 calculator using the POLYNOMIAL_DEFAULT CRC32 polynomial. 33 | */ 34 | public CRC32() 35 | { 36 | this(POLYNOMIAL_DEFAULT); 37 | } 38 | 39 | /** 40 | * Creates a new CRC32 calculator using a 41 | * specific CRC32 polynomial. 42 | * @param polynomial the polynomial to use. 43 | */ 44 | public CRC32(int polynomial) 45 | { 46 | this.polynomial = polynomial; 47 | crcCache = new int[256]; 48 | int c; 49 | 50 | for (int n = 0; n < 256; n++) 51 | { 52 | c = n; 53 | for (int k = 0; k < 8; k++) 54 | { 55 | if ((c & 1) == 1) 56 | c = polynomial ^ (c >>> 1); 57 | else 58 | c >>>= 1; 59 | } 60 | crcCache[n] = c; 61 | } 62 | } 63 | 64 | /** 65 | * Generates a CRC32 checksum for a set of bytes. 66 | * This will generate a checksum for all of the bytes in the array. 67 | * @param startCRC the starting checksum value. 68 | * @param buf the bytes to generate the checksum for. 69 | * @return a CRC32 checksum of the desired bytes. 70 | */ 71 | public int createCRC32(int startCRC, byte[] buf) 72 | { 73 | return createCRC32(startCRC, buf, buf.length); 74 | } 75 | 76 | /** 77 | * Generates a CRC32 checksum for a set of bytes. 78 | * Uses a starting checksum value of -1 (0xffffffff). 79 | * This will generate a checksum for all of the bytes in the array. 80 | * @param buf the bytes to generate the checksum for. 81 | * @return a CRC32 checksum of the desired bytes. 82 | */ 83 | public int createCRC32(byte[] buf) 84 | { 85 | return createCRC32(buf, buf.length); 86 | } 87 | 88 | /** 89 | * Generates a CRC32 checksum for a set of bytes. 90 | * Uses a starting checksum value of -1 (0xffffffff). 91 | * @param buf the bytes to generate the checksum for. 92 | * @param len the amount of bytes in the array to use. 93 | * @return a CRC32 checksum of the desired bytes. 94 | */ 95 | public int createCRC32(byte[] buf, int len) 96 | { 97 | return createCRC32(0xffffffff, buf, buf.length); 98 | } 99 | 100 | /** 101 | * Generates a CRC32 checksum for a set of bytes. 102 | * @param startCRC the starting checksum value. 103 | * @param buf the bytes to generate the checksum for. 104 | * @param len the amount of bytes in the array to use. 105 | * @return a CRC32 checksum of the desired bytes. 106 | */ 107 | public int createCRC32(int startCRC, byte[] buf, int len) 108 | { 109 | return ~updateCRC(startCRC, buf, len); 110 | } 111 | 112 | // CRC adding function. 113 | private int updateCRC(int crc, byte[] buf, int len) 114 | { 115 | int c = crc; 116 | for (int n = 0; n < len; n++) 117 | c = (c >>> 8) ^ crcCache[(buf[n] & 0x0FF) ^ (c & 0x000000FF)]; 118 | return c; 119 | } 120 | 121 | /** 122 | * @return the polynomial used for this CRC object. 123 | */ 124 | public int getPolynomial() 125 | { 126 | return polynomial; 127 | } 128 | 129 | 130 | } -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/struct/io/IOUtils.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.struct.io; 9 | 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.io.OutputStream; 13 | 14 | /** 15 | * I/O utils. 16 | * @author Matthew Tropiano 17 | */ 18 | public final class IOUtils 19 | { 20 | /** The relay buffer used by relay(). */ 21 | private static final ThreadLocal RELAY_BUFFER = ThreadLocal.withInitial(()->new byte[8192]); 22 | 23 | private IOUtils() {} 24 | 25 | /** 26 | * Reads from an input stream, reading in a consistent set of data 27 | * and writing it to the output stream. The read/write is buffered 28 | * so that it does not bog down the OS's other I/O requests. 29 | * This method finishes when the end of the source stream is reached. 30 | * Note that this may block if the input stream is a type of stream 31 | * that will block if the input stream blocks for additional input. 32 | * This method is thread-safe. 33 | * @param in the input stream to grab data from. 34 | * @param out the output stream to write the data to. 35 | * @return the total amount of bytes relayed. 36 | * @throws IOException if a read or write error occurs. 37 | */ 38 | public static int relay(InputStream in, OutputStream out) throws IOException 39 | { 40 | return relay(in, out, -1); 41 | } 42 | 43 | /** 44 | * Reads from an input stream, reading in a consistent set of data 45 | * and writing it to the output stream. The read/write is buffered 46 | * so that it does not bog down the OS's other I/O requests. 47 | * This method finishes when the end of the source stream is reached. 48 | * Note that this may block if the input stream is a type of stream 49 | * that will block if the input stream blocks for additional input. 50 | * This method is thread-safe. 51 | * @param in the input stream to grab data from. 52 | * @param out the output stream to write the data to. 53 | * @param maxLength the maximum amount of bytes to relay, or a value < 0 for no max. 54 | * @return the total amount of bytes relayed. 55 | * @throws IOException if a read or write error occurs. 56 | */ 57 | public static int relay(InputStream in, OutputStream out, int maxLength) throws IOException 58 | { 59 | int total = 0; 60 | int buf = 0; 61 | 62 | byte[] BUFFER = RELAY_BUFFER.get(); 63 | 64 | while ((buf = in.read(BUFFER, 0, Math.min(maxLength < 0 ? Integer.MAX_VALUE : maxLength, BUFFER.length))) > 0) 65 | { 66 | out.write(BUFFER, 0, buf); 67 | total += buf; 68 | if (maxLength >= 0) 69 | maxLength -= buf; 70 | } 71 | return total; 72 | } 73 | 74 | /** 75 | * Attempts to close an {@link AutoCloseable} object. 76 | * If the object is null, this does nothing. 77 | * @param c the reference to the AutoCloseable object. 78 | */ 79 | public static void close(AutoCloseable c) 80 | { 81 | if (c == null) return; 82 | try { c.close(); } catch (Exception e){} 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/struct/io/PNGContainerReader.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.struct.io; 9 | 10 | import java.io.File; 11 | import java.io.FileInputStream; 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.util.Arrays; 15 | 16 | public class PNGContainerReader implements AutoCloseable 17 | { 18 | /** PNG Header. */ 19 | private static final byte[] PNG_HEADER = { 20 | (byte)0x089, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A 21 | }; 22 | 23 | private InputStream in; 24 | 25 | /** 26 | * Creates a new PNG container reader from a file. 27 | * @param f the file to read. 28 | * @throws IOException if a read error occurs or this is not a PNG file. 29 | */ 30 | public PNGContainerReader(File f) throws IOException 31 | { 32 | this(new FileInputStream(f)); 33 | } 34 | 35 | /** 36 | * Creates a new PNG container reader using an input stream. 37 | * @param i the input stream to read. 38 | * @throws IOException if a read error occurs or this is not PNG data. 39 | */ 40 | public PNGContainerReader(InputStream i) throws IOException 41 | { 42 | this.in = i; 43 | if (!Arrays.equals(PNG_HEADER, (new SerialReader(SerialReader.BIG_ENDIAN)).readBytes(in, 8))) 44 | throw new IOException("Not a PNG file. Header may be corrupt."); 45 | } 46 | 47 | /** 48 | * Reads the next chunk in this container stream. 49 | * @return a new chunk. 50 | * @throws IOException on a read error. 51 | */ 52 | public Chunk nextChunk() throws IOException 53 | { 54 | Chunk chunk = null; 55 | try {chunk = new Chunk(in);} catch (IOException e) {} 56 | return chunk; 57 | } 58 | 59 | @Override 60 | public void close() throws IOException 61 | { 62 | in.close(); 63 | } 64 | 65 | /** 66 | * PNG Chunk data. 67 | */ 68 | public static class Chunk 69 | { 70 | /** Chunk name. */ 71 | private String name; 72 | /** CRC number. */ 73 | private int crcNumber; 74 | /** Data. */ 75 | private byte[] data; 76 | 77 | Chunk(InputStream in) throws IOException 78 | { 79 | SerialReader sr = new SerialReader(SerialReader.BIG_ENDIAN); 80 | int len = sr.readInt(in); 81 | name = sr.readString(in, 4, "ASCII").trim(); 82 | data = sr.readBytes(in, len); 83 | crcNumber = sr.readInt(in); 84 | } 85 | 86 | /** 87 | * @return this chunk's identifier. 88 | */ 89 | public String getName() 90 | { 91 | return name; 92 | } 93 | 94 | /** 95 | * @return this chunk's CRC value. 96 | */ 97 | public int getCRCNumber() 98 | { 99 | return crcNumber; 100 | } 101 | 102 | /** 103 | * @return the data in this chunk. 104 | */ 105 | public byte[] getData() 106 | { 107 | return data; 108 | } 109 | 110 | @Override 111 | public String toString() 112 | { 113 | return name + " Length: " + data.length + " CRC: " + String.format("%08x", crcNumber); 114 | } 115 | 116 | /** 117 | * @return true if this chunk is not a part of the required image chunks. 118 | */ 119 | public boolean isAncillary() 120 | { 121 | return Character.isLowerCase(name.charAt(0)); 122 | } 123 | 124 | /** 125 | * @return true if this chunk is part of a non-public specification. 126 | */ 127 | public boolean isPrivate() 128 | { 129 | return Character.isLowerCase(name.charAt(1)); 130 | } 131 | 132 | /** 133 | * @return true if this chunk is this chunk has the reserved bit set. 134 | */ 135 | public boolean isReserved() 136 | { 137 | return Character.isLowerCase(name.charAt(2)); 138 | } 139 | 140 | /** 141 | * @return true if this chunk is safe to blindly copy, requiring no 142 | * other chunks and contains no image-centric data. 143 | */ 144 | public boolean isSafeToCopy() 145 | { 146 | return Character.isLowerCase(name.charAt(3)); 147 | } 148 | } 149 | 150 | } -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/struct/io/PNGContainerWriter.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.struct.io; 9 | 10 | import java.io.ByteArrayOutputStream; 11 | import java.io.File; 12 | import java.io.FileNotFoundException; 13 | import java.io.FileOutputStream; 14 | import java.io.IOException; 15 | import java.io.OutputStream; 16 | 17 | public class PNGContainerWriter implements AutoCloseable 18 | { 19 | /** PNG Header. */ 20 | private static final byte[] PNG_HEADER = { 21 | (byte)0x089, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A 22 | }; 23 | 24 | /** PNG CRC32 generator. */ 25 | private static final CRC32 PNG_CRC = new CRC32(CRC32.POLYNOMIAL_IEEE); 26 | 27 | /** Did we write the header, yet? */ 28 | private OutputStream out; 29 | /** Did we write the header, yet? */ 30 | private boolean wroteHeader; 31 | 32 | /** 33 | * Creates a new PNG container writer using a file to write to. 34 | * @param f the file to read. 35 | * @throws FileNotFoundException if the file to be created is an existing directory. 36 | * @throws SecurityException if the file cannot be created. 37 | */ 38 | public PNGContainerWriter(File f) throws FileNotFoundException 39 | { 40 | this(new FileOutputStream(f)); 41 | } 42 | 43 | /** 44 | * Creates a new PNG container writer using an input stream. 45 | * @param out the output stream to write to. 46 | */ 47 | public PNGContainerWriter(OutputStream out) 48 | { 49 | this.out = out; 50 | } 51 | 52 | /** 53 | * Writes the next chunk in this container stream. 54 | * @param name the name of the chunk. Must be length 4 (excluding whitespace), 55 | * and follow the guidelines for naming necessary/private/etc. chunks. 56 | * @param data the data to write. 57 | * @throws IOException if the write could not occur. 58 | */ 59 | public void writeChunk(String name, byte[] data) throws IOException 60 | { 61 | if (name.trim().length() != 4) 62 | throw new IllegalArgumentException("Name must be 4 alphabetical characters long."); 63 | 64 | if (!wroteHeader) 65 | { 66 | (new SerialWriter(SerialWriter.BIG_ENDIAN)).writeBytes(out, PNG_HEADER); 67 | wroteHeader = true; 68 | } 69 | 70 | SerialWriter sw = new SerialWriter(SerialWriter.BIG_ENDIAN); 71 | 72 | sw.writeInt(out, data.length); 73 | 74 | ByteArrayOutputStream baout = new ByteArrayOutputStream(); 75 | sw.writeBytes(baout, name.getBytes("ASCII")); 76 | sw.writeBytes(baout, data); 77 | 78 | byte[] bytes = baout.toByteArray(); 79 | sw.writeBytes(out, bytes); 80 | sw.writeInt(out, PNG_CRC.createCRC32(bytes)); 81 | } 82 | 83 | @Override 84 | public void close() throws IOException 85 | { 86 | out.close(); 87 | } 88 | 89 | } -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/struct/io/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * General Doom-related I/O objects. 3 | */ 4 | package net.mtrop.doom.struct.io; -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/struct/map/SparseGridIndex.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.struct.map; 9 | 10 | import java.util.HashMap; 11 | import java.util.Iterator; 12 | import java.util.Map; 13 | 14 | import net.mtrop.doom.struct.Sizable; 15 | 16 | /** 17 | * This is a grid that contains a grid of Object data generally used for maps and lookups. 18 | * This map is sparse, which means it uses as little memory as possible, which can increase the lookup time in most cases. 19 | * @author Matthew Tropiano 20 | * @param the value type. 21 | */ 22 | public class SparseGridIndex implements Iterable>, Sizable 23 | { 24 | private static final ThreadLocal CACHEPAIR = ThreadLocal.withInitial(()->new Pair()); 25 | 26 | /** List of grid codes. */ 27 | protected HashMap data; 28 | 29 | /** 30 | * Creates a new sparse grid of an unspecified width and height. 31 | * @throws IllegalArgumentException if capacity is negative or ratio is 0 or less. 32 | */ 33 | public SparseGridIndex() 34 | { 35 | data = new HashMap(); 36 | } 37 | 38 | /** 39 | * Clears everything from the grid. 40 | */ 41 | public void clear() 42 | { 43 | data.clear(); 44 | } 45 | 46 | /** 47 | * Sets an object at a particular part of the grid. 48 | * @param x the grid position x to set info. 49 | * @param y the grid position y to set info. 50 | * @param object the object to set. Can be null. 51 | */ 52 | public void set(int x, int y, T object) 53 | { 54 | Pair tempPair = CACHEPAIR.get(); 55 | tempPair.x = x; 56 | tempPair.y = y; 57 | if (object == null) 58 | data.remove(tempPair); 59 | else 60 | data.put(new Pair(x, y), object); 61 | } 62 | 63 | /** 64 | * Gets the object at a particular part of the grid. 65 | * @param x the grid position x to get info. 66 | * @param y the grid position y to get info. 67 | * @return the object at that set of coordinates or null if not object. 68 | */ 69 | public T get(int x, int y) 70 | { 71 | Pair tempPair = CACHEPAIR.get(); 72 | tempPair.x = x; 73 | tempPair.y = y; 74 | return data.get(tempPair); 75 | } 76 | 77 | @Override 78 | public String toString() 79 | { 80 | return data.toString(); 81 | } 82 | 83 | @Override 84 | public Iterator> iterator() 85 | { 86 | return data.entrySet().iterator(); 87 | } 88 | 89 | @Override 90 | public int size() 91 | { 92 | return data.size(); 93 | } 94 | 95 | @Override 96 | public boolean isEmpty() 97 | { 98 | return size() == 0; 99 | } 100 | 101 | /** 102 | * Ordered Pair integer object. 103 | */ 104 | public static class Pair 105 | { 106 | /** X-coordinate. */ 107 | private int x; 108 | /** Y-coordinate. */ 109 | private int y; 110 | 111 | /** 112 | * Creates a new Pair (0,0). 113 | */ 114 | private Pair() 115 | { 116 | this(0, 0); 117 | } 118 | 119 | /** 120 | * Creates a new Pair. 121 | * @param x the x-coordinate value. 122 | * @param y the y-coordinate value. 123 | */ 124 | private Pair(int x, int y) 125 | { 126 | this.x = x; 127 | this.y = y; 128 | } 129 | 130 | public int getX() 131 | { 132 | return x; 133 | } 134 | 135 | public int getY() 136 | { 137 | return y; 138 | } 139 | 140 | @Override 141 | public int hashCode() 142 | { 143 | return x ^ ~y; 144 | } 145 | 146 | @Override 147 | public boolean equals(Object obj) 148 | { 149 | if (obj instanceof Pair) 150 | return equals((Pair)obj); 151 | else 152 | return super.equals(obj); 153 | } 154 | 155 | /** 156 | * Checks if this pair equals another. 157 | * @param p the other pair. 158 | * @return true if so, false if not. 159 | */ 160 | public boolean equals(Pair p) 161 | { 162 | return x == p.x && y == p.y; 163 | } 164 | 165 | @Override 166 | public String toString() 167 | { 168 | return "(" + x + ", " + y + ")"; 169 | } 170 | 171 | } 172 | 173 | } -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/struct/map/SparseQueueGridIndex.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.struct.map; 9 | 10 | import java.util.Iterator; 11 | import java.util.LinkedList; 12 | import java.util.Queue; 13 | 14 | /** 15 | * A sparse grid index that contains lists of objects. 16 | * Be advised that the {@link #get(int, int)} method may return null if no objects 17 | * are queued at that particular spot. 18 | * @author Matthew Tropiano 19 | * @param the value type. 20 | */ 21 | public class SparseQueueGridIndex extends SparseGridIndex> 22 | { 23 | /** Holds the true size of this grid map. */ 24 | private int trueSize; 25 | 26 | /** 27 | * Creates a new sparse queue grid of an unspecified width and height. 28 | * @throws IllegalArgumentException if capacity is negative or ratio is 0 or less. 29 | */ 30 | public SparseQueueGridIndex() 31 | { 32 | super(); 33 | trueSize = 0; 34 | } 35 | 36 | /** 37 | * Enqueues an object at a particular grid coordinate. 38 | * @param x the x-coordinate. 39 | * @param y the y-coordinate. 40 | * @param object the object to add. 41 | */ 42 | public void enqueue(int x, int y, T object) 43 | { 44 | if (object != null) 45 | { 46 | getQueue(x, y).add(object); 47 | trueSize++; 48 | } 49 | } 50 | 51 | /** 52 | * Dequeues an object at a particular grid coordinate. 53 | * @param x the x-coordinate. 54 | * @param y the y-coordinate. 55 | * @return the first object added at the set of coordinates, null if no objects enqueued. 56 | */ 57 | public T dequeue(int x, int y) 58 | { 59 | T out = getQueue(x, y).poll(); 60 | if (out != null) 61 | trueSize--; 62 | return out; 63 | } 64 | 65 | /** 66 | * Dequeues an object at a particular grid coordinate. 67 | * @param x the x-coordinate. 68 | * @param y the y-coordinate. 69 | * @param object the object to remove. 70 | * @return the first object added at the set of coordinates, null if no objects enqueued. 71 | */ 72 | public boolean remove(int x, int y, T object) 73 | { 74 | boolean out = getQueue(x, y).remove(object); 75 | if (out) 76 | trueSize--; 77 | return out; 78 | } 79 | 80 | /** 81 | * Returns an iterator for a queue at a particular grid coordinate. 82 | * @param x the x-coordinate. 83 | * @param y the y-coordinate. 84 | * @return a resettable iterator for the queue, or null if no queue exists. 85 | */ 86 | public Iterator iterator(int x, int y) 87 | { 88 | return getQueue(x, y).iterator(); 89 | } 90 | 91 | /** 92 | * Returns a queue for a set of coordinates. If no queue exists, it is created. 93 | * This should NEVER return null. 94 | * @param x the x-coordinate. 95 | * @param y the y-coordinate. 96 | * @return a reference to the queue using the provided coordinates. 97 | */ 98 | protected Queue getQueue(int x, int y) 99 | { 100 | Queue out = get(x, y); 101 | if (out == null) 102 | { 103 | out = new LinkedList(); 104 | set(x, y, out); 105 | } 106 | return out; 107 | } 108 | 109 | @Override 110 | public void set(int x, int y, Queue queue) 111 | { 112 | Queue oldQueue = get(x, y); 113 | if (oldQueue != null) 114 | trueSize -= oldQueue.size(); 115 | super.set(x, y, queue); 116 | if (queue != null) 117 | trueSize += queue.size(); 118 | } 119 | 120 | @Override 121 | public void clear() 122 | { 123 | super.clear(); 124 | trueSize = 0; 125 | } 126 | 127 | @Override 128 | public int size() 129 | { 130 | return trueSize; 131 | } 132 | 133 | @Override 134 | public boolean isEmpty() 135 | { 136 | return size() == 0; 137 | } 138 | 139 | } -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/struct/map/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains Map structures. 3 | */ 4 | package net.mtrop.doom.struct.map; -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/struct/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Additional helper data structures. 3 | *

NOTICE: This entire package (and subpackages) is subject to change - do not use this outside of this library. 4 | */ 5 | package net.mtrop.doom.struct; 6 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/struct/trie/CaseInsensitiveTrieMap.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.struct.trie; 9 | 10 | /** 11 | * An implementation of a Trie that stores strings, case-insensitively. 12 | * @author Matthew Tropiano 13 | * @param the value type. 14 | */ 15 | public class CaseInsensitiveTrieMap extends StringTrieMap 16 | { 17 | public CaseInsensitiveTrieMap() 18 | { 19 | super(); 20 | } 21 | 22 | @Override 23 | protected Character[] getSegmentsForKey(String value) 24 | { 25 | Character[] out = new Character[value.length()]; 26 | for (int i = 0; i < value.length(); i++) 27 | out[i] = Character.toLowerCase(value.charAt(i)); 28 | return out; 29 | } 30 | 31 | @Override 32 | public boolean equalityMethodForKey(String object1, String object2) 33 | { 34 | if (object1 == null && object2 != null) 35 | return false; 36 | else if (object1 != null && object2 == null) 37 | return false; 38 | else if (object1 == null && object2 == null) 39 | return true; 40 | return object1.equalsIgnoreCase(object2); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/struct/trie/StringTrieMap.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.struct.trie; 9 | 10 | /** 11 | * An implementation of a Trie that stores strings mapped to values. 12 | * @author Matthew Tropiano 13 | * @param the value type. 14 | */ 15 | public class StringTrieMap extends AbstractTrieMap 16 | { 17 | public StringTrieMap() 18 | { 19 | super(); 20 | } 21 | 22 | @Override 23 | protected Character[] getSegmentsForKey(String value) 24 | { 25 | Character[] out = new Character[value.length()]; 26 | for (int i = 0; i < value.length(); i++) 27 | out[i] = value.charAt(i); 28 | return out; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/struct/trie/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains trie structures. 3 | */ 4 | package net.mtrop.doom.struct.trie; -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/struct/vector/AbstractArrayStorage.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.struct.vector; 9 | 10 | /** 11 | * This class contains the base for all data structures 12 | * that make use of a contiguous memory structure. 13 | * @author Matthew Tropiano 14 | * @param the value type that this contains. 15 | */ 16 | public abstract class AbstractArrayStorage 17 | { 18 | /** Default capacity for a new array. */ 19 | public static final int DEFAULT_CAPACITY = 8; 20 | 21 | /** Underlying object array. */ 22 | protected Object[] storageArray; 23 | 24 | /** 25 | * Initializes the array with the default storage capacity. 26 | */ 27 | protected AbstractArrayStorage() 28 | { 29 | this(DEFAULT_CAPACITY); 30 | } 31 | 32 | /** 33 | * Initializes the array with a particular storage capacity. 34 | * @param capacity the desired capacity. 35 | */ 36 | protected AbstractArrayStorage(int capacity) 37 | { 38 | storageArray = new Object[capacity]; 39 | } 40 | 41 | /** 42 | * Gets data at a particular index in the array. 43 | * @param index the desired index. 44 | * @return the data at a particular index in the array. 45 | * @throws ArrayIndexOutOfBoundsException if the index falls outside of the array bounds. 46 | */ 47 | @SuppressWarnings("unchecked") 48 | protected T get(int index) 49 | { 50 | return (T)storageArray[index]; 51 | } 52 | 53 | /** 54 | * Sets the data at a particular index in the array. 55 | * @param index the desired index. 56 | * @param object the object to set. 57 | * @throws ArrayIndexOutOfBoundsException if the index falls outside of the array bounds. 58 | */ 59 | protected void set(int index, T object) 60 | { 61 | storageArray[index] = object; 62 | } 63 | 64 | } -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/struct/vector/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains vectors. 3 | */ 4 | package net.mtrop.doom.struct.vector; -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/texture/CommonPatch.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.texture; 9 | 10 | import net.mtrop.doom.object.BinaryObject; 11 | import net.mtrop.doom.util.RangeUtils; 12 | 13 | /** 14 | * Singular patch entry for a texture. 15 | */ 16 | public abstract class CommonPatch implements BinaryObject 17 | { 18 | /** Horizontal offset of the patch. */ 19 | protected int originX; 20 | /** Vertical offset of the patch. */ 21 | protected int originY; 22 | /** Index of patch in patch names lump to use. */ 23 | protected int patchIndex; 24 | 25 | public CommonPatch() 26 | { 27 | originX = 0; 28 | originY = 0; 29 | patchIndex = 0; 30 | } 31 | 32 | /** 33 | * @return the horizontal offset of the patch in pixels. 34 | */ 35 | public int getOriginX() 36 | { 37 | return originX; 38 | } 39 | 40 | /** 41 | * Sets the horizontal offset of the patch in pixels. 42 | * @param originX the patch origin, x-coordinate. 43 | * @throws IllegalArgumentException if originX is less than -32768 or more than 32767. 44 | */ 45 | public void setOriginX(int originX) 46 | { 47 | RangeUtils.checkShort("Patch Origin X", originX); 48 | this.originX = originX; 49 | } 50 | 51 | /** 52 | * @return the vertical offset of the patch in pixels. 53 | */ 54 | public int getOriginY() 55 | { 56 | return originY; 57 | } 58 | 59 | /** 60 | * Sets the vertical offset of the patch in pixels. 61 | * @param originY the patch origin, y-coordinate. 62 | * @throws IllegalArgumentException if originY is less than -32768 or more than 32767. 63 | */ 64 | public void setOriginY(int originY) 65 | { 66 | RangeUtils.checkShort("Patch Origin Y", originY); 67 | this.originY = originY; 68 | } 69 | 70 | /** 71 | * @return the patch's index into the patch name lump. 72 | */ 73 | public int getNameIndex() 74 | { 75 | return patchIndex; 76 | } 77 | 78 | /** 79 | * Sets the patch's index into the patch name lump. 80 | * @param patchIndex the patch index. 81 | * @throws IllegalArgumentException if patchIndex is less than 0 or more than 65535. 82 | * @see PatchNames 83 | */ 84 | public void setNameIndex(int patchIndex) 85 | { 86 | RangeUtils.checkShortUnsigned("Patch Index", patchIndex); 87 | this.patchIndex = patchIndex; 88 | } 89 | 90 | @Override 91 | public String toString() 92 | { 93 | StringBuilder sb = new StringBuilder(); 94 | sb.append("Patch Name #"); 95 | sb.append(patchIndex); 96 | sb.append(" ("); 97 | sb.append(originX); 98 | sb.append(", "); 99 | sb.append(originY); 100 | sb.append(")"); 101 | return sb.toString(); 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/texture/StrifeTextureList.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.texture; 9 | 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.io.OutputStream; 13 | 14 | import net.mtrop.doom.object.BinaryObject; 15 | import net.mtrop.doom.struct.io.SerialReader; 16 | import net.mtrop.doom.struct.io.SerialWriter; 17 | import net.mtrop.doom.util.NameUtils; 18 | 19 | /** 20 | * This is the lump that contains a collection of Strife-formatted textures. 21 | * All textures are stored in here, usually named TEXTURE1 or TEXTURE2 in the WAD. 22 | * @author Matthew Tropiano 23 | */ 24 | public class StrifeTextureList extends CommonTextureList implements BinaryObject 25 | { 26 | /** 27 | * Creates a new TextureList with a default starting capacity. 28 | */ 29 | public StrifeTextureList() 30 | { 31 | super(); 32 | } 33 | 34 | /** 35 | * Creates a new TextureList with a specific starting capacity. 36 | * @param capacity the starting capacity. 37 | */ 38 | public StrifeTextureList(int capacity) 39 | { 40 | super(capacity); 41 | } 42 | 43 | @Override 44 | public Texture createTexture(String texture) 45 | { 46 | Texture out = new Texture(texture); 47 | addCreatedTexture(out); 48 | return out; 49 | } 50 | 51 | @Override 52 | public void readBytes(InputStream in) throws IOException 53 | { 54 | clear(); 55 | SerialReader sr = new SerialReader(SerialReader.LITTLE_ENDIAN); 56 | int n = sr.readInt(in); 57 | 58 | in.skip(n*4); 59 | 60 | while(n-- > 0) 61 | { 62 | Texture t = new Texture(); 63 | t.readBytes(in); 64 | addCreatedTexture(t); 65 | } 66 | } 67 | 68 | /** 69 | * This class represents a single texture entry in a TEXTURE1/TEXTURE2 lump. 70 | * Strife Textures use Strife's texture representation. 71 | * @author Matthew Tropiano 72 | */ 73 | public static class Texture extends CommonTexture 74 | { 75 | private Texture() 76 | { 77 | super(); 78 | } 79 | 80 | /** 81 | * Creates a new texture. 82 | * @param name the new texture name. 83 | * @throws IllegalArgumentException if the texture name is invalid. 84 | */ 85 | private Texture(String name) 86 | { 87 | super(name); 88 | } 89 | 90 | @Override 91 | public Patch createPatch() 92 | { 93 | Patch out = new Patch(); 94 | patches.add(out); 95 | return out; 96 | } 97 | 98 | @Override 99 | public void readBytes(InputStream in) throws IOException 100 | { 101 | SerialReader sr = new SerialReader(SerialReader.LITTLE_ENDIAN); 102 | name = NameUtils.toValidTextureName(NameUtils.nullTrim(new String(sr.readBytes(in, 8), "ASCII"))); 103 | sr.readShort(in); 104 | sr.readShort(in); 105 | width = sr.readUnsignedShort(in); 106 | height = sr.readUnsignedShort(in); 107 | 108 | int n = sr.readUnsignedShort(in); 109 | while (n-- > 0) 110 | { 111 | Patch p = new Patch(); 112 | p.readBytes(in); 113 | patches.add(p); 114 | } 115 | } 116 | 117 | @Override 118 | public void writeBytes(OutputStream out) throws IOException 119 | { 120 | SerialWriter sw = new SerialWriter(SerialWriter.LITTLE_ENDIAN); 121 | sw.writeBytes(out, NameUtils.toASCIIBytes(name, 8)); 122 | sw.writeUnsignedShort(out, 0); 123 | sw.writeUnsignedShort(out, 0); 124 | sw.writeUnsignedShort(out, width); 125 | sw.writeUnsignedShort(out, height); 126 | sw.writeUnsignedShort(out, patches.size()); 127 | for (Patch p : patches) 128 | p.writeBytes(out); 129 | } 130 | 131 | /** 132 | * Singular patch entry for a texture. 133 | */ 134 | public static class Patch extends CommonPatch 135 | { 136 | /** The length of a single patch. */ 137 | public static final int LENGTH = 10; 138 | 139 | @Override 140 | public void readBytes(InputStream in) throws IOException 141 | { 142 | SerialReader sr = new SerialReader(SerialReader.LITTLE_ENDIAN); 143 | originX = sr.readShort(in); 144 | originY = sr.readShort(in); 145 | patchIndex = sr.readUnsignedShort(in); 146 | } 147 | 148 | @Override 149 | public void writeBytes(OutputStream out) throws IOException 150 | { 151 | SerialWriter sw = new SerialWriter(SerialWriter.LITTLE_ENDIAN); 152 | sw.writeShort(out, (short)originX); 153 | sw.writeShort(out, (short)originY); 154 | sw.writeUnsignedShort(out, patchIndex); 155 | } 156 | 157 | } 158 | 159 | } 160 | 161 | } 162 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/texture/package-info.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Matt Tropiano 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Lesser Public License v2.1 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | /** 9 | * Texture data and similar structures. 10 | */ 11 | package net.mtrop.doom.texture; 12 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/util/TextUtils.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.util; 9 | 10 | import java.nio.charset.Charset; 11 | 12 | /** 13 | * Text utilities and constants. 14 | * @author Matthew Tropiano 15 | * @since 2.13.0 16 | */ 17 | public final class TextUtils 18 | { 19 | /** ASCII encoding. */ 20 | public static final Charset ASCII = Charset.forName("ASCII"); 21 | /** CP437 encoding (the extended MS-DOS charset). */ 22 | public static final Charset CP437 = Charset.forName("CP437"); 23 | /** UTF-8 encoding. */ 24 | public static final Charset UTF8 = Charset.forName("UTF-8"); 25 | 26 | private TextUtils() {} 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/mtrop/doom/util/package-info.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Matt Tropiano 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the GNU Lesser Public License v2.1 5 | * which accompanies this distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | /** 9 | * Contains utility classes. 10 | */ 11 | package net.mtrop.doom.util; 12 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/WadTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom; 9 | 10 | import static net.mtrop.doom.test.TestUtils.assertEqual; 11 | 12 | import java.io.File; 13 | 14 | import net.mtrop.doom.test.TestUtils.AfterAllTests; 15 | import net.mtrop.doom.test.TestUtils.BeforeAllTests; 16 | import net.mtrop.doom.test.TestUtils.Test; 17 | 18 | public final class WadTest 19 | { 20 | private static final File TEST_DIR = new File("testjunk"); 21 | 22 | @BeforeAllTests 23 | public static void beforeAllTests() throws Exception 24 | { 25 | assertEqual(TEST_DIR.mkdirs(), true); 26 | } 27 | 28 | @AfterAllTests 29 | public static void afterAllTests() throws Exception 30 | { 31 | assertEqual(TEST_DIR.delete(), true); 32 | } 33 | 34 | @Test 35 | public void isWadTest() throws Exception 36 | { 37 | assertEqual(Wad.isWAD(new File("src/test/resources/doommap.wad")), true); 38 | assertEqual(Wad.isWAD(new File("src/test/resources/hexenmap.wad")), true); 39 | assertEqual(Wad.isWAD(new File("src/test/resources/udmfmap.wad")), true); 40 | assertEqual(Wad.isWAD(new File("src/test/resources/viscerus.pk3")), false); 41 | assertEqual(Wad.isWAD(new File("src/test/resources/does-not-exist.wad")), false); 42 | assertEqual(Wad.isWAD(new File("src/test/resources")), false); // is dir 43 | } 44 | 45 | @Test 46 | public void openWadMap() throws Exception 47 | { 48 | WadMap wad = new WadMap("src/test/resources/doommap.wad"); 49 | wad.close(); 50 | } 51 | 52 | @Test 53 | public void openWadFile() throws Exception 54 | { 55 | WadFile wad = new WadFile("src/test/resources/doommap.wad"); 56 | wad.close(); 57 | } 58 | 59 | @Test 60 | public void openWadBuffer() throws Exception 61 | { 62 | WadBuffer wad = new WadBuffer("src/test/resources/doommap.wad"); 63 | wad.close(); 64 | } 65 | 66 | @Test 67 | public void getFileData() throws Exception 68 | { 69 | WadFile wad = new WadFile("src/test/resources/doommap.wad"); 70 | wad.getData("THINGS"); 71 | wad.close(); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/demo/DemoTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.demo; 9 | 10 | import java.io.IOException; 11 | 12 | import net.mtrop.doom.WadFile; 13 | import net.mtrop.doom.LoggingFactory; 14 | import net.mtrop.doom.LoggingFactory.Logger; 15 | 16 | public final class DemoTest 17 | { 18 | public static void main(String[] args) throws IOException 19 | { 20 | Logger logger = LoggingFactory.createConsoleLoggerFor(DemoTest.class); 21 | 22 | WadFile wad = new WadFile(args[0]); 23 | Demo demo = wad.getDataAs("DEMO1", Demo.class); 24 | logger.info(demo); 25 | for (Demo.Tic[] tics : demo) 26 | for (Demo.Tic tic : tics) 27 | logger.info(tic); 28 | wad.close(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/graphics/AnimatedTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.graphics; 9 | 10 | import java.io.IOException; 11 | 12 | import net.mtrop.doom.WadFile; 13 | import net.mtrop.doom.texture.Animated; 14 | import net.mtrop.doom.LoggingFactory; 15 | import net.mtrop.doom.LoggingFactory.Logger; 16 | 17 | 18 | public final class AnimatedTest 19 | { 20 | public static void main(String[] args) throws IOException 21 | { 22 | Logger logger = LoggingFactory.createConsoleLoggerFor(AnimatedTest.class); 23 | 24 | WadFile wad = new WadFile(args[0]); 25 | for (Animated.Entry entry : wad.getDataAs("ANIMATED", Animated.class)) 26 | logger.info(entry); 27 | 28 | wad.close(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/graphics/ColormapTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.graphics; 9 | 10 | import java.io.IOException; 11 | 12 | import net.mtrop.doom.WadFile; 13 | import net.mtrop.doom.LoggingFactory; 14 | import net.mtrop.doom.LoggingFactory.Logger; 15 | 16 | public final class ColormapTest 17 | { 18 | public static void main(String[] args) throws IOException 19 | { 20 | Logger logger = LoggingFactory.createConsoleLoggerFor(ColormapTest.class); 21 | WadFile wad = new WadFile(args[0]); 22 | for (Colormap colormap : wad.getDataAs("COLORMAP", Colormap.class, Colormap.LENGTH)) 23 | logger.info(colormap); 24 | wad.close(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/graphics/GraphicDirTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.graphics; 9 | 10 | import java.io.File; 11 | import java.io.IOException; 12 | 13 | import net.mtrop.doom.object.BinaryObject; 14 | import net.mtrop.doom.util.GraphicUtils; 15 | import net.mtrop.doom.util.WadUtils; 16 | 17 | public final class GraphicDirTest 18 | { 19 | public static void main(String[] args) throws IOException 20 | { 21 | Palette pal = WadUtils.openWadAndGet(args[0], 22 | (wad) -> wad.getDataAs("PLAYPAL", Palette.class) 23 | ); 24 | 25 | for (File f : (new File(args[1])).listFiles((file)->file.getName().toLowerCase().endsWith(".png"))) 26 | { 27 | File out = new File(f.getParent() + File.separator + f.getName() + ".lmp"); 28 | GraphicUtils.createPicture(BinaryObject.read(PNGPicture.class, f), pal).writeFile(out); 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/graphics/GraphicTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.graphics; 9 | 10 | import java.awt.image.BufferedImage; 11 | import java.io.File; 12 | import java.io.IOException; 13 | 14 | import javax.imageio.ImageIO; 15 | 16 | import net.mtrop.doom.WadFile; 17 | import net.mtrop.doom.util.GraphicUtils; 18 | 19 | public final class GraphicTest 20 | { 21 | public static void main(String[] args) throws IOException 22 | { 23 | WadFile wad = new WadFile(args[0]); 24 | 25 | Palette pal = wad.getDataAs("PLAYPAL", Palette.class); 26 | Flat f = Flat.create(64, 64, wad.getData("FWATER1")); 27 | Picture p = wad.getDataAs("TROOA1", Picture.class); 28 | EndDoom endoom = wad.getDataAs("ENDOOM", EndDoom.class); 29 | 30 | wad.close(); 31 | 32 | BufferedImage fi = GraphicUtils.createImage(f, pal); 33 | BufferedImage pi = GraphicUtils.createImage(p, pal); 34 | BufferedImage ei = GraphicUtils.createImageForEndDoom(endoom, true); 35 | 36 | ImageIO.write(fi, "PNG", new File("out.png")); 37 | ImageIO.write(pi, "PNG", new File("out2.png")); 38 | ImageIO.write(ei, "PNG", new File("endoom.png")); 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/graphics/PaletteTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.graphics; 9 | 10 | import java.io.IOException; 11 | 12 | import net.mtrop.doom.WadFile; 13 | import net.mtrop.doom.LoggingFactory; 14 | import net.mtrop.doom.LoggingFactory.Logger; 15 | 16 | public final class PaletteTest 17 | { 18 | public static void main(String[] args) throws IOException 19 | { 20 | Logger logger = LoggingFactory.createConsoleLoggerFor(PaletteTest.class); 21 | 22 | WadFile wad = new WadFile(args[0]); 23 | for (Palette pal : wad.getDataAs("PLAYPAL", Palette.class, Palette.LENGTH)) 24 | logger.info(pal); 25 | wad.close(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/graphics/TallGraphicTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.graphics; 9 | 10 | import java.io.File; 11 | import java.io.IOException; 12 | 13 | import javax.imageio.ImageIO; 14 | 15 | import net.mtrop.doom.WadFile; 16 | import net.mtrop.doom.object.BinaryObject; 17 | import net.mtrop.doom.util.GraphicUtils; 18 | 19 | public final class TallGraphicTest 20 | { 21 | public static void main(String[] args) throws IOException 22 | { 23 | WadFile wad = new WadFile(args[0]); 24 | Palette pal = wad.getDataAs("PLAYPAL", Palette.class); 25 | wad.close(); 26 | 27 | GraphicUtils.createPicture(ImageIO.read(new File(args[1])), pal).writeFile(new File("junk.lmp")); 28 | ImageIO.write(GraphicUtils.createImage(BinaryObject.read(Picture.class, new File("junk.lmp")), pal), "png", new File("junk.png")); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/map/MapTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map; 9 | 10 | import java.io.IOException; 11 | 12 | import net.mtrop.doom.LoggingFactory; 13 | import net.mtrop.doom.LoggingFactory.Logger; 14 | import net.mtrop.doom.WadFile; 15 | import net.mtrop.doom.exception.MapException; 16 | 17 | import net.mtrop.doom.util.MapUtils; 18 | 19 | public final class MapTest 20 | { 21 | public static void main(String[] args) throws MapException, IOException 22 | { 23 | Logger logger = LoggingFactory.createConsoleLoggerFor(MapTest.class); 24 | 25 | WadFile wad = new WadFile(args[0]); 26 | int[] mapindices = MapUtils.getAllMapIndices(wad); 27 | for (int i : mapindices) 28 | { 29 | MapFormat format = MapUtils.getMapFormat(wad, i); 30 | logger.info(wad.getEntry(i).getName() + " " + format); 31 | switch (format) 32 | { 33 | case DOOM: 34 | logger.info(MapUtils.createDoomMap(wad, i)); 35 | break; 36 | case HEXEN: 37 | logger.info(MapUtils.createHexenMap(wad, i)); 38 | break; 39 | case UDMF: 40 | logger.info(MapUtils.createUDMFMap(wad, i)); 41 | break; 42 | } 43 | 44 | } 45 | wad.close(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/map/data/BlockmapTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data; 9 | 10 | import java.io.IOException; 11 | 12 | import net.mtrop.doom.WadFile; 13 | import net.mtrop.doom.LoggingFactory; 14 | import net.mtrop.doom.LoggingFactory.Logger; 15 | 16 | 17 | public final class BlockmapTest 18 | { 19 | public static void main(String[] args) throws IOException 20 | { 21 | Logger logger = LoggingFactory.createConsoleLoggerFor(BlockmapTest.class); 22 | WadFile wad = new WadFile(args[0]); 23 | Blockmap blockmap = wad.getDataAs("BLOCKMAP", Blockmap.class); 24 | logger.info(blockmap.toBytes()); 25 | wad.close(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/map/data/DoomLinedefTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data; 9 | 10 | import java.io.IOException; 11 | 12 | import net.mtrop.doom.WadFile; 13 | import net.mtrop.doom.LoggingFactory; 14 | import net.mtrop.doom.LoggingFactory.Logger; 15 | 16 | public class DoomLinedefTest 17 | { 18 | public static void main(String[] args) throws IOException 19 | { 20 | Logger logger = LoggingFactory.createConsoleLoggerFor(DoomLinedefTest.class); 21 | 22 | WadFile wad = new WadFile(args[0]); 23 | int i = 0; 24 | for (DoomLinedef object : wad.getDataAs("LINEDEFS", DoomLinedef.class, DoomLinedef.LENGTH)) 25 | logger.info((i++) + " " + object); 26 | wad.close(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/map/data/DoomSectorTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data; 9 | 10 | import java.io.IOException; 11 | 12 | import net.mtrop.doom.WadFile; 13 | import net.mtrop.doom.LoggingFactory; 14 | import net.mtrop.doom.LoggingFactory.Logger; 15 | 16 | public class DoomSectorTest 17 | { 18 | public static void main(String[] args) throws IOException 19 | { 20 | Logger logger = LoggingFactory.createConsoleLoggerFor(DoomSectorTest.class); 21 | 22 | WadFile wad = new WadFile(args[0]); 23 | int i = 0; 24 | for (DoomSector object : wad.getDataAs("SECTORS", DoomSector.class, DoomSector.LENGTH)) 25 | logger.info((i++) + " " + object); 26 | wad.close(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/map/data/DoomSidedefTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data; 9 | 10 | import java.io.IOException; 11 | 12 | import net.mtrop.doom.WadFile; 13 | import net.mtrop.doom.LoggingFactory; 14 | import net.mtrop.doom.LoggingFactory.Logger; 15 | 16 | public class DoomSidedefTest 17 | { 18 | public static void main(String[] args) throws IOException 19 | { 20 | Logger logger = LoggingFactory.createConsoleLoggerFor(DoomSidedefTest.class); 21 | 22 | WadFile wad = new WadFile(args[0]); 23 | int i = 0; 24 | for (DoomSidedef object : wad.getDataAs("SIDEDEFS", DoomSidedef.class, DoomSidedef.LENGTH)) 25 | logger.info((i++) + " " + object); 26 | wad.close(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/map/data/DoomThingTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data; 9 | 10 | import java.io.IOException; 11 | 12 | import net.mtrop.doom.WadFile; 13 | import net.mtrop.doom.LoggingFactory; 14 | import net.mtrop.doom.LoggingFactory.Logger; 15 | 16 | public class DoomThingTest 17 | { 18 | public static void main(String[] args) throws IOException 19 | { 20 | Logger logger = LoggingFactory.createConsoleLoggerFor(DoomThingTest.class); 21 | 22 | WadFile wad = new WadFile(args[0]); 23 | int i = 0; 24 | for (DoomThing object : wad.getDataAs("THINGS", DoomThing.class, DoomThing.LENGTH)) 25 | logger.info((i++) + " " + object); 26 | wad.close(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/map/data/DoomVertexTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data; 9 | 10 | import java.io.IOException; 11 | 12 | import net.mtrop.doom.WadFile; 13 | import net.mtrop.doom.LoggingFactory; 14 | import net.mtrop.doom.LoggingFactory.Logger; 15 | 16 | public class DoomVertexTest 17 | { 18 | public static void main(String[] args) throws IOException 19 | { 20 | Logger logger = LoggingFactory.createConsoleLoggerFor(DoomVertexTest.class); 21 | 22 | WadFile wad = new WadFile(args[0]); 23 | int i = 0; 24 | for (DoomVertex object : wad.getDataAs("VERTEXES", DoomVertex.class, DoomVertex.LENGTH)) 25 | logger.info((i++) + " " + object); 26 | wad.close(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/map/data/HexenLinedefTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data; 9 | 10 | import java.io.IOException; 11 | 12 | import net.mtrop.doom.WadFile; 13 | import net.mtrop.doom.LoggingFactory; 14 | import net.mtrop.doom.LoggingFactory.Logger; 15 | 16 | public class HexenLinedefTest 17 | { 18 | public static void main(String[] args) throws IOException 19 | { 20 | Logger logger = LoggingFactory.createConsoleLoggerFor(HexenLinedefTest.class); 21 | 22 | WadFile wad = new WadFile(args[0]); 23 | int i = 0; 24 | for (HexenLinedef object : wad.getDataAs("LINEDEFS", HexenLinedef.class, HexenLinedef.LENGTH)) 25 | logger.info((i++) + " " + object); 26 | wad.close(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/map/data/HexenThingTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data; 9 | 10 | import java.io.IOException; 11 | 12 | import net.mtrop.doom.WadFile; 13 | import net.mtrop.doom.LoggingFactory; 14 | import net.mtrop.doom.LoggingFactory.Logger; 15 | 16 | public class HexenThingTest 17 | { 18 | public static void main(String[] args) throws IOException 19 | { 20 | Logger logger = LoggingFactory.createConsoleLoggerFor(HexenThingTest.class); 21 | 22 | WadFile wad = new WadFile(args[0]); 23 | int i = 0; 24 | for (HexenThing object : wad.getDataAs("THINGS", HexenThing.class, HexenThing.LENGTH)) 25 | logger.info((i++) + " " + object); 26 | wad.close(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/map/data/RejectTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.data; 9 | 10 | import java.io.IOException; 11 | 12 | import net.mtrop.doom.WadFile; 13 | 14 | public final class RejectTest 15 | { 16 | public static void main(String[] args) throws IOException 17 | { 18 | WadFile wad = new WadFile(args[0]); 19 | DoomSector[] sectors = wad.getDataAs("SECTORS", DoomSector.class, DoomSector.LENGTH); 20 | Reject reject = new Reject(sectors.length); 21 | reject.fromBytes(wad.getData("REJECT")); 22 | 23 | wad.close(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/map/udmf/UDMFReaderTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf; 9 | 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.io.StringWriter; 13 | 14 | import net.mtrop.doom.WadFile; 15 | import net.mtrop.doom.LoggingFactory; 16 | import net.mtrop.doom.LoggingFactory.Logger; 17 | 18 | 19 | public class UDMFReaderTest 20 | { 21 | public static void main(String[] args) throws IOException 22 | { 23 | Logger logger = LoggingFactory.createConsoleLoggerFor(UDMFReaderTest.class); 24 | 25 | WadFile wad = new WadFile(args[0]); 26 | InputStream in = wad.getInputStream("TEXTMAP"); 27 | 28 | UDMFTable udmftable = UDMFReader.readData(wad.getInputStream("TEXTMAP")); 29 | StringWriter writer = new StringWriter(); 30 | UDMFWriter.writeTable(udmftable, writer); 31 | logger.info("\n"+writer.toString()); 32 | 33 | in.close(); 34 | wad.close(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/map/udmf/UDMFScannerTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.map.udmf; 9 | 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | 13 | import net.mtrop.doom.WadFile; 14 | 15 | import net.mtrop.doom.LoggingFactory; 16 | import net.mtrop.doom.LoggingFactory.LogLevel; 17 | import net.mtrop.doom.LoggingFactory.Logger; 18 | 19 | 20 | public class UDMFScannerTest 21 | { 22 | public static void main(String[] args) throws IOException 23 | { 24 | Logger logger = LoggingFactory.createConsoleLoggerFor(UDMFScannerTest.class); 25 | logger.setLoggingLevel(LogLevel.INFO); 26 | 27 | WadFile wad = new WadFile(args[0]); 28 | InputStream in = wad.getInputStream("TEXTMAP"); 29 | 30 | UDMFScanner scanner = UDMFScanner.createScanner(in); 31 | while (scanner.hasNext()) 32 | { 33 | UDMFScanner.Element element = scanner.next(); 34 | switch (element.getType()) 35 | { 36 | case GLOBAL_ATTRIBUTE: 37 | logger.infof("ATTRIB: %s = \"%s\"", element.getName(), element.getValue().toString()); 38 | break; 39 | case OBJECT: 40 | logger.infof("OBJECT: Type %s", element.getName()); 41 | break; 42 | } 43 | } 44 | 45 | in.close(); 46 | wad.close(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/sound/MUSTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.sound; 9 | 10 | import java.io.IOException; 11 | 12 | import net.mtrop.doom.WadFile; 13 | import net.mtrop.doom.LoggingFactory; 14 | import net.mtrop.doom.LoggingFactory.Logger; 15 | 16 | 17 | public final class MUSTest 18 | { 19 | public static void main(String[] args) throws IOException 20 | { 21 | Logger logger = LoggingFactory.createConsoleLoggerFor(MUSTest.class); 22 | WadFile wad = new WadFile(args[0]); 23 | MUS mus = wad.getDataAs("D_RUNNIN", MUS.class); 24 | for (MUS.Event event : mus) 25 | logger.info(event); 26 | wad.close(); 27 | 28 | /* 29 | long n = 1000000000/140; 30 | long millis = n / 1000000; 31 | int nanos = (int)(n % 1000000); 32 | 33 | AtomicLong t = new AtomicLong(0); 34 | MUS.SequencerListener listener = new MUS.SequencerListener() 35 | { 36 | @Override 37 | public void onSystemEvent(int channel, int type) 38 | { 39 | } 40 | 41 | @Override 42 | public void onScoreEnd(int channel) 43 | { 44 | } 45 | 46 | @Override 47 | public void onPitchEvent(int channel, int pitch) 48 | { 49 | } 50 | 51 | @Override 52 | public void onNoteReleaseEvent(int channel, int note) 53 | { 54 | } 55 | 56 | @Override 57 | public void onNotePlayEvent(int channel, int note, int volume) 58 | { 59 | System.out.println(t + " P "+channel + ", " + note + " v"+volume); 60 | } 61 | 62 | @Override 63 | public void onNotePlayEvent(int channel, int note) 64 | { 65 | System.out.println(t + " P "+channel + ", " + note); 66 | } 67 | 68 | @Override 69 | public void onControllerChangeEvent(int channel, int controllerNumber, int controllerValue) 70 | { 71 | } 72 | }; 73 | 74 | MUS.Sequencer seq = mus.getSequencer(listener); 75 | while (seq.step()) 76 | try 77 | { 78 | Thread.sleep(millis, nanos); 79 | t.incrementAndGet(); 80 | } 81 | catch (InterruptedException e) 82 | { 83 | // TODO Auto-generated catch block 84 | e.printStackTrace(); 85 | } 86 | */ 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/sound/SoundTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.sound; 9 | 10 | import java.io.IOException; 11 | 12 | import net.mtrop.doom.WadFile; 13 | import net.mtrop.doom.sound.DMXSound.InterpolationType; 14 | 15 | 16 | public final class SoundTest 17 | { 18 | public static void main(String[] args) throws IOException 19 | { 20 | WadFile wad = new WadFile(args[0]); 21 | DMXSound sound = wad.getDataAs("DSRLAUNC", DMXSound.class) 22 | .resample(InterpolationType.CUBIC, DMXSound.SAMPLERATE_22KHZ); 23 | for (int i = 0 ; i < sound.getSampleCount(); i++) 24 | System.out.println(sound.getSample(i)); 25 | wad.close(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/test/TestSuite.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.test; 9 | 10 | import net.mtrop.doom.PK3Test; 11 | import net.mtrop.doom.WadTest; 12 | import net.mtrop.doom.test.TestUtils.TestDependsOn; 13 | import net.mtrop.doom.util.NameUtilsTest; 14 | 15 | @TestDependsOn({ 16 | WadTest.class, 17 | PK3Test.class, 18 | NameUtilsTest.class, 19 | }) 20 | public final class TestSuite 21 | { 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/texture/TextureTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.texture; 9 | 10 | import java.io.IOException; 11 | 12 | import net.mtrop.doom.texture.TextureSet.Patch; 13 | import net.mtrop.doom.texture.TextureSet.Texture; 14 | import net.mtrop.doom.util.WadUtils; 15 | import net.mtrop.doom.LoggingFactory; 16 | import net.mtrop.doom.LoggingFactory.Logger; 17 | 18 | 19 | public final class TextureTest 20 | { 21 | public static void main(String[] args) throws IOException 22 | { 23 | Logger logger = LoggingFactory.createConsoleLoggerFor(TextureTest.class); 24 | 25 | TextureSet set = WadUtils.openWadAndGet(args[0], (wad) -> 26 | new TextureSet( 27 | wad.getDataAs("PNAMES", PatchNames.class), 28 | wad.getDataAs("TEXTURE1", DoomTextureList.class) 29 | ) 30 | ); 31 | 32 | for (Texture tex : set) 33 | { 34 | logger.infof("%-8s %dx%d %d patches", tex.getName(), tex.getWidth(), tex.getHeight(), tex.getPatchCount()); 35 | for (Patch patch : tex) 36 | logger.infof("\t%-8s (%d, %d)", patch.getName(), patch.getOriginX(), patch.getOriginY()); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/util/MapUtilsTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.util; 9 | 10 | import java.io.File; 11 | import java.io.FileOutputStream; 12 | import java.io.IOException; 13 | 14 | import javax.sound.sampled.AudioFileFormat.Type; 15 | import javax.sound.sampled.UnsupportedAudioFileException; 16 | 17 | import net.mtrop.doom.Wad; 18 | import net.mtrop.doom.WadEntry; 19 | import net.mtrop.doom.WadFile; 20 | import net.mtrop.doom.sound.DMXSound; 21 | 22 | public final class MapUtilsTest 23 | { 24 | public static void main(String[] args) throws IOException 25 | { 26 | Wad wad = new WadFile(args[0]); 27 | for (WadEntry e : MapUtils.getMapEntries(wad, args[1])) 28 | System.out.println(e.getName()); 29 | wad.close(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/util/NameUtilsTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.util; 9 | 10 | import static net.mtrop.doom.test.TestUtils.assertEqual; 11 | 12 | import net.mtrop.doom.test.TestUtils.Test; 13 | 14 | public final class NameUtilsTest 15 | { 16 | @Test 17 | public void isValidEntryName() throws Exception 18 | { 19 | assertEqual(NameUtils.isValidEntryName("-"), true); 20 | assertEqual(NameUtils.isValidEntryName("WALL00_3"), true); 21 | assertEqual(NameUtils.isValidEntryName("SFALL1"), true); 22 | assertEqual(NameUtils.isValidEntryName("_SFALL1"), true); 23 | assertEqual(NameUtils.isValidEntryName("SFALL[1]"), true); 24 | assertEqual(NameUtils.isValidEntryName("^SFALL1"), true); 25 | assertEqual(NameUtils.isValidEntryName("METAL-2"), true); 26 | assertEqual(NameUtils.isValidEntryName("--------"), true); 27 | assertEqual(NameUtils.isValidEntryName("\\MARKER"), true); 28 | assertEqual(NameUtils.isValidEntryName("\\\\MARKER"), true); 29 | assertEqual(NameUtils.isValidEntryName("O2V+35_0"), true); 30 | assertEqual(NameUtils.isValidEntryName("12345678"), true); 31 | assertEqual(NameUtils.isValidEntryName("\\FLAT**"), true); 32 | assertEqual(NameUtils.isValidEntryName("!@#$%^&*"), true); 33 | 34 | assertEqual(NameUtils.isValidEntryName("123456789"), false); 35 | assertEqual(NameUtils.isValidEntryName("wall00_3"), false); 36 | assertEqual(NameUtils.isValidEntryName(" "), false); 37 | assertEqual(NameUtils.isValidEntryName(""), false); 38 | assertEqual(NameUtils.isValidEntryName("NOUMLÄUT"), false); 39 | } 40 | 41 | @Test 42 | public void isValidTextureName() throws Exception 43 | { 44 | assertEqual(NameUtils.isValidTextureName("-"), true); 45 | assertEqual(NameUtils.isValidTextureName("AASTINKY"), true); 46 | assertEqual(NameUtils.isValidTextureName("SFALL1"), true); 47 | assertEqual(NameUtils.isValidTextureName("_SFALL1"), true); 48 | assertEqual(NameUtils.isValidTextureName("METAL-2"), true); 49 | assertEqual(NameUtils.isValidTextureName("--------"), true); 50 | assertEqual(NameUtils.isValidTextureName("O2V+35_0"), true); 51 | assertEqual(NameUtils.isValidTextureName("12345678"), true); 52 | assertEqual(NameUtils.isValidTextureName("SFALL[1]"), true); 53 | assertEqual(NameUtils.isValidTextureName("^SFALL1"), true); 54 | assertEqual(NameUtils.isValidTextureName("\\MARKER"), true); 55 | assertEqual(NameUtils.isValidTextureName("\\FLAT**"), true); 56 | assertEqual(NameUtils.isValidTextureName("!@#$%^&*"), true); 57 | 58 | assertEqual(NameUtils.isValidTextureName("123456789"), false); 59 | assertEqual(NameUtils.isValidTextureName("sfall1"), false); 60 | assertEqual(NameUtils.isValidTextureName(" "), false); 61 | assertEqual(NameUtils.isValidTextureName(""), false); 62 | assertEqual(NameUtils.isValidTextureName("NOUMLÄUT"), false); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/net/mtrop/doom/util/SoundUtilTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015-2023 Matt Tropiano 3 | * This program and the accompanying materials are made available under the 4 | * terms of the GNU Lesser Public License v2.1 which accompanies this 5 | * distribution, and is available at 6 | * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html 7 | ******************************************************************************/ 8 | package net.mtrop.doom.util; 9 | 10 | import java.io.File; 11 | import java.io.FileOutputStream; 12 | import java.io.IOException; 13 | 14 | import javax.sound.sampled.AudioFileFormat.Type; 15 | import javax.sound.sampled.UnsupportedAudioFileException; 16 | 17 | import net.mtrop.doom.sound.DMXSound; 18 | 19 | public final class SoundUtilTest 20 | { 21 | public static void main(String[] args) throws IOException, UnsupportedAudioFileException 22 | { 23 | DMXSound sound = SoundUtils.createSound(new File(args[0])); 24 | sound.writeBytes(new FileOutputStream(new File("DSJUNK.dmx"))); 25 | SoundUtils.writeSoundToFile(sound, Type.WAVE, new File("DSJUNK.wav")); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/resources/doommap.wad: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MTrop/DoomStruct/f43d66c00d382e30ca7ec5ea0a5cda7ef0d382f9/src/test/resources/doommap.wad -------------------------------------------------------------------------------- /src/test/resources/hexenmap.wad: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MTrop/DoomStruct/f43d66c00d382e30ca7ec5ea0a5cda7ef0d382f9/src/test/resources/hexenmap.wad -------------------------------------------------------------------------------- /src/test/resources/udmfmap.wad: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MTrop/DoomStruct/f43d66c00d382e30ca7ec5ea0a5cda7ef0d382f9/src/test/resources/udmfmap.wad -------------------------------------------------------------------------------- /src/test/resources/viscerus.pk3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MTrop/DoomStruct/f43d66c00d382e30ca7ec5ea0a5cda7ef0d382f9/src/test/resources/viscerus.pk3 --------------------------------------------------------------------------------