Переглянути джерело

Merge branch 'master' of github.com:taylor001/crown

Daniele Bartolini 10 роки тому
батько
коміт
d65194a9bc

+ 4 - 4
src/core/containers/queue.h

@@ -129,14 +129,14 @@ namespace queue
 
 		q[q._size] = item;
 
-		q._size++;
+		++q._size;
 	}
 
 	template <typename T>
 	inline void pop_back(Queue<T>& q)
 	{
 		CE_ASSERT(q._size > 0, "The queue is empty");
-		q._size--;
+		--q._size;
 	}
 
 	template <typename T>
@@ -149,7 +149,7 @@ namespace queue
 
 		q[0] = item;
 
-		q._size++;
+		++q._size;
 	}
 
 	template <typename T>
@@ -158,7 +158,7 @@ namespace queue
 		CE_ASSERT(q._size > 0, "The queue is empty");
 
 		q._read = (q._read + 1) % array::size(q._queue);
-		q._size--;
+		--q._size;
 	}
 
 	template <typename T>

+ 6 - 6
src/core/containers/vector.h

@@ -124,14 +124,14 @@ namespace vector
 			v._capacity = capacity;
 			v._data = (T*)v._allocator->allocate(capacity * sizeof(T), CE_ALIGNOF(T));
 
-			for (uint32_t i = 0; i < v._size; i++)
+			for (uint32_t i = 0; i < v._size; ++i)
 			{
 				new (v._data + i) T(tmp[i]);
 			}
 
 			if (tmp)
 			{
-				for (uint32_t i = 0; i < v._size; i++)
+				for (uint32_t i = 0; i < v._size; ++i)
 				{
 					tmp[i].~T();
 				}
@@ -185,7 +185,7 @@ namespace vector
 			grow(v, v._size + count);
 
 		T* arr = &v._data[v._size];
-		for (uint32_t i = 0; i < count; i++)
+		for (uint32_t i = 0; i < count; ++i)
 			arr[i] = items[i];
 
 		v._size += count;
@@ -195,7 +195,7 @@ namespace vector
 	template <typename T>
 	inline void clear(Vector<T>& v)
 	{
-		for (uint32_t i = 0; i < v._size; i++)
+		for (uint32_t i = 0; i < v._size; ++i)
 			v._data[i].~T();
 
 		v._size = 0;
@@ -286,7 +286,7 @@ inline Vector<T>::Vector(const Vector<T>& other)
 template <typename T>
 inline Vector<T>::~Vector()
 {
-	for (uint32_t i = 0; i < _size; i++)
+	for (uint32_t i = 0; i < _size; ++i)
 		_data[i].~T();
 
 	if (_data)
@@ -313,7 +313,7 @@ inline const Vector<T>& Vector<T>::operator=(const Vector<T>& other)
 	const uint32_t size = vector::size(other);
 	vector::resize(*this, size);
 
-	for (uint32_t i = 0; i < size; i++)
+	for (uint32_t i = 0; i < size; ++i)
 		_data[i] = other._data[i];
 
 	return *this;

+ 1 - 1
src/core/memory/linear_allocator.cpp

@@ -31,7 +31,7 @@ LinearAllocator::~LinearAllocator()
 	if (_backing)
 		_backing->deallocate(_physical_start);
 
-	CE_ASSERT(_offset == 0, "Memory leak of %ld bytes, maybe you forgot to call clear()?", _offset);
+	CE_ASSERT(_offset == 0, "Memory leak of %d bytes, maybe you forgot to call clear()?", _offset);
 }
 
 void* LinearAllocator::allocate(uint32_t size, uint32_t align)

+ 5 - 2
src/core/memory/memory.cpp

@@ -49,8 +49,11 @@ namespace memory
 
 		~HeapAllocator()
 		{
-			CE_ASSERT(_allocation_count == 0 && total_allocated() == 0,
-				"Missing %d deallocations causing a leak of %ld bytes", _allocation_count, total_allocated());
+			CE_ASSERT(_allocation_count == 0 && total_allocated() == 0
+				, "Missing %d deallocations causing a leak of %d bytes"
+				, _allocation_count
+				, total_allocated()
+				);
 		}
 
 		/// @copydoc Allocator::allocate()

+ 5 - 2
src/core/memory/stack_allocator.cpp

@@ -19,8 +19,11 @@ StackAllocator::StackAllocator(void* start, uint32_t size)
 
 StackAllocator::~StackAllocator()
 {
-	CE_ASSERT(_allocation_count == 0 && total_allocated() == 0,
-		"Missing %d deallocations causing a leak of %ld bytes", _allocation_count, total_allocated());
+	CE_ASSERT(_allocation_count == 0 && total_allocated() == 0
+		, "Missing %d deallocations causing a leak of %d bytes"
+		, _allocation_count
+		, total_allocated()
+		);
 }
 
 void* StackAllocator::allocate(uint32_t size, uint32_t align)

+ 9 - 9
src/core/network/net_address.h

@@ -5,7 +5,6 @@
 
 #pragma once
 
-#include "config.h"
 #include "types.h"
 
 namespace crown
@@ -18,13 +17,13 @@ struct NetAddress
 {
 	/// Initializes the address to 127.0.0.1
 	NetAddress()
-		: m_addr(0)
+		: _addr(0)
 	{
 		set(127, 0, 0, 1);
 	}
 
 	NetAddress(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
-		: m_addr(0)
+		: _addr(0)
 	{
 		set(a, b, c, d);
 	}
@@ -32,18 +31,19 @@ struct NetAddress
 	/// Returns the IP address as packed 32-bit integer.
 	uint32_t address() const
 	{
-		return m_addr;
+		return _addr;
 	}
 
 	void set(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
 	{
-		m_addr = uint32_t(a) << 24
-			| uint32_t(b) << 16
-			| uint32_t(c) << 8
-			| uint32_t(d);
+		_addr = 0;
+		_addr |= uint32_t(a) << 24;
+		_addr |= uint32_t(b) << 16;
+		_addr |= uint32_t(c) << 8;
+		_addr |= uint32_t(d) << 0;
 	}
 
-	uint32_t m_addr;
+	uint32_t _addr;
 };
 
 } // namespace crown

+ 8 - 8
src/core/os.h

@@ -5,7 +5,7 @@
 
 #pragma once
 
-#include "config.h"
+#include "platform.h"
 #include "types.h"
 #include "vector.h"
 #include "dynamic_string.h"
@@ -14,14 +14,14 @@
 #include "temp_allocator.h"
 
 #if CROWN_PLATFORM_POSIX
-	#include <dirent.h>
-	#include <dlfcn.h>
-	#include <sys/stat.h>
-	#include <sys/time.h>
-	#include <sys/wait.h>
+	#include <dirent.h> // opendir, readdir
+	#include <dlfcn.h> // dlopen, dlclose, dlsym
+	#include <sys/stat.h> // lstat, mknod, mkdir
+	#include <sys/wait.h> // wait
 	#include <errno.h>
-	#include <time.h>
-	#include <unistd.h>
+	#include <time.h> // clock_gettime
+	#include <unistd.h> // access, unlink, rmdir, getcwd, fork, execv
+ 	#include <stdlib.h> // exit
 #elif CROWN_PLATFORM_WINDOWS
 	#include <win_headers.h>
 	#include <io.h>

+ 0 - 3
src/core/strings/dynamic_string.h

@@ -7,12 +7,9 @@
 
 #include "error.h"
 #include "memory.h"
-#include "string_utils.h"
 #include "array.h"
-#include "string_utils.h"
 #include "string_id.h"
 #include <string.h> // memmove
-#include <algorithm>
 
 namespace crown
 {

+ 0 - 1
src/core/strings/path.cpp

@@ -4,7 +4,6 @@
  */
 
 #include "path.h"
-#include "platform.h"
 #include <ctype.h> // isalpha
 #include <string.h> // strlen, strrchr
 

+ 1 - 2
src/core/strings/string_stream.h

@@ -7,7 +7,6 @@
 
 #include "array.h"
 #include "string_utils.h"
-#include <stdio.h>
 
 namespace crown
 {
@@ -104,7 +103,7 @@ namespace string_stream
 	inline StringStream& stream_printf(StringStream& s, const char* format, T& val)
 	{
 		char buf[32];
-		snprintf(buf, 32, format, val);
+		snprintf(buf, sizeof(buf), format, val);
 		return s << buf;
 	}
 } // namespace string_stream

+ 2 - 2
src/core/strings/string_utils.h

@@ -7,9 +7,9 @@
 
 #include "types.h"
 #include "error.h"
-#include "config.h"
+#include "platform.h"
 #include "macros.h"
-#include <stdio.h> // sscanf
+#include <stdio.h> // sscanf, vsnprintf
 #include <string.h>
 #include <stdarg.h>
 #include <ctype.h> // isspace

+ 1 - 1
src/core/thread/atomic_int.h

@@ -5,7 +5,7 @@
 
 #pragma once
 
-#include "config.h"
+#include "platform.h"
 
 #if CROWN_PLATFORM_WINDOWS
 	#include "types.h"

+ 1 - 1
src/core/thread/mutex.h

@@ -5,7 +5,7 @@
 
 #pragma once
 
-#include "config.h"
+#include "platform.h"
 #include "types.h"
 #include "error.h"
 #include "macros.h"

+ 1 - 1
src/core/thread/semaphore.h

@@ -5,7 +5,7 @@
 
 #pragma once
 
-#include "config.h"
+#include "platform.h"
 #include "error.h"
 #include "mutex.h"
 

+ 1 - 1
src/core/thread/thread.h

@@ -5,7 +5,7 @@
 
 #pragma once
 
-#include "config.h"
+#include "platform.h"
 #include "error.h"
 #include "types.h"
 #include "semaphore.h"

+ 1 - 0
src/resource/resource_loader.cpp

@@ -4,6 +4,7 @@
  */
 
 #include "resource_loader.h"
+#include "config.h"
 #include "memory.h"
 #include "resource_registry.h"
 #include "queue.h"

+ 1 - 0
src/resource/unit_resource.cpp

@@ -19,6 +19,7 @@
 #include "vector3.h"
 #include "camera.h"
 #include "unit_resource.h"
+#include <algorithm> // std::sort
 
 namespace crown
 {