package fm.ak.client;
import fm.ak.burer.client.Burer;
import fm.ak.client.twod.Floater;
import fm.ak.client.twod.Dialog;
import fm.ak.client.twod.Datagram;
import fm.ak.client.object.Player;
import fm.ak.client.object.Entity;
import fm.ak.client.twod.Tooltip;
import fm.ak.client.object.Tile;
import fm.ak.otse.Otse;
import fm.ak.otse.font.Text;
import fm.ak.otse.twod.Component;
import fm.ak.otse.twod.ComponentRenderer;
import fm.ak.otse.twod.Shader;
import fm.ak.otse.twod.Sheet;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import static org.lwjgl.opengl.GL11.*;
public class Main extends Otse {
static public Main main;
private Burer burer;
static final public int INTERVAL = 1000; // TODO: Below 200 will kill DeferredResource loading
private Text tfps;
private Text players;
private Text entities;
private Text regions;
private Text tiles;
private float cubeRotation = 0.0f;
public static final int[] opposite = {2, 3, 0, 1};
/**
* stopper of programs
*/
public boolean kill = false;
/**
* not unlike kill
*/
public boolean stop = false;
public Clear clear;
public Viewport viewport;
public Component background;
public Dialog dialog;
public float fadeToBlack = 1.f;
public static int width = 1000;
public static int height = 600;
public Sheet sheet1;
public Sheet gooey;
public Sheet guy;
boolean pause = false;
Main() throws LWJGLException {
super();
}
/*
* todo: main shouldn't throw interrupted wut :c
*/
public static void main(String[] args)
throws InterruptedException, LWJGLException {
//-Djava.library.path=C:\lwjgl-2.8.1/native/windows
//Sys.alert("yeah", "OOH THIS IS BAD");
main = new Main();
try {
main.getScreen().title = "AK";
main.getScreen().create(width, height, false);
//background = new Component("$postal", 0, 0, width, height);
//background.setSheetSprite(new Sheet("img/zone.png"), "entirety");
//background.position(0, 0, Main.width, Main.height);
//background.index = 0;
main.firstThing();
main.runtime();
} catch (LWJGLException | InterruptedException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
System.exit(-1);
} finally {
System.err.println("did something go wrong?");
main.destroy();
}
}
private void makeDebugTexts() {
tfps = Text.create(StaticFont.SegoeUILight14,
" fps: " + getHertz().getFps(),
12, 12, 0, Text.ZERO_WIDTH, Text.NORMAL_ANGLE, Text.Fades.NONE,
1, 1, 1, 1);
players = Text.create(StaticFont.SegoeUILight14,
//"cycle0100: " + cycle0100 +
" players: " + Local.Players.size(),
12, 12 + StaticFont.SegoeUILight14.getMetrics().Height * 1,
0, Text.ZERO_WIDTH, Text.NORMAL_ANGLE, Text.Fades.NONE,
1, 1, 1, 1);
entities = Text.create(StaticFont.SegoeUILight14,
//"cycle0100: " + cycle0100 +
" entities: " + Local.Entities.size(),
12, 12 + StaticFont.SegoeUILight14.getMetrics().Height * 2,
0, Text.ZERO_WIDTH, Text.NORMAL_ANGLE, Text.Fades.NONE,
1, 1, 1, 1);
regions = Text.create(StaticFont.SegoeUILight14,
//"cycle0100: " + cycle0100 +
" regions: " + Local.Regions.size(),
12, 12 + StaticFont.SegoeUILight14.getMetrics().Height * 3,
0, Text.ZERO_WIDTH, Text.NORMAL_ANGLE, Text.Fades.NONE,
1, 1, 1, 1);
tiles = Text.create(StaticFont.SegoeUILight14,
//"cycle0100: " + cycle0100 +
" tiles: " + Local.Tiles.size(),
12, 12 + StaticFont.SegoeUILight14.getMetrics().Height * 4,
0, Text.ZERO_WIDTH, Text.NORMAL_ANGLE, Text.Fades.NONE,
1, 1, 1, 1);
}
private void disposeDebugTexts() {
tfps.markDispose();
players.markDispose();
entities.markDispose();
regions.markDispose();
tiles.markDispose();
}
public int cycle0100;
/*
* this function is the beating heart of the program
*/
public void runtime() throws InterruptedException {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glViewport(0, 0, width, height);
while ( ! kill && ! Display.isCloseRequested() ) {
int delta = getHertz().delta();
if ( pause ) {
getKeyboard().pollKeyboard();
Display.update();
continue;
}
cycle0100 = (cycle0100 == 99) ? 0 : cycle0100 + 1;
//makeDebugTexts();
if ( Display.isVisible() ) {
Local.doPatch();
getKeyboard().pollKeyboard();
getMouse().pollMouse();
getComponentRenderer().flushQueue();
Tooltip.pass();
//glClear(GL_COLOR_BUFFER_BIT);
getRenderer().render();
} else {
if (Display.isDirty()) {
//Render();
}
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
System.err.println("dirty display thingie");
}
}
//disposeDebugTexts();
Display.update();
//Display.sync(60);
}
System.out.println("end render loop");
}
@Override
public void hookMouse() {
//System.out.println("leftMouse: " + leftMouse);
if ( Local.Stages.GAME == Local.getStage() ) {
viewport.handleMouseFocus();
}
// TODO: rewrite
Component focus = null;
ComponentRenderer cr = Otse.getInstance().getComponentRenderer();
focus = cr.findAndTriggerSingleMouseTarget();
if ( focus != null ) {
System.out.println("focus is on " + focus.develName);
focus.handleMouseFocus();
}
if ( null == focus ) {
for ( Player p : Local.Players.values() )
if ( p.listens && p.hovers() ) {
p.handleMouseFocus();
break;
}
}
if ( null == focus ) {
for ( Entity e : Local.Entities.values() ) {
if ( e.listens && e.hovers() ) {
e.handleMouseFocus();
break;
}
}
}
//for( Entity e : Local.Entities.values() ) e.Hovers();
}
public Thread worker;
/**
* first thing is a function enforced by {@link #runtime() }
*
* @throws InterruptedException
*/
private void firstThing() throws InterruptedException {
sheet1 = new Sheet("img/Sheet.png");
Tile.sheet = sheet1;
StaticFont.make();
Shader.StaticShader();
clear = new Clear();
clear.load();
clear.display();
//clear.message("loading stuff...");
//Thread.sleep(1000);
Static.fillSprites();
Connect connect = new Connect();
worker = new Thread(connect, "connect"); // constructor generates name if we don't
worker.start();
//c.runtime();
}
@Override
public void hookKeyboard() {
}
/**
* connects to a server
*/
class Connect implements Runnable {
@Override
public void run() {
try {
//synchronized (Component.queue) {
Local.setStage(Local.Stages.FIRSTSCREEN);
//}
Datagram.create("puzzle");
Datagram.create("puzzle");
Datagram.create("puzzle");
Datagram.create("puzzle");
//float c = 0.3450980392156863f; // the perfect grey
//Component slate;
//slate = new Component("Slate block", (Main.width / 2) -
// (440 / 2), (Main.height / 2) - (150 / 2), 440, 150);
//slate.rgba(68, 76, 82, 1);
//Component.queue.add(slate);
clear.message("Kick back, this may take a whi-- Never mind.");
Thread.sleep(INTERVAL * 2);
burer = new Burer();
burer.connect("127.0.0.1", 4444);
//if ( net.bconnected() ) {
//Callback.Try(Net.Do.CONNECT, null, true);
//net.Caller.join();
//Viewport.justify();
//Net.Map(true);
//net.Caller.join();
clear.message("We've connected");
Thread.sleep(INTERVAL * 1);
Floater.leans();
ComponentRenderer cr = Otse.getInstance().getComponentRenderer();
synchronized (cr.queue) {
Mouse.setGrabbed(false);
if ( Local.fatal )
return;
clear.hide();
clear.unload();
cr.queue.add(background);
//viewport = new Viewport();
//Component.queue.add(Viewport.getMarker());
//Local.setStage(Local.Stages.GAME);
//Component.queue.sprite(Main.dialog =
// new Dialog(Dialog.WELCOME_MESSAGE));
}
//Callback.Try(Net.Do.ZERO, null, false);
/*} else {
clear.message("We couldn't connect");
Thread.sleep(INTERVAL * 4);
kill = true;
}*/
} catch (UnknownHostException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}