Пример #1
0
func marshalControlFlags(c ControlFlags) (n int) {
	n = bits.SetCond(n, 7, c.UseMaximumTime)
	n = bits.SetCond(n, 6, c.UseMinimumTime)
	n = bits.SetCond(n, 5, c.SyncWithAdjacentStation)
	n = bits.SetCond(n, 4, c.LeaveIfAnotherTrainArrives)
	n = bits.SetCond(n, 3, c.WaitForLoad)
	n |= int(c.Load)
	return n
}
Пример #2
0
Файл: track.go Проект: silky/rct
// Turn track elements back into bytes (opposite of above function)
//
// Taken from http://freerct.github.io/RCTTechDepot-Archive/trackQualifier.html
func marshalElement(e Element) ([]byte, error) {
	buf := make([]byte, 2)
	buf[0] = byte(e.Segment.Type)
	featureBit := 0
	featureBit = bits.SetCond(featureBit, 7, e.ChainLift)
	featureBit = bits.SetCond(featureBit, 6, e.InvertedTrack)
	featureBit = bits.SetCond(featureBit, 3, e.Station)
	if e.Segment.Type == ELEM_END_STATION || e.Segment.Type == ELEM_BEGIN_STATION || e.Segment.Type == ELEM_MIDDLE_STATION {
		// Set the station bit
		featureBit |= e.StationNumber
	}

	// XXX booster?
	if e.Segment.Type == ELEM_BRAKES || e.Segment.Type == ELEM_BLOCK_BRAKES {
		bm := e.BoostMagnitude / 7.6
		featureBit |= int(bm)
	} else {
		// 2nd bit seems to be set in most cases.
		featureBit |= 1 << 2
	}
	// XXX, rotation for multi dimensional coasters
	buf[1] = byte(featureBit)
	return buf, nil
}
Пример #3
0
func marshalEgress(egr Egress) ([]byte, error) {
	buf := make([]byte, 6)
	ftrBit := egr.Direction
	ftrBit = bits.SetCond(ftrBit, 7, egr.Exit)
	buf[1] = byte(ftrBit)

	b := new(bytes.Buffer)
	err := binary.Write(b, binary.LittleEndian, egr.XOffset)
	if err != nil {
		return []byte{}, err
	}
	copy(buf[2:4], b.Bytes())
	b.Reset()
	err = binary.Write(b, binary.LittleEndian, egr.YOffset)
	if err != nil {
		return []byte{}, err
	}
	copy(buf[4:6], b.Bytes())
	return buf, nil
}