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
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)
}
Example #3
0
func main() {
	var err error
	ugo.MaxProcs()
	dirTmpSkipper.AddPatterns("_tmp")
	push := func(msg string, push bool, pusher func() error) {
		defer wg.Done()
		if push {
			if err = pusher(); err != nil {
				panic(err)
			} else {
				log.Println(msg + "YUP.")
			}
		} else {
			log.Println(msg + "NOPE.")
		}
	}
	wg.Add(2)
	log.Println("Waiting...")
	go push("DropBox?... ", pushToDropBox, copyToDropbox)
	go push("GitHub?... ", pushToGitRepos, copyToRepos)
	wg.Wait()
	log.Println("...all done.")
}
Example #4
0
//	Called by each example-app's func main(). Initializes go:ngine, calls the specified setupExampleScene function, then enters The Loop.
func Main(setupExampleScene, onAppThread, onWinThread func()) {
	//	by design, go:ngine doesn't do this for you automagically:
	runtime.LockOSThread()
	ugo.MaxProcs()
	spew.Config.DisableMethods = true

	//	can set window options before it is created
	win := &ng.UserIO.Window
	//	release apps shouldn't do this, but during dev/test we want to observe max fps:
	win.SetSwapInterval(0)
	win.SetSize(1366, 768)
	winTitle.appName = filepath.Base(os.Args[0])
	win.SetTitle(fmt.Sprintf("Loading \"%s\" example app... (%v CPU cores)", winTitle.appName, runtime.GOMAXPROCS(0)))

	opt := &ng.Options

	//	While the default for this (true on Macs only) is reasonable for release apps at present,
	//	here we force core profile to verify all of go:ngine's GL code is fully core-profile compliant
	opt.Initialization.GlContext.CoreProfile.ForceFirst = true

	//	Release apps shouldn't do this, but here we're verifying everything runs in the oldest-supported GL version:
	opt.Initialization.GlContext.CoreProfile.VersionHint = 3.3
	opt.Initialization.DefaultCanvas.GammaViaShader = true

	//	Worth toggling this every once in a while just to see whether it makes a perf diff at all...
	opt.Loop.GcEvery.Frame = true

	opt.AppDir.BasePath = AppDirBasePath()
	opt.AppDir.Temp.BaseName = filepath.Join("_tmp", filepath.Base(os.Args[0]))
	opt.AppDir.Temp.ShaderSources, opt.AppDir.Temp.CachedTextures = "glsl", "tex"
	// but for now, we don't need separate per-app tmp dirs:
	opt.AppDir.Temp.BaseName = "_tmp"

	if compressCachedTextures := true; compressCachedTextures {
		opt.Textures.Storage.DiskCache.Compressor = func(w io.WriteCloser) (wc io.WriteCloser) {
			var err error
			if wc, err = flate.NewWriter(w, 9); err != nil {
				panic(err)
			}
			return
		}
		opt.Textures.Storage.DiskCache.Decompressor = func(r io.ReadCloser) io.ReadCloser {
			return flate.NewReader(r)
		}
	}

	//	STEP 1: init go:ngine
	err := ng.Init(WinFullscreen, newGlCtx())
	if err != nil {
		fmt.Printf("ABORT:\n%v\n", err)
	} else {
		//	STEP 2: post-init, pre-loop setup
		ng.Loop.On.EverySec, ng.Loop.On.AppThread, ng.Loop.On.WinThread = onSec, onAppThread, onWinThread

		PostFxCanvas = ng.Core.Render.Canvases[0]
		PostFxView = PostFxCanvas.Views[0]
		PostFxView.RenderStates.ClearColor.Set(0.9, 0.6, 0.3, 1)

		if setupExampleScene != nil {
			SceneCanvas = ng.Core.Render.Canvases.AddNew(true, 1, 1)
			SceneView = SceneCanvas.AddNewView("Scene")
			rts := SceneView.Technique_Scene()
			SceneCam, winTitle.batched = &rts.Camera, ugo.Ifi(rts.Batch.Enabled, 1, 0)
			SceneView.RenderStates.ClearColor.Set(0.5, 0.6, 0.85, 1)
			setupExampleScene()
			if err = ng.Core.Libs.Meshes.GpuSync(); err != nil {
				panic(err)
			} else {
				for m := 0; m < len(ng.Core.Libs.Meshes); m++ {
					ng.Core.Libs.Meshes[m].Unload()
				}
			}
			ng.Core.GpuSyncImageLibs()
		}
		time.Sleep(ArtificialSplashScreenDelay)
		numCgo.preLoop = runtime.NumCgoCall()

		//	STEP 3: enter... Da Loop.
		ng.Loop.Run()
		numCgo.postLoop = runtime.NumCgoCall()
		PrintPostLoopSummary() // don't wanna defer this: useless when exit-on-panic
		ng.Dispose()           // don't wanna defer this: unpredictable state when exit-on-panic
	}
}