scripting.html 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]--><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="Asciidoctor 1.5.4"><title>Scripting in JME3 with Groovy. All about it!</title><link rel="stylesheet" href="./asciidoctor.css">
  2. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
  3. <link rel="stylesheet" href="./coderay-asciidoctor.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css"></head><body class="article toc2 toc-left"><div id="header"><div id="toolbar"><a href="https://github.com/jMonkeyEngine/wiki/edit/master/src/docs/asciidoc/jme3/scripting.adoc"><i class="fa fa-pencil-square" aria-hidden="true"></i></a><a href="https://github.com/jMonkeyEngine/wiki/new/master/src/docs/asciidoc/jme3/"><i class="fa fa-plus-square" aria-hidden="true"></i></a><input dir="auto" style="position: relative; vertical-align: top;" spellcheck="false" autocomplete="off" class="searchbox__input aa-input" id="doc-search" name="search" placeholder="Search in the doc" required="required" type="search"></div><h1>Scripting in JME3 with Groovy. All about it!</h1><div class="details"><span class="author" id="author"></span><br><span id="revnumber">version ,</span> <span id="revdate">2016/03/17 20:48</span></div><div id="toc" class="toc2"><div id="toctitle">Table of Contents</div><ul class="sectlevel1"><li><a href="#introduction">Introduction:</a></li><li><a href="#content">Content:</a></li><li><a href="#get-started">GET STARTED</a><ul class="sectlevel2"><li><a href="#what-is-groovy">WHAT IS GROOVY?</a></li><li><a href="#highlight">Highlight</a></li><li><a href="#setup-groovy">SETUP GROOVY?</a></li><li><a href="#what-can-be-script">WHAT CAN BE SCRIPT</a></li><li><a href="#when-to-use-scripting">WHEN TO USE SCRIPTING:</a></li><li><a href="#note">NOTE:</a></li></ul></li><li><a href="#learn-groovy">LEARN GROOVY</a><ul class="sectlevel2"><li><a href="#groovy-for-smarty">Groovy – for smarty</a></li><li><a href="#official-examples-misc">Official examples &amp; Misc</a></li><li><a href="#gpars">GPars</a></li></ul></li><li><a href="#embed-groovy">EMBED GROOVY</a><ul class="sectlevel2"><li><a href="#overview">OVERVIEW</a></li><li><a href="#groovy-in-jme3">Groovy in JME3</a></li><li><a href="#groovy-in-jmp">Groovy in JMP</a></li><li><a href="#groovy-everywhere-snipets">Groovy everywhere (snipets)</a></li></ul></li><li><a href="#into-the-game">INTO THE GAME</a><ul class="sectlevel2"><li><a href="#basic-scripts">Basic Scripts</a></li><li><a href="#event-trigger-manager">Event – Trigger - Manager</a></li><li><a href="#configurations-with-groovy">Configurations with Groovy</a></li><li><a href="#ai-tricks-with-groovy">AI Tricks with Groovy</a></li><li><a href="#build-script-with-groovy">Build Script with Groovy</a></li></ul></li><li><a href="#design-patterns-in-groovy-game-wip">DESIGN PATTERNS IN GROOVY GAME (WIP)</a></li><li><a href="#advanced-tricks">ADVANCED TRICKS</a><ul class="sectlevel2"><li><a href="#hack-the-jvm-with-groovy">Hack the JVM with Groovy</a></li><li><a href="#codegen">Codegen</a></li><li><a href="#groovy-almighty-god">Groovy – Almighty God!</a></li></ul></li><li><a href="#conclusion">CONCLUSION</a></li></ul></div></div><div id="content"><div id="preamble"><div class="sectionbody"><div class="paragraph"><p><strong>Monkeys</strong>,</p></div>
  4. <div class="paragraph"><p>For anyone who still ask for something like <strong>“Scripting” with JME3</strong>, here is it, about it at once!</p></div>
  5. <div class="paragraph"><p>We nearly reach 3.0, i’m so excited about it and want to write something for it. In this post you will have a good run from Zero to Hero with Groovy and Monkey :p
  6. Not kidding!</p></div>
  7. <div style="text-align: right;" class="imageblock"><div class="content"><img src="../wiki/stll_monkey_typing.jpg" alt="100" width="" height=""></div></div>
  8. <div class="admonitionblock important"><table><tr><td class="icon"><i class="fa icon-important" title="Important"></i></td><td class="content"><div class="paragraph"><p>emoji:<br>
  9. <strong>Quick question</strong>: What this related to my other tuts emoji:confused ?<br></p></div>
  10. <div class="paragraph"><p>[atomixtuts]
  11. <strong>Answer</strong>: As I wrote the others, I thought I should write this first, because if no one know about Groovy, no one can understand a single line of my code emoji:confused , and it’s bad!</p></div></td></tr></table></div></div></div>
  12. <div class="sect1"><h2 id="introduction">Introduction:</h2><div class="sectionbody"><div class="paragraph"><p>We will go from basic setup of Groovy in JMP and then example by example every aspect of game you can develop with Groovy.
  13. More advanced topic come at the end, eg: the way to get the speed of Java, meta-programing, a lot of programming patterns (PP), even AI and Constraint Programming…
  14. Sounds insanse? Nah ah…</p></div>
  15. <div class="admonitionblock important"><table><tr><td class="icon"><i class="fa icon-important" title="Important"></i></td><td class="content"><div class="literalblock"><div class="content"><pre>Let me know if you want to write or to read other topics of Groovy or Scripting. Thanks!</pre></div></div></td></tr></table></div>
  16. <div class="paragraph"><p>Let’s start!</p></div></div></div>
  17. <div class="sect1"><h2 id="content">Content:</h2><div class="sectionbody"><div class="olist arabic"><ol class="arabic"><li><p>GET STARTED</p></li><li><p>LEARN GROOVY</p><div class="olist loweralpha"><ol class="loweralpha" type="a"><li><p>Syntax and Gotchas</p></li><li><p>Meta-programming</p></li><li><p>Groovy Builder – SwingBuilder</p></li><li><p>Groovy – for smarty</p></li><li><p>GPars</p></li></ol></div></li><li><p>EMBED GROOVY</p><div class="olist loweralpha"><ol class="loweralpha" type="a"><li><p>Groovy in JME3</p></li><li><p>Groovy in JMP</p></li><li><p>Groovy everywhere (snipets)</p></li></ol></div></li><li><p>INTO THE GAME</p><div class="olist loweralpha"><ol class="loweralpha" type="a"><li><p>Basic Scripts</p></li><li><p>Event – Trigger Manager</p></li><li><p>Configurations with Groovy</p></li><li><p>AI Tricks with Groovy</p></li><li><p>Build Script with Groovy</p></li></ol></div></li><li><p>DESIGN PATTERNS IN GROOVY GAME (WIP)</p></li><li><p>ADVANCED TRICKS</p><div class="olist loweralpha"><ol class="loweralpha" type="a"><li><p>Hack the JVM with Groovy</p></li><li><p>Codegen</p></li><li><p>Groovy – Almighty God!</p></li></ol></div></li></ol></div></div></div>
  18. <div class="sect2"><h3 id="get-started">GET STARTED</h3><div class="admonitionblock tip"><table><tr><td class="icon"><i class="fa icon-tip" title="Tip"></i></td><td class="content"><div class="paragraph"><p>If you already know about Groovy and just curious about how to intergrate Groovy into JME3. Go straight to Part <a href="../jme3/scripting.html#into_the_game">scripting</a></p></div></td></tr></table></div>
  19. <div class="sect2"><h3 id="what-is-groovy">WHAT IS GROOVY?</h3><div class="paragraph"><p><strong>Groovy</strong>…</p></div>
  20. <div style="text-align: right;" class="imageblock"><div class="content"><img src="../wiki/groovy-logo.png" alt="200" width="" height=""></div></div>
  21. <div class="paragraph"><p>is an agile and dynamic language for the Java Virtual Machine
  22. builds upon the strengths of Java but has additional power features inspired by languages like Python, Ruby and Smalltalk</p></div>
  23. <div class="paragraph"><p><a href="http://groovy-lang.org/">http://groovy-lang.org/</a></p></div></div>
  24. <div class="sect2"><h3 id="highlight">Highlight</h3><div class="paragraph"><p>The shortest highlight of the language can be found here:+
  25. <a href="http://en.wikipedia.org/wiki/Groovy_%28programming_language%29">http://en.wikipedia.org/wiki/Groovy_%28programming_language%29</a></p></div>
  26. <div class="ulist"><ul><li><p>Most valid Java files are also valid Groovy files. Although the two languages are similar, Groovy code can be more compact, because it does not require all the elements that Java requires. This makes it possible for Java programmers to gradually learn Groovy by starting with familiar Java syntax before acquiring more Groovy idioms.</p></li><li><p>Groovy features not available in Java include both static and dynamic typing (with the def keyword), closures, operator overloading, native syntax for lists and associative arrays (maps), native support for regular expressions, polymorphic iteration, expressions embedded inside strings, additional helper methods, and the safe navigation operator “?. to automatically check for nulls (for example, “variable?.method(), or “variable?.field).</p></li><li><p>Since version 2 Groovy also supports modularity, being able to ship only the needed jars according to the project needs, thus reducing the size of groovy&#8217;s lib, type checking, static compilation, Project Coin syntax enhancements, multicatch blocks and ongoing performance enhancements using JDK7&#8217;s invoke dynamic instruction.</p></li><li><p>Groovy provides native support for various markup languages such as XML and <abbr title="HyperText Markup Language">HTML</abbr>, accomplished via an inline DOM syntax. This feature enables the definition and manipulation of many types of heterogeneous data assets with a uniform and concise syntax and programming methodology.[citation needed]</p></li><li><p>Unlike Java, a Groovy source code file can be executed as an (uncompiled) script if it contains code outside any class definition, is a class with a main method, or is a Runnable or GroovyTestCase. A Groovy script is fully parsed, compiled, and generated before execution (similar to Perl and Ruby). (This occurs under the hood, and the compiled version is not saved as an artifact of the process.)</p></li></ul></div></div>
  27. <div class="sect2"><h3 id="setup-groovy">SETUP GROOVY?</h3><div class="paragraph"><p>If you used JMP to code your game (I don’t know about Eclipse users, sorry). Go to Update Center to install Groovy plugin, then download the lastest Groovy (ver2.1) and wrap it as a Library. You are ready for the adventure!</p></div>
  28. <div class="paragraph"><p><a href="http://groovy-lang.org/Download?nc">http://groovy-lang.org/Download?nc</a></p></div></div>
  29. <div class="sect2"><h3 id="what-can-be-script">WHAT CAN BE SCRIPT</h3><div class="paragraph"><p><strong><em>or “TO SCRIPT OR NOT TO SCRIPT, is the PROBLEM”?</em></strong></p></div>
  30. <div class="paragraph"><p><strong>Everything</strong>.
  31. You can do almost every thing with Groovy just like with Java.</p></div>
  32. <div class="paragraph"><p>In this post i will show example by example every aspect of game you can develop with Groovy.</p></div>
  33. <div class="paragraph"><p><strong><u>Pros:</u></strong></p></div>
  34. <div class="ulist"><ul><li><p>Scripting is very common and intuitive way to do game programing. It&#8217;s common because it&#8217;s shorter, cleaner, easy to read, maintain and re-use.</p></li><li><p>Groovy is young but developed by very talent people, a lot of devoted contributors.</p></li><li><p>Web and Enterprise in your hand. Ever heard of Grails <a href="http://grails.org/">http://grails.org/</a>?</p></li><li><p>Multi-additions to fullfil Java. God-like in Swing, ORM, XML…</p></li><li><p>Performance improved recently: If you worry about the performance, , in the next release, it can even get to the speed of Java, and soon to be a very competitive opponent to Scala! Read this? <a href="http://java.dzone.com/articles/groovy-20-performance-compared">http://java.dzone.com/articles/groovy-20-performance-compared</a></p></li></ul></div>
  35. <div class="paragraph"><p><strong><u>Cons:</u></strong></p></div>
  36. <div class="paragraph"><p>It’s good, but what about the down-side?</p></div>
  37. <div class="ulist"><ul><li><p>Can not run in Android, yet!</p></li><li><p>Some things can be wrong without noticed, appeared in run-time like every scripting language</p></li><li><p>Still a performance problem.</p></li></ul></div></div>
  38. <div class="sect2"><h3 id="when-to-use-scripting">WHEN TO USE SCRIPTING:</h3><div class="paragraph"><p>Some obvious but always existing problems of Scripting.</p></div>
  39. <div class="paragraph"><p>First every scripting language got the same type-safe dilemma. If you invest too much into Scripting, you fall immediately into the mess that hidden errors which are always very hard to find, only show up in run-time. The balance between benefit and hell of Scripting is thin.
  40. Duck-typing is not always a win-win.</p></div>
  41. <div class="sect3"><h4 id="not-type-safe">Not type-safe</h4><div class="paragraph"><p>As Groovy support Duck-typing, is almost impossible to know the type, methods of the object you want to use. This can be improved if you are in Static mode but this mode simply not what we really want with Scripting purpose?</p></div>
  42. <div class="paragraph"><p>So, as the question had been asked by a forum&#8217;s member:</p></div>
  43. <div class="admonitionblock important"><table><tr><td class="icon"><i class="fa icon-important" title="Important"></i></td><td class="content"><div class="paragraph"><p>Heh. I’d love to go Groovy myself, but I’ve been finding it very hard for me to explore the set of methods that a passed-in object supports.emoji:</p></div></td></tr></table></div>
  44. <div class="paragraph"><p><strong>Answer:</strong></p></div>
  45. <div class="paragraph"><p>From my experience, just ask you self, how “natural” your code are coded, in <strong>OOP</strong> sense:</p></div>
  46. <div class="paragraph"><p><strong>Chicken.eat(rice)</strong>
  47. <em>You know what methods and their parameter’s type, and name.</em></p></div>
  48. <div class="paragraph"><p><strong>Monkey.eat(banana)</strong>
  49. <em>You know what common in classes in a package. Without knowing the inheritance and interface they implemented.</em></p></div>
  50. <div class="paragraph"><p><strong>Human.eat([chicken,rice,banana])</strong>
  51. <em>You can guess Human are derivated from Monkey and code are coded flexible, ex: methods are multi-type, optional param. etc…</em></p></div>
  52. <div class="paragraph"><p>If it have that level of “natural” sense, you don’t have to learn by heart at all, so use scripting in the situation.</p></div>
  53. <div class="paragraph"><p>In other hand, this very related to IDE support for such language. If you watch closely, Groovy going to have better support in Netbean:</p></div>
  54. <div class="paragraph"><p><a href="https://blogs.oracle.com/netbeansgroovy/entry/groovy_refactoring_in_netbeans">https://blogs.oracle.com/netbeansgroovy/entry/groovy_refactoring_in_netbeans</a></p></div></div></div>
  55. <div class="sect2"><h3 id="note">NOTE:</h3><div class="ulist"><ul><li><p>You <strong>CAN</strong> use GROOVY for Java as Lua for C++ (even much more better)</p></li><li><p>You <strong>CAN</strong> get GROOVY run as FAST as Java</p></li><li><p>You <strong>CAN</strong> let GROOVY seamlessy intergrated with Java and other JVM languages.</p></li><li><p>Last but not least, Groovy <strong>kick</strong> asses! :p</p></li></ul></div></div></div>
  56. <div class="sect2"><h3 id="learn-groovy">LEARN GROOVY</h3><div class="admonitionblock tip"><table><tr><td class="icon"><i class="fa icon-tip" title="Tip"></i></td><td class="content"><div class="paragraph"><p>If you already know about Groovy and just curious about how to intergrate Groovy into JME3. Go straight to Part <a href="../jme3/scripting.html#into_the_game">scripting</a></p></div></td></tr></table></div>
  57. <div class="paragraph"><p>First, Groovy is much more shorter – cleaner than Java. It seamlessly get Java to the world of functional programming, like Python, Haskell, etc, but still make Java developer feel at home. You can read much more in the Groovy site and the internet, so I will not blow it up.</p></div>
  58. <div class="paragraph"><p>Anyway, let’s learn some Groovy syntax, I bet you can master it in 3 hours!</p></div>
  59. <div class="paragraph"><p>GOTO <a href="../jme3/scripting/groovy_learn.html">groovy_learn</a></p></div>
  60. <div class="sect2"><h3 id="groovy-for-smarty">Groovy – for smarty</h3><div class="paragraph"><p>emoji:*So, what you can do with Groovy?*
  61. emoji: everything, even get laid! emoji:open_mouth</p></div>
  62. <div class="paragraph"><p>I means use your imagination. I give you some examples:</p></div>
  63. <div class="ulist"><ul><li><p>Fasten the build process</p></li><li><p>Replace almost the configuration</p></li><li><p>Extract infos from XML and text, web…</p></li><li><p>Convert RenderMonkey, FXComposer shaders</p></li><li><p>Script the Dialoge, Cinematic,…</p></li><li><p>Make In-game Editor, JMP’s plugins</p></li><li><p>Make a whole freaking game</p></li><li><p>Even feed my dogs …</p></li></ul></div>
  64. <div class="paragraph"><p>[10 more]</p></div>
  65. <div class="paragraph"><p>What I want to say is <strong>Groovy</strong> is for smarty, master it and it save you <u>freaking big times</u> ! Java and Groovy are a sweetest combination of programing languages I ever tried beside of dozen of others.</p></div>
  66. <div class="admonitionblock important"><table><tr><td class="icon"><i class="fa icon-important" title="Important"></i></td><td class="content"><div class="paragraph"><p>Some of the example above will be include in this post or in my AtomScript project!</p></div></td></tr></table></div></div>
  67. <div class="sect2"><h3 id="official-examples-misc">Official examples &amp; Misc</h3><div class="paragraph"><p>Here are some website that you can find a lot of examples from simple to complicated tasks:</p></div>
  68. <div class="paragraph"><p><a href="http://groovy-lang.org/Cookbook+Examples">http://groovy-lang.org/Cookbook+Examples</a></p></div>
  69. <div class="paragraph"><p><a href="http://www.groovyexamples.org/">http://www.groovyexamples.org/</a></p></div>
  70. <div class="paragraph"><p><a href="http://snipplr.com/all/language/groovy">http://snipplr.com/all/language/groovy</a></p></div>
  71. <div class="paragraph"><p><a href="http://rosettacode.org/wiki/Rosetta_Code">http://rosettacode.org/wiki/Rosetta_Code</a> ⇐ learn Groovy and java if you come from other programming languages.</p></div></div>
  72. <div class="sect2"><h3 id="gpars">GPars</h3><div class="paragraph"><p>If you already know Groovy, I recommend you to try <strong>GPars! Groovy Parallel Systems</strong>.
  73. Why? Because <strong>it’s #$kin awesome</strong>, that’s why?
  74. Every smart monkey and Java developer should know about it, to build apps and games!</p></div>
  75. <div class="paragraph"><p><em>The GPars framework offers Java developers intuitive and safe ways to handle Java or Groovy tasks concurrently. Leveraging the enormous flexibility of the Groovy programing language and building on proven Java technologies, we aim to make concurrent programming for multi-core hardware intuitive, robust and enjoyable.</em></p></div>
  76. <div class="paragraph"><p><a href="http://gpars.codehaus.org/">http://gpars.codehaus.org/</a></p></div>
  77. <div class="admonitionblock tip"><table><tr><td class="icon"><i class="fa icon-tip" title="Tip"></i></td><td class="content"><div class="paragraph"><p>I will explain some concepts and usages of GPars that help me a lot in JME3′s game and other tasks!</p></div></td></tr></table></div>
  78. <div class="paragraph"><p>GOTO <a href="../jme3/scripting/gpars_usecases.html">gpars_usecases</a></p></div></div></div>
  79. <div class="sect2"><h3 id="embed-groovy">EMBED GROOVY</h3><div class="admonitionblock tip"><table><tr><td class="icon"><i class="fa icon-tip" title="Tip"></i></td><td class="content"><div class="paragraph"><p>First I recommend all who don&#8217;t know much about Groovy read this official documentation <a href="http://groovy-lang.org/Embedding+Groovy">http://groovy-lang.org/Embedding+Groovy</a></p></div></td></tr></table></div>
  80. <div class="paragraph"><p>Groovy is very suitable for embeding in Java application, even game. Our intention here is to get Groovy to work with JME in few ways. Some common problems, difficulties may arised cause of the differencies, uncompatiable between Java-Groovy-Native OpenGL.</p></div>
  81. <div class="paragraph"><p>So technical problem and requirement will be dicussed first, then the Design of the integration is sketched, at last the full implementation. The full source code are in the AtomScript project!</p></div>
  82. <div class="sect2"><h3 id="overview">OVERVIEW</h3><div class="sect3"><h4 id="tech-probs">TECH PROBS</h4></div>
  83. <div class="sect3"><h4 id="need-of-powerful-scripting-system">NEED OF POWERFUL SCRIPTING SYSTEM</h4><iframe src=https://docs.google.com/presentation/d/1Kc1ehI1qLbtEGe-6-q8NikY7Q77A6jvozDaX94BqX0g/embed?start=false&loop=false&delayms=3000 width="100%" height="850px" alt=""></iframe></div>
  84. <div class="sect3"><h4 id="design-architecture">DESIGN &amp; ARCHITECTURE</h4><div class="paragraph"><p>Slide</p></div></div>
  85. <div class="sect3"><h4 id="implementation">IMPLEMENTATION</h4><div class="paragraph"><p>Slide</p></div></div></div>
  86. <div class="sect2"><h3 id="groovy-in-jme3">Groovy in JME3</h3><div class="paragraph"><p>ScriptEngine</p></div>
  87. <div class="paragraph"><p>ScriptBase</p></div>
  88. <div class="paragraph"><p>Tools</p></div></div>
  89. <div class="sect2"><h3 id="groovy-in-jmp">Groovy in JMP</h3><div class="sect3"><h4 id="scriptbasetopcomponent">ScriptBaseTopComponent</h4></div>
  90. <div class="sect3"><h4 id="scriptenginemodule">ScriptEngineModule</h4></div>
  91. <div class="sect3"><h4 id="advanced-tricks-to-get-jmp-scripted">Advanced Tricks to get JMP Scripted</h4></div></div>
  92. <div class="sect2"><h3 id="groovy-everywhere-snipets">Groovy everywhere (snipets)</h3><div class="sect3"><h4 id="extract-infos-from-xml-and-text-web">Extract infos from XML and text, web…</h4></div>
  93. <div class="sect3"><h4 id="convert-rendermonkey-fxcomposer-shaders">Convert RenderMonkey, FXComposer shaders</h4><div class="paragraph"><p>GOTO <a href="../jme3/scripting/snippets.html">snippets</a></p></div></div></div></div>
  94. <div class="sect2"><h3 id="into-the-game">INTO THE GAME</h3><div class="admonitionblock important"><table><tr><td class="icon"><i class="fa icon-important" title="Important"></i></td><td class="content"><div class="paragraph"><p>Grab the example code from the AtomScript project link</p></div></td></tr></table></div>
  95. <div class="sect2"><h3 id="basic-scripts">Basic Scripts</h3><div class="sect3"><h4 id="rotate-the-wheel">Rotate the wheel</h4></div>
  96. <div class="sect3"><h4 id="travel-a-tree">Travel a tree</h4></div>
  97. <div class="sect3"><h4 id="queue-a-task">Queue a task</h4></div>
  98. <div class="sect3"><h4 id="groovyappstate">GroovyAppState</h4></div>
  99. <div class="sect3"><h4 id="closurecondition">ClosureCondition</h4><div class="paragraph"><p>GOTO <a href="../jme3/scripting/groovy_basicscripts.html">groovy_basicscripts</a></p></div></div></div>
  100. <div class="sect2"><h3 id="event-trigger-manager">Event – Trigger - Manager</h3><div class="paragraph"><p>The first idea come to my mind when think of game programming is a game cycle-update or events.</p></div>
  101. <div class="paragraph"><p>In fact, frequently update and sudden event is quite opposite paradigm, the point is to get the best of both world in one design. But can we? At least I can answer partly yes. And such sollution I&#8217;ve seen in big database system use the same hyrid concept.</p></div>
  102. <div class="paragraph"><p>I also saw in the forum, guys had conversation about Entity System, which partly envolve such design… But this one it&#8217;s different. It&#8217;s not general, I means that the code below tent to be used in kind of RTS game like War-craft of Starcraft, and I precisely model it like those two games. And the codes are very short, extremely short, show the power of Groovy in the usecase.</p></div>
  103. <div class="paragraph"><p>GOTO <a href="../jme3/scripting/groovy_event.html">groovy_event</a></p></div></div>
  104. <div class="sect2"><h3 id="configurations-with-groovy">Configurations with Groovy</h3><div class="paragraph"><p>Think about the way to config your game&#8217;s screen resolution, keyboard, database connection, without have to write and parse java property or XML files. Groovy script is text file but much more powerful, like it has variables, methods (def), loop (for), conditions (if-else)…etc to build complicated things (like a program), compared to just plain text.
  105. In short Groovy can replace almost every configuration task you can imagine. This topic about using Groovy scrips for that purpose.</p></div>
  106. <div class="paragraph"><p>GOTO <a href="../jme3/scripting/groovy_config.html">groovy_config</a></p></div></div>
  107. <div class="sect2"><h3 id="ai-tricks-with-groovy">AI Tricks with Groovy</h3><div class="paragraph"><p>As in the introduction above I said this wiki will include everything about Scripting… So, it should also include AI (Artifacial Intelligent) … But I&#8217;m not going to tell you all about AI in this wiki, it should be more in another wiki of some AI professiors. I just want to show how a quick implementation of simple AI models can be coded in Groovy:</p></div>
  108. <div class="paragraph"><p>GOTO <a href="../jme3/scripting/groovy/ai.html">ai</a></p></div>
  109. <div class="sect3"><h4 id="finite-state-machine">Finite State Machine</h4><div class="paragraph"><p>What is the most simple but affective techique to make AI. It&#8217;s FSM</p></div></div>
  110. <div class="sect3"><h4 id="decision-tree">Decision Tree</h4><div class="paragraph"><p>Builder</p></div></div>
  111. <div class="sect3"><h4 id="pattern-matching">Pattern Matching</h4><div class="paragraph"><p>Regexp emoji:</p></div></div>
  112. <div class="sect3"><h4 id="simple-chatbot">Simple Chatbot</h4><div class="paragraph"><p>Builder + Closure emoji:</p></div></div>
  113. <div class="sect3"><h4 id="simple-goalbase-agent">Simple Goalbase Agent</h4><div class="paragraph"><p>emoji:</p></div></div>
  114. <div class="sect3"><h4 id="simple-path-finding">Simple Path finding</h4><div class="paragraph"><p>Use Groovy extension
  115. emoji:</p></div></div>
  116. <div class="sect3"><h4 id="simple-steering-behavior">Simple Steering behavior</h4><div class="paragraph"><p>emoji:</p></div></div></div>
  117. <div class="sect2"><h3 id="build-script-with-groovy">Build Script with Groovy</h3><div class="paragraph"><p>Groovy can use Ant and Maven in a snapt. but wait… it also has its own build extension named Gradle.</p></div>
  118. <div class="paragraph"><p><a href="http://www.gradle.org/">http://www.gradle.org/</a></p></div>
  119. <div class="paragraph"><p>Check this out:
  120. For JME3 Desktop:
  121. emoji:</p></div>
  122. <div class="paragraph"><p>For JME3 Android:
  123. <a href="http://tools.android.com/tech-docs/new-build-system/user-guide">http://tools.android.com/tech-docs/new-build-system/user-guide</a></p></div></div></div>
  124. <div class="sect1"><h2 id="design-patterns-in-groovy-game-wip">DESIGN PATTERNS IN GROOVY GAME (WIP)</h2><div class="sectionbody"></div></div>
  125. <div class="sect2"><h3 id="advanced-tricks">ADVANCED TRICKS</h3><div class="sect2"><h3 id="hack-the-jvm-with-groovy">Hack the JVM with Groovy</h3></div>
  126. <div class="sect2"><h3 id="codegen">Codegen</h3><div class="paragraph"><p>This should be in another wiki but somehow is super fit for an example of advanced Groovy usage. The project CodeGen - Code generator is my first Groovy project. It&#8217;s tented to be a general code generator for Java, Groovy, GLSL and can also be a fun playground for non-developer. It inspirated by the concept of:</p></div>
  127. <div class="paragraph"><p>Alice <a href="http://www.alice.org/index.php">http://www.alice.org/index.php</a></p></div>
  128. <div class="paragraph"><p>GreenFoot <a href="http://www.greenfoot.org/door">http://www.greenfoot.org/door</a></p></div>
  129. <div class="paragraph"><p>and an old plugin of PGI - a JME forum&#8217;s member : PgiLogic
  130. <a href="http://hub.jmonkeyengine.org/forum/topic/dead-combinable-logic-framework/">http://hub.jmonkeyengine.org/forum/topic/dead-combinable-logic-framework/</a></p></div>
  131. <div class="paragraph"><p>It&#8217;s going to be in a suite for making Jme3 Games : Atom framework. Visit :
  132. GOTO <a href="../jme3/advanced/atom_framework.html">atom_framework</a>
  133. GOTO <a href="../jme3/advanced/atom_framework/codegen.html">codegen</a></p></div></div>
  134. <div class="sect2"><h3 id="groovy-almighty-god">Groovy – Almighty God!</h3><div class="sect3"><h4 id="get-to-the-speed-of-java">Get to the speed of Java</h4></div>
  135. <div class="sect3"><h4 id="extension-and-modulize">Extension and Modulize</h4></div>
  136. <div class="sect3"><h4 id="database-and-orm">Database and ORM</h4></div>
  137. <div class="sect3"><h4 id="dsl">DSL</h4></div>
  138. <div class="sect3"><h4 id="visit-the-moon">Visit the Moon</h4></div></div></div>
  139. <div class="sect1"><h2 id="conclusion">CONCLUSION</h2><div class="sectionbody"><div class="paragraph"><p>After reading for a while, I guess you are in love with Groovy already. You&#8217;re welcome! emoji:sunglasses</p></div>
  140. <div class="admonitionblock warning"><table><tr><td class="icon"><i class="fa icon-warning" title="Warning"></i></td><td class="content"><div class="paragraph"><p>This page <strong>CAN NOT</strong> be a full description of Groovy… but a snapshot of its good with a few home grown codes for your JME3 game!</p></div></td></tr></table></div>
  141. <div class="paragraph"><p>Beside of knowing the power and the weaknesses of the language and the way to use it in your everyday life. If you want to have the full snippets, download AtomScript project.</p></div>
  142. <div class="paragraph"><p>Any correction are welcome!</p></div></div></div></div><div id="footer"><div id="footer-text">Version <br>Last updated 2018-02-28 16:23:40 +00:00</div></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script><script>docsearch({
  143. apiKey: 'a736b6d93de805e26ec2f49b55013fbd',
  144. indexName: 'jmonkeyengine',
  145. inputSelector: '#doc-search',
  146. debug: false // Set debug to true if you want to inspect the dropdown
  147. });</script></body></html>