Skip to content

Commit 35b2c90

Browse files
committed
files from monorepo @ 14e6258901c6fb47ae598705682837ef6c298e60
0 parents  commit 35b2c90

File tree

8 files changed

+2655
-0
lines changed

8 files changed

+2655
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Ignore some special directories
2+
.zig-cache
3+
zig-out
4+
5+
# Ignore some special OS files
6+
*.DS_Store

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Michal Ziulek
4+
Copyright (c) 2024 zig-gamedev contributors
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# znoise
2+
3+
Zig build package and bindings for [FastNoiseLite](https://github.com/Auburn/FastNoiseLite)
4+
5+
## Getting started
6+
7+
Example `build.zig`:
8+
9+
```zig
10+
pub fn build(b: *std.Build) void {
11+
const exe = b.addExecutable(.{ ... });
12+
13+
const znoise = b.dependency("znoise", .{});
14+
exe.root_module.addImport("znoise", znoise.module("root"));
15+
exe.linkLibrary(znoise.artifact("FastNoiseLite"));
16+
}
17+
```
18+
19+
Now in your code you may import and use znoise:
20+
21+
```zig
22+
const znoise = @import("znoise");
23+
24+
pub fn main() !void {
25+
...
26+
{
27+
const gen = znoise.FnlGenerator{};
28+
const n2 = gen.noise2(0.1, 0.2);
29+
const n3 = gen.noise3(1.0, 2.0, 3.0);
30+
31+
var x: f32 = 1.0;
32+
var y: f32 = 2.0;
33+
var z: f32 = 3.0;
34+
gen.domainWarp3(&x, &y, &z);
35+
}
36+
37+
{
38+
const gen = znoise.FnlGenerator{
39+
.seed = 1337,
40+
.frequency = 0.01,
41+
.noise_type = .opensimplex2,
42+
.rotation_type3 = .none,
43+
.fractal_type = .none,
44+
.octaves = 3,
45+
.lacunarity = 2.0,
46+
.gain = 0.5,
47+
.weighted_strength = 0.0,
48+
.ping_pong_strength = 2.0,
49+
.cellular_distance_func = .euclideansq,
50+
.cellular_return_type = .distance,
51+
.cellular_jitter_mod = 1.0,
52+
.domain_warp_type = .opensimplex2,
53+
.domain_warp_amp = 1.0,
54+
};
55+
const n = gen.noise2(0.1, 0.2);
56+
}
57+
}
58+
```

build.zig

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const std = @import("std");
2+
3+
pub fn build(b: *std.Build) void {
4+
const optimize = b.standardOptimizeOption(.{});
5+
const target = b.standardTargetOptions(.{});
6+
7+
_ = b.addModule("root", .{
8+
.root_source_file = b.path("src/znoise.zig"),
9+
});
10+
11+
const fnl = b.addStaticLibrary(.{
12+
.name = "FastNoiseLite",
13+
.target = target,
14+
.optimize = optimize,
15+
});
16+
fnl.linkLibC();
17+
fnl.addIncludePath(b.path("libs/FastNoiseLite"));
18+
fnl.addCSourceFile(.{
19+
.file = b.path("libs/FastNoiseLite/FastNoiseLite.c"),
20+
.flags = &.{ "-std=c99", "-fno-sanitize=undefined" },
21+
});
22+
b.installArtifact(fnl);
23+
24+
const test_step = b.step("test", "Run znoise tests");
25+
26+
const tests = b.addTest(.{
27+
.name = "znoise-tests",
28+
.root_source_file = b.path("src/znoise.zig"),
29+
.target = target,
30+
.optimize = optimize,
31+
});
32+
tests.linkLibrary(fnl);
33+
b.installArtifact(tests);
34+
35+
test_step.dependOn(&b.addRunArtifact(tests).step);
36+
}

build.zig.zon

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.{
2+
.name = "znoise",
3+
.version = "0.3.0-dev",
4+
.paths = .{
5+
"build.zig",
6+
"build.zig.zon",
7+
"libs",
8+
"src",
9+
"README.md",
10+
"LICENSE",
11+
},
12+
}

libs/FastNoiseLite/FastNoiseLite.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define FNL_IMPL
2+
#include "FastNoiseLite.h"

0 commit comments

Comments
 (0)