1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//! In order to get the crate running, you have to copy `msvc` folder and `build.rs` from crates
//! [repository](https://github.com/jakubDoka/rustbatch)
//! and place it into root of your project.
//! # RustBatch
//! This crate provides some performant tools for building big 2D games that deals with huge amount of entities.
//! So far crate contains:
//! - OpenGl abstraction based around batching.
//! - Collision scanner that provides fast collision detection for couple thousand entities
//! - Multithreaded pathfinder that has no problems ewen with 1000 X 1000 tile-maps
//! - Math module that contains structs like Matrix, Vector or Rectangle
//! - Custom per-batch vertex and fragment shader also supported
//! - Sprite packing so you can take advantage of batching as match as you can
//! # Warming
//! Important thing to note is that some functions from render module are calling functions and
//! using enums from gl crate. Functions has to be loaded first witch you achieve by creating
//! window.
//! # Example
//! ```
//!extern crate rustbatch;
//!
//!use rustbatch::{sdl2, image, gl};
//!use rustbatch::debug::FPS;
//!use rustbatch::{Window, Texture, Sprite, Batch};
//!use rustbatch::{Mat, Vect};
//!use rustbatch::render::texture::TextureConfig;
//!use rustbatch::rgba::WHITE;
//!
//!fn main() {
//!    // creating window to draw to and event pump to read input. Ignore
//!    // gl var, it cannot be dropped otherwise rendering will not work so just leave it be
//!
//!
//!    let (mut window, mut event_pump, _gl, _sdl, _video_subsystem) = Window::new(|sys| {
//!        sys.window("rusty batch", 400, 400)
//!            .opengl()
//!            .resizable()
//!            .build()
//!            .unwrap()
//!    });
//!
//!    window.set_background_color(&[0.5f32, 0.5f32, 0.5f32, 1f32]); //gray background
//!
//!    // This is wrapped opengl texture object
//!    let texture = Texture::new(
//!        "C:/Users/jakub/Documents/programming/rust/src/rustbatch/assets/logo.png",
//!       TextureConfig::DEFAULT,
//!    ).unwrap();
//!
//!    // Creating sprite. Notice that sprite is just collection of points and it cannot be directly
//!    // drawn to window
//!    let mut sprite = Sprite::new(texture.frame());
//!
//!    // On the other hand batch owns texture witch can be drawn to window
//!    let mut batch = Batch::new(texture);
//!
//!    // this is just a little helper
//!    let mut fps = FPS::new(1f32);
//!
//!    'main: loop {
//!        //polling events
//!        for event in event_pump.poll_iter() {
//!            match event {
//!                // break loop if X button on window is pressed
//!                sdl2::event::Event::Quit { .. } => break 'main,
//!                _ => {}
//!            }
//!        }
//!
//!        // i hope you know how to get delta on your own but fps returns is as bonus if you supply
//!        // 0f32 as delta
//!        let _delta = fps.increase(0f32);
//!
//!        window.clear();
//!
//!        // drawing sprite to batch
//!        // texture color is multiplied by inputted color
//!        sprite.draw(&mut batch, Vect::ZERO, Vect::mirror(1f32), 0f32, &WHITE);
//!
//!        // drawing batch to window
//!        batch.draw(&mut window.canvas);
//!
//!        // Don't forget to clear batch if you not planning to use it as canvas,
//!        // after all drawing sprites to batch takes some time
//!        batch.clear();
//!
//!        // finishing with window update so you can se it changing
//!        window.update();
//!    }
//!}
//! ```


/// math::vect::vect constructor that works on any type of number
#[macro_export]
macro_rules! vect {
        ($x: expr, $y: expr) => {
            Vect { x: $x as f32, y: $y as f32}
        }
    }

/// math::rect::Rect constructor that works on any type of number
#[macro_export]
macro_rules! rect {
        ($x: expr, $y: expr, $x1: expr, $y1: expr) => {
            Rect{
                min: Vect {
                    x: $x as f32,
                    y: $y as f32,
                },
                max: Vect {
                    x: $x1 as f32,
                    y: $y1 as f32,
                },
            }
        }
    }

/// math::circle::Circ constructor that works on any type of number
#[macro_export]
macro_rules! circ {
    ($x: expr, $y: expr; $r: expr) => {
        Circ{
            c: Vect {
                    x: $x as f32,
                    y: $y as f32,
                },
            r: $r as f32,
        }
    };
}

/// math::raycast::Ray constructor that works on any type of number
#[macro_export]
macro_rules! ray {
    ($ox: expr, $oy: expr, $vx: expr, $vy: expr) => {
            Ray {
                o: Vect {
                    x: $ox as f32,
                    y: $oy as f32,
                },
                v: Vect {
                    x: $vx as f32,
                    y: $vy as f32,
                },
            }
        }
}

/// math::curve::Curve constructor that works on any type of number
#[macro_export]
macro_rules! curve {
    ($ax: expr, $ay: expr; $ahx: expr, $ahy: expr; $bx: expr, $by: expr; $bhx: expr, $bhy: expr) => {
        Curve {
            a: Vect {x: $ax as f32, y: $ay as f32},
            a_handle: Vect {x: $ahx as f32, y: $ahy as f32},
            b: Vect {x: $bx as f32, y: $by as f32},
            b_handle: Vect {x: $bhx as f32, y: $bhy as f32},
            placeholder: false,
        }
    }
}

/// clamp clamps any types that can be compared
#[macro_export]
macro_rules! clamp {
    ($a: expr, $min: expr, $max: expr) => {
        if $a < $min { $min } else if $a > $max { $max } else { $a }
    };
}

pub mod images;
pub mod render;
pub mod debug;
pub mod math;
pub mod entities;

pub use sdl2;
pub use image;
pub use gl;
pub use rand;

pub use debug::FPS;
pub use render::{window::Window, texture::{ Texture, TextureConfig, TextureSize}, sprite::Sprite,
                 batch::Batch, canvas::Canvas, buffer::Buffer, program::Program, shader::Shader};
pub use entities::{pathfinder::PathFinder, predict, storage::ComponentArray, timer::Timer,
                   detection::{quadmap::QuadMap, spatial_hash::SpatialHasher}};
pub use images::Sheet;
pub use math::{mat::Mat, rgba, vect::Vect, rect::Rect, curve::Curve, base::Base, angle, circle::Circ,
               raycast::Ray, Intersection, IntersectionPoints};