Skip to main content
GameDev.net gamedev.net
🔒 Locked

Lisp Math Engine

Started by neo88 Nov 15, 2004 at 7:37 PM 11 replies 2.5k views
Original Post
neo88
neo88
Hi all I am an avid Lisp programmer, as well as being interested in writing games. The two don't seem to mix well, usually though. I believe this is unforunate, since Lisp has many concepts that would be very useful for writing games such as lexical closures and macros. Doing math fast is not Lisp's forte however. C++ is really good at math. I want to write a math engine for Lisp, and I was wondering what may have already been implemented in Lisp (I know the basic trig functions, etc). I want to add vectors, quaternions, basic calc, polor co-ordinate systems and the like as well. Currently, I am reading chapters 4 and 5 of LaMothe's "Tricks of the Game Porgramming Gurus", and will probably follow his math engine model. Is there a better one? What kind of functions would you like to see in a math engine? I could use some ideas from those people who know anaylitic geometry. If you have any ideas, please post them here, or email me please. Hopefully, this math engine will make Lisp better at developing standerd game constructs such as floating cameras and graphics rasterization. Please do not start a programming language flame war here, that's not what this is meant to be. I have my reasons for liking Lisp, I also have my reasons for disliking C++, but this thread is not meant to get into all of that. Also, if you don't know Lisp, that's ok, please still free to give me your ideas and suggestions. Regards Philip Haddad (neo88)
My Kung Fu is stronger.May the Source be with you.neo88
ajas95
ajas95
Well, you'll be happy to know that Jak & Daxter, Jak 2, and Jak 3 were all written completely in Lisp + assembly (or Scheme, more precisely), and all are well-known for squeezing every ounce of processing power out of the PS2 (they did write their own Scheme-PS2 compiler, though).

As for "C++ is really good at math". That's certainly false. I just tripled performance of a recent demo by converting the inner loops from C++ fpu code to SSE assembly. You don't appreciate how truly awful the generated fpu code is until you go into a profiler and watch it cycle by cycle.

If you're going to write a math engine, you need to make sure the lowest-level constructs are written with the target processor architecture in mind (i.e. SSE, 16-byte aligned 4-element vectors, column major 4x4 matrices, + lots more).
neo88
neo88
hmmm, so much of the engine will be based on the platform... makes sense. I knew about Jak and Dexter, as a matter of fact that was my primary insperation for starting this project.
The platform that I am developing on is a P1 166 running Mandrake Linux. I want to make sure that the engine works with windoze though, so I will also be tweaking the code for the Allegro compiler.

Philip
My Kung Fu is stronger.May the Source be with you.neo88
LilBudyWizer
LilBudyWizer
A starting point might be to simply interface to an existing runtime. That would let you work out the details of the interface before you start into the details of the implementation. I believe CharlesB's main project right now is a fast math library.
Keys to success: Ability, ambition and opportunity.
neo88
neo88
I don't know of any Lisp math libs that I can interface to. If you know of one, please let me know.

Phil
My Kung Fu is stronger.May the Source be with you.neo88
MrRowl
MrRowl
Can't you interface to (i.e. write a wrapper around) a math library written in C/C++?
ajas95
ajas95
Well, SSE didn't surface until Pentium 3. Back on P1s I think people were still doing all integer math libraries. I really don't know. I'd bet Michael Abrash's Black Book would have quite a bit of relevance if your target platform is P1-160.
Extrarius
Extrarius
Quote:
Original post by ajas95
Well, SSE didn't surface until Pentium 3. Back on P1s I think people were still doing all integer math libraries. I really don't know. I'd bet Michael Abrash's Black Book would have quite a bit of relevance if your target platform is P1-160.
Actually, the black book(if you mean ISBN 1576101746) covers mostly 386/486. It does have some chapters on the U/V pipelines of the pentium, but that is an aside in the book and not an area of focus. Only 3 of the 70 chapters talk about the pentium, and those chapters only cover the pentium 1 (ie no MMX or anything like that, just the U/V pipelines).
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
LilBudyWizer
LilBudyWizer
Why does it need to be in Lisp? It is just a library. Who cares what language was used to create it? All that matters is whether it does what you need and whether you have a natural interface for using it within Lisp. You aren't going to rewrite Windows in Lisp to provide access to the Windows API. Why take that approach with a math library?
Keys to success: Ability, ambition and opportunity.
neo88
neo88
Quote:
Original post by LilBudyWizer
Why does it need to be in Lisp? It is just a library. Who cares what language was used to create it? All that matters is whether it does what you need and whether you have a natural interface for using it within Lisp. You aren't going to rewrite Windows in Lisp to provide access to the Windows API. Why take that approach with a math library?


Mainly because I want to write an entire game with Lisp and no other language used for anything else... just to prove that someone can do it. I won't be writing anything complectated, maybe a Pac-man clone or something. I just want to have access to math functions that CL does not provide such as quaternions.
Using a C++ wrapper is not as challenging and not nearly as fun as writing a library in Lisp. This is the difference between most Lispers and the main reason Lisp is not used for games I think, because in Lisp you build the language to your problems, and in C++ you build down the problem to your language. Wrappers are useful, but not as fun to write, and since I'm not getting paid for this, I want it to be a LOT of fun :)

Phil
My Kung Fu is stronger.May the Source be with you.neo88
neo88
neo88
Quote:
Original post by ajas95
Well, SSE didn't surface until Pentium 3. Back on P1s I think people were still doing all integer math libraries. I really don't know. I'd bet Michael Abrash's Black Book would have quite a bit of relevance if your target platform is P1-160.


Forgive my ignorance, but what is SSE? BTW, I am using the P1 166, I believe I metioned that already but if not....

Phil
My Kung Fu is stronger.May the Source be with you.neo88
ajas95
ajas95
Well here is an article about how/why Naughty Dog uses Lisp. Andy Gavin is the evil genius behind the whole Lisp operation... you might just try writing to him through the naughty dog website. I met a few of them at E3, they're super friendly.
neo88
neo88
Quote:
Original post by ajas95
Well here is an article about how/why Naughty Dog uses Lisp. Andy Gavin is the evil genius behind the whole Lisp operation... you might just try writing to him through the naughty dog website. I met a few of them at E3, they're super friendly.


Sweet, thanks man. I have read the article, but never thought of contacting them, maily cause I didn't know it was Andy Gavin :)

Phil
My Kung Fu is stronger.May the Source be with you.neo88

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.