mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-14 12:58:37 +00:00
0ca162a55c
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
74 lines
2.7 KiB
Java
74 lines
2.7 KiB
Java
/*
|
|
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
|
*
|
|
* The MIT License
|
|
* Copyright © 2014-2022 Ilkka Seppälä
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
* THE SOFTWARE.
|
|
*/
|
|
package com.iluwatar.gameloop;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
/**
|
|
* A game loop runs continuously during gameplay. Each turn of the loop, it processes user input
|
|
* without blocking, updates the game state, and renders the game. It tracks the passage of time to
|
|
* control the rate of gameplay.
|
|
*/
|
|
@Slf4j
|
|
public class App {
|
|
|
|
/** Each type of game loop will run for 2 seconds. */
|
|
private static final int GAME_LOOP_DURATION_TIME = 2000;
|
|
|
|
/**
|
|
* Program entry point.
|
|
*
|
|
* @param args runtime arguments
|
|
*/
|
|
public static void main(String[] args) {
|
|
|
|
try {
|
|
LOGGER.info("Start frame-based game loop:");
|
|
var frameBasedGameLoop = new FrameBasedGameLoop();
|
|
frameBasedGameLoop.run();
|
|
Thread.sleep(GAME_LOOP_DURATION_TIME);
|
|
frameBasedGameLoop.stop();
|
|
LOGGER.info("Stop frame-based game loop.");
|
|
|
|
LOGGER.info("Start variable-step game loop:");
|
|
var variableStepGameLoop = new VariableStepGameLoop();
|
|
variableStepGameLoop.run();
|
|
Thread.sleep(GAME_LOOP_DURATION_TIME);
|
|
variableStepGameLoop.stop();
|
|
LOGGER.info("Stop variable-step game loop.");
|
|
|
|
LOGGER.info("Start fixed-step game loop:");
|
|
var fixedStepGameLoop = new FixedStepGameLoop();
|
|
fixedStepGameLoop.run();
|
|
Thread.sleep(GAME_LOOP_DURATION_TIME);
|
|
fixedStepGameLoop.stop();
|
|
LOGGER.info("Stop variable-step game loop.");
|
|
|
|
} catch (InterruptedException e) {
|
|
LOGGER.error(e.getMessage());
|
|
}
|
|
}
|
|
}
|