Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
tutorial:modding_architecture:zh [2023/11/03 06:32]
hfsr [架构是什么?]
tutorial:modding_architecture:zh [2023/11/03 06:58]
hfsr [Registering an architecture]
Line 30: Line 30:
 在最简单的样例中,每次调用`runThreaded()`时在你的虚拟机中仅仅进行若干`run`调用。不过这样做实际用处不大,因为你会想要以某种方式与外界通信。为了实现此功能,需要将与组件的通信提供给虚拟机。你需要在虚拟机内定义用于与执行机API通信的API(例如:`components()`和`invoke()`)。 在最简单的样例中,每次调用`runThreaded()`时在你的虚拟机中仅仅进行若干`run`调用。不过这样做实际用处不大,因为你会想要以某种方式与外界通信。为了实现此功能,需要将与组件的通信提供给虚拟机。你需要在虚拟机内定义用于与执行机API通信的API(例如:`components()`和`invoke()`)。
  
-Synchronized calls and call limits+同步调用与调用上限
 ---------------------------------- ----------------------------------
-Callbacks on components may declare to be "​direct",​ and in addition to that they may declare a "call limit"​. Per default, all component callbacks are *synchronizedcalls, i.e. the architecture must ensure that they are only called from runSynchronized(). +组件可能有一些回调函数声明为“直接调用”,此外它们可能还会定义“调用上限”。默认情况下,所有的组件回调函数都是**同步调用**,即架构必须保证这些函数只能由`runSynchronized()`调用。 
-The call limit for direct calls limits how often per tick any single method may be called from any single machine. The limit itself is enforced in the machine'​s ​invoke ​method, which will throw a `LimitReachedException` ​once there were too many call. At that point the architecture should either perform a short sleep, or fall back to perform a synchronized call instead.+直接调用的调用上限限制了单个执行机每tick调用某一个函数的次数。限制本身由执行机的`invoke`方法确保实现,此方法会在调用次数过多时抛出`LimitReachedException`异常。此时架构应当短暂休眠,或者改为执行非同步调用。
  
-- *Note*: while writing this I realized I forgot to pull some methods required to perform checks on this into the API. This will be remedied in the next API update, making methods for this available in the Component ​interface. For now, either reflect into it or build against the OC sources. Sorry about that.+- **注意:**在写这段内容的时候,我发现我忘记了把一些执行检查所需的方法放入API中。这将在下一个API更新中得到修复,使这些方法在`Component`接口中可用。现在的话,要么将它们反射进去,要么从OC源码自行构建模组。我对此表示抱歉。
  
 Example code Example code
Line 225: Line 225:
 ``` ```
  
-Registering an architecture+注册架构
 --------------------------- ---------------------------
-This one's pretty simple: just do `li.cil.oc.api.Machine.add(PseudoArchitecture.class)`. This will allow CPUs to provide the registered architecture. If you do not wish OC CPUs to provide your architecture,​ you can either add your own `Processor` ​driver that can be used to get access to the architecture,​ or go one step further and add your own computer block, that will exclusively run your architecture,​ for example.+这一步非常简单,只需调用`li.cil.oc.api.Machine.add(PseudoArchitecture.class)`即可。注册架构后CPU即可提供被注册的架构。如果你不想让OC模组的CPU提供你的架构,那么你可以添加自己的`Processor`驱动程序以用于访问架构。或者更进一步,添加你自己的电脑方块,专用于运行你的架构。
  
 目录 目录
 ------------ ------------
 {{page>​tutorial:​contents:​zh&​noheader&​noeditbutton&​nouser&​nofooter}} {{page>​tutorial:​contents:​zh&​noheader&​noeditbutton&​nouser&​nofooter}}