shadowengine2d 2.0.0

A comprehensive 2D game engine built in Rust with ECS, rendering, audio, assets, animations, and scene management
Documentation
/*
 * MIT License
 * 
 * Copyright (c) 2025 ShadowEngine2D
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

use std::sync::atomic::{AtomicBool, Ordering};

static OUTPUT_ENABLED: AtomicBool = AtomicBool::new(true);

pub struct Output;

impl Output {

    pub fn set_enabled(enabled: bool) {
        OUTPUT_ENABLED.store(enabled, Ordering::Relaxed);
    }

    pub fn is_enabled() -> bool {
        OUTPUT_ENABLED.load(Ordering::Relaxed)
    }

    pub fn debug(message: &str) {
        if Self::is_enabled() {
            println!("[DEBUG] {}", message);
        }
    }

    pub fn info(message: &str) {
        if Self::is_enabled() {
            println!("[INFO] {}", message);
        }
    }

    pub fn warn(message: &str) {
        if Self::is_enabled() {
            println!("[WARN] {}", message);
        }
    }

    pub fn error(message: &str) {
        println!("[ERROR] {}", message);
    }

    pub fn print_fmt<T: std::fmt::Display>(level: &str, message: T) {
        if Self::is_enabled() {
            println!("[{}] {}", level, message);
        }
    }

    #[deprecated(note = "Use Output::set_enabled instead")]
    pub fn set_toggle(enabled: bool) {
        Self::set_enabled(enabled);
    }

    #[deprecated(note = "Use Output::debug instead")]
    pub fn print(message: &str) {
        Self::debug(message);
    }
}

#[macro_export]
macro_rules! debug {
    ($($arg:tt)*) => {
        if $crate::Output::Output::is_enabled() {
            println!("[DEBUG] {}", format!($($arg)*));
        }
    };
}

#[macro_export]
macro_rules! info {
    ($($arg:tt)*) => {
        if $crate::Output::Output::is_enabled() {
            println!("[INFO] {}", format!($($arg)*));
        }
    };
}

#[macro_export]
macro_rules! warn {
    ($($arg:tt)*) => {
        if $crate::Output::Output::is_enabled() {
            println!("[WARN] {}", format!($($arg)*));
        }
    };
}

#[macro_export]
macro_rules! error {
    ($($arg:tt)*) => {
        println!("[ERROR] {}", format!($($arg)*));
    };
}

#[deprecated(note = "Use Output::debug instead")]
pub fn output_print(message: &str) {
    Output::debug(message);
}

#[deprecated(note = "Use Output::is_enabled instead")]
pub fn output_enabled() -> bool {
    Output::is_enabled()
}