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/>.

//! Quake items.
//!
//! Taken from <https://github.com/id-Software/Quake/>.

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

/// The `CMP_NONE` macro.
///
/// # Synopsis
///
/// ```c
/// // Quake/WinQuake/wad.h
///
/// #define CMP_NONE        0
/// ```
pub(in crate::wad) const CMP_NONE: i8 = 0;

/// The `CMP_LZSS` macro.
///
/// # Synopsis
///
/// ```c
/// // Quake/WinQuake/wad.h
///
/// #define CMP_LZSS        1
/// ```
pub(in crate::wad) const CMP_LZSS: i8 = 1;

/// The `TYP_NONE` macro.
///
/// # Synopsis
///
/// ```c
/// // Quake/WinQuake/wad.h
///
/// #define TYP_NONE        0
/// ```
pub(in crate::wad) const TYP_NONE: i8 = 0;

/// The `TYP_LABEL` macro.
///
/// # Synopsis
///
/// ```c
/// // Quake/WinQuake/wad.h
///
/// #define TYP_LABEL       1
/// ```
pub(in crate::wad) const TYP_LABEL: i8 = 1;

/// The `TYP_LUMPY` macro.
///
/// # Synopsis
///
/// ```c
/// // Quake/WinQuake/wad.h
///
/// #define TYP_LUMPY       64              // 64 + grab command number
/// ```
#[expect(dead_code)]
pub(in crate::wad) const TYP_LUMPY: i8 = 64;

/// The `TYP_PALETTE` macro.
///
/// # Synopsis
///
/// ```c
/// // Quake/WinQuake/wad.h
///
/// #define TYP_PALETTE     64
/// ```
pub(in crate::wad) const TYP_PALETTE: i8 = 64;

/// The `TYP_QTEX` macro.
///
/// # Synopsis
///
/// ```c
/// // Quake/WinQuake/wad.h
///
/// #define TYP_QTEX        65
/// ```
pub(in crate::wad) const TYP_QTEX: i8 = 65;

/// The `TYP_QPIC` macro.
///
/// # Synopsis
///
/// ```c
/// // Quake/WinQuake/wad.h
///
/// #define TYP_QPIC        66
/// ```
pub(in crate::wad) const TYP_QPIC: i8 = 66;

/// The `TYP_SOUND` macro.
///
/// # Synopsis
///
/// ```c
/// // Quake/WinQuake/wad.h
///
/// #define TYP_SOUND       67
/// ```
pub(in crate::wad) const TYP_SOUND: i8 = 67;

/// The `TYP_MIPTEX` macro.
///
/// # Synopsis
///
/// ```c
/// // Quake/WinQuake/wad.h
///
/// #define TYP_MIPTEX      68
/// ```
pub(in crate::wad) const TYP_MIPTEX: i8 = 68;

/// The `byte` type alias.
///
/// # Synopsis
///
/// ```c
/// // Quake/WinQuake/common.h
///
/// typedef unsigned char       byte
/// ```
#[allow(non_camel_case_types)]
pub(in crate::wad) type byte = u8;

/// The `qpic_t` structure.
///
/// # Synopsis
///
/// ```c
/// // Quake/WinQuake/wad.h
///
/// typedef struct
/// {
///     int         width, height;
///     byte        data[4];            // variably sized
/// } qpic_t;
/// ```
#[expect(dead_code)]
#[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 qpic_t {
	pub width:  i32,
	pub height: i32,
	pub data:   [byte; 4],
}

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

unsafe impl Init for qpic_t {}

/// 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
/// // Quake/WinQuake/wad.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
/// // Quake/WinQuake/wad.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 {}