aboutsummaryrefslogtreecommitdiffstats
path: root/src/jake2/sys
diff options
context:
space:
mode:
authorHolger Zickner <[email protected]>2004-07-07 19:59:59 +0000
committerHolger Zickner <[email protected]>2004-07-07 19:59:59 +0000
commit6e23fc1074d1f0c2c2812f4c2e663f5a21a43c20 (patch)
tree46ecc6d0255c874ba4cd26dc3d0733f785019896 /src/jake2/sys
import of Jake2 version sunrisesunrise
Diffstat (limited to 'src/jake2/sys')
-rw-r--r--src/jake2/sys/IN.java122
-rw-r--r--src/jake2/sys/InputListener.java109
-rw-r--r--src/jake2/sys/Jake2InputEvent.java48
-rw-r--r--src/jake2/sys/KBD.java219
-rw-r--r--src/jake2/sys/NET.java731
-rw-r--r--src/jake2/sys/RW.java151
-rw-r--r--src/jake2/sys/Sys.java278
7 files changed, 1658 insertions, 0 deletions
diff --git a/src/jake2/sys/IN.java b/src/jake2/sys/IN.java
new file mode 100644
index 0000000..db88226
--- /dev/null
+++ b/src/jake2/sys/IN.java
@@ -0,0 +1,122 @@
+/*
+ * IN.java
+ * Copyright (C) 2003
+ *
+ * $Id: IN.java,v 1.1 2004-07-07 19:59:51 hzi Exp $
+ */
+/*
+Copyright (C) 1997-2001 Id Software, Inc.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+package jake2.sys;
+
+import jake2.Globals;
+import jake2.game.usercmd_t;
+import jake2.qcommon.Cvar;
+
+import java.awt.*;
+
+import javax.swing.ImageIcon;
+
+/**
+ * IN
+ */
+public final class IN extends Globals {
+
+ static Component c = null;
+ static Cursor emptyCursor = null;
+
+ static boolean mouse_avail = true;
+ static boolean mouse_active = false;
+ static boolean ignorefirst = false;
+
+ public static void ActivateMouse() {
+ // if (!mouse_avail || c == null) return;
+ if (!mouse_active) {
+ KBD.mx = KBD.my = 0; // don't spazz
+ install_grabs();
+ mouse_active = true;
+ }
+ }
+
+ public static void DeactivateMouse() {
+ // if (!mouse_avail || c == null) return;
+ if (mouse_active) {
+ uninstall_grabs();
+ mouse_active = false;
+ }
+ }
+
+ private static void install_grabs() {
+ if (emptyCursor == null) {
+ ImageIcon emptyIcon = new ImageIcon(new byte[0]);
+ emptyCursor = c.getToolkit().createCustomCursor(emptyIcon.getImage(), new Point(0, 0), "emptyCursor");
+ }
+ c.setCursor(emptyCursor);
+ KBD.centerMouse();
+
+ ignorefirst = true;
+ }
+
+ private static void uninstall_grabs() {
+ c.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+
+ public static void toggleMouse() {
+ if (mouse_active)
+ DeactivateMouse();
+ else
+ ActivateMouse();
+ }
+
+ public static void Init() {
+ in_mouse = Cvar.Get("in_mouse", "1", CVAR_ARCHIVE);
+ in_joystick = Cvar.Get("in_joystick", "0", CVAR_ARCHIVE);
+ }
+
+ public static void Shutdown() {
+ RW.IN_Shutdown();
+ }
+
+ public static void Real_IN_Init() {
+ RW.IN_Init();
+ }
+
+ public static void Commands() {
+ RW.IN_Commands();
+ }
+
+ public static void Frame() {
+
+ if ( !cl.refresh_prepped || cls.key_dest == key_console || cls.key_dest == key_menu)
+ RW.IN_Activate(false);
+ else
+ RW.IN_Activate(true);
+
+ RW.IN_Frame();
+ }
+
+ public static void CenterView() {
+ cl.viewangles[PITCH] = -SHORT2ANGLE(cl.frame.playerstate.pmove.delta_angles[PITCH]);
+ }
+
+ public static void Move(usercmd_t cmd) {
+ RW.IN_Move(cmd);
+ }
+
+}
diff --git a/src/jake2/sys/InputListener.java b/src/jake2/sys/InputListener.java
new file mode 100644
index 0000000..52a6d4a
--- /dev/null
+++ b/src/jake2/sys/InputListener.java
@@ -0,0 +1,109 @@
+/*
+ * InputListener.java
+ * Copyright (C) 2004
+ *
+ * $Id: InputListener.java,v 1.1 2004-07-07 19:59:51 hzi Exp $
+ */
+/*
+Copyright (C) 1997-2001 Id Software, Inc.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+package jake2.sys;
+
+import java.awt.event.*;
+import java.util.LinkedList;
+
+/**
+ * InputListener
+ */
+public final class InputListener implements KeyListener, MouseListener, MouseMotionListener, ComponentListener {
+
+ // modifications of eventQueue must be thread safe!
+ private static LinkedList eventQueue = new LinkedList();
+
+ static void addEvent(Jake2InputEvent ev) {
+ synchronized (eventQueue) {
+ eventQueue.addLast(ev);
+ }
+ }
+
+ static Jake2InputEvent nextEvent() {
+ Jake2InputEvent ev = null;
+ synchronized (eventQueue) {
+ try {
+ ev = (Jake2InputEvent)eventQueue.removeFirst();
+ } catch (Exception e) {}
+ }
+ return ev;
+ }
+
+ public void keyPressed(KeyEvent e) {
+ addEvent(new Jake2InputEvent(Jake2InputEvent.KeyPress, e));
+ }
+
+ public void keyReleased(KeyEvent e) {
+ addEvent(new Jake2InputEvent(Jake2InputEvent.KeyRelease, e));
+ }
+
+ public void keyTyped(KeyEvent e) {
+ }
+
+ public void mouseClicked(MouseEvent e) {
+ }
+
+ public void mouseEntered(MouseEvent e) {
+ }
+
+ public void mouseExited(MouseEvent e) {
+ }
+
+ public void mousePressed(MouseEvent e) {
+ addEvent(new Jake2InputEvent(Jake2InputEvent.ButtonPress, e));
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ addEvent(new Jake2InputEvent(Jake2InputEvent.ButtonRelease, e));
+ }
+
+ public void mouseDragged(MouseEvent e) {
+ addEvent(new Jake2InputEvent(Jake2InputEvent.MotionNotify, e));
+ }
+
+ public void mouseMoved(MouseEvent e) {
+ addEvent(new Jake2InputEvent(Jake2InputEvent.MotionNotify, e));
+ }
+
+ public void componentHidden(ComponentEvent e) {
+ }
+
+ public void componentMoved(ComponentEvent e) {
+ addEvent(new Jake2InputEvent(Jake2InputEvent.ConfigureNotify, e));
+ }
+
+ public void componentResized(ComponentEvent e) {
+ addEvent(new Jake2InputEvent(Jake2InputEvent.ConfigureNotify, e));
+ }
+
+ public void componentShown(ComponentEvent e) {
+ IN.c = e.getComponent();
+ addEvent(new Jake2InputEvent(Jake2InputEvent.CreateNotify, e));
+ }
+
+
+}
+
diff --git a/src/jake2/sys/Jake2InputEvent.java b/src/jake2/sys/Jake2InputEvent.java
new file mode 100644
index 0000000..7da899f
--- /dev/null
+++ b/src/jake2/sys/Jake2InputEvent.java
@@ -0,0 +1,48 @@
+/*
+ * Jake2InputEvent.java
+ * Copyright (C) 2004
+ *
+ * $Id: Jake2InputEvent.java,v 1.1 2004-07-07 19:59:51 hzi Exp $
+ */
+/*
+Copyright (C) 1997-2001 Id Software, Inc.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+package jake2.sys;
+
+import java.awt.AWTEvent;
+
+/**
+ * Jake2InputEvent
+ */
+class Jake2InputEvent {
+ static final int KeyPress = 0;
+ static final int KeyRelease = 1;
+ static final int MotionNotify = 2;
+ static final int ButtonPress = 3;
+ static final int ButtonRelease = 4;
+ static final int CreateNotify = 5;
+ static final int ConfigureNotify = 6;
+ int type;
+ AWTEvent ev;
+
+ Jake2InputEvent(int type, AWTEvent ev) {
+ this.type = type;
+ this.ev = ev;
+ }
+}
diff --git a/src/jake2/sys/KBD.java b/src/jake2/sys/KBD.java
new file mode 100644
index 0000000..b680063
--- /dev/null
+++ b/src/jake2/sys/KBD.java
@@ -0,0 +1,219 @@
+/*
+ * KBD.java
+ * Copyright (C) 2004
+ *
+ * $Id: KBD.java,v 1.1 2004-07-07 19:59:51 hzi Exp $
+ */
+/*
+Copyright (C) 1997-2001 Id Software, Inc.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+package jake2.sys;
+
+import jake2.client.Key;
+
+import java.awt.*;
+import java.awt.event.*;
+
+/**
+ * KBD
+ */
+public final class KBD {
+
+ static int win_x = 0;
+ static int win_y = 0;
+ static int win_w2 = 0;
+ static int win_h2 = 0;
+
+ // motion values
+ public static int mx = 0;
+ public static int my = 0;
+
+ static Robot robot;
+ public static InputListener listener = new InputListener();
+
+ static {
+ try {
+ robot = new Robot();
+ } catch (AWTException e) {
+ System.exit(1);
+ }
+ }
+
+ public static void Init() {
+ }
+
+ public static void Update() {
+ // get events
+ HandleEvents();
+ }
+
+ public static void Close() {
+ }
+
+ static void HandleEvents() {
+ int b;
+
+ Jake2InputEvent event;
+ while ( (event=InputListener.nextEvent()) != null ) {
+ switch(event.type) {
+ case Jake2InputEvent.KeyPress:
+ case Jake2InputEvent.KeyRelease:
+ Do_Key_Event(XLateKey((KeyEvent)event.ev), event.type == Jake2InputEvent.KeyPress);
+ break;
+
+ case Jake2InputEvent.MotionNotify:
+// if (IN.ignorefirst) {
+// IN.ignorefirst = false;
+// break;
+// }
+ if (IN.mouse_active) {
+ mx = (((MouseEvent)event.ev).getX() - win_w2) * 2;
+ my = (((MouseEvent)event.ev).getY() - win_h2) * 2;
+ } else {
+ mx = 0;
+ my = 0;
+ }
+ break;
+
+ case Jake2InputEvent.ButtonPress:
+ b=((MouseEvent)event.ev).getButton()-1;
+ Do_Key_Event(Key.K_MOUSE1 + b, true);
+ break;
+
+ case Jake2InputEvent.ButtonRelease:
+ b=((MouseEvent)event.ev).getButton()-1;
+ Do_Key_Event(Key.K_MOUSE1 + b, false);
+ break;
+
+ case Jake2InputEvent.CreateNotify :
+ case Jake2InputEvent.ConfigureNotify :
+ Component c = ((ComponentEvent)event.ev).getComponent();
+ win_x = 0;
+ win_y = 0;
+ win_w2 = c.getWidth() / 2;
+ win_h2 = c.getHeight() / 2;
+ while (c != null) {
+ if (c instanceof Container) {
+ Insets insets = ((Container)c).getInsets();
+ win_x += insets.left;
+ win_y += insets.top;
+ }
+ win_x += c.getX();
+ win_y += c.getY();
+ c = c.getParent();
+ }
+ break;
+ }
+ }
+
+ if (mx != 0 || my != 0) {
+ // move the mouse to the window center again
+ robot.mouseMove(win_x + win_w2, win_y + win_h2);
+ }
+ }
+
+ private static int XLateKey(KeyEvent ev) {
+
+ int key = 0;
+ int code = ev.getKeyCode();
+
+ switch(code) {
+// 00626 case XK_KP_Page_Up: key = K_KP_PGUP; break;
+ case KeyEvent.VK_PAGE_UP: key = Key.K_PGUP; break;
+
+// 00629 case XK_KP_Page_Down: key = K_KP_PGDN; break;
+ case KeyEvent.VK_PAGE_DOWN: key = Key.K_PGDN; break;
+
+// 00632 case XK_KP_Home: key = K_KP_HOME; break;
+ case KeyEvent.VK_HOME: key = Key.K_HOME; break;
+
+// 00635 case XK_KP_End: key = K_KP_END; break;
+ case KeyEvent.VK_END: key = Key.K_END; break;
+
+ case KeyEvent.VK_KP_LEFT: key = Key.K_KP_LEFTARROW; break;
+ case KeyEvent.VK_LEFT: key = Key.K_LEFTARROW; break;
+
+ case KeyEvent.VK_KP_RIGHT: key = Key.K_KP_RIGHTARROW; break;
+ case KeyEvent.VK_RIGHT: key = Key.K_RIGHTARROW; break;
+
+ case KeyEvent.VK_KP_DOWN: key = Key.K_KP_DOWNARROW; break;
+ case KeyEvent.VK_DOWN: key = Key.K_DOWNARROW; break;
+
+ case KeyEvent.VK_KP_UP: key = Key.K_KP_UPARROW; break;
+ case KeyEvent.VK_UP: key = Key.K_UPARROW; break;
+
+ case KeyEvent.VK_ESCAPE: key = Key.K_ESCAPE; break;
+
+
+ case KeyEvent.VK_ENTER: key = Key.K_ENTER; break;
+// 00652 case XK_KP_Enter: key = K_KP_ENTER; break;
+
+ case KeyEvent.VK_TAB: key = Key.K_TAB; break;
+
+ case KeyEvent.VK_F1: key = Key.K_F1; break;
+ case KeyEvent.VK_F2: key = Key.K_F2; break;
+ case KeyEvent.VK_F3: key = Key.K_F3; break;
+ case KeyEvent.VK_F4: key = Key.K_F4; break;
+ case KeyEvent.VK_F5: key = Key.K_F5; break;
+ case KeyEvent.VK_F6: key = Key.K_F6; break;
+ case KeyEvent.VK_F7: key = Key.K_F7; break;
+ case KeyEvent.VK_F8: key = Key.K_F8; break;
+ case KeyEvent.VK_F9: key = Key.K_F9; break;
+ case KeyEvent.VK_F10: key = Key.K_F10; break;
+ case KeyEvent.VK_F11: key = Key.K_F11; break;
+ case KeyEvent.VK_F12: key = Key.K_F12; break;
+
+ case KeyEvent.VK_BACK_SPACE: key = Key.K_BACKSPACE; break;
+
+ case KeyEvent.VK_DELETE: key = Key.K_DEL; break;
+// 00683 case XK_KP_Delete: key = K_KP_DEL; break;
+
+ case KeyEvent.VK_PAUSE: key = Key.K_PAUSE; break;
+
+ case KeyEvent.VK_SHIFT: key = Key.K_SHIFT; break;
+ case KeyEvent.VK_CONTROL: key = Key.K_CTRL; break;
+
+ case KeyEvent.VK_ALT:
+ case KeyEvent.VK_ALT_GRAPH: key = Key.K_ALT; break;
+
+// 00700 case XK_KP_Begin: key = K_KP_5; break;
+// 00701
+ case KeyEvent.VK_INSERT: key = Key.K_INS; break;
+
+ default:
+ key = ev.getKeyChar();
+ if (key >= 'A' && key <= 'Z')
+ key = key - 'A' + 'a';
+ break;
+ }
+ if (key > 255) key = 0;
+
+ return key;
+ }
+
+ static void Do_Key_Event(int key, boolean down) {
+ Key.Event(key, down, Sys.Milliseconds());
+ }
+
+ static void centerMouse() {
+ robot.mouseMove(win_x + win_w2, win_y + win_h2);
+ }
+
+}
+
diff --git a/src/jake2/sys/NET.java b/src/jake2/sys/NET.java
new file mode 100644
index 0000000..19a3a59
--- /dev/null
+++ b/src/jake2/sys/NET.java
@@ -0,0 +1,731 @@
+/*
+ * NET.java
+ * Copyright (C) 2003
+ *
+ * $Id: NET.java,v 1.1 2004-07-07 19:59:51 hzi Exp $
+ */
+/*
+Copyright (C) 1997-2001 Id Software, Inc.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+package jake2.sys;
+
+import jake2.Defines;
+import jake2.Globals;
+import jake2.game.cvar_t;
+import jake2.qcommon.*;
+import jake2.util.Lib;
+
+import java.net.*;
+import java.util.Arrays;
+
+public final class NET extends Defines {
+
+ public static netadr_t net_local_adr = new netadr_t();
+
+ // 127.0.0.1
+ public final static int LOOPBACK = 0x7f000001;
+
+ public final static int MAX_LOOPBACK = 4;
+
+ public static class loopmsg_t {
+ byte data[] = new byte[Defines.MAX_MSGLEN];
+ int datalen;
+ };
+
+ public static class loopback_t {
+ public loopback_t()
+ {
+ msgs = new loopmsg_t[MAX_LOOPBACK];
+ for (int n=0; n < MAX_LOOPBACK;n++)
+ {
+ msgs[n] = new loopmsg_t();
+ }
+ }
+ loopmsg_t msgs[];
+
+ int get, send;
+ };
+
+ public static loopback_t loopbacks[] = new loopback_t[2];
+ static {
+ loopbacks[0] = new loopback_t();
+ loopbacks[1] = new loopback_t();
+ }
+ public static DatagramSocket ip_sockets[] = {null,null};
+ //public static DatagramSocket ipx_sockets[] = new int[2];
+
+ // we dont need beschissene sockaddr_in structs in java !
+
+ //=============================================================================
+
+// void NetadrToSockadr (netadr_t *a, struct sockaddr_in *s)
+// {
+// memset (s, 0, sizeof(*s));
+//
+// if (a.type == NA_BROADCAST)
+// {
+// s.sin_family = AF_INET;
+//
+// s.sin_port = a.port;
+// *(int *)&s.sin_addr = -1;
+// }
+// else if (a.type == NA_IP)
+// {
+// s.sin_family = AF_INET;
+//
+// *(int *)&s.sin_addr = *(int *)&a.ip;
+// s.sin_port = a.port;
+// }
+// }
+//
+// void SockadrToNetadr (struct sockaddr_in *s, netadr_t *a)
+// {
+// *(int *)&a.ip = *(int *)&s.sin_addr;
+// a.port = s.sin_port;
+// a.type = NA_IP;
+// }
+//
+
+ public static boolean CompareAdr(netadr_t a, netadr_t b) {
+ if (a.ip[0] == b.ip[0] && a.ip[1] == b.ip[1] && a.ip[2] == b.ip[2] && a.ip[3] == b.ip[3] && a.port == b.port)
+ return true;
+ return false;
+ }
+
+ /*
+ ===================
+ NET_CompareBaseAdr
+
+ Compares without the port
+ ===================
+ */
+ public static boolean NET_CompareBaseAdr(netadr_t a, netadr_t b) {
+ if (a.type != b.type)
+ return false;
+
+ if (a.type == Defines.NA_LOOPBACK)
+ return true;
+
+ if (a.type == Defines.NA_IP) {
+ if (a.ip[0] == b.ip[0] && a.ip[1] == b.ip[1] && a.ip[2] == b.ip[2] && a.ip[3] == b.ip[3])
+ return true;
+ return false;
+ }
+
+ /*
+ if (a.type == Defines.NA_IPX) {
+ for (int n = 0; n < 10; n++)
+ if (a.ipx[n] != b.ipx[n])
+ return false;
+
+ //was:
+ //if ((memcmp(a.ipx, b.ipx, 10) == 0)) return true;
+ return true;
+ }
+ */
+
+ return false;
+ }
+
+
+
+ public static String AdrToString(netadr_t a) {
+ //was:
+ //static char s[64];
+ //Com_sprintf (s, sizeof(s), "%i.%i.%i.%i:%i", a.ip[0], a.ip[1], a.ip[2], a.ip[3], ntohs(a.port));
+
+ return "" + (a.ip[0] & 0xff) + "." + (a.ip[1] & 0xff) + "." + (a.ip[2] & 0xff) + "." + (a.ip[3] & 0xff) + ":" + a.port;
+ }
+
+
+
+ public static String NET_BaseAdrToString(netadr_t a) {
+ //was:
+ //static char s[64];
+ //Com_sprintf (s, sizeof(s), "%i.%i.%i.%i", a.ip[0], a.ip[1], a.ip[2], a.ip[3]);
+ return "" + (a.ip[0] & 0xff) + "." + (a.ip[1] & 0xff) + "." + (a.ip[2] & 0xff) + "." + (a.ip[3] & 0xff);
+ }
+
+ /*
+ =============
+ NET_StringToAdr
+
+ localhost
+ idnewt
+ idnewt:28000
+ 192.246.40.70
+ 192.246.40.70:28000
+ =============
+ */
+// boolean NET_StringToSockaddr (char *s, struct sockaddr *sadr)
+// {
+// struct hostent *h;
+// char *colon;
+// char copy[128];
+//
+// memset (sadr, 0, sizeof(*sadr));
+// ((struct sockaddr_in *)sadr).sin_family = AF_INET;
+//
+// ((struct sockaddr_in *)sadr).sin_port = 0;
+//
+// strcpy (copy, s);
+// // strip off a trailing :port if present
+// for (colon = copy ; *colon ; colon++)
+// if (*colon == ':')
+// {
+// *colon = 0;
+// ((struct sockaddr_in *)sadr).sin_port = htons((short)atoi(colon+1));
+// }
+//
+// if (copy[0] >= '0' && copy[0] <= '9')
+// {
+// *(int *)&((struct sockaddr_in *)sadr).sin_addr = inet_addr(copy);
+// }
+// else
+// {
+// if (! (h = gethostbyname(copy)) )
+// return 0;
+// *(int *)&((struct sockaddr_in *)sadr).sin_addr = *(int *)h.h_addr_list[0];
+// }
+//
+// return true;
+// }
+//
+// /*
+// =============
+// NET_StringToAdr
+//
+// localhost
+// idnewt
+// idnewt:28000
+// 192.246.40.70
+// 192.246.40.70:28000
+// =============
+// */
+// boolean NET_StringToAdr (char *s, netadr_t *a)
+// {
+// struct sockaddr_in sadr;
+//
+// if (!strcmp (s, "localhost"))
+// {
+// memset (a, 0, sizeof(*a));
+// a.type = NA_LOOPBACK;
+// return true;
+// }
+//
+// if (!NET_StringToSockaddr (s, (struct sockaddr *)&sadr))
+// return false;
+//
+// SockadrToNetadr (&sadr, a);
+//
+// return true;
+// }
+//
+
+ public static boolean StringToAdr( String s, netadr_t a)
+ {
+
+ // bugfix bzw. hack cwei
+ if (s.equalsIgnoreCase("localhost")) {
+ a.type = Defines.NA_LOOPBACK;
+ Arrays.fill(a.ip, (byte)0);
+ a.port = 0;
+ return true;
+ }
+ try
+ {
+ String[] address = s.split(":");
+ InetAddress ia = InetAddress.getByName(address[0]);
+ a.ip = ia.getAddress();
+ a.type= NA_IP;
+ if (address.length == 2) a.port = Integer.parseInt(address[1]);
+ return true;
+ }
+ catch
+ (
+ Exception e)
+ {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+
+
+ public static boolean IsLocalAddress (netadr_t adr)
+ {
+ return CompareAdr (adr, net_local_adr);
+ }
+
+ /*
+ =============================================================================
+
+ LOOPBACK BUFFERS FOR LOCAL PLAYER
+
+ =============================================================================
+ */
+
+ // trivial! this SHOULD work !
+ public static boolean NET_GetLoopPacket (int sock, netadr_t net_from, sizebuf_t net_message)
+ {
+ int i;
+ loopback_t loop;
+
+ loop = loopbacks[sock];
+
+ if (loop.send - loop.get > MAX_LOOPBACK)
+ loop.get = loop.send - MAX_LOOPBACK;
+
+ if (loop.get >= loop.send)
+ return false;
+
+ i = loop.get & (MAX_LOOPBACK-1);
+ loop.get++;
+
+ //memcpy (net_message.data, loop.msgs[i].data, loop.msgs[i].datalen);
+ System.arraycopy(loop.msgs[i].data, 0, net_message.data, 0, loop.msgs[i].datalen);
+ net_message.cursize = loop.msgs[i].datalen;
+
+ net_from.ip = net_local_adr.ip;
+ net_from.port = net_local_adr.port;
+ net_from.type = net_local_adr.type;
+
+ return true;
+
+ }
+
+
+ // trivial! this SHOULD work !
+ public static void NET_SendLoopPacket (int sock, int length, byte [] data, netadr_t to)
+ {
+ int i;
+ loopback_t loop;
+
+ loop = loopbacks[sock^1];
+
+ // modulo 4
+ i = loop.send & (MAX_LOOPBACK-1);
+ loop.send++;
+
+ //memcpy (loop.msgs[i].data, data, length);
+
+ System.arraycopy(data,0,loop.msgs[i].data,0,length);
+ loop.msgs[i].datalen = length;
+ }
+
+
+ private static DatagramPacket receivedatagrampacket = new DatagramPacket(new byte[65507], 65507);
+
+ //=============================================================================
+ public static boolean GetPacket (int sock, netadr_t net_from, sizebuf_t net_message)
+ {
+ DatagramSocket net_socket;
+// int ret;
+// struct sockaddr_in from;
+// int fromlen;
+//
+// int protocol;
+// int err;
+
+
+ if (NET_GetLoopPacket (sock, net_from, net_message))
+ {
+ //Com.DPrintf("received packet on sock=" + sock + " len=" + net_message.cursize+"\n");
+ return true;
+ }
+ net_socket = ip_sockets[sock];
+
+ if (net_socket == null)
+ return false;
+
+ try
+ {
+ net_socket.receive(receivedatagrampacket);
+
+ // no timeout...
+
+ net_from.ip = receivedatagrampacket.getAddress().getAddress();
+ net_from.port = receivedatagrampacket.getPort();
+ net_from.type = NA_IP;
+
+ if (receivedatagrampacket.getLength() > net_message.maxsize)
+ {
+ Com.Printf ("Oversize packet from " + AdrToString(net_from) + "\n");
+ return false;
+ }
+ int length = receivedatagrampacket.getLength();
+ System.arraycopy(receivedatagrampacket.getData(), 0, net_message.data, 0, length);
+
+ // bugfix cwei
+ net_message.cursize = length; // set the size
+ net_message.data[length] = 0; // sentinel
+
+
+ //Com.DPrintf(Lib.hexDump(net_message.data, Math.max(length, length - (length % 16) + 16), false));
+ //Com.DPrintf("\n");
+
+ return true;
+
+ }
+ catch (SocketTimeoutException e1)
+ {
+ return false;
+ }
+
+ catch(Exception e)
+ {
+ Com.DPrintf ("NET_GetPacket: " + e + " from " + AdrToString(net_from) + "\n");
+ return false;
+ }
+
+
+ //fromlen = sizeof(from);
+ //ret = recvfrom (net_socket, net_message.data, net_message.maxsize
+ // , 0, (struct sockaddr *)&from, &fromlen);
+
+ //SockadrToNetadr (&from, net_from);
+
+// if (ret == -1)
+// {
+// err = errno;
+//
+// if (err == EWOULDBLOCK || err == ECONNREFUSED)
+// continue;
+// Com_Printf ("NET_GetPacket: %s from %s\n", NET_ErrorString(),
+// NET_AdrToString(*net_from));
+// continue;
+// }
+//
+// if (ret == net_message.maxsize)
+// {
+// Com_Printf ("Oversize packet from %s\n", NET_AdrToString (*net_from));
+// continue;
+// }
+//
+// net_message.cursize = ret;
+// return true;
+
+ }
+
+// =============================================================================
+
+ public static void SendPacket (int sock, int length, byte [] data, netadr_t to)
+ {
+ //Com.Printf("NET_SendPacket: sock=" + sock + " len=" + length + "\n");
+ //Com.DPrintf(Lib.hexDump(data, Math.max(length, length - (length % 16) + 16), false));
+ //Com.DPrintf("\n");
+
+ int ret;
+ //struct sockaddr_in addr;
+
+ DatagramSocket net_socket;
+
+ if ( to.type == NA_LOOPBACK )
+ {
+ NET_SendLoopPacket (sock, length, data, to);
+ return;
+ }
+
+ if (to.type == NA_BROADCAST)
+ {
+ net_socket = ip_sockets[sock];
+ if (net_socket==null)
+ return;
+ }
+ else if (to.type == NA_IP)
+ {
+ net_socket = ip_sockets[sock];
+ if (net_socket==null)
+ return;
+ }
+ /*
+ else if (to.type == NA_IPX)
+ {
+ net_socket = ipx_sockets[sock];
+ if (net_socket==null)
+ return;
+ }
+ else if (to.type == NA_BROADCAST_IPX)
+ {
+ net_socket = ipx_sockets[sock];
+ if (!net_socket)
+ return;
+ }
+ */
+ else
+ {
+ Com.Error (ERR_FATAL, "NET_SendPacket: bad address type");
+ return;
+ }
+
+ //was:
+ //NetadrToSockadr (&to, &addr);
+
+ try
+ { //was:
+ //ret = sendto (net_socket, data, length, 0, (struct sockaddr *)&addr, sizeof(addr) );
+
+ DatagramPacket dp;
+
+ if (to.type == NA_BROADCAST)
+ {
+ dp = new DatagramPacket(data, length, InetAddress.getByAddress(new byte[]{-1,-1,-1,-1}), to.port);
+ }
+ else
+ dp = new DatagramPacket(data, length, to.getInetAddress(), to.port);
+
+ net_socket.send(dp);
+ }
+ catch(Exception e)
+ {
+ Com.Printf ("NET_SendPacket ERROR: " + e + " to " + AdrToString (to) + "\n");
+ }
+ }
+
+
+ //=============================================================================
+
+
+
+
+ /*
+ ====================
+ NET_OpenIP
+ ====================
+ */
+ public static void NET_OpenIP ()
+ {
+ cvar_t port, ip;
+
+ port = Cvar.Get ("port", "" + Defines.PORT_SERVER, CVAR_NOSET);
+ ip = Cvar.Get ("ip", "localhost", CVAR_NOSET);
+
+ if (ip_sockets[NS_SERVER]==null)
+ ip_sockets[NS_SERVER] = NET_Socket (ip.string, (int)port.value);
+
+ if (ip_sockets[NS_CLIENT]==null)
+ ip_sockets[NS_CLIENT] = NET_Socket (ip.string, Defines.PORT_ANY);
+ }
+
+ /*
+ ====================
+ NET_OpenIPX
+ ====================
+ */
+ public static void NET_OpenIPX ()
+ {
+ }
+
+
+ /*
+ ====================
+ NET_Config
+
+ A single player game will only use the loopback code
+ ====================
+ */
+ public static void Config (boolean multiplayer)
+ {
+ int i;
+
+ if (!multiplayer)
+ { // shut down any existing sockets
+ for (i=0 ; i<2 ; i++)
+ {
+ if (ip_sockets[i]!=null)
+ {
+ ip_sockets[i].close();
+ ip_sockets[i] = null;
+ }
+ /*
+ if (ipx_sockets[i])
+ {
+ ipx_sockets[i].close();
+ ipx_sockets[i] = null;
+ }
+ */
+ }
+ }
+ else
+ { // open sockets
+ NET_OpenIP ();
+ }
+ }
+
+
+ //===================================================================
+
+
+ /*
+ ====================
+ NET_Init
+ ====================
+ */
+ public static void NET_Init ()
+ {
+ //empty
+ }
+
+ /*
+ ====================
+ NET_Socket
+ ====================
+ */
+ public static DatagramSocket NET_Socket (String ip, int port)
+ {
+
+ DatagramSocket newsocket = null;
+ try
+ {
+ if (ip==null || ip.length()==0 || ip.equals("localhost"))
+ {
+ if (port == PORT_ANY)
+ {
+ newsocket = new DatagramSocket();
+ }
+ else
+ {
+ newsocket = new DatagramSocket(port);
+ }
+ }
+ else
+ {
+ InetAddress ia = InetAddress.getByName(ip);
+ newsocket = new DatagramSocket(port, ia);
+ }
+
+ newsocket.setBroadcast(true);
+ // nonblocking (1 ms), 0== neverending infinite timeout
+ newsocket.setSoTimeout(1);
+ }
+ catch (Exception e)
+ {
+ newsocket = null;
+ }
+
+ return newsocket;
+
+// int newsocket;
+// //struct sockaddr_in address;
+// qboolean _true = true;
+// int i = 1;
+//
+// if ((newsocket = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
+// {
+// Com.Printf ("ERROR: UDP_OpenSocket: socket: ", NET_ErrorString());
+// return 0;
+// }
+//
+// // make it non-blocking
+// if (ioctl (newsocket, FIONBIO, &_true) == -1)
+// {
+// Com_Printf ("ERROR: UDP_OpenSocket: ioctl FIONBIO:%s\n", NET_ErrorString());
+// return 0;
+// }
+//
+// // make it broadcast capable
+// if (setsockopt(newsocket, SOL_SOCKET, SO_BROADCAST, (char *)&i, sizeof(i)) == -1)
+// {
+// Com_Printf ("ERROR: UDP_OpenSocket: setsockopt SO_BROADCAST:%s\n", NET_ErrorString());
+// return 0;
+// }
+//
+// if (!net_interface || !net_interface[0] || !stricmp(net_interface, "localhost"))
+// address.sin_addr.s_addr = INADDR_ANY;
+// else
+// NET_StringToSockaddr (net_interface, (struct sockaddr *)&address);
+//
+// if (port == PORT_ANY)
+// address.sin_port = 0;
+// else
+// address.sin_port = htons((short)port);
+//
+// address.sin_family = AF_INET;
+//
+// if( bind (newsocket, (void *)&address, sizeof(address)) == -1)
+// {
+// Com_Printf ("ERROR: UDP_OpenSocket: bind: %s\n", NET_ErrorString());
+// close (newsocket);
+// return 0;
+// }
+//
+// return newsocket;
+ }
+
+
+ /*
+ ====================
+ NET_Shutdown
+ ====================
+ */
+ public static void NET_Shutdown ()
+ {
+ Config (false); // close sockets
+ }
+
+
+ /*
+ ====================
+ NET_ErrorString
+ ====================
+ */
+ public static String NET_ErrorString() {
+ int code;
+
+ //code = errno;
+ //return strerror (code);
+ return "errno can not yet resolved in java";
+ }
+
+ // sleeps msec or until net socket is ready
+ public static void NET_Sleep(int msec)
+ {
+ if (ip_sockets[NS_SERVER]==null || (Globals.dedicated!=null && Globals.dedicated.value == 0))
+ return; // we're not a server, just run full speed
+
+ try {
+ //TODO: check for
+ Thread.sleep(msec);
+ }
+ catch (InterruptedException e) {
+ }
+ //ip_sockets[NS_SERVER].
+
+
+ // this should wait up to 100ms until a packet
+ /*
+ struct timeval timeout;
+ fd_set fdset;
+ extern cvar_t *dedicated;
+ extern qboolean stdin_active;
+
+ if (!ip_sockets[NS_SERVER] || (dedicated && !dedicated.value))
+ return; // we're not a server, just run full speed
+
+ FD_ZERO(&fdset);
+ if (stdin_active)
+ FD_SET(0, &fdset); // stdin is processed too
+ FD_SET(ip_sockets[NS_SERVER], &fdset); // network socket
+ timeout.tv_sec = msec/1000;
+ timeout.tv_usec = (msec%1000)*1000;
+ select(ip_sockets[NS_SERVER]+1, &fdset, NULL, NULL, &timeout);
+ */
+ }
+
+}
diff --git a/src/jake2/sys/RW.java b/src/jake2/sys/RW.java
new file mode 100644
index 0000000..31ca7ca
--- /dev/null
+++ b/src/jake2/sys/RW.java
@@ -0,0 +1,151 @@
+/*
+ * RW.java
+ * Copyright (C) 2004
+ *
+ * $Id: RW.java,v 1.1 2004-07-07 19:59:52 hzi Exp $
+ */
+/*
+Copyright (C) 1997-2001 Id Software, Inc.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+package jake2.sys;
+
+import jake2.Globals;
+import jake2.client.CL;
+import jake2.client.Key;
+import jake2.game.Cmd;
+import jake2.game.usercmd_t;
+import jake2.qcommon.Cvar;
+import jake2.qcommon.xcommand_t;
+
+/**
+ * RW
+ */
+public final class RW extends Globals {
+ static int mouse_buttonstate;
+ static int mouse_oldbuttonstate;
+ static int old_mouse_x;
+ static int old_mouse_y;
+ static boolean mlooking;
+
+ static void IN_MLookDown() {
+ mlooking = true;
+ }
+
+ static void IN_MLookUp() {
+ mlooking = false;
+ IN.CenterView();
+ }
+
+ static void IN_Init(/*in_state_t in_state_p*/) {
+ int mtype;
+ int i;
+
+// in_state = in_state_p;
+
+ // mouse variables
+ m_filter = Cvar.Get("m_filter", "0", 0);
+ in_mouse = Cvar.Get("in_mouse", "1", CVAR_ARCHIVE);
+ freelook = Cvar.Get("freelook", "0", 0 );
+ lookstrafe = Cvar.Get("lookstrafe", "0", 0);
+ sensitivity = Cvar.Get("sensitivity", "3", 0);
+ m_pitch = Cvar.Get("m_pitch", "0.022", 0);
+ m_yaw = Cvar.Get("m_yaw", "0.022", 0);
+ m_forward = Cvar.Get("m_forward", "1", 0);
+ m_side = Cvar.Get("m_side", "0.8", 0);
+
+ Cmd.AddCommand("+mlook", new xcommand_t() {
+ public void execute() {IN_MLookDown();}});
+ Cmd.AddCommand("-mlook", new xcommand_t() {
+ public void execute() {IN_MLookUp();}});
+
+ Cmd.AddCommand ("force_centerview", new xcommand_t() {
+ public void execute() {Force_CenterView_f();}});
+
+ IN.mouse_avail = true;
+ }
+
+ static void Force_CenterView_f() {
+ cl.viewangles[PITCH] = 0;
+ }
+
+ public static void IN_Shutdown() {
+ IN.mouse_avail = false;
+ }
+
+ static void IN_Frame() {
+ }
+
+ static void IN_Activate(boolean active) {
+ if (active)
+ IN.ActivateMouse();
+ else
+ IN.DeactivateMouse ();
+ }
+
+ static void IN_Commands() {
+ int i;
+
+ if (!IN.mouse_avail)
+ return;
+
+ for (i=0 ; i<3 ; i++) {
+ if ( (mouse_buttonstate & (1<<i)) != 0 && (mouse_oldbuttonstate & (1<<i)) == 0 )
+ KBD.Do_Key_Event(Key.K_MOUSE1 + i, true);
+
+ if ( (mouse_buttonstate & (1<<i)) == 0 && (mouse_oldbuttonstate & (1<<i)) != 0 )
+ KBD.Do_Key_Event(Key.K_MOUSE1 + i, false);
+ }
+ mouse_oldbuttonstate = mouse_buttonstate;
+ }
+
+ /*
+ ===========
+ IN_Move
+ ===========
+ */
+ static void IN_Move(usercmd_t cmd) {
+ if (!IN.mouse_avail)
+ return;
+
+ if (m_filter.value != 0.0f) {
+ KBD.mx = (KBD.mx + old_mouse_x) / 2;
+ KBD.my = (KBD.my + old_mouse_y) / 2;
+ }
+
+ old_mouse_x = KBD.mx;
+ old_mouse_y = KBD.my;
+
+ KBD.mx = (int)(KBD.mx * sensitivity.value);
+ KBD.my = (int)(KBD.my * sensitivity.value);
+
+ // add mouse X/Y movement to cmd
+ if ( (CL.in_strafe.state & 1) != 0 || ((lookstrafe.value != 0) && mlooking )) {
+ cmd.sidemove += m_side.value * KBD.mx;
+ } else {
+ cl.viewangles[YAW] -= m_yaw.value * KBD.mx;
+ }
+
+ if ( (mlooking || freelook.value != 0.0f) && (CL.in_strafe.state & 1) == 0) {
+ cl.viewangles[PITCH] += m_pitch.value * KBD.my;
+ } else {
+ cmd.forwardmove -= m_forward.value * KBD.my;
+ }
+ KBD.mx = KBD.my = 0;
+ }
+}
diff --git a/src/jake2/sys/Sys.java b/src/jake2/sys/Sys.java
new file mode 100644
index 0000000..6327531
--- /dev/null
+++ b/src/jake2/sys/Sys.java
@@ -0,0 +1,278 @@
+/*
+ * Sys.java
+ * Copyright (C) 2003
+ *
+ * $Id: Sys.java,v 1.1 2004-07-07 19:59:52 hzi Exp $
+ */
+/*
+Copyright (C) 1997-2001 Id Software, Inc.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+package jake2.sys;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+import jake2.Defines;
+import jake2.Globals;
+import jake2.client.CL;
+import jake2.game.Game;
+import jake2.game.game_export_t;
+import jake2.game.game_import_t;
+import jake2.qcommon.Com;
+import jake2.util.Lib;
+
+/**
+ * Sys
+ */
+public final class Sys extends Defines {
+
+ public static void StackTrace() {
+
+ StackTraceElement trace[] = new Throwable().getStackTrace();
+ Com.Println("StackTrace:");
+ for (int i = 0; i < trace.length; i++)
+ Com.Println("" + trace[i]);
+ }
+
+ public static void Error(String error) {
+
+ CL.Shutdown();
+ //StackTrace();
+ new Exception(error).printStackTrace();
+ System.exit(1);
+ }
+
+ public static void Quit() {
+ CL.Shutdown();
+
+ System.exit(0);
+ }
+
+ //ok!
+ public static File[] FindAll(String path, int musthave, int canthave) {
+
+ int index = path.lastIndexOf('/');
+
+ if (index != -1) {
+ findbase = path.substring(0, index);
+ findpattern = path.substring(index + 1, path.length());
+ }
+ else {
+ findbase = path;
+ findpattern = "*";
+ }
+
+ if (findpattern.equals("*.*")) {
+ findpattern = "*";
+ }
+
+ File fdir = new File(findbase);
+
+ if (!fdir.exists())
+ return null;
+
+ FilenameFilter filter = new FileFilter(findpattern, musthave, canthave);
+
+ return fdir.listFiles(filter);
+ }
+
+ /**
+ * Match the pattern findpattern against the filename.
+ *
+ * In the pattern string, `*' matches any sequence of characters,
+ * `?' matches any character, [SET] matches any character in the specified set,
+ * [!SET] matches any character not in the specified set.
+ * A set is composed of characters or ranges; a range looks like
+ * character hyphen character (as in 0-9 or A-Z).
+ * [0-9a-zA-Z_] is the set of characters allowed in C identifiers.
+ * Any other character in the pattern must be matched exactly.
+ * To suppress the special syntactic significance of any of `[]*?!-\',
+ * and match the character exactly, precede it with a `\'.
+ */
+ static class FileFilter implements FilenameFilter {
+
+ String regexpr;
+ int musthave, canthave;
+
+ FileFilter(String findpattern, int musthave, int canthave) {
+ this.regexpr = convert2regexpr(findpattern);
+ this.musthave = musthave;
+ this.canthave = canthave;
+
+ }
+
+ /*
+ * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
+ */
+ public boolean accept(File dir, String name) {
+ if (name.matches(regexpr)) {
+ return CompareAttributes(dir, musthave, canthave);
+ }
+ return false;
+ }
+
+ String convert2regexpr(String pattern) {
+
+ StringBuffer sb = new StringBuffer();
+
+ char c;
+ boolean escape = false;
+
+ String subst;
+
+ // convert pattern
+ for (int i = 0; i < pattern.length(); i++) {
+ c = pattern.charAt(i);
+ subst = null;
+ switch (c) {
+ case '*' :
+ subst = (!escape) ? ".*" : "*";
+ break;
+ case '.' :
+ subst = (!escape) ? "\\." : ".";
+ break;
+ case '!' :
+ subst = (!escape) ? "^" : "!";
+ break;
+ case '?' :
+ subst = (!escape) ? "." : "?";
+ break;
+ case '\\' :
+ escape = !escape;
+ break;
+ default :
+ escape = false;
+ }
+ if (subst != null) {
+ sb.append(subst);
+ escape = false;
+ }
+ else
+ sb.append(c);
+ }
+
+ // the converted pattern
+ String regexpr = sb.toString();
+
+ //Com.DPrintf("pattern: " + pattern + " regexpr: " + regexpr + '\n');
+ try {
+ Pattern.compile(regexpr);
+ }
+ catch (PatternSyntaxException e) {
+ Com.Printf("invalid file pattern ( *.* is used instead )\n");
+ return ".*"; // the default
+ }
+ return regexpr;
+ }
+
+ boolean CompareAttributes(File dir, int musthave, int canthave) {
+ // . and .. never match
+ String name = dir.getName();
+
+ if (Lib.strcmp(name, ".") == 0 || Lib.strcmp(name, "..") == 0)
+ return false;
+
+ return true;
+ }
+
+ }
+
+ private static long secbase = 0;
+ public static int Milliseconds() {
+ if (secbase == 0) {
+ secbase = System.currentTimeMillis();
+ return 0;
+ }
+ return Globals.curtime = (int)(System.currentTimeMillis() - secbase);
+ }
+
+ //============================================
+
+ static File[] fdir;
+ static int fileindex;
+ static String findbase;
+ static String findpattern;
+
+ // ok.
+ public static File FindFirst(String path, int musthave, int canthave) {
+
+ if (fdir != null)
+ Sys.Error("Sys_BeginFind without close");
+
+ // COM_FilePath (path, findbase);
+
+ fdir = FindAll(path, canthave, musthave);
+ fileindex =0;
+
+ if (fdir == null) return null;
+
+ return FindNext();
+ }
+
+ public static File FindNext() {
+
+ if (fileindex >= fdir.length)
+ return null;
+
+ return fdir[fileindex++];
+ }
+
+ public static void FindClose() {
+
+ if (fdir != null)
+ fdir = null;
+
+ }
+
+
+ public static void UnloadGame()
+ {
+ //TODO:implement UnloadGame
+ //Com.Error(Defines.ERR_FATAL, "UnloadGame not implemented!");
+
+ }
+
+ public static void SendKeyEvents() {
+ KBD.Update();
+
+ // grab frame time
+ Globals.sys_frame_time = Sys.Milliseconds();
+ }
+
+ public static game_export_t GetGameAPI(game_import_t gimport)
+ {
+ return Game.GetGameApi(gimport);
+ }
+
+ public static String GetClipboardData() {
+ // TODO: implement GetClipboardData
+ return null;
+ }
+
+ public static void ConsoleOutput(String msg)
+ {
+ if (Globals.nostdout != null && Globals.nostdout.value != 0)
+ return;
+
+ System.out.print(msg);
+ }
+
+}