JGO Grabbag

In the spirit of “It’s better to ask forgiveness than permission” I’d started an experiment.

The idea is a non-library of java game related code snippets that one could search through in the same manner as one might have searched through 's attic when one was a kid looking for treasure.

Pretty nice… Considering I myself have a project on my workspace called “CodeSnippets” where I dump all my code experiments, as well as interesting snippets I take from other people.

:slight_smile:

Yes there are a lot of little interesting code snippets out there and everyone has a util/misc package in his project. Would be nice if we would have a huge repository with many code-snippets of this category.

here three random snippets from my code base which could be usefull 1, 2 & 3

[quote=“Danny02,post:3,topic:46215”]
The Shared Code subforum could probably serve that purpose. In fact, I began my CodeSnippets “project” after reading this thread and realizing all those small pieces of code I had spread through my different projects would better be compiled somewhere… In fact, after I found out Riven’s site, my CondeSnippets project now has it’s own src.riven package :stuck_out_tongue:

(I like to create a package per author of the original code snippets, helps when looking to ask questions :slight_smile: )

@Danny02: There…now you can add stuff

The rough idea is to be complimentary to shared code/pastebin. I find that there is code that I think about sharing which I don’t because it would be awkward as a shared code post and too messy as a pastebin. Most of the stuff that I do post is drastically paired down from my existing.

Hey kids: Sharing is caring! Make my day and bombard me with requests to be made a contributor.

The PRNG set is now stubbed out…just needs a few tweaks and additions to helper functions. There 6 main generators which cover all possible use-cases in a game runtime (other than 4K). Added a novelty generator than runs in both directions. Added non-progressive Sobol generators…you have to decided in advance the number of points you want to generate…generators are reusable.

Given the popularity of cube-world stuff, uniform 2D grids and the like…added in-order 2D/3D cell walking along line segment or ray. Barely tested. Oh and some other stuff:

I know what ya’ll really want: an arbitrary discrete probability distribution function map.

https://github.com/roquendm/JGO-Grabbag/blob/master/src/roquen/math/rng/RandomSelect.java

[start of google translate]
A fixed list of entries each of which has a fixed probability of occurring. You pass it a pseudo or quasi random number and it selects a matching entry.
[end of translation]

Example usage: single item drop list or population, fluff text from a unit/NPC, etc.

During the building process instead of providing the extra probabilities you provide “weight” values which indicate relative probabilities. Example you enter (rock,5) (lint,1) (thing,2). You’re 5 times as likely to get “rock” as a result when compared to “lint” and 2x as likely to get “thing” compared to “lint”. The exact numbers have no meaning.

Ray/Grid traversal for all touched cells RayGrid{2,3}D and a generic factory.

First pass of experimental testing of HotSpot transforms: https://github.com/roquendm/JGO-Grabbag/blob/master/src/roquen/info/HsIntrinsics.java

Some observations (insignificant number of data points so take with grain of salt). HotSpot is doing the simple thing (nothing wrong with that given the compiler is a work-stealer) and is only handling certain types of primitives in each logical register set. Integer/pointers in general purpose, float/double in SSE…except when x87 has specialized opcodes for the operation. In that case it does the simple thing…move SSE to memory, memory to x87 perform op and store…rinse and repeat. Likewise where an integer op could be performed in SSE…move to GP…do the thing, etc.

If an intrinsic math function (Float,Double,Math) has SSE support then the native opcode is generated. Example: (float)Math.sqrt(floatValue) generates single opcode sqrtss which is pure single, Math.sqrt(doubleValue) generates single opcode sqrtsd. Don’t know about floor & ceiling…my newish hardware is working hard to melt the polar ice-caps. For icore2 it’s doing typically functionality for performing the ops without changing the rounding mode.

This is an amazing thread!