The PajamaApplication class is the main entry point for initializing and running a game application using the Pajama framework. It simplifies the process of setting up the application context and executing the primary game loop.
The PajamaApplication class:
- Initializes the
EngineContextfor managing application components. - Locates the main game loop annotated with
@GameLoop. - Validates and executes the game loop if it implements
Runnable.
- Automatic Context Setup: Derives the base package from the main class or accepts a custom package for component scanning.
- Game Loop Management: Ensures the presence of a valid
@GameLoopannotated class and invokes itsrunmethod. - Error Handling: Provides runtime exceptions for misconfigured main classes.
- Type:
EngineContext - Description: Holds the shared context for managing application components and their dependencies.
Initializes the application context using the package of the specified main class and executes its game loop.
mainClass: The main class of the application annotated with@GameLoop.
Exceptionif:- Context initialization fails.
- The game loop is misconfigured or invalid.
public static void main(String[] args) {
PajamaApplication.run(MyGame.class);
}Initializes the application context using a custom base package and executes the game loop of the specified main class.
mainClass: The main class of the application annotated with@GameLoop.basePackage: The custom base package to scan for components.
Exceptionif:- Context initialization fails.
- The game loop is misconfigured or invalid.
public static void main(String[] args) {
PajamaApplication.run(MyGame.class, "com.example.mygame");
}Validates the presence and configuration of the game loop in the current context and executes it if valid.
mainClass: The class annotated with@GameLoopto run.
RuntimeExceptionif:- The main class is not annotated with
@GameLoop. - The main class is not registered in the context.
- The main class does not implement
Runnable.
- The main class is not annotated with
- Retrieves the
@GameLoopannotated class instance from the context. - Verifies that the class:
- Is properly annotated with
@GameLoop. - Implements
Runnable.
- Is properly annotated with
- Invokes the
runmethod of the class if valid.
@GameLoop
public class MyGame implements Runnable {
@Override
public void run() {
System.out.println("Game loop running...");
}
}
public static void main(String[] args) throws Exception {
PajamaApplication.run(MyGame.class);
}- Marks a class as the main entry point for the application’s game loop.
- The annotated class must implement
Runnable.
NO_GAME_LOOP_FOUND:- Triggered when no
@GameLoopannotated class is found in the context.
- Triggered when no
GAME_LOOP_HAS_NOT_IMPLEMENTED_RUNNABLE:- Triggered when the
@GameLoopclass does not implementRunnable.
- Triggered when the
@GameLoop
public class MyGame implements Runnable {
@Override
public void run() {
System.out.println("Starting the game loop...");
// Game loop logic here
}
}
public static void main(String[] args) throws Exception {
PajamaApplication.run(MyGame.class);
}@GameLoop
public class MyGame implements Runnable {
@Override
public void run() {
System.out.println("Game loop running with custom package...");
}
}
public static void main(String[] args) throws Exception {
PajamaApplication.run(MyGame.class, "com.custom.game");
}- Framework Dependency: Relies on the
EngineContextclass for component management. - Annotations: Requires
@GameLoopto identify the main game loop class. - Runnable Interface: The main game loop class must implement
Runnableto be executed.