mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vfmt: reformat examples/sokol/particles *.v files
This commit is contained in:
@@ -1,38 +1,35 @@
|
||||
// Copyright(C) 2019 Lars Pontoppidan. All rights reserved.
|
||||
// Use of this source code is governed by an MIT license file distributed with this software package
|
||||
|
||||
module particle
|
||||
|
||||
import vec2
|
||||
import rand
|
||||
import sokol.sgl
|
||||
|
||||
pub struct SystemConfig {
|
||||
pool int
|
||||
pool int
|
||||
}
|
||||
|
||||
pub struct System {
|
||||
width int
|
||||
height int
|
||||
width int
|
||||
height int
|
||||
mut:
|
||||
pool []&Particle
|
||||
bin []&Particle
|
||||
pool []&Particle
|
||||
bin []&Particle
|
||||
}
|
||||
|
||||
pub fn (mut s System) init(sc SystemConfig) {
|
||||
for i := 0; i < sc.pool; i++ {
|
||||
p := particle.new( vec2.Vec2{f32(s.width)*0.5, f32(s.height)*0.5} )
|
||||
p := new(vec2.Vec2{f32(s.width) * 0.5, f32(s.height) * 0.5})
|
||||
s.pool << p
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut s System) update(dt f64) {
|
||||
|
||||
mut p := &Particle(0)
|
||||
for i := 0; i < s.pool.len; i++ {
|
||||
p = s.pool[i]
|
||||
|
||||
p.update(dt)
|
||||
|
||||
if p.is_dead() {
|
||||
s.bin << p
|
||||
s.pool.delete(i)
|
||||
@@ -59,26 +56,20 @@ pub fn (mut s System) reset() {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut s System) explode(x f32, y f32) {
|
||||
|
||||
pub fn (mut s System) explode(x, y f32) {
|
||||
mut reserve := 500
|
||||
|
||||
center := vec2.Vec2{x,y}
|
||||
|
||||
center := vec2.Vec2{x, y}
|
||||
mut p := &Particle(0)
|
||||
for i := 0; i < s.bin.len && reserve > 0; i++ {
|
||||
p = s.bin[i]
|
||||
|
||||
p.reset()
|
||||
|
||||
p.location.from(center)
|
||||
p.acceleration = vec2.Vec2{rand.f32_in_range(-0.5,0.5),rand.f32_in_range(-0.5,0.5)}
|
||||
p.velocity = vec2.Vec2{rand.f32_in_range(-0.5,0.5),rand.f32_in_range(-0.5,0.5)}
|
||||
p.life_time = rand.f64_in_range(500,2000)
|
||||
|
||||
p.acceleration = vec2.Vec2{rand.f32_in_range(-0.5, 0.5), rand.f32_in_range(-0.5,
|
||||
0.5)}
|
||||
p.velocity = vec2.Vec2{rand.f32_in_range(-0.5, 0.5), rand.f32_in_range(-0.5, 0.5)}
|
||||
p.life_time = rand.f64_in_range(500, 2000)
|
||||
s.pool << p
|
||||
s.bin.delete(i)
|
||||
|
||||
reserve--
|
||||
}
|
||||
}
|
||||
@@ -86,24 +77,23 @@ pub fn (mut s System) explode(x f32, y f32) {
|
||||
pub fn (mut s System) free() {
|
||||
for p in s.pool {
|
||||
if p == 0 {
|
||||
print(ptr_str(p)+' ouch')
|
||||
print(ptr_str(p) + ' ouch')
|
||||
continue
|
||||
}
|
||||
unsafe{
|
||||
unsafe {
|
||||
free(p)
|
||||
}
|
||||
}
|
||||
s.pool.clear()
|
||||
for p in s.bin {
|
||||
if p == 0 {
|
||||
print(ptr_str(p)+' ouch')
|
||||
print(ptr_str(p) + ' ouch')
|
||||
continue
|
||||
}
|
||||
|
||||
unsafe{
|
||||
//println('Freeing from bin')
|
||||
unsafe {
|
||||
// println('Freeing from bin')
|
||||
free(p)
|
||||
}
|
||||
}
|
||||
s.bin.clear()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user