hotline_rs/
lib.rs

1/// Operating system module (Windows, Application, Input).
2pub mod os;
3
4/// Graphics and compute abstraction module.
5pub mod gfx;
6
7/// Hardware accelerated audio and video decoding.
8pub mod av;
9
10/// Image reading/writing module support for (png, jpg, bmp, tiff, dds).
11pub mod image;
12
13/// Imgui rendering and platform implementation.
14pub mod imgui;
15
16/// Immediate mode primitive rendering API.
17pub mod imdraw;
18
19/// High level graphics (data driven render pipelines, shaders, views).
20pub mod pmfx;
21
22/// Primitive geometry meshes (quad, cube, sphere, etc).
23pub mod primitives;
24
25/// Hotline clinet context contains an `App`, `Device`, `SwapChain` and main `Window` automatically setup
26/// It can load code dynamically from other `dylibs` or `dlls` abnd provides a very thin run loop for you to hook your own plugins into.
27pub mod client;
28
29/// Trait's and macros to assist the creation of plugins in other dynamically loaded libraries
30pub mod plugin;
31
32/// Module to aid data / code file watching, rebuilding and reloading
33pub mod reloader;
34
35/// Shared types and resources for use with bevy ecs
36pub mod ecs_base;
37
38/// Use bitmask for flags
39#[macro_use]
40extern crate bitflags;
41
42/// Generic errors for modules to define their own
43pub struct Error {
44    pub msg: String,
45}
46
47/// Generic debug for errors
48impl std::fmt::Debug for Error {
49    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
50        write!(f, "{}", self.msg)
51    }
52}
53
54impl<T> From<T> for Error where T: ToString {
55    fn from(err: T) -> Error {
56        Error {
57            msg: err.to_string()
58        }
59    }
60}
61
62/// Returns the config name for the current configuration, this is useful to local items in target/debug
63#[cfg(debug_assertions)]
64pub const fn get_config_name() -> &'static str {
65    "debug"
66}
67
68/// Returns the config name for the current configuration, this is useful to local items in target/release
69#[cfg(not(debug_assertions))]
70pub const fn get_config_name() -> &'static str {
71    "release"
72}
73
74/// Return an absolute path for a resource given the relative resource name from the /hotline-data/src_data dir
75pub fn get_src_data_path(asset: &str) -> String {
76    let exe_path = std::env::current_exe().ok().unwrap();
77    // back 2 (client)
78    let data_path = exe_path.parent().unwrap().join("../../hotline-data/src");
79    if data_path.join(asset).exists() {
80        let path = std::fs::canonicalize(data_path.join(asset)).unwrap();
81        String::from(path.to_str().unwrap()).replace("\\\\?\\", "")
82    }
83    else {
84        // back 3 (examples)
85        let data_path = exe_path.parent().unwrap().join("../../../hotline-data/src");
86        if data_path.join(asset).exists() {
87            let path = std::fs::canonicalize(data_path.join(asset)).unwrap();
88            String::from(path.to_str().unwrap()).replace("\\\\?\\", "")
89        }
90        else {
91            panic!();
92        }
93    }
94}
95
96/// Return an absolute path for a resource given the relative resource name from the /data dir
97pub fn get_data_path(asset: &str) -> String {
98    let exe_path = std::env::current_exe().ok().unwrap();
99    // back 1 (target/data)
100    let data_path = exe_path.parent().unwrap().join("../data");
101    if data_path.exists() {
102        let path = std::fs::canonicalize(data_path.join(asset));
103        if path.is_err() {
104            println!("{:?}", data_path);
105            println!("{}", asset);
106        }
107        String::from(path.unwrap().to_str().unwrap()).replace("\\\\?\\", "")
108    }
109    else {
110        // back 2 (examples)
111        let data_path = exe_path.parent().unwrap().join("../../data");
112        if data_path.exists() {
113            let path = std::fs::canonicalize(data_path.join(asset)).unwrap();
114            String::from(path.to_str().unwrap()).replace("\\\\?\\", "")
115        }
116        else {
117            // unable to locate data
118            panic!()
119        }
120    }
121}
122
123/// Return an absolute path for a resource given the relative path from the /executable dir
124pub fn get_exe_path(asset: &str) -> String {
125    let exe_path = std::env::current_exe().ok().unwrap();
126    String::from(exe_path.join(asset).to_str().unwrap())
127}
128
129/// Recursivley get files from folder as a vector
130fn get_files_recursive(dir: &str, mut files: Vec<String>) -> Vec<String> {
131    let paths = std::fs::read_dir(dir).unwrap();
132    for path in paths {
133        let path = path.unwrap().path();
134        if std::fs::read_dir(&path).is_ok() {
135            files = get_files_recursive(path.to_str().unwrap(), files);
136        }
137        else {
138            files.push(path.to_str().unwrap().to_string());
139        }   
140    }
141    files
142}
143
144/// This is a hardcoded compile time selection of os backend for windows as win32
145#[cfg(target_os = "windows")]
146pub use os::win32 as os_platform;
147
148/// This is a hardcoded compile time selection of os backend for windows as d3d12
149#[cfg(target_os = "windows")]
150pub use gfx::d3d12 as gfx_platform;
151
152/// This is a hardcoded compile time selection of os backend for windows as wmf
153#[cfg(target_os = "windows")]
154pub use av::wmf as av_platform;
155
156
157/// Most commonly used re-exported types.
158#[cfg(target_os = "windows")]
159pub mod prelude {
160    #[doc(hidden)]
161    pub use crate::{
162        // modules
163        gfx,
164        os,
165        client,
166        plugin,
167        pmfx,
168        imgui,
169        image,
170
171        // platform specific 
172        gfx_platform,
173        os_platform,
174        av_platform,
175
176        // traits
177        ecs_base::*,
178        gfx::{Device, SwapChain, CmdBuf, Texture, RenderPass, Pipeline, Buffer},
179        pmfx::{DrawData, MaterialData, PointLightData, SpotLightData, DirectionalLightData, WorldBufferReserveInfo, WorldBufferInfo},
180        os::{App, Window},
181        pmfx::Pmfx,
182        imgui::ImGui,
183        imdraw::ImDraw,
184        client::{Client, HotlineInfo, PluginInfo},
185        plugin::{Plugin},
186        av::{VideoPlayer},
187
188        // macros
189        hotline_plugin,
190        system_func,
191        render_func,
192        render_func_closure,
193
194        compute_func,
195        compute_func_closure,
196        compute_func_query,
197        compute_func_query_closure,
198
199        demos,
200        systems
201    };
202}
203
204#[cfg(not(target_os = "windows"))]
205pub mod prelude {
206    #[doc(hidden)]
207    pub use crate::{
208        // modules
209        gfx,
210        os,
211        client,
212        plugin,
213        pmfx,
214        imgui,
215
216        // traits
217        gfx::{Device, SwapChain, CmdBuf, Texture, RenderPass},
218        os::{App, Window},
219        pmfx::Pmfx,
220        imgui::ImGui,
221        imdraw::ImDraw,
222        client::{Client, HotlineInfo, PluginInfo},
223        plugin::{Plugin},
224        av::{VideoPlayer},
225    };
226}