Package com.ardor3d.example
Class PropertiesGameSettings
java.lang.Object
com.ardor3d.example.PropertiesGameSettings
PropertiesGameSettings
handles loading and saving a properties file that defines the display settings. A
property file is identified during creation of the object. The properties file should have the following format:
<CODE> FREQ=60 RENDERER=JOGL WIDTH=1280 HEIGHT=1024 DEPTH=32 FULLSCREEN=false </CODE>
-
Field Summary
Modifier and TypeFieldDescriptionprotected static Integer
protected static Integer
protected static Integer
protected static Integer
protected static Integer
protected static Boolean
protected static Integer
protected static Boolean
protected static String
protected static Integer
protected static String
protected static Boolean
protected static Integer
protected static Boolean
protected static Integer
protected boolean
-
Constructor Summary
ConstructorDescriptionPropertiesGameSettings
(String personalFilename, String dfltsFilename) Constructor creates thePropertiesGameSettings
object for use. -
Method Summary
Modifier and TypeMethodDescriptionprotected static void
assignDefaults
(String propFileName) Sets default* static variables according to GameSettings.DEFAULT_* values and an optional .properties file.void
clear()
get
takes an arbitrary string as a key and returns any value associated with it, null if none.int
If the properties file does not contain the setting or was not read properly, the default value is returned.boolean
getBoolean
(String name, boolean defaultValue) byte[]
getByteArray
(String name, byte[] defaultValue) This is only getting the "default" value, which may not be changed by end-users.int
getDepth()
getDepth
returns the depth as read from the properties file.int
If the properties file does not contain the setting or was not read properly, the default value is returned.double
float
int
If the properties file does not contain the setting or was not read properly, the default value is returned.int
getFrequency
returns the frequency of the monitor as read from the properties file.boolean
Deprecated.Use method isFullscreen instead.int
getHeight
returns the height as read from the properties file.int
long
getRenderer
returns the requested rendering API, or the default.int
If the properties file does not contain the setting or was not read properly, the default value is returned.int
If the properties file does not contain the setting or was not read properly, the default value is returned.int
getWidth()
getWidth
returns the width as read from the properties file.boolean
isFullscreen
returns the fullscreen flag as read from the properties file.boolean
isMusic()
If the properties file does not contain the setting or was not read properly, the default value is returned.boolean
isNew()
boolean
isSFX()
If the properties file does not contain the setting or was not read properly, the default value is returned.boolean
If the properties file does not contain the setting or was not read properly, the default value is returned.boolean
load()
load
attempts to load the properties file defined during instantiation and put all properties in the table.static Boolean
loadBoolean
(String name, Properties props) static Integer
loadInteger
(String name, Properties props) protected static String
normalizeName
(String inName) void
Removes specified property, if present.void
save()
Persists current property mappings to designated file, overwriting if file already present.boolean
Deprecated.void
Sets a property.void
setAlphaBits
(int alphaBits) void
setBoolean
(String name, boolean value) void
setByteArray
(String name, byte[] value) void
setDepth
(int depth) void
setDepthBits
(int depthBits) void
void
void
setFramerate
(int framerate) void
setFrequency
(int freq) void
setFullscreen
(boolean fullscreen) void
setHeight
(int height) void
void
setIsNew
(boolean isNew) void
void
setMusic
(boolean music) void
Not implemented.void
setRenderer
(String renderer) void
setSamples
(int samples) void
setSFX
(boolean sfx) void
setStencilBits
(int stencilBits) void
setVerticalSync
(boolean verticalSync) void
setWidth
(int width) void
save() method which throws only a RuntimeException.
-
Field Details
-
isNew
protected boolean isNew -
defaultWidth
-
defaultHeight
-
defaultDepth
-
defaultFrequency
-
defaultFullscreen
-
defaultRenderer
-
defaultVerticalSync
-
defaultDepthBits
-
defaultAlphaBits
-
defaultStencilBits
-
defaultSamples
-
defaultMusic
-
defaultSFX
-
defaultFramerate
-
defaultSettingsWidgetImage
-
-
Constructor Details
-
PropertiesGameSettings
Constructor creates thePropertiesGameSettings
object for use.- Parameters:
personalFilename
- the properties file to use, read from filesystem. Must not be null.dfltsFilename
- the properties file to use, read from CLASSPATH. Null to not seek any runtime defaults file.- Throws:
Ardor3dException
- if the personalFilename is null.
-
-
Method Details
-
clear
public void clear() -
get
get
takes an arbitrary string as a key and returns any value associated with it, null if none.- Parameters:
key
- the key to use for data retrieval.- Returns:
- the string associated with the key, null if none.
-
get
-
getAlphaBits
public int getAlphaBits()If the properties file does not contain the setting or was not read properly, the default value is returned.- Returns:
- the alpha bits
- Throws:
InternalError
- in all cases
-
getBoolean
-
getByteArray
-
getDefaultSettingsWidgetImage
This is only getting the "default" value, which may not be changed by end-users.- Returns:
- the widget image of the default settings
-
getDepth
public int getDepth()getDepth
returns the depth as read from the properties file. If the properties file does not contain depth or was not read properly, the default depth is returned.- Returns:
- the depth determined by the properties file, or the default.
-
getDepthBits
public int getDepthBits()If the properties file does not contain the setting or was not read properly, the default value is returned.- Returns:
- the depth bits
- Throws:
InternalError
- in all cases
-
getDouble
-
getFloat
-
getFramerate
public int getFramerate()If the properties file does not contain the setting or was not read properly, the default value is returned.- Returns:
- the frame rate
- Throws:
InternalError
- in all cases
-
getFrequency
public int getFrequency()getFrequency
returns the frequency of the monitor as read from the properties file. If the properties file does not contain frequency or was not read properly the default frequency is returned.- Returns:
- the frequency determined by the properties file, or the default.
-
getFullscreen
Deprecated.Use method isFullscreen instead.Legacy method.- Returns:
true
if the full screen mode is enabled- See Also:
-
getHeight
public int getHeight()getHeight
returns the height as read from the properties file. If the properties file does not contain height or was not read properly, the default height is returned.- Returns:
- the height determined by the properties file, or the default.
-
getInt
-
getLong
-
getObject
-
getRenderer
getRenderer
returns the requested rendering API, or the default.- Returns:
- the rendering API or the default.
-
getSamples
public int getSamples()If the properties file does not contain the setting or was not read properly, the default value is returned.- Returns:
- the samples
- Throws:
InternalError
- in all cases
-
getStencilBits
public int getStencilBits()If the properties file does not contain the setting or was not read properly, the default value is returned.- Returns:
- the stencil bits
- Throws:
InternalError
- in all cases
-
getWidth
public int getWidth()getWidth
returns the width as read from the properties file. If the properties file does not contain width or was not read properly, the default width is returned.- Returns:
- the width determined by the properties file, or the default.
-
isFullscreen
public boolean isFullscreen()isFullscreen
returns the fullscreen flag as read from the properties file. If the properties file does not contain the fullscreen flag or was not read properly, the default value is returned.- Returns:
- the fullscreen flag determined by the properties file, or the default.
-
isMusic
public boolean isMusic()If the properties file does not contain the setting or was not read properly, the default value is returned.- Returns:
true
if the music is enabled- Throws:
InternalError
- in all cases
-
isNew
public boolean isNew() -
isSFX
public boolean isSFX()If the properties file does not contain the setting or was not read properly, the default value is returned.- Returns:
true
if the special effects are enabled- Throws:
InternalError
- in all cases
-
isVerticalSync
public boolean isVerticalSync()If the properties file does not contain the setting or was not read properly, the default value is returned.- Returns:
true
if the vertical sync is enabled- Throws:
InternalError
- in all cases
-
load
public boolean load()load
attempts to load the properties file defined during instantiation and put all properties in the table. If there is a problem loading or reading the file, false is returned. If all goes well, true is returned.- Returns:
- the success of the load, true indicated success and false indicates failure.
-
remove
Removes specified property, if present.- Parameters:
name
- the name of the property to remove
-
save
Persists current property mappings to designated file, overwriting if file already present.- Throws:
IOException
- for I/O failures
-
save
@Deprecated public boolean save(int width, int height, int depth, int freq, boolean fullscreen, String renderer) Deprecated.save(int, int, int, int, boolean, String)
overwrites the properties file with the given parameters.- Parameters:
width
- the width of the resolution.height
- the height of the resolution.depth
- the bits per pixel.freq
- the frequency of the monitor.fullscreen
- use fullscreen or not.renderer
- the string denoting the renderer- Returns:
- true if save was successful, false otherwise.
-
set
Sets a property.- Parameters:
name
- the name of the propertyvalue
- the value of the property
-
setAlphaBits
public void setAlphaBits(int alphaBits) - Parameters:
alphaBits
- the alpha bits to set- Throws:
InternalError
- in all cases
-
setBoolean
- Parameters:
name
- the name of the propertyvalue
- the value of the property- See Also:
-
setByteArray
- Parameters:
name
- the name of the propertyvalue
- the value of the property- See Also:
-
setDepth
public void setDepth(int depth) -
setDepthBits
public void setDepthBits(int depthBits) - Parameters:
depthBits
- the depth bits to set- Throws:
InternalError
- in all cases
-
setDouble
- Parameters:
name
- the name of the propertyvalue
- the value of the property- See Also:
-
setFloat
- Parameters:
name
- the name of the propertyvalue
- the value of the property- See Also:
-
setFramerate
public void setFramerate(int framerate) - Parameters:
framerate
- the frame rate- Throws:
InternalError
- in all cases
-
setFrequency
public void setFrequency(int freq) -
setFullscreen
public void setFullscreen(boolean fullscreen) -
setHeight
public void setHeight(int height) -
setInt
- Parameters:
name
- the name of the propertyvalue
- the value of the property- See Also:
-
setIsNew
public void setIsNew(boolean isNew) -
setLong
- Parameters:
name
- the name of the propertyvalue
- the value of the property- See Also:
-
setMusic
public void setMusic(boolean music) - Parameters:
music
-true
if the music is enabled- Throws:
InternalError
- in all cases
-
setObject
Not implemented. Properties can not store an arbitrary Object in human-readable format. Use set(String, String) instead.- Parameters:
name
- the name of the propertyvalue
- the value of the property- Throws:
InternalError
- in all cases- See Also:
-
setRenderer
-
setSamples
public void setSamples(int samples) - Parameters:
samples
- the samples- Throws:
InternalError
- in all cases
-
setSFX
public void setSFX(boolean sfx) - Parameters:
sfx
-true
if the special effects are enabled- Throws:
InternalError
- in all cases
-
setStencilBits
public void setStencilBits(int stencilBits) - Parameters:
stencilBits
- the stencil bits- Throws:
InternalError
- in all cases
-
setVerticalSync
public void setVerticalSync(boolean verticalSync) - Parameters:
verticalSync
-true
if the vertical sync is enabled- Throws:
InternalError
- in all cases
-
setWidth
public void setWidth(int width) -
wrappedSave
public void wrappedSave()save() method which throws only a RuntimeException.- See Also:
-
assignDefaults
Sets default* static variables according to GameSettings.DEFAULT_* values and an optional .properties file. Note that we are talking about defaults here, not user-specific settings.This method should be called once the game name is known to the subclass. To override any default with your subclass (as opposed to by using a .properties file), just set the static variable before or after calling this method (before or after depends on the precedence you want among programmatic and declarative DEFAULT_*, default* settings).
Add new setting names by making your own method which does its own thing and calls AbstractGameSettings.assignDefaults(propfilename). Property file paths are relative to CLASSPATH element roots.- Parameters:
propFileName
- Properties file read as CLASSPATH resource. If you give null, no properties file will be loaded.
-
loadBoolean
-
loadInteger
-
normalizeName
- Parameters:
inName
- Must be non-null- Returns:
- normalized name. All lower-case with no shell meta-characters.
-