My Project: Formine

I suppose I will announce this as you can actually fly around this thing and look at the existing map at the moment.

Formine is a voxel game written in Fortran 03+, LuaJIT, and C.

Here is a video: https://youtu.be/Sn-0dpEhpT4

Here is the github: GitHub - jordan4ibanez/formine: A voxel game, written in Fortran, LuaJIT, and C.

Extremely early stages. I am working on the Vulkan backend at the moment.

13 Likes

Can you explain the roles of each of the three languages?

1 Like

Fortran: The main driver, basically 95% of the program is written in this.
LuaJIT: The scripting language. Allows extremely easy modding and JIT compilation of mods. (only blocks and biomes at the moment)
C: For when I need to get deeper to the hardware.

A specific example in C would be this, which is the Vulkan driver I am writing for it:

#include <stdlib.h>
#include <assert.h>
#include <vulkan/vulkan_core.h>

VkInstance *vk_grab_instance_pointer()
{
  void *data = malloc(sizeof(VkInstance));

  assert(data);

  return (VkInstance *)data;
}

I cannot get the size of VkInstance to create the base data. It’s a pointer, I have access to it. Just pass that to Fortran. :slight_smile:

And in forvk.f90:

module forvk
  interface
    function vk_grab_instance_pointer() result(ptr) bind(c, name = "vk_grab_instance_pointer")
      use, intrinsic :: iso_c_binding
      implicit none

      type(c_ptr) :: ptr
    end function vk_grab_instance_pointer
  end interface
end module forvk

If you look at hashmap_f90 and fortran_vector, you’ll see how I use C to get more performance out of Fortran without making it a nightmare to work with.

Additionally, some things I quite literally need C to work with. In Forthread I must use pthreads. This allows me to create a high performance thread pool to do tasks as fast as the hardware will allow me to without restricting the way it it used.

Also you’ll notice that it says it’s like 20% C++ for some reason, this is probably github getting confused as I ship STB_IMAGE and there’s a whole bunch of comments and ifdefs. :smiley:

1 Like

Maybe this recent post about a .gitattributes file could be helpful:

Incredible work! This is a good example of how Fortran is able to work as a general use language besides just number crunching

2 Likes

I’m not sure this will actually have any affect sadly because it’s a pure C file that’s just huge. STB libs have a lot of comments, which I can probably solve relatively easily. But I like complaining about it first lol.

1 Like

Thank you, thank you. I will certainly keep it up. 8)

Well, I kept it up. And now we have our first Vulkan triangle.

10 Likes

I’m impressed by the smoothness of the build process. Clone, fpm run, done. Nothing else had to be done.

2 Likes