[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Enigma-cvs] enigma/src options.hh,1.25,1.26 options.cc,1.29,1.30
From: |
Daniel Heck <address@hidden> |
Subject: |
[Enigma-cvs] enigma/src options.hh,1.25,1.26 options.cc,1.29,1.30 |
Date: |
Sun, 16 Nov 2003 19:33:53 +0000 |
Update of /cvsroot/enigma/enigma/src
In directory subversions:/tmp/cvs-serv17856/src
Modified Files:
options.hh options.cc
Log Message:
Added SetOption(), GetOption(),
GetBool(), GetDouble(), GetInt(), GetString().
Changed signature of GetLevelStatus.
Removed SetLevelTime() (now in class LevelPack).
Index: options.hh
===================================================================
RCS file: /cvsroot/enigma/enigma/src/options.hh,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** options.hh 9 Nov 2003 11:55:13 -0000 1.25
--- options.hh 16 Nov 2003 19:33:51 -0000 1.26
***************
*** 1,4 ****
/*
! * Copyright (C) 2002 Daniel Heck
*
* This program is free software; you can redistribute it and/or
--- 1,4 ----
/*
! * Copyright (C) 2002, 2003 Daniel Heck
*
* This program is free software; you can redistribute it and/or
***************
*** 19,22 ****
--- 19,29 ----
#define OPTIONS_HH
+ /*
+ ** Options are ``persistent'' settings that can saved to a Lua file or
+ ** loaded from it. This file defined the C++ interface to options;
+ ** loading and saving are handled by Lua functions defined in
+ ** `startup.lua'.
+ */
+
#include <ctime>
#include <string>
***************
*** 30,99 ****
/* -------------------- Variables -------------------- */
! extern int BitsPerPixel;
! extern double MouseSpeed;
! extern bool WizardMode;
! extern bool FullScreen;
! extern bool ShowFPS;
! extern bool UseAlpha;
! extern bool Nograb;
! extern bool Nozoom;
! extern bool InGameMusic;
! extern double SoundVolume;
! extern double MusicVolume;
! extern double StereoSeparation;
! extern string MenuMusicFile;
! extern string LevelMusicFile;
! extern int SoundSet;
! extern bool SkipSolvedLevels;
! extern bool TimeHunting;
! extern int Difficulty;
! extern int VideoMode;
! extern int LevelMenuPosition;
!
! // True if any LevelStatus differs from last saved state.
extern bool LevelStatusChanged;
! // An option was changed that will not take effect until Enigma is
! // restarted.
extern bool MustRestart;
! // An option was changed that makes it necessary to restart the
! // current level (e.g. Difficulty changed while playing level).
! // When 'MustRestartLevel' is set to true, the current level
! // will restart w/o any further questions.
extern bool MustRestartLevel;
! /* -------------------- Constants -------------------- */
!
! const int minMouseSpeed = 1;
! const int maxMouseSpeed = 15;
! /* -------------------- Functions -------------------- */
using levels::LevelStatus;
! /* Get the status of a particular level in a particular pack.
! Returns 0 if no record for this level exists. */
! LevelStatus *GetLevelStatus(const string &levelpack,
! const string &levelname);
! /* Set the status of a particular level. The previous entry (if
! available) for this level is discarded. */
void SetLevelStatus(const string &levelpack,
const string &levelname,
const LevelStatus &stat);
! /* Returns true if time is new record for this level */
! bool SetLevelTime(const string &pack, const string &level,
! int difficulty, int revision, int time);
!
! /* Save the current set of options to the user's configuration
! file. (Either ~/.enigmarc on Unix systems or ./enigmarc.lua on
! Win32. */
bool Save ();
! /* Try to load the user's configuration file. Returns true if
! successful. */
bool Load ();
}
--- 37,86 ----
/* -------------------- Variables -------------------- */
! /*! True if any LevelStatus differs from last saved state. */
extern bool LevelStatusChanged;
! /*! An option was changed that will not take effect until Enigma is
! restarted. */
extern bool MustRestart;
! /*! An option was changed that makes it necessary to restart the
! current level (e.g. Difficulty changed during the game). When
! 'MustRestartLevel' is set to true, the current level will
! restart w/o any further questions. */
extern bool MustRestartLevel;
+ /* -------------------- Functions -------------------- */
! void SetOption (const char *name, double value);
! void SetOption (const char *name, const std::string &value);
! void GetOption (const char *name, double &value);
! void GetOption (const char *name, std::string &value);
! bool GetBool (const char *name);
! double GetDouble (const char *name);
! int GetInt (const char *name);
! string GetString (const char *name);
using levels::LevelStatus;
! /*! Get the status of a particular level in a particular pack.
! Returns false if no record for this level exists. */
! bool GetLevelStatus (const string &levelpack,
! const string &levelname,
! LevelStatus &stat);
! /*! Set the status of a particular level. The previous entry (if
! available) for this level is discarded. */
void SetLevelStatus(const string &levelpack,
const string &levelname,
const LevelStatus &stat);
! /*! Save the current set of options to the user's configuration
! file. (Either ~/.enigmarc on Unix systems or ./enigmarc.lua on
! Win32. */
bool Save ();
! /*! Try to load the user's configuration file. Returns true if
! successful. */
bool Load ();
}
Index: options.cc
===================================================================
RCS file: /cvsroot/enigma/enigma/src/options.cc,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** options.cc 9 Nov 2003 11:55:27 -0000 1.29
--- options.cc 16 Nov 2003 19:33:51 -0000 1.30
***************
*** 37,73 ****
using namespace std;
namespace options
{
- int BitsPerPixel = 16;
- double MouseSpeed = 5.0;
- double MouseDamping = 25.0;
- bool WizardMode = false;
- bool FullScreen = true;
- bool ShowFPS = false;
- bool UseAlpha = true;
- bool Nograb = false;
- bool Nozoom = true;
- bool InGameMusic = false;
- int Difficulty = enigma::DIFFICULTY_HARD ;
- int VideoMode = 0;
- int LevelMenuPosition = 0;
-
- double SoundVolume = 1.0;
- double MusicVolume = 1.0;
- double StereoSeparation = 10.0;
-
- string MenuMusicFile = "/sound/menu.s3m";
- string LevelMusicFile = "/sound/Emilie.xm";
-
- int SoundSet = 0;
- // 0 = 'enigma' for enigma, appropriate oxyd sound sets for diff. oxyd
versions
- // 1 = 'enigma'
- // 2.. = OxydVersion-2
-
- bool SkipSolvedLevels = false;
- bool TimeHunting = false;
-
- // not stored in ~/.enigmarc :
-
bool LevelStatusChanged = false;
bool MustRestart = false;
--- 37,45 ----
using namespace std;
+
+ /* -------------------- Variables -------------------- */
+
namespace options
{
bool LevelStatusChanged = false;
bool MustRestart = false;
***************
*** 75,172 ****
}
! namespace
{
! px::Dict<LevelStatus> level_status_dict;
}
!
! LevelStatus::LevelStatus(int easy, int hard, int fin, int solved_rev)
! : time_easy(easy),
! time_hard(hard),
! finished(fin),
! solved_revision(solved_rev)
{
! // if (!solved_at && fin>0)
! // solved_at = time(0); // default to now
}
! bool LevelStatus::operator != (const LevelStatus& other) const
{
! return !(time_easy == other.time_easy &&
! time_hard == other.time_hard &&
! finished == other.finished &&
! solved_revision == other.solved_revision);
}
! static string
! levelkey(const string &/*levelpack*/, const string &levelname)
! {
! return string("#")+levelname;
}
! /* Get the status of a particular level in a particular pack.
! Returns 0 if no record for this level exists. */
! LevelStatus *
! options::GetLevelStatus(const string &levelpack, const string &levelname)
! {
! px::Dict<LevelStatus>::iterator i;
! i = level_status_dict.find (levelkey (levelpack, levelname));
! return (i != level_status_dict.end()) ? &i->second : 0;
}
! /* Set the status of a particular level. The previous entry (if
! available) for this level is discarded. */
! void
! options::SetLevelStatus(const string &levelpack, const string &levelname,
! const LevelStatus &stat)
! {
! string key = levelkey (levelpack, levelname);
! px::Dict<LevelStatus>::iterator i = level_status_dict.find (key);
! if (i != level_status_dict.end()) { // status exists -> overwrite
! if (i->second != stat) {
! LevelStatusChanged = true;
! }
! i->second = stat;
! }
! else {
! level_status_dict.insert(key,stat);
! LevelStatusChanged = true;
! }
}
! bool
! options::SetLevelTime(const string &pack, const string &level, int
difficulty, int revision, int time)
{
! LevelStatus *stat = GetLevelStatus(pack, level);
! if (stat) {
! if (((stat->solved_revision < revision) && (stat->solved_revision >=
1)) || stat->finished == 0)
! {
! stat->time_hard = -1;
! stat->time_easy = -1;
! stat->finished = 0;
! }
! stat->finished |= difficulty;
! stat->solved_revision = revision;
! }
! else {
! SetLevelStatus(pack, level, LevelStatus(-1, -1, difficulty,
revision));
! stat = GetLevelStatus(pack, level);
! assert(stat);
}
! bool new_record = false;
! int& time_curr = difficulty == enigma::DIFFICULTY_EASY ? stat->time_easy
: stat->time_hard;
! if (time_curr > time || time_curr == -1) {
! time_curr = time;
! new_record = true;
! }
LevelStatusChanged = true;
! return new_record;
}
--- 47,162 ----
}
!
! /* -------------------- Functions -------------------- */
!
! void options::SetOption (const char *name, double value)
{
! lua_State *L = lua::GlobalState();
! lua::SetTableVar (L, "options", name, value);
}
! void options::SetOption (const char *name, const std::string &value)
{
! lua_State *L = lua::GlobalState();
! lua_getglobal (L, "options");
! lua_pushstring (L, name);
! lua_pushstring (L, value.c_str());
! lua_rawset (L, -3);
! lua_pop (L, 1);
}
! void options::GetOption (const char *name, double &value)
{
! lua_State *L = lua::GlobalState();
! lua_getglobal (L, "options");
! lua_pushstring (L, name);
! lua_rawget (L, -2);
! value = lua_tonumber (L, -1);
! lua_pop(L, 2);
}
+ void options::GetOption (const char *name, std::string &value) {
+ lua_State *L = lua::GlobalState();
+ lua_getglobal (L, "options");
+ lua_pushstring (L, name);
+ lua_rawget (L, -2);
+ value = lua_tostring (L, -1);
+ lua_pop (L, 2);
+ }
! bool options::GetBool (const char *name) {
! double val = 0;
! GetOption (name, val);
! return val != 0;
}
! double options::GetDouble (const char *name) {
! double val = 0;
! GetOption (name, val);
! return val;
}
! int options::GetInt (const char *name) {
! double val = 0;
! GetOption (name, val);
! return static_cast<int>(val);
! }
! string options::GetString (const char *name) {
! string val;
! GetOption (name, val);
! return val;
}
! bool options::GetLevelStatus (const string &levelpack,
! const string &levelname,
! LevelStatus &stat)
{
! lua_State *L = lua::GlobalState();
! int oldtop = lua_gettop(L);
! lua_getglobal(L, "stats");
! lua_pushstring (L, levelname.c_str());
! lua_rawget (L, -2);
! if (!lua_istable(L, -1) || !lua_getn(L, -1)==4) {
! lua_settop(L, oldtop);
! return false;
}
! lua_rawgeti (L, -1, 1); stat.time_easy = (int) lua_tonumber (L, -1);
lua_pop(L, 1);
! lua_rawgeti (L, -1, 2); stat.time_hard = (int) lua_tonumber (L, -1);
lua_pop(L, 1);
! lua_rawgeti (L, -1, 3); stat.finished = (int) lua_tonumber (L, -1);
lua_pop(L, 1);
! lua_rawgeti (L, -1, 4); stat.solved_revision = (int) lua_tonumber (L, -1);
! lua_settop(L, oldtop);
! return true;
! }
!
! void
! options::SetLevelStatus(const string &levelpack, const string &levelname,
! const LevelStatus &stat)
! {
! LevelStatus oldstat;
! if (GetLevelStatus(levelpack, levelname, oldstat))
! if (oldstat == stat)
! return; // If nothing changed, return
LevelStatusChanged = true;
!
! lua_State *L = lua::GlobalState();
!
! int oldtop = lua_gettop(L);
!
! lua_getglobal(L, "stats");
! lua_pushstring (L, levelname.c_str());
! lua_newtable (L);
! lua_pushnumber (L, stat.time_easy); lua_rawseti (L, -2, 1);
! lua_pushnumber (L, stat.time_hard); lua_rawseti (L, -2, 2);
! lua_pushnumber (L, stat.finished); lua_rawseti (L, -2, 3);
! lua_pushnumber (L, stat.solved_revision); lua_rawseti (L, -2, 4);
! lua_rawset (L, -3); // stats[levename] =
!
! lua_settop(L, oldtop);
}
***************
*** 238,284 ****
#endif
! FILE *fp = fopen(fname.c_str(), "wt");
!
! if (fp) {
! fprintf (fp, "options.MouseSpeed = %f\n", MouseSpeed);
! fprintf (fp, "options.MouseDamping = %f\n", MouseDamping);
! fprintf (fp, "options.FullScreen = %d\n", FullScreen);
! fprintf (fp, "options.UseAlpha = %d\n", UseAlpha);
! fprintf (fp, "options.SoundVolume = %f\n", SoundVolume);
! fprintf (fp, "options.MusicVolume = %f\n", MusicVolume);
! fprintf (fp, "options.InGameMusic = %d\n", InGameMusic);
! fprintf (fp, "options.StereoSeparation = %f\n", StereoSeparation);
! fprintf (fp, "options.MenuMusicFile = \"%s\"\n",
MenuMusicFile.c_str());
! fprintf (fp, "options.LevelMusicFile = \"%s\"\n",
LevelMusicFile.c_str());
! fprintf (fp, "options.SoundSet = \"%i\"\n", SoundSet);
! fprintf (fp, "options.SkipSolvedLevels = %d\n", SkipSolvedLevels);
! fprintf (fp, "options.TimeHunting = %d\n", TimeHunting);
! fprintf (fp, "options.Difficulty = %d\n", Difficulty);
! fprintf (fp, "options.VideoMode = %d\n", VideoMode);
! fprintf (fp, "options.LevelMenuPosition = %d\n",
LevelMenuPosition);
!
! // Save level information
! set<string> sorted;
! px::Dict<LevelStatus>::iterator i = level_status_dict.begin();
! for (; i!=level_status_dict.end(); ++i) {
! sorted.insert(i->first.c_str());
! }
!
! set<string>::const_iterator ni = sorted.begin();
! for (; ni != sorted.end(); ++ni) {
! i = level_status_dict.find(*ni);
! assert(i != level_status_dict.end()); // has to be found!
! LevelStatus& ls = i->second;
!
! fprintf (fp, "options.LevelStat2(\"%s\", {%d, %d, %d, %d})\n",
! i->first.c_str(),
! ls.time_easy,
! ls.time_hard,
! ls.finished,
! ls.solved_revision);
! }
!
! fclose(fp);
!
LevelStatusChanged = false;
return true;
--- 228,232 ----
#endif
! if (lua::CallFunc(lua::GlobalState(), "SaveOptions", fname+"2") == 0) {
LevelStatusChanged = false;
return true;
***************
*** 290,294 ****
load_from_file (const char *fname)
{
! switch (lua_dofile (lua::state, fname)) {
case 0: // Everything ok
case LUA_ERRFILE: // File not found is not fatal
--- 238,242 ----
load_from_file (const char *fname)
{
! switch (lua_dofile (lua::GlobalState(), fname)) {
case 0: // Everything ok
case LUA_ERRFILE: // File not found is not fatal
***************
*** 314,317 ****
--- 262,267 ----
fname = Personal_ConfigurationFileName();
error |= load_from_file (fname.c_str());
+
+ lua::CallFunc (lua::GlobalState(), "LoadOptions", fname + "2");
LevelStatusChanged = false;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Enigma-cvs] enigma/src options.hh,1.25,1.26 options.cc,1.29,1.30,
Daniel Heck <address@hidden> <=