Skip to content

Commit

Permalink
🧑‍💻 削除済みID配列とデータストレージのGC処理を分割
Browse files Browse the repository at this point in the history
  • Loading branch information
haiiro2gou committed Jan 5, 2024
1 parent dfef2a6 commit 636d7d4
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 24 deletions.
2 changes: 1 addition & 1 deletion data/indexstorage/functions/gc/_index.d.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
#> GC resize
# @within function
# indexstorage:tick
# indexstorage:gc/resize/loop
# indexstorage:gc/resize/data
#declare score_holder #ResizeIndex
8 changes: 0 additions & 8 deletions data/indexstorage/functions/gc/main/_index.d.mcfunction

This file was deleted.

4 changes: 2 additions & 2 deletions data/indexstorage/functions/gc/main/loop.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# indexstorage:gc/main/loop

# 1加える
execute store result storage indexstorage:core m.id int 1 run scoreboard players add #GCIndex Ashen.IndexStorage.ID 1
execute if score #GCIndex Ashen.IndexStorage.ID > #StorageIDIndex Ashen.Global.Global run return 0
execute store result storage indexstorage:core m.id int 1 run scoreboard players add #GCIndex Ashen.Global.Temporary 1
execute if score #GCIndex Ashen.Global.Temporary > #StorageIDIndex Ashen.Global.Global run return 0

# 存在しなければ削除
function indexstorage:gc/main/copy.m with storage indexstorage:core m
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#> indexstorage:gc/resize/loop
# @within function
# indexstorage:tick
# indexstorage:gc/resize/loop
# indexstorage:gc/resize/data

# 末尾を削除
data remove storage indexstorage: data[-1]
# ループ
scoreboard players remove #ResizeIndex Ashen.Global.Temporary 1
execute if score #ResizeIndex Ashen.Global.Temporary matches 1.. run function indexstorage:gc/resize/loop
execute if score #ResizeIndex Ashen.Global.Temporary > #StorageIDIndex Ashen.Global.Global run function indexstorage:gc/resize/data
17 changes: 17 additions & 0 deletions data/indexstorage/functions/gc/resize/id.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#> indexstorage:gc/resize/id
# @within function
# indexstorage:tick
# indexstorage:gc/resize/id

#> Val
# @private
#declare score_holder #TargetID

# スコアに変換
execute store result score #TargetID Ashen.Global.Temporary run data get storage indexstorage:core temp[-1]
# 上限値より小さければそのまま戻す
execute if score #TargetID Ashen.Global.Temporary <= #StorageIDIndex Ashen.Global.Global run data modify storage indexstorage:core UnusedID append from storage indexstorage:core temp[-1]
# ループ
data remove storage indexstorage:core temp[-1]
scoreboard players reset #TargetID Ashen.Global.Temporary
execute if data storage indexstorage:core temp[-1] run function indexstorage:gc/resize/id
6 changes: 3 additions & 3 deletions data/indexstorage/functions/provide/.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
execute unless data storage indexstorage:core UnusedID[-1] run data modify storage indexstorage: data append value {}
execute if data storage indexstorage:core UnusedID[-1] run function ashen_lib:array/session/open
execute if data storage indexstorage:core UnusedID[-1] run data modify storage ashen_lib:api Array set from storage indexstorage:core UnusedID
execute if data storage indexstorage:core UnusedID[-1] run function ashen_lib:array/sort/descend
execute if data storage indexstorage:core UnusedID[-1] run function ashen_lib:array/sort/ascend
execute if data storage indexstorage:core UnusedID[-1] run data modify storage indexstorage:core UnusedID set from storage ashen_lib:api Array
execute if data storage indexstorage:core UnusedID[-1] run function ashen_lib:array/session/close
execute if data storage indexstorage:core UnusedID[-1] store result score @s Ashen.IndexStorage.ID run data get storage indexstorage:core UnusedID[-1]
execute if data storage indexstorage:core UnusedID[-1] run data remove storage indexstorage:core UnusedID[-1]
execute if data storage indexstorage:core UnusedID[-1] store result score @s Ashen.IndexStorage.ID run data get storage indexstorage:core UnusedID[0]
execute if data storage indexstorage:core UnusedID[-1] run data remove storage indexstorage:core UnusedID[0]

# ストレージ割り当て
execute store result storage indexstorage:core m.id int 1 run scoreboard players get @s Ashen.IndexStorage.ID
Expand Down
25 changes: 17 additions & 8 deletions data/indexstorage/functions/tick.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,29 @@
scoreboard players operation #LatestGC Ashen.Global.Temporary -= #CurrentTime Ashen.Global.Temporary
scoreboard players operation #LatestGC Ashen.Global.Temporary *= #-1 Ashen.Global.Const

title @a actionbar [{"score":{"name":"#LatestGC","objective":"Ashen.Global.Temporary"}},{"text":" / "},{"score":{"name":"#GCInterval","objective":"Ashen.Global.Global"}}]

# (#GCDuration)tick経過していたらgcループを発火
# 存在しないデータを削除
execute if score #LatestGC Ashen.Global.Temporary >= #GCInterval Ashen.Global.Global run scoreboard players set #GCIndex Ashen.IndexStorage.ID -1
execute if score #LatestGC Ashen.Global.Temporary >= #GCInterval Ashen.Global.Global run scoreboard players set #GCIndex Ashen.Global.Temporary -1
execute if score #LatestGC Ashen.Global.Temporary >= #GCInterval Ashen.Global.Global run function indexstorage:gc/main/loop
execute if score #LatestGC Ashen.Global.Temporary >= #GCInterval Ashen.Global.Global store result storage indexstorage:core LatestGC int 1 run scoreboard players get #CurrentTime Ashen.Global.Temporary
# 配列のリサイズ
execute if score #LatestGC Ashen.Global.Temporary >= #GCInterval Ashen.Global.Global run scoreboard players operation #ResizeIndex Ashen.Global.Temporary = #StorageIDIndex Ashen.Global.Global
execute if score #LatestGC Ashen.Global.Temporary >= #GCInterval Ashen.Global.Global run scoreboard players set #StorageIDIndex Ashen.Global.Global -1
execute if score #LatestGC Ashen.Global.Temporary >= #GCInterval Ashen.Global.Global run scoreboard players operation #StorageIDIndex Ashen.Global.Global > * Ashen.IndexStorage.ID
execute if score #LatestGC Ashen.Global.Temporary >= #GCInterval Ashen.Global.Global run scoreboard players operation #ResizeIndex Ashen.Global.Temporary -= #StorageIDIndex Ashen.Global.Global
execute if score #LatestGC Ashen.Global.Temporary >= #GCInterval Ashen.Global.Global if score #ResizeIndex Ashen.Global.Temporary matches 1.. run function indexstorage:gc/resize/loop
# 現存するエンティティの中のIDの最大値を取得
execute if score #LatestGC Ashen.Global.Temporary >= #GCInterval Ashen.Global.Global run scoreboard players operation #ResizeIndex Ashen.Global.Temporary = #StorageIDIndex Ashen.Global.Global
execute if score #LatestGC Ashen.Global.Temporary >= #GCInterval Ashen.Global.Global run scoreboard players set #StorageIDIndex Ashen.Global.Global -1
execute if score #LatestGC Ashen.Global.Temporary >= #GCInterval Ashen.Global.Global run scoreboard players operation #StorageIDIndex Ashen.Global.Global > * Ashen.IndexStorage.ID
# データの整理
execute if score #LatestGC Ashen.Global.Temporary >= #GCInterval Ashen.Global.Global if score #ResizeIndex Ashen.Global.Temporary > #StorageIDIndex Ashen.Global.Global run function indexstorage:gc/resize/data
# 削除済みIDの整理
execute if score #LatestGC Ashen.Global.Temporary >= #GCInterval Ashen.Global.Global run data modify storage indexstorage:core temp set from storage indexstorage:core UnusedID
execute if score #LatestGC Ashen.Global.Temporary >= #GCInterval Ashen.Global.Global run data modify storage indexstorage:core UnusedID set value []
execute if score #LatestGC Ashen.Global.Temporary >= #GCInterval Ashen.Global.Global if data storage indexstorage:core temp[-1] run function indexstorage:gc/resize/id
# 実行時刻を記録
execute if score #LatestGC Ashen.Global.Temporary >= #GCInterval Ashen.Global.Global store result storage indexstorage:core LatestGC int 1 run scoreboard players get #CurrentTime Ashen.Global.Temporary

# リセット
data remove storage indexstorage:core temp
scoreboard players reset #CurrentTime Ashen.Global.Temporary
scoreboard players reset #LatestGC Ashen.Global.Temporary
scoreboard players reset #GCIndex Ashen.IndexStorage.ID
scoreboard players reset #GCIndex Ashen.Global.Temporary
scoreboard players reset #ResizeIndex Ashen.Global.Temporary

0 comments on commit 636d7d4

Please sign in to comment.