Compare commits
No commits in common. "3bb0cbf026c8a9982d5b70b258a47696f30828e7" and "1cb833b9877b5b3a7d3c428a3e39a87bf6045826" have entirely different histories.
3bb0cbf026
...
1cb833b987
5 changed files with 92 additions and 94 deletions
|
@ -62,7 +62,14 @@ impl Color {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn serialize(&self) -> Vec<u8> {
|
pub fn serialize(&self) -> Vec<u8> {
|
||||||
vec![self.r, self.g, self.b, self.a]
|
let mut bytes = Vec::new();
|
||||||
|
|
||||||
|
bytes.push(self.r);
|
||||||
|
bytes.push(self.g);
|
||||||
|
bytes.push(self.b);
|
||||||
|
bytes.push(self.a);
|
||||||
|
|
||||||
|
bytes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
#[cfg(not(target_family = "wasm"))]
|
use std::{fs::File, io::Result as IOResult, path::PathBuf, str::FromStr};
|
||||||
use std::fs::File;
|
|
||||||
use std::{io::Result as IOResult, path::PathBuf, str::FromStr};
|
|
||||||
|
|
||||||
use crate::agnostic_interface::CameraInterface;
|
use crate::agnostic_interface::CameraInterface;
|
||||||
use crate::faux_quicksilver::{Circle, Color, Rectangle, Transform, Vector, Window};
|
use crate::faux_quicksilver::{Circle, Color, Rectangle, Transform, Vector, Window};
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
#[cfg(target_family = "wasm")]
|
use std::os::raw::{c_int, c_void};
|
||||||
use std::sync::mpsc::{Receiver, TryRecvError};
|
use std::sync::mpsc::{Receiver, TryRecvError};
|
||||||
|
|
||||||
const WIDTH_F: f32 = 800.0;
|
const WIDTH_F: f32 = 800.0;
|
||||||
const HEIGHT_F: f32 = 600.0;
|
const HEIGHT_F: f32 = 600.0;
|
||||||
//const MUSIC2_LENGTH: f32 = 2.0 * 60.0 * 1000.0;
|
const MUSIC2_LENGTH: f32 = 2.0 * 60.0 * 1000.0;
|
||||||
const TEXT_RATE: f32 = 0.1;
|
const TEXT_RATE: f32 = 0.1;
|
||||||
const PP_GEN_RATE: f32 = 0.075;
|
const PP_GEN_RATE: f32 = 0.075;
|
||||||
const PARTICLE_RAND_VEL_RANGE: f32 = 80.0;
|
const PARTICLE_RAND_VEL_RANGE: f32 = 80.0;
|
||||||
|
@ -22,8 +20,7 @@ const JOINING_NEAR_DIST: f32 = 150.0;
|
||||||
const DOUBLE_CLICK_TIME: f32 = 0.350;
|
const DOUBLE_CLICK_TIME: f32 = 0.350;
|
||||||
const SL_NOTIF_TIME: f32 = 7.0;
|
const SL_NOTIF_TIME: f32 = 7.0;
|
||||||
const MAX_MOONS: usize = 5;
|
const MAX_MOONS: usize = 5;
|
||||||
#[cfg(not(target_family = "wasm"))]
|
const SAVE_FILENAME: &'static str = "LudumDare45_OneAndAll_SaveFile.bin";
|
||||||
const SAVE_FILENAME: &str = "LudumDare45_OneAndAll_SaveFile.bin";
|
|
||||||
|
|
||||||
fn interp_sq_inv(x: f32) -> f32 {
|
fn interp_sq_inv(x: f32) -> f32 {
|
||||||
if x < 0.0 {
|
if x < 0.0 {
|
||||||
|
@ -44,8 +41,6 @@ fn interp_sq(x: f32) -> f32 {
|
||||||
x * x
|
x * x
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
enum MenuItemType {
|
enum MenuItemType {
|
||||||
Button {
|
Button {
|
||||||
text: &'static str,
|
text: &'static str,
|
||||||
|
@ -71,7 +66,6 @@ enum MenuItemType {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
struct MenuItem {
|
struct MenuItem {
|
||||||
x: f32,
|
x: f32,
|
||||||
y: f32,
|
y: f32,
|
||||||
|
@ -93,7 +87,6 @@ struct Menu {
|
||||||
items: Vec<MenuItem>,
|
items: Vec<MenuItem>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
impl Menu {
|
impl Menu {
|
||||||
fn button(
|
fn button(
|
||||||
x: f32,
|
x: f32,
|
||||||
|
@ -694,7 +687,6 @@ impl Default for ParticleSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParticleSystem {
|
impl ParticleSystem {
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
fn new(
|
fn new(
|
||||||
spawn_time: f32,
|
spawn_time: f32,
|
||||||
lifetime: f32,
|
lifetime: f32,
|
||||||
|
@ -804,7 +796,7 @@ impl ParticleSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn force_spawn(&mut self, count: usize) {
|
fn force_spawn(&mut self, count: usize) {
|
||||||
for _ in 0..count {
|
for i in 0..count {
|
||||||
self.particles.push(Particle {
|
self.particles.push(Particle {
|
||||||
rect: self.host_rect,
|
rect: self.host_rect,
|
||||||
circle: self.host_circle,
|
circle: self.host_circle,
|
||||||
|
@ -936,9 +928,9 @@ impl ParticleSystem {
|
||||||
bytes.append(&mut particle.serialize());
|
bytes.append(&mut particle.serialize());
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes.extend(self.spawn_timer.to_be_bytes());
|
bytes.extend(self.spawn_timer.to_be_bytes().into_iter());
|
||||||
bytes.extend(self.spawn_time.to_be_bytes());
|
bytes.extend(self.spawn_time.to_be_bytes().into_iter());
|
||||||
bytes.extend(self.lifetime.to_be_bytes());
|
bytes.extend(self.lifetime.to_be_bytes().into_iter());
|
||||||
|
|
||||||
bytes.append(&mut self.host_rect.serialize());
|
bytes.append(&mut self.host_rect.serialize());
|
||||||
|
|
||||||
|
@ -950,8 +942,8 @@ impl ParticleSystem {
|
||||||
|
|
||||||
bytes.append(&mut self.color.serialize());
|
bytes.append(&mut self.color.serialize());
|
||||||
|
|
||||||
bytes.extend(self.opacity.to_be_bytes());
|
bytes.extend(self.opacity.to_be_bytes().into_iter());
|
||||||
bytes.extend(self.vel_multiplier.to_be_bytes());
|
bytes.extend(self.vel_multiplier.to_be_bytes().into_iter());
|
||||||
|
|
||||||
bytes
|
bytes
|
||||||
}
|
}
|
||||||
|
@ -977,7 +969,6 @@ impl Default for RotatingParticleSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RotatingParticleSystem {
|
impl RotatingParticleSystem {
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
fn new(
|
fn new(
|
||||||
spawn_time: f32,
|
spawn_time: f32,
|
||||||
lifetime: f32,
|
lifetime: f32,
|
||||||
|
@ -1119,9 +1110,9 @@ impl RotatingParticleSystem {
|
||||||
|
|
||||||
bytes.append(&mut self.particle_system.serialize());
|
bytes.append(&mut self.particle_system.serialize());
|
||||||
|
|
||||||
bytes.extend(self.r.to_be_bytes());
|
bytes.extend(self.r.to_be_bytes().into_iter());
|
||||||
bytes.extend(self.velr.to_be_bytes());
|
bytes.extend(self.velr.to_be_bytes().into_iter());
|
||||||
bytes.extend(self.offset.to_be_bytes());
|
bytes.extend(self.offset.to_be_bytes().into_iter());
|
||||||
|
|
||||||
bytes
|
bytes
|
||||||
}
|
}
|
||||||
|
@ -1156,7 +1147,7 @@ impl ExplConvParticleSystem {
|
||||||
|
|
||||||
fn activate(&mut self, count: usize, offset: f32) {
|
fn activate(&mut self, count: usize, offset: f32) {
|
||||||
self.life_timer = 0.0;
|
self.life_timer = 0.0;
|
||||||
for _ in 0..count {
|
for i in 0..count {
|
||||||
self.particles.push(ExplConvCircleParticle {
|
self.particles.push(ExplConvCircleParticle {
|
||||||
circle: self.host_circle,
|
circle: self.host_circle,
|
||||||
offset,
|
offset,
|
||||||
|
@ -1220,7 +1211,7 @@ impl ExplConvParticleSystem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Default)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
struct Planet {
|
struct Planet {
|
||||||
circle: Circle,
|
circle: Circle,
|
||||||
color: Color,
|
color: Color,
|
||||||
|
@ -1228,6 +1219,17 @@ struct Planet {
|
||||||
moons: Vec<RotatingParticleSystem>,
|
moons: Vec<RotatingParticleSystem>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Planet {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
circle: Circle::default(),
|
||||||
|
color: Color::default(),
|
||||||
|
particle_system: ParticleSystem::default(),
|
||||||
|
moons: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Planet {
|
impl Planet {
|
||||||
fn new(circle: Circle, color: Color) -> Self {
|
fn new(circle: Circle, color: Color) -> Self {
|
||||||
let mut smaller_circle = circle;
|
let mut smaller_circle = circle;
|
||||||
|
@ -1251,7 +1253,7 @@ impl Planet {
|
||||||
|
|
||||||
let r: f32 = rand::thread_rng().gen_range(0.0..360.0);
|
let r: f32 = rand::thread_rng().gen_range(0.0..360.0);
|
||||||
let clockwise = rand::thread_rng().gen_bool(0.5);
|
let clockwise = rand::thread_rng().gen_bool(0.5);
|
||||||
for _ in 0..rand::thread_rng().gen_range(0..MAX_MOONS) {
|
for i in 0..rand::thread_rng().gen_range(0..MAX_MOONS) {
|
||||||
planet.moons.push(RotatingParticleSystem::new(
|
planet.moons.push(RotatingParticleSystem::new(
|
||||||
rand::thread_rng().gen_range(1.0..2.6),
|
rand::thread_rng().gen_range(1.0..2.6),
|
||||||
0.6,
|
0.6,
|
||||||
|
@ -1347,7 +1349,7 @@ impl Planet {
|
||||||
bytes.append(&mut self.particle_system.serialize());
|
bytes.append(&mut self.particle_system.serialize());
|
||||||
|
|
||||||
let moons_size = self.moons.len();
|
let moons_size = self.moons.len();
|
||||||
bytes.extend(moons_size.to_be_bytes());
|
bytes.extend(moons_size.to_be_bytes().into_iter());
|
||||||
for i in 0..moons_size {
|
for i in 0..moons_size {
|
||||||
bytes.append(&mut self.moons[i].serialize());
|
bytes.append(&mut self.moons[i].serialize());
|
||||||
}
|
}
|
||||||
|
@ -1475,8 +1477,8 @@ impl Star {
|
||||||
bytes.append(&mut self.color.serialize());
|
bytes.append(&mut self.color.serialize());
|
||||||
bytes.append(&mut self.particle_system.serialize());
|
bytes.append(&mut self.particle_system.serialize());
|
||||||
|
|
||||||
bytes.extend(self.velr.to_be_bytes());
|
bytes.extend(self.velr.to_be_bytes().into_iter());
|
||||||
bytes.extend(self.r.to_be_bytes());
|
bytes.extend(self.r.to_be_bytes().into_iter());
|
||||||
|
|
||||||
bytes
|
bytes
|
||||||
}
|
}
|
||||||
|
@ -1719,12 +1721,12 @@ impl Fish {
|
||||||
|
|
||||||
bytes.append(&mut self.pos.serialize());
|
bytes.append(&mut self.pos.serialize());
|
||||||
|
|
||||||
bytes.extend(self.r.to_be_bytes());
|
bytes.extend(self.r.to_be_bytes().into_iter());
|
||||||
bytes.extend(self.swim_time.to_be_bytes());
|
bytes.extend(self.swim_time.to_be_bytes().into_iter());
|
||||||
bytes.extend(self.swim_timer.to_be_bytes());
|
bytes.extend(self.swim_timer.to_be_bytes().into_iter());
|
||||||
bytes.extend(self.swim_v.to_be_bytes());
|
bytes.extend(self.swim_v.to_be_bytes().into_iter());
|
||||||
bytes.extend(self.anim_timer.to_be_bytes());
|
bytes.extend(self.anim_timer.to_be_bytes().into_iter());
|
||||||
bytes.extend(self.anim_time.to_be_bytes());
|
bytes.extend(self.anim_time.to_be_bytes().into_iter());
|
||||||
|
|
||||||
bytes.append(&mut self.color.serialize());
|
bytes.append(&mut self.color.serialize());
|
||||||
bytes.append(&mut self.body_rect.serialize());
|
bytes.append(&mut self.body_rect.serialize());
|
||||||
|
@ -1734,7 +1736,7 @@ impl Fish {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Default)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
struct SaveData {
|
struct SaveData {
|
||||||
planets: Vec<Planet>,
|
planets: Vec<Planet>,
|
||||||
stars: Vec<Star>,
|
stars: Vec<Star>,
|
||||||
|
@ -1745,6 +1747,18 @@ struct SaveData {
|
||||||
|
|
||||||
const SAVE_DATA_IDENTIFIER: [u8; 4] = [0x53, 0x41, 0x56, 0x45];
|
const SAVE_DATA_IDENTIFIER: [u8; 4] = [0x53, 0x41, 0x56, 0x45];
|
||||||
|
|
||||||
|
impl Default for SaveData {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
planets: Vec::new(),
|
||||||
|
stars: Vec::new(),
|
||||||
|
fishes: Vec::new(),
|
||||||
|
player: Rectangle::default(),
|
||||||
|
joining_particles: RotatingParticleSystem::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl SaveData {
|
impl SaveData {
|
||||||
pub fn deserialize(data: &[u8]) -> Result<(SaveData, usize), ()> {
|
pub fn deserialize(data: &[u8]) -> Result<(SaveData, usize), ()> {
|
||||||
let mut idx: usize = 0;
|
let mut idx: usize = 0;
|
||||||
|
@ -1824,17 +1838,17 @@ impl SaveData {
|
||||||
|
|
||||||
bytes.extend(SAVE_DATA_IDENTIFIER.iter());
|
bytes.extend(SAVE_DATA_IDENTIFIER.iter());
|
||||||
|
|
||||||
bytes.extend(self.planets.len().to_be_bytes());
|
bytes.extend(self.planets.len().to_be_bytes().into_iter());
|
||||||
for planet in &self.planets {
|
for planet in &self.planets {
|
||||||
bytes.append(&mut planet.serialize());
|
bytes.append(&mut planet.serialize());
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes.extend(self.stars.len().to_be_bytes());
|
bytes.extend(self.stars.len().to_be_bytes().into_iter());
|
||||||
for star in &self.stars {
|
for star in &self.stars {
|
||||||
bytes.append(&mut star.serialize());
|
bytes.append(&mut star.serialize());
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes.extend(self.fishes.len().to_be_bytes());
|
bytes.extend(self.fishes.len().to_be_bytes().into_iter());
|
||||||
for fish in &self.fishes {
|
for fish in &self.fishes {
|
||||||
bytes.append(&mut fish.serialize());
|
bytes.append(&mut fish.serialize());
|
||||||
}
|
}
|
||||||
|
@ -1852,7 +1866,6 @@ enum SaveLoadNotification {
|
||||||
Load { text: Option<String>, timer: f32 },
|
Load { text: Option<String>, timer: f32 },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub struct GameState {
|
pub struct GameState {
|
||||||
s_boom: String,
|
s_boom: String,
|
||||||
s_get: String,
|
s_get: String,
|
||||||
|
@ -2114,7 +2127,7 @@ impl GameState {
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
// spawn fish
|
// spawn fish
|
||||||
for _ in 0..rng.gen_range(1..4) {
|
for i in 0..rng.gen_range(1..4) {
|
||||||
self.fishes.push(Fish::new(
|
self.fishes.push(Fish::new(
|
||||||
click_pos,
|
click_pos,
|
||||||
rng.gen_range(0.0..360.0),
|
rng.gen_range(0.0..360.0),
|
||||||
|
@ -2177,7 +2190,7 @@ impl GameState {
|
||||||
} else {
|
} else {
|
||||||
match self.state {
|
match self.state {
|
||||||
0 | 1 => self.state += 1,
|
0 | 1 => self.state += 1,
|
||||||
3..=6 => self.state = 7,
|
3 | 4 | 5 | 6 => self.state = 7,
|
||||||
7 => self.state = 8,
|
7 => self.state = 8,
|
||||||
9 => self.state = 10,
|
9 => self.state = 10,
|
||||||
_ => self.state = 0,
|
_ => self.state = 0,
|
||||||
|
@ -2190,28 +2203,25 @@ impl GameState {
|
||||||
MenuItemType::AppearingText {
|
MenuItemType::AppearingText {
|
||||||
text,
|
text,
|
||||||
text_idx,
|
text_idx,
|
||||||
text_size: _,
|
text_size,
|
||||||
text_c: _,
|
text_c,
|
||||||
timer: _,
|
timer,
|
||||||
} => {
|
} => {
|
||||||
*text_idx = text.len();
|
*text_idx = text.len();
|
||||||
}
|
}
|
||||||
MenuItemType::Button {
|
MenuItemType::Button {
|
||||||
text: _,
|
text,
|
||||||
text_c: _,
|
text_c,
|
||||||
h_c: _,
|
h_c,
|
||||||
c: _,
|
c,
|
||||||
} => {
|
} => {
|
||||||
//let style = FontStyle::new(42.0, *text_c);
|
//let style = FontStyle::new(42.0, *text_c);
|
||||||
}
|
}
|
||||||
MenuItemType::Pause {
|
MenuItemType::Pause { timer, length } => (),
|
||||||
timer: _,
|
|
||||||
length: _,
|
|
||||||
} => (),
|
|
||||||
MenuItemType::InstantText {
|
MenuItemType::InstantText {
|
||||||
text: _,
|
text,
|
||||||
text_size: _,
|
text_size,
|
||||||
text_color: _,
|
text_color,
|
||||||
} => {}
|
} => {}
|
||||||
}
|
}
|
||||||
mi.is_loaded = true;
|
mi.is_loaded = true;
|
||||||
|
@ -2391,10 +2401,10 @@ impl GameState {
|
||||||
if !mi.is_loaded {
|
if !mi.is_loaded {
|
||||||
match &mut mi.item_type {
|
match &mut mi.item_type {
|
||||||
MenuItemType::Button {
|
MenuItemType::Button {
|
||||||
text: _,
|
text,
|
||||||
text_c: _,
|
text_c,
|
||||||
h_c: _,
|
h_c,
|
||||||
c: _,
|
c,
|
||||||
} => {
|
} => {
|
||||||
//self.font.execute(|font| {
|
//self.font.execute(|font| {
|
||||||
// let style = FontStyle::new(42.0, *text_c);
|
// let style = FontStyle::new(42.0, *text_c);
|
||||||
|
@ -2413,8 +2423,8 @@ impl GameState {
|
||||||
MenuItemType::AppearingText {
|
MenuItemType::AppearingText {
|
||||||
text,
|
text,
|
||||||
text_idx,
|
text_idx,
|
||||||
text_size: _,
|
text_size,
|
||||||
text_c: _,
|
text_c,
|
||||||
timer,
|
timer,
|
||||||
} => {
|
} => {
|
||||||
*timer += dt;
|
*timer += dt;
|
||||||
|
@ -2450,9 +2460,9 @@ impl GameState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MenuItemType::InstantText {
|
MenuItemType::InstantText {
|
||||||
text: _,
|
text,
|
||||||
text_size: _,
|
text_size,
|
||||||
text_color: _,
|
text_color,
|
||||||
} => {
|
} => {
|
||||||
//if text_image.is_none() {
|
//if text_image.is_none() {
|
||||||
// self.font.execute(|f| {
|
// self.font.execute(|f| {
|
||||||
|
@ -2597,9 +2607,9 @@ impl GameState {
|
||||||
MenuItemType::AppearingText {
|
MenuItemType::AppearingText {
|
||||||
text,
|
text,
|
||||||
text_idx,
|
text_idx,
|
||||||
text_size: _,
|
text_size,
|
||||||
text_c,
|
text_c,
|
||||||
timer: _,
|
timer,
|
||||||
} => {
|
} => {
|
||||||
window.get_font_mut(&self.font)?.draw(
|
window.get_font_mut(&self.font)?.draw(
|
||||||
if *text_idx < text.len() {
|
if *text_idx < text.len() {
|
||||||
|
@ -2626,10 +2636,7 @@ impl GameState {
|
||||||
*text_color,
|
*text_color,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
MenuItemType::Pause {
|
MenuItemType::Pause { timer, length } => (),
|
||||||
timer: _,
|
|
||||||
length: _,
|
|
||||||
} => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.player_particles.draw(window, Transform::IDENTITY);
|
self.player_particles.draw(window, Transform::IDENTITY);
|
||||||
|
@ -2673,7 +2680,7 @@ impl GameState {
|
||||||
255,
|
255,
|
||||||
255,
|
255,
|
||||||
255,
|
255,
|
||||||
((*timer / SL_NOTIF_TIME) * 255.0) as u8,
|
((*timer / SL_NOTIF_TIME) as f32 * 255.0) as u8,
|
||||||
),
|
),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ extern "C" {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn glVertexAttrib3f(index: ::std::os::raw::c_uint, x: f32, y: f32, z: f32);
|
pub fn glVertexAttrib3f(index: ::std::os::raw::c_uint, x: f32, y: f32, z: f32);
|
||||||
}
|
}
|
||||||
#[allow(dead_code)]
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn glVertexAttrib4f(index: ::std::os::raw::c_uint, x: f32, y: f32, z: f32, w: f32);
|
pub fn glVertexAttrib4f(index: ::std::os::raw::c_uint, x: f32, y: f32, z: f32, w: f32);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,12 @@
|
||||||
#[cfg(target_family = "wasm")]
|
|
||||||
use std::os::raw::*;
|
use std::os::raw::*;
|
||||||
#[cfg(not(target_family = "wasm"))]
|
|
||||||
use std::sync::mpsc::Receiver;
|
|
||||||
#[cfg(target_family = "wasm")]
|
|
||||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||||
|
|
||||||
#[cfg(not(target_family = "wasm"))]
|
#[cfg(not(target_family = "wasm"))]
|
||||||
#[allow(dead_code)]
|
pub fn save_data(data: &[u8]) -> std::io::Result<()> {
|
||||||
pub fn save_data(_data: &[u8]) -> std::io::Result<()> {
|
|
||||||
Err(std::io::Error::other("Unimplemented for native"))
|
Err(std::io::Error::other("Unimplemented for native"))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_family = "wasm"))]
|
#[cfg(not(target_family = "wasm"))]
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn load_data() -> std::io::Result<Receiver<Vec<u8>>> {
|
pub fn load_data() -> std::io::Result<Receiver<Vec<u8>>> {
|
||||||
Err(std::io::Error::other("Unimplemented for native"))
|
Err(std::io::Error::other("Unimplemented for native"))
|
||||||
}
|
}
|
||||||
|
@ -20,7 +14,8 @@ pub fn load_data() -> std::io::Result<Receiver<Vec<u8>>> {
|
||||||
#[cfg(target_family = "wasm")]
|
#[cfg(target_family = "wasm")]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn ld45_load_rust_handler(usr: *mut c_void, data: *const c_void, len: c_int) {
|
pub extern "C" fn ld45_load_rust_handler(usr: *mut c_void, data: *const c_void, len: c_int) {
|
||||||
let sender_box: Box<Sender<Vec<u8>>> = unsafe { Box::from_raw(usr as *mut Sender<Vec<u8>>) };
|
let mut sender_box: Box<Sender<Vec<u8>>> =
|
||||||
|
unsafe { Box::from_raw(usr as *mut Sender<Vec<u8>>) };
|
||||||
|
|
||||||
if data.is_null() || len == 0 {
|
if data.is_null() || len == 0 {
|
||||||
(*sender_box).send(Vec::new()).ok();
|
(*sender_box).send(Vec::new()).ok();
|
||||||
|
@ -55,10 +50,10 @@ pub fn save_data(data: &[u8]) -> std::io::Result<()> {
|
||||||
#[cfg(target_family = "wasm")]
|
#[cfg(target_family = "wasm")]
|
||||||
pub fn load_data() -> std::io::Result<Receiver<Vec<u8>>> {
|
pub fn load_data() -> std::io::Result<Receiver<Vec<u8>>> {
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
let handler = Box::new(tx);
|
let mut handler = Box::new(tx);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = Box::into_raw(handler);
|
let mut ptr = Box::into_raw(handler);
|
||||||
ld45_load_async(ptr as *mut c_void);
|
ld45_load_async(ptr as *mut c_void);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,6 @@
|
||||||
EM_ENV = "${HOME}/git/emsdk/emsdk_env.sh"
|
EM_ENV = "${HOME}/git/emsdk/emsdk_env.sh"
|
||||||
CC = source ${EM_ENV} && emcc
|
CC = source ${EM_ENV} && emcc
|
||||||
|
|
||||||
RUST_SOURCES = \
|
|
||||||
../src/agnostic_interface/raylib_impl.rs \
|
|
||||||
../src/bin.rs \
|
|
||||||
../src/agnostic_interface.rs \
|
|
||||||
../src/shaders.rs \
|
|
||||||
../src/faux_quicksilver.rs \
|
|
||||||
../src/lib.rs \
|
|
||||||
../src/original_impl.rs \
|
|
||||||
../src/wasm_helpers.rs
|
|
||||||
|
|
||||||
all: ld45.html
|
all: ld45.html
|
||||||
|
|
||||||
ld45.html: src/main.c ../target/wasm32-unknown-emscripten/release/libld45_lib.a
|
ld45.html: src/main.c ../target/wasm32-unknown-emscripten/release/libld45_lib.a
|
||||||
|
@ -29,7 +19,7 @@ ld45.html: src/main.c ../target/wasm32-unknown-emscripten/release/libld45_lib.a
|
||||||
#-fsanitize=address \
|
#-fsanitize=address \
|
||||||
#-sWARN_UNALIGNED=1 \
|
#-sWARN_UNALIGNED=1 \
|
||||||
|
|
||||||
../target/wasm32-unknown-emscripten/release/libld45_lib.a: ${RUST_SOURCES}
|
../target/wasm32-unknown-emscripten/release/libld45_lib.a: ../src/lib.rs
|
||||||
cd .. && source ${EM_ENV} && cargo build --lib --release --target wasm32-unknown-emscripten
|
cd .. && source ${EM_ENV} && cargo build --lib --release --target wasm32-unknown-emscripten
|
||||||
# cd .. && source ${EM_ENV} && cargo rustc --lib --release --target wasm32-unknown-emscripten -- -C link-args=-Wl,-zstack-size=8388608
|
# cd .. && source ${EM_ENV} && cargo rustc --lib --release --target wasm32-unknown-emscripten -- -C link-args=-Wl,-zstack-size=8388608
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue