Coder Social home page Coder Social logo

marinmitev / transport-tycoon-demo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vladoschreiner/transport-tycoon-demo

0.0 1.0 0.0 21.29 MB

Collision prevention for OpenTTD (http://openttd.org/)

License: GNU General Public License v2.0

Makefile 0.06% Shell 0.23% Squirrel 0.87% Visual Basic 0.42% HTML 0.54% Roff 0.02% C++ 89.38% C 6.45% Awk 0.21% Batchfile 0.04% NSIS 0.17% Objective-C++ 0.81% Objective-C 0.75% Java 0.05%

transport-tycoon-demo's Introduction

Transport Tycoon Demo

OpenTTD collision prevention using Hazelcast Jet.

About

OpenTTD (Open Transport Tycoon Deluxe) is an open source simulation game based upon the popular Microprose game "Transport Tycoon Deluxe", written by Chris Sawyer. A player builds his empire by transporting people and material between cities and industries.

This demo extracts real-time vehicle data from OpenTTD and analyses it using Hazelcast Jet data processing engine. The analytical job in Jet predicts train collisions. A pedicted collision information is pushed back to the running OpenTTD game to stop the affected trains (and save lifes:-).

A goal is to demonstrate the possibilities of an in-memory streaming for a real-time (sub-second) processing on a large data streams.

Watch a demo recording

Watch the demo

Architecture

The source code of OpenTTD was changed to export vehicle position data. This approach was inspired by Using OpenTTD to create a realistic data stream blog. For each vehicle, the changed game code exports a JSON record with the telemetry approximatelly 30x per second.

JSON record example:


{
	"Name":"Train 4",
	"TimeStamp":"1562933209898",
	"X position":1880,
	"Y position":1480
}


The position records are sent to a the Hazelcast Jet cluster to be analysed. In-memory data structures of Hazelcast Jet are used for reliable low-latency messaging. OpenTTD is implemented in C++ and Hazelcast comes with C++ client. This allows a straightforward data extraction.

The message buffer is consumed by the analytical job residing in the Hazelcast Jet cluster. The analytical job observes the position updates for each vehicle. It predicts the vehicle position in next second based on a vehicle position one second ago and a vehicle position now (it simply extends it's motion vector). Collision is predicted if there is an intersection between two or more vectors.

Prediction visualised

This happens each 50 milliseconds. Higher resolution isn't possible as the frequency of the vehicle data is just 30 Hz (vehicle position update arrives each 30-40 millisecond for each vehicle).

The analytical job is implemented using the Pipeline API of Hazelcast Jet (see the code).

If a collision is detected, it's recorded to a K-V store in Hazelcast Jet. This store allows an event-driven programming. Storing new collision triggers an event that is delivered to the C++ client in OpenTTD. OpenTTD can stop the affected vehicles.

Pipeline

Performance

TODO:

In-memory approach to meet the low-latency requirements (collision detection + train stop duration must happen within 1 second - prediction forecast interval). Possible thanks to combining in-mem messaging, processing, event-driven programming.

Scaling to handle millions of events per second to support many game instances

Fault-tolerance using in-memory replication.

Structure

openttd directory contains a fork of OpenTTD 1.9.2 source code extended with Hazelcast 3.11 C++ client to export the data and handle the collision events. See the openttd/src/log_events.h and openttd/src/log_events.cpp for the Hazelcast integration.

vehicle-telemetry-analytics contains the messaging and the analytical infrastructure: input message buffer, stream processing cluster with the analytical job, K-V store for the detected collisions

game-positions contains the saved OpenTTD game positions that can be used for a demonstration

Prerequisites

Prerequisites of OpenTTD are covered in next section.

Building the Application

To build the Vehicle Telemetry Analytics, run:

cd vehicle-telemetry-analytics
mvn clean package

To build OpenTTD, please follow the Compiling instructions. For troubleshooting, please follow the Compiling OpenTTD guide.

Running the Application

Start Jet (Collision Detection is disabled now):

cd vehicle-telemetry-analytics
mvn exec:java -Dexec.mainClass="biz.schr.StartJet"

Start OpenTTD:

cd openttd/bin
./openttd

Load the game position from game-positions/demo1.sav. Start all deployed trains by hitting the green flag from the train overview window and see the tragedy.

Pipeline

Start the collision detector within Jet:

cd vehicle-telemetry-analytics
mvn exec:java -Dexec.mainClass="biz.schr.StartCollisionDetector"

Reload game position, launch trains and let Jet save some lifes.

Licensing

This demo is licensed under GPL 2 license

Hazelcast Jet and Hazelcast C++ client are licensed under Apache 2 license

OpenTTD is licensed under GPL 2. See more

Versions used

transport-tycoon-demo's People

Contributors

vladoschreiner avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.