Initial commit.
This commit is contained in:
83
samples/Sample_Tests/Main.cpp
Normal file
83
samples/Sample_Tests/Main.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include "Task.h"
|
||||
#include "TimeSystem.h"
|
||||
#include "TaskFSM.h"
|
||||
|
||||
// User-defined GetGlobalTime() is required to link Task.h
|
||||
NAMESPACE_SQUID_BEGIN
|
||||
tTaskTime GetGlobalTime()
|
||||
{
|
||||
return (tTaskTime)TimeSystem::GetTime();
|
||||
}
|
||||
NAMESPACE_SQUID_END
|
||||
|
||||
Task<> IdleTask()
|
||||
{
|
||||
TASK_NAME(__FUNCTION__);
|
||||
|
||||
printf("Idle task\n");
|
||||
co_await WaitForever();
|
||||
}
|
||||
|
||||
Task<> PeriodicTask(float in_duration)
|
||||
{
|
||||
TASK_NAME(__FUNCTION__);
|
||||
printf("Periodic task\n");
|
||||
co_await WaitSeconds(in_duration);
|
||||
}
|
||||
|
||||
Task<> TestFsmTask()
|
||||
{
|
||||
TASK_NAME(__FUNCTION__);
|
||||
TaskFSM fsm;
|
||||
|
||||
auto LambdaStateTask = [](float in_duration) -> Task<>
|
||||
{
|
||||
TASK_NAME(__FUNCTION__);
|
||||
printf("Lambda state!\n");
|
||||
|
||||
auto stopCtx = co_await GetStopContext();
|
||||
co_await WaitSeconds(in_duration).CancelIf([&] { return stopCtx.IsStopRequested(); });
|
||||
};
|
||||
|
||||
auto idleState = fsm.State("Idle", IdleTask);
|
||||
auto periodicState = fsm.State("Periodic", &PeriodicTask);
|
||||
auto lambdaState = fsm.State("Lambda", LambdaStateTask);
|
||||
auto endState = fsm.State("End");
|
||||
|
||||
fsm.EntryLinks({
|
||||
idleState.Link(),
|
||||
});
|
||||
fsm.StateLinks(idleState, {
|
||||
periodicState.Link([]() -> std::optional<float> { return 1.0f; }),
|
||||
endState.OnCompleteLink(),
|
||||
});
|
||||
fsm.StateLinks(periodicState, {
|
||||
lambdaState.Link([]() -> std::optional<float> { return 2.0f; }),
|
||||
});
|
||||
fsm.StateLinks(lambdaState, {
|
||||
idleState.OnCompleteLink(),
|
||||
});
|
||||
|
||||
auto fsmTask = fsm.Run();
|
||||
fsmTask.RequestStop();
|
||||
co_await std::move(fsmTask);
|
||||
}
|
||||
|
||||
void TestTaskFSM()
|
||||
{
|
||||
auto task = TestFsmTask();
|
||||
while(task.Resume() != eTaskStatus::Done)
|
||||
{
|
||||
TimeSystem::UpdateTime(); // Update time before each frame (logically, all tasks should resume "at the same time")
|
||||
}
|
||||
}
|
||||
|
||||
// Simple main function
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TimeSystem::Create();
|
||||
|
||||
TestTaskFSM();
|
||||
|
||||
return 0;
|
||||
}
|
||||
172
samples/Sample_Tests/Sample_Tests.vcxproj
Normal file
172
samples/Sample_Tests/Sample_Tests.vcxproj
Normal file
@@ -0,0 +1,172 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\include\FunctionGuard.h" />
|
||||
<ClInclude Include="..\..\include\Private\TasksCommonPrivate.h" />
|
||||
<ClInclude Include="..\..\include\Private\TaskFSMPrivate.h" />
|
||||
<ClInclude Include="..\..\include\Private\TaskPrivate.h" />
|
||||
<ClInclude Include="..\..\include\Task.h" />
|
||||
<ClInclude Include="..\..\include\TaskFSM.h" />
|
||||
<ClInclude Include="..\..\include\TaskManager.h" />
|
||||
<ClInclude Include="..\..\include\TasksConfig.h" />
|
||||
<ClInclude Include="..\..\include\TokenList.h" />
|
||||
<ClInclude Include="..\Common\TimeSystem.h" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{ABA88D0D-D79F-4371-BA63-D441662242B4}</ProjectGuid>
|
||||
<RootNamespace>Sample_Tests</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
<ProjectName>Sample_Tests</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);SQUIDTASK_TIME_PRECISION_DOUBLE</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>Default</LanguageStandard>
|
||||
<AdditionalOptions>/await -Xclang -fcoroutines-ts %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalIncludeDirectories>../../include;../Common</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);SQUIDTASK_TIME_PRECISION_DOUBLE</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>Default</LanguageStandard>
|
||||
<AdditionalOptions>/await -Xclang -fcoroutines-ts %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalIncludeDirectories>../../include;../Common</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions);SQUIDTASK_TIME_PRECISION_DOUBLE</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>Default</LanguageStandard>
|
||||
<AdditionalOptions>/await -Xclang -fcoroutines-ts %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalIncludeDirectories>../../include;../Common</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions);SQUIDTASK_TIME_PRECISION_DOUBLE</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>Default</LanguageStandard>
|
||||
<AdditionalOptions>/await -Xclang -fcoroutines-ts %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalIncludeDirectories>../../include;../Common</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
63
samples/Sample_Tests/Sample_Tests.vcxproj.filters
Normal file
63
samples/Sample_Tests/Sample_Tests.vcxproj.filters
Normal file
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\SquidTasks">
|
||||
<UniqueIdentifier>{63b632a7-ce3c-4dd9-a970-5e661d591932}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\SquidTasks\Private">
|
||||
<UniqueIdentifier>{89a92d2a-3fa9-4c0d-8dbf-466c03830dc3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Common">
|
||||
<UniqueIdentifier>{cf5b02a9-ec31-44ea-9840-80634ce22458}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\include\FunctionGuard.h">
|
||||
<Filter>Source Files\SquidTasks</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\Task.h">
|
||||
<Filter>Source Files\SquidTasks</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\TaskManager.h">
|
||||
<Filter>Source Files\SquidTasks</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\TasksConfig.h">
|
||||
<Filter>Source Files\SquidTasks</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\TokenList.h">
|
||||
<Filter>Source Files\SquidTasks</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\TaskFSM.h">
|
||||
<Filter>Source Files\SquidTasks</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\Private\TaskFSMPrivate.h">
|
||||
<Filter>Source Files\SquidTasks\Private</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\Private\TaskPrivate.h">
|
||||
<Filter>Source Files\SquidTasks\Private</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\Private\TasksCommonPrivate.h">
|
||||
<Filter>Source Files\SquidTasks\Private</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Common\TimeSystem.h">
|
||||
<Filter>Source Files\Common</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user