Skip to content

Instantly share code, notes, and snippets.

View tommyettinger's full-sized avatar
⚙️
Keeping the commit streak alive

Tommy Ettinger tommyettinger

⚙️
Keeping the commit streak alive
View GitHub Profile
@tommyettinger
tommyettinger / StartOnFirstThreadHelper.java
Created April 26, 2023 04:17
-XstartOnFirstThread (Magic)
/*
* Copyright 2020 damios
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
using SquidLib.SquidMath;
namespace Maps
{
/**
* An experimental way of speeding up {@link FastNoise} by using a large buffer of random bytes, and choosing a byte
* from the buffer purely by the current seed and position (a simpler calculation than a hash). This currently gives a
* modest speed boost to {@link #SIMPLEX}, {@link #PERLIN}, {@link #CUBIC}, and {@link #HONEY}, a smaller speed boost to
* {@link #FOAM}, and no change for {@link #VALUE} or {@link #WHITE_NOISE}. This class only uses the least-significant
@memononen
memononen / biasgaininf.c
Last active February 2, 2022 10:09
bias gain inflection point
float evalCurve(float x, float tx, float ty, float sa, float sb)
{
const float EPS = 1e-6f;
if (x < tx) {
return (ty * x) / (x + sa * (tx - x) + EPS);
} else {
return ((1-ty) * (x-1)) / ((1-x) - sb * (tx - x) + EPS) + 1.0f;
}
}
@tommyettinger
tommyettinger / Probit.java
Created August 13, 2020 23:49
Probit function in Java
/**
* Provides a {@link #probit(double)} method to convert from the (0.0,1.0) domain to a Gaussian range.
* Uses an algorithm by Peter John Acklam, as implemented by Sherali Karimov.
* Free to use, but you should credit Acklam and Karimov appropriately.
*/
public final class Probit {
private static final double LOW = 0.02425;
private static final double HIGH = 1.0 - LOW;
// Coefficients in rational approximations.
@mgsx-dev
mgsx-dev / Basic3DGame.java
Created May 2, 2020 07:35
Basic libgdx 3D boilerplate
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.Model;
@tommyettinger
tommyettinger / MemoryUsageOfDataStructures.txt
Created June 15, 2019 23:16
Memory usage of data structures on the JVM
This includes JDK8 and Guava 28 data structures, with the analysis done by https://github.com/DimitrisAndreou/memory-measurer .
========================================== 64-bit architecture ==========================================
========================================== Basic Lists, Sets, Maps ==========================================
ArrayList :: Bytes = 4.71, Objects = 0.00 Refs = 1.18 Primitives = {}
ImmutableList :: Bytes = 4.00, Objects = 0.00 Refs = 1.00 Primitives = {}
HashSet :: Bytes = 40.24, Objects = 1.00 Refs = 5.06 Primitives = {int=1.0}
@apangin
apangin / JDK 9 intrinsics
Last active May 11, 2023 18:32
JDK 9 intrinsics
_hashCode java/lang/Object.hashCode()I
_getClass java/lang/Object.getClass()Ljava/lang/Class;
_clone java/lang/Object.clone()Ljava/lang/Object;
_notify java/lang/Object.notify()V
_notifyAll java/lang/Object.notifyAll()V
_dabs java/lang/Math.abs(D)D
_dsin java/lang/Math.sin(D)D
_dcos java/lang/Math.cos(D)D
_dtan java/lang/Math.tan(D)D
_datan2 java/lang/Math.atan2(DD)D
@tommyettinger
tommyettinger / CLEANED_UP.txt
Last active September 7, 2020 08:21
SquidLib DungeonGenerator sample given TilesetType.DEFAULT_DUNGEON
┌─────────────┬─────┬───────────────┐ ┌─────┬───────────┐ ┌─────┐ ┌───────┐ ┌─────────┐ ┌─────┬───────────┐ ┌─────────┐
│ . . . . . . │ . . │ . . . . . . . └───┘ . . │ . . . . . │ │ . . │ ┌─┘ . . . ├───────────────┘ . . . . └───┘ . . │ . . . . . │ │ . . . . │
│ . . . . . . │ . . │ . . ────. . . . . . . . │ . . . . . ├───────┘ . . └─┐ │ . . . . │ . . . . . . . . . . . . . . . . . │ . . . . . │ ┌─┘ . . . ┌─┘
│ . . │ . ┌───┘ . . │ . . . . . . . . . . . . │ . . . . . │ . . . . . . . │ │ . . . ┌─┤ . . . . . . . . . . . . . . . . . │ . . . . . └─┘ . . . . └───┐
│ . . │ . │ . . . . . . . ──┬───────┬───┐ . . └─+ ──┐ . . . . . . . . . . │ │ . . ┌─┘ │ . . │ . . ┌───+ ┬─┐ . . ┌───┐ . . │ . . │ . . . . . . . . . . └─┐
│ . . │ . │ . . . . . . . . │ . . . │ │ . . . . . │ . . . . . . ┌─┐ . . └─────┘ . . └───┘ . . │ . . │ . . │ │ . . │ │ . . . . . │ . . . . . . . . . . . └─┐
│ . . . . │ . . . . │ . . . │ . . . │ │ . . . . . │ . .
@apangin
apangin / HotSpot JVM intrinsics
Last active May 11, 2023 18:32
HotSpot JVM intrinsics
_hashCode java/lang/Object.hashCode()I
_getClass java/lang/Object.getClass()Ljava/lang/Class;
_clone java/lang/Object.clone()Ljava/lang/Object;
_dabs java/lang/Math.abs(D)D
_dsin java/lang/Math.sin(D)D
_dcos java/lang/Math.cos(D)D
_dtan java/lang/Math.tan(D)D
_datan2 java/lang/Math.atan2(DD)D
_dsqrt java/lang/Math.sqrt(D)D
_dlog java/lang/Math.log(D)D
@MobiDevelop
MobiDevelop / EncryptedFileHandle.java
Created August 30, 2013 13:18
LibGDX FileHandleWrapper
package com.mobidevelop.files;
import java.io.InputStream;
import java.io.OutputStream;
import com.badlogic.gdx.files.FileHandle;
public class EncryptedFileHandle extends FileHandleWrapper {
public EncryptedFileHandle(FileHandle file) {