Skip to content
Browse files

Rails Setup

  • Loading branch information...
1 parent 9f25e41 commit be2c2c7bd2b68196e630c1db85ebc98cbdfbd1e6 @MathiasPaumgarten committed Dec 8, 2010
Showing with 20,285 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. +30 −0 Gemfile
  3. +73 −0 Gemfile.lock
  4. +7 −0 Rakefile
  5. +3 −0 app/controllers/application_controller.rb
  6. +2 −0 app/helpers/application_helper.rb
  7. +14 −0 app/views/layouts/application.html.erb
  8. +4 −0 config.ru
  9. +42 −0 config/application.rb
  10. +13 −0 config/boot.rb
  11. +5 −0 config/environment.rb
  12. +26 −0 config/environments/development.rb
  13. +49 −0 config/environments/production.rb
  14. +35 −0 config/environments/test.rb
  15. +7 −0 config/initializers/backtrace_silencers.rb
  16. +10 −0 config/initializers/inflections.rb
  17. +5 −0 config/initializers/mime_types.rb
  18. +7 −0 config/initializers/secret_token.rb
  19. +8 −0 config/initializers/session_store.rb
  20. +5 −0 config/locales/en.yml
  21. +58 −0 config/routes.rb
  22. +7 −0 db/seeds.rb
  23. +2 −0 doc/README_FOR_APP
  24. 0 lib/tasks/.gitkeep
  25. +26 −0 public/404.html
  26. +26 −0 public/422.html
  27. +26 −0 public/500.html
  28. 0 public/favicon.ico
  29. BIN public/images/rails.png
  30. +239 −0 public/index.html
  31. +2 −0 public/javascripts/application.js
  32. +19 −0 public/javascripts/box2d/README.md
  33. +31 −0 public/javascripts/box2d/collision/ClipVertex.js
  34. +62 −0 public/javascripts/box2d/collision/Features.js
  35. +48 −0 public/javascripts/box2d/collision/b2AABB.js
  36. +54 −0 public/javascripts/box2d/collision/b2Bound.js
  37. +27 −0 public/javascripts/box2d/collision/b2BoundValues.js
  38. +812 −0 public/javascripts/box2d/collision/b2BroadPhase.js
  39. +27 −0 public/javascripts/box2d/collision/b2BufferedPair.js
  40. +621 −0 public/javascripts/box2d/collision/b2Collision.js
  41. +49 −0 public/javascripts/box2d/collision/b2ContactID.js
  42. +36 −0 public/javascripts/box2d/collision/b2ContactPoint.js
  43. +294 −0 public/javascripts/box2d/collision/b2Distance.js
  44. +36 −0 public/javascripts/box2d/collision/b2Manifold.js
  45. +33 −0 public/javascripts/box2d/collision/b2OBB.js
  46. +86 −0 public/javascripts/box2d/collision/b2Pair.js
  47. +33 −0 public/javascripts/box2d/collision/b2PairCallback.js
  48. +365 −0 public/javascripts/box2d/collision/b2PairManager.js
  49. +40 −0 public/javascripts/box2d/collision/b2Proxy.js
  50. +53 −0 public/javascripts/box2d/collision/shapes/b2BoxDef.js
  51. +33 −0 public/javascripts/box2d/collision/shapes/b2CircleDef.js
  52. +174 −0 public/javascripts/box2d/collision/shapes/b2CircleShape.js
  53. +28 −0 public/javascripts/box2d/collision/shapes/b2MassData.js
  54. +50 −0 public/javascripts/box2d/collision/shapes/b2PolyDef.js
  55. +455 −0 public/javascripts/box2d/collision/shapes/b2PolyShape.js
  56. +251 −0 public/javascripts/box2d/collision/shapes/b2Shape.js
  57. +83 −0 public/javascripts/box2d/collision/shapes/b2ShapeDef.js
  58. +31 −0 public/javascripts/box2d/collision/shapes/b2ShapeFactory.js
  59. +68 −0 public/javascripts/box2d/common/b2Settings.js
  60. +140 −0 public/javascripts/box2d/common/math/b2Mat22.js
  61. +58 −0 public/javascripts/box2d/common/math/b2Math.js
  62. +193 −0 public/javascripts/box2d/common/math/b2Vec2.js
  63. +440 −0 public/javascripts/box2d/dynamics/b2Body.js
  64. +86 −0 public/javascripts/box2d/dynamics/b2BodyDef.js
  65. +46 −0 public/javascripts/box2d/dynamics/b2CollisionFilter.js
  66. +290 −0 public/javascripts/box2d/dynamics/b2ContactManager.js
  67. +279 −0 public/javascripts/box2d/dynamics/b2Island.js
  68. +28 −0 public/javascripts/box2d/dynamics/b2TimeStep.js
  69. +475 −0 public/javascripts/box2d/dynamics/b2World.js
  70. +44 −0 public/javascripts/box2d/dynamics/b2WorldListener.js
  71. +92 −0 public/javascripts/box2d/dynamics/contacts/b2CircleContact.js
  72. +210 −0 public/javascripts/box2d/dynamics/contacts/b2Conservative.js
  73. +97 −0 public/javascripts/box2d/dynamics/contacts/b2Contact.js
  74. +41 −0 public/javascripts/box2d/dynamics/contacts/b2ContactConstraint.js
  75. +36 −0 public/javascripts/box2d/dynamics/contacts/b2ContactConstraintPoint.js
  76. +90 −0 public/javascripts/box2d/dynamics/contacts/b2ContactFactory.js
  77. +29 −0 public/javascripts/box2d/dynamics/contacts/b2ContactNode.js
  78. +28 −0 public/javascripts/box2d/dynamics/contacts/b2ContactRegister.js
  79. +510 −0 public/javascripts/box2d/dynamics/contacts/b2ContactSolver.js
  80. +71 −0 public/javascripts/box2d/dynamics/contacts/b2NullContact.js
  81. +92 −0 public/javascripts/box2d/dynamics/contacts/b2PolyAndCircleContact.js
  82. +143 −0 public/javascripts/box2d/dynamics/contacts/b2PolyContact.js
  83. +244 −0 public/javascripts/box2d/dynamics/joints/b2DistanceJoint.js
  84. +43 −0 public/javascripts/box2d/dynamics/joints/b2DistanceJointDef.js
  85. +254 −0 public/javascripts/box2d/dynamics/joints/b2GearJoint.js
  86. +43 −0 public/javascripts/box2d/dynamics/joints/b2GearJointDef.js
  87. +54 −0 public/javascripts/box2d/dynamics/joints/b2Jacobian.js
  88. +140 −0 public/javascripts/box2d/dynamics/joints/b2Joint.js
  89. +37 −0 public/javascripts/box2d/dynamics/joints/b2JointDef.js
  90. +39 −0 public/javascripts/box2d/dynamics/joints/b2JointFactory.js
  91. +29 −0 public/javascripts/box2d/dynamics/joints/b2JointNode.js
  92. +212 −0 public/javascripts/box2d/dynamics/joints/b2MouseJoint.js
  93. +45 −0 public/javascripts/box2d/dynamics/joints/b2MouseJointDef.js
  94. +601 −0 public/javascripts/box2d/dynamics/joints/b2PrismaticJoint.js
  95. +46 −0 public/javascripts/box2d/dynamics/joints/b2PrismaticJointDef.js
  96. +534 −0 public/javascripts/box2d/dynamics/joints/b2PulleyJoint.js
  97. +56 −0 public/javascripts/box2d/dynamics/joints/b2PulleyJointDef.js
  98. +436 −0 public/javascripts/box2d/dynamics/joints/b2RevoluteJoint.js
  99. +47 −0 public/javascripts/box2d/dynamics/joints/b2RevoluteJointDef.js
  100. +965 −0 public/javascripts/controls.js
  101. +974 −0 public/javascripts/dragdrop.js
  102. +1,123 −0 public/javascripts/effects.js
  103. +6,001 −0 public/javascripts/prototype.js
  104. +175 −0 public/javascripts/rails.js
  105. +5 −0 public/robots.txt
  106. 0 public/stylesheets/.gitkeep
  107. +6 −0 script/rails
  108. +9 −0 test/performance/browsing_test.rb
  109. +13 −0 test/test_helper.rb
  110. 0 vendor/plugins/.gitkeep
View
6 .gitignore
@@ -0,0 +1,6 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/**/*
+
+config/database.yml
View
30 Gemfile
@@ -0,0 +1,30 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.0'
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+gem 'sqlite3-ruby', :require => 'sqlite3'
+
+# Use unicorn as the web server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger
+# gem 'ruby-debug'
+
+# Bundle the extra gems:
+# gem 'bj'
+# gem 'nokogiri'
+# gem 'sqlite3-ruby', :require => 'sqlite3'
+# gem 'aws-s3', :require => 'aws/s3'
+
+# Bundle gems for the local environment. Make sure to
+# put test-only gems in this group so their generators
+# and rake tasks are available in development mode:
+# group :development, :test do
+# gem 'webrat'
+# end
View
73 Gemfile.lock
@@ -0,0 +1,73 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.0)
+ actionpack (= 3.0.0)
+ mail (~> 2.2.5)
+ actionpack (3.0.0)
+ activemodel (= 3.0.0)
+ activesupport (= 3.0.0)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4.1)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.12)
+ rack-test (~> 0.5.4)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.0)
+ activesupport (= 3.0.0)
+ builder (~> 2.1.2)
+ i18n (~> 0.4.1)
+ activerecord (3.0.0)
+ activemodel (= 3.0.0)
+ activesupport (= 3.0.0)
+ arel (~> 1.0.0)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.0)
+ activemodel (= 3.0.0)
+ activesupport (= 3.0.0)
+ activesupport (3.0.0)
+ arel (1.0.1)
+ activesupport (~> 3.0.0)
+ builder (2.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ i18n (0.4.1)
+ mail (2.2.7)
+ activesupport (>= 2.3.6)
+ mime-types
+ treetop (>= 1.4.5)
+ mime-types (1.16)
+ polyglot (0.3.1)
+ rack (1.2.1)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-test (0.5.6)
+ rack (>= 1.0)
+ rails (3.0.0)
+ actionmailer (= 3.0.0)
+ actionpack (= 3.0.0)
+ activerecord (= 3.0.0)
+ activeresource (= 3.0.0)
+ activesupport (= 3.0.0)
+ bundler (~> 1.0.0)
+ railties (= 3.0.0)
+ railties (3.0.0)
+ actionpack (= 3.0.0)
+ activesupport (= 3.0.0)
+ rake (>= 0.8.4)
+ thor (~> 0.14.0)
+ rake (0.8.7)
+ sqlite3-ruby (1.3.1-x86-mingw32)
+ thor (0.14.3)
+ treetop (1.4.8)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.23)
+
+PLATFORMS
+ x86-mingw32
+
+DEPENDENCIES
+ rails (= 3.0.0)
+ sqlite3-ruby
View
7 Rakefile
@@ -0,0 +1,7 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require File.expand_path('../config/application', __FILE__)
+require 'rake'
+
+Marblerun::Application.load_tasks
View
3 app/controllers/application_controller.rb
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
View
2 app/helpers/application_helper.rb
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
View
14 app/views/layouts/application.html.erb
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Marblerun</title>
+ <%= stylesheet_link_tag :all %>
+ <%= javascript_include_tag :defaults %>
+ <%= csrf_meta_tag %>
+</head>
+<body>
+
+<%= yield %>
+
+</body>
+</html>
View
4 config.ru
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Marblerun::Application
View
42 config/application.rb
@@ -0,0 +1,42 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+# If you have a Gemfile, require the gems listed there, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(:default, Rails.env) if defined?(Bundler)
+
+module Marblerun
+ class Application < Rails::Application
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Custom directories with classes and modules you want to be autoloadable.
+ # config.autoload_paths += %W(#{config.root}/extras)
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named.
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Activate observers that should always be running.
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
+ # config.time_zone = 'Central Time (US & Canada)'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+ # config.i18n.default_locale = :de
+
+ # JavaScript files you want as :defaults (application.js is always included).
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
+
+ # Configure the default encoding used in templates for Ruby 1.9.
+ config.encoding = "utf-8"
+
+ # Configure sensitive parameters which will be filtered from the log file.
+ config.filter_parameters += [:password]
+ end
+end
View
13 config/boot.rb
@@ -0,0 +1,13 @@
+require 'rubygems'
+
+# Set up gems listed in the Gemfile.
+gemfile = File.expand_path('../../Gemfile', __FILE__)
+begin
+ ENV['BUNDLE_GEMFILE'] = gemfile
+ require 'bundler'
+ Bundler.setup
+rescue Bundler::GemNotFound => e
+ STDERR.puts e.message
+ STDERR.puts "Try running `bundle install`."
+ exit!
+end if File.exist?(gemfile)
View
5 config/environment.rb
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Marblerun::Application.initialize!
View
26 config/environments/development.rb
@@ -0,0 +1,26 @@
+Marblerun::Application.configure do
+ # Settings specified here will take precedence over those in config/environment.rb
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the webserver when you make code changes.
+ config.cache_classes = false
+
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_view.debug_rjs = true
+ config.action_controller.perform_caching = false
+
+ # Don't care if the mailer can't send
+ config.action_mailer.raise_delivery_errors = false
+
+ # Print deprecation notices to the Rails logger
+ config.active_support.deprecation = :log
+
+ # Only use best-standards-support built into browsers
+ config.action_dispatch.best_standards_support = :builtin
+end
+
View
49 config/environments/production.rb
@@ -0,0 +1,49 @@
+Marblerun::Application.configure do
+ # Settings specified here will take precedence over those in config/environment.rb
+
+ # The production environment is meant for finished, "live" apps.
+ # Code is not reloaded between requests
+ config.cache_classes = true
+
+ # Full error reports are disabled and caching is turned on
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Specifies the header that your server uses for sending files
+ config.action_dispatch.x_sendfile_header = "X-Sendfile"
+
+ # For nginx:
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
+
+ # If you have no front-end server that supports something like X-Sendfile,
+ # just comment this out and Rails will serve the files
+
+ # See everything in the log (default is :info)
+ # config.log_level = :debug
+
+ # Use a different logger for distributed setups
+ # config.logger = SyslogLogger.new
+
+ # Use a different cache store in production
+ # config.cache_store = :mem_cache_store
+
+ # Disable Rails's static asset server
+ # In production, Apache or nginx will already do this
+ config.serve_static_assets = false
+
+ # Enable serving of images, stylesheets, and javascripts from an asset server
+ # config.action_controller.asset_host = "http://assets.example.com"
+
+ # Disable delivery errors, bad email addresses will be ignored
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable threaded mode
+ # config.threadsafe!
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation can not be found)
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners
+ config.active_support.deprecation = :notify
+end
View
35 config/environments/test.rb
@@ -0,0 +1,35 @@
+Marblerun::Application.configure do
+ # Settings specified here will take precedence over those in config/environment.rb
+
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+ config.cache_classes = true
+
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Raise exceptions instead of rendering exception templates
+ config.action_dispatch.show_exceptions = false
+
+ # Disable request forgery protection in test environment
+ config.action_controller.allow_forgery_protection = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
+ # like if you have constraints or database-specific column types
+ # config.active_record.schema_format = :sql
+
+ # Print deprecation notices to the stderr
+ config.active_support.deprecation = :stderr
+end
View
7 config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
View
10 config/initializers/inflections.rb
@@ -0,0 +1,10 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format
+# (all these examples are active by default):
+# ActiveSupport::Inflector.inflections do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
View
5 config/initializers/mime_types.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
+# Mime::Type.register_alias "text/html", :iphone
View
7 config/initializers/secret_token.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# Your secret key for verifying the integrity of signed cookies.
+# If you change this key, all old signed cookies will become invalid!
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+Marblerun::Application.config.secret_token = '27685cb6fe0e341cadc051456952b33b19a4e17c15fb6275af56b4958c918707ab20d814d942dc6447d32cc03bf6d20e573a2228427534524368b5666a757780'
View
8 config/initializers/session_store.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+Marblerun::Application.config.session_store :cookie_store, :key => '_marblerun_session'
+
+# Use the database for sessions instead of the cookie-based default,
+# which shouldn't be used to store highly confidential information
+# (create the session table with "rake db:sessions:create")
+# Marblerun::Application.config.session_store :active_record_store
View
5 config/locales/en.yml
@@ -0,0 +1,5 @@
+# Sample localization file for English. Add more files in this directory for other locales.
+# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
+
+en:
+ hello: "Hello world"
View
58 config/routes.rb
@@ -0,0 +1,58 @@
+Marblerun::Application.routes.draw do
+ # The priority is based upon order of creation:
+ # first created -> highest priority.
+
+ # Sample of regular route:
+ # match 'products/:id' => 'catalog#view'
+ # Keep in mind you can assign values other than :controller and :action
+
+ # Sample of named route:
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
+ # This route can be invoked with purchase_url(:id => product.id)
+
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
+ # resources :products
+
+ # Sample resource route with options:
+ # resources :products do
+ # member do
+ # get 'short'
+ # post 'toggle'
+ # end
+ #
+ # collection do
+ # get 'sold'
+ # end
+ # end
+
+ # Sample resource route with sub-resources:
+ # resources :products do
+ # resources :comments, :sales
+ # resource :seller
+ # end
+
+ # Sample resource route with more complex sub-resources
+ # resources :products do
+ # resources :comments
+ # resources :sales do
+ # get 'recent', :on => :collection
+ # end
+ # end
+
+ # Sample resource route within a namespace:
+ # namespace :admin do
+ # # Directs /admin/products/* to Admin::ProductsController
+ # # (app/controllers/admin/products_controller.rb)
+ # resources :products
+ # end
+
+ # You can have the root of your site routed with "root"
+ # just remember to delete public/index.html.
+ # root :to => "welcome#index"
+
+ # See how all your routes lay out with "rake routes"
+
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
+ # Note: This route will make all actions in every controller accessible via GET requests.
+ # match ':controller(/:action(/:id(.:format)))'
+end
View
7 db/seeds.rb
@@ -0,0 +1,7 @@
+# This file should contain all the record creation needed to seed the database with its default values.
+# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
+#
+# Examples:
+#
+# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
+# Mayor.create(:name => 'Daley', :city => cities.first)
View
2 doc/README_FOR_APP
@@ -0,0 +1,2 @@
+Use this README file to introduce your application and point to useful places in the API for learning more.
+Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
View
0 lib/tasks/.gitkeep
No changes.
View
26 public/404.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>The page you were looking for doesn't exist (404)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/404.html -->
+ <div class="dialog">
+ <h1>The page you were looking for doesn't exist.</h1>
+ <p>You may have mistyped the address or the page may have moved.</p>
+ </div>
+</body>
+</html>
View
26 public/422.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>The change you wanted was rejected (422)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/422.html -->
+ <div class="dialog">
+ <h1>The change you wanted was rejected.</h1>
+ <p>Maybe you tried to change something you didn't have access to.</p>
+ </div>
+</body>
+</html>
View
26 public/500.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>We're sorry, but something went wrong (500)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/500.html -->
+ <div class="dialog">
+ <h1>We're sorry, but something went wrong.</h1>
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
+ </div>
+</body>
+</html>
View
0 public/favicon.ico
No changes.
View
BIN public/images/rails.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
239 public/index.html
@@ -0,0 +1,239 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Ruby on Rails: Welcome aboard</title>
+ <style type="text/css" media="screen">
+ body {
+ margin: 0;
+ margin-bottom: 25px;
+ padding: 0;
+ background-color: #f0f0f0;
+ font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
+ font-size: 13px;
+ color: #333;
+ }
+
+ h1 {
+ font-size: 28px;
+ color: #000;
+ }
+
+ a {color: #03c}
+ a:hover {
+ background-color: #03c;
+ color: white;
+ text-decoration: none;
+ }
+
+
+ #page {
+ background-color: #f0f0f0;
+ width: 750px;
+ margin: 0;
+ margin-left: auto;
+ margin-right: auto;
+ }
+
+ #content {
+ float: left;
+ background-color: white;
+ border: 3px solid #aaa;
+ border-top: none;
+ padding: 25px;
+ width: 500px;
+ }
+
+ #sidebar {
+ float: right;
+ width: 175px;
+ }
+
+ #footer {
+ clear: both;
+ }
+
+
+ #header, #about, #getting-started {
+ padding-left: 75px;
+ padding-right: 30px;
+ }
+
+
+ #header {
+ background-image: url("images/rails.png");
+ background-repeat: no-repeat;
+ background-position: top left;
+ height: 64px;
+ }
+ #header h1, #header h2 {margin: 0}
+ #header h2 {
+ color: #888;
+ font-weight: normal;
+ font-size: 16px;
+ }
+
+
+ #about h3 {
+ margin: 0;
+ margin-bottom: 10px;
+ font-size: 14px;
+ }
+
+ #about-content {
+ background-color: #ffd;
+ border: 1px solid #fc0;
+ margin-left: -55px;
+ margin-right: -10px;
+ }
+ #about-content table {
+ margin-top: 10px;
+ margin-bottom: 10px;
+ font-size: 11px;
+ border-collapse: collapse;
+ }
+ #about-content td {
+ padding: 10px;
+ padding-top: 3px;
+ padding-bottom: 3px;
+ }
+ #about-content td.name {color: #555}
+ #about-content td.value {color: #000}
+
+ #about-content ul {
+ padding: 0;
+ list-style-type: none;
+ }
+
+ #about-content.failure {
+ background-color: #fcc;
+ border: 1px solid #f00;
+ }
+ #about-content.failure p {
+ margin: 0;
+ padding: 10px;
+ }
+
+
+ #getting-started {
+ border-top: 1px solid #ccc;
+ margin-top: 25px;
+ padding-top: 15px;
+ }
+ #getting-started h1 {
+ margin: 0;
+ font-size: 20px;
+ }
+ #getting-started h2 {
+ margin: 0;
+ font-size: 14px;
+ font-weight: normal;
+ color: #333;
+ margin-bottom: 25px;
+ }
+ #getting-started ol {
+ margin-left: 0;
+ padding-left: 0;
+ }
+ #getting-started li {
+ font-size: 18px;
+ color: #888;
+ margin-bottom: 25px;
+ }
+ #getting-started li h2 {
+ margin: 0;
+ font-weight: normal;
+ font-size: 18px;
+ color: #333;
+ }
+ #getting-started li p {
+ color: #555;
+ font-size: 13px;
+ }
+
+
+ #sidebar ul {
+ margin-left: 0;
+ padding-left: 0;
+ }
+ #sidebar ul h3 {
+ margin-top: 25px;
+ font-size: 16px;
+ padding-bottom: 10px;
+ border-bottom: 1px solid #ccc;
+ }
+ #sidebar li {
+ list-style-type: none;
+ }
+ #sidebar ul.links li {
+ margin-bottom: 5px;
+ }
+
+ </style>
+ <script type="text/javascript">
+ function about() {
+ info = document.getElementById('about-content');
+ if (window.XMLHttpRequest)
+ { xhr = new XMLHttpRequest(); }
+ else
+ { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
+ xhr.open("GET","rails/info/properties",false);
+ xhr.send("");
+ info.innerHTML = xhr.responseText;
+ info.style.display = 'block'
+ }
+ </script>
+ </head>
+ <body>
+ <div id="page">
+ <div id="sidebar">
+ <ul id="sidebar-items">
+ <li>
+ <h3>Browse the documentation</h3>
+ <ul class="links">
+ <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
+ <li><a href="http://stdlib.rubyonrails.org/">Ruby standard library</a></li>
+ <li><a href="http://corelib.rubyonrails.org/">Ruby core</a></li>
+ <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
+ </ul>
+ </li>
+ </ul>
+ </div>
+
+ <div id="content">
+ <div id="header">
+ <h1>Welcome aboard</h1>
+ <h2>You&rsquo;re riding Ruby on Rails!</h2>
+ </div>
+
+ <div id="about">
+ <h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
+ <div id="about-content" style="display: none"></div>
+ </div>
+
+ <div id="getting-started">
+ <h1>Getting started</h1>
+ <h2>Here&rsquo;s how to get rolling:</h2>
+
+ <ol>
+ <li>
+ <h2>Use <code>rails generate</code> to create your models and controllers</h2>
+ <p>To see all available options, run it without parameters.</p>
+ </li>
+
+ <li>
+ <h2>Set up a default route and remove or rename this file</h2>
+ <p>Routes are set up in config/routes.rb.</p>
+ </li>
+
+ <li>
+ <h2>Create your database</h2>
+ <p>Run <code>rake db:migrate</code> to create your database. If you're not using SQLite (the default), edit <code>config/database.yml</code> with your username and password.</p>
+ </li>
+ </ol>
+ </div>
+ </div>
+
+ <div id="footer">&nbsp;</div>
+ </div>
+ </body>
+</html>
View
2 public/javascripts/application.js
@@ -0,0 +1,2 @@
+// Place your application-specific JavaScript functions and classes here
+// This file is automatically included by javascript_include_tag :defaults
View
19 public/javascripts/box2d/README.md
@@ -0,0 +1,19 @@
+# Box2d-JS
+
+## Inspiration
+* [Box2D](http://www.box2d.org/) is an actively maintained, open-source C++ library.
+* [Box2D-JS](http://sourceforge.net/projects/box2d-js/) Is a javascript port of the C++ library. It was last updated 15 May, 2008.
+ * See the original demo [here](http://box2d-js.sourceforge.net/).
+
+## Pixel Lab Box2d-JS
+The folks at [Pixel Lab](http://thinkpixellab.com) modified the library to use [Google's Closure Javascript Compiler](http://code.google.com/closure/compiler/) for great compression--with the added benefit of compile-time checking. (We found a lot of bugs in the original javascript).
+
+It's being used for [Agent 008 Ball](http://www.agent8ball.com/) - an HTML5 billiards game.
+
+The demo site is [here](http://box2d.thinkpixellab.com/).
+
+The demo site source, including demo code, can be found in [this Github repository](http://github.com/thinkpixellab/box2dWeb).
+
+Please open issues or fork, fix, and send a pull request.
+
+Happy to work with you.
View
31 public/javascripts/box2d/collision/ClipVertex.js
@@ -0,0 +1,31 @@
+/*
+* Copyright (c) 2006-2007 Erin Catto http:
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked, and must not be
+* misrepresented the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+goog.provide('box2d.ClipVertex');
+
+goog.require('box2d.ContactID');
+goog.require('box2d.Vec2');
+
+/**
+ @constructor
+ */
+box2d.ClipVertex = function() {
+ // initialize instance variables for references
+ this.v = new box2d.Vec2();
+ this.id = new box2d.ContactID();
+};
View
62 public/javascripts/box2d/collision/Features.js
@@ -0,0 +1,62 @@
+/*
+* Copyright (c) 2006-2007 Erin Catto http:
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked, and must not be
+* misrepresented the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+goog.provide('box2d.Features');
+
+/**
+ @constructor
+ @param {!box2d.ContactID} contactId
+ */
+box2d.Features = function(contactId) {
+ /*
+ @type {!box2d.ContactID}
+ */
+ this._m_id = contactId;
+ this._incidentEdg = 0;
+ this._incidentVertex = 0;
+ this._referenceFace = 0;
+ this._flip = 0;
+};
+box2d.Features.prototype.set_referenceFace = function(value) {
+ this._referenceFace = value;
+ this._m_id._key = (this._m_id._key & 0xffffff00) | (this._referenceFace & 0x000000ff);
+};
+box2d.Features.prototype.get_referenceFace = function() {
+ return this._referenceFace;
+};
+box2d.Features.prototype.set_incidentEdge = function(value) {
+ this._incidentEdge = value;
+ this._m_id._key = (this._m_id._key & 0xffff00ff) | ((this._incidentEdge << 8) & 0x0000ff00);
+};
+box2d.Features.prototype.get_incidentEdge = function() {
+ return this._incidentEdge;
+};
+box2d.Features.prototype.set_incidentVertex = function(value) {
+ this._incidentVertex = value;
+ this._m_id._key = (this._m_id._key & 0xff00ffff) | ((this._incidentVertex << 16) & 0x00ff0000);
+};
+box2d.Features.prototype.get_incidentVertex = function() {
+ return this._incidentVertex;
+};
+box2d.Features.prototype.set_flip = function(value) {
+ this._flip = value;
+ this._m_id._key = (this._m_id._key & 0x00ffffff) | ((this._flip << 24) & 0xff000000);
+};
+box2d.Features.prototype.get_flip = function() {
+ return this._flip;
+};
View
48 public/javascripts/box2d/collision/b2AABB.js
@@ -0,0 +1,48 @@
+/*
+* Copyright (c) 2006-2007 Erin Catto http:
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked, and must not be
+* misrepresented the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+goog.provide('box2d.AABB');
+
+goog.require('box2d.Vec2');
+
+// A manifold for two touching convex shapes.
+/**
+ @constructor
+ */
+box2d.AABB = function() {
+
+ /** @type {box2d.Vec2} */
+ this.minVertex = new box2d.Vec2();
+
+ /** @type {box2d.Vec2} */
+ this.maxVertex = new box2d.Vec2();
+};
+
+/** @return {boolean} */
+box2d.AABB.prototype.IsValid = function() {
+ //var d = box2d.Vec2.subtract(this.maxVertex, this.minVertex);
+ var dX = this.maxVertex.x;
+ var dY = this.maxVertex.y;
+ dX = this.maxVertex.x;
+ dY = this.maxVertex.y;
+ dX -= this.minVertex.x;
+ dY -= this.minVertex.y;
+ var valid = dX >= 0.0 && dY >= 0.0;
+ valid = valid && this.minVertex.IsValid() && this.maxVertex.IsValid();
+ return valid;
+};
View
54 public/javascripts/box2d/collision/b2Bound.js
@@ -0,0 +1,54 @@
+/*
+* Copyright (c) 2006-2007 Erin Catto http:
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked, and must not be
+* misrepresented the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+goog.provide('box2d.Bound');
+
+/**
+ @constructor
+ */
+box2d.Bound = function() {
+ this.value = 0;
+ this.proxyId = 0;
+ this.stabbingCount = 0;
+};
+
+/**
+ @return {boolean}
+*/
+box2d.Bound.prototype.IsLower = function() {
+ return (this.value & 1) == 0;
+};
+/**
+ @return {boolean}
+*/
+box2d.Bound.prototype.IsUpper = function() {
+ return (this.value & 1) == 1;
+};
+box2d.Bound.prototype.Swap = function(b) {
+ var tempValue = this.value;
+ var tempProxyId = this.proxyId;
+ var tempStabbingCount = this.stabbingCount;
+
+ this.value = b.value;
+ this.proxyId = b.proxyId;
+ this.stabbingCount = b.stabbingCount;
+
+ b.value = tempValue;
+ b.proxyId = tempProxyId;
+ b.stabbingCount = tempStabbingCount;
+};
View
27 public/javascripts/box2d/collision/b2BoundValues.js
@@ -0,0 +1,27 @@
+/*
+* Copyright (c) 2006-2007 Erin Catto http:
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked, and must not be
+* misrepresented the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+goog.provide('box2d.BoundValues');
+
+/**
+ @constructor
+ */
+box2d.BoundValues = function() {
+ this.lowerValues = [0, 0];
+ this.upperValues = [0, 0];
+};
View
812 public/javascripts/box2d/collision/b2BroadPhase.js
@@ -0,0 +1,812 @@
+/*
+* Copyright (c) 2006-2007 Erin Catto http:
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked, and must not be
+* misrepresented the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+goog.provide('box2d.BroadPhase');
+
+goog.require('box2d.Bound');
+goog.require('box2d.BoundValues');
+goog.require('box2d.PairManager');
+goog.require('box2d.Proxy');
+goog.require('box2d.Settings');
+goog.require('box2d.Vec2');
+
+/*
+This broad phase uses the Sweep and Prune algorithm in:
+Collision Detection in Interactive 3D Environments by Gino van den Bergen
+Also, some ideas, such integral values for fast compares comes from
+Bullet (http:/www.bulletphysics.com).
+*/
+
+// Notes:
+// - we use bound arrays instead of linked lists for cache coherence.
+// - we use quantized integral values for fast compares.
+// - we use short indices rather than pointers to save memory.
+// - we use a stabbing count for fast overlap queries (less than order N).
+// - we also use a time stamp on each proxy to speed up the registration of
+// overlap query results.
+// - where possible, we compare bound indices instead of values to reduce
+// cache misses (TODO_ERIN).
+// - no broadphase is perfect and neither is this one: it is not great for huge
+// worlds (use a multi-SAP instead), it is not great for large objects.
+/**
+ @constructor
+ @param {!box2d.AABB} worldAABB
+ @param {!box2d.ContactManager} callback
+ */
+box2d.BroadPhase = function(worldAABB, callback) {
+ // initialize instance variables for references
+ this.m_pairManager = new box2d.PairManager();
+
+ /**
+ @type {!Array.<box2d.Proxy>}
+ */
+ this.proxyPool = new Array(box2d.Settings.b2_maxPairs);
+ this.m_bounds = new Array(2 * box2d.Settings.b2_maxProxies);
+ this.m_queryResults = new Array(box2d.Settings.b2_maxProxies);
+ this.m_quantizationFactor = new box2d.Vec2();
+ //
+ //box2d.Settings.b2Assert(worldAABB.IsValid());
+ var i = 0;
+
+ this.m_pairManager.Initialize(this, callback);
+
+ this.m_worldAABB = worldAABB;
+
+ this.m_proxyCount = 0;
+
+ // query results
+ for (i = 0; i < box2d.Settings.b2_maxProxies; i++) {
+ this.m_queryResults[i] = 0;
+ }
+
+ // bounds array
+ this.m_bounds = new Array(2);
+ for (i = 0; i < 2; i++) {
+ this.m_bounds[i] = new Array(2 * box2d.Settings.b2_maxProxies);
+ for (var j = 0; j < 2 * box2d.Settings.b2_maxProxies; j++) {
+ this.m_bounds[i][j] = new box2d.Bound();
+ }
+ }
+
+ //var d = box2d.Vec2.subtract(worldAABB.maxVertex, worldAABB.minVertex);
+ var dX = worldAABB.maxVertex.x;
+ var dY = worldAABB.maxVertex.y;
+ dX -= worldAABB.minVertex.x;
+ dY -= worldAABB.minVertex.y;
+
+ this.m_quantizationFactor.x = box2d.Settings.USHRT_MAX / dX;
+ this.m_quantizationFactor.y = box2d.Settings.USHRT_MAX / dY;
+
+ var tProxy;
+ for (i = 0; i < box2d.Settings.b2_maxProxies - 1; ++i) {
+ tProxy = new box2d.Proxy();
+ this.proxyPool[i] = tProxy;
+ tProxy.SetNext(i + 1);
+ tProxy.timeStamp = 0;
+ tProxy.overlapCount = box2d.Settings.invalid;
+ tProxy.userData = null;
+ }
+ tProxy = new box2d.Proxy();
+ this.proxyPool[box2d.Settings.b2_maxProxies - 1] = tProxy;
+ tProxy.SetNext(box2d.Pair.b2_nullProxy);
+ tProxy.timeStamp = 0;
+ tProxy.overlapCount = box2d.Settings.invalid;
+ tProxy.userData = null;
+ this.m_freeProxy = 0;
+
+ this.m_timeStamp = 1;
+ this.m_queryResultCount = 0;
+};
+
+//~b2BroadPhase();
+// Use this to see if your proxy is in range. If it is not in range,
+// it should be destroyed. Otherwise you may get O(m^2) pairs, where m
+// is the number of proxies that are out of range.
+box2d.BroadPhase.prototype.InRange = function(aabb) {
+ var dX;
+ var dY;
+ var d2X;
+ var d2Y;
+
+ dX = aabb.minVertex.x;
+ dY = aabb.minVertex.y;
+ dX -= this.m_worldAABB.maxVertex.x;
+ dY -= this.m_worldAABB.maxVertex.y;
+
+ d2X = this.m_worldAABB.minVertex.x;
+ d2Y = this.m_worldAABB.minVertex.y;
+ d2X -= aabb.maxVertex.x;
+ d2Y -= aabb.maxVertex.y;
+
+ dX = Math.max(dX, d2X);
+ dY = Math.max(dY, d2Y);
+
+ return Math.max(dX, dY) < 0.0;
+};
+
+// Get a single proxy. Returns NULL if the id is invalid.
+box2d.BroadPhase.prototype.GetProxy = function(proxyId) {
+ if (proxyId == box2d.Pair.b2_nullProxy || this.proxyPool[proxyId].IsValid() == false) {
+ return null;
+ }
+
+ return this.proxyPool[proxyId];
+};
+
+box2d.BroadPhase.prototype.DestroyProxy = function(proxyId) {
+
+ //box2d.Settings.b2Assert(0 < this.m_proxyCount && this.m_proxyCount <= b2_maxProxies);
+ var proxy = this.proxyPool[proxyId];
+ //box2d.Settings.b2Assert(proxy.IsValid());
+ var boundCount = 2 * this.m_proxyCount;
+
+ for (var axis = 0; axis < 2; ++axis) {
+ var bounds = this.m_bounds[axis];
+
+ var lowerIndex = proxy.lowerBounds[axis];
+ var upperIndex = proxy.upperBounds[axis];
+ var lowerValue = bounds[lowerIndex].value;
+ var upperValue = bounds[upperIndex].value;
+
+ // replace memmove calls
+ //memmove(bounds + lowerIndex, bounds + lowerIndex + 1, (upperIndex - lowerIndex - 1) * sizeof(b2Bound));
+ var tArr = new Array();
+ var j = 0;
+ var tEnd = upperIndex - lowerIndex - 1;
+ var tBound1;
+ var tBound2;
+ // make temp array
+ for (j = 0; j < tEnd; j++) {
+ tArr[j] = new box2d.Bound();
+ tBound1 = tArr[j];
+ tBound2 = bounds[lowerIndex + 1 + j];
+ tBound1.value = tBound2.value;
+ tBound1.proxyId = tBound2.proxyId;
+ tBound1.stabbingCount = tBound2.stabbingCount;
+ }
+ // move temp array back in to bounds
+ tEnd = tArr.length;
+ var tIndex = lowerIndex;
+ for (j = 0; j < tEnd; j++) {
+ //bounds[tIndex+j] = tArr[j];
+ tBound2 = tArr[j];
+ tBound1 = bounds[tIndex + j];
+ tBound1.value = tBound2.value;
+ tBound1.proxyId = tBound2.proxyId;
+ tBound1.stabbingCount = tBound2.stabbingCount;
+ }
+ //memmove(bounds + upperIndex-1, bounds + upperIndex + 1, (edgeCount - upperIndex - 1) * sizeof(b2Bound));
+ // make temp array
+ tArr = new Array();
+ tEnd = boundCount - upperIndex - 1;
+ for (j = 0; j < tEnd; j++) {
+ tArr[j] = new box2d.Bound();
+ tBound1 = tArr[j];
+ tBound2 = bounds[upperIndex + 1 + j];
+ tBound1.value = tBound2.value;
+ tBound1.proxyId = tBound2.proxyId;
+ tBound1.stabbingCount = tBound2.stabbingCount;
+ }
+ // move temp array back in to bounds
+ tEnd = tArr.length;
+ tIndex = upperIndex - 1;
+ for (j = 0; j < tEnd; j++) {
+ //bounds[tIndex+j] = tArr[j];
+ tBound2 = tArr[j];
+ tBound1 = bounds[tIndex + j];
+ tBound1.value = tBound2.value;
+ tBound1.proxyId = tBound2.proxyId;
+ tBound1.stabbingCount = tBound2.stabbingCount;
+ }
+
+ // Fix bound indices.
+ tEnd = boundCount - 2;
+ for (var index = lowerIndex; index < tEnd; ++index) {
+ var proxy2 = this.proxyPool[bounds[index].proxyId];
+ if (bounds[index].IsLower()) {
+ proxy2.lowerBounds[axis] = index;
+ } else {
+ proxy2.upperBounds[axis] = index;
+ }
+ }
+
+ // Fix stabbing count.
+ tEnd = upperIndex - 1;
+ for (var index2 = lowerIndex; index2 < tEnd; ++index2) {
+ bounds[index2].stabbingCount--;
+ }
+
+ // this.Query for pairs to be removed. lowerIndex and upperIndex are not needed.
+ // make lowerIndex and upper output using an array and do this for others if compiler doesn't pick them up
+ this.Query([0], [0], lowerValue, upperValue, bounds, boundCount - 2, axis);
+ }
+
+ //box2d.Settings.b2Assert(this.m_queryResultCount < box2d.Settings.b2_maxProxies);
+ for (var i = 0; i < this.m_queryResultCount; ++i) {
+ //box2d.Settings.b2Assert(this.proxyPool[this.m_queryResults[i]].IsValid());
+ this.m_pairManager.RemoveBufferedPair(proxyId, this.m_queryResults[i]);
+ }
+
+ this.m_pairManager.Commit();
+
+ // Prepare for next query.
+ this.m_queryResultCount = 0;
+ this.IncrementTimeStamp();
+
+ // Return the proxy to the pool.
+ proxy.userData = null;
+ proxy.overlapCount = box2d.Settings.invalid;
+ proxy.lowerBounds[0] = box2d.Settings.invalid;
+ proxy.lowerBounds[1] = box2d.Settings.invalid;
+ proxy.upperBounds[0] = box2d.Settings.invalid;
+ proxy.upperBounds[1] = box2d.Settings.invalid;
+
+ proxy.SetNext(this.m_freeProxy);
+ this.m_freeProxy = proxyId;
+ --this.m_proxyCount;
+};
+
+// this.Query an AABB for overlapping proxies, returns the user data and
+// the count, up to the supplied maximum count.
+box2d.BroadPhase.prototype.QueryAABB = function(aabb, userData, maxCount) {
+ var lowerValues = new Array();
+ var upperValues = new Array();
+ this.ComputeBounds(lowerValues, upperValues, aabb);
+
+ var lowerIndex = 0;
+ var upperIndex = 0;
+ var lowerIndexOut = [lowerIndex];
+ var upperIndexOut = [upperIndex];
+ this.Query(lowerIndexOut, upperIndexOut, lowerValues[0], upperValues[0], this.m_bounds[0], 2 * this.m_proxyCount, 0);
+ this.Query(lowerIndexOut, upperIndexOut, lowerValues[1], upperValues[1], this.m_bounds[1], 2 * this.m_proxyCount, 1);
+
+ //box2d.Settings.b2Assert(this.m_queryResultCount < box2d.Settings.b2_maxProxies);
+ var count = 0;
+ for (var i = 0; i < this.m_queryResultCount && count < maxCount; ++i, ++count) {
+ //box2d.Settings.b2Assert(this.m_queryResults[i] < box2d.Settings.b2_maxProxies);
+ var proxy = this.proxyPool[this.m_queryResults[i]];
+ //box2d.Settings.b2Assert(proxy.IsValid());
+ userData[i] = proxy.userData;
+ }
+
+ // Prepare for next query.
+ this.m_queryResultCount = 0;
+ this.IncrementTimeStamp();
+
+ return count;
+};
+
+box2d.BroadPhase.prototype.Validate = function() {
+ var pair;
+ var proxy1;
+ var proxy2;
+ var overlap;
+
+ for (var axis = 0; axis < 2; ++axis) {
+ var bounds = this.m_bounds[axis];
+
+ var boundCount = 2 * this.m_proxyCount;
+ var stabbingCount = 0;
+
+ for (var i = 0; i < boundCount; ++i) {
+ var bound = bounds[i];
+ //box2d.Settings.b2Assert(i == 0 || bounds[i-1].value <= bound->value);
+ //box2d.Settings.b2Assert(bound->proxyId != b2_nullProxy);
+ //box2d.Settings.b2Assert(this.proxyPool[bound->proxyId].IsValid());
+ if (bound.IsLower() == true) {
+ //box2d.Settings.b2Assert(this.proxyPool[bound.proxyId].lowerBounds[axis] == i);
+ stabbingCount++;
+ } else {
+ //box2d.Settings.b2Assert(this.proxyPool[bound.proxyId].upperBounds[axis] == i);
+ stabbingCount--;
+ }
+
+ //box2d.Settings.b2Assert(bound.stabbingCount == stabbingCount);
+ }
+ }
+
+};
+
+//private:
+box2d.BroadPhase.prototype.ComputeBounds = function(lowerValues, upperValues, aabb) {
+ //box2d.Settings.b2Assert(aabb.maxVertex.x > aabb.minVertex.x);
+ //box2d.Settings.b2Assert(aabb.maxVertex.y > aabb.minVertex.y);
+ var minVertexX = aabb.minVertex.x;
+ var minVertexY = aabb.minVertex.y;
+ minVertexX = Math.min(minVertexX, this.m_worldAABB.maxVertex.x);
+ minVertexY = Math.min(minVertexY, this.m_worldAABB.maxVertex.y);
+ minVertexX = Math.max(minVertexX, this.m_worldAABB.minVertex.x);
+ minVertexY = Math.max(minVertexY, this.m_worldAABB.minVertex.y);
+
+ var maxVertexX = aabb.maxVertex.x;
+ var maxVertexY = aabb.maxVertex.y;
+ maxVertexX = Math.min(maxVertexX, this.m_worldAABB.maxVertex.x);
+ maxVertexY = Math.min(maxVertexY, this.m_worldAABB.maxVertex.y);
+ maxVertexX = Math.max(maxVertexX, this.m_worldAABB.minVertex.x);
+ maxVertexY = Math.max(maxVertexY, this.m_worldAABB.minVertex.y);
+
+ // Bump lower bounds downs and upper bounds up. This ensures correct sorting of
+ // lower/upper bounds that would have equal values.
+ // TODO_ERIN implement fast float to uint16 conversion.
+ lowerValues[0] =
+ /*uint*/
+ (this.m_quantizationFactor.x * (minVertexX - this.m_worldAABB.minVertex.x)) & (box2d.Settings.USHRT_MAX - 1);
+ upperValues[0] = (
+ /*uint*/
+ (this.m_quantizationFactor.x * (maxVertexX - this.m_worldAABB.minVertex.x)) & 0x0000ffff) | 1;
+
+ lowerValues[1] =
+ /*uint*/
+ (this.m_quantizationFactor.y * (minVertexY - this.m_worldAABB.minVertex.y)) & (box2d.Settings.USHRT_MAX - 1);
+ upperValues[1] = (
+ /*uint*/
+ (this.m_quantizationFactor.y * (maxVertexY - this.m_worldAABB.minVertex.y)) & 0x0000ffff) | 1;
+};
+
+// This one is only used for validation.
+box2d.BroadPhase.prototype.TestOverlapValidate = function(p1, p2) {
+
+ for (var axis = 0; axis < 2; ++axis) {
+ var bounds = this.m_bounds[axis];
+
+ //box2d.Settings.b2Assert(p1.lowerBounds[axis] < 2 * this.m_proxyCount);
+ //box2d.Settings.b2Assert(p1.upperBounds[axis] < 2 * this.m_proxyCount);
+ //box2d.Settings.b2Assert(p2.lowerBounds[axis] < 2 * this.m_proxyCount);
+ //box2d.Settings.b2Assert(p2.upperBounds[axis] < 2 * this.m_proxyCount);
+ if (bounds[p1.lowerBounds[axis]].value > bounds[p2.upperBounds[axis]].value) return false;
+
+ if (bounds[p1.upperBounds[axis]].value < bounds[p2.lowerBounds[axis]].value) return false;
+ }
+
+ return true;
+};
+
+box2d.BroadPhase.prototype.TestOverlap = function(b, p) {
+ for (var axis = 0; axis < 2; ++axis) {
+ var bounds = this.m_bounds[axis];
+
+ //box2d.Settings.b2Assert(p.lowerBounds[axis] < 2 * this.m_proxyCount);
+ //box2d.Settings.b2Assert(p.upperBounds[axis] < 2 * this.m_proxyCount);
+ if (b.lowerValues[axis] > bounds[p.upperBounds[axis]].value) return false;
+
+ if (b.upperValues[axis] < bounds[p.lowerBounds[axis]].value) return false;
+ }
+
+ return true;
+};
+
+box2d.BroadPhase.prototype.Query = function(lowerQueryOut, upperQueryOut, lowerValue, upperValue, bounds, boundCount, axis) {
+
+ var lowerQuery = box2d.BroadPhase.BinarySearch(bounds, boundCount, lowerValue);
+ var upperQuery = box2d.BroadPhase.BinarySearch(bounds, boundCount, upperValue);
+
+ // Easy case: lowerQuery <= lowerIndex(i) < upperQuery
+ // Solution: search query range for min bounds.
+ for (var j = lowerQuery; j < upperQuery; ++j) {
+ if (bounds[j].IsLower()) {
+ this.IncrementOverlapCount(bounds[j].proxyId);
+ }
+ }
+
+ // Hard case: lowerIndex(i) < lowerQuery < upperIndex(i)
+ // Solution: use the stabbing count to search down the bound array.
+ if (lowerQuery > 0) {
+ var i = lowerQuery - 1;
+ var s = bounds[i].stabbingCount;
+
+ // Find the s overlaps.
+ while (s) {
+ //box2d.Settings.b2Assert(i >= 0);
+ if (bounds[i].IsLower()) {
+ var proxy = this.proxyPool[bounds[i].proxyId];
+ if (lowerQuery <= proxy.upperBounds[axis]) {
+ this.IncrementOverlapCount(bounds[i].proxyId);
+ --s;
+ }
+ } --i;
+ }
+ }
+
+ lowerQueryOut[0] = lowerQuery;
+ upperQueryOut[0] = upperQuery;
+};
+
+box2d.BroadPhase.prototype.IncrementOverlapCount = function(proxyId) {
+ var proxy = this.proxyPool[proxyId];
+ if (proxy.timeStamp < this.m_timeStamp) {
+ proxy.timeStamp = this.m_timeStamp;
+ proxy.overlapCount = 1;
+ } else {
+ proxy.overlapCount = 2;
+ //box2d.Settings.b2Assert(this.m_queryResultCount < box2d.Settings.b2_maxProxies);
+ this.m_queryResults[this.m_queryResultCount] = proxyId;
+ ++this.m_queryResultCount;
+ }
+};
+box2d.BroadPhase.prototype.IncrementTimeStamp = function() {
+ if (this.m_timeStamp == box2d.Settings.USHRT_MAX) {
+ for (var i = 0; i < box2d.Settings.b2_maxProxies; ++i) {
+ this.proxyPool[i].timeStamp = 0;
+ }
+ this.m_timeStamp = 1;
+ } else {
+ ++this.m_timeStamp;
+ }
+};
+
+// Call this.MoveProxy times like, then when you are done
+// call this.Commit to finalized the proxy pairs (for your time step).
+/**
+ @param {number} proxyId
+ @param {!box2d.AABB} aabb
+ */
+box2d.BroadPhase.prototype.MoveProxy = function(proxyId, aabb) {
+ var axis = 0;
+ var index = 0;
+ var bound;
+ var prevBound;
+ var nextBound;
+ var nextProxyId = 0;
+ var nextProxy;
+
+ if (proxyId == box2d.Pair.b2_nullProxy || box2d.Settings.b2_maxProxies <= proxyId) {
+ //box2d.Settings.b2Assert(false);
+ return;
+ }
+
+ if (aabb.IsValid() == false) {
+ //box2d.Settings.b2Assert(false);
+ return;
+ }
+
+ var boundCount = 2 * this.m_proxyCount;
+
+ var proxy = this.proxyPool[proxyId];
+ // Get new bound values
+ var newValues = new box2d.BoundValues();
+ this.ComputeBounds(newValues.lowerValues, newValues.upperValues, aabb);
+
+ // Get old bound values
+ var oldValues = new box2d.BoundValues();
+ for (axis = 0; axis < 2; ++axis) {
+ oldValues.lowerValues[axis] = this.m_bounds[axis][proxy.lowerBounds[axis]].value;
+ oldValues.upperValues[axis] = this.m_bounds[axis][proxy.upperBounds[axis]].value;
+ }
+
+ for (axis = 0; axis < 2; ++axis) {
+ var bounds = this.m_bounds[axis];
+
+ var lowerIndex = proxy.lowerBounds[axis];
+ var upperIndex = proxy.upperBounds[axis];
+
+ var lowerValue = newValues.lowerValues[axis];
+ var upperValue = newValues.upperValues[axis];
+
+ var deltaLower = lowerValue - bounds[lowerIndex].value;
+ var deltaUpper = upperValue - bounds[upperIndex].value;
+
+ bounds[lowerIndex].value = lowerValue;
+ bounds[upperIndex].value = upperValue;
+
+ //
+ // Expanding adds overlaps
+ //
+ // Should we move the lower bound down?
+ if (deltaLower < 0) {
+ index = lowerIndex;
+ while (index > 0 && lowerValue < bounds[index - 1].value) {
+ bound = bounds[index];
+ prevBound = bounds[index - 1];
+
+ var prevProxyId = prevBound.proxyId;
+ var prevProxy = this.proxyPool[prevBound.proxyId];
+
+ prevBound.stabbingCount++;
+
+ if (prevBound.IsUpper() == true) {
+ if (this.TestOverlap(newValues, prevProxy)) {
+ this.m_pairManager.AddBufferedPair(proxyId, prevProxyId);
+ }
+
+ prevProxy.upperBounds[axis]++;
+ bound.stabbingCount++;
+ } else {
+ prevProxy.lowerBounds[axis]++;
+ bound.stabbingCount--;
+ }
+
+ proxy.lowerBounds[axis]--;
+
+ // swap
+ //var temp = bound;
+ //bound = prevEdge;
+ //prevEdge = temp;
+ bound.Swap(prevBound);
+ --index;
+ }
+ }
+
+ // Should we move the upper bound up?
+ if (deltaUpper > 0) {
+ index = upperIndex;
+ while (index < boundCount - 1 && bounds[index + 1].value <= upperValue) {
+ bound = bounds[index];
+ nextBound = bounds[index + 1];
+ nextProxyId = nextBound.proxyId;
+ nextProxy = this.proxyPool[nextProxyId];
+
+ nextBound.stabbingCount++;
+
+ if (nextBound.IsLower() == true) {
+ if (this.TestOverlap(newValues, nextProxy)) {
+ this.m_pairManager.AddBufferedPair(proxyId, nextProxyId);
+ }
+
+ nextProxy.lowerBounds[axis]--;
+ bound.stabbingCount++;
+ } else {
+ nextProxy.upperBounds[axis]--;
+ bound.stabbingCount--;
+ }
+
+ proxy.upperBounds[axis]++;
+ // swap
+ //var temp = bound;
+ //bound = nextEdge;
+ //nextEdge = temp;
+ bound.Swap(nextBound);
+ index++;
+ }
+ }
+
+ //
+ // Shrinking removes overlaps
+ //
+ // Should we move the lower bound up?
+ if (deltaLower > 0) {
+ index = lowerIndex;
+ while (index < boundCount - 1 && bounds[index + 1].value <= lowerValue) {
+ bound = bounds[index];
+ nextBound = bounds[index + 1];
+
+ nextProxyId = nextBound.proxyId;
+ nextProxy = this.proxyPool[nextProxyId];
+
+ nextBound.stabbingCount--;
+
+ if (nextBound.IsUpper()) {
+ if (this.TestOverlap(oldValues, nextProxy)) {
+ this.m_pairManager.RemoveBufferedPair(proxyId, nextProxyId);
+ }
+
+ nextProxy.upperBounds[axis]--;
+ bound.stabbingCount--;
+ } else {
+ nextProxy.lowerBounds[axis]--;
+ bound.stabbingCount++;
+ }
+
+ proxy.lowerBounds[axis]++;
+ // swap
+ //var temp = bound;
+ //bound = nextEdge;
+ //nextEdge = temp;
+ bound.Swap(nextBound);
+ index++;
+ }
+ }
+
+ // Should we move the upper bound down?
+ if (deltaUpper < 0) {
+ index = upperIndex;
+ while (index > 0 && upperValue < bounds[index - 1].value) {
+ bound = bounds[index];
+ prevBound = bounds[index - 1];
+
+ prevProxyId = prevBound.proxyId;
+ prevProxy = this.proxyPool[prevProxyId];
+
+ prevBound.stabbingCount--;
+
+ if (prevBound.IsLower() == true) {
+ if (this.TestOverlap(oldValues, prevProxy)) {
+ this.m_pairManager.RemoveBufferedPair(proxyId, prevProxyId);
+ }
+
+ prevProxy.lowerBounds[axis]++;
+ bound.stabbingCount--;
+ } else {
+ prevProxy.upperBounds[axis]++;
+ bound.stabbingCount++;
+ }
+
+ proxy.upperBounds[axis]--;
+ // swap
+ //var temp = bound;
+ //bound = prevEdge;
+ //prevEdge = temp;
+ bound.Swap(prevBound);
+ index--;
+ }
+ }
+ }
+};
+
+/**
+ @return {!Array.<box2d.Pair>}
+ */
+box2d.BroadPhase.prototype.Commit = function() {
+ return this.m_pairManager.Commit();
+};
+
+/**
+ // Create and destroy proxies. These call Flush first.
+ @param {!box2d.AABB} aabb
+ @param {!box2d.Shape} userData
+ @return {number}
+ */
+box2d.BroadPhase.prototype.CreateProxy = function(aabb, userData) {
+ var index = 0;
+ var proxy;
+
+ //box2d.Settings.b2Assert(this.m_proxyCount < b2_maxProxies);
+ //box2d.Settings.b2Assert(this.m_freeProxy != box2d.Pair.b2_nullProxy);
+ var proxyId = this.m_freeProxy;
+ proxy = this.proxyPool[proxyId];
+ this.m_freeProxy = proxy.GetNext();
+
+ proxy.overlapCount = 0;
+ proxy.userData = userData;
+
+ var boundCount = 2 * this.m_proxyCount;
+
+ var lowerValues = new Array();
+ var upperValues = new Array();
+ this.ComputeBounds(lowerValues, upperValues, aabb);
+
+ for (var axis = 0; axis < 2; ++axis) {
+ var bounds = this.m_bounds[axis];
+ var lowerIndex = 0;
+ var upperIndex = 0;
+ var lowerIndexOut = [lowerIndex];
+ var upperIndexOut = [upperIndex];
+ this.Query(lowerIndexOut, upperIndexOut, lowerValues[axis], upperValues[axis], bounds, boundCount, axis);
+ lowerIndex = lowerIndexOut[0];
+ upperIndex = upperIndexOut[0];
+
+ // Replace memmove calls
+ //memmove(bounds + upperIndex + 2, bounds + upperIndex, (edgeCount - upperIndex) * sizeof(b2Bound));
+ var tArr = new Array();
+ var j = 0;
+ var tEnd = boundCount - upperIndex;
+ var tBound1;
+ var tBound2;
+ // make temp array
+ for (j = 0; j < tEnd; j++) {
+ tArr[j] = new box2d.Bound();
+ tBound1 = tArr[j];
+ tBound2 = bounds[upperIndex + j];
+ tBound1.value = tBound2.value;
+ tBound1.proxyId = tBound2.proxyId;
+ tBound1.stabbingCount = tBound2.stabbingCount;
+ }
+ // move temp array back in to bounds
+ tEnd = tArr.length;
+ var tIndex = upperIndex + 2;
+ for (j = 0; j < tEnd; j++) {
+ //bounds[tIndex+j] = tArr[j];
+ tBound2 = tArr[j];
+ tBound1 = bounds[tIndex + j];
+ tBound1.value = tBound2.value;
+ tBound1.proxyId = tBound2.proxyId;
+ tBound1.stabbingCount = tBound2.stabbingCount;
+ }
+ //memmove(bounds + lowerIndex + 1, bounds + lowerIndex, (upperIndex - lowerIndex) * sizeof(b2Bound));
+ // make temp array
+ tArr = new Array();
+ tEnd = upperIndex - lowerIndex;
+ for (j = 0; j < tEnd; j++) {
+ tArr[j] = new box2d.Bound();
+ tBound1 = tArr[j];
+ tBound2 = bounds[lowerIndex + j];
+ tBound1.value = tBound2.value;
+ tBound1.proxyId = tBound2.proxyId;
+ tBound1.stabbingCount = tBound2.stabbingCount;
+ }
+ // move temp array back in to bounds
+ tEnd = tArr.length;
+ tIndex = lowerIndex + 1;
+ for (j = 0; j < tEnd; j++) {
+ //bounds[tIndex+j] = tArr[j];
+ tBound2 = tArr[j];
+ tBound1 = bounds[tIndex + j];
+ tBound1.value = tBound2.value;
+ tBound1.proxyId = tBound2.proxyId;
+ tBound1.stabbingCount = tBound2.stabbingCount;
+ }
+
+ // The upper index has increased because of the lower bound insertion.
+ ++upperIndex;
+
+ // Copy in the new bounds.
+ bounds[lowerIndex].value = lowerValues[axis];
+ bounds[lowerIndex].proxyId = proxyId;
+ bounds[upperIndex].value = upperValues[axis];
+ bounds[upperIndex].proxyId = proxyId;
+
+ bounds[lowerIndex].stabbingCount = lowerIndex == 0 ? 0 : bounds[lowerIndex - 1].stabbingCount;
+ bounds[upperIndex].stabbingCount = bounds[upperIndex - 1].stabbingCount;
+
+ // Adjust the stabbing count between the new bounds.
+ for (index = lowerIndex; index < upperIndex; ++index) {
+ bounds[index].stabbingCount++;
+ }
+
+ // Adjust the all the affected bound indices.
+ for (index = lowerIndex; index < boundCount + 2; ++index) {
+ var proxy2 = this.proxyPool[bounds[index].proxyId];
+ if (bounds[index].IsLower()) {
+ proxy2.lowerBounds[axis] = index;
+ } else {
+ proxy2.upperBounds[axis] = index;
+ }
+ }
+ }
+
+ ++this.m_proxyCount;
+
+ //box2d.Settings.b2Assert(this.m_queryResultCount < box2d.Settings.b2_maxProxies);
+ for (var i = 0; i < this.m_queryResultCount; ++i) {
+ //box2d.Settings.b2Assert(this.m_queryResults[i] < b2_maxProxies);
+ //box2d.Settings.b2Assert(this.proxyPool[this.m_queryResults[i]].IsValid());
+ this.m_pairManager.AddBufferedPair(proxyId, this.m_queryResults[i]);
+ }
+
+ this.m_pairManager.Commit();
+
+ // Prepare for next query.
+ this.m_queryResultCount = 0;
+ this.IncrementTimeStamp();
+
+ return proxyId;
+};
+
+/**
+ @private
+ @type {number}
+ */
+box2d.BroadPhase.m_freeProxy = 0;
+
+box2d.BroadPhase.s_validate = false;
+box2d.BroadPhase.b2_nullEdge = box2d.Settings.USHRT_MAX;
+box2d.BroadPhase.BinarySearch = function(bounds, count, value) {
+ var low = 0;
+ var high = count - 1;
+ while (low <= high) {
+ var mid = Math.floor((low + high) / 2);
+ if (bounds[mid].value > value) {
+ high = mid - 1;
+ } else if (bounds[mid].value < value) {
+ low = mid + 1;
+ } else {
+ return (mid);
+ }
+ }
+
+ return (low);
+};
View
27 public/javascripts/box2d/collision/b2BufferedPair.js
@@ -0,0 +1,27 @@
+/*
+* Copyright (c) 2006-2007 Erin Catto http:
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked, and must not be
+* misrepresented the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+goog.provide('box2d.BufferedPair');
+
+/**
+ @constructor
+ */
+box2d.BufferedPair = function() {
+ this.proxyId1 = 0;
+ this.proxyId2 = 0;
+};
View
621 public/javascripts/box2d/collision/b2Collision.js
@@ -0,0 +1,621 @@
+/*
+* Copyright (c) 2006-2007 Erin Catto http:
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked, and must not be
+* misrepresented the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+
+goog.provide('box2d.Collision');
+
+goog.require('box2d.ClipVertex');
+
+box2d.Collision.b2_nullFeature = 0x000000ff;
+box2d.Collision.ClipSegmentToLine = function(vOut, vIn, normal, offset) {
+ // Start with no output points
+ var numOut = 0;
+
+ var vIn0 = vIn[0].v;
+ var vIn1 = vIn[1].v;
+
+ // Calculate the distance of end points to the line
+ var distance0 = goog.math.Vec2.dot(normal, vIn[0].v) - offset;
+ var distance1 = goog.math.Vec2.dot(normal, vIn[1].v) - offset;
+
+ // If the points are behind the plane
+ if (distance0 <= 0.0) vOut[numOut++] = vIn[0];
+ if (distance1 <= 0.0) vOut[numOut++] = vIn[1];
+
+ // If the points are on different sides of the plane
+ if (distance0 * distance1 < 0.0) {
+ // Find intersection point of edge and plane
+ var interp = distance0 / (distance0 - distance1);
+ // expanded for performance
+ var tVec = vOut[numOut].v;
+ tVec.x = vIn0.x + interp * (vIn1.x - vIn0.x);
+ tVec.y = vIn0.y + interp * (vIn1.y - vIn0.y);
+ if (distance0 > 0.0) {
+ vOut[numOut].id = vIn[0].id;
+ } else {
+ vOut[numOut].id = vIn[1].id;
+ } ++numOut;
+ }
+
+ return numOut;
+};
+box2d.Collision.EdgeSeparation = function(poly1, edge1, poly2) {
+ var vert1s = poly1.m_vertices;
+ var count2 = poly2.m_vertexCount;
+ var vert2s = poly2.m_vertices;
+
+ // Convert normal from into poly2's frame.
+ //box2d.Settings.b2Assert(edge1 < poly1.m_vertexCount);
+ //var normal = box2d.Math.b2MulMV(poly1.m_R, poly1->m_normals[edge1]);
+ var normalX = poly1.m_normals[edge1].x;
+ var normalY = poly1.m_normals[edge1].y;
+ var tX = normalX;
+ var tMat = poly1.m_R;
+ normalX = tMat.col1.x * tX + tMat.col2.x * normalY;
+ normalY = tMat.col1.y * tX + tMat.col2.y * normalY;
+ // ^^^^^^^ normal.MulM(poly1.m_R);
+ //var normalLocal2 = box2d.Math.b2MulTMV(poly2.m_R, normal);
+ var normalLocal2X = normalX;
+ var normalLocal2Y = normalY;
+ tMat = poly2.m_R;
+ tX = normalLocal2X * tMat.col1.x + normalLocal2Y * tMat.col1.y;
+ normalLocal2Y = normalLocal2X * tMat.col2.x + normalLocal2Y * tMat.col2.y;
+ normalLocal2X = tX;
+ // ^^^^^ normalLocal2.MulTM(poly2.m_R);
+ // Find support vertex on poly2 for -normal.
+ var vertexIndex2 = 0;
+ var minDot = Number.MAX_VALUE;
+ for (var i = 0; i < count2; ++i) {
+ //var dot = goog.math.Vec2.dot(vert2s[i], normalLocal2);
+ var tVec = vert2s[i];
+ var dot = tVec.x * normalLocal2X + tVec.y * normalLocal2Y;
+ if (dot < minDot) {
+ minDot = dot;
+ vertexIndex2 = i;
+ }
+ }
+
+ //box2d.Vec2 v1 = poly1->m_position + b2Mul(poly1->m_R, vert1s[edge1]);
+ tMat = poly1.m_R;
+ var v1X = poly1.m_position.x + (tMat.col1.x * vert1s[edge1].x + tMat.col2.x * vert1s[edge1].y);
+ var v1Y = poly1.m_position.y + (tMat.col1.y * vert1s[edge1].x + tMat.col2.y * vert1s[edge1].y);
+
+ //box2d.Vec2 v2 = poly2->m_position + b2Mul(poly2->m_R, vert2s[vertexIndex2]);
+ tMat = poly2.m_R;
+ var v2X = poly2.m_position.x + (tMat.col1.x * vert2s[vertexIndex2].x + tMat.col2.x * vert2s[vertexIndex2].y);
+ var v2Y = poly2.m_position.y + (tMat.col1.y * vert2s[vertexIndex2].x + tMat.col2.y * vert2s[vertexIndex2].y);
+
+ //var separation = goog.math.Vec2.dot( box2d.Vec2.subtract( v2, v1 ) , normal);
+ v2X -= v1X;
+ v2Y -= v1Y;
+ //var separation = goog.math.Vec2.dot( v2 , normal);
+ var separation = v2X * normalX + v2Y * normalY;
+ return separation;
+};
+box2d.Collision.FindMaxSeparation = function(edgeIndex
+/*int ptr*/
+, poly1, poly2, conservative) {
+ var count1 = poly1.m_vertexCount;
+
+ // Vector pointing from the origin of poly1 to the origin of poly2.
+ //var d = box2d.Vec2.subtract( poly2.m_position, poly1.m_position );
+ var dX = poly2.m_position.x - poly1.m_position.x;
+ var dY = poly2.m_position.y - poly1.m_position.y;
+
+ //var dLocal1 = box2d.Math.b2MulTMV(poly1.m_R, d);
+ var dLocal1X = (dX * poly1.m_R.col1.x + dY * poly1.m_R.col1.y);
+ var dLocal1Y = (dX * poly1.m_R.col2.x + dY * poly1.m_R.col2.y);
+
+ // Get support vertex hint for our search
+ var edge = 0;
+ var maxDot = -Number.MAX_VALUE;
+ for (var i = 0; i < count1; ++i) {
+ //var dot = goog.math.Vec2.dot(poly.m_normals[i], dLocal1);
+ var dot = (poly1.m_normals[i].x * dLocal1X + poly1.m_normals[i].y * dLocal1Y);
+ if (dot > maxDot) {
+ maxDot = dot;
+ edge = i;
+ }
+ }
+
+ // Get the separation for the edge normal.
+ var s = box2d.Collision.EdgeSeparation(poly1, edge, poly2);
+ if (s > 0.0 && conservative == false) {
+ return s;
+ }
+
+ // Check the separation for the neighboring edges.
+ var prevEdge = edge - 1 >= 0 ? edge - 1 : count1 - 1;
+ var sPrev = box2d.Collision.EdgeSeparation(poly1, prevEdge, poly2);
+ if (sPrev > 0.0 && conservative == false) {
+ return sPrev;
+ }
+
+ var nextEdge = edge + 1 < count1 ? edge + 1 : 0;
+ var sNext = box2d.Collision.EdgeSeparation(poly1, nextEdge, poly2);
+ if (sNext > 0.0 && conservative == false) {
+ return sNext;
+ }
+
+ // Find the best edge and the search direction.
+ var bestEdge = 0;
+ var bestSeparation;
+ var increment = 0;
+ if (sPrev > s && sPrev > sNext) {
+ increment = -1;
+ bestEdge = prevEdge;
+ bestSeparation = sPrev;
+ } else if (sNext > s) {
+ increment = 1;
+ bestEdge = nextEdge;
+ bestSeparation = sNext;
+ } else {
+ // pointer out
+ edgeIndex[0] = edge;
+ return s;
+ }
+
+ while (true) {
+
+ if (increment == -1) edge = bestEdge - 1 >= 0 ? bestEdge -