From 16b518a75830faba7967d6432ec2a01e2179c439 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 12 Jan 2023 22:38:57 +0100 Subject: [PATCH] Added my module readmes. --- modules/entity_spell_system.md | 600 +++++++++++++++++++++++++++++++++ modules/mesh_data_resource.md | 69 ++++ modules/mesh_utils.md | 60 ++++ modules/props.md | 95 ++++++ modules/props_2d.md | 95 ++++++ modules/rtile_map.md | 25 ++ modules/skeleton_editor.md | 28 ++ modules/terraman.md | 220 ++++++++++++ modules/terraman_2d.md | 222 ++++++++++++ modules/texture_packer.md | 105 ++++++ modules/thread_pool.md | 144 ++++++++ modules/ui_extensions.md | 78 +++++ modules/voxelman.md | 227 +++++++++++++ 13 files changed, 1968 insertions(+) create mode 100644 modules/entity_spell_system.md create mode 100644 modules/mesh_data_resource.md create mode 100644 modules/mesh_utils.md create mode 100644 modules/props.md create mode 100644 modules/props_2d.md create mode 100644 modules/rtile_map.md create mode 100644 modules/skeleton_editor.md create mode 100644 modules/terraman.md create mode 100644 modules/terraman_2d.md create mode 100644 modules/texture_packer.md create mode 100644 modules/thread_pool.md create mode 100644 modules/ui_extensions.md create mode 100644 modules/voxelman.md diff --git a/modules/entity_spell_system.md b/modules/entity_spell_system.md new file mode 100644 index 0000000..8196bb3 --- /dev/null +++ b/modules/entity_spell_system.md @@ -0,0 +1,600 @@ +# Entity Spell System + +An entity and spell system for the GODOT Engine, that is usable for both 2d, and 3d games. The main purpose of this +module is to handle spells, auras, and most entity-related things like spawning, items, inventory, containers, +vendors, interaction, targeting, equipment (+ visuals), loot, crafting, talents, pets, npcs, etc ... + +The module supports networking. It is designed to be authoritative, so players shouldn't be able to cheat by design. + +It is a c++ engine module, which means you will need to compile it into godot. (See compiling) + +## Godot Version Support + +This module is developed with the 3.x branch of godot, usually at the newest revisions. + +3.2 - Will likely work, probably needs changes by now. (TODO check.)\ +3.3 - Will more likely work, might need smaller changes by now. (TODO check.)\ +3.4 - Should work without any issues. (TODO check.)\ +3.x - Works.\ +4.0 - Have been fixing support from time to time. Currently it won't build on the latest master, and it will take considerable amount of work to get it to work again after the virtual method binding rework. It will be done eventually, but it will take time. [Here](https://github.com/godotengine/godot/commit/b7e10141197fdd9b0dbc4cfa7890329510d36540)'s the last know-to-work commit. + +## Project setup tl;dr + +### First + +You need to create an `ESSResourceDB` resource somewhere in you project. (Or alloocate it dynamically.) + +Now you can either: + +-Go to `ProjectSettings->Ess->Data`, and set the `ess_resource_db_path` property also make sure that `automatic_load` is on. + +-Or you can load it yourself and set it into the `ESS` singleton either using the `resource_db` property. + +### Second + +You need to add an `ESSEntitySpawner` somewhere into your SceneTree. I recommend that you create an autoload for it. +This is where you have to implement your spawning logic. + +### What the module doesn't cover + +Movement, and controls. + +Unfortunately, there isn't a one-stop-shop solution for movement, especially if we throw networking into the mix, +and the same is true for targeting. This means that this module cannot really do much in this regard, but it will +give you as much help to set everything up as possible. + +## Optional Dependencies + +Mesh Data Resource + +https://github.com/Relintai/mesh_data_resource.git + +Adds mesh (MeshDataResource) support to ModelVisuals. + +## Pre-built binaries + +You can grab a pre-built editor binary from the [Broken Seals](https://github.com/Relintai/broken_seals/releases) +repo, should you want to. It contains all my modules. + +## Overview + +The module provides a huge number of script callbacks, usually as virtual methods they usually start with an underscore. + +Do not call methods with underscores, all of them has a normal counterpart, always call that. + +For example entity has `crafts(int id)` and `_crafts(int id)` (virtual). Always use `crafts(int id)`, it will +call `_crafts(int id)`. + +For networked classes, every variable is broken up into clientside, and serverside. This makes it easier to +develop games that can also run locally, with less overhead and simpler logic. +E.g. this makes it easy to use the visibility system even when you play locally on the server, because you just use the clientside variables, +and your logic will work the same way. + +## Settings + +Entity and spell system comes with quite a few settings, you can find these under `ProjectSettings->Ess`. + +## Singletons + +The module contains 2 singletons. `ESS`, and `ProfileManager`. Both are accessible from scripts. + +### The ESS singleton + +Contains the active `ESSResourceDB` instance, and for convenience a reference to the active `ESSEntitySpawner` +instance. Also loads/handles/processes all of the entity and spell system related ProjectSettings, so if you need +any ESS related value from ProjectSettings, don't query it directly, get it from this singleton. + +Customizable enums values are preprocessed, and you usually have multiple ways of getting them. + +### The ProfileManager singleton + +Contains methods to easily load/save/handle `PlayerProfile`s. + +#### PlayerProfile + +Contains player-related data, most notably `ClassProfile`s. + +#### ClassProfile + +Contains class-related data, most notably `ActionBarProfile`s, and `InputProfiles`. + +#### ActionBarProfile + +Contains the data for a set of actionbars. + +#### InputProfileswd + +Contains the keybind data for a class. + +## Enums + +ESS needs lots of enums to work, and to reduce complexity with includes they ended up in a few separate classes. + +I'm still in the process of converting these to be customizable (`ESS` singleton / ProjectSettings). + +(Only the ones that worth it will be converted.) + +### EntityEnums + +Contains Entity-related enums, like AIStates, skeleton attach points, entity flags, immunity flags, +state flags. + +### ItemEnums + +Contains item-related enums, like rarity, armor type, item types. + +### SpellEnums + +Contains spell-related enums, like aura types, damage types, spell categories, spell types, trigger types, +and quite a few notification constants. + +### Customizable enums + +Open `ProjectSettings`, and then go to `ESS/Enums`. + +All of the string properties are customizable enums. These require a comma-separated list. +They are essentially a godot comma separated property hint enum string. + +They all have defaults. + +Fer example: + +If you want you game to work with the following stats: Agility,Intellect,Crit,Weapon Damage,Stamina +and you want Agility,Intellect,Stamina as you main stats. + +Firstly you want to put you main stats at the beginning, because the system will take the first `main_stat_count` +stats as main stats. + +And then just enter `Agility,Intellect,Stamina,Crit,Weapon Damage` into the `stats` setting, and then +set `main_stat_count` to 3. + +When these values are expected to be used as properties, the `ESS` singleton will create snake_cased versions automatically. +`String stat_get_property_name(id: int) const` inside the ESS singleton for example. + +So in the example case `ESS.stat_get_property_name(4)` would return `weapon_damage`. + +## ESSResourceDB + +This is a class that maps ids to resources for quick lookups. +This is necessary in order to support networking, because you don't want to send resource paths over the network +every time somebody casts a spell for example. + +### ESSResourceDBStatic + +Simple static resource db. Just drag and drop all your data that you use into it with the inspector. + +Stores the data as vectors. + +Supports id remapping, which means that it can assign new ids to all added resources, so they don't clash. +The added resource's index will be set as it's id. + +This is useful for modding support, as you can just collect every mod's resource dbs, and add them to a static db, +and with this option enabled the ids will not clash. + +You can see an example of this [here](https://github.com/Relintai/broken_seals/blob/master/game/scripts/game_modules/DataManager.gd). + +### ESSResourceDBMap + +Stores everything as a vector, and a map. + +#### ESSResourceDBFolders + +Inherited from `ESSResourceDBMap`. + +It will load everything from the folders that you set up into it's `folders` property. + +## Entity + +This is the main class that can be used for players/mobs/npcs and also other things like chests. + +I ended up merging subclass functionality into it, because +that way it gains a lot more utility, by sacrificing only a small amount of memory. +For example this way it is easy to make chests attack the player, or make spell that animate objects. + +## Entity Body + +Originally entities used to be inherited from `Spatial` or `Node2D`, so they could contain/drive their own models, +but eventually on order to support both 2d, and 3d, bodies were separated from them. This unfortunately +complicates the setup a bit, but the upsides overweight the downsides, as this way you don't need to create different +entities for every model/body you have. + +Bodies are stored at `EntityData->EntitySpeciesData->ModelDatas (SpeciesModelData)->Body` + +When an `Entity` gets initialized, it will instance it's body automatically, but if you want to do it yourself, +you can call `void instance_body(entity_data: EntityData, model_index: int)` on an `Entity`. + +The `model_index` property tell the `Entity` which one it should use. + +Instancing bodies does not happen immediately, but you will probably want to set an `Entity`'s position right where +you create it, a few helpers were added:\ + +`void set_transform_2d(transform: Transform2D, only_stored: bool = false)`\ +`void set_transform_3d(transform: Transform, only_stored: bool = false)` + +Your body implementation then can get this from an entity an set itself to the right place. + +### CharacterSkeletons + +CharacterSkeletons handle the looks of your characters. + +They come in two variants, one for 2d, one for 3d. + +They have quite a few helper methods. + +They can store ModelVisuals, and ModelVisualEntries. + +They support attach points. For example a character's hand. +It adds properties based on the selected entity_type. +These are based on the values from `ProjectSettings->ESS->Enums->skeletons_bone_attachment_points`. + +If you want to merge meshes this is where you can implement it. + +#### CharacterSkeleton3D + +The 3d variant. + +[Complex 3d skeleton scene](https://github.com/Relintai/broken_seals/blob/master/game/models/entities/human/models/armature_huf.tscn) \ +[Complex 3d skeleton script](https://github.com/Relintai/broken_seals/blob/master/game/player/CharacterSkeletonGD.gd) + +#### CharacterSkeleton2D + +The 2d variant. + +[Simple 2d roguelike skeleton script](https://github.com/Relintai/broken_seals_roguelike/blob/master/game/characters/SimpleCharacter.gd) \ +[Simple 2d roguelike skeleton scene](https://github.com/Relintai/broken_seals_roguelike/blob/master/game/characters/SimpleCharacter.tscn) + +#### ModelVisual + +A collection ModelVisualEntries. + +You will need to use this to define a look. For example if you have an item that will change your character's clothes, +you will use this. + +##### ModelVisualEntry + +Contains meshes, textures, texture tints, mesh transforms. + +It has 2 modes, `Bone` and `Attachment`. + +In the bone mode, you need to select an entity type, and then a concrete bone. This is the "merge this into the final character mesh" mode. + +In the attachment mode, you need to select a common attach point (`ProjectSettings->Ess->enums->skeletons_bone_attachment_points`), +and the containing mesh will be put on to that point by the CharacterSkeleton. This is how you can implement weapons for example. + +### EntitySpeciesData + +Contains data related to a species, like `SpeciesModelData`s, and species specific spells, and auras. + +#### SpeciesModelData + +Contains a scene of a species's body and it's customizations. + +The `customizable_slots_string` and `customizable_colors_string` should be filled with a comma separated string, +they will add properties. Currently you need to click on something else, and back on the resource for these to show up, +after a change to the strings. + +The body can be any scene, Entity will instance it, and set it to it's body property. + +The body should handle movement based on the player's input, it should handle sending position information through the network, +if you want networking, it might (`CharacterSkeleton`s can also do it) also drive your animations/animation players if you have it. + +Bodies does not need to handle the graphics themselves (`ModelVisualEntries` for example) (you can implement your logic here +if you want to), but the `CharacterSkeleton` classes exist for that purpose. + +[Complex 3d body script](https://github.com/Relintai/broken_seals/blob/master/game/player/Body.gd) \ +[Complex 3d body scene](https://github.com/Relintai/broken_seals/blob/master/game/models/entities/human/models/HumanFemale.tscn) + +[Simple 2d roguelike body script](https://github.com/Relintai/broken_seals_roguelike/blob/master/game/player/Body.gd) \ +[Simple 2d roguelike body scene](https://github.com/Relintai/broken_seals_roguelike/blob/master/game/player/Body.gd) + +#### SpeciesInstance + +This class will store character model customization data. E.g. which hairstyle you want for an `Entity`. + +Not yet finished! + +### Spawning + +Since spawning (= creating) entities is entirely dependent on the type of game you are making, ESS cannot do +everything for you. It will set up stats, equipment etc, but there is no way to set up positions for example. + +You can implement your spawning logic by inheriting from `ESSEntitySpawner`, and implementing `_request_entity_spawn`. + +You should only have one spawner at any given time. It will register itself into the ESS singleton automatically. + +Since it is inherited from Node, I recommend that you create an autoload for it. + +The ESS singleton also contains convenience methods to request spawning an Entity. + +[Sample 3d spawner implementation](https://github.com/Relintai/broken_seals/blob/master/game/player/bs_entity_spawner.gd) \ +[Sample 2d spawner implementation](https://github.com/Relintai/broken_seals_roguelike/blob/master/game/player/bs_entity_spawner.gd) + +#### EntityCreateInfo + +Entity spawning usually requires a lot of complexity and hassle, this helper class aims to make it painless. + +All methods that deal with spawning will take this as a parameter. + +### EntityData + +Since setting up Entities as scenes is usually quite the hassle, `EntityData` had to be created. + +It stores everything an entity needs. + +In order to spawn an entity you need it. + +#### EntityClassData + +`EntityClassData` holds class-related information, like specs (`CharacterSpec`), spells, start spells, start auras, +alternative ais, `EntityResource`s (mana for example). + +#### CharacterSpec + +`CharacterSpec` holds spec-related information, most notably talents. + +#### EntityResource + +EntityResources are things like mana, health, or speed. These add greater flexibility over stats. + +The resource system is quite flexible, if you add a resource serverside, it will be automatically +added clientside. (You have to add `EntityResource`s to the active `ESSResourceDB`!) + +By default all entities have the build in speed and health resources, as a set index +(`EntityEnums::ENTITY_RESOURCE_INDEX_HEALTH` and `EntityEnums::ENTITY_RESOURCE_INDEX_SPEED`). + +There is also the `EntityEnums::ENTITY_RESOURCE_INDEX_RESOURCES_BEGIN` constant, so you have +the current offset where the custom resources start. + +Entity allocates these in it's `_initialize()` virtual method, if you want to customize them. + +Note that `EntityClassData` contains an array, so you can add more resources easily to classes, +these will be automatically added when the system initializes an `Entity`. + +##### EntityResourceHealth + +The standard health resource implementation. + +##### EntityResourceSpeed + +The standard speed resource implementation. + +#### EntityResourceCostData + +This is the class that lets you implement resource costs. For example mana cost for a spell. + +##### EntityResourceCostDataResource + +The standard resource cost implementation. + +##### EntityResourceCostDataHealth + +The standard health resource cost implementation. + +It has a resource property, so you can just assign any resource to this. + +### Interactions + +If you want your player to interact with it's target. For example a vendor, or loot. + +First make sure that you can interact, by checking `Entity.cans_interact()` or `Entity.canc_interact()`. +If this returns true, you can call `Entity.crequest_interact()`. This will call `Entity.sinteract()` serverside. + +Interactions are handled by `EntityData` by default. It has the same methods. If `EntityData` is not set, the `Entity` +will try to call the same overridable on itself. + +You can see an example implementation [here](https://github.com/Relintai/broken_seals/blob/master/game/scripts/entities/EntityDataGD.gd). + +### AI + +You can implement ai by extending `EntityAI`, and then assigning it to an `EntityData`. + +When an `Entity` gets spawned it will create a copy for itself, so you can safely use class variables. + +#### AIFormation + +Not yet finished, it was meant as a way to calculate offset pet positions, (If an `Entity` has let's say +4 pets you don't just want them all to stay on top of their controller). + +If this functionality ends up in `EntityAI`, after pets are finished, this will be removed. + +### Pets + +Unfortunately pet support is not yet finished. + +It is mostly done though, so you will see pet-related methods scattered around. + +### Bags + +Stores items. See `Bag`. It has quite a few virtual methods, you should be able to implement most inventory types +should you want to. + +Entity will send these over the network. + +Also Entities have a target bag property. For example this makes vendors easily implementable. + +### VRPCs + +Entities has a networked visibility system. The method itself is called `vrpc`, it works the same way as normal rpcs. +If you want to send data to every client that sees the current entity, use this. + +## Spells, Auras, Talents + +Spell is the class you need to create both spells, and aura.\ +It stores the data, and also it has the ability to be scripted.\ +Talents are actually just spells used as Auras. Right now the system just applies them as a permanent aura.\ +You don't need to worry about applying auras, cast them as spells instead. It they are set to permanent, or they have a duration set they will be applied as an aura automatically. + +Talent ranks are implemented by deapplying the earlier rank first, then applying the new rank. + +### How to + +Request casting a spell clientside: `void spell_crequest_cast(spell_id: int)` \ +Request to learn a spell clientside: `void spell_learn_requestc(id: int)` + +Request talent learning clientside: \ +`void character_talent_crequest_learn(spec_index: int, character_talent_row: int, character_talent_culomn: int)` or \ +`void class_talent_crequest_learn(spec_index: int, class_talent_row: int, class_talent_culomn: int)` + +#### Cast a spell + +Note that you should only do this serverside. + +``` +# Or get it from the active ESSResourceDB, etc +export(Spell) var spell : Spell + +func scast_spell() -> void: + var sci : SpellCastInfo = SpellCastInfo.new() + + sci.caster = info.caster + sci.target = info.target + sci.has_cast_time = spell.cast_enabled + sci.cast_time = spell.cast_cast_time + sci.spell_scale = info.spell_scale + sci.set_spell(spell) + + spell.cast_starts(sci) + +``` + +#### Apply an aura + +Normally you shouldn't do this, this is for more advanced uses. Cast the aura as a spell instead. + +Note that you should only apply auras serverside, they will be sent to clients automatically. + +``` +# Or get it from the active ESSResourceDB, etc +export(Spell) var aura : Spell + +func sapply_aura() -> void: + var ainfo : AuraApplyInfo = AuraApplyInfo.new() + + ainfo.caster = info.caster + ainfo.target = info.caster + ainfo.spell_scale = 1 + ainfo.aura = aura + + aura.sapply(ainfo) + +``` + +#### UI + +[Complete UI Implementation](https://github.com/Relintai/broken_seals/tree/master/game/ui/player) + +[Player UI Core Implementation](https://github.com/Relintai/broken_seals/tree/master/game/ui/player/player_ui) + +[Aura Frame Implementation](https://github.com/Relintai/broken_seals/tree/master/game/ui/player/auraframe) \ +[Castbar Implementation](https://github.com/Relintai/broken_seals/tree/master/game/ui/player/castbar) \ +[Unitframe Implementation](https://github.com/Relintai/broken_seals/tree/master/game/ui/player/unitframes) + +[Actionbar Implementation](https://github.com/Relintai/broken_seals/tree/master/game/ui/player/actionbars) + +[Character Window Implementation](https://github.com/Relintai/broken_seals/tree/master/game/ui/player/character) \ +[Inventory Window Implementation](https://github.com/Relintai/broken_seals/tree/master/game/ui/player/bags) \ +[Crafting Window Implementation](https://github.com/Relintai/broken_seals/tree/master/game/ui/player/crafting) \ +[Loot Window Implementation](https://github.com/Relintai/broken_seals/tree/master/game/ui/player/loot_window) \ +[Talent Window Implementation](https://github.com/Relintai/broken_seals/tree/master/game/ui/player/talents) \ +[Spellbook Window Implementation](https://github.com/Relintai/broken_seals/tree/master/game/ui/player/spellbook) \ +[Vendor Window Implementation](https://github.com/Relintai/broken_seals/tree/master/game/ui/player/vendor_window) \ +[Trainer Window Implementation](https://github.com/Relintai/broken_seals/tree/master/game/ui/player/trainer) + +[3D Nameplate Implementation](https://github.com/Relintai/broken_seals/tree/master/game/ui/world/nameplates) \ +[2D Nameplate Implementation](https://github.com/Relintai/broken_seals_roguelike/tree/master/game/ui/nameplates) + +### Infos / Pipelines + +#### SpellCastInfo + +Stores information about the state of a spell's cast. + +#### AuraApplyInfo + +Helps to apply auras + +#### SpellDamageInfo, SpellHealInfo + +These are used in the damage and heal calculation. For example these can be used to implement immunities, or absorb effects +by modifying their damage values in aura callbacks. + +### Projectiles + +Spells support projectiles, they are created/set up inside `void handle_projectile(info: SpellCastInfo)`. + +The default implementation will instance `Spell`'s projectile scene (if set), and then it will try to call a +`void setup_projectile(info: SpellCastInfo)` on it if exists. + +You can override this behaviour by implementing your own `_void handle_projectile(info: SpellCastInfo)` on `Spell` + +Note that the module already adds `SpellFollowProjectile3D`, but this has not been finished yet. + +## Items + +Items are implemented using 2 classes, `ItemTemplate`, and `ItemInstance`. + +`ItemTemplate` contains all information for a potential item. You can generate `Iteminstance`s with this, +using it's `ItemInstance create_item_instance()` method. You can also implement your custom item creation logic +using the `void _create_item_instance()` virtual. + +`ItemInstance` is the actual item. + +### Loot + +Looting can be implemented using `Entity`'s target bag functionality. + +You can see an example implementation [here](https://github.com/Relintai/broken_seals/blob/master/game/scripts/entities/EntityDataGD.gd). \ +And an example ui implementation [here](https://github.com/Relintai/broken_seals/tree/master/game/ui/player/loot_window). + +## XP + +You can set all the xp values for your levels in `ProjectSettings->Ess->xp`. + +Now you can start distributing xp, for whatever you'd like to Entities, using `Entity.xp_adds(value : int)` + +## Examples + +Eventually I'll create a separate repository with a few examples/demos, but for now you can check the game +I've been working on for examples. + +3d: +https://github.com/Relintai/broken_seals.git + +2d turn based: +https://github.com/Relintai/broken_seals_roguelike + +2d: +https://github.com/Relintai/broken_seals_2d.git + +## Compiling + +First make sure that you can compile godot. See the official docs: https://docs.godotengine.org/en/3.x/development/compiling/index.html + +1. Clone the engine if you haven't already: + +If you want Godot 3.x: +```git clone -b 3.x https://github.com/godotengine/godot.git godot``` + +If you want Godot 4.0: +```git clone https://github.com/godotengine/godot.git godot``` + +2. go into the modules folder inside the engine's directory" + +```cd godot``` +```cd modules``` + +3. clone this repository + +```git clone https://github.com/Relintai/entity_spell_system.git entity_spell_system``` + +(the folder needs to be named entity_spell_system!) + +4. Go up one folder + +```cd ..``` + +5. Compile godot. + +For example: + +```scons p=x11 t=release_debug tools=yes``` diff --git a/modules/mesh_data_resource.md b/modules/mesh_data_resource.md new file mode 100644 index 0000000..6a9af3f --- /dev/null +++ b/modules/mesh_data_resource.md @@ -0,0 +1,69 @@ +# Mesh data resource Module + +A c++ Godot engine module, that adds a resource, which contains raw mesh data for merging and collider information. + +The module also comes with importers (gltf, and collada for now), you can import 3d models as MeshDataResources with these. + +## Optional Dependencies + +`https://github.com/Relintai/props`: If present, you also get a prop importer for MeshDataInstances. +`https://github.com/Relintai/mesh_utils`: If present, you get mesh simplification/optimization options at import. + +## Pre-built binaries + +You can grab a pre-built editor binary from the [Broken Seals](https://github.com/Relintai/broken_seals/releases) +repo, should you want to. It contains all my modules. + +## MeshDataResource + +The resource that holds mesh and collider data. + +## MeshDataResourceCollection + +Holds a list of MeshDataResources. + +## MeshDataInstance + +You can easily put MeshDataResources into the scene with these. They are equivalent to MeshInstances, except they work +with MeshDataResources. + +## Importers + +In order to import a 3d model as a MeshDataResource, select the model, go to the import tab, and switch the import type to ` MDR`. Like: + +![Import Tab](screenshots/import.png) + +If you set the import type to single, the importers will convert the first model that they encounter into a MeshDataResource, then save that, +if you set it to multiple, you get a MeshDataResourceCollection as the main resource, and also all encountered models as files separately. + +Since MeshDataResource can hold collider information, these importers can create this for you. There are quite a few options for it: + +![Colliders](screenshots/import_2.png) + +## Building + +1. Get the source code for the engine. + +If you want Godot 3.2: +```git clone -b 3.2 https://github.com/godotengine/godot.git godot``` + +If you want Godot 4.0: +```git clone https://github.com/godotengine/godot.git godot``` + +[last tested commit for 4.0](https://github.com/godotengine/godot/commit/b7e10141197fdd9b0dbc4cfa7890329510d36540) + +2. Go into Godot's modules directory. + +``` +cd ./godot/modules/ +``` + +3. Clone this repository + +``` +git clone https://github.com/Relintai/mesh_data_resource mesh_data_resource +``` + +4. Build Godot. [Tutorial](https://docs.godotengine.org/en/latest/development/compiling/index.html) + + diff --git a/modules/mesh_utils.md b/modules/mesh_utils.md new file mode 100644 index 0000000..25006dd --- /dev/null +++ b/modules/mesh_utils.md @@ -0,0 +1,60 @@ +# Mesh Utils Module + +This is a c++ engine module for the Godot engine, containing my mesh merging utilities. + +It supports both godot 3.2 and 4.0 (master [last tested commit](https://github.com/godotengine/godot/commit/b7e10141197fdd9b0dbc4cfa7890329510d36540)). Note that since 4.0 is still in very early stages I only +check whether it works from time to time. + +# Pre-built binaries + +You can grab a pre-built editor binary from the [Broken Seals](https://github.com/Relintai/broken_seals/releases) +repo, should you want to. It contains all my modules. + +# Optional Dependencies + +[Mesh Data Resource](https://github.com/Relintai/mesh_data_resource): Support for merged meshes, even in gles2. +Adds MeshMerger a few helper methods. + +# MeshUtils Singleton + +Contains generic algorithms that manipulate meshes. + +# Mesh Merger + +Works similarly to SurfaceTool, but it has more utility functions. + +# Fast Quadratic Mesh Simplifier + +A port of https://github.com/Whinarn/UnityMeshSimplifier . +For future reference it's based on e8ff4e8862735197c3308cfe926eeba68e0d2edb. +Porting is mostly done, but it does needs some debugging (it has a crash if smart linking is enabled). + +I might just return to using the original FQMS. As if meshes are merged together using `MeshUtils.merge_mesh_array`, or +`bake_mesh_array_uv` the original algorithm will work fine. Still on the fence about it. + +# Building + +1. Get the source code for the engine. + +If you want Godot 3.2: +```git clone -b 3.2 https://github.com/godotengine/godot.git godot``` + +If you want Godot 4.0: +```git clone https://github.com/godotengine/godot.git godot``` + + +2. Go into Godot's modules directory. + +``` +cd ./godot/modules/ +``` + +3. Clone this repository + +``` +git clone https://github.com/Relintai/mesh_utils mesh_utils +``` + +4. Build Godot. [Tutorial](https://docs.godotengine.org/en/latest/development/compiling/index.html) + + diff --git a/modules/props.md b/modules/props.md new file mode 100644 index 0000000..8efc048 --- /dev/null +++ b/modules/props.md @@ -0,0 +1,95 @@ +# Props Module + +This is a c++ engine module for the Godot Engine. + +It gives you props, and editor utilities to convert scenes to props. + +It supports both godot 3.2 and 4.0 (master [last tested commit](https://github.com/godotengine/godot/commit/b7e10141197fdd9b0dbc4cfa7890329510d36540)). Note that since 4.0 is still in very early stages I only +check whether it works from time to time. + +# Pre-built binaries + +You can grab a pre-built editor binary from the [Broken Seals](https://github.com/Relintai/broken_seals/releases) +repo, should you want to. It contains all my modules. + +# Optional Dependencies + +[Mesh Data Resource](https://github.com/Relintai/mesh_data_resource): Support for merged meshes, even in gles2.\ +[Texture Packer](https://github.com/Relintai/texture_packer): Prop Instance will use this to merge textures. + +# PropData + +Props are basically 3D scenes in a simple format, so other things can easily process them without instancing. + +For example if you create a building from MeshDataInstances, and then convert that scene to a prop, Voxelman +can spawn it, merge it's meshes, and create lods without any scene instancing. + +PropData is the main class you'll use, it's main purpose it to store a list of PropDataEntries. + +# PropDataEntries + +These are the classes that actually store data. + +They contain 4 methods for scene->prop conversion, namely: + +``` +//Whether or not this PropDataEntry can process the given Node. +virtual bool _processor_handles(Node *node); + +//Save the given Node into the given prop_data any way you like, at transform. +virtual void _processor_process(Ref prop_data, Node *node, const Transform &transform); + +//Turn PropDataEntry back into a Node +virtual Node *_processor_get_node_for(const Transform &transform); + +//Whether the system should skip evaluating the children of a processes Node or not. See PropDataScene, or PropDataProp. +virtual bool _processor_evaluate_children(); +``` + +# PropInstances + +PropInstances are not yet finished. + +They will be able to merge meshes, texture etc from a Prop, and also generate lods for it. + +Essentially they will be a more advanced MeshInstance. + +Voxelman implements all of this, just haven't finished porting it yet. + +# PropUtils Singleton + +The PropUtils singleton helps with scene->prop conversion. + +You can register new PropDataEntries as processors, should you need to. + +# Scene conversion + +You can either click the new "To Prop" button on the menubar of the 3D scene for a quick conversion, +or look into Project->Tools. + +# Building + +1. Get the source code for the engine. + +If you want Godot 3.2: +```git clone -b 3.2 https://github.com/godotengine/godot.git godot``` + +If you want Godot 4.0: +```git clone https://github.com/godotengine/godot.git godot``` + + +2. Go into Godot's modules directory. + +``` +cd ./godot/modules/ +``` + +3. Clone this repository + +``` +git clone https://github.com/Relintai/props props +``` + +4. Build Godot. [Tutorial](https://docs.godotengine.org/en/latest/development/compiling/index.html) + + diff --git a/modules/props_2d.md b/modules/props_2d.md new file mode 100644 index 0000000..4e4ba90 --- /dev/null +++ b/modules/props_2d.md @@ -0,0 +1,95 @@ +# Prop2Ds Module + +This is a c++ engine module for the Godot Engine. + +It gives you props, and editor utilities to convert scenes to props. + +It supports both godot 3.2 and 4.0 (master [last tested commit](https://github.com/godotengine/godot/commit/b7e10141197fdd9b0dbc4cfa7890329510d36540)). Note that since 4.0 is still in very early stages I only +check whether it works from time to time. + +# Pre-built binaries + +You can grab a pre-built editor binary from the [Broken Seals](https://github.com/Relintai/broken_seals/releases) +repo, should you want to. It contains all my modules. + +# Optional Dependencies + +[Mesh Data Resource](https://github.com/Relintai/mesh_data_resource): Support for merged meshes, even in gles2.\ +[Texture Packer](https://github.com/Relintai/texture_packer): Prop2D Instance will use this to merge textures. + +# Prop2DData + +Prop2Ds are basically 3D scenes in a simple format, so other things can easily process them without instancing. + +For example if you create a building from MeshDataInstances, and then convert that scene to a prop, Voxelman +can spawn it, merge it's meshes, and create lods without any scene instancing. + +Prop2DData is the main class you'll use, it's main purpose it to store a list of Prop2DDataEntries. + +# Prop2DDataEntries + +These are the classes that actually store data. + +They contain 4 methods for scene->prop conversion, namely: + +``` +//Whether or not this Prop2DDataEntry can process the given Node. +virtual bool _processor_handles(Node *node); + +//Save the given Node into the given prop_data any way you like, at transform. +virtual void _processor_process(Ref prop_data, Node *node, const Transform &transform); + +//Turn Prop2DDataEntry back into a Node +virtual Node *_processor_get_node_for(const Transform &transform); + +//Whether the system should skip evaluating the children of a processes Node or not. See Prop2DDataScene, or Prop2DDataProp2D. +virtual bool _processor_evaluate_children(); +``` + +# Prop2DInstances + +Prop2DInstances are not yet finished. + +They will be able to merge meshes, texture etc from a Prop2D, and also generate lods for it. + +Essentially they will be a more advanced MeshInstance. + +Voxelman implements all of this, just haven't finished porting it yet. + +# Prop2DUtils Singleton + +The Prop2DUtils singleton helps with scene->prop conversion. + +You can register new Prop2DDataEntries as processors, should you need to. + +# Scene conversion + +You can either click the new "To Prop2D" button on the menubar of the 3D scene for a quick conversion, +or look into Project->Tools. + +# Building + +1. Get the source code for the engine. + +If you want Godot 3.2: +```git clone -b 3.2 https://github.com/godotengine/godot.git godot``` + +If you want Godot 4.0: +```git clone https://github.com/godotengine/godot.git godot``` + + +2. Go into Godot's modules directory. + +``` +cd ./godot/modules/ +``` + +3. Clone this repository + +``` +git clone https://github.com/Relintai/props props +``` + +4. Build Godot. [Tutorial](https://docs.godotengine.org/en/latest/development/compiling/index.html) + + diff --git a/modules/rtile_map.md b/modules/rtile_map.md new file mode 100644 index 0000000..d4d8704 --- /dev/null +++ b/modules/rtile_map.md @@ -0,0 +1,25 @@ +# TileMap + +Godot's TileMap but as an engine module, with a few smaller features added. + +The tilemap classes will be prefixed with R, so it compiles cleanly with the built in TileMap class. + +# Building + +1. Get the source code for the engine. + +```git clone -b 3.x https://github.com/godotengine/godot.git godot``` + +2. Go into Godot's modules directory. + +``` +cd ./godot/modules/ +``` + +3. Clone this repository + +``` +git clone https://github.com/Relintai/rtile_map.git rtile_map +``` + +4. Build Godot. [Tutorial](https://docs.godotengine.org/en/latest/development/compiling/index.html) diff --git a/modules/skeleton_editor.md b/modules/skeleton_editor.md new file mode 100644 index 0000000..a791d47 --- /dev/null +++ b/modules/skeleton_editor.md @@ -0,0 +1,28 @@ +# Skeleton Editor + +This is a c++ engine module for the Godot engine that contains a modularized version of TokageItLab's pr's 3.2 version from the godot engine repository, until it gets merged. + +The original pr is here: https://github.com/godotengine/godot/pull/45699 +Tht 3.x version (linked in the pr itself) is here (This is the base for this module): https://github.com/TokageItLab/godot/tree/pose-edit-mode + +I'm developing this for godot 3.x, it will probably work on earlier versions though. 4.0 is not supported. + +# Building + +1. Get the source code for the engine. + +```git clone -b 3.x https://github.com/godotengine/godot.git godot``` + +2. Go into Godot's modules directory. + +``` +cd ./godot/modules/ +``` + +3. Clone this repository + +``` +git clone https://github.com/Relintai/skeleton_editor skeleton_editor +``` + +4. Build Godot. [Tutorial](https://docs.godotengine.org/en/latest/development/compiling/index.html) diff --git a/modules/terraman.md b/modules/terraman.md new file mode 100644 index 0000000..2ada903 --- /dev/null +++ b/modules/terraman.md @@ -0,0 +1,220 @@ +# Terraman + +A terrain engine for godot, focusing more on editor integration, gameplay-related features, and extendability (even from gdscript), without sacrificing too much speed. + +It is a spinoff of [Voxelman](https://github.com/Relintai/voxelman). I started working on it when I realized that not only a full 3d voxel engine is too hard for me to use properly for an rpg (just think about how hard it is to do smooth zone - zone and dungeon transitions with the proper fidelity for an rpg), it's also unnecessary. + +I could have technically implemented all of this into voxelman, as having only have one row of chunks, and then setting chunk height to 1, and creating a mesher that reads isolevel values as a normal height map will achieve the same effect. However as voxelman has lots of features with noises, lights and vertices, adding this on top of that module would have ended up being messy just for this reason alone (and also let's not forget the 3d apis). + +So I ended up creating this. Everything works the same as in voxelman, but the apis have been simplified to make UX a bit better. + +This is an engine module! Which means that you will need to compile it into Godot! [See the compiling section here.](#compiling) + +You can grab pre-built binaries (even editor + export templates) from the [Broken Seals](https://github.com/Relintai/broken_seals/releases) repo. + +## Godot Version Support + +3.2 - Will likely work, probably needs changes by now. (TODO check.)\ +3.3 - Will more likely work, might need smaller changes by now. (TODO check.)\ +3.4 - Should work without any issues. (TODO check.)\ +3.x - Works.\ +4.0 - Have been fixing support from time to time. Currently it won't build. Mostly done with the fix though. + +## Optional Dependencies + +`https://github.com/Relintai/texture_packer`: You get access to [TerraLibraryMerger](#voxellibrarymerger) and [TerraLibraryMergerPCM](#voxellibrarymergerpcm). \ +`https://github.com/Relintai/mesh_data_resource`: You get access to a bunch of properties, and methods that can manipulate meshes.\ +`https://github.com/Relintai/props`: You get access to a bunch of properties, and methods that can manipulate, and use props.\ +`https://github.com/Relintai/mesh_utils`: Lets you use lod levels higher than 4 by default. + +## Usage + +First create a scene, and add a TerraWorldBlocky node into it. Create a TerraLibrary, and assign it to the Library property. +Also, add a TerraSurface into your library. + +Tick the editable property, deselect, then select the world again, and click the insert button at the top toolbar, or press B to insert a +voxel at the inspector's camera's location. + +Select the add button, and now you can just add voxels with the mouse, by clicking on the newly added voxel. + +## TerraLibrary + +This class stores the materials, and the TerraSurfaces. + +Lod levels will automatically try to use materials of their own index.\ +For example lod level 1 will try to use material index 1, lod level 2 will try to use material index 2, etc.\ +If a material index is not available, they'll use the highest that is.\ +For example lod level 5 will try to get material index 5, but if you only have 3 materials it will use the 3rd. + +### TerraLibrarySimple + +The simplest library, just assign a material with a texture, and using the atlas_rows and atlas_culomns properties to tell the system +how the UVs should be divided. + +This is the basic Minecraft-style lib rary. Use this if you just have one texture atlas. + +### TerraLibraryMerger + +You will only have this if your godot also contains https://github.com/Relintai/texture_packer + +You can assign any texture to your surfaces with this, and it will merge them together. + +### TerraLibraryMergerPCM + +(PCM = Per Chunk Material) + +You will only have this if your godot also contains https://github.com/Relintai/texture_packer + +You can assign any texture to your surfaces with this, and it will merge them together, but it will do it for every required chunk/voxel combination. + +For example if you have a chunk with voxel Grass, and voxel Stone used in it, this library will create a material with a merged texture for Stone and Grass. +If you have an anouther chunk which only has Grass and Stone in it, this material will be reused. +And if you have a third chunk which only has a Grass voxel used in it, it will get a new merged material and texture only containing Grass voxel. + +## Worlds + +The 2 base classes. These won't do meshing on their own: + +TerraWorld: Basic world, does not do anything until you implemnent the required virtual methods!\ +TerraWorldDefault: This adds threading, and LoD storage support to TerraWorld. Will not create meshes for you! + +### TerraWorldBlocky + +It generated UV mapped standard simple terrain meshes. +The default algorithm can also generate normal lods. + +### Level generation + +Assign a TerraManLevelGenerator to the `World`'s `Level Generator` property. + +You can write your own algorithm by implementing the ``` void _generate_chunk(chunk: TerraChunk) virtual ``` method. + +`TerraManLevelGeneratorFlat` is also available, it will generate a floor for you, if you use it. + +## TerraJobs + +Producing just a terrain mesh for a chunk is not that hard by itself. However when you start adding layers/features +like lod generation, collision meshes (especially since manipulating the physics server is not threadsafe), +vertex lights, props, snapping props, props with vertex lights, etc +chunk mesh generation can quickly become a serious mess. + +TerraJobs are meant to solve the issue with less complexity. + +They also provide a way to easily modularize mesh and lod generation. + +### TerraJob + +Base class for jobs. + +This is inherited from `ThreadPoolJob`. + +A job has a reference to it's owner chunk. + +If you implement your own jobs, when your job finishes call `next_job()`. + +### TerraLightJob + +This is the job that will generate vertex light based ao, random ao, and will bake your `TerraLight`s. + +### TerraTerrainJob + +This will generate your terrain collider and mesh (with lods) for you, using the meshers that you add into it. + +Your lod setup is easily customizable with [TerraMesherJobSteps](https://github.com/Relintai/terraman/blob/master/world/jobs/voxel_mesher_job_step.h). The setup happens in your selected world's `_create_chunk` method. + +### TerraPropJob + +This will generate your prop meshes (with lods). + +Also supports [TerraMesherJobSteps](https://github.com/Relintai/terraman/blob/master/world/jobs/voxel_mesher_job_step.h). + +### Internal workings + +#### TerraWorld + +Whenever you want to spawn a chunk your World will create it using the ``` TerraChunk _create_chunk(x: int, y: int, z: int, chunk: TerraChunk) virtual ``` method. + +Since properly initializing a chunk usually takes quite a few steps that you probably don't want to repeat everywhere the `chunk` +parameter was added. This means you can just call the super `_create_chunk` methods, and you won't need to worry about your chunk +getting overridden. Like: + +Note that `_create_chunk` is also responsible for initializing chunks if you have them stored inside a scene. +This is done by `setup_chunk(shunk)` in `TerraWorld`. + +``` + func _create_chunk(x : int, y : int, z : int, chunk : TerraChunk) -> TerraChunk: + if !chunk: + chunk = MyChunk.new() + + # We need to check whether or not we need to initialize jobs + if chunk.job_get_count() == 0: + # Setup a blocky (minecratf like) mesher job + var tj : TerraTerrainJob = TerraTerrainJob.new() + + var s : TerraMesherJobStep = TerraMesherJobStep.new() + s.job_type = TerraMesherJobStep.TYPE_NORMAL + tj.add_jobs_step(s) + + tj.add_mesher(TerraMesherBlocky.new()) + tj.add_liquid_mesher(TerraMesherLiquidBlocky.new()) + + chunk.job_add(tj); + + #setup your chunk here + + return ._create_chunk(x, y, z, chunk) +``` + +You can look at the world implementations for more examples: [TerraWorldBlocky](https://github.com/Relintai/terraman/blob/master/world/blocky/voxel_world_blocky.cpp). + +#### TerraChunk + +Stores terrain data, prop data. And mesh data (TerraChunkDefault), and the mesh generation jobs. + +When it starts building meshes it will start submitting jobs to thread_pool (if present) one by one. + +#### TerraMesher + +If you want to implement your own meshing algorithm you can do so by overriding ``` void _add_chunk(chunk: TerraChunk) virtual ```. + +TerraMesher works similarly to SurfaceTool, so first you need to set colors, uvs, etc and then call add_vertex. +They won't get reset, so for example if you want all your vertices to have a certain color, you can get away with setting it only once. + +## Compiling + +First make sure that you can compile godot. See the official docs: https://docs.godotengine.org/en/3.x/development/compiling/index.html + +1. Clone the engine if you haven't already: + +If you want Godot 3.x: +```git clone -b 3.x https://github.com/godotengine/godot.git godot``` + +If you want Godot 4.0: +```git clone https://github.com/godotengine/godot.git godot``` + + +2. go into the modules folder inside the engine's directory: + +```cd godot``` \ +```cd modules``` + +3. clone this repository + +```git clone https://github.com/Relintai/terraman.git terraman``` + +(the folder needs to be named terraman!) + +4. If you want the optional dependencies run these commands as well: + +```git clone https://github.com/Relintai/texture_packer.git texture_packer``` \ +```git clone https://github.com/Relintai/mesh_data_resource.git mesh_data_resource``` + +5. Go up one folder + +```cd ..``` + +6. Compile godot. + +For example: + +```scons p=x11 t=release_debug tools=yes``` diff --git a/modules/terraman_2d.md b/modules/terraman_2d.md new file mode 100644 index 0000000..ceca0e8 --- /dev/null +++ b/modules/terraman_2d.md @@ -0,0 +1,222 @@ +# Terraman + +A terrain engine for godot, focusing more on editor integration, gameplay-related features, and extendability (even from gdscript), without sacrificing too much speed. + +It is a spinoff of [Voxelman](https://github.com/Relintai/voxelman). I started working on it when I realized that not only a full 3d voxel engine is too hard for me to use properly for an rpg (just think about how hard it is to do smooth zone - zone and dungeon transitions with the proper fidelity for an rpg), it's also unnecessary. + +I could have technically implemented all of this into voxelman, as having only have one row of chunks, and then setting chunk height to 1, and creating a mesher that reads isolevel values as a normal height map will achieve the same effect. However as voxelman has lots of features with noises, lights and vertices, adding this on top of that module would have ended up being messy just for this reason alone (and also let's not forget the 3d apis). + +So I ended up creating this. Everything works the same as in voxelman, but the apis have been simplified to make UX a bit better. + +This is an engine module! Which means that you will need to compile it into Godot! [See the compiling section here.](#compiling) + +You can grab pre-built binaries (even editor + export templates) from the [Broken Seals](https://github.com/Relintai/broken_seals/releases) repo. + +## Godot Version Support + +3.2 - Will likely work, probably needs changes by now. (TODO check.)\ +3.3 - Will more likely work, might need smaller changes by now. (TODO check.)\ +3.4 - Should work without any issues. (TODO check.)\ +3.x - Works.\ +4.0 - Have been fixing support from time to time. Currently it won't build. Mostly done with the fix though. + +## Optional Dependencies + +`https://github.com/Relintai/thread_pool`: Threaded chunk generation. Without this terraman is single threaded! \ +`https://github.com/Relintai/texture_packer`: You get access to [TerraLibraryMerger](#voxellibrarymerger) and [TerraLibraryMergerPCM](#voxellibrarymergerpcm). \ +`https://github.com/Relintai/mesh_data_resource`: You get access to a bunch of properties, and methods that can manipulate meshes.\ +`https://github.com/Relintai/props`: You get access to a bunch of properties, and methods that can manipulate, and use props.\ +`https://github.com/Relintai/mesh_utils`: Lets you use lod levels higher than 4 by default. + +## Usage + +First create a scene, and add a TerraWorldBlocky node into it. Create a TerraLibrary, and assign it to the Library property. +Also, add a TerraSurface into your library. + +Tick the editable property, deselect, then select the world again, and click the insert button at the top toolbar, or press B to insert a +voxel at the inspector's camera's location. + +Select the add button, and now you can just add voxels with the mouse, by clicking on the newly added voxel. + +## TerraLibrary + +This class stores the materials, and the TerraSurfaces. + +Lod levels will automatically try to use materials of their own index.\ +For example lod level 1 will try to use material index 1, lod level 2 will try to use material index 2, etc.\ +If a material index is not available, they'll use the highest that is.\ +For example lod level 5 will try to get material index 5, but if you only have 3 materials it will use the 3rd. + +### TerraLibrarySimple + +The simplest library, just assign a material with a texture, and using the atlas_rows and atlas_culomns properties to tell the system +how the UVs should be divided. + +This is the basic Minecraft-style lib rary. Use this if you just have one texture atlas. + +### TerraLibraryMerger + +You will only have this if your godot also contains https://github.com/Relintai/texture_packer + +You can assign any texture to your surfaces with this, and it will merge them together. + +### TerraLibraryMergerPCM + +(PCM = Per Chunk Material) + +You will only have this if your godot also contains https://github.com/Relintai/texture_packer + +You can assign any texture to your surfaces with this, and it will merge them together, but it will do it for every required chunk/voxel combination. + +For example if you have a chunk with voxel Grass, and voxel Stone used in it, this library will create a material with a merged texture for Stone and Grass. +If you have an anouther chunk which only has Grass and Stone in it, this material will be reused. +And if you have a third chunk which only has a Grass voxel used in it, it will get a new merged material and texture only containing Grass voxel. + +## Worlds + +The 2 base classes. These won't do meshing on their own: + +TerraWorld: Basic world, does not do anything until you implemnent the required virtual methods!\ +TerraWorldDefault: This adds threading, and LoD storage support to TerraWorld. Will not create meshes for you! + +### TerraWorldBlocky + +It generated UV mapped standard simple terrain meshes. +The default algorithm can also generate normal lods. + +### Level generation + +Assign a TerraManLevelGenerator to the `World`'s `Level Generator` property. + +You can write your own algorithm by implementing the ``` void _generate_chunk(chunk: TerraChunk) virtual ``` method. + +`TerraManLevelGeneratorFlat` is also available, it will generate a floor for you, if you use it. + +## TerraJobs + +Producing just a terrain mesh for a chunk is not that hard by itself. However when you start adding layers/features +like lod generation, collision meshes (especially since manipulating the physics server is not threadsafe), +vertex lights, props, snapping props, props with vertex lights, etc +chunk mesh generation can quickly become a serious mess. + +TerraJobs are meant to solve the issue with less complexity. + +They also provide a way to easily modularize mesh and lod generation. + +### TerraJob + +Base class for jobs. + +If the [thread pool](https://github.com/Relintai/thread_pool) module is present, this is inherited from `ThreadPoolJob`, +else it implements the same api as `ThreadPoolJob`, but it's not going to use threading. + +A job has a reference to it's owner chunk. + +If you implement your own jobs, when your job finishes call `next_job()`. + +### TerraLightJob + +This is the job that will generate vertex light based ao, random ao, and will bake your `TerraLight`s. + +### TerraTerrain2DJob + +This will generate your terrain collider and mesh (with lods) for you, using the meshers that you add into it. + +Your lod setup is easily customizable with [TerraMesherJobSteps](https://github.com/Relintai/terraman/blob/master/world/jobs/voxel_mesher_job_step.h). The setup happens in your selected world's `_create_chunk` method. + +### TerraProp2DJob + +This will generate your prop meshes (with lods). + +Also supports [TerraMesherJobSteps](https://github.com/Relintai/terraman/blob/master/world/jobs/voxel_mesher_job_step.h). + +### Internal workings + +#### TerraWorld + +Whenever you want to spawn a chunk your World will create it using the ``` TerraChunk _create_chunk(x: int, y: int, z: int, chunk: TerraChunk) virtual ``` method. + +Since properly initializing a chunk usually takes quite a few steps that you probably don't want to repeat everywhere the `chunk` +parameter was added. This means you can just call the super `_create_chunk` methods, and you won't need to worry about your chunk +getting overridden. Like: + +Note that `_create_chunk` is also responsible for initializing chunks if you have them stored inside a scene. +This is done by `setup_chunk(shunk)` in `TerraWorld`. + +``` + func _create_chunk(x : int, y : int, z : int, chunk : TerraChunk) -> TerraChunk: + if !chunk: + chunk = MyChunk.new() + + # We need to check whether or not we need to initialize jobs + if chunk.job_get_count() == 0: + # Setup a blocky (minecratf like) mesher job + var tj : TerraTerrain2DJob = TerraTerrain2DJob.new() + + var s : TerraMesherJobStep = TerraMesherJobStep.new() + s.job_type = TerraMesherJobStep.TYPE_NORMAL + tj.add_jobs_step(s) + + tj.add_mesher(TerraMesherBlocky.new()) + tj.add_liquid_mesher(TerraMesherLiquidBlocky.new()) + + chunk.job_add(tj); + + #setup your chunk here + + return ._create_chunk(x, y, z, chunk) +``` + +You can look at the world implementations for more examples: [TerraWorldBlocky](https://github.com/Relintai/terraman/blob/master/world/blocky/voxel_world_blocky.cpp). + +#### TerraChunk + +Stores terrain data, prop data. And mesh data (TerraChunkDefault), and the mesh generation jobs. + +When it starts building meshes it will start submitting jobs to thread_pool one by one. + +#### TerraMesher + +If you want to implement your own meshing algorithm you can do so by overriding ``` void _add_chunk(chunk: TerraChunk) virtual ```. + +TerraMesher works similarly to SurfaceTool, so first you need to set colors, uvs, etc and then call add_vertex. +They won't get reset, so for example if you want all your vertices to have a certain color, you can get away with setting it only once. + +## Compiling + +First make sure that you can compile godot. See the official docs: https://docs.godotengine.org/en/3.x/development/compiling/index.html + +1. Clone the engine if you haven't already: + +If you want Godot 3.x: +```git clone -b 3.x https://github.com/godotengine/godot.git godot``` + +If you want Godot 4.0: +```git clone https://github.com/godotengine/godot.git godot``` + + +2. go into the modules folder inside the engine's directory: + +```cd godot``` \ +```cd modules``` + +3. clone this repository + +```git clone https://github.com/Relintai/terraman.git terraman``` + +(the folder needs to be named terraman!) + +4. If you want the optional dependencies run these commands as well: + +```git clone https://github.com/Relintai/texture_packer.git texture_packer``` \ +```git clone https://github.com/Relintai/mesh_data_resource.git mesh_data_resource``` + +5. Go up one folder + +```cd ..``` + +6. Compile godot. + +For example: + +```scons p=x11 t=release_debug tools=yes``` diff --git a/modules/texture_packer.md b/modules/texture_packer.md new file mode 100644 index 0000000..68b84be --- /dev/null +++ b/modules/texture_packer.md @@ -0,0 +1,105 @@ +# Texture Packer for the Godot Engine + +This is a texture packer engine module, for the Godot Engine. + +It can create texture atlases for you even in the running game. + +It uses the legacy version of [rectpack2D](https://github.com/TeamHypersomnia/rectpack2D/tree/legacy) + +It should work on all platforms. + +It supports both godot 3.2 and 4.0 (master [last tested commit](https://github.com/godotengine/godot/commit/b7e10141197fdd9b0dbc4cfa7890329510d36540)). Note that since 4.0 is still in very early stages I only +check whether it works from time to time. + +# Pre-built binaries + +You can grab a pre-built editor binary from the [Broken Seals](https://github.com/Relintai/broken_seals/releases) +repo, should you want to. It contains all my modules. + +# Building + +1. Get the source code for the engine. + +If you want Godot 3.2: +```git clone -b 3.2 https://github.com/godotengine/godot.git godot``` + +If you want Godot 4.0: +```git clone https://github.com/godotengine/godot.git godot``` + + +2. Go into Godot's modules directory. + +``` +cd ./godot/modules/ +``` + +3. Clone this repository + +``` +git clone https://github.com/Relintai/texture_packer texture_packer +``` + +4. Build Godot. [Tutorial](https://docs.godotengine.org/en/latest/development/compiling/index.html) + +# Features and Usage + +## TexturePacker + +This is the class that can merge textures. Add every texture you want into it using it's API (add_texture()), and then call merge(). + +add_texture() will return an AtlasTexture, this is the texture you want to use in your classes. It is immediately usable, it will just contain the original texture. Calling merge() will change it, to point to the new (merged) texture. + +Supports filters, custom background color, margins. + +### The keep_original_atlases option: + +If you set this to true, and then add AtlasTextures, TexturePacker will change these ones (the ones you actually added) +after the bake. + +You can use this to bake gui textures together, without changing the resources everywhere at runtime. +Think of rpgs, when you have a huge number of potential icons that the player can put on his or her actionbars. +You can take look at Tales of Maj'Eyal or pretty much every actually complex MMORPGs as an example. + +Note: Doing something like this in only recommended, if you can't pre-make the atlases (or it's really unfeasible), you are better off +making the atlases yourself during development. + +## TextureMerger + +A Node that can bake textures for you. It uses TexturePacker internally. + +It has an exposed Array, so you can assign textures to it in the editor. + +## PackerImageResource + +This is a simple Texture, which just contains an imported Image. It has no logic for drawing. + +Useful for textures you only need for baking, as this class will not register it's data into the RenderingServer. + +The module also contains an editor plugin which can import textures as `PackerImageResource` Resource. + +To access it, click on a texture, switch to the import tab, and in the "Import As" Dropdown, select "Packer Image Recource". + +## TextureLayerMerger + +This class can merge together textures as layers. Useful for example to merge together (and color) skin, and clothes for a character. + +It can handle both AtlasTextures and normal Textures. + +Add the layers from bottom to top with the add_texture() method, when you added everything call merge(). + +You can set the resulting image's size with the `width`, and `height` properties. If you leave them at 0, they will +change to the first added texture's size. + +add_texture looks like this: + +``` +void add_texture(Ref p_texture, Color p_color = Color(1, 1, 1, 1), Vector2 p_position = Vector2(), Rect2 p_rect = Rect2()); +``` + +The color parameter will color the given texture on merge(). +With the position parameter you can offset your texture (in the resulted texture), and with the rect parameter, you can crop it. + +There are setters to manipulate the added data later. + +After the merge, you can either use `get_result_as_texture()` (it creates an ImageTexture on the fly), or the `data` property to +grab the resulting Image. diff --git a/modules/thread_pool.md b/modules/thread_pool.md new file mode 100644 index 0000000..2e28b87 --- /dev/null +++ b/modules/thread_pool.md @@ -0,0 +1,144 @@ +# Thread pool module + +A c++ Godot engine module, that will help you with threading. + +It can also work if threads are not available (like on the javascript backend), in this case it runs jobs on the +main thread. Jobs themselves can also distribute their work onto multiple frames, and you can set how much time +is allocated per frame. + +You can access it's setting from the `Project->Project Settings...` menu, in the `ThreadPool` category. + +# Pre-built binaries + +You can grab a pre-built editor binary from the [Broken Seals](https://github.com/Relintai/broken_seals/releases) +repo, should you want to. It contains all my modules. + +# ThreadPoolJob + +Contains a job that can run on different threads. + +A job is only considered finished, if you set the 'complete' property to 'true'. If multiple threads are available, +the system will not check for this though, because there is no need. + +If you want to support environments that doesn't have threading, you can use: + +``` +bool should_do(const bool just_check = false); +bool should_return(); +``` + +For example: + +``` +func _execute(): + # On the first run this will return true, on subsequent runs it will return false + if should_do(): + thing1() + + # if you ran out the allocated timeframe in a frame, this will return true + if should_return(): + return + + if should_do(): + thing2() + + if should_return(): + return + + thing3() + + complete = true + +``` + +`should_do`'s optional parameter will let you just query the system, whether you finished a step, without +incrementing internal couters. This is useful for example to distribute algorithms onto multiple frames. + +For example: + +``` +func _execute(): + if should_do(true): + while current <= elements.size(): + #do heavy calculations + + current += 1 + + if should_return(): + return + + #The heavy calculation finished, increment counters + should_do() + + if should_return(): + return + + if should_do(): + thing2() + + if should_return(): + return + + thing3() + + complete = true + +``` + +This class will need little tweaks, hopefully I can get to is soon. + +# ThreadPoolExecuteJob + +This will let you run a method uin an another thread, without creating your own jobs. + +Use it through the ThreadPool Singleton. Like: + +``` +ThreadPool.create_execute_job(self, "method", arg1, arg2, ...) + +#or +ThreadPool.create_execute_job_simple(self, "method") +``` + +This class will need little tweaks, hopefully I can get to is soon. + +# ThreadPool singleton + +The ThreadPool singleton handles jobs. + +If you have a job, submit it using `add_job`: + +``` +MyJob job = MyJob.new() +ThreadPool.add_job(job) +``` + +It's api is still a bit messy, it will be cleaned up (hopefully very soon). + +# Building + +1. Get the source code for the engine. + +If you want Godot 3.2: +```git clone -b 3.2 https://github.com/godotengine/godot.git godot``` + +If you want Godot 4.0: +```git clone https://github.com/godotengine/godot.git godot``` + +[last tested commit](https://github.com/godotengine/godot/commit/b7e10141197fdd9b0dbc4cfa7890329510d36540) + +2. Go into Godot's modules directory. + +``` +cd ./godot/modules/ +``` + +3. Clone this repository + +``` +git clone https://github.com/Relintai/thread_pool thread_pool +``` + +4. Build Godot. [Tutorial](https://docs.godotengine.org/en/latest/development/compiling/index.html) + + diff --git a/modules/ui_extensions.md b/modules/ui_extensions.md new file mode 100644 index 0000000..809fde2 --- /dev/null +++ b/modules/ui_extensions.md @@ -0,0 +1,78 @@ +# UI Extensions + +This is a c++ engine module for the Godot engine, containing smaller utilities. + +It supports both godot 3.2 and 4.0 (master [last tested commit](https://github.com/godotengine/godot/commit/b7e10141197fdd9b0dbc4cfa7890329510d36540)). Note that since 4.0 is still in very early stages I only +check whether it works from time to time. + +# Pre-built binaries + +You can grab a pre-built editor binary from the [Broken Seals](https://github.com/Relintai/broken_seals/releases) +repo, should you want to. It contains all my modules. + +# TouchButton + +A `Control` based button, that handles multitouch properly. + +# BSInputEventKey + +An `inputEventKey` implementation, that matches actions exactly. + +For example with the default godot implementation if you have an action that gets triggered +with the key `E` then `Ctrl-E` will also trigger it. + +This has the side effect, that if you bind an action to `E`, and an another one to `Ctrl-E`, +then hitting `Ctrl-E` will trigger both. + +This implementation changes that behaviour. + +However, you do need to replace normal input events at startup like this: + +``` +func _ready(): + var actions : Array = InputMap.get_actions() + + for action in actions: + var acts : Array = InputMap.get_action_list(action) + + for i in range(len(acts)): + var a = acts[i] + if a is InputEventKey: + var nie : BSInputEventKey = BSInputEventKey.new() + nie.from_input_event_key(a as InputEventKey) + acts[i] = nie + + InputMap.action_erase_event(action, a) + InputMap.action_add_event(action, nie) + +``` + +I recommend putting this code into a singleton. + +# Building + +1. Get the source code for the engine. + +If you want Godot 3.2: +```git clone -b 3.2 https://github.com/godotengine/godot.git godot``` + +If you want Godot 4.0: +```git clone https://github.com/godotengine/godot.git godot``` + + +2. Go into Godot's modules directory. + +``` +cd ./godot/modules/ +``` + +3. Clone this repository + +``` +git clone https://github.com/Relintai/ui_extensions ui_extensions +``` + +4. Build Godot. [Tutorial](https://docs.godotengine.org/en/latest/development/compiling/index.html) + + + diff --git a/modules/voxelman.md b/modules/voxelman.md new file mode 100644 index 0000000..92ada63 --- /dev/null +++ b/modules/voxelman.md @@ -0,0 +1,227 @@ +# Voxelman + +A voxel engine for godot, focusing more on editor integration, gameplay-related features, and extendability (even from gdscript), without sacrificing too much speed. + +This is an engine module! Which means that you will need to compile it into Godot! [See the compiling section here.](#compiling) + +You can find a demonstration project (with pre-built binaries) here: https://github.com/Relintai/the_tower + +## Godot Version Support + +I'm currently mostly using [Terraman](https://github.com/Relintai/terraman) instead of this, so it might get temporarily a bit behind.\ +If compile breaks, and I don't notice please report. + +3.2 - Will likely work, probably needs changes by now. (TODO check.)\ +3.3 - Will more likely work, might need smaller changes by now. (TODO check.)\ +3.4 - Should work without any issues. (TODO check.)\ +3.x - Works. [last tested commit](6ea58db2d849d9ca0ccee5bc6a6d2b919d404bc1)\ +4.0 - Have been fixing support from time to time. Currently it won't build. Mostly done with the fix though. + +## Optional Dependencies + +`https://github.com/Relintai/texture_packer`: You get access to [VoxelLibraryMerger](#voxellibrarymerger) and [VoxelLibraryMergerPCM](#voxellibrarymergerpcm). \ +`https://github.com/Relintai/mesh_data_resource`: You get access to a bunch of properties, and methods that can manipulate meshes.\ +`https://github.com/Relintai/props`: You get access to a bunch of properties, and methods that can manipulate, and use props.\ +`https://github.com/Relintai/mesh_utils`: Lets you use lod levels higher than 4 by default. + +## Usage + +First create a scene, and add a VoxelWorldBlocky / VoxelWorldMarchingCubes node into it. Create a VoxelLibrary, and assign it to the Library property. +Also, add a VoxelSurface into your library. + +Tick the editable property, deselect, then select the world again, and click the insert button at the top toolbar, or press B to insert a +voxel at the inspector's camera's location. + +Select the add button, and now you can just add voxels with the mouse, by clicking on the newly added voxel. + +## VoxelLibrary + +This class stores the materials, and the VoxelSurfaces. + +Lod levels will automatically try to use materials of their own index.\ +For example lod level 1 will try to use material index 1, lod level 2 will try to use material index 2, etc.\ +If a material index is not available, they'll use the highest that is.\ +For example lod level 5 will try to get material index 5, but if you only have 3 materials it will use the 3rd. + +### VoxelLibrarySimple + +The simplest library, just assign a material with a texture, and using the atlas_rows and atlas_culomns properties to tell the system +how the UVs should be divided. + +This is the basic Minecraft-style lib rary. Use this if you just have one texture atlas. + +### VoxelLibraryMerger + +You will only have this if your godot also contains https://github.com/Relintai/texture_packer + +You can assign any texture to your surfaces with this, and it will merge them together. + +### VoxelLibraryMergerPCM + +(PCM = Per Chunk Material) + +You will only have this if your godot also contains https://github.com/Relintai/texture_packer + +You can assign any texture to your surfaces with this, and it will merge them together, but it will do it for every required chunk/voxel combination. + +For example if you have a chunk with voxel Grass, and voxel Stone used in it, this library will create a material with a merged texture for Stone and Grass. +If you have an anouther chunk which only has Grass and Stone in it, this material will be reused. +And if you have a third chunk which only has a Grass voxel used in it, it will get a new merged material and texture only containing Grass voxel. + +## Worlds + +The 2 base classes. These won't do meshing on their own: + +VoxelWorld: Basic world, does not do anything until you implemnent the required virtual methods!\ +VoxelWorldDefault: This adds threading, and LoD storage support to VoxelWorld. Will not create meshes for you! + +### VoxelWorldBlocky + +The most basic world. It is the Minecraft-style world. + +### VoxelWorldMarchingCubes + +A marching cubes based Voxel World. Actually it uses a modified version of the Transvoxel tables, because it is UV mapped. + +### VoxelWorldCubic + +This is my own meshing algorithm, it's basically a Minecraft style mesher that can take isolevel into account. + +It's kind of a pain to use, it might get removed. + +### Level generation + +Assign a VoxelManLevelGenerator to the `World`'s `Level Generator` property. + +You can write your own algorithm by implementing the ``` void _generate_chunk(chunk: VoxelChunk) virtual ``` method. + +`VoxelManLevelGeneratorFlat` is also available, it will generate a floor for you, if you use it. + +## VoxelJobs + +Producing just a terrain mesh for a chunk is not that hard by itself. However when you start adding layers/features +like lod generation, collision meshes (especially since manipulating the physics server is not threadsafe), +vertex lights, props, snapping props, props with vertex lights, etc +chunk mesh generation can quickly become a serious mess. + +VoxelJobs are meant to solve the issue with less complexity. + +They also provide a way to easily modularize mesh and lod generation. + +### VoxelJob + +Base class for jobs. + +If the [thread pool](https://github.com/Relintai/thread_pool) module is present, this is inherited from `ThreadPoolJob`, +else it implements the same api as `ThreadPoolJob`, but it's not going to use threading. + +A job has a reference to it's owner chunk. + +If you implement your own jobs, when your job finishes call `next_job()`. + +### VoxelLightJob + +This is the job that will generate vertex light based ao, random ao, and will bake your `VoxelLight`s. + +### VoxelTerrainJob + +This will generate your terrain collider and mesh (with lods) for you, using the meshers that you add into it. + +Your lod setup is easily customizable with [VoxelMesherJobSteps](https://github.com/Relintai/voxelman/blob/master/world/jobs/voxel_mesher_job_step.h). The setup happens in your selected world's `_create_chunk` method. + +### VoxelPropJob + +This will generate your prop meshes (with lods). + +Also supports [VoxelMesherJobSteps](https://github.com/Relintai/voxelman/blob/master/world/jobs/voxel_mesher_job_step.h). + +### Internal workings + +#### VoxelWorld + +Whenever you want to spawn a chunk your World will create it using the ``` VoxelChunk _create_chunk(x: int, y: int, z: int, chunk: VoxelChunk) virtual ``` method. + +Since properly initializing a chunk usually takes quite a few steps that you probably don't want to repeat everywhere the `chunk` +parameter was added. This means you can just call the super `_create_chunk` methods, and you won't need to worry about your chunk +getting overridden. Like: + +Note that `_create_chunk` is also responsible for initializing chunks if you have them stored inside a scene. +This is done by `setup_chunk(shunk)` in `VoxelWorld`. + +``` + func _create_chunk(x : int, y : int, z : int, chunk : VoxelChunk) -> VoxelChunk: + if !chunk: + chunk = MyChunk.new() + + # We need to check whether or not we need to initialize jobs + if chunk.job_get_count() == 0: + # Setup a blocky (minecratf like) mesher job + var tj : VoxelTerrainJob = VoxelTerrainJob.new() + + var s : VoxelMesherJobStep = VoxelMesherJobStep.new() + s.job_type = VoxelMesherJobStep.TYPE_NORMAL + tj.add_jobs_step(s) + + tj.add_mesher(VoxelMesherBlocky.new()) + tj.add_liquid_mesher(VoxelMesherLiquidBlocky.new()) + + chunk.job_add(tj); + + #setup your chunk here + + return ._create_chunk(x, y, z, chunk) +``` + +You can look at the world implementations for more examples: [VoxelWorldBlocky](https://github.com/Relintai/voxelman/blob/master/world/blocky/voxel_world_blocky.cpp), [VoxelWorldMarchingCubes](https://github.com/Relintai/voxelman/blob/master/world/marching_cubes/voxel_world_marching_cubes.cpp). + +#### VoxelChunk + +Stores terrain data, prop data. And mesh data (VoxelChunkDefault), and the mesh generation jobs. + +When it starts building meshes it will start submitting jobs to thread_pool one by one. + +#### VoxelMesher + +If you want to implement your own meshing algorithm you can do so by overriding ``` void _add_chunk(chunk: VoxelChunk) virtual ```. + +VoxelMesher works similarly to SurfaceTool, so first you need to set colors, uvs, etc and then call add_vertex. +They won't get reset, so for example if you want all your vertices to have a certain color, you can get away with setting it only once. + +## Compiling + +First make sure that you can compile godot. See the official docs: https://docs.godotengine.org/en/3.x/development/compiling/index.html + +1. Clone the engine if you haven't already: + +If you want Godot 3.x: +```git clone -b 3.x https://github.com/godotengine/godot.git godot``` + +If you want Godot 4.0: +```git clone https://github.com/godotengine/godot.git godot``` + + +2. go into the modules folder inside the engine's directory: + +```cd godot``` \ +```cd modules``` + +3. clone this repository + +```git clone https://github.com/Relintai/voxelman.git voxelman``` + +(the folder needs to be named voxelman!) + +4. If you want the optional dependencies run these commands as well: + +```git clone https://github.com/Relintai/texture_packer.git texture_packer``` \ +```git clone https://github.com/Relintai/mesh_data_resource.git mesh_data_resource``` + +5. Go up one folder + +```cd ..``` + +6. Compile godot. + +For example: + +```scons p=x11 t=release_debug tools=yes```