Skip to content

Instantly share code, notes, and snippets.

@JohnnyonFlame
Last active March 7, 2022 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnnyonFlame/9a8817430f7ecef06a1a13d2200e6c47 to your computer and use it in GitHub Desktop.
Save JohnnyonFlame/9a8817430f7ecef06a1a13d2200e6c47 to your computer and use it in GitHub Desktop.
TresBashers perf fix

Known Issues:

  • Hell Well still falls a bit under 60fps on RK3326, investigate how to improve enemy logic performance.

Changes to code:

  • Added disabling/enabling bg instances only when necessary
  • Added logic when obj_weathervane gets in and out of screen:
    • Activate/Deactivate obj_relic_ring instances when offscreen state flips.
    • Don't the rotation math and set visible to false.
  • Modified behavior of obj_camera object culling:
    • Allow a single frame before start culling for initialization of different elements.
      • e.g.: Allows enough time for backgrounds to settle
    • Cull every obj_parent_disabler child
    • Force closed boss gates to not be culled
    • Lowered cull range significantly, might end up increasing back to original ranges
  • Scale obj_water_surface by setting image_xscale to the number of drawn tiles (so it can be culled by the obj_parent_disabler logic).
  • Leave obj_water_surface's draw event earlier, and only draw visible tiles

Added the obj_parent_disabler parent to the following objects:

  • obj_weathervane Check manual relic_ring disable logic
  • obj_relic_ring Check manual relic_ring disable logic
  • obj_ufo_tractor_beam
  • obj_dragowary_monster
  • obj_mantis_monster
  • obj_wendigo_field
  • obj_camera_zone_free_vertical
  • obj_relic
  • obj_wheel_platform_wheel
  • obj_monster_parent
  • obj_dpad_icon_up
  • obj_boombox
  • obj_save_point
  • obj_bestiary_collectible
  • obj_parent_physics
  • obj_platform
  • parent_enm
  • obj_ladder
  • obj_spring
  • obj_shop_item_parent
  • obj_porta_potty_bashable
  • obj_water_block
  • obj_water_surface_tiles
  • obj_keycard
  • obj_camera_lock_zone
  • obj_camera_center_zone
  • obj_music_cue
  • obj_door_3d
  • obj_swingset
  • obj_locker_bashable
  • obj_vendingmachine_bashable
  • obj_door_3d_red
  • obj_ufo_tube_bashable
  • obj_bg_color_area

Things learned:

  • Avoid using object_id when you can reference the instance's id to avoid expensive lookups.
  • Be extremely frugal with instance_activate_object, the performance hit is incredibly high
    • Objects that are to be deactivated per-frame must be parented to an object that will be globally deactivated, this saves on instance_deactivate_object costs.
    • Keep a tally of what to enable and disable so you can avoid these calls.
diff --color -u Export_Code_org/gml_Object_obj_bg_color_area_Create_0.gml Export_Code/gml_Object_obj_bg_color_area_Create_0.gml
--- Export_Code_org/gml_Object_obj_bg_color_area_Create_0.gml 2022-03-04 19:15:09.241787100 -0300
+++ Export_Code/gml_Object_obj_bg_color_area_Create_0.gml 2022-03-05 21:41:20.285269500 -0300
@@ -1,4 +1,5 @@
blurb = "\nUnknown"
+blurb_cache = 0
bg_layers = 0
bg_id[0] = 0
bg_id[1] = 0
@@ -7,3 +8,4 @@
alarm[0] = 10
color_mode = 0
color_bg = 0
+_status = -1
diff --color -u Export_Code_org/gml_Object_obj_bg_color_area_Step_0.gml Export_Code/gml_Object_obj_bg_color_area_Step_0.gml
--- Export_Code_org/gml_Object_obj_bg_color_area_Step_0.gml 2022-03-04 19:15:09.004723400 -0300
+++ Export_Code/gml_Object_obj_bg_color_area_Step_0.gml 2022-03-05 21:41:20.265264600 -0300
@@ -1,6 +1,7 @@
if instance_place(x, y, obj_camera)
{
- var str = string_replace_all(blurb, "\n", " ")
+ if (blurb_cache == 0)
+ blurb_cache = string_replace_all(blurb, "\n", " ")
if (obj_area_notification.blurb != blurb)
{
with (obj_area_notification)
@@ -9,25 +10,37 @@
alarm[0] = 180
visible = true
}
- global.area_title = str
+ global.area_title = blurb_cache
}
- for (i = 0; i <= bg_layers; i++)
+ if (_status != 1)
{
- if (bg_id[i] != obj_npc_mouse)
+ for (i = 0; i <= bg_layers; i++)
{
- if instance_exists(bg_id[i])
- bg_id[i].visible = true
+ if (bg_id[i] != obj_npc_mouse)
+ {
+ instance_activate_object(bg_id[i])
+ if instance_exists(bg_id[i])
+ bg_id[i].visible = true
+ }
}
}
+ _status = 1
}
else
{
- for (i = 0; i <= bg_layers; i++)
+ if (_status != 0)
{
- if (bg_id[i] != obj_npc_mouse)
+ for (i = 0; i <= bg_layers; i++)
{
- if instance_exists(bg_id[i])
- bg_id[i].visible = false
+ if (bg_id[i] != obj_npc_mouse)
+ {
+ if instance_exists(bg_id[i])
+ {
+ bg_id[i].visible = false
+ instance_deactivate_object(bg_id[i])
+ }
+ }
}
}
+ _status = 0
}
diff --color -u Export_Code_org/gml_Object_obj_boss_gate_cue_Collision_obj_player.gml Export_Code/gml_Object_obj_boss_gate_cue_Collision_obj_player.gml
--- Export_Code_org/gml_Object_obj_boss_gate_cue_Collision_obj_player.gml 2022-03-04 21:08:14.167258800 -0300
+++ Export_Code/gml_Object_obj_boss_gate_cue_Collision_obj_player.gml 2022-03-05 21:41:19.701141300 -0300
@@ -3,7 +3,7 @@
instance_activate_object(obj_boss_gate)
with (obj_boss_gate)
{
- if (!closed)
+ if ((!closed) && distance_to_object(obj_player) < (camera_get_view_width(view_camera[0]) * 6))
{
audio_stop_sound(sfx_boss_gate_shut)
audio_play_sound(sfx_boss_gate_shut, 10, false)
diff --color -u Export_Code_org/gml_Object_obj_camera_Create_0.gml Export_Code/gml_Object_obj_camera_Create_0.gml
--- Export_Code_org/gml_Object_obj_camera_Create_0.gml 2022-03-04 19:15:06.691865000 -0300
+++ Export_Code/gml_Object_obj_camera_Create_0.gml 2022-03-05 21:41:19.210026600 -0300
@@ -5,6 +5,7 @@
if (os_type == os_android)
fullscreen_mode = 0
reverse_camera = 0
+first = 1
if object_exists(obj_player)
{
x = obj_player.x
diff --color -u Export_Code_org/gml_Object_obj_camera_Step_1.gml Export_Code/gml_Object_obj_camera_Step_1.gml
--- Export_Code_org/gml_Object_obj_camera_Step_1.gml 2022-03-04 19:15:06.762881400 -0300
+++ Export_Code/gml_Object_obj_camera_Step_1.gml 2022-03-05 21:41:19.238033800 -0300
@@ -1,10 +1,29 @@
-with (obj_monster_parent)
- scr_deactivate_offscreen()
-with (obj_parent_physics)
- scr_deactivate_offscreen()
-instance_activate_object(obj_player)
-instance_activate_object(obj_npc_parent)
-instance_activate_object(obj_touch_buttons)
-instance_activate_object(obj_controls_cover)
-instance_activate_object(obj_crt_filter_test)
-instance_activate_object(obj_controller)
+if (first == 0)
+{
+ var sz = 0
+ var air_list = []
+ with (obj_boss_gate)
+ {
+ if closed
+ air_list[sz++] = id
+ }
+ instance_deactivate_object(obj_parent_disabler)
+ var vx = camera_get_view_x(view_camera[0])
+ var vy = camera_get_view_y(view_camera[0])
+ var vw = camera_get_view_width(view_camera[0])
+ var vh = camera_get_view_height(view_camera[0])
+ var px = x
+ var py = y
+ instance_activate_region((vx - (vw * 1)), (vy - (vh * 1)), (vw * 3), (vh * 3), true)
+ for (i = 0; i < sz; i++)
+ instance_activate_object(air_list[i])
+}
+else
+{
+ instance_activate_object(obj_player)
+ instance_activate_object(obj_controller)
+ instance_activate_object(obj_touch_buttons)
+ instance_activate_object(obj_controls_cover)
+ instance_activate_object(obj_crt_filter_test)
+}
+first = 0
diff --color -u Export_Code_org/gml_Object_obj_water_surface_tiles_Create_0.gml Export_Code/gml_Object_obj_water_surface_tiles_Create_0.gml
--- Export_Code_org/gml_Object_obj_water_surface_tiles_Create_0.gml 2022-03-04 19:15:06.905911400 -0300
+++ Export_Code/gml_Object_obj_water_surface_tiles_Create_0.gml 2022-03-05 21:41:19.326052500 -0300
@@ -17,3 +17,5 @@
x_check += 8
i++
}
+i_max_w = ((i_max + 1) * 8)
+image_xscale = (i_max_w + 1)
diff --color -u Export_Code_org/gml_Object_obj_water_surface_tiles_Draw_0.gml Export_Code/gml_Object_obj_water_surface_tiles_Draw_0.gml
--- Export_Code_org/gml_Object_obj_water_surface_tiles_Draw_0.gml 2022-03-04 19:15:06.918914700 -0300
+++ Export_Code/gml_Object_obj_water_surface_tiles_Draw_0.gml 2022-03-05 21:41:19.334055100 -0300
@@ -1,10 +1,19 @@
x_check = xstart
y_check = ystart
-i = 0
-repeat (i_max + 1)
+var vx = camera_get_view_x(view_camera[0])
+var vy = camera_get_view_y(view_camera[0])
+var vw = camera_get_view_width(view_camera[0])
+var vh = camera_get_view_height(view_camera[0])
+if rectangle_in_rectangle(x, y, (x + i_max_w), (y + 8), vx, vy, (vx + vw), (vy + vh))
{
- if x_tile[i]
- draw_sprite(sprite_index, image_index, x_check, y_check)
- x_check += 8
- i++
+ var i = max(0, floor(((vx - x) / 8)))
+ var ineg = min(((vw / 8) + 1), ((i_max + 1) - i))
+ x_check += (i * 8)
+ repeat ineg
+ {
+ if x_tile[i]
+ draw_sprite(sprite_index, image_index, x_check, y_check)
+ x_check += 8
+ i++
+ }
}
diff --color -u Export_Code_org/gml_Object_obj_weathervane_PreCreate_0.gml Export_Code/gml_Object_obj_weathervane_PreCreate_0.gml
--- Export_Code_org/gml_Object_obj_weathervane_PreCreate_0.gml 2022-03-04 19:15:07.869332200 -0300
+++ Export_Code/gml_Object_obj_weathervane_PreCreate_0.gml 2022-03-05 21:41:19.676131700 -0300
@@ -1 +1,2 @@
event_inherited()
+_was_onscreen = 0
diff --color -u Export_Code_org/gml_Object_obj_weathervane_Step_0.gml Export_Code/gml_Object_obj_weathervane_Step_0.gml
--- Export_Code_org/gml_Object_obj_weathervane_Step_0.gml 2022-03-04 19:15:07.834326400 -0300
+++ Export_Code/gml_Object_obj_weathervane_Step_0.gml 2022-03-05 21:41:19.662127800 -0300
@@ -1,17 +1,31 @@
-image_xscale = (sin((t * f)) * a)
-t++
-if (state == 1)
+if scr_onscreen_check()
{
- if generating_wind
+ if (_was_onscreen != 1)
{
- state = 2
- alarm[0] = 1
+ instance_activate_object(obj_relic_ring)
+ visible = true
+ }
+ image_xscale = (sin((t * f)) * a)
+ t++
+ if (state == 1)
+ {
+ if generating_wind
+ {
+ state = 2
+ alarm[0] = 1
+ }
+ }
+ if (state >= 1)
+ {
+ t += speed_increase
+ var _speed_max = 3
+ if (speed_increase < _speed_max)
+ speed_increase += 0.01
}
}
-if (state >= 1)
+else if (_was_onscreen == 1)
{
- t += speed_increase
- var _speed_max = 3
- if (speed_increase < _speed_max)
- speed_increase += 0.01
+ instance_deactivate_object(obj_relic_ring)
+ visible = false
}
+_was_onscreen = onscreen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment