Skip to content
Snippets Groups Projects
Commit cb87c461 authored by Bariatti Francesco's avatar Bariatti Francesco
Browse files

Changed makefile to include GUI: a make run command allow to run the program....

Changed makefile to include GUI: a make run command allow to run the program. Small changes in GUI to allow compilation and execution
parent 5e566903
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,6 @@ import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
import view.TileView;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
......@@ -30,9 +29,9 @@ import java.util.ResourceBundle;
public class Controller implements Initializable
{
private static final String iaProgramPath = "../bin/penguin";
private static final String introMusicFile = "./resource/pingu_theme.wav";
private static final String clickSoundFile = "./resource/clic.wav";
public static String iaProgramPath = "bin/penguin";
public static String introMusicFile = "resource/pingu_theme.wav";
public static String clickSoundFile = "resource/clic.wav";
private static final int max1Fish = 30, max2Fish = 20, max3Fish = 10;
private GameState gameState;
......@@ -94,7 +93,7 @@ public class Controller implements Initializable
new Thread(() -> {
try
{
AudioPlayer.player.start(new AudioStream(new FileInputStream(introMusicFile)));
AudioPlayer.player.start(new AudioStream(getClass().getClassLoader().getResourceAsStream(introMusicFile)));
} catch (IOException e)
{
e.printStackTrace();
......@@ -286,7 +285,7 @@ public class Controller implements Initializable
{
try
{
AudioPlayer.player.start(new AudioStream(new FileInputStream(clickSoundFile)));
AudioPlayer.player.start(new AudioStream(getClass().getClassLoader().getResourceAsStream(clickSoundFile)));
} catch (IOException e)
{
e.printStackTrace();
......
package main;
import controller.Controller;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
import java.io.FileInputStream;
import java.io.InputStream;
public class Main extends Application
......@@ -17,7 +13,10 @@ public class Main extends Application
public static void main(String[] args)
{
launch(args);
if(args.length < 1)
throw new RuntimeException("You must pass the path to the AI program as argument");
Controller.iaProgramPath = args[0];
launch();
}
@Override
......@@ -26,7 +25,7 @@ public class Main extends Application
try
{
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("../view/view.fxml"));
loader.setLocation(getClass().getClassLoader().getResource("view/view.fxml"));
BorderPane root = (BorderPane) loader.load();
Scene scene = new Scene(root);
primaryStage.setScene(scene);
......
# Compiler
CC=g++
# Makefile for the Penguin game project.
# This project is composed of two modules: AI(Artificial Intelligence), that manage the game, and GUI that allows you to play it
# To compile the AI run 'make ai'; it is written in C++.
# To compile the GUI run 'make gui'; it is written in java and javafx.
# To compile everything run 'make all' or 'make'.
# To run the GUI (that will launch the AI) run 'make run'.
# Run 'make clean' to delete compiled files and programs. 'make cleanai' and 'make cleangui' also exist
# COMPILERS AND PROGRAMS
# Compiler for the AI: g++ >= 4.9
CC = g++
# JAVA ENVIRONMENT FOR THE GUI
# Java compiler >= 1.8
JAVAC = javac
# Java jar utility
JAR = jar
# Java executable used for the run target >= 1.8
JAVA = java
all: ai gui
clean: aiclean guiclean
# ============================================ AI (C++) =============================================
#Root directory for the AI module
AIRoot = AI
# Output directory
BIN=bin
AIOutputDir = $(AIRoot)/bin
# Name of the executable
EXECUTABLE=$(BIN)/penguin
AIExecutable = $(AIOutputDir)/penguin
# Source files directory
AISRC = $(AIRoot)/src
# Directories with .h files
INCLUDE=-I src/game -I src/util -I src/monte_carlo -I src/mcts -I src/json
AIInclude=-I $(AISRC)/game -I $(AISRC)/util -I $(AISRC)/monte_carlo -I $(AISRC)/mcts -I $(AISRC)/json
# Cpp source files
AISourceFile = omp_util.cpp fast_log.cpp display_node.cpp penguin.cpp test_two_players_game.cpp monte_carlo.cpp \
test_fast_log.cpp statistics.cpp node.cpp allocator.cpp test_allocator.cpp openings.cpp mcts_two_players.cpp \
test_mcts_two_players.cpp bits.cpp test_bits.cpp main.cpp
# Directories in which make will search for files
vpath %.cpp src/game src/main src/util src/monte_carlo src/mcts src/gdl
vpath %.cpp $(AISRC)/game $(AISRC)/main $(AISRC)/util $(AISRC)/monte_carlo $(AISRC)/mcts $(AISRC)/gdl
# Flags passed to the compiler
CFLAGS=-g -O3 -ffast-math -fopenmp -Wall -std=c++11
# Flags passed to the linker
LDFLAGS=-fopenmp -std=c++11 #-lprofiler -Wl,-no_pie
# Cpp source files
SOURCES=omp_util.cpp fast_log.cpp display_node.cpp penguin.cpp test_two_players_game.cpp monte_carlo.cpp \
test_fast_log.cpp statistics.cpp node.cpp allocator.cpp test_allocator.cpp openings.cpp mcts_two_players.cpp \
test_mcts_two_players.cpp bits.cpp test_bits.cpp main.cpp
# Generating .o files' names
OBJECTS=$(addprefix $(BIN)/, $(SOURCES:.cpp=.o))
AIOobjects=$(addprefix $(AIOutputDir)/, $(AISourceFile:.cpp=.o))
# ========= RULES ============
# ==== RULES ====
# Main rule for creating the executable
ai: aioutputdir $(AIExecutable)
aioutputdir:
mkdir -p $(AIOutputDir)
# Creates the output directory and the executable
all: bindir $(EXECUTABLE)
# Creates the output directory if it doesn't exist
bindir:
mkdir -p $(BIN)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@
$(AIExecutable): $(AIOobjects)
$(CC) $(LDFLAGS) $(AIOobjects) -o $@
# Creates .o files with automatic generation of dependencies (.d) files
$(BIN)/%.o: %.cpp
$(CC) -c $(CFLAGS) $(INCLUDE) -MD -MP $< -o $@
$(AIOutputDir)/%.o: %.cpp
$(CC) -c $(CFLAGS) $(AIInclude) -MD -MP $< -o $@
# Include the dependency files into the makefile
-include $(OBJECTS:.o=.d)
-include $(AIOobjects:.o=.d)
# Deletes .o, .d and the executable
clean:
rm -f $(BIN)/*.o $(BIN)/*.d $(EXECUTABLE)
aiclean:
rm -f $(AIOutputDir)/*.o $(AIOutputDir)/*.d $(AIExecutable)
# ============================================ GUI (Java) =============================================
#Root directory of the GUI module
GUIRoot = GUI
# Output directory
GUIOutputDir = $(GUIRoot)/bin
# Name of the output jar
GUIOutputJar = $(GUIOutputDir)/penguin.jar
# Directory with all the java sources
GUISourceDir = $(GUIRoot)/src
vpath %.java $(GUISourceDir)
# Path to the JSON lib
GUIJSONJar = $(GUIRoot)/json-20160212.jar
# Classes needed in the projet (in the form: package/className)
GUIClasses = model/GameState model/Move model/Player model/Tile view/TileView controller/Controller controller/UpdateThread main/Main
# Resources that will be included in the jar (they will be appended to the jar creation command. See man for the -C option that will allow to specify a relative path inside the jar)
GUIJarResources = -C $(GUISourceDir) view/view.fxml -C $(GUISourceDir) resource/clic.wav -C $(GUISourceDir) resource/pingu_theme.wav
# Output directory of compiled classes
GUIClassesOutDir = $(GUIOutputDir)/classes
# Classpath used for compiling
GUICompileClasspath = $(GUIJSONJar):$(GUIClassesOutDir)
# Classpath used for running
GUIRunClasspath = $(GUIOutputJar):$(GUIJSONJar)
# ==== RULES ====
# Main rule for creating the jar of the GUI: it needs the output folder and all the compiled classes
gui: guioutputdir $(addsuffix .class, $(GUIClasses))
$(JAR) cvfe $(GUIOutputJar) main.Main -C $(GUIClassesOutDir) ./ $(GUIJarResources)
guioutputdir:
mkdir -p $(GUIOutputDir)
# Rule for compiling a java class
%.class: %.java guiclassesoutdir
$(JAVAC) -sourcepath $(GUISourceDir) -classpath $(GUICompileClasspath) -d $(GUIClassesOutDir) $<
guiclassesoutdir:
mkdir -p $(GUIClassesOutDir)
run:
$(JAVA) -classpath $(GUIRunClasspath) main.Main $(AIExecutable)
guiclean:
rm -r $(GUIOutputDir)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment