Hi! I'm new to Godot and game development in general, and I'm interested in working on a game that makes heavy use of numerical simulations of systems like partial differential equations, cellular automata, or probabilistic systems, which I like a lot (I'm a computational scientist for work) and think could make for some really fun core game mechanics.
I usually work in Python, where there are lots of nice libraries exposing multidimensional array types which have nice overloaded operators (addition, multiplication, matrix multiplication) that make it simple to code up simulations. The foundational library is numpy
.
Looking around, it seems like GDScript does not have such a library: the linear algebra code seems limited to 2D matrices and vectors. There are pooled/packed array types, which would form the core of a multidimensional array, but these don't come with math operators.
I'm interested in finding a nice way to work with a numpy-like API in GDScript rather than writing lots of for loops manually. Two options occur to me:
- Writing my own
numpy
-style library just containing the functions I need directly in GDScript.
- Trying to expose the API of a C++ ndarray library (such as xtensor) via a GDExtension so that it would be accessible in GDScript.
I'm wondering if anyone here has any perspectives on these options, or ideas for other options. From my point of view (1.) is straightforward but can take a lot of work depending on how much I want to do, and I'm not too worried about speed but it could be an issue for real-time simulations. (2.) could be a timesaver and I think it could be fast, but my guess is that writing a GDExtension and trying to expose an API from C++ into GDScript is not going to be simple, although I am a working programmer and happy in C++ and Python.
My guess is that just writing for loops is probably going to be the best option, but I wanted to ask anyway 🙂. Thanks for reading!
There is also another thread on this forum (https://godotforums.org/d/19635-python-numpy-via-gdnative) about accessing numpy itself, but my understanding is that this would only be possible by working in Python, and I think I'd like to use GDScript.