Skip to content

Commit

Permalink
Merge pull request #23 from svencc/feature/make-map-component-pannable
Browse files Browse the repository at this point in the history
Feature/make map component pannable
  • Loading branch information
svencc authored Jan 28, 2024
2 parents a82e798 + 2525901 commit fe09c53
Show file tree
Hide file tree
Showing 69 changed files with 1,090 additions and 472 deletions.
60 changes: 4 additions & 56 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,12 @@

# 1
* new InputComponent interacting with MapComponent
* panning
* zooming
*
* Command-Queue (->)
* add commands to queue (/)
* A Command is a class with a type and can check by itself if its condition is met or not. (/)
* Commands are Singletons or at least reusable (/)
* Commands have to be registered/activated in the central InputManager (/)
* execute commands in update by InputComponents (/)
* after execution, remove command from queue (after Input has been processed; clear queue) (/)
* Commands: (<-)
*
*
* There are two types of commands: Instant and Continuous
* Instant/Sequential Commands (e.g. MouseClick)
* Sequence (amount of repetitions, delay between repetitions is counted by the command ITSELF -> stored in central event-queue and popped by the command itself after update delta time)
* Instant Commands are executed immediately after they are added to the queue
* Instant Commands are removed from the queue after they are executed
* Mouse Commands:
* Left ( Pixel position )
* Right ( Pixel position )
* Center ( Pixel position )
* Double Click ( Pixel position )
* Mouse Wheel ( Pixel position, Wheel delta )
* Keyboard Commands:
* Key Press ( Key )
* Keys can be pressed multiple times
* Key is pressed after key-release
* Continuous Commands (e.g. MouseDrag)
* Continuous Commands are executed every update cycle as long as they are in the queue
* Continuous Commands are removed from the queue after they are released
* Mouse Commands:
* Drag Left ( Pixel position, Drag vector )
* Drag Right ( Pixel position, Drag vector )
* Drag Center ( Pixel position, Drag vector )
* Hold Left ( Pixel position, Drag vector )
* Hold Right ( Pixel position, Drag vector )
* Hold Center ( Pixel position, Drag vector )
* Mouse Click
* Left ( Pixel position )
* Right ( Pixel position )
* Drag Left ( Pixel position, Drag vector )
* Drag Right ( Pixel position, Drag vector )
* Mouse Wheel ( Pixel position, Wheel delta )
*
*
* panning (/)
* zooming (<-)
*
* PhysicsCore holds position in TransformComponent or Object
* Transform is modified when moved!

* RenderPipeline Renders a SceneGraph ... our MergeableLayer is kind of a SceneGraph
* a RenderableComponent could be a node in the SceneGraph
* so other RenderableComponents could be added to the RenderableComponent Node
* this way we could implement a "graphical" scene graph
* the both interfaces: ParentPropagatableDirtyState + ChildPropagatableDirtyState will be put into the graph-node concept!
*
*

* NULLImplementations -> Optionals ...
*
* dynamic changeable render properties!
* optimize Layers so that they must not be reinstantiated every time on update. Reuse layers and remove/extend entities on update
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.recom.tacview.engine;

public interface Updatable {
public interface IsUpdatable {

void update(final long elapsedNanoTime);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import java.nio.IntBuffer;

public class CanvasBufferSwapCommand {
public class SwappableCanvasBuffer {

@NonNull
private final Canvas canvas;
Expand All @@ -28,7 +28,7 @@ public class CanvasBufferSwapCommand {
public int lastBackBufferIndex = -1;


public CanvasBufferSwapCommand(
public SwappableCanvasBuffer(
@NonNull final Canvas canvas,
@NonNull final RendererProperties rendererProperties,
@NonNull final ScreenComposer screenComposer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.recom.tacview.engine;

import com.recom.tacview.engine.graphics.ScreenComposer;
import com.recom.tacview.engine.input.GenericInputEventListener;
import com.recom.tacview.engine.input.GenericFXInputEventListener;
import com.recom.tacview.engine.input.InputManager;
import com.recom.tacview.engine.input.command.mapper.MouseClickCommandMapper;
import com.recom.tacview.engine.input.mapper.keyboard.JavaFxKeyboardCommandMapper;
import com.recom.tacview.engine.input.mapper.mousebutton.JavaFxMouseButtonCommandMapper;
import com.recom.tacview.engine.input.mapper.scroll.JavaFxMouseScrollCommandMapper;
import com.recom.tacview.engine.module.EngineModule;
import com.recom.tacview.property.RendererProperties;
import com.recom.tacview.property.TickProperties;
Expand Down Expand Up @@ -31,13 +33,13 @@ public class TacViewer extends Canvas {
@NonNull
private final EngineModule engineModule;
@NonNull
private final GenericInputEventListener genericInputEventListener;
private final GenericFXInputEventListener genericFXInputEventListener;
@NonNull
private final InputManager inputManager;


@NonNull
private final CanvasBufferSwapCommand canvasBuffer;
private final SwappableCanvasBuffer canvasBuffer;
@NonNull
private final AnimationTimer animationTimerLoop;

Expand All @@ -53,28 +55,33 @@ public TacViewer(
@NonNull final ProfilerProvider profilerProvider,
@NonNull final ScreenComposer screenComposer,
@NonNull final EngineModule engineModule,
@NonNull final GenericInputEventListener genericInputEventListener,
@NonNull final GenericFXInputEventListener genericFXInputEventListener,
@NonNull final InputManager inputManager
) {
super(rendererProperties.getWidth(), rendererProperties.getHeight());
this.rendererProperties = rendererProperties;
this.tickProperties = tickProperties;
this.screenComposer = screenComposer;
this.engineModule = engineModule;
this.genericInputEventListener = genericInputEventListener;
this.genericFXInputEventListener = genericFXInputEventListener;
this.inputManager = inputManager;

this.canvasBuffer = new CanvasBufferSwapCommand(this, rendererProperties, screenComposer);
// this.setScaleX(2);
// this.setScaleY(2);
this.canvasBuffer = new SwappableCanvasBuffer(this, rendererProperties, screenComposer);
this.profiler = new TacViewerProfiler(profilerProvider);
this.profiler.startProfiling();

this.animationTimerLoop = provideAnimationTimer();

this.setFocusTraversable(true);
this.requestFocus();
this.setEventHandler(InputEvent.ANY, this.genericInputEventListener);

this.inputManager.registerCommandMapper(new MouseClickCommandMapper());
// register input event listener
this.setEventHandler(InputEvent.ANY, this.genericFXInputEventListener);
this.inputManager.registerCommandMapper(new JavaFxMouseButtonCommandMapper());
this.inputManager.registerCommandMapper(new JavaFxMouseScrollCommandMapper());
this.inputManager.registerCommandMapper(new JavaFxKeyboardCommandMapper());
}

@NonNull
Expand Down Expand Up @@ -111,7 +118,7 @@ private void engineLoop(
// HANDLE INPUT
final long inputHandlingStart = System.nanoTime();
inputManager.mapInputEventsToCommands();
engineModule.handleInputCommands(inputManager.getCreatedInputCommands());
engineModule.handleInputCommands(inputManager.popInputCommands());
inputManager.clearInputQueues();
profiler.inputHandlingNanoTime = System.nanoTime() - inputHandlingStart;

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.recom.tacview.engine.entitycomponentsystem.component;

import com.recom.tacview.engine.input.command.IsInputCommand;
import com.recom.tacview.engine.input.command.IsCommand;
import lombok.NonNull;

public interface HandlesInputCommand {

void handleInputCommand(@NonNull final IsInputCommand inputCommand);
void handleInputCommand(@NonNull final IsCommand<?> inputCommand);

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.recom.tacview.engine.entitycomponentsystem.component;

import com.recom.tacview.engine.input.command.IsInputCommand;
import com.recom.tacview.engine.input.command.IsCommand;
import lombok.NonNull;

public abstract class InputComponent extends ComponentTemplate implements HandlesInputCommand {
Expand All @@ -10,6 +10,6 @@ public InputComponent() {
}

@Override
public abstract void handleInputCommand(@NonNull final IsInputCommand inputCommand);
public abstract void handleInputCommand(@NonNull final IsCommand<?> inputCommand);

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.recom.tacview.engine.entitycomponentsystem.component;

import com.recom.tacview.engine.Updatable;
import com.recom.tacview.engine.IsUpdatable;
import lombok.NonNull;

public interface IsComponent extends BelongsToEntity, HasComponentType, Updatable {
public interface IsComponent extends BelongsToEntity, HasComponentType, IsUpdatable {

@NonNull
ComponentType componentType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ public void propagateDirtyStateToParent() {
public void prepareBuffer() {

}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.recom.tacview.engine.entitycomponentsystem.entity;

import com.recom.tacview.engine.Updatable;
import com.recom.tacview.engine.IsUpdatable;
import com.recom.tacview.engine.entitycomponentsystem.component.ComponentType;
import com.recom.tacview.engine.entitycomponentsystem.component.IsComponent;
import com.recom.tacview.engine.entitycomponentsystem.environment.IsEnvironment;
Expand Down Expand Up @@ -29,6 +29,7 @@ public class Entity implements IsEntity {
@Override
public void addComponent(@NonNull final IsComponent component) {
components.add(component);
component.setEntity(this);
components.sort(Comparator.comparing(IsComponent::getComponentProcessingOrder));
reIndexComponents();
}
Expand All @@ -50,6 +51,7 @@ public void reIndexComponents() {
@Override
public void removeComponent(@NonNull final IsComponent component) {
components.remove(component);
component.setEntity(NullEntity.INSTANCE);
reIndexComponents();
}

Expand Down Expand Up @@ -83,7 +85,7 @@ public List<IsComponent> getComponents() {

@Override
public void update(final long elapsedNanoTime) {
for (@NonNull final Updatable component : components) {
for (@NonNull final IsUpdatable component : components) {
component.update(elapsedNanoTime);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.recom.tacview.engine.entitycomponentsystem.entity;

import com.recom.tacview.engine.Updatable;
import com.recom.tacview.engine.IsUpdatable;

public interface IsEntity extends BelongsToEnvironment, HasLocatableComponents, Updatable {
public interface IsEntity extends BelongsToEnvironment, HasLocatableComponents, IsUpdatable {

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.recom.tacview.engine.entitycomponentsystem.environment;

import com.recom.tacview.engine.Updatable;
import com.recom.tacview.engine.IsUpdatable;
import com.recom.tacview.engine.graphics.renderpipeline.IsRenderPipeline;
import com.recom.tacview.engine.renderer.RenderProvider;
import com.recom.tacview.property.RendererProperties;
import com.recom.tacview.service.RendererExecutorProvider;
import lombok.NonNull;

public interface IsEnvironment extends Updatable, HasManagableEntities {
public interface IsEnvironment extends IsUpdatable, HasManagableEntities {

void update(final long elapsedNanoTime);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.recom.tacview.engine.graphics;

import com.recom.tacview.engine.renderables.Soilable;
import com.recom.tacview.engine.renderables.IsSoilable;
import com.recom.tacview.engine.units.PixelDimension;

public interface Bufferable extends Scanable, Soilable {
public interface IsBufferable extends IsScanable, IsSoilable {

PixelDimension getDimension();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.recom.tacview.engine.renderables.HasPixelBuffer;
import lombok.NonNull;

public interface Composable extends HasPixelBuffer {
public interface IsComposable extends HasPixelBuffer {

int compose(@NonNull final Environment environment);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
package com.recom.tacview.engine.graphics;

import com.recom.tacview.engine.renderables.Mergeable;
import com.recom.tacview.engine.renderables.IsMergeable;
import com.recom.tacview.engine.graphics.buffer.PixelBuffer;
import lombok.NonNull;

public interface Renderable {
public interface IsRenderable {

void render(
@NonNull final Scanable sourceScanable,
@NonNull final Bufferable targetBuffer,
@NonNull final IsScanable sourceScanable,
@NonNull final IsBufferable targetBuffer,
final int xOffset,
final int yOffset
);

void renderMergeable(
@NonNull final Mergeable source,
@NonNull final IsMergeable source,
@NonNull final PixelBuffer targetBuffer,
final int xOffset,
final int yOffset
);

void renderMergeable(
@NonNull final Mergeable source,
@NonNull final Bufferable target,
@NonNull final IsMergeable source,
@NonNull final IsBufferable target,
final int xOffset,
final int yOffset
);

void setPixelAt(
@NonNull final Bufferable target,
@NonNull final IsBufferable target,
final int x,
final int y,
final int newPixelValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import com.recom.tacview.engine.units.PixelDimension;

public interface Scanable {
public interface IsScanable {

PixelDimension getDimension();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@Slf4j
@Component
public class ScreenComposer implements Composable {
public class ScreenComposer implements IsComposable {

@NonNull
private final ExecutorService renderExecutorService;
Expand All @@ -39,7 +39,7 @@ public int compose(@NonNull final Environment environment) {
} else {
pixelRingBuffer.next();
pixelRingBuffer.getPixelBuffer().clearBuffer();
renderLayerPipelineInParallel(environment.getRenderPipeline());
renderLayersInParallel(environment.getRenderPipeline());
environment.getRenderPipeline().getLayers().forEach(layer -> {
layer.mergeBufferWith(pixelRingBuffer.getPixelBuffer(), 0, 0);
layer.dispose();
Expand All @@ -51,7 +51,7 @@ public int compose(@NonNull final Environment environment) {
}
}

private void renderLayerPipelineInParallel(@NonNull final IsRenderPipeline renderPipeline) {
private void renderLayersInParallel(@NonNull final IsRenderPipeline renderPipeline) {
final CountDownLatch latch = new CountDownLatch(renderPipeline.getLayers().size());
for (final MergeableComponentLayer mergeableLayer : renderPipeline.getLayers()) {
renderExecutorService.execute(() -> {
Expand Down
Loading

0 comments on commit fe09c53

Please sign in to comment.