Refactor setting variables

This commit is contained in:
Tomoaki Kawada 2016-11-19 21:03:51 +09:00
parent 785d62d1f8
commit 6a7af96daf
57 changed files with 412 additions and 268 deletions

View File

@ -466,6 +466,8 @@
E8B93AD518559EC700BD01E1 /* SDL2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E8B93AD418559EC600BD01E1 /* SDL2.framework */; };
E8C92A0C18695EA500740C9F /* SWModelRenderer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8C92A0A18695EA500740C9F /* SWModelRenderer.cpp */; };
E8C92A0F186A902500740C9F /* CpuID.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8C92A0E186A902500740C9F /* CpuID.cpp */; };
E8CB47CD1DE071CA00BF606A /* SWUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8CB47CC1DE071CA00BF606A /* SWUtils.cpp */; };
E8CB47CE1DE071CA00BF606A /* SWUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8CB47CC1DE071CA00BF606A /* SWUtils.cpp */; };
E8CF039A178EDABD000683D4 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E8CF0399178EDABD000683D4 /* OpenAL.framework */; };
E8CF03A8178EDF6A000683D4 /* IRenderer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8CF03A6178EDF6A000683D4 /* IRenderer.cpp */; };
E8CF03AB178EDF74000683D4 /* GLRenderer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8CF03A9178EDF74000683D4 /* GLRenderer.cpp */; };
@ -1001,6 +1003,7 @@
E8C92A0B18695EA500740C9F /* SWModelRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWModelRenderer.h; sourceTree = "<group>"; };
E8C92A0D186A8D3600740C9F /* CpuID.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CpuID.h; sourceTree = "<group>"; };
E8C92A0E186A902500740C9F /* CpuID.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CpuID.cpp; sourceTree = "<group>"; };
E8CB47CC1DE071CA00BF606A /* SWUtils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SWUtils.cpp; sourceTree = "<group>"; };
E8CF0385178ED9D2000683D4 /* OpenSpades-CmdLine */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "OpenSpades-CmdLine"; sourceTree = BUILT_PRODUCTS_DIR; };
E8CF0399178EDABD000683D4 /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = System/Library/Frameworks/OpenAL.framework; sourceTree = SDKROOT; };
E8CF039B178EDAC9000683D4 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
@ -1285,6 +1288,7 @@
E81A7C761864171100BF3FCE /* SWMapRenderer.h */,
E81A7C7818642BCA00BF3FCE /* SWFlatMapRenderer.cpp */,
E81A7C7918642BCA00BF3FCE /* SWFlatMapRenderer.h */,
E8CB47CC1DE071CA00BF606A /* SWUtils.cpp */,
E8FC02D8186829BC00F84A0D /* SWUtils.h */,
E8C92A0A18695EA500740C9F /* SWModelRenderer.cpp */,
E8C92A0B18695EA500740C9F /* SWModelRenderer.h */,
@ -2297,6 +2301,7 @@
E82E67EE18EA7A51004DBA18 /* win32.c in Sources */,
E82E67EF18EA7A51004DBA18 /* pnglite.c in Sources */,
E82E673318EA7972004DBA18 /* as_atomic.cpp in Sources */,
E8CB47CE1DE071CA00BF606A /* SWUtils.cpp in Sources */,
E82E673418EA7972004DBA18 /* as_builder.cpp in Sources */,
E82E673518EA7972004DBA18 /* as_bytecode.cpp in Sources */,
E82E673618EA7972004DBA18 /* as_callfunc.cpp in Sources */,
@ -2791,6 +2796,7 @@
E8B6B72317E452ED00E35523 /* IAudioChunk.cpp in Sources */,
E8B6B72517E46C1D00E35523 /* PrimitiveArray.cpp in Sources */,
E8B6B72817E5AC9C00E35523 /* ServerAddress.cpp in Sources */,
E8CB47CD1DE071CA00BF606A /* SWUtils.cpp in Sources */,
E8B6B72B17E6095900E35523 /* GLLensDustFilter.cpp in Sources */,
E8428888189FE1710060743D /* Fog.vs in Sources */,
E8B6B72E17E68B1C00E35523 /* GLSoftLitSpriteRenderer.cpp in Sources */,

View File

@ -34,9 +34,9 @@
#include <stdlib.h>
#include <cstring>
SPADES_SETTING(s_maxPolyphonics, "96");
SPADES_SETTING(s_eax, "1");
SPADES_SETTING(s_alPreciseErrorCheck, "1");
DEFINE_SPADES_SETTING(s_maxPolyphonics, "96");
DEFINE_SPADES_SETTING(s_eax, "1");
DEFINE_SPADES_SETTING(s_alPreciseErrorCheck, "1");
//lm: seems to be missing for me..
#ifndef ALC_ALL_DEVICES_SPECIFIER
@ -847,4 +847,4 @@ namespace spades {
if(oldMap) oldMap->Release();
}
}
}
}

View File

@ -25,14 +25,14 @@
#include <Core/Math.h>
#if defined(__APPLE__)
SPADES_SETTING(s_alDriver, "/System/Library/Frameworks/OpenAL.framework/OpenAL");
DEFINE_SPADES_SETTING(s_alDriver, "/System/Library/Frameworks/OpenAL.framework/OpenAL");
#elif defined(WIN32)
SPADES_SETTING(s_alDriver, "OpenAL32.dll");
DEFINE_SPADES_SETTING(s_alDriver, "OpenAL32.dll");
#else
SPADES_SETTING(s_alDriver, "libopenal.so.1;libopenal.so.0;libopenal.so");
DEFINE_SPADES_SETTING(s_alDriver, "libopenal.so.1;libopenal.so.0;libopenal.so");
#endif
SPADES_SETTING(s_alErrorFatal, "1");
DEFINE_SPADES_SETTING(s_alErrorFatal, "1");
namespace al{

View File

@ -31,17 +31,17 @@
#include <Core/IStream.h>
#if defined(__APPLE__)
SPADES_SETTING(s_ysrDriver, "libysrspades.dylib");
DEFINE_SPADES_SETTING(s_ysrDriver, "libysrspades.dylib");
#elif defined(WIN32)
SPADES_SETTING(s_ysrDriver, "YSRSpades.dll");
DEFINE_SPADES_SETTING(s_ysrDriver, "YSRSpades.dll");
#else
SPADES_SETTING(s_ysrDriver, "libysrspades.so");
DEFINE_SPADES_SETTING(s_ysrDriver, "libysrspades.so");
#endif
SPADES_SETTING(s_ysrNumThreads, "2");
SPADES_SETTING(s_maxPolyphonics, "");
SPADES_SETTING(s_ysrBufferSize, "1024");
SPADES_SETTING(s_ysrDebug, "0");
DEFINE_SPADES_SETTING(s_ysrNumThreads, "2");
SPADES_SETTING(s_maxPolyphonics);
DEFINE_SPADES_SETTING(s_ysrBufferSize, "1024");
DEFINE_SPADES_SETTING(s_ysrDebug, "0");
namespace spades {
namespace audio {

View File

@ -29,8 +29,8 @@
#include <Core/Math.h>
#include <Core/Settings.h>
SPADES_SETTING(cg_chatHeight, "30");
SPADES_SETTING(cg_killfeedHeight, "26");
DEFINE_SPADES_SETTING(cg_chatHeight, "30");
DEFINE_SPADES_SETTING(cg_killfeedHeight, "26");
namespace spades {
namespace client{

View File

@ -55,10 +55,10 @@
#include "NetClient.h"
SPADES_SETTING(cg_chatBeep, "1");
DEFINE_SPADES_SETTING(cg_chatBeep, "1");
SPADES_SETTING(cg_serverAlert, "1");
DEFINE_SPADES_SETTING(cg_serverAlert, "1");

View File

@ -43,8 +43,8 @@
#include "GunCasing.h"
#include "IAudioChunk.h"
SPADES_SETTING(cg_ragdoll, "");
SPADES_SETTING(cg_ejectBrass, "");
SPADES_SETTING(cg_ragdoll);
SPADES_SETTING(cg_ejectBrass);
namespace spades {
namespace client {

View File

@ -56,15 +56,15 @@
#include "NetClient.h"
SPADES_SETTING(cg_hitIndicator, "1");
SPADES_SETTING(cg_debugAim, "0");
SPADES_SETTING(cg_keyReloadWeapon, "");
SPADES_SETTING(cg_screenshotFormat, "jpeg");
SPADES_SETTING(cg_stats, "0");
SPADES_SETTING(cg_hideHud, "0");
SPADES_SETTING(cg_playerNames, "2");
SPADES_SETTING(cg_playerNameX, "0");
SPADES_SETTING(cg_playerNameY, "0");
DEFINE_SPADES_SETTING(cg_hitIndicator, "1");
DEFINE_SPADES_SETTING(cg_debugAim, "0");
SPADES_SETTING(cg_keyReloadWeapon);
DEFINE_SPADES_SETTING(cg_screenshotFormat, "jpeg");
DEFINE_SPADES_SETTING(cg_stats, "0");
DEFINE_SPADES_SETTING(cg_hideHud, "0");
DEFINE_SPADES_SETTING(cg_playerNames, "2");
DEFINE_SPADES_SETTING(cg_playerNameX, "0");
DEFINE_SPADES_SETTING(cg_playerNameY, "0");
namespace spades {
namespace client {

View File

@ -40,53 +40,53 @@
using namespace std;
SPADES_SETTING(cg_mouseSensitivity, "1");
SPADES_SETTING(cg_zoomedMouseSensScale, "0.6");
SPADES_SETTING(cg_mouseExpPower, "1");
SPADES_SETTING(cg_invertMouseY, "0");
DEFINE_SPADES_SETTING(cg_mouseSensitivity, "1");
DEFINE_SPADES_SETTING(cg_zoomedMouseSensScale, "0.6");
DEFINE_SPADES_SETTING(cg_mouseExpPower, "1");
DEFINE_SPADES_SETTING(cg_invertMouseY, "0");
SPADES_SETTING(cg_holdAimDownSight, "0");
DEFINE_SPADES_SETTING(cg_holdAimDownSight, "0");
SPADES_SETTING(cg_keyAttack, "LeftMouseButton");
SPADES_SETTING(cg_keyAltAttack, "RightMouseButton");
SPADES_SETTING(cg_keyToolSpade, "1");
SPADES_SETTING(cg_keyToolBlock, "2");
SPADES_SETTING(cg_keyToolWeapon, "3");
SPADES_SETTING(cg_keyToolGrenade, "4");
SPADES_SETTING(cg_keyReloadWeapon, "r");
SPADES_SETTING(cg_keyFlashlight, "f");
SPADES_SETTING(cg_keyLastTool, "");
DEFINE_SPADES_SETTING(cg_keyAttack, "LeftMouseButton");
DEFINE_SPADES_SETTING(cg_keyAltAttack, "RightMouseButton");
DEFINE_SPADES_SETTING(cg_keyToolSpade, "1");
DEFINE_SPADES_SETTING(cg_keyToolBlock, "2");
DEFINE_SPADES_SETTING(cg_keyToolWeapon, "3");
DEFINE_SPADES_SETTING(cg_keyToolGrenade, "4");
DEFINE_SPADES_SETTING(cg_keyReloadWeapon, "r");
DEFINE_SPADES_SETTING(cg_keyFlashlight, "f");
DEFINE_SPADES_SETTING(cg_keyLastTool, "");
SPADES_SETTING(cg_keyMoveLeft, "a");
SPADES_SETTING(cg_keyMoveRight, "d");
SPADES_SETTING(cg_keyMoveForward, "w");
SPADES_SETTING(cg_keyMoveBackward, "s");
SPADES_SETTING(cg_keyJump, "Space");
SPADES_SETTING(cg_keyCrouch, "Control");
SPADES_SETTING(cg_keySprint, "Shift");
SPADES_SETTING(cg_keySneak, "v");
DEFINE_SPADES_SETTING(cg_keyMoveLeft, "a");
DEFINE_SPADES_SETTING(cg_keyMoveRight, "d");
DEFINE_SPADES_SETTING(cg_keyMoveForward, "w");
DEFINE_SPADES_SETTING(cg_keyMoveBackward, "s");
DEFINE_SPADES_SETTING(cg_keyJump, "Space");
DEFINE_SPADES_SETTING(cg_keyCrouch, "Control");
DEFINE_SPADES_SETTING(cg_keySprint, "Shift");
DEFINE_SPADES_SETTING(cg_keySneak, "v");
SPADES_SETTING(cg_keyCaptureColor, "e");
SPADES_SETTING(cg_keyGlobalChat, "t");
SPADES_SETTING(cg_keyTeamChat, "y");
SPADES_SETTING(cg_keyChangeMapScale, "m");
SPADES_SETTING(cg_keyToggleMapZoom, "n");
SPADES_SETTING(cg_keyScoreboard, "Tab");
SPADES_SETTING(cg_keyLimbo, "l");
DEFINE_SPADES_SETTING(cg_keyCaptureColor, "e");
DEFINE_SPADES_SETTING(cg_keyGlobalChat, "t");
DEFINE_SPADES_SETTING(cg_keyTeamChat, "y");
DEFINE_SPADES_SETTING(cg_keyChangeMapScale, "m");
DEFINE_SPADES_SETTING(cg_keyToggleMapZoom, "n");
DEFINE_SPADES_SETTING(cg_keyScoreboard, "Tab");
DEFINE_SPADES_SETTING(cg_keyLimbo, "l");
SPADES_SETTING(cg_keyScreenshot, "0");
SPADES_SETTING(cg_keySceneshot, "9");
SPADES_SETTING(cg_keySaveMap, "8");
DEFINE_SPADES_SETTING(cg_keyScreenshot, "0");
DEFINE_SPADES_SETTING(cg_keySceneshot, "9");
DEFINE_SPADES_SETTING(cg_keySaveMap, "8");
SPADES_SETTING(cg_switchToolByWheel, "1");
DEFINE_SPADES_SETTING(cg_switchToolByWheel, "1");
SPADES_SETTING(cg_debugCorpse, "0");
DEFINE_SPADES_SETTING(cg_debugCorpse, "0");
SPADES_SETTING(cg_alerts, "1");
DEFINE_SPADES_SETTING(cg_alerts, "1");
SPADES_SETTING(cg_manualFocus, "0");
SPADES_SETTING(cg_keyAutoFocus, "MiddleMouseButton");
SPADES_SETTING(cg_manualFocus);
DEFINE_SPADES_SETTING(cg_keyAutoFocus, "MiddleMouseButton");
namespace spades {
namespace client {

View File

@ -52,11 +52,11 @@
#include "NetClient.h"
SPADES_SETTING(cg_blood, "1");
SPADES_SETTING(cg_reduceSmoke, "0");
SPADES_SETTING(cg_waterImpact, "1");
SPADES_SETTING(cg_manualFocus, "0");
SPADES_SETTING(cg_autoFocusSpeed, "0.4");
DEFINE_SPADES_SETTING(cg_blood, "1");
DEFINE_SPADES_SETTING(cg_reduceSmoke, "0");
DEFINE_SPADES_SETTING(cg_waterImpact, "1");
SPADES_SETTING(cg_manualFocus);
DEFINE_SPADES_SETTING(cg_autoFocusSpeed, "0.4");
namespace spades {
namespace client {

View File

@ -40,7 +40,7 @@
#include "NetClient.h"
SPADES_SETTING(cg_centerMessage, "2");
DEFINE_SPADES_SETTING(cg_centerMessage, "2");
namespace spades {
namespace client {

View File

@ -41,10 +41,10 @@
#include "NetClient.h"
SPADES_SETTING(cg_fov, "68");
SPADES_SETTING(cg_thirdperson, "0");
SPADES_SETTING(cg_manualFocus, "0");
SPADES_SETTING(cg_depthOfFieldAmount, "1");
DEFINE_SPADES_SETTING(cg_fov, "68");
DEFINE_SPADES_SETTING(cg_thirdperson, "0");
DEFINE_SPADES_SETTING(cg_manualFocus, "0");
DEFINE_SPADES_SETTING(cg_depthOfFieldAmount, "1");
static float nextRandom() {
return (float)rand() / (float)RAND_MAX;

View File

@ -49,12 +49,12 @@
#include "NetClient.h"
SPADES_SETTING(cg_ragdoll, "1");
SPADES_SETTING(cg_blood, "1");
SPADES_SETTING(cg_ejectBrass, "1");
DEFINE_SPADES_SETTING(cg_ragdoll, "1");
SPADES_SETTING(cg_blood);
DEFINE_SPADES_SETTING(cg_ejectBrass, "1");
SPADES_SETTING(cg_alerts, "");
SPADES_SETTING(cg_centerMessage, "");
SPADES_SETTING(cg_alerts);
SPADES_SETTING(cg_centerMessage);
namespace spades {

View File

@ -29,7 +29,7 @@
using namespace std;
SPADES_SETTING(r_corpseLineCollision, "1");
DEFINE_SPADES_SETTING(r_corpseLineCollision, "1");
namespace spades {
namespace client {

View File

@ -32,7 +32,7 @@
#include <Core/FileManager.h>
#include <time.h> //windows needs this.
SPADES_SETTING(cg_smp, "");
SPADES_SETTING(cg_smp);
namespace spades {
namespace client {

View File

@ -30,9 +30,9 @@
#include "TCGameMode.h"
#include "../Core/Settings.h"
SPADES_SETTING(cg_minimapSize, "128");
SPADES_SETTING(cg_Minimap_Player_Color,"1");
SPADES_SETTING(cg_Minimap_Player_Icon,"1");
DEFINE_SPADES_SETTING(cg_minimapSize, "128");
DEFINE_SPADES_SETTING(cg_Minimap_Player_Color,"1");
DEFINE_SPADES_SETTING(cg_Minimap_Player_Icon,"1");
namespace spades {
namespace client {

View File

@ -42,8 +42,8 @@
#include <Core/CP437.h>
#include <Core/Strings.h>
SPADES_SETTING(cg_protocolVersion, "3");
SPADES_SETTING(cg_unicode, "1");
DEFINE_SPADES_SETTING(cg_protocolVersion, "3");
DEFINE_SPADES_SETTING(cg_unicode, "1");
namespace spades {
namespace client {

View File

@ -37,7 +37,7 @@
#include <Core/Strings.h>
#include "../Core/Settings.h"
SPADES_SETTING(cg_Minimap_Player_Color,"1");
SPADES_SETTING(cg_Minimap_Player_Color);
namespace spades {
namespace client {

View File

@ -26,7 +26,7 @@
#include "../Core/Debug.h"
#include "../Core/Settings.h"
SPADES_SETTING(cg_protocolVersion, "3");
SPADES_SETTING(cg_protocolVersion);
namespace spades {
namespace client {

View File

@ -37,7 +37,7 @@
#include "HitTestDebugger.h"
#include <deque>
SPADES_SETTING(cg_debugHitTest, "0");
DEFINE_SPADES_SETTING(cg_debugHitTest, "0");
namespace spades {
namespace client {

View File

@ -46,7 +46,7 @@
#include "ThreadLocalStorage.h"
SPADES_SETTING(core_numDispatchQueueThreads, "auto");
DEFINE_SPADES_SETTING(core_numDispatchQueueThreads, "auto");
static int GetNumCores() {
#ifdef WIN32

View File

@ -27,7 +27,7 @@
#include <Core/Settings.h>
// FIXME: make this changable for every calls for "Save"
SPADES_SETTING(core_jpegQuality, "95");
DEFINE_SPADES_SETTING(core_jpegQuality, "95");
namespace spades {
class JpegWriter: public IBitmapCodec {

View File

@ -52,7 +52,7 @@ namespace spades {
{
auto prefs = ImportFltkPreference();
for(const auto& item: prefs) {
auto *it = GetItem(item.first);
auto *it = GetItem(item.first, nullptr);
it->Set(item.second);
}
@ -156,7 +156,7 @@ namespace spades {
linePos++;
std::string val = readString(false);
auto *item = GetItem(key);
auto *item = GetItem(key, nullptr);
item->Set(val);
line++;
@ -283,26 +283,39 @@ namespace spades {
}
Settings::Item *Settings::GetItem(const std::string &name,
const std::string& def,
const std::string& desc){
const SettingItemDescriptor *descriptor){
SPADES_MARK_FUNCTION();
std::map<std::string, Item *>::iterator it;
Item *item;
it = items.find(name);
if(it == items.end()){
Item *item = new Item();
item = new Item();
item->name = name;
item->desc = desc;
item->defaultValue = def;
item->value = static_cast<float>(atof(def.c_str()));
item->intValue = atoi(def.c_str());
item->string = def;
item->defaults = true;
item->descriptor = descriptor;
item->defaults = true;
items[name] = item;
return item;
}
return it->second;
} else {
item = it->second;
}
if (descriptor) {
if (item->descriptor) {
if (*item->descriptor != *descriptor) {
SPLog("WARNING: setting '%s' has multiple descriptors", name.c_str());
}
} else {
item->descriptor = descriptor;
const std::string &defaultValue = descriptor->defaultValue;
if (item->defaults) {
item->value = static_cast<float>(atof(defaultValue.c_str()));
item->intValue = atoi(defaultValue.c_str());
item->string = defaultValue;
}
}
}
return item;
}
void Settings::Item::Load() {
@ -314,6 +327,8 @@ namespace spades {
value = static_cast<float>(atof(str.c_str()));
intValue = atoi(str.c_str());
defaults = false;
NotifyChange();
}
@ -325,6 +340,8 @@ namespace spades {
intValue = v;
value = (float)v;
defaults = false;
NotifyChange();
}
void Settings::Item::Set(float v){
@ -335,28 +352,21 @@ namespace spades {
intValue = (int)v;
value = v;
defaults = false;
NotifyChange();
}
void Settings::Item::NotifyChange() {
for (ISettingItemListener *listener: listeners) {
listener->SettingChanged(name);
}
}
Settings::ItemHandle::ItemHandle(const std::string& name,
const std::string& def,
const std::string& desc){
const SettingItemDescriptor *descriptor){
SPADES_MARK_FUNCTION();
item = Settings::GetInstance()->GetItem(name, def, desc);
if( !def.empty() && item->defaultValue.empty() ){
item->defaultValue = def;
if(item->defaults) {
item->Set(def);
item->defaults = true;
}
}
if( !desc.empty() && item->desc.empty() ){
item->desc = desc;
}
if( item->defaultValue != def && !def.empty() ){
fprintf(stderr, "WARNING: setting '%s' has multiple default values ('%s', '%s')\n",
name.c_str(), def.c_str(), item->defaultValue.c_str());
}
item = Settings::GetInstance()->GetItem(name, descriptor);
}
void Settings::ItemHandle::operator =(const std::string& value){
@ -387,9 +397,27 @@ namespace spades {
const char *Settings::ItemHandle::CString() {
item->Load();
return item->string.c_str();
}
std::string Settings::ItemHandle::GetDescription() {
return item->desc;
}
void Settings::ItemHandle::AddListener(ISettingItemListener *listener) {
auto &listeners = item->listeners;
listeners.push_back(listener);
}
void Settings::ItemHandle::RemoveListener(ISettingItemListener *listener) {
auto &listeners = item->listeners;
auto it = std::find(listeners.begin(), listeners.end(), listener);
if (it != listeners.end()) {
listeners.erase(it);
}
}
namespace
{
const SettingItemDescriptor defaultDescriptor {
std::string(), SettingItemFlags::None};
}
const SettingItemDescriptor &Settings::ItemHandle::GetDescriptor() {
return item->descriptor ? *item->descriptor : defaultDescriptor;
}

View File

@ -23,8 +23,55 @@
#include <string>
#include <map>
#include <vector>
#include <type_traits>
namespace spades {
enum class SettingItemFlags {
None = 0
};
inline SettingItemFlags operator | (SettingItemFlags lhs, SettingItemFlags rhs)
{
using T = std::underlying_type<SettingItemFlags>::type;
return (SettingItemFlags)(static_cast<T>(lhs) | static_cast<T>(rhs));
}
inline SettingItemFlags& operator |= (SettingItemFlags& lhs, SettingItemFlags rhs)
{
using T = std::underlying_type<SettingItemFlags>::type;
lhs = (SettingItemFlags)(static_cast<T>(lhs) | static_cast<T>(rhs));
return lhs;
}
struct SettingItemDescriptor {
const std::string defaultValue;
const SettingItemFlags flags;
SettingItemDescriptor() = default;
SettingItemDescriptor(const std::string &defaultValue = std::string(),
SettingItemFlags flags = SettingItemFlags::None) :
defaultValue(defaultValue),
flags(flags)
{}
bool operator == (const SettingItemDescriptor &o) const {
return defaultValue == o.defaultValue &&
flags == o.flags;
}
bool operator != (const SettingItemDescriptor &o) const {
return !(*this == o);
}
};
class ISettingItemListener {
protected:
ISettingItemListener() = default;
virtual ~ISettingItemListener() {}
public:
virtual void SettingChanged(const std::string &name) = 0;
};
class Settings {
struct Item {
std::string name;
@ -32,22 +79,24 @@ namespace spades {
float value;
int intValue;
std::string defaultValue;
std::string desc;
const SettingItemDescriptor *descriptor;
bool defaults;
std::vector<ISettingItemListener *> listeners;
void Load();
void Set(const std::string&);
void Set(int);
void Set(float);
void NotifyChange();
};
std::map<std::string, Item *> items;
bool loaded;
Settings();
Item *GetItem(const std::string& name,
const std::string& def = std::string(),
const std::string& desc = std::string());
const SettingItemDescriptor *descriptor);
void Save();
@ -58,9 +107,8 @@ namespace spades {
class ItemHandle {
Item *item;
public:
ItemHandle(const std::string& name,
const std::string& def = std::string(),
const std::string& desc = std::string());
ItemHandle(const std::string& name,
const SettingItemDescriptor *descriptor);
void operator =(const std::string&);
void operator =(int);
void operator =(float);
@ -70,7 +118,10 @@ namespace spades {
operator bool();
const char *CString();
std::string GetDescription();
const SettingItemDescriptor &GetDescriptor();
void AddListener(ISettingItemListener *);
void RemoveListener(ISettingItemListener *);
};
void Load();
@ -90,8 +141,14 @@ namespace spades {
return str == (std::string)handle;
}
#define SPADES_SETTING(name, def) static spades::Settings::ItemHandle name ( # name , def, "" )
#define SPADES_SETTING2(name, def, desc) static spades::Settings::ItemHandle name ( # name , def, desc )
}
// Define SettingItemDescriptor with external linkage so duplicates are
// detected as linker errors.
#define DEFINE_SPADES_SETTING(name, ...) \
spades::SettingItemDescriptor name ## _desc { __VA_ARGS__ }; \
static spades::Settings::ItemHandle name ( # name , & name ## _desc )
#define SPADES_SETTING(name) \
extern spades::SettingItemDescriptor name ## _desc; \
static spades::Settings::ItemHandle name ( # name , & name ## _desc )
}

View File

@ -31,7 +31,7 @@
#include "FileManager.h"
#include "IStream.h"
#include <Core/Debug.h>
SPADES_SETTING(core_locale, "");
DEFINE_SPADES_SETTING(core_locale, "");
#ifdef WIN32
// FIMXE: not tested

View File

@ -26,7 +26,7 @@
#include "../Core/Settings.h"
#include "GLProfiler.h"
SPADES_SETTING(r_shadowMapSize, "2048");
DEFINE_SPADES_SETTING(r_shadowMapSize, "2048");
namespace spades {
namespace draw {

View File

@ -31,7 +31,7 @@
#include "../Core/Debug.h"
#include <Core/Settings.h>
SPADES_SETTING(r_bloom, "");
SPADES_SETTING(r_bloom);
namespace spades {
namespace draw {

View File

@ -32,8 +32,8 @@
#include "GLProfiler.h"
#include "../Core/Settings.h"
SPADES_SETTING(r_depthOfField, "");
SPADES_SETTING(r_depthOfFieldMaxCoc, "0.01");
SPADES_SETTING(r_depthOfField);
DEFINE_SPADES_SETTING(r_depthOfFieldMaxCoc, "0.01");
namespace spades {
namespace draw {

View File

@ -25,14 +25,12 @@
#include "../Core/Debug.h"
#include "../Core/Exception.h"
SPADES_SETTING(r_multisamples, "0");
SPADES_SETTING(r_depthBits, ""); // TODO: use this value
SPADES_SETTING(r_colorBits, ""); // TOOD: use this value
SPADES_SETTING(r_srgb, "0");
SPADES_SETTING(r_highPrec, "1");
SPADES_SETTING(r_hdr, "0");
SPADES_SETTING(r_blitFramebuffer, "1");
SPADES_SETTING(r_water, "2");
DEFINE_SPADES_SETTING(r_multisamples, "0");
SPADES_SETTING(r_srgb);
DEFINE_SPADES_SETTING(r_highPrec, "1");
DEFINE_SPADES_SETTING(r_hdr, "0");
DEFINE_SPADES_SETTING(r_blitFramebuffer, "1");
SPADES_SETTING(r_water);
namespace spades {
namespace draw {

View File

@ -32,7 +32,7 @@
#include <stdlib.h>
#include <Core/Settings.h>
SPADES_SETTING(r_hdr, "");
SPADES_SETTING(r_hdr);
namespace spades {
namespace draw {

View File

@ -27,7 +27,7 @@
#include <Core/Settings.h>
#include "SWFeatureLevel.h"
SPADES_SETTING(r_hdr, "");
SPADES_SETTING(r_hdr);
namespace spades {
namespace draw {

View File

@ -31,7 +31,7 @@
#include "../Core/Settings.h"
#include "GLDynamicLightShader.h"
SPADES_SETTING(r_water, "2");
SPADES_SETTING(r_water);
#include <AngelScript/include/angelscript.h> // for asOFFSET. somehow `offsetof` fails on gcc-4.8

View File

@ -35,7 +35,7 @@
#include "GLDynamicLightShader.h"
#include "GLProfiler.h"
SPADES_SETTING(r_physicalLighting, "0");
DEFINE_SPADES_SETTING(r_physicalLighting, "0");
namespace spades {
namespace draw {

View File

@ -31,7 +31,7 @@
#include "../Core/Debug.h"
#include <Core/Settings.h>
SPADES_SETTING(r_hdrGamma, "2.2");
DEFINE_SPADES_SETTING(r_hdrGamma, "2.2");
namespace spades {
namespace draw {

View File

@ -27,7 +27,7 @@
#include "../Core/Debug.h"
#include "IGLDevice.h"
SPADES_SETTING(r_debugTiming, "0");
SPADES_SETTING(r_debugTiming);
namespace spades {
namespace draw {

View File

@ -32,8 +32,8 @@
#include "../Core/Stopwatch.h"
#include <Core/Settings.h>
SPADES_SETTING(r_hdr, "");
SPADES_SETTING(r_fogShadow, "");
SPADES_SETTING(r_hdr);
SPADES_SETTING(r_fogShadow);
namespace spades {
namespace draw {

View File

@ -33,7 +33,7 @@
#include "GLProfiler.h"
SPADES_SETTING(r_radiosity, "0");
SPADES_SETTING(r_radiosity);
namespace spades {
namespace draw {

View File

@ -64,27 +64,27 @@
#include "GLSoftLitSpriteRenderer.h"
#include "GLAutoExposureFilter.h"
SPADES_SETTING(r_water, "2");
SPADES_SETTING(r_bloom, "1");
SPADES_SETTING(r_lens, "1");
SPADES_SETTING(r_depthOfField, "0");
SPADES_SETTING(r_lensFlare, "1");
SPADES_SETTING(r_lensFlareDynamic, "1");
SPADES_SETTING(r_softParticles, "1");
SPADES_SETTING(r_cameraBlur, "1");
SPADES_SETTING(r_dlights, "1");
SPADES_SETTING(r_optimizedVoxelModel, "1");
SPADES_SETTING(r_radiosity, "0");
SPADES_SETTING(r_fogShadow, "0");
SPADES_SETTING(r_fxaa, "1");
SPADES_SETTING(r_srgb, "");
SPADES_SETTING(r_srgb2D, "1");
SPADES_SETTING(r_colorCorrection, "1");
SPADES_SETTING(r_hdr, "");
SPADES_SETTING(r_hdrAutoExposure, "0");
SPADES_SETTING(r_exposureValue, "0");
DEFINE_SPADES_SETTING(r_water, "2");
DEFINE_SPADES_SETTING(r_bloom, "1");
DEFINE_SPADES_SETTING(r_lens, "1");
DEFINE_SPADES_SETTING(r_depthOfField, "0");
DEFINE_SPADES_SETTING(r_lensFlare, "1");
DEFINE_SPADES_SETTING(r_lensFlareDynamic, "1");
DEFINE_SPADES_SETTING(r_softParticles, "1");
DEFINE_SPADES_SETTING(r_cameraBlur, "1");
DEFINE_SPADES_SETTING(r_dlights, "1");
DEFINE_SPADES_SETTING(r_optimizedVoxelModel, "1");
DEFINE_SPADES_SETTING(r_radiosity, "0");
DEFINE_SPADES_SETTING(r_fogShadow, "0");
DEFINE_SPADES_SETTING(r_fxaa, "1");
DEFINE_SPADES_SETTING(r_srgb, "0");
DEFINE_SPADES_SETTING(r_srgb2D, "1");
DEFINE_SPADES_SETTING(r_colorCorrection, "1");
SPADES_SETTING(r_hdr);
DEFINE_SPADES_SETTING(r_hdrAutoExposure, "0");
DEFINE_SPADES_SETTING(r_exposureValue, "0");
SPADES_SETTING(r_debugTiming, "0");
DEFINE_SPADES_SETTING(r_debugTiming, "0");
namespace spades {
namespace draw {

View File

@ -27,8 +27,8 @@
#include "GLSparseShadowMapRenderer.h"
#include "../Core/Debug.h"
SPADES_SETTING(r_modelShadows, "1");
SPADES_SETTING(r_sparseShadowMaps, "1");
DEFINE_SPADES_SETTING(r_modelShadows, "1");
DEFINE_SPADES_SETTING(r_sparseShadowMaps, "1");
namespace spades {
namespace draw {
@ -84,4 +84,4 @@ namespace spades {
return texStage;
}
}
}
}

View File

@ -31,11 +31,11 @@
#include "GLSparseShadowMapRenderer.h"
#include "GLImage.h"
SPADES_SETTING(r_mapSoftShadow, "0");
SPADES_SETTING(r_radiosity, "0");
DEFINE_SPADES_SETTING(r_mapSoftShadow, "0");
SPADES_SETTING(r_radiosity);
SPADES_SETTING(r_modelShadows, "1");
SPADES_SETTING(r_sparseShadowMaps, "1");
SPADES_SETTING(r_modelShadows);
SPADES_SETTING(r_sparseShadowMaps);
namespace spades {
namespace draw {

View File

@ -32,7 +32,7 @@
#include <Core/Settings.h>
#include "SWFeatureLevel.h"
SPADES_SETTING(r_hdr, "");
SPADES_SETTING(r_hdr);
namespace spades {
namespace draw {

View File

@ -30,7 +30,7 @@
#include <Core/Settings.h>
#include "SWFeatureLevel.h"
SPADES_SETTING(r_hdr, "");
SPADES_SETTING(r_hdr);
namespace spades {
namespace draw {

View File

@ -29,7 +29,7 @@
#include "GLRenderer.h"
#include "GLModel.h"
SPADES_SETTING(r_shadowMapSize, "2048");
SPADES_SETTING(r_shadowMapSize);
namespace spades {
namespace draw {

View File

@ -27,7 +27,7 @@
#include "SWFeatureLevel.h"
#include <Core/Settings.h>
SPADES_SETTING(r_hdr, "");
SPADES_SETTING(r_hdr);
namespace spades {
namespace draw {

View File

@ -36,9 +36,9 @@
#include "GLProfiler.h"
#include "../Core/Settings.h"
SPADES_SETTING(r_water, "2");
SPADES_SETTING(r_maxAnisotropy, "8");
SPADES_SETTING(r_occlusionQuery, "0");
SPADES_SETTING(r_water);
DEFINE_SPADES_SETTING(r_maxAnisotropy, "8");
DEFINE_SPADES_SETTING(r_occlusionQuery, "0");
namespace spades {
namespace draw {

View File

@ -33,7 +33,7 @@
using namespace std;
SPADES_SETTING(r_swUndersampling, "0");
DEFINE_SPADES_SETTING(r_swUndersampling, "0");
namespace spades {
namespace draw {

View File

@ -36,8 +36,8 @@
#include "SWUtils.h"
SPADES_SETTING(r_swStatistics, "0");
SPADES_SETTING(r_swNumThreads, "4");
DEFINE_SPADES_SETTING(r_swStatistics, "0");
DEFINE_SPADES_SETTING(r_swNumThreads, "4");
namespace spades {
namespace draw {

33
Sources/Draw/SWUtils.cpp Normal file
View File

@ -0,0 +1,33 @@
/*
Copyright (c) 2013 yvt
This file is part of OpenSpades.
OpenSpades 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 3 of the License, or
(at your option) any later version.
OpenSpades 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 OpenSpades. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Core/Settings.h>
#include "SWUtils.h"
SPADES_SETTING(r_swNumThreads);
namespace spades {
namespace draw {
int GetNumSWRendererThreads()
{
return r_swNumThreads;
}
}
}

View File

@ -25,14 +25,12 @@
#include <algorithm>
#include <Core/ConcurrentDispatch.h>
#include <Core/Debug.h>
#include <Core/Settings.h>
#include <array>
#include <memory>
namespace spades {
namespace draw {
SPADES_SETTING(r_swNumThreads, "");
namespace draw {
int GetNumSWRendererThreads();
template <class F>
static void InvokeParallel(F f, unsigned int numThreads) {
@ -55,7 +53,7 @@ namespace spades {
template <class F>
static void InvokeParallel2(F f) {
unsigned int numThreads = static_cast<unsigned int>((int)r_swNumThreads);
unsigned int numThreads = static_cast<unsigned int>(GetNumSWRendererThreads());
numThreads = std::max(numThreads, 1U);
numThreads = std::min(numThreads, 32U);

View File

@ -73,7 +73,7 @@ static const unsigned char Icon[] = {
};
#endif
SPADES_SETTING(cl_showStartupWindow, "1");
DEFINE_SPADES_SETTING(cl_showStartupWindow, "1");
#ifdef WIN32
#include <windows.h>
@ -81,7 +81,7 @@ SPADES_SETTING(cl_showStartupWindow, "1");
#define strncasecmp(x,y,z) _strnicmp(x,y,z)
#define strcasecmp(x,y) _stricmp(x,y)
SPADES_SETTING(core_win32BeginPeriod, "1");
DEFINE_SPADES_SETTING(core_win32BeginPeriod, "1");
class ThreadQuantumSetter {
public:
@ -163,9 +163,9 @@ class ThreadQuantumSetter {
#endif
SPADES_SETTING(cg_lastQuickConnectHost, "");
SPADES_SETTING(cg_protocolVersion, "");
SPADES_SETTING(cg_playerName, "");
SPADES_SETTING(cg_lastQuickConnectHost);
SPADES_SETTING(cg_protocolVersion);
SPADES_SETTING(cg_playerName);
int cg_autoConnect = 0;
bool cg_printVersion = false;
bool cg_printHelp = false;

View File

@ -30,9 +30,9 @@
#include <Core/Strings.h>
#include <ScriptBindings/Config.h>
SPADES_SETTING(cg_lastQuickConnectHost, "127.0.0.1");
SPADES_SETTING(cg_protocolVersion, "");
SPADES_SETTING(cg_playerName, "Deuce");
DEFINE_SPADES_SETTING(cg_lastQuickConnectHost, "127.0.0.1");
SPADES_SETTING(cg_protocolVersion);
DEFINE_SPADES_SETTING(cg_playerName, "Deuce");
namespace spades {
namespace gui {

View File

@ -30,7 +30,7 @@
#include <algorithm>
#include <cctype>
SPADES_SETTING(cl_serverListUrl, "http://services.buildandshoot.com/serverlist.json");
DEFINE_SPADES_SETTING(cl_serverListUrl, "http://services.buildandshoot.com/serverlist.json");
namespace spades {

View File

@ -26,9 +26,9 @@
#include <Core/Exception.h>
#include <Core/Strings.h>
SPADES_SETTING(cg_smp, "0");
SPADES_SETTING(r_videoWidth, "1024");
SPADES_SETTING(r_videoHeight, "640");
DEFINE_SPADES_SETTING(cg_smp, "0");
DEFINE_SPADES_SETTING(r_videoWidth, "1024");
DEFINE_SPADES_SETTING(r_videoHeight, "640");
namespace spades {
namespace gui {

View File

@ -35,7 +35,7 @@ using namespace spades::draw;
#define __PRETTY_FUNCTION__ __FUNCDNAME__
#endif
SPADES_SETTING(r_ignoreGLErrors, "1");
DEFINE_SPADES_SETTING(r_ignoreGLErrors, "1");
static uint32_t vertCount = 0;
static uint32_t drawOps = 0;

View File

@ -47,18 +47,18 @@ static const unsigned char Icon[] = {
};
#endif
SPADES_SETTING(r_videoWidth, "1024");
SPADES_SETTING(r_videoHeight, "640");
SPADES_SETTING(r_fullscreen, "0");
SPADES_SETTING(r_colorBits, "32");
SPADES_SETTING(r_depthBits, "16");
SPADES_SETTING(r_vsync, "1");
SPADES_SETTING(r_allowSoftwareRendering, "0");
SPADES_SETTING(r_renderer, "gl");
SPADES_SETTING(r_videoWidth);
SPADES_SETTING(r_videoHeight);
DEFINE_SPADES_SETTING(r_fullscreen, "0");
DEFINE_SPADES_SETTING(r_colorBits, "32");
DEFINE_SPADES_SETTING(r_depthBits, "16");
DEFINE_SPADES_SETTING(r_vsync, "1");
DEFINE_SPADES_SETTING(r_allowSoftwareRendering, "0");
DEFINE_SPADES_SETTING(r_renderer, "gl");
#ifdef __APPLE__
SPADES_SETTING(s_audioDriver, "ysr");
DEFINE_SPADES_SETTING(s_audioDriver, "ysr");
#else
SPADES_SETTING(s_audioDriver, "openal");
DEFINE_SPADES_SETTING(s_audioDriver, "openal");
#endif
namespace spades {

View File

@ -37,39 +37,39 @@ static const unsigned char Icon[] = {
};
#endif
SPADES_SETTING(r_bloom, "");
SPADES_SETTING(r_lens, "");
SPADES_SETTING(r_cameraBlur, "");
SPADES_SETTING(r_softParticles, "");
SPADES_SETTING(r_mapSoftShadow, "");
SPADES_SETTING(r_modelShadows, "");
SPADES_SETTING(r_radiosity, "");
SPADES_SETTING(r_dlights, "");
SPADES_SETTING(r_water, "");
SPADES_SETTING(r_multisamples, "");
SPADES_SETTING(r_fxaa, "");
SPADES_SETTING(r_depthBits, "");
SPADES_SETTING(r_colorBits, "");
SPADES_SETTING(r_videoWidth, "");
SPADES_SETTING(r_videoHeight, "");
SPADES_SETTING(r_fullscreen, "");
SPADES_SETTING(r_fogShadow, "");
SPADES_SETTING(r_lensFlare, "");
SPADES_SETTING(r_lensFlareDynamic, "");
SPADES_SETTING(r_blitFramebuffer, "");
SPADES_SETTING(r_srgb, "");
SPADES_SETTING(r_shadowMapSize, "");
SPADES_SETTING(s_maxPolyphonics, "");
SPADES_SETTING(s_eax, "");
SPADES_SETTING(r_maxAnisotropy, "");
SPADES_SETTING(r_colorCorrection, "");
SPADES_SETTING(r_physicalLighting, "");
SPADES_SETTING(r_occlusionQuery, "");
SPADES_SETTING(r_depthOfField, "");
SPADES_SETTING(r_vsync, "");
SPADES_SETTING(r_renderer, "");
SPADES_SETTING(r_swUndersampling, "");
SPADES_SETTING(r_hdr, "");
SPADES_SETTING(r_bloom);
SPADES_SETTING(r_lens);
SPADES_SETTING(r_cameraBlur);
SPADES_SETTING(r_softParticles);
SPADES_SETTING(r_mapSoftShadow);
SPADES_SETTING(r_modelShadows);
SPADES_SETTING(r_radiosity);
SPADES_SETTING(r_dlights);
SPADES_SETTING(r_water);
SPADES_SETTING(r_multisamples);
SPADES_SETTING(r_fxaa);
SPADES_SETTING(r_depthBits);
SPADES_SETTING(r_colorBits);
SPADES_SETTING(r_videoWidth);
SPADES_SETTING(r_videoHeight);
SPADES_SETTING(r_fullscreen);
SPADES_SETTING(r_fogShadow);
SPADES_SETTING(r_lensFlare);
SPADES_SETTING(r_lensFlareDynamic);
SPADES_SETTING(r_blitFramebuffer);
SPADES_SETTING(r_srgb);
SPADES_SETTING(r_shadowMapSize);
SPADES_SETTING(s_maxPolyphonics);
SPADES_SETTING(s_eax);
SPADES_SETTING(r_maxAnisotropy);
SPADES_SETTING(r_colorCorrection);
SPADES_SETTING(r_physicalLighting);
SPADES_SETTING(r_occlusionQuery);
SPADES_SETTING(r_depthOfField);
SPADES_SETTING(r_vsync);
SPADES_SETTING(r_renderer);
SPADES_SETTING(r_swUndersampling);
SPADES_SETTING(r_hdr);
namespace spades {
namespace gui {

View File

@ -22,10 +22,30 @@
#include <Core/Settings.h>
#include <Core/RefCountedObject.h>
#include <Core/ThreadLocalStorage.h>
#include <unordered_map>
namespace spades {
static ThreadLocalStorage<bool> writeAllowed;
namespace
{
ThreadLocalStorage<bool> writeAllowed;
// SettingItemDescriptor supplied to ItemHandle must have the static storage duration
std::unordered_map<std::string, const SettingItemDescriptor *>
settingItemDescriptors;
const SettingItemDescriptor *MakeSettingItemDescriptor
(const std::string &name, const std::string &defaultValue)
{
auto it = settingItemDescriptors.find(name);
if (it != settingItemDescriptors.end()) {
return it->second;
}
auto *descriptor = new SettingItemDescriptor(defaultValue, SettingItemFlags::None);
settingItemDescriptors.insert(make_pair(name, descriptor));
return descriptor;
}
}
void MaskConfigUpdateByScript(bool disabled)
{
@ -34,6 +54,7 @@ namespace spades {
}
*writeAllowed = !disabled;
}
class ConfigRegistrar: public ScriptObjectRegistrar {
@ -44,16 +65,19 @@ namespace spades {
class ConfigItem: public RefCountedObject {
Settings::ItemHandle handle;
public:
ConfigItem(const std::string& name, const std::string& defaultValue):
handle(name, defaultValue){
}
public:
ConfigItem(const std::string& name, const std::string& defaultValue):
handle(name, MakeSettingItemDescriptor(name, defaultValue)){
}
ConfigItem(const std::string& name):
handle(name, nullptr){
}
static ConfigItem *Construct(const std::string& name, const std::string& defaultValue) {
return new ConfigItem(name, defaultValue);
}
static ConfigItem *Construct(const std::string& name) {
return new ConfigItem(name, std::string());
return new ConfigItem(name);
}
ConfigItem *operator =(float fv) {