doom

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KEY_RIGHTARROW = 0xae
	KEY_LEFTARROW  = 0xac
	KEY_UPARROW    = 0xad
	KEY_DOWNARROW  = 0xaf
	KEY_STRAFE_L   = 0xa0
	KEY_STRAFE_R   = 0xa1
	KEY_USE        = 0xa2
	KEY_FIRE       = 0xa3
	KEY_ESCAPE     = 27
	KEY_ENTER      = 13
	KEY_TAB        = 9
	KEY_F1         = (0x80 + 0x3b)
	KEY_F2         = (0x80 + 0x3c)
	KEY_F3         = (0x80 + 0x3d)
	KEY_F4         = (0x80 + 0x3e)
	KEY_F5         = (0x80 + 0x3f)
	KEY_F6         = (0x80 + 0x40)
	KEY_F7         = (0x80 + 0x41)
	KEY_F8         = (0x80 + 0x42)
	KEY_F9         = (0x80 + 0x43)
	KEY_F10        = (0x80 + 0x44)
	KEY_F11        = (0x80 + 0x57)
	KEY_F12        = (0x80 + 0x58)
	KEY_BACKSPACE  = 0x7f
	KEY_PAUSE      = 0xff
	KEY_EQUALS     = 0x3d
	KEY_MINUS      = 0x2d
	KEY_RSHIFT     = (0x80 + 0x36)
	KEY_RCTRL      = (0x80 + 0x1d)
	KEY_RALT       = (0x80 + 0x38)
	KEY_LALT       = KEY_RALT
	KEY_CAPSLOCK   = (0x80 + 0x3a)
)

Doom key codes (from doomkeys.h)

View Source
const (
	MIDINoteOff       = 0x80
	MIDINoteOn        = 0x90
	MIDIControlChange = 0xB0
	MIDIProgramChange = 0xC0
)

MIDI event types

Variables

View Source
var (
	// ErrGameExit is returned when the game exits normally
	ErrGameExit = errors.New("game exit")

	// ErrMissingExports is returned when required WASM exports are missing
	ErrMissingExports = errors.New("missing required WASM exports")

	// ErrInvalidScreenDimensions is returned when screen dimensions are invalid
	ErrInvalidScreenDimensions = errors.New("invalid screen dimensions")

	// ErrNoScreenBuffer is returned when screen buffer pointer is not available
	ErrNoScreenBuffer = errors.New("no screen buffer pointer returned")

	// ErrReadScreenBuffer is returned when reading screen buffer fails
	ErrReadScreenBuffer = errors.New("failed to read screen buffer")

	// ErrMIDITooShort is returned when MIDI data is too short
	ErrMIDITooShort = errors.New("MIDI data too short")

	// ErrMIDIInvalidHeader is returned when MIDI header is invalid
	ErrMIDIInvalidHeader = errors.New("invalid MIDI header")

	// ErrNotMIDI is returned when data is not a MIDI file
	ErrNotMIDI = errors.New("not a MIDI file")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	WASMData      []byte
	IWADData      []byte
	IWADName      string
	SoundFontData []byte
	Verbose       bool
	ExtraArgs     []string
}

Config holds the configuration for a new game

type Game

type Game struct {
	// contains filtered or unexported fields
}

Game holds the WASM runtime and game state

func NewGame

func NewGame(cfg Config) (*Game, error)

NewGame creates a new DOOM game instance

func (*Game) Close

func (g *Game) Close() error

Close cleans up resources

func (*Game) FrameReady

func (g *Game) FrameReady() bool

FrameReady returns true if a new frame is ready

func (*Game) GetScreenBuffer

func (g *Game) GetScreenBuffer() ([]byte, error)

GetScreenBuffer returns the screen pixels as RGBA

func (*Game) ScreenHeight

func (g *Game) ScreenHeight() int

ScreenHeight returns the screen height

func (*Game) ScreenWidth

func (g *Game) ScreenWidth() int

ScreenWidth returns the screen width

func (*Game) Tick

func (g *Game) Tick() error

Tick runs one game frame

func (*Game) WindowTitle

func (g *Game) WindowTitle() string

WindowTitle returns the current window title

type GameEngine

type GameEngine interface {
	// Tick runs one game frame
	Tick() error

	// GetScreenBuffer returns the screen pixels as RGBA
	GetScreenBuffer() ([]byte, error)

	// ScreenWidth returns the screen width
	ScreenWidth() int

	// ScreenHeight returns the screen height
	ScreenHeight() int

	// FrameReady returns true if a new frame is ready
	FrameReady() bool

	// WindowTitle returns the current window title
	WindowTitle() string

	// Close cleans up resources
	Close() error
}

GameEngine defines the interface for a DOOM game engine

type KeyEvent

type KeyEvent struct {
	Pressed bool
	Key     byte
}

KeyEvent represents a keyboard event

type KeyboardState

type KeyboardState struct {
	// contains filtered or unexported fields
}

KeyboardState tracks the state of all keys

func NewKeyboardState

func NewKeyboardState() *KeyboardState

NewKeyboardState creates a new keyboard state tracker

func (*KeyboardState) GetEvent

func (k *KeyboardState) GetEvent() *KeyEvent

GetEvent returns the next key event, or nil if none

func (*KeyboardState) HasEvents

func (k *KeyboardState) HasEvents() bool

HasEvents returns true if there are pending events

func (*KeyboardState) Update

func (k *KeyboardState) Update()

Update checks for key state changes and generates events

type MIDIEvent

type MIDIEvent struct {
	Time       float64 // Time in seconds
	Type       int
	Channel    int
	Key        int
	Velocity   int
	Program    int
	Controller int
	Value      int
}

MIDIEvent represents a MIDI event

type MIDIFile

type MIDIFile struct {
	Events []MIDIEvent
}

MIDIFile represents a parsed MIDI file

func ParseMIDI

func ParseMIDI(data []byte) (*MIDIFile, error)

ParseMIDI parses MIDI data

type MusicStream

type MusicStream struct {
	// contains filtered or unexported fields
}

MusicStream implements io.Reader for SoundFont audio playback

func (*MusicStream) IsPlaying

func (m *MusicStream) IsPlaying() bool

func (*MusicStream) Read

func (m *MusicStream) Read(buf []byte) (int, error)

func (*MusicStream) SetPaused

func (m *MusicStream) SetPaused(paused bool)

func (*MusicStream) SetVolume

func (m *MusicStream) SetVolume(vol float64)

func (*MusicStream) Stop

func (m *MusicStream) Stop()

type Runtime

type Runtime struct {
	// contains filtered or unexported fields
}

Runtime manages the WASM runtime and module

func NewRuntime

func NewRuntime(cfg RuntimeConfig, game *Game) (*Runtime, error)

NewRuntime creates a new WASM runtime with the DOOM module

func (*Runtime) Close

func (r *Runtime) Close() error

Close cleans up the runtime

func (*Runtime) Context

func (r *Runtime) Context() context.Context

Context returns the runtime context

func (*Runtime) ExportedFunction

func (r *Runtime) ExportedFunction(name string) api.Function

ExportedFunction returns an exported function by name

func (*Runtime) Memory

func (r *Runtime) Memory() api.Memory

Memory returns the WASM memory

func (*Runtime) Module

func (r *Runtime) Module() api.Module

Module returns the WASM module

type RuntimeConfig

type RuntimeConfig struct {
	WASMData []byte
	IWADData []byte
	IWADName string
	Args     []string
	Verbose  bool
}

RuntimeConfig holds configuration for creating a runtime

type SoundConfig

type SoundConfig struct {
	SoundFontPath string
	SoundFontData []byte
	Verbose       bool
}

SoundConfig holds configuration for creating a sound system

type SoundPlayer

type SoundPlayer interface {
	// StartSound plays a sound effect
	StartSound(id, channel, vol, sep int, data []byte) int

	// StopSound stops a sound effect
	StopSound(channel int)

	// SoundIsPlaying returns true if a sound is playing
	SoundIsPlaying(channel int) bool

	// PlayMusic starts MIDI music playback
	PlayMusic(data []byte, looping bool)

	// StopMusic stops music playback
	StopMusic()

	// SetMusicVolume sets the music volume
	SetMusicVolume(volume int)

	// PauseMusic pauses music playback
	PauseMusic()

	// ResumeMusic resumes music playback
	ResumeMusic()

	// MusicIsPlaying returns true if music is playing
	MusicIsPlaying() bool

	// Close cleans up resources
	Close()
}

SoundPlayer defines the interface for sound playback

type SoundSystem

type SoundSystem struct {
	// contains filtered or unexported fields
}

SoundSystem handles sound effects and music playback

func NewSoundSystem

func NewSoundSystem(cfg SoundConfig) (*SoundSystem, error)

NewSoundSystem creates a new sound system

func NewSoundSystemFromData

func NewSoundSystemFromData(soundFontData []byte, verbose bool) (*SoundSystem, error)

NewSoundSystemFromData creates a new sound system from embedded data (deprecated: use NewSoundSystem)

func (*SoundSystem) Close

func (s *SoundSystem) Close()

Close cleans up the sound system

func (*SoundSystem) MusicIsPlaying

func (s *SoundSystem) MusicIsPlaying() bool

func (*SoundSystem) PauseMusic

func (s *SoundSystem) PauseMusic()

func (*SoundSystem) PlayMusic

func (s *SoundSystem) PlayMusic(data []byte, looping bool)

PlayMusic starts MIDI music playback

func (*SoundSystem) ResumeMusic

func (s *SoundSystem) ResumeMusic()

func (*SoundSystem) SetMusicVolume

func (s *SoundSystem) SetMusicVolume(volume int)

func (*SoundSystem) SoundIsPlaying

func (s *SoundSystem) SoundIsPlaying(channel int) bool

func (*SoundSystem) StartSound

func (s *SoundSystem) StartSound(id, channel, vol, sep int, data []byte) int

StartSound plays a sound effect

func (*SoundSystem) StopMusic

func (s *SoundSystem) StopMusic()

func (*SoundSystem) StopSound

func (s *SoundSystem) StopSound(channel int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL