Sign in to follow this  
Norman Barrows

game programming language capabilites

Recommended Posts

No single language can handle all  the  challenges in games well.  For rendering and math you want to be close to the hardware, something without a stop  the world garbage collector, etc.. But for game logic it's entirely different, you want a high level language that ideally has higher order and first class functions, suitable for writing dsl's, etc..

 

Instead of looking for the one true language, go learn 5-6 different languages so you can pick the best tool for the job, instead of forcing the tool you know to do a job  it's not designed for (not that you are doing that, it's just a general statement).

 

Chris

Share this post


Link to post
Share on other sites
When I try to imagine a language written exclusively for writing games --- and I have to try really hard for that --- I come up with a language that has absolutely nothing to do with rendering or animating or user interfaces or audio or anything else.

A language written just for writing games is going to be a scripting language within an existing game engine. It would control other systems through a mix of metadata such as animation graphs, something along the lines of an event and response driven language, or possibly a functional language that manipulates a block of game data.

The closest I can come to imagining such a language would be a redacted form of Lua, but even that doesn't fit the question.


As snacktime points out above, good games are built up with many different languages and tools. An engine might use two, three or four languages by itself, and one or two more for scripting systems that do all the fun gameplay stuff.

Share this post


Link to post
Share on other sites

well it seems i have come upon the opportunity to create my own game programming language.

 

i have three language projects going on at the moment.

 

one is a macro processor / code generator that uses a syntax designed to minimize keystrokes to generate c++ code.

 

the second is a virtual machine run time module with high level opcodes like beginscene

 

the third is another VM rtm, with p-code compiler and its own proprietary syntax and instruction set., used for copy protection schemes, and is not germane to this discussion.

 

so i'm not looking for a single [existing] language that can handle all the challenges in games well, i'm not looking for the one true [existing] language...

 

i guess i'm...  thinking of making one.

 

i took formal languages and systems and all all that stuff. so i could actually go the metal with a full blown compiler if i wanted to. but i don't really think that's necessary, it would be a LOT of work, and i'd be caught in a never ending cycle of keeping up with the jones as far as features / capabilites vs other languages. Much better to take something like MS C++ 2012 and work from there.

 

I've been looking into game engines vs libraries, code design difficulties experienced in games, and ways to speed up typing in code.

 

The short story is that it looks like libraries are more flexible than engines, many code design issues appear to be related to specific types of use of specific syntax in specific languages, and a macro processor / code generator inserted upstream of the compiler in the build pipeline will create faster running code than a VM implementing the same syntax, and will be much faster to implement than a full blown machine code generating compiler (especially for me, since i've already written two of them! <g>).

Share this post


Link to post
Share on other sites

what capabilities would one want in a high level programming language designed just for writing games?
 
high level as as in keywords / opcodes like BeginScene, and DrawIndexedPrimitive.

 
The most important thinks I can imagine I'd like to have in an game oriented language would be iterator like features and continuation passing style mechanisms to make it easier to write game logic and event driven code.
 
What I mean by this is:
 
I want to write code like:
(and I'm imagining here)

   def changeHealth(amount)
      change Player.Health to Player.Health + amount
      over 2sec
      continueWith
         if (Player.Health < 0)
            deathAnimation  
            chagngeState Game.DeatScreen
         else
            flashHealthBarAnimation
    ...
    def countDown()
       for i in 3..0 over 3sec step 1sec
          coudownAnimation(i)
I hope I've made my idea sufficiently clear.

P.S. Any similarities to Python syntax are pure coincidence tongue.png

Share this post


Link to post
Share on other sites

* composition

* For rendering and math you want to be close to the hardware

* something without a stop  the world garbage collector

 higher order and first class functions, suitable for writing dsl's, etc

  It would control other systems through a mix of metadata such as animation graphs, something along the lines of an event and response driven language, or possibly a functional language that manipulates a block of game data.

 

anything else?

 

pretend there were no limits - a wish list.  what would you want?

Share this post


Link to post
Share on other sites

def changeHealth(amount)
change Player.Health to Player.Health + amount
over 2sec
continueWith
if (Player.Health < 0)
deathAnimation
chagngeState Game.DeatScreen
else
flashHealthBarAnimation
 

 

that would be something like a DeltaThen command.

 

command name: delta then

purpose: delta a value over time, then execute a block of code.

keyword: dt, DeltaThen, deltathen, delta then, dthen, etc - pick one. i'm shooting for low keystrokes ad mnemonic, so perhaps dt unless that's already taken (i have  list of 160 or so, so far). or maybe dthen. short but mnemonic.

syntax:

dthen value delta time
// code block code goes here
.                                         // a period means "end code block"

this would be what you'd type in the CScript scripting language (the macro processor / code generator language)

 

my plan is to make it so CScript can generate code to work with various libraries. so there would be a library that implemented event processing, such as incrementing a variable by an amount each time its called, and one that called a function after a timer expired. Then the code gen would generate the calls to add the event handler to the list of active events, and start the time delayed function call, and generate the code for the function called when the timer expires.

 

you can freely mix, C, C++ and CScript syntax together. so you could say:

 

dthen player.health amount time
// your c++ code  goes here
.

 

and it would turn it all into c++ code for you.

 

come to think of it, it would probably be better as two functions, delta var over time, and call function on timer.

 

sounds like a basic need for a library for time triggered function calls, ie: it calls functions repeatedly at some constant time interval, or calls them once after some period of time. attach a timer to a function pointer with a little controlling code and you've got it. functions with parameters may be an issue, but may be unnecessary.

 

so you have your "event system library" hooked into your game loop with a single call. when its called, it checks its active events. an event could just be a time delta, a function call, and how many iterations. its start time is saved when an event is added to the list of active events. if current time >= start time + time delta, it calls the function. it does this for "iteration" number of times, then deactivates.

 

so that would lead to CScript syntax like:

 

addevent time iterations
// your code goes here
.

 

or in your case, perhaps something like:

 

// setup two events: add amount to player health over 2 seconds,
// and check for player dead after 2.1 seconds (100 milliseconds later to give the first event a chance to complete).
 
addevent 1000  2                          // addevent, 1000 millisecs per iteration, 2 iterations
player.health+=amount/2
.                                                    // end code block
addevent 2100 1                          // addevent 2100 millisecs per iteration, 1 iteration
if (Player.Health < 0)
deathAnimation
chagngeState Game.DeatScreen
else
flashHealthBarAnimation
.                                                           // end code block
 
Edited by Norman Barrows

Share this post


Link to post
Share on other sites
A short personal wishlist of mine would include stuff like:

Functional purity as default, enforced by compiler
Mutation-using code allowed inside pure functions as long as it only operates on local data (and so does not cause an actual loss of purity)
Can annotate an individual pure function call at call site to enforce the arguments must be const and the whole thing must therefore be eliminated at compile time
Strong typing, strong type inference so you rarely have to spell out the types
Deep/transitive const
Generic code written with the same syntax as other code
Generic containers and algorithms connected with ranges, iterators
Designed to allow fast and automatic incremental compilation and re-linking on the fly while in development mode, without having to add any crud in the code to make it happen

The D language already manages quite a bit of those, and also allows getting close to hardware so you don't need a separate language for that.

Tim Sweeney's old opinion touches on many of the same things:
http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/sweeny.pdf

Share this post


Link to post
Share on other sites


A language written just for writing games is going to be a scripting language within an existing game engine.

 

 

and if such an engine didn't exist, what features would you like to see in the language that you used to implement the required custom engine?

 

obviously, if you're building a game for which a perfectly suitable engine exists, there's no need for a "game programming language". 

Share this post


Link to post
Share on other sites

 


A language written just for writing games is going to be a scripting language within an existing game engine.

 

 

and if such an engine didn't exist, what features would you like to see in the language that you used to implement the required custom engine?

 

obviously, if you're building a game for which a perfectly suitable engine exists, there's no need for a "game programming language". 

 

 

A language suitable for engines isn't necessarily suitable for game logic, it is two fairly different beasts.

 

For engine level code you want fairly low level functionality, good control over memory layout and access, keywords to provide optimization hints for the compiler (pure/impure functions, hot/cold functions, memory aliasing information, etc), support for SIMD in a way that works well across different CPU architectures and doesn't fail miserably on platforms without SIMD support and ofcourse easy access to existing C and C++ libraries (as most current systems have C APIs)

Share this post


Link to post
Share on other sites

higher order and first class functions, suitable for writing dsl's,

 
dsl's:  distributed systems logic? as in distributed systems programming?

Domain specific languages. To solve a set of problems, you use the high-level features of the host language to write a mini-language specifically for that kind of problem, and then use the mini-language to solve the problems. The DSL may be embedded (still valid code in the host language, but may look extremely different than typical host language code); this means you don't need a separate parser, compiler, or interface between two separate languages. The Lisp language family is famous for being used in that way. Among more recent languages, Scala has been specifically designed to be very good at DSLs. The characteristics needed from the host language are raw (expressive) power and flexible syntax.

Alternatively, the DSL can be an entirely separate language in which case you write an interpreter or compiler. The same languages that are good hosts for embedded DSLs also tend to be very good for writing these tools.

See here:
http://www.stanford.edu/class/cs442/
http://www.scala-lang.org/old/node/1403 Edited by Yrjö P.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this