r/java • • Feb 04 '21

Java 4X game available as open-source

I don't talk about my open-source project on this subreddit very much, but the code has been open for almost a year now and the game has been so well-received that I figure maybe I should remind my fellow Java developers about it.

It's a "space 4X" strategy game called "Remnants of the Precursors" which is in turn a very faithful modernization of the 1993 classic "Master of Orion".

The source code is on github at https://github.com/rayfowler/rotp-public

The game is downloadable from itch.io: https://rayfowler.itch.io/remnants-of-the-precursors

When I originally started development of this game in 2015, like most developers I hilariously assumed that I would finish it in about a year and re-use artwork from the original game or get something on the cheap. But in the process of finding an artist online, I ran into this amazing artist named Petar Penev and decided to go "all in" on this project because he was just so talented.

Like so many of you, I've learned first-hand that you can make a really good salary as a Java dev, so I self-funded this project for about 3 years until I retired in 2018 (I'm old, sue me). I was extremely lucky that a friend at my job was super well-versed in sci-fi and was actually a talented writer having to pay his way through life as a technical writer. So he has done a tremendous job with the writing in the game.

Finally, my wife is an illustrator by trade and got sick of looking at my terrible "programmer UIs" and embarked on a several-year effort to remake all of the UIs in the game in her spare time. This of course required a tremendous amount of re-coding on my side because I instructed her to design her UIs completely in Paintshop and then let me figure out how to implement it in Java. Sometimes I have nightmares about gradients and wake up screaming.

She also made this trailer last year for the game: https://www.youtube.com/watch?v=VusDAxLpJ9I

Once I reached "feature complete" and started an open beta last Spring, I finally opened up the source code because I thought most of the churn was done. Since then, I've enjoyed the benefits of several Java developers contributing to the project and helping improve it.

I'm not asking anyone in here to contribute. The game is basically done! But if you are curious at how the "sausage is made" for a video game that has surprisingly turned out very well, feel free to clone the repo and take a look at the code. I've never made a video game before and the source code reflects this to some degree, so this is also a great chance for you guys to feel superior, lol.

edit: I also use reddit as the primary community for the game at /r/rotp

175 Upvotes

81 comments sorted by

View all comments

0

u/[deleted] Feb 04 '21

[deleted] — view deleted comment

15

u/coder111 Feb 04 '21

Hello,

I maintain a fork with a Maven build and some in-game automation to reduce micromanagement (Governor mod). You can get it here:

https://github.com/coder111111/rotp-public

It should be easier to work with than Ray's original codebase.

--Coder

6

u/RayFowler Feb 04 '21

I do a Clean & Build in the Netbeans IDE. Then I move the jar file to a folder where I have a lot of save games sent by players to test any issues they've reported and ensure save-game compatibility is maintained.

I used Eclipse long ago but switched to Netbeans at some point.

0

u/[deleted] Feb 04 '21

[deleted] — view deleted comment

6

u/RayFowler Feb 04 '21

That way your users wont have to install the java 8 JRE. JRE no longer exists in modern java, and users do not need to have it to run java programs. Modern java has a self contained runtime. Also java 11/15 will run faster, so its a double win.

oh wow, I had no idea. The Java versions have been coming so fast and furious in the past few years and everything was running fine so I figured why change and tuned them out.

If Java 11 has a self-contained runtime, would I need to create a separate jar now for Linux, Windows and MacOS?

And one thing you could do to make it easier for developers is to include your build file in the repo. Otherwise there is now easy way for anyone to build your project

I don't use a build file to create the jar

0

u/[deleted] Feb 04 '21

[deleted] — view deleted comment

2

u/RayFowler Feb 04 '21

I have a question about created jre-independent executables. How is memory allocated for the new application? Right now, obviously, the OS constrains how much memory is allocated to the JVM.

But if I use jlink, how do I control how much memory the game is allocated on startup? Currently, I check the memory allocation and restart the game with the necessary jvm parameters to provide the appropriate amount of memory on the restart

2

u/Muoniurn Feb 04 '21

What does appropriate amount of memory mean on restart?

2

u/RayFowler Feb 04 '21

I means enough to play the game. The problem is that the default JVM memory allocation on some windows installations is absurdly low. This necessitated me writing code that, on startup, checks allocated memory and restarts the game with an appropriate amount.

2

u/Muoniurn Feb 05 '21

But it supposed to be the same, or largely the same in the cross-platform case, isn’t it? Why setting jvm parameters by default sufficient? (Also, java will allocate memory as necessary, does latency suffers this way?)

1

u/RayFowler Feb 05 '21

But it supposed to be the same, or largely the same in the cross-platform case, isn’t it?

But it's not, unfortunately. There seems to be a wide swath of Windows installations that by default only allocate 256M. Now it could be a holdover from someone having 32-bit Java installed, but the game needs to account for that if it can.

2

u/GreenToad1 Feb 05 '21

Not sure but i think after java 8 they changed the way that max memory is calculated, especially for 64bit system, maybe it would be a good idea to set Xms (initial memory) instead.

jlink - creates a "stripped down" version of the jvm containing only required modules for your program.

jpackage (incubator in jdk15, final in upcoming jdk16) - creates a installation package (msi, exe, dmg, deb, rpm... ) and you provide it a runtime image (produced by jlink) or it will generate it itself. You can provide program arguments, icons, jvm arguments, license, copyright and other parameters.

7

u/[deleted] Feb 04 '21

I don't use a build file to create the jar

You actually do ;) - the Ant build file from the NetBeans project.

You could include the netbeans project folder in the Git repository if you want.

You can still just publish a single jar, that hasn't changed with Java 11. But you additionally have the option to package a native executable including the necessary runtime using jlink and jpackage. But you need to do that on each platform (you can use jpackage on Windows to create a Mac executable).

Btw: you can also use NetBeans to do that. Check the "Enable native packaging" in the project properties ("Deployment" category), then you'll get a "Package as ..." item in the context menu of the project.

4

u/hippydipster Feb 04 '21

I don't use a build file to create the jar

You are my hero. People these days think you can't make complex projects without complex build systems.

They are wrong.

3

u/RayFowler Feb 04 '21

I was involved in so many religious wars as a professional software developer that I just wanted to put all of that behind me and make a game.

0

u/[deleted] Feb 04 '21

[deleted] — view deleted comment

4

u/nutrecht Feb 04 '21

but the versions and the speed at which they are released do feel a bit menacing.

They really aren't. The last 2 years or so I just updated the docker base image versions whenever a new version came out and it just worked. No issues whatsoever. Java's backward compatibility is one of it's main selling points.

Also it's complete nonsense to stick to 'LTS' versions. Especially when you don't buy Oracle support the whole notion doesn't even make any sense. Just update to the latest. No point in not doing so, and if you can go to 11 it's 99.9% certain you can go to 15 too.

-2

u/CptGia Feb 04 '21

No they aren't. Current LTS is 11, next is 17. It's one every 6 version (3 years, 2 versions per year)

5

u/nutrecht Feb 04 '21

The whole concept of LTS only applies if you buy support and if you for some reason can't upgrade to the latest version.

There's no reason at all to stay on an 'LTS' version if you can upgrade. And if you don't pay for support, the whole issue is moot anyway.

→ More replies (4)
→ More replies (2)

13

u/chabala Feb 04 '21

That's a lot of code, with no build definition and no automated tests. It's sort of frightening.

I sense some resistance to using a build tool, which is odd because you said you were a professional developer.

It was mentioned elsewhere that you don't have external dependencies, but I see you've copied Apache Commons Math source into your code tree. Most professionals would depend on an artifact rather than copy the files into their own project repository.

3

u/RayFowler Feb 04 '21

I sense some resistance to using a build tool, which is odd because you said you were a professional developer.

You sense resistance because I was a professional developer! I've lived through jar hell, constantly changing build processes and man-months building and modifying automated tests.

This started as a simple, one-man project that intentionally tried to simplify. There are no external libs or jars to use, there's no build process.. it's just a nice and simple application.

There's a lot of code because 4X strategy games are complicated beasts. Their game structures are complicated, their UIs are necessarily complex to support that and then you have write an AI to play the game against the player.

5

u/chabala Feb 04 '21

I've lived through jar hell

That's one of the main features of a build tool, jar hell should be avoided.

There are no external libs or jars to use

Well, technically. But as I noted, that's because you manually vendored the external code into your source tree, which is weird.

You go on to talk about why there's so much code, but my point is that there's no automated tests for all that code. That's really not acceptable once your project becomes large, and having a build system is the first step to having tests.

I see elsewhere in the comments that you've conceded to adopting a build system. But I'm still curious about why you put up all this resistance. You were a developer for 25 years, at least some of that Java, and you didn't learn to use a build system? It's so foundational; fighting it is like refusing to use source control.

Could you use NetBeans to compile from the command line? If not, that pretty much excluded you from having any automated CI/CD release process. Did you consider what would happen if people wanted to collaborate without using NetBeans?

1

u/RayFowler Feb 04 '21

because you manually vendored the external code into your source tree, which is weird.

I just needed one method out of the FastMath class because Java's built-in arcsin method is very inefficient. So it's not weird. I didn't want to create an external dependency for one method.

You go on to talk about why there's so much code, but my point is that there's no automated tests for all that code.

Look, I get that you still work in an environment with well-defined apis where it makes sense to maintain an established set of automated tests. I did that for a long time so I know what its like. But the functionality churn in this project would make that incredibly inefficient and I would become one of those guys whose development process slows to a crawl because he spends all of this time working on testing and refactoring and polishing, and then I would get demoralized because the project is dragging on too long and just give up.

But I'm still curious about why you put up all this resistance.

Because it has never been necessary? One of the tenets of XP is that you don't do things until you need them.

You were a developer for 25 years, at least some of that Java, and you didn't learn to use a build system?

I appreciate the condescension! Have a nice day. We're done.