1
0
Fork 0

auts: crushing stone object with processor test

This commit is contained in:
coaljoe 2020-09-06 20:30:29 +03:00
parent d40166ef0d
commit 11b475090c
9 changed files with 109 additions and 12 deletions

View File

@ -14,6 +14,36 @@ fn crush_stone_bit() {
}
// stone -> crushed stone
// XXX turn stone object into crushed stone object
// XXX all volume
// XXX this can be created/used as a factory (?)
fn crush_stone_object2(ob &Object) {
println("crush_stone_object2")
// TODO: amt, force, fracture_force?
// XXX crush entire object
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)
}
// stone -> crushed stone
fn crush_stone_object(ob &Object) {

View File

@ -2,10 +2,24 @@ module bits
fn init_elem_lib() {
mut el := new_elem()
el.name = "stone"
el.elem_type = .stone
el.density = 8000
{
mut el := new_elem()
el.name = "stone"
el.elem_type = .stone
el.density = 8000
bits_ctx.elem_lib["stone"] = el
bits_ctx.elem_lib["stone"] = el
}
{
mut el := new_elem()
el.name = "crushed_stone"
el.elem_type = .stone // XXX?
el.density = 8000 // XXX?
// custom material/element density?
el.aggregate_state = .crushed
bits_ctx.elem_lib["crushed_stone"] = el
}
}

View File

@ -37,8 +37,17 @@ enum ElemType {
// XXX add only as a subtype of concrete? only useful for recycling information...
reinforced_concrete // Approx 90% concrete, 10% steel (on average)
}
enum SolidState {
solid
liquid
gas
}
enum AggregateState {
solid
crushed
}
struct Elem {
@ -47,7 +56,14 @@ mut:
elem_type ElemType
density int // kg/m3 // XXX per bit?
flameable bool
liquid bool
liquid bool // XXX is technically a liquid in its normal state?
// Matter state
solid_state SolidState
// Material aggregate state
// XXX?
aggregate_state AggregateState
// when
//when_crushed_fn fn()
@ -69,6 +85,10 @@ fn new_elem() &Elem {
//generic_processor0: none,
}
*/
e := &Elem{}
e := &Elem{
solid_state: .solid,
aggregate_state: .solid,
}
return e
}

View File

@ -26,7 +26,8 @@ fn (gpc &GenericCrusherProcessor) process(ob &Object) {
if ob.elem.name == "stone" {
println("> create smaller stones")
crush_stone_object(ob)
//crush_stone_object(ob)
crush_stone_object2(ob)
println("> create sand")
println("> (visual) create dust")

View File

@ -16,3 +16,12 @@ test:
should dimentions just be marked explicitly as optional?
? should elements/objects/blocs have material aggregate state,
like crushed|solid|liquid etc?
? how to make a compound object with two or more materials/elems?
like tree with green leaves?
? should there be materials? as a separate thing from elements
(custom elements?)
? use virtual processors in the bit world to create debris/ruins/
break objects?

View File

@ -3,8 +3,10 @@ module bits
pub fn bits_main() {
println("bits: bits_main()")
// Init
bits_ctx = bits.new_context()
init_elem_lib()
mut e := new_elem()
@ -120,6 +122,10 @@ pub fn bits_main() {
mut gcp := new_generic_crusher_processor()
gcp.process(ob)
println("new bits volume: ${ob.bits_volume()}")
println("new volume: ${ob.volume()}")
println("new elem name: ${ob.elem.name}")
//e4.generic_processor0 = gcp
// Try to process itself

View File

@ -17,6 +17,7 @@ mut:
//dim_x int // Approx.
//dim_y int
//dim_z int
// XXX use volume to calculate object bounds.
// Material/Elem
elem &Elem // XXX use id/enum

View File

@ -1,5 +1,6 @@
module bits
// A convertor from one element to another
struct Processor {
mut:
name string
@ -23,8 +24,23 @@ fn new_processor() &Processor {
return p
}
fn (p &Processor) process(o &Object) {
fn (p &Processor) process(mut o Object) {
println("processor process")
new_elem := p.out_elem
new_bits_size := int(o.bits_size * p.output_factor)
if isnil(new_elem) {
println("error: new_elem cannot be nil")
exit(2)
}
println("new_elem: ${isnil(new_elem)}")
println("new_elem: $new_elem")
println("new_bits_size: $new_bits_size")
o.elem = new_elem
o.bits_size = new_bits_size
println("done processing")
}

View File

@ -1,6 +1,6 @@
module bits
import math
//import math
[inline]
fn bits_to_m(n_bits int) f32 {