Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 571788db6a12b9ecc7554aa9196296e3eb3fb2a6 @blaix committed May 18, 2011
@@ -0,0 +1,10 @@
+.DS_Store
+
+# lwjgl natives (automatically added to root directory when loaded by jme)
+liblwjgl.jnilib
+
+# configs created automatically by rawr
+Info.plist
+
+# build files
+package/*
@@ -0,0 +1 @@
+rvm jruby-1.6.0@jme
@@ -0,0 +1,3 @@
+source :rubygems
+
+gem "rawr"
@@ -0,0 +1,25 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ builder (3.0.0)
+ hoe (2.9.4)
+ rake (>= 0.8.7)
+ rake (0.8.7)
+ rawr (1.4.5)
+ rubyzip
+ user-choices
+ rubyzip (0.9.4)
+ s4t-utils (1.0.4)
+ hoe (>= 1.3.0)
+ user-choices (1.1.6.1)
+ builder (>= 2.1.2)
+ s4t-utils (>= 1.0.3)
+ xml-simple (>= 1.0.11)
+ xml-simple (1.0.15)
+
+PLATFORMS
+ java
+ ruby
+
+DEPENDENCIES
+ rawr
@@ -0,0 +1,25 @@
+Copyright (c) 2011, Justin Blake
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+* Neither the name of Hentzia nor the names of its
+ contributors may be used to endorse or promote products derived from this
+ software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,56 @@
+# jMonkeyEngine 3 with JRuby
+
+This is an example/template for game programming using [jMonkeyEngine 3][1]
+with [JRuby][2]. Including multi-platform packaging using [Rawr][3].
+
+[1]: http://jmonkeyengine.com/
+[2]: http://www.jruby.org/
+[3]: http://rawr.rubyforge.org/
+
+The sample code is adapted and expanded from
+[the "Hello SimpleApplication" tutorial on the jme wiki](http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_simpleapplication)
+
+## Important directories:
+
+ jme3-jruby-template
+ |
+ |__lib
+ | |
+ | |__java # => Put third-party java libraries here
+ |
+ |__package
+ | |
+ | |__classes
+ | |
+ | |_java # => Where your own java classes get compiled to
+ |
+ |__src
+ |
+ |__java # => Source code for your own java classes
+ |
+ |__ruby
+ |
+ |__lib # => The bulk of your ruby code should live here
+ |
+ |__main.rb # => The file that actually gets run
+
+## Running the sample code:
+
+The sample code displays a blue box. You can walk around with the wasd keys
+and look around with the mouse. As an example of mixing ruby and java, it also
+includes code to print messages to the console from a ruby class and a java
+class. See `src/ruby/main.rb` for the juicy details.
+
+First, install [JRuby][1] and [Rawr][3]. I'll leave the specifics up to you,
+but I highly recommend [rvm](https://rvm.beginrescueend.com/).
+
+To run the code directly with jruby:
+
+ rake rawr:compile
+ jruby src/ruby/main.rb
+
+## TODO:
+
+When running the code as a jar or windows/osx executable, it chokes on
+`require "mygame/ruby_player"`. Need to fix that and add packaging to the
+usage instructions.
@@ -0,0 +1 @@
+require 'rawr'
@@ -0,0 +1,89 @@
+configuration do |c|
+ # The name for your resulting application file (e.g., if the project_name is 'foo' then you'll get foo.jar, foo.exe, etc.)
+ # default value: "jruby-test"
+ #
+ #c.project_name = "jruby-test"
+
+ # Undocumented option 'output_dir'
+ # default value: "package"
+ #
+ #c.output_dir = "package"
+
+ # The main ruby file to invoke, minus the .rb extension
+ # default value: "main"
+ #
+ c.main_ruby_file = "ruby/main"
+
+ # The fully-qualified name of the main Java file used to initiate the application.
+ # default value: "org.rubyforge.rawr.Main"
+ #
+ #c.main_java_file = "org.rubyforge.rawr.Main"
+
+ # A list of directories where source files reside
+ # default value: ["src"]
+ #
+ #c.source_dirs = ["src"]
+
+ # A list of regexps of files to exclude
+ # default value: []
+ #
+ #c.source_exclude_filter = []
+
+ # Whether Ruby source files should be compiled into .class files
+ # default value: true
+ #
+ #c.compile_ruby_files = true
+
+ # A list of individual Java library files to include.
+ # default value: []
+ #
+ #c.java_lib_files = []
+
+ # A list of directories for rawr to include . All files in the given directories get bundled up.
+ # default value: ["lib/java"]
+ #
+ #c.java_lib_dirs = ["lib/java"]
+
+ # Undocumented option 'files_to_copy'
+ # default value: []
+ #
+ #c.files_to_copy = []
+
+ # Undocumented option 'target_jvm_version'
+ # default value: 1.6
+ #
+ #c.target_jvm_version = 1.6
+
+ # Undocumented option 'jvm_arguments'
+ # default value: ""
+ #
+ #c.jvm_arguments = ""
+
+ # Undocumented option 'java_library_path'
+ # default value: ""
+ #
+ #c.java_library_path = ""
+
+ # Undocumented option 'extra_user_jars'
+ # default value: {}
+ #
+ #c.extra_user_jars[:data] = { :directory => 'data/images/png',
+ # :location_in_jar => 'images',
+ # :exclude => /*.bak$/ }
+
+ # Undocumented option 'mac_do_not_generate_plist'
+ # default value: nil
+ #
+ #c.mac_do_not_generate_plist = nil
+
+ # Undocumented option 'mac_icon_path'
+ # default value: nil
+ #
+ #c.mac_icon_path = nil
+
+ # Undocumented option 'windows_icon_path'
+ # default value: nil
+ #
+ #c.windows_icon_path = nil
+
+end
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,7 @@
+package com.mygame;
+
+public class JavaPlayer {
+ public String greeting() {
+ return "================> Hello from Java!";
+ }
+}
@@ -0,0 +1,67 @@
+package org.rubyforge.rawr;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.InputStream;
+import java.io.IOException;
+import java.net.URL;
+
+
+import java.util.ArrayList;
+import org.jruby.Ruby;
+import org.jruby.RubyInstanceConfig;
+import org.jruby.javasupport.JavaEmbedUtils;
+
+public class Main
+{
+ public static void main(String[] args) throws Exception
+ {
+ RubyInstanceConfig config = new RubyInstanceConfig();
+ config.setArgv(args);
+ Ruby runtime = JavaEmbedUtils.initialize(new ArrayList(0), config);
+ String mainRubyFile = "main";
+
+ ArrayList<String> config_data = new ArrayList<String>();
+ try{
+ java.io.InputStream ins = Main.class.getClassLoader().getResourceAsStream("run_configuration");
+ if (ins == null ) {
+ System.err.println("Did not find configuration file 'run_configuration', using defaults.");
+ } else {
+ config_data = getConfigFileContents(ins);
+ }
+ }
+ catch(IOException ioe)
+ {
+ System.err.println("Error loading run configuration file 'run_configuration', using defaults: " + ioe);
+ }
+ catch(java.lang.NullPointerException npe)
+ {
+ System.err.println("Error loading run configuration file 'run_configuration', using defaults: " + npe );
+ }
+
+ for(String line : config_data) {
+ String[] parts = line.split(":");
+ if("main_ruby_file".equals(parts[0].replaceAll(" ", ""))) {
+ mainRubyFile = parts[1].replaceAll(" ", "");
+ }
+ }
+
+ runtime.evalScriptlet("require '" + mainRubyFile + "'");
+ }
+
+ public static URL getResource(String path) {
+ return Main.class.getClassLoader().getResource(path);
+ }
+
+ private static ArrayList<String> getConfigFileContents(InputStream input) throws IOException, java.lang.NullPointerException {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(input));
+ String line;
+ ArrayList<String> contents = new ArrayList<String>();
+
+ while ((line = reader.readLine()) != null) {
+ contents.add(line);
+ }
+ reader.close();
+ return(contents);
+ }
+}
@@ -0,0 +1,3 @@
+module Mygame
+ # Top-level namespace stuffs...
+end
@@ -0,0 +1,7 @@
+module Mygame
+ class RubyPlayer
+ def greeting
+ "================> Hello from Ruby!"
+ end
+ end
+end
@@ -0,0 +1,53 @@
+require "java"
+require "pathname"
+
+PROJECT_ROOT = Pathname.new(File.expand_path("../..", File.dirname(__FILE__)))
+$CLASSPATH << PROJECT_ROOT + "lib/java/jme3/jMonkeyEngine3.jar"
+
+# Our own java classes will be compiled to this directory.
+$CLASSPATH << PROJECT_ROOT + "package/classes/java"
+
+# Our ruby code will be compiled as java classes here
+$CLASSPATH << PROJECT_ROOT + "package/classes/ruby/ruby/lib"
+
+# Our own ruby code should be under this directory...
+$: << PROJECT_ROOT + "src/ruby/lib"
+
+# ...for example, our ruby player class!
+require "mygame/ruby_player"
+
+java_import com.jme3.app.SimpleApplication
+java_import com.jme3.material.Material
+java_import com.jme3.math.Vector3f
+java_import com.jme3.scene.Geometry
+java_import com.jme3.scene.shape.Box
+java_import com.jme3.math.ColorRGBA
+
+class Main < SimpleApplication
+
+ # You should be able to use simple_init_app here but it seemed buggy. So stick
+ # with java-style camel-casing when overriding methods defined in jme java
+ # classes. Oh well.
+ def simpleInitApp
+
+ # Draw a blue box. Look around with mouse. Move around with wasd.
+ box = Box.new(Vector3f::ZERO, 1, 1, 1)
+ geometry = Geometry.new("Box", box)
+ material = Material.new(self.asset_manager, "Common/MatDefs/Misc/Unshaded.j3md")
+ material.set_color("Color", ColorRGBA::Blue)
+ geometry.material = material
+ self.root_node.attach_child(geometry)
+
+ # Example of using your own ruby and java classes.
+ # Use include (ruby) and java_import (java) to access without namespaces.
+ java_player = com.mygame.JavaPlayer.new
+ ruby_player = Mygame::RubyPlayer.new
+
+ # Output will display in the console (not the game window).
+ puts java_player.greeting
+ puts ruby_player.greeting
+ end
+end
+
+main = Main.new
+main.start

0 comments on commit 571788d

Please sign in to comment.