diff --git a/NoteHandler.gd b/NoteHandler.gd index afd63b1..8244f4f 100644 --- a/NoteHandler.gd +++ b/NoteHandler.gd @@ -12,6 +12,11 @@ var tex_judgement_text := preload("res://assets/text-4k.png") var tex_slide_arrow := preload("res://assets/slide-arrow-4k.png") var slide_trail_shadermaterial := preload("res://shaders/slidetrail.tres") +var SlideTrailHandler +var JudgeText +var notelines +var meshinstance + var snd_miss := preload("res://assets/miss.wav") var snd_clap := preload("res://assets/softclap.wav") var snd_count_in := snd_clap @@ -439,14 +444,14 @@ func _draw(): noteline_data.unlock() var noteline_data_tex = ImageTexture.new() noteline_data_tex.create_from_image(noteline_data, 0) - $notelines.set_texture(noteline_data_tex) + notelines.set_texture(noteline_data_tex) - $meshinstance.set_mesh(mesh) + meshinstance.set_mesh(mesh) var textmesh := ArrayMesh.new() for text in active_judgement_texts: make_judgement_text(textmesh, TextJudgement[text.judgement], text.col, (t-text.time)/GameTheme.judge_text_duration) - $JudgeText.set_mesh(textmesh) + JudgeText.set_mesh(textmesh) func _input(event): @@ -482,7 +487,7 @@ func set_time(seconds: float): time_zero_msec = msecs - (seconds * 1000) time = seconds t = game_time(time) - + func make_noteline_mesh_old() -> ArrayMesh: var rec_scale1 = (float(screen_height)/float(GameTheme.receptor_ring_radius))*0.5 var uv_array_playfield := PoolVector2Array([Vector2(-1.0, -1.0)*rec_scale1, Vector2(-1.0, 1.0)*rec_scale1, Vector2(1.0, -1.0)*rec_scale1, Vector2(1.0, 1.0)*rec_scale1]) @@ -503,7 +508,7 @@ func make_noteline_mesh(vertices := 32) -> ArrayMesh: var rec_scale1 = (float(screen_height)/float(GameTheme.receptor_ring_radius))*0.5 var uv_array_playfield := PoolVector2Array([Vector2(0.0, 0.0)]) var vertex_array_playfield := PoolVector2Array([Vector2(0.0, 0.0)]) - + var angle_increment = TAU/float(vertices) # Outer polygon side-length = inner side-length / sin(inside angle/2) # inside angle for a polygon is pi-tau/n. We already precalculated tau/n for other purposes. @@ -513,7 +518,7 @@ func make_noteline_mesh(vertices := 32) -> ArrayMesh: var angle = i * angle_increment uv_array_playfield.append(polar2cartesian(UV_r, -angle)) vertex_array_playfield.append(polar2cartesian(r, angle)) - + var mesh_playfield := ArrayMesh.new() var arrays = [] arrays.resize(Mesh.ARRAY_MAX) @@ -524,8 +529,14 @@ func make_noteline_mesh(vertices := 32) -> ArrayMesh: # Called when the node enters the scene tree for the first time. func _ready(): - $notelines.set_mesh(make_noteline_mesh()) - $notelines.material.set_shader_param("bps", bpm/60.0) + SlideTrailHandler = $"Viewport/Center/SlideTrailHandler" + JudgeText = $"Viewport/Center/JudgeText" + notelines = $"Viewport/Center/notelines" + meshinstance = $"Viewport/Center/meshinstance" + + notelines.set_mesh(make_noteline_mesh()) + notelines.material.set_shader_param("bps", bpm/60.0) + noteline_array_image.create(16, 16, false, Image.FORMAT_RGBF) noteline_array_image.fill(Color(0.0, 0.0, 0.0)) @@ -559,11 +570,11 @@ func load_track(data: Dictionary, difficulty_idx: int): if note.type == Note.NOTE_SLIDE: slide_trail_meshes[note.slide_id] = make_slide_trail_mesh(note) - $meshinstance.material.set_shader_param("star_color", GameTheme.COLOR_STAR) - $meshinstance.material.set_shader_param("held_color", GameTheme.COLOR_HOLD_HELD) - $meshinstance.material.set_shader_param("bps", bpm/60.0) - $meshinstance.material.set_shader_param("screen_size", get_viewport().get_size()) - $meshinstance.set_texture(tex) + meshinstance.material.set_shader_param("star_color", GameTheme.COLOR_STAR) + meshinstance.material.set_shader_param("held_color", GameTheme.COLOR_HOLD_HELD) + meshinstance.material.set_shader_param("bps", bpm/60.0) + meshinstance.material.set_shader_param("screen_size", get_viewport().get_size()) + meshinstance.set_texture(tex) func stop(): $"/root/main/music".stop() @@ -596,8 +607,8 @@ func _process(delta): if !running: return - $meshinstance.material.set_shader_param("bps", bpm/60.0) - $notelines.material.set_shader_param("bps", bpm/60.0) + meshinstance.material.set_shader_param("bps", bpm/60.0) + notelines.material.set_shader_param("bps", bpm/60.0) var t_old := game_time(time) # time += delta @@ -635,7 +646,7 @@ func _process(delta): var note = active_notes[i] if note.time_death < t: if note.type == Note.NOTE_SLIDE: - $SlideTrailHandler.remove_child(slide_trail_mesh_instances[note.slide_id]) + SlideTrailHandler.remove_child(slide_trail_mesh_instances[note.slide_id]) slide_trail_mesh_instances.erase(note.slide_id) var idx = active_slide_trails.find(note) if idx >= 0: @@ -681,7 +692,7 @@ func _process(delta): meshi.material.set_shader_param("trail_progress", 0.0) meshi.set_texture(tex_slide_arrow) slide_trail_mesh_instances[note.slide_id] = meshi - $SlideTrailHandler.add_child(meshi) + SlideTrailHandler.add_child(meshi) next_note_to_load += 1 @@ -695,5 +706,6 @@ func _process(delta): emit_signal("finished_song", song_key, scores) # Redraw - $meshinstance.material.set_shader_param("screen_size", get_viewport().get_size()) + meshinstance.material.set_shader_param("screen_size", get_viewport().get_size()) update() + $Painter.update() diff --git a/NotePainter.gd b/NotePainter.gd new file mode 100644 index 0000000..0071d26 --- /dev/null +++ b/NotePainter.gd @@ -0,0 +1,4 @@ +extends Node2D + +func _draw(): + draw_texture_rect($"../Viewport".get_texture(), Rect2(-540, -540, 1080, 1080), false) diff --git a/NoteViewport.gd b/NoteViewport.gd new file mode 100644 index 0000000..17ebc2d --- /dev/null +++ b/NoteViewport.gd @@ -0,0 +1,16 @@ +extends Viewport + +func set_render_scale(scale: Vector2): + size = Vector2(1080, 1080) * scale + $Center.position = size * 0.5 + $Center.scale = scale + +func slider_slot(arg1): + set_render_scale(Vector2($"/root/main/InputHandler/SSXSlider".value, $"/root/main/InputHandler/SSYSlider".value)) + +# Called when the node enters the scene tree for the first time. +func _ready(): +# set_render_scale(Vector2(0.5, 1.0)) + $"/root/main/InputHandler/SSXSlider".connect("value_changed", self, "slider_slot") + $"/root/main/InputHandler/SSYSlider".connect("value_changed", self, "slider_slot") + slider_slot(1) diff --git a/Receptors.gd b/Receptors.gd index 372e24a..9c19b66 100644 --- a/Receptors.gd +++ b/Receptors.gd @@ -30,7 +30,7 @@ func make_ring_mesh(inner_vertices: int, thickness: float, radius: float, skew:= var r2 = (radius + thickness*0.5)/sin((PI-angle_increment)/2) var UV_r1 = r1/radius var UV_r2 = r2/radius - + var vertex_list = PoolVector2Array() var UV_list = PoolVector2Array() var inner_list = PoolVector2Array() @@ -52,7 +52,7 @@ func make_ring_mesh(inner_vertices: int, thickness: float, radius: float, skew:= UV_list.push_back(UV_list[0]) UV_list.push_back(UV_list[1]) return [vertex_list, inner_list, outer_list, UV_list] - + func triangle_area(a: Vector2, b: Vector2, c: Vector2) -> float: return 0.5 * abs((a.x-c.x)*(b.y-a.y) - (a.x-b.x)*(c.y-a.y)) @@ -91,8 +91,8 @@ func draw_tris(): var ring_vertices func update_ring_mesh(): - var mesh_v = $VerticesSlider.value - var skew = $SkewSlider.value + var mesh_v = $"../InputHandler/VerticesSlider".value + var skew = $"../InputHandler/SkewSlider".value var ring_thickness = receptor_px + shadow_px*2 ring_vertices = make_ring_mesh(mesh_v, ring_thickness, GameTheme.receptor_ring_radius, skew) var temp_mesh = ArrayMesh.new() @@ -103,24 +103,24 @@ func update_ring_mesh(): # mesh_arrays[Mesh.ARRAY_COLOR] = colors temp_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLE_STRIP, mesh_arrays) mesh = temp_mesh - + func _draw(): # draw_old(true, true) # draw_tris() - var mesh_v = $VerticesSlider.value - var skew = $SkewSlider.value + var mesh_v = $"../InputHandler/VerticesSlider".value + var skew = $"../InputHandler/SkewSlider".value var ring_thickness = receptor_px + shadow_px*2 var estimated_area = circumscribe_polygon_area(GameTheme.receptor_ring_radius+ring_thickness*0.5, mesh_v) - inscribe_polygon_area(GameTheme.receptor_ring_radius-ring_thickness*0.5, mesh_v) var ideal_ring_area = PI * (pow(GameTheme.receptor_ring_radius+receptor_px/2+shadow_px, 2) - pow(GameTheme.receptor_ring_radius-receptor_px/2-shadow_px, 2)) - + # var l = len(ring_vertices) # for i in l: # estimated_area += triangle_area(ring_vertices[i], ring_vertices[(i+1)%l], ring_vertices[(i+2)%l]) var quad_area = 4*pow(GameTheme.receptor_ring_radius+receptor_px/2+shadow_px, 2) var fps = Performance.get_monitor(Performance.TIME_FPS) $"/root/main/InputHandler".text = "Vertices: %d*2 Skew: %.3f\nArea: %.0f\n(%.0f%% ideal ring)\n(%.0f%% quad)\nFPS: %.0f"%[mesh_v, skew, estimated_area, 100.0*estimated_area/ideal_ring_area, 100.0*estimated_area/quad_area, fps] - + material.set_shader_param("dot_radius", 0.5*receptor_px/GameTheme.receptor_ring_radius) material.set_shader_param("line_thickness", 0.5*ring_px/GameTheme.receptor_ring_radius) material.set_shader_param("shadow_thickness", shadow_px/GameTheme.receptor_ring_radius) @@ -142,12 +142,12 @@ func _ready(): receptor_data_tex.create_from_image(receptor_array_image, 0) set_texture(receptor_data_tex) material.set_shader_param("num_receptors", Rules.COLS) - + update_ring_mesh() - $VerticesSlider.connect("value_changed", self, "update_ring_mesh_1arg") - $SkewSlider.connect("value_changed", self, "update_ring_mesh_1arg") + $"../InputHandler/VerticesSlider".connect("value_changed", self, "update_ring_mesh_1arg") + $"../InputHandler/SkewSlider".connect("value_changed", self, "update_ring_mesh_1arg") $"/root".connect("size_changed", self, "update") - + func _process(delta): if not Engine.editor_hint: update() \ No newline at end of file diff --git a/main.gd b/main.gd index e45ede9..cd0fb51 100644 --- a/main.gd +++ b/main.gd @@ -10,7 +10,7 @@ func resize(): var screen_size = $"/root".get_visible_rect().size screen_center = screen_size*0.5 position = screen_center - + screen_height = screen_size.y x_margin = max((screen_size.x - screen_size.y)/2.0, 0.0) y_margin = max((screen_size.y - screen_size.x)/2.0, 0.0) diff --git a/main.tscn b/main.tscn index f115b50..8d1ab5a 100644 --- a/main.tscn +++ b/main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=19 format=2] +[gd_scene load_steps=22 format=2] [ext_resource path="res://main.gd" type="Script" id=1] [ext_resource path="res://video.gd" type="Script" id=2] @@ -6,17 +6,19 @@ [ext_resource path="res://shaders/receptors.shader" type="Shader" id=4] [ext_resource path="res://Receptors.gd" type="Script" id=5] [ext_resource path="res://NoteHandler.gd" type="Script" id=6] -[ext_resource path="res://assets/text-4k.png" type="Texture" id=7] -[ext_resource path="res://shaders/notelines.shader" type="Shader" id=8] +[ext_resource path="res://NoteViewport.gd" type="Script" id=7] +[ext_resource path="res://assets/text-4k.png" type="Texture" id=8] [ext_resource path="res://shaders/notemesh.shader" type="Shader" id=9] -[ext_resource path="res://Menu.gd" type="Script" id=10] -[ext_resource path="res://shaders/scoretext.tres" type="Material" id=11] -[ext_resource path="res://ScoreText.gd" type="Script" id=12] -[ext_resource path="res://Bezel.gd" type="Script" id=13] -[ext_resource path="res://assets/NotoSans.tres" type="DynamicFont" id=14] -[ext_resource path="res://InputHandler.gd" type="Script" id=15] +[ext_resource path="res://shaders/notelines.shader" type="Shader" id=10] +[ext_resource path="res://NotePainter.gd" type="Script" id=11] +[ext_resource path="res://Menu.gd" type="Script" id=12] +[ext_resource path="res://shaders/scoretext.tres" type="Material" id=13] +[ext_resource path="res://ScoreText.gd" type="Script" id=14] +[ext_resource path="res://Bezel.gd" type="Script" id=15] +[ext_resource path="res://assets/NotoSans.tres" type="DynamicFont" id=16] +[ext_resource path="res://InputHandler.gd" type="Script" id=17] -[sub_resource type="ShaderMaterial" id=4] +[sub_resource type="ShaderMaterial" id=1] shader = ExtResource( 4 ) shader_param/num_receptors = 8 shader_param/line_color = Color( 0, 0, 1, 1 ) @@ -28,11 +30,18 @@ shader_param/shadow_thickness = 0.01 shader_param/shadow_thickness_taper = 0.33 shader_param/px = 0.002 +[sub_resource type="ShaderMaterial" id=3] +shader = ExtResource( 9 ) +shader_param/bps = null +shader_param/star_color = null +shader_param/held_color = null +shader_param/screen_size = null + [sub_resource type="ShaderMaterial" id=2] -shader = ExtResource( 8 ) -shader_param/line_color = Plane( 0.8, 0.8, 1, 0.8 ) -shader_param/line_color_double = Plane( 1, 1, 0.6, 0.9 ) -shader_param/dot_color = Plane( 1, 1, 1, 0.8 ) +shader = ExtResource( 10 ) +shader_param/line_color = Color( 0.8, 0.8, 1, 0.8 ) +shader_param/line_color_double = Color( 1, 1, 0.6, 0.9 ) +shader_param/dot_color = Color( 1, 1, 1, 0.8 ) shader_param/bps = 1.0 shader_param/line_thickness = 0.012 shader_param/line_thickness_min = 0.0 @@ -41,12 +50,8 @@ shader_param/dot_fullbright_thickness = 0.013 shader_param/max_angle = 1.0708 shader_param/max_dist = 1.25 -[sub_resource type="ShaderMaterial" id=3] -shader = ExtResource( 9 ) -shader_param/bps = null -shader_param/star_color = null -shader_param/held_color = null -shader_param/screen_size = null +[sub_resource type="CanvasItemMaterial" id=4] +blend_mode = 4 [node name="main" type="Node2D"] position = Vector2( 540, 540 ) @@ -77,65 +82,110 @@ __meta__ = { script = ExtResource( 3 ) [node name="Receptors" type="MeshInstance2D" parent="."] -material = SubResource( 4 ) +material = SubResource( 1 ) script = ExtResource( 5 ) -[node name="SkewSlider" type="HSlider" parent="Receptors"] -visible = false -margin_left = -200.0 -margin_top = -30.0 -margin_right = 200.0 -margin_bottom = 30.0 -grow_horizontal = 2 -grow_vertical = 2 -size_flags_horizontal = 3 -size_flags_vertical = 3 -max_value = 1.0 -step = 0.001 -tick_count = 3 -ticks_on_borders = true - -[node name="VerticesSlider" type="HSlider" parent="Receptors"] -visible = false -margin_left = -200.0 -margin_top = -100.0 -margin_right = 200.0 -margin_bottom = -84.0 -min_value = 3.0 -max_value = 72.0 -value = 36.0 -tick_count = 2 -ticks_on_borders = true - [node name="NoteHandler" type="Node2D" parent="."] script = ExtResource( 6 ) -[node name="SlideTrailHandler" type="Node2D" parent="NoteHandler"] +[node name="Viewport" type="Viewport" parent="NoteHandler"] +size = Vector2( 540, 540 ) +transparent_bg = true +usage = 1 +render_target_v_flip = true +script = ExtResource( 7 ) -[node name="JudgeText" type="MeshInstance2D" parent="NoteHandler"] -texture = ExtResource( 7 ) +[node name="Center" type="Node2D" parent="NoteHandler/Viewport"] +position = Vector2( 270, 270 ) +scale = Vector2( 0.5, 0.5 ) -[node name="notelines" type="MeshInstance2D" parent="NoteHandler"] -material = SubResource( 2 ) +[node name="SlideTrailHandler" type="Node2D" parent="NoteHandler/Viewport/Center"] -[node name="meshinstance" type="MeshInstance2D" parent="NoteHandler"] +[node name="JudgeText" type="MeshInstance2D" parent="NoteHandler/Viewport/Center"] +texture = ExtResource( 8 ) + +[node name="meshinstance" type="MeshInstance2D" parent="NoteHandler/Viewport/Center"] material = SubResource( 3 ) -[node name="Menu" type="Node2D" parent="."] -script = ExtResource( 10 ) +[node name="notelines" type="MeshInstance2D" parent="NoteHandler/Viewport/Center"] +material = SubResource( 2 ) -[node name="ScoreText" type="Node2D" parent="Menu"] -material = ExtResource( 11 ) +[node name="Painter" type="Node2D" parent="NoteHandler"] +material = SubResource( 4 ) +script = ExtResource( 11 ) + +[node name="Menu" type="Node2D" parent="."] script = ExtResource( 12 ) +[node name="ScoreText" type="Node2D" parent="Menu"] +material = ExtResource( 13 ) +script = ExtResource( 14 ) + [node name="Bezel" type="Node2D" parent="."] -script = ExtResource( 13 ) +script = ExtResource( 15 ) [node name="InputHandler" type="Label" parent="."] margin_left = -540.0 margin_top = -540.0 margin_right = 540.0 margin_bottom = 540.0 -custom_fonts/font = ExtResource( 14 ) +custom_fonts/font = ExtResource( 16 ) text = "Fingers on the screen:" -script = ExtResource( 15 ) +script = ExtResource( 17 ) + +[node name="VerticesSlider" type="HSlider" parent="InputHandler"] +margin_left = 10.0 +margin_top = 280.0 +margin_right = 310.0 +margin_bottom = 296.0 +min_value = 3.0 +max_value = 72.0 +value = 36.0 +tick_count = 2 +ticks_on_borders = true + +[node name="SkewSlider" type="HSlider" parent="InputHandler"] +margin_left = 10.0 +margin_top = 310.0 +margin_right = 310.0 +margin_bottom = 320.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +max_value = 0.5 +step = 0.01 +tick_count = 3 +ticks_on_borders = true + +[node name="SSXSlider" type="HSlider" parent="InputHandler"] +margin_left = 10.0 +margin_top = 400.0 +margin_right = 310.0 +margin_bottom = 410.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +min_value = 0.1 +max_value = 2.0 +step = 0.01 +value = 1.0 +tick_count = 3 +ticks_on_borders = true + +[node name="SSYSlider" type="HSlider" parent="InputHandler"] +margin_left = 10.0 +margin_top = 430.0 +margin_right = 310.0 +margin_bottom = 440.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +min_value = 0.1 +max_value = 2.0 +step = 0.01 +value = 1.0 +tick_count = 3 +ticks_on_borders = true diff --git a/project.godot b/project.godot index f4c741a..4e50b08 100644 --- a/project.godot +++ b/project.godot @@ -44,12 +44,12 @@ gdscript/warnings/integer_division=false [display] -window/size/width=1080 +window/size/width=1920 window/size/height=1080 window/size/fullscreen=true window/handheld/orientation="sensor" window/stretch/mode="2d" -window/stretch/aspect="expand" +window/stretch/aspect="keep_height" [gdnative] @@ -57,6 +57,7 @@ singletons=[ "res://addons/videodecoder.gdnlib" ] [rendering] +vram_compression/import_etc=true environment/default_clear_color=Color( 0, 0, 0, 1 ) quality/filters/msaa=1 environment/default_environment="res://default_env.tres"