Removed system.h and system.c (replaced by System class)

This commit is contained in:
Michaël Lemaire 2013-10-26 23:19:49 +02:00
parent cd37d45e98
commit ea25cdaa55
18 changed files with 77 additions and 104 deletions

View file

@ -9,7 +9,7 @@
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
#include "tools.h" #include "tools.h"
#include "rendering/system.h" #include "System.h"
/*************** PreviewChunk ***************/ /*************** PreviewChunk ***************/
class PreviewChunk class PreviewChunk
@ -168,7 +168,7 @@ void PreviewDrawingThread::run()
/*************** PreviewDrawingManager ***************/ /*************** PreviewDrawingManager ***************/
PreviewDrawingManager::PreviewDrawingManager() PreviewDrawingManager::PreviewDrawingManager()
{ {
_thread_count = systemGetCoreCount(); _thread_count = System::getCoreCount();
} }
void PreviewDrawingManager::startThreads() void PreviewDrawingManager::startThreads()

View file

@ -9,7 +9,7 @@
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "rendering/system.h" #include "System.h"
#include "rendering/tools.h" #include "rendering/tools.h"
#include "rendering/tools/cache.h" #include "rendering/tools/cache.h"
#include "rendering/tools/texture.h" #include "rendering/tools/texture.h"

View file

@ -5,7 +5,6 @@
#include <string.h> #include <string.h>
#include "../tools.h" #include "../tools.h"
#include "../renderer.h" #include "../renderer.h"
#include "../system.h"
static int _inited = 0; static int _inited = 0;

View file

@ -5,7 +5,6 @@
#include <string.h> #include <string.h>
#include "../tools.h" #include "../tools.h"
#include "../renderer.h" #include "../renderer.h"
#include "../system.h"
/******************** Fake ********************/ /******************** Fake ********************/
static AtmosphereResult _fakeApplyAerialPerspective(Renderer* renderer, Vector3 location, Color base) static AtmosphereResult _fakeApplyAerialPerspective(Renderer* renderer, Vector3 location, Color base)

View file

@ -2,7 +2,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "tools/data.h" #include "tools/data.h"
#include "system.h"
#include "scenery.h" #include "scenery.h"
#include "render.h" #include "render.h"
#include "main.h" #include "main.h"
@ -12,7 +11,6 @@
void paysagesInit() void paysagesInit()
{ {
systemInit();
if (!dataInit()) if (!dataInit())
{ {
/* TODO Add error callback (for interface) */ /* TODO Add error callback (for interface) */

View file

@ -6,10 +6,10 @@
#include "renderer.h" #include "renderer.h"
#include "camera.h" #include "camera.h"
#include "system.h"
#include "PictureFile.h" #include "PictureFile.h"
#include "Thread.h" #include "Thread.h"
#include "Mutex.h" #include "Mutex.h"
#include "System.h"
typedef struct typedef struct
{ {

View file

@ -1,11 +1,11 @@
#include "renderer.h" #include "renderer.h"
#include "tools/lighting.h" #include "tools/lighting.h"
#include "system.h" #include "System.h"
#include "Thread.h"
#include "render.h" #include "render.h"
#include "scenery.h" #include "scenery.h"
#include "tools.h" #include "tools.h"
#include "Thread.h"
static RayCastingResult _RAYCASTING_NULL = {0}; static RayCastingResult _RAYCASTING_NULL = {0};

View file

@ -12,7 +12,6 @@ INCLUDEPATH += $$PWD/..
SOURCES += main.c \ SOURCES += main.c \
tools.c \ tools.c \
system.c \
scenery.c \ scenery.c \
renderer.c \ renderer.c \
render.c \ render.c \
@ -69,7 +68,6 @@ SOURCES += main.c \
HEADERS += \ HEADERS += \
tools.h \ tools.h \
system.h \
scenery.h \ scenery.h \
renderer.h \ renderer.h \
render.h \ render.h \

View file

@ -6,7 +6,6 @@
#include "rendering/tools/color.h" #include "rendering/tools/color.h"
#include "rendering/tools/euclid.h" #include "rendering/tools/euclid.h"
#include "rendering/render.h" #include "rendering/render.h"
#include "rendering/system.h"
static AtmosphereDefinition* _atmosphere; static AtmosphereDefinition* _atmosphere;
static CameraDefinition* _camera; static CameraDefinition* _camera;

View file

@ -1,63 +0,0 @@
#include "system.h"
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#ifndef NDEBUG
#define DEBUG_ONETHREAD 1
#endif
#ifdef WIN32
#include <windows.h>
#endif
static int _core_count = 1;
static int _getCoreCount()
{
int core_count = 1;
#ifdef WIN32
DWORD processAffinityMask;
DWORD systemAffinityMask;
if (GetProcessAffinityMask( GetCurrentProcess(),
&processAffinityMask,
&systemAffinityMask)){
processAffinityMask = (processAffinityMask & 0x55555555)
+ (processAffinityMask >> 1 & 0x55555555);
processAffinityMask = (processAffinityMask & 0x33333333)
+ (processAffinityMask >> 2 & 0x33333333);
processAffinityMask = (processAffinityMask & 0x0f0f0f0f)
+ (processAffinityMask >> 4 & 0x0f0f0f0f);
processAffinityMask = (processAffinityMask & 0x00ff00ff)
+ (processAffinityMask >> 8 & 0x00ff00ff);
core_count = (processAffinityMask & 0x0000ffff)
+ (processAffinityMask >>16 & 0x0000ffff);
}
#endif
#ifdef _SC_NPROCESSORS_ONLN
core_count = (int)sysconf(_SC_NPROCESSORS_ONLN);
#endif
#ifdef DEBUG_ONETHREAD
core_count = 1;
#endif
return core_count;
}
void systemInit()
{
_core_count = _getCoreCount();
}
int systemGetCoreCount()
{
return _core_count;
}
int systemGetFileSize(const char* path)
{
struct stat st;
stat(path, &st);
return st.st_size;
}

View file

@ -1,22 +0,0 @@
#ifndef _PAYSAGES_SYSTEM_H_
#define _PAYSAGES_SYSTEM_H_
/* Library dependent features */
#include "rendering_global.h"
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
RENDERINGSHARED_EXPORT void systemInit();
RENDERINGSHARED_EXPORT int systemGetCoreCount();
RENDERINGSHARED_EXPORT int systemGetFileSize(const char* path);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -1,7 +1,8 @@
#include "parallel.h" #include "parallel.h"
#include <assert.h> #include <assert.h>
#include "../system.h" #include <stdlib.h>
#include "System.h"
#include "Thread.h" #include "Thread.h"
#include "Mutex.h" #include "Mutex.h"

View file

@ -2,7 +2,7 @@
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
#include "../system.h" #include "System.h"
#include "PictureFile.h" #include "PictureFile.h"
struct Texture2D struct Texture2D

27
src/system/System.cpp Normal file
View file

@ -0,0 +1,27 @@
#include "System.h"
#include <QThread>
#include <QDebug>
static int core_count = -1;
int System::getCoreCount()
{
if (core_count < 0)
{
core_count = QThread::idealThreadCount();
if (core_count <= 0)
{
qWarning() << "Can't find number of CPU cores, using only 1";
core_count = 1;
}
}
return core_count;
}
// Transitional C-API
int systemGetCoreCount()
{
return System::getCoreCount();
}

35
src/system/System.h Normal file
View file

@ -0,0 +1,35 @@
#ifndef SYSTEM_H
#define SYSTEM_H
#include "system_global.h"
#ifdef __cplusplus
namespace paysages
{
namespace system
{
/*!
* \brief Access to system info
*/
class SYSTEMSHARED_EXPORT System
{
public:
static int getCoreCount();
};
}
}
extern "C" {
#endif
// Transitional C-API
int systemGetCoreCount();
#ifdef __cplusplus
}
#endif
#endif // SYSTEM_H

View file

@ -15,13 +15,15 @@ CONFIG(release, debug|release): DEFINES += NDEBUG
SOURCES += \ SOURCES += \
PictureFile.cpp \ PictureFile.cpp \
Thread.cpp \ Thread.cpp \
Mutex.cpp Mutex.cpp \
System.cpp
HEADERS += \ HEADERS += \
system_global.h \ system_global.h \
PictureFile.h \ PictureFile.h \
Thread.h \ Thread.h \
Mutex.h Mutex.h \
System.h
unix:!symbian { unix:!symbian {
maemo5 { maemo5 {

View file

@ -2,7 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "rendering/main.h" #include "rendering/main.h"
#include "rendering/system.h" #include "System.h"
int tests_cpu_count; int tests_cpu_count;
extern void test_euclid_case(Suite* s); extern void test_euclid_case(Suite* s);

View file

@ -1,5 +1,5 @@
#include "testing/common.h" #include "testing/common.h"
#include "rendering/system.h" #include "System.h"
#include "rendering/scenery.h" #include "rendering/scenery.h"
#define OUTPUT_WIDTH 400 #define OUTPUT_WIDTH 400