Class Demo

java.lang.Object
net.mtrop.doom.demo.Demo
All Implemented Interfaces:
Iterable<Demo.Tic[]>, BinaryObject

public class Demo extends Object implements BinaryObject, Iterable<Demo.Tic[]>
This class is an abstract representation of a DEMO lump in Doom. It stores player controls per game tic, since everything else is deterministic, all things equal.

The method readBytes(InputStream) will read until it detects the end of the DEMO information.

Author:
Matthew Tropiano
  • Field Details

    • VERSION_12

      public static final int VERSION_12
      Demo version 1.2 byte.
      See Also:
    • VERSION_14

      public static final int VERSION_14
      Demo version 1.4 byte.
      See Also:
    • VERSION_15

      public static final int VERSION_15
      Demo version 1.5 byte.
      See Also:
    • VERSION_1666

      public static final int VERSION_1666
      Demo version 1.666 byte.
      See Also:
    • VERSION_19

      public static final int VERSION_19
      Demo version 1.9 byte.
      See Also:
    • VERSION_FINALDOOM

      public static final int VERSION_FINALDOOM
      Demo version 1.9 byte.
      See Also:
    • VERSION_BOOM

      public static final int VERSION_BOOM
      Demo version Boom.
      See Also:
    • VERSION_BOOM201

      public static final int VERSION_BOOM201
      Demo version Boom v2.01.
      See Also:
    • VERSION_BOOM202

      public static final int VERSION_BOOM202
      Demo version Boom v2.02.
      See Also:
    • VERSION_LXDOOM

      public static final int VERSION_LXDOOM
      Demo version LxDoom.
      See Also:
    • VERSION_MBF

      public static final int VERSION_MBF
      Demo version MBF.
      See Also:
    • VERSION_PRBOOM210

      public static final int VERSION_PRBOOM210
      Demo version PrBoom v2.1.X.
      See Also:
    • VERSION_PRBOOM220

      public static final int VERSION_PRBOOM220
      Demo version PrBoom v2.2.X.
      See Also:
    • VERSION_PRBOOM230

      public static final int VERSION_PRBOOM230
      Demo version PrBoom v2.3.X.
      See Also:
    • VERSION_PRBOOM240

      public static final int VERSION_PRBOOM240
      Demo version PrBoom v2.4.X.
      See Also:
    • VERSION_PRBOOM250

      public static final int VERSION_PRBOOM250
      Demo version PrBoom v2.5.0.X.
      See Also:
    • SKILL_VERY_EASY

      public static final byte SKILL_VERY_EASY
      Demo skill byte (very easy).
      See Also:
    • SKILL_EASY

      public static final byte SKILL_EASY
      Demo skill byte (easy).
      See Also:
    • SKILL_MEDIUM

      public static final byte SKILL_MEDIUM
      Demo skill byte (medium).
      See Also:
    • SKILL_HARD

      public static final byte SKILL_HARD
      Demo skill byte (hard).
      See Also:
    • SKILL_VERY_HARD

      public static final byte SKILL_VERY_HARD
      Demo skill byte (very hard).
      See Also:
    • MODE_NORMAL

      public static final byte MODE_NORMAL
      Demo play mode byte (Single/co-op).
      See Also:
    • MODE_DEATHMATCH

      public static final byte MODE_DEATHMATCH
      Demo play mode byte (Deathmatch).
      See Also:
    • MODE_ALTDEATH

      public static final byte MODE_ALTDEATH
      Demo play mode byte (Alt. Deathmatch).
      See Also:
    • DEMO_INSURANCE_NONE

      public static final int DEMO_INSURANCE_NONE
      Demo insurance - no correction.
      See Also:
    • DEMO_INSURANCE_FIX

      public static final int DEMO_INSURANCE_FIX
      Demo insurance - attempt fix.
      See Also:
    • DEMO_INSURANCE_RECORD_ONLY

      public static final int DEMO_INSURANCE_RECORD_ONLY
      Demo insurance - only attempt fix during recording.
      See Also:
    • DEMO_END

      public static final byte DEMO_END
      Demo terminal byte.
      See Also:
    • COMPLEVEL_DOOM_12

      public static final int COMPLEVEL_DOOM_12
      Compatibility Level Doom v1.2
      See Also:
    • COMPLEVEL_DOOM_1666

      public static final int COMPLEVEL_DOOM_1666
      Compatibility Level Doom v1.666
      See Also:
    • COMPLEVEL_DOOM_19

      public static final int COMPLEVEL_DOOM_19
      Compatibility Level Doom v1.9
      See Also:
    • COMPLEVEL_UDOOM

      public static final int COMPLEVEL_UDOOM
      Compatibility Level Ultimate Doom
      See Also:
    • COMPLEVEL_FINAL_DOOM

      public static final int COMPLEVEL_FINAL_DOOM
      Compatibility Level Final Doom
      See Also:
    • COMPLEVEL_DOSDOOM

      public static final int COMPLEVEL_DOSDOOM
      Compatibility Level DOSDoom
      See Also:
    • COMPLEVEL_BOOM

      public static final int COMPLEVEL_BOOM
      Compatibility Level Boom v2.0
      See Also:
    • COMPLEVEL_BOOM201

      public static final int COMPLEVEL_BOOM201
      Compatibility Level Boom v2.01
      See Also:
    • COMPLEVEL_BOOM202

      public static final int COMPLEVEL_BOOM202
      Compatibility Level Boom v2.02
      See Also:
    • COMPLEVEL_LXDOOM

      public static final int COMPLEVEL_LXDOOM
      Compatibility Level LxDoom 1.4.X
      See Also:
    • COMPLEVEL_MBF

      public static final int COMPLEVEL_MBF
      Compatibility Level MBF
      See Also:
    • COMPLEVEL_PRBOOM_203B

      public static final int COMPLEVEL_PRBOOM_203B
      Compatibility Level PrBoom v2.03b
      See Also:
    • COMPLEVEL_PRBOOM_210

      public static final int COMPLEVEL_PRBOOM_210
      Compatibility Level PrBoom v2.1.0
      See Also:
    • COMPLEVEL_PRBOOM_211_226

      public static final int COMPLEVEL_PRBOOM_211_226
      Compatibility Level PrBoom v2.1.1-2.2.6
      See Also:
    • COMPLEVEL_PRBOOM_23X

      public static final int COMPLEVEL_PRBOOM_23X
      Compatibility Level PrBoom v2.3.X
      See Also:
    • COMPLEVEL_PRBOOM_240

      public static final int COMPLEVEL_PRBOOM_240
      Compatibility Level PrBoom v2.4.0
      See Also:
    • COMPLEVEL_CURRENT_PRBOOM

      public static final int COMPLEVEL_CURRENT_PRBOOM
      Compatibility Level PrBoom Current
      See Also:
    • COMPFLAG_TELEFRAG

      public static final int COMPFLAG_TELEFRAG
      Compatibility flag: Any monster can telefrag on MAP30.
      See Also:
    • COMPFLAG_DROPOFF

      public static final int COMPFLAG_DROPOFF
      Compatibility flag: Some objects never hang over tall ledges.
      See Also:
    • COMPFLAG_VILEGHOST

      public static final int COMPFLAG_VILEGHOST
      Compatibility flag: Arch-Vile resurrects invincible ghosts.
      See Also:
    • COMPFLAG_PAINLIMIT

      public static final int COMPFLAG_PAINLIMIT
      Compatibility flag: Pain Elementals limited to 21 lost souls.
      See Also:
    • COMPFLAG_LOSTSOULWALLS

      public static final int COMPFLAG_LOSTSOULWALLS
      Compatibility flag: Lost souls get stuck behind walls.
      See Also:
    • COMPFLAG_BLAZECLOSESOUND

      public static final int COMPFLAG_BLAZECLOSESOUND
      Compatibility flag: Blazing doors make double closing sounds.
      See Also:
    • COMPFLAG_DOORLIGHT

      public static final int COMPFLAG_DOORLIGHT
      Compatibility flag: Tagged doors don't trigger special lighting.
      See Also:
    • COMPFLAG_DOOMTRIGGERMODEL

      public static final int COMPFLAG_DOOMTRIGGERMODEL
      Compatibility flag: Use Doom's linedef trigger model
      See Also:
    • COMPFLAG_GOD

      public static final int COMPFLAG_GOD
      Compatibility flag: God mode isn't absolute (can still be killed by telefrag).
      See Also:
    • COMPFLAG_FALLOFF

      public static final int COMPFLAG_FALLOFF
      Compatibility flag: Objects don't fall under their own weight.
      See Also:
    • COMPFLAG_DOOMFLOORMOTION

      public static final int COMPFLAG_DOOMFLOORMOTION
      Compatibility flag: Use Doom's floor motion behavior.
      See Also:
    • COMPFLAG_SKYINVUL

      public static final int COMPFLAG_SKYINVUL
      Compatibility flag: Sky is unaffected by invulnerability.
      See Also:
    • COMPFLAG_PURSUIT

      public static final int COMPFLAG_PURSUIT
      Compatibility flag: Monsters don't give up pursuit of targets.
      See Also:
    • COMPFLAG_DOORSTUCK

      public static final int COMPFLAG_DOORSTUCK
      Compatibility flag: Monsters get stuck on doortracks.
      See Also:
    • COMPFLAG_STAYLIFT

      public static final int COMPFLAG_STAYLIFT
      Compatibility flag: Monsters randomly walk off of moving lifts.
      See Also:
    • COMPFLAG_DEADPLAYEREXIT

      public static final int COMPFLAG_DEADPLAYEREXIT
      Compatibility flag: Dead players can exit levels.
      See Also:
    • COMPFLAG_BUGGYSTAIRS

      public static final int COMPFLAG_BUGGYSTAIRS
      Compatibility flag: Use Doom's stairbuilding method.
      See Also:
    • COMPFLAG_INFCHEAT

      public static final int COMPFLAG_INFCHEAT
      Compatibility flag: Powerup cheats are not infinite duration.
      See Also:
    • COMPFLAG_ZEROTAGS

      public static final int COMPFLAG_ZEROTAGS
      Compatibility flag: Linedef effects still work with sector tag = 0.
      See Also:
    • COMPFLAG_DOOMCLIPPING

      public static final int COMPFLAG_DOOMCLIPPING
      Compatibility flag: Use Doom's movement clipping code.
      See Also:
    • COMPFLAG_DOOMRESPAWN

      public static final int COMPFLAG_DOOMRESPAWN
      Compatibility flag: Use Doom's respawn code.
      See Also:
    • COMPFLAG_BUGGYSOUND

      public static final int COMPFLAG_BUGGYSOUND
      Compatibility flag: Use Doom's sound code behavior.
      See Also:
    • COMPFLAG_666

      public static final int COMPFLAG_666
      Compatibility flag: All boss types can trigger tag 666 at ExM8.
      See Also:
    • COMPFLAG_SOULBOUNCE

      public static final int COMPFLAG_SOULBOUNCE
      Compatibility flag: Lost souls don't bounce off flat surfaces.
      See Also:
    • COMPFLAG_MASKEDANIM

      public static final int COMPFLAG_MASKEDANIM
      Compatibility flag: 2S middle textures do not animate.
      See Also:
    • COMPFLAG_LENGTH

      public static final int COMPFLAG_LENGTH
      Length of compatibility flags.
      See Also:
    • OPTION_FLAGS_LENGTH

      public static final int OPTION_FLAGS_LENGTH
      Length of option flag chunk in Boom DEMOs.
      See Also:
    • MAX_PLAYERS

      public static final int MAX_PLAYERS
      Maximum players.
      See Also:
    • BOOM_MIN_MAXPLAYERS

      public static final int BOOM_MIN_MAXPLAYERS
      Minimum maximum players in Boom (according to Boom source code).
      See Also:
    • MBF_SIGNATURE

      public static final byte[] MBF_SIGNATURE
      MBF Demo Signature
    • BOOM_SIGNATURE

      public static final byte[] BOOM_SIGNATURE
      Boom Demo Signature
  • Constructor Details

    • Demo

      public Demo()
      Creates a new, blank demo with default values. One player.
    • Demo

      public Demo(int players)
      Creates a new, blank demo with default values and a set amount of players.
      Parameters:
      players - the amount of players that this tracks.
  • Method Details

    • reset

      public void reset()
      Resets the contents of this demo.
    • getPlayers

      public int getPlayers()
      Returns:
      the amount of players in this demo.
    • getVersion

      public int getVersion()
      Gets the version of Doom that with which this demo was made. See the VERSION macros for the important values. This affects how the demo is exported if written to an output stream of some kind.
      Returns:
      the version value.
    • setVersion

      public void setVersion(int version)
      Sets the version of Doom that with which this demo was made. See the VERSION macros for the important values.

      This affects how the demo is exported if written to an output stream of some kind.

      Parameters:
      version - the version value.
      Throws:
      IllegalArgumentException - if version is outside the range 0 to 255.
    • getSkill

      public int getSkill()
      Gets the skill level that this demo is for. See the SKILL macros for the important values.
      Returns:
      the skill level value.
    • setSkill

      public void setSkill(int skill)
      Sets the skill level that this demo is for. See the SKILL macros for the important values.
      Parameters:
      skill - the skill level value.
      Throws:
      IllegalArgumentException - if skill is outside the range 0 to 4.
    • getEpisode

      public int getEpisode()
      Gets the episode that this demo is for.

      Doom 2, Hexen, and Strife do not have episodes, so this is 1 for those games.

      Returns:
      the episode number.
    • setEpisode

      public void setEpisode(int episode)
      Sets the episode that this demo is for.

      Doom 2, Hexen, and Strife do not have episodes, so this is 1 for those games.

      Parameters:
      episode - the episode number.
      Throws:
      IllegalArgumentException - if episode is outside the range 0 to 255.
    • getMap

      public int getMap()
      Returns:
      the map/mission number that this demo is for.
    • setMap

      public void setMap(int map)
      Sets the map/mission number that this demo is for.
      Parameters:
      map - the map number.
      Throws:
      IllegalArgumentException - if map is outside the range 0 to 255.
    • getGameMode

      public int getGameMode()
      Gets the game mode that this demo is for. See the MODE constants.
      Returns:
      the game mode value.
    • setGameMode

      public void setGameMode(int mode)
      Sets the game mode that this demo is for. See the MODE constants.
      Parameters:
      mode - the game mode value.
    • getMonsterRespawn

      public boolean getMonsterRespawn()
      Is monster respawning set for this demo?
      Returns:
      true if so, false if not.
    • setMonsterRespawn

      public void setMonsterRespawn(boolean respawn)
      Sets if monster respawning is set for this demo.
      Parameters:
      respawn - true if so, false if not.
    • getFastMonsters

      public boolean getFastMonsters()
      Is fast monsters set for this demo?
      Returns:
      true if so, false if not.
    • setFastMonsters

      public void setFastMonsters(boolean fast)
      Sets if fast monsters are set for this demo.
      Parameters:
      fast - true if so, false if not.
    • getNoMonsters

      public boolean getNoMonsters()
      Is "no monsters" set for this demo?
      Returns:
      true if so, false if not.
    • setNoMonsters

      public void setNoMonsters(boolean nomonsters)
      Sets the "no monsters" flag for this demo.
      Parameters:
      nomonsters - true if so, false if not.
    • getMonstersRememberTarget

      public boolean getMonstersRememberTarget()
      Gets if monsters remember their last target.
      Returns:
      true if so, false if not.
    • setMonstersRememberTarget

      public void setMonstersRememberTarget(boolean monstersRememberTarget)
      Sets if monsters remember their last target.
      Parameters:
      monstersRememberTarget - true if so, false if not.
    • getEnableFriction

      public boolean getEnableFriction()
      Gets if the friction specials are enabled.
      Returns:
      true if so, false if not.
    • setEnableFriction

      public void setEnableFriction(boolean enableFriction)
      Sets if the friction specials are enabled.
      Parameters:
      enableFriction - true if so, false if not.
    • getEnableWeaponRecoil

      public boolean getEnableWeaponRecoil()
      Gets if weapon recoil is enabled.
      Returns:
      true if so, false if not.
    • setEnableWeaponRecoil

      public void setEnableWeaponRecoil(boolean enableWeaponRecoil)
      Sets if weapon recoil is enabled.
      Parameters:
      enableWeaponRecoil - true if so, false if not.
    • getAllowPushers

      public boolean getAllowPushers()
      Gets if push/pull objects are enabled.
      Returns:
      true if so, false if not.
    • setAllowPushers

      public void setAllowPushers(boolean allowPushers)
      Sets if push/pull objects are enabled.
      Parameters:
      allowPushers - true if so, false if not.
    • getEnablePlayerBobbing

      public boolean getEnablePlayerBobbing()
      Gets if player bobbing is enabled.
      Returns:
      true if so, false if not.
    • setEnablePlayerBobbing

      public void setEnablePlayerBobbing(boolean enablePlayerBobbing)
      Sets if player bobbing is enabled.
      Parameters:
      enablePlayerBobbing - true if so, false if not.
    • getDemoInsurance

      public int getDemoInsurance()
      Gets what kind of "demo insurance" this is set for. See the DEMO_INSURANCE constants.
      Returns:
      the demo insurance value.
    • setDemoInsurance

      public void setDemoInsurance(int demoInsurance)
      Sets what kind of "demo insurance" this is set for. See the DEMO_INSURANCE constants.
      Parameters:
      demoInsurance - the new demo insurance value.
    • getRandomSeed

      public int getRandomSeed()
      Gets the random seeding number that this demo uses.
      Returns:
      the seed number.
    • setRandomSeed

      public void setRandomSeed(int randomSeed)
      Sets the random seeding number that this demo uses.
      Parameters:
      randomSeed - the new seed value.
    • getFriendFollowDistance

      public int getFriendFollowDistance()
      Gets the follow distance of allied CPU friends.
      Returns:
      the follow distance that was set.
    • setFriendFollowDistance

      public void setFriendFollowDistance(int friendFollowDistance)
      Sets the follow distance of allied CPU friends.
      Parameters:
      friendFollowDistance - the new follow distance.
      Throws:
      IllegalArgumentException - if the distance is outside the range 0 to 999.
    • getMonsterInfighting

      public boolean getMonsterInfighting()
      Gets if monster infighting is enabled.
      Returns:
      true if so, false if not.
    • setMonsterInfighting

      public void setMonsterInfighting(boolean monsterInfighting)
      Sets if monster infighting is enabled.
      Parameters:
      monsterInfighting - true if so, false if not.
    • getEnableDogs

      public boolean getEnableDogs()
      Gets if helper dogs are enabled.
      Returns:
      true if so, false if not.
    • setEnableDogs

      public void setEnableDogs(boolean enableDogs)
      Sets if helper dogs are enabled.
      Parameters:
      enableDogs - true if so, false if not.
    • getEnableMonkeys

      public boolean getEnableMonkeys()
      Gets if helper monkeys are enabled.
      Returns:
      true if so, false if not.
    • setEnableMonkeys

      public void setEnableMonkeys(boolean enableMonkeys)
      Sets if helper monkeys are enabled.
      Parameters:
      enableMonkeys - true if so, false if not.
    • getDogsJump

      public boolean getDogsJump()
      Gets if helper dogs jump.
      Returns:
      true if so, false if not.
    • setDogsJump

      public void setDogsJump(boolean dogsJump)
      Sets if helper dogs jump.
      Parameters:
      dogsJump - true if so, false if not.
    • getMonsterBacking

      public boolean getMonsterBacking()
      Gets if monster backing is enabled.
      Returns:
      true if so, false if not.
    • setMonsterBacking

      public void setMonsterBacking(boolean monsterBacking)
      Sets if monster backing is enabled.
      Parameters:
      monsterBacking - true if so, false if not.
    • getMonstersAvoidHazards

      public boolean getMonstersAvoidHazards()
      Gets if monsters avoid hazardous areas.
      Returns:
      true if so, false if not.
    • setMonstersAvoidHazards

      public void setMonstersAvoidHazards(boolean monstersAvoidHazards)
      Sets if monsters avoid hazardous areas.
      Parameters:
      monstersAvoidHazards - true if so, false if not.
    • getMonsterFriction

      public boolean getMonsterFriction()
      Gets if monsters are susceptible to environmental friction.
      Returns:
      true if so, false if not.
    • setMonsterFriction

      public void setMonsterFriction(boolean monsterFriction)
      Sets if monsters are susceptible to environmental friction.
      Parameters:
      monsterFriction - true if so, false if not.
    • getHelperCount

      public int getHelperCount()
      Returns:
      how many helpers are spawned.
    • setHelperCount

      public void setHelperCount(int helperCount)
      Sets how many helpers are spawned.
      Parameters:
      helperCount - the amount of helpers.
    • getForceOldBSP

      public boolean getForceOldBSP()
      Gets if old BSP methods are forced.
      Returns:
      true if so, false if not.
    • setForceOldBSP

      public void setForceOldBSP(boolean forceOldBSP)
      Sets if old BSP methods are forced.
      Parameters:
      forceOldBSP - true if so, false if not.
    • getViewpoint

      public int getViewpoint()
      Gets the player viewpoint index that this demo is being played back from. Zero is player 1.
      Returns:
      the corresponding viewpoint index.
    • setViewpoint

      public void setViewpoint(int viewpoint)
      Sets the player viewpoint index that this demo is being played back from. Zero is player 1.
      Parameters:
      viewpoint - the new viewpoint index.
      Throws:
      IllegalArgumentException - if viewpoint is outside the range 0 to 255.
    • getCompatibilityLevel

      public int getCompatibilityLevel()
      Gets the demo's stored compatibility level. Only useful if this is a Boom-format Demo. See the COMPLEVEL constants for more info.
      Returns:
      the current compatibility level.
    • setCompatibilityLevel

      public void setCompatibilityLevel(int compatibilityLevel)
      Sets the demo's stored compatibility level. This affects how the demo is exported if written to an output stream of some kind. See the COMPLEVEL constants for more info.
      Parameters:
      compatibilityLevel - the new level.
    • getCompatibilityFlag

      public boolean getCompatibilityFlag(int flag)
      Gets a compatibility flag setting.
      Parameters:
      flag - the flag index (see COMPATFLAG constants).
      Returns:
      true if set, false if not.
      Throws:
      ArrayIndexOutOfBoundsException - if flag is less than 0 or greater than or equal to 32.
    • setCompatibilityFlag

      public void setCompatibilityFlag(int flag, boolean value)
      Sets a compatibility flag setting. This affects how the demo is exported if written to an output stream of some kind.
      Parameters:
      flag - the flag to set (see COMPATFLAG constants).
      value - true to set, false to unset.
      Throws:
      ArrayIndexOutOfBoundsException - if flag is less than 0 or greater than or equal to 32.
    • getTicCount

      public int getTicCount()
      Returns:
      how many game tics were recorded in this demo.
    • getLength

      public double getLength()
      Returns:
      how many seconds this demo lasts (approximate).
    • getTic

      public Demo.Tic getTic(int tic, int player)
      Returns a Tic at a particular gametic.
      Parameters:
      tic - the tic index.
      player - the player index.
      Returns:
      the corresponding Tic or null if out of range.
      Throws:
      ArrayIndexOutOfBoundsException - if player is out of range.
    • getTic

      public Demo.Tic getTic(int tic)
      Gets a demo Tic at a particular gametic, first player only.
      Parameters:
      tic - the tic index.
      Returns:
      the corresponding Tic or null if out of range.
      See Also:
    • addTic

      public void addTic(Demo.Tic... tics)
      Adds a single tic for a set of players. If the amount of tics to add does not equal the number of players,
      Parameters:
      tics - the set of tic data to add for one player.
      Throws:
      IllegalArgumentException - if the amount of tics to add is not equal to the number of players.
    • iterator

      public Iterator<Demo.Tic[]> iterator()
      Specified by:
      iterator in interface Iterable<Demo.Tic[]>
    • readBytes

      public void readBytes(InputStream in) throws IOException
      Description copied from interface: BinaryObject
      Reads from an InputStream and sets this object's fields. Only reads the amount of bytes that it takes to read a single instance of the object. Note that not every object may have a consistent length!
      Specified by:
      readBytes in interface BinaryObject
      Parameters:
      in - the InputStream to read from.
      Throws:
      IOException - if a read error occurs.
    • writeBytes

      public void writeBytes(OutputStream out) throws IOException
      Description copied from interface: BinaryObject
      Writes this object to an OutputStream.
      Specified by:
      writeBytes in interface BinaryObject
      Parameters:
      out - the OutputStream to write to.
      Throws:
      IOException - if a write error occurs.
    • toString

      public String toString()
      Overrides:
      toString in class Object