2012-12-19 09:30:18 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
2015-11-10 05:21:49 +00:00
|
|
|
* Project64 - A Nintendo 64 emulator. *
|
2012-12-19 09:30:18 +00:00
|
|
|
* http://www.pj64-emu.com/ *
|
|
|
|
* Copyright (C) 2012 Project64. All rights reserved. *
|
|
|
|
* *
|
|
|
|
* License: *
|
|
|
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
2008-09-18 03:15:49 +00:00
|
|
|
#pragma once
|
|
|
|
|
2016-01-13 07:23:22 +00:00
|
|
|
#include <Project64-core/Settings/SettingType/SettingsType-Base.h>
|
2018-04-02 18:30:50 +00:00
|
|
|
#include <Project64-core/Settings/SettingsID.h>
|
2016-02-01 06:05:30 +00:00
|
|
|
#include <map>
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-10-25 10:50:28 +00:00
|
|
|
enum SettingDataType
|
|
|
|
{
|
2016-01-28 09:40:08 +00:00
|
|
|
Data_DWORD = 0,
|
|
|
|
Data_String = 1,
|
|
|
|
Data_CPUTYPE = 2,
|
|
|
|
Data_SelfMod = 3,
|
|
|
|
Data_OnOff = 4,
|
|
|
|
Data_YesNo = 5,
|
2015-10-25 10:50:28 +00:00
|
|
|
Data_SaveChip = 6
|
2008-09-18 03:15:49 +00:00
|
|
|
};
|
|
|
|
|
2015-10-25 10:50:28 +00:00
|
|
|
class CSettings
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
public:
|
2016-01-28 09:40:08 +00:00
|
|
|
typedef void(*SettingChangedFunc)(void *);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-10-25 10:50:28 +00:00
|
|
|
CSettings(void);
|
|
|
|
~CSettings(void);
|
|
|
|
|
2016-01-28 09:40:08 +00:00
|
|
|
bool Initialize(const char * BaseDirectory, const char * AppName);
|
2015-10-25 10:50:28 +00:00
|
|
|
|
|
|
|
//return the values
|
2018-03-28 08:28:02 +00:00
|
|
|
bool LoadBool(SettingID Type);
|
|
|
|
bool LoadBool(SettingID Type, bool & Value);
|
|
|
|
bool LoadBoolIndex(SettingID Type, uint32_t index);
|
|
|
|
bool LoadBoolIndex(SettingID Type, uint32_t index, bool & Value);
|
2016-01-28 09:40:08 +00:00
|
|
|
uint32_t LoadDword(SettingID Type);
|
2018-03-28 08:28:02 +00:00
|
|
|
bool LoadDword(SettingID Type, uint32_t & Value);
|
|
|
|
uint32_t LoadDwordIndex(SettingID Type, uint32_t index);
|
|
|
|
bool LoadDwordIndex(SettingID Type, uint32_t index, uint32_t & Value);
|
|
|
|
std::string LoadStringVal(SettingID Type);
|
|
|
|
bool LoadStringVal(SettingID Type, std::string & Value);
|
|
|
|
bool LoadStringVal(SettingID Type, char * Buffer, uint32_t BufferSize);
|
|
|
|
std::string LoadStringIndex(SettingID Type, uint32_t index);
|
|
|
|
bool LoadStringIndex(SettingID Type, uint32_t index, std::string & Value);
|
|
|
|
bool LoadStringIndex(SettingID Type, uint32_t index, char * Buffer, uint32_t BufferSize);
|
2015-10-25 10:50:28 +00:00
|
|
|
|
|
|
|
//Load the default value for the setting
|
2018-03-28 08:28:02 +00:00
|
|
|
bool LoadDefaultBool(SettingID Type);
|
|
|
|
void LoadDefaultBool(SettingID Type, bool & Value);
|
|
|
|
bool LoadDefaultBoolIndex(SettingID Type, uint32_t index);
|
|
|
|
void LoadDefaultBoolIndex(SettingID Type, uint32_t index, bool & Value);
|
2016-01-28 09:40:08 +00:00
|
|
|
uint32_t LoadDefaultDword(SettingID Type);
|
2018-03-28 08:28:02 +00:00
|
|
|
void LoadDefaultDword(SettingID Type, uint32_t & Value);
|
|
|
|
uint32_t LoadDefaultDwordIndex(SettingID Type, uint32_t index);
|
|
|
|
void LoadDefaultDwordIndex(SettingID Type, uint32_t index, uint32_t & Value);
|
|
|
|
std::string LoadDefaultString(SettingID Type);
|
|
|
|
void LoadDefaultString(SettingID Type, std::string & Value);
|
|
|
|
void LoadDefaultString(SettingID Type, char * Buffer, uint32_t BufferSize);
|
|
|
|
std::string LoadDefaultStringIndex(SettingID Type, uint32_t index);
|
|
|
|
void LoadDefaultStringIndex(SettingID Type, uint32_t index, std::string & Value);
|
|
|
|
void LoadDefaultStringIndex(SettingID Type, uint32_t index, char * Buffer, uint32_t BufferSize);
|
2015-10-25 10:50:28 +00:00
|
|
|
|
|
|
|
//Update the settings
|
2018-03-28 08:28:02 +00:00
|
|
|
void SaveBool(SettingID Type, bool Value);
|
|
|
|
void SaveBoolIndex(SettingID Type, uint32_t index, bool Value);
|
|
|
|
void SaveDword(SettingID Type, uint32_t Value);
|
|
|
|
void SaveDwordIndex(SettingID Type, uint32_t index, uint32_t Value);
|
|
|
|
void SaveString(SettingID Type, const std::string & Value);
|
|
|
|
void SaveStringIndex(SettingID Type, uint32_t index, const std::string & Value);
|
|
|
|
void SaveString(SettingID Type, const char * Buffer);
|
|
|
|
void SaveStringIndex(SettingID Type, uint32_t index, const char * Buffer);
|
2015-10-25 10:50:28 +00:00
|
|
|
|
|
|
|
// Delete a setting
|
2016-01-28 09:40:08 +00:00
|
|
|
void DeleteSetting(SettingID Type);
|
2018-03-28 08:28:02 +00:00
|
|
|
void DeleteSettingIndex(SettingID Type, uint32_t index);
|
2015-10-25 10:50:28 +00:00
|
|
|
|
|
|
|
//Register Notification of change
|
2016-01-28 09:40:08 +00:00
|
|
|
void RegisterChangeCB(SettingID Type, void * Data, SettingChangedFunc Func);
|
|
|
|
void UnregisterChangeCB(SettingID Type, void * Data, SettingChangedFunc Func);
|
2015-10-25 10:50:28 +00:00
|
|
|
|
|
|
|
// information about setting
|
2018-03-28 08:28:02 +00:00
|
|
|
SettingType GetSettingType(SettingID Type);
|
|
|
|
bool IndexBasedSetting(SettingID Type);
|
|
|
|
void SettingTypeChanged(SettingType Type);
|
|
|
|
bool IsSettingSet(SettingID Type);
|
2015-10-25 10:50:28 +00:00
|
|
|
|
|
|
|
// static functions for plugins
|
2016-01-28 09:40:08 +00:00
|
|
|
static uint32_t GetSetting(CSettings * _this, SettingID Type);
|
2018-03-28 08:28:02 +00:00
|
|
|
static const char * GetSettingSz(CSettings * _this, SettingID Type, char * Buffer, uint32_t BufferSize);
|
2016-08-07 08:27:14 +00:00
|
|
|
static void SetSetting(CSettings * _this, SettingID ID, uint32_t Value);
|
|
|
|
static void SetSettingSz(CSettings * _this, SettingID ID, const char * Value);
|
|
|
|
static void RegisterSetting(CSettings * _this, SettingID ID, SettingID DefaultID, SettingDataType DataType,
|
2018-03-28 08:28:02 +00:00
|
|
|
SettingType Type, const char * Category, const char * DefaultStr, uint32_t Value);
|
2016-08-07 08:27:14 +00:00
|
|
|
static uint32_t FindSetting(CSettings * _this, const char * Name);
|
|
|
|
static void FlushSettings(CSettings * _this);
|
|
|
|
static void sRegisterChangeCB(CSettings * _this, SettingID Type, void * Data, SettingChangedFunc Func);
|
|
|
|
static void sUnregisterChangeCB(CSettings * _this, SettingID Type, void * Data, SettingChangedFunc Func);
|
2016-01-28 09:40:08 +00:00
|
|
|
|
2016-02-01 06:31:33 +00:00
|
|
|
//Notification
|
|
|
|
void NotifyCallBacks(SettingID Type);
|
2016-04-13 07:34:19 +00:00
|
|
|
void AddHandler(SettingID TypeID, CSettingType * Handler);
|
2016-02-01 06:31:33 +00:00
|
|
|
|
2016-01-28 09:40:08 +00:00
|
|
|
private:
|
|
|
|
void AddHowToHandleSetting(const char * BaseDirectory);
|
|
|
|
void UnknownSetting(SettingID Type);
|
|
|
|
|
|
|
|
struct SETTING_CHANGED_CB
|
|
|
|
{
|
2018-03-28 08:28:02 +00:00
|
|
|
void * Data;
|
|
|
|
SettingChangedFunc Func;
|
2016-01-28 09:40:08 +00:00
|
|
|
SETTING_CHANGED_CB * Next;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::map<SettingID, SETTING_CHANGED_CB *> SETTING_CALLBACK;
|
|
|
|
typedef std::map<SettingID, CSettingType *> SETTING_MAP;
|
|
|
|
typedef SETTING_MAP::iterator SETTING_HANDLER;
|
2008-12-04 10:41:51 +00:00
|
|
|
|
2018-03-28 08:28:02 +00:00
|
|
|
SETTING_MAP m_SettingInfo;
|
2015-10-25 10:50:28 +00:00
|
|
|
SETTING_CALLBACK m_Callback;
|
2018-03-28 08:28:02 +00:00
|
|
|
uint32_t m_NextAutoSettingId;
|
2008-09-18 03:15:49 +00:00
|
|
|
};
|
|
|
|
|
2012-11-17 01:02:04 +00:00
|
|
|
extern CSettings * g_Settings;
|