Compare commits
16 Commits
newtps
...
moduleSyst
Author | SHA1 | Date | |
---|---|---|---|
8c7c37c9c0 | |||
3b24ee0531 | |||
953614a7d8 | |||
7f57510ac8 | |||
c7842935ba | |||
f520d4b2c6 | |||
5a06788652 | |||
56e9be727b | |||
e795d76367 | |||
a9724d9d4c | |||
3859db5b27 | |||
513feb1093 | |||
531a8c99c3
|
|||
942c665d73 | |||
5a521fc131 | |||
361d795ab1 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -37,3 +37,4 @@ build_packages/NSIS/*
|
||||
!build_packages/DEB
|
||||
build_packages/DEB/*
|
||||
!build_packages/DEB/template
|
||||
*.log
|
||||
|
@ -111,7 +111,9 @@ switch (OperatingSystem.current()) {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
|
||||
|
||||
implementation 'org.jetbrains:annotations:20.1.0'
|
||||
implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
|
||||
|
||||
implementation "org.lwjgl:lwjgl"
|
||||
implementation "org.lwjgl:lwjgl-glfw"
|
||||
|
69
docs/CONTRIBUTING.md
Normal file
69
docs/CONTRIBUTING.md
Normal file
@ -0,0 +1,69 @@
|
||||
# Contributing Guidelines
|
||||
|
||||
This document lists conventions adopted by Progressia developers.
|
||||
|
||||
## git
|
||||
|
||||
### Branches
|
||||
Progressia repository contains a `master` branch and several "feature" branches.
|
||||
|
||||
`master` is expected to contain a version of the game suitable for demonstration and forking/branching. Do not commit directly to `master` without OLEGSHA's approval.
|
||||
- `master` must always correctly build without compiler warnings (see below).
|
||||
- `master` must always pass all unit tests.
|
||||
- `master` must always be able to launch successfully.
|
||||
- `master` must always only contain working features.
|
||||
- `master` should not contain excessive debug code.
|
||||
- `master` must always have its code and filenames formatted (see below).
|
||||
|
||||
"Feature" branches are branches dedicated to the development of a single feature. When the feature reaches completion the branch is merged into `master` and removed. Intermediate merges into `master` may occur when some fitting milestone is reached. Intermediate merges from `master` may be done as necessary. Merges between "feature" branches should generally be avoided.
|
||||
|
||||
When beginning work on a new feature, create a new branch based on `master` (or on another "feature" branch if absolutely necessary). Use `all-small-with-dashes` to name the branch: `add-trees` or `rebalance-plastics` are good names. Do not fix unrelated bugs or work on unrelated features in a "feature" branch - create a new one, switch to an existing one or commit directly to `master` if the changes are small enough.
|
||||
|
||||
"Feature" branches may not be formatted properly. Formatting is required before merging into `master` or other branches.
|
||||
|
||||
### Commits
|
||||
- Commits must leave the branch in a state that builds without compiler warnings (see below).
|
||||
- Changes should be grouped in commits semantically. Avoid committing many small related changes in sequence; if necessary, wait and accumulate them. Avoid committing unrelated changes together; if necessary, split staged changes into several commits. This should normally result in about 1-2 commits for a day's work.
|
||||
- Commit bulk changes (renaming, formatting, ...) separately. Don't ever commit whitespace changes outside formatting commits.
|
||||
- Message format:
|
||||
|
||||
```
|
||||
Short description of changes
|
||||
<empty line>
|
||||
- Enumeration of changes
|
||||
- Nest when appropriate
|
||||
- Use dashes only
|
||||
- List not needed for small commits
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
Changed packages for relations, renamed Face to ShapePart
|
||||
|
||||
- Added BlockRelation as an abstract superclass to existing relations
|
||||
- Must be given an absolute "up" direction before use
|
||||
- Moved AbsFace, AbsRelation and BlockRelation to .world.rels
|
||||
- Renamed Face to ShapePart to reduce confusion with AbsFace
|
||||
```
|
||||
|
||||
- Only commit changes described in the commit message. Please double-check staged files before committing.
|
||||
- Avoid merge conflicts. Pull before committing.
|
||||
- Better sign commits than not. See: [git](https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work), [GitHub](https://docs.github.com/en/github/authenticating-to-github/managing-commit-signature-verification).
|
||||
|
||||
## Code
|
||||
|
||||
### Warnings
|
||||
Make sure that all committed code contains no compiler warnings. This specifically includes unused imports, unused private members, missing `@Override`s and warnings related to generics.
|
||||
|
||||
Warnings about unknown tokens in `@SuppressWarnings` are temporarily ignored. Please disable them in your IDE.
|
||||
|
||||
### Code Style
|
||||
Formatting code is important.
|
||||
|
||||
- The format is specified within the files inside `/templates_and_presets/eclipse_ide`. Import the specifications into Eclipse or IntelliJ IDEA and use the IDEs' format feature. Alternatively format the code manually in accordance with existing files.
|
||||
- Only use tabs for indentation. Never indent with spaces even when wrapping lines. This is to ensure that indentation does not break when tab width is different.
|
||||
- Don't use `I` prefix for interfaces (not `IDoable` but `Doable`).
|
||||
- Prioritize readability over compactness. Do not hesitate to use (very) long identifiers if they aid comprehension.
|
||||
- Document all mathematics unless it is trivial, especially when using math notation for variable names.
|
||||
- Use proper English when writing comments. Avoid boxes in comments. Use `//` for single-line comments.
|
@ -28,6 +28,7 @@ import ru.windcorp.progressia.client.graphics.font.Typefaces;
|
||||
import ru.windcorp.progressia.client.graphics.texture.Atlases;
|
||||
import ru.windcorp.progressia.client.graphics.world.WorldRenderProgram;
|
||||
import ru.windcorp.progressia.client.localization.Localizer;
|
||||
import ru.windcorp.progressia.common.modules.TaskManager;
|
||||
import ru.windcorp.progressia.common.resource.ResourceManager;
|
||||
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
||||
import ru.windcorp.progressia.server.ServerState;
|
||||
@ -57,6 +58,8 @@ public class ClientProxy implements Proxy {
|
||||
Atlases.loadAllAtlases();
|
||||
|
||||
AudioSystem.initialize();
|
||||
TaskManager.getInstance().startLoading();
|
||||
|
||||
|
||||
ServerState.startServer();
|
||||
ClientState.connectToLocalServer();
|
||||
|
@ -15,24 +15,38 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package ru.windcorp.progressia.client.audio;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import ru.windcorp.progressia.common.modules.Module;
|
||||
import ru.windcorp.progressia.common.modules.Task;
|
||||
import ru.windcorp.progressia.common.modules.TaskManager;
|
||||
import ru.windcorp.progressia.common.resource.ResourceManager;
|
||||
|
||||
public class AudioSystem {
|
||||
static public void initialize() {
|
||||
Module audioModule = new Module("AudioModule:System");
|
||||
AudioManager.initAL();
|
||||
Thread shutdownHook = new Thread(AudioManager::closeAL, "AL Shutdown Hook");
|
||||
Runtime.getRuntime().addShutdownHook(shutdownHook);
|
||||
loadAudioData();
|
||||
|
||||
Task t = new Task("AudioSystem:Initialize") {
|
||||
@Override
|
||||
protected void perform() {
|
||||
loadAudioData();
|
||||
LogManager.getLogger().info("Audio data is loaded");
|
||||
}
|
||||
};
|
||||
audioModule.addTask(t);
|
||||
TaskManager.getInstance().registerModule(audioModule);
|
||||
}
|
||||
|
||||
static void loadAudioData() {
|
||||
AudioManager.loadSound(
|
||||
ResourceManager.getResource("assets/sounds/block_destroy_clap.ogg"),
|
||||
"Progressia:BlockDestroy",
|
||||
AudioFormat.MONO
|
||||
ResourceManager.getResource("assets/sounds/block_destroy_clap.ogg"),
|
||||
"Progressia:BlockDestroy",
|
||||
AudioFormat.MONO
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,83 +0,0 @@
|
||||
package ru.windcorp.progressia.client.graphics.gui;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import glm.mat._4.Mat4;
|
||||
import glm.vec._2.i.Vec2i;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import ru.windcorp.progressia.client.graphics.backend.InputTracker;
|
||||
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
||||
import ru.windcorp.progressia.client.graphics.font.Font;
|
||||
import ru.windcorp.progressia.client.graphics.Colors;
|
||||
import ru.windcorp.progressia.client.graphics.gui.event.FocusEvent;
|
||||
import ru.windcorp.progressia.client.graphics.gui.event.HoverEvent;
|
||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
||||
import ru.windcorp.progressia.client.graphics.input.bus.InputListener;
|
||||
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
||||
|
||||
public class Button extends Interactable {
|
||||
|
||||
public <T extends InputEvent> Button(String name, Label textLabel, Consumer<Button> onClick) {//, InputListener<T> onClick, Class<? extends T> onClickClass) {
|
||||
super(name, textLabel);
|
||||
setPreferredSize(107,34);
|
||||
//Button inButton = (Button) setFocusable(true);
|
||||
|
||||
addListener((Class<KeyEvent>) KeyEvent.class, (InputListener<KeyEvent>) e -> {if ((e.isLeftMouseButton() && containsCursor()) || (e.getKey()==GLFW.GLFW_KEY_ENTER && isFocused()) )
|
||||
{
|
||||
isClicked = e.isPress();
|
||||
if (!isDisabled())
|
||||
{
|
||||
onClick.accept(this);
|
||||
takeFocus();
|
||||
}
|
||||
requestReassembly();
|
||||
return true;
|
||||
}
|
||||
return false;});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assembleSelf(RenderTarget target) {
|
||||
//Border
|
||||
if (isDisabled())
|
||||
{
|
||||
target.fill(getX(), getY(), getWidth(), getHeight(), 0xFFE5E5E5);
|
||||
}
|
||||
else if (isClicked() || isHovered() || isFocused())
|
||||
{
|
||||
target.fill(getX(), getY(), getWidth(), getHeight(), 0xFF37A2E6);
|
||||
}
|
||||
else
|
||||
{
|
||||
target.fill(getX(), getY(), getWidth(), getHeight(), 0xFFCBCBD0);
|
||||
}
|
||||
//Inside area
|
||||
if (!isClicked() && isHovered() && !isDisabled())
|
||||
{
|
||||
target.fill(getX()+2, getY()+2, getWidth()-4, getHeight()-4, 0xFFC3E4F7);
|
||||
}
|
||||
else if (!isClicked() || isDisabled())
|
||||
{
|
||||
target.fill(getX()+2, getY()+2, getWidth()-4, getHeight()-4, Colors.WHITE);
|
||||
}
|
||||
Font tempFont = new Font().withColor(Colors.BLACK);
|
||||
if (isDisabled())
|
||||
{
|
||||
tempFont = tempFont.withColor(Colors.GRAY_A);
|
||||
}
|
||||
else if (isClicked())
|
||||
{
|
||||
tempFont = tempFont.withColor(Colors.WHITE);
|
||||
}
|
||||
|
||||
target.pushTransform(new Mat4().identity().translate( getX()+.5f*getWidth()-.5f*label.getPreferredSize().x, getY(), 0));
|
||||
label = new Label(label.getName(), tempFont, label.getContentSupplier());
|
||||
label.assembleSelf(target);
|
||||
target.popTransform();
|
||||
}
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
package ru.windcorp.progressia.client.graphics.gui;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import glm.mat._4.Mat4;
|
||||
import glm.vec._2.i.Vec2i;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import ru.windcorp.progressia.client.graphics.backend.InputTracker;
|
||||
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
||||
import ru.windcorp.progressia.client.graphics.font.Font;
|
||||
import ru.windcorp.progressia.client.graphics.Colors;
|
||||
import ru.windcorp.progressia.client.graphics.gui.event.FocusEvent;
|
||||
import ru.windcorp.progressia.client.graphics.gui.event.HoverEvent;
|
||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
||||
import ru.windcorp.progressia.client.graphics.input.bus.InputListener;
|
||||
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
||||
|
||||
public class Checkbox extends Interactable {
|
||||
|
||||
private boolean isActive;
|
||||
|
||||
public <T extends InputEvent> Checkbox(String name, Label textLabel, Consumer<Checkbox> onSet, Consumer<Checkbox> onReset) {//, InputListener<T> onClick, Class<? extends T> onClickClass) {
|
||||
super(name, textLabel);
|
||||
setPreferredSize(44 + textLabel.getPreferredSize().x,textLabel.getPreferredSize().y);
|
||||
//Checkbox inCheck = (Checkbox) setFocusable(true);
|
||||
|
||||
addListener((Class<KeyEvent>) KeyEvent.class, (InputListener<KeyEvent>) e -> {if (e.isLeftMouseButton() && containsCursor()|| (e.getKey()==GLFW.GLFW_KEY_ENTER && isFocused()))
|
||||
{
|
||||
isClicked = e.isPress();
|
||||
if (!isDisabled())
|
||||
{
|
||||
if (!isClicked && !isActive)
|
||||
{
|
||||
onSet.accept(this);
|
||||
isActive = !isActive;
|
||||
}
|
||||
else if (!isClicked && isActive)
|
||||
{
|
||||
onReset.accept(this);
|
||||
isActive = !isActive;
|
||||
}
|
||||
else if (isClicked)
|
||||
{
|
||||
takeFocus();
|
||||
}
|
||||
}
|
||||
requestReassembly();
|
||||
return true;
|
||||
}
|
||||
return false;});
|
||||
}
|
||||
|
||||
public boolean isActive()
|
||||
{
|
||||
return isActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assembleSelf(RenderTarget target) {
|
||||
//Border
|
||||
if (isDisabled())
|
||||
{
|
||||
target.fill(getX()+label.getPreferredSize().x, getY(), getWidth()-label.getPreferredSize().x, getHeight(), 0xFFE5E5E5);
|
||||
}
|
||||
else if (isClicked() || isHovered() || isFocused())
|
||||
{
|
||||
target.fill(getX()+label.getPreferredSize().x, getY(), getWidth()-label.getPreferredSize().x, getHeight(), 0xFF37A2E6); // blue
|
||||
}
|
||||
else
|
||||
{
|
||||
target.fill(getX()+label.getPreferredSize().x, getY(), getWidth()-label.getPreferredSize().x, getHeight(), 0xFFCBCBD0);
|
||||
}
|
||||
//Inside area
|
||||
if (!isClicked() && isHovered() && !isDisabled())
|
||||
{
|
||||
target.fill(getX()+2+label.getPreferredSize().x, getY()+2, getWidth()-label.getPreferredSize().x-4, getHeight()-4, 0xFFC3E4F7); // light blue
|
||||
}
|
||||
else if (!isClicked() || isDisabled())
|
||||
{
|
||||
target.fill(getX()+2+label.getPreferredSize().x, getY()+2, getWidth()-label.getPreferredSize().x-4, getHeight()-4, Colors.WHITE);
|
||||
}
|
||||
if (isActive() && !isClicked())
|
||||
{
|
||||
if (isDisabled())
|
||||
{
|
||||
target.fill(getX()+getWidth()-getHeight()+4, getY()+4, getHeight()-8, getHeight()-8, 0xFFB3D7EF);
|
||||
}
|
||||
else
|
||||
{
|
||||
target.fill(getX()+getWidth()-getHeight()+4, getY()+4, getHeight()-8, getHeight()-8, 0xFF37A2E6); // blue
|
||||
}
|
||||
}
|
||||
else if (!isClicked())
|
||||
{
|
||||
if (isDisabled())
|
||||
{
|
||||
target.fill(getX()+label.getPreferredSize().x+4, getY()+4, getHeight()-8, getHeight()-8, 0xFFE5E5E5);
|
||||
}
|
||||
else if (isFocused() || isHovered())
|
||||
{
|
||||
target.fill(getX()+label.getPreferredSize().x+4, getY()+4, getHeight()-8, getHeight()-8, 0xFF37A2E6); // blue
|
||||
}
|
||||
else
|
||||
{
|
||||
target.fill(getX()+label.getPreferredSize().x+4, getY()+4, getHeight()-8, getHeight()-8, 0xFFCBCBD0);
|
||||
}
|
||||
target.fill(getX()+label.getPreferredSize().x+6, getY()+6, getHeight()-12, getHeight()-12, Colors.WHITE);
|
||||
}
|
||||
target.pushTransform(new Mat4().identity().translate( getX(), getY(), 0));
|
||||
label.assembleSelf(target);
|
||||
target.popTransform();
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
package ru.windcorp.progressia.client.graphics.gui;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import ru.windcorp.progressia.client.graphics.gui.event.FocusEvent;
|
||||
import ru.windcorp.progressia.client.graphics.gui.event.HoverEvent;
|
||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
||||
import glm.vec._2.i.Vec2i;
|
||||
|
||||
public class Interactable extends Component {
|
||||
|
||||
private Vec2i currentSize;
|
||||
protected boolean isDisabled;
|
||||
protected boolean isClicked;
|
||||
protected Label label;
|
||||
|
||||
public Interactable(String name, Label textLabel)
|
||||
{
|
||||
super(name);
|
||||
label = textLabel;
|
||||
addChild(textLabel);
|
||||
|
||||
addListener(new Object() {
|
||||
@Subscribe
|
||||
public void onHoverChanged(HoverEvent e) {
|
||||
requestReassembly();
|
||||
}
|
||||
});
|
||||
|
||||
addListener(new Object() {
|
||||
@Subscribe
|
||||
public void onFocusChanged(FocusEvent e) {
|
||||
//inButton.setText(new Label("dummy",new Font().withColor(Colors.BLACK),e.getNewState() ? "Is Focused" : "Isn't focused"));
|
||||
requestReassembly();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isClicked()
|
||||
{
|
||||
return isClicked;
|
||||
}
|
||||
|
||||
public void setDisable(boolean isDisabled)
|
||||
{
|
||||
this.isDisabled = isDisabled;
|
||||
setFocusable(isDisabled);
|
||||
}
|
||||
|
||||
public boolean isDisabled()
|
||||
{
|
||||
return isDisabled;
|
||||
}
|
||||
|
||||
public void setText(Label newText)
|
||||
{
|
||||
removeChild(label);
|
||||
label = newText;
|
||||
addChild(label);
|
||||
requestReassembly();
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
package ru.windcorp.progressia.client.graphics.gui;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import glm.mat._4.Mat4;
|
||||
import glm.vec._2.i.Vec2i;
|
||||
import ru.windcorp.progressia.client.graphics.Colors;
|
||||
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
||||
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
||||
import ru.windcorp.progressia.client.graphics.input.bus.InputListener;
|
||||
|
||||
public class RadioButton extends Interactable {
|
||||
private RadioManager manager;
|
||||
private boolean isSelected;
|
||||
|
||||
public RadioButton(String name, Label textLabel, Consumer<RadioButton> onSelect, RadioManager myManager)
|
||||
{
|
||||
super(name, textLabel);
|
||||
setPreferredSize(textLabel.getPreferredSize().x+23,textLabel.getPreferredSize().y);
|
||||
manager = myManager;
|
||||
manager.addOption(this);
|
||||
|
||||
addListener((Class<KeyEvent>) KeyEvent.class, (InputListener<KeyEvent>) e -> {if ((e.isLeftMouseButton() && containsCursor()) || (e.getKey()==GLFW.GLFW_KEY_ENTER && isFocused()) )
|
||||
{
|
||||
isClicked = e.isPress();
|
||||
if (!isDisabled() && !isClicked)
|
||||
{
|
||||
onSelect.accept(this);
|
||||
manager.selectSelf(this);
|
||||
}
|
||||
requestReassembly();
|
||||
return true;
|
||||
}
|
||||
return false;});
|
||||
}
|
||||
|
||||
public boolean isSelected()
|
||||
{
|
||||
return isSelected;
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected)
|
||||
{
|
||||
isSelected = selected;
|
||||
}
|
||||
|
||||
protected void assembleSelf(RenderTarget target) {
|
||||
if (isDisabled())
|
||||
{
|
||||
target.fill(getX()+getWidth()-getHeight(), getY(), getHeight(), getHeight(), 0xFFE5E5E5);
|
||||
}
|
||||
else if (isClicked() || isHovered() || isFocused())
|
||||
{
|
||||
target.fill(getX()+getWidth()-getHeight(), getY(), getHeight(), getHeight(), 0xFF37A2E6);
|
||||
}
|
||||
else
|
||||
{
|
||||
target.fill(getX()+getWidth()-getHeight(), getY(), getHeight(), getHeight(), 0xFFCBCBD0);
|
||||
}
|
||||
//Inside area
|
||||
if (!isClicked() && isHovered() && !isDisabled())
|
||||
{
|
||||
target.fill(getX()+getWidth()-getHeight()+2, getY()+2, getHeight()-4, getHeight()-4, 0xFFC3E4F7);
|
||||
}
|
||||
else if (!isClicked() || isDisabled())
|
||||
{
|
||||
target.fill(getX()+getWidth()-getHeight()+2, getY()+2, getHeight()-4, getHeight()-4, Colors.WHITE);
|
||||
}
|
||||
if (isSelected())
|
||||
{
|
||||
if (!isDisabled())
|
||||
{
|
||||
target.fill(getX()+getWidth()-getHeight()+4, getY()+4, getHeight()-8, getHeight()-8, 0xFF37A2E6);
|
||||
}
|
||||
else
|
||||
{
|
||||
target.fill(getX()+getWidth()-getHeight()+4, getY()+4, getHeight()-8, getHeight()-8, 0xFFC3E4F7);
|
||||
}
|
||||
}
|
||||
|
||||
target.pushTransform(new Mat4().identity().translate( getX(), getY(), 0));
|
||||
label.assembleSelf(target);
|
||||
target.popTransform();
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package ru.windcorp.progressia.client.graphics.gui;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class RadioManager {
|
||||
private List<RadioButton> options;
|
||||
private int selectedOption;
|
||||
|
||||
public RadioManager()
|
||||
{
|
||||
options = Collections.synchronizedList(new CopyOnWriteArrayList<>());
|
||||
}
|
||||
|
||||
public void addOption(RadioButton option)
|
||||
{
|
||||
options.add(option);
|
||||
}
|
||||
|
||||
public int getSelected()
|
||||
{
|
||||
return selectedOption;
|
||||
}
|
||||
|
||||
public void selectSelf(RadioButton option)
|
||||
{
|
||||
if (!options.contains(option))
|
||||
{
|
||||
return;
|
||||
}
|
||||
options.get(selectedOption).setSelected(false);
|
||||
selectedOption = options.indexOf(option);
|
||||
option.takeFocus();
|
||||
option.setSelected(true);
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package ru.windcorp.progressia.common.modules;
|
||||
|
||||
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Module extends Namespaced {
|
||||
|
||||
private final Set<Task> tasks = new HashSet<>();
|
||||
private final Map<String, String> meta = new HashMap<>();
|
||||
|
||||
/**
|
||||
* @param id the identifier of a task object.
|
||||
* Its format is restricted by {@link Namespaced}.
|
||||
* @see Namespaced#Namespaced
|
||||
*/
|
||||
public Module(String id) {
|
||||
super(id);
|
||||
meta.put("id", id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return meta information of the module as {@link Map}.
|
||||
*/
|
||||
public Map<String, String> getMeta() {
|
||||
return Collections.unmodifiableMap(meta);
|
||||
}
|
||||
|
||||
public Set<Task> getTasks() {
|
||||
return Collections.unmodifiableSet(tasks);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param task that will be attached to the module.
|
||||
* A task can't be added to any module second time.
|
||||
*/
|
||||
public void addTask(Task task) {
|
||||
task.setOwner(this);
|
||||
tasks.add(task);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package ru.windcorp.progressia.common.modules;
|
||||
|
||||
public class ModuleBuilder {
|
||||
private final Module module;
|
||||
|
||||
public ModuleBuilder(String id) {
|
||||
module = new Module(id);
|
||||
}
|
||||
|
||||
public ModuleBuilder AddTask(Task task) {
|
||||
module.addTask(task);
|
||||
return this;
|
||||
}
|
||||
}
|
130
src/main/java/ru/windcorp/progressia/common/modules/Task.java
Normal file
130
src/main/java/ru/windcorp/progressia/common/modules/Task.java
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package ru.windcorp.progressia.common.modules;
|
||||
|
||||
import ru.windcorp.jputil.chars.StringUtil;
|
||||
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
||||
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public abstract class Task
|
||||
extends Namespaced
|
||||
implements Runnable {
|
||||
|
||||
private final Set<Task> requiredTasks = new HashSet<>();
|
||||
private final AtomicBoolean isDone = new AtomicBoolean(false);
|
||||
private final AtomicBoolean isActive = new AtomicBoolean(false);
|
||||
private Module owner;
|
||||
|
||||
/**
|
||||
* @param id the identifier of a task object.
|
||||
* Its format is restricted by {@link Namespaced}.
|
||||
* @see Namespaced#Namespaced
|
||||
*/
|
||||
protected Task(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!canRun()) {
|
||||
List<Task> undoneTasks = new ArrayList<>();
|
||||
for (Iterator<Task> iterator = requiredTasks.iterator(); iterator.hasNext(); ) {
|
||||
Task t = iterator.next();
|
||||
if (!t.isDone()) {
|
||||
undoneTasks.add(t);
|
||||
}
|
||||
}
|
||||
|
||||
throw CrashReports.report(new Throwable(),
|
||||
"The following required Tasks are not done:\n%s",
|
||||
StringUtil.iterableToString(undoneTasks, "\n"));
|
||||
} else if (isDone()) {
|
||||
throw CrashReports.report(new Throwable(),
|
||||
"The task cannot be performed second time");
|
||||
} else {
|
||||
isActive.set(true);
|
||||
perform();
|
||||
isActive.set(false);
|
||||
isDone.set(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The method is to be invoked in run().
|
||||
* @see Task#run()
|
||||
*/
|
||||
protected abstract void perform();
|
||||
|
||||
public boolean isDone() {
|
||||
return isDone.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the {@link Task#run()} method is being invoked at the moment or not.
|
||||
*/
|
||||
public boolean isActive() {
|
||||
return isActive.get();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true - the method is not done and not active
|
||||
* and all requirement tasks are done, false - otherwise.
|
||||
*/
|
||||
public boolean canRun() {
|
||||
if (this.isActive.get() || isDone.get()) return false;
|
||||
for (Iterator<Task> iterator = requiredTasks.iterator(); iterator.hasNext(); ) {
|
||||
Task reqTask = iterator.next();
|
||||
if (!reqTask.isDone()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Set<Task> getRequiredTasks() {
|
||||
return Collections.unmodifiableSet(requiredTasks);
|
||||
}
|
||||
|
||||
public void addRequiredTask(Task task) {
|
||||
requiredTasks.add(task);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the module the task is attached to.
|
||||
*/
|
||||
public Module getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param module to which the task will be attached.
|
||||
* Only one module can be the owner of the task.
|
||||
*/
|
||||
public void setOwner(Module module) {
|
||||
if (owner != null) {
|
||||
throw CrashReports.crash(
|
||||
null
|
||||
, "Could not set %s as owner of %s, because %s is already owner of it.",
|
||||
module.getId(), this.getId(), this.owner.getId());
|
||||
} else {
|
||||
owner = module;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package ru.windcorp.progressia.common.modules;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
||||
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static java.util.concurrent.Executors.newFixedThreadPool;
|
||||
|
||||
public final class TaskManager {
|
||||
private static final TaskManager INSTANCE = new TaskManager();
|
||||
|
||||
private final Set<Task> tasks = new HashSet<>();
|
||||
private final Set<Module> modules = new HashSet<>();
|
||||
private final ExecutorService executorService;
|
||||
|
||||
final AtomicBoolean loadingDone;
|
||||
final AtomicInteger activeThreadsCount;
|
||||
|
||||
private final Map<Thread, Namespaced> loadersMonitorMap;
|
||||
|
||||
private TaskManager() {
|
||||
loadingDone = new AtomicBoolean(false);
|
||||
activeThreadsCount = new AtomicInteger(0);
|
||||
executorService = newFixedThreadPool(
|
||||
Runtime.getRuntime().availableProcessors(), Thread::new);
|
||||
loadersMonitorMap = new HashMap<>(Runtime.getRuntime().availableProcessors());
|
||||
}
|
||||
|
||||
public static TaskManager getInstance() {
|
||||
return TaskManager.INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the module and its tasks that are
|
||||
* to be performed by {@link TaskManager#startLoading()}.
|
||||
*
|
||||
* @param module from where to register tasks for loading.
|
||||
*/
|
||||
public void registerModule(Module module) {
|
||||
tasks.addAll(module.getTasks());
|
||||
modules.add(module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a task that is to be performed
|
||||
* by {@link TaskManager#startLoading()}.
|
||||
*
|
||||
* @param task to register for loading.
|
||||
*/
|
||||
public void addTask(Task task) {
|
||||
tasks.add(task);
|
||||
}
|
||||
|
||||
public boolean isLoadingDone() {
|
||||
return loadingDone.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* The method to start loading. It will perform every registered task.
|
||||
*/
|
||||
public void startLoading() {
|
||||
LogManager.getLogger().info("Loading is started");
|
||||
int procAmount = Runtime.getRuntime().availableProcessors();
|
||||
for (int i = 0; i < procAmount; i++) {
|
||||
executorService.submit(loaderTask);
|
||||
}
|
||||
|
||||
waitForLoadingEnd();
|
||||
if (!tasks.isEmpty()) {
|
||||
throw CrashReports.crash(null, "Loading is failed");
|
||||
}
|
||||
LogManager.getLogger().info("Loading is finished");
|
||||
executorService.shutdownNow();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Task - founded registered task with {@link Task#canRun()} = true;
|
||||
* null - there is no available task found.
|
||||
* @see Task#canRun()
|
||||
*/
|
||||
synchronized Task getRunnableTask() {
|
||||
if (!tasks.isEmpty()) {
|
||||
for (Iterator<Task> iterator = tasks.iterator(); iterator.hasNext(); ) {
|
||||
Task t = iterator.next();
|
||||
if (t.canRun()) {
|
||||
tasks.remove(t);
|
||||
return t;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the thread that is performing this method
|
||||
* to wait until the loading is not done.
|
||||
*/
|
||||
private void waitForLoadingEnd() {
|
||||
synchronized (tasks) {
|
||||
while (!loadingDone.get()) {
|
||||
try {
|
||||
tasks.wait();
|
||||
} catch (InterruptedException ignored) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void stopLoading() {
|
||||
loadingDone.set(true);
|
||||
synchronized (tasks) {
|
||||
tasks.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a map where key is a thread making loading
|
||||
* and where value is a {@link Namespaced} of {@link Task} that is being performed by it
|
||||
* at the moment.
|
||||
* @see Namespaced
|
||||
*/
|
||||
public Map<Thread, Namespaced> getLoadersMonitorMap() {
|
||||
return Collections.unmodifiableMap(loadersMonitorMap);
|
||||
}
|
||||
|
||||
private final Runnable loaderTask = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (!loadingDone.get()) {
|
||||
Task t = getRunnableTask();
|
||||
if (t != null) {
|
||||
activeThreadsCount.incrementAndGet();
|
||||
loadersMonitorMap.put(Thread.currentThread(), t);
|
||||
t.run();
|
||||
loadersMonitorMap.put(Thread.currentThread(), null);
|
||||
activeThreadsCount.decrementAndGet();
|
||||
synchronized (tasks) {
|
||||
tasks.notifyAll();
|
||||
}
|
||||
} else if (activeThreadsCount.get() > 0) {
|
||||
try {
|
||||
synchronized (tasks) {
|
||||
tasks.wait();
|
||||
}
|
||||
} catch (InterruptedException ignored) {}
|
||||
} else {
|
||||
stopLoading();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
@ -26,15 +26,10 @@ import ru.windcorp.progressia.client.graphics.Colors;
|
||||
import ru.windcorp.progressia.client.graphics.backend.GraphicsBackend;
|
||||
import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface;
|
||||
import ru.windcorp.progressia.client.graphics.font.Font;
|
||||
import ru.windcorp.progressia.client.graphics.gui.Button;
|
||||
import ru.windcorp.progressia.client.graphics.gui.Checkbox;
|
||||
import ru.windcorp.progressia.client.graphics.gui.DynamicLabel;
|
||||
import ru.windcorp.progressia.client.graphics.gui.GUILayer;
|
||||
import ru.windcorp.progressia.client.graphics.gui.Button;
|
||||
import ru.windcorp.progressia.client.graphics.gui.Label;
|
||||
import ru.windcorp.progressia.client.graphics.gui.Panel;
|
||||
import ru.windcorp.progressia.client.graphics.gui.RadioButton;
|
||||
import ru.windcorp.progressia.client.graphics.gui.RadioManager;
|
||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical;
|
||||
import ru.windcorp.progressia.client.localization.Localizer;
|
||||
@ -61,54 +56,6 @@ public class LayerTestGUI extends GUILayer {
|
||||
Font font = new Font().withColor(color).deriveOutlined();
|
||||
|
||||
TestPlayerControls tpc = TestPlayerControls.getInstance();
|
||||
|
||||
Button disableButton = new Button("TestButton",
|
||||
new Label("TestButtonLabel", new Font().withColor(Colors.BLACK), "I'm in TestGUI"),
|
||||
b -> {b.setDisable(!b.isDisabled());}
|
||||
);
|
||||
|
||||
panel.addChild(disableButton);
|
||||
|
||||
panel.addChild(
|
||||
new Button(
|
||||
"TestButton2",
|
||||
new Label("TestButtonLabel2", new Font().withColor(Colors.BLACK), "I enable the above button"),
|
||||
b -> {disableButton.setDisable(false);}
|
||||
)
|
||||
);
|
||||
|
||||
panel.addChild(
|
||||
new Checkbox(
|
||||
"Checkbox1",
|
||||
new Label("CheckboxLabel", font,"Reset"),
|
||||
c -> {c.setText(
|
||||
new Label("CheckboxLabel", font, "Set")
|
||||
);},
|
||||
c -> {c.setText(
|
||||
new Label("CheckboxLabel", font, "Reset")
|
||||
);}
|
||||
)
|
||||
);
|
||||
|
||||
RadioManager manager = new RadioManager();
|
||||
|
||||
panel.addChild(
|
||||
new RadioButton(
|
||||
"Radio1,1",
|
||||
new Label("RadioLabel1,1",font,"Option 1"),
|
||||
rb -> {},
|
||||
manager
|
||||
)
|
||||
);
|
||||
|
||||
panel.addChild(
|
||||
new RadioButton(
|
||||
"Radio1,2",
|
||||
new Label("RadioLabel1,2",font,"Option 2"),
|
||||
rb -> {},
|
||||
manager
|
||||
)
|
||||
);
|
||||
|
||||
panel.addChild(
|
||||
new Label(
|
||||
@ -313,127 +260,13 @@ public class LayerTestGUI extends GUILayer {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class Counter {
|
||||
|
||||
private int DISPLAY_INERTIA = 200;
|
||||
private long AVERAGE_TIME = 10000;
|
||||
private long first_time;
|
||||
|
||||
private final long[] values;
|
||||
private int size;
|
||||
private int head;
|
||||
|
||||
private long lastUpdate;
|
||||
|
||||
public Counter(long averageTime, int maxTPS)
|
||||
{
|
||||
DISPLAY_INERTIA = (int) averageTime*maxTPS/1000;
|
||||
AVERAGE_TIME = averageTime;
|
||||
first_time = -1;
|
||||
values = new long[DISPLAY_INERTIA];
|
||||
}
|
||||
|
||||
public void add(long value) {
|
||||
if (first_time==-1)
|
||||
{
|
||||
first_time=System.currentTimeMillis();
|
||||
}
|
||||
if (size == values.length) {
|
||||
values[head] = value;
|
||||
head++;
|
||||
if (head == values.length)
|
||||
head = 0;
|
||||
} else {
|
||||
values[size] = value;
|
||||
size++;
|
||||
}
|
||||
}
|
||||
|
||||
public double average() {
|
||||
double count=0;
|
||||
long ctime = System.currentTimeMillis();
|
||||
for (int i=0;i<size;i++)
|
||||
{
|
||||
if ((ctime-values[i])<AVERAGE_TIME)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if ((ctime-first_time)<AVERAGE_TIME)
|
||||
{
|
||||
if ((ctime-first_time)<10)
|
||||
{
|
||||
return 20.0;
|
||||
}
|
||||
return count/(ctime-first_time)*1000;
|
||||
}
|
||||
return count/AVERAGE_TIME*1000;
|
||||
}
|
||||
|
||||
public double update() {
|
||||
long now = (long) (GraphicsInterface.getTime() / .05);
|
||||
if (lastUpdate != now) {
|
||||
lastUpdate = now;
|
||||
add(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
return average();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class Queue {
|
||||
|
||||
private static final int DISPLAY_INERTIA = 32;
|
||||
private static final double UPDATE_INTERVAL = Units.get(50.0, "ms");
|
||||
|
||||
private final double[] values = new double[DISPLAY_INERTIA];
|
||||
private int size;
|
||||
private int head;
|
||||
|
||||
private long lastUpdate;
|
||||
|
||||
public void add(double value) {
|
||||
if (size == values.length) {
|
||||
values[head] = value;
|
||||
head++;
|
||||
if (head == values.length)
|
||||
head = 0;
|
||||
} else {
|
||||
values[size] = value;
|
||||
size++;
|
||||
}
|
||||
}
|
||||
|
||||
public double average() {
|
||||
if (size == values.length && head!=0) {
|
||||
return (values[head-1]-values[head])/DISPLAY_INERTIA*20;
|
||||
} else if (head==0) {
|
||||
return (values[size-1]-values[0])/DISPLAY_INERTIA*20;
|
||||
} else {
|
||||
return values[head-1]/size*20;
|
||||
}
|
||||
}
|
||||
|
||||
public double update(double value) {
|
||||
long now = (long) (GraphicsInterface.getTime() / UPDATE_INTERVAL);
|
||||
if (lastUpdate != now) {
|
||||
lastUpdate = now;
|
||||
add(value);
|
||||
}
|
||||
|
||||
return average();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final Averager FPS_RECORD = new Averager();
|
||||
private static final Queue TPS_RECORD = new Queue();
|
||||
private static final Averager TPS_RECORD = new Averager();
|
||||
|
||||
private static final Supplier<CharSequence> TPS_STRING = DynamicStrings.builder()
|
||||
.addDyn(new MutableStringLocalized("LayerTestGUI.TPSDisplay"))
|
||||
.addDyn(() -> TPS_RECORD.update(ServerState.getInstance().getUptimeTicks()), 5, 1)
|
||||
.addDyn(() -> TPS_RECORD.update(ServerState.getInstance().getTPS()), 5, 1)
|
||||
.buildSupplier();
|
||||
|
||||
private static final Supplier<CharSequence> POS_STRING = DynamicStrings.builder()
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 94 KiB |
Reference in New Issue
Block a user