Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*
   Copyright (c) 2014 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy of this software
   and associated documentation files (the "Software"), to deal in the Software without restriction,
   including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

#ifndef _PARAM_HANDLER_H_
#define _PARAM_HANDLER_H_

#include "Console.h"
#include "cdigginsAny.h"
#include "Utility/Headers/HashMap.h"
#include "Utility/Headers/Localization.h"
#include "Hardware/Platform/Headers/SharedMutex.h"
#include "Hardware/Platform/Headers/PlatformDefines.h"

namespace Divide {

DEFINE_SINGLETON (ParamHandler)
typedef hashMapImpl<stringImpl, cdiggins::any> ParamMap;
/// A special map for string types (small perf. optimization for add/retrieve)
typedef hashMapImpl<stringImpl, stringImpl > ParamStringMap;
/// A special map for boolean types (small perf. optimization for add/retrieve) 
/// Used a lot as option toggles
typedef hashMapImpl<stringImpl, bool > ParamBoolMap;

public:
	inline void setDebugOutput(bool logState) {
		_logState = logState;
	}

	template<typename T>
	inline T getParam(const stringImpl& name, T defaultValue = T()) const {
		ReadLock r_lock(_mutex);
		ParamMap::const_iterator it = _params.find(name);
		if(it != _params.end()) {
            bool success = false;
		    const T& ret = it->second.constant_cast<T>(success);
#           ifdef _DEBUG		
		        if (!success) {
			        ERROR_FN(Locale::get("ERROR_PARAM_CAST"),name.c_str());
					DIVIDE_ASSERT(success, 
                                  "ParamHandler error: Can't cast requested param to specified type!");
		        } 
#           endif

		    return ret;
		} 
		
		ERROR_FN(Locale::get("ERROR_PARAM_GET"), name.c_str());
	    return defaultValue; //integers will be 0, string will be empty, etc;
	}

    template<typename T>
	void setParam(const stringImpl& name, const T& value) {
		WriteLock w_lock(_mutex);
		ParamMap::iterator it = _params.find(name); 
        if (it == _params.end()) {
			DIVIDE_ASSERT(emplace(_params, name, cdiggins::any(value)).second,
                          "ParamHandler error: can't add specified value to map!");
        } else {
			it->second = cdiggins::any(value);
        }
	}

	template<typename T>
	inline void delParam(const stringImpl& name) {
		if (isParam(name)) {
			WriteLock w_lock(_mutex);
			_params.erase(name);
			if (_logState) {
                PRINT_FN(Locale::get("PARAM_REMOVE"), name.c_str());
            }
		} else {
			ERROR_FN(Locale::get("ERROR_PARAM_REMOVE"),name.c_str());
		}
	}

	template<typename T>
	inline bool isParam(const stringImpl& param) const {
		ReadLock r_lock(_mutex);
		return _params.find(param) != _params.end();
	}

	template<>
	inline stringImpl getParam(const stringImpl& name, stringImpl defaultValue) const {
		ReadLock r_lock(_mutex);
		ParamStringMap::const_iterator it = _paramsStr.find(name);
		if (it != _paramsStr.end()) {
			return it->second;
		}

		ERROR_FN(Locale::get("ERROR_PARAM_GET"), name.c_str());
		return defaultValue;
	}

	template<>
	void setParam(const stringImpl& name, const stringImpl& value) {
		WriteLock w_lock(_mutex);
		ParamStringMap::iterator it = _paramsStr.find(name);
		if (it == _paramsStr.end()) {
			DIVIDE_ASSERT(emplace(_paramsStr, name, value).second, 
                          "ParamHandler error: can't add specified value to map!");
		} else {
			it->second = value;
		}
	}

#if defined(STRING_IMP) && STRING_IMP != 1
	template<>
	inline std::string getParam(const stringImpl& name, std::string defaultValue) const {
		return stringAlg::fromBase(getParam<stringImpl>(name, stringAlg::toBase(defaultValue)));
	}

	template<>
	inline void setParam(const stringImpl& name, const std::string& value) {
		setParam(name, stringImpl(value.c_str()));
	}
	
	template<>
	inline void delParam<std::string>(const stringImpl& name) {
		delParam<stringImpl>(name);
	}
#endif

	template<>
	inline void delParam<stringImpl>(const stringImpl& name) {
		if (isParam<stringImpl>(name)) {
			WriteLock w_lock(_mutex);
			_paramsStr.erase(name);
			if (_logState) {
				PRINT_FN(Locale::get("PARAM_REMOVE"), name.c_str());
			}
		} else {
			ERROR_FN(Locale::get("ERROR_PARAM_REMOVE"), name.c_str());
		}
	}

	template<>
	inline bool isParam<stringImpl>(const stringImpl& param) const {
		ReadLock r_lock(_mutex);
		return _paramsStr.find(param) != _paramsStr.end();
	}

	template<>
	inline bool getParam(const stringImpl& name, bool defaultValue) const {
		ReadLock r_lock(_mutex);
		ParamBoolMap::const_iterator it = _paramBool.find(name);
		if (it != _paramBool.end()) {
			return it->second;
		}

		ERROR_FN(Locale::get("ERROR_PARAM_GET"), name.c_str());
		return defaultValue;
	}

	template<>
	void setParam(const stringImpl& name, const bool& value) {
		WriteLock w_lock(_mutex);
		ParamBoolMap::iterator it = _paramBool.find(name);
		if (it == _paramBool.end()) {
			DIVIDE_ASSERT(emplace(_paramBool, name, value).second,
                          "ParamHandler error: can't add specified value to map!");
		} else {
			it->second = value;
		}
	}

	template<>
	inline void delParam<bool>(const stringImpl& name) {
		if (isParam<stringImpl>(name)) {
			WriteLock w_lock(_mutex);
			_paramBool.erase(name);
			if (_logState) {
				PRINT_FN(Locale::get("PARAM_REMOVE"), name.c_str());
			}
		} else {
			ERROR_FN(Locale::get("ERROR_PARAM_REMOVE"), name.c_str());
		}
	}

	template<>
	inline bool isParam<bool>(const stringImpl& param) const {
		ReadLock r_lock(_mutex);
		return _paramBool.find(param) != _paramBool.end();
	}

protected:
	ParamHandler()
	{
	}

	~ParamHandler()
	{
		_params.clear();
		_paramBool.clear();
		_paramsStr.clear();
	}
private:
	ParamMap _params;
	ParamBoolMap _paramBool;
	ParamStringMap _paramsStr;
	mutable SharedLock _mutex;
	std::atomic_bool _logState;

END_SINGLETON

}; //namespace Divide

#endif

Commits for Divide-Framework/trunk/Source Code/Core/Headers/ParamHandler.h

Diff revisions: vs.
Revision Author Commited Message
331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

326 Diff Diff IonutCava picture IonutCava Tue 30 Sep, 2014 21:11:32 +0000

[Ionut]
- Fixed more memory leaks
- Simplified Task interface and timing System
- Improved compatibility between Boost, STL and EASTL with random combinations of vectors, strings and maps
- Simplified Light class by removing the “slot” member
- Random optimizations

323 Diff Diff IonutCava picture IonutCava Thu 11 Sep, 2014 20:58:50 +0000

[Ionut]
- Reworked GFXDevice API initialization system
- Added a separate map for boolean values in ParamHandler
- More cleanups in GFXDevice class
- Fixed an infinite loop issue in Task class

322 Diff Diff IonutCava picture IonutCava Sat 06 Sep, 2014 20:33:47 +0000

[Ionut]
- Refactored most of Boost related code to be C++11 based
— Boost is only used for ThreadPool, Mutex handling, XML parsing and networking (ASIO)
— Function binds, threads, regex, NonCopyable base, Hashing algorithms and more are now using C++11 libraries
- Replaced all FOR_EACH calls with standard, range, “for” calls

321 Diff Diff IonutCava picture IonutCava Wed 03 Sep, 2014 22:05:15 +0000

[Ionut]
- Added support (and enabled by default) for the EASTL library (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html / https://github.com/paulhodge/EASTL)
— Strings, vectors and hash_maps can be combined from EASTL, STL and Boost (not all combinations work. e.g. EASTL strings with STL/Boost containers due to the lack of a proper hash function)

319 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 21:37:57 +0000

[Ionut]
- Performance tweaks based on profiling data

318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

251 Diff Diff k1ngp1n picture k1ngp1n Wed 02 Apr, 2014 20:38:18 +0000

[Ionut] [[BR]]

  • Divide is now a 64bit statically linked application * [[BR]]

- Updated to a Visual Studio 2013 solution for better C++11 support [[BR]]
— Recompiled all projects with platform toolset v120 [[BR]]
- Recompiled all projects as x64 – MT / MTd (from x86 – MD / MDd) [[BR]]
- Updated PhysX to 3.3 [[BR]]
- Updated GLFW to 3.0.4 [[BR]]

221 Diff Diff k1ngp1n picture k1ngp1n Wed 08 Jan, 2014 18:50:02 +0000

[Ionut] [[BR]]
- Merged branch “Shadows And Animations” back into trunk [[BR]]
- Added DoxygenGUI project file [[BR]]

  • Buggy *
170 k1ngp1n picture k1ngp1n Sun 03 Nov, 2013 17:24:57 +0000

-Moved hardware related code to a separate project [[BR]]
-More work on post-processing: [[BR]]
— HDR rendering is working, but final tonemapping needs more work [[BR]]
-Important changes in BloomPreRenderOperator.cpp, PostFX.cpp and glFrameBufferObject.cpp [[BR]]
-Trailing and leading whitespace cleanups [[BR]]