Compare commits
2 Commits
543b088341
...
8b2dcb496e
| Author | SHA1 | Date | |
|---|---|---|---|
| 8b2dcb496e | |||
| e58a4fd20c |
@ -10,16 +10,8 @@ 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 :: () {
|
||||
@ -32,5 +24,6 @@ game_tick :: () {
|
||||
|
||||
game_draw :: () {
|
||||
create_set_cam_rendering_task(cam);
|
||||
create_world_rendering_tasks(*world);
|
||||
curworld := get_current_world();
|
||||
if curworld.valid then create_world_rendering_tasks(curworld.world);
|
||||
}
|
||||
|
||||
@ -46,8 +46,6 @@ pointerHit : bool;
|
||||
pointerX : s32;
|
||||
pointerY : s32;
|
||||
|
||||
world : World;
|
||||
|
||||
show_trile_preview : bool = true;
|
||||
trile_preview_x : int = 0;
|
||||
trile_preview_y : int = 0;
|
||||
@ -86,8 +84,6 @@ 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;
|
||||
}
|
||||
@ -176,12 +172,13 @@ 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}, world);
|
||||
gen_reference(tacomaResolution, tacomaResolution, .{tacomaExposure, tacomaContrast, tacomaSaturation}, .{cam.target, cam.position, tacomaSamples, true}, curworld.world.*);
|
||||
}
|
||||
r.y += r.h;
|
||||
if current_screenshot.valid {
|
||||
@ -266,6 +263,7 @@ 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);
|
||||
@ -273,13 +271,14 @@ 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 {
|
||||
world.ground[floor(point.y).(int) + 500][floor(point.x).(int) + 500] = groundType;
|
||||
curworld.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;
|
||||
@ -288,7 +287,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 world.positions {
|
||||
for curworld.world.positions {
|
||||
for v, idx: it.positions {
|
||||
if loose_float_comp(v.x, x)
|
||||
&& loose_float_comp(v.y, y)
|
||||
@ -299,7 +298,7 @@ add_trile :: (name: string, x: float, y: float, z: float) {
|
||||
}
|
||||
}
|
||||
|
||||
for world.positions {
|
||||
for curworld.world.positions {
|
||||
if it.trileName == name {
|
||||
array_add(*it.positions, Vector4.{x,y,z,1});
|
||||
return;
|
||||
@ -310,7 +309,7 @@ add_trile :: (name: string, x: float, y: float, z: float) {
|
||||
};
|
||||
|
||||
array_add(*poses.positions, Vector4.{x,y,z,1});
|
||||
array_add(*world.positions, poses);
|
||||
array_add(*curworld.world.positions, poses);
|
||||
} @Command
|
||||
|
||||
|
||||
@ -334,8 +333,10 @@ 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(*world);
|
||||
create_world_rendering_tasks(curworld.world);
|
||||
}
|
||||
|
||||
draw_level_editor_ui :: (theme: *GR.Overall_Theme) {
|
||||
@ -359,13 +360,14 @@ 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;
|
||||
autoedit(r, *world.conf, theme);
|
||||
if curworld.valid then autoedit(r, *curworld.world.conf, theme);
|
||||
}
|
||||
draw_trile_picker(theme);
|
||||
}
|
||||
|
||||
@ -54,3 +54,18 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -544,10 +544,10 @@ create_postprocess_pipeline :: () {
|
||||
gPipelines.postprocess.pipeline = sg_make_pipeline(*pipeline);
|
||||
|
||||
quad_vertices : [16]float = .[
|
||||
-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
|
||||
-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
|
||||
];
|
||||
quad_indices : [6]u16 = .[
|
||||
0, 1, 2, 0, 2, 3
|
||||
|
||||
@ -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] = uv0;
|
||||
tri.uv[1] = uv1;
|
||||
tri.uv[2] = uv2;
|
||||
tri.uv[0] = flip_y_if_plat(uv0);
|
||||
tri.uv[1] = flip_y_if_plat(uv1);
|
||||
tri.uv[2] = flip_y_if_plat(uv2);
|
||||
}
|
||||
|
||||
arb_tri_add(tri);
|
||||
|
||||
@ -2,18 +2,38 @@
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
world_table :: Table(string, World);
|
||||
|
||||
|
||||
current_world : Current_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;
|
||||
@ -33,8 +53,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
|
||||
|
||||
@ -81,12 +101,13 @@ TrilePositions :: struct {
|
||||
}
|
||||
|
||||
Ground_Tile :: enum {
|
||||
WATER = 0;
|
||||
GRASS = 1;
|
||||
SAND = 2;
|
||||
WATER;
|
||||
GRASS;
|
||||
SAND;
|
||||
}
|
||||
|
||||
World :: struct {
|
||||
name : string;
|
||||
conf : World_Config;
|
||||
positions : [..]TrilePositions;
|
||||
ground : [1000][1000]Ground_Tile;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user