1
0
Fork 0
This commit is contained in:
coaljoe 2020-09-13 23:14:28 +03:00
parent 040f5cdc88
commit 7ce395a5b2
6 changed files with 67 additions and 8 deletions

View File

@ -45,6 +45,40 @@ fn crush_stone_object2(ob &Object) {
prc.process(ob)
}
// XXX should be registered on facrory
// XXX rename to stole_crush_object() ?
fn stone_crush_object_part(ob &Object) {
println("stone_crush_object_part")
// TODO: amt, force, fracture_force?
// XXX crush entire object part
//for pt in ob.parts_info.elems_list() {
num_bits := ob.bits_volume()
mut prc := new_processor()
prc.name = "crushed_stone"
prc.in_elem = bits_ctx.elem_lib["stone"]
prc.out_elem = bits_ctx.elem_lib["crushed_stone"]
prc.output_factor = 0.6
prc.req_electricity = true
prc.req_power = 1000
// Checks
if isnil(prc.in_elem) {
panic("bad in_elem")
}
if isnil(prc.out_elem) {
panic("bad out_elem")
}
prc.process(ob)
//prc.process_part(pt)
//}
}
// stone -> crushed stone
fn crush_stone_object(ob &Object) {
println("crush_stone_object")

View File

@ -29,10 +29,11 @@ fn (gpc &GenericCrusherProcessor) process(ob &Object) {
println("> create smaller stones")
//crush_stone_object(ob)
crush_stone_object2(ob)
crush_stone_object2_part(ob, ob.stone_part)
crush_stone_object_part(ob)
crush_object_part(ob, "stone")
//crush_stone_object2(ob)
//crush_stone_object2_part(ob, ob.stone_part)
//crush_stone_object_part(ob)
//crush_object_part(ob, "stone")
stone_crush_object_part(ob)
println("> create sand")
println("> (visual) create dust")

View File

@ -51,6 +51,8 @@ pub fn bits_main() {
//
// Effects
//
println("effects")
mut ef := new_effect()
ef.name = "melt"
@ -65,6 +67,8 @@ pub fn bits_main() {
// Objects
//
println("objects")
mut ob := new_object()
ob.name = "stone1"
//ob.dim_x = 2
@ -98,6 +102,8 @@ pub fn bits_main() {
// Processors
//
println("processors")
mut prc := new_processor()
prc.name = "crushed_stone"
prc.in_elem = e4

View File

@ -50,12 +50,16 @@ mut:
}
fn new_object() &Object {
println("new_object()")
o := &Object{
//elem: &Elem(0),
//mat_info: &MaterialInfo(0),
parts_info: &PartsInfo(0),
//parts_info: &PartsInfo(0),
parts_info: new_parts_info(),
//transform: new_transform(),
}
return o
}

View File

@ -27,6 +27,9 @@ fn new_processor() &Processor {
fn (p &Processor) process(mut o Object) {
println("processor process")
println("in elem: $p.in_elem.name")
println("out elem: $p.out_elem.name")
new_elem := p.out_elem
if isnil(new_elem) {
@ -34,12 +37,17 @@ fn (p &Processor) process(mut o Object) {
exit(2)
}
mut processed := false
// Process all elems
mut elems_list := o.parts_info.elems_list()
for i, _ in elems_list {
mut me := elems_list[i]
if me.elem == p.in_elem {
println("me.elem: $me.elem.name")
println("me.bits_size: $me.bits_size")
if me.elem.name == p.in_elem.name { // XXX fixme
println("process for ${me.elem}")
new_bits_size := int(me.bits_size * p.output_factor)
@ -50,8 +58,14 @@ fn (p &Processor) process(mut o Object) {
me.elem = new_elem
me.bits_size = new_bits_size
processed = true
}
}
if !processed {
println("failed to process")
}
println("done processing")
}

View File

@ -1,7 +1,7 @@
module main
type Atexit_func_t fn ()
fn C.atexit(Atexit_func_t)
//fn C.atexit(Atexit_func_t)
fn C.SDL_GetMouseState(x, y &int) u32
//fn C.SDL_GetKeyboardState(intptr numkeys) voidptr
//fn C.SDL_GetKeyboardState(voidptr numkeys) voidptr
@ -10,4 +10,4 @@ fn C.SDL_GetKeyboardState(voidptr numkeys) byteptr
//fn C.SDL_GetKeyboardState(intptr numkeys) intptr
//fn C.SDL_GetKeyboardState(intptr numkeys) &int
fn C.SDL_GetScancodeFromKey(key int) int
fn C.SDL_PumpEvents()
fn C.SDL_PumpEvents()