Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Commit

Permalink
bugfixes + a new MainLoop example
Browse files Browse the repository at this point in the history
  • Loading branch information
aidinabedi committed Dec 13, 2009
1 parent 90430aa commit 0cfb423
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 19 deletions.
199 changes: 199 additions & 0 deletions Samples/MainLoop/Demo_MainLoop.vcproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="Demo_MainLoop"
ProjectGUID="{23595110-7DBF-45AE-95B6-A1A888AED9BF}"
RootNamespace="Demo_Simple"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="../../bin/$(ConfigurationName)"
IntermediateDirectory="../../obj/$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="Shiny.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="../../lib/$(ConfigurationName)"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="../../bin/$(ConfigurationName)"
IntermediateDirectory="../../obj/$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="Shiny.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="../../lib/$(ConfigurationName)"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\MainLoop.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
101 changes: 101 additions & 0 deletions Samples/MainLoop/MainLoop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
The zlib/libpng License
Copyright (c) 2007 Aidin Abedi (http:https://sourceforge.net/projects/shinyprofiler)
This software is provided 'as-is', without any express or implied warranty. In no event will
the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented; you must not claim that
you wrote the original software. If you use this software in a product,
an acknowledgment in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

#include "Shiny.h"

#ifdef _WIN32
#include <windows.h>
#else // assume POSIX
#include <unistd.h>
#endif


//-----------------------------------------------------------------------------

void millisleep(unsigned int milliseconds) {
#ifdef _WIN32
Sleep(milliseconds);
#else
usleep(milliseconds * 1000);
#endif
}


//-----------------------------------------------------------------------------

PROFILE_SHARED_DEFINE(Physics);

void DoPhysicsSimulation() {
PROFILE_SHARED_BLOCK(Physics);
}

void CheckPhysicsRaycast() {
PROFILE_SHARED_BEGIN(Physics);
PROFILE_END();
}

//-----------------------------------------------------------------------------

void UpdateAllCharacters() {
PROFILE_BEGIN(Gamelogic);

PROFILE_BEGIN(AI);
CheckPhysicsRaycast();
PROFILE_END();

PROFILE_BEGIN(Player);
PROFILE_END();

PROFILE_END();
}


//-----------------------------------------------------------------------------

void DrawWorldObjects() {
for (int i = 0; i < 10; i++) {
PROFILE_BLOCK(Graphics);
}
}


//-----------------------------------------------------------------------------


int main() {
int loops = 100;

while (loops--) {
UpdateAllCharacters();
DoPhysicsSimulation();
DrawWorldObjects();
}

PROFILE_UPDATE(); // update all profiles
PROFILE_OUTPUT(stdout); // print to cout

#ifdef _WIN32
system("pause");
#endif
return 0;
}
5 changes: 2 additions & 3 deletions Samples/Recursion/Recursion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ applications, and to alter it and redistribute it freely, subject to the followi
#include <unistd.h>
#endif

#include <iostream>
using namespace std;


//-----------------------------------------------------------------------------

Expand All @@ -49,6 +46,8 @@ void millisleep(unsigned int milliseconds) {
void Recursion(int calls_left) {
PROFILE_FUNC(); // begin profile until end of block

millisleep(20);

if (calls_left > 0) Recursion(calls_left - 1);
}

Expand Down
20 changes: 15 additions & 5 deletions Samples/Simple/Simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ applications, and to alter it and redistribute it freely, subject to the followi
#include <unistd.h>
#endif

#include <iostream>
using namespace std;


//-----------------------------------------------------------------------------

Expand All @@ -46,18 +43,31 @@ void millisleep(unsigned int milliseconds) {

//-----------------------------------------------------------------------------

void ProfileMe(void) {
void LazyHelloWorld(void) {
PROFILE_FUNC(); // begin profile until end of block

millisleep(100);
}


//-----------------------------------------------------------------------------

void HelloWorld(void) {
PROFILE_BEGIN(Hello_world_This_is_Shiny);

millisleep(100);

PROFILE_END();
}


//-----------------------------------------------------------------------------

int main() {

ProfileMe();
HelloWorld();

LazyHelloWorld();

PROFILE_UPDATE(); // update all profiles
PROFILE_OUTPUT(stdout); // print to cout
Expand Down
6 changes: 6 additions & 0 deletions Shiny.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo_Recursion", "Samples\R
{D44CCFEB-7FC2-46E6-8290-E0B00D06A636} = {D44CCFEB-7FC2-46E6-8290-E0B00D06A636}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo_MainLoop", "Samples\MainLoop\Demo_MainLoop.vcproj", "{23595110-7DBF-45AE-95B6-A1A888AED9BF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Expand All @@ -31,6 +33,10 @@ Global
{D0EB96F2-10EC-4DCC-AC4F-93E20D2717AC}.Debug|Win32.Build.0 = Debug|Win32
{D0EB96F2-10EC-4DCC-AC4F-93E20D2717AC}.Release|Win32.ActiveCfg = Release|Win32
{D0EB96F2-10EC-4DCC-AC4F-93E20D2717AC}.Release|Win32.Build.0 = Release|Win32
{23595110-7DBF-45AE-95B6-A1A888AED9BF}.Debug|Win32.ActiveCfg = Debug|Win32
{23595110-7DBF-45AE-95B6-A1A888AED9BF}.Debug|Win32.Build.0 = Debug|Win32
{23595110-7DBF-45AE-95B6-A1A888AED9BF}.Release|Win32.ActiveCfg = Release|Win32
{23595110-7DBF-45AE-95B6-A1A888AED9BF}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading

0 comments on commit 0cfb423

Please sign in to comment.