goldforge 0.8.1

Library for handling file formats used by GoldSrc and related engines.
Documentation
// Copyright 2025-2026 Gabriel Bjørnager Jensen.
//
// This Source Code Form is subject to the terms of
// the Mozilla Public License, v. 2.0. If a copy of
// the MPL was not distributed with this file, you
// can obtain one at:
// <https://mozilla.org/MPL/2.0/>.

//! Half-Life items.
//!
//! Taken from <https://github.com/ValveSoftware/halflife/>.

use oct::{FromOcts, Immutable, Init, Zeroable};

/// The `CMP_NONE` macro.
///
/// Note that this constant is virtually identical
/// to [`quake::CMP_NONE`].
///
/// [`quake::CMP_NONE`]: crate::wad::ffi::quake::CMP_NONE
///
/// # Synopsis
///
/// ```c
/// // halflife/utils/common/wadlib.h
///
/// #define CMP_NONE        0
/// ```
#[expect(dead_code)]
pub(in crate::wad) const CMP_NONE: i8 = 0;

/// The `CMP_LZSS` macro.
///
/// Note that this constant is virtually identical
/// to [`quake::CMP_LZSS`].
///
/// [`quake::CMP_LZSS`]: crate::wad::ffi::quake::CMP_LZSS
///
/// # Synopsis
///
/// ```c
/// // halflife/utils/common/wadlib.h
///
/// #define CMP_LZSS        1
/// ```
#[expect(dead_code)]
pub(in crate::wad) const CMP_LZSS: i8 = 1;

/// The `TYP_NONE` macro.
///
/// Note that this constant is virtually identical
/// to [`quake::TYP_NONE`].
///
/// [`quake::TYP_NONE`]: crate::wad::ffi::quake::TYP_NONE
///
/// # Synopsis
///
/// ```c
/// // halflife/utils/common/wadlib.h
///
/// #define TYP_NONE        0
/// ```
#[expect(dead_code)]
pub(in crate::wad) const TYP_NONE: i8 = 0;

/// The `TYP_LABEL` macro.
///
/// Note that this constant is virtually identical
/// to [`quake::TYP_LABEL`].
///
/// [`quake::TYP_LABEL`]: crate::wad::ffi::quake::TYP_LABEL
///
/// # Synopsis
///
/// ```c
/// // halflife/utils/common/wadlib.h
///
/// #define TYP_LABEL       1
/// ```
#[expect(dead_code)]
pub(in crate::wad) const TYP_LABEL: i8 = 1;

/// The `TYP_LUMPY` macro.
///
/// Note that this constant is virtually identical
/// to [`quake::TYP_LUMPY`].
///
/// [`quake::TYP_LUMPY`]: crate::wad::ffi::quake::TYP_LUMPY
///
/// # Synopsis
///
/// ```c
/// // halflife/utils/common/wadlib.h
///
/// #define TYP_LUMPY       64              // 64 + grab command number
/// ```
#[expect(dead_code)]
pub(in crate::wad) const TYP_LUMPY: i8 = 64;

/// The `wadinfo_t` structure.
///
/// Note that this structure is virtually identical
/// to [`doom::wadinfo_t`].
///
/// [`doom::wadinfo_t`]: crate::wad::ffi::doom::wadinfo_t
///
/// # Synopsis
///
/// ```c
/// // halflife/utils/common/wadlib.h
///
/// typedef struct
/// {
///     char        identification[4];      // should be WAD2 or 2DAW
///     int         numlumps;
///     int         infotableofs;
/// } wadinfo_t;
/// ```
#[allow(clippy::missing_docs_in_private_items)]
#[allow(non_camel_case_types)]
#[repr(C, packed)]
#[derive(
	Clone,
	Copy,
	Debug,
	FromOcts,
	Immutable,
	Zeroable,
)]
pub(in crate::wad) struct wadinfo_t {
	pub identification: [i8; 4],
	pub numlumps:       i32,
	pub infotableofs:   i32,
}

impl Default for wadinfo_t {
	/// Equivalent to [`Bytes::zeroed`].
	#[inline(always)]
	fn default() -> Self {
		Self::zeroed()
	}
}

unsafe impl Init for wadinfo_t {}

/// The `lumpinfo_t` structure.
///
/// # Synopsis
///
/// ```c
/// // halflife/utils/common/wadlib.h
///
/// typedef struct
/// {
///     int         filepos;
///     int         disksize;
///     int         size;               // uncompressed
///     char        type;
///     char        compression;
///     char        pad1, pad2;
///     char        name[16];           // must be null terminated
/// } lumpinfo_t;
/// ```
#[allow(clippy::missing_docs_in_private_items)]
#[allow(non_camel_case_types)]
#[repr(C, packed)]
#[derive(
	Clone,
	Copy,
	Debug,
	FromOcts,
	Immutable,
	Zeroable,
)]
pub(in crate::wad) struct lumpinfo_t {
	pub filepos:     i32,
	pub disksize:    i32,
	pub size:        i32,
	pub r#type:      i8,
	pub compression: i8,
	pub pad1:        i8,
	pub pad2:        i8,
	pub name:        [i8; 16],
}

impl Default for lumpinfo_t {
	/// Equivalent to [`Bytes::zeroed`].
	#[inline(always)]
	fn default() -> Self {
		Self::zeroed()
	}
}

unsafe impl Init for lumpinfo_t {}