Rename some material parameters, look up the true material density, and add some more function types.

fixes #1074
This commit is contained in:
IntegratedQuantum 2025-02-20 20:42:26 +01:00
parent 894a8bd93a
commit feff96b3f3
22 changed files with 201 additions and 120 deletions

View File

@ -3,10 +3,12 @@
.blockHealth = 6,
.item = .{
.material = .{
.density = 1.0,
.resistance = 1.0,
.power = 0.2,
.roughness = 0.7,
.density = 0.45,
.strength = 1.0,
.elasticity = 1.2,
.grip = 1.5,
.hardness = 1.9,
.textureRoughness = 0.7,
.colors = .{
0xff8c6f59, 0xffa07f66, 0xffb8917b, 0xffd7b194, 0xffe4c29f,
},

View File

@ -6,10 +6,12 @@
},
.item = .{
.material = .{
.density = 0.7,
.resistance = 1.3,
.power = 0.3,
.roughness = 2.5,
.density = 3.0,
.strength = 1.3,
.elasticity = 2.5,
.grip = 0.4,
.hardness = 6.0,
.textureRoughness = 2.5,
.colors = .{
0xff282328, 0xff353135, 0xff434041, 0xff4A4849, 0xff605E5F,
},

View File

@ -3,10 +3,12 @@
.blockHealth = 6,
.item = .{
.material = .{
.density = 0.6,
.resistance = 0.8,
.power = 0.2,
.roughness = 0.7,
.density = 0.59,
.strength = 0.8,
.elasticity = 0.7,
.grip = 1.0,
.hardness = 2.0,
.textureRoughness = 0.7,
.colors = .{
0xff9b7a5b, 0xffbf9872, 0xffdeb287, 0xfff2c89c, 0xffffdfb7,
},

View File

@ -6,10 +6,12 @@
},
.item = .{
.material = .{
.density = 1.0,
.resistance = 1.0,
.power = 0.4,
.roughness = 1.0,
.density = 2.4,
.strength = 1.0,
.elasticity = 2.0,
.grip = 0.4,
.hardness = 7.0,
.textureRoughness = 1.0,
.colors = .{
0xff3d3d3d, 0xff535353, 0xff6b6b6b, 0xff81807e, 0xff9c9996,
},

View File

@ -7,10 +7,12 @@
},
.item = .{
.material = .{
.density = 0.9,
.resistance = 1.1,
.power = 0.35,
.roughness = 0.5,
.density = 2.6,
.strength = 1.1,
.elasticity = 2.0,
.grip = 0.3,
.hardness = 5.5,
.textureRoughness = 0.5,
.colors = .{
0xff72403C, 0xff905B57, 0xffB77966, 0xffC2846A, 0xffC49B77,
},

View File

@ -7,10 +7,12 @@
},
.item = .{
.material = .{
.density = 0.8,
.resistance = 1.6,
.power = 0.4,
.roughness = 1.5,
.density = 2.8,
.strength = 1.6,
.elasticity = 3.5,
.grip = 0.4,
.hardness = 7.5,
.textureRoughness = 1.5,
.colors = .{
0xff6E757F, 0xff86898E, 0xffA4A7AA, 0xffB9BCBF, 0xffCACCCE,
},

View File

@ -7,10 +7,12 @@
},
.item = .{
.material = .{
.density = 1.25,
.resistance = 0.9,
.power = 0.35,
.roughness = 0.9,
.density = 2.1,
.strength = 0.9,
.elasticity = 1.5,
.grip = 0.5,
.hardness = 4.5,
.textureRoughness = 0.9,
.colors = .{
0xff70583E, 0xff886D52, 0xffAB8D6A, 0xffC09B6E, 0xffCCA780,
},

View File

@ -3,10 +3,12 @@
.blockHealth = 6,
.item = .{
.material = .{
.density = 1.0,
.resistance = 1.2,
.power = 0.3,
.roughness = 0.7,
.density = 0.55,
.strength = 1.2,
.elasticity = 1.0,
.grip = 1.2,
.hardness = 2.1,
.textureRoughness = 0.7,
.colors = .{
0xff734c2f, 0xff8e5d38, 0xffa26a3f, 0xffbd7e48, 0xffcf9459,
},

View File

@ -6,10 +6,12 @@
},
.item = .{
.material = .{
.density = 1.25,
.resistance = 1.4,
.power = 0.5,
.roughness = 0.5,
.density = 2.7,
.strength = 1.4,
.elasticity = 2.8,
.grip = 0.5,
.hardness = 4.0,
.textureRoughness = 0.5,
.colors = .{
0xffA89B94, 0xffC9C0BB, 0xffECE9E3, 0xffFBF8F1, 0xffECE9E3,
},

View File

@ -3,10 +3,12 @@
.blockHealth = 6,
.item = .{
.material = .{
.density = 1.0,
.resistance = 1.0,
.power = 0.2,
.roughness = 0.7,
.density = 0.64,
.strength = 1.0,
.elasticity = 0.9,
.grip = 1.0,
.hardness = 2.0,
.textureRoughness = 0.7,
.colors = .{
0xff835e37, 0xffa37543, 0xffbd8a4f, 0xffd3a164, 0xffe5b570,
},

View File

@ -7,10 +7,12 @@
},
.item = .{
.material = .{
.density = 0.5,
.resistance = 2.0,
.power = 0.5,
.roughness = 0.1,
.density = 2.5,
.strength = 0.5,
.elasticity = 7.0,
.grip = 0.3,
.hardness = 6.0,
.textureRoughness = 0.1,
.colors = .{
0xff0F0811, 0xff19121C, 0xff312436, 0xff69486B, 0xff462F47,
},

View File

@ -3,10 +3,12 @@
.blockHealth = 6,
.item = .{
.material = .{
.density = 1.5,
.resistance = 1.2,
.power = 0.2,
.roughness = 0.7,
.density = 0.5,
.strength = 1.2,
.elasticity = 1.1,
.grip = 1.0,
.hardness = 2.0,
.textureRoughness = 0.7,
.colors = .{
0xff533f27, 0xff664c2e, 0xff795a37, 0xff8c6b41, 0xffa37b46,
},

View File

@ -6,10 +6,12 @@
},
.item = .{
.material = .{
.density = 0.25,
.resistance = 0.25,
.power = 0.25,
.roughness = 3.0,
.density = 1.9,
.strength = -0.5,
.elasticity = 0.1,
.grip = 0.7,
.hardness = 5.0,
.textureRoughness = 3.0,
.colors = .{
0xffAF8354, 0xffC89965, 0xffE6B776, 0xffEEC589, 0xffEDD0AD,
},

View File

@ -7,10 +7,12 @@
},
.item = .{
.material = .{
.density = 1.0,
.resistance = 1.5,
.power = 0.4,
.roughness = 1.0,
.density = 2.4,
.strength = 1.0,
.elasticity = 2.0,
.grip = 0.4,
.hardness = 7.0,
.textureRoughness = 1.0,
.colors = .{
0xff444444, 0xff626262, 0xff7A7876, 0xff878583, 0xff9c9996,
},

View File

@ -7,10 +7,12 @@
},
.item = .{
.material = .{
.density = 2.0,
.resistance = 3.0,
.power = 0.8,
.roughness = 2.0,
.density = 3.5,
.strength = 3.0,
.elasticity = 7.0,
.grip = 0.1,
.hardness = 8.5,
.textureRoughness = 2.0,
.colors = .{
0xff030308, 0xff0D0C11, 0xff151420, 0xff1C1A2B, 0xff28253D,
},

View File

@ -3,10 +3,12 @@
.blockHealth = 6,
.item = .{
.material = .{
.density = 1.0,
.resistance = 1.0,
.power = 0.2,
.roughness = 0.7,
.density = 0.39,
.strength = 1.0,
.elasticity = 0.9,
.grip = 0.9,
.hardness = 2.5,
.textureRoughness = 0.7,
.colors = .{
0xff35281b, 0xff493523, 0xff60462e, 0xff6f5133, 0xff815d39,
},

View File

@ -1,10 +1,12 @@
.{
.texture = "diamond.png",
.material = .{
.density = 1.0,
.resistance = -5.0,
.power = 20.0,
.roughness = 0.1,
.density = 3.5,
.strength = -5.0,
.elasticity = 10.0,
.grip = 0.1,
.hardness = 10.0,
.textureRoughness = 0.1,
.colors = .{
0xff847bce, 0xff8b9fe0, 0xff94c6ea, 0xffb0eaf6, 0xffffffff,
},

View File

@ -1,10 +1,12 @@
.{
.texture = "iron_ingot.png",
.material = .{
.density = 1.5,
.resistance = 2.5,
.power = 5.0,
.roughness = 0.1,
.density = 7.874,
.strength = 5.0,
.elasticity = 10.0,
.grip = 0.1,
.hardness = 4.0,
.textureRoughness = 0.1,
.colors = .{
0xff69696b, 0xff878484, 0xffa3a3a3, 0xffc2c2c2, 0xffe9e9e9,
},

View File

@ -5,7 +5,7 @@
.name = .handle,
.parameterSets = .{
.{
.source = .resistance,
.source = .strength,
.destination = .maxDurability,
.factor = 20,
},
@ -14,13 +14,19 @@
.destination = .swingTime,
.factor = 0.1,
},
.{
.source = .grip,
.destination = .swingTime,
.functionType = .inverse,
.factor = 0.05,
},
},
},
.{
.name = .center,
.parameterSets = .{
.{
.source = .resistance,
.source = .strength,
.destination = .maxDurability,
.factor = 50,
},
@ -35,7 +41,7 @@
.factor = 0.2,
},
.{
.source = .power,
.source = .hardness,
.destination = .power,
.functionType = .squareRoot,
.factor = 0.1,
@ -46,7 +52,7 @@
.name = .blade,
.parameterSets = .{
.{
.source = .resistance,
.source = .strength,
.destination = .maxDurability,
.factor = 20,
},
@ -61,7 +67,7 @@
.factor = 0.2,
},
.{
.source = .power,
.source = .hardness,
.destination = .power,
.factor = 0.7,
},
@ -72,7 +78,7 @@
.optional = true,
.parameterSets = .{
.{
.source = .resistance,
.source = .strength,
.destination = .maxDurability,
.factor = 2,
},
@ -88,7 +94,7 @@
.optional = true,
.parameterSets = .{
.{
.source = .resistance,
.source = .strength,
.destination = .maxDurability,
.factor = 2,
},
@ -104,7 +110,7 @@
.optional = true,
.parameterSets = .{
.{
.source = .resistance,
.source = .strength,
.destination = .maxDurability,
.factor = 20,
},

View File

@ -5,7 +5,7 @@
.name = .handle,
.parameterSets = .{
.{
.source = .resistance,
.source = .strength,
.destination = .maxDurability,
.factor = 20,
},
@ -14,13 +14,19 @@
.destination = .swingTime,
.factor = 0.1,
},
.{
.source = .grip,
.destination = .swingTime,
.functionType = .inverse,
.factor = 0.05,
},
},
},
.{
.name = .center,
.parameterSets = .{
.{
.source = .resistance,
.source = .strength,
.destination = .maxDurability,
.factor = 50,
},
@ -29,13 +35,19 @@
.destination = .swingTime,
.factor = 0.02,
},
.{
.source = .elasticity,
.destination = .swingTime,
.functionType = .inverseSquare,
.factor = 0.1,
},
.{
.source = .density,
.destination = .power,
.factor = 0.2,
},
.{
.source = .power,
.source = .hardness,
.destination = .power,
.functionType = .squareRoot,
.factor = 0.1,
@ -46,7 +58,7 @@
.name = .bridge,
.parameterSets = .{
.{
.source = .resistance,
.source = .strength,
.destination = .maxDurability,
.factor = 10,
},
@ -55,13 +67,19 @@
.destination = .swingTime,
.factor = 0.02,
},
.{
.source = .elasticity,
.destination = .swingTime,
.functionType = .inverseSquare,
.factor = 0.1,
},
.{
.source = .density,
.destination = .power,
.factor = 0.2,
},
.{
.source = .power,
.source = .hardness,
.destination = .power,
.functionType = .squareRoot,
.factor = 0.1,
@ -72,7 +90,7 @@
.name = .tip,
.parameterSets = .{
.{
.source = .resistance,
.source = .strength,
.destination = .maxDurability,
.factor = 20,
},
@ -81,13 +99,19 @@
.destination = .swingTime,
.factor = 0.02,
},
.{
.source = .elasticity,
.destination = .swingTime,
.functionType = .inverseSquare,
.factor = 0.1,
},
.{
.source = .density,
.destination = .power,
.factor = 0.2,
},
.{
.source = .power,
.source = .hardness,
.destination = .power,
.factor = 0.7,
},
@ -98,7 +122,7 @@
.optional = true,
.parameterSets = .{
.{
.source = .resistance,
.source = .strength,
.destination = .maxDurability,
.factor = 2,
},
@ -114,7 +138,7 @@
.optional = true,
.parameterSets = .{
.{
.source = .resistance,
.source = .strength,
.destination = .maxDurability,
.factor = 20,
},

View File

@ -5,7 +5,7 @@
.name = .handle,
.parameterSets = .{
.{
.source = .resistance,
.source = .strength,
.destination = .maxDurability,
.factor = 20,
},
@ -14,13 +14,19 @@
.destination = .swingTime,
.factor = 0.1,
},
.{
.source = .grip,
.destination = .swingTime,
.functionType = .inverse,
.factor = 0.05,
},
},
},
.{
.name = .center,
.parameterSets = .{
.{
.source = .resistance,
.source = .strength,
.destination = .maxDurability,
.factor = 60,
},
@ -30,7 +36,7 @@
.factor = 0.02,
},
.{
.source = .power,
.source = .hardness,
.destination = .power,
.functionType = .squareRoot,
.factor = 0.1,
@ -41,7 +47,7 @@
.name = .blade,
.parameterSets = .{
.{
.source = .resistance,
.source = .strength,
.destination = .maxDurability,
.factor = 20,
},
@ -51,7 +57,7 @@
.factor = 0.02,
},
.{
.source = .power,
.source = .hardness,
.destination = .power,
.factor = 0.3,
},
@ -61,7 +67,7 @@
.name = .tip,
.parameterSets = .{
.{
.source = .resistance,
.source = .strength,
.destination = .maxDurability,
.factor = 20,
},
@ -71,7 +77,7 @@
.factor = 0.02,
},
.{
.source = .power,
.source = .hardness,
.destination = .power,
.factor = 0.6,
},
@ -82,7 +88,7 @@
.optional = true,
.parameterSets = .{
.{
.source = .resistance,
.source = .strength,
.destination = .maxDurability,
.factor = 30,
},
@ -92,7 +98,7 @@
.factor = 0.1,
},
.{
.source = .power,
.source = .hardness,
.destination = .power,
.factor = 0.7,
},
@ -103,7 +109,7 @@
.optional = true,
.parameterSets = .{
.{
.source = .resistance,
.source = .strength,
.destination = .maxDurability,
.factor = 10,
},
@ -119,7 +125,7 @@
.optional = true,
.parameterSets = .{
.{
.source = .resistance,
.source = .strength,
.destination = .maxDurability,
.factor = 2,
},

View File

@ -18,25 +18,23 @@ const NeverFailingAllocator = main.utils.NeverFailingAllocator;
pub const Inventory = @import("Inventory.zig");
/// Holds the basic properties of a tool crafting material.
const Material = struct { // MARK: Material
/// how much it weighs
density: f32 = undefined,
/// how long it takes until the tool breaks
resistance: f32 = undefined,
/// how useful it is for block breaking
power: f32 = undefined,
strength: f32 = undefined,
elasticity: f32 = undefined,
grip: f32 = undefined,
hardness: f32 = undefined,
/// How rough the texture should look.
roughness: f32 = undefined,
/// The colors that are used to make tool textures.
textureRoughness: f32 = undefined,
colorPalette: []Color = undefined,
pub fn init(self: *Material, allocator: NeverFailingAllocator, zon: ZonElement) void {
self.density = zon.get(f32, "density", 1.0);
self.resistance = zon.get(f32, "resistance", 1.0);
self.power = zon.get(f32, "power", 1.0);
self.roughness = @max(0, zon.get(f32, "roughness", 1.0));
self.strength = zon.get(f32, "strength", 1.0);
self.elasticity = zon.get(f32, "elasticity", 1.0);
self.grip = zon.get(f32, "grip", 1.0);
self.hardness = zon.get(f32, "hardness", 1.0);
self.textureRoughness = @max(0, zon.get(f32, "textureRoughness", 1.0));
const colors = zon.getChild("colors");
self.colorPalette = allocator.alloc(Color, colors.array.items.len);
for(colors.array.items, self.colorPalette) |item, *color| {
@ -52,9 +50,12 @@ const Material = struct { // MARK: Material
pub fn hashCode(self: Material) u32 {
var hash: u32 = @bitCast(self.density);
hash = 101*%hash +% @as(u32, @bitCast(self.resistance));
hash = 101*%hash +% @as(u32, @bitCast(self.power));
hash = 101*%hash +% @as(u32, @bitCast(self.roughness));
hash = 101*%hash +% @as(u32, @bitCast(self.density));
hash = 101*%hash +% @as(u32, @bitCast(self.strength));
hash = 101*%hash +% @as(u32, @bitCast(self.elasticity));
hash = 101*%hash +% @as(u32, @bitCast(self.grip));
hash = 101*%hash +% @as(u32, @bitCast(self.hardness));
hash = 101*%hash +% @as(u32, @bitCast(self.textureRoughness));
hash ^= hash >> 24;
return hash;
}
@ -68,13 +69,15 @@ const Material = struct { // MARK: Material
const MaterialProperty = enum {
density,
resistance,
power,
strength,
elasticity,
grip,
hardness,
fn fromString(string: []const u8) MaterialProperty {
return std.meta.stringToEnum(MaterialProperty, string) orelse {
std.log.err("Couldn't find material property {s}. Replacing it with power", .{string});
return .power;
std.log.err("Couldn't find material property {s}. Replacing it with strength", .{string});
return .strength;
};
}
};
@ -178,7 +181,7 @@ const TextureGenerator = struct { // MARK: TextureGenerator
while(dy <= 0) : (dy += 1) {
if(y + dy < 0 or y + dy >= 16) continue;
const otherItem = itemGrid[@intCast(x + dx)][@intCast(y + dy)];
heightMap[x][y] = if(otherItem) |item| (if(item.material) |material| 1 + (4*random.nextFloat(seed) - 2)*material.roughness else 0) else 0;
heightMap[x][y] = if(otherItem) |item| (if(item.material) |material| 1 + (4*random.nextFloat(seed) - 2)*material.textureRoughness else 0) else 0;
if(otherItem != oneItem) {
hasDifferentItems = true;
}
@ -284,16 +287,22 @@ const ParameterSet = struct {
const FunctionType = enum {
linear,
inverse,
square,
inverseSquare,
squareRoot,
inverseSquareRoot,
exp2,
log2,
fn eval(self: FunctionType, val: f32) f32 {
switch(self) {
.linear => return val,
.inverse => return 1.0/val,
.square => return val*val,
.inverseSquare => return 1.0/(val*val),
.squareRoot => return @sqrt(val),
.inverseSquareRoot => return 1.0/@sqrt(val),
.exp2 => return @exp2(val),
.log2 => return @log2(val),
}