Module: Doom

Defined in:
lib/doom/benchmark.rb,
lib/doom.rb,
lib/doom/version.rb,
lib/doom/map/data.rb,
lib/doom/wad/flat.rb,
lib/doom/benchmark.rb,
lib/doom/game/menu.rb,
lib/doom/wad/patch.rb,
lib/doom/wad/sound.rb,
lib/doom/game/world.rb,
lib/doom/net/client.rb,
lib/doom/wad/reader.rb,
lib/doom/wad/sprite.rb,
lib/doom/game/combat.rb,
lib/doom/game/player.rb,
lib/doom/game/random.rb,
lib/doom/game/ticcmd.rb,
lib/doom/net/session.rb,
lib/doom/render/font.rb,
lib/doom/wad/palette.rb,
lib/doom/wad/texture.rb,
lib/doom/net/lockstep.rb,
lib/doom/net/protocol.rb,
lib/doom/platform/sdl.rb,
lib/doom/wad/colormap.rb,
lib/doom/game/geometry.rb,
lib/doom/game/snapshot.rb,
lib/doom/net/transport.rb,
lib/doom/wad_downloader.rb,
lib/doom/game/animations.rb,
lib/doom/game/monster_ai.rb,
lib/doom/game/state_hash.rb,
lib/doom/net/game_server.rb,
lib/doom/render/renderer.rb,
lib/doom/game/item_pickup.rb,
lib/doom/wad/hud_graphics.rb,
lib/doom/game/intermission.rb,
lib/doom/game/player_state.rb,
lib/doom/game/sound_engine.rb,
lib/doom/render/status_bar.rb,
lib/doom/render/world_mesh.rb,
lib/doom/net/desync_monitor.rb,
lib/doom/render/screen_melt.rb,
lib/doom/game/player_physics.rb,
lib/doom/game/sector_actions.rb,
lib/doom/game/sector_effects.rb,
lib/doom/platform/gosu_window.rb,
lib/doom/platform/window_logic.rb,
lib/doom/render/ray_tracing/bvh.rb,
lib/doom/render/weapon_renderer.rb,
lib/doom/render/renderer_factory.rb,
lib/doom/render/zbuffer_renderer.rb,
lib/doom/game/framebuffer_blitter.rb,
lib/doom/render/hardware_renderer.rb,
lib/doom/render/ray_tracing_renderer.rb,
lib/doom/render/spinel_native/kernel.rb,
lib/doom/render/spinel_native_renderer.rb,
lib/doom/render/ray_tracing/texture_atlas.rb,
lib/doom/render/ray_tracing/material_state.rb

Overview

Stub Gosu so the renderer's Platform module can load without the gem.

Defined Under Namespace

Modules: Benchmark, Game, Map, Net, Platform, Render, Wad Classes: Error, WadDownloader

Constant Summary collapse

VERSION =
'0.11.0'

Class Method Summary collapse

Class Method Details

.run(wad_path, map_name: 'E1M1', rubykaigi: false, net: nil, frag_limit: nil, renderer: :classic) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/doom.rb', line 59

def run(wad_path, map_name: 'E1M1', rubykaigi: false, net: nil, frag_limit: nil, renderer: :classic)
  return run_server(wad_path, map_name, net, frag_limit) if net && net[:role] == :serve
  return run_client(wad_path, map_name, net, renderer) if net && net[:role] == :join

  session = build_session(net, map_name)
  if session
    # The host decides the map, seed and mode; a client is told them. Wait
    # for that before loading anything, so both sides load the same level.
    map_name = wait_for_session(session) || map_name
  end

  puts "Loading WAD: #{wad_path}"
  wad = Wad::Reader.new(wad_path)
  puts "  #{wad.type}: #{wad.num_lumps} lumps"

  # If it's a PWAD, we need a base IWAD for resources (palette, textures, etc.)
  if wad.pwad?
    iwad_path = find_iwad
    unless iwad_path
      raise Error,
            'PWAD requires a base IWAD (doom1.wad). Place it in the current directory or ~/.doom/'
    end

    puts "  PWAD detected, loading base IWAD: #{iwad_path}"
    base_wad = Wad::Reader.new(iwad_path)
    base_wad.merge_pwad(wad)
    wad = base_wad

    # Auto-detect map name from PWAD lumps
    pwad_map = wad.directory.find { |e| e.name =~ /^(E\dM\d|MAP\d\d)$/ }
    map_name = pwad_map.name if pwad_map
    puts "  Using map: #{map_name}"
  end

  puts 'Loading palette...'
  palette = Wad::Palette.load(wad)

  puts 'Loading colormap...'
  colormap = Wad::Colormap.load(wad)

  puts 'Loading flats...'
  flats = Wad::Flat.load_all(wad)
  puts "  #{flats.size} flats"

  puts 'Loading textures...'
  textures = Wad::TextureManager.new(wad)
  puts "  #{textures.textures.size} textures, #{textures.pnames.size} patches"

  puts 'Loading sprites...'
  sprites = Wad::SpriteManager.new(wad)

  puts 'Loading HUD graphics...'
  hud_graphics = Wad::HudGraphics.new(wad)

  puts "Loading map #{map_name}..."
  map = Map::MapData.load(wad, map_name)
  puts "  #{map.vertices.size} vertices, #{map.linedefs.size} linedefs"
  puts "  #{map.segs.size} segs, #{map.subsectors.size} subsectors, #{map.nodes.size} nodes"

  # Find player start
  player_start = map.player_start
  if player_start
    puts "  Player start: (#{player_start.x}, #{player_start.y}) angle #{player_start.angle}"
  else
    puts '  Warning: No player start found!'
    Map::Thing.new(0, 0, 90, 1, 0)
  end

  puts 'Initializing animations...'
  flat_names = flats.map(&:name)
  animations = Game::Animations.new(textures.texture_names, flat_names)

  puts 'Creating renderer...'
  # No initial camera pose needed: the world owns the player, and draw aims
  # the camera at it every frame.
  renderer = Render::RendererFactory.build(renderer, wad, map, textures, palette, colormap,
                                           flats, sprites, animations)

  puts 'Building world...'
  sound_mgr = Wad::SoundManager.new(wad)
  sound_engine = Game::SoundEngine.new(sound_mgr)
  # One RNG shared by every subsystem that touches game state -- its index is
  # part of the simulation, so all peers must draw from the same sequence.
  # In a session the seed and mode come from the host, so every peer builds
  # the same world; solo play picks its own.
  random = Game::Random.new(session ? session.seed : 0)
  world = Game::World.new(map, sprites: sprites, sound: sound_engine, random: random,
                               mode: session ? session.mode : :coop,
                               frag_limit: frag_limit)
  ids = session ? session.player_ids : [0]
  ids.each { |id| world.add_player(id: id) }
  player = world.player(session ? session.local_id : 0)
  player_state = player.state

  puts 'Setting up HUD...'
  status_bar = Render::StatusBar.new(hud_graphics, player_state)
  weapon_renderer = Render::WeaponRenderer.new(hud_graphics, player_state)
  doom_font = Render::Font.new(wad, hud_graphics)
  menu = Game::Menu.new(wad, hud_graphics, doom_font)
  menu.instance_variable_set(:@state, Game::Menu::STATE_NONE) if ENV['DOOM_DEBUG_POSE']

  # RubyKaigi mode: god mode, no aggression, benchmark HUD
  if rubykaigi
    menu.options[:rubykaigi_mode] = true
    menu.options[:god_mode] = true
  end

  puts 'Starting game window...'
  window = Platform::GosuWindow.new(renderer, palette, world, status_bar, weapon_renderer,
                                    animations, menu, sound_engine, session: session)
  # A networked game skips the title screen: the other players are already
  # waiting, and there is nothing to configure that the host has not set.
  menu.instance_variable_set(:@state, Game::Menu::STATE_NONE) if session
  window.show
ensure
  session&.quit
end