...
 
Commits (2)
cmake_minimum_required(VERSION 3.6.2)
project(DuodimEngine)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++17")
include_directories("${PROJECT_SOURCE_DIR}")
project(DuodimEngine VERSION 1.0
DESCRIPTION "2D physics engine implementation for the 2019/2020 course \"Computer science basics for visual computing\", made by Leon Willens"
LANGUAGES CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I")
set(CXX_STANDARD 17)
add_subdirectory(engine)
add_subdirectory(demo)
\ No newline at end of file
cmake_minimum_required(VERSION 3.6.2)
project(DuodimDemo_Demo)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++17")
file(GLOB SRC ${PROJECT_SOURCE_DIR}/src/*.cpp)
link_directories("../engine/build")
include_directories(include)
include_directories("../engine/include")
include_directories("../glut/include")
add_executable(${PROJECT_NAME} ${SRC})
target_link_libraries(${PROJECT_NAME} duodim_engine glut32.dll)
\ No newline at end of file
project(DuodimDemo_DemoExec VERSION 1.0
DESCRIPTION "Executable demonstration of the 2D physics engine."
LANGUAGES CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I")
set(CXX_STANDARD 17)
add_executable(demo "./src/main.cpp")
target_link_libraries(demo duodim_engine glut32.dll)
\ No newline at end of file
cmake_minimum_required(VERSION 3.6.2)
project(DuodimDemo_Engine)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++17")
include_directories(include)
project(DuodimDemo_Engine VERSION 1.0
DESCRIPTION "2D physics engine core"
LANGUAGES CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I")
set(CXX_STANDARD 17)
file(GLOB SRC "src/*.cpp")
add_library(duodim_engine SHARED ${SRC})
\ No newline at end of file
file(GLOB INCLUDE "include/*.hpp")
add_library(engine STATIC ${SRC})
target_link_directories(engine PUBLIC ${INCLUDE})
target_link_libraries(engine PUBLIC "../glut/build/glut32.dll")
target_compile_features(engine PUBLIC cxx_std_17)
\ No newline at end of file
#ifndef INCLUDE_ENGINE_H
#define INCLUDE_ENGINE_H
#include <optional>
#ifndef WIN32
#include <chrono>
#endif
using namespace std;
using namespace chrono;
namespace duodim
{
class Engine
......@@ -23,15 +21,9 @@ namespace duodim
void iterate();
void toggleFrameStepping();
#ifdef WIN32
float getElapsedTime();
float getTimeDifference();
LONGLONG getCurrentTime();
#else
long long getElapsedTime();
long long getTimeDifference();
long long getCurrentTime();
#endif
private:
static Engine* _instance;
Engine() {} // prevent instantiation from outside
......@@ -47,15 +39,9 @@ namespace duodim
double accumulator = 0;
bool running = false;
#ifdef WIN32
LARGE_INTEGER mFreq;
LARGE_INTEGER mStart, mStop, mCurrent;
void query(LARGE_INTEGER& q);
#else
chrono::high_resolution_clock::time_point mStart;
chrono::high_resolution_clock::time_point mStop;
chrono::high_resolution_clock::time_point mCurrent;
#endif
high_resolution_clock::time_point mStart;
high_resolution_clock::time_point mStop;
high_resolution_clock::time_point mCurrent;
};
Engine* Engine::_instance = 0;
}
......
......@@ -15,15 +15,8 @@ Engine* Engine::getInstance()
_instance->fps = 75.f;
_instance->dt = 1 / fps;
#ifdef WIN32
SetThreadAffinityMask(GetCurrentThread(), 1);
_Query_perf_frequency(_instance->mFreq);
_Query_perf_counter(_instance->mStart);
_Query_perf_counter(_instance->mStop);
#else
_instance->mStart = high_resolution_clock::now();
_instance->mStop = high_resolution_clock::now();
#endif
Scene::getInstance(); // Fire up Scene instance along with Engine
}
return _instance;
......@@ -31,14 +24,8 @@ Engine* Engine::getInstance()
void Engine::iterate()
{
#ifdef WIN32
accumulator += getElapsedTime();
_Query_perf_counter(&mStart);
#else
accumulator += (getElapsedTime() / static_cast<double>(duration_cast<nanoseconds>(seconds(1)).count()));
mStart = high_resolution_clock::now();
#endif
accumulator += (getElapsedTime() / static_cast<double>(duration_cast<nanoseconds>(seconds(1)).count()));
accumulator = clamp(0., .1, accumulator);
Scene* scene = Scene::getInstance();
......@@ -58,34 +45,10 @@ void Engine::iterate()
}
accumulator -= dt;
}
#ifdef WIN32
_Query_perf_counter(&mStop);
#else
mStop = high_resolution_clock::now();
#endif
scene->render();
}
#ifdef WIN32
float Engine::getElapsedTime()
{
_Query_perf_counter(&mCurrent);
return (mCurrent.QuadPart - mStart.QuadPart) / (float) mFreq.QuadPart;
}
float Engine::getTimeDifference()
{
return (mStop.QuadPart - mStart.QuadPart) / (float) mFreq.QuadPart;
}
LONGLONG Engine::getCurrentTime()
{
_Query_perf_counter(&mCurrent);
return mCurrent.QuadPart;
}
#else
long long Engine::getElapsedTime()
{
mCurrent = high_resolution_clock::now();
......@@ -102,7 +65,6 @@ long long Engine::getCurrentTime()
mCurrent = high_resolution_clock::now();
return duration_cast<nanoseconds>(mCurrent.time_since_epoch()).count();
}
#endif
void Engine::toggleFrameStepping()
{
......