Example #1
0
func main() {
	ugo.MaxProcs()
	var srcTimeGlsl, srcTimeEmbeds time.Time
	force := false
	nginePath = os.Args[1]
	outFilePath = filepath.Join(nginePath, "core", "-gen-embed.go")
	if fileInfo, err := os.Stat(outFilePath); err == nil {
		outFileTime = fileInfo.ModTime()
	} else {
		force = true
	}
	if outFileTime.IsZero() {
		force = true
	}

	srcDirPathEmbeds := filepath.Join(nginePath, "core", "_embed")
	if !force {
		if errs := ufs.NewDirWalker(false, nil, newWalkerVisitor_IsNewerThan(outFileTime, &srcTimeGlsl)).Walk(srcDirPathEmbeds); len(errs) > 0 {
			panic(errs[0])
		}
	}

	if force || srcTimeGlsl.UnixNano() > outFileTime.UnixNano() || srcTimeEmbeds.UnixNano() > outFileTime.UnixNano() {
		fmt.Printf("Re-generating %s...\n", outFilePath)
		wait.Add(2)
		go makeShaders(srcDirPathEmbeds)
		go makeEmbeds(srcDirPathEmbeds)
		wait.Wait()
		ufs.WriteTextFile(outFilePath, fmt.Sprintf("package core\n\n//\tGenerated by ng-buildrun\nfunc init() {\n%s\n%s\n}", newSrc.shaders, newSrc.embeds))
	}
}
Example #2
0
//	Attempts to xml.Unmarshal() all files in the "infiles" sub-directory of the specified directory path into the interface{} structure returned by the specified constructor.
//	For each such input file, then attempts to xml.MarshalIndent() said structure back into a new output XML file with the same name, in the "outfiles" sub-directory of the specified directory path.
func TestViaRemarshal(dirPath string, makeEmptyDoc func() interface{}) {
	var dirPathInFiles = filepath.Join(dirPath, "infiles")
	var dirPathOutFiles = filepath.Join(dirPath, "outfiles")
	var loadXmlDocFile = func(filename string) bool {
		log.Printf("Loading %s", filename)
		doc, dataOrig := makeEmptyDoc(), ufs.ReadBinaryFile(filename, true)
		err := xml.Unmarshal(dataOrig, doc)
		if err != nil {
			panic(err)
		}
		if OnDocLoaded != nil {
			OnDocLoaded(doc)
		}
		outFileName := filepath.Join(dirPathOutFiles, filepath.Base(filename))
		log.Printf("Writing %s", outFileName)
		dataFaks, err := xml.MarshalIndent(doc, "", "\t")
		if err != nil {
			panic(err)
		}
		ufs.WriteTextFile(outFileName, strings.Trim(string(dataFaks), " \r\n\t"))
		log.Printf("Verifying...")
		if errs := verifyDocs(dataOrig, dataFaks); len(errs) > 0 {
			for _, err = range errs {
				log.Printf("%v", err)
			}
		}
		return true
	}
	if errs := ufs.NewDirWalker(false, nil, loadXmlDocFile).Walk(dirPathInFiles); len(errs) > 0 {
		panic(errs[0])
	}
}
Example #3
0
func main() {
	ugo.MaxProcs()
	ufs.NewDirWalker(false, nil, func(fullPath string) bool {
		blobs = append(blobs, ufs.ReadBinaryFile(fullPath, true))
		return true
	}).Walk(dirPath)

	testComp("flate1", func(w io.Writer) (wc io.WriteCloser) {
		var err error
		if wc, err = flate.NewWriter(w, 1); err != nil {
			panic(err)
		}
		return
	}, flate.NewReader)
	testComp("flate9", func(w io.Writer) (wc io.WriteCloser) {
		var err error
		if wc, err = flate.NewWriter(w, 9); err != nil {
			panic(err)
		}
		return
	}, flate.NewReader)
	testComp("lzw\t", func(w io.Writer) io.WriteCloser {
		return lzw.NewWriter(w, lzw.MSB, 8)
	}, func(r io.Reader) io.ReadCloser {
		return lzw.NewReader(r, lzw.MSB, 8)
	})
	testComp("zlib", func(w io.Writer) io.WriteCloser {
		return zlib.NewWriter(w)
	}, func(r io.Reader) (rc io.ReadCloser) {
		var err error
		if rc, err = zlib.NewReader(r); err != nil {
			panic(err)
		}
		return
	})
	testComp("gzip", func(w io.Writer) io.WriteCloser {
		return gzip.NewWriter(w)
	}, func(r io.Reader) (rc io.ReadCloser) {
		var err error
		if rc, err = gzip.NewReader(r); err != nil {
			panic(err)
		}
		return
	})
	printStats("PACK:", packStats)
	printStats("UNPACK:", unpackStats)
}