pouët.net

Go to bottom

Making 4k intro with Nim programming language

category: code [glöplog]
I made 4k intro samples using Nim programming language.
https://github.com/demotomohiro/nim-4k-intro-sample

I wrote a blog post about how to make 4k intro with Nim.
English:
https://internet-of-tomohiro.netlify.app/nim/nim4k.en.html
日本語:
https://internet-of-tomohiro.netlify.app/nim/nim4k.ja.html
added on the 2020-05-07 03:39:24 by tomohiro tomohiro
nice!
added on the 2020-05-07 05:07:02 by psenough psenough
this rules, well done!
added on the 2020-05-07 10:06:16 by ferris ferris
pretty language
added on the 2020-05-07 12:57:56 by rutra80 rutra80
hints for other languages with no visual noise characters like ';', '{' or '}'?
added on the 2020-05-07 13:00:04 by rutra80 rutra80
Thanks for pointing my attention to the Nim programming language, which seems to be interesting.
added on the 2020-05-07 13:09:17 by Adok Adok
Quote:
hints for other languages with no visual noise characters like ';', '{' or '}'?


lisp could be one example.
@psenough, @ferris
Thx!

Quote:
hints for other languages with no visual noise characters like ';', '{' or '}'?

Python, Julia and Crystal are such languages.
But Python and Julia are dynamically typed language and I don't think they can be used for making 4k intro.
Crystal is statically type-checked but I don't know whether it can make 4k intro.
added on the 2020-05-07 16:38:13 by tomohiro tomohiro
nice!

Though, most of the "important" code in a 4k is either the softsynth or a shader, so this feels a bit silly to pursue?

But I can definitely see why using Nim (or Rust, or Zig, or ...) is a feasible option for eg. 64ks.
added on the 2020-05-07 16:42:29 by porocyon porocyon
Quote:
Though, most of the "important" code in a 4k is either the softsynth or a shader, so this feels a bit silly to pursue?

To be fair, I can see a softsynth working, depending on how good the compiler is.
added on the 2020-05-07 17:43:24 by Gargaj Gargaj
langs with ';', '{' or '}'? = ❤️,
langs without = 🤮
added on the 2020-05-08 20:34:20 by greggman greggman
Will people ever get tired of inventing another bicycle?
added on the 2020-05-08 23:25:18 by dex46... dex46...
There are new bicycle models all the time...
added on the 2020-05-09 11:49:48 by absence absence
bicycle

obTopic: I find it hard to believe that a high-level language would make sense for a barebones 4k intro structure: getting a fullscreen quad for the shader and audio output from a soft synth. Maybe something that's specifically tailored to brute-force different instruction combinations and orderings to get the best possible compression out of Crinkler. For a soft synth a high-level language migth make sense.

Can this Nim framework beat, say, Compofiller Studio or Leviathan?
added on the 2020-05-09 14:19:58 by yzi yzi
Thank you Tomohiro! Looks very useful.
added on the 2020-05-09 18:10:03 by Zavie Zavie
Quote:
obTopic: I find it hard to believe that a high-level language would make sense for a barebones 4k intro structure: getting a fullscreen quad for the shader and audio output from a soft synth. Maybe something that's specifically tailored to brute-force different instruction combinations and orderings to get the best possible compression out of Crinkler. For a soft synth a high-level language migth make sense.


Nim is a systems programming language and try to generate fastest code like C.
Nim compiler generate C code from Nim code and it call C compiler(gcc, vcc, clang, etc) to generate an executable file.
It has low level programming feature:
pointer
inline assembler
choose calling convention
type compatible to C type
string compatible C char*
All runtime checks can be disabled with -d:danger option.
Nim code can run on small embedded microprocessors with only a few kilobytes of memory.

There are people who hate C or C++. They might try to make a 4k intro with Nim.

Quote:
Can this Nim framework beat, say, Compofiller Studio or Leviathan?

This is just a simple sample code to show how to write a 4k intro in Nim and it can generate an executable almost as small as C.
NimScript is the subset of Nim that can be evaluated by Nim's builtin virtual machine. It can be used to configure compile options and runs. It might be able to automate build process or process GLSL code.
added on the 2020-05-10 01:03:38 by tomohiro tomohiro
Seriously guys, not everything needs to strive for being the most optimal solution(which is subjective anyways considering size vs maintainability). Also although I'm a fan of semicolons, curly braces etc. I have a feeling that there's quite a large portion of developers who're not *coughs in python*, heck in some scenarios even I actually prefer indentation aware languages.

So I commend the effort to bring another flavor into the mix for the people who might like it.

That being said, you might want to look into using glCreateShaderProgram(also available through an extension in earlier GL versions) to shave off a bunch more bytes.
added on the 2020-05-10 20:43:36 by LJ LJ
does it have dx11 bindings?
added on the 2020-05-10 20:53:35 by Gargaj Gargaj
@LJ
Thx! It seems I can remove shader object related code with glCreateShaderProgram.
But when I want to use vertex and fragment shaders, I have to use pipeline object.
Anyway, I think it can reduce the number of OpenGL calls.

@Gargaj
You can search Nim Package in https://nimble.directory/.
I found this wrapper.

There are also tools that automaticall generate wrapper from C code.
https://github.com/nimterop/nimterop
https://github.com/nim-lang/c2nim/blob/master/doc/c2nim.rst
But I don't know if they work correctly to dx11.
added on the 2020-05-11 11:07:30 by tomohiro tomohiro
It's of course interesting that there are new languages and compilers that can feasibly do 4k intros. But aside from using something different just for the sake of using something different, what is the problem domain that Nim helps to handle better? Why do you want to put x86 code in a 4k intro, unless it's the last resort? I thought you should generally avoid doing anything in x86 land, because the produced code is low-level and hard to compress. Compared to, say, GLSL which sits on a higher level of abstraction. Is the motivation being able to make a data-driven engine of some sort, for a soft synth or something?
added on the 2020-05-11 11:59:10 by yzi yzi
It's the demoscene - why anything? The answer is because.
added on the 2020-05-11 13:58:58 by Preacher Preacher
Well, *assuming* C is too low-level for my taste *and* I start to get fed up with C++, then it is certainly an interesting idea. Think platforms other than Windows 4k, basically anything where the buld of the work is done on the CPU.
added on the 2020-05-11 14:39:41 by Moerder Moerder
bulk
added on the 2020-05-11 14:40:09 by Moerder Moerder
Don't be that guy:

BB Image
added on the 2020-05-11 17:09:18 by Zavie Zavie
yawn
added on the 2020-05-11 18:13:46 by Moerder Moerder

login

Go to top