Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
495 changes: 438 additions & 57 deletions src/main_scene/main_scene.cpp

Large diffs are not rendered by default.

44 changes: 40 additions & 4 deletions src/main_scene/main_scene.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
#pragma once

#include <godot_cpp/classes/control.hpp>
#include <godot_cpp/classes/node3d.hpp>
#include <godot_cpp/classes/button.hpp>
#include <godot_cpp/classes/option_button.hpp>
#include <godot_cpp/classes/label.hpp>
#include <godot_cpp/classes/file_dialog.hpp>
#include <godot_cpp/classes/packed_scene.hpp>
#include <godot_cpp/classes/standard_material3d.hpp>
#include <godot_cpp/classes/shader_material.hpp>
#include <godot_cpp/classes/resource_loader.hpp>
#include <godot_cpp/classes/mesh_instance3d.hpp>
#include <godot_cpp/classes/csg_primitive3d.hpp>
#include <godot_cpp/classes/plane_mesh.hpp>
#include <godot_cpp/classes/collision_shape3d.hpp>
#include <godot_cpp/classes/concave_polygon_shape3d.hpp>
#include <godot_cpp/classes/scene_tree.hpp>
#include <godot_cpp/classes/tween.hpp>
#include <godot_cpp/classes/property_tweener.hpp>
#include <godot_cpp/classes/engine.hpp>

#include <godot_cpp/variant/utility_functions.hpp>

#include <fstream>
#include <vector>
#include <map>

#include "../utils/utils.hpp"

using namespace godot;
using namespace std;

class MainScene : public Control {
GDCLASS(MainScene, Control)
class MainScene : public Node3D {
GDCLASS(MainScene, Node3D)

private:
vector<Piece> pieces;
Expand All @@ -28,13 +42,32 @@ class MainScene : public Control {
bool is_solved = false;
AlgoType algo_type = BFS;

Label* time = nullptr;
Label* time_label = nullptr;

Button* solve_button = nullptr;
Button* reset_button = nullptr;
Button* load_button = nullptr;
OptionButton* algo_button = nullptr;

Ref<PackedScene> car2_template;
Ref<PackedScene> car3_template;
Ref<StandardMaterial3D> primary_piece_material;
Ref<StandardMaterial3D> non_primary_piece_material;
MeshInstance3D* floor = nullptr;
vector<Node3D*> spawned_car_nodes;
Vector3 floor_center_offset = Vector3(0.0f, 0.0f, 0.0f);

map<Coordinates, Node3D*> coord_to_car_node_map;

Solution current_solution;
int current_move_index = -1;
bool is_animating_solution = false;
const float ANIMATION_DURATION = 0.5f;

void _animate_next_move();
void _on_move_animation_finished();
Vector3 _get_3d_position_for_piece_coords(const Coordinates& piece_top_left_coords, int piece_size, bool is_vertical_piece);

void _on_solve_button_pressed();
void _on_reset_button_pressed();
void _on_algo_button_selected(int index);
Expand All @@ -46,6 +79,9 @@ class MainScene : public Control {

bool load_input(String path, vector<Piece>& pieces, Board& board);

void _clear_all_cars();
void _spawn_piece_as_car(const Piece& piece_data);

protected:
static void _bind_methods();
void _notification(int p_what);
Expand Down
15 changes: 15 additions & 0 deletions src/utils/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ enum AlgoType {
struct Coordinates {
int x;
int y;

bool operator<(const Coordinates& other) const {
if (x != other.x) {
return x < other.x;
}
return y < other.y;
}

bool operator==(const Coordinates& other) const {
return x == other.x && y == other.y;
}

bool operator!=(const Coordinates& other) const {
return !(*this == other);
}
};

struct Piece {
Expand Down
8 changes: 8 additions & 0 deletions test/2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
5 5
5
EAAA.
ED.PB
.D.PB
.DCCB
.....
K
Binary file removed tukang-parkir-simulator/assets/Textures-16.png
Binary file not shown.
34 changes: 0 additions & 34 deletions tukang-parkir-simulator/assets/Textures-16.png.import

This file was deleted.

6 changes: 5 additions & 1 deletion tukang-parkir-simulator/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ config_version=5
[application]

config/name="tukang_parkir_simulator"
run/main_scene="res://scenes/main.tscn"
run/main_scene="uid://deic8j1v28f5m"
config/features=PackedStringArray("4.4", "Forward Plus")
config/icon="res://icon.svg"

Expand All @@ -21,6 +21,10 @@ window/size/viewport_width=1280
window/size/viewport_height=720
window/stretch/mode="viewport"

[physics]

3d/physics_engine="Jolt Physics"

[rendering]

renderer/rendering_method="gl_compatibility"
Expand Down
41 changes: 41 additions & 0 deletions tukang-parkir-simulator/scenes/car2.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[gd_scene load_steps=4 format=3 uid="uid://bj1kkdl8im8kb"]

[ext_resource type="Material" uid="uid://6hu2nb8ajcvx" path="res://scenes/non_primary_material.tres" id="1_2fv4s"]
[ext_resource type="Material" uid="uid://dyl801edovtaw" path="res://scenes/wheel_material.tres" id="1_je4r3"]

[sub_resource type="BoxShape3D" id="BoxShape3D_rc6gd"]
size = Vector3(0.8, 0.8, 1.8)

[node name="Car2" type="RigidBody3D"]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.9, 0, 0.4)

[node name="Body" type="CSGBox3D" parent="."]
size = Vector3(0.7, 0.5, 1.8)
material = ExtResource("1_2fv4s")

[node name="Wheel" type="CSGCylinder3D" parent="Body"]
transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0, 1, -0.3, -0.2, -0.5)
radius = 0.2
height = 0.2
material = ExtResource("1_je4r3")

[node name="Wheel2" type="CSGCylinder3D" parent="Body"]
transform = Transform3D(1.31134e-07, 1, 0, -1, 1.31134e-07, 0, 0, 0, 1, 0.3, -0.2, -0.5)
radius = 0.2
height = 0.2
material = ExtResource("1_je4r3")

[node name="Wheel3" type="CSGCylinder3D" parent="Body"]
transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0, 1, -0.3, -0.2, 0.5)
radius = 0.2
height = 0.2
material = ExtResource("1_je4r3")

[node name="Wheel4" type="CSGCylinder3D" parent="Body"]
transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0, 1, 0.3, -0.2, 0.5)
radius = 0.2
height = 0.2
material = ExtResource("1_je4r3")

[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("BoxShape3D_rc6gd")
41 changes: 41 additions & 0 deletions tukang-parkir-simulator/scenes/car3.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[gd_scene load_steps=4 format=3 uid="uid://nk8hrlhom63t"]

[ext_resource type="Material" uid="uid://c0xrqwe2nwfyy" path="res://scenes/primary_material.tres" id="1_1b0sv"]
[ext_resource type="Material" uid="uid://dyl801edovtaw" path="res://scenes/wheel_material.tres" id="1_6a10o"]

[sub_resource type="BoxShape3D" id="BoxShape3D_hnjk1"]
size = Vector3(0.8, 0.8, 2.8)

[node name="Car3" type="RigidBody3D"]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 1.4, 0, 0.4)

[node name="Body" type="CSGBox3D" parent="."]
size = Vector3(0.7, 0.6, 2.8)
material = ExtResource("1_1b0sv")

[node name="Wheel" type="CSGCylinder3D" parent="Body"]
transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0, 1, -0.3, -0.2, -0.9)
radius = 0.2
height = 0.2
material = ExtResource("1_6a10o")

[node name="Wheel2" type="CSGCylinder3D" parent="Body"]
transform = Transform3D(1.31134e-07, 1, 0, -1, 1.31134e-07, 0, 0, 0, 1, 0.3, -0.2, -0.9)
radius = 0.2
height = 0.2
material = ExtResource("1_6a10o")

[node name="Wheel3" type="CSGCylinder3D" parent="Body"]
transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0, 1, -0.3, -0.2, 0.8)
radius = 0.2
height = 0.2
material = ExtResource("1_6a10o")

[node name="Wheel4" type="CSGCylinder3D" parent="Body"]
transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0, 1, 0.3, -0.2, 0.8)
radius = 0.2
height = 0.2
material = ExtResource("1_6a10o")

[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("BoxShape3D_hnjk1")
51 changes: 51 additions & 0 deletions tukang-parkir-simulator/scenes/floor.gdshader
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
shader_type spatial;

uniform vec4 base_color : source_color = vec4(0.8, 0.8, 0.8, 1.0);
uniform vec4 line_color : source_color = vec4(0.0, 0.0, 0.0, 1.0);
uniform float grid_spacing = 1.0;
uniform float line_thickness = 0.1;
uniform vec2 mesh_actual_size;
uniform int grid_plane = 1;

varying vec3 v_local_position;

void vertex() {
v_local_position = VERTEX;
}

void fragment() {
vec2 coord_on_plane;

if (grid_plane == 1) {
Copy link

Copilot AI May 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be helpful to document the expected values for 'grid_plane' (e.g., 0, 1, and any other value representing the YZ plane) to improve clarity for future maintainers.

Copilot uses AI. Check for mistakes.
coord_on_plane = v_local_position.xz;
} else if (grid_plane == 0) {
coord_on_plane = v_local_position.xy;
} else {
coord_on_plane = v_local_position.yz;
}

vec2 shifted_coord = coord_on_plane + mesh_actual_size / 2.0;
float half_thick = line_thickness / 2.0;

float mod_val_x = mod(shifted_coord.x, grid_spacing);
bool on_vertical_line = (mod_val_x < half_thick || mod_val_x > grid_spacing - half_thick);

if (abs(shifted_coord.x - mesh_actual_size.x) < half_thick && mesh_actual_size.x > 0.001) {
on_vertical_line = true;
}

float mod_val_y = mod(shifted_coord.y, grid_spacing);
bool on_horizontal_line = (mod_val_y < half_thick || mod_val_y > grid_spacing - half_thick);

if (abs(shifted_coord.y - mesh_actual_size.y) < half_thick && mesh_actual_size.y > 0.001) {
on_horizontal_line = true;
}

if (on_vertical_line || on_horizontal_line) {
ALBEDO = line_color.rgb;
ALPHA = line_color.a;
} else {
ALBEDO = base_color.rgb;
ALPHA = base_color.a;
}
}
1 change: 1 addition & 0 deletions tukang-parkir-simulator/scenes/floor.gdshader.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dif4yb3527o0r
Loading
Loading