Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions classic.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
mouse_sensitivity 5
sfx_volume 8
music_volume 8
show_messages 1
key_right 77
key_left 75
key_up 72
key_down 80
key_strafeleft 51
key_straferight 52
key_fire 29
key_use 57
key_strafe 56
key_speed 54
use_mouse 0
mouseb_fire 0
mouseb_strafe 1
mouseb_forward 2
use_joystick 0
joyb_fire 0
joyb_strafe 1
joyb_use 3
joyb_speed 2
screenblocks 10
detaillevel 0
snd_channels 8
snd_musicdevice 3
snd_sfxdevice 3
snd_sbport 0
snd_sbirq 0
snd_sbdma 0
snd_mport 0
usegamma 0
chatmacro0 "No"
chatmacro1 "I'm ready to kick butt!"
chatmacro2 "I'm OK."
chatmacro3 "I'm not looking too good!"
chatmacro4 "Help!"
chatmacro5 "You suck!"
chatmacro6 "Next time, scumbag..."
chatmacro7 "Come here!"
chatmacro8 "I'll take care of it."
chatmacro9 "Yes"
2 changes: 2 additions & 0 deletions src/awt/EventBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ static <H extends Enum<H> & EventBase<H>> Optional<H> findById(H[] values, int e

@SafeVarargs
static <H extends Enum<H> & EventBase<H>> Relation<H>[] Relate(H src, H... dests) {
@SuppressWarnings("unchecked")
final IntFunction<Relation<H>[]> arrayer = Relation[]::new;
return Arrays.stream(dests)
.map(dest -> new Relation<>(src, dest))
Expand Down Expand Up @@ -166,6 +167,7 @@ public KeyStateInterest(
final class KeyStateHolder<Handler extends Enum<Handler> & EventBase<Handler>> {
private final Set<Signals.ScanCode> holdingSet;
private final LinkedHashSet<KeyStateInterest<Handler>> keyInterests;
@SuppressWarnings("unchecked")
private final IntFunction<KeyStateInterest<Handler>[]> generator = KeyStateInterest[]::new;

public KeyStateHolder() {
Expand Down
50 changes: 44 additions & 6 deletions src/doom/ConfigBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import m.Settings;
import utils.OSValidator;
Expand Down Expand Up @@ -63,19 +64,30 @@ public static class Files {

public final Comparator<Settings> comparator;
public final String fileName;
// flags that configuration is provided by the -config argument
public final boolean alternate;

public boolean changed = true;

private String[] paths;

public Files(String fileName) {
this(fileName, Comparator.comparing(Enum::name, String::compareTo));
this(fileName, false);
}

public Files(String fileName, boolean alternate) {
this(fileName, Comparator.comparing(Enum::name, String::compareTo), alternate);
}

public Files(String fileName, Comparator<Settings> comparator) {
this(fileName, comparator, false);
}

public Files(String fileName, Comparator<Settings> comparator, boolean alternate) {
this.fileName = fileName;
this.comparator = comparator;
this.alternate = alternate;
}

public Optional<ResourceIO> firstValidPathIO() {
return Arrays.stream(getPaths())
.map(ResourceIO::new)
Expand All @@ -86,7 +98,33 @@ public Optional<ResourceIO> firstValidPathIO() {
public ResourceIO workDirIO() {
return new ResourceIO(getFolder() + fileName);
}


@Override
public int hashCode() {
int hash = 7;
hash = 53 * hash + Objects.hashCode(this.fileName);
hash = 53 * hash + (this.alternate ? 1 : 0);
return hash;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Files other = (Files) obj;
if (this.alternate != other.alternate) {
return false;
}
return Objects.equals(this.fileName, other.fileName);
}

/**
* Get file / paths combinations
*
Expand Down Expand Up @@ -146,7 +184,7 @@ public static List<Files> getFiles() {
*/
if (!Engine.getCVM()
.with(CommandVariable.CONFIG, 0, (String[] fileNames) ->
Arrays.stream(fileNames).map(Files::new).forEach(ret::add))
Arrays.stream(fileNames).map(fileName -> new Files(fileName, true)).forEach(ret::add))

/**
* If there is no such argument, load default.cfg (or .doomrc) and mochadoom.cfg
Expand Down
8 changes: 7 additions & 1 deletion src/doom/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,17 @@ public <T> T getValue(final Settings setting, final Class<T> valueType) {

public void SaveDefaults() {
SETTINGS_MAP.forEach((file, settings) -> {
// skip writing settings which are not part of the loaded config files,
// this helps to not overwrite default.cfg with empty content in case we're using the -config argument
if (!this.configFiles.contains(file)) {
return;
}

// do not write unless there is changes
if (!file.changed) {
return;
}

// choose existing config file or create one in current working directory
final ResourceIO rio = file.firstValidPathIO().orElseGet(file::workDirIO);
final Iterator<Settings> it = settings.stream().sorted(file.comparator).iterator();
Expand Down
63 changes: 33 additions & 30 deletions src/doom/DoomMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import f.EndLevel;
import f.Finale;
import f.Wiper;
import g.Signals;
import static g.Signals.ScanCode.*;
import hu.HU;
import i.DiskDrawer;
Expand Down Expand Up @@ -1289,21 +1290,7 @@ public boolean Responder(event_t ev) {
ev.withKey(sc -> {
gamekeydown[sc.ordinal()] = true;
if (vanillaKeyBehavior) {
switch(sc) {
case SC_LSHIFT:
case SC_RSHIFT:
gamekeydown[SC_RSHIFT.ordinal()] = gamekeydown[SC_LSHIFT.ordinal()] = true;
break;
case SC_LCTRL:
case SC_RCTRL:
gamekeydown[SC_RCTRL.ordinal()] = gamekeydown[SC_LCTRL.ordinal()] = true;
break;
case SC_LALT:
case SC_RALT:
gamekeydown[SC_RALT.ordinal()] = gamekeydown[SC_LALT.ordinal()] = true;
break;
default: break;
}
handleVanillaKeys(sc, true);
}
});
return true; // eat key down events
Expand All @@ -1318,21 +1305,7 @@ public boolean Responder(event_t ev) {
ev.withKey(sc -> {
gamekeydown[sc.ordinal()] = false;
if (vanillaKeyBehavior) {
switch(sc) {
case SC_LSHIFT:
case SC_RSHIFT:
gamekeydown[SC_RSHIFT.ordinal()] = gamekeydown[SC_LSHIFT.ordinal()] = false;
break;
case SC_LCTRL:
case SC_RCTRL:
gamekeydown[SC_RCTRL.ordinal()] = gamekeydown[SC_LCTRL.ordinal()] = false;
break;
case SC_LALT:
case SC_RALT:
gamekeydown[SC_RALT.ordinal()] = gamekeydown[SC_LALT.ordinal()] = false;
break;
default: break;
}
handleVanillaKeys(sc, false);
}
});
return false; // always let key up events filter down
Expand Down Expand Up @@ -1368,6 +1341,36 @@ public boolean Responder(event_t ev) {
return false;
}

private void handleVanillaKeys(Signals.ScanCode sc, boolean keyDown) {
switch(sc) {
case SC_LSHIFT:
case SC_RSHIFT:
gamekeydown[SC_RSHIFT.ordinal()] = gamekeydown[SC_LSHIFT.ordinal()] = keyDown;
break;
case SC_LCTRL:
case SC_RCTRL:
gamekeydown[SC_RCTRL.ordinal()] = gamekeydown[SC_LCTRL.ordinal()] = keyDown;
break;
case SC_LALT:
case SC_RALT:
gamekeydown[SC_RALT.ordinal()] = gamekeydown[SC_LALT.ordinal()] = keyDown;
break;
case SC_UP:
gamekeydown[SC_NUMKEY8.ordinal()] = keyDown;
break;
case SC_DOWN:
gamekeydown[SC_NUMKEY2.ordinal()] = keyDown;
break;
case SC_LEFT:
gamekeydown[SC_NUMKEY4.ordinal()] = keyDown;
break;
case SC_RIGHT:
gamekeydown[SC_NUMKEY6.ordinal()] = keyDown;
break;
default: break;
}
}

private final String turbomessage="is turbo!";

/**
Expand Down
4 changes: 2 additions & 2 deletions src/doom/DoomStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ public void setPaused(boolean paused) {
protected byte[] savebuffer;

/* TODO Proper reconfigurable controls. Defaults hardcoded for now. T3h h4x, d00d. */
public int key_right = SC_NUMKEY6.ordinal();
public int key_left = SC_NUMKEY4.ordinal();
public int key_right = SC_RIGHT.ordinal();
public int key_left = SC_LEFT.ordinal();
public int key_up = SC_W.ordinal();
public int key_down = SC_S.ordinal();
public int key_strafeleft = SC_A.ordinal();
Expand Down
1 change: 1 addition & 0 deletions src/mochadoom/Loggers.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public static <EventHandler extends Enum<EventHandler> & EventBase<EventHandler>

lastHandler = handler;

@SuppressWarnings("unchecked")
final IntFunction<EventBase<EventHandler>[]> arrayGenerator = EventBase[]::new;
final EventBase<EventHandler>[] depends = actionStateHolder
.cooperations(handler, RelationType.DEPEND)
Expand Down
2 changes: 1 addition & 1 deletion src/rr/SimpleTextureManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void InitTextures () throws IOException
mtexture.unpack(maptex[texset]);

// MAES: the HashTable only needs to know the correct names.
TextureCache.put(mtexture.name.toUpperCase(), new Integer(i));
TextureCache.put(mtexture.name.toUpperCase(), Integer.valueOf(i));

// We don't need to manually copy trivial fields.
textures[i]=new texture_t();
Expand Down
25 changes: 13 additions & 12 deletions src/utils/C2JUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
Expand Down Expand Up @@ -167,9 +168,9 @@ public static String nullTerminatedString(char[] s) {
public static <T> void initArrayOfObjects(T[] os, Class<T> c) {
try {
for (int i = 0; i < os.length; i++) {
os[i] = c.newInstance();
os[i] = c.getDeclaredConstructor().newInstance();
}
} catch (IllegalAccessException | InstantiationException e) {
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
System.err.println("Failure to allocate " + os.length
+ " objects of class" + c.getName() + "!");
Expand All @@ -192,9 +193,9 @@ public static <T> void initArrayOfObjects(T[] os) {
Class<T> c = (Class<T>) os.getClass().getComponentType();
try {
for (int i = 0; i < os.length; i++) {
os[i] = c.newInstance();
os[i] = c.getDeclaredConstructor().newInstance();
}
} catch (IllegalAccessException | InstantiationException e) {
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
System.err.println("Failure to allocate " + os.length
+ " objects of class " + c.getName() + "!");
Expand Down Expand Up @@ -229,9 +230,9 @@ public static <T> T[] createArrayOfObjects(Class<T> c, int num) {

try {
for (int i = 0; i < os.length; i++) {
os[i] = c.newInstance();
os[i] = c.getDeclaredConstructor().newInstance();
}
} catch (IllegalAccessException | InstantiationException e) {
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
System.err.println("Failure to instantiate " + os.length + " objects of class " + c.getName() + "!");
System.exit(-1);
Expand Down Expand Up @@ -264,9 +265,9 @@ public static <T> T[] createArrayOfObjects(T instance, int num) {

try {
for (int i = 0; i < os.length; i++) {
os[i] = c.newInstance();
os[i] = c.getDeclaredConstructor().newInstance();
}
} catch (IllegalAccessException | InstantiationException e) {
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
System.err.println("Failure to instantiate " + os.length
+ " objects of class " + c.getName() + "!");
Expand Down Expand Up @@ -294,9 +295,9 @@ public static <T> void initArrayOfObjects(T[] os, int startpos, int endpos) {
Class<T> c = (Class<T>) os.getClass().getComponentType();
try {
for (int i = startpos; i < endpos; i++) {
os[i] = c.newInstance();
os[i] = c.getDeclaredConstructor().newInstance();
}
} catch (IllegalAccessException | InstantiationException e) {
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
System.err.println("Failure to allocate " + os.length
+ " objects of class " + c.getName() + "!");
Expand Down Expand Up @@ -708,9 +709,9 @@ public static <T> T[] resize(T[] oldarray, int newsize) {

T cls;
try {
cls = (T) oldarray.getClass().getComponentType().newInstance();
cls = (T) oldarray.getClass().getComponentType().getDeclaredConstructor().newInstance();
return resize(cls, oldarray, newsize);
} catch (IllegalAccessException | InstantiationException e) {
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
System.err.println("Cannot autodetect type in resizeArray.\n");
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/w/DoomIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public static void readObjectArrayWithReflection(DataInputStream dis,IReadableDo
Class<?> c=s.getClass().getComponentType();

for (int i=0;i<Math.min(len,s.length);i++){
if (s[i]==null) s[i]=(IReadableDoomObject) c.newInstance();
if (s[i]==null) s[i]=(IReadableDoomObject) c.getDeclaredConstructor().newInstance();
s[i].read(dis);
}
}
Expand All @@ -253,7 +253,7 @@ public static void readObjectArray(DataInputStream dis,IReadableDoomObject[] s,i

for (int i=0;i<Math.min(len,s.length);i++){
if (s[i]==null) {
s[i]=(IReadableDoomObject) c.newInstance();
s[i]=(IReadableDoomObject) c.getDeclaredConstructor().newInstance();
}
s[i].read(dis);
}
Expand Down
Loading