Skip to content

Commit

Permalink
update 2024-04
Browse files Browse the repository at this point in the history
  • Loading branch information
lace-wing committed Mar 15, 2024
1 parent 3e28291 commit 68b67ec
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions info/preview-updates/2024-04.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,82 @@ Pull Request:https://github.com/tModLoader/tModLoader/pull/4087
## 提示
- LocalizationLoader 的 GetCultureAndPrefixFromPath 改成了 TryGetCultureAndPrefixFromPath。不过本来就没人用这个吧。
-->

---

<!--
# Two PRs improving the performance and usability of `HookList` and `GlobalHookList`
by **Chicken Bones** have been merged.
**Pull Requests:** <https://github.com/tModLoader/tModLoader/pull/4088> <https://github.com/tModLoader/tModLoader/pull/4089>
**Arrives in Preview**: Available Now
**Arrives in Stable**: <t:1711933200:f>
**Runtime Breakage**: 🟡 - **Minor**
**Source-code Breakage**: 🟡 - **Extremely Minor**
## Short Summary
> - Improves mod loading times by up to 10%
> - Methods for custom hooks are no longer specified via reflection, and instead use the 'lambda expression' syntax
> - The only mods with runtime breakage are those with custom hooks that have `ref` or `out` parameters.
## Examples of adding custom hooks (for an imaginary method `OnThrow` in `MyInterface`):
```cs
// GlobalItem hook
GlobalHookList<GlobalItem> HookOnThrow = ItemLoader.AddModHook(GlobalHookList<GlobalItem>.Create(g => ((MyInterface)g).OnThrow));
// ModPlayer hook
HookList<ModPlayer> HookOnThrow = PlayerLoader.AddModHook(HookList<ModPlayer>.Create(p => ((MyInterface)p).OnThrow));
```
Ping <@133915372964282368> or <@273470797916405770> if you need help updating your mod or implementing custom hooks
-->

# 改善 `HookList``GlobalHookList` 的可用性与性能
by **Chicken Bones**
**Pull Requests**<https://github.com/tModLoader/tModLoader/pull/4088><https://github.com/tModLoader/tModLoader/pull/4089>
**更新至预览版**:已完成
**更新至稳定版**:2024-04-01 09:00
**运行时破坏性**:🟡 - ****
**代码破坏性**:🟡 - **极微**

## 简要总结
- 最高减少10%模组加载时间。
- 自定义钩子的方法不再由反射,而是由“Lambda 表达式”创建。
- 只影响有含 `ref``out` 参数的钩子的模组运行。

## 添加钩子的示例
假设有接口 `MyInterface`,其中有方法 `OnThrow`
```cs
// GlobalItem 钩子
GlobalHookList<GlobalItem> HookOnThrow = ItemLoader.AddModHook(GlobalHookList<GlobalItem>.Create(g => ((MyInterface)g).OnThrow));

// ModPlayer 钩子
HookList<ModPlayer> HookOnThrow = PlayerLoader.AddModHook(HookList<ModPlayer>.Create(p => ((MyInterface)p).OnThrow));
```

如需相关帮助,可咨询 Chicken Bones 或 Mirsario。

<!--
# 改善 HookList 和 GlobalHookList 的可用性与性能
by Chicken Bones
Pull Requests:https://github.com/tModLoader/tModLoader/pull/4088、https://github.com/tModLoader/tModLoader/pull/4089
更新至预览版:已完成
更新至稳定版:2024-04-01 09:00
运行时破坏性:🟡 - 微
代码破坏性:🟡 - 极微
## 简要总结
- 最高减少10%模组加载时间。
- 自定义钩子的方法不再由反射,而是由“Lambda 表达式”创建。
- 只影响有含 ref 或 out 参数的钩子的模组运行。
## 添加钩子的示例
假设有接口 MyInterface,其中有方法 OnThrow;
// GlobalItem 钩子
GlobalHookList<GlobalItem> HookOnThrow = ItemLoader.AddModHook(GlobalHookList<GlobalItem>.Create(g => ((MyInterface)g).OnThrow));
// ModPlayer 钩子
HookList<ModPlayer> HookOnThrow = PlayerLoader.AddModHook(HookList<ModPlayer>.Create(p => ((MyInterface)p).OnThrow));
如需相关帮助,可咨询 Chicken Bones 或 Mirsario。
-->

0 comments on commit 68b67ec

Please sign in to comment.