Skip to content

Commit

Permalink
🧑‍💻 配列のリサイズ機能を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
haiiro2gou committed Jan 5, 2024
1 parent 926e994 commit 9a5cf8d
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 49 deletions.
2 changes: 1 addition & 1 deletion data/ashen_lib/tags/functions/tick/.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"replace": false,
"values": [
"indexstorage:gc/tick"
"indexstorage:tick"
]
}
14 changes: 11 additions & 3 deletions data/indexstorage/functions/gc/_index.d.mcfunction
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#> indexstorage:gc/_index.d
# @private

#> score_holder
# @within function indexstorage:gc/*
#declare score_holder #LoopIndex
#> GC main
# @within function
# indexstorage:tick
# indexstorage:gc/main/loop
#declare score_holder #GCIndex

#> GC resize
# @within function
# indexstorage:tick
# indexstorage:gc/resize/loop
#declare score_holder #ResizeIndex
18 changes: 0 additions & 18 deletions data/indexstorage/functions/gc/loop.mcfunction

This file was deleted.

8 changes: 8 additions & 0 deletions data/indexstorage/functions/gc/main/_index.d.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#> indexstorage:gc/main/_index.d
# @private

#> score_holder
# @within function
# indexstorage:tick
# indexstorage:gc/main/loop
#declare score_holder #GCIndex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#> indexstorage:gc/copy.m
#> indexstorage:gc/main/copy.m
# @input args
# id : int
# @within function indexstorage:gc/loop
# @within function indexstorage:gc/main/loop

$data modify storage indexstorage:core m.name set from storage indexstorage: data[$(id)].UUIDString
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#> indexstorage:gc/exec.m
#> indexstorage:gc/main/exec.m
# @input args
# name : string
# @within function indexstorage:gc/loop
# @within function indexstorage:gc/main/loop

$execute if score $(name) Ashen.IndexStorage.ID matches 0.. run return 0
function indexstorage:deprive/ with storage indexstorage:core m
18 changes: 18 additions & 0 deletions data/indexstorage/functions/gc/main/loop.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#> indexstorage:gc/main/loop
# @within function
# indexstorage:tick
# 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

# 存在しなければ削除
function indexstorage:gc/main/copy.m with storage indexstorage:core m
function indexstorage:gc/main/exec.m with storage indexstorage:core m

# reset
data remove storage indexstorage:core m

# ループを入れる
function indexstorage:gc/main/loop
10 changes: 10 additions & 0 deletions data/indexstorage/functions/gc/resize/loop.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#> indexstorage:gc/resize/loop
# @within function
# indexstorage:tick
# indexstorage:gc/resize/loop

# 末尾を削除
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
23 changes: 0 additions & 23 deletions data/indexstorage/functions/gc/tick.mcfunction

This file was deleted.

31 changes: 31 additions & 0 deletions data/indexstorage/functions/tick.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#> indexstorage:tick
# @within tag/function ashen_lib:tick/

#> Val
# @private
#declare score_holder #CurrentTime
#declare score_holder #LatestGC

# 前回GCからの経過時間を取得
execute store result score #CurrentTime Ashen.Global.Temporary run data get storage global Time 1
execute store result score #LatestGC Ashen.Global.Temporary run data get storage indexstorage:core LatestGC 1
scoreboard players operation #LatestGC Ashen.Global.Temporary -= #CurrentTime Ashen.Global.Temporary
scoreboard players operation #LatestGC Ashen.Global.Temporary *= #-1 Ashen.Global.Const

# (#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 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

# リセット
scoreboard players reset #CurrentTime Ashen.Global.Temporary
scoreboard players reset #LatestGC Ashen.Global.Temporary
scoreboard players reset #GCIndex Ashen.IndexStorage.ID
scoreboard players reset #ResizeIndex Ashen.Global.Temporary

0 comments on commit 9a5cf8d

Please sign in to comment.