Daniele Bartolini 13 лет назад
Родитель
Сommit
90244f76e1

+ 1 - 0
CMakeLists.txt

@@ -20,6 +20,7 @@ set (INCLUDES
 	${CMAKE_SOURCE_DIR}/src/core/streams
 	${CMAKE_SOURCE_DIR}/src/core/streams
 	${CMAKE_SOURCE_DIR}/src/core/strings
 	${CMAKE_SOURCE_DIR}/src/core/strings
 	${CMAKE_SOURCE_DIR}/src/core/threads
 	${CMAKE_SOURCE_DIR}/src/core/threads
+	${CMAKE_SOURCE_DIR}/src/core/settings
 	${CMAKE_SOURCE_DIR}/src/os
 	${CMAKE_SOURCE_DIR}/src/os
 	${CMAKE_SOURCE_DIR}/src/os/linux
 	${CMAKE_SOURCE_DIR}/src/os/linux
 	${CMAKE_SOURCE_DIR}/src/input
 	${CMAKE_SOURCE_DIR}/src/input

+ 12 - 1
src/CMakeLists.txt

@@ -178,6 +178,16 @@ set (THREADS_SRC
 	core/threads/Mutex.cpp
 	core/threads/Mutex.cpp
 )
 )
 
 
+set (SETTINGS_SRC
+	core/settings/IntSetting.cpp
+	core/settings/FloatSetting.cpp
+)
+
+set (SETTINGS_HEADERS
+	core/settings/IntSetting.h
+	core/settings/FloatSetting.h
+)
+
 set (INPUT_SRC
 set (INPUT_SRC
 	input/EventDispatcher.cpp
 	input/EventDispatcher.cpp
 	input/InputManager.cpp
 	input/InputManager.cpp
@@ -278,9 +288,10 @@ set (SOURCES
 	${MEM_HEADERS}
 	${MEM_HEADERS}
 	${COMPRESSORS_SRC}
 	${COMPRESSORS_SRC}
 	${COMPRESSORS_HEADERS}
 	${COMPRESSORS_HEADERS}
-
 	${THREADS_SRC}
 	${THREADS_SRC}
 	${THREADS_HEADERS}
 	${THREADS_HEADERS}
+	${SETTINGS_SRC}
+	${SETTINGS_HEADERS}
 
 
 	${INPUT_SRC}
 	${INPUT_SRC}
 	${INPUT_HEADERS}
 	${INPUT_HEADERS}

+ 4 - 0
src/Crown.h

@@ -87,6 +87,10 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Thread.h"
 #include "Thread.h"
 #include "Mutex.h"
 #include "Mutex.h"
 
 
+// Core/Settings
+#include "IntSetting.h"
+#include "FloatSetting.h"
+
 // Engine
 // Engine
 #include "Camera.h"
 #include "Camera.h"
 #include "Device.h"
 #include "Device.h"

+ 104 - 0
src/core/settings/FloatSetting.cpp

@@ -0,0 +1,104 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+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.
+*/
+
+#include "FloatSetting.h"
+
+namespace crown
+{
+
+FloatSetting* FloatSetting::g_float_settings_head = NULL;
+
+//-----------------------------------------------------------------------------
+FloatSetting::FloatSetting(const char* name, const char* synopsis, float value, float min, float max) :
+	m_name(name),
+	m_synopsis(synopsis),
+	m_value(0),
+	m_min(min),
+	m_max(max),
+	m_next(NULL)
+{
+	set_value(value);
+
+	if (FloatSetting::g_float_settings_head == NULL)
+	{
+		FloatSetting::g_float_settings_head = this;
+		m_next = NULL;
+	}
+	else
+	{
+		m_next = FloatSetting::g_float_settings_head;
+		FloatSetting::g_float_settings_head = this;
+	}
+}
+
+//-----------------------------------------------------------------------------
+const char* FloatSetting::name() const
+{
+	return m_name;
+}
+
+//-----------------------------------------------------------------------------
+const char* FloatSetting::synopsis() const
+{
+	return m_synopsis;
+}
+
+//-----------------------------------------------------------------------------
+float FloatSetting::value() const
+{
+	return m_value;
+}
+
+//-----------------------------------------------------------------------------
+float FloatSetting::min() const
+{
+	return m_min;
+}
+
+//-----------------------------------------------------------------------------
+float FloatSetting::max() const
+{
+	return m_max;
+}
+
+//-----------------------------------------------------------------------------
+void FloatSetting::set_value(float value)
+{
+	if (value > m_max)
+	{
+		m_value = m_max;
+	}
+	else if (value < m_min)
+	{
+		m_value = m_min;
+	}
+	else
+	{
+		m_value = value;
+	}
+}
+
+} // namespace crown
+

+ 64 - 0
src/core/settings/FloatSetting.h

@@ -0,0 +1,64 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+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.
+*/
+
+#pragma once
+
+#include "Types.h"
+
+namespace crown
+{
+
+class FloatSetting
+{
+public:
+
+						FloatSetting(const char* name, const char* synopsis, float value, float min, float max);
+
+	const char*			name() const;
+	const char*			synopsis() const;
+	float				value() const;
+	float				min() const;
+	float				max() const;
+
+	void				set_value(float value);
+
+private:
+
+	static FloatSetting*	g_float_settings_head;
+
+private:
+
+	const char*			m_name;
+	const char*			m_synopsis;
+
+	float				m_value;
+	float				m_min;
+	float				m_max;
+
+	FloatSetting*		m_next;
+};
+
+} // namespace crown
+

+ 104 - 0
src/core/settings/IntSetting.cpp

@@ -0,0 +1,104 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+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.
+*/
+
+#include "IntSetting.h"
+
+namespace crown
+{
+
+IntSetting* IntSetting::g_int_settings_head = NULL;
+
+//-----------------------------------------------------------------------------
+IntSetting::IntSetting(const char* name, const char* synopsis, int32_t value, int32_t min, int32_t max) :
+	m_name(name),
+	m_synopsis(synopsis),
+	m_value(0),
+	m_min(min),
+	m_max(max),
+	m_next(NULL)
+{
+	set_value(value);
+
+	if (IntSetting::g_int_settings_head == NULL)
+	{
+		IntSetting::g_int_settings_head = this;
+		m_next = NULL;
+	}
+	else
+	{
+		m_next = IntSetting::g_int_settings_head;
+		IntSetting::g_int_settings_head = this;
+	}
+}
+
+//-----------------------------------------------------------------------------
+const char* IntSetting::name() const
+{
+	return m_name;
+}
+
+//-----------------------------------------------------------------------------
+const char* IntSetting::synopsis() const
+{
+	return m_synopsis;
+}
+
+//-----------------------------------------------------------------------------
+int32_t IntSetting::value() const
+{
+	return m_value;
+}
+
+//-----------------------------------------------------------------------------
+int32_t IntSetting::min() const
+{
+	return m_min;
+}
+
+//-----------------------------------------------------------------------------
+int32_t IntSetting::max() const
+{
+	return m_max;
+}
+
+//-----------------------------------------------------------------------------
+void IntSetting::set_value(int32_t value)
+{
+	if (value > m_max)
+	{
+		m_value = m_max;
+	}
+	else if (value < m_min)
+	{
+		m_value = m_min;
+	}
+	else
+	{
+		m_value = value;
+	}
+}
+
+} // namespace crown
+

+ 64 - 0
src/core/settings/IntSetting.h

@@ -0,0 +1,64 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+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.
+*/
+
+#pragma once
+
+#include "Types.h"
+
+namespace crown
+{
+
+class IntSetting
+{
+public:
+
+						IntSetting(const char* name, const char* synopsis, int32_t value, int32_t min, int32_t max);
+
+	const char*			name() const;
+	const char*			synopsis() const;
+	int32_t				value() const;
+	int32_t				min() const;
+	int32_t				max() const;
+
+	void				set_value(int32_t value);
+
+private:
+
+	static IntSetting*	g_int_settings_head;
+
+private:
+
+	const char*			m_name;
+	const char*			m_synopsis;
+
+	int32_t				m_value;
+	int32_t				m_min;
+	int32_t				m_max;
+
+	IntSetting*			m_next;
+};
+
+} // namespace crown
+