Skip to content

Commit

Permalink
Fix writing alternate config files
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbata committed Sep 29, 2023
1 parent a7d8cf5 commit a37a14e
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 23 deletions.
43 changes: 43 additions & 0 deletions .doomrc
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 17
key_down 31
key_strafeleft 30
key_straferight 32
key_fire 29
key_use 57
key_strafe 56
key_speed 54
use_mouse 1
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"
10 changes: 8 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
**/*.c linguist-vendored
**/*.h linguist-vendored
src/g/g_game.c linguist-vendored
src/i/i_main.c linguist-vendored
src/i/i_net.c linguist-vendored
src/doom/d_french.h linguist-vendored
src/g/g_game.h linguist-vendored
src/i/i_net.h linguist-vendored
src/i/i_system.h linguist-vendored
src/i/i_video.h linguist-vendored

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ dist/
build.xml
nbproject/
.gradle
mochadoom.cfg

# Intellij
*.iml
Expand Down
2 changes: 1 addition & 1 deletion CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ In general, Mocha Doom supports all of the standard vanilla/DOS Doom command-lin
parameters, plus some of its own. Here's the documentation for some that might
be useful:

* `-config`:
* `-config <file1> [file2] ...`:
Specify an alternate configuration file to use (default is `default.cfg`).
* `-fullscreen`:
Can also be specified in the `default.cfg` file with the: `fullscreen true` setting.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ You may also download the freely distributable Shareware version of Doom (includ
* `mochadoom-classic.bat`
* Platform independent
* `java -jar mochadoom.jar`
* `java -jar mochadoom.jar -config classic.cfg`
* `java -jar mochadoom.jar -config classic.cfg mochadoom.cfg`

Mocha Doom tries to find a valid Doom WAD file in the directory
defined by the `DOOMWADDIR` environment variable (defaults to the current directory).
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ distributions {
from jar
from 'wads'
from("$projectDir") {
include 'LICENSE.txt'
include 'LICENSE.TXT'
include 'README.md'
include 'CONFIG.md'
include '.doomrc'
include 'default.cfg'
include 'classic.cfg'
include 'mochadoom.cfg'
include 'mochadoom*.sh'
include 'mochadoom*.bat'
}
Expand Down
2 changes: 1 addition & 1 deletion mochadoom-classic.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@echo off
mochadoom.bat -config classic.cfg %*
mochadoom.bat -config classic.cfg mochadoom.cfg %*

2 changes: 1 addition & 1 deletion mochadoom-classic.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
mochadoom.sh -config classic.cfg "$@"
mochadoom.sh -config classic.cfg mochadoom.cfg "$@"

30 changes: 30 additions & 0 deletions mochadoom.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
alwaysrun false
automap_plotter_style Thin
color_depth Indexed
enable_colormap_lump true
extend_button_slots_limit true
extend_plats_limit true
fix_blockmap true
fix_gamma_palette false
fix_gamma_ramp false
fix_medi_need false
fix_ouch_face false
fix_sky_change false
fix_sky_palette false
fullscreen false
fullscreen_interpolation Nearest
fullscreen_mode Best
fullscreen_stretch Fit
fuzz_mix false
greyscale_filter Luminance
line_of_sight Vanilla
mb_used 2
parallelism_patch_columns 0
parallelism_realcolor_tint 16
reconstruct_savegame_pointers true
scale_melt true
scale_screen_tiles true
scene_renderer_mode Serial
semi_translucent_fuzz false
vanilla_key_behavior true
vestrobe false
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
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
2 changes: 1 addition & 1 deletion src/i/Strings.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package i;

public final class Strings {
public static final String MOCHA_DOOM_TITLE="Mocha Doom Alpha 1.6.1";
public static final String MOCHA_DOOM_TITLE="Mocha Doom Alpha 1.6.2";

public static final String MODIFIED_GAME=
("===========================================================================\n"+
Expand Down
8 changes: 4 additions & 4 deletions src/utils/C2JUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,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 @@ -230,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
2 changes: 1 addition & 1 deletion src/w/WadLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ public void CloseAllHandles(){

}

// TODO: finalize is deprecated - CloseAllHandles() call is moved to shutdown hook (needs verification)
// TODO: finalize is deprecated - CloseAllHandles() call is moved to shutdown hook
//@Override
//public void finalize(){
// CloseAllHandles();
Expand Down

0 comments on commit a37a14e

Please sign in to comment.