create golf version of quine

This commit is contained in:
Crispy 2024-08-11 19:28:17 +02:00
parent aa610035b1
commit 5b59f487e6
7 changed files with 365 additions and 1 deletions

80
Assets/test/QuineGolf.mat Normal file
View file

@ -0,0 +1,80 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: QuineGolf
m_Shader: {fileID: 4800000, guid: 0c4c2f5d8a89897eeaca772520f257ab, type: 3}
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 71fb6677d855d7ec3a0fdaea5ec5d779
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -122,6 +122,162 @@ NavMeshSettings:
debug: debug:
m_Flags: 0 m_Flags: 0
m_NavMeshData: {fileID: 0} m_NavMeshData: {fileID: 0}
--- !u!1 &97266993
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 97267000}
- component: {fileID: 97266999}
- component: {fileID: 97266998}
- component: {fileID: 97266997}
- component: {fileID: 97266996}
- component: {fileID: 97266995}
- component: {fileID: 97266994}
m_Layer: 0
m_Name: QuineGolf
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &97266994
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 97266993}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 990f6f4efb7f4ec98ad99f6dff1bc6f6, type: 3}
m_Name:
m_EditorClassIdentifier:
type: 3
objectId: bab5c804-640f-445c-90c5-fda732b56ca6
randomNum: 62965840
unityVersion: 2021.3.41f1
cckVersion: 3.10:132
--- !u!114 &97266995
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 97266993}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a37fd8d654d5c2840a0ab3a5ad65a5ae, type: 3}
m_Name:
m_EditorClassIdentifier:
spawnHeight: 0
useAdditionalValues: 0
syncValues: []
propPrivacy: 1
subSyncs: []
spawnableType: 0
preGeneratedInstanceId:
--- !u!114 &97266996
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 97266993}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 12974925555b471580cacf5d2d5fa9e3, type: 3}
m_Name:
m_EditorClassIdentifier:
gripType: 1
gripOrigin: {fileID: 0}
disallowTheft: 0
maximumGrabDistance: 0
snappingReferences: []
autoHold: 0
updateWithPhysics: 1
ikReference: {fileID: 0}
--- !u!65 &97266997
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 97266993}
m_Material: {fileID: 0}
m_IsTrigger: 1
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 0.05}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &97266998
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 97266993}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 71fb6677d855d7ec3a0fdaea5ec5d779, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &97266999
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 97266993}
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &97267000
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 97266993}
m_LocalRotation: {x: 0, y: 1, z: 0, w: 0}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 10
m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0}
--- !u!1 &393682612 --- !u!1 &393682612
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1451,7 +1607,7 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2046637839} m_GameObject: {fileID: 2046637839}
m_LocalRotation: {x: 0, y: 1, z: 0, w: 0} m_LocalRotation: {x: 0, y: 1, z: 0, w: 0}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: -1, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 0c4c2f5d8a89897eeaca772520f257ab
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

4
text_shader/out_golfed.h Normal file

File diff suppressed because one or more lines are too long

View file

@ -8,6 +8,7 @@ use image::{GenericImageView, ImageReader};
const FULL_CHARSET: &[u8] = b" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\n\t"; const FULL_CHARSET: &[u8] = b" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\n\t";
fn main() { fn main() {
golfed();
// source code conversion // source code conversion
let source_text = read_to_string("../Assets/test/quine.shader").unwrap(); let source_text = read_to_string("../Assets/test/quine.shader").unwrap();
let mut encoded_text: Vec<u32> = Vec::new(); let mut encoded_text: Vec<u32> = Vec::new();
@ -35,6 +36,10 @@ fn main() {
temp = 0; temp = 0;
} }
} }
if i > 0{
temp <<= (4-i)*8;
encoded_text.push(temp);
}
let mut out_string = String::new(); let mut out_string = String::new();
out_string += "\t\t\t\tconst uint text[] = {"; out_string += "\t\t\t\tconst uint text[] = {";
for t in &encoded_text { for t in &encoded_text {
@ -76,3 +81,75 @@ fn main() {
let mut file = File::create("out.h").unwrap(); let mut file = File::create("out.h").unwrap();
file.write_all(out_string.as_bytes()).unwrap(); file.write_all(out_string.as_bytes()).unwrap();
} }
fn golfed() {
// source code conversion
let source_text = read_to_string("../Assets/test/quine_golf.shader").unwrap();
let mut encoded_text: Vec<u32> = Vec::new();
let mut temp = 0;
let mut i = 0;
let mut blob_start = 0;
let mut used_charset:Vec<_> = " 0123456789abcdefx,".chars().collect();
for (index, char) in source_text.chars().enumerate() {
if char == '?' {
blob_start = index;
}
temp <<= 8;
let char_index = used_charset
.iter()
.position(|&c| c == char)
.unwrap_or_else(|| {
used_charset.push(char);
used_charset.len() - 1
});
temp |= (char_index as u32) & 0xff;
i += 1;
if i == 4 {
i = 0;
encoded_text.push(temp);
temp = 0;
}
}
if i > 0{
temp <<= (4-i)*8;
encoded_text.push(temp);
}
let mut out_string = String::new();
out_string += "w t[]={";
for t in &encoded_text {
out_string += &format!("{t:#010x},");
}
out_string += "};\n";
out_string += &format!("w L={};\n", encoded_text.len()*11);
out_string += &format!("w b={blob_start};\n");
// font
let img = ImageReader::open("6x6.png").unwrap().decode().unwrap();
let mut out = Vec::new();
for c in used_charset {
let col = c as u32 & 0b1_1111;
let row = (c as u32 >> 5) & 0b111;
let mut encoded: [u32; 4] = [0; 4];
for section in 0..4 {
for y in 0..4 {
for x in 0..8 {
let px = col * 9 + x;
let py = row * 16 + (16 - 1 - section * 4) - y;
let pixel = (img.get_pixel(px, py).0[0] != 0) as u32;
let offset = x + ((y & 3) << 3);
encoded[section as usize] |= pixel << offset;
}
}
}
out.push(encoded);
}
out_string += "w A[][4]={";
for (_i, c) in out.iter().enumerate() {
out_string += &format!("{{{},{},{},{}}},", c[0], c[1], c[2], c[3]);
}
out_string += "};\n";
let mut file = File::create("out_golfed.h").unwrap();
file.write_all(out_string.as_bytes()).unwrap();
}