Digging through jme

can i ask how the GameSettings class work

theirs no code or extenstions and it sets the parameters and save

i understand its an interface but how does it go about doing anything with no code

the code below works but settings is declared as GameSettings not PropertiesGameSettings

should I, declare settings as PropertiesGameSettings to prevent any future issues or is declaring it as Gamesettings fine. everything works now it saves and loads but I have no idea how




package com.tps1.aMain;

import com.jme.system.GameSettings;
import com.jme.system.PreferencesGameSettings;
import com.tps1.util.SysInfo;

import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.Preferences;

public class Game {
 
    private static GameSettings settings;
   
    private static boolean debugMode;
   
    /**
     * Initialize settings
     */
    static {
        settings = new PreferencesGameSettings(Preferences.userRoot().node(SysInfo.gameTitle));
       
        settings.set("title", SysInfo.GameName + " "
                            + SysInfo.GameVersion + " "
                            + SysInfo.ReleaseNumber);
       
        settings.setSamples(0);
        settings.setDepthBits(8);
        settings.setAlphaBits(0);
        settings.setStencilBits(0);
        settings.setFramerate(-1);
       
    }
   
    /**
     * Enable or disable debug mode.
     *
     * During debug mode, more logging messages are displayed
     * and an in-game console is available.
     */
    public static void setDebug(boolean debug){
        debugMode = debug;
       
        if (debug){
            Logger.getLogger("").setLevel(Level.FINEST);
        }else{
            Logger.getLogger("").setLevel(Level.WARNING);
        }
    }
   
    /**
     * Returns true if debug mode is set.
     */
    public static boolean isDebug(){
        return debugMode;
    }
   
    /**
     * Settings for the game. Cannot be null.
     */
    public static GameSettings getSettings(){
        return settings;
    }
   
}

hmm i realized it was because I defined it as PreferencesGameSettings but how does it save preferenceGameSettigns call  preferences.flush(); which is another interface method unlike propertiesGameSettins which actually saves the file through a buffer

You should read up on interfaces / class hierarchy / inheritance to understand how things work.



In your code you create a instance of PreferencesGameSettings.

PreferencesGameSettings is a implementation GameSettings.


how does it go about doing anything with no code

An interface just says 'classes who implement me, need to define those methods'.

PropertiesGameSettings uses a property file to save the settings.
PreferencesGameSettings uses the registry to save the settings (on windows)

should I, declare settings as PropertiesGameSettings

no, by declaring it as GameSettings, you can later simply change the implementation and the other part of your code stays the same.
Core-Dump said:

You should read up on interfaces / class hierarchy / inheritance to understand how things work.

In your code you create a instance of PreferencesGameSettings.
PreferencesGameSettings is a implementation GameSettings.

how does it go about doing anything with no code

An interface just says 'classes who implement me, need to define those methods'.

PropertiesGameSettings uses a property file to save the settings.
PreferencesGameSettings uses the registry to save the settings (on windows)

should I, declare settings as PropertiesGameSettings

no, by declaring it as GameSettings, you can later simply change the implementation and the other part of your code stays the same.


I understand how interfaces work which was why I was initially confused I didn't realize it was initalized as PreferencesGameSettings() so this much makes sense to me but I will definitly have to research the other parts of the class

thank you for explaining