![]() This is not so hard for simple functions and variables, but it would be very difficult to expose complicated classes and member functions. I found that it is quite difficult to expose C++ functions to the V8 JavaScript engine - there is no established Luabind equivalent, so I had to create a much more low-level wrapper than I did for Lua. We already use JavaScript for our WebKit UI layer, but is it good for game logic as well? While Lua is a popular game scripting language, JavaScript is the most popular scripting language for everything else. Print numbers counting from 1 to "to_what" Second, Lua has its own idiosyncratic syntax - here is an example: First, Lua is a dynamically-typed prototype-based language, while C++ is a statically-typed class-based language. However, it would be very difficult to port Lua code to C++ and back. It does support operator overloading, so it should be easily usable for 3D vector math. Because it is so popular, it has specialized libraries like Luabind which make it easy to embed in C++ programs. ![]() Lua is a very popular game scripting language, used in everything from Aquaria to World of Warcraft. With these requirements in mind, let's evaluate our three candidates: Lua, V8, and AngelScript. I'm sure there are many great programmers out there who can read and debug code like that (the entire Scheme programming language is based on this principle, for instance) but I find it difficult! (model_view_matrix.Mult(player_two_position))).xy()) (model_view_matrix.Mult(player_one_position)).xy().Sub( Without operator overloading, we have to replace all of those basic math operators with member functions like Multiply() or Subtract(), making it look more like this: (model_view_matrix * player_two_position).xy()) (model_view_matrix * player_one_position).xy(). I won't get into exactly how this works, but using operator overloading this would look like this: For example, let's say I want to find how far apart two players are on the screen (in order to make sure their names don't overlap). Operator overloading lets us add, subtract and multiply vectors and matrices as easily as we add, subtract and multiply integers. This is also controversial, but I find that operator overloading is essential for writing maintainable linear algebra code. User-defined types and operator overloading Constantly translating code between C++ and Scheme, for example, would be really annoying and error-prone.ģ. Many of you probably disagree with this point, but hear me out before writing irate comments! By using a scripting language that's similar to C++, I can prototype performance-critical functions, and then smoothly copy them into the game engine code when they are done. The easier it is to share functions and variables between the game engine and the scripting language, the less development time it will take to hook up. ![]() For example, a gun class in the game engine might need to call a 'shoot' function from a script, and the script would then need to call a 'raycast' check from the engine to find out if it hit anything. In order for a scripting language to be able to do anything, it needs to be connected to the game engine. Third, it has to support user-defined types and operator overloading. First, it has to be easy to embed in Overgrowth. There are three things I need from a scripting language. What do we need from a scripting language? I've seen how much live texture and shader updating speeds up my graphics work, so the idea of live code updating is very appealing. ![]() However, this is not really that important: high-level game logic is almost never a performance bottleneck. I've avoided scripting in the past because native C++ code runs orders of magnitudes faster than interpreted languages. Finally, it allows players to write their own scripts, resulting in much more complex and interesting mods. Second, it helps enforce the division between the game engine and the game itself, encouraging modular and reusable code. First, it makes gameplay programmers more efficient by reducing the amount of time they spend waiting for their code to compile. In games, their use is more specific: they are embedded into the game in order to run external "scripts" (pieces of code that can be modified without recompiling the entire game). In general, scripting languages are programming languages that are used to control other applications. I haven't worked with scripting before, so I hooked up Lua, V8 and AngelScript in order to give them each a fair trial and see which is most appropriate for us. For the last week or two I've been working on choosing a scripting language for Overgrowth.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |