Gamefield subsampling for low-end devices

This commit is contained in:
Luke Hubmayer-Werner 2019-12-21 20:42:19 +10:30
parent 48e275153c
commit d9914c4552
7 changed files with 178 additions and 95 deletions

View File

@ -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):
@ -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()

4
NotePainter.gd Normal file
View File

@ -0,0 +1,4 @@
extends Node2D
func _draw():
draw_texture_rect($"../Viewport".get_texture(), Rect2(-540, -540, 1080, 1080), false)

16
NoteViewport.gd Normal file
View File

@ -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)

View File

@ -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()
@ -108,8 +108,8 @@ func update_ring_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))
@ -144,8 +144,8 @@ func _ready():
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):

172
main.tscn
View File

@ -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

View File

@ -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"