Giter Club home page Giter Club logo

jdrive's Introduction

NextTTD (JDrive)

This is an OpenTTD port to Java.

Java CI

Current state: The game is basically playable - aircrafts, trains, ships and road vehicles are working. But Save/load is not completely tested.

You're welcome to take part in testing and/or development!

News

  • AI is operational
  • Language packs support restored
  • Sounds/MIDI music are working

Screenshots:

27 Aug 2021

23 Aug 2021

What for

OpenTTD is beautiful. But it still carries on most of the original TTD architectural solutions. Bit banging, obscure data structures and crazy assembler style encoding of tile state.

It's time to move on.

My goals:

  • Reduce code complexity and obscurity. Core functions code must be twice shorter in terms of byte count.
  • No more bit fields and C/asm style polymorphism. Make code more OO and, where possible, functional.
  • Make game save automatic. No manual enumeration of fields to save.

As a result game code must be really easy to understand and modify.

Example:

Obscure and long:

FOR_ALL_INDUSTRIES(ind) {
	if (ind->xy != 0 && (cargo_type == ind->accepts_cargo[0] || cargo_type
			 == ind->accepts_cargo[1] || cargo_type == ind->accepts_cargo[2]) &&
			 ind->produced_cargo[0] != CT_INVALID &&
			 ind->produced_cargo[0] != cargo_type &&
			 (t = DistanceManhattan(ind->xy, xy)) < 2 * u) 
	{
		...
	}
}

Easy to understand and short:

Industry.forEach( ind ->
{			
	if (ind.isValid() && ind.acceptsCargo(cargo_type) 
			&& !ind.producesCargo(cargo_type)
			&& (t = Map.DistanceManhattan(ind.xy, xy)) < 2 * u[0]) 
	{
		...
	}
});

One more example. Code:

static bool AnyTownExists(void)
{
	const Town* t;

	FOR_ALL_TOWNS(t) {
		if (t->xy != 0) return true;
	}
	return false;
}

Becomes:

public static boolean anyTownExist()
{
	return stream().anyMatch( t -> t.isValid() );
}

Why Java

  • Portability for free. It just runs everywhere. Really.
  • Cleaner code. (Not yet, but I'm on my way:)
  • It is easier to build complex data structures in a language with GC.
  • Mature graphics, sound and midi subsystems

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.