0

refac: xcommand_t -> Runnable

This commit is contained in:
2026-02-11 20:40:18 +03:00
parent d2b9627ff3
commit 3fc318dee2
22 changed files with 696 additions and 1242 deletions

View File

@@ -36,7 +36,6 @@ import lwjake2.qcommon.SZ;
import lwjake2.qcommon.netadr_t; import lwjake2.qcommon.netadr_t;
import lwjake2.qcommon.qfiles; import lwjake2.qcommon.qfiles;
import lwjake2.qcommon.sizebuf_t; import lwjake2.qcommon.sizebuf_t;
import lwjake2.qcommon.xcommand_t;
import lwjake2.server.SV_MAIN; import lwjake2.server.SV_MAIN;
import lwjake2.sound.S; import lwjake2.sound.S;
import lwjake2.sys.IN; import lwjake2.sys.IN;
@@ -55,6 +54,7 @@ import java.nio.ByteOrder;
/** /**
* CL * CL
*/ */
@SuppressWarnings("ALL")
public final class CL { public final class CL {
static int precache_check; // for autodownload of precache items static int precache_check; // for autodownload of precache items
@@ -102,26 +102,23 @@ public final class CL {
* *
* Stop recording a demo. * Stop recording a demo.
*/ */
static xcommand_t Stop_f = new xcommand_t() { static Runnable Stop_f = () -> {
public void execute() { try {
try { int len;
int len; if (!Globals.cls.demorecording) {
Com.Printf("Not recording a demo.\n");
if (!Globals.cls.demorecording) { return;
Com.Printf("Not recording a demo.\n");
return;
}
// finish up
len = -1;
Globals.cls.demofile.writeInt(EndianHandler.swapInt(len));
Globals.cls.demofile.close();
Globals.cls.demofile = null;
Globals.cls.demorecording = false;
Com.Printf("Stopped demo.\n");
} catch (IOException e) {
} }
// finish up
len = -1;
Globals.cls.demofile.writeInt(EndianHandler.swapInt(len));
Globals.cls.demofile.close();
Globals.cls.demofile = null;
Globals.cls.demorecording = false;
Com.Printf("Stopped demo.\n");
} catch (IOException e) {
} }
}; };
@@ -133,191 +130,181 @@ public final class CL {
* record <demoname> * record <demoname>
* Begins recording a demo from the current position. * Begins recording a demo from the current position.
*/ */
static xcommand_t Record_f = new xcommand_t() { static Runnable Record_f = () -> {
public void execute() { try {
try { String name;
String name; byte buf_data[] = new byte[Defines.MAX_MSGLEN];
byte buf_data[] = new byte[Defines.MAX_MSGLEN]; sizebuf_t buf = new sizebuf_t();
sizebuf_t buf = new sizebuf_t(); int i;
int i; entity_state_t ent;
entity_state_t ent;
if (Cmd.Argc() != 2) { if (Cmd.Argc() != 2) {
Com.Printf("record <demoname>\n"); Com.Printf("record <demoname>\n");
return; return;
} }
if (Globals.cls.demorecording) { if (Globals.cls.demorecording) {
Com.Printf("Already recording.\n"); Com.Printf("Already recording.\n");
return; return;
} }
if (Globals.cls.state != Defines.ca_active) { if (Globals.cls.state != Defines.ca_active) {
Com.Printf("You must be in a level to record.\n"); Com.Printf("You must be in a level to record.\n");
return; return;
} }
// //
// open the demo file // open the demo file
// //
name = FS.Gamedir() + "/demos/" + Cmd.Argv(1) + ".dm2"; name = FS.Gamedir() + "/demos/" + Cmd.Argv(1) + ".dm2";
Com.Printf("recording to " + name + ".\n"); Com.Printf("recording to " + name + ".\n");
FS.CreatePath(name); FS.CreatePath(name);
Globals.cls.demofile = new RandomAccessFile(name, "rw"); Globals.cls.demofile = new RandomAccessFile(name, "rw");
if (Globals.cls.demofile == null) { if (Globals.cls.demofile == null) {
Com.Printf("ERROR: couldn't open.\n"); Com.Printf("ERROR: couldn't open.\n");
return; return;
} }
Globals.cls.demorecording = true; Globals.cls.demorecording = true;
// don't start saving messages until a non-delta compressed // don't start saving messages until a non-delta compressed
// message is received // message is received
Globals.cls.demowaiting = true; Globals.cls.demowaiting = true;
// //
// write out messages to hold the startup information // write out messages to hold the startup information
// //
SZ.Init(buf, buf_data, Defines.MAX_MSGLEN); SZ.Init(buf, buf_data, Defines.MAX_MSGLEN);
// send the serverdata // send the serverdata
MSG.WriteByte(buf, Defines.svc_serverdata); MSG.WriteByte(buf, Defines.svc_serverdata);
MSG.WriteInt(buf, Defines.PROTOCOL_VERSION); MSG.WriteInt(buf, Defines.PROTOCOL_VERSION);
MSG.WriteInt(buf, 0x10000 + Globals.cl.servercount); MSG.WriteInt(buf, 0x10000 + Globals.cl.servercount);
MSG.WriteByte(buf, 1); // demos are always attract loops MSG.WriteByte(buf, 1); // demos are always attract loops
MSG.WriteString(buf, Globals.cl.gamedir); MSG.WriteString(buf, Globals.cl.gamedir);
MSG.WriteShort(buf, Globals.cl.playernum); MSG.WriteShort(buf, Globals.cl.playernum);
MSG.WriteString(buf, Globals.cl.configstrings[Defines.CS_NAME]); MSG.WriteString(buf, Globals.cl.configstrings[Defines.CS_NAME]);
// configstrings // configstrings
for (i = 0; i < Defines.MAX_CONFIGSTRINGS; i++) { for (i = 0; i < Defines.MAX_CONFIGSTRINGS; i++) {
if (Globals.cl.configstrings[i].length() > 0) { if (Globals.cl.configstrings[i].length() > 0) {
if (buf.cursize + Globals.cl.configstrings[i].length() if (buf.cursize + Globals.cl.configstrings[i].length()
+ 32 > buf.maxsize) { + 32 > buf.maxsize) {
// write it out // write it out
Globals.cls.demofile.writeInt(EndianHandler.swapInt(buf.cursize));
Globals.cls.demofile
.write(buf.data, 0, buf.cursize);
buf.cursize = 0;
}
MSG.WriteByte(buf, Defines.svc_configstring);
MSG.WriteShort(buf, i);
MSG.WriteString(buf, Globals.cl.configstrings[i]);
}
}
// baselines
nullstate.clear();
for (i = 0; i < Defines.MAX_EDICTS; i++) {
ent = Globals.cl_entities[i].baseline;
if (ent.modelindex == 0)
continue;
if (buf.cursize + 64 > buf.maxsize) { // write it out
Globals.cls.demofile.writeInt(EndianHandler.swapInt(buf.cursize)); Globals.cls.demofile.writeInt(EndianHandler.swapInt(buf.cursize));
Globals.cls.demofile.write(buf.data, 0, buf.cursize); Globals.cls.demofile
.write(buf.data, 0, buf.cursize);
buf.cursize = 0; buf.cursize = 0;
} }
MSG.WriteByte(buf, Defines.svc_spawnbaseline); MSG.WriteByte(buf, Defines.svc_configstring);
MSG.WriteDeltaEntity(nullstate, MSG.WriteShort(buf, i);
Globals.cl_entities[i].baseline, buf, true, true); MSG.WriteString(buf, Globals.cl.configstrings[i]);
} }
MSG.WriteByte(buf, Defines.svc_stufftext);
MSG.WriteString(buf, "precache\n");
// write it to the demo file
Globals.cls.demofile.writeInt(EndianHandler.swapInt(buf.cursize));
Globals.cls.demofile.write(buf.data, 0, buf.cursize);
// the rest of the demo file will be individual frames
} catch (IOException e) {
} }
// baselines
nullstate.clear();
for (i = 0; i < Defines.MAX_EDICTS; i++) {
ent = Globals.cl_entities[i].baseline;
if (ent.modelindex == 0)
continue;
if (buf.cursize + 64 > buf.maxsize) { // write it out
Globals.cls.demofile.writeInt(EndianHandler.swapInt(buf.cursize));
Globals.cls.demofile.write(buf.data, 0, buf.cursize);
buf.cursize = 0;
}
MSG.WriteByte(buf, Defines.svc_spawnbaseline);
MSG.WriteDeltaEntity(nullstate,
Globals.cl_entities[i].baseline, buf, true, true);
}
MSG.WriteByte(buf, Defines.svc_stufftext);
MSG.WriteString(buf, "precache\n");
// write it to the demo file
Globals.cls.demofile.writeInt(EndianHandler.swapInt(buf.cursize));
Globals.cls.demofile.write(buf.data, 0, buf.cursize);
// the rest of the demo file will be individual frames
} catch (IOException e) {
} }
}; };
/** /**
* ForwardToServer_f * ForwardToServer_f
*/ */
static xcommand_t ForwardToServer_f = new xcommand_t() { static Runnable ForwardToServer_f = () -> {
public void execute() { if (Globals.cls.state != Defines.ca_connected
if (Globals.cls.state != Defines.ca_connected && Globals.cls.state != Defines.ca_active) {
&& Globals.cls.state != Defines.ca_active) { Com.Printf("Can't \"" + Cmd.Argv(0) + "\", not connected\n");
Com.Printf("Can't \"" + Cmd.Argv(0) + "\", not connected\n"); return;
return; }
}
// don't forward the first argument // don't forward the first argument
if (Cmd.Argc() > 1) { if (Cmd.Argc() > 1) {
MSG.WriteByte(Globals.cls.netchan.message, MSG.WriteByte(Globals.cls.netchan.message,
Defines.clc_stringcmd); Defines.clc_stringcmd);
SZ.Print(Globals.cls.netchan.message, Cmd.Args()); SZ.Print(Globals.cls.netchan.message, Cmd.Args());
}
} }
}; };
/** /**
* Pause_f * Pause_f
*/ */
static xcommand_t Pause_f = new xcommand_t() { static Runnable Pause_f = () -> {
public void execute() { // never pause in multiplayer
// never pause in multiplayer
if (Cvar.VariableValue("maxclients") > 1 if (Cvar.VariableValue("maxclients") > 1
|| Globals.server_state == 0) { || Globals.server_state == 0) {
Cvar.SetValue("paused", 0); Cvar.SetValue("paused", 0);
return; return;
}
Cvar.SetValue("paused", Globals.cl_paused.value);
} }
Cvar.SetValue("paused", Globals.cl_paused.value);
}; };
/** /**
* Quit_f * Quit_f
*/ */
static xcommand_t Quit_f = new xcommand_t() { static Runnable Quit_f = () -> {
public void execute() { Disconnect();
Disconnect(); Com.Quit();
Com.Quit();
}
}; };
/** /**
* Connect_f * Connect_f
*/ */
static xcommand_t Connect_f = new xcommand_t() { static Runnable Connect_f = () -> {
public void execute() { String server;
String server;
if (Cmd.Argc() != 2) { if (Cmd.Argc() != 2) {
Com.Printf("usage: connect <server>\n"); Com.Printf("usage: connect <server>\n");
return; return;
}
if (Globals.server_state != 0) {
// if running a local server, kill it and reissue
SV_MAIN.SV_Shutdown("Server quit\n", false);
} else {
Disconnect();
}
server = Cmd.Argv(1);
NET.Config(true); // allow remote
Disconnect();
Globals.cls.state = Defines.ca_connecting;
//strncpy (cls.servername, server, sizeof(cls.servername)-1);
Globals.cls.servername = server;
Globals.cls.connect_time = -99999;
// CL_CheckForResend() will fire immediately
} }
if (Globals.server_state != 0) {
// if running a local server, kill it and reissue
SV_MAIN.SV_Shutdown("Server quit\n", false);
} else {
Disconnect();
}
server = Cmd.Argv(1);
NET.Config(true); // allow remote
Disconnect();
Globals.cls.state = Defines.ca_connecting;
//strncpy (cls.servername, server, sizeof(cls.servername)-1);
Globals.cls.servername = server;
Globals.cls.connect_time = -99999;
// CL_CheckForResend() will fire immediately
}; };
/** /**
@@ -325,77 +312,68 @@ public final class CL {
* *
* Send the rest of the command line over as an unconnected command. * Send the rest of the command line over as an unconnected command.
*/ */
static xcommand_t Rcon_f = new xcommand_t() { static Runnable Rcon_f = () -> {
public void execute() { if (Globals.rcon_client_password.string.length() == 0) {
Com.Printf("You must set 'rcon_password' before\nissuing an rcon command.\n");
return;
}
if (Globals.rcon_client_password.string.length() == 0) { StringBuffer message = new StringBuffer(1024);
Com.Printf("You must set 'rcon_password' before\nissuing an rcon command.\n");
// connection less packet
message.append('\u00ff');
message.append('\u00ff');
message.append('\u00ff');
message.append('\u00ff');
// allow remote
NET.Config(true);
message.append("rcon ");
message.append(Globals.rcon_client_password.string);
message.append(" ");
for (int i = 1; i < Cmd.Argc(); i++) {
message.append(Cmd.Argv(i));
message.append(" ");
}
netadr_t to = new netadr_t();
if (Globals.cls.state >= Defines.ca_connected)
to = Globals.cls.netchan.remote_address;
else {
if (Globals.rcon_address.string.length() == 0) {
Com.Printf("You must either be connected,\nor set the 'rcon_address' cvar\nto issue rcon commands\n");
return; return;
} }
NET.StringToAdr(Globals.rcon_address.string, to);
StringBuffer message = new StringBuffer(1024); if (to.port == 0) to.port = Defines.PORT_SERVER;
// connection less packet
message.append('\u00ff');
message.append('\u00ff');
message.append('\u00ff');
message.append('\u00ff');
// allow remote
NET.Config(true);
message.append("rcon ");
message.append(Globals.rcon_client_password.string);
message.append(" ");
for (int i = 1; i < Cmd.Argc(); i++) {
message.append(Cmd.Argv(i));
message.append(" ");
}
netadr_t to = new netadr_t();
if (Globals.cls.state >= Defines.ca_connected)
to = Globals.cls.netchan.remote_address;
else {
if (Globals.rcon_address.string.length() == 0) {
Com.Printf("You must either be connected,\nor set the 'rcon_address' cvar\nto issue rcon commands\n");
return;
}
NET.StringToAdr(Globals.rcon_address.string, to);
if (to.port == 0) to.port = Defines.PORT_SERVER;
}
message.append('\0');
String b = message.toString();
NET.SendPacket(Defines.NS_CLIENT, b.length(), Lib.stringToBytes(b), to);
} }
message.append('\0');
String b = message.toString();
NET.SendPacket(Defines.NS_CLIENT, b.length(), Lib.stringToBytes(b), to);
}; };
static xcommand_t Disconnect_f = new xcommand_t() { static Runnable Disconnect_f = () -> Com.Error(Defines.ERR_DROP, "Disconnected from server");
public void execute() {
Com.Error(Defines.ERR_DROP, "Disconnected from server");
}
};
/** /**
* Changing_f * Changing_f
* *
* Just sent as a hint to the client that they should drop to full console. * Just sent as a hint to the client that they should drop to full console.
*/ */
static xcommand_t Changing_f = new xcommand_t() { static Runnable Changing_f = () -> {
public void execute() { //ZOID
//ZOID //if we are downloading, we don't change!
//if we are downloading, we don't change! // This so we don't suddenly stop downloading a map
// This so we don't suddenly stop downloading a map
if (Globals.cls.download != null) if (Globals.cls.download != null)
return; return;
SCR.BeginLoadingPlaque(); SCR.BeginLoadingPlaque();
Globals.cls.state = Defines.ca_connected; // not active anymore, but Globals.cls.state = Defines.ca_connected; // not active anymore, but
// not disconnected // not disconnected
Com.Printf("\nChanging map...\n"); Com.Printf("\nChanging map...\n");
}
}; };
/** /**
@@ -403,93 +381,89 @@ public final class CL {
* *
* The server is changing levels. * The server is changing levels.
*/ */
static xcommand_t Reconnect_f = new xcommand_t() { static Runnable Reconnect_f = () -> {
public void execute() { //ZOID
//ZOID //if we are downloading, we don't change! This so we don't suddenly
//if we are downloading, we don't change! This so we don't suddenly // stop downloading a map
// stop downloading a map if (Globals.cls.download != null)
if (Globals.cls.download != null) return;
return;
S.StopAllSounds(); S.StopAllSounds();
if (Globals.cls.state == Defines.ca_connected) { if (Globals.cls.state == Defines.ca_connected) {
Com.Printf("reconnecting...\n"); Com.Printf("reconnecting...\n");
Globals.cls.state = Defines.ca_connected; Globals.cls.state = Defines.ca_connected;
MSG.WriteChar(Globals.cls.netchan.message, MSG.WriteChar(Globals.cls.netchan.message,
Defines.clc_stringcmd); Defines.clc_stringcmd);
MSG.WriteString(Globals.cls.netchan.message, "new"); MSG.WriteString(Globals.cls.netchan.message, "new");
return; return;
} }
if (Globals.cls.servername != null) { if (Globals.cls.servername != null) {
if (Globals.cls.state >= Defines.ca_connected) { if (Globals.cls.state >= Defines.ca_connected) {
Disconnect(); Disconnect();
Globals.cls.connect_time = Globals.cls.realtime - 1500; Globals.cls.connect_time = Globals.cls.realtime - 1500;
} else } else
Globals.cls.connect_time = -99999; // fire immediately Globals.cls.connect_time = -99999; // fire immediately
Globals.cls.state = Defines.ca_connecting; Globals.cls.state = Defines.ca_connecting;
Com.Printf("reconnecting...\n"); Com.Printf("reconnecting...\n");
}
} }
}; };
/** /**
* PingServers_f * PingServers_f
*/ */
static xcommand_t PingServers_f = new xcommand_t() { static Runnable PingServers_f = () -> {
public void execute() { int i;
int i; netadr_t adr = new netadr_t();
netadr_t adr = new netadr_t(); //char name[32];
//char name[32]; String name;
String name; String adrstring;
String adrstring; cvar_t noudp;
cvar_t noudp; cvar_t noipx;
cvar_t noipx;
NET.Config(true); // allow remote NET.Config(true); // allow remote
// send a broadcast packet // send a broadcast packet
Com.Printf("pinging broadcast...\n"); Com.Printf("pinging broadcast...\n");
noudp = Cvar.Get("noudp", "0", Defines.CVAR_NOSET); noudp = Cvar.Get("noudp", "0", Defines.CVAR_NOSET);
if (noudp.value == 0.0f) { if (noudp.value == 0.0f) {
adr.type = Defines.NA_BROADCAST; adr.type = Defines.NA_BROADCAST;
adr.port = Defines.PORT_SERVER; adr.port = Defines.PORT_SERVER;
//adr.port = BigShort(PORT_SERVER); //adr.port = BigShort(PORT_SERVER);
Netchan.OutOfBandPrint(Defines.NS_CLIENT, adr, "info " Netchan.OutOfBandPrint(Defines.NS_CLIENT, adr, "info "
+ Defines.PROTOCOL_VERSION); + Defines.PROTOCOL_VERSION);
}
// we use no IPX
noipx = Cvar.Get("noipx", "1", Defines.CVAR_NOSET);
if (noipx.value == 0.0f) {
adr.type = Defines.NA_BROADCAST_IPX;
//adr.port = BigShort(PORT_SERVER);
adr.port = Defines.PORT_SERVER;
Netchan.OutOfBandPrint(Defines.NS_CLIENT, adr, "info "
+ Defines.PROTOCOL_VERSION);
}
// send a packet to each address book entry
for (i = 0; i < 16; i++) {
//Com_sprintf (name, sizeof(name), "adr%i", i);
name = "adr" + i;
adrstring = Cvar.VariableString(name);
if (adrstring == null || adrstring.length() == 0)
continue;
Com.Printf("pinging " + adrstring + "...\n");
if (!NET.StringToAdr(adrstring, adr)) {
Com.Printf("Bad address: " + adrstring + "\n");
continue;
} }
if (adr.port == 0)
// we use no IPX
noipx = Cvar.Get("noipx", "1", Defines.CVAR_NOSET);
if (noipx.value == 0.0f) {
adr.type = Defines.NA_BROADCAST_IPX;
//adr.port = BigShort(PORT_SERVER); //adr.port = BigShort(PORT_SERVER);
adr.port = Defines.PORT_SERVER; adr.port = Defines.PORT_SERVER;
Netchan.OutOfBandPrint(Defines.NS_CLIENT, adr, "info " Netchan.OutOfBandPrint(Defines.NS_CLIENT, adr, "info "
+ Defines.PROTOCOL_VERSION); + Defines.PROTOCOL_VERSION);
}
// send a packet to each address book entry
for (i = 0; i < 16; i++) {
//Com_sprintf (name, sizeof(name), "adr%i", i);
name = "adr" + i;
adrstring = Cvar.VariableString(name);
if (adrstring == null || adrstring.length() == 0)
continue;
Com.Printf("pinging " + adrstring + "...\n");
if (!NET.StringToAdr(adrstring, adr)) {
Com.Printf("Bad address: " + adrstring + "\n");
continue;
}
if (adr.port == 0)
//adr.port = BigShort(PORT_SERVER);
adr.port = Defines.PORT_SERVER;
Netchan.OutOfBandPrint(Defines.NS_CLIENT, adr, "info "
+ Defines.PROTOCOL_VERSION);
}
} }
}; };
@@ -498,31 +472,27 @@ public final class CL {
* *
* Load or download any custom player skins and models. * Load or download any custom player skins and models.
*/ */
static xcommand_t Skins_f = new xcommand_t() { static Runnable Skins_f = () -> {
public void execute() { int i;
int i;
for (i = 0; i < Defines.MAX_CLIENTS; i++) { for (i = 0; i < Defines.MAX_CLIENTS; i++) {
if (Globals.cl.configstrings[Defines.CS_PLAYERSKINS + i] == null) if (Globals.cl.configstrings[Defines.CS_PLAYERSKINS + i] == null)
continue; continue;
Com.Printf("client " + i + ": " Com.Printf("client " + i + ": "
+ Globals.cl.configstrings[Defines.CS_PLAYERSKINS + i] + Globals.cl.configstrings[Defines.CS_PLAYERSKINS + i]
+ "\n"); + "\n");
SCR.UpdateScreen(); SCR.UpdateScreen();
Sys.SendKeyEvents(); // pump message loop Sys.SendKeyEvents(); // pump message loop
CL_parse.ParseClientinfo(i); CL_parse.ParseClientinfo(i);
}
} }
}; };
/** /**
* Userinfo_f * Userinfo_f
*/ */
static xcommand_t Userinfo_f = new xcommand_t() { static Runnable Userinfo_f = () -> {
public void execute() { Com.Printf("User info settings:\n");
Com.Printf("User info settings:\n"); Info.Print(Cvar.Userinfo());
Info.Print(Cvar.Userinfo());
}
}; };
/** /**
@@ -531,12 +501,10 @@ public final class CL {
* Restart the sound subsystem so it can pick up new parameters and flush * Restart the sound subsystem so it can pick up new parameters and flush
* all sounds. * all sounds.
*/ */
static xcommand_t Snd_Restart_f = new xcommand_t() { static Runnable Snd_Restart_f = () -> {
public void execute() { S.Shutdown();
S.Shutdown(); S.Init();
S.Init(); CL_parse.RegisterSounds();
CL_parse.RegisterSounds();
}
}; };
// ENV_CNT is map load, ENV_CNT+1 is first env map // ENV_CNT is map load, ENV_CNT+1 is first env map
@@ -551,28 +519,26 @@ public final class CL {
* The server will send this command right before allowing the client into * The server will send this command right before allowing the client into
* the server. * the server.
*/ */
static xcommand_t Precache_f = new xcommand_t() { static Runnable Precache_f = () -> {
public void execute() { // Yet another hack to let old demos work the old precache sequence.
// Yet another hack to let old demos work the old precache sequence. if (Cmd.Argc() < 2) {
if (Cmd.Argc() < 2) {
int iw[] = { 0 }; // for detecting cheater maps int iw[] = { 0 }; // for detecting cheater maps
CM.CM_LoadMap(Globals.cl.configstrings[Defines.CS_MODELS + 1], CM.CM_LoadMap(Globals.cl.configstrings[Defines.CS_MODELS + 1],
true, iw); true, iw);
CL_parse.RegisterSounds(); CL_parse.RegisterSounds();
CL_view.PrepRefresh(); CL_view.PrepRefresh();
return; return;
}
CL.precache_check = Defines.CS_MODELS;
CL.precache_spawncount = Lib.atoi(Cmd.Argv(1));
CL.precache_model = null;
CL.precache_model_skin = 0;
RequestNextDownload();
} }
CL.precache_check = Defines.CS_MODELS;
CL.precache_spawncount = Lib.atoi(Cmd.Argv(1));
CL.precache_model = null;
CL.precache_model_skin = 0;
RequestNextDownload();
}; };
private static int extratime; private static int extratime;
@@ -729,7 +695,7 @@ public final class CL {
SCR.StopCinematic(); SCR.StopCinematic();
if (Globals.cls.demorecording) if (Globals.cls.demorecording)
Stop_f.execute(); Stop_f.run();
// send a disconnect message to the server // send a disconnect message to the server
fin = (char) Defines.clc_stringcmd + "disconnect"; fin = (char) Defines.clc_stringcmd + "disconnect";

View File

@@ -29,7 +29,6 @@ import lwjake2.qcommon.MSG;
import lwjake2.qcommon.Netchan; import lwjake2.qcommon.Netchan;
import lwjake2.qcommon.SZ; import lwjake2.qcommon.SZ;
import lwjake2.qcommon.sizebuf_t; import lwjake2.qcommon.sizebuf_t;
import lwjake2.qcommon.xcommand_t;
import lwjake2.sys.IN; import lwjake2.sys.IN;
import lwjake2.util.Lib; import lwjake2.util.Lib;
import lwjake2.util.Math3D; import lwjake2.util.Math3D;
@@ -37,6 +36,7 @@ import lwjake2.util.Math3D;
/** /**
* CL_input * CL_input
*/ */
@SuppressWarnings("ALL")
public class CL_input { public class CL_input {
static long frame_msec; static long frame_msec;
@@ -487,167 +487,39 @@ public class CL_input {
* ============ CL_InitInput ============ * ============ CL_InitInput ============
*/ */
static void InitInput() { static void InitInput() {
Cmd.AddCommand("centerview", new xcommand_t() { Cmd.AddCommand("centerview", IN::CenterView);
public void execute() {
IN.CenterView();
}
});
Cmd.AddCommand("+moveup", new xcommand_t() { Cmd.AddCommand("+moveup", CL_input::IN_UpDown);
public void execute() { Cmd.AddCommand("-moveup", CL_input::IN_UpUp);
IN_UpDown(); Cmd.AddCommand("+movedown", CL_input::IN_DownDown);
} Cmd.AddCommand("-movedown", CL_input::IN_DownUp);
}); Cmd.AddCommand("+left", CL_input::IN_LeftDown);
Cmd.AddCommand("-moveup", new xcommand_t() { Cmd.AddCommand("-left", CL_input::IN_LeftUp);
public void execute() { Cmd.AddCommand("+right", CL_input::IN_RightDown);
IN_UpUp(); Cmd.AddCommand("-right", CL_input::IN_RightUp);
} Cmd.AddCommand("+forward", CL_input::IN_ForwardDown);
}); Cmd.AddCommand("-forward", CL_input::IN_ForwardUp);
Cmd.AddCommand("+movedown", new xcommand_t() { Cmd.AddCommand("+back", CL_input::IN_BackDown);
public void execute() { Cmd.AddCommand("-back", CL_input::IN_BackUp);
IN_DownDown(); Cmd.AddCommand("+lookup", CL_input::IN_LookupDown);
} Cmd.AddCommand("-lookup", CL_input::IN_LookupUp);
}); Cmd.AddCommand("+lookdown", CL_input::IN_LookdownDown);
Cmd.AddCommand("-movedown", new xcommand_t() { Cmd.AddCommand("-lookdown", CL_input::IN_LookdownUp);
public void execute() { Cmd.AddCommand("+strafe", CL_input::IN_StrafeDown);
IN_DownUp(); Cmd.AddCommand("-strafe", CL_input::IN_StrafeUp);
} Cmd.AddCommand("+moveleft", CL_input::IN_MoveleftDown);
}); Cmd.AddCommand("-moveleft", CL_input::IN_MoveleftUp);
Cmd.AddCommand("+left", new xcommand_t() { Cmd.AddCommand("+moveright", CL_input::IN_MoverightDown);
public void execute() { Cmd.AddCommand("-moveright", CL_input::IN_MoverightUp);
IN_LeftDown(); Cmd.AddCommand("+speed", CL_input::IN_SpeedDown);
} Cmd.AddCommand("-speed", CL_input::IN_SpeedUp);
}); Cmd.AddCommand("+attack", CL_input::IN_AttackDown);
Cmd.AddCommand("-left", new xcommand_t() { Cmd.AddCommand("-attack", CL_input::IN_AttackUp);
public void execute() { Cmd.AddCommand("+use", CL_input::IN_UseDown);
IN_LeftUp(); Cmd.AddCommand("-use", CL_input::IN_UseUp);
} Cmd.AddCommand("impulse", CL_input::IN_Impulse);
}); Cmd.AddCommand("+klook", CL_input::IN_KLookDown);
Cmd.AddCommand("+right", new xcommand_t() { Cmd.AddCommand("-klook", CL_input::IN_KLookUp);
public void execute() {
IN_RightDown();
}
});
Cmd.AddCommand("-right", new xcommand_t() {
public void execute() {
IN_RightUp();
}
});
Cmd.AddCommand("+forward", new xcommand_t() {
public void execute() {
IN_ForwardDown();
}
});
Cmd.AddCommand("-forward", new xcommand_t() {
public void execute() {
IN_ForwardUp();
}
});
Cmd.AddCommand("+back", new xcommand_t() {
public void execute() {
IN_BackDown();
}
});
Cmd.AddCommand("-back", new xcommand_t() {
public void execute() {
IN_BackUp();
}
});
Cmd.AddCommand("+lookup", new xcommand_t() {
public void execute() {
IN_LookupDown();
}
});
Cmd.AddCommand("-lookup", new xcommand_t() {
public void execute() {
IN_LookupUp();
}
});
Cmd.AddCommand("+lookdown", new xcommand_t() {
public void execute() {
IN_LookdownDown();
}
});
Cmd.AddCommand("-lookdown", new xcommand_t() {
public void execute() {
IN_LookdownUp();
}
});
Cmd.AddCommand("+strafe", new xcommand_t() {
public void execute() {
IN_StrafeDown();
}
});
Cmd.AddCommand("-strafe", new xcommand_t() {
public void execute() {
IN_StrafeUp();
}
});
Cmd.AddCommand("+moveleft", new xcommand_t() {
public void execute() {
IN_MoveleftDown();
}
});
Cmd.AddCommand("-moveleft", new xcommand_t() {
public void execute() {
IN_MoveleftUp();
}
});
Cmd.AddCommand("+moveright", new xcommand_t() {
public void execute() {
IN_MoverightDown();
}
});
Cmd.AddCommand("-moveright", new xcommand_t() {
public void execute() {
IN_MoverightUp();
}
});
Cmd.AddCommand("+speed", new xcommand_t() {
public void execute() {
IN_SpeedDown();
}
});
Cmd.AddCommand("-speed", new xcommand_t() {
public void execute() {
IN_SpeedUp();
}
});
Cmd.AddCommand("+attack", new xcommand_t() {
public void execute() {
IN_AttackDown();
}
});
Cmd.AddCommand("-attack", new xcommand_t() {
public void execute() {
IN_AttackUp();
}
});
Cmd.AddCommand("+use", new xcommand_t() {
public void execute() {
IN_UseDown();
}
});
Cmd.AddCommand("-use", new xcommand_t() {
public void execute() {
IN_UseUp();
}
});
Cmd.AddCommand("impulse", new xcommand_t() {
public void execute() {
IN_Impulse();
}
});
Cmd.AddCommand("+klook", new xcommand_t() {
public void execute() {
IN_KLookDown();
}
});
Cmd.AddCommand("-klook", new xcommand_t() {
public void execute() {
IN_KLookUp();
}
});
cl_nodelta = Cvar.Get("cl_nodelta", "0", 0); cl_nodelta = Cvar.Get("cl_nodelta", "0", 0);
} }

View File

@@ -29,7 +29,6 @@ import lwjake2.qcommon.Cvar;
import lwjake2.qcommon.FS; import lwjake2.qcommon.FS;
import lwjake2.qcommon.MSG; import lwjake2.qcommon.MSG;
import lwjake2.qcommon.SZ; import lwjake2.qcommon.SZ;
import lwjake2.qcommon.xcommand_t;
import lwjake2.render.model_t; import lwjake2.render.model_t;
import lwjake2.sound.S; import lwjake2.sound.S;
import lwjake2.sys.Sys; import lwjake2.sys.Sys;
@@ -41,6 +40,7 @@ import java.io.RandomAccessFile;
/** /**
* CL_parse * CL_parse
*/ */
@SuppressWarnings("ALL")
public class CL_parse { public class CL_parse {
//// cl_parse.c -- parse a message received from the server //// cl_parse.c -- parse a message received from the server
@@ -131,44 +131,42 @@ public class CL_parse {
* *
* Request a download from the server =============== * Request a download from the server ===============
*/ */
public static xcommand_t Download_f = new xcommand_t() { public static Runnable Download_f = () -> {
public void execute() { String filename;
String filename;
if (Cmd.Argc() != 2) { if (Cmd.Argc() != 2) {
Com.Printf("Usage: download <filename>\n"); Com.Printf("Usage: download <filename>\n");
return; return;
}
filename = Cmd.Argv(1);
if (filename.indexOf("..") != -1) {
Com.Printf("Refusing to download a path with ..\n");
return;
}
if (FS.LoadFile(filename) != null) { // it exists, no need to
// download
Com.Printf("File already exists.\n");
return;
}
Globals.cls.downloadname = filename;
Com.Printf("Downloading " + Globals.cls.downloadname + "\n");
// download to a temp name, and only rename
// to the real name when done, so if interrupted
// a runt file wont be left
Globals.cls.downloadtempname = Com
.StripExtension(Globals.cls.downloadname);
Globals.cls.downloadtempname += ".tmp";
MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd);
MSG.WriteString(Globals.cls.netchan.message, "download "
+ Globals.cls.downloadname);
Globals.cls.downloadnumber++;
} }
filename = Cmd.Argv(1);
if (filename.indexOf("..") != -1) {
Com.Printf("Refusing to download a path with ..\n");
return;
}
if (FS.LoadFile(filename) != null) { // it exists, no need to
// download
Com.Printf("File already exists.\n");
return;
}
Globals.cls.downloadname = filename;
Com.Printf("Downloading " + Globals.cls.downloadname + "\n");
// download to a temp name, and only rename
// to the real name when done, so if interrupted
// a runt file wont be left
Globals.cls.downloadtempname = Com
.StripExtension(Globals.cls.downloadname);
Globals.cls.downloadtempname += ".tmp";
MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd);
MSG.WriteString(Globals.cls.netchan.message, "download "
+ Globals.cls.downloadname);
Globals.cls.downloadnumber++;
}; };
/* /*

View File

@@ -25,7 +25,6 @@ import lwjake2.qcommon.Cbuf;
import lwjake2.qcommon.Com; import lwjake2.qcommon.Com;
import lwjake2.qcommon.Cvar; import lwjake2.qcommon.Cvar;
import lwjake2.qcommon.FS; import lwjake2.qcommon.FS;
import lwjake2.qcommon.xcommand_t;
import lwjake2.util.Lib; import lwjake2.util.Lib;
import lwjake2.util.Vargs; import lwjake2.util.Vargs;
@@ -36,108 +35,100 @@ import java.util.Arrays;
/** /**
* Console * Console
*/ */
@SuppressWarnings("ALL")
public final class Console extends Globals { public final class Console extends Globals {
public static xcommand_t ToggleConsole_f = new xcommand_t() { public static Runnable ToggleConsole_f = () -> {
public void execute() { SCR.EndLoadingPlaque(); // get rid of loading plaque
SCR.EndLoadingPlaque(); // get rid of loading plaque
if (Globals.cl.attractloop) { if (Globals.cl.attractloop) {
Cbuf.AddText("killserver\n"); Cbuf.AddText("killserver\n");
return; return;
} }
if (Globals.cls.state == Defines.ca_disconnected) { if (Globals.cls.state == Defines.ca_disconnected) {
// start the demo loop again // start the demo loop again
Cbuf.AddText("d1\n"); Cbuf.AddText("d1\n");
return; return;
} }
Key.ClearTyping(); Key.ClearTyping();
Console.ClearNotify(); Console.ClearNotify();
if (Globals.cls.key_dest == Defines.key_console) { if (Globals.cls.key_dest == Defines.key_console) {
Menu.ForceMenuOff(); Menu.ForceMenuOff();
Cvar.Set("paused", "0"); Cvar.Set("paused", "0");
} else { } else {
Menu.ForceMenuOff(); Menu.ForceMenuOff();
Globals.cls.key_dest = Defines.key_console; Globals.cls.key_dest = Defines.key_console;
if (Cvar.VariableValue("maxclients") == 1 if (Cvar.VariableValue("maxclients") == 1
&& Globals.server_state != 0) && Globals.server_state != 0)
Cvar.Set("paused", "1"); Cvar.Set("paused", "1");
}
} }
}; };
public static xcommand_t Clear_f = new xcommand_t() { public static Runnable Clear_f = () -> Arrays.fill(Globals.con.text, (byte) ' ');
public void execute() {
Arrays.fill(Globals.con.text, (byte) ' '); public static Runnable Dump_f = () -> {
int l, x;
int line;
RandomAccessFile f;
byte[] buffer = new byte[1024];
String name;
if (Cmd.Argc() != 2) {
Com.Printf("usage: condump <filename>\n");
return;
} }
};
public static xcommand_t Dump_f = new xcommand_t() { //Com_sprintf (name, sizeof(name), "%s/%s.txt", FS_Gamedir(),
public void execute() { // Cmd_Argv(1));
name = FS.Gamedir() + "/" + Cmd.Argv(1) + ".txt";
int l, x; Com.Printf("Dumped console text to " + name + ".\n");
int line; FS.CreatePath(name);
RandomAccessFile f; f = Lib.fopen(name, "rw");
byte[] buffer = new byte[1024]; if (f == null) {
String name; Com.Printf("ERROR: couldn't open.\n");
return;
}
if (Cmd.Argc() != 2) { // skip empty lines
Com.Printf("usage: condump <filename>\n"); for (l = con.current - con.totallines + 1; l <= con.current; l++) {
return; line = (l % con.totallines) * con.linewidth;
} for (x = 0; x < con.linewidth; x++)
if (con.text[line + x] != ' ')
break;
if (x != con.linewidth)
break;
}
//Com_sprintf (name, sizeof(name), "%s/%s.txt", FS_Gamedir(), // write the remaining lines
// Cmd_Argv(1)); buffer[con.linewidth] = 0;
name = FS.Gamedir() + "/" + Cmd.Argv(1) + ".txt"; for (; l <= con.current; l++) {
line = (l % con.totallines) * con.linewidth;
Com.Printf("Dumped console text to " + name + ".\n"); //strncpy (buffer, line, con.linewidth);
FS.CreatePath(name); System.arraycopy(con.text, line, buffer, 0, con.linewidth);
f = Lib.fopen(name, "rw"); for (x = con.linewidth - 1; x >= 0; x--) {
if (f == null) { if (buffer[x] == ' ')
Com.Printf("ERROR: couldn't open.\n"); buffer[x] = 0;
return; else
}
// skip empty lines
for (l = con.current - con.totallines + 1; l <= con.current; l++) {
line = (l % con.totallines) * con.linewidth;
for (x = 0; x < con.linewidth; x++)
if (con.text[line + x] != ' ')
break;
if (x != con.linewidth)
break; break;
} }
for (x = 0; buffer[x] != 0; x++)
buffer[x] &= 0x7f;
// write the remaining lines buffer[x] = '\n';
buffer[con.linewidth] = 0; // fprintf (f, "%s\n", buffer);
for (; l <= con.current; l++) { try {
line = (l % con.totallines) * con.linewidth; f.write(buffer, 0, x + 1);
//strncpy (buffer, line, con.linewidth); } catch (IOException e) {
System.arraycopy(con.text, line, buffer, 0, con.linewidth);
for (x = con.linewidth - 1; x >= 0; x--) {
if (buffer[x] == ' ')
buffer[x] = 0;
else
break;
}
for (x = 0; buffer[x] != 0; x++)
buffer[x] &= 0x7f;
buffer[x] = '\n';
// fprintf (f, "%s\n", buffer);
try {
f.write(buffer, 0, x + 1);
} catch (IOException e) {
}
} }
Lib.fclose(f);
} }
Lib.fclose(f);
}; };
/** /**
@@ -242,40 +233,34 @@ public final class Console extends Globals {
/* /*
* ================ Con_ToggleChat_f ================ * ================ Con_ToggleChat_f ================
*/ */
static xcommand_t ToggleChat_f = new xcommand_t() { static Runnable ToggleChat_f = () -> {
public void execute() { Key.ClearTyping();
Key.ClearTyping();
if (cls.key_dest == key_console) { if (cls.key_dest == key_console) {
if (cls.state == ca_active) { if (cls.state == ca_active) {
Menu.ForceMenuOff(); Menu.ForceMenuOff();
cls.key_dest = key_game; cls.key_dest = key_game;
} }
} else } else
cls.key_dest = key_console; cls.key_dest = key_console;
ClearNotify(); ClearNotify();
}
}; };
/* /*
* ================ Con_MessageMode_f ================ * ================ Con_MessageMode_f ================
*/ */
static xcommand_t MessageMode_f = new xcommand_t() { static Runnable MessageMode_f = () -> {
public void execute() { chat_team = false;
chat_team = false; cls.key_dest = key_message;
cls.key_dest = key_message;
}
}; };
/* /*
* ================ Con_MessageMode2_f ================ * ================ Con_MessageMode2_f ================
*/ */
static xcommand_t MessageMode2_f = new xcommand_t() { static Runnable MessageMode2_f = () -> {
public void execute() { chat_team = true;
chat_team = true; cls.key_dest = key_message;
cls.key_dest = key_message;
}
}; };
/* /*

View File

@@ -24,7 +24,6 @@ import lwjake2.game.Cmd;
import lwjake2.qcommon.Cbuf; import lwjake2.qcommon.Cbuf;
import lwjake2.qcommon.Com; import lwjake2.qcommon.Com;
import lwjake2.qcommon.Cvar; import lwjake2.qcommon.Cvar;
import lwjake2.qcommon.xcommand_t;
import lwjake2.util.Lib; import lwjake2.util.Lib;
import java.io.IOException; import java.io.IOException;
@@ -34,6 +33,7 @@ import java.util.Vector;
/** /**
* Key * Key
*/ */
@SuppressWarnings("ALL")
public class Key extends Globals { public class Key extends Globals {
// //
// these are the key numbers that should be passed to Key_Event // these are the key numbers that should be passed to Key_Event
@@ -317,7 +317,7 @@ public class Key extends Globals {
if (!down) if (!down)
return; return;
Console.ToggleConsole_f.execute(); Console.ToggleConsole_f.run();
return; return;
} }
@@ -709,11 +709,7 @@ public class Key extends Globals {
return; return;
} }
public static xcommand_t Bind_f = new xcommand_t() { public static Runnable Bind_f = Key::Key_Bind_f;
public void execute() {
Key_Bind_f();
}
};
static void Key_Bind_f() { static void Key_Bind_f() {
int c = Cmd.Argc(); int c = Cmd.Argc();
@@ -757,11 +753,7 @@ public class Key extends Globals {
Globals.keybindings[keynum] = binding; Globals.keybindings[keynum] = binding;
} }
static xcommand_t Unbind_f = new xcommand_t() { static Runnable Unbind_f = Key::Key_Unbind_f;
public void execute() {
Key_Unbind_f();
}
};
static void Key_Unbind_f() { static void Key_Unbind_f() {
@@ -779,22 +771,14 @@ public class Key extends Globals {
Key.SetBinding(b, null); Key.SetBinding(b, null);
} }
static xcommand_t Unbindall_f = new xcommand_t() { static Runnable Unbindall_f = Key::Key_Unbindall_f;
public void execute() {
Key_Unbindall_f();
}
};
static void Key_Unbindall_f() { static void Key_Unbindall_f() {
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)
Key.SetBinding(i, null); Key.SetBinding(i, null);
} }
static xcommand_t Bindlist_f = new xcommand_t() { static Runnable Bindlist_f = Key::Key_Bindlist_f;
public void execute() {
Key_Bindlist_f();
}
};
static void Key_Bindlist_f() { static void Key_Bindlist_f() {
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)

View File

@@ -26,7 +26,6 @@ import lwjake2.qcommon.Com;
import lwjake2.qcommon.Cvar; import lwjake2.qcommon.Cvar;
import lwjake2.qcommon.FS; import lwjake2.qcommon.FS;
import lwjake2.qcommon.netadr_t; import lwjake2.qcommon.netadr_t;
import lwjake2.qcommon.xcommand_t;
import lwjake2.sound.S; import lwjake2.sound.S;
import lwjake2.sys.NET; import lwjake2.sys.NET;
import lwjake2.sys.Sys; import lwjake2.sys.Sys;
@@ -45,11 +44,12 @@ import java.util.Comparator;
* *
* *
*/ */
@SuppressWarnings("ALL")
abstract class keyfunc_t { abstract class keyfunc_t {
abstract String execute(int key); abstract String execute(int key);
} }
@SuppressWarnings("ALL")
public final class Menu extends Key { public final class Menu extends Key {
static int m_main_cursor; static int m_main_cursor;
@@ -66,7 +66,7 @@ public final class Menu extends Key {
// won't disrupt the sound // won't disrupt the sound
static xcommand_t m_drawfunc; static Runnable m_drawfunc;
static keyfunc_t m_keyfunc; static keyfunc_t m_keyfunc;
@@ -76,7 +76,7 @@ public final class Menu extends Key {
public final static int MAX_MENU_DEPTH = 8; public final static int MAX_MENU_DEPTH = 8;
public static class menulayer_t { public static class menulayer_t {
xcommand_t draw; Runnable draw;
keyfunc_t key; keyfunc_t key;
} }
@@ -181,7 +181,7 @@ public final class Menu extends Key {
viddef.height / 2 - 110, name); viddef.height / 2 - 110, name);
} }
static void PushMenu(xcommand_t draw, keyfunc_t key) { //, String(*key) static void PushMenu(Runnable draw, keyfunc_t key) { //, String(*key)
// (int k) ) { // (int k) ) {
int i; int i;
@@ -435,11 +435,7 @@ public final class Menu extends Key {
*/ */
static final int MAIN_ITEMS = 5; static final int MAIN_ITEMS = 5;
static xcommand_t Main_Draw = new xcommand_t() { static Runnable Main_Draw = Menu::Main_Draw;
public void execute() {
Main_Draw();
}
};
static void Main_Draw() { static void Main_Draw() {
int i; int i;
@@ -540,18 +536,10 @@ public final class Menu extends Key {
return null; return null;
} }
static xcommand_t Menu_Main = new xcommand_t() { static Runnable Menu_Main = Menu::Menu_Main_f;
public void execute() {
Menu_Main_f();
}
};
static void Menu_Main_f() { static void Menu_Main_f() {
PushMenu(new xcommand_t() { PushMenu(Menu::Main_Draw, new keyfunc_t() {
public void execute() {
Main_Draw();
}
}, new keyfunc_t() {
public String execute(int key) { public String execute(int key) {
return Main_Key(key); return Main_Key(key);
} }
@@ -642,19 +630,11 @@ public final class Menu extends Key {
return Default_MenuKey(s_multiplayer_menu, key); return Default_MenuKey(s_multiplayer_menu, key);
} }
static xcommand_t Menu_Multiplayer = new xcommand_t() { static Runnable Menu_Multiplayer = Menu::Menu_Multiplayer_f;
public void execute() {
Menu_Multiplayer_f();
}
};
static void Menu_Multiplayer_f() { static void Menu_Multiplayer_f() {
Multiplayer_MenuInit(); Multiplayer_MenuInit();
PushMenu(new xcommand_t() { PushMenu(Menu::Multiplayer_MenuDraw, new keyfunc_t() {
public void execute() {
Multiplayer_MenuDraw();
}
}, new keyfunc_t() {
public String execute(int key) { public String execute(int key) {
return Multiplayer_MenuKey(key); return Multiplayer_MenuKey(key);
} }
@@ -1154,11 +1134,7 @@ public final class Menu extends Key {
Menu_Center(s_keys_menu); Menu_Center(s_keys_menu);
} }
static xcommand_t Keys_MenuDraw = new xcommand_t() { static Runnable Keys_MenuDraw = Menu::Keys_MenuDraw_f;
public void execute() {
Keys_MenuDraw_f();
}
};
static void Keys_MenuDraw_f() { static void Keys_MenuDraw_f() {
Menu_AdjustCursor(s_keys_menu, 1); Menu_AdjustCursor(s_keys_menu, 1);
@@ -1207,19 +1183,11 @@ public final class Menu extends Key {
} }
} }
static xcommand_t Menu_Keys = new xcommand_t() { static Runnable Menu_Keys = Menu::Menu_Keys_f;
public void execute() {
Menu_Keys_f();
}
};
static void Menu_Keys_f() { static void Menu_Keys_f() {
Keys_MenuInit(); Keys_MenuInit();
PushMenu(new xcommand_t() { PushMenu(Menu::Keys_MenuDraw_f, new keyfunc_t() {
public void execute() {
Keys_MenuDraw_f();
}
}, new keyfunc_t() {
public String execute(int key) { public String execute(int key) {
return Keys_MenuKey_f(key); return Keys_MenuKey_f(key);
} }
@@ -1420,7 +1388,7 @@ public final class Menu extends Key {
// the text box won't show up unless we do a buffer swap // the text box won't show up unless we do a buffer swap
re.EndFrame(); re.EndFrame();
CL.Snd_Restart_f.execute(); CL.Snd_Restart_f.run();
} }
} }
@@ -1650,19 +1618,11 @@ public final class Menu extends Key {
return Default_MenuKey(s_options_menu, key); return Default_MenuKey(s_options_menu, key);
} }
static xcommand_t Menu_Options = new xcommand_t() { static Runnable Menu_Options = Menu::Menu_Options_f;
public void execute() {
Menu_Options_f();
}
};
static void Menu_Options_f() { static void Menu_Options_f() {
Options_MenuInit(); Options_MenuInit();
PushMenu(new xcommand_t() { PushMenu(Menu::Options_MenuDraw, new keyfunc_t() {
public void execute() {
Options_MenuDraw();
}
}, new keyfunc_t() {
public String execute(int key) { public String execute(int key) {
return Options_MenuKey(key); return Options_MenuKey(key);
} }
@@ -1677,19 +1637,11 @@ public final class Menu extends Key {
* ======================================================================= * =======================================================================
*/ */
static xcommand_t Menu_Video = new xcommand_t() { static Runnable Menu_Video = Menu::Menu_Video_f;
public void execute() {
Menu_Video_f();
}
};
static void Menu_Video_f() { static void Menu_Video_f() {
VID.MenuInit(); VID.MenuInit();
PushMenu(new xcommand_t() { PushMenu(VID::MenuDraw, new keyfunc_t() {
public void execute() {
VID.MenuDraw();
}
}, new keyfunc_t() {
public String execute(int key) { public String execute(int key) {
return VID.MenuKey(key); return VID.MenuKey(key);
} }
@@ -1897,11 +1849,7 @@ public final class Menu extends Key {
} }
static xcommand_t Menu_Credits = new xcommand_t() { static Runnable Menu_Credits = Menu::Menu_Credits_f;
public void execute() {
Menu_Credits_f();
}
};
static void Menu_Credits_f() { static void Menu_Credits_f() {
int n; int n;
@@ -1933,11 +1881,7 @@ public final class Menu extends Key {
} }
credits_start_time = cls.realtime; credits_start_time = cls.realtime;
PushMenu(new xcommand_t() { PushMenu(Menu::Credits_MenuDraw, new keyfunc_t() {
public void execute() {
Credits_MenuDraw();
}
}, new keyfunc_t() {
public String execute(int key) { public String execute(int key) {
return Credits_Key(key); return Credits_Key(key);
} }
@@ -2108,19 +2052,11 @@ public final class Menu extends Key {
return Default_MenuKey(s_game_menu, key); return Default_MenuKey(s_game_menu, key);
} }
static xcommand_t Menu_Game = new xcommand_t() { static Runnable Menu_Game = Menu::Menu_Game_f;
public void execute() {
Menu_Game_f();
}
};
static void Menu_Game_f() { static void Menu_Game_f() {
Game_MenuInit(); Game_MenuInit();
PushMenu(new xcommand_t() { PushMenu(Menu::Game_MenuDraw, new keyfunc_t() {
public void execute() {
Game_MenuDraw();
}
}, new keyfunc_t() {
public String execute(int key) { public String execute(int key) {
return Game_MenuKey(key); return Game_MenuKey(key);
} }
@@ -2238,19 +2174,11 @@ public final class Menu extends Key {
return Default_MenuKey(s_loadgame_menu, key); return Default_MenuKey(s_loadgame_menu, key);
} }
static xcommand_t Menu_LoadGame = new xcommand_t() { static Runnable Menu_LoadGame = Menu::Menu_LoadGame_f;
public void execute() {
Menu_LoadGame_f();
}
};
static void Menu_LoadGame_f() { static void Menu_LoadGame_f() {
LoadGame_MenuInit(); LoadGame_MenuInit();
PushMenu(new xcommand_t() { PushMenu(Menu::LoadGame_MenuDraw, new keyfunc_t() {
public void execute() {
LoadGame_MenuDraw();
}
}, new keyfunc_t() {
public String execute(int key) { public String execute(int key) {
return LoadGame_MenuKey(key); return LoadGame_MenuKey(key);
} }
@@ -2324,22 +2252,14 @@ public final class Menu extends Key {
return Default_MenuKey(s_savegame_menu, key); return Default_MenuKey(s_savegame_menu, key);
} }
static xcommand_t Menu_SaveGame = new xcommand_t() { static Runnable Menu_SaveGame = Menu::Menu_SaveGame_f;
public void execute() {
Menu_SaveGame_f();
}
};
static void Menu_SaveGame_f() { static void Menu_SaveGame_f() {
if (0 == Globals.server_state) if (0 == Globals.server_state)
return; // not playing a game return; // not playing a game
SaveGame_MenuInit(); SaveGame_MenuInit();
PushMenu(new xcommand_t() { PushMenu(Menu::SaveGame_MenuDraw, new keyfunc_t() {
public void execute() {
SaveGame_MenuDraw();
}
}, new keyfunc_t() {
public String execute(int key) { public String execute(int key) {
return SaveGame_MenuKey(key); return SaveGame_MenuKey(key);
} }
@@ -2443,7 +2363,7 @@ public final class Menu extends Key {
re.EndFrame(); re.EndFrame();
// send out info packets // send out info packets
CL.PingServers_f.execute(); CL.PingServers_f.run();
} }
static void SearchLocalGamesFunc(Object self) { static void SearchLocalGamesFunc(Object self) {
@@ -2520,19 +2440,11 @@ public final class Menu extends Key {
return Default_MenuKey(s_joinserver_menu, key); return Default_MenuKey(s_joinserver_menu, key);
} }
static xcommand_t Menu_JoinServer = new xcommand_t() { static Runnable Menu_JoinServer = Menu::Menu_JoinServer_f;
public void execute() {
Menu_JoinServer_f();
}
};
static void Menu_JoinServer_f() { static void Menu_JoinServer_f() {
JoinServer_MenuInit(); JoinServer_MenuInit();
PushMenu(new xcommand_t() { PushMenu(Menu::JoinServer_MenuDraw, new keyfunc_t() {
public void execute() {
JoinServer_MenuDraw();
}
}, new keyfunc_t() {
public String execute(int key) { public String execute(int key) {
return JoinServer_MenuKey(key); return JoinServer_MenuKey(key);
} }
@@ -2905,17 +2817,9 @@ public final class Menu extends Key {
return Default_MenuKey(s_startserver_menu, key); return Default_MenuKey(s_startserver_menu, key);
} }
static xcommand_t Menu_StartServer = new xcommand_t() { static Runnable Menu_StartServer = Menu::Menu_StartServer_f;
public void execute() {
Menu_StartServer_f();
}
};
static xcommand_t startServer_MenuDraw = new xcommand_t() { static Runnable startServer_MenuDraw = Menu::StartServer_MenuDraw;
public void execute() {
StartServer_MenuDraw();
}
};
static keyfunc_t startServer_MenuKey = new keyfunc_t() { static keyfunc_t startServer_MenuKey = new keyfunc_t() {
public String execute(int key) { public String execute(int key) {
return StartServer_MenuKey(key); return StartServer_MenuKey(key);
@@ -3379,19 +3283,11 @@ public final class Menu extends Key {
return Default_MenuKey(s_dmoptions_menu, key); return Default_MenuKey(s_dmoptions_menu, key);
} }
static xcommand_t Menu_DMOptions = new xcommand_t() { static Runnable Menu_DMOptions = Menu::Menu_DMOptions_f;
public void execute() {
Menu_DMOptions_f();
}
};
static void Menu_DMOptions_f() { static void Menu_DMOptions_f() {
DMOptions_MenuInit(); DMOptions_MenuInit();
PushMenu(new xcommand_t() { PushMenu(Menu::DMOptions_MenuDraw, new keyfunc_t() {
public void execute() {
DMOptions_MenuDraw();
}
}, new keyfunc_t() {
public String execute(int key) { public String execute(int key) {
return DMOptions_MenuKey(key); return DMOptions_MenuKey(key);
} }
@@ -3544,19 +3440,11 @@ public final class Menu extends Key {
return Default_MenuKey(s_downloadoptions_menu, key); return Default_MenuKey(s_downloadoptions_menu, key);
} }
static xcommand_t Menu_DownloadOptions = new xcommand_t() { static Runnable Menu_DownloadOptions = Menu::Menu_DownloadOptions_f;
public void execute() {
Menu_DownloadOptions_f();
}
};
static void Menu_DownloadOptions_f() { static void Menu_DownloadOptions_f() {
DownloadOptions_MenuInit(); DownloadOptions_MenuInit();
PushMenu(new xcommand_t() { PushMenu(Menu::DownloadOptions_MenuDraw, new keyfunc_t() {
public void execute() {
DownloadOptions_MenuDraw();
}
}, new keyfunc_t() {
public String execute(int key) { public String execute(int key) {
return DownloadOptions_MenuKey(key); return DownloadOptions_MenuKey(key);
} }
@@ -3619,30 +3507,18 @@ public final class Menu extends Key {
return Default_MenuKey(s_addressbook_menu, key); return Default_MenuKey(s_addressbook_menu, key);
} }
static xcommand_t AddressBook_MenuDraw = new xcommand_t() { static Runnable AddressBook_MenuDraw = Menu::AddressBook_MenuDraw_f;
public void execute() {
AddressBook_MenuDraw_f();
}
};
static void AddressBook_MenuDraw_f() { static void AddressBook_MenuDraw_f() {
Banner("m_banner_addressbook"); Banner("m_banner_addressbook");
Menu_Draw(s_addressbook_menu); Menu_Draw(s_addressbook_menu);
} }
static xcommand_t Menu_AddressBook = new xcommand_t() { static Runnable Menu_AddressBook = Menu::Menu_AddressBook_f;
public void execute() {
Menu_AddressBook_f();
}
};
static void Menu_AddressBook_f() { static void Menu_AddressBook_f() {
AddressBook_MenuInit(); AddressBook_MenuInit();
PushMenu(new xcommand_t() { PushMenu(Menu::AddressBook_MenuDraw_f, new keyfunc_t() {
public void execute() {
AddressBook_MenuDraw_f();
}
}, new keyfunc_t() {
public String execute(int key) { public String execute(int key) {
return AddressBook_MenuKey_f(key); return AddressBook_MenuKey_f(key);
} }
@@ -4180,11 +4056,7 @@ public final class Menu extends Key {
return Default_MenuKey(s_player_config_menu, key); return Default_MenuKey(s_player_config_menu, key);
} }
static xcommand_t Menu_PlayerConfig = new xcommand_t() { static Runnable Menu_PlayerConfig = Menu::Menu_PlayerConfig_f;
public void execute() {
Menu_PlayerConfig_f();
}
};
static void Menu_PlayerConfig_f() { static void Menu_PlayerConfig_f() {
if (!PlayerConfig_MenuInit()) { if (!PlayerConfig_MenuInit()) {
@@ -4193,11 +4065,7 @@ public final class Menu extends Key {
return; return;
} }
Menu_SetStatusBar(s_multiplayer_menu, null); Menu_SetStatusBar(s_multiplayer_menu, null);
PushMenu(new xcommand_t() { PushMenu(Menu::PlayerConfig_MenuDraw, new keyfunc_t() {
public void execute() {
PlayerConfig_MenuDraw();
}
}, new keyfunc_t() {
public String execute(int key) { public String execute(int key) {
return PlayerConfig_MenuKey(key); return PlayerConfig_MenuKey(key);
} }
@@ -4223,7 +4091,7 @@ public final class Menu extends Key {
case 'Y': case 'Y':
case 'y': case 'y':
cls.key_dest = key_console; cls.key_dest = key_console;
CL.Quit_f.execute(); CL.Quit_f.run();
break; break;
default: default:
@@ -4243,18 +4111,10 @@ public final class Menu extends Key {
re.DrawPic((viddef.width - w) / 2, (viddef.height - h) / 2, "quit"); re.DrawPic((viddef.width - w) / 2, (viddef.height - h) / 2, "quit");
} }
static xcommand_t Menu_Quit = new xcommand_t() { static Runnable Menu_Quit = Menu::Menu_Quit_f;
public void execute() {
Menu_Quit_f();
}
};
static void Menu_Quit_f() { static void Menu_Quit_f() {
PushMenu(new xcommand_t() { PushMenu(Menu::Quit_Draw, new keyfunc_t() {
public void execute() {
Quit_Draw();
}
}, new keyfunc_t() {
public String execute(int key) { public String execute(int key) {
return Quit_Key(key); return Quit_Key(key);
} }
@@ -4306,7 +4166,7 @@ public final class Menu extends Key {
else else
re.DrawFadeScreen(); re.DrawFadeScreen();
m_drawfunc.execute(); m_drawfunc.run();
// delay playing the enter sound until after the // delay playing the enter sound until after the
// menu has been drawn, to avoid delay while // menu has been drawn, to avoid delay while

View File

@@ -28,7 +28,6 @@ import lwjake2.qcommon.FS;
import lwjake2.qcommon.MSG; import lwjake2.qcommon.MSG;
import lwjake2.qcommon.SZ; import lwjake2.qcommon.SZ;
import lwjake2.qcommon.qfiles; import lwjake2.qcommon.qfiles;
import lwjake2.qcommon.xcommand_t;
import lwjake2.sound.S; import lwjake2.sound.S;
import lwjake2.sys.Timer; import lwjake2.sys.Timer;
import lwjake2.util.Lib; import lwjake2.util.Lib;
@@ -42,6 +41,7 @@ import java.util.Arrays;
/** /**
* SCR * SCR
*/ */
@SuppressWarnings("ALL")
public final class SCR extends Globals { public final class SCR extends Globals {
// cl_scrn.c -- master for refresh, status bar, console, chat, notify, etc // cl_scrn.c -- master for refresh, status bar, console, chat, notify, etc
@@ -436,31 +436,11 @@ public final class SCR extends Globals {
// //
// register our commands // register our commands
// //
Cmd.AddCommand("timerefresh", new xcommand_t() { Cmd.AddCommand("timerefresh", SCR::TimeRefresh_f);
public void execute() { Cmd.AddCommand("loading", SCR::Loading_f);
TimeRefresh_f(); Cmd.AddCommand("sizeup", SCR::SizeUp_f);
} Cmd.AddCommand("sizedown", SCR::SizeDown_f);
}); Cmd.AddCommand("sky", SCR::Sky_f);
Cmd.AddCommand("loading", new xcommand_t() {
public void execute() {
Loading_f();
}
});
Cmd.AddCommand("sizeup", new xcommand_t() {
public void execute() {
SizeUp_f();
}
});
Cmd.AddCommand("sizedown", new xcommand_t() {
public void execute() {
SizeDown_f();
}
});
Cmd.AddCommand("sky", new xcommand_t() {
public void execute() {
Sky_f();
}
});
scr_initialized = true; scr_initialized = true;
} }
@@ -1300,11 +1280,7 @@ public final class SCR extends Globals {
crosshair_pic); crosshair_pic);
} }
private static xcommand_t updateScreenCallback = new xcommand_t() { private static Runnable updateScreenCallback = () -> UpdateScreen2();
public void execute() {
UpdateScreen2();
}
};
// wird anstelle von der richtigen UpdateScreen benoetigt // wird anstelle von der richtigen UpdateScreen benoetigt
public static void UpdateScreen() { public static void UpdateScreen() {

View File

@@ -23,7 +23,6 @@ import lwjake2.game.Cmd;
import lwjake2.game.cvar_t; import lwjake2.game.cvar_t;
import lwjake2.qcommon.Com; import lwjake2.qcommon.Com;
import lwjake2.qcommon.Cvar; import lwjake2.qcommon.Cvar;
import lwjake2.qcommon.xcommand_t;
import lwjake2.sys.Timer; import lwjake2.sys.Timer;
import lwjake2.util.Math3D; import lwjake2.util.Math3D;
import lwjake2.util.Vargs; import lwjake2.util.Vargs;
@@ -34,6 +33,7 @@ import java.nio.FloatBuffer;
/** /**
* V * V
*/ */
@SuppressWarnings("ALL")
public final class V extends Globals { public final class V extends Globals {
static cvar_t cl_testblend; static cvar_t cl_testblend;
@@ -235,31 +235,25 @@ public final class V extends Globals {
} }
} }
static xcommand_t Gun_Next_f = new xcommand_t() { static Runnable Gun_Next_f = () -> {
public void execute() { gun_frame++;
gun_frame++; Com.Printf("frame " + gun_frame + "\n");
Com.Printf("frame " + gun_frame + "\n");
}
}; };
static xcommand_t Gun_Prev_f = new xcommand_t() { static Runnable Gun_Prev_f = () -> {
public void execute() { gun_frame--;
gun_frame--; if (gun_frame < 0)
if (gun_frame < 0) gun_frame = 0;
gun_frame = 0; Com.Printf("frame " + gun_frame + "\n");
Com.Printf("frame " + gun_frame + "\n");
}
}; };
static xcommand_t Gun_Model_f = new xcommand_t() { static Runnable Gun_Model_f = () -> {
public void execute() { if (Cmd.Argc() != 2) {
if (Cmd.Argc() != 2) { gun_model = null;
gun_model = null; return;
return;
}
String name = "models/" + Cmd.Argv(1) + "/tris.md2";
gun_model = re.RegisterModel(name);
} }
String name = "models/" + Cmd.Argv(1) + "/tris.md2";
gun_model = re.RegisterModel(name);
}; };
/* /*
@@ -379,14 +373,10 @@ public final class V extends Globals {
/* /*
* ============= V_Viewpos_f ============= * ============= V_Viewpos_f =============
*/ */
static xcommand_t Viewpos_f = new xcommand_t() { static Runnable Viewpos_f = () -> Com.Printf("(%i %i %i) : %i\n", new Vargs(4).add(
public void execute() { (int) cl.refdef.vieworg[0]).add((int) cl.refdef.vieworg[1])
Com.Printf("(%i %i %i) : %i\n", new Vargs(4).add( .add((int) cl.refdef.vieworg[2]).add(
(int) cl.refdef.vieworg[0]).add((int) cl.refdef.vieworg[1]) (int) cl.refdef.viewangles[YAW]));
.add((int) cl.refdef.vieworg[2]).add(
(int) cl.refdef.viewangles[YAW]));
}
};
public static void Init() { public static void Init() {
Cmd.AddCommand("gun_next", Gun_Next_f); Cmd.AddCommand("gun_next", Gun_Next_f);

View File

@@ -24,7 +24,6 @@ import lwjake2.game.Cmd;
import lwjake2.game.cvar_t; import lwjake2.game.cvar_t;
import lwjake2.qcommon.Com; import lwjake2.qcommon.Com;
import lwjake2.qcommon.Cvar; import lwjake2.qcommon.Cvar;
import lwjake2.qcommon.xcommand_t;
import lwjake2.render.Renderer; import lwjake2.render.Renderer;
import lwjake2.sound.S; import lwjake2.sound.S;
import lwjake2.sys.IN; import lwjake2.sys.IN;
@@ -40,6 +39,7 @@ import java.awt.DisplayMode;
* *
* @author cwei * @author cwei
*/ */
@SuppressWarnings("ALL")
public class VID extends Globals { public class VID extends Globals {
// Main windowed and fullscreen graphics interface module. This module // Main windowed and fullscreen graphics interface module. This module
// is used for both the software and OpenGL rendering versions of the // is used for both the software and OpenGL rendering versions of the
@@ -282,7 +282,7 @@ public class VID extends Globals {
if ( Globals.cls.key_dest != Defines.key_console ) if ( Globals.cls.key_dest != Defines.key_console )
{ {
try { try {
Console.ToggleConsole_f.execute(); Console.ToggleConsole_f.run();
} catch (Exception e) { } catch (Exception e) {
} }
} }
@@ -311,11 +311,7 @@ public class VID extends Globals {
vid_modes[11].height = (int)vid_height.value; vid_modes[11].height = (int)vid_height.value;
/* Add some console commands that we want to handle */ /* Add some console commands that we want to handle */
Cmd.AddCommand ("vid_restart", new xcommand_t() { Cmd.AddCommand ("vid_restart", VID::Restart_f);
public void execute() {
Restart_f();
}
});
/* Disable the 3Dfx splash screen */ /* Disable the 3Dfx splash screen */
// putenv("FX_GLIDE_NO_SPLASH=0"); // putenv("FX_GLIDE_NO_SPLASH=0");

View File

@@ -18,7 +18,6 @@
package lwjake2.client; package lwjake2.client;
import lwjake2.qcommon.xcommand_t;
import lwjake2.render.image_t; import lwjake2.render.image_t;
import lwjake2.render.model_t; import lwjake2.render.model_t;
import lwjake2.sys.KBD; import lwjake2.sys.KBD;
@@ -95,7 +94,7 @@ public interface refexport_t {
* *
* *
*/ */
void updateScreen(xcommand_t callback); void updateScreen(Runnable callback);
int apiVersion(); int apiVersion();

View File

@@ -28,7 +28,6 @@ import lwjake2.qcommon.FS;
import lwjake2.qcommon.MSG; import lwjake2.qcommon.MSG;
import lwjake2.qcommon.SZ; import lwjake2.qcommon.SZ;
import lwjake2.qcommon.cmd_function_t; import lwjake2.qcommon.cmd_function_t;
import lwjake2.qcommon.xcommand_t;
import lwjake2.server.SV_GAME; import lwjake2.server.SV_GAME;
import lwjake2.util.Lib; import lwjake2.util.Lib;
@@ -39,102 +38,91 @@ import java.util.Vector;
/** /**
* Cmd * Cmd
*/ */
@SuppressWarnings("ALL")
public final class Cmd { public final class Cmd {
static xcommand_t List_f = new xcommand_t() { static Runnable List_f = () -> {
public void execute() { cmd_function_t cmd = Cmd.cmd_functions;
cmd_function_t cmd = Cmd.cmd_functions; int i = 0;
int i = 0;
while (cmd != null) { while (cmd != null) {
Com.Printf(cmd.name + '\n'); Com.Printf(cmd.name + '\n');
i++; i++;
cmd = cmd.next; cmd = cmd.next;
}
Com.Printf(i + " commands\n");
} }
Com.Printf(i + " commands\n");
}; };
static xcommand_t Exec_f = new xcommand_t() { static Runnable Exec_f = () -> {
public void execute() { if (Cmd.Argc() != 2) {
if (Cmd.Argc() != 2) { Com.Printf("exec <filename> : execute a script file\n");
Com.Printf("exec <filename> : execute a script file\n"); return;
return;
}
byte[] f = null;
f = FS.LoadFile(Cmd.Argv(1));
if (f == null) {
Com.Printf("couldn't exec " + Cmd.Argv(1) + "\n");
return;
}
Com.Printf("execing " + Cmd.Argv(1) + "\n");
Cbuf.InsertText(new String(f));
FS.FreeFile(f);
} }
byte[] f = null;
f = FS.LoadFile(Cmd.Argv(1));
if (f == null) {
Com.Printf("couldn't exec " + Cmd.Argv(1) + "\n");
return;
}
Com.Printf("execing " + Cmd.Argv(1) + "\n");
Cbuf.InsertText(new String(f));
FS.FreeFile(f);
}; };
static xcommand_t Echo_f = new xcommand_t() { static Runnable Echo_f = () -> {
public void execute() { for (int i = 1; i < Cmd.Argc(); i++) {
for (int i = 1; i < Cmd.Argc(); i++) { Com.Printf(Cmd.Argv(i) + " ");
Com.Printf(Cmd.Argv(i) + " ");
}
Com.Printf("'\n");
} }
Com.Printf("'\n");
}; };
static xcommand_t Alias_f = new xcommand_t() { static Runnable Alias_f = () -> {
public void execute() { cmdalias_t a = null;
cmdalias_t a = null; if (Cmd.Argc() == 1) {
if (Cmd.Argc() == 1) { Com.Printf("Current alias commands:\n");
Com.Printf("Current alias commands:\n");
for (a = Globals.cmd_alias; a != null; a = a.next) {
Com.Printf(a.name + " : " + a.value);
}
return;
}
String s = Cmd.Argv(1);
if (s.length() > Defines.MAX_ALIAS_NAME) {
Com.Printf("Alias name is too long\n");
return;
}
// if the alias already exists, reuse it
for (a = Globals.cmd_alias; a != null; a = a.next) { for (a = Globals.cmd_alias; a != null; a = a.next) {
if (s.equalsIgnoreCase(a.name)) { Com.Printf(a.name + " : " + a.value);
a.value = null;
break;
}
} }
return;
if (a == null) {
a = new cmdalias_t();
a.next = Globals.cmd_alias;
Globals.cmd_alias = a;
}
a.name = s;
// copy the rest of the command line
String cmd = "";
int c = Cmd.Argc();
for (int i = 2; i < c; i++) {
cmd = cmd + Cmd.Argv(i);
if (i != (c - 1))
cmd = cmd + " ";
}
cmd = cmd + "\n";
a.value = cmd;
} }
String s = Cmd.Argv(1);
if (s.length() > Defines.MAX_ALIAS_NAME) {
Com.Printf("Alias name is too long\n");
return;
}
// if the alias already exists, reuse it
for (a = Globals.cmd_alias; a != null; a = a.next) {
if (s.equalsIgnoreCase(a.name)) {
a.value = null;
break;
}
}
if (a == null) {
a = new cmdalias_t();
a.next = Globals.cmd_alias;
Globals.cmd_alias = a;
}
a.name = s;
// copy the rest of the command line
String cmd = "";
int c = Cmd.Argc();
for (int i = 2; i < c; i++) {
cmd = cmd + Cmd.Argv(i);
if (i != (c - 1))
cmd = cmd + " ";
}
cmd = cmd + "\n";
a.value = cmd;
}; };
public static xcommand_t Wait_f = new xcommand_t() { public static Runnable Wait_f = () -> Globals.cmd_wait = true;
public void execute() {
Globals.cmd_wait = true;
}
};
public static cmd_function_t cmd_functions = null; public static cmd_function_t cmd_functions = null;
@@ -304,7 +292,7 @@ public final class Cmd {
} }
} }
public static void AddCommand(String cmd_name, xcommand_t function) { public static void AddCommand(String cmd_name, Runnable function) {
cmd_function_t cmd; cmd_function_t cmd;
//Com.DPrintf("Cmd_AddCommand: " + cmd_name + "\n"); //Com.DPrintf("Cmd_AddCommand: " + cmd_name + "\n");
// fail if the command is a variable name // fail if the command is a variable name
@@ -409,7 +397,7 @@ public final class Cmd {
if (null == cmd.function) { // forward to server command if (null == cmd.function) { // forward to server command
Cmd.ExecuteString("cmd " + text); Cmd.ExecuteString("cmd " + text);
} else { } else {
cmd.function.execute(); cmd.function.run();
} }
return; return;
} }

View File

@@ -36,6 +36,7 @@ import java.io.RandomAccessFile;
* Com * Com
* *
*/ */
@SuppressWarnings("ALL")
public final class Com public final class Com
{ {
@@ -241,13 +242,7 @@ public final class Com
return new String(com_token, 0, len); return new String(com_token, 0, len);
} }
public static xcommand_t Error_f= new xcommand_t() public static Runnable Error_f= () -> Error(Defines.ERR_FATAL, Cmd.Argv(1));
{
public void execute() throws longjmpException
{
Error(Defines.ERR_FATAL, Cmd.Argv(1));
}
};
public static void Error(int code, String fmt) throws longjmpException public static void Error(int code, String fmt) throws longjmpException
{ {

View File

@@ -32,6 +32,7 @@ import java.util.Vector;
/** /**
* Cvar implements console variables. The original code is located in cvar.c * Cvar implements console variables. The original code is located in cvar.c
*/ */
@SuppressWarnings("ALL")
public class Cvar extends Globals { public class Cvar extends Globals {
/** /**
@@ -228,66 +229,61 @@ public class Cvar extends Globals {
* Set command, sets variables. * Set command, sets variables.
*/ */
static xcommand_t Set_f = new xcommand_t() { static Runnable Set_f = () -> {
public void execute() { int c;
int c; int flags;
int flags;
c = Cmd.Argc(); c = Cmd.Argc();
if (c != 3 && c != 4) { if (c != 3 && c != 4) {
Com.Printf("usage: set <variable> <value> [u / s]\n"); Com.Printf("usage: set <variable> <value> [u / s]\n");
return;
}
if (c == 4) {
if (Cmd.Argv(3).equals("u"))
flags = CVAR_USERINFO;
else if (Cmd.Argv(3).equals("s"))
flags = CVAR_SERVERINFO;
else {
Com.Printf("flags can only be 'u' or 's'\n");
return; return;
} }
Cvar.FullSet(Cmd.Argv(1), Cmd.Argv(2), flags);
if (c == 4) { } else
if (Cmd.Argv(3).equals("u")) Cvar.Set(Cmd.Argv(1), Cmd.Argv(2));
flags = CVAR_USERINFO;
else if (Cmd.Argv(3).equals("s"))
flags = CVAR_SERVERINFO;
else {
Com.Printf("flags can only be 'u' or 's'\n");
return;
}
Cvar.FullSet(Cmd.Argv(1), Cmd.Argv(2), flags);
} else
Cvar.Set(Cmd.Argv(1), Cmd.Argv(2));
}
}; };
/** /**
* List command, lists all available commands. * List command, lists all available commands.
*/ */
static xcommand_t List_f = new xcommand_t() { static Runnable List_f = () -> {
public void execute() { cvar_t var;
cvar_t var; int i;
int i;
i = 0; i = 0;
for (var = Globals.cvar_vars; var != null; var = var.next, i++) { for (var = Globals.cvar_vars; var != null; var = var.next, i++) {
if ((var.flags & CVAR_ARCHIVE) != 0) if ((var.flags & CVAR_ARCHIVE) != 0)
Com.Printf("*"); Com.Printf("*");
else else
Com.Printf(" "); Com.Printf(" ");
if ((var.flags & CVAR_USERINFO) != 0) if ((var.flags & CVAR_USERINFO) != 0)
Com.Printf("U"); Com.Printf("U");
else else
Com.Printf(" "); Com.Printf(" ");
if ((var.flags & CVAR_SERVERINFO) != 0) if ((var.flags & CVAR_SERVERINFO) != 0)
Com.Printf("S"); Com.Printf("S");
else else
Com.Printf(" "); Com.Printf(" ");
if ((var.flags & CVAR_NOSET) != 0) if ((var.flags & CVAR_NOSET) != 0)
Com.Printf("-"); Com.Printf("-");
else if ((var.flags & CVAR_LATCH) != 0) else if ((var.flags & CVAR_LATCH) != 0)
Com.Printf("L"); Com.Printf("L");
else else
Com.Printf(" "); Com.Printf(" ");
Com.Printf(" " + var.name + " \"" + var.string + "\"\n"); Com.Printf(" " + var.name + " \"" + var.string + "\"\n");
}
Com.Printf(i + " cvars\n");
} }
Com.Printf(i + " cvars\n");
}; };

View File

@@ -42,6 +42,7 @@ import java.util.List;
* *
* @author cwei * @author cwei
*/ */
@SuppressWarnings("ALL")
public final class FS extends Globals { public final class FS extends Globals {
/* /*
@@ -882,21 +883,9 @@ public final class FS extends Globals {
* InitFilesystem * InitFilesystem
*/ */
public static void InitFilesystem() { public static void InitFilesystem() {
Cmd.AddCommand("path", new xcommand_t() { Cmd.AddCommand("path", FS::Path_f);
public void execute() { Cmd.AddCommand("link", FS::Link_f);
Path_f(); Cmd.AddCommand("dir", FS::Dir_f);
}
});
Cmd.AddCommand("link", new xcommand_t() {
public void execute() {
Link_f();
}
});
Cmd.AddCommand("dir", new xcommand_t() {
public void execute() {
Dir_f();
}
});
fs_userdir = System.getProperty("user.home") + "/.lwjake2"; fs_userdir = System.getProperty("user.home") + "/.lwjake2";
FS.CreatePath(fs_userdir + "/"); FS.CreatePath(fs_userdir + "/");

View File

@@ -24,5 +24,5 @@ package lwjake2.qcommon;
public final class cmd_function_t { public final class cmd_function_t {
public cmd_function_t next = null; public cmd_function_t next = null;
public String name = null; public String name = null;
public xcommand_t function; public Runnable function;
} }

View File

@@ -1,27 +0,0 @@
/*
* 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 lwjake2.qcommon;
/**
* xcommand_t
*/
public abstract class xcommand_t {
abstract public void execute();
}

View File

@@ -20,7 +20,6 @@ package lwjake2.render;
import lwjake2.client.refdef_t; import lwjake2.client.refdef_t;
import lwjake2.client.refexport_t; import lwjake2.client.refexport_t;
import lwjake2.qcommon.xcommand_t;
import lwjake2.sys.KBD; import lwjake2.sys.KBD;
import java.awt.Dimension; import java.awt.Dimension;
@@ -166,8 +165,8 @@ public class DummyRenderer implements refexport_t {
/* (non-Javadoc) /* (non-Javadoc)
* @see jake2.client.refexport_t#updateScreen(jake2.qcommon.xcommand_t) * @see jake2.client.refexport_t#updateScreen(jake2.qcommon.xcommand_t)
*/ */
public void updateScreen(xcommand_t callback) { public void updateScreen(Runnable callback) {
callback.execute(); callback.run();
} }
/* (non-Javadoc) /* (non-Javadoc)

View File

@@ -22,7 +22,6 @@ import lwjake2.Defines;
import lwjake2.client.VID; import lwjake2.client.VID;
import lwjake2.client.viddef_t; import lwjake2.client.viddef_t;
import lwjake2.game.cvar_t; import lwjake2.game.cvar_t;
import lwjake2.qcommon.xcommand_t;
import java.awt.Dimension; import java.awt.Dimension;
import java.util.ArrayList; import java.util.ArrayList;
@@ -38,6 +37,7 @@ import org.lwjgl.opengl.GL11;
* *
* @author dsanders/cwei * @author dsanders/cwei
*/ */
@SuppressWarnings("ALL")
public abstract class LWJGLBase { public abstract class LWJGLBase {
// IMPORTED FUNCTIONS // IMPORTED FUNCTIONS
protected DisplayMode oldDisplayMode; protected DisplayMode oldDisplayMode;
@@ -345,7 +345,7 @@ public abstract class LWJGLBase {
* this is a hack for jogl renderers. * this is a hack for jogl renderers.
* @param callback * @param callback
*/ */
public final void updateScreen(xcommand_t callback) { public final void updateScreen(Runnable callback) {
callback.execute(); callback.run();
} }
} }

View File

@@ -30,7 +30,6 @@ import lwjake2.game.cvar_t;
import lwjake2.qcommon.Com; import lwjake2.qcommon.Com;
import lwjake2.qcommon.Cvar; import lwjake2.qcommon.Cvar;
import lwjake2.qcommon.qfiles; import lwjake2.qcommon.qfiles;
import lwjake2.qcommon.xcommand_t;
import lwjake2.render.glconfig_t; import lwjake2.render.glconfig_t;
import lwjake2.render.glstate_t; import lwjake2.render.glstate_t;
import lwjake2.render.image_t; import lwjake2.render.image_t;
@@ -53,6 +52,7 @@ import org.lwjgl.opengl.GL13;
* *
* @author cwei * @author cwei
*/ */
@SuppressWarnings("ALL")
public abstract class Main extends Base { public abstract class Main extends Base {
public static int[] d_8to24table = new int[256]; public static int[] d_8to24table = new int[256];
@@ -995,27 +995,11 @@ public abstract class Main extends Base {
vid_gamma = Cvar.Get("vid_gamma", "1.0", Globals.CVAR_ARCHIVE); vid_gamma = Cvar.Get("vid_gamma", "1.0", Globals.CVAR_ARCHIVE);
vid_ref = Cvar.Get("vid_ref", "lwjgl", Globals.CVAR_ARCHIVE); vid_ref = Cvar.Get("vid_ref", "lwjgl", Globals.CVAR_ARCHIVE);
Cmd.AddCommand("imagelist", new xcommand_t() { Cmd.AddCommand("imagelist", this::GL_ImageList_f);
public void execute() {
GL_ImageList_f();
}
});
Cmd.AddCommand("screenshot", new xcommand_t() { Cmd.AddCommand("screenshot", this::GL_ScreenShot_f);
public void execute() { Cmd.AddCommand("modellist", this::Mod_Modellist_f);
GL_ScreenShot_f(); Cmd.AddCommand("gl_strings", this::GL_Strings_f);
}
});
Cmd.AddCommand("modellist", new xcommand_t() {
public void execute() {
Mod_Modellist_f();
}
});
Cmd.AddCommand("gl_strings", new xcommand_t() {
public void execute() {
GL_Strings_f();
}
});
} }
/** /**

View File

@@ -35,7 +35,6 @@ import lwjake2.qcommon.Netchan;
import lwjake2.qcommon.SZ; import lwjake2.qcommon.SZ;
import lwjake2.qcommon.netadr_t; import lwjake2.qcommon.netadr_t;
import lwjake2.qcommon.sizebuf_t; import lwjake2.qcommon.sizebuf_t;
import lwjake2.qcommon.xcommand_t;
import lwjake2.sys.NET; import lwjake2.sys.NET;
import lwjake2.sys.Sys; import lwjake2.sys.Sys;
import lwjake2.util.Lib; import lwjake2.util.Lib;
@@ -48,6 +47,7 @@ import java.io.IOException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.util.Calendar; import java.util.Calendar;
@SuppressWarnings("ALL")
public class SV_CCMDS { public class SV_CCMDS {
/* /*
@@ -1024,92 +1024,28 @@ public class SV_CCMDS {
================== ==================
*/ */
public static void SV_InitOperatorCommands() { public static void SV_InitOperatorCommands() {
Cmd.AddCommand("heartbeat", new xcommand_t() { Cmd.AddCommand("heartbeat", SV_CCMDS::SV_Heartbeat_f);
public void execute() { Cmd.AddCommand("kick", SV_CCMDS::SV_Kick_f);
SV_Heartbeat_f(); Cmd.AddCommand("status", SV_CCMDS::SV_Status_f);
} Cmd.AddCommand("serverinfo", SV_CCMDS::SV_Serverinfo_f);
}); Cmd.AddCommand("dumpuser", SV_CCMDS::SV_DumpUser_f);
Cmd.AddCommand("kick", new xcommand_t() {
public void execute() {
SV_Kick_f();
}
});
Cmd.AddCommand("status", new xcommand_t() {
public void execute() {
SV_Status_f();
}
});
Cmd.AddCommand("serverinfo", new xcommand_t() {
public void execute() {
SV_Serverinfo_f();
}
});
Cmd.AddCommand("dumpuser", new xcommand_t() {
public void execute() {
SV_DumpUser_f();
}
});
Cmd.AddCommand("map", new xcommand_t() { Cmd.AddCommand("map", SV_CCMDS::SV_Map_f);
public void execute() { Cmd.AddCommand("demomap", SV_CCMDS::SV_DemoMap_f);
SV_Map_f(); Cmd.AddCommand("gamemap", SV_CCMDS::SV_GameMap_f);
} Cmd.AddCommand("setmaster", SV_CCMDS::SV_SetMaster_f);
});
Cmd.AddCommand("demomap", new xcommand_t() {
public void execute() {
SV_DemoMap_f();
}
});
Cmd.AddCommand("gamemap", new xcommand_t() {
public void execute() {
SV_GameMap_f();
}
});
Cmd.AddCommand("setmaster", new xcommand_t() {
public void execute() {
SV_SetMaster_f();
}
});
if (Globals.dedicated.value != 0) if (Globals.dedicated.value != 0)
Cmd.AddCommand("say", new xcommand_t() { Cmd.AddCommand("say", SV_CCMDS::SV_ConSay_f);
public void execute() {
SV_ConSay_f();
}
});
Cmd.AddCommand("serverrecord", new xcommand_t() { Cmd.AddCommand("serverrecord", SV_CCMDS::SV_ServerRecord_f);
public void execute() { Cmd.AddCommand("serverstop", SV_CCMDS::SV_ServerStop_f);
SV_ServerRecord_f();
}
});
Cmd.AddCommand("serverstop", new xcommand_t() {
public void execute() {
SV_ServerStop_f();
}
});
Cmd.AddCommand("save", new xcommand_t() { Cmd.AddCommand("save", SV_CCMDS::SV_Savegame_f);
public void execute() { Cmd.AddCommand("load", SV_CCMDS::SV_Loadgame_f);
SV_Savegame_f();
}
});
Cmd.AddCommand("load", new xcommand_t() {
public void execute() {
SV_Loadgame_f();
}
});
Cmd.AddCommand("killserver", new xcommand_t() { Cmd.AddCommand("killserver", SV_CCMDS::SV_KillServer_f);
public void execute() {
SV_KillServer_f();
}
});
Cmd.AddCommand("sv", new xcommand_t() { Cmd.AddCommand("sv", SV_CCMDS::SV_ServerCommand_f);
public void execute() {
SV_ServerCommand_f();
}
});
} }
} }

View File

@@ -27,7 +27,6 @@ import lwjake2.game.entity_state_t;
import lwjake2.qcommon.Com; import lwjake2.qcommon.Com;
import lwjake2.qcommon.Cvar; import lwjake2.qcommon.Cvar;
import lwjake2.qcommon.FS; import lwjake2.qcommon.FS;
import lwjake2.qcommon.xcommand_t;
import lwjake2.sound.S; import lwjake2.sound.S;
import lwjake2.sound.Sound; import lwjake2.sound.Sound;
import lwjake2.sound.WaveLoader; import lwjake2.sound.WaveLoader;
@@ -55,6 +54,7 @@ import org.lwjgl.openal.OpenALException;
* *
* @author dsanders/cwei * @author dsanders/cwei
*/ */
@SuppressWarnings("ALL")
public final class LWJGLSoundImpl implements Sound { public final class LWJGLSoundImpl implements Sound {
static { static {
@@ -98,26 +98,10 @@ public final class LWJGLSoundImpl implements Sound {
int count = Channel.init(buffers); int count = Channel.init(buffers);
Com.Printf("... using " + count + " channels\n"); Com.Printf("... using " + count + " channels\n");
AL10.alDistanceModel(AL10.AL_INVERSE_DISTANCE_CLAMPED); AL10.alDistanceModel(AL10.AL_INVERSE_DISTANCE_CLAMPED);
Cmd.AddCommand("play", new xcommand_t() { Cmd.AddCommand("play", this::Play);
public void execute() { Cmd.AddCommand("stopsound", this::StopAllSounds);
Play(); Cmd.AddCommand("soundlist", this::SoundList);
} Cmd.AddCommand("soundinfo", this::SoundInfo_f);
});
Cmd.AddCommand("stopsound", new xcommand_t() {
public void execute() {
StopAllSounds();
}
});
Cmd.AddCommand("soundlist", new xcommand_t() {
public void execute() {
SoundList();
}
});
Cmd.AddCommand("soundinfo", new xcommand_t() {
public void execute() {
SoundInfo_f();
}
});
num_sfx = 0; num_sfx = 0;

View File

@@ -24,12 +24,12 @@ import lwjake2.client.Key;
import lwjake2.game.Cmd; import lwjake2.game.Cmd;
import lwjake2.game.usercmd_t; import lwjake2.game.usercmd_t;
import lwjake2.qcommon.Cvar; import lwjake2.qcommon.Cvar;
import lwjake2.qcommon.xcommand_t;
import lwjake2.util.Math3D; import lwjake2.util.Math3D;
/** /**
* IN * IN
*/ */
@SuppressWarnings("ALL")
public final class IN extends Globals { public final class IN extends Globals {
static boolean mouse_avail = true; static boolean mouse_avail = true;
@@ -106,28 +106,12 @@ public final class IN extends Globals {
Globals.m_forward = Cvar.Get("m_forward", "1", 0); Globals.m_forward = Cvar.Get("m_forward", "1", 0);
Globals.m_side = Cvar.Get("m_side", "0.8", 0); Globals.m_side = Cvar.Get("m_side", "0.8", 0);
Cmd.AddCommand("+mlook", new xcommand_t() { Cmd.AddCommand("+mlook", IN::MLookDown);
public void execute() { Cmd.AddCommand("-mlook", IN::MLookUp);
MLookDown();
}
});
Cmd.AddCommand("-mlook", new xcommand_t() {
public void execute() {
MLookUp();
}
});
Cmd.AddCommand("force_centerview", new xcommand_t() { Cmd.AddCommand("force_centerview", IN::Force_CenterView_f);
public void execute() {
Force_CenterView_f();
}
});
Cmd.AddCommand("togglemouse", new xcommand_t() { Cmd.AddCommand("togglemouse", IN::toggleMouse);
public void execute() {
toggleMouse();
}
});
IN.mouse_avail = true; IN.mouse_avail = true;
} }