Initial commit

This commit is contained in:
2025-12-15 14:43:40 +01:00
commit 20eb1e8979
17 changed files with 613 additions and 0 deletions
@@ -0,0 +1,20 @@
package be.seeseemelk.diceos;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.graphics.glutils.HdpiMode;
import io.avaje.inject.BeanScope;
public class Bootloader {
public static void main(String[] args) {
try (var beanScope = BeanScope.builder().build()) {
var config = new Lwjgl3ApplicationConfiguration();
config.setTitle("DiceOS");
config.setWindowedMode(640+12, 360);
// config.setFullscreenMode(Lwjgl3ApplicationConfiguration.getDisplayMode());
//config.setResizable(false);
config.setHdpiMode(HdpiMode.Pixels);
new Lwjgl3Application(beanScope.get(DiceOS.class), config);
}
}
}
@@ -0,0 +1,73 @@
package be.seeseemelk.diceos;
import be.seeseemelk.diceos.system.DisplayService;
import be.seeseemelk.diceos.system.OnStartup;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.utils.ScreenUtils;
import com.badlogic.gdx.utils.viewport.FillViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import io.avaje.inject.Component;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
@Slf4j
@Component
@RequiredArgsConstructor
public class DiceOS extends ApplicationAdapter {
private final DisplayService display;
private final List<OnStartup> startupTasks;
private Texture background;
private Texture border;
private Viewport viewport;
@Override
public void create() {
log.info("DiceOS starting...");
background = new Texture("src/main/resources/background.png");
border = new Texture("src/main/resources/border.png");
viewport = new FillViewport(2, 2);
for (var task : startupTasks) {
task.onStartup();
}
log.info("DiceOS started!");
}
@Override
public void render() {
display.getScreenBuffer().begin();
viewport.apply();
display.getBatch().setProjectionMatrix(viewport.getCamera().combined);
display.getBatch().begin();
ScreenUtils.clear(Color.GREEN);
for (int y = 0; y < display.getHeight(); y += 8) {
for (int x = 0; x < display.getWidth(); x += 8) {
display.draw(background, x, y);
}
}
var param = new DisplayService.Parameters();
display.draw(border, 0, 0, param);
param.flipX = true;
display.draw(border, display.getWidth() - 8, 0, param);
param.flipY = true;
display.draw(border, display.getWidth() - 8, display.getHeight() - 8, param);
param.flipX = false;
display.draw(border, 0, display.getHeight() - 8, param);
display.getBatch().end();
display.getScreenBuffer().end();
display.getBatch().begin();
display.getBatch().draw(display.getScreenBuffer().getColorBufferTexture(),
0, 0);
display.getBatch().end();
}
}
@@ -0,0 +1,53 @@
package be.seeseemelk.diceos.system;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import io.avaje.inject.Component;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RequiredArgsConstructor
@Component
public class DisplayService implements OnStartup {
@Getter
private FrameBuffer screenBuffer;
@Getter
private SpriteBatch batch;
// private final GraphicsFactory graphicsFactory;
@Override
public void onStartup() {
screenBuffer = new FrameBuffer(Pixmap.Format.RGBA8888, getWidth(), getHeight(), false);
batch = new SpriteBatch();
}
public int getWidth() {
return 640;
}
public int getHeight() {
return 360;
}
public void draw(Texture texture, int x, int y) {
draw(texture, x, y, Parameters.DEFAULT);
}
public void draw(Texture texture, int x, int y, Parameters params) {
batch.draw(texture,
x, getHeight() - y - texture.getHeight(), texture.getWidth(), texture.getHeight(),
0, 0, texture.getWidth(), texture.getHeight(),
params.flipX, params.flipY);
}
public static class Parameters {
public final static Parameters DEFAULT = new Parameters();
public boolean flipX;
public boolean flipY;
}
}
@@ -0,0 +1,8 @@
package be.seeseemelk.diceos.system;
/**
* Interface for components that need to perform actions on system startup.
*/
public interface OnStartup {
void onStartup();
}
@@ -0,0 +1,17 @@
package be.seeseemelk.diceos.system.gfx;
import io.avaje.inject.AssistFactory;
import lombok.RequiredArgsConstructor;
/**
* Graphics context and rendering utilities.
*/
@RequiredArgsConstructor
@AssistFactory(GraphicsFactory.class)
public class Graphics {
// private final
//
// public void begin() {
//
// }
}
@@ -0,0 +1,5 @@
package be.seeseemelk.diceos.system.gfx;
public interface GraphicsFactory {
Graphics create();
}
@@ -0,0 +1,7 @@
package be.seeseemelk.diceos.system.math;
import io.avaje.inject.Component;
@Component
public class RandomService {
}
@@ -0,0 +1,18 @@
package be.seeseemelk.diceos.system.math;
/**
* Implementation of the Zanzlanz's Football Formula.
* @see https://www.youtube.com/watch?v=XDsYPXRCXAs
*/
public class ZanzlanzFootballFormula {
private int state = 1;
/**
* Generates the next pseudo-random number using Zanzlanz's Football Formula.
*
* @return the next pseudo-random number
*/
public void nextIteration() {
state = (state * 25 + 102803) % 236196;
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 B