|
30 | 30 |
|
31 | 31 | - [Introduction](#introduction) |
32 | 32 | - [Performance](#performance) |
| 33 | + - [Benchmarks](#benchmarks) |
33 | 34 | - [Simplicity](#simplicity) |
34 | 35 | - [Flexibility](#flexibility) |
35 | 36 | - [Installation](#installation) |
|
65 | 66 | - [Fragment Requirements](#fragment-requirements) |
66 | 67 | - [Destruction Policies](#destruction-policies) |
67 | 68 | - [Custom Component Storages](#custom-component-storages) |
| 69 | + - [Error Handling](#error-handling) |
68 | 70 | - [Garbage Collection](#garbage-collection) |
69 | 71 | - [Cheat Sheet](#cheat-sheet) |
70 | 72 | - [Aliases](#aliases) |
@@ -98,6 +100,10 @@ This library is designed to be fast. Many techniques are employed to achieve thi |
98 | 100 |
|
99 | 101 | Not all the optimizations I want to implement are done yet, but I will be working on them. However, I can already say that the library is fast enough for most use cases. |
100 | 102 |
|
| 103 | +#### Benchmarks |
| 104 | + |
| 105 | +The library contains some micro-benchmarks for internal use in the [develop/benchmarks](./develop/benchmarks/) directory, but they are not comprehensive and are not intended for comparison with other ECS libraries. I don't like cross-library benchmarks, as they are often biased and not representative of real-world performance. However, you can look at benchmarks from independent third-party authors, for example, [these](https://github.com/jeffzi/lua-ecs-benchmark) nice benchmarks by [@jeffzi](https://github.com/jeffzi) that cover most libraries, including `evolved.lua`. |
| 106 | + |
101 | 107 | ### Simplicity |
102 | 108 |
|
103 | 109 | I have tried to keep the [API](#cheat-sheet) as simple and intuitive as possible. I also keep the number of functions under control. All the functions are self-explanatory and easy to use. After reading the [Overview](#overview) section, you should be able to use the library without any problems. |
@@ -1426,6 +1432,24 @@ evolved.builder() |
1426 | 1432 | evolved.process_with(MOVEMENT_SYSTEM, 0.016) |
1427 | 1433 | ``` |
1428 | 1434 |
|
| 1435 | +### Error Handling |
| 1436 | + |
| 1437 | +Since systems perform processing in a deferred scope, any errors that occur during processing can leave the library in an inconsistent state. To handle this, the library runs a protected call for each system and catches any errors that occur. By default, the library will collect the error message and the current stack trace and rethrow the error with this information. It is safe to catch errors, but it can be inconvenient to use with a debugger, because debuggers usually break on the rethrow instead of the place where the error happened. To make it easier to debug errors in systems, the library provides a way to set a custom error handler that will be called when an error occurs during system processing. For example, you can set an error handler that breaks into the debugger: |
| 1438 | + |
| 1439 | +```lua |
| 1440 | +-- we use Local Lua Debugger in this example |
| 1441 | +local debugger = require 'lldebugger' |
| 1442 | +debugger.start() |
| 1443 | + |
| 1444 | +local evolved = require 'evolved' |
| 1445 | +evolved.error_handler(function(message) |
| 1446 | + debugger.requestBreak() |
| 1447 | + return debug.traceback(message) |
| 1448 | +end) |
| 1449 | +``` |
| 1450 | + |
| 1451 | +This way, when an error occurs during system processing, the error handler will be called, which will break into the debugger, allowing you to inspect the state of the program at the moment of the error. After you continue execution in the debugger, the error will be rethrown with the original message and stack trace. |
| 1452 | + |
1429 | 1453 | ### Garbage Collection |
1430 | 1454 |
|
1431 | 1455 | While using the library, some internal data structures can become obsolete and should be cleaned up to free memory. For example, empty chunks that no longer contain entities can be removed. Component storages can also have unused capacity that can be shrunk to save memory. The library provides a function to control this garbage collection process. |
|
0 commit comments