Author: | Ruslan Mustakov |
---|---|
Version: | 0.5.1 |
GitHub: | https://github.com/pragmagic/godot-nim |
godot-nim library allows to create games on Godot Engine with Nim programming language. Nim is a statically typed language with an elegant Python-like syntax that compiles to native code. It is garbage-collected, but its GC supports real-time mode which this library makes use of. It means the GC will never run during game frames and will use fixed amount of frame idle time to collect garbage. This leads to no stalls and close to zero compromise on performance comparing to native languages with manual memory management.
If you are not familiar with Nim yet, it is recommended to go through the official tutorial.
VSCode is the recommended editor for working with Nim code. It is cross-platform and has the excellent nim plugin that supports most of the features you would expect from an IDE. It also has godot-tools plugin which adds features for editing GDScript and Godot resource files.
Getting Started
Building Godot
The library requires a not yet released Godot version 3.0, which you can build yourself by running the commands below (requires Git, Python 2.7, SCons):
git clone https://github.com/godotengine/godot.git cd godot scons platform=<your_platform>
where <your_platform> can be windows, osx, x11. After build is finished, Godot binaries will be under the bin folder. More details about compiling Godot can be found in Godot documentation.
Building Nim
The library requires a not yet released Nim version 0.17.1, which you can build yourself by following instructions in the Nim repository. Make sure to also run ./koch tools -d:release after the steps described there to build nimble (package manager) and nimsuggest (IDE helper tool, used by VSCode Nim plugin)
Creating Project
The fastest way to set up a Godot-Nim project is to use an existing stub:
git clone --depth=1 https://github.com/pragmagic/godot-nim-stub.git myproject
(you can then delete the .git directory within to untie the project from the stub repository)
The stub contains the necessary build configuration to compile your code for desktop and mobile platforms, as well as a couple of very simple scenes to help you get started. Consult the stub's README for information about compiling the project.
Adding Nim to Existing Project
If you would like to use Nim in an existing project:
- Copy nakefile.nim file and src directory from the stub described in the previous section above your Godot project folder. Adjust paths in build scripts (nakefile.nim, src/stub.nimble) according to your own project structure.
- Copy project/nimlib.tres to your Godot project folder. It is a GDNative library resource that contains paths to dynamic libraries compiled by Nim.
Next Steps
Once you are familiarized with the build process (it's as simple as running nake build after you are set up), it is recommended to go through godotmacros and godotnim module documentations. They describe special macros and procedures needed to define or instantiate Godot objects. After you learned that, the rest is similar to using any Nim library. These bindings do not limit any of Nim's capabilities, and you can use any Nim types as fields or parameters of Godot objects and their procedures (but, obviously, you may not be able to export some of them to Godot editor or GDScript, unless you define your own converters).
Modules
The binding library consists of three major modules:
- godot - Contains core types and macro definitions. You need to import this in any module that defines or makes use of Godot types.
- godotinternal - Contains raw wrappers over few core types, such as GodotVariant, GodotString, GodotNodePath, GodotDictionary, pool arrays. These are used by godotapigen and macro implementations, and you don't have to use them at all in your code, unless you want to go into low-level details for some reason. Each of those types needs to be destructed manually with deinit procedure.
- godotapigen - Wrapper generator based on data from Godot's ClassDB. You only need to use it as a part of the build process.
godot Module
Contains core types and macro definitions. You need to import this in any module that defines or makes use of Godot types. The sumbodules below are exported and you don't have to import any of them directly.
- godotnim Defines NimGodotObject and Varaint converters for standard Nim types.
- godotmacros Defines gdobj macro for defining Godot objects.
- variants Variant type represents a "dynamic object" that many Godot procedures make use of.
- arrays Defines Array of Variants.
- basis Defines 3D Basis.
- colors Defines ARGB Color.
- dictionaries Defines Variant -> Variant Dictionary.
- nodepaths Defines NodePath - a path to a Node.
- planes Defines 3D Plane.
- poolarrays Defines pooled arrays: PoolByteArray, PoolIntArray, PoolRealArray, PoolVector2Array, PoolVector3Array, PoolColorArray, PoolStringArray.
- quats Defines Quat (quaternion) describing object rotation in 3D space.
- rect2 Defines Rect2 - a 2D rectangle.
- rect3 Defines Rect3 - a 3D box.
- rids Defines RID - a resource identifier.
- transform2d Defines Transform2D.
- transforms Defines Transform.
- vector2 Defines Vector2.
- vector3 Defines Vector3.
- godotbase Defines Error type and few common math procedures missing in Nim's standard library.
Godot API
This is an auto-generated list of Godot API modules. It's built from Godot changeset 81dde2687f2f80f5f365a02d68913322d35e9be1.
- a_star
- accept_dialog
- animated_sprite
- animated_sprite_3d
- animation
- animation_player
- animation_tree_player
- area
- area_2d
- array_mesh
- arvr_anchor
- arvr_camera
- arvr_controller
- arvr_interface
- arvr_origin
- arvr_positional_tracker
- arvr_script_interface
- arvr_server
- atlas_texture
- audio_bus_layout
- audio_effect
- audio_effect_amplify
- audio_effect_band_limit_filter
- audio_effect_band_pass_filter
- audio_effect_chorus
- audio_effect_compressor
- audio_effect_delay
- audio_effect_distortion
- audio_effect_eq
- audio_effect_eq10
- audio_effect_eq21
- audio_effect_eq6
- audio_effect_filter
- audio_effect_high_pass_filter
- audio_effect_high_shelf_filter
- audio_effect_limiter
- audio_effect_low_pass_filter
- audio_effect_low_shelf_filter
- audio_effect_notch_filter
- audio_effect_panner
- audio_effect_phaser
- audio_effect_pitch_shift
- audio_effect_reverb
- audio_effect_stereo_enhance
- audio_server
- audio_stream
- audio_stream_ogg_vorbis
- audio_stream_playback
- audio_stream_player
- audio_stream_player_2d
- audio_stream_player_3d
- audio_stream_random_pitch
- audio_stream_sample
- back_buffer_copy
- base_button
- bit_map
- bitmap_font
- bone_attachment
- box_container
- box_shape
- button
- button_group
- camera
- camera_2d
- canvas_item
- canvas_item_material
- canvas_layer
- canvas_modulate
- capsule_mesh
- capsule_shape
- capsule_shape_2d
- center_container
- check_box
- check_button
- circle_shape_2d
- class_db
- collision_object
- collision_object_2d
- collision_polygon
- collision_polygon_2d
- collision_shape
- collision_shape_2d
- color_picker
- color_picker_button
- color_rect
- concave_polygon_shape
- concave_polygon_shape_2d
- cone_twist_joint
- config_file
- confirmation_dialog
- container
- control
- convex_polygon_shape
- convex_polygon_shape_2d
- cube_map
- cube_mesh
- curve
- curve_2d
- curve_3d
- curve_texture
- cylinder_mesh
- damped_spring_joint_2d
- directional_light
- directory
- dynamic_font
- dynamic_font_data
- editor_file_dialog
- editor_file_system
- editor_file_system_directory
- editor_import_plugin
- editor_plugin
- editor_resource_preview
- editor_resource_preview_generator
- editor_script
- editor_selection
- editor_settings
- editor_spatial_gizmo
- engine
- environment
- file
- file_dialog
- font
- func_ref
- gd_function_state
- gd_native
- gd_native_class
- gd_native_library
- gd_os
- gd_script
- generic_6dof_joint
- geometry
- geometry_instance
- gi_probe
- gi_probe_data
- global_constants
- godotall
- godottypes
- gradient
- gradient_texture
- graph_edit
- graph_node
- grid_container
- grid_map
- groove_joint_2d
- h_box_container
- h_scroll_bar
- h_separator
- h_slider
- h_split_container
- hinge_joint
- http_client
- http_request
- image
- image_texture
- immediate_geometry
- input
- input_default
- input_event
- input_event_action
- input_event_joypad_button
- input_event_joypad_motion
- input_event_key
- input_event_mouse
- input_event_mouse_button
- input_event_mouse_motion
- input_event_screen_drag
- input_event_screen_touch
- input_event_with_modifiers
- input_map
- instance_placeholder
- interpolated_camera
- ip
- ip_unix
- item_list
- joint
- joint_2d
- kinematic_body
- kinematic_body_2d
- label
- large_texture
- light
- light_2d
- light_occluder_2d
- line_2d
- line_edit
- line_shape_2d
- link_button
- listener
- main_loop
- margin_container
- marshalls
- material
- menu_button
- mesh
- mesh_data_tool
- mesh_instance
- mesh_library
- multi_mesh
- multi_mesh_instance
- mutex
- native_script
- navigation
- navigation_2d
- navigation_mesh
- navigation_mesh_instance
- navigation_polygon
- navigation_polygon_instance
- networked_multiplayer_e_net
- networked_multiplayer_peer
- nine_patch_rect
- node
- node_2d
- objects
- occluder_polygon_2d
- omni_light
- option_button
- p_hash_translation
- packed_data_container
- packed_data_container_ref
- packed_scene
- packet_peer
- packet_peer_stream
- packet_peer_udp
- panel
- panel_container
- panorama_sky
- parallax_background
- parallax_layer
- particles
- particles_2d
- particles_material
- path
- path_2d
- path_follow
- path_follow_2d
- pck_packer
- performance
- physics_2d_direct_body_state
- physics_2d_direct_body_state_sw
- physics_2d_direct_space_state
- physics_2d_server
- physics_2d_server_sw
- physics_2d_shape_query_parameters
- physics_2d_shape_query_result
- physics_2d_test_motion_result
- physics_body
- physics_body_2d
- physics_direct_body_state
- physics_direct_body_state_sw
- physics_direct_space_state
- physics_server
- physics_server_sw
- physics_shape_query_parameters
- physics_shape_query_result
- pin_joint
- pin_joint_2d
- plane_mesh
- plane_shape
- polygon_2d
- polygon_path_finder
- popup
- popup_dialog
- popup_menu
- popup_panel
- portal
- position_2d
- position_3d
- primitive_mesh
- prism_mesh
- procedural_sky
- progress_bar
- project_settings
- proximity_group
- quad_mesh
- range
- ray_cast
- ray_cast_2d
- ray_shape
- ray_shape_2d
- rectangle_shape_2d
- reference
- reference_rect
- reflection_probe
- reg_ex
- reg_ex_match
- remote_transform
- remote_transform_2d
- resource
- resource_importer
- resource_importer_ogg_vorbis
- resource_interactive_loader
- resource_loader
- resource_preloader
- resource_saver
- rich_text_label
- rigid_body
- rigid_body_2d
- room
- room_bounds
- scene_state
- scene_tree
- scene_tree_timer
- script
- script_editor
- scroll_bar
- scroll_container
- segment_shape_2d
- semaphore
- separator
- shader
- shader_material
- shape
- shape_2d
- short_cut
- skeleton
- sky
- slider
- slider_joint
- spatial
- spatial_gizmo
- spatial_material
- spatial_velocity_tracker
- sphere_mesh
- sphere_shape
- spin_box
- split_container
- spot_light
- sprite
- sprite_3d
- sprite_base_3d
- sprite_frames
- static_body
- static_body_2d
- stream_peer
- stream_peer_buffer
- stream_peer_ssl
- stream_peer_tcp
- stream_texture
- style_box
- style_box_empty
- style_box_flat
- style_box_texture
- surface_tool
- tab_container
- tabs
- tcp_server
- text_edit
- texture
- texture_button
- texture_progress
- texture_rect
- theme
- thread
- tile_map
- tile_set
- timer
- tool_button
- touch_screen_button
- translation
- translation_server
- tree
- tree_item
- triangle_mesh
- tween
- undo_redo
- v_box_container
- v_scroll_bar
- v_separator
- v_slider
- v_split_container
- vehicle_body
- vehicle_wheel
- video_player
- video_stream
- viewport
- viewport_container
- viewport_texture
- visibility_enabler
- visibility_enabler_2d
- visibility_notifier
- visibility_notifier_2d
- visual_instance
- visual_script
- visual_script_basic_type_constant
- visual_script_builtin_func
- visual_script_class_constant
- visual_script_comment
- visual_script_condition
- visual_script_constant
- visual_script_constructor
- visual_script_custom_node
- visual_script_deconstruct
- visual_script_emit_signal
- visual_script_engine_singleton
- visual_script_expression
- visual_script_function
- visual_script_function_call
- visual_script_function_state
- visual_script_global_constant
- visual_script_index_get
- visual_script_index_set
- visual_script_input_action
- visual_script_iterator
- visual_script_local_var
- visual_script_local_var_set
- visual_script_math_constant
- visual_script_node
- visual_script_operator
- visual_script_preload
- visual_script_property_get
- visual_script_property_set
- visual_script_resource_path
- visual_script_return
- visual_script_scene_node
- visual_script_scene_tree
- visual_script_select
- visual_script_self
- visual_script_sequence
- visual_script_sub_call
- visual_script_switch
- visual_script_type_cast
- visual_script_variable_get
- visual_script_variable_set
- visual_script_while
- visual_script_yield
- visual_script_yield_signal
- visual_server
- weak_ref
- window_dialog
- world
- world_2d
- world_environment
- xml_parser
- y_sort
godotinternal Module
Contains low-level wrappers over Godot types that require manual memory management. This module is used within godot-nim implementation and you don't need to import it unless you know what you are doing.