forked from WG21-SG14/SG14
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from swardle/sg14-from-swardle-master-compare-v…
…table-function Add a C++ example of a entity inner loop
- Loading branch information
Showing
21 changed files
with
861 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.23107.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cpp_entity_example", "cpp_entity_example\cpp_entity_example.vcxproj", "{824B9034-F61C-4936-A66C-C0D27C9C2923}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{824B9034-F61C-4936-A66C-C0D27C9C2923}.Debug|x64.ActiveCfg = Debug|x64 | ||
{824B9034-F61C-4936-A66C-C0D27C9C2923}.Debug|x64.Build.0 = Debug|x64 | ||
{824B9034-F61C-4936-A66C-C0D27C9C2923}.Debug|x86.ActiveCfg = Debug|Win32 | ||
{824B9034-F61C-4936-A66C-C0D27C9C2923}.Debug|x86.Build.0 = Debug|Win32 | ||
{824B9034-F61C-4936-A66C-C0D27C9C2923}.Release|x64.ActiveCfg = Release|x64 | ||
{824B9034-F61C-4936-A66C-C0D27C9C2923}.Release|x64.Build.0 = Release|x64 | ||
{824B9034-F61C-4936-A66C-C0D27C9C2923}.Release|x86.ActiveCfg = Release|Win32 | ||
{824B9034-F61C-4936-A66C-C0D27C9C2923}.Release|x86.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
25 changes: 25 additions & 0 deletions
25
cpp_entity_example/cpp_entity_example/Debug/cpp_entity_example.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Build started 2015-09-26 4:02:44 PM. | ||
1>Project "C:\github\SG14\cpp_entity_example\cpp_entity_example\cpp_entity_example.vcxproj" on node 2 (Build target(s)). | ||
1>ClCompile: | ||
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /sdl /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Yu"stdafx.h" /Fp"Debug\cpp_entity_example.pch" /Fo"Debug\\" /Fd"Debug\vc140.pdb" /Gd /TP /analyze- /errorReport:prompt cpp_entity_example.cpp | ||
cpp_entity_example.cpp | ||
1>c:\github\sg14\cpp_entity_example\cpp_entity_example\cpp_entity_example.cpp(57): error C2065: 'default_random_engine': undeclared identifier | ||
1>c:\github\sg14\cpp_entity_example\cpp_entity_example\cpp_entity_example.cpp(57): error C2146: syntax error: missing ';' before identifier 'generator' | ||
1>c:\github\sg14\cpp_entity_example\cpp_entity_example\cpp_entity_example.cpp(57): error C2065: 'generator': undeclared identifier | ||
1>c:\github\sg14\cpp_entity_example\cpp_entity_example\cpp_entity_example.cpp(58): error C2065: 'uniform_real_distribution': undeclared identifier | ||
1>c:\github\sg14\cpp_entity_example\cpp_entity_example\cpp_entity_example.cpp(58): error C2062: type 'float' unexpected | ||
1>c:\github\sg14\cpp_entity_example\cpp_entity_example\cpp_entity_example.cpp(59): error C2065: 'unique_ptr': undeclared identifier | ||
1>c:\github\sg14\cpp_entity_example\cpp_entity_example\cpp_entity_example.cpp(59): error C2275: 'entity': illegal use of this type as an expression | ||
c:\github\sg14\cpp_entity_example\cpp_entity_example\cpp_entity_example.cpp(32): note: see declaration of 'entity' | ||
1>c:\github\sg14\cpp_entity_example\cpp_entity_example\cpp_entity_example.cpp(59): error C2974: 'std::vector': invalid template argument for '_Ty', type expected | ||
c:\program files (x86)\microsoft visual studio 14.0\vc\include\vector(678): note: see declaration of 'std::vector' | ||
c:\program files (x86)\microsoft visual studio 14.0\vc\include\vector(678): note: see declaration of 'std::vector' | ||
1>c:\github\sg14\cpp_entity_example\cpp_entity_example\cpp_entity_example.cpp(59): error C2143: syntax error: missing ';' before '>' | ||
1>c:\github\sg14\cpp_entity_example\cpp_entity_example\cpp_entity_example.cpp(59): error C2059: syntax error: '>' | ||
1>c:\github\sg14\cpp_entity_example\cpp_entity_example\cpp_entity_example.cpp(60): error C2065: 'entity_vec': undeclared identifier | ||
1>c:\github\sg14\cpp_entity_example\cpp_entity_example\cpp_entity_example.cpp(62): error C2059: syntax error: 'return' | ||
1>Done Building Project "C:\github\SG14\cpp_entity_example\cpp_entity_example\cpp_entity_example.vcxproj" (Build target(s)) -- FAILED. | ||
|
||
Build FAILED. | ||
|
||
Time Elapsed 00:00:00.22 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
======================================================================== | ||
CONSOLE APPLICATION : cpp_entity_example Project Overview | ||
======================================================================== | ||
|
||
AppWizard has created this cpp_entity_example application for you. | ||
|
||
This file contains a summary of what you will find in each of the files that | ||
make up your cpp_entity_example application. | ||
|
||
|
||
cpp_entity_example.vcxproj | ||
This is the main project file for VC++ projects generated using an Application Wizard. | ||
It contains information about the version of Visual C++ that generated the file, and | ||
information about the platforms, configurations, and project features selected with the | ||
Application Wizard. | ||
|
||
cpp_entity_example.vcxproj.filters | ||
This is the filters file for VC++ projects generated using an Application Wizard. | ||
It contains information about the association between the files in your project | ||
and the filters. This association is used in the IDE to show grouping of files with | ||
similar extensions under a specific node (for e.g. ".cpp" files are associated with the | ||
"Source Files" filter). | ||
|
||
cpp_entity_example.cpp | ||
This is the main application source file. | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
Other standard files: | ||
|
||
StdAfx.h, StdAfx.cpp | ||
These files are used to build a precompiled header (PCH) file | ||
named cpp_entity_example.pch and a precompiled types file named StdAfx.obj. | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
Other notes: | ||
|
||
AppWizard uses "TODO:" comments to indicate parts of the source code you | ||
should add to or customize. | ||
|
||
///////////////////////////////////////////////////////////////////////////// |
238 changes: 238 additions & 0 deletions
238
cpp_entity_example/cpp_entity_example/cpp_entity_example.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,238 @@ | ||
// cpp_entity_example.cpp : Defines the entry point for the console application. | ||
// | ||
|
||
#include "stdafx.h" | ||
#include "entity.h" | ||
#include "lerp.h" | ||
#include "hermite.h" | ||
|
||
#include <vector> | ||
#include <memory> | ||
#include <random> | ||
#include <iostream> | ||
#include <assert.h> | ||
#include <chrono> | ||
#include <ctime> | ||
#include <algorithm> | ||
using namespace std; | ||
|
||
#define ARRAY_SIZE(array) (sizeof((array))/sizeof((array[0]))) | ||
float dummyOut[100]; | ||
int dummyOutIndex = 0; | ||
vector<std::chrono::duration<double, std::ratio<1, 1000>>> gSlowSimpleUpdateExampleTimers; | ||
vector<std::chrono::duration<double, std::ratio<1, 1000>>> gSlowComplicatedUpdateExampleTimers; | ||
vector<std::chrono::duration<double, std::ratio<1, 1000>>> gFastUpdateExampleTimers; | ||
|
||
|
||
class mytimer | ||
{ | ||
public: | ||
std::chrono::time_point<std::chrono::high_resolution_clock> m_start; | ||
std::chrono::time_point<std::chrono::high_resolution_clock> m_end; | ||
mytimer() | ||
{ | ||
m_start = std::chrono::high_resolution_clock::now(); | ||
} | ||
std::chrono::duration<double> stop() | ||
{ | ||
m_end = std::chrono::high_resolution_clock::now(); | ||
return m_end - m_start; | ||
} | ||
}; | ||
|
||
|
||
void SlowUpdateExample() | ||
{ | ||
#ifdef PRINT | ||
cout << "SlowUpdateExample" << endl; | ||
#endif | ||
default_random_engine generator; | ||
uniform_real_distribution<float> distribution(0, 1); | ||
|
||
int number_of_lerp = 400; | ||
int number_of_hermite = 1000; | ||
vector<long long> create_types; | ||
for (int i = 0; i < number_of_lerp; i++) | ||
{ | ||
create_types.emplace_back(entity_lerp_slow::type); | ||
} | ||
for (int i = 0; i < number_of_hermite; i++) | ||
{ | ||
create_types.emplace_back(entity_hermite::type); | ||
} | ||
|
||
shuffle(create_types.begin(), create_types.end(), generator); | ||
|
||
vector<unique_ptr<entity>> entity_vec; | ||
for (auto &create_type : create_types) | ||
{ | ||
if (create_type == entity_hermite::type) | ||
{ | ||
unique_ptr<entity> a(create_entity_hermite(distribution(generator), distribution(generator), distribution(generator), distribution(generator))); | ||
entity_vec.emplace_back(std::move(a)); | ||
} | ||
else | ||
{ | ||
unique_ptr<entity> a(create_entity_lerp_slow(distribution(generator), distribution(generator))); | ||
entity_vec.emplace_back(std::move(a)); | ||
} | ||
} | ||
|
||
{ | ||
mytimer a; | ||
for (float t = 0.0f; t < 1.0; t += 0.05f) | ||
{ | ||
for (auto &a : entity_vec) | ||
{ | ||
a->Update(t); | ||
#ifdef PRINT | ||
cout << endl; | ||
#endif | ||
} | ||
} | ||
gSlowSimpleUpdateExampleTimers.emplace_back(a.stop()); | ||
} | ||
} | ||
|
||
void SlowComplicatedUpdateExample() | ||
{ | ||
#ifdef PRINT | ||
cout << "SlowComplicatedUpdateExample" << endl; | ||
#endif | ||
default_random_engine generator; | ||
uniform_real_distribution<float> distribution(0, 1); | ||
|
||
int number_of_lerp = 400; | ||
int number_of_hermite = 1000; | ||
vector<long long> create_types; | ||
for (int i = 0; i < number_of_lerp; i++) | ||
{ | ||
create_types.emplace_back(entity_lerp_fast::type); | ||
} | ||
for (int i = 0; i < number_of_hermite; i++) | ||
{ | ||
create_types.emplace_back(entity_hermite::type); | ||
} | ||
|
||
shuffle(create_types.begin(), create_types.end(), generator); | ||
|
||
vector<unique_ptr<entity>> entity_vec; | ||
for (auto &create_type : create_types) | ||
{ | ||
if (create_type == entity_hermite::type) | ||
{ | ||
unique_ptr<entity> a(create_entity_hermite(distribution(generator), distribution(generator), distribution(generator), distribution(generator))); | ||
entity_vec.emplace_back(std::move(a)); | ||
} | ||
else | ||
{ | ||
unique_ptr<entity> a(create_entity_lerp_fast(distribution(generator), distribution(generator))); | ||
entity_vec.emplace_back(std::move(a)); | ||
} | ||
} | ||
|
||
|
||
{ | ||
mytimer a; | ||
for (float t = 0.0f; t < 1.0; t += 0.05f) | ||
{ | ||
for (auto &a : entity_vec) | ||
{ | ||
if (a->GetType() != entity_lerp_fast::type) | ||
{ | ||
a->Update(t); | ||
#ifdef PRINT | ||
cout << endl; | ||
#endif | ||
} | ||
} | ||
entity_lerp_fast::UpdateAll(t); | ||
} | ||
gSlowComplicatedUpdateExampleTimers.emplace_back(a.stop()); | ||
} | ||
} | ||
|
||
void FastUpdateExampleTimers() | ||
{ | ||
#ifdef PRINT | ||
cout << "FastUpdateExampleTimers" << endl; | ||
#endif | ||
default_random_engine generator; | ||
uniform_real_distribution<float> distribution(0, 1); | ||
|
||
int number_of_lerp = 400; | ||
int number_of_hermite = 1000; | ||
vector<long long> create_types; | ||
for (int i = 0; i < number_of_lerp; i++) | ||
{ | ||
create_types.emplace_back(entity_lerp_fast::type); | ||
} | ||
for (int i = 0; i < number_of_hermite; i++) | ||
{ | ||
create_types.emplace_back(entity_hermite::type); | ||
} | ||
|
||
shuffle(create_types.begin(), create_types.end(), generator); | ||
|
||
vector<unique_ptr<entity>> entity_vec; | ||
for (auto &create_type : create_types) | ||
{ | ||
if (create_type == entity_hermite::type) | ||
{ | ||
unique_ptr<entity> a(create_entity_hermite(distribution(generator), distribution(generator), distribution(generator), distribution(generator))); | ||
entity_vec.emplace_back(std::move(a)); | ||
} | ||
else | ||
{ | ||
unique_ptr<entity> a(create_entity_lerp_fast(distribution(generator), distribution(generator))); | ||
entity_vec.emplace_back(std::move(a)); | ||
} | ||
} | ||
|
||
|
||
{ | ||
mytimer a; | ||
for (float t = 0.0f; t < 1.0; t += 0.05f) | ||
{ | ||
for (auto &a : entity_vec) | ||
{ | ||
if (*a->m_typedata != entity_lerp_fast::type) | ||
{ | ||
a->Update(t); | ||
#ifdef PRINT | ||
cout << endl; | ||
#endif | ||
} | ||
} | ||
entity_lerp_fast::UpdateAll(t); | ||
} | ||
gFastUpdateExampleTimers.emplace_back(a.stop()); | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
SlowUpdateExample(); | ||
SlowComplicatedUpdateExample(); | ||
FastUpdateExampleTimers(); | ||
|
||
for (auto a : dummyOut) | ||
{ | ||
cout << "dummyOut " << a << endl; | ||
} | ||
|
||
for (auto & t : gSlowSimpleUpdateExampleTimers) | ||
{ | ||
cout << "gSlowUpdateExample ms " << t.count() << endl; | ||
} | ||
for (auto & t : gSlowComplicatedUpdateExampleTimers) | ||
{ | ||
cout << "gSlowComplicatedUpdateExampleTimers ms " << t.count() << endl; | ||
} | ||
for (auto & t : gFastUpdateExampleTimers) | ||
{ | ||
cout << "gFastUpdateExampleTimers ms " << t.count() << endl; | ||
} | ||
return 0; | ||
} | ||
|
Oops, something went wrong.