Skip to content

Commit

Permalink
Merge pull request #35 from scallyw4g/develop
Browse files Browse the repository at this point in the history
develop
  • Loading branch information
scallyw4g authored Feb 11, 2024
2 parents 3bfce55 + 0c6d89c commit cd352a9
Show file tree
Hide file tree
Showing 96 changed files with 2,974 additions and 486 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
* 1.3.9

- Implemented VoronoiNoise3D

- Implemented ComputeNormalsForChunkFromNoiseValues

This adds the ability to vary the terrain surface by the normal of the surface

- Combined VoronoiNoise3D and ComputeNormalsForChunkFromNoiseValues in
terrain_gen to make some craggy cliffs

- Generally improved terrain generation performance by quite a bit. It's still pretty slow

* 1.3.8

- Uploading build artifacts to release page

* 1.3.0

- Major improvement to serialization code
Expand Down
66 changes: 52 additions & 14 deletions examples/terrain_gen/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ GrassyIslandTerrain( perlin_noise *Noise,
}

#if 1
GrowGrass( Chunk, V3i(x,y,z), NoiseValue, 1.f, SrcToDest, WorldChunkDim, WorldZBiased, &ThisColor, &NoiseChoice );
GrowGrassPerlin( Chunk, V3i(x,y,z), NoiseValue, 1.f, SrcToDest, WorldChunkDim, WorldZBiased, &ThisColor, &NoiseChoice );
#else
s32 Below = TryGetIndex(x, y, z-1, Dim);
s32 B0 = TryGetIndex(x+1, y, z-1, Dim);
Expand Down Expand Up @@ -413,12 +413,24 @@ BONSAI_API_WORKER_THREAD_CALLBACK()
{
// Bumpy Sin(x)+Cos(y) noise. Useful for visualizing the polylines/splines mapping noise values to their final values.
s32 Frequency = 100;
s32 Amplititude = 50;
s32 Amplititude = 250;
/* s32 Frequency = 100; */
/* s32 Amplititude = 2500; */
s32 StartingZDepth = -1;
chunk_init_flags InitFlags = ChunkInitFlag_Noop;
InitializeChunkWithNoise( SinCosTerrain, Thread, Chunk, Chunk->Dim, 0, Frequency, Amplititude, StartingZDepth, Ignored, InitFlags, 0);
} break;

case TerrainGenType_Voronoi:
{
// Voronoi noise .. looks like rocks.
s32 Frequency = 100;
s32 Amplititude = 50;
s32 StartingZDepth = -1;
chunk_init_flags InitFlags = ChunkInitFlag_Noop;
InitializeChunkWithNoise( VoronoiTerrain, Thread, Chunk, Chunk->Dim, 0, Frequency, Amplititude, StartingZDepth, Ignored, InitFlags, 0);
} break;

case TerrainGenType_Checkerboard:
{
// Custom flat noise function that produces a checkerboard
Expand Down Expand Up @@ -516,13 +528,13 @@ BONSAI_API_WORKER_THREAD_CALLBACK()
s32 Frequency = 0; // Ignored
s32 Amplititude = 0; // Ignored
s32 StartingZDepth = -100;
u32 OctaveCount = 1;
u32 OctaveCount = 2;

octave_buffer OctaveBuf = { OctaveCount, {} };
OctaveBuf.Octaves = Allocate(octave, Thread->TempMemory, OctaveCount);

OctaveBuf.Octaves[0] = {V3(1400, 1400, 800), 350, V3(1.f)};
/* OctaveBuf.Octaves[1] = {V3(400, 400, 200), 150, V3(1.f)}; */
OctaveBuf.Octaves[1] = {V3(400, 400, 200), 150, V3(1.f)};
/* OctaveBuf.Octaves[2] = {V3(35, 35, 50), 6, V3(2.f)}; */
/* OctaveBuf.Octaves[2] = {V3(500, 500, 20), 200, V3(2.f)}; */
/* OctaveBuf.Octaves[2] = {75, 60, 1}; */
Expand All @@ -535,6 +547,28 @@ BONSAI_API_WORKER_THREAD_CALLBACK()
InitializeChunkWithNoise( GrassyTerracedTerrain3, Thread, Chunk, Chunk->Dim, 0, Frequency, Amplititude, StartingZDepth, MeshBit_Lod0, InitFlags, (void*)&OctaveBuf);
} break;

case TerrainGenType_GrassyTerracedTerrain4:
{
// Custom FBM noise example generating slightly-more-complex game-world-like terrain
s32 Frequency = 0; // Ignored
s32 Amplititude = 0; // Ignored
s32 StartingZDepth = -100;
u32 OctaveCount = 3;

octave_buffer OctaveBuf = { OctaveCount, {} };
OctaveBuf.Octaves = Allocate(octave, Thread->TempMemory, OctaveCount);

OctaveBuf.Octaves[0] = {V3(800, 800, 1700), 350, V3(1.f)};
OctaveBuf.Octaves[1] = {V3(400, 400, 200), 350, V3(1.f)};
OctaveBuf.Octaves[2] = {V3(35, 35, 25), 6, V3(2.f)};

/* chunk_init_flags InitFlags = ChunkInitFlag_ComputeStandingSpots; */
/* chunk_init_flags InitFlags = ChunkInitFlag_GenMipMapLODs; */
chunk_init_flags InitFlags = ChunkInitFlag_Noop;
InitializeChunkWithNoise( GrassyTerracedTerrain4, Thread, Chunk, Chunk->Dim, 0, Frequency, Amplititude, StartingZDepth, MeshBit_Lod0, InitFlags, (void*)&OctaveBuf);
} break;


case TerrainGenType_TerracedTerrain:
{
// Custom FBM noise example generating slightly-more-complex game-world-like terrain
Expand Down Expand Up @@ -675,20 +709,30 @@ BONSAI_API_MAIN_THREAD_INIT_CALLBACK()
world_position WorldCenter = {};
canonical_position CameraTargetP = {};

StandardCamera(Graphics->Camera, 10000.0f, 1000.0f, DEFAULT_CAMERA_BLENDING, CameraTargetP);
StandardCamera(Graphics->Camera, 10000.0f, 5000.0f, DEFAULT_CAMERA_BLENDING, CameraTargetP);

AllocateWorld(World, WorldCenter, WORLD_CHUNK_DIM, g_VisibleRegion);

GameState = Allocate(game_state, Resources->Memory, 1);

/* GameState->TerrainGenType = TerrainGenType_GrassyTerracedTerrain; */

GameState->TerrainGenType = TerrainGenType_GrassyLargeTerracedTerrain;
GameState->TerrainGenType = TerrainGenType_SinCos;
/* GameState->TerrainGenType = TerrainGenType_GrassyTerracedTerrain4; */
/* GameState->TerrainGenType = TerrainGenType_Voronoi; */
/* World->Center = V3i(-22, 101, 1); */

Camera->GhostId = GetFreeEntity(EntityTable);
entity *CameraGhost = GetEntity(EntityTable, Camera->GhostId);
CameraGhost->P.WorldP = V3i(-22, 101, 1);
/* CameraGhost->P.WorldP = V3i(-53, -93, 2); */
/* CameraGhost->P.WorldP = V3i(-25, -75, 2); */
/* CameraGhost->P.WorldP = V3i(-5, -121, 2); */

CameraGhost->P.WorldP = V3i(330, -87, 2);
/* CameraGhost->P.WorldP = V3i(33, -87, 2); */
/* CameraGhost->P.WorldP = V3i(5, -73, 2); */
CameraGhost->Behavior = entity_behavior_flags(CameraGhost->Behavior|EntityBehaviorFlags_DefatulCameraGhostBehavior|EntityBehaviorFlags_WorldCenter);

SpawnEntity(CameraGhost);

return GameState;
Expand All @@ -702,12 +746,6 @@ BONSAI_API_MAIN_THREAD_CALLBACK()
TIMED_FUNCTION();
UNPACK_ENGINE_RESOURCES(Resources);

entity *Ghost = GetEntity(EntityTable, Camera->GhostId);
if (Ghost && Ghost->Id == Resources->Graphics->GameCamera.GhostId)
{
Ghost->Behavior = entity_behavior_flags(Ghost->Behavior|EntityBehaviorFlags_WorldCenter);
}

f32 dt = Plat->dt;
f32 Speed = 80.f;

Expand All @@ -721,7 +759,7 @@ BONSAI_API_MAIN_THREAD_CALLBACK()
{
GetRadioEnum(&TerrainGenTypeRadio, &GameState->TerrainGenType);
SignalAndWaitForWorkers(&Plat->WorkerThreadsSuspendFutex);
HardResetWorld(Resources);
HardResetWorld(Resources, HardResetFlag_NoResetCamera);
UnsignalFutex(&Plat->WorkerThreadsSuspendFutex);
}
}
Expand Down
18 changes: 17 additions & 1 deletion examples/terrain_gen/game_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,33 @@ global_variable chunk_dimension
/* g_VisibleRegion = Chunk_Dimension(64, 64, 6); */
/* g_VisibleRegion = Chunk_Dimension(32, 32, 16); */
/* g_VisibleRegion = Chunk_Dimension(32, 32, 10); */
g_VisibleRegion = Chunk_Dimension(32, 32, 6);
/* g_VisibleRegion = Chunk_Dimension(32, 32, 8); */
/* g_VisibleRegion = Chunk_Dimension(32, 32, 6); */
/* g_VisibleRegion = Chunk_Dimension(32, 32, 4); */
/* g_VisibleRegion = Chunk_Dimension(24, 24, 4); */
/* g_VisibleRegion = Chunk_Dimension(24, 24, 6); */
g_VisibleRegion = Chunk_Dimension(16, 16, 8);
/* g_VisibleRegion = Chunk_Dimension(16, 16, 6); */
/* g_VisibleRegion = Chunk_Dimension(10, 10, 10); */
/* g_VisibleRegion = Chunk_Dimension(8, 8, 6); */


/* global_variable chunk_dimension */
/* WORLD_CHUNK_DIM = Chunk_Dimension(16, 16, 16); */

/* global_variable chunk_dimension */
/* WORLD_CHUNK_DIM = Chunk_Dimension(16, 16, 16); */

/* global_variable chunk_dimension */
/* WORLD_CHUNK_DIM = Chunk_Dimension(28, 28, 28); */

/* global_variable chunk_dimension */
/* WORLD_CHUNK_DIM = Chunk_Dimension(32, 32, 32); */

/* global_variable chunk_dimension */
/* WORLD_CHUNK_DIM = Chunk_Dimension(64, 64, 64); */


global_variable chunk_dimension
WORLD_CHUNK_DIM = Chunk_Dimension(64, 64, 64);

Expand Down
24 changes: 13 additions & 11 deletions examples/terrain_gen/game_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ enum terrain_gen_type
TerrainGenType_Flat = (1 << 0),
TerrainGenType_Checkerboard = (1 << 1),
TerrainGenType_SinCos = (1 << 2),
TerrainGenType_Perlin2D = (1 << 3),
TerrainGenType_Perlin3D = (1 << 4),
TerrainGenType_FBM2D = (1 << 5),
TerrainGenType_TerracedTerrain = (1 << 6),
TerrainGenType_GrassyTerracedTerrain = (1 << 7),
TerrainGenType_GrassyLargeTerracedTerrain = (1 << 8),
TerrainGenType_GrassyTerracedTerrain2 = (1 << 9),
TerrainGenType_GrassyTerracedTerrain3 = (1 << 10),
TerrainGenType_GrassyIsland = (1 << 11),
TerrainGenType_Hoodoo = (1 << 12),
TerrainGenType_Warped = (1 << 13),
TerrainGenType_Voronoi = (1 << 3),
TerrainGenType_Perlin2D = (1 << 4),
TerrainGenType_Perlin3D = (1 << 5),
TerrainGenType_FBM2D = (1 << 6),
TerrainGenType_TerracedTerrain = (1 << 7),
TerrainGenType_GrassyTerracedTerrain = (1 << 8),
TerrainGenType_GrassyLargeTerracedTerrain = (1 << 9),
TerrainGenType_GrassyTerracedTerrain2 = (1 << 10),
TerrainGenType_GrassyTerracedTerrain3 = (1 << 11),
TerrainGenType_GrassyTerracedTerrain4 = (1 << 12),
TerrainGenType_GrassyIsland = (1 << 13),
TerrainGenType_Hoodoo = (1 << 14),
TerrainGenType_Warped = (1 << 15),
};

poof(radio_button_group_for_bitfield_enum(terrain_gen_type))
Expand Down
4 changes: 2 additions & 2 deletions examples/turn_based/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ GameEntityUpdate(engine_resources *Engine, entity *Entity )

Assert(Spawned(Entity));

if (Entity->Carrying)
if (Entity->Carrying.Generation)
{
entity *Carrying = GetEntity(EntityTable, Entity->Carrying);
v3 EntitySimP = GetSimSpaceBaseP(World, Entity);
Expand Down Expand Up @@ -520,7 +520,7 @@ FireballPhysics()
link_internal b32
HoldingItem(entity *Player)
{
b32 Result = Player->Carrying;
b32 Result = Player->Carrying.Generation > 0;
return Result;
}

Expand Down
2 changes: 1 addition & 1 deletion external/bonsai_debug
12 changes: 12 additions & 0 deletions generated/are_equal_bonsai_type_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,16 @@ AreEqual(bonsai_type_info *Thing1, bonsai_type_info *Thing2)
return Result;
}

link_internal b32
AreEqual(bonsai_type_info Thing1, bonsai_type_info Thing2)
{
b32 Result = True;
Result &= AreEqual(Thing1.Name, Thing2.Name);

Result &= AreEqual(Thing1.Version, Thing2.Version);

Result &= AreEqual(Thing1.SizeOfInBytes, Thing2.SizeOfInBytes);

return Result;
}

18 changes: 18 additions & 0 deletions generated/are_equal_debug_profile_scope.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// external/bonsai_debug/src/api.h:110:0

link_internal b32
AreEqual(debug_profile_scope *Thing1, debug_profile_scope *Thing2)
{
b32 Result = MemoryIsEqual((u8*)Thing1, (u8*)Thing2, sizeof( debug_profile_scope ) );

return Result;
}

link_internal b32
AreEqual(debug_profile_scope Thing1, debug_profile_scope Thing2)
{
b32 Result = MemoryIsEqual((u8*)&Thing1, (u8*)&Thing2, sizeof( debug_profile_scope ) );

return Result;
}

12 changes: 12 additions & 0 deletions generated/are_equal_file_traversal_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,16 @@ AreEqual(file_traversal_node *Thing1, file_traversal_node *Thing2)
return Result;
}

link_internal b32
AreEqual(file_traversal_node Thing1, file_traversal_node Thing2)
{
b32 Result = True;
Result &= AreEqual(Thing1.Type, Thing2.Type);

Result &= AreEqual(Thing1.Dir, Thing2.Dir);

Result &= AreEqual(Thing1.Name, Thing2.Name);

return Result;
}

7 changes: 7 additions & 0 deletions generated/are_equal_memory_arena_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ AreEqual(memory_arena_stats *Thing1, memory_arena_stats *Thing2)
return Result;
}

link_internal b32
AreEqual(memory_arena_stats Thing1, memory_arena_stats Thing2)
{
b32 Result = MemoryIsEqual((u8*)&Thing1, (u8*)&Thing2, sizeof( memory_arena_stats ) );

return Result;
}

18 changes: 18 additions & 0 deletions generated/are_equal_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,22 @@ AreEqual(texture *Thing1, texture *Thing2)
return Result;
}

link_internal b32
AreEqual(texture Thing1, texture Thing2)
{
b32 Result = True;
Result &= AreEqual(Thing1.ID, Thing2.ID);

Result &= AreEqual(Thing1.Dim, Thing2.Dim);

Result &= AreEqual(Thing1.Slices, Thing2.Slices);

Result &= AreEqual(Thing1.Channels, Thing2.Channels);

Result &= AreEqual(Thing1.IsDepthTexture, Thing2.IsDepthTexture);

Result &= AreEqual(Thing1.DebugName, Thing2.DebugName);

return Result;
}

7 changes: 7 additions & 0 deletions generated/are_equal_ui_toggle.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ AreEqual(ui_toggle *Thing1, ui_toggle *Thing2)
return Result;
}

link_internal b32
AreEqual(ui_toggle Thing1, ui_toggle Thing2)
{
b32 Result = MemoryIsEqual((u8*)&Thing1, (u8*)&Thing2, sizeof( ui_toggle ) );

return Result;
}

7 changes: 7 additions & 0 deletions generated/are_equal_voxel_synthesis_change_propagation_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ AreEqual(voxel_synthesis_change_propagation_info *Thing1, voxel_synthesis_change
return Result;
}

link_internal b32
AreEqual(voxel_synthesis_change_propagation_info Thing1, voxel_synthesis_change_propagation_info Thing2)
{
b32 Result = MemoryIsEqual((u8*)&Thing1, (u8*)&Thing2, sizeof( voxel_synthesis_change_propagation_info ) );

return Result;
}

7 changes: 7 additions & 0 deletions generated/are_equal_xml_tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ AreEqual(xml_tag *Thing1, xml_tag *Thing2)
return Result;
}

link_internal b32
AreEqual(xml_tag Thing1, xml_tag Thing2)
{
b32 Result = MemoryIsEqual((u8*)&Thing1, (u8*)&Thing2, sizeof( xml_tag ) );

return Result;
}

2 changes: 1 addition & 1 deletion generated/block_array_entity_ptr_688856411.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// src/engine/world_chunk.h:320:0
// src/engine/world_chunk.h:326:0

struct entity_ptr_block
{
Expand Down
2 changes: 1 addition & 1 deletion generated/block_array_h_asset_thumbnail_688856411.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// src/engine/editor.h:244:0
// src/engine/editor.h:238:0

struct asset_thumbnail_block
{
Expand Down
2 changes: 1 addition & 1 deletion generated/block_array_standing_spot_688853862.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// src/engine/world_chunk.h:462:0
// src/engine/world_chunk.h:474:0

struct standing_spot_block
{
Expand Down
2 changes: 1 addition & 1 deletion generated/block_array_voxel_stack_element_688853862.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// src/engine/world_chunk.cpp:3863:0
// src/engine/world_chunk.cpp:4029:0

struct voxel_stack_element_block
{
Expand Down
Loading

0 comments on commit cd352a9

Please sign in to comment.