https://github.com/libsdl-org/Maelstrom/commit/612726908c47c87d39b4e81331c21c49891a15f9
From 612726908c47c87d39b4e81331c21c49891a15f9 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 4 Nov 2011 21:34:21 -0400
Subject: [PATCH] Moved the preferences code to the utils directory and under
the zlib license, because it might be useful in other projects.
---
Maelstrom_Globals.h | 7 +++--
Makefile.am | 2 --
Makefile.in | 7 ++---
controls.cpp | 4 +--
utils/Makefile.am | 4 ++-
utils/Makefile.in | 29 +++++++++++++++++--
prefs.cpp => utils/prefs.cpp | 43 +++++++++++++--------------
prefs.h => utils/prefs.h | 56 ++++++++++++------------------------
8 files changed, 76 insertions(+), 76 deletions(-)
rename prefs.cpp => utils/prefs.cpp (72%)
rename prefs.h => utils/prefs.h (54%)
diff --git a/Maelstrom_Globals.h b/Maelstrom_Globals.h
index 0f93e8ad..8998c64c 100644
--- a/Maelstrom_Globals.h
+++ b/Maelstrom_Globals.h
@@ -33,12 +33,13 @@
#include "maclib/Mac_Sound.h"
#include "maclib/Mac_Compat.h"
+#include "utils/prefs.h"
+
#include "Maelstrom.h"
#include "myerror.h"
#include "fastrand.h"
#include "logic.h"
-#include "prefs.h"
#include "scores.h"
#include "controls.h"
@@ -106,8 +107,8 @@ extern StarPtr gTheStars[MAX_STARS];
extern Uint32 gStarColors[];
// in controls.cpp :
extern Controls controls;
-extern PrefsVariable<Uint8> gSoundLevel;
-extern PrefsVariable<Uint8> gGammaCorrect;
+extern PrefsVariable<int> gSoundLevel;
+extern PrefsVariable<int> gGammaCorrect;
// int scores.cpp :
extern Scores hScores[];
diff --git a/Makefile.am b/Makefile.am
index 6b4d6853..7eb05b8c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -23,8 +23,6 @@ Maelstrom_SOURCES = \
main.h \
myerror.cpp \
myerror.h \
- prefs.cpp \
- prefs.h \
rect.cpp \
rect.h \
scores.cpp \
diff --git a/Makefile.in b/Makefile.in
index 92f3d4ab..6efbba37 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -53,8 +53,8 @@ binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
PROGRAMS = $(bin_PROGRAMS)
am_Maelstrom_OBJECTS = MaelstromUI.$(OBJEXT) MacDialog.$(OBJEXT) \
controls.$(OBJEXT) fastrand.$(OBJEXT) init.$(OBJEXT) \
- load.$(OBJEXT) main.$(OBJEXT) myerror.$(OBJEXT) \
- prefs.$(OBJEXT) rect.$(OBJEXT) scores.$(OBJEXT)
+ load.$(OBJEXT) main.$(OBJEXT) myerror.$(OBJEXT) rect.$(OBJEXT) \
+ scores.$(OBJEXT)
Maelstrom_OBJECTS = $(am_Maelstrom_OBJECTS)
Maelstrom_DEPENDENCIES = $(LOGIC)/liblogic.a screenlib/libSDLscreen.a \
maclib/libSDLmac.a utils/libutils.a
@@ -220,8 +220,6 @@ Maelstrom_SOURCES = \
main.h \
myerror.cpp \
myerror.h \
- prefs.cpp \
- prefs.h \
rect.cpp \
rect.h \
scores.cpp \
@@ -336,7 +334,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/load.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/myerror.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/prefs.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rect.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scores.Po@am__quote@
diff --git a/controls.cpp b/controls.cpp
index 92631e45..65f5d195 100644
--- a/controls.cpp
+++ b/controls.cpp
@@ -60,8 +60,8 @@ Controls::Bind(Prefs *prefs)
}
Controls controls;
-PrefsVariable<Uint8> gSoundLevel("SoundLevel", 4);
-PrefsVariable<Uint8> gGammaCorrect("GammaCorrect", 3);
+PrefsVariable<int> gSoundLevel("SoundLevel", 4);
+PrefsVariable<int> gGammaCorrect("GammaCorrect", 3);
void LoadControls(void)
diff --git a/utils/Makefile.am b/utils/Makefile.am
index 53e41b5a..7679f9fe 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -5,4 +5,6 @@ libutils_a_SOURCES = \
hashtable.c \
hashtable.h \
physfsrwops.c \
- physfsrwops.h
+ physfsrwops.h \
+ prefs.cpp \
+ prefs.h
diff --git a/utils/Makefile.in b/utils/Makefile.in
index 91076cb4..e289690d 100644
--- a/utils/Makefile.in
+++ b/utils/Makefile.in
@@ -47,7 +47,8 @@ AR = ar
ARFLAGS = cru
libutils_a_AR = $(AR) $(ARFLAGS)
libutils_a_LIBADD =
-am_libutils_a_OBJECTS = hashtable.$(OBJEXT) physfsrwops.$(OBJEXT)
+am_libutils_a_OBJECTS = hashtable.$(OBJEXT) physfsrwops.$(OBJEXT) \
+ prefs.$(OBJEXT)
libutils_a_OBJECTS = $(am_libutils_a_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -56,6 +57,11 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+CXXLD = $(CXX)
+CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
+ -o $@
SOURCES = $(libutils_a_SOURCES)
DIST_SOURCES = $(libutils_a_SOURCES)
ETAGS = etags
@@ -171,12 +177,14 @@ libutils_a_SOURCES = \
hashtable.c \
hashtable.h \
physfsrwops.c \
- physfsrwops.h
+ physfsrwops.h \
+ prefs.cpp \
+ prefs.h
all: all-am
.SUFFIXES:
-.SUFFIXES: .c .o .obj
+.SUFFIXES: .c .cpp .o .obj
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
@@ -222,6 +230,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hashtable.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/physfsrwops.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/prefs.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@@ -237,6 +246,20 @@ distclean-compile:
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+.cpp.o:
+@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $<
+
+.cpp.obj:
+@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
diff --git a/prefs.cpp b/utils/prefs.cpp
similarity index 72%
rename from prefs.cpp
rename to utils/prefs.cpp
index 5438879b..11976c90 100644
--- a/prefs.cpp
+++ b/utils/prefs.cpp
@@ -1,27 +1,24 @@
/*
- Maelstrom: Open Source version of the classic game by Ambrosia Software
- Copyright (C) 1997-2011 Sam Lantinga
-
- 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
-
- Sam Lantinga
- slouken@libsdl.org
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
*/
+#include "SDL.h"
#include "physfs.h"
-#include "utils/hashtable.h"
+#include "hashtable.h"
#include "prefs.h"
@@ -145,7 +142,7 @@ Prefs::SetString(const char *key, const char *value)
}
void
-Prefs::SetNumber(const char *key, Uint32 value)
+Prefs::SetNumber(const char *key, int value)
{
char buf[32];
@@ -164,8 +161,8 @@ Prefs::GetString(const char *key, const char *defaultValue)
return defaultValue;
}
-Uint32
-Prefs::GetNumber(const char *key, Uint32 defaultValue)
+int
+Prefs::GetNumber(const char *key, int defaultValue)
{
const char *value;
diff --git a/prefs.h b/utils/prefs.h
similarity index 54%
rename from prefs.h
rename to utils/prefs.h
index c74f9f07..d11ec26a 100644
--- a/prefs.h
+++ b/utils/prefs.h
@@ -1,30 +1,24 @@
/*
- Maelstrom: Open Source version of the classic game by Ambrosia Software
- Copyright (C) 1997-2011 Sam Lantinga
-
- 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
-
- Sam Lantinga
- slouken@libsdl.org
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _prefs_h
#define _prefs_h
-#include "SDL.h"
-
class HashTable;
class Prefs
@@ -37,34 +31,22 @@ class Prefs
bool Save();
void SetString(const char *key, const char *value);
- void SetNumber(const char *key, Uint32 value);
+ void SetNumber(const char *key, int value);
void Set(const char *key, const char *value) {
SetString(key, value);
}
void Set(const char *key, int value) {
SetNumber(key, value);
}
- void Set(const char *key, Uint32 value) {
- SetNumber(key, value);
- }
- void Set(const char *key, Uint8 value) {
- SetNumber(key, value);
- }
- const char *GetString(const char *key, const char *defaultValue = NULL);
- Uint32 GetNumber(const char *key, Uint32 defaultValue = 0);
+ const char *GetString(const char *key, const char *defaultValue = 0);
+ int GetNumber(const char *key, int defaultValue = 0);
void Get(const char *key, const char *&value, const char *defaultValue) {
value = GetString(key, defaultValue);
}
void Get(const char *key, int &value, int defaultValue) {
value = GetNumber(key, defaultValue);
}
- void Get(const char *key, Uint32 &value, Uint32 defaultValue) {
- value = GetNumber(key, defaultValue);
- }
- void Get(const char *key, Uint8 &value, Uint8 defaultValue) {
- value = GetNumber(key, defaultValue);
- }
protected:
char *m_file;
@@ -76,7 +58,7 @@ class PrefsVariable
{
public:
PrefsVariable(const char *name, const T &rhs) {
- m_prefs = NULL;
+ m_prefs = 0;
m_name = name;
m_defaultValue = m_value = rhs;
}