OpenTTD port to Java

Overview

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!

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
Comments
  • Rails on slopes are displayed weird

    Rails on slopes are displayed weird

    Behavior of train on such slope tile is unpredictable. image image On the last image the rail is straight and train goes ahead regardless of displayed rail shape.

    bug 
    opened by alexey-lukyanenko 14
  • This repository violates OpenTTD's license; please fix ASAP

    This repository violates OpenTTD's license; please fix ASAP

    Sorry to also bother you here too, but I cannot stress enough how important this is.

    Initially we mentioned this in https://www.tt-forums.net/viewtopic.php?p=1248233#p1248233 and via Discord, but I should have done this in your repository from the start. My apologies for not realizing this earlier.

    OpenTTD is licensed under GPLv2, and by that contract, any derivative work has to be licensed under (a compatible) GPLv2 license too. Your code is (obviously) a derivative. But, your code is currently licensed under MIT, and as such, is in violation of OpenTTD's license. See https://www.gnu.org/licenses/gpl-faq.html#AllCompatibility for more details on what is possible. Be mindful of the footnotes.

    Please address this issue ASAP. As you currently only have one other contributor, it is still easy to ask @alexey-lukyanenko if they mind you relicensing from MIT to GPLv2. If you would get more contributors, this becomes harder and harder.

    Please act now. Don't delay this. I can understand this is not your primary concern, as you just want to code and have fun; and licensing is rarely classified as fun. But the sooner you get this over with, the sooner we can all enjoy working for OpenTTD and their ports!

    Thank you.

    opened by TrueBrain 1
  • Network support

    Network support

    http://underpop.online.fr/j/java/help/datagramchannel-network-dev-java-programming-language.html.gz https://www.developer.com/java/data/what-is-non-blocking-socket-programming-in-java/

    opened by dzavalishin 1
  • DrawStringMultiCenter crashes in News

    DrawStringMultiCenter crashes in News

    NewsItem.java:74, crash in Strings.java:15, parameter is null Text is '.Service subsidy awarded...'

    text ':{BLACK}{BIGFONT}Service subsidy awarded to {COMPANY}!{}{}{STRING} service from {STATION} to {STATION} will pay triple rates for the next year!'

    Supposed to eat 5 args (2 for COMPANY), but there are just 4 of them sent.

    bug 
    opened by dzavalishin 1
  • Multithreading - locks!

    Multithreading - locks!

    menuItemTranspBuildings.addActionListener( e -> 
    { 
    	Global._display_opt ^= Global.DO_TRANS_BUILDINGS;
    	Hal.MarkWholeScreenDirty();
    });
    

    MarkWholeScreenDirty(); needs to be synchronized, for it's called from awt thread

    enhancement 
    opened by dzavalishin 0
Owner
Dmitry Zavalishin
Dmitry Zavalishin
Java port of Brainxyz's Artificial Life, a simple program to simulate primitive Artificial Life using simple rules of attraction or repulsion among atom-like particles, producing complex self-organzing life-like patterns.

ParticleSimulation simple Java port of Brainxyz's Artificial Life A simple program to simulate primitive Artificial Life using simple rules of attract

Koonts 3 Oct 5, 2022
Minecraft Multi-Threading Mod Fabric Port

MCMTFabric - Minecraft Multi-Threading Mod Fabric Port This mod is based on the amazing work on JMT-MCMT. Please check that repository for details. No

Grider 108 Dec 30, 2022
OptiFine 1.7.3 HD MT G2 (+ Long Distance Patch) port to Fabric.

Fabric Example Mod with StationAPI and BIN Mappings for beta 1.7.3 server + client Setup See the StationAPI wiki. Common Issues Here. License This tem

null 4 Dec 2, 2022
Port of the forge api to fabric, under the same path.

MinecraftForge Forge is a free, open-source modding API all of your favourite mods use! Version Support 1.18.x Active 1.16.x LTS Download Forum Discor

null 16 Dec 6, 2022
Golden Axe (1989) game implemented in java using only standard libraries (Java 2D, Swing, AWT & Java Sound API)

Golden Axe (1989) game implemented in java using only standard libraries (Java 2D, Swing, AWT & Java Sound API), so no external libraries required. Video: https://youtu.be/uevIVLNhQqs

Leo 101 Jul 21, 2022
It is a simple java terminal game. I built it in order to practice my code skills that I obtained while I was learning Java.

Java-terminal-game It is a simple java terminal game. I built it in order to practice my code skills that I obtained while I was learning Java. The ga

Baistan Tashkulov 0 Jan 20, 2022
A Java Game Engine created in Java with LWJGL!

?? Suffler Engine Suffler Game Engine is an engine created in java using OpenGL to Graphics. Currently being developed at Eclipse, and Visual Studio C

Suffler Engine 2 Jul 23, 2022
Desktop/Android/HTML5/iOS Java game development framework

Cross-platform Game Development Framework libGDX is a cross-platform Java game development framework based on OpenGL (ES) that works on Windows, Linux

libgdx 20.9k Jan 1, 2023
A complete 3D game development suite written purely in Java.

jMonkeyEngine jMonkeyEngine is a 3-D game engine for adventurous Java developers. It’s open-source, cross-platform, and cutting-edge. 3.2.4 is the lat

jMonkeyEngine 3.3k Dec 31, 2022
LWJGL is a Java library that enables cross-platform access to popular native APIs useful in the development of graphics (OpenGL, Vulkan), audio (OpenAL), parallel computing (OpenCL, CUDA) and XR (OpenVR, LibOVR) applications.

LWJGL - Lightweight Java Game Library 3 LWJGL (https://www.lwjgl.org) is a Java library that enables cross-platform access to popular native APIs usef

Lightweight Java Game Library 4k Dec 29, 2022
Java / JavaFX / Kotlin Game Library (Engine)

About JavaFX Game Development Framework Why FXGL? No installation or setup required "Out of the box": Java 8-15, Win/Mac/Linux/Android 8+/iOS 11.0+/We

Almas Baimagambetov 3k Jan 2, 2023
Jetserver is a high speed nio socket based multiplayer java game server written using Netty and Mike Rettig's Jetlang.It is specifically tuned for network based multiplayer games and supports TCP and UDP network protocols.

Note New version of Jetserver is called Nadron and is in a new netty 4 branch of this same repo. JetServer is a java nio based server specifically des

Abraham Menacherry 1.2k Dec 14, 2022
[LEGACY] LWJGL 2.X - The Lightweight Java Game Library.

[LEGACY] LWJGL - Lightweight Java Game Library WARNING This is the repository of the original LWJGL, which is no longer actively maintained. Unless yo

Lightweight Java Game Library 529 Dec 26, 2022
A Java game development framework that deploys to JVM, HTML5, Android and iOS.

PlayN PlayN is a cross-platform Java game development library written in Java that targets HTML5 browsers (via GWT), desktop JVMs, Android and iOS dev

null 237 Dec 9, 2022
A fast, customizable and compatible open source server for Minecraft: Java Edition

Glowstone A fast, customizable and compatible open source server for Minecraft: Java Edition. Introduction Glowstone is a lightweight, from scratch, o

Glowstone Project 1.7k Dec 31, 2022
A Java user-interface library with support for Minecraft.

interfaces Building interfaces since 2021. interfaces is a builder-style user interface library designed to make creation of flexible user interfaces

Incendo 54 Dec 24, 2022
Java mod library

GasLirary GasLirary is a Mindustry java mod library for making new content type: Gas. Usage/Examples Gas creating Gas is created in the same way as It

null 10 Jan 2, 2023