Modding:Modding Efficiently: Difference between revisions

From Vintage Story Wiki
no edit summary
No edit summary
No edit summary
Line 11: Line 11:
* Use the error reporter activated via <code>/errorreporter 1</code> to save yourself the work of finding and scouring through the log files for problems. This feature will make it so that a dialog pop ups during start up of the game if any errors were encountered.
* Use the error reporter activated via <code>/errorreporter 1</code> to save yourself the work of finding and scouring through the log files for problems. This feature will make it so that a dialog pop ups during start up of the game if any errors were encountered.
* If you want to create json patches, you can use ModMaker 3000™, a command line tool that ships with the game, to build the patches for you
* If you want to create json patches, you can use ModMaker 3000™, a command line tool that ships with the game, to build the patches for you
* If you are doing programming tasks
 
** Use break points for debugging
== When writing C# mods ==
** Browse through the many utility classes provided by the VS API, you might be able to save a lot of coding efforts! (e.g. [https://github.com/anegostudios/vsapi/blob/master/Math/ColorUtil.cs ColorUtil], [https://github.com/anegostudios/vsapi/blob/master/Math/GameMath.cs GameMath], [https://github.com/anegostudios/vsapi/blob/master/Util/ArrayExtensions.cs ArrayExtensions], [https://github.com/anegostudios/vsapi/blob/master/Util/DictExtensions.cs DictExtensions], [https://github.com/anegostudios/vsapi/blob/master/Util/HashsetExtensions.cs HashsetExtensions], [https://github.com/anegostudios/vsapi/blob/master/Util/JsonUtil.cs JsonUtil], [https://github.com/anegostudios/vsapi/blob/master/Util/JsonUtil.cs ReaderWriterExtensions], [https://github.com/anegostudios/vsapi/blob/master/Util/SerializerUtil.cs SerializerUtil], [https://github.com/anegostudios/vsapi/blob/master/Util/WildcardUtil.cs WildcardUtil]
* Use break points for debugging
** You can use edit&continue feature of Visual Studio to modify code while the game is running!
* Browse through the many utility classes provided by the VS API, you might be able to save a lot of coding efforts! (e.g. [https://github.com/anegostudios/vsapi/blob/master/Math/ColorUtil.cs ColorUtil], [https://github.com/anegostudios/vsapi/blob/master/Math/GameMath.cs GameMath], [https://github.com/anegostudios/vsapi/blob/master/Util/ArrayExtensions.cs ArrayExtensions], [https://github.com/anegostudios/vsapi/blob/master/Util/DictExtensions.cs DictExtensions], [https://github.com/anegostudios/vsapi/blob/master/Util/HashsetExtensions.cs HashsetExtensions], [https://github.com/anegostudios/vsapi/blob/master/Util/JsonUtil.cs JsonUtil], [https://github.com/anegostudios/vsapi/blob/master/Util/JsonUtil.cs ReaderWriterExtensions], [https://github.com/anegostudios/vsapi/blob/master/Util/SerializerUtil.cs SerializerUtil], [https://github.com/anegostudios/vsapi/blob/master/Util/WildcardUtil.cs WildcardUtil]
** If you don't already use the [https://github.com/anegostudios/vsmodexamples/blob/master/RedirectLogs.cs RedirectLogs] mod during testing to see the log output live in the Visual Studio output window
* You can use edit&continue feature of Visual Studio to modify code while the game is running!
** If you are working with shaders, you can reload them with <code>.reload shaders</code>
* If you don't have already make sure the games log output ends up in the Visual Studio output window
** If you do not use Visual Studio, you may have limited success with the <code>/reloadmods</code> command to reload source code mods during runtime.
* If you are working with shaders, you can reload them with <code>.reload shaders</code>
 
=== Efficient Search Methods ===
 
More often than not, you'd want your code to find something in the game world. As you might already know, computers are not exactly the best at parallel processing like human eyes are, so they have to sequentially look through the entire search space. When doing so, first and foremost, the most efficient search method is one that never runs, within a search space that is of size zero ;-)
In other words, sometimes you can avoid searches altogether through other clever means! If you still need to do a search, here's some more optimal ways than the brute force way:
 
<ul>
<li><strong>Entity Search</strong><br>
Use [https://github.com/anegostudios/vsessentialsmod/blob/master/Systems/EntityPartitioning.cs EntityPartitioning] - <code>api.ModLoader.GetModSystem<EntityPartitioning>().WalkEntityPartitions()</code>. This system partitions entities into 8x8x8 block buckets through the entire loaded game world, then only searches inside those buckets, within your supplied search radius, greatly reducing the search space.</li>
<li><strong>Block Search</strong><br>
a) If you want an entity to find a certain, not extremely common block, use the [https://github.com/anegostudios/vsessentialsmod/blob/master/Systems/POIRegistry.cs POI Registry]. This registry lets block entities register a point of interest that entities can search through very efficiently. They are also partitioned into chunk column buckets to additionally reduce the search space.<br>
b) For regular full chunk scans, I recommend a separate background thread that loads the chunk and access the raw block data via <code>chunk.Blocks</code>. It's an array indexed with <code>(y * chunksize + z) * chunksize + x</code>, where the xyz are local coordinate from 0 to chunkize-1
c) For rare area scans, there is `api.World.GetBlockAccessorPrefetch()`. This blockaccessor lets you pre-load an area and then rather efficiently iterate through each block in given area
Confirmedusers, Bureaucrats, editor, Administrators
1,778

edits