Merge branch 'Sprint1' of https://github.com/dean11/Danbias into Graphics
Conflicts: Bin/DLL/DebugCameraVertex.cso Bin/DLL/DebugPixel.cso Bin/DLL/GamePhysics_x86D.dll Bin/DLL/GamePhysics_x86D.exp Bin/DLL/GamePhysics_x86D.ilk Bin/DLL/GamePhysics_x86D.pdb Bin/DLL/OysterGraphics_x86D.dll Bin/DLL/OysterGraphics_x86D.exp Bin/DLL/OysterGraphics_x86D.ilk Bin/DLL/OysterGraphics_x86D.pdb Bin/DLL/TextureDebug.cso Bin/DLL/VertexGatherData.cso Code/OysterGraphics/FileLoader/ObjReader.cpp Code/OysterGraphics/FileLoader/TextureLoader.cpp Code/OysterGraphics/FileLoader/TextureLoader.h Code/OysterGraphics/OysterGraphics.vcxproj Code/OysterGraphics/OysterGraphics.vcxproj.filters Code/OysterGraphics/Render/Resources/Resources.cpp Code/OysterGraphics/Shader/HLSL/SimpleDebug/Debug.hlsl Code/OysterGraphics/Shader/HLSL/SimpleDebug/DebugCameraVertex.hlsl Code/OysterGraphics/Shader/HLSL/SimpleDebug/DebugPixel.hlsl Code/OysterGraphics/Shader/HLSL/SimpleDebug/TextureDebug.hlsl Code/Tester/MainTest.cpp
This commit is contained in:
commit
469ccaab6c
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -29,6 +29,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GamePhysics", "GamePhysics\
|
|||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Tester", "Tester\Tester.vcxproj", "{1B3BEA4C-CF75-438A-9693-60FB8444BBF3}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DanBiasGame", "DanBiasGame\DanBiasGame.vcxproj", "{2A1BC987-AF42-4500-802D-89CD32FC1309}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Mixed Platforms = Debug|Mixed Platforms
|
||||
|
@ -175,6 +177,7 @@ Global
|
|||
{104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|x64.Build.0 = Debug|x64
|
||||
{104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Release|Mixed Platforms.ActiveCfg = Release|Win32
|
||||
{104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Release|Mixed Platforms.Build.0 = Release|Win32
|
||||
{104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Release|Win32.ActiveCfg = Release|Win32
|
||||
|
@ -190,6 +193,18 @@ Global
|
|||
{1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Release|Win32.Build.0 = Release|Win32
|
||||
{1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Release|x64.ActiveCfg = Release|Win32
|
||||
{2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
|
||||
{2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|Mixed Platforms.Build.0 = Debug|Win32
|
||||
{2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|x64.Build.0 = Debug|x64
|
||||
{2A1BC987-AF42-4500-802D-89CD32FC1309}.Release|Mixed Platforms.ActiveCfg = Release|Win32
|
||||
{2A1BC987-AF42-4500-802D-89CD32FC1309}.Release|Mixed Platforms.Build.0 = Release|Win32
|
||||
{2A1BC987-AF42-4500-802D-89CD32FC1309}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{2A1BC987-AF42-4500-802D-89CD32FC1309}.Release|Win32.Build.0 = Release|Win32
|
||||
{2A1BC987-AF42-4500-802D-89CD32FC1309}.Release|x64.ActiveCfg = Release|x64
|
||||
{2A1BC987-AF42-4500-802D-89CD32FC1309}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -0,0 +1,193 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{2A1BC987-AF42-4500-802D-89CD32FC1309}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>DanBiasGame</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</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 Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<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 Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<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>
|
||||
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
|
||||
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
|
||||
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(LibraryPath)$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
|
||||
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
|
||||
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(LibraryPath)$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)GameLogic;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>OysterGraphics_$(PlatformShortName)D.lib;Input_$(PlatformShortName)D.lib;GameLogic_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<DelayLoadDLLs>OysterGraphics_$(PlatformShortName)D.dll;GameLogic_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)GameLogic;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>OysterGraphics_$(PlatformShortName)D.lib;Input_$(PlatformShortName)D.lib;GameLogic_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<DelayLoadDLLs>OysterGraphics_$(PlatformShortName)D.dll;GameLogic_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)GameLogic;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;GameLogic_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<DelayLoadDLLs>OysterGraphics_$(PlatformShortName)D.dll;GameLogic_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)GameLogic;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;GameLogic_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<DelayLoadDLLs>OysterGraphics_$(PlatformShortName)D.dll;GameLogic_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\GameLogic\GameLogic.vcxproj">
|
||||
<Project>{b1195bb9-b3a5-47f0-906c-8dea384d1520}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Input\Input.vcxproj">
|
||||
<Project>{7e3990d2-3d94-465c-b58d-64a74b3ecf9b}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\OysterMath\OysterMath.vcxproj">
|
||||
<Project>{f10cbc03-9809-4cba-95d8-327c287b18ee}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\OysterPhysics3D\OysterPhysics3D.vcxproj">
|
||||
<Project>{4285bd3f-3c6c-4670-b7af-a29afef5f6a8}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="DanBiasMaincpp.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -0,0 +1,316 @@
|
|||
//--------------------------------------------------------------------------------------
|
||||
// File: TemplateMain.cpp
|
||||
//
|
||||
// BTH-D3D-Template
|
||||
//
|
||||
// Copyright (c) Stefan Petersson 2011. All rights reserved.
|
||||
//--------------------------------------------------------------------------------------
|
||||
#define NOMINMAX
|
||||
#include <Windows.h>
|
||||
|
||||
#include "DllInterfaces/GFXAPI.h"
|
||||
#include "IGame.h"
|
||||
|
||||
#include "L_inputClass.h"
|
||||
|
||||
// debug window include
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Global Variables
|
||||
//--------------------------------------------------------------------------------------
|
||||
HINSTANCE g_hInst = NULL;
|
||||
HWND g_hWnd = NULL;
|
||||
|
||||
GameLogic::IGame* game;
|
||||
InputClass* inputObj;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//--------------------------------------------------------------------------------------
|
||||
HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow );
|
||||
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
||||
HRESULT Render(float deltaTime);
|
||||
HRESULT Update(float deltaTime);
|
||||
HRESULT InitDirect3D();
|
||||
HRESULT InitGame();
|
||||
HRESULT CleanUp();
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Entry point to the program. Initializes everything and goes into a message processing
|
||||
// loop. Idle time is used to render the scene.
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
void SetStdOutToNewConsole()
|
||||
{
|
||||
// allocate a console for this app
|
||||
AllocConsole();
|
||||
|
||||
// redirect unbuffered STDOUT to the console
|
||||
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
int fileDescriptor = _open_osfhandle((intptr_t)consoleHandle, _O_TEXT);
|
||||
FILE *fp = _fdopen( fileDescriptor, "w" );
|
||||
*stdout = *fp;
|
||||
setvbuf( stdout, NULL, _IONBF, 0 );
|
||||
|
||||
// give the console window a nicer title
|
||||
|
||||
SetConsoleTitle(L"Debug Output");
|
||||
|
||||
// give the console window a bigger buffer size
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
if ( GetConsoleScreenBufferInfo(consoleHandle, &csbi) )
|
||||
{
|
||||
COORD bufferSize;
|
||||
bufferSize.X = csbi.dwSize.X;
|
||||
bufferSize.Y = 50;
|
||||
SetConsoleScreenBufferSize(consoleHandle, bufferSize);
|
||||
}
|
||||
}
|
||||
|
||||
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
|
||||
{
|
||||
// for dynamic .dll loading
|
||||
// path is relative to the .exe and .dll pos
|
||||
// also change the VC directories - working dir is set to $(SolutionDir)..\Bin\Executable\Tester
|
||||
// to fit with where the .obj files is
|
||||
// linker/ input/ delayed load .dll - specify the .dll that should be loaded
|
||||
|
||||
BOOL success = SetDllDirectory(L"..\\..\\DLL");
|
||||
if (success == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( FAILED( InitWindow( hInstance, nCmdShow ) ) )
|
||||
return 0;
|
||||
|
||||
if( FAILED( InitDirect3D() ) )
|
||||
return 0;
|
||||
|
||||
if( FAILED( InitGame() ) )
|
||||
return 0;
|
||||
|
||||
__int64 cntsPerSec = 0;
|
||||
QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec);
|
||||
float secsPerCnt = 1.0f / (float)cntsPerSec;
|
||||
|
||||
__int64 prevTimeStamp = 0;
|
||||
QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);
|
||||
|
||||
//debug window
|
||||
//SetStdOutToNewConsole();
|
||||
|
||||
// Main message loop
|
||||
MSG msg = {0};
|
||||
while(WM_QUIT != msg.message)
|
||||
{
|
||||
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE) )
|
||||
{
|
||||
TranslateMessage( &msg );
|
||||
DispatchMessage( &msg );
|
||||
}
|
||||
else
|
||||
{
|
||||
__int64 currTimeStamp = 0;
|
||||
QueryPerformanceCounter((LARGE_INTEGER*)&currTimeStamp);
|
||||
float dt = (currTimeStamp - prevTimeStamp) * secsPerCnt;
|
||||
|
||||
//render
|
||||
Update(dt);
|
||||
Render(dt);
|
||||
|
||||
prevTimeStamp = currTimeStamp;
|
||||
}
|
||||
}
|
||||
CleanUp();
|
||||
return (int) msg.wParam;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Register class and create window
|
||||
//--------------------------------------------------------------------------------------
|
||||
HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow )
|
||||
{
|
||||
// Register class
|
||||
WNDCLASSEX wcex;
|
||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wcex.lpfnWndProc = WndProc;
|
||||
wcex.cbClsExtra = 0;
|
||||
wcex.cbWndExtra = 0;
|
||||
wcex.hInstance = hInstance;
|
||||
wcex.hIcon = 0;
|
||||
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
||||
wcex.lpszMenuName = NULL;
|
||||
wcex.lpszClassName = L"BTH_D3D_Template";
|
||||
wcex.hIconSm = 0;
|
||||
if( !RegisterClassEx(&wcex) )
|
||||
return E_FAIL;
|
||||
|
||||
// Adjust and create window
|
||||
g_hInst = hInstance;
|
||||
RECT rc = { 0, 0, 1024, 768 };
|
||||
AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );
|
||||
|
||||
if(!(g_hWnd = CreateWindow(
|
||||
L"BTH_D3D_Template",
|
||||
L"BTH - Direct3D 11.0 Template",
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
rc.right - rc.left,
|
||||
rc.bottom - rc.top,
|
||||
NULL,
|
||||
NULL,
|
||||
hInstance,
|
||||
NULL)))
|
||||
{
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
ShowWindow( g_hWnd, nCmdShow );
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Create Direct3D with Oyster Graphics
|
||||
//--------------------------------------------------------------------------------------
|
||||
HRESULT InitDirect3D()
|
||||
{
|
||||
if(Oyster::Graphics::API::Init(g_hWnd, false, false, Oyster::Math::Float2( 1024, 768)) != Oyster::Graphics::API::Sucsess)
|
||||
return E_FAIL;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Init the input and the game
|
||||
//-------------------------------------------------------------------------------------
|
||||
HRESULT InitGame()
|
||||
{
|
||||
inputObj = new InputClass;
|
||||
if(!inputObj->Initialize(g_hInst, g_hWnd, 1024, 768))
|
||||
{
|
||||
MessageBox(0, L"Could not initialize the input object.", L"Error", MB_OK);
|
||||
return false;
|
||||
}
|
||||
game = new GameLogic::IGame();
|
||||
game->Init();
|
||||
game->StartGame();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT Update(float deltaTime)
|
||||
{
|
||||
inputObj->Update();
|
||||
GameLogic::keyInput key = GameLogic::keyInput_none;
|
||||
|
||||
if(inputObj->IsKeyPressed(DIK_W))
|
||||
{
|
||||
key = GameLogic::keyInput_W;
|
||||
}
|
||||
else if(inputObj->IsKeyPressed(DIK_A))
|
||||
{
|
||||
key = GameLogic::keyInput_A;
|
||||
}
|
||||
else if(inputObj->IsKeyPressed(DIK_S))
|
||||
{
|
||||
key = GameLogic::keyInput_S;
|
||||
}
|
||||
else if(inputObj->IsKeyPressed(DIK_D))
|
||||
{
|
||||
key = GameLogic::keyInput_D;
|
||||
}
|
||||
|
||||
float pitch = 0;
|
||||
float yaw = 0;
|
||||
|
||||
//if(inputObj->IsMousePressed())
|
||||
//{
|
||||
pitch = inputObj->GetPitch();
|
||||
yaw = inputObj->GetYaw();
|
||||
//}
|
||||
|
||||
game->Update(key, pitch, yaw);
|
||||
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT Render(float deltaTime)
|
||||
{
|
||||
int isPressed = 0;
|
||||
if(inputObj->IsKeyPressed(DIK_A))
|
||||
{
|
||||
isPressed = 1;
|
||||
//std::cout<<"test";
|
||||
}
|
||||
|
||||
game->Render();
|
||||
wchar_t title[255];
|
||||
swprintf(title, sizeof(title), L"| Pressing A: %d | \n", (int)(isPressed));
|
||||
SetWindowText(g_hWnd, title);
|
||||
|
||||
Oyster::Graphics::API::EndFrame();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CleanUp()
|
||||
{
|
||||
|
||||
if(game)
|
||||
{
|
||||
delete game;
|
||||
game = NULL;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Called every time the application receives a message
|
||||
//--------------------------------------------------------------------------------------
|
||||
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
|
||||
{
|
||||
PAINTSTRUCT ps;
|
||||
HDC hdc;
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case WM_PAINT:
|
||||
hdc = BeginPaint(hWnd, &ps);
|
||||
EndPaint(hWnd, &ps);
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
|
||||
case WM_KEYDOWN:
|
||||
|
||||
switch(wParam)
|
||||
{
|
||||
case VK_ESCAPE:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,185 @@
|
|||
#include "Camera.h"
|
||||
|
||||
Camera::Camera()
|
||||
{
|
||||
this->m_position = Oyster::Math::Float3(0, 50, 0);
|
||||
this->mRight = Oyster::Math::Float3(1, 0, 0);
|
||||
this->mUp = Oyster::Math::Float3(0, 1, 0);
|
||||
this->mLook = Oyster::Math::Float3(0, 0, 1);
|
||||
}
|
||||
|
||||
Camera::~Camera()
|
||||
{
|
||||
}
|
||||
|
||||
void Camera::SetPosition(const Oyster::Math::Float3& v)
|
||||
{
|
||||
this->m_position = v;
|
||||
}
|
||||
|
||||
Oyster::Math::Float3 Camera::GetPosition()const
|
||||
{
|
||||
return this->m_position;
|
||||
}
|
||||
|
||||
Oyster::Math::Float3 Camera::GetRight()const
|
||||
{
|
||||
return this->mRight;
|
||||
}
|
||||
|
||||
Oyster::Math::Float3 Camera::GetUp()const
|
||||
{
|
||||
return this->mUp;
|
||||
}
|
||||
|
||||
Oyster::Math::Float3 Camera::GetLook()const
|
||||
{
|
||||
return this->mLook;
|
||||
}
|
||||
|
||||
float Camera::GetNearZ()const
|
||||
{
|
||||
return this->mNearZ;
|
||||
}
|
||||
|
||||
float Camera::GetFarZ()const
|
||||
{
|
||||
return this->mFarZ;
|
||||
}
|
||||
|
||||
float Camera::GetAspect()const
|
||||
{
|
||||
return this->mAspect;
|
||||
}
|
||||
|
||||
Oyster::Math::Float3 Camera::CrossMatrix(const Oyster::Math::Float3& vector, const Oyster::Math::Float4x4& matrix)
|
||||
{
|
||||
Oyster::Math::Float3 vec;
|
||||
vec.x = matrix.m11*vector.x + matrix.m12*vector.y + matrix.m13*vector.z;
|
||||
vec.y = matrix.m21*vector.x + matrix.m22*vector.y + matrix.m23*vector.z;
|
||||
vec.z = matrix.m31*vector.x + matrix.m32*vector.y + matrix.m33*vector.z;
|
||||
return vec;
|
||||
}
|
||||
|
||||
void Camera::SetLens(float fovY, float aspect, float zn, float zf)
|
||||
{
|
||||
this->mFovY = fovY;
|
||||
this->mAspect = aspect;
|
||||
this->mNearZ = zn;
|
||||
this->mFarZ = zf;
|
||||
|
||||
float yScale = tan((Oyster::Math::pi*0.5f) - (mFovY*0.5f));
|
||||
float xScale = yScale/this->mAspect;
|
||||
|
||||
mProj = Oyster::Math::Float4x4(xScale, 0, 0, 0,
|
||||
0, yScale, 0, 0,
|
||||
0, 0, zf/(zf-zn), 1,
|
||||
0, 0, -zn*zf/(zf-zn), 0);
|
||||
mProj.Transpose();
|
||||
}
|
||||
|
||||
void Camera::LookAt(Oyster::Math::Float3 pos, Oyster::Math::Float3 target, Oyster::Math::Float3 worldUp)
|
||||
{
|
||||
Oyster::Math::Float3 L;
|
||||
|
||||
L = target - pos;
|
||||
L.Normalize();
|
||||
|
||||
Oyster::Math::Float3 R;
|
||||
R = worldUp.Cross(L);
|
||||
R.Normalize();
|
||||
|
||||
Oyster::Math::Float3 U;
|
||||
U = L.Cross(R);
|
||||
|
||||
this->m_position = pos;
|
||||
this->mLook = L;
|
||||
this->mRight = R;
|
||||
this->mUp = U;
|
||||
}
|
||||
|
||||
Oyster::Math::Float4x4 Camera::View()const
|
||||
{
|
||||
return this->mView;
|
||||
}
|
||||
|
||||
Oyster::Math::Float4x4 Camera::Proj()const
|
||||
{
|
||||
return this->mProj;
|
||||
}
|
||||
|
||||
Oyster::Math::Float4x4 Camera::ViewsProj()const
|
||||
{
|
||||
Oyster::Math::Float4x4 M;
|
||||
M = mView * mProj;
|
||||
return M;
|
||||
}
|
||||
|
||||
void Camera::Walk(float dist)
|
||||
{
|
||||
this->m_position += dist*this->mLook;
|
||||
}
|
||||
|
||||
void Camera::Strafe(float dist)
|
||||
{
|
||||
this->m_position += dist*this->mRight;
|
||||
}
|
||||
|
||||
void Camera::Pitch(float angle)
|
||||
{
|
||||
float radians = angle * 0.0174532925f;
|
||||
|
||||
Oyster::Math::Float4x4 R;
|
||||
|
||||
Oyster::Math3D::RotationMatrix(radians,-mRight,R);
|
||||
this->mUp = CrossMatrix(this->mUp, R);
|
||||
this->mLook = CrossMatrix(this->mLook, R);
|
||||
}
|
||||
|
||||
void Camera::Yaw(float angle)
|
||||
{
|
||||
float radians = angle * 0.0174532925f;
|
||||
|
||||
Oyster::Math::Float4x4 R;
|
||||
|
||||
Oyster::Math::Float3 up(0,1,0);
|
||||
Oyster::Math3D::RotationMatrix(radians,-up,R);
|
||||
|
||||
this->mRight = CrossMatrix(this->mRight, R);
|
||||
this->mUp = CrossMatrix(mUp, R);
|
||||
this->mLook = CrossMatrix(this->mLook, R);
|
||||
}
|
||||
|
||||
void Camera::UpdateViewMatrix()
|
||||
{
|
||||
mLook.Normalize();
|
||||
mUp = mLook.Cross(mRight);
|
||||
mUp.Normalize();
|
||||
mRight = mUp.Cross(mLook);
|
||||
|
||||
float x = -m_position.Dot(mRight);
|
||||
float y = -m_position.Dot(mUp);
|
||||
float z = -m_position.Dot(mLook);
|
||||
|
||||
mView.m11 = mRight.x;
|
||||
mView.m21 = mRight.y;
|
||||
mView.m31 = mRight.z;
|
||||
mView.m41 = x;
|
||||
|
||||
mView.m12 = mUp.x;
|
||||
mView.m22 = mUp.y;
|
||||
mView.m32 = mUp.z;
|
||||
mView.m42 = y;
|
||||
|
||||
mView.m13 = mLook.x;
|
||||
mView.m23 = mLook.y;
|
||||
mView.m33 = mLook.z;
|
||||
mView.m43 = z;
|
||||
|
||||
mView.m14 = 0.0f;
|
||||
mView.m24 = 0.0f;
|
||||
mView.m34 = 0.0f;
|
||||
mView.m44 = 1.0f;
|
||||
|
||||
mView.Transpose();
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
#ifndef CAMERA__H
|
||||
#define CAMERA__H
|
||||
|
||||
#include "OysterMath.h"
|
||||
|
||||
class Camera
|
||||
{
|
||||
private:
|
||||
|
||||
Oyster::Math::Float3 m_position;
|
||||
Oyster::Math::Float3 mRight;
|
||||
Oyster::Math::Float3 mUp;
|
||||
Oyster::Math::Float3 mLook;
|
||||
|
||||
|
||||
|
||||
float mNearZ;
|
||||
float mFarZ;
|
||||
float mAspect;
|
||||
float mFovY;
|
||||
|
||||
Oyster::Math::Float4x4 mView;
|
||||
Oyster::Math::Float4x4 mProj;
|
||||
|
||||
public:
|
||||
Camera();
|
||||
virtual ~Camera();
|
||||
|
||||
void SetPosition(const Oyster::Math::Float3& v);
|
||||
|
||||
Oyster::Math::Float3 GetPosition()const;
|
||||
|
||||
Oyster::Math::Float3 GetRight()const;
|
||||
Oyster::Math::Float3 GetUp()const;
|
||||
Oyster::Math::Float3 GetLook()const;
|
||||
|
||||
float GetNearZ()const;
|
||||
float GetFarZ()const;
|
||||
float GetAspect()const;
|
||||
|
||||
Oyster::Math::Float3 CrossMatrix(const Oyster::Math::Float3& v, const Oyster::Math::Float4x4& m);
|
||||
|
||||
void SetLens(float fovY, float aspect, float zn, float zf);
|
||||
|
||||
void LookAt(Oyster::Math::Float3 pos, Oyster::Math::Float3 target, Oyster::Math::Float3 worldUp);
|
||||
|
||||
void setLook(Oyster::Math::Float3 look) { mLook = look; }
|
||||
void setUp(Oyster::Math::Float3 up) { mUp = up; }
|
||||
void setRight(Oyster::Math::Float3 right) { mRight = right; }
|
||||
|
||||
Oyster::Math::Float4x4 View()const;
|
||||
Oyster::Math::Float4x4 Proj()const;
|
||||
Oyster::Math::Float4x4 ViewsProj()const;
|
||||
|
||||
void Walk(float dist);
|
||||
void Strafe(float dist);
|
||||
|
||||
void Pitch(float angle);
|
||||
void Yaw(float angle);
|
||||
|
||||
void UpdateViewMatrix();
|
||||
};
|
||||
#endif
|
|
@ -0,0 +1,50 @@
|
|||
#include "CollisionManager.h"
|
||||
|
||||
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
||||
namespace CollisionManager
|
||||
{
|
||||
|
||||
void PlayerCollision(Oyster::Physics::ICustomBody &rigidBodyPlayer,Oyster::Physics::ICustomBody &obj)
|
||||
{
|
||||
Player *player = ((Player*)GameLogic::RefManager::getInstance()->GetMap(rigidBodyPlayer));
|
||||
Object *realObj = GameLogic::RefManager::getInstance()->GetMap(obj);
|
||||
|
||||
switch (realObj->GetType())
|
||||
{
|
||||
case Object::OBJECT_TYPE_BOX:
|
||||
PlayerVBox(*player,(*(DynamicObject*) realObj));
|
||||
break;
|
||||
case Object::OBJECT_TYPE_PLAYER:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
//spela ljud? ta skada? etc etc
|
||||
}
|
||||
|
||||
void PlayerVBox(Player &player, DynamicObject &box)
|
||||
{
|
||||
//spela ljud? ta skada? etc etc
|
||||
}
|
||||
|
||||
void BoxCollision(Oyster::Physics::ICustomBody &rigidBodyBox, Oyster::Physics::ICustomBody &obj)
|
||||
{
|
||||
DynamicObject *box = ((DynamicObject*)GameLogic::RefManager::getInstance()->GetMap(rigidBodyBox));
|
||||
Object *realObj = GameLogic::RefManager::getInstance()->GetMap(obj);
|
||||
|
||||
switch (realObj->GetType())
|
||||
{
|
||||
case Object::OBJECT_TYPE_BOX:
|
||||
|
||||
break;
|
||||
case Object::OBJECT_TYPE_PLAYER:
|
||||
PlayerVBox(*(Player*)realObj,*box);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef COLLISIONMANAGER_H
|
||||
#define COLLISIONMANAGER_H
|
||||
|
||||
#include "Object.h"
|
||||
#include "PhysicsAPI.h"
|
||||
#include "RefManager.h"
|
||||
#include "DynamicObject.h"
|
||||
#include "Player.h"
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
||||
namespace CollisionManager
|
||||
{
|
||||
//these are the main collision functions
|
||||
void PlayerCollision(Oyster::Physics::ICustomBody &rigidBodyPlayer,Oyster::Physics::ICustomBody &obj);
|
||||
void BoxCollision(Oyster::Physics::ICustomBody &rigidBodyBox, Oyster::Physics::ICustomBody &obj);
|
||||
|
||||
//these are the specific collision case functions
|
||||
void PlayerVBox(Player &player, DynamicObject &box);
|
||||
void BoxVBox(DynamicObject &box1, DynamicObject &box2);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,20 @@
|
|||
#include "DynamicObject.h"
|
||||
|
||||
using namespace GameLogic;
|
||||
using namespace Oyster::Physics;
|
||||
using namespace Utility::DynamicMemory;
|
||||
|
||||
DynamicObject::DynamicObject(void)
|
||||
:Object()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DynamicObject::~DynamicObject(void)
|
||||
{
|
||||
}
|
||||
|
||||
void DynamicObject::Update()
|
||||
{
|
||||
//update object
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
//////////////////////////////////////////////////
|
||||
//Created by Erik and Linda of the GameLogic team
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef DYNAMICOBJECT_H
|
||||
#define DYNAMICOBJECT_H
|
||||
|
||||
#include "Object.h"
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
||||
|
||||
class DynamicObject : public Object
|
||||
{
|
||||
|
||||
public:
|
||||
DynamicObject(void);
|
||||
~DynamicObject(void);
|
||||
|
||||
void Update();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,68 @@
|
|||
#include "Game.h"
|
||||
using namespace GameLogic;
|
||||
|
||||
Game::Game(void)
|
||||
{
|
||||
player = NULL;
|
||||
level = NULL;
|
||||
camera = NULL;
|
||||
}
|
||||
|
||||
|
||||
Game::~Game(void)
|
||||
{
|
||||
//SAFE_DELETE(player);
|
||||
if(player)
|
||||
{
|
||||
delete player;
|
||||
player = NULL;
|
||||
}
|
||||
if(camera)
|
||||
{
|
||||
delete camera;
|
||||
camera = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void Game::Init()
|
||||
{
|
||||
player = new Player();
|
||||
camera = new Camera();
|
||||
}
|
||||
void Game::StartGame()
|
||||
{
|
||||
Oyster::Math::Float3 dir = Oyster::Math::Float3(0,0,-1);
|
||||
Oyster::Math::Float3 up =Oyster::Math::Float3(0,1,0);
|
||||
Oyster::Math::Float3 pos = Oyster::Math::Float3(0, 0, 100);
|
||||
|
||||
camera->LookAt(pos, dir, up);
|
||||
camera->SetLens(3.14f/2, 1024/768, 1, 1000);
|
||||
}
|
||||
void Game::Update(keyInput keyPressed, float pitch, float yaw)
|
||||
{
|
||||
//player->Update(keyPressed);
|
||||
camera->Yaw(yaw);
|
||||
camera->Pitch(pitch);
|
||||
if(keyPressed == keyInput_A)
|
||||
{
|
||||
camera->Strafe(-0.1);
|
||||
}
|
||||
if(keyPressed == keyInput_D)
|
||||
{
|
||||
camera->Strafe(0.1);
|
||||
}
|
||||
if(keyPressed == keyInput_S)
|
||||
{
|
||||
camera->Walk(-0.1);
|
||||
}
|
||||
if(keyPressed == keyInput_W)
|
||||
{
|
||||
camera->Walk(0.1);
|
||||
}
|
||||
camera->UpdateViewMatrix();
|
||||
}
|
||||
void Game::Render()
|
||||
{
|
||||
Oyster::Graphics::API::NewFrame(camera->View(), camera->Proj());
|
||||
player->Render();
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef GAME_H
|
||||
#define GAME_H
|
||||
|
||||
#include "Level.h"
|
||||
#include "Player.h"
|
||||
#include "IGame.h"
|
||||
#include "Camera.h"
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
class Game
|
||||
{
|
||||
public:
|
||||
Game();
|
||||
~Game();
|
||||
|
||||
void Init();
|
||||
void StartGame();
|
||||
void Update(keyInput keyPressed, float pitch, float yaw);
|
||||
void Render();
|
||||
|
||||
private:
|
||||
Level* level;
|
||||
Player* player;
|
||||
Camera* camera;
|
||||
};
|
||||
}
|
||||
#endif
|
|
@ -24,30 +24,30 @@
|
|||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
|
@ -66,34 +66,41 @@
|
|||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
|
||||
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
|
||||
<LibraryPath>$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;$(LibraryPath)</LibraryPath>
|
||||
<TargetExt>.dll</TargetExt>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
|
||||
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
|
||||
<LibraryPath>$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
|
||||
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
|
||||
<LibraryPath>$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
|
||||
<OutDir>$(SolutionDir)..\Bin\DLL\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
|
||||
<LibraryPath>$(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>GAME_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>OysterGraphics_$(PlatformShortName)D.lib;Input_$(PlatformShortName)D.lib;GamePhysics_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
|
@ -101,10 +108,12 @@
|
|||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>GAME_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>OysterGraphics_$(PlatformShortName)D.lib;Input_$(PlatformShortName)D.lib;GamePhysics_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
|
@ -114,12 +123,14 @@
|
|||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>GAME_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;GamePhysics_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
|
@ -129,21 +140,34 @@
|
|||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)GamePhysics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>GAME_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;GamePhysics_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\GamePhysics\GamePhysics.vcxproj">
|
||||
<Project>{104fa3e9-94d9-4e1d-a941-28a03bc8a095}</Project>
|
||||
<Private>false</Private>
|
||||
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
|
||||
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
|
||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
||||
<UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Input\Input.vcxproj">
|
||||
<Project>{7e3990d2-3d94-465c-b58d-64a74b3ecf9b}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Misc\Misc.vcxproj">
|
||||
<Project>{2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\OysterGraphics\OysterGraphics.vcxproj">
|
||||
<Project>{0ec83e64-230e-48ef-b08c-6ac9651b4f82}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\OysterMath\OysterMath.vcxproj">
|
||||
<Project>{f10cbc03-9809-4cba-95d8-327c287b18ee}</Project>
|
||||
</ProjectReference>
|
||||
|
@ -151,6 +175,35 @@
|
|||
<Project>{4285bd3f-3c6c-4670-b7af-a29afef5f6a8}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Camera.h" />
|
||||
<ClInclude Include="CollisionManager.h" />
|
||||
<ClInclude Include="DynamicObject.h" />
|
||||
<ClInclude Include="Game.h" />
|
||||
<ClInclude Include="GameMode.h" />
|
||||
<ClInclude Include="IGame.h" />
|
||||
<ClInclude Include="Level.h" />
|
||||
<ClInclude Include="Object.h" />
|
||||
<ClInclude Include="Player.h" />
|
||||
<ClInclude Include="RefManager.h" />
|
||||
<ClInclude Include="StaticObject.h" />
|
||||
<ClInclude Include="Weapon.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Camera.cpp" />
|
||||
<ClCompile Include="CollisionManager.cpp" />
|
||||
<ClCompile Include="DynamicObject.cpp" />
|
||||
<ClCompile Include="Game.cpp" />
|
||||
<ClCompile Include="GameMode.cpp" />
|
||||
<ClCompile Include="IGame.cpp" />
|
||||
<ClCompile Include="Level.cpp" />
|
||||
<ClCompile Include="Object.cpp" />
|
||||
<ClCompile Include="Player.cpp" />
|
||||
<ClCompile Include="RefManager.cpp" />
|
||||
<ClCompile Include="StaticObject.cpp" />
|
||||
<ClCompile Include="TestGLMain.cpp" />
|
||||
<ClCompile Include="Weapon.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
|
|
|
@ -14,4 +14,83 @@
|
|||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Game.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Level.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Object.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Player.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="IGame.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="StaticObject.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Weapon.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="DynamicObject.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="RefManager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GameMode.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CollisionManager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Camera.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Game.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Level.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Object.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Player.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="IGame.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="StaticObject.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Weapon.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="DynamicObject.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="RefManager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="TestGLMain.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GameMode.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CollisionManager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Camera.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,15 @@
|
|||
#include "GameMode.h"
|
||||
|
||||
using namespace GameLogic;
|
||||
|
||||
|
||||
GameMode::GameMode(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
GameMode::~GameMode(void)
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
//////////////////////////////////////////////////
|
||||
//Created by Erik and Linda of the GameLogic team
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef GAMEMODE_H
|
||||
#define GAMEMODE_H
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
||||
class GameMode
|
||||
{
|
||||
public:
|
||||
GameMode(void);
|
||||
~GameMode(void);
|
||||
private:
|
||||
//variabels that control what game rules the level runs on
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,43 @@
|
|||
#include "IGame.h"
|
||||
#include "Game.h"
|
||||
#include <windows.h>
|
||||
|
||||
BOOL WINAPI DllMain(
|
||||
_In_ HINSTANCE hinstDLL,
|
||||
_In_ DWORD fdwReason,
|
||||
_In_ LPVOID lpvReserved
|
||||
)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
using namespace GameLogic;
|
||||
|
||||
IGame::IGame()
|
||||
{
|
||||
gameModule = new Game();
|
||||
}
|
||||
IGame::~IGame()
|
||||
{
|
||||
delete gameModule;
|
||||
}
|
||||
|
||||
void IGame::Init()
|
||||
{
|
||||
gameModule->Init();
|
||||
}
|
||||
void IGame::StartGame()
|
||||
{
|
||||
gameModule->StartGame();
|
||||
}
|
||||
void IGame::Update(keyInput keyPressed, float pitch, float yaw)
|
||||
{
|
||||
gameModule->Update(keyPressed, pitch, yaw);
|
||||
}
|
||||
void IGame::Render()
|
||||
{
|
||||
gameModule->Render();
|
||||
}
|
||||
Game* IGame::getGameModule()
|
||||
{
|
||||
return gameModule;
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
//////////////////////////////////////////////////
|
||||
//Created by Erik and Linda of the GameLogic team
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
#ifndef IGAME_H
|
||||
#define IGAME_H
|
||||
|
||||
#if defined GAME_DLL_EXPORT
|
||||
#define GAME_DLL_USAGE __declspec(dllexport)
|
||||
#else
|
||||
#define GAME_DLL_USAGE __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
class Game;
|
||||
|
||||
enum keyInput
|
||||
{
|
||||
keyInput_W,
|
||||
keyInput_A,
|
||||
keyInput_S,
|
||||
keyInput_D,
|
||||
keyInput_none
|
||||
};
|
||||
|
||||
class GAME_DLL_USAGE IGame
|
||||
{
|
||||
private:
|
||||
Game* gameModule;
|
||||
public:
|
||||
IGame();
|
||||
~IGame();
|
||||
|
||||
|
||||
void Init();
|
||||
void StartGame();
|
||||
/************************************************************************/
|
||||
/* Get key input to update the player */
|
||||
/************************************************************************/
|
||||
void Update(keyInput keyPressed, float pitch, float yaw);
|
||||
void Render();
|
||||
Game* getGameModule();
|
||||
private:
|
||||
};
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,12 @@
|
|||
#include "Level.h"
|
||||
|
||||
using namespace GameLogic;
|
||||
|
||||
Level::Level(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Level::~Level(void)
|
||||
{
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
//////////////////////////////////////////////////
|
||||
//Created by Erik and Linda of the GameLogic team
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef LEVEL_H
|
||||
#define LEVEL_H
|
||||
|
||||
#include "StaticObject.h"
|
||||
#include "DynamicObject.h"
|
||||
#include "GameMode.h"
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
||||
class Level
|
||||
{
|
||||
|
||||
public:
|
||||
Level(void);
|
||||
~Level(void);
|
||||
|
||||
private:
|
||||
StaticObject** staticObjects;
|
||||
int nrOfStaticObjects;
|
||||
|
||||
DynamicObject** dynamicObjects;
|
||||
int nrOfDynamicObjects;
|
||||
|
||||
GameMode* gameMode;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,47 @@
|
|||
#include "Object.h"
|
||||
#include "OysterMath.h"
|
||||
#include "DllInterfaces\GFXAPI.h"
|
||||
#include "CollisionManager.h"
|
||||
|
||||
|
||||
using namespace GameLogic;
|
||||
|
||||
using namespace Oyster::Math;
|
||||
using namespace Oyster::Graphics::Model;
|
||||
|
||||
using namespace Utility::DynamicMemory;
|
||||
using namespace Oyster::Physics;
|
||||
|
||||
Object::Object(void)
|
||||
{
|
||||
|
||||
model = new Model();
|
||||
model = Oyster::Graphics::API::CreateModel(L"bth.obj");
|
||||
|
||||
API::SimpleBodyDescription sbDesc;
|
||||
//sbDesc.centerPosition =
|
||||
|
||||
ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
|
||||
|
||||
GameLogic::RefManager::getInstance()->AddMapping(*rigidBody, *this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Object::~Object(void)
|
||||
{
|
||||
|
||||
Oyster::Graphics::API::DeleteModel(model);
|
||||
|
||||
}
|
||||
|
||||
void Object::Render()
|
||||
{
|
||||
this->rigidBody->GetOrientation(model->WorldMatrix);
|
||||
Oyster::Graphics::API::RenderScene(model, 1);
|
||||
}
|
||||
|
||||
Object::OBJECT_TYPE Object::GetType()
|
||||
{
|
||||
return this->type;
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
//////////////////////////////////////////////////
|
||||
//Created by Erik and Linda of the GameLogic team
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef OBJECT_H
|
||||
#define OBJECT_H
|
||||
|
||||
#include "PhysicsAPI.h"
|
||||
#include "DllInterfaces/GFXAPI.h"
|
||||
|
||||
#include "Model/Model.h"
|
||||
#include "Utilities.h"
|
||||
|
||||
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
class Object
|
||||
{
|
||||
public:
|
||||
|
||||
enum OBJECT_TYPE
|
||||
{
|
||||
OBJECT_TYPE_PLAYER,
|
||||
OBJECT_TYPE_BOX,
|
||||
};
|
||||
Object(void);
|
||||
virtual ~Object(void);
|
||||
|
||||
void Render();
|
||||
|
||||
OBJECT_TYPE GetType();
|
||||
|
||||
private:
|
||||
OBJECT_TYPE type;
|
||||
|
||||
protected:
|
||||
//either a model pointer or an ID to an arraypos filled with models that are to be rendered
|
||||
//rigidBody
|
||||
|
||||
Oyster::Physics::ICustomBody *rigidBody;
|
||||
Oyster::Graphics::Model::Model *model;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,55 @@
|
|||
#include "Player.h"
|
||||
#include "OysterMath.h"
|
||||
|
||||
using namespace GameLogic;
|
||||
using namespace Oyster::Physics;
|
||||
|
||||
Player::Player(void)
|
||||
:Object()
|
||||
{
|
||||
life = 100;
|
||||
}
|
||||
Player::~Player(void)
|
||||
{
|
||||
delete this->rigidBody;
|
||||
}
|
||||
|
||||
void Player::Update(keyInput keyPressed)
|
||||
{
|
||||
if(keyPressed != keyInput_none)
|
||||
{
|
||||
Move(keyPressed);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::Move(keyInput keyPressed)
|
||||
{
|
||||
if(keyPressed == keyInput_A)
|
||||
{
|
||||
Oyster::Math::Float3 pos = this->rigidBody->GetCenter();
|
||||
pos.x -= 0.1;
|
||||
rigidBody->SetCenter(pos);
|
||||
}
|
||||
if(keyPressed == keyInput_D)
|
||||
{
|
||||
Oyster::Math::Float3 pos = this->rigidBody->GetCenter();
|
||||
pos.x += 0.1;
|
||||
rigidBody->SetCenter(pos);
|
||||
}
|
||||
if(keyPressed == keyInput_S)
|
||||
{
|
||||
Oyster::Math::Float3 pos = this->rigidBody->GetCenter();
|
||||
pos.y -= 0.1;
|
||||
rigidBody->SetCenter(pos);
|
||||
}
|
||||
if(keyPressed == keyInput_W)
|
||||
{
|
||||
Oyster::Math::Float3 pos = this->rigidBody->GetCenter();
|
||||
pos.y += 0.1;
|
||||
rigidBody->SetCenter(pos);
|
||||
}
|
||||
}
|
||||
void Player::Shoot()
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
//////////////////////////////////////////////////
|
||||
//Created by Erik and Linda of the GameLogic team
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
#include "Object.h"
|
||||
#include "Weapon.h"
|
||||
#include "IGame.h"
|
||||
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
class Player : public Object
|
||||
{
|
||||
|
||||
public:
|
||||
Player(void);
|
||||
~Player(void);
|
||||
|
||||
/********************************************************
|
||||
* Update the position of the rigid body
|
||||
* This will be done with physics later
|
||||
********************************************************/
|
||||
void Update(keyInput keyPressed);
|
||||
|
||||
void Move(keyInput keyPressed);
|
||||
void Shoot();
|
||||
|
||||
private:
|
||||
int life;
|
||||
Weapon *weapon;
|
||||
};
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,47 @@
|
|||
#include "RefManager.h"
|
||||
|
||||
using namespace GameLogic;
|
||||
|
||||
typedef std::pair<Oyster::Physics::ICustomBody*, Object*> mapData;
|
||||
|
||||
RefManager* RefManager::instance = 0;
|
||||
|
||||
RefManager::RefManager(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RefManager::~RefManager(void)
|
||||
{
|
||||
}
|
||||
|
||||
void RefManager::Release()
|
||||
{
|
||||
if (instance)
|
||||
{
|
||||
delete instance;
|
||||
instance = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RefManager* RefManager::getInstance( )
|
||||
{
|
||||
if (!instance)
|
||||
{
|
||||
instance = new RefManager();
|
||||
};
|
||||
return instance;
|
||||
}
|
||||
|
||||
Object* RefManager::GetMap(Oyster::Physics::ICustomBody &body)
|
||||
{
|
||||
return mapper[&body];
|
||||
}
|
||||
|
||||
void RefManager::AddMapping(Oyster::Physics::ICustomBody &body, Object &obj)
|
||||
{
|
||||
mapper.insert(mapData(&body,&obj));
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
//////////////////////////////////////////////////
|
||||
//Created by Erik and Linda of the GameLogic team
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef REFMANAGER_H
|
||||
#define REFMANAGER_H
|
||||
|
||||
#include<map>
|
||||
#include "Object.h"
|
||||
#include "PhysicsAPI.h"
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
||||
class RefManager
|
||||
{
|
||||
public:
|
||||
RefManager(void);
|
||||
~RefManager(void);
|
||||
|
||||
static RefManager* getInstance( );
|
||||
void Release();
|
||||
|
||||
|
||||
Object* GetMap(Oyster::Physics::ICustomBody &body); //returns the object of an rigidBody, mainly used for CollisionHandler
|
||||
void AddMapping(Oyster::Physics::ICustomBody &body, Object &obj); //adds a mapping with body as key and the object as a value
|
||||
|
||||
|
||||
private:
|
||||
static RefManager* instance;
|
||||
std::map<Oyster::Physics::ICustomBody*,Object*> mapper; //mapper points a rigidBody to an actual game object
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,12 @@
|
|||
#include "StaticObject.h"
|
||||
|
||||
using namespace GameLogic;
|
||||
|
||||
StaticObject::StaticObject(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
StaticObject::~StaticObject(void)
|
||||
{
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
//////////////////////////////////////////////////
|
||||
//Created by Erik and Linda of the GameLogic team
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef STATICOBJECT_H
|
||||
#define STATICOBJECT_H
|
||||
|
||||
#include "Object.h"
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
||||
class StaticObject : public Object
|
||||
{
|
||||
|
||||
public:
|
||||
StaticObject(void);
|
||||
~StaticObject(void);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,304 @@
|
|||
//--------------------------------------------------------------------------------------
|
||||
// File: TemplateMain.cpp
|
||||
//
|
||||
// BTH-D3D-Template
|
||||
//
|
||||
// Copyright (c) Stefan Petersson 2011. All rights reserved.
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Test main function for game logic when .exe
|
||||
// Doesn't run when Game logic is compiled as a .dll
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define NOMINMAX
|
||||
#include <Windows.h>
|
||||
#include "Core/Core.h"
|
||||
#include "DllInterfaces/GFXAPI.h"
|
||||
#include "IGame.h"
|
||||
|
||||
#include "L_inputClass.h"
|
||||
|
||||
// debug window include
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Global Variables
|
||||
//--------------------------------------------------------------------------------------
|
||||
HINSTANCE g_hInst = NULL;
|
||||
HWND g_hWnd = NULL;
|
||||
|
||||
GameLogic::IGame *game;
|
||||
InputClass *inputObj;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//--------------------------------------------------------------------------------------
|
||||
HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow );
|
||||
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
||||
HRESULT Render(float deltaTime);
|
||||
HRESULT Update(float deltaTime);
|
||||
HRESULT InitDirect3D();
|
||||
HRESULT InitGame();
|
||||
HRESULT CleanUp();
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Entry point to the program. Initializes everything and goes into a message processing
|
||||
// loop. Idle time is used to render the scene.
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
void SetStdOutToNewConsole()
|
||||
{
|
||||
// allocate a console for this app
|
||||
AllocConsole();
|
||||
|
||||
// redirect unbuffered STDOUT to the console
|
||||
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
int fileDescriptor = _open_osfhandle((intptr_t)consoleHandle, _O_TEXT);
|
||||
FILE *fp = _fdopen( fileDescriptor, "w" );
|
||||
*stdout = *fp;
|
||||
setvbuf( stdout, NULL, _IONBF, 0 );
|
||||
|
||||
// give the console window a nicer title
|
||||
|
||||
SetConsoleTitle(L"Debug Output");
|
||||
|
||||
// give the console window a bigger buffer size
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
if ( GetConsoleScreenBufferInfo(consoleHandle, &csbi) )
|
||||
{
|
||||
COORD bufferSize;
|
||||
bufferSize.X = csbi.dwSize.X;
|
||||
bufferSize.Y = 50;
|
||||
SetConsoleScreenBufferSize(consoleHandle, bufferSize);
|
||||
}
|
||||
}
|
||||
|
||||
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
|
||||
{
|
||||
if( FAILED( InitWindow( hInstance, nCmdShow ) ) )
|
||||
return 0;
|
||||
|
||||
if( FAILED( InitDirect3D() ) )
|
||||
return 0;
|
||||
|
||||
if( FAILED( InitGame() ) )
|
||||
return 0;
|
||||
|
||||
__int64 cntsPerSec = 0;
|
||||
QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec);
|
||||
float secsPerCnt = 1.0f / (float)cntsPerSec;
|
||||
|
||||
__int64 prevTimeStamp = 0;
|
||||
QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);
|
||||
|
||||
//Init debug window
|
||||
//SetStdOutToNewConsole();
|
||||
|
||||
// Main message loop
|
||||
MSG msg = {0};
|
||||
while(WM_QUIT != msg.message)
|
||||
{
|
||||
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE) )
|
||||
{
|
||||
TranslateMessage( &msg );
|
||||
DispatchMessage( &msg );
|
||||
}
|
||||
else
|
||||
{
|
||||
__int64 currTimeStamp = 0;
|
||||
QueryPerformanceCounter((LARGE_INTEGER*)&currTimeStamp);
|
||||
float dt = (currTimeStamp - prevTimeStamp) * secsPerCnt;
|
||||
|
||||
//render
|
||||
Update(dt);
|
||||
Render(dt);
|
||||
|
||||
prevTimeStamp = currTimeStamp;
|
||||
}
|
||||
}
|
||||
CleanUp();
|
||||
return (int) msg.wParam;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Register class and create window
|
||||
//--------------------------------------------------------------------------------------
|
||||
HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow )
|
||||
{
|
||||
// Register class
|
||||
WNDCLASSEX wcex;
|
||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wcex.lpfnWndProc = WndProc;
|
||||
wcex.cbClsExtra = 0;
|
||||
wcex.cbWndExtra = 0;
|
||||
wcex.hInstance = hInstance;
|
||||
wcex.hIcon = 0;
|
||||
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
||||
wcex.lpszMenuName = NULL;
|
||||
wcex.lpszClassName = L"BTH_D3D_Template";
|
||||
wcex.hIconSm = 0;
|
||||
if( !RegisterClassEx(&wcex) )
|
||||
return E_FAIL;
|
||||
|
||||
// Adjust and create window
|
||||
g_hInst = hInstance;
|
||||
RECT rc = { 0, 0, 1024, 768 };
|
||||
AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );
|
||||
|
||||
if(!(g_hWnd = CreateWindow(
|
||||
L"BTH_D3D_Template",
|
||||
L"BTH - Direct3D 11.0 Template",
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
rc.right - rc.left,
|
||||
rc.bottom - rc.top,
|
||||
NULL,
|
||||
NULL,
|
||||
hInstance,
|
||||
NULL)))
|
||||
{
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
ShowWindow( g_hWnd, nCmdShow );
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Create Direct3D with Oyster Graphics
|
||||
//--------------------------------------------------------------------------------------
|
||||
HRESULT InitDirect3D()
|
||||
{
|
||||
if(Oyster::Graphics::API::Init(g_hWnd, false, false, Oyster::Math::Float2( 1024, 768)) != Oyster::Graphics::API::Sucsess)
|
||||
return E_FAIL;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Init the input and the game
|
||||
//-------------------------------------------------------------------------------------
|
||||
HRESULT InitGame()
|
||||
{
|
||||
inputObj = new InputClass;
|
||||
if(!inputObj->Initialize(g_hInst, g_hWnd, 1024, 768))
|
||||
{
|
||||
MessageBox(0, L"Could not initialize the input object.", L"Error", MB_OK);
|
||||
return false;
|
||||
}
|
||||
game = new GameLogic::IGame();
|
||||
game->Init();
|
||||
game->StartGame();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT Update(float deltaTime)
|
||||
{
|
||||
inputObj->Update();
|
||||
GameLogic::keyInput key = GameLogic::keyInput_none;
|
||||
|
||||
if(inputObj->IsKeyPressed(DIK_W))
|
||||
{
|
||||
key = GameLogic::keyInput_W;
|
||||
}
|
||||
else if(inputObj->IsKeyPressed(DIK_A))
|
||||
{
|
||||
key = GameLogic::keyInput_A;
|
||||
}
|
||||
else if(inputObj->IsKeyPressed(DIK_S))
|
||||
{
|
||||
key = GameLogic::keyInput_S;
|
||||
}
|
||||
else if(inputObj->IsKeyPressed(DIK_D))
|
||||
{
|
||||
key = GameLogic::keyInput_D;
|
||||
}
|
||||
|
||||
float pitch = 0;
|
||||
float yaw = 0;
|
||||
|
||||
// move only when mouse is pressed
|
||||
//if(inputObj->IsMousePressed())
|
||||
//{
|
||||
pitch = inputObj->GetPitch();
|
||||
yaw = inputObj->GetYaw();
|
||||
//}
|
||||
|
||||
game->Update(key, pitch, yaw);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT Render(float deltaTime)
|
||||
{
|
||||
int isPressed = 0;
|
||||
if(inputObj->IsKeyPressed(DIK_A))
|
||||
{
|
||||
isPressed = 1;
|
||||
//std::cout<<"test";
|
||||
}
|
||||
|
||||
game->Render();
|
||||
wchar_t title[255];
|
||||
swprintf(title, sizeof(title), L"| Pressing A: %d | \n", (int)(isPressed));
|
||||
SetWindowText(g_hWnd, title);
|
||||
|
||||
Oyster::Graphics::API::EndFrame();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CleanUp()
|
||||
{
|
||||
SAFE_DELETE(game);
|
||||
return S_OK;
|
||||
}
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Called every time the application receives a message
|
||||
//--------------------------------------------------------------------------------------
|
||||
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
|
||||
{
|
||||
PAINTSTRUCT ps;
|
||||
HDC hdc;
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case WM_PAINT:
|
||||
hdc = BeginPaint(hWnd, &ps);
|
||||
EndPaint(hWnd, &ps);
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
|
||||
case WM_KEYDOWN:
|
||||
|
||||
switch(wParam)
|
||||
{
|
||||
case VK_ESCAPE:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
#include "Weapon.h"
|
||||
|
||||
using namespace GameLogic;
|
||||
|
||||
Weapon::Weapon(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Weapon::~Weapon(void)
|
||||
{
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
//////////////////////////////////////////////////
|
||||
//Created by Erik and Linda of the GameLogic team
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef WEAPON_H
|
||||
#define WEAPON_H
|
||||
|
||||
#include "Object.h"
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
||||
class Weapon : public Object
|
||||
{
|
||||
|
||||
public:
|
||||
Weapon(void);
|
||||
~Weapon(void);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
|
@ -156,6 +156,7 @@
|
|||
<ClInclude Include="PhysicsAPI.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Implementation\Octree.cpp" />
|
||||
<ClCompile Include="Implementation\DLLMain.cpp" />
|
||||
<ClCompile Include="Implementation\PhysicsAPI_Impl.cpp" />
|
||||
<ClCompile Include="Implementation\SimpleRigidBody.cpp" />
|
||||
|
|
|
@ -33,6 +33,9 @@
|
|||
<ClInclude Include="Implementation\SphericalRigidBody.h">
|
||||
<Filter>Header Files\Implementation</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Implementation\Octree.h">
|
||||
<Filter>Header Files\Implementation</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Implementation\PhysicsAPI_Impl.cpp">
|
||||
|
@ -47,5 +50,8 @@
|
|||
<ClCompile Include="Implementation\SphericalRigidBody.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Implementation\Octree.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,193 @@
|
|||
#include "Octree.h"
|
||||
|
||||
using namespace Oyster;
|
||||
using namespace Physics;
|
||||
using namespace ::Utility::DynamicMemory;
|
||||
|
||||
const unsigned int Octree::invalid_ref = ::Utility::Value::numeric_limits<unsigned int>::max();
|
||||
|
||||
Octree::Octree(unsigned int bufferSize, unsigned char numLayers, Math::Float3 worldSize)
|
||||
{
|
||||
this->worldNode.dataPtr = NULL;
|
||||
|
||||
this->worldNode.container.maxVertex = worldSize*0.5f;
|
||||
this->worldNode.container.minVertex = -worldSize*0.5f;
|
||||
}
|
||||
|
||||
Octree::~Octree()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Octree& Octree::operator=(const Octree& orig)
|
||||
{
|
||||
this->leafData = orig.leafData;
|
||||
this->updateQueue = orig.updateQueue;
|
||||
this->worldNode = orig.worldNode;
|
||||
this->mapReferences = orig.mapReferences;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Octree::AddObject(UniquePointer< ICustomBody > customBodyRef)
|
||||
{
|
||||
Data data;
|
||||
//Data* tempPtr = this->worldNode.dataPtr;
|
||||
|
||||
data.container = customBodyRef->GetBoundingSphere();
|
||||
data.queueRef = -1;
|
||||
data.next = NULL;
|
||||
data.prev = NULL;
|
||||
data.customBodyRef = customBodyRef;
|
||||
this->mapReferences.insert(std::pair <ICustomBody*, unsigned int> (customBodyRef, this->leafData.size()));
|
||||
this->leafData.push_back(data);
|
||||
|
||||
/*if(tempPtr != NULL)
|
||||
{
|
||||
tempPtr->prev->next = &this->leafData[this->leafData.size() - 1];
|
||||
this->leafData[this->leafData.size() - 1].prev = tempPtr->prev;
|
||||
tempPtr->prev = &this->leafData[this->leafData.size() - 1];
|
||||
this->leafData[this->leafData.size() - 1].next = tempPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->worldNode.dataPtr = &this->leafData[this->leafData.size() - 1];
|
||||
this->worldNode.dataPtr->next = this->worldNode.dataPtr;
|
||||
this->worldNode.dataPtr->prev = this->worldNode.dataPtr;
|
||||
}*/
|
||||
}
|
||||
|
||||
void Octree::MoveToUpdateQueue(UniquePointer< ICustomBody > customBodyRef)
|
||||
{
|
||||
/*this->leafData[this->mapReferences[customBodyRef]].queueRef = this->updateQueue.size();
|
||||
this->updateQueue.push_back(&this->leafData[this->mapReferences[customBodyRef]]);*/
|
||||
}
|
||||
|
||||
void Octree::DestroyObject(UniquePointer< ICustomBody > customBodyRef)
|
||||
{
|
||||
std::map<const ICustomBody*, unsigned int>::iterator it = this->mapReferences.find(customBodyRef);
|
||||
|
||||
this->mapReferences.erase(it);
|
||||
|
||||
this->leafData.erase(this->leafData.begin() + this->leafData[this->mapReferences[customBodyRef]].queueRef);
|
||||
}
|
||||
|
||||
std::vector<ICustomBody*>& Octree::Sample(ICustomBody* customBodyRef, std::vector<ICustomBody*>& updateList)
|
||||
{
|
||||
auto object = this->mapReferences.find(customBodyRef);
|
||||
|
||||
if(object == this->mapReferences.end())
|
||||
{
|
||||
return updateList;
|
||||
}
|
||||
|
||||
unsigned int tempRef = object->second;
|
||||
|
||||
for(unsigned int i = 0; i<this->leafData.size(); i++)
|
||||
{
|
||||
if(tempRef != i) if(this->leafData[tempRef].container.Intersects(this->leafData[i].container))
|
||||
{
|
||||
updateList.push_back(this->leafData[i].customBodyRef);
|
||||
}
|
||||
}
|
||||
|
||||
return updateList;
|
||||
}
|
||||
|
||||
std::vector<ICustomBody*>& Octree::Sample(const Oyster::Collision3D::ICollideable& collideable, std::vector<ICustomBody*>& updateList)
|
||||
{
|
||||
for(unsigned int i = 0; i<this->leafData.size(); i++)
|
||||
{
|
||||
if(this->leafData[i].container.Intersects(collideable))
|
||||
{
|
||||
updateList.push_back(this->leafData[i].customBodyRef);
|
||||
}
|
||||
}
|
||||
|
||||
return updateList;
|
||||
}
|
||||
|
||||
void Octree::Visit(ICustomBody* customBodyRef, VistorAction hitAction )
|
||||
{
|
||||
auto object = this->mapReferences.find(customBodyRef);
|
||||
|
||||
if(object == this->mapReferences.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int tempRef = object->second;
|
||||
|
||||
for(unsigned int i = 0; i<this->leafData.size(); i++)
|
||||
{
|
||||
if(tempRef != i) if(this->leafData[tempRef].container.Intersects(this->leafData[i].container))
|
||||
{
|
||||
hitAction(*this, tempRef, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Octree::Visit(const Oyster::Collision3D::ICollideable& collideable, VistorAction hitAction)
|
||||
{
|
||||
for(unsigned int i = 0; i<this->leafData.size(); i++)
|
||||
{
|
||||
if(this->leafData[i].container.Intersects(collideable))
|
||||
{
|
||||
//hitAction(*this, tempRef, i); // @todo TODO: Add typedef to handle function calls with ICollideable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ICustomBody* Octree::GetCustomBody(const unsigned int tempRef)
|
||||
{
|
||||
return this->leafData[tempRef].customBodyRef;
|
||||
}
|
||||
|
||||
UniquePointer<ICustomBody> Octree::Extract( const ICustomBody* objRef )
|
||||
{ // Dan Andersson
|
||||
auto iter = this->mapReferences.find( objRef );
|
||||
if( iter != this->mapReferences.end() )
|
||||
{
|
||||
return this->Extract( iter->second );
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
UniquePointer<ICustomBody> Octree::Extract( unsigned int tempRef )
|
||||
{
|
||||
if( tempRef != Octree::invalid_ref )
|
||||
{
|
||||
//! @todo TODO: implement stub
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int Octree::GetTemporaryReferenceOf( const ICustomBody* objRef ) const
|
||||
{ // Dan Andersson
|
||||
auto iter = this->mapReferences.find( objRef );
|
||||
if( iter != this->mapReferences.end() )
|
||||
{
|
||||
return iter->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Octree::invalid_ref;
|
||||
}
|
||||
}
|
||||
|
||||
void Octree::SetAsAltered( unsigned int tempRef )
|
||||
{
|
||||
//! @todo TODO: implement stub
|
||||
}
|
||||
|
||||
void Octree::EvaluatePosition( unsigned int tempRef )
|
||||
{
|
||||
//! @todo TODO: implement stub
|
||||
}
|
|
@ -15,6 +15,10 @@ namespace Oyster
|
|||
class Octree
|
||||
{
|
||||
public:
|
||||
static const unsigned int invalid_ref;
|
||||
|
||||
typedef void(*VistorAction)(Octree&, unsigned int, unsigned int);
|
||||
|
||||
struct Data
|
||||
{
|
||||
Data* prev;
|
||||
|
@ -22,33 +26,49 @@ namespace Oyster
|
|||
|
||||
Collision3D::Sphere container;
|
||||
|
||||
Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef;
|
||||
::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef;
|
||||
|
||||
unsigned int queueRef;
|
||||
};
|
||||
|
||||
struct OctreeNode
|
||||
{
|
||||
|
||||
OctreeNode* children[8];
|
||||
Data* dataPtr;
|
||||
Collision3D::BoxAxisAligned container;
|
||||
};
|
||||
|
||||
Octree(unsigned int bufferSize, unsigned char numLayers, Math::Float3 worldSize);
|
||||
Octree(unsigned int bufferSize = 0, unsigned char numLayers = 0, Math::Float3 worldSize = Math::Float3::null);
|
||||
virtual ~Octree();
|
||||
|
||||
void AddObject(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
|
||||
Octree& operator=(const Octree& orig);
|
||||
|
||||
void MoveToUpdateQueue(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
|
||||
void AddObject(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
|
||||
|
||||
void Update();
|
||||
void MoveToUpdateQueue(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
|
||||
|
||||
void DestroyObject(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
|
||||
void DestroyObject(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
|
||||
|
||||
std::vector<ICustomBody*>& Sample(ICustomBody* customBodyRef, std::vector<ICustomBody*>& updateList);
|
||||
std::vector<ICustomBody*>& Sample(const Oyster::Collision3D::ICollideable& collideable, std::vector<ICustomBody*>& updateList);
|
||||
void Visit(ICustomBody* customBodyRef, VistorAction hitAction );
|
||||
void Visit(const Oyster::Collision3D::ICollideable& collideable, VistorAction hitAction );
|
||||
|
||||
ICustomBody* GetCustomBody(const unsigned int tempRef);
|
||||
|
||||
::Utility::DynamicMemory::UniquePointer<ICustomBody> Extract( const ICustomBody* objRef );
|
||||
::Utility::DynamicMemory::UniquePointer<ICustomBody> Extract( unsigned int tempRef ); // Dan vill ha
|
||||
unsigned int GetTemporaryReferenceOf( const ICustomBody* objRef ) const; // Dan vill ha
|
||||
void SetAsAltered( unsigned int tempRef ); // Dan vill ha
|
||||
void EvaluatePosition( unsigned int tempRef ); // Dan vill ha
|
||||
|
||||
void Sample(Collision3D::ICollideable& collideable);
|
||||
private:
|
||||
std::vector < Data > leafData;
|
||||
std::vector < Data* > updateQueue;
|
||||
|
||||
std::map< ICustomBody*, unsigned int > mapReferences;
|
||||
std::map< const ICustomBody*, unsigned int > mapReferences;
|
||||
|
||||
OctreeNode worldNode;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "PhysicsAPI_Impl.h"
|
||||
#include "SimpleRigidBody.h"
|
||||
#include "OysterPhysics3D.h"
|
||||
#include "SimpleRigidBody.h"
|
||||
#include "SphericalRigidBody.h"
|
||||
|
||||
using namespace ::Oyster::Physics;
|
||||
using namespace ::Oyster::Physics3D;
|
||||
|
@ -10,13 +11,21 @@ using namespace ::Utility::DynamicMemory;
|
|||
|
||||
API_Impl API_instance;
|
||||
|
||||
// default API::EventAction_Collision
|
||||
void defaultCollisionAction( const ICustomBody *proto, const ICustomBody *deuter )
|
||||
{ /* do nothing */ }
|
||||
namespace
|
||||
{
|
||||
void OnPossibleCollision( Octree& worldScene, unsigned int protoTempRef, unsigned int deuterTempRef )
|
||||
{ /** @todo TODO: OnPossibleCollision is a temporary solution .*/
|
||||
auto proto = worldScene.GetCustomBody( protoTempRef );
|
||||
auto deuter = worldScene.GetCustomBody( deuterTempRef );
|
||||
|
||||
// default API::EventAction_Destruction
|
||||
void defaultDestructionAction( UniquePointer<ICustomBody> proto )
|
||||
{ /* do nothing besides proto auto deleting itself. */ }
|
||||
float deltaWhen;
|
||||
Float3 worldWhere;
|
||||
if( deuter->Intersects(*deuter, 1.0f, deltaWhen, worldWhere) )
|
||||
{
|
||||
proto->CallSubscription( proto, deuter );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Float4x4 & MomentOfInertia::CreateSphereMatrix( const Float mass, const Float radius)
|
||||
{
|
||||
|
@ -49,39 +58,63 @@ API & API::Instance()
|
|||
}
|
||||
|
||||
API_Impl::API_Impl()
|
||||
: gravityConstant( Constant::gravity_constant ),
|
||||
updateFrameLength( 1.0f / 120.0f ),
|
||||
collisionAction( defaultCollisionAction ),
|
||||
destructionAction( defaultDestructionAction )
|
||||
{}
|
||||
{
|
||||
this->gravityConstant = Constant::gravity_constant;
|
||||
this->updateFrameLength = 1.0f / 120.0f;
|
||||
this->destructionAction = Default::EventAction_Destruction;
|
||||
this->worldScene = Octree();
|
||||
}
|
||||
|
||||
API_Impl::~API_Impl() {}
|
||||
|
||||
void API_Impl::Init( unsigned int numObjects, unsigned int numGravityWells , const Float3 &worldSize )
|
||||
{
|
||||
//! @todo TODO: implement stub
|
||||
unsigned char numLayers = 4; //!< @todo TODO: calc numLayers from worldSize
|
||||
this->worldScene = Octree( numObjects, numLayers, worldSize );
|
||||
}
|
||||
|
||||
void API_Impl::SetDeltaTime( float deltaTime )
|
||||
void API_Impl::SetFrameTimeLength( float deltaTime )
|
||||
{
|
||||
updateFrameLength = deltaTime;
|
||||
this->updateFrameLength = deltaTime;
|
||||
}
|
||||
|
||||
void API_Impl::SetGravityConstant( float g )
|
||||
{
|
||||
this->gravityConstant = g;
|
||||
}
|
||||
void API_Impl::SetAction( API::EventAction_Collision functionPointer )
|
||||
|
||||
void API_Impl::SetSubscription( API::EventAction_Destruction functionPointer )
|
||||
{
|
||||
this->collisionAction = functionPointer;
|
||||
}
|
||||
void API_Impl::SetAction( API::EventAction_Destruction functionPointer )
|
||||
if( functionPointer )
|
||||
{
|
||||
this->destructionAction = functionPointer;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->destructionAction = Default::EventAction_Destruction;
|
||||
}
|
||||
}
|
||||
|
||||
void API_Impl::Update()
|
||||
{ /** @todo TODO: Update is a temporary solution .*/
|
||||
::std::vector<ICustomBody*> updateList;
|
||||
auto proto = this->worldScene.Sample( Universe(), updateList ).begin();
|
||||
for( ; proto != updateList.end(); ++proto )
|
||||
{
|
||||
/** @todo TODO: Fix this function.*/
|
||||
this->worldScene.Visit( *proto, OnPossibleCollision );
|
||||
}
|
||||
|
||||
proto = updateList.begin();
|
||||
for( ; proto != updateList.end(); ++proto )
|
||||
{
|
||||
switch( (*proto)->Update(this->updateFrameLength) )
|
||||
{
|
||||
case UpdateState_altered:
|
||||
this->worldScene.SetAsAltered( this->worldScene.GetTemporaryReferenceOf(*proto) );
|
||||
case UpdateState_resting: default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool API_Impl::IsInLimbo( const ICustomBody* objRef )
|
||||
|
@ -101,71 +134,139 @@ void API_Impl::ReleaseFromLimbo( const ICustomBody* objRef )
|
|||
|
||||
void API_Impl::AddObject( ::Utility::DynamicMemory::UniquePointer<ICustomBody> handle )
|
||||
{
|
||||
/** @todo TODO: Fix this function.*/
|
||||
this->worldScene.AddObject( handle );
|
||||
}
|
||||
|
||||
::Utility::DynamicMemory::UniquePointer<ICustomBody> API_Impl::ExtractObject( const ICustomBody* objRef )
|
||||
UniquePointer<ICustomBody> API_Impl::ExtractObject( const ICustomBody* objRef )
|
||||
{
|
||||
//! @todo TODO: implement stub
|
||||
return NULL;
|
||||
return this->worldScene.Extract( objRef );
|
||||
}
|
||||
|
||||
void API_Impl::DestroyObject( const ICustomBody* objRef )
|
||||
{
|
||||
/** @todo TODO: Fix this function.*/
|
||||
UniquePointer<ICustomBody> object = this->worldScene.Extract( objRef );
|
||||
if( object )
|
||||
{
|
||||
this->destructionAction( object );
|
||||
}
|
||||
}
|
||||
|
||||
void API_Impl::ApplyForceAt( const ICustomBody* objRef, const Float3 &worldPos, const Float3 &worldF )
|
||||
{
|
||||
//! @todo TODO: implement stub
|
||||
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
|
||||
if( tempRef != this->worldScene.invalid_ref )
|
||||
{
|
||||
//this->worldScene.GetCustomBody( tempRef )->Apply //!< @todo TODO: need function
|
||||
this->worldScene.SetAsAltered( tempRef );
|
||||
}
|
||||
}
|
||||
|
||||
void API_Impl::ApplyCollisionResponse( const ICustomBody* objRefA, const ICustomBody* objRefB, Float &deltaWhen, Float3 &worldPointOfContact )
|
||||
{
|
||||
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRefA );
|
||||
if( tempRef != this->worldScene.invalid_ref )
|
||||
{
|
||||
//! @todo TODO: implement stub
|
||||
this->worldScene.SetAsAltered( tempRef );
|
||||
}
|
||||
}
|
||||
|
||||
void API_Impl::SetMomentOfInertiaTensor_KeepVelocity( const ICustomBody* objRef, const Float4x4 &localI )
|
||||
{ // deprecated
|
||||
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
|
||||
if( tempRef != this->worldScene.invalid_ref )
|
||||
{
|
||||
//! @todo TODO: implement stub
|
||||
this->worldScene.GetCustomBody( tempRef )->SetMomentOfInertiaTensor_KeepVelocity( localI );
|
||||
}
|
||||
}
|
||||
|
||||
void API_Impl::SetMomentOfInertiaTensor_KeepMomentum( const ICustomBody* objRef, const Float4x4 &localI )
|
||||
{ // deprecated
|
||||
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
|
||||
if( tempRef != this->worldScene.invalid_ref )
|
||||
{
|
||||
//! @todo TODO: implement stub
|
||||
this->worldScene.GetCustomBody( tempRef )->SetMomentOfInertiaTensor_KeepMomentum( localI );
|
||||
}
|
||||
}
|
||||
|
||||
void API_Impl::SetMass_KeepVelocity( const ICustomBody* objRef, Float m )
|
||||
{ // deprecated
|
||||
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
|
||||
if( tempRef != this->worldScene.invalid_ref )
|
||||
{
|
||||
//! @todo TODO: implement stub
|
||||
this->worldScene.GetCustomBody( tempRef )->SetMass_KeepVelocity( m );
|
||||
}
|
||||
}
|
||||
|
||||
void API_Impl::SetMass_KeepMomentum( const ICustomBody* objRef, Float m )
|
||||
{ // deprecated
|
||||
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
|
||||
if( tempRef != this->worldScene.invalid_ref )
|
||||
{
|
||||
//! @todo TODO: implement stub
|
||||
this->worldScene.GetCustomBody( tempRef )->SetMass_KeepMomentum( m );
|
||||
}
|
||||
}
|
||||
|
||||
void API_Impl::SetCenter( const ICustomBody* objRef, const Float3 &worldPos )
|
||||
{
|
||||
//! @todo TODO: implement stub
|
||||
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
|
||||
if( tempRef != this->worldScene.invalid_ref )
|
||||
{
|
||||
//this->worldScene.GetCustomBody( tempRef )->Set //!< @todo TODO: need function
|
||||
this->worldScene.EvaluatePosition( tempRef );
|
||||
}
|
||||
}
|
||||
|
||||
void API_Impl::SetRotation( const ICustomBody* objRef, const Float4x4 &rotation )
|
||||
{
|
||||
//! @todo TODO: implement stub
|
||||
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
|
||||
if( tempRef != this->worldScene.invalid_ref )
|
||||
{
|
||||
this->worldScene.GetCustomBody( tempRef )->SetRotation( rotation );
|
||||
this->worldScene.EvaluatePosition( tempRef );
|
||||
}
|
||||
}
|
||||
|
||||
void API_Impl::SetOrientation( const ICustomBody* objRef, const Float4x4 &orientation )
|
||||
{
|
||||
//! @todo TODO: implement stub
|
||||
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
|
||||
if( tempRef != this->worldScene.invalid_ref )
|
||||
{
|
||||
this->worldScene.GetCustomBody( tempRef )->SetOrientation( orientation );
|
||||
this->worldScene.EvaluatePosition( tempRef );
|
||||
}
|
||||
}
|
||||
|
||||
void API_Impl::SetSize( const ICustomBody* objRef, const Float3 &size )
|
||||
{
|
||||
//! @todo TODO: implement stub
|
||||
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
|
||||
if( tempRef != this->worldScene.invalid_ref )
|
||||
{
|
||||
this->worldScene.GetCustomBody( tempRef )->SetSize( size );
|
||||
this->worldScene.EvaluatePosition( tempRef );
|
||||
}
|
||||
}
|
||||
|
||||
UniquePointer<ICustomBody> API_Impl::CreateSimpleRigidBody() const
|
||||
UniquePointer<ICustomBody> API_Impl::CreateRigidBody( const API::SimpleBodyDescription &desc ) const
|
||||
{
|
||||
return new SimpleRigidBody();
|
||||
return new SimpleRigidBody( desc );
|
||||
}
|
||||
|
||||
UniquePointer<ICustomBody> API_Impl::CreateRigidBody( const API::SphericalBodyDescription &desc ) const
|
||||
{
|
||||
return new SphericalRigidBody( desc );
|
||||
}
|
||||
|
||||
namespace Oyster { namespace Physics
|
||||
{
|
||||
namespace Default
|
||||
{
|
||||
void EventAction_Destruction( ::Utility::DynamicMemory::UniquePointer<::Oyster::Physics::ICustomBody> proto )
|
||||
{ /* Do nothing except allowing the proto uniquePointer destroy itself. */ }
|
||||
|
||||
::Oyster::Physics::ICustomBody::SubscriptMessage EventAction_Collision( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter )
|
||||
{ /* Do nothing except returning business as usual. */
|
||||
return ::Oyster::Physics::ICustomBody::SubscriptMessage_none;
|
||||
}
|
||||
}
|
||||
} }
|
|
@ -2,6 +2,7 @@
|
|||
#define PHYSICS_API_IMPL_H
|
||||
|
||||
#include "../PhysicsAPI.h"
|
||||
#include "Octree.h"
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
|
@ -15,10 +16,9 @@ namespace Oyster
|
|||
|
||||
void Init( unsigned int numObjects, unsigned int numGravityWells , const ::Oyster::Math::Float3 &worldSize );
|
||||
|
||||
void SetDeltaTime( float deltaTime );
|
||||
void SetFrameTimeLength( float deltaTime );
|
||||
void SetGravityConstant( float g );
|
||||
void SetAction( EventAction_Collision functionPointer );
|
||||
void SetAction( EventAction_Destruction functionPointer );
|
||||
void SetSubscription( EventAction_Destruction functionPointer );
|
||||
|
||||
void Update();
|
||||
|
||||
|
@ -42,14 +42,21 @@ namespace Oyster
|
|||
void SetOrientation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &orientation );
|
||||
void SetSize( const ICustomBody* objRef, const ::Oyster::Math::Float3 &size );
|
||||
|
||||
::Utility::DynamicMemory::UniquePointer<ICustomBody> CreateSimpleRigidBody() const;
|
||||
::Utility::DynamicMemory::UniquePointer<ICustomBody> CreateRigidBody( const SimpleBodyDescription &desc ) const;
|
||||
::Utility::DynamicMemory::UniquePointer<ICustomBody> CreateRigidBody( const SphericalBodyDescription &desc ) const;
|
||||
|
||||
private:
|
||||
::Oyster::Math::Float gravityConstant, updateFrameLength;
|
||||
EventAction_Collision collisionAction;
|
||||
EventAction_Destruction destructionAction;
|
||||
Octree worldScene;
|
||||
};
|
||||
}
|
||||
|
||||
namespace Default
|
||||
{
|
||||
void EventAction_Destruction( ::Utility::DynamicMemory::UniquePointer<::Oyster::Physics::ICustomBody> proto );
|
||||
::Oyster::Physics::ICustomBody::SubscriptMessage EventAction_Collision( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -2,16 +2,38 @@
|
|||
#include "PhysicsAPI_Impl.h"
|
||||
|
||||
using namespace ::Oyster::Physics;
|
||||
using namespace ::Oyster::Physics3D;
|
||||
using namespace ::Oyster::Math3D;
|
||||
using namespace ::Oyster::Collision3D;
|
||||
using namespace ::Utility::DynamicMemory;
|
||||
using namespace ::Utility::Value;
|
||||
|
||||
SimpleRigidBody::SimpleRigidBody()
|
||||
: previous(), current(),
|
||||
gravityNormal(0.0f),
|
||||
subscribeCollision(true),
|
||||
ignoreGravity(false) {}
|
||||
{
|
||||
this->rigid = RigidBody( Box(Float4x4::identity, Float3::null, Float3(1.0f)), 16.0f, Float4x4::identity );
|
||||
this->gravityNormal = Float3::null;
|
||||
this->collisionAction = Default::EventAction_Collision;
|
||||
this->ignoreGravity = false;
|
||||
}
|
||||
|
||||
SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc )
|
||||
{
|
||||
this->rigid = RigidBody( Box( desc.rotation, desc.centerPosition, desc.size ),
|
||||
desc.mass,
|
||||
desc.inertiaTensor );
|
||||
this->gravityNormal = Float3::null;
|
||||
|
||||
if( desc.subscription )
|
||||
{
|
||||
this->collisionAction = desc.subscription;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->collisionAction = Default::EventAction_Collision;
|
||||
}
|
||||
|
||||
this->ignoreGravity = desc.ignoreGravity;
|
||||
}
|
||||
|
||||
SimpleRigidBody::~SimpleRigidBody() {}
|
||||
|
||||
|
@ -20,9 +42,9 @@ UniquePointer<ICustomBody> SimpleRigidBody::Clone() const
|
|||
return new SimpleRigidBody( *this );
|
||||
}
|
||||
|
||||
bool SimpleRigidBody::IsSubscribingCollisions() const
|
||||
{ // Assumption
|
||||
return this->subscribeCollision;
|
||||
void SimpleRigidBody::CallSubscription( const ICustomBody *proto, const ICustomBody *deuter )
|
||||
{
|
||||
this->collisionAction( proto, deuter );
|
||||
}
|
||||
|
||||
bool SimpleRigidBody::IsAffectedByGravity() const
|
||||
|
@ -32,10 +54,10 @@ bool SimpleRigidBody::IsAffectedByGravity() const
|
|||
|
||||
bool SimpleRigidBody::Intersects( const ICustomBody &object, Float timeStepLength, Float &deltaWhen, Float3 &worldPointOfContact ) const
|
||||
{
|
||||
if( object.Intersects(this->current.box) )
|
||||
if( object.Intersects(this->rigid.box) )
|
||||
{ //! @todo TODO: better implementation needed
|
||||
deltaWhen = timeStepLength;
|
||||
worldPointOfContact = Average( this->current.box.center, object.GetCenter() );
|
||||
worldPointOfContact = Average( this->rigid.box.center, object.GetCenter() );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -46,18 +68,18 @@ bool SimpleRigidBody::Intersects( const ICustomBody &object, Float timeStepLengt
|
|||
|
||||
bool SimpleRigidBody::Intersects( const ICollideable &shape ) const
|
||||
{
|
||||
return this->current.box.Intersects( shape );
|
||||
return this->rigid.box.Intersects( shape );
|
||||
}
|
||||
|
||||
Sphere & SimpleRigidBody::GetBoundingSphere( Sphere &targetMem ) const
|
||||
{
|
||||
return targetMem = Sphere( this->current.box.center, this->current.box.boundingOffset.GetMagnitude() );
|
||||
return targetMem = Sphere( this->rigid.box.center, this->rigid.box.boundingOffset.GetMagnitude() );
|
||||
}
|
||||
|
||||
Float3 & SimpleRigidBody::GetNormalAt( const Float3 &worldPos, Float3 &targetMem ) const
|
||||
{
|
||||
//! @todo TODO: better implementation needed
|
||||
return targetMem = (worldPos - this->current.box.center).GetNormalized();
|
||||
return targetMem = (worldPos - this->rigid.box.center).GetNormalized();
|
||||
}
|
||||
|
||||
Float3 & SimpleRigidBody::GetGravityNormal( Float3 &targetMem ) const
|
||||
|
@ -67,32 +89,43 @@ Float3 & SimpleRigidBody::GetGravityNormal( Float3 &targetMem ) const
|
|||
|
||||
Float3 & SimpleRigidBody::GetCenter( Float3 &targetMem ) const
|
||||
{
|
||||
return targetMem = this->current.box.center;
|
||||
return targetMem = this->rigid.box.center;
|
||||
}
|
||||
|
||||
Float4x4 & SimpleRigidBody::GetRotation( Float4x4 &targetMem ) const
|
||||
{
|
||||
return targetMem = this->current.box.rotation;
|
||||
return targetMem = this->rigid.box.rotation;
|
||||
}
|
||||
|
||||
Float4x4 & SimpleRigidBody::GetOrientation( Float4x4 &targetMem ) const
|
||||
{
|
||||
return targetMem = this->current.GetOrientation();
|
||||
return targetMem = this->rigid.GetOrientation();
|
||||
}
|
||||
|
||||
Float4x4 & SimpleRigidBody::GetView( Float4x4 &targetMem ) const
|
||||
{
|
||||
return targetMem = this->current.GetView();
|
||||
return targetMem = this->rigid.GetView();
|
||||
}
|
||||
|
||||
UpdateState SimpleRigidBody::Update( Float timeStepLength )
|
||||
{
|
||||
this->previous = this->current; // memorizing the old state
|
||||
|
||||
this->current.Update_LeapFrog( timeStepLength );
|
||||
this->rigid.Update_LeapFrog( timeStepLength );
|
||||
|
||||
// compare previous and new state and return result
|
||||
return this->current == this->previous ? resting : altered;
|
||||
//return this->current == this->previous ? UpdateState_resting : UpdateState_altered;
|
||||
return UpdateState_altered;
|
||||
}
|
||||
|
||||
void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_Collision functionPointer )
|
||||
{
|
||||
if( functionPointer )
|
||||
{
|
||||
this->collisionAction = functionPointer;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->collisionAction = Default::EventAction_Collision;
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleRigidBody::SetGravity( bool ignore)
|
||||
|
@ -106,47 +139,42 @@ void SimpleRigidBody::SetGravityNormal( const Float3 &normalizedVector )
|
|||
this->gravityNormal = normalizedVector;
|
||||
}
|
||||
|
||||
void SimpleRigidBody::SetSubscription( bool subscribeCollision )
|
||||
{
|
||||
this->subscribeCollision = subscribeCollision;
|
||||
}
|
||||
|
||||
void SimpleRigidBody::SetMomentOfInertiaTensor_KeepVelocity( const Float4x4 &localI )
|
||||
{
|
||||
this->current.SetMomentOfInertia_KeepVelocity( localI );
|
||||
this->rigid.SetMomentOfInertia_KeepVelocity( localI );
|
||||
}
|
||||
|
||||
void SimpleRigidBody::SetMomentOfInertiaTensor_KeepMomentum( const Float4x4 &localI )
|
||||
{
|
||||
this->current.SetMomentOfInertia_KeepMomentum( localI );
|
||||
this->rigid.SetMomentOfInertia_KeepMomentum( localI );
|
||||
}
|
||||
|
||||
void SimpleRigidBody::SetMass_KeepVelocity( Float m )
|
||||
{
|
||||
this->current.SetMass_KeepVelocity( m );
|
||||
this->rigid.SetMass_KeepVelocity( m );
|
||||
}
|
||||
|
||||
void SimpleRigidBody::SetMass_KeepMomentum( Float m )
|
||||
{
|
||||
this->current.SetMass_KeepMomentum( m );
|
||||
this->rigid.SetMass_KeepMomentum( m );
|
||||
}
|
||||
|
||||
void SimpleRigidBody::SetCenter( const Float3 &worldPos )
|
||||
{
|
||||
this->current.SetCenter( worldPos );
|
||||
this->rigid.SetCenter( worldPos );
|
||||
}
|
||||
|
||||
void SimpleRigidBody::SetRotation( const Float4x4 &rotation )
|
||||
{
|
||||
this->current.SetRotation( rotation );
|
||||
this->rigid.SetRotation( rotation );
|
||||
}
|
||||
|
||||
void SimpleRigidBody::SetOrientation( const Float4x4 &orientation )
|
||||
{
|
||||
this->current.SetOrientation( orientation );
|
||||
this->rigid.SetOrientation( orientation );
|
||||
}
|
||||
|
||||
void SimpleRigidBody::SetSize( const Float3 &size )
|
||||
{
|
||||
this->current.SetSize( size );
|
||||
this->rigid.SetSize( size );
|
||||
}
|
|
@ -10,11 +10,12 @@ namespace Oyster { namespace Physics
|
|||
{
|
||||
public:
|
||||
SimpleRigidBody();
|
||||
SimpleRigidBody( const API::SimpleBodyDescription &desc );
|
||||
virtual ~SimpleRigidBody();
|
||||
|
||||
::Utility::DynamicMemory::UniquePointer<ICustomBody> Clone() const;
|
||||
|
||||
bool IsSubscribingCollisions() const;
|
||||
void CallSubscription( const ICustomBody *proto, const ICustomBody *deuter );
|
||||
bool IsAffectedByGravity() const;
|
||||
bool Intersects( const ICustomBody &object, ::Oyster::Math::Float timeStepLength, ::Oyster::Math::Float &deltaWhen, ::Oyster::Math::Float3 &worldPointOfContact ) const;
|
||||
bool Intersects( const ::Oyster::Collision3D::ICollideable &shape ) const;
|
||||
|
@ -29,9 +30,9 @@ namespace Oyster { namespace Physics
|
|||
|
||||
UpdateState Update( ::Oyster::Math::Float timeStepLength );
|
||||
|
||||
void SetSubscription( EventAction_Collision functionPointer );
|
||||
void SetGravity( bool ignore);
|
||||
void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector );
|
||||
void SetSubscription( bool subscribeCollision );
|
||||
void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI );
|
||||
void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI );
|
||||
void SetMass_KeepVelocity( ::Oyster::Math::Float m );
|
||||
|
@ -42,9 +43,10 @@ namespace Oyster { namespace Physics
|
|||
void SetSize( const ::Oyster::Math::Float3 &size );
|
||||
|
||||
private:
|
||||
::Oyster::Physics3D::RigidBody previous, current;
|
||||
::Oyster::Physics3D::RigidBody rigid;
|
||||
::Oyster::Math::Float3 gravityNormal;
|
||||
bool subscribeCollision, ignoreGravity;
|
||||
EventAction_Collision collisionAction;
|
||||
bool ignoreGravity;
|
||||
};
|
||||
} }
|
||||
|
||||
|
|
|
@ -2,17 +2,40 @@
|
|||
#include "PhysicsAPI_Impl.h"
|
||||
|
||||
using namespace ::Oyster::Physics;
|
||||
using namespace ::Oyster::Physics3D;
|
||||
using namespace ::Oyster::Math3D;
|
||||
using namespace ::Oyster::Collision3D;
|
||||
using namespace ::Utility::DynamicMemory;
|
||||
using namespace ::Utility::Value;
|
||||
|
||||
SphericalRigidBody::SphericalRigidBody()
|
||||
: previous(), current( Box(Float4x4::identity, Float3::null, Float3(1.0f)) ),
|
||||
gravityNormal( 0.0f ),
|
||||
subscribeCollision( true ),
|
||||
ignoreGravity( false ),
|
||||
body( Float3::null, 0.5f ) {}
|
||||
{
|
||||
this->rigid = RigidBody( Box(Float4x4::identity, Float3::null, Float3(1.0f)), 10.0f, Float4x4::identity );
|
||||
this->gravityNormal = Float3::null;
|
||||
this->collisionAction = Default::EventAction_Collision;
|
||||
this->ignoreGravity = false;
|
||||
this->body = Sphere( Float3::null, 0.5f );
|
||||
}
|
||||
|
||||
SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &desc )
|
||||
{
|
||||
this->rigid = RigidBody( Box( desc.rotation, desc.centerPosition, Float3(2.0f * desc.radius) ),
|
||||
desc.mass,
|
||||
MomentOfInertia::CreateSphereMatrix( desc.mass, desc.radius ) );
|
||||
this->gravityNormal = Float3::null;
|
||||
|
||||
if( desc.subscription )
|
||||
{
|
||||
this->collisionAction = desc.subscription;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->collisionAction = Default::EventAction_Collision;
|
||||
}
|
||||
|
||||
this->ignoreGravity = desc.ignoreGravity;
|
||||
this->body = Sphere( desc.centerPosition, desc.radius );
|
||||
}
|
||||
|
||||
SphericalRigidBody::~SphericalRigidBody() {}
|
||||
|
||||
|
@ -21,9 +44,9 @@ UniquePointer<ICustomBody> SphericalRigidBody::Clone() const
|
|||
return new SphericalRigidBody( *this );
|
||||
}
|
||||
|
||||
bool SphericalRigidBody::IsSubscribingCollisions() const
|
||||
{ // Assumption
|
||||
return this->subscribeCollision;
|
||||
void SphericalRigidBody::CallSubscription( const ICustomBody *proto, const ICustomBody *deuter )
|
||||
{
|
||||
this->collisionAction( proto, deuter );
|
||||
}
|
||||
|
||||
bool SphericalRigidBody::IsAffectedByGravity() const
|
||||
|
@ -47,7 +70,7 @@ bool SphericalRigidBody::Intersects( const ICustomBody &object, Float timeStepLe
|
|||
|
||||
bool SphericalRigidBody::Intersects( const ICollideable &shape ) const
|
||||
{
|
||||
return this->current.box.Intersects( shape );
|
||||
return this->rigid.box.Intersects( shape );
|
||||
}
|
||||
|
||||
Sphere & SphericalRigidBody::GetBoundingSphere( Sphere &targetMem ) const
|
||||
|
@ -58,7 +81,7 @@ Sphere & SphericalRigidBody::GetBoundingSphere( Sphere &targetMem ) const
|
|||
Float3 & SphericalRigidBody::GetNormalAt( const Float3 &worldPos, Float3 &targetMem ) const
|
||||
{
|
||||
//! @todo TODO: better implementation needed
|
||||
return targetMem = (worldPos - this->current.box.center).GetNormalized();
|
||||
return targetMem = (worldPos - this->rigid.box.center).GetNormalized();
|
||||
}
|
||||
|
||||
Float3 & SphericalRigidBody::GetGravityNormal( Float3 &targetMem ) const
|
||||
|
@ -68,33 +91,44 @@ Float3 & SphericalRigidBody::GetGravityNormal( Float3 &targetMem ) const
|
|||
|
||||
Float3 & SphericalRigidBody::GetCenter( Float3 &targetMem ) const
|
||||
{
|
||||
return targetMem = this->current.box.center;
|
||||
return targetMem = this->rigid.box.center;
|
||||
}
|
||||
|
||||
Float4x4 & SphericalRigidBody::GetRotation( Float4x4 &targetMem ) const
|
||||
{
|
||||
return targetMem = this->current.box.rotation;
|
||||
return targetMem = this->rigid.box.rotation;
|
||||
}
|
||||
|
||||
Float4x4 & SphericalRigidBody::GetOrientation( Float4x4 &targetMem ) const
|
||||
{
|
||||
return targetMem = this->current.GetOrientation();
|
||||
return targetMem = this->rigid.GetOrientation();
|
||||
}
|
||||
|
||||
Float4x4 & SphericalRigidBody::GetView( Float4x4 &targetMem ) const
|
||||
{
|
||||
return targetMem = this->current.GetView();
|
||||
return targetMem = this->rigid.GetView();
|
||||
}
|
||||
|
||||
UpdateState SphericalRigidBody::Update( Float timeStepLength )
|
||||
{
|
||||
this->previous = this->current; // memorizing the old state
|
||||
|
||||
this->current.Update_LeapFrog( timeStepLength );
|
||||
this->body.center = this->current.GetCenter();
|
||||
this->rigid.Update_LeapFrog( timeStepLength );
|
||||
this->body.center = this->rigid.GetCenter();
|
||||
|
||||
// compare previous and new state and return result
|
||||
return this->current == this->previous ? resting : altered;
|
||||
//return this->current == this->previous ? UpdateState_resting : UpdateState_altered;
|
||||
return UpdateState_altered;
|
||||
}
|
||||
|
||||
void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_Collision functionPointer )
|
||||
{
|
||||
if( functionPointer )
|
||||
{
|
||||
this->collisionAction = functionPointer;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->collisionAction = Default::EventAction_Collision;
|
||||
}
|
||||
}
|
||||
|
||||
void SphericalRigidBody::SetGravity( bool ignore)
|
||||
|
@ -108,50 +142,45 @@ void SphericalRigidBody::SetGravityNormal( const Float3 &normalizedVector )
|
|||
this->gravityNormal = normalizedVector;
|
||||
}
|
||||
|
||||
void SphericalRigidBody::SetSubscription( bool subscribeCollision )
|
||||
{
|
||||
this->subscribeCollision = subscribeCollision;
|
||||
}
|
||||
|
||||
void SphericalRigidBody::SetMomentOfInertiaTensor_KeepVelocity( const Float4x4 &localI )
|
||||
{
|
||||
this->current.SetMomentOfInertia_KeepVelocity( localI );
|
||||
this->rigid.SetMomentOfInertia_KeepVelocity( localI );
|
||||
}
|
||||
|
||||
void SphericalRigidBody::SetMomentOfInertiaTensor_KeepMomentum( const Float4x4 &localI )
|
||||
{
|
||||
this->current.SetMomentOfInertia_KeepMomentum( localI );
|
||||
this->rigid.SetMomentOfInertia_KeepMomentum( localI );
|
||||
}
|
||||
|
||||
void SphericalRigidBody::SetMass_KeepVelocity( Float m )
|
||||
{
|
||||
this->current.SetMass_KeepVelocity( m );
|
||||
this->rigid.SetMass_KeepVelocity( m );
|
||||
}
|
||||
|
||||
void SphericalRigidBody::SetMass_KeepMomentum( Float m )
|
||||
{
|
||||
this->current.SetMass_KeepMomentum( m );
|
||||
this->rigid.SetMass_KeepMomentum( m );
|
||||
}
|
||||
|
||||
void SphericalRigidBody::SetCenter( const Float3 &worldPos )
|
||||
{
|
||||
this->current.SetCenter( worldPos );
|
||||
this->rigid.SetCenter( worldPos );
|
||||
this->body.center = worldPos;
|
||||
}
|
||||
|
||||
void SphericalRigidBody::SetRotation( const Float4x4 &rotation )
|
||||
{
|
||||
this->current.SetRotation( rotation );
|
||||
this->rigid.SetRotation( rotation );
|
||||
}
|
||||
|
||||
void SphericalRigidBody::SetOrientation( const Float4x4 &orientation )
|
||||
{
|
||||
this->current.SetOrientation( orientation );
|
||||
this->rigid.SetOrientation( orientation );
|
||||
this->body.center = orientation.v[3].xyz;
|
||||
}
|
||||
|
||||
void SphericalRigidBody::SetSize( const Float3 &size )
|
||||
{
|
||||
this->current.SetSize( size );
|
||||
this->rigid.SetSize( size );
|
||||
this->body.radius = 0.5f * Min( Min( size.x, size.y ), size.z ); // inline Min( FloatN )?
|
||||
}
|
|
@ -11,11 +11,12 @@ namespace Oyster { namespace Physics
|
|||
{
|
||||
public:
|
||||
SphericalRigidBody();
|
||||
SphericalRigidBody( const API::SphericalBodyDescription &desc );
|
||||
virtual ~SphericalRigidBody();
|
||||
|
||||
::Utility::DynamicMemory::UniquePointer<ICustomBody> Clone() const;
|
||||
|
||||
bool IsSubscribingCollisions() const;
|
||||
void CallSubscription( const ICustomBody *proto, const ICustomBody *deuter );
|
||||
bool IsAffectedByGravity() const;
|
||||
bool Intersects( const ICustomBody &object, ::Oyster::Math::Float timeStepLength, ::Oyster::Math::Float &deltaWhen, ::Oyster::Math::Float3 &worldPointOfContact ) const;
|
||||
bool Intersects( const ::Oyster::Collision3D::ICollideable &shape ) const;
|
||||
|
@ -30,9 +31,9 @@ namespace Oyster { namespace Physics
|
|||
|
||||
UpdateState Update( ::Oyster::Math::Float timeStepLength );
|
||||
|
||||
void SetSubscription( EventAction_Collision functionPointer );
|
||||
void SetGravity( bool ignore);
|
||||
void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector );
|
||||
void SetSubscription( bool subscribeCollision );
|
||||
void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI );
|
||||
void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI );
|
||||
void SetMass_KeepVelocity( ::Oyster::Math::Float m );
|
||||
|
@ -43,9 +44,10 @@ namespace Oyster { namespace Physics
|
|||
void SetSize( const ::Oyster::Math::Float3 &size );
|
||||
|
||||
private:
|
||||
::Oyster::Physics3D::RigidBody previous, current;
|
||||
::Oyster::Physics3D::RigidBody rigid;
|
||||
::Oyster::Math::Float3 gravityNormal;
|
||||
bool subscribeCollision, ignoreGravity;
|
||||
EventAction_Collision collisionAction;
|
||||
bool ignoreGravity;
|
||||
::Oyster::Collision3D::Sphere body;
|
||||
};
|
||||
} }
|
||||
|
|
|
@ -19,8 +19,8 @@ namespace Oyster
|
|||
|
||||
enum UpdateState
|
||||
{
|
||||
resting,
|
||||
altered
|
||||
UpdateState_resting,
|
||||
UpdateState_altered
|
||||
};
|
||||
|
||||
namespace Constant
|
||||
|
@ -45,7 +45,9 @@ namespace Oyster
|
|||
class PHYSICS_DLL_USAGE API
|
||||
{
|
||||
public:
|
||||
typedef void (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter );
|
||||
struct SimpleBodyDescription;
|
||||
struct SphericalBodyDescription;
|
||||
|
||||
typedef void (*EventAction_Destruction)( ::Utility::DynamicMemory::UniquePointer<ICustomBody> proto );
|
||||
|
||||
/** Gets the Physics instance. */
|
||||
|
@ -62,7 +64,7 @@ namespace Oyster
|
|||
/********************************************************
|
||||
* Sets the time length of each physics update frame.
|
||||
********************************************************/
|
||||
virtual void SetDeltaTime( float seconds ) = 0;
|
||||
virtual void SetFrameTimeLength( float seconds ) = 0;
|
||||
|
||||
/********************************************************
|
||||
* Sets the Gravityconstant in the physics that will be
|
||||
|
@ -71,19 +73,14 @@ namespace Oyster
|
|||
********************************************************/
|
||||
virtual void SetGravityConstant( float g ) = 0;
|
||||
|
||||
/********************************************************
|
||||
* Sets the function that will be called by the engine
|
||||
* whenever a subscribed collision occurs.
|
||||
********************************************************/
|
||||
virtual void SetAction( EventAction_Collision functionPointer ) = 0;
|
||||
|
||||
/********************************************************
|
||||
* Sets the function that will be called by the engine
|
||||
* whenever an object is being destroyed for some reason.
|
||||
* - Because DestroyObject(...) were called.
|
||||
* - Out of memory forced engine to destroy an object.
|
||||
* @param functionPointer: If NULL, an empty default function will be set.
|
||||
********************************************************/
|
||||
virtual void SetAction( EventAction_Destruction functionPointer ) = 0;
|
||||
virtual void SetSubscription( EventAction_Destruction functionPointer ) = 0;
|
||||
|
||||
/********************************************************
|
||||
* Triggers the engine to run next update frame.
|
||||
|
@ -213,9 +210,17 @@ namespace Oyster
|
|||
|
||||
/********************************************************
|
||||
* Creates a new dynamically allocated object that can be used as a component for more complex ICustomBodies.
|
||||
* @param desc: @see API::SimpleBodyDescription
|
||||
* @return A pointer along with the responsibility to delete.
|
||||
********************************************************/
|
||||
virtual ::Utility::DynamicMemory::UniquePointer<ICustomBody> CreateSimpleRigidBody() const = 0;
|
||||
virtual ::Utility::DynamicMemory::UniquePointer<ICustomBody> CreateRigidBody( const SimpleBodyDescription &desc ) const = 0;
|
||||
|
||||
/********************************************************
|
||||
* Creates a new dynamically allocated object that can be used as a component for more complex ICustomBodies.
|
||||
* @param desc: @see API::SphericalBodyDescription
|
||||
* @return A pointer along with the responsibility to delete.
|
||||
********************************************************/
|
||||
virtual ::Utility::DynamicMemory::UniquePointer<ICustomBody> CreateRigidBody( const SphericalBodyDescription &desc ) const = 0;
|
||||
|
||||
protected:
|
||||
virtual ~API() {}
|
||||
|
@ -225,6 +230,14 @@ namespace Oyster
|
|||
class PHYSICS_DLL_USAGE ICustomBody
|
||||
{
|
||||
public:
|
||||
enum SubscriptMessage
|
||||
{
|
||||
SubscriptMessage_none,
|
||||
SubscriptMessage_ignore_collision_response
|
||||
};
|
||||
|
||||
typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter );
|
||||
|
||||
virtual ~ICustomBody() {};
|
||||
|
||||
/********************************************************
|
||||
|
@ -234,9 +247,9 @@ namespace Oyster
|
|||
virtual ::Utility::DynamicMemory::UniquePointer<ICustomBody> Clone() const = 0;
|
||||
|
||||
/********************************************************
|
||||
* @return true if Engine should call the EventAction_Collision function.
|
||||
* @todo TODO: need doc
|
||||
********************************************************/
|
||||
virtual bool IsSubscribingCollisions() const = 0;
|
||||
virtual void CallSubscription( const ICustomBody *proto, const ICustomBody *deuter ) = 0;
|
||||
|
||||
/********************************************************
|
||||
* @return true if Engine should apply gravity on this object.
|
||||
|
@ -312,6 +325,13 @@ namespace Oyster
|
|||
********************************************************/
|
||||
virtual UpdateState Update( ::Oyster::Math::Float timeStepLength ) = 0;
|
||||
|
||||
/********************************************************
|
||||
* Sets the function that will be called by the engine
|
||||
* whenever a collision occurs.
|
||||
* @param functionPointer: If NULL, an empty default function will be set.
|
||||
********************************************************/
|
||||
virtual void SetSubscription( EventAction_Collision functionPointer ) = 0;
|
||||
|
||||
/********************************************************
|
||||
* @param ignore: True if Engine should not apply Gravity.
|
||||
********************************************************/
|
||||
|
@ -323,11 +343,6 @@ namespace Oyster
|
|||
********************************************************/
|
||||
virtual void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector ) = 0;
|
||||
|
||||
/********************************************************
|
||||
* @param subscribeCollision: If is true, engine will call EventAction_Collision when this collides.
|
||||
********************************************************/
|
||||
virtual void SetSubscription( bool subscribeCollision ) = 0;
|
||||
|
||||
/********************************************************
|
||||
* To not be called if is in Engine
|
||||
* Use API::SetMomentOfInertiaTensor_KeepVelocity(...) instead
|
||||
|
@ -376,6 +391,48 @@ namespace Oyster
|
|||
********************************************************/
|
||||
virtual void SetSize( const ::Oyster::Math::Float3 &size ) = 0;
|
||||
};
|
||||
|
||||
struct API::SimpleBodyDescription
|
||||
{
|
||||
::Oyster::Math::Float4x4 rotation;
|
||||
::Oyster::Math::Float3 centerPosition;
|
||||
::Oyster::Math::Float3 size;
|
||||
::Oyster::Math::Float mass;
|
||||
::Oyster::Math::Float4x4 inertiaTensor;
|
||||
ICustomBody::EventAction_Collision subscription;
|
||||
bool ignoreGravity;
|
||||
|
||||
SimpleBodyDescription()
|
||||
{
|
||||
this->rotation = ::Oyster::Math::Float4x4::identity;
|
||||
this->centerPosition = ::Oyster::Math::Float3::null;
|
||||
this->size = ::Oyster::Math::Float3( 1.0f );
|
||||
this->mass = 12.0f;
|
||||
this->inertiaTensor = ::Oyster::Math::Float4x4::identity;
|
||||
this->subscription = NULL;
|
||||
this->ignoreGravity = false;
|
||||
}
|
||||
};
|
||||
|
||||
struct API::SphericalBodyDescription
|
||||
{
|
||||
::Oyster::Math::Float4x4 rotation;
|
||||
::Oyster::Math::Float3 centerPosition;
|
||||
::Oyster::Math::Float radius;
|
||||
::Oyster::Math::Float mass;
|
||||
ICustomBody::EventAction_Collision subscription;
|
||||
bool ignoreGravity;
|
||||
|
||||
SphericalBodyDescription()
|
||||
{
|
||||
this->rotation = ::Oyster::Math::Float4x4::identity;
|
||||
this->centerPosition = ::Oyster::Math::Float3::null;
|
||||
this->radius = 0.5f;
|
||||
this->mass = 10.0f;
|
||||
this->subscription = NULL;
|
||||
this->ignoreGravity = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -18,13 +18,19 @@
|
|||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="L_inputClass.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="L_inputClass.h" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{7E3990D2-3D94-465C-B58D-64A74B3ECF9B}</ProjectGuid>
|
||||
<RootNamespace>Input</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
|
|
|
@ -14,4 +14,14 @@
|
|||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="L_inputClass.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="L_inputClass.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,200 @@
|
|||
#include "L_inputclass.h"
|
||||
|
||||
InputClass::InputClass()
|
||||
{
|
||||
m_directInput = NULL;
|
||||
m_keyboard = NULL;
|
||||
m_mouse = NULL;
|
||||
}
|
||||
|
||||
InputClass::~InputClass()
|
||||
{
|
||||
// Release the mouse.
|
||||
if(m_mouse)
|
||||
{
|
||||
(m_mouse)->Unacquire();
|
||||
(m_mouse)->Release();
|
||||
(m_mouse) = NULL;
|
||||
}
|
||||
//SAFE_UNACQUIRE(m_mouse);
|
||||
|
||||
// Release the keyboard.
|
||||
if(m_keyboard)
|
||||
{
|
||||
(m_keyboard)->Unacquire();
|
||||
(m_keyboard)->Release();
|
||||
(m_keyboard) = NULL;
|
||||
}
|
||||
//SAFE_UNACQUIRE(m_keyboard);
|
||||
|
||||
// Release the main interface to direct input.
|
||||
if( m_directInput )
|
||||
{
|
||||
(m_directInput)->Release();
|
||||
(m_directInput) = NULL;
|
||||
}
|
||||
//SAFE_RELEASE(m_directInput);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool InputClass::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, int screenHeight)
|
||||
{
|
||||
HRESULT result;
|
||||
|
||||
// Initialize the main direct input interface.
|
||||
result = DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_directInput, NULL);
|
||||
if(FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Initialize the direct input interface for the keyboard.
|
||||
result = m_directInput->CreateDevice(GUID_SysKeyboard, &m_keyboard, NULL);
|
||||
if(FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the cooperative level of the keyboard to not share with other programs.
|
||||
result = m_keyboard->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
|
||||
if(FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Set the data format. In this case since it is a keyboard we can use the predefined data format.
|
||||
result = m_keyboard->SetDataFormat(&c_dfDIKeyboard);
|
||||
if(FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now acquire the keyboard.
|
||||
result = m_keyboard->Acquire();
|
||||
if(FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Initialize the direct input interface for the mouse.
|
||||
result = m_directInput->CreateDevice(GUID_SysMouse, &m_mouse, NULL);
|
||||
if(FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the data format for the mouse using the pre-defined mouse data format.
|
||||
result = m_mouse->SetDataFormat(&c_dfDIMouse);
|
||||
if(FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the cooperative level of the mouse to share with other programs.
|
||||
result = m_mouse->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
|
||||
if(FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Acquire the mouse.
|
||||
result = m_mouse->Acquire();
|
||||
if(FAILED(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InputClass::Update()
|
||||
{
|
||||
bool result;
|
||||
|
||||
//Read the current state of the keyboard.
|
||||
result = ReadKeyboard();
|
||||
if(!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the current state of the mouse.
|
||||
result = ReadMouse();
|
||||
if(!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InputClass::ReadKeyboard()
|
||||
{
|
||||
HRESULT result;
|
||||
|
||||
// Read the keyboard device.
|
||||
result = m_keyboard->GetDeviceState(sizeof(m_keyboardState), (LPVOID)&m_keyboardState);
|
||||
if(FAILED(result))
|
||||
{
|
||||
// If the keyboard lost focus or was not acquired then try to get control back.
|
||||
if((result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED))
|
||||
{
|
||||
m_keyboard->Acquire();
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InputClass::ReadMouse()
|
||||
{
|
||||
HRESULT result;
|
||||
|
||||
// Read the mouse device.
|
||||
result = m_mouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&m_mouseState);
|
||||
if(FAILED(result))
|
||||
{
|
||||
// If the mouse lost focus or was not acquired then try to get control back.
|
||||
if((result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED))
|
||||
{
|
||||
m_mouse->Acquire();
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
float InputClass::GetPitch( )
|
||||
{
|
||||
float dy = (static_cast<float>( m_mouseState.lY)/5);
|
||||
return -dy;
|
||||
}
|
||||
float InputClass::GetYaw( )
|
||||
{
|
||||
float dX = (static_cast<float>( m_mouseState.lX)/5);
|
||||
return -dX;
|
||||
}
|
||||
|
||||
bool InputClass::IsMousePressed()
|
||||
{
|
||||
if (m_mouseState.rgbButtons[0])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool InputClass::IsKeyPressed(int key)
|
||||
{
|
||||
if( m_keyboardState[key] & 0x80 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
// Temp input handler, not stable!
|
||||
// When starting the program, don't click anywhere until the program starts
|
||||
// because that breaks the input..
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _INPUTCLASS_H_
|
||||
#define _INPUTCLASS_H_
|
||||
|
||||
|
||||
#define DIRECTINPUT_VERSION 0x0800
|
||||
|
||||
#pragma comment(lib, "dinput8.lib")
|
||||
#pragma comment(lib, "dxguid.lib")
|
||||
|
||||
#include <dinput.h>
|
||||
|
||||
|
||||
|
||||
class InputClass
|
||||
{
|
||||
private:
|
||||
IDirectInput8* m_directInput;
|
||||
IDirectInputDevice8* m_keyboard;
|
||||
IDirectInputDevice8* m_mouse;
|
||||
|
||||
unsigned char m_keyboardState[256];
|
||||
DIMOUSESTATE m_mouseState;
|
||||
|
||||
bool ReadKeyboard();
|
||||
bool ReadMouse();
|
||||
|
||||
public:
|
||||
|
||||
InputClass();
|
||||
~InputClass();
|
||||
|
||||
// Initialize DirectInput8Create and acquire the mouse and keyboard
|
||||
bool Initialize(HINSTANCE, HWND, int, int);
|
||||
|
||||
//read the mouse and keyboard and send back
|
||||
// delta mouse pos and if any button is pressed
|
||||
bool Update();
|
||||
|
||||
bool IsKeyPressed(int key);
|
||||
bool IsMousePressed();
|
||||
|
||||
// Call if mouse is pressed
|
||||
float GetYaw();
|
||||
float GetPitch();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef I_QUEUE_H
|
||||
#define I_QUEUE_H
|
||||
|
||||
/////////////////////////////////
|
||||
// Created by Sam Svensson 2013//
|
||||
/////////////////////////////////
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Queue
|
||||
{
|
||||
template <typename Type>
|
||||
class IQueue
|
||||
{
|
||||
public:
|
||||
|
||||
//---------------------------------------------
|
||||
//standard operations of the std::queue
|
||||
//---------------------------------------------
|
||||
virtual ~IQueue() {};
|
||||
virtual void Push( Type item ) = 0;
|
||||
virtual Type Pop() = 0;
|
||||
|
||||
virtual Type Front() = 0;
|
||||
virtual Type Back() = 0;
|
||||
|
||||
virtual int Size() = 0;
|
||||
virtual bool IsEmpty() = 0;
|
||||
|
||||
virtual void Swap( IQueue<Type> &queue ) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -156,12 +156,14 @@
|
|||
<ClCompile Include="WinTimer.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="IQueue.h" />
|
||||
<ClInclude Include="Resource\OysterResource.h" />
|
||||
<ClInclude Include="Resource\OResource.h" />
|
||||
<ClInclude Include="ThreadSafeQueue.h" />
|
||||
<ClInclude Include="Thread\IThreadObject.h" />
|
||||
<ClInclude Include="Thread\OysterMutex.h" />
|
||||
<ClInclude Include="Thread\OysterThread.h" />
|
||||
<ClInclude Include="Utilities-InlineImpl.h" />
|
||||
<ClInclude Include="Utilities-Impl.h" />
|
||||
<ClInclude Include="Utilities.h" />
|
||||
<ClInclude Include="WinTimer.h" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -27,12 +27,24 @@
|
|||
<ClCompile Include="Resource\OResourceHandler.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Thread\OysterMutex.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Thread\OysterThread_Impl.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Resource\Loaders\ByteLoader.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Resource\Loaders\CustomLoader.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Thread\OysterMutex.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Thread\OysterThread_Impl.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Utilities.h">
|
||||
|
@ -41,14 +53,38 @@
|
|||
<ClInclude Include="WinTimer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Utilities-InlineImpl.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resource\OysterResource.h">
|
||||
<ClInclude Include="Utilities-Impl.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resource\OResource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resource\OysterResource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Thread\IThreadObject.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Thread\OysterMutex.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Thread\OysterThread.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Thread\IThreadObject.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Thread\OysterMutex.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Thread\OysterThread.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="IQueue.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ThreadSafeQueue.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,72 +0,0 @@
|
|||
<?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;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;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>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Utilities.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="WinTimer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Resource\OResource.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Resource\OResourceHandler.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Resource\Loaders\ByteLoader.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Resource\Loaders\CustomLoader.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<ClCompile Include="Thread\OysterMutex.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Thread\OysterThread_Impl.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
>>>>>>> 48c812b0338b859aa6c00c8504dd2f16a4bb44f9
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Utilities.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="WinTimer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Utilities-InlineImpl.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resource\OysterResource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resource\OResource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Thread\IThreadObject.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Thread\OysterMutex.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Thread\OysterThread.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,6 +1,3 @@
|
|||
/////////////////////////////////////////////////////////////////////
|
||||
// Created by [Dennis Andersen] [2013]
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "..\OResource.h"
|
||||
#include "..\..\Utilities.h"
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
/////////////////////////////////////////////////////////////////////
|
||||
// Created by [Dennis Andersen] [2013]
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "OResource.h"
|
||||
|
||||
using namespace Oyster::Resource;
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace Oyster
|
|||
ResourceType_Byte_UNICODE, /**< Handle can be interpeted as char[] or char* */
|
||||
ResourceType_Byte_UTF16LE, /**< Handle can be interpeted as char[] or char* */
|
||||
|
||||
ResourceType_COUNT, /**< Not used. */
|
||||
ResourceType_COUNT, /**< Handle can be interpeted as ? */
|
||||
|
||||
ResourceType_UNKNOWN = -1, /**< Handle can be interpeted as void* */
|
||||
ResourceType_INVALID = -2, /**< Invalid or non existing resource */
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include <thread>
|
||||
#include <future>
|
||||
|
||||
using namespace Oyster::Thread;
|
||||
|
||||
|
||||
OysterMutex::OysterMutex()
|
||||
|
|
|
@ -9,10 +9,6 @@
|
|||
#include <thread>
|
||||
#include <atomic>
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Thread
|
||||
{
|
||||
class OysterMutex
|
||||
{
|
||||
public:
|
||||
|
@ -31,7 +27,5 @@ namespace Oyster
|
|||
|
||||
OysterMutex(const OysterMutex&);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !MISC_OYSTER_MUTEX_H
|
||||
|
|
|
@ -10,14 +10,14 @@
|
|||
#include <atomic>
|
||||
|
||||
using namespace Oyster::Thread;
|
||||
using namespace Utility::DynamicMemory::SmartPointer;
|
||||
using namespace Utility::DynamicMemory;
|
||||
|
||||
|
||||
#pragma region Declerations
|
||||
|
||||
struct ThreadData;
|
||||
/** A typical Oyster thread function */
|
||||
typedef void (*ThreadFunction)(StdSmartPointer<ThreadData>&);
|
||||
typedef void (*ThreadFunction)(SmartPointer<ThreadData>&);
|
||||
|
||||
enum OYSTER_THREAD_STATE
|
||||
{
|
||||
|
@ -32,12 +32,13 @@ using namespace Utility::DynamicMemory::SmartPointer;
|
|||
struct ThreadData
|
||||
{
|
||||
std::atomic<OYSTER_THREAD_STATE> state; //<! The current thread state.
|
||||
//OYSTER_THREAD_STATE state; //<! The current thread state.
|
||||
StdSmartPointer<std::thread> workerThread; //<! The worker thread.
|
||||
SmartPointer<std::thread> workerThread; //<! The worker thread.
|
||||
std::thread::id callingThread; //<! The owner thread.
|
||||
IThreadObject *owner; //<! The owner of the thread as IThread.
|
||||
std::atomic<int> msec; //<! A timer in miliseconds.
|
||||
|
||||
//OysterMutex mutexLock; //<! The lock, locking the member variabls.
|
||||
//OYSTER_THREAD_STATE state; //<! The current thread state.
|
||||
|
||||
ThreadData() {}
|
||||
~ThreadData() {}
|
||||
|
@ -45,7 +46,7 @@ using namespace Utility::DynamicMemory::SmartPointer;
|
|||
};
|
||||
struct OysterThread::PrivateData
|
||||
{
|
||||
StdSmartPointer<ThreadData> threadData;
|
||||
SmartPointer<ThreadData> threadData;
|
||||
|
||||
PrivateData()
|
||||
:threadData(new ThreadData())
|
||||
|
@ -76,11 +77,11 @@ using namespace Utility::DynamicMemory::SmartPointer;
|
|||
|
||||
int tempId = 0;
|
||||
std::vector<int> IDS;
|
||||
static void ThreadingFunction(StdSmartPointer<ThreadData> &origin)
|
||||
static void ThreadingFunction(SmartPointer<ThreadData> &origin)
|
||||
{
|
||||
|
||||
bool shouldContinue;
|
||||
StdSmartPointer<ThreadData> w = origin;
|
||||
SmartPointer<ThreadData> w = origin;
|
||||
|
||||
theBegining:
|
||||
|
||||
|
|
|
@ -0,0 +1,218 @@
|
|||
#ifndef THREAD_SAFE_QUEUE_H
|
||||
#define THREAD_SAFE_QUEUE_H
|
||||
|
||||
////////////////////////////////////////////
|
||||
// Thread safe queue implemented
|
||||
// with single linked list and template.
|
||||
// uses mutex to lock the queue
|
||||
// otherwise its a standard queue
|
||||
// Created by Sam Svensson 2013
|
||||
/////////////////////////////////////////////
|
||||
|
||||
#include "IQueue.h"
|
||||
#include "Thread/OysterMutex.h"
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Queue
|
||||
{
|
||||
template <typename Type>
|
||||
class ThreadSafeQueue : public IQueue<Type>
|
||||
{
|
||||
public:
|
||||
ThreadSafeQueue<Type>();
|
||||
virtual ~ThreadSafeQueue<Type>();
|
||||
|
||||
virtual void Push( Type item );
|
||||
virtual Type Pop();
|
||||
|
||||
virtual Type Front();
|
||||
virtual Type Back();
|
||||
|
||||
virtual int Size();
|
||||
virtual bool IsEmpty();
|
||||
virtual void Swap( IQueue<Type> &queue );
|
||||
|
||||
private:
|
||||
class Node
|
||||
{
|
||||
public:
|
||||
Type item;
|
||||
Node *next;
|
||||
Node(Type item){ this->item = item; this->next = NULL; };
|
||||
~Node() {};
|
||||
};
|
||||
|
||||
Node *front;
|
||||
Node *back;
|
||||
int nrOfNodes;
|
||||
OysterMutex mutex;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------
|
||||
//implemented template functions
|
||||
//----------------------------------------------
|
||||
|
||||
template < typename Type >
|
||||
ThreadSafeQueue<Type>::ThreadSafeQueue()
|
||||
{
|
||||
this->front = NULL;
|
||||
this->back = NULL;
|
||||
this->nrOfNodes = 0;
|
||||
|
||||
}
|
||||
|
||||
template < typename Type >
|
||||
ThreadSafeQueue<Type>::~ThreadSafeQueue()
|
||||
{
|
||||
this->mutex.LockMutex();
|
||||
|
||||
if(this->front != NULL)
|
||||
{
|
||||
Node *destroyer;
|
||||
Node *walker = this->front;
|
||||
|
||||
for(int i = 0; i < this->nrOfNodes; i++)
|
||||
{
|
||||
destroyer = walker;
|
||||
walker = walker->next;
|
||||
|
||||
delete destroyer;
|
||||
}
|
||||
|
||||
this->front = NULL;
|
||||
this->back = NULL;
|
||||
}
|
||||
|
||||
this->mutex.UnlockMutex();
|
||||
}
|
||||
|
||||
|
||||
template < typename Type >
|
||||
void ThreadSafeQueue<Type>::Push(Type item)
|
||||
{
|
||||
Node *e = new Node(item);
|
||||
|
||||
mutex.LockMutex();
|
||||
if(this->front != NULL)
|
||||
{
|
||||
this->back->next = e;
|
||||
this->back = e;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
this->front = e;
|
||||
this->back = e;
|
||||
}
|
||||
|
||||
this->nrOfNodes++;
|
||||
|
||||
mutex.UnlockMutex();
|
||||
}
|
||||
|
||||
template < typename Type >
|
||||
Type ThreadSafeQueue<Type>::Pop()
|
||||
{
|
||||
mutex.LockMutex();
|
||||
if(this->front != NULL)
|
||||
{
|
||||
Type item = this->front->item;
|
||||
Node *destroyer = this->front;
|
||||
this->front = front->next;
|
||||
|
||||
delete destroyer;
|
||||
this->nrOfNodes--;
|
||||
|
||||
if(nrOfNodes == 0)
|
||||
{
|
||||
this->front = NULL;
|
||||
this->back = NULL;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
mutex.UnlockMutex();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
template < typename Type >
|
||||
Type ThreadSafeQueue<Type>::Front()
|
||||
{
|
||||
mutex.LockMutex();
|
||||
if(front != NULL)
|
||||
{
|
||||
return this->front->item;
|
||||
}
|
||||
mutex.UnlockMutex();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
template < typename Type >
|
||||
Type ThreadSafeQueue<Type>::Back()
|
||||
{
|
||||
mutex.LockMutex();
|
||||
if(back != NULL)
|
||||
{
|
||||
return this->back->item;
|
||||
}
|
||||
mutex.UnlockMutex();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
template < typename Type >
|
||||
int ThreadSafeQueue<Type>::Size()
|
||||
{
|
||||
//? behövs denna låsas?
|
||||
mutex.LockMutex();
|
||||
return this->nrOfNodes;
|
||||
mutex.UnlockMutex();
|
||||
}
|
||||
|
||||
template < typename Type >
|
||||
bool ThreadSafeQueue<Type>::IsEmpty()
|
||||
{
|
||||
mutex.LockMutex();
|
||||
if(nrOfNodes == 0 && this->front == NULL)
|
||||
{
|
||||
mutex.UnlockMutex();
|
||||
return true;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
mutex.UnlockMutex();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template < typename Type >
|
||||
void ThreadSafeQueue<Type>::Swap(IQueue<Type> &queue )
|
||||
{
|
||||
mutex.LockMutex();
|
||||
int prevNrOfNodes = this->nrOfNodes;
|
||||
int size = queue.Size();
|
||||
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
this->Push(queue.Pop());
|
||||
}
|
||||
|
||||
for(int i = 0; i < prevNrOfNodes; i++)
|
||||
{
|
||||
queue.Push(this->Pop());
|
||||
}
|
||||
mutex.UnlockMutex();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
/////////////////////////////////////////////////////////////////////
|
||||
// Inline and template implementations for
|
||||
// the Utility Collection of Miscellanious Handy Functions
|
||||
// © Dan Andersson 2013
|
||||
// © Dennis Andersen 2013 TODO: Is this correct?
|
||||
//
|
||||
// Created 2013 by Dan Andersson
|
||||
// Edited 2013 by
|
||||
// * Dan Andersson
|
||||
// * Dennis Andersen
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef UTILITIES_INLINE_IMPL_H
|
||||
|
@ -32,6 +35,7 @@ namespace Utility
|
|||
}
|
||||
}
|
||||
|
||||
#pragma region UnuiqePointer
|
||||
template<typename Type>
|
||||
UniquePointer<Type>::UniquePointer( Type *assignedInstance )
|
||||
{
|
||||
|
@ -39,17 +43,17 @@ namespace Utility
|
|||
}
|
||||
|
||||
template<typename Type>
|
||||
UniquePointer<Type>::~UniquePointer()
|
||||
UniquePointer<Type>::UniquePointer( const UniquePointer<Type> &donor )
|
||||
{
|
||||
SafeDeleteInstance( this->ownedInstance );
|
||||
this->ownedInstance = donor.ownedInstance;
|
||||
donor.ownedInstance = NULL;
|
||||
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
UniquePointer<Type> & UniquePointer<Type>::operator = ( Type *assignedInstance )
|
||||
UniquePointer<Type>::~UniquePointer()
|
||||
{
|
||||
SafeDeleteInstance( this->ownedInstance );
|
||||
this->ownedInstance = assignedInstance;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
|
@ -91,6 +95,18 @@ namespace Utility
|
|||
return this->ownedInstance != NULL;
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
bool UniquePointer<Type>::operator == ( Type *stray ) const
|
||||
{
|
||||
return this->ownedInstance == stray;
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
bool UniquePointer<Type>::operator != ( Type *stray ) const
|
||||
{
|
||||
return this->ownedInstance != stray;
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
Type* UniquePointer<Type>::Release()
|
||||
{
|
||||
|
@ -112,16 +128,17 @@ namespace Utility
|
|||
}
|
||||
|
||||
template<typename Type>
|
||||
UniqueArray<Type>::~UniqueArray()
|
||||
UniqueArray<Type>::UniqueArray( const UniqueArray<Type> &donor )
|
||||
{
|
||||
SafeDeleteArray( this->ownedArray );
|
||||
this->ownedArray = donor.ownedArray;
|
||||
donor.ownedArray = NULL;
|
||||
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
UniqueArray<Type> & UniqueArray<Type>::operator = ( Type assignedArray[] )
|
||||
UniqueArray<Type>::~UniqueArray()
|
||||
{
|
||||
SafeDeleteArray( this->ownedArray );
|
||||
this->ownedArray = assignedArray;
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
|
@ -150,7 +167,20 @@ namespace Utility
|
|||
return this->ownedArray != NULL;
|
||||
}
|
||||
|
||||
template<typename Type>Type* UniqueArray<Type>::Release()
|
||||
template<typename Type>
|
||||
bool UniqueArray<Type>::operator == ( Type *stray ) const
|
||||
{
|
||||
return this->ownedArray == stray;
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
bool UniqueArray<Type>::operator != ( Type *stray ) const
|
||||
{
|
||||
return this->ownedArray != stray;
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
Type* UniqueArray<Type>::Release()
|
||||
{
|
||||
Type *copy = this->ownedArray;
|
||||
this->ownedArray = NULL;
|
||||
|
@ -162,39 +192,42 @@ namespace Utility
|
|||
{
|
||||
return this->operator bool();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
namespace SmartPointer
|
||||
{
|
||||
template<typename T> void StdSmartPointer<T>::Destroy()
|
||||
#pragma region SmartPointer
|
||||
template<typename T> void SmartPointer<T>::Destroy()
|
||||
{
|
||||
delete this->_rc;
|
||||
this->_rc = NULL;
|
||||
delete this->_ptr;
|
||||
|
||||
//Use default function for memory deallocation.
|
||||
SafeDeleteInstance<T>(this->_ptr);
|
||||
|
||||
this->_ptr = NULL;
|
||||
}
|
||||
template<typename T> StdSmartPointer<T>::StdSmartPointer()
|
||||
template<typename T> SmartPointer<T>::SmartPointer()
|
||||
:_rc(0), _ptr(0)
|
||||
{ }
|
||||
template<typename T> StdSmartPointer<T>::StdSmartPointer(T* p)
|
||||
template<typename T> SmartPointer<T>::SmartPointer(T* p)
|
||||
:_ptr(p)
|
||||
{
|
||||
this->_rc = new ReferenceCount();
|
||||
this->_rc->Incref();
|
||||
}
|
||||
template<typename T> StdSmartPointer<T>::StdSmartPointer(const StdSmartPointer& d)
|
||||
template<typename T> SmartPointer<T>::SmartPointer(const SmartPointer& d)
|
||||
:_ptr(d._ptr), _rc(d._rc)
|
||||
{
|
||||
if(this->_rc)
|
||||
this->_rc->Incref();
|
||||
}
|
||||
template<typename T> StdSmartPointer<T>::~StdSmartPointer()
|
||||
template<typename T> SmartPointer<T>::~SmartPointer()
|
||||
{
|
||||
if (this->_rc && this->_rc->Decref() == 0)
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
}
|
||||
template<typename T> StdSmartPointer<T>& StdSmartPointer<T>::operator= (const StdSmartPointer<T>& p)
|
||||
template<typename T> SmartPointer<T>& SmartPointer<T>::operator= (const SmartPointer<T>& p)
|
||||
{
|
||||
if (this != &p)
|
||||
{
|
||||
|
@ -211,7 +244,7 @@ namespace Utility
|
|||
}
|
||||
return *this;
|
||||
}
|
||||
template<typename T> StdSmartPointer<T>& StdSmartPointer<T>::operator= (T* p)
|
||||
template<typename T> SmartPointer<T>& SmartPointer<T>::operator= (T* p)
|
||||
{
|
||||
if (this->_ptr != p)
|
||||
{
|
||||
|
@ -233,39 +266,40 @@ namespace Utility
|
|||
}
|
||||
return *this;
|
||||
}
|
||||
template<typename T> inline bool StdSmartPointer<T>::operator== (const StdSmartPointer<T>& d)
|
||||
template<typename T> inline bool SmartPointer<T>::operator== (const SmartPointer<T>& d)
|
||||
{
|
||||
return d._ptr == this->_ptr;
|
||||
}
|
||||
template<typename T> inline bool StdSmartPointer<T>::operator== (const T& p)
|
||||
template<typename T> inline bool SmartPointer<T>::operator== (const T& p)
|
||||
{
|
||||
return &p == this->_ptr;
|
||||
}
|
||||
template<typename T> inline T& StdSmartPointer<T>::operator* ()
|
||||
template<typename T> inline T& SmartPointer<T>::operator* ()
|
||||
{
|
||||
return *this->_ptr;
|
||||
}
|
||||
template<typename T> inline T* StdSmartPointer<T>::operator-> ()
|
||||
template<typename T> inline T* SmartPointer<T>::operator-> ()
|
||||
{
|
||||
return this->_ptr;
|
||||
}
|
||||
template<typename T> inline StdSmartPointer<T>::operator T* ()
|
||||
template<typename T> inline SmartPointer<T>::operator T* ()
|
||||
{
|
||||
return this->_ptr;
|
||||
}
|
||||
template<typename T> inline StdSmartPointer<T>::operator bool()
|
||||
template<typename T> inline SmartPointer<T>::operator bool()
|
||||
{
|
||||
return (this->_ptr != 0);
|
||||
}
|
||||
template<typename T> inline T* StdSmartPointer<T>::Get()
|
||||
template<typename T> inline T* SmartPointer<T>::Get()
|
||||
{
|
||||
return this->_ptr;
|
||||
}
|
||||
template<typename T> inline bool StdSmartPointer<T>::IsValid()
|
||||
template<typename T> inline bool SmartPointer<T>::IsValid()
|
||||
{
|
||||
return (this->_ptr != NULL) ? true : false;
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Utility Collection of Miscellanious Handy Functions
|
||||
// © Dan Andersson 2013
|
||||
// © Dennis Andersen 2013
|
||||
|
||||
//
|
||||
// Created 2013 by Dan Andersson
|
||||
// Edited 2013 by
|
||||
// * Dan Andersson
|
||||
// * Dennis Andersen
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef UTILITIES_H
|
||||
#define UTILITIES_H
|
||||
|
@ -18,120 +21,180 @@ namespace Utility
|
|||
{
|
||||
namespace DynamicMemory
|
||||
{
|
||||
//! If dynamicInstance is not NULL, then delete
|
||||
/******************************************************************
|
||||
* If dynamicInstance is not NULL, then delete.
|
||||
******************************************************************/
|
||||
template<typename Type> void SafeDeleteInstance( Type *dynamicInstance );
|
||||
|
||||
//! If dynamicArray is not NULL, then delete []
|
||||
/******************************************************************
|
||||
* If dynamicArray is not NULL, then delete [].
|
||||
******************************************************************/
|
||||
template<typename Type> void SafeDeleteArray( Type dynamicArray[] );
|
||||
|
||||
//! Wrapper to safely transfer dynamic ownership/responsibility
|
||||
template<typename Type> struct UniquePointer
|
||||
{
|
||||
public:
|
||||
//! Assigns assignedInstance ownership to this UniquePonter, old owned instance will be deleted.
|
||||
//! If NULL is assigned is equavalent with clearing all responsibilities from this UniquePointer.
|
||||
UniquePointer( Type *assignedInstance = NULL );
|
||||
|
||||
//! Will auto delete assigned dynamic instance.
|
||||
~UniquePointer();
|
||||
|
||||
//! Assigns assignedInstance ownership to this UniquePonter, old owned instance will be deleted.
|
||||
//! If NULL is assigned is equavalent with clearing all responsibilities from this UniquePointer.
|
||||
UniquePointer<Type> & operator = ( Type *assignedInstance );
|
||||
|
||||
//! Transfers assignedInstance ownership from donor to this UniquePonter, old owned instance will be deleted.
|
||||
//! If donor had nothing, is equavalent with clearing all responsibilities from this UniquePointer.
|
||||
UniquePointer<Type> & operator = ( const UniquePointer<Type> &donor );
|
||||
|
||||
//! Access the assigned dynamic instance. Will crash if nothing there
|
||||
operator Type* ();
|
||||
|
||||
//! Access the assigned dynamic instance. Will crash if nothing there
|
||||
operator const Type* () const;
|
||||
|
||||
//! Access members of the assigned dynamic instance. Will crash if nothing there
|
||||
Type * operator -> ();
|
||||
|
||||
//! Access members of the assigned dynamic instance. Will crash if nothing there
|
||||
const Type * operator -> () const;
|
||||
|
||||
//! If true, this UniquePointer have a current ownership/responsibility of a dynamic instance.
|
||||
operator bool () const;
|
||||
|
||||
//! This UniquePointer drops all claims of ownership/responsibility and returns the dynamic instance. Now it is your responsibility to delete.
|
||||
Type* Release();
|
||||
|
||||
//! (inline) If true, this UniquePointer have a current ownership/responsibility of a dynamic instance.
|
||||
bool HaveOwnership() const;
|
||||
|
||||
private:
|
||||
mutable Type *ownedInstance;
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
struct UniqueArray
|
||||
{ //! Wrapper to safely transfer dynamic ownership/responsibility
|
||||
public:
|
||||
//! Assigns assignedInstance ownership to this UniquePonter, old owned array will be deleted.
|
||||
//! If NULL is assigned is equavalent with clearing all responsibilities from this UniqueArray.
|
||||
UniqueArray( Type assignedArray[] = NULL );
|
||||
|
||||
//! Will auto delete assigned dynamic array.
|
||||
~UniqueArray();
|
||||
|
||||
//! Assigns assignedInstance ownership to this UniquePonter, old owned array will be deleted.
|
||||
//! If NULL is assigned is equavalent with clearing all responsibilities from this UniqueArray.
|
||||
UniqueArray<Type> & operator = ( Type assignedArray[] );
|
||||
|
||||
//! Transfers assignedInstance ownership from donor to this UniquePonter, old owned array will be deleted.
|
||||
//! If donor had nothing, is equavalent with clearing all responsibilities from this UniqueArray.
|
||||
UniqueArray<Type> & operator = ( const UniqueArray<Type> &donor );
|
||||
|
||||
//! Accesses the instance at index i of this UniqeArray's owned dynamic array.
|
||||
//! Will crash if out-of-bound or there is no assigned array.
|
||||
template<typename Index> Type & operator [] ( Index i );
|
||||
|
||||
//! Accesses the instance at index i of this UniqeArray's owned dynamic array.
|
||||
//! Will crash if out-of-bound or there is no assigned array.
|
||||
template<typename Index> const Type & operator [] ( Index i ) const;
|
||||
|
||||
//! If true, this UniqueArray have a current ownership/responsibility of a dynamic instance.
|
||||
operator bool () const;
|
||||
|
||||
//! This UniqueArray drops all claims of ownership/responsibility and returns the dynamic array. Now it is your responsibility to delete.
|
||||
Type* Release();
|
||||
|
||||
//! (inline) If true, this UniqueArray have a current ownership/responsibility of a dynamic array.
|
||||
bool HaveOwnership() const;
|
||||
|
||||
private:
|
||||
mutable Type *ownedArray;
|
||||
};
|
||||
|
||||
//! A simple reference counter with some extra functionality
|
||||
struct ReferenceCount
|
||||
{
|
||||
private:
|
||||
std::atomic<int> count;
|
||||
int count;
|
||||
|
||||
public:
|
||||
ReferenceCount() :count(0) { }
|
||||
ReferenceCount(const ReferenceCount& o) { count.store(o.count); }
|
||||
inline const ReferenceCount& operator=(const ReferenceCount& o) { count.store(o.count); return *this;}
|
||||
ReferenceCount(const ReferenceCount& o) { count = o.count; }
|
||||
inline const ReferenceCount& operator=(const ReferenceCount& o) { count = o.count; return *this;}
|
||||
inline void Incref() { this->count++; }
|
||||
inline void Incref(int c) { this->count += c; }
|
||||
inline int Decref() { return --this->count;}
|
||||
inline void Reset() { this->count = 0; }
|
||||
};
|
||||
|
||||
namespace SmartPointer
|
||||
//! Wrapper to safely transfer dynamic ownership/responsibility
|
||||
template<typename Type> struct UniquePointer
|
||||
{
|
||||
//! Smart pointer for a regular object.
|
||||
/**
|
||||
* Regular objects, objects that is deleted normaly (ie not COM objects, or array pointers)
|
||||
* can use this class to easy the use of dynamic memory
|
||||
*/
|
||||
template<typename T>
|
||||
struct StdSmartPointer
|
||||
public:
|
||||
/******************************************************************
|
||||
* Assigns assignedInstance ownership to this UniquePonter, old owned instance will be deleted.
|
||||
* If NULL is assigned is equivalent with clearing all responsibilities from this UniquePointer.
|
||||
******************************************************************/
|
||||
UniquePointer( Type *assignedInstance = NULL );
|
||||
|
||||
/******************************************************************
|
||||
* Transfers assignedInstance ownership from donor to this UniquePonter, old owned instance will be deleted.
|
||||
* If donor had nothing, is equivalent with clearing all responsibilities from this UniquePointer.
|
||||
******************************************************************/
|
||||
UniquePointer( const UniquePointer<Type> &donor );
|
||||
|
||||
/******************************************************************
|
||||
* Will auto delete assigned dynamic instance.
|
||||
******************************************************************/
|
||||
~UniquePointer();
|
||||
|
||||
/******************************************************************
|
||||
* Transfers assignedInstance ownership from donor to this UniquePonter, old owned instance will be deleted.
|
||||
* If donor had nothing, is equivalent with clearing all responsibilities from this UniquePointer.
|
||||
******************************************************************/
|
||||
UniquePointer<Type> & operator = ( const UniquePointer<Type> &donor );
|
||||
|
||||
/******************************************************************
|
||||
* Access the assigned dynamic instance. Will crash if nothing there
|
||||
******************************************************************/
|
||||
operator Type* ();
|
||||
|
||||
/******************************************************************
|
||||
* Access the assigned dynamic instance. Will crash if nothing there
|
||||
******************************************************************/
|
||||
operator const Type* () const;
|
||||
|
||||
/******************************************************************
|
||||
* Access members of the assigned dynamic instance. Will crash if nothing there
|
||||
******************************************************************/
|
||||
Type * operator -> ();
|
||||
|
||||
/******************************************************************
|
||||
* Access members of the assigned dynamic instance. Will crash if nothing there
|
||||
******************************************************************/
|
||||
const Type * operator -> () const;
|
||||
|
||||
/******************************************************************
|
||||
* @return true if this UniquePointer have a current ownership/responsibility of a dynamic instance.
|
||||
******************************************************************/
|
||||
operator bool () const;
|
||||
|
||||
/******************************************************************
|
||||
* @return true if this ownedInstance matches with stray
|
||||
******************************************************************/
|
||||
bool operator == ( Type *stray ) const;
|
||||
|
||||
/******************************************************************
|
||||
* @return false if this ownedInstance matches with stray
|
||||
******************************************************************/
|
||||
bool operator != ( Type *stray ) const;
|
||||
|
||||
/******************************************************************
|
||||
* This UniquePointer drops all claims of ownership/responsibility and returns the dynamic instance. Now it is your responsibility to delete.
|
||||
******************************************************************/
|
||||
Type* Release();
|
||||
|
||||
/******************************************************************
|
||||
* @return true if this UniquePointer have a current ownership/responsibility of a dynamic instance.
|
||||
* inline of @see operator bool () const
|
||||
******************************************************************/
|
||||
bool HaveOwnership() const;
|
||||
|
||||
private:
|
||||
mutable Type *ownedInstance;
|
||||
};
|
||||
|
||||
//! Wrapper to safely transfer dynamic ownership/responsibility
|
||||
template<typename Type> struct UniqueArray
|
||||
{
|
||||
public:
|
||||
/******************************************************************
|
||||
* Assigns assignedInstance ownership to this UniquePonter, old owned array will be deleted.
|
||||
* If NULL is assigned is equivalent with clearing all responsibilities from this UniqueArray.
|
||||
******************************************************************/
|
||||
UniqueArray( Type assignedArray[] = NULL );
|
||||
|
||||
/******************************************************************
|
||||
* Transfers assignedInstance ownership from donor to this UniquePonter, old owned array will be deleted.
|
||||
* If donor had nothing, is equivalent with clearing all responsibilities from this UniqueArray.
|
||||
******************************************************************/
|
||||
UniqueArray( const UniqueArray<Type> &donor );
|
||||
|
||||
/******************************************************************
|
||||
* Will auto delete assigned dynamic array.
|
||||
******************************************************************/
|
||||
~UniqueArray();
|
||||
|
||||
/******************************************************************
|
||||
* Transfers assignedInstance ownership from donor to this UniquePonter, old owned array will be deleted.
|
||||
* If donor had nothing, is equivalent with clearing all responsibilities from this UniqueArray.
|
||||
******************************************************************/
|
||||
UniqueArray<Type> & operator = ( const UniqueArray<Type> &donor );
|
||||
|
||||
/******************************************************************
|
||||
* Accesses the instance at index i of this UniqeArray's owned dynamic array.
|
||||
* Will crash if out-of-bound or there is no assigned array.
|
||||
******************************************************************/
|
||||
template<typename Index> Type & operator [] ( Index i );
|
||||
|
||||
/******************************************************************
|
||||
* Accesses the instance at index i of this UniqeArray's owned dynamic array.
|
||||
* Will crash if out-of-bound or there is no assigned array.
|
||||
******************************************************************/
|
||||
template<typename Index> const Type & operator [] ( Index i ) const;
|
||||
|
||||
/******************************************************************
|
||||
* @return true if this UniqueArray have a current ownership/responsibility of a dynamic array.
|
||||
******************************************************************/
|
||||
operator bool () const;
|
||||
|
||||
/******************************************************************
|
||||
* @return true if this ownedInstance matches with stray.
|
||||
******************************************************************/
|
||||
bool operator == ( Type *stray ) const;
|
||||
|
||||
/******************************************************************
|
||||
* @return false if this ownedInstance matches with stray.
|
||||
******************************************************************/
|
||||
bool operator != ( Type *stray ) const;
|
||||
|
||||
/******************************************************************
|
||||
* This UniqueArray drops all claims of ownership/responsibility and returns the dynamic array. Now it is your responsibility to delete.
|
||||
******************************************************************/
|
||||
Type* Release();
|
||||
|
||||
/******************************************************************
|
||||
* @return true if this UniqueArray have a current ownership/responsibility of a dynamic array.
|
||||
* inline of @see operator bool () const
|
||||
******************************************************************/
|
||||
bool HaveOwnership() const;
|
||||
|
||||
private:
|
||||
mutable Type *ownedArray;
|
||||
};
|
||||
|
||||
//! Wrapper to manage references on a pointer.
|
||||
template<typename T> struct SmartPointer
|
||||
{
|
||||
private:
|
||||
ReferenceCount *_rc;
|
||||
|
@ -141,13 +204,13 @@ namespace Utility
|
|||
void Destroy();
|
||||
|
||||
public:
|
||||
StdSmartPointer();
|
||||
StdSmartPointer(T* p);
|
||||
StdSmartPointer(const StdSmartPointer& d);
|
||||
virtual~StdSmartPointer();
|
||||
StdSmartPointer<T>& operator= (const StdSmartPointer<T>& p);
|
||||
StdSmartPointer<T>& operator= (T* p);
|
||||
bool operator== (const StdSmartPointer<T>& d);
|
||||
SmartPointer();
|
||||
SmartPointer(T* p);
|
||||
SmartPointer(const SmartPointer& d);
|
||||
virtual~SmartPointer();
|
||||
SmartPointer<T>& operator= (const SmartPointer<T>& p);
|
||||
SmartPointer<T>& operator= (T* p);
|
||||
bool operator== (const SmartPointer<T>& d);
|
||||
bool operator== (const T& p);
|
||||
T& operator* ();
|
||||
T* operator-> ();
|
||||
|
@ -155,18 +218,17 @@ namespace Utility
|
|||
operator bool();
|
||||
|
||||
/**
|
||||
* Returns the connected pointer */
|
||||
* Returns the connected pointer
|
||||
*/
|
||||
T* Get();
|
||||
|
||||
/** Checks if the pointer is valid (not NULL)
|
||||
Returns true for valid, else false. */
|
||||
* Returns true for valid, else false.
|
||||
*/
|
||||
bool IsValid();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
namespace String
|
||||
{
|
||||
// string
|
||||
|
@ -310,8 +372,13 @@ namespace Utility
|
|||
template<> inline unsigned long long AverageWithDelta<unsigned long long>( const unsigned long long &origin, const unsigned long long &delta )
|
||||
{ return origin + (delta >> 1); }
|
||||
}
|
||||
|
||||
namespace Thread
|
||||
{
|
||||
//Utilities for threading
|
||||
}
|
||||
}
|
||||
|
||||
#include "Utilities-InlineImpl.h"
|
||||
#include "Utilities-Impl.h"
|
||||
|
||||
#endif
|
|
@ -1,319 +0,0 @@
|
|||
//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!
|
||||
// Utility Collection of Miscellanious Handy Functions
|
||||
// © Dan Andersson 2013
|
||||
<<<<<<< HEAD
|
||||
//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!//!
|
||||
=======
|
||||
// © Dennis Andersen 2013
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
>>>>>>> 48c812b0338b859aa6c00c8504dd2f16a4bb44f9
|
||||
|
||||
#ifndef UTILITIES_H
|
||||
#define UTILITIES_H
|
||||
|
||||
#include <string>
|
||||
#include <istream>
|
||||
#include <vector>
|
||||
#include <locale>
|
||||
#include <limits>
|
||||
|
||||
namespace Utility
|
||||
{
|
||||
namespace DynamicMemory
|
||||
{
|
||||
//! If dynamicInstance is not NULL, then delete
|
||||
template<typename Type> void SafeDeleteInstance( Type *dynamicInstance );
|
||||
|
||||
//! If dynamicArray is not NULL, then delete []
|
||||
template<typename Type> void SafeDeleteArray( Type dynamicArray[] );
|
||||
|
||||
//! Wrapper to safely transfer dynamic ownership/responsibility
|
||||
template<typename Type> struct UniquePointer
|
||||
{
|
||||
public:
|
||||
//! Assigns assignedInstance ownership to this UniquePonter, old owned instance will be deleted.
|
||||
//! If NULL is assigned is equavalent with clearing all responsibilities from this UniquePointer.
|
||||
UniquePointer( Type *assignedInstance = NULL );
|
||||
|
||||
//! Will auto delete assigned dynamic instance.
|
||||
~UniquePointer();
|
||||
|
||||
//! Assigns assignedInstance ownership to this UniquePonter, old owned instance will be deleted.
|
||||
//! If NULL is assigned is equavalent with clearing all responsibilities from this UniquePointer.
|
||||
UniquePointer<Type> & operator = ( Type *assignedInstance );
|
||||
|
||||
//! Transfers assignedInstance ownership from donor to this UniquePonter, old owned instance will be deleted.
|
||||
//! If donor had nothing, is equavalent with clearing all responsibilities from this UniquePointer.
|
||||
UniquePointer<Type> & operator = ( const UniquePointer<Type> &donor );
|
||||
|
||||
//! Access the assigned dynamic instance. Will crash if nothing there
|
||||
operator Type* ();
|
||||
|
||||
//! Access the assigned dynamic instance. Will crash if nothing there
|
||||
operator const Type* () const;
|
||||
|
||||
//! Access members of the assigned dynamic instance. Will crash if nothing there
|
||||
Type * operator -> ();
|
||||
|
||||
//! Access members of the assigned dynamic instance. Will crash if nothing there
|
||||
const Type * operator -> () const;
|
||||
|
||||
//! If true, this UniquePointer have a current ownership/responsibility of a dynamic instance.
|
||||
operator bool () const;
|
||||
|
||||
//! This UniquePointer drops all claims of ownership/responsibility and returns the dynamic instance. Now it is your responsibility to delete.
|
||||
Type* Release();
|
||||
|
||||
//! (inline) If true, this UniquePointer have a current ownership/responsibility of a dynamic instance.
|
||||
bool HaveOwnership() const;
|
||||
|
||||
private:
|
||||
mutable Type *ownedInstance;
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
struct UniqueArray
|
||||
{ //! Wrapper to safely transfer dynamic ownership/responsibility
|
||||
public:
|
||||
//! Assigns assignedInstance ownership to this UniquePonter, old owned array will be deleted.
|
||||
//! If NULL is assigned is equavalent with clearing all responsibilities from this UniqueArray.
|
||||
UniqueArray( Type assignedArray[] = NULL );
|
||||
|
||||
//! Will auto delete assigned dynamic array.
|
||||
~UniqueArray();
|
||||
|
||||
//! Assigns assignedInstance ownership to this UniquePonter, old owned array will be deleted.
|
||||
//! If NULL is assigned is equavalent with clearing all responsibilities from this UniqueArray.
|
||||
UniqueArray<Type> & operator = ( Type assignedArray[] );
|
||||
|
||||
//! Transfers assignedInstance ownership from donor to this UniquePonter, old owned array will be deleted.
|
||||
//! If donor had nothing, is equavalent with clearing all responsibilities from this UniqueArray.
|
||||
UniqueArray<Type> & operator = ( const UniqueArray<Type> &donor );
|
||||
|
||||
//! Accesses the instance at index i of this UniqeArray's owned dynamic array.
|
||||
//! Will crash if out-of-bound or there is no assigned array.
|
||||
template<typename Index> Type & operator [] ( Index i );
|
||||
|
||||
//! Accesses the instance at index i of this UniqeArray's owned dynamic array.
|
||||
//! Will crash if out-of-bound or there is no assigned array.
|
||||
template<typename Index> const Type & operator [] ( Index i ) const;
|
||||
|
||||
//! If true, this UniqueArray have a current ownership/responsibility of a dynamic instance.
|
||||
operator bool () const;
|
||||
|
||||
//! This UniqueArray drops all claims of ownership/responsibility and returns the dynamic array. Now it is your responsibility to delete.
|
||||
Type* Release();
|
||||
|
||||
//! (inline) If true, this UniqueArray have a current ownership/responsibility of a dynamic array.
|
||||
bool HaveOwnership() const;
|
||||
|
||||
private:
|
||||
mutable Type *ownedArray;
|
||||
};
|
||||
|
||||
struct ReferenceCount
|
||||
{
|
||||
private:
|
||||
int count;
|
||||
|
||||
public:
|
||||
ReferenceCount() :count(0) { }
|
||||
ReferenceCount(const ReferenceCount& o) { count = o.count; }
|
||||
inline const ReferenceCount& operator=(const ReferenceCount& o) { count = o.count; return *this;}
|
||||
inline void Incref() { this->count++; }
|
||||
inline void Incref(int c) { this->count += c; }
|
||||
inline int Decref() { return --this->count;}
|
||||
inline void Reset() { this->count = 0; }
|
||||
};
|
||||
|
||||
namespace SmartPointer
|
||||
{
|
||||
//! Smart pointer for a regular object.
|
||||
/**
|
||||
* Regular objects, objects that is deleted normaly (ie not COM objects, or array pointers)
|
||||
* can use this class to easy the use of dynamic memory
|
||||
*/
|
||||
template<typename T>
|
||||
struct StdSmartPointer
|
||||
{
|
||||
private:
|
||||
ReferenceCount *_rc;
|
||||
T *_ptr;
|
||||
|
||||
/** Destroys the pointer and returns the memory allocated. */
|
||||
void Destroy();
|
||||
|
||||
public:
|
||||
StdSmartPointer();
|
||||
StdSmartPointer(T* p);
|
||||
StdSmartPointer(const StdSmartPointer& d);
|
||||
virtual~StdSmartPointer();
|
||||
StdSmartPointer<T>& operator= (const StdSmartPointer<T>& p);
|
||||
StdSmartPointer<T>& operator= (T* p);
|
||||
bool operator== (const StdSmartPointer<T>& d);
|
||||
bool operator== (const T& p);
|
||||
T& operator* ();
|
||||
T* operator-> ();
|
||||
operator T* ();
|
||||
|
||||
/**
|
||||
* Returns the connected pointer */
|
||||
T* Get();
|
||||
|
||||
/** Checks if the pointer is valid (not NULL)
|
||||
Returns true for valid, else false. */
|
||||
bool IsValid();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
namespace String
|
||||
{
|
||||
// string
|
||||
|
||||
::std::vector<::std::string> & Split( ::std::vector<::std::string> &output, const ::std::string &str, char delim, ::std::string::size_type offset = 0 );
|
||||
::std::vector<::std::string> & Split( ::std::vector<::std::string> &output, const ::std::string &str, const ::std::string &delim, ::std::string::size_type offset = 0 );
|
||||
::std::vector<::std::string> & Split( ::std::vector<::std::string> &output, const ::std::string &str, const ::std::vector<::std::string> &delim, ::std::string::size_type offset = 0 );
|
||||
::std::string Trim( const ::std::string &str );
|
||||
::std::string & ToLowerCase( ::std::string &output, const ::std::string &str );
|
||||
::std::string & ToLowerCase( ::std::string &str );
|
||||
::std::string & ToUpperCase( ::std::string &output, const ::std::string &str );
|
||||
::std::string & ToUpperCase( ::std::string &str );
|
||||
::std::string & ExtractDirPath( ::std::string &output, const ::std::string &file, char dirDelimeter );
|
||||
::std::string & ExtractDirPath( ::std::string &output, const ::std::string &file, const ::std::string &dirDelimeter );
|
||||
::std::string & ReplaceCharacters( ::std::string &str, char characterToReplace, char newCharacter, const ::std::string::size_type &offset = 0, const ::std::string::size_type &end = ::std::string::npos );
|
||||
|
||||
// wstring
|
||||
|
||||
::std::vector<::std::wstring> & Split( ::std::vector<::std::wstring> &output, const ::std::wstring &str, char delim, ::std::wstring::size_type offset = 0 );
|
||||
::std::vector<::std::wstring> & Split( ::std::vector<::std::wstring> &output, const ::std::wstring &str, const ::std::wstring &delim, ::std::wstring::size_type offset = 0 );
|
||||
::std::vector<::std::wstring> & Split( ::std::vector<::std::wstring> &output, const ::std::wstring &str, const ::std::vector<::std::wstring> &delim, ::std::wstring::size_type offset = 0 );
|
||||
::std::wstring & wToLowerCase( ::std::wstring &output, const ::std::wstring &str );
|
||||
::std::wstring & wToLowerCase( ::std::wstring &str );
|
||||
|
||||
//To wstring
|
||||
|
||||
::std::wstring & StringToWstring( const ::std::string &str, ::std::wstring &wstr );
|
||||
::std::string & WStringToString( const ::std::wstring &wstr, ::std::string &str );
|
||||
}
|
||||
|
||||
namespace Stream
|
||||
{
|
||||
float* ReadFloats( float *output, ::std::istream &input, unsigned int numFloats );
|
||||
}
|
||||
|
||||
namespace StaticArray
|
||||
{
|
||||
template<typename ScalarType, unsigned int num>
|
||||
inline unsigned int NumElementsOf( const ScalarType(&)[num] )
|
||||
{ return num; }
|
||||
|
||||
template<typename ScalarType, unsigned int num>
|
||||
inline ScalarType & FirstElementOf( ScalarType (&arr)[num] )
|
||||
{ return arr[0]; }
|
||||
|
||||
template<typename ScalarType, unsigned int num>
|
||||
inline ScalarType & LastElementOf( ScalarType (&arr)[num] )
|
||||
{ return arr[num-1]; }
|
||||
}
|
||||
|
||||
namespace Element
|
||||
{
|
||||
template<typename ScalarType>
|
||||
inline void Swap( ScalarType &elementA, ScalarType &elementB, ScalarType &swapSpace )
|
||||
{ swapSpace = elementA; elementA = elementB; elementB = swapSpace; }
|
||||
|
||||
template<typename ScalarType>
|
||||
inline void Swap( ScalarType &elementA, ScalarType &elementB )
|
||||
{ ScalarType swapSpace; Swap( elementA, elementB, swapSpace ); }
|
||||
}
|
||||
|
||||
namespace Value
|
||||
{
|
||||
using ::std::numeric_limits;
|
||||
|
||||
template<typename ValueType>
|
||||
inline ValueType Abs( const ValueType &value )
|
||||
{ return value < 0 ? value * -1 : value; }
|
||||
|
||||
template<typename ValueType>
|
||||
inline ValueType Max( const ValueType &valueA, const ValueType &valueB )
|
||||
{ return valueA > valueB ? valueA : valueB; }
|
||||
|
||||
template<typename ValueType>
|
||||
inline ValueType Min( const ValueType &valueA, const ValueType &valueB )
|
||||
{ return valueA < valueB ? valueA : valueB; }
|
||||
|
||||
template<typename ValueType>
|
||||
inline ValueType Average( const ValueType &valueA, const ValueType &valueB )
|
||||
{ return (valueA + valueB) * 0.5f; }
|
||||
|
||||
template<typename ValueType>
|
||||
inline ValueType AverageWithDelta( const ValueType &origin, const ValueType &delta )
|
||||
{ return origin + (delta * 0.5f); }
|
||||
|
||||
template<typename ValueType>
|
||||
inline ValueType Radian( const ValueType °ree )
|
||||
{ return degree * (3.1415926535897932384626433832795f / 180.0f); }
|
||||
|
||||
template<typename ValueType>
|
||||
inline ValueType Degree( const ValueType &radian )
|
||||
{ return radian * (180.0f / 3.1415926535897932384626433832795f); }
|
||||
|
||||
// SPECIALIZATIONS //!//!//!//!//!//!//!//!//!//!//!//!//!//!
|
||||
|
||||
template<> inline char Average<char>( const char &valueA, const char &valueB )
|
||||
{ return (valueA + valueB) >> 1; }
|
||||
|
||||
template<> inline unsigned char Average<unsigned char>( const unsigned char &valueA, const unsigned char &valueB )
|
||||
{ return (valueA + valueB) >> 1; }
|
||||
|
||||
template<> inline int Average<int>( const int &valueA, const int &valueB )
|
||||
{ return (valueA + valueB) >> 1; }
|
||||
|
||||
template<> inline unsigned int Average<unsigned int>( const unsigned int &valueA, const unsigned int &valueB )
|
||||
{ return (valueA + valueB) >> 1; }
|
||||
|
||||
template<> inline long Average<long>( const long &valueA, const long &valueB )
|
||||
{ return (valueA + valueB) >> 1; }
|
||||
|
||||
template<> inline unsigned long Average<unsigned long>( const unsigned long &valueA, const unsigned long &valueB )
|
||||
{ return (valueA + valueB) >> 1; }
|
||||
|
||||
template<> inline long long Average<long long>( const long long &valueA, const long long &valueB )
|
||||
{ return (valueA + valueB) >> 1; }
|
||||
|
||||
template<> inline unsigned long long Average<unsigned long long>( const unsigned long long &valueA, const unsigned long long &valueB )
|
||||
{ return (valueA + valueB) >> 1; }
|
||||
|
||||
template<> inline char AverageWithDelta<char>( const char &origin, const char &delta )
|
||||
{ return origin + (delta >> 1); }
|
||||
|
||||
template<> inline unsigned char AverageWithDelta<unsigned char>( const unsigned char &origin, const unsigned char &delta )
|
||||
{ return origin + (delta >> 1); }
|
||||
|
||||
template<> inline int AverageWithDelta<int>( const int &origin, const int &delta )
|
||||
{ return origin + (delta >> 1); }
|
||||
|
||||
template<> inline unsigned int AverageWithDelta<unsigned int>( const unsigned int &origin, const unsigned int &delta )
|
||||
{ return origin + (delta >> 1); }
|
||||
|
||||
template<> inline long AverageWithDelta<long>( const long &origin, const long &delta )
|
||||
{ return origin + (delta >> 1); }
|
||||
|
||||
template<> inline unsigned long AverageWithDelta<unsigned long>( const unsigned long &origin, const unsigned long &delta )
|
||||
{ return origin + (delta >> 1); }
|
||||
|
||||
template<> inline long long AverageWithDelta<long long>( const long long &origin, const long long &delta )
|
||||
{ return origin + (delta >> 1); }
|
||||
|
||||
template<> inline unsigned long long AverageWithDelta<unsigned long long>( const unsigned long long &origin, const unsigned long long &delta )
|
||||
{ return origin + (delta >> 1); }
|
||||
}
|
||||
}
|
||||
|
||||
#include "Utilities-InlineImpl.h"
|
||||
|
||||
#endif
|
|
@ -0,0 +1,153 @@
|
|||
#include "Connection.h"
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <fcntl.h>
|
||||
|
||||
using namespace Oyster::Network;
|
||||
|
||||
Connection::~Connection()
|
||||
{
|
||||
closesocket( this->socket );
|
||||
}
|
||||
|
||||
int Connection::Connect(unsigned short port , const char serverName[])
|
||||
{
|
||||
struct hostent *hostEnt;
|
||||
if((hostEnt = gethostbyname(serverName)) == NULL)
|
||||
{
|
||||
return WSAGetLastError();
|
||||
}
|
||||
|
||||
struct sockaddr_in server;
|
||||
server.sin_family = AF_INET;
|
||||
server.sin_port = htons(port);
|
||||
server.sin_addr.s_addr = *(unsigned long*) hostEnt->h_addr;
|
||||
|
||||
if(connect(this->socket, (sockaddr*)&server, sizeof(server)) == SOCKET_ERROR)
|
||||
{
|
||||
return WSAGetLastError();
|
||||
}
|
||||
|
||||
//connection succesfull!
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Connection::InitiateServer(unsigned short port)
|
||||
{
|
||||
int errorCode = 0;
|
||||
|
||||
if((errorCode = InitiateSocket()) != 0)
|
||||
{
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
struct sockaddr_in server;
|
||||
server.sin_family = AF_INET;
|
||||
server.sin_port = htons(port);
|
||||
server.sin_addr.s_addr = INADDR_ANY;
|
||||
|
||||
if(bind(this->socket, (sockaddr*)&server, sizeof(server)) == SOCKET_ERROR)
|
||||
{
|
||||
errorCode = WSAGetLastError();
|
||||
closesocket(this->socket);
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
//not our Listen function! its trying to keep our socket open for connections
|
||||
if(listen(this->socket, 5) == SOCKET_ERROR)
|
||||
{
|
||||
errorCode = WSAGetLastError();
|
||||
closesocket(this->socket);
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
//Server started!
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Connection::InitiateClient()
|
||||
{
|
||||
return InitiateSocket();
|
||||
}
|
||||
|
||||
int Connection::Disconnect()
|
||||
{
|
||||
closesocket(this->socket);
|
||||
|
||||
return WSAGetLastError();
|
||||
}
|
||||
|
||||
int Connection::Send(OysterByte& bytes)
|
||||
{
|
||||
int nBytes;
|
||||
|
||||
nBytes = send(this->socket, bytes, bytes.GetSize(), 0);
|
||||
if(nBytes == SOCKET_ERROR)
|
||||
{
|
||||
return WSAGetLastError();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Connection::Recieve(OysterByte& bytes)
|
||||
{
|
||||
int nBytes;
|
||||
|
||||
bytes.Clear(1000);
|
||||
nBytes = recv(this->socket, bytes, 500, 0);
|
||||
if(nBytes == SOCKET_ERROR)
|
||||
{
|
||||
return WSAGetLastError();
|
||||
}
|
||||
else
|
||||
{
|
||||
bytes.SetSize(nBytes);
|
||||
}
|
||||
|
||||
std::cout << "Size of the recieved data: " << nBytes << " bytes" << std::endl;
|
||||
|
||||
//bytes.byteArray[nBytes] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Connection::Listen()
|
||||
{
|
||||
int clientSocket;
|
||||
if((clientSocket = accept(this->socket, NULL, NULL)) == INVALID_SOCKET)
|
||||
{
|
||||
return WSAGetLastError();
|
||||
}
|
||||
|
||||
return clientSocket;
|
||||
}
|
||||
|
||||
///////////////////////////////////////
|
||||
//Private functions
|
||||
///////////////////////////////////////
|
||||
int Connection::InitiateSocket()
|
||||
{
|
||||
this->socket = ::socket(AF_INET, SOCK_STREAM, 0);
|
||||
if(this->socket == SOCKET_ERROR)
|
||||
{
|
||||
return WSAGetLastError();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Connection::SetBlockingMode(bool blocking)
|
||||
{
|
||||
//TODO: Implement this function. Setting the socket to blocking or non-blocking.
|
||||
if(blocking)
|
||||
{
|
||||
//fcntl(this->socket, F_SETFL, O_NONBLOCK);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
#ifndef NETWORK_DEPENDENCIES_CONNECTION_H
|
||||
#define NETWORK_DEPENDENCIES_CONNECTION_H
|
||||
|
||||
//////////////////////////////////
|
||||
// Created by Sam Svensson 2013 //
|
||||
//////////////////////////////////
|
||||
|
||||
#include "IConnection.h"
|
||||
#include "../NetworkDependencies/OysterByte.h"
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Network
|
||||
{
|
||||
class Connection : public IConnection
|
||||
{
|
||||
|
||||
public:
|
||||
Connection() { this->socket = 0; };
|
||||
Connection( int socket ) { this->socket = socket; };
|
||||
virtual ~Connection();
|
||||
|
||||
|
||||
virtual int InitiateServer( unsigned short port );
|
||||
virtual int InitiateClient();
|
||||
|
||||
virtual int Send( OysterByte& bytes );
|
||||
virtual int Recieve( OysterByte& bytes );
|
||||
|
||||
virtual int Disconnect();
|
||||
virtual int Connect( unsigned short port , const char serverName[] );
|
||||
|
||||
virtual int Listen();
|
||||
|
||||
private:
|
||||
int InitiateSocket();
|
||||
void SetBlockingMode( bool blocking );
|
||||
|
||||
int socket;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,262 +0,0 @@
|
|||
#include "Event.h"
|
||||
using namespace Event;
|
||||
|
||||
|
||||
//----------------------------
|
||||
// BulletCreated class definitions
|
||||
BulletCreated::BulletCreated(int ownerID, Float3 position, Float3 direction)
|
||||
:
|
||||
GameEvent()
|
||||
{
|
||||
data.owner=ownerID;
|
||||
data.head=direction;
|
||||
}
|
||||
void BulletCreated::LoadRawData(char* d)
|
||||
{
|
||||
memcpy(&data, d, GetSize());
|
||||
/*int offset=0;
|
||||
memcpy(&data.position, data, sizeof(Float3));
|
||||
offset+=sizeof(Float3);
|
||||
|
||||
memcpy(&data.head, d+offset, sizeof(Float3));
|
||||
offset+=sizeof(Float3);
|
||||
memcpy(&data.owner, d+offset, sizeof(int));*/
|
||||
}
|
||||
void BulletCreated::SaveRawData(char* d)
|
||||
{
|
||||
memcpy(d, &data, GetSize());
|
||||
}
|
||||
|
||||
//----------------------------
|
||||
// BulletHit class definitions
|
||||
BulletHit::BulletHit(int attacker, int hitPlayer)
|
||||
:
|
||||
GameEvent()
|
||||
{
|
||||
data.hitTarget=hitPlayer;
|
||||
data.attackingTarget=attacker;
|
||||
//this->hpLeft=hl;
|
||||
//this->shieldLeft=sl;
|
||||
}
|
||||
void BulletHit::LoadRawData(char* d)
|
||||
{
|
||||
memcpy(&data, d, GetSize());
|
||||
}
|
||||
void BulletHit::SaveRawData(char* d)
|
||||
{
|
||||
memcpy(d, &data, GetSize());
|
||||
}
|
||||
|
||||
ScoreUpdate::ScoreUpdate(Score* scores)
|
||||
{
|
||||
for (int i=0; i<PLAYER_MAX_COUNT; i++)
|
||||
{
|
||||
data.scoreboard[i]=scores[i];
|
||||
}
|
||||
}
|
||||
void ScoreUpdate::LoadRawData(char* d)
|
||||
{
|
||||
memcpy(&data, d, GetSize());
|
||||
}
|
||||
void ScoreUpdate::SaveRawData(char* d)
|
||||
{
|
||||
memcpy(d, &data, GetSize());
|
||||
}
|
||||
|
||||
//----------------------------
|
||||
// ShipSpawned class definitions
|
||||
ShipSpawned::ShipSpawned(Float3 position, int id)
|
||||
:
|
||||
GameEvent()
|
||||
{
|
||||
data.position=position;
|
||||
data.playerID=id;
|
||||
}
|
||||
void ShipSpawned::LoadRawData(char* d)
|
||||
{
|
||||
memcpy(&data, d, this->GetSize());
|
||||
/*int offset=0;
|
||||
memcpy(&data.position, data, sizeof(Float3));
|
||||
offset+=sizeof(Float3);
|
||||
|
||||
memcpy(&playerID, data+offset, sizeof(int));*/
|
||||
}
|
||||
void ShipSpawned::SaveRawData(char* d)
|
||||
{
|
||||
memcpy(d, &data, GetSize());
|
||||
}
|
||||
|
||||
|
||||
//----------------------------
|
||||
// GameEnded class definitions
|
||||
GameEnded::GameEnded()
|
||||
:
|
||||
GameEvent()
|
||||
{
|
||||
}
|
||||
GameEnded::GameEnded(int winner)
|
||||
:
|
||||
GameEvent()
|
||||
{
|
||||
data.winningTeam=winner;
|
||||
}
|
||||
void GameEnded::LoadRawData(char* d)
|
||||
{
|
||||
memcpy(&data, d, GetSize());
|
||||
/*int offset=0;
|
||||
memcpy(&eventPosition, data, sizeof(Float3));
|
||||
offset+=sizeof(Float3);
|
||||
|
||||
memcpy(&winningTeam, data+offset, sizeof(int));
|
||||
offset+=sizeof(int);
|
||||
|
||||
for (int i=0; i<PLAYER_MAX_COUNT; i++)
|
||||
{
|
||||
memcpy(&data.scoreboard[i], data+offset, sizeof(Score));
|
||||
offset+=sizeof(Score);
|
||||
}*/
|
||||
}
|
||||
void GameEnded::SaveRawData(char* d)
|
||||
{
|
||||
memcpy(d, &data, GetSize());
|
||||
}
|
||||
void GameEnded::setScore(int i, Score score)
|
||||
{
|
||||
data.scoreboard[i]=score;
|
||||
}
|
||||
void GameEnded::setScore(int i, int k, int d, int tk)
|
||||
{
|
||||
data.scoreboard[i].id=i;
|
||||
data.scoreboard[i].kills=k;
|
||||
data.scoreboard[i].deaths=d;
|
||||
data.scoreboard[i].teamkills=tk;
|
||||
}
|
||||
void GameEnded::sortScore()
|
||||
{
|
||||
float sort[PLAYER_MAX_COUNT];
|
||||
for(int i=0; i<PLAYER_MAX_COUNT; i++)
|
||||
{
|
||||
sort[i]=((float)(data.scoreboard[i].kills-data.scoreboard[i].teamkills))/(float)data.scoreboard[i].deaths;
|
||||
}
|
||||
Score tmp;
|
||||
int bestID=0;
|
||||
float bestScore;
|
||||
for(int i=0; i<PLAYER_MAX_COUNT; i++)
|
||||
{
|
||||
bestScore=sort[i];
|
||||
bestID=i;
|
||||
for (int j=i; j<PLAYER_MAX_COUNT; j++)
|
||||
{
|
||||
if(bestScore<sort[j])
|
||||
{
|
||||
bestID=j;
|
||||
bestScore=sort[j];
|
||||
}
|
||||
}
|
||||
tmp=data.scoreboard[i];
|
||||
data.scoreboard[i]=data.scoreboard[bestID];
|
||||
data.scoreboard[bestID]=tmp;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------
|
||||
// ShipDestroyed class definitions
|
||||
ShipDestroyed::ShipDestroyed(int pid, int kid)
|
||||
:
|
||||
GameEvent()
|
||||
{
|
||||
data.playerID=pid;
|
||||
data.killerID=kid;
|
||||
}
|
||||
void ShipDestroyed::setScore(int i, Score score)
|
||||
{
|
||||
data.scoreboard[i]=score;
|
||||
}
|
||||
void ShipDestroyed::setScore(int i, int k, int d, int tk)
|
||||
{
|
||||
data.scoreboard[i].id=i;
|
||||
data.scoreboard[i].kills=k;
|
||||
data.scoreboard[i].deaths=d;
|
||||
data.scoreboard[i].teamkills=tk;
|
||||
}
|
||||
void ShipDestroyed::sortScore()
|
||||
{
|
||||
float sort[PLAYER_MAX_COUNT];
|
||||
for(int i=0; i<PLAYER_MAX_COUNT; i++)
|
||||
{
|
||||
sort[i]=((float)(data.scoreboard[i].kills-data.scoreboard[i].teamkills))/data.scoreboard[i].deaths;
|
||||
}
|
||||
Score tmp;
|
||||
int bestID=0;
|
||||
float bestScore;
|
||||
for(int i=0; i<PLAYER_MAX_COUNT; i++)
|
||||
{
|
||||
bestScore=sort[i];
|
||||
bestID=i;
|
||||
for (int j=i; j<PLAYER_MAX_COUNT; j++)
|
||||
{
|
||||
if(bestScore<sort[j])
|
||||
{
|
||||
bestID=j;
|
||||
bestScore=sort[j];
|
||||
}
|
||||
}
|
||||
tmp=data.scoreboard[i];
|
||||
data.scoreboard[i]=data.scoreboard[bestID];
|
||||
data.scoreboard[bestID]=tmp;
|
||||
}
|
||||
}
|
||||
void ShipDestroyed::LoadRawData(char* d)
|
||||
{
|
||||
memcpy(&data, d, GetSize());
|
||||
/*int offset=0;
|
||||
memcpy(&eventPosition, data, sizeof(Float3));
|
||||
offset+=sizeof(Float3);
|
||||
|
||||
memcpy(&playerID, data+offset, sizeof(int));
|
||||
offset+=sizeof(int);
|
||||
memcpy(&killerID, data+offset, sizeof(int));
|
||||
offset+=sizeof(int);
|
||||
for (int i=0; i<PLAYER_MAX_COUNT; i++)
|
||||
{
|
||||
memcpy(&data.scoreboard[i], data+offset, sizeof(Score));
|
||||
offset+=sizeof(Score);
|
||||
}*/
|
||||
}
|
||||
void ShipDestroyed::SaveRawData(char* d)
|
||||
{
|
||||
memcpy(d, &data, GetSize());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Event::Type Event::getEventType(Event::GameEvent* evt)
|
||||
{
|
||||
if (typeid(*evt)==typeid(Event::BulletCreated))
|
||||
{
|
||||
return eBulletCreated;
|
||||
}
|
||||
else if(typeid(*evt)==typeid(Event::BulletHit))
|
||||
{
|
||||
return eBulletHit;
|
||||
}
|
||||
else if(typeid(*evt)==typeid(Event::ShipSpawned))
|
||||
{
|
||||
return eShipSpawned;
|
||||
}
|
||||
else if(typeid(*evt)==typeid(Event::GameEnded))
|
||||
{
|
||||
return eGameEnded;
|
||||
}
|
||||
else if(typeid(*evt)==typeid(Event::ShipDestroyed))
|
||||
{
|
||||
return eShipDestroyed;
|
||||
}
|
||||
else if(typeid(*evt)==typeid(Event::ScoreUpdate))
|
||||
{
|
||||
return eScoreUpdate;
|
||||
}
|
||||
printf("UNSUPPORTED EVENT at getEventType, Event.cpp\n");
|
||||
return UNSUPPORTED_TYPE;
|
||||
}
|
|
@ -1,142 +0,0 @@
|
|||
#include "NetworkIncludes.h"
|
||||
#include "EventStructs.h"
|
||||
#pragma once
|
||||
#ifndef EVENT_H
|
||||
#define EVENT_H
|
||||
//There's a variable called eventList in Session.
|
||||
//if you push_back any type of event, the server will pick them up in order after every update() is run.
|
||||
|
||||
|
||||
//Try to keep events pointer-free. Trying to send a class with a pointer over a socket will result in a problem because
|
||||
//it will send the pointer rather than the data in the pointer. That results in either
|
||||
//A: Program crashing because it's not allowed to read that space if it's on the same computer as the server or
|
||||
//B: Program crashing because the pointer most probably points to an unused space if the client is on a separate computer.
|
||||
|
||||
//This is the basic event class.
|
||||
//a position should always be given with all events, to use as a main location for sounds, effects, or whatever. We can remove it if we decide it's not needed later on.
|
||||
|
||||
namespace Event
|
||||
{
|
||||
class GameEvent
|
||||
{
|
||||
protected:
|
||||
public:
|
||||
GameEvent(){}
|
||||
virtual int GetSize()=0;
|
||||
virtual void LoadRawData(char* d)=0;
|
||||
virtual void SaveRawData(char* d)=0;
|
||||
};
|
||||
|
||||
//When a player fires a projectile, a BulletCreated event should be added.
|
||||
class BulletCreated : public GameEvent
|
||||
{
|
||||
private:
|
||||
EventStruct::BulletCreatedStruct data;
|
||||
public:
|
||||
BulletCreated():GameEvent(){}
|
||||
BulletCreated(int ownerID, Float3 position, Float3 Head);
|
||||
int GetOwner(){return data.owner;}
|
||||
int GetSize(){return sizeof(data);}
|
||||
EventStruct::BulletCreatedStruct GetAsStruct(){return data;}
|
||||
void LoadRawData(char* d);
|
||||
void SaveRawData(char* d);
|
||||
};
|
||||
|
||||
class ScoreUpdate : public GameEvent
|
||||
{
|
||||
private:
|
||||
EventStruct::ScoreUpdateStruct data;
|
||||
public:
|
||||
ScoreUpdate():GameEvent(){}
|
||||
ScoreUpdate(Score* scoreboard);
|
||||
int GetSize(){return sizeof(data);}
|
||||
EventStruct::ScoreUpdateStruct GetAsStruct(){return data;}
|
||||
void LoadRawData(char* d);
|
||||
void SaveRawData(char* d);
|
||||
};
|
||||
|
||||
//When some kind of player-fired projectile hits an enemy, a BulletHit even should be added.
|
||||
class BulletHit : public GameEvent
|
||||
{
|
||||
private:
|
||||
EventStruct::BulletHitStruct data;
|
||||
public:
|
||||
BulletHit():GameEvent(){}
|
||||
BulletHit(int attacker, int hitPlayer);
|
||||
int getAttackerID(){return data.attackingTarget;}
|
||||
int getHitTargetID(){return data.hitTarget;}
|
||||
int GetSize(){return sizeof(data);}
|
||||
EventStruct::BulletHitStruct GetAsStruct(){return data;}
|
||||
void LoadRawData(char* d);
|
||||
void SaveRawData(char* d);
|
||||
};
|
||||
|
||||
//Shipspawned event, for when a ship respawns.
|
||||
//In ShipSpawned, all data that the client requires should be given.
|
||||
class ShipSpawned : public GameEvent
|
||||
{
|
||||
private:
|
||||
EventStruct::ShipSpawnedStruct data;
|
||||
public:
|
||||
ShipSpawned():GameEvent(){}
|
||||
ShipSpawned(Float3 position, int id);
|
||||
int GetSize(){return sizeof(data);}
|
||||
EventStruct::ShipSpawnedStruct GetAsStruct(){return data;}
|
||||
void LoadRawData(char* d);
|
||||
void SaveRawData(char* d);
|
||||
};
|
||||
|
||||
class ShipDestroyed : public GameEvent
|
||||
{
|
||||
public:
|
||||
EventStruct::ShipDestroyedStruct data;
|
||||
public:
|
||||
ShipDestroyed():GameEvent(){}
|
||||
ShipDestroyed(int pid, int kid);
|
||||
void setScore(int i, Score score);
|
||||
void setScore(int i, int k, int d, int tk);
|
||||
void sortScore();
|
||||
int getDestroyedID() const {return data.playerID;}
|
||||
int getAttackerID() const {return data.killerID;}
|
||||
EventStruct::ShipDestroyedStruct GetAsStruct(){return data;}
|
||||
|
||||
int GetSize(){return sizeof(data);}
|
||||
void LoadRawData(char* d);
|
||||
void SaveRawData(char* d);
|
||||
};
|
||||
|
||||
|
||||
class GameEnded : public GameEvent
|
||||
{
|
||||
private:
|
||||
EventStruct::GameEndedStruct data;
|
||||
//Have some variables which shows scores of player, who won, etc
|
||||
//you just need the ids. Don't send names etc.
|
||||
public:
|
||||
GameEnded();
|
||||
GameEnded(int winner);
|
||||
void setScore(int i, Score score);
|
||||
void setScore(int i, int k, int d, int tk);
|
||||
void sortScore();
|
||||
int GetSize(){return sizeof(data);}
|
||||
EventStruct::GameEndedStruct GetAsStruct(){return data;}
|
||||
void LoadRawData(char* d);
|
||||
void SaveRawData(char* d);
|
||||
};
|
||||
|
||||
enum Type
|
||||
{
|
||||
UNSUPPORTED_TYPE,
|
||||
eBulletCreated,
|
||||
eBulletHit,
|
||||
eShipSpawned,
|
||||
eGameEnded,
|
||||
eShipDestroyed,
|
||||
eScoreUpdate
|
||||
};
|
||||
Event::Type getEventType(Event::GameEvent* evt);
|
||||
|
||||
|
||||
|
||||
}
|
||||
#endif
|
|
@ -1,55 +0,0 @@
|
|||
#include "NetworkIncludes.h"
|
||||
#include "NetworkConstants.h"
|
||||
#ifndef NET_EVT_STRUCTS_H
|
||||
#define NET_EVT_STRUCTS_H
|
||||
struct Score
|
||||
{
|
||||
int id;//Leaderboard var
|
||||
int kills;
|
||||
int deaths;
|
||||
int teamkills;
|
||||
Score(){id=0;kills=0;deaths=0;teamkills=0;}
|
||||
Score& operator+=(const Score add)
|
||||
{
|
||||
id+=add.id;
|
||||
kills+=add.kills;
|
||||
deaths+=add.deaths;
|
||||
teamkills+=add.teamkills;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
namespace EventStruct
|
||||
{
|
||||
struct BulletCreatedStruct
|
||||
{
|
||||
Float3 position;
|
||||
Float3 head;
|
||||
int owner;
|
||||
};
|
||||
struct BulletHitStruct
|
||||
{
|
||||
int hitTarget;
|
||||
int attackingTarget;
|
||||
};
|
||||
struct ShipSpawnedStruct
|
||||
{
|
||||
Float3 position;
|
||||
int playerID;
|
||||
};
|
||||
struct ShipDestroyedStruct
|
||||
{
|
||||
int playerID;
|
||||
int killerID;
|
||||
Score scoreboard[PLAYER_MAX_COUNT];
|
||||
};
|
||||
struct ScoreUpdateStruct
|
||||
{
|
||||
Score scoreboard[PLAYER_MAX_COUNT];
|
||||
};
|
||||
struct GameEndedStruct
|
||||
{
|
||||
int winningTeam;
|
||||
Score scoreboard[PLAYER_MAX_COUNT];
|
||||
};
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef NETWORK_DEPENDENCIES_I_CONNECTION_H
|
||||
#define NETWORK_DEPENDENCIES_I_CONNECTION_H
|
||||
|
||||
//////////////////////////////////
|
||||
// Created by Sam Svensson 2013 //
|
||||
//////////////////////////////////
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Network
|
||||
{
|
||||
class OysterByte;
|
||||
class IConnection
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//sends and recieve functions with bytearrays,
|
||||
//will send to the users connection via socket
|
||||
virtual int Send( OysterByte& bytes ) = 0;
|
||||
virtual int Recieve( OysterByte& bytes) = 0;
|
||||
|
||||
//initiates sockets and address for server and client
|
||||
virtual int InitiateServer( unsigned short port ) { return false; };
|
||||
virtual int InitiateClient() { return false; };
|
||||
|
||||
//Listen function to let client connect, only used by the server
|
||||
virtual int Listen() { return -1; };
|
||||
|
||||
//enables the client to connect with a server with use of name and port
|
||||
//(servers uses Listen instead of connect)
|
||||
virtual int Connect( unsigned short port, const char serverName[] ) { return false; };
|
||||
|
||||
//Disconnects the client or server TODO: optimize!
|
||||
virtual int Disconnect() = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef NETWORK_SERVER_ILISTENER_H
|
||||
#define NETWORK_SERVER_ILISTENER_H
|
||||
|
||||
/////////////////////////////////////
|
||||
// Created by Pontus Fransson 2013 //
|
||||
/////////////////////////////////////
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Network
|
||||
{
|
||||
namespace Server
|
||||
{
|
||||
class IListener
|
||||
{
|
||||
public:
|
||||
virtual bool Init(unsigned int port) = 0;
|
||||
virtual int Accept() = 0;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef NETWORK_DEPENDENCIES_I_POST_BOX_H
|
||||
#define NETWORK_DEPENDENCIES_I_POST_BOX_H
|
||||
|
||||
/////////////////////////////////////
|
||||
// Created by Pontus Fransson 2013 //
|
||||
/////////////////////////////////////
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Network
|
||||
{
|
||||
template <class T>
|
||||
class IPostBox
|
||||
{
|
||||
public:
|
||||
virtual ~IPostBox() {}
|
||||
virtual void PostMessage(T& message) = 0;
|
||||
virtual void FetchMessage(T& message) = 0;
|
||||
virtual bool IsFull() = 0;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef NETWORK_DEPENDENCIES_I_TRANSLATE
|
||||
#define NETWORK_DEPENDENCIES_I_TRANSLATE
|
||||
|
||||
//////////////////////////////////
|
||||
// Created by Sam Svensson 2013 //
|
||||
//////////////////////////////////
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Network
|
||||
{
|
||||
class OysterByte;
|
||||
class ITranslate
|
||||
{
|
||||
|
||||
public:
|
||||
//packs and unpacks packages for sending or recieving over the connection
|
||||
virtual void Pack (Protocols::ProtocolHeader &header, OysterByte& bytes) = 0;
|
||||
virtual void Unpack (Protocols::ProtocolSet* set, OysterByte& bytes ) = 0;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,69 @@
|
|||
#include "Listener.h"
|
||||
|
||||
using namespace Oyster::Network::Server;
|
||||
|
||||
Listener::Listener()
|
||||
{
|
||||
connection = NULL;
|
||||
}
|
||||
|
||||
Listener::~Listener()
|
||||
{
|
||||
if(connection)
|
||||
{
|
||||
delete connection;
|
||||
}
|
||||
}
|
||||
|
||||
bool Listener::Init(unsigned int port)
|
||||
{
|
||||
connection = new Connection();
|
||||
|
||||
connection->InitiateServer(port);
|
||||
|
||||
thread.Create(this, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Listener::Shutdown()
|
||||
{
|
||||
thread.Terminate();
|
||||
}
|
||||
|
||||
void Listener::SetPostBox(Oyster::Network::IPostBox<int>* postBox)
|
||||
{
|
||||
mutex.LockMutex();
|
||||
this->postBox = postBox;
|
||||
mutex.UnlockMutex();
|
||||
}
|
||||
|
||||
int Listener::Accept()
|
||||
{
|
||||
int clientSocket = 0;
|
||||
clientSocket = connection->Listen();
|
||||
|
||||
mutex.LockMutex();
|
||||
postBox->PostMessage(clientSocket);
|
||||
mutex.UnlockMutex();
|
||||
|
||||
return clientSocket;
|
||||
}
|
||||
|
||||
bool Listener::DoWork()
|
||||
{
|
||||
Accept();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
void Listener::ThreadEntry()
|
||||
{
|
||||
std::cout << "Thread started" << std::endl;
|
||||
}
|
||||
|
||||
void Listener::ThreadExit()
|
||||
{
|
||||
std::cout << "Thread stopped" << std::endl;
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
#ifndef NETWORK_SERVER_LISTENER_H
|
||||
#define NETWORK_SERVER_LISTENER_H
|
||||
|
||||
/////////////////////////////////////
|
||||
// Created by Pontus Fransson 2013 //
|
||||
/////////////////////////////////////
|
||||
|
||||
#include "IListener.h"
|
||||
#include "../NetworkDependencies/Connection.h"
|
||||
#include "../../Misc/Thread/OysterThread.h"
|
||||
#include "../../Misc/Thread/OysterMutex.h"
|
||||
#include "IPostBox.h"
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Network
|
||||
{
|
||||
namespace Server
|
||||
{
|
||||
class Listener : public ::Oyster::Thread::IThreadObject
|
||||
{
|
||||
public:
|
||||
Listener();
|
||||
~Listener();
|
||||
|
||||
bool Init(unsigned int port);
|
||||
void Shutdown();
|
||||
|
||||
void SetPostBox(IPostBox<int>* postBox);
|
||||
|
||||
//Thread functions
|
||||
bool DoWork();
|
||||
void ThreadEntry();
|
||||
void ThreadExit();
|
||||
|
||||
private:
|
||||
//Function that runs in the thread.
|
||||
int Accept();
|
||||
|
||||
|
||||
private:
|
||||
::Oyster::Network::Connection* connection;
|
||||
|
||||
::Oyster::Thread::OysterThread thread;
|
||||
OysterMutex mutex;
|
||||
|
||||
IPostBox<int>* postBox;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,254 @@
|
|||
#include "MessageHeader.h"
|
||||
#include "../Packing.h"
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
using namespace Oyster::Network;
|
||||
using namespace Oyster::Network::Messages;
|
||||
using namespace Oyster::Network::Protocols;
|
||||
|
||||
MessageHeader::MessageHeader()
|
||||
{
|
||||
size = 0;
|
||||
}
|
||||
|
||||
MessageHeader::~MessageHeader()
|
||||
{
|
||||
}
|
||||
|
||||
void MessageHeader::Pack(ProtocolHeader& header, OysterByte& bytes)
|
||||
{
|
||||
size = 0;
|
||||
|
||||
PackInt(header.size, bytes);
|
||||
PackInt(header.packageType, bytes);
|
||||
PackInt(header.clientID, bytes);
|
||||
SetSize(bytes);
|
||||
}
|
||||
|
||||
void MessageHeader::Unpack(OysterByte& bytes, ProtocolHeader& header)
|
||||
{
|
||||
size = 0;
|
||||
|
||||
header.size = UnpackInt(bytes);
|
||||
header.packageType = UnpackInt(bytes);
|
||||
header.clientID = UnpackInt(bytes);
|
||||
}
|
||||
|
||||
/**************************
|
||||
Pack
|
||||
**************************/
|
||||
|
||||
void MessageHeader::PackBool(bool i, OysterByte& bytes)
|
||||
{
|
||||
bytes.AddSize(1);
|
||||
Packing::Pack(&bytes.GetByteArray()[size], i);
|
||||
size += 1;
|
||||
}
|
||||
|
||||
void MessageHeader::PackChar(char i, OysterByte& bytes)
|
||||
{
|
||||
bytes.AddSize(1);
|
||||
Packing::Pack(&bytes.GetByteArray()[size], i);
|
||||
size += 1;
|
||||
}
|
||||
|
||||
void MessageHeader::PackUnsignedChar(unsigned char i, OysterByte& bytes)
|
||||
{
|
||||
bytes.AddSize(1);
|
||||
Packing::Pack(&bytes.GetByteArray()[size], i);
|
||||
size += 1;
|
||||
}
|
||||
|
||||
void MessageHeader::PackShort(short i, OysterByte& bytes)
|
||||
{
|
||||
bytes.AddSize(2);
|
||||
Packing::Pack(&bytes.GetByteArray()[size], i);
|
||||
size += 2;
|
||||
}
|
||||
|
||||
void MessageHeader::PackUnsignedShort(unsigned short i, OysterByte& bytes)
|
||||
{
|
||||
bytes.AddSize(2);
|
||||
Packing::Pack(&bytes.GetByteArray()[size], i);
|
||||
size += 2;
|
||||
}
|
||||
|
||||
void MessageHeader::PackInt(int i, OysterByte& bytes)
|
||||
{
|
||||
bytes.AddSize(4);
|
||||
Packing::Pack(&bytes.GetByteArray()[size], i);
|
||||
size += 4;
|
||||
}
|
||||
|
||||
void MessageHeader::PackUnsignedInt(unsigned int i, OysterByte& bytes)
|
||||
{
|
||||
bytes.AddSize(4);
|
||||
Packing::Pack(&bytes.GetByteArray()[size], i);
|
||||
size += 4;
|
||||
}
|
||||
|
||||
void MessageHeader::PackInt64(__int64 i, OysterByte& bytes)
|
||||
{
|
||||
bytes.AddSize(8);
|
||||
Packing::Pack(&bytes.GetByteArray()[size], i);
|
||||
size += 8;
|
||||
}
|
||||
|
||||
void MessageHeader::PackUnsignedInt64(unsigned __int64 i, OysterByte& bytes)
|
||||
{
|
||||
bytes.AddSize(8);
|
||||
Packing::Pack(&bytes.GetByteArray()[size], i);
|
||||
size += 8;
|
||||
}
|
||||
|
||||
void MessageHeader::PackFloat(float i, OysterByte& bytes)
|
||||
{
|
||||
bytes.AddSize(4);
|
||||
Packing::Pack(&bytes.GetByteArray()[size], i);
|
||||
size += 4;
|
||||
}
|
||||
|
||||
void MessageHeader::PackFloat(float i[], unsigned int elementCount, OysterByte& bytes)
|
||||
{
|
||||
bytes.AddSize(4);
|
||||
//Pack number of elements
|
||||
PackUnsignedInt(elementCount, bytes);
|
||||
|
||||
//Pack all elements
|
||||
for(int j = 0; j < (int)elementCount; j++)
|
||||
{
|
||||
PackFloat(i[j], bytes);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageHeader::PackDouble(double i, OysterByte& bytes)
|
||||
{
|
||||
bytes.AddSize(8);
|
||||
Packing::Pack(&bytes.GetByteArray()[size], i);
|
||||
size += 8;
|
||||
}
|
||||
|
||||
void MessageHeader::PackStr(char str[], OysterByte& bytes)
|
||||
{
|
||||
int totalSize = 2 + strlen(str);
|
||||
bytes.AddSize(totalSize);
|
||||
Packing::Pack(&bytes.GetByteArray()[size], str);
|
||||
size += totalSize;
|
||||
}
|
||||
|
||||
void MessageHeader::PackStr(std::string str, OysterByte& bytes)
|
||||
{
|
||||
int totalSize = 2 + str.length();
|
||||
bytes.AddSize(totalSize);
|
||||
Packing::Pack(&bytes.GetByteArray()[size], str);
|
||||
size += totalSize;
|
||||
}
|
||||
|
||||
/**************************
|
||||
Unpack
|
||||
**************************/
|
||||
|
||||
bool MessageHeader::UnpackBool(OysterByte& bytes)
|
||||
{
|
||||
bool i = Packing::Unpackb(&bytes.GetByteArray()[size]);
|
||||
size += 1;
|
||||
return i;
|
||||
}
|
||||
|
||||
char MessageHeader::UnpackChar(OysterByte& bytes)
|
||||
{
|
||||
char i = Packing::Unpackc(&bytes.GetByteArray()[size]);
|
||||
size += 1;
|
||||
return i;
|
||||
}
|
||||
|
||||
unsigned char MessageHeader::UnpackUnsignedChar(OysterByte& bytes)
|
||||
{
|
||||
unsigned char i = Packing::UnpackC(&bytes.GetByteArray()[size]);
|
||||
size += 1;
|
||||
return i;
|
||||
}
|
||||
|
||||
short MessageHeader::UnpackShort(OysterByte& bytes)
|
||||
{
|
||||
short i = Packing::Unpacks(&bytes.GetByteArray()[size]);
|
||||
size += 2;
|
||||
return i;
|
||||
}
|
||||
|
||||
unsigned short MessageHeader::UnpackUnsignedShort(OysterByte& bytes)
|
||||
{
|
||||
unsigned short i = Packing::UnpackS(&bytes.GetByteArray()[size]);
|
||||
size += 2;
|
||||
return i;
|
||||
}
|
||||
|
||||
int MessageHeader::UnpackInt(OysterByte& bytes)
|
||||
{
|
||||
int i = Packing::Unpacki(&bytes.GetByteArray()[size]);
|
||||
size += 4;
|
||||
return i;
|
||||
}
|
||||
|
||||
unsigned int MessageHeader::UnpackUnsignedInt(OysterByte& bytes)
|
||||
{
|
||||
unsigned int i = Packing::UnpackI(&bytes.GetByteArray()[size]);
|
||||
size += 4;
|
||||
return i;
|
||||
}
|
||||
|
||||
__int64 MessageHeader::UnpackInt64(OysterByte& bytes)
|
||||
{
|
||||
__int64 i = Packing::Unpacki64(&bytes.GetByteArray()[size]);
|
||||
size += 8;
|
||||
return i;
|
||||
}
|
||||
|
||||
unsigned __int64 MessageHeader::UnpackUnsignedInt64(OysterByte& bytes)
|
||||
{
|
||||
unsigned __int64 i = Packing::UnpackI64(&bytes.GetByteArray()[size]);
|
||||
size += 8;
|
||||
return i;
|
||||
}
|
||||
|
||||
float MessageHeader::UnpackFloat(OysterByte& bytes)
|
||||
{
|
||||
float i = Packing::Unpackf(&bytes.GetByteArray()[size]);
|
||||
size += 4;
|
||||
return i;
|
||||
}
|
||||
|
||||
float* MessageHeader::UnpackFloat(unsigned int& elementCount, OysterByte& bytes)
|
||||
{
|
||||
float* i;
|
||||
|
||||
elementCount = UnpackUnsignedInt(bytes);
|
||||
|
||||
i = new float[elementCount];
|
||||
for(int j = 0; j < (int)elementCount; j++)
|
||||
{
|
||||
i[j] = UnpackFloat(bytes);
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
double MessageHeader::UnpackDouble(OysterByte& bytes)
|
||||
{
|
||||
double i = Packing::Unpackd(&bytes.GetByteArray()[size]);
|
||||
size += 8;
|
||||
return i;
|
||||
}
|
||||
|
||||
std::string MessageHeader::UnpackStr(OysterByte& bytes)
|
||||
{
|
||||
std::string str = Packing::UnpackStr(&bytes.GetByteArray()[size]);
|
||||
size += 2 + str.length();
|
||||
return str;
|
||||
}
|
||||
|
||||
void MessageHeader::SetSize(OysterByte& bytes)
|
||||
{
|
||||
Packing::Pack(bytes, size);
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
#ifndef NETWORK_DEPENDENCIES_MESSAGE_HEADER_H
|
||||
#define NETWORK_DEPENDENCIES_MESSAGE_HEADER_H
|
||||
|
||||
/////////////////////////////////////
|
||||
// Created by Pontus Fransson 2013 //
|
||||
/////////////////////////////////////
|
||||
|
||||
#include <string>
|
||||
#include "../Protocols.h"
|
||||
#include "../OysterByte.h"
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Network
|
||||
{
|
||||
namespace Messages
|
||||
{
|
||||
class MessageHeader
|
||||
{
|
||||
public:
|
||||
MessageHeader();
|
||||
virtual ~MessageHeader();
|
||||
|
||||
virtual void Pack(Protocols::ProtocolHeader& header, OysterByte& bytes );
|
||||
virtual void Unpack(OysterByte& bytes, Protocols::ProtocolHeader& header);
|
||||
|
||||
protected:
|
||||
//Pack variables to messages
|
||||
void PackBool(bool i, OysterByte& bytes);
|
||||
|
||||
void PackChar(char i, OysterByte& bytes);
|
||||
void PackUnsignedChar(unsigned char i, OysterByte& bytes);
|
||||
|
||||
void PackShort(short i, OysterByte& bytes);
|
||||
void PackUnsignedShort(unsigned short i, OysterByte& bytes);
|
||||
|
||||
void PackInt(int i, OysterByte& bytes);
|
||||
void PackUnsignedInt(unsigned int i, OysterByte& bytes);
|
||||
|
||||
void PackInt64(__int64 i, OysterByte& bytes);
|
||||
void PackUnsignedInt64(unsigned __int64 i, OysterByte& bytes);
|
||||
|
||||
void PackFloat(float i, OysterByte& bytes);
|
||||
void PackFloat(float i[], unsigned int elementCount, OysterByte& bytes);
|
||||
void PackDouble(double i, OysterByte& bytes);
|
||||
|
||||
void PackStr(char str[], OysterByte& bytes);
|
||||
void PackStr(std::string str, OysterByte& bytes);
|
||||
|
||||
//TODO: Add Pack functions for Vec2, 3, 4 and maybe Matrix. Etc.
|
||||
|
||||
|
||||
//Unpack variables from message
|
||||
bool UnpackBool(OysterByte& bytes);
|
||||
|
||||
char UnpackChar(OysterByte& bytes);
|
||||
unsigned char UnpackUnsignedChar(OysterByte& bytes);
|
||||
|
||||
short UnpackShort(OysterByte& bytes);
|
||||
unsigned short UnpackUnsignedShort(OysterByte& bytes);
|
||||
|
||||
int UnpackInt(OysterByte& bytes);
|
||||
unsigned int UnpackUnsignedInt(OysterByte& bytes);
|
||||
|
||||
__int64 UnpackInt64(OysterByte& bytes);
|
||||
unsigned __int64 UnpackUnsignedInt64(OysterByte& bytes);
|
||||
|
||||
float UnpackFloat(OysterByte& bytes);
|
||||
float* UnpackFloat(unsigned int& elementCount, OysterByte& bytes);
|
||||
double UnpackDouble(OysterByte& bytes);
|
||||
|
||||
std::string UnpackStr(OysterByte& bytes);
|
||||
|
||||
//TODO: Add Unpack functions for Vec2, 3, 4 and maybe Matrix. Etc.
|
||||
|
||||
|
||||
//Sets the this->size to the first position in msg
|
||||
void SetSize(OysterByte& bytes);
|
||||
|
||||
private:
|
||||
unsigned int size;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,30 @@
|
|||
#include "MessageTest.h"
|
||||
|
||||
using namespace Oyster::Network;
|
||||
using namespace Oyster::Network::Messages;
|
||||
using namespace Oyster::Network::Protocols;
|
||||
|
||||
MessageTest::MessageTest()
|
||||
{
|
||||
}
|
||||
|
||||
MessageTest::~MessageTest()
|
||||
{
|
||||
}
|
||||
|
||||
void MessageTest::Pack(ProtocolHeader& header, OysterByte& bytes)
|
||||
{
|
||||
MessageHeader::Pack(header, bytes);
|
||||
|
||||
PackStr(static_cast<ProtocolTest*>(&header)->textMessage, bytes);
|
||||
PackFloat(static_cast<ProtocolTest*>(&header)->f, static_cast<ProtocolTest*>(&header)->numOfFloats, bytes);
|
||||
SetSize(bytes);
|
||||
}
|
||||
|
||||
void MessageTest::Unpack(OysterByte& bytes, ProtocolHeader& header)
|
||||
{
|
||||
MessageHeader::Unpack(bytes, header);
|
||||
|
||||
static_cast<ProtocolTest*>(&header)->textMessage = UnpackStr(bytes);
|
||||
static_cast<ProtocolTest*>(&header)->f = UnpackFloat(static_cast<ProtocolTest*>(&header)->numOfFloats, bytes);
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef NETWORK_DEPENDENCIES_MESSAGE_TEST_H
|
||||
#define NETWORK_DEPENDENCIES_MESSAGE_TEST_H
|
||||
|
||||
/////////////////////////////////////
|
||||
// Created by Pontus Fransson 2013 //
|
||||
/////////////////////////////////////
|
||||
|
||||
#include "MessageHeader.h"
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Network
|
||||
{
|
||||
namespace Messages
|
||||
{
|
||||
class MessageTest : public MessageHeader
|
||||
{
|
||||
public:
|
||||
MessageTest();
|
||||
virtual ~MessageTest();
|
||||
|
||||
virtual void Pack(Protocols::ProtocolHeader& header, OysterByte& bytes);
|
||||
virtual void Unpack(OysterByte& bytes, Protocols::ProtocolHeader& header);
|
||||
|
||||
private:
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef NETWORK_DEPENDENCIES_MESSAGES_INCLUDE_H
|
||||
#define NETWORK_DEPENDENCIES_MESSAGES_INCLUDE_H
|
||||
|
||||
/////////////////////////////////////
|
||||
// Created by Pontus Fransson 2013 //
|
||||
/////////////////////////////////////
|
||||
|
||||
#include "MessageHeader.h"
|
||||
#include "MessageTest.h"
|
||||
|
||||
#endif
|
|
@ -1,11 +0,0 @@
|
|||
#ifndef NETWORK_H
|
||||
#define NETWORK_H
|
||||
#include "NetworkIncludes.h"
|
||||
#include "EventStructs.h"
|
||||
#include "NetworkUpdateStructs.h"
|
||||
#include "NetworkInitStructs.h"
|
||||
#include "EventStructs.h"
|
||||
#include "Event.h"
|
||||
#include "NetworkMiscFunctions.h"
|
||||
#include "NetworkTimer.h"
|
||||
#endif
|
|
@ -1,11 +0,0 @@
|
|||
#pragma once
|
||||
#ifndef NET_CONST_H
|
||||
#define NET_CONST_H
|
||||
//const int PLAYER_WAIT_COUNT = 1;
|
||||
const int PLAYER_MAX_COUNT = 8;
|
||||
const float LOBBY_WAIT_TIME = 4;
|
||||
/*namespace Network
|
||||
{
|
||||
void LoadData(){}
|
||||
}*/
|
||||
#endif
|
|
@ -27,7 +27,7 @@
|
|||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
|
@ -69,28 +69,36 @@
|
|||
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
|
||||
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\Program Files (x86)\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
|
||||
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\Program Files (x86)\Visual Leak Detector\lib\Win64;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
|
||||
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\Program Files (x86)\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
|
||||
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\Program Files (x86)\Visual Leak Detector\lib\Win64;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>..\..\Misc;..\..\OysterMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
@ -101,7 +109,7 @@
|
|||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>..\..\Misc;..\..\OysterMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
@ -114,7 +122,7 @@
|
|||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>..\..\Misc;..\..\OysterMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
@ -129,7 +137,7 @@
|
|||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>..\..\Misc;..\..\OysterMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
@ -137,35 +145,38 @@
|
|||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Event.h" />
|
||||
<ClInclude Include="EventStructs.h" />
|
||||
<ClInclude Include="Network.h" />
|
||||
<ClInclude Include="NetworkConstants.h" />
|
||||
<ClInclude Include="NetworkIncludes.h" />
|
||||
<ClInclude Include="NetworkInitStructs.h" />
|
||||
<ClInclude Include="NetworkMiscFunctions.h" />
|
||||
<ClInclude Include="NetworkTimer.h" />
|
||||
<ClInclude Include="NetworkUpdateStructs.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Event.cpp" />
|
||||
<ClCompile Include="NetworkMiscFunctions.cpp" />
|
||||
<ClCompile Include="NetworkTimer.cpp" />
|
||||
<ClCompile Include="UpdateStructs.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Misc\Misc.vcxproj">
|
||||
<Project>{2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\OysterMath\OysterMath.vcxproj">
|
||||
<Project>{f10cbc03-9809-4cba-95d8-327c287b18ee}</Project>
|
||||
<Private>true</Private>
|
||||
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
|
||||
<CopyLocalSatelliteAssemblies>true</CopyLocalSatelliteAssemblies>
|
||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
||||
<UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Connection.cpp" />
|
||||
<ClCompile Include="Listener.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="Messages\MessageHeader.cpp" />
|
||||
<ClCompile Include="Messages\MessageTest.cpp" />
|
||||
<ClCompile Include="OysterByte.cpp" />
|
||||
<ClCompile Include="Packing.cpp" />
|
||||
<ClCompile Include="Translator.cpp" />
|
||||
<ClCompile Include="WinsockFunctions.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Connection.h" />
|
||||
<ClInclude Include="IConnection.h" />
|
||||
<ClInclude Include="IListener.h" />
|
||||
<ClInclude Include="IPostBox.h" />
|
||||
<ClInclude Include="Listener.h" />
|
||||
<ClInclude Include="Messages\MessageHeader.h" />
|
||||
<ClInclude Include="Messages\MessagesInclude.h" />
|
||||
<ClInclude Include="Messages\MessageTest.h" />
|
||||
<ClInclude Include="OysterByte.h" />
|
||||
<ClInclude Include="Packing.h" />
|
||||
<ClInclude Include="ITranslate.h" />
|
||||
<ClInclude Include="PostBox.h" />
|
||||
<ClInclude Include="Protocols.h" />
|
||||
<ClInclude Include="Translator.h" />
|
||||
<ClInclude Include="WinsockFunctions.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
|
|
@ -1,60 +1,31 @@
|
|||
<?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;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;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>
|
||||
<ClCompile Include="Connection.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="Messages\MessageHeader.cpp" />
|
||||
<ClCompile Include="Messages\MessageTest.cpp" />
|
||||
<ClCompile Include="Packing.cpp" />
|
||||
<ClCompile Include="Translator.cpp" />
|
||||
<ClCompile Include="Listener.cpp" />
|
||||
<ClCompile Include="WinsockFunctions.cpp" />
|
||||
<ClCompile Include="OysterByte.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Network.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="NetworkConstants.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="NetworkIncludes.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="NetworkInitStructs.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="NetworkMiscFunctions.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="NetworkTimer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="NetworkUpdateStructs.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="EventStructs.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Event.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="NetworkMiscFunctions.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="NetworkTimer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="UpdateStructs.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Event.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="Connection.h" />
|
||||
<ClInclude Include="IConnection.h" />
|
||||
<ClInclude Include="Messages\MessageHeader.h" />
|
||||
<ClInclude Include="Messages\MessageTest.h" />
|
||||
<ClInclude Include="Packing.h" />
|
||||
<ClInclude Include="ITranslate.h" />
|
||||
<ClInclude Include="Protocols.h" />
|
||||
<ClInclude Include="Translator.h" />
|
||||
<ClInclude Include="Messages\MessagesInclude.h" />
|
||||
<ClInclude Include="Listener.h" />
|
||||
<ClInclude Include="IListener.h" />
|
||||
<ClInclude Include="WinsockFunctions.h" />
|
||||
<ClInclude Include="OysterByte.h" />
|
||||
<ClInclude Include="IPostBox.h" />
|
||||
<ClInclude Include="PostBox.h" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,23 +0,0 @@
|
|||
#ifndef NET_INCL_H
|
||||
#define NET_INCL_H
|
||||
#ifndef UNICODE
|
||||
#define UNICODE
|
||||
#endif
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <winsock2.h>
|
||||
#include <Ws2tcpip.h>
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
#include <time.h>
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
|
||||
#include "OysterMath.h"
|
||||
using namespace Oyster::Math;
|
||||
|
||||
//ws2_32.lib is a lib file the linker requires for winsock compilation
|
||||
#pragma comment(lib, "Ws2_32.lib")
|
||||
#endif
|
|
@ -1,70 +0,0 @@
|
|||
#ifndef NET_INIT_STRUCTS_H
|
||||
#define NET_INIT_STRUCTS_H
|
||||
#include "NetworkIncludes.h"
|
||||
#include "NetworkConstants.h"
|
||||
struct PlayerInitStruct
|
||||
{
|
||||
INT8 pid;
|
||||
int teamid;
|
||||
Oyster::Math::Float4x4 position;
|
||||
PlayerInitStruct()
|
||||
{
|
||||
pid=0;
|
||||
//position=Oyster::Math::Float4x4::identity;
|
||||
}
|
||||
};
|
||||
|
||||
struct GameInitData
|
||||
{
|
||||
INT8 pid;
|
||||
//std::string playerNames[PLAYER_MAX_COUNT];
|
||||
PlayerInitStruct player[PLAYER_MAX_COUNT];
|
||||
};
|
||||
|
||||
struct LobbyUserStruct
|
||||
{
|
||||
INT8 pid;
|
||||
INT8 shipID;
|
||||
char usrName[15];
|
||||
LobbyUserStruct()
|
||||
{
|
||||
pid=0;
|
||||
shipID=0;
|
||||
usrName[0]='\0';
|
||||
}
|
||||
void setName(const char* n)
|
||||
{
|
||||
strcpy_s(usrName, n);
|
||||
}
|
||||
int size()
|
||||
{
|
||||
int sz=sizeof(pid);
|
||||
sz+=sizeof(shipID);
|
||||
int tmp=(int)strlen(usrName);
|
||||
sz+=(int)strlen(usrName);
|
||||
return sz;
|
||||
}
|
||||
};
|
||||
struct LobbyInitData
|
||||
{
|
||||
INT8 pid;
|
||||
INT8 playerCount;
|
||||
int timer;
|
||||
LobbyUserStruct players[PLAYER_MAX_COUNT];
|
||||
LobbyInitData()
|
||||
{
|
||||
pid=0;
|
||||
for (int i=0; i<PLAYER_MAX_COUNT; i++)
|
||||
{
|
||||
players[i].pid=i;
|
||||
}
|
||||
}
|
||||
int size()
|
||||
{
|
||||
int sz=sizeof(pid);
|
||||
for (int i=0; i<PLAYER_MAX_COUNT; i++)
|
||||
sz+=players[i].size();
|
||||
return sz;
|
||||
}
|
||||
};
|
||||
#endif
|
|
@ -1,12 +0,0 @@
|
|||
#include "NetworkMiscFunctions.h"
|
||||
std::vector<std::string> splitString(const char* p_inStr, char p_delim)
|
||||
{
|
||||
std::stringstream ss(p_inStr);
|
||||
std::vector<std::string> elems;
|
||||
std::string item;
|
||||
while(std::getline(ss, item, p_delim))
|
||||
{
|
||||
elems.push_back(item);
|
||||
}
|
||||
return elems;
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
#ifndef NET_MISC_FNC_H
|
||||
#define NET_MISC_FNC_H
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
std::vector<std::string> splitString(const char* p_inStr, char p_delim);
|
||||
#define SSTR( x ) dynamic_cast< std::ostringstream & >( \
|
||||
( std::ostringstream() << std::dec << x ) ).str()
|
||||
#endif
|
|
@ -1,85 +0,0 @@
|
|||
#include "NetworkTimer.h"
|
||||
NetworkTimer::NetworkTimer()
|
||||
:
|
||||
c_SecondsPerCount(0.0),
|
||||
c_DeltaTime(-1.0),
|
||||
c_BaseTime(0),
|
||||
c_PausedTime(0),
|
||||
c_PrevTime(0),
|
||||
c_CurrTime(0),
|
||||
c_Stopped(false)
|
||||
{
|
||||
__int64 countsPerSec;
|
||||
QueryPerformanceFrequency((LARGE_INTEGER*)&countsPerSec);
|
||||
c_SecondsPerCount =1.0 / (double)countsPerSec;
|
||||
|
||||
QueryPerformanceCounter((LARGE_INTEGER*)&c_PrevTime);
|
||||
}
|
||||
|
||||
void NetworkTimer::start()
|
||||
{
|
||||
__int64 p_StartTime;
|
||||
QueryPerformanceCounter((LARGE_INTEGER*)&p_StartTime);
|
||||
if(c_Stopped)
|
||||
{
|
||||
c_PausedTime += (p_StartTime-c_StopTime);
|
||||
c_PrevTime = p_StartTime;
|
||||
c_StopTime = 0;
|
||||
c_Stopped = false;
|
||||
}
|
||||
}
|
||||
__int64 NetworkTimer::getTime()
|
||||
{
|
||||
__int64 testInt;
|
||||
return QueryPerformanceCounter((LARGE_INTEGER*)&testInt);
|
||||
return testInt;
|
||||
}
|
||||
|
||||
void NetworkTimer::stop()
|
||||
{
|
||||
if(!c_Stopped)
|
||||
{
|
||||
__int64 p_CurrTime;
|
||||
QueryPerformanceCounter((LARGE_INTEGER*)&p_CurrTime);
|
||||
c_StopTime = p_CurrTime;
|
||||
c_Stopped = true;
|
||||
}
|
||||
}
|
||||
void NetworkTimer::reset()
|
||||
{
|
||||
__int64 p_CurrTime;
|
||||
QueryPerformanceCounter((LARGE_INTEGER*)&p_CurrTime);
|
||||
c_BaseTime = p_CurrTime;
|
||||
c_PrevTime = p_CurrTime;
|
||||
c_StopTime = 0;
|
||||
c_Stopped = false;
|
||||
}
|
||||
void NetworkTimer::tick()
|
||||
{
|
||||
if (c_Stopped)
|
||||
{
|
||||
c_DeltaTime= 0.0;
|
||||
return;
|
||||
}
|
||||
__int64 p_CurrTime;
|
||||
QueryPerformanceCounter((LARGE_INTEGER*)&p_CurrTime);
|
||||
c_CurrTime=p_CurrTime;
|
||||
|
||||
c_DeltaTime=(c_CurrTime-c_PrevTime)*c_SecondsPerCount;
|
||||
c_PrevTime=c_CurrTime;
|
||||
if(c_DeltaTime<0.0) c_DeltaTime=0.0;
|
||||
}
|
||||
float NetworkTimer::getGameTime() const
|
||||
{
|
||||
if(c_Stopped)
|
||||
{
|
||||
return (float)((c_StopTime-c_BaseTime)*c_SecondsPerCount);
|
||||
} else
|
||||
{
|
||||
return (float)(((c_CurrTime-c_PausedTime)-c_BaseTime)*c_SecondsPerCount);
|
||||
}
|
||||
}
|
||||
float NetworkTimer::getDeltaTime() const
|
||||
{
|
||||
return (float)c_DeltaTime;
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
#include "NetworkIncludes.h"
|
||||
#ifndef _NET_TIMER_H
|
||||
#define _NET_TIMER_H
|
||||
class NetworkTimer
|
||||
{
|
||||
private:
|
||||
double c_SecondsPerCount;
|
||||
double c_DeltaTime;
|
||||
__int64 c_BaseTime;
|
||||
__int64 c_PausedTime;
|
||||
__int64 c_StopTime;
|
||||
__int64 c_PrevTime;
|
||||
__int64 c_CurrTime;
|
||||
bool c_Stopped;
|
||||
public:
|
||||
NetworkTimer();
|
||||
__int64 getTime();
|
||||
void start();
|
||||
void stop();
|
||||
void reset();
|
||||
void tick();
|
||||
float getGameTime() const;
|
||||
float getDeltaTime() const;
|
||||
};
|
||||
#endif
|
|
@ -1,62 +0,0 @@
|
|||
#ifndef NET_UPD_STRUCTS_H
|
||||
#define NET_UPD_STRUCTS_H
|
||||
#include "NetworkIncludes.h"
|
||||
namespace Network
|
||||
{
|
||||
struct EffectData
|
||||
{
|
||||
int identifier;
|
||||
Float3 head;
|
||||
Float3 tail;
|
||||
};
|
||||
struct ServerToClientUpdateData
|
||||
{
|
||||
int pid;
|
||||
Oyster::Math::Float4x4 position;
|
||||
float dirVecLen;
|
||||
int hp;
|
||||
int shield;
|
||||
long updateCount;
|
||||
ServerToClientUpdateData()
|
||||
{
|
||||
pid=0;
|
||||
updateCount=0;
|
||||
hp=0;
|
||||
shield=0;
|
||||
}
|
||||
};
|
||||
const int SERVER_PLAYER_DATA_SIZE = 84;
|
||||
struct ClientToServerUpdateData
|
||||
{
|
||||
__int8 pid;
|
||||
//Oyster::Math::Float4x4 position;
|
||||
__int8 forward;
|
||||
__int8 roll;
|
||||
__int8 straferight;
|
||||
__int8 strafeup;
|
||||
bool firePrim;
|
||||
bool fireSecond;
|
||||
bool fireSpecial;
|
||||
long updateCount;
|
||||
bool braking;
|
||||
float TurnHor;
|
||||
float TurnVer;
|
||||
ClientToServerUpdateData()
|
||||
{
|
||||
pid=0;
|
||||
forward=0;
|
||||
roll=0;
|
||||
straferight=0;
|
||||
strafeup=0;
|
||||
firePrim=false;
|
||||
fireSecond=false;
|
||||
fireSpecial=false;
|
||||
updateCount=0;
|
||||
braking=false;
|
||||
TurnHor= 0.0f;
|
||||
TurnVer= 0.0f;
|
||||
}
|
||||
};
|
||||
const int CLIENT_PLAYER_DATA_SIZE = sizeof(ClientToServerUpdateData);
|
||||
}
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue