Compare commits

..

No commits in common. "8b2dcb496e093e36d40f913f3c332887632c966f" and "543b088341c5c49485abe98116a7217b589fc776" have entirely different histories.

6 changed files with 37 additions and 68 deletions

View File

@ -10,8 +10,16 @@ cam : Camera = .{
position = .{3.0, 5.0, 3.0}
};
world : World;
#scope_export
game_init :: () {
world.ground[500][500] = .GRASS;
world.ground[500][501] = .GRASS;
world.ground[500][499] = .GRASS;
world.ground[499][500] = .GRASS;
world.ground[500][500] = .GRASS;
world.ground[501][500] = .GRASS;
}
game_ui :: () {
@ -24,6 +32,5 @@ game_tick :: () {
game_draw :: () {
create_set_cam_rendering_task(cam);
curworld := get_current_world();
if curworld.valid then create_world_rendering_tasks(curworld.world);
create_world_rendering_tasks(*world);
}

View File

@ -46,6 +46,8 @@ pointerHit : bool;
pointerX : s32;
pointerY : s32;
world : World;
show_trile_preview : bool = true;
trile_preview_x : int = 0;
trile_preview_y : int = 0;
@ -84,6 +86,8 @@ get_level_editor_camera :: () -> Camera {
tick_level_editor_camera :: () {
if console_open_ignore_input then return;
world.ground[500][500] = .GRASS;
if get_time() - lastInputTime > CAMERA_INACTIVE_TIME_TO_ORBIT { // idle rotating camera
cameraRotation += cast(float) delta_time;
}
@ -172,13 +176,12 @@ tick_level_editor_camera :: () {
}
draw_tacoma_tab :: (theme: *GR.Overall_Theme, total_r: GR.Rect) {
curworld := get_current_world();
r := total_r;
r.h = ui_h(3,0);
#if HAS_TACOMA {
if GR.button(r, "Render with Tacoma", *theme.button_theme) {
cam := get_level_editor_camera();
gen_reference(tacomaResolution, tacomaResolution, .{tacomaExposure, tacomaContrast, tacomaSaturation}, .{cam.target, cam.position, tacomaSamples, true}, curworld.world.*);
gen_reference(tacomaResolution, tacomaResolution, .{tacomaExposure, tacomaContrast, tacomaSaturation}, .{cam.target, cam.position, tacomaSamples, true}, world);
}
r.y += r.h;
if current_screenshot.valid {
@ -263,7 +266,6 @@ draw_tools_tab :: (theme: *GR.Overall_Theme, total_r: GR.Rect) {
}
handle_tool_click :: (x: int, y: int, z: int) {
curworld := get_current_world();
if editMode == {
case .TRILES;
if editor_current_trile != null then add_trile(editor_current_trile.name, cast(float)x, cast(float)y, cast(float)z);
@ -271,14 +273,13 @@ handle_tool_click :: (x: int, y: int, z: int) {
ray := get_mouse_ray(*get_level_editor_camera());
hit, point := ray_plane_collision_point(ray, 0, 100);
if hit {
curworld.world.ground[floor(point.y).(int) + 500][floor(point.x).(int) + 500] = groundType;
world.ground[floor(point.y).(int) + 500][floor(point.x).(int) + 500] = groundType;
}
}
}
add_trile :: (name: string, x: float, y: float, z: float) {
curworld := get_current_world();
loose_float_comp :: (a: float, b: float) -> bool {
return abs(a-b) < 0.001;
@ -287,7 +288,7 @@ add_trile :: (name: string, x: float, y: float, z: float) {
// Check if the position is already occupied. @ToDo: we would probably like to
// have some acceleration structure like a hashmap to speed up this check when
// we are checking for collisions.
for curworld.world.positions {
for world.positions {
for v, idx: it.positions {
if loose_float_comp(v.x, x)
&& loose_float_comp(v.y, y)
@ -298,7 +299,7 @@ add_trile :: (name: string, x: float, y: float, z: float) {
}
}
for curworld.world.positions {
for world.positions {
if it.trileName == name {
array_add(*it.positions, Vector4.{x,y,z,1});
return;
@ -309,7 +310,7 @@ add_trile :: (name: string, x: float, y: float, z: float) {
};
array_add(*poses.positions, Vector4.{x,y,z,1});
array_add(*curworld.world.positions, poses);
array_add(*world.positions, poses);
} @Command
@ -333,10 +334,8 @@ tick_level_editor :: () {
}
draw_level_editor :: () {
curworld := get_current_world();
if !curworld.valid then return;
create_set_cam_rendering_task(get_level_editor_camera());
create_world_rendering_tasks(curworld.world);
create_world_rendering_tasks(*world);
}
draw_level_editor_ui :: (theme: *GR.Overall_Theme) {
@ -360,14 +359,13 @@ draw_level_editor_ui :: (theme: *GR.Overall_Theme) {
}
r.y += tab_r.h;
curworld := get_current_world();
if current_tab == {
case .TOOLS;
draw_tools_tab(theme, r);
case .TACOMA;
draw_tacoma_tab(theme, r);
case .INFO;
if curworld.valid then autoedit(r, *curworld.world.conf, theme);
autoedit(r, *world.conf, theme);
}
draw_trile_picker(theme);
}

View File

@ -54,18 +54,3 @@ get_render_size :: () -> (s32, s32) {
// wl, hl := get_low_res(w,h, 360);
return w, h;
}
flip_y_if_plat :: inline (v: Vector2) -> Vector2 {
return .{v.x, flip_if_plat(v.y)};
}
// Some platforms draw UVs in weird reverse way
// so this function here does the flip on those platforms
// so we don't need to do the platform check in many places.
flip_if_plat :: inline (n: float) -> float {
#if OS == .MACOS {
return 1 - n;
} else {
return n;
}
}

View File

@ -544,10 +544,10 @@ create_postprocess_pipeline :: () {
gPipelines.postprocess.pipeline = sg_make_pipeline(*pipeline);
quad_vertices : [16]float = .[
-1.0, 1.0, 0.0, flip_if_plat(1.0), // top-let
-1.0, -1.0, 0.0, flip_if_plat(0.0), // bottom-let
1.0, -1.0, 1.0, flip_if_plat(0.0), // bottom-right
1.0, 1.0, 1.0, flip_if_plat(1.0), // top-right
-1.0, 1.0, 0.0, 1.0, // top-let
-1.0, -1.0, 0.0, 0.0, // bottom-let
1.0, -1.0, 1.0, 0.0, // bottom-right
1.0, 1.0, 1.0, 1.0, // top-right
];
quad_indices : [6]u16 = .[
0, 1, 2, 0, 2, 3

View File

@ -253,9 +253,9 @@ immediate_triangle :: (p0: Vector3, p1: Vector3, p2: Vector3, c0 := Vector4.{1,1
tri.uv[1] = nullUV;
tri.uv[2] = nullUV;
} else {
tri.uv[0] = flip_y_if_plat(uv0);
tri.uv[1] = flip_y_if_plat(uv1);
tri.uv[2] = flip_y_if_plat(uv2);
tri.uv[0] = uv0;
tri.uv[1] = uv1;
tri.uv[2] = uv2;
}
arb_tri_add(tri);

View File

@ -2,38 +2,18 @@
Pool :: #import "Pool";
Current_World :: struct {
world : *World;
current_world : struct {
world : World;
pool : Pool.Pool; // A memory pool to allocate stuff for the lifetime of this level being active.
valid : bool = false;
};
current_world : Current_World;
world_table : Table(string, World);
world_table :: Table(string, World);
#scope_export
nworld :: (name: string) {
w : World;
table_set(*world_table, name, w);
} @Command;
lworld :: (name: string) {
if current_world.valid {
Pool.reset(*current_world.pool);
} else {
Pool.set_allocators(*current_world.pool);
}
worldptr := table_find_pointer(*world_table, name);
current_world.world = worldptr;
current_world.valid = true;
} @Command;
get_current_world :: () -> *Current_World {
return *current_world;
}
sworlds :: () {
Jaison :: #import "Jaison";
worlds : [..]World;
@ -53,8 +33,8 @@ lworlds :: () {
s := load_string_from_pack("./game/resources/worlds.json");
success, worlds := Jaison.json_parse_string(s, [..]World,, temp);
for worlds {
// set_trile(sprint("%",it.name), trile_from_serialize_form(it));
// print("Loaded %\n", it.name);
set_trile(sprint("%",it.name), trile_from_serialize_form(it));
print("Loaded %\n", it.name);
}
} @Command
@ -101,13 +81,12 @@ TrilePositions :: struct {
}
Ground_Tile :: enum {
WATER;
GRASS;
SAND;
WATER = 0;
GRASS = 1;
SAND = 2;
}
World :: struct {
name : string;
conf : World_Config;
positions : [..]TrilePositions;
ground : [1000][1000]Ground_Tile;