From da5b9c73065ad8335bc89d18cef913956e204c60 Mon Sep 17 00:00:00 2001 From: lanariel Date: Wed, 12 Feb 2014 12:05:27 +0100 Subject: [PATCH 01/22] Nomal Mapping For TA --- .../Shader/Passes/Gather/GatherPixel.hlsl | 43 ++++++++++++++++++- .../Shader/Passes/Gather/GatherVertex.hlsl | 1 + .../Shader/Passes/Gather/Header.hlsli | 2 +- .../Shader/Passes/Post/PostPass.hlsl | 2 +- Code/Tester/MainTest.cpp | 4 +- 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl index b0a2f40f..0fbf0b92 100644 --- a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl @@ -1,9 +1,50 @@ #include "Header.hlsli" + + +float3x3 cotangent_frame( float3 N, float3 p, float2 uv ) +{ + // get edge vectors of the pixel triangle + float3 dp1 = ddx( p ); + float3 dp2 = ddy( p ); + float2 duv1 = ddx( uv ); + float2 duv2 = ddy( uv ); + + // solve the linear system + float3 dp2perp = cross( dp2, N ); + float3 dp1perp = cross( N, dp1 ); + float3 T = dp2perp * duv1.x + dp1perp * duv2.x; + float3 B = dp2perp * duv1.y + dp1perp * duv2.y; + + // construct a scale-invariant frame + float invmax = 1/sqrt( max( dot(T,T), dot(B,B) ) ); + return float3x3( T * invmax, B * invmax, N ); +} + +float3 perturb_normal( float3 N, float3 V, float2 texcoord ) +{ + // assume N, the interpolated vertex normal and + // V, the view vector (vertex to eye) + float3 map = Normal.Sample(S1,texcoord).xyz; + map = map * 255./127. - 128./127.; +#ifdef WITH_NORMALMAP_2CHANNEL + map.z = sqrt( 1. - dot( map.xy, map.xy ) ); +#endif +#ifdef WITH_NORMALMAP_GREEN_UP + map.y = -map.y; +#endif + float3x3 TBN = cotangent_frame( N, -V, texcoord ); + return normalize( mul(transpose(TBN), map) ); +} + PixelOut main(VertexOut input) { PixelOut output; output.DiffuseGlow = Diffuse.Sample(S1, input.UV); - output.NormalSpec = float4(normalize(input.normal), Normal.Sample(S1,input.UV).w); + float3 normal = normalize(input.normal); + + normal = perturb_normal( normal, normalize(-input.ViewPos), input.UV ); + + output.NormalSpec = float4(normal, Normal.Sample(S1,input.UV).w); return output; } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/Gather/GatherVertex.hlsl b/Code/OysterGraphics/Shader/Passes/Gather/GatherVertex.hlsl index 4042c224..fd3da6b1 100644 --- a/Code/OysterGraphics/Shader/Passes/Gather/GatherVertex.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Gather/GatherVertex.hlsl @@ -14,6 +14,7 @@ VertexOut main( VertexIn input ) input.normal = mul(boneTrans,float4(input.normal,1)).xyz * Animated + input.normal * int(1-Animated); output.pos = mul(WVP, float4(input.pos,1)); + output.ViewPos = mul(WV, float4(input.pos,1)); output.normal = mul(WV, float4(input.normal,0)).xyz; output.UV = input.UV; return output; diff --git a/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli b/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli index a313a649..14e0db5a 100644 --- a/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli +++ b/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli @@ -12,7 +12,7 @@ struct VertexIn struct VertexOut { float4 pos : SV_POSITION; - //float4 ViewPos : POSITION; + float4 ViewPos : POSITION; float2 UV : TEXCOORD; float3 normal : NORMAL; //float3 tangent : TANGENT; diff --git a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl index 247efb42..53cfabb2 100644 --- a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl @@ -17,7 +17,7 @@ void main( uint3 DTid : SV_DispatchThreadID ) float4 Light = Diffuse[DTid.xy] + saturate(Specular[DTid.xy]); float4 Amb = float4(Ambient[DTid.xy/2].xyz * Ambient[DTid.xy/2].w, 0); float4 GUI; - uint2 index = DTid.xy/2 + uint2(Pixels.x/2,0); + uint2 index = DTid.xy/2 + uint2((uint)Pixels.x/(uint)2,0); float3 PostLight = Amb.xyz * AmbFactor; PostLight = PostLight + Light.xyz; GUI = float4(Ambient[index]); diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index 4462f060..baf63cb3 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -176,7 +176,7 @@ HRESULT InitDirect3D() m->WorldMatrix.m[2][2] = 0.00000005f; m2 = Oyster::Graphics::API::CreateModel(L"char_temporary.dan"); m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(4,0,0),Oyster::Math::Float3::null); - Oyster::Graphics::API::PlayAnimation(m2, L"movement",false); + Oyster::Graphics::API::PlayAnimation(m2, L"movement"); t = Oyster::Graphics::API::CreateTexture(L"structure_corp_mdg.png"); t2 = Oyster::Graphics::API::CreateTexture(L"whiteGui.png"); @@ -233,7 +233,7 @@ HRESULT Render(float deltaTime) Oyster::Graphics::API::RenderModel(m2); Oyster::Graphics::API::StartGuiRender(); Oyster::Graphics::API::RenderGuiElement(t,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1)); - //Oyster::Graphics::API::RenderGuiElement(t2,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float3(1,0,0)); + Oyster::Graphics::API::RenderGuiElement(t2,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float3(1,0,0)); Oyster::Graphics::API::StartTextRender(); std::wstring fps; float f = 1/deltaTime; From 11b6f6eddc983726a02bf4eb86540f8f9d93ebc6 Mon Sep 17 00:00:00 2001 From: lanariel Date: Wed, 12 Feb 2014 13:53:52 +0100 Subject: [PATCH 02/22] Fixed Spec coefficient --- Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl | 2 +- Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli | 2 ++ Code/Tester/MainTest.cpp | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl index 0fbf0b92..464da702 100644 --- a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl @@ -45,6 +45,6 @@ PixelOut main(VertexOut input) normal = perturb_normal( normal, normalize(-input.ViewPos), input.UV ); - output.NormalSpec = float4(normal, Normal.Sample(S1,input.UV).w); + output.NormalSpec = float4(normal, Normal.Sample(S1, input.UV).w*255); return output; } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli b/Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli index 8a1ff05a..3dc2b45e 100644 --- a/Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli +++ b/Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli @@ -24,5 +24,7 @@ DiffSpec LightCalc(PointLight pl, float3 pos, int2 texCoord) output.Diffuse = float3(0,0,0); output.Specular = float3(0,0,0); } + float SpecCo = normalSpec.w < 1 ? 0.0f : 1.0f; + output.Specular = output.Specular * SpecCo; return output; } \ No newline at end of file diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index baf63cb3..3813d3e9 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -229,11 +229,11 @@ HRESULT Render(float deltaTime) Oyster::Graphics::API::SetView(V); Oyster::Graphics::API::NewFrame(); - Oyster::Graphics::API::RenderModel(m); + //Oyster::Graphics::API::RenderModel(m); Oyster::Graphics::API::RenderModel(m2); Oyster::Graphics::API::StartGuiRender(); - Oyster::Graphics::API::RenderGuiElement(t,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1)); - Oyster::Graphics::API::RenderGuiElement(t2,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float3(1,0,0)); + //Oyster::Graphics::API::RenderGuiElement(t,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1)); + //Oyster::Graphics::API::RenderGuiElement(t2,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1),Oyster::Math::Float3(1,0,0)); Oyster::Graphics::API::StartTextRender(); std::wstring fps; float f = 1/deltaTime; From 64b2d688bd41fe5be16ba1e7863fe0c2cf9c9282 Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Wed, 12 Feb 2014 14:48:58 +0100 Subject: [PATCH 03/22] =?UTF-8?q?F=C3=B6rs=C3=B6k=20till=20merge=20men=20d?= =?UTF-8?q?et=20=C3=A4r=20cp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DanBiasGame/GameClientState/GameState.cpp | 21 +- .../LevelLoader/LevelLoader.cpp | 23 ++- .../GameClientState/LevelLoader/LevelLoader.h | 18 +- .../LevelLoader/LevelParser.cpp | 147 ++++++++++++-- .../GameClientState/LevelLoader/LevelParser.h | 2 +- .../LevelLoader/ObjectDefines.h | 180 ++++++++++++++---- .../LevelLoader/ParseFunctions.cpp | 83 +++++++- .../LevelLoader/ParseFunctions.h | 4 +- Code/Game/GameLogic/CollisionManager.cpp | 23 +-- Code/Game/GameLogic/DynamicObject.cpp | 10 +- Code/Game/GameLogic/DynamicObject.h | 12 +- Code/Game/GameLogic/Game.cpp | 4 +- Code/Game/GameLogic/Game.h | 6 +- Code/Game/GameLogic/GameAPI.h | 3 +- Code/Game/GameLogic/GameLogicStates.h | 9 - Code/Game/GameLogic/Game_LevelData.cpp | 2 +- Code/Game/GameLogic/Game_PlayerData.cpp | 9 +- Code/Game/GameLogic/JumpPad.cpp | 3 +- Code/Game/GameLogic/JumpPad.h | 2 +- Code/Game/GameLogic/Level.cpp | 146 ++++++++++++-- .../GameLogic/LevelLoader/LevelParser.cpp | 56 +++--- .../GameLogic/LevelLoader/ObjectDefines.h | 28 ++- .../GameLogic/LevelLoader/ParseFunctions.cpp | 29 ++- .../GameLogic/LevelLoader/ParseFunctions.h | 3 +- Code/Game/GameLogic/Object.cpp | 16 +- Code/Game/GameLogic/Object.h | 24 ++- Code/Game/GameLogic/Player.cpp | 11 +- Code/Game/GameLogic/Player.h | 11 +- Code/Game/GameLogic/StaticObject.cpp | 10 +- Code/Game/GameLogic/StaticObject.h | 12 +- 30 files changed, 676 insertions(+), 231 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 4c2899e1..556ee28d 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -4,7 +4,9 @@ #include "NetworkClient.h" #include "Camera.h" #include +#include "LevelLoader\ObjectDefines.h" +using namespace GameLogic; using namespace DanBias::Client; using namespace Oyster::Math; struct GameState::myData @@ -78,7 +80,7 @@ GameState::gameStateState GameState::LoadGame() //LoadModels("3bana.bias"); // hardcoded objects - LoadModels(); + LoadModels("C:/Users/Sam/Documents/GitHub/Danbias/Bin/Content/worlds/ccc.bias"); Float3 startPos = Float3(0,0,20.0f); InitCamera(startPos); return gameStateState_playing; @@ -199,9 +201,9 @@ bool GameState::LoadModels(std::string mapFile) modelData.modelPath.assign(staticObjData->ModelFile.begin(), staticObjData->ModelFile.end()); modelData.visible = true; - //modelData.position = ; - //modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(2,2,-2), 1); - //modelData.scale = Oyster::Math::Float3(2,2,2); + modelData.position = staticObjData->position; + modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(staticObjData->rotation), staticObjData->rotation[3]); + modelData.scale = staticObjData->scale; modelData.id = modelId++; this->staticObjects.Push(new C_StaticObj()); @@ -211,11 +213,11 @@ bool GameState::LoadModels(std::string mapFile) case GameLogic::ObjectType::ObjectType_Dynamic: { GameLogic::ObjectHeader* dynamicObjData = ((GameLogic::ObjectHeader*)obj); - //modelData.position = ; - //modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(2,2,-2), 1); - //modelData.scale = Oyster::Math::Float3(2,2,2); modelData.modelPath.assign(dynamicObjData->ModelFile.begin(), dynamicObjData->ModelFile.end()); modelData.visible = true; + modelData.position = dynamicObjData->position; + modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(dynamicObjData->rotation), dynamicObjData->rotation[3]); + modelData.scale = dynamicObjData->scale; modelData.id = modelId++; this->dynamicObjects.Push(new C_DynamicObj()); @@ -229,8 +231,8 @@ bool GameState::LoadModels(std::string mapFile) if(lightData->lightType == GameLogic::LightType_PointLight) { Oyster::Graphics::Definitions::Pointlight plight; - plight.Pos = ((GameLogic::PointLight*)lightData)->position; - plight.Color = lightData->diffuseColor; + plight.Pos = ((GameLogic::BasicLight*)lightData)->position; + plight.Color = lightData->color; plight.Radius = 100; plight.Bright = 0.9f; Oyster::Graphics::API::AddLight(plight); @@ -560,6 +562,7 @@ void GameState::Protocol( ObjPos* pos ) if(dynamicObjects[i]->GetId() == myId) // playerobj { + Float3 pos = dynamicObjects[i]->getPos(); Float3 up = dynamicObjects[i]->getWorld().v[1]; Float3 objForward = dynamicObjects[i]->getWorld().v[2]; diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.cpp b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.cpp index 55a39725..8fe880f3 100644 --- a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.cpp @@ -17,7 +17,14 @@ struct LevelLoader::PrivData LevelLoader::LevelLoader() : pData(new PrivData) { - pData->folderPath = "Standard path"; + //standard path + pData->folderPath = ""; +} + +LevelLoader::LevelLoader(std::string folderPath) + : pData(new PrivData) +{ + pData->folderPath = folderPath; } LevelLoader::~LevelLoader() @@ -26,10 +33,20 @@ LevelLoader::~LevelLoader() std::vector> LevelLoader::LoadLevel(std::string fileName) { - return pData->parser.Parse(fileName); + return pData->parser.Parse(pData->folderPath + fileName); } LevelMetaData LevelLoader::LoadLevelHeader(std::string fileName) { - return pData->parser.ParseHeader(fileName); + return pData->parser.ParseHeader(pData->folderPath + fileName); +} + +std::string LevelLoader::GetFolderPath() +{ + return this->pData->folderPath; +} + +void LevelLoader::SetFolderPath(std::string folderPath) +{ + } \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.h b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.h index bcd6e587..184a7005 100644 --- a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.h +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.h @@ -17,11 +17,15 @@ namespace GameLogic public: LevelLoader(); + /*********************************************************** + * Lets you set the standard folderpath for the levels + ********************************************************/ + LevelLoader(std::string folderPath); ~LevelLoader(); /******************************************************** * Loads the level and objects from file. - * @param fileName: Path to the level-file that you want to load. + * @param fileName: Path/name to the level-file that you want to load. * @return: Returns all structs with objects and information about the level. ********************************************************/ std::vector> LoadLevel(std::string fileName); @@ -33,10 +37,20 @@ namespace GameLogic ********************************************************/ LevelMetaData LoadLevelHeader(std::string fileName); //. + /*********************************************************** + * @return: Returns the current standard folder path + ********************************************************/ + std::string GetFolderPath(); + + /*********************************************************** + * Sets the standard folder path + ********************************************************/ + void SetFolderPath(std::string folderPath); + private: struct PrivData; Utility::DynamicMemory::SmartPointer pData; - }; + }; } #endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.cpp b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.cpp index 088c3916..c5dfa8cc 100644 --- a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.cpp @@ -1,3 +1,7 @@ +///////////////////////////////////// +// Created by Pontus Fransson 2013 // +///////////////////////////////////// + #include "LevelParser.h" #include "Loader.h" @@ -9,7 +13,7 @@ using namespace Utility::DynamicMemory; LevelParser::LevelParser() { - formatVersion.formatVersionMajor = 1; + formatVersion.formatVersionMajor = 3; formatVersion.formatVersionMinor = 0; } @@ -21,6 +25,7 @@ std::vector> LevelParser::Parse(std::string filen { int bufferSize = 0; int counter = 0; + bool loadCgf; std::vector> objects; @@ -29,35 +34,117 @@ std::vector> LevelParser::Parse(std::string filen char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); //Read format version - FormatVersion levelFormatVersion; + LevelLoaderInternal::FormatVersion levelFormatVersion; ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion)); counter += sizeof(levelFormatVersion); if(this->formatVersion != levelFormatVersion) { - //Do something if it's not the same version + //Returns an empty vector, because it will most likely fail to read the level format. + return objects; } while(counter < bufferSize) { + loadCgf = true; //Get typeID - ObjectTypeHeader typeID; + ObjectType typeID; ParseObject(&buffer[counter], &typeID, sizeof(typeID)); - switch((int)typeID.typeID) + switch((int)typeID) { case ObjectType_LevelMetaData: { - LevelMetaData* header = new LevelMetaData; - ParseLevelMetaData(&buffer[counter], *header, counter); + SmartPointer header = new LevelMetaData; + ParseLevelMetaData(&buffer[counter], *(LevelMetaData*)header.Get(), counter); objects.push_back(header); break; } - //This is by design, static and dynamic is using the same converter. Do not add anything inbetween them. + //This is by design, static and dynamic is using the same converter. Do not add anything inbetween them. + //Unless they are changed to not be the same. case ObjectType_Static: case ObjectType_Dynamic: { - ObjectHeader* header = new ObjectHeader; - ParseObject(&buffer[counter], *header, counter); - objects.push_back(header); + //Get specialType. + ObjectSpecialType specialType; + ParseObject(&buffer[counter+4], &specialType, sizeof(typeID)); + + switch(specialType) + { + //there is no difference when parsing these specialTypes. + case ObjectSpecialType_CrystalShard: + case ObjectSpecialType_CrystalFormation: + case ObjectSpecialType_Spike: + case ObjectSpecialType_SpikeBox: + case ObjectSpecialType_RedExplosiveBox: + case ObjectSpecialType_StandarsBox: + case ObjectSpecialType_Stone: + case ObjectSpecialType_Building: + { + ObjectHeader* header = new ObjectHeader; + ParseObject(&buffer[counter], *header, counter, loadCgf); + objects.push_back(header); + + break; + } + + case ObjectSpecialType_JumpPad: + { + JumpPadAttributes* header = new JumpPadAttributes; + ParseObject(&buffer[counter], *header, counter, loadCgf); + + //Read the spec + ParseObject(&buffer[counter], header->direction, 16); + counter += 16; + objects.push_back(header); + + break; + } + + case ObjectSpecialType_Portal: + { + PortalAttributes* header = new PortalAttributes; + ParseObject(&buffer[counter], *header, counter, loadCgf); + + ParseObject(&buffer[counter], header->destination, 12); + counter += 12; + objects.push_back(header); + + break; + } + + case ObjectSpecialType_World: + { + WorldAttributes* header = new WorldAttributes; + ParseObject(&buffer[counter], *header, counter, loadCgf); + + ParseObject(&buffer[counter], &header->worldSize, 8); + counter += 8; + objects.push_back(header); + break; + } + + case ObjectSpecialType_Sky: + { + loadCgf = false; + SkyAttributes* header = new SkyAttributes; + ParseObject(&buffer[counter], *header, counter, loadCgf); + + ParseObject(&buffer[counter], &header->skySize, 4); + counter += 4; + objects.push_back(header); + break; + } + + case ObjectSpecialType_SpawnPoint: + { + loadCgf = false; + ObjectHeader* header = new ObjectHeader; + ParseObject(&buffer[counter], *header, counter, loadCgf); + } + + default: + //Couldn't find specialType + break; + } break; } @@ -68,7 +155,12 @@ std::vector> LevelParser::Parse(std::string filen //Get Light type ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); - switch(lightType) + //We only support PointLight for now. + BasicLight* header = new BasicLight; + ParseObject(&buffer[counter], header, sizeof(*header)); + counter += sizeof(*header); + objects.push_back(header); + /*switch(lightType) { case LightType_PointLight: { @@ -98,7 +190,7 @@ std::vector> LevelParser::Parse(std::string filen //Undefined LightType. break; } - break; + break;*/ } default: //Couldn't find typeID. FAIL!!!!!! @@ -123,21 +215,25 @@ LevelMetaData LevelParser::ParseHeader(std::string filename) char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); //Read format version - FormatVersion levelFormatVersion; + LevelLoaderInternal::FormatVersion levelFormatVersion; ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion)); counter += sizeof(levelFormatVersion); if(this->formatVersion != levelFormatVersion) { //Do something if it's not the same version + + //Returns an empty levelHeader with ObjectType_Unknown. + //Because it will not be able to read another version of the level format. + return levelHeader; } //Find the header in the returned string. while(counter < bufferSize) { - ObjectTypeHeader typeID; + ObjectType typeID; ParseObject(&buffer[counter], &typeID, sizeof(typeID)); - switch(typeID.typeID) + switch(typeID) { case ObjectType_LevelMetaData: ParseLevelMetaData(&buffer[counter], levelHeader, counter); @@ -148,7 +244,19 @@ LevelMetaData LevelParser::ParseHeader(std::string filename) case ObjectType_Static: case ObjectType_Dynamic: { ObjectHeader header; - ParseObject(&buffer[counter], header, counter); + ParseObject(&buffer[counter], &header, counter); + + switch(header.specialTypeID) + { + case ObjectSpecialType_JumpPad: + counter += sizeof(16); + break; + case ObjectSpecialType_Portal: + counter += sizeof(12); + break; + default: + break; + } break; } @@ -157,6 +265,9 @@ LevelMetaData LevelParser::ParseHeader(std::string filename) LightType lightType; ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); + //We only support pointlight for now. + counter += sizeof(BasicLight); + /* switch(lightType) { case LightType_PointLight: @@ -177,7 +288,7 @@ LevelMetaData LevelParser::ParseHeader(std::string filename) default: //Undefined LightType. break; - } + }*/ } default: diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.h b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.h index 9ad30642..346b75b5 100644 --- a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.h +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.h @@ -23,7 +23,7 @@ namespace GameLogic LevelMetaData ParseHeader(std::string filename); private: - FormatVersion formatVersion; + LevelLoaderInternal::FormatVersion formatVersion; }; } diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/ObjectDefines.h b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ObjectDefines.h index 8287dafb..09556cdc 100644 --- a/Code/Game/DanBiasGame/GameClientState/LevelLoader/ObjectDefines.h +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ObjectDefines.h @@ -9,7 +9,7 @@ namespace GameLogic /************************************ Enums *************************************/ - + enum ObjectType { ObjectType_LevelMetaData, @@ -23,31 +23,45 @@ namespace GameLogic ObjectType_Unknown = -1 }; - enum UsePhysics + enum ObjectSpecialType { - UsePhysics_UseFullPhysics, - UsePhysics_IgnoreGravity, - UsePhysics_IgnorePhysics, - UsePhysics_IgnoreCollision, + ObjectSpecialType_None, + ObjectSpecialType_Sky, + ObjectSpecialType_World, //Always the main celestial body + ObjectSpecialType_Building, + ObjectSpecialType_Stone, + ObjectSpecialType_StandarsBox, + ObjectSpecialType_RedExplosiveBox, + ObjectSpecialType_SpikeBox, + ObjectSpecialType_Spike, + ObjectSpecialType_CrystalFormation, + ObjectSpecialType_CrystalShard, + ObjectSpecialType_JumpPad, + ObjectSpecialType_Portal, + ObjectSpecialType_SpawnPoint, + ObjectSpecialType_Player, + - UsePhysics_Count, - UsePhysics_Unknown = -1 + ObjectSpecialType_Count, + ObjectSpecialType_Unknown = -1 }; enum CollisionGeometryType { CollisionGeometryType_Box, CollisionGeometryType_Sphere, + CollisionGeometryType_Cylinder, CollisionGeometryType_Count, CollisionGeometryType_Unknown = -1 }; + //Only supports Pointlight right now. enum LightType { LightType_PointLight, - LightType_DirectionalLight, - LightType_SpotLight, + //LightType_DirectionalLight, + //LightType_SpotLight, LightType_Count, LightType_Unknown = -1 @@ -80,38 +94,84 @@ namespace GameLogic /************************************ Structs *************************************/ - - struct FormatVersion + namespace LevelLoaderInternal { - unsigned int formatVersionMajor; - unsigned int formatVersionMinor; - - bool operator ==(const FormatVersion& obj) + struct FormatVersion { - return (this->formatVersionMajor != obj.formatVersionMajor && this->formatVersionMinor != obj.formatVersionMinor); - } + unsigned int formatVersionMajor; + unsigned int formatVersionMinor; + + FormatVersion() + : formatVersionMajor(0), formatVersionMinor(0) + {} - bool operator !=(const FormatVersion& obj) - { - return !(*this == obj); - } - }; + FormatVersion(unsigned int major, unsigned int minor) + : formatVersionMajor(major), formatVersionMinor(minor) + {} + + bool operator ==(const FormatVersion& obj) + { + return (this->formatVersionMajor == obj.formatVersionMajor && this->formatVersionMinor == obj.formatVersionMinor); + } + + bool operator !=(const FormatVersion& obj) + { + return !(*this == obj); + } + }; + } struct ObjectTypeHeader { ObjectType typeID; + + //Unless this is here the object destructor wont be called. + virtual ~ObjectTypeHeader(){} }; - struct PhysicsObject + namespace LevelLoaderInternal { - UsePhysics usePhysics; - float mass; - float inertiaMagnitude[3]; - float inertiaRotation[3]; - float frictionCoeffStatic; - float frictionCoeffDynamic; - CollisionGeometryType geometryType; - }; + const FormatVersion boundingVolumeVersion(2, 0); + + struct BoundingVolumeBase + { + CollisionGeometryType geoType; + float position[3]; + float rotation[4]; + float frictionCoeffStatic; + float frictionCoeffDynamic; + float restitutionCoeff; + float mass; + }; + + struct BoundingVolumeBox : public BoundingVolumeBase + { + float size[3]; + }; + + struct BoundingVolumeSphere : public BoundingVolumeBase + { + float radius; + }; + + struct BoundingVolumeCylinder : public BoundingVolumeBase + { + float length; + float radius; + }; + + struct BoundingVolume + { + CollisionGeometryType geoType; + union + { + LevelLoaderInternal::BoundingVolumeBox box; + LevelLoaderInternal::BoundingVolumeSphere sphere; + LevelLoaderInternal::BoundingVolumeCylinder cylinder; + }; + }; + + } struct LevelMetaData : public ObjectTypeHeader { @@ -123,21 +183,56 @@ namespace GameLogic WorldSize worldSize; std::string overviewPicturePath; std::vector gameModesSupported; + + virtual ~LevelMetaData(){} + }; - struct ObjectHeader : public ObjectTypeHeader, public PhysicsObject + struct ObjectHeader : public ObjectTypeHeader { + //Special type id for special objects: portal, jumppad, exploding objects, etc. + ObjectSpecialType specialTypeID; //Model, std::string ModelFile; //Position float position[3]; - //Rotation - float rotation[3]; - float angle; + //Rotation Quaternion + float rotation[4]; //Scale float scale[3]; + + ::GameLogic::LevelLoaderInternal::BoundingVolume boundingVolume; + + virtual ~ObjectHeader(){} }; + /************************************ + Special objects + *************************************/ + + struct JumpPadAttributes : public ObjectHeader + { + float direction[3]; + float power; + }; + + struct PortalAttributes : public ObjectHeader + { + float destination[3]; + }; + + struct WorldAttributes : public ObjectHeader + { + float worldSize; + float atmoSphereSize; + }; + + struct SkyAttributes : public ObjectHeader + { + float skySize; + }; + + /************************************ Lights @@ -145,12 +240,13 @@ namespace GameLogic struct BasicLight : public ObjectTypeHeader { - LightType lightType; - float ambientColor[3]; - float diffuseColor[3]; - float specularColor[3]; + LightType lightType; //Is not used right now + float color[3]; + float position[3]; + float raduis; + float intensity; }; - + /* We only support pointlight right now. struct PointLight : public BasicLight { float position[3]; @@ -166,7 +262,7 @@ namespace GameLogic float direction[3]; float range; float attenuation[3]; - }; + };*/ } #endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.cpp b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.cpp index 08823d3d..7f5550d7 100644 --- a/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.cpp @@ -3,10 +3,9 @@ ////////////////////////////////// #include "ParseFunctions.h" -#include "../../../../Misc/Packing/Packing.h" +#include "Loader.h" #include -using namespace Oyster::Packing; using namespace GameLogic::LevelFileLoader; using namespace GameLogic; using namespace std; @@ -15,12 +14,13 @@ namespace GameLogic { namespace LevelFileLoader { + //can parse any struct if the struct doesnt contain strings or char[] void ParseObject(char* buffer, void *header, int size) { memcpy(header, buffer, size); } - void ParseObject(char* buffer, ObjectHeader& header, int& size) + void ParseObject(char* buffer, ObjectHeader& header, int& size, bool loadCgf) { char tempName[128]; unsigned int tempSize = 0; @@ -29,6 +29,9 @@ namespace GameLogic memcpy(&header.typeID, &buffer[start], 4); start += 4; + memcpy(&header.specialTypeID, &buffer[start], 4); + start += 4; + memcpy(&tempSize, &buffer[start], 4); start += 4; @@ -36,13 +39,29 @@ namespace GameLogic header.ModelFile.assign(&tempName[0], &tempName[tempSize]); start += tempSize; + //The reset of the object struct //3 float[3], 1 float memcpy(&header.position, &buffer[start], 40); start += 40; + + //if loadCgf : Read path for bounding volume + if(loadCgf) + { + ParseBoundingVolume(&buffer[start], header.boundingVolume, start); + } - //2 float[3], 3 float, 2 uint - memcpy(&header.usePhysics, &buffer[start], 44); - start += 44; + //else make sure the counter counts the name so we can jump over the string in the buffer. + else + { + memcpy(&tempSize, &buffer[start], 4); + start += 4; + + memcpy(&tempName, &buffer[start], tempSize); + + string fileName; + fileName.assign(&tempName[0], &tempName[tempSize]); + start += tempSize; + } size += start; } @@ -107,5 +126,57 @@ namespace GameLogic size += start; } + + void ParseBoundingVolume(char* buffer, LevelLoaderInternal::BoundingVolume& volume, int &size) + { + int start = 0; + int tempSize = 0; + char tempName[128]; + + memcpy(&tempSize, &buffer[start], 4); + start += 4; + + memcpy(&tempName, &buffer[start], tempSize); + + string fileName; + fileName.assign(&tempName[0], &tempName[tempSize]); + start += tempSize; + + size += start; + + //Läs in filen. + int fileLength = 0; + Loader loader; + char* buf = loader.LoadFile("C:/Users/Sam/Documents/GitHub/Danbias/Bin/Content/worlds/cgf/"+ fileName, fileLength); + + start = 0; + LevelLoaderInternal::FormatVersion version; + memcpy(&version, &buf[0], sizeof(version)); + start += 4; + + memcpy(&volume.geoType, &buf[start], sizeof(volume.geoType)); + start += sizeof(volume.geoType); + + switch(volume.geoType) + { + case CollisionGeometryType_Box: + memcpy(&volume.box, &buf[start], sizeof(volume.box)); + start += sizeof(volume.box); + break; + + case CollisionGeometryType_Sphere: + memcpy(&volume.sphere, &buf[start], sizeof(volume.sphere)); + start += sizeof(volume.sphere); + break; + + case CollisionGeometryType_Cylinder: + memcpy(&volume.cylinder, &buf[start], sizeof(volume.cylinder)); + start += sizeof(volume.cylinder); + break; + + default: + break; + } + } } } \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.h b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.h index f68a9289..0fc6dbc6 100644 --- a/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.h +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.h @@ -17,10 +17,10 @@ namespace GameLogic Or the current index that is being used to parse the entire file (if it is sent by reference) this means you have to increase size with the appropiate size after you have copied. */ - void ParseObject(char* buffer, void *header, int size); - void ParseObject(char* buffer, ObjectHeader& header, int& size); + void ParseObject(char* buffer, ObjectHeader& header, int& size , bool loadCgf); void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size); + void ParseBoundingVolume(char* buffer, LevelLoaderInternal::BoundingVolume& volume, int &size); } } diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 0ef2a204..a0d768a3 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -24,19 +24,14 @@ using namespace GameLogic; switch (realObj->GetObjectType()) { - case OBJECT_TYPE::OBJECT_TYPE_GENERIC: + case ObjectSpecialType_StandarsBox: PlayerVObject(*player,*realObj, kineticEnergyLoss); //return Physics::ICustomBody::SubscriptMessage_none; break; - - case OBJECT_TYPE::OBJECT_TYPE_BOX: - PlayerVObject(*player,*realObj, kineticEnergyLoss); + case ObjectSpecialType_Player: //return Physics::ICustomBody::SubscriptMessage_none; break; - case OBJECT_TYPE::OBJECT_TYPE_PLAYER: - //return Physics::ICustomBody::SubscriptMessage_none; - break; - case OBJECT_TYPE::OBJECT_TYPE_WORLD: + case ObjectSpecialType_World: PlayerVObject(*player,*realObj, kineticEnergyLoss); //player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; break; @@ -52,14 +47,14 @@ using namespace GameLogic; switch (realObj->GetObjectType()) { - case OBJECT_TYPE::OBJECT_TYPE_GENERIC: + case ObjectSpecialType_Generic: break; - case OBJECT_TYPE::OBJECT_TYPE_BOX: + case ObjectSpecialType_StandarsBox: break; - case OBJECT_TYPE::OBJECT_TYPE_PLAYER: + case ObjectSpecialType_Player: SendObjectFlying(*obj, jumpPad->pushForce); break; - case OBJECT_TYPE::OBJECT_TYPE_WORLD: + case ObjectSpecialType_World: break; } } @@ -115,7 +110,7 @@ using namespace GameLogic; Object *realObj = (Object*)obj->GetCustomTag(); - if(realObj->GetObjectType() == OBJECT_TYPE_PLAYER || realObj->GetObjectType() == OBJECT_TYPE_WORLD) + if(realObj->GetObjectType() == ObjectSpecialType_Player || realObj->GetObjectType() == ObjectSpecialType_World) return; obj->ApplyImpulse(((forcePushData*)(args))->pushForce); @@ -138,7 +133,7 @@ using namespace GameLogic; switch(realObj->GetObjectType()) { - case OBJECT_TYPE::OBJECT_TYPE_BOX: + case ObjectSpecialType_StandarsBox: //move obj to limbo in physics to make sure it wont collide with anything Oyster::Physics::API::Instance().MoveToLimbo(obj); weapon->heldObject = obj; //weapon now holds the object diff --git a/Code/Game/GameLogic/DynamicObject.cpp b/Code/Game/GameLogic/DynamicObject.cpp index 05a4138d..b6193f30 100644 --- a/Code/Game/GameLogic/DynamicObject.cpp +++ b/Code/Game/GameLogic/DynamicObject.cpp @@ -9,28 +9,28 @@ DynamicObject::DynamicObject() { } -DynamicObject::DynamicObject(OBJECT_TYPE type) +DynamicObject::DynamicObject(ObjectSpecialType type) :Object(type) { } -DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type) +DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type) :Object(rigidBody,type) { } -DynamicObject::DynamicObject( void* collisionFuncAfter, OBJECT_TYPE type) +DynamicObject::DynamicObject( void* collisionFuncAfter, ObjectSpecialType type) :Object(collisionFuncAfter,type) { } -DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, OBJECT_TYPE type) +DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, ObjectSpecialType type) :Object(rigidBody, collisionFuncAfter, type) { } -DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) +DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type) :Object(rigidBody, collisionFuncAfter, type) { diff --git a/Code/Game/GameLogic/DynamicObject.h b/Code/Game/GameLogic/DynamicObject.h index 815875b3..e8aa25ce 100644 --- a/Code/Game/GameLogic/DynamicObject.h +++ b/Code/Game/GameLogic/DynamicObject.h @@ -14,11 +14,13 @@ namespace GameLogic public: DynamicObject(); - DynamicObject(OBJECT_TYPE type); - DynamicObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type); - DynamicObject( void* collisionFuncAfter, OBJECT_TYPE type); - DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, OBJECT_TYPE type); - DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); + + DynamicObject(ObjectSpecialType type); + DynamicObject(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type); + DynamicObject( void* collisionFuncAfter, ObjectSpecialType type); + DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, ObjectSpecialType type); + DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type); + ~DynamicObject(void); diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index c78abb09..8be3f7a8 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -81,8 +81,8 @@ Game::LevelData* Game::CreateLevel() if(this->level) return this->level; this->level = new LevelData(); - this->level->level->InitiateLevel(1000); - //this->level->level->InitiateLevel("3bana.bias"); + //this->level->level->InitiateLevel(1000); + this->level->level->InitiateLevel("C:/Users/Sam/Documents/GitHub/Danbias/Bin/Content/worlds/ccc.bias"); return this->level; } diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index d88ddd7b..93e130f5 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -40,8 +40,10 @@ namespace GameLogic Oyster::Math::Float3 GetScale() override; Oyster::Math::Float4x4 GetOrientation() override; int GetID() const override; - OBJECT_TYPE GetObjectType() const override; void Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) override; + ObjectSpecialType GetObjectType() const override; + + Player *player; }; @@ -56,7 +58,7 @@ namespace GameLogic Oyster::Math::Float3 GetScale() override; Oyster::Math::Float4x4 GetOrientation() override; int GetID() const override; - OBJECT_TYPE GetObjectType() const override; + ObjectSpecialType GetObjectType() const override; int getNrOfDynamicObj()const override; IObjectData* GetObjectAt(int ID) const override; Level *level; diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 79656878..30e86e8c 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -12,6 +12,7 @@ #include "GameLogicDef.h" #include "GameLogicStates.h" #include +#include "LevelLoader\ObjectDefines.h" namespace GameLogic @@ -66,7 +67,7 @@ namespace GameLogic /** Get the type of the object * @return The OBJECT_TYPE of the object is returned */ - virtual OBJECT_TYPE GetObjectType() const = 0; + virtual ObjectSpecialType GetObjectType() const = 0; }; class IPlayerData :public IObjectData diff --git a/Code/Game/GameLogic/GameLogicStates.h b/Code/Game/GameLogic/GameLogicStates.h index 00c2e7ff..9ae0d482 100644 --- a/Code/Game/GameLogic/GameLogicStates.h +++ b/Code/Game/GameLogic/GameLogicStates.h @@ -21,15 +21,6 @@ namespace GameLogic PLAYER_STATE_INVALID = 8, }; - enum OBJECT_TYPE - { - OBJECT_TYPE_PLAYER = 0, - OBJECT_TYPE_BOX = 1, - OBJECT_TYPE_WORLD = 2, - OBJECT_TYPE_GENERIC = 4, - OBJECT_TYPE_UNKNOWN = -1, - }; - enum WEAPON_FIRE { WEAPON_USE_PRIMARY_PRESS = 0, diff --git a/Code/Game/GameLogic/Game_LevelData.cpp b/Code/Game/GameLogic/Game_LevelData.cpp index b8006af3..b007ce01 100644 --- a/Code/Game/GameLogic/Game_LevelData.cpp +++ b/Code/Game/GameLogic/Game_LevelData.cpp @@ -38,7 +38,7 @@ int Game::LevelData::GetID() const { return ((IObjectData*)this->level)->GetID(); } -OBJECT_TYPE Game::LevelData::GetObjectType() const +ObjectSpecialType Game::LevelData::GetObjectType() const { return ((IObjectData*)this->level)->GetObjectType(); //return OBJECT_TYPE_UNKNOWN; diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 56df13c4..efeab2ee 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -6,7 +6,9 @@ using namespace GameLogic; Game::PlayerData::PlayerData() { //set some stats that are appropriate to a player - Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(0,603,0); + + Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(0,400,0); + Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,1.0f,0.5f); Oyster::Math::Float mass = 60; Oyster::Math::Float restitutionCoeff = 0.5; @@ -18,7 +20,8 @@ Game::PlayerData::PlayerData() Oyster::Physics::ICustomBody* rigidBody = Oyster::Physics::API::Instance().AddCollisionBox(size, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f ); rigidBody->SetAngularFactor(0.0f); //create player with this rigid body - this->player = new Player(rigidBody, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER); + this->player = new Player(rigidBody, Player::PlayerCollision, ObjectSpecialType_Player); + this->player->GetRigidBody()->SetCustomTag(this); player->EndFrame(); } @@ -68,7 +71,7 @@ int Game::PlayerData::GetTeamID() const return this->player->GetTeamID(); } -OBJECT_TYPE Game::PlayerData::GetObjectType() const +ObjectSpecialType Game::PlayerData::GetObjectType() const { return this->player->GetObjectType(); } diff --git a/Code/Game/GameLogic/JumpPad.cpp b/Code/Game/GameLogic/JumpPad.cpp index 15b80dc8..2a7d7043 100644 --- a/Code/Game/GameLogic/JumpPad.cpp +++ b/Code/Game/GameLogic/JumpPad.cpp @@ -8,7 +8,8 @@ JumpPad::JumpPad(void) { } -JumpPad::JumpPad(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type, Oyster::Math::Float3 pushForce) + +JumpPad::JumpPad(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, Oyster::Math::Float3 pushForce) :StaticObject(rigidBody, collisionFuncAfter, type) { diff --git a/Code/Game/GameLogic/JumpPad.h b/Code/Game/GameLogic/JumpPad.h index 8d645a00..23601849 100644 --- a/Code/Game/GameLogic/JumpPad.h +++ b/Code/Game/GameLogic/JumpPad.h @@ -10,7 +10,7 @@ namespace GameLogic JumpPad(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss) - ,OBJECT_TYPE type, Oyster::Math::Float3 pushForce); + ,ObjectSpecialType type, Oyster::Math::Float3 pushForce); ~JumpPad(void); diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 04324fcc..6ccf6c5d 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -53,6 +53,11 @@ void Level::InitiateLevel(std::string levelPath) int modelCount = 0; int staticObjCount = 0; int dynamicObjCount = 0; + Oyster::Math::Float3 rigidWorldPos; + Oyster::Math::Float4 rigidWorldRotation; + float rigidBodyMass; + float rigidBodyRadius; + Oyster::Math::Float3 rigidBodySize; for (int i = 0; i < objCount; i++) { ObjectTypeHeader* obj = objects.at(i); @@ -73,33 +78,135 @@ void Level::InitiateLevel(std::string levelPath) //LevelLoaderInternal::BoundingVolumeBase* staticObjPhysicData = ((ObjectHeader*)obj); staticObjData->ModelFile; - ICustomBody* rigidBody_Static; + ICustomBody* rigidBody_Static = NULL; + // collision shape // radius, rotation in world, position in world, mass, restitution, static and dynamic friction - ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); - + if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Sphere) + { + //offset the rigidPosition from modelspace to worldspace; + rigidWorldPos = (Oyster::Math::Float3)staticObjData->position + (Oyster::Math::Float3)staticObjData->boundingVolume.sphere.position; + //scales the position so the collision geomentry is in the right place + rigidWorldPos = rigidWorldPos * staticObjData->scale; + + //offset the rigidRotation from modelspace to worldspace; + rigidWorldRotation = (Oyster::Math::Float4)staticObjData->rotation + (Oyster::Math::Float4)staticObjData->boundingVolume.sphere.rotation; + + //mass scaled + rigidBodyMass = staticObjData->scale[0] * staticObjData->scale[1] * staticObjData->scale[2] * staticObjData->boundingVolume.sphere.mass; + + //Radius scaled + rigidBodyRadius = (staticObjData->scale[0] * staticObjData->scale[1] * staticObjData->scale[2] / 3) * staticObjData->boundingVolume.sphere.radius; + + //create the rigid body + rigidBody_Static = API::Instance().AddCollisionSphere( rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, staticObjData->boundingVolume.sphere.restitutionCoeff , staticObjData->boundingVolume.sphere.frictionCoeffStatic , staticObjData->boundingVolume.sphere.frictionCoeffDynamic); + } + + else if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Box) + { + //offset the rigidPosition from modelspace to worldspace; + rigidWorldPos = (Oyster::Math::Float3)staticObjData->position + (Oyster::Math::Float3)staticObjData->boundingVolume.box.position; + //scales the position so the collision geomentry is in the right place + rigidWorldPos = rigidWorldPos * staticObjData->scale; + + //offset the rigidRotation from modelspace to worldspace; + rigidWorldRotation = (Oyster::Math::Float4)staticObjData->rotation + (Oyster::Math::Float4)staticObjData->boundingVolume.box.rotation; + + //mass scaled + rigidBodyMass = staticObjData->scale[0] * staticObjData->scale[1] * staticObjData->scale[2] * staticObjData->boundingVolume.box.mass; + + //size scaled + rigidBodySize = (Oyster::Math::Float3)staticObjData->boundingVolume.box.size * (Oyster::Math::Float3)staticObjData->scale; + + //create the rigid body + rigidBody_Static = API::Instance().AddCollisionBox(rigidBodySize , rigidWorldRotation , rigidWorldPos , rigidBodyMass, staticObjData->boundingVolume.box.restitutionCoeff , staticObjData->boundingVolume.box.frictionCoeffStatic , staticObjData->boundingVolume.box.frictionCoeffDynamic); + } + + else if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Cylinder) + { + + } + + // add rigidbody to the logical obj // Object::DefaultCollisionBefore, Object::DefaultCollisionAfter for now, gamelogic will take care of this // set object_type to objID - this->staticObjects.Push(new StaticObject(rigidBody, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); - this->staticObjects[staticObjCount]->objectID = modelCount++; - rigidBody->SetCustomTag(this->staticObjects[staticObjCount]); + if(rigidBody_Static != NULL) + { + this->staticObjects.Push(new StaticObject(rigidBody_Static, Object::DefaultCollisionAfter, (ObjectSpecialType)staticObjData->specialTypeID)); + this->staticObjects[staticObjCount]->objectID = modelCount++; + rigidBody_Static->SetCustomTag(this->staticObjects[staticObjCount]); + } + } break; case ObjectType::ObjectType_Dynamic: { - ObjectHeader* staticObjData = ((ObjectHeader*)obj); - staticObjData->ModelFile; + ObjectHeader* dynamicObjData = ((ObjectHeader*)obj); + dynamicObjData->ModelFile; - ICustomBody* rigidBody_Dynamic; + ICustomBody* rigidBody_Dynamic = NULL; - rigidBody_Dynamic = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 605 + i*5, 10), 5, 0.5f, 0.8f, 0.6f); + // collision shape + // radius, rotation in world, position in world, mass, restitution, static and dynamic friction + if(dynamicObjData->boundingVolume.geoType == CollisionGeometryType_Sphere) + { + //offset the rigidPosition from modelspace to worldspace; + rigidWorldPos = (Oyster::Math::Float3)dynamicObjData->position + (Oyster::Math::Float3)dynamicObjData->boundingVolume.sphere.position; + //scales the position so the collision geomentry is in the right place + rigidWorldPos = rigidWorldPos * dynamicObjData->scale; + + //offset the rigidRotation from modelspace to worldspace; + rigidWorldRotation = (Oyster::Math::Float4)dynamicObjData->rotation + (Oyster::Math::Float4)dynamicObjData->boundingVolume.sphere.rotation; + + //mass scaled + rigidBodyMass = dynamicObjData->scale[0] * dynamicObjData->scale[1] * dynamicObjData->scale[2] * dynamicObjData->boundingVolume.sphere.mass; + + //size scaled + rigidBodyRadius = (dynamicObjData->scale[0] * dynamicObjData->scale[1] * dynamicObjData->scale[2] / 3) * dynamicObjData->boundingVolume.sphere.radius; + + //create the rigid body + rigidBody_Dynamic = API::Instance().AddCollisionBox(rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, dynamicObjData->boundingVolume.sphere.restitutionCoeff , dynamicObjData->boundingVolume.sphere.frictionCoeffStatic , dynamicObjData->boundingVolume.sphere.frictionCoeffDynamic); + } + + else if(dynamicObjData->boundingVolume.geoType == CollisionGeometryType_Box) + { + //offset the rigidPosition from modelspace to worldspace; + rigidWorldPos = (Oyster::Math::Float3)dynamicObjData->position + (Oyster::Math::Float3)dynamicObjData->boundingVolume.box.position; + //scales the position so the collision geomentry is in the right place + rigidWorldPos = rigidWorldPos * dynamicObjData->scale; + + //offset the rigidRotation from modelspace to worldspace; + rigidWorldRotation = (Oyster::Math::Float4)dynamicObjData->rotation + (Oyster::Math::Float4)dynamicObjData->boundingVolume.box.rotation; + + //mass scaled + rigidBodyMass = dynamicObjData->scale[0] * dynamicObjData->scale[1] * dynamicObjData->scale[2] * dynamicObjData->boundingVolume.box.mass; + + //size scaled + rigidBodySize = (Oyster::Math::Float3)dynamicObjData->boundingVolume.box.size * (Oyster::Math::Float3)dynamicObjData->scale; + + //create the rigid body + rigidBody_Dynamic = API::Instance().AddCollisionBox(rigidBodySize , rigidWorldRotation , rigidWorldPos , rigidBodyMass, dynamicObjData->boundingVolume.box.restitutionCoeff , dynamicObjData->boundingVolume.box.frictionCoeffStatic , dynamicObjData->boundingVolume.box.frictionCoeffDynamic); + } + + else if(dynamicObjData->boundingVolume.geoType == CollisionGeometryType_Cylinder) + { + + } + + + // add rigidbody to the logical obj + // Object::DefaultCollisionBefore, Object::DefaultCollisionAfter for now, gamelogic will take care of this + // set object_type to objID + if(rigidBody_Dynamic != NULL) + { + this->dynamicObjects.Push(new DynamicObject(rigidBody_Dynamic , Object::DefaultCollisionAfter, (ObjectSpecialType)dynamicObjData->specialTypeID)); + this->dynamicObjects[dynamicObjCount]->objectID = modelCount++; + rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[dynamicObjCount]); + } - this->dynamicObjects.Push(new DynamicObject(rigidBody_Dynamic, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); - this->dynamicObjects[dynamicObjCount]->objectID = modelCount++; - rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[dynamicObjCount]); } break; case ObjectType::ObjectType_Light: @@ -117,7 +224,9 @@ void Level::InitiateLevel(float radius) int idCount = 100; // add level sphere ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); - levelObj = new StaticObject(rigidBody, LevelCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_WORLD); + + levelObj = new StaticObject(rigidBody, LevelCollisionAfter, ObjectSpecialType_World); + this->levelObj->objectID = idCount++; rigidBody->SetCustomTag(levelObj); @@ -130,7 +239,8 @@ void Level::InitiateLevel(float radius) { rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 605 + i*5, 10), 5, 0.5f, 0.8f, 0.6f); - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); + this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultCollisionAfter, ObjectSpecialType_StandarsBox)); + this->dynamicObjects[i]->objectID = idCount++; rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]); } @@ -168,7 +278,7 @@ void Level::InitiateLevel(float radius) // add crystal ICustomBody* rigidBody_Crystal = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(10, 605, 0), 5, 0.5f, 0.8f, 0.6f); - this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); + this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultCollisionAfter, ObjectSpecialType_StandarsBox)); rigidBody_Crystal->SetCustomTag(this->dynamicObjects[nrOfBoxex]); this->dynamicObjects[nrOfBoxex]->objectID = idCount++; @@ -176,7 +286,7 @@ void Level::InitiateLevel(float radius) // add house ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(20, 20, 20), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(-50, 590, 0), 0, 0.5f, 0.8f, 0.6f); - this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC)); + this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultCollisionAfter, ObjectSpecialType_Generic)); rigidBody_House->SetCustomTag(this->staticObjects[0]); this->staticObjects[0]->objectID = idCount++; } @@ -202,7 +312,7 @@ int Level::getNrOfDynamicObj() } Object* Level::GetObj( int ID) const { - for (int i = 0; i< this->dynamicObjects.Size(); i++) + for (int i = 0; i < this->dynamicObjects.Size(); i++) { if(this->dynamicObjects[i]->GetID() == ID) return this->dynamicObjects[i]; diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp index f66fbe08..c5dfa8cc 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp @@ -25,6 +25,7 @@ std::vector> LevelParser::Parse(std::string filen { int bufferSize = 0; int counter = 0; + bool loadCgf; std::vector> objects; @@ -38,14 +39,13 @@ std::vector> LevelParser::Parse(std::string filen counter += sizeof(levelFormatVersion); if(this->formatVersion != levelFormatVersion) { - //Do something if it's not the same version - //Returns an empty vector, because it will most likely fail to read the level format. return objects; } while(counter < bufferSize) { + loadCgf = true; //Get typeID ObjectType typeID; ParseObject(&buffer[counter], &typeID, sizeof(typeID)); @@ -69,45 +69,43 @@ std::vector> LevelParser::Parse(std::string filen switch(specialType) { - //These three does not have any specail variables at this time. - //There for they are using the same 'parser'. + //there is no difference when parsing these specialTypes. + case ObjectSpecialType_CrystalShard: + case ObjectSpecialType_CrystalFormation: + case ObjectSpecialType_Spike: + case ObjectSpecialType_SpikeBox: + case ObjectSpecialType_RedExplosiveBox: + case ObjectSpecialType_StandarsBox: + case ObjectSpecialType_Stone: case ObjectSpecialType_Building: - case ObjectSpecialType_Damaging: - case ObjectSpecialType_Explosive: { ObjectHeader* header = new ObjectHeader; - ParseObject(&buffer[counter], *header, counter); + ParseObject(&buffer[counter], *header, counter, loadCgf); objects.push_back(header); break; } + case ObjectSpecialType_JumpPad: { JumpPadAttributes* header = new JumpPadAttributes; - ParseObject(&buffer[counter], *header, counter); + ParseObject(&buffer[counter], *header, counter, loadCgf); //Read the spec ParseObject(&buffer[counter], header->direction, 16); + counter += 16; objects.push_back(header); break; } - case ObjectSpecialType_BoostPad: - { - JumpPadAttributes* header = new JumpPadAttributes; - ParseObject(&buffer[counter], *header, counter); - - ParseObject(&buffer[counter], header->direction, 16); - objects.push_back(header); - - break; - } + case ObjectSpecialType_Portal: { PortalAttributes* header = new PortalAttributes; - ParseObject(&buffer[counter], *header, counter); + ParseObject(&buffer[counter], *header, counter, loadCgf); ParseObject(&buffer[counter], header->destination, 12); + counter += 12; objects.push_back(header); break; @@ -116,22 +114,33 @@ std::vector> LevelParser::Parse(std::string filen case ObjectSpecialType_World: { WorldAttributes* header = new WorldAttributes; - ParseObject(&buffer[counter], *header, counter); + ParseObject(&buffer[counter], *header, counter, loadCgf); ParseObject(&buffer[counter], &header->worldSize, 8); + counter += 8; objects.push_back(header); break; } case ObjectSpecialType_Sky: { + loadCgf = false; SkyAttributes* header = new SkyAttributes; - ParseObject(&buffer[counter], *header, counter); + ParseObject(&buffer[counter], *header, counter, loadCgf); ParseObject(&buffer[counter], &header->skySize, 4); + counter += 4; objects.push_back(header); break; } + + case ObjectSpecialType_SpawnPoint: + { + loadCgf = false; + ObjectHeader* header = new ObjectHeader; + ParseObject(&buffer[counter], *header, counter, loadCgf); + } + default: //Couldn't find specialType break; @@ -235,16 +244,13 @@ LevelMetaData LevelParser::ParseHeader(std::string filename) case ObjectType_Static: case ObjectType_Dynamic: { ObjectHeader header; - ParseObject(&buffer[counter], header, counter); + ParseObject(&buffer[counter], &header, counter); switch(header.specialTypeID) { case ObjectSpecialType_JumpPad: counter += sizeof(16); break; - case ObjectSpecialType_BoostPad: - counter += sizeof(16); - break; case ObjectSpecialType_Portal: counter += sizeof(12); break; diff --git a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h index 05d09714..4cf34366 100644 --- a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h +++ b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h @@ -25,30 +25,28 @@ namespace GameLogic enum ObjectSpecialType { + ObjectSpecialType_None, + ObjectSpecialType_Sky, ObjectSpecialType_World, //Always the main celestial body ObjectSpecialType_Building, - ObjectSpecialType_Damaging, - ObjectSpecialType_Explosive, + ObjectSpecialType_Stone, + ObjectSpecialType_StandarsBox, + ObjectSpecialType_RedExplosiveBox, + ObjectSpecialType_SpikeBox, + ObjectSpecialType_Spike, + ObjectSpecialType_CrystalFormation, + ObjectSpecialType_CrystalShard, ObjectSpecialType_JumpPad, - ObjectSpecialType_BoostPad, ObjectSpecialType_Portal, - ObjectSpecialType_Sky, + ObjectSpecialType_SpawnPoint, + ObjectSpecialType_Player, + ObjectSpecialType_Generic, + ObjectSpecialType_Count, ObjectSpecialType_Unknown = -1 }; - enum UsePhysics - { - UsePhysics_UseFullPhysics, - UsePhysics_IgnoreGravity, - UsePhysics_IgnorePhysics, - UsePhysics_IgnoreCollision, - - UsePhysics_Count, - UsePhysics_Unknown = -1 - }; - enum CollisionGeometryType { CollisionGeometryType_Box, diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp index d917a146..54c41b12 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp @@ -16,13 +16,13 @@ namespace GameLogic { namespace LevelFileLoader { - //can parse any struct without strings or char[] + //can parse any struct if the struct doesnt contain strings or char[] void ParseObject(char* buffer, void *header, int size) { memcpy(header, buffer, size); } - void ParseObject(char* buffer, ObjectHeader& header, int& size) + void ParseObject(char* buffer, ObjectHeader& header, int& size, bool loadCgf) { char tempName[128]; unsigned int tempSize = 0; @@ -46,8 +46,24 @@ namespace GameLogic memcpy(&header.position, &buffer[start], 40); start += 40; - //Read path for bounding volume - ParseBoundingVolume(&buffer[start], header.boundingVolume, start); + //if loadCgf : Read path for bounding volume + if(loadCgf) + { + ParseBoundingVolume(&buffer[start], header.boundingVolume, start); + } + + //else make sure the counter counts the name so we can jump over the string in the buffer. + else + { + memcpy(&tempSize, &buffer[start], 4); + start += 4; + + memcpy(&tempName, &buffer[start], tempSize); + + string fileName; + fileName.assign(&tempName[0], &tempName[tempSize]); + start += tempSize; + } size += start; } @@ -133,15 +149,14 @@ namespace GameLogic //Läs in filen. int fileLength = 0; Loader loader; - char* buf = loader.LoadFile("E:\\Dropbox\\Programming\\Github\\Danbias\\Bin\\Content\\Worlds\\cgf\\"+ fileName, fileLength); + char* buf = loader.LoadFile("C:/Users/Sam/Documents/GitHub/Danbias/Bin/Content/worlds/cgf/"+ fileName, fileLength); start = 0; LevelLoaderInternal::FormatVersion version; memcpy(&version, &buf[0], sizeof(version)); - start += 4; + start += 8; memcpy(&volume.geoType, &buf[start], sizeof(volume.geoType)); - start += sizeof(volume.geoType); switch(volume.geoType) { diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h index f66351b4..0fc6dbc6 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h @@ -17,9 +17,8 @@ namespace GameLogic Or the current index that is being used to parse the entire file (if it is sent by reference) this means you have to increase size with the appropiate size after you have copied. */ - void ParseObject(char* buffer, void *header, int size); - void ParseObject(char* buffer, ObjectHeader& header, int& size); + void ParseObject(char* buffer, ObjectHeader& header, int& size , bool loadCgf); void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size); void ParseBoundingVolume(char* buffer, LevelLoaderInternal::BoundingVolume& volume, int &size); } diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 631ae1b7..80ff0ad6 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -18,25 +18,26 @@ Object::Object() this->rigidBody = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.0f, 0.0f, 0.0f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); - this->type = OBJECT_TYPE::OBJECT_TYPE_UNKNOWN; + this->type = ObjectSpecialType_Unknown; this->objectID = GID(); } -Object::Object(OBJECT_TYPE type) +Object::Object(ObjectSpecialType type) { this->rigidBody = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.0f, 0.0f, 0.0f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); this->type = type; this->objectID = GID(); } -Object::Object(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type) +Object::Object(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type) { this->rigidBody = rigidBody; this->type = type; this->objectID = GID(); } -Object::Object( void* collisionFuncAfter, OBJECT_TYPE type) +Object::Object( void* collisionFuncAfter, ObjectSpecialType type) + { this->rigidBody = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.0f, 0.0f, 0.0f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); @@ -44,7 +45,7 @@ Object::Object( void* collisionFuncAfter, OBJECT_TYPE type) this->objectID = GID(); } -Object::Object(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, OBJECT_TYPE type) +Object::Object(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, ObjectSpecialType type) { this->rigidBody = rigidBody; this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter)); @@ -52,7 +53,8 @@ Object::Object(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter this->objectID = GID(); } -Object::Object(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) + +Object::Object(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type) { this->rigidBody = rigidBody; this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter)); @@ -71,7 +73,7 @@ Object::~Object(void) } -OBJECT_TYPE Object::GetObjectType() const +ObjectSpecialType Object::GetObjectType() const { return this->type; } diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index 677aef13..83e12277 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -18,21 +18,24 @@ namespace GameLogic { public: Object(); - Object(OBJECT_TYPE type); - Object(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type); - Object(void* collisionFuncAfter, OBJECT_TYPE type); - Object(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, OBJECT_TYPE type); - Object(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); + Object(ObjectSpecialType type); + Object(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type); + Object(void* collisionFuncAfter, ObjectSpecialType type); + Object(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, ObjectSpecialType type); + Object(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type); ~Object(void); - OBJECT_TYPE GetObjectType() const override; - int GetID() const override; + ObjectSpecialType GetObjectType() const override; + int GetID() const override; + void setID(int id); Oyster::Math::Float3 GetPosition() override; Oyster::Math::Quaternion GetRotation() override; Oyster::Math::Float3 GetScale() override; Oyster::Math::Float4x4 GetOrientation() override; - void setID(int id); + // API overrides + + Oyster::Physics::ICustomBody* GetRigidBody(); void ApplyLinearImpulse(Oyster::Math::Float3 force); @@ -45,8 +48,9 @@ namespace GameLogic static Oyster::Physics::ICustomBody::SubscriptMessage DefaultCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); - public: //HACK: This should be private when level is dynamic - OBJECT_TYPE type; + + public: //TODO: Hax This should be private when level is dynamic + ObjectSpecialType type; int objectID; protected: diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 90f2c66b..f6dddb85 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -13,27 +13,28 @@ Player::Player() { } -Player::Player(OBJECT_TYPE type) +Player::Player(ObjectSpecialType type) :DynamicObject(type) { InitPlayer(); } -Player::Player(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type) +Player::Player(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type) :DynamicObject(rigidBody,type) { InitPlayer(); } -Player::Player( void* collisionFuncAfter, OBJECT_TYPE type) + +Player::Player( void* collisionFuncAfter, ObjectSpecialType type) :DynamicObject(collisionFuncAfter,type) { InitPlayer(); } -Player::Player(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, OBJECT_TYPE type) +Player::Player(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, ObjectSpecialType type) :DynamicObject(rigidBody, collisionFuncAfter, type) { InitPlayer(); } -Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) +Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type) :DynamicObject(rigidBody, collisionFuncAfter, type) { InitPlayer(); diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index d2adb4be..b10d1114 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -16,11 +16,12 @@ namespace GameLogic { public: Player(void); - Player(OBJECT_TYPE type); - Player(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type); - Player( void* collisionFuncAfter, OBJECT_TYPE type); - Player(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, OBJECT_TYPE type); - Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); + Player(ObjectSpecialType type); + Player(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type); + Player( void* collisionFuncAfter, ObjectSpecialType type); + Player(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, ObjectSpecialType type); + Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type); + ~Player(void); void InitPlayer(); diff --git a/Code/Game/GameLogic/StaticObject.cpp b/Code/Game/GameLogic/StaticObject.cpp index 12725595..f9156e3c 100644 --- a/Code/Game/GameLogic/StaticObject.cpp +++ b/Code/Game/GameLogic/StaticObject.cpp @@ -10,29 +10,29 @@ StaticObject::StaticObject() { } -StaticObject::StaticObject(OBJECT_TYPE type) +StaticObject::StaticObject(ObjectSpecialType type) :Object(type) { } -StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type) +StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type) :Object(rigidBody,type) { //this->rigidBody->SetGravity(true); //this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse)(CollisionManager::IgnoreCollision)); } -StaticObject::StaticObject( void* collisionFuncAfter, OBJECT_TYPE type) +StaticObject::StaticObject( void* collisionFuncAfter, ObjectSpecialType type) :Object(collisionFuncAfter,type) { } -StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, OBJECT_TYPE type) +StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, ObjectSpecialType type) :Object(rigidBody, collisionFuncAfter, type) { } -StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) +StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type) :Object(rigidBody, collisionFuncAfter, type) { diff --git a/Code/Game/GameLogic/StaticObject.h b/Code/Game/GameLogic/StaticObject.h index 585594e6..4e655808 100644 --- a/Code/Game/GameLogic/StaticObject.h +++ b/Code/Game/GameLogic/StaticObject.h @@ -8,6 +8,7 @@ #include "Object.h" + namespace GameLogic { @@ -16,12 +17,13 @@ namespace GameLogic public: StaticObject(); - StaticObject(OBJECT_TYPE type); - StaticObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type); - StaticObject( void* collisionFuncAfter, OBJECT_TYPE type); - StaticObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, OBJECT_TYPE type); - StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); + StaticObject(ObjectSpecialType type); + StaticObject(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type); + StaticObject( void* collisionFuncAfter, ObjectSpecialType type); + StaticObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, ObjectSpecialType type); + StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type); + ~StaticObject(void); private: From b9c4fe18493fe71954b915249ca442a8dc85ea9c Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 12 Feb 2014 15:12:01 +0100 Subject: [PATCH 04/22] GL - Eventhandler does not delete collections any more. --- .../GameClientState/Buttons/ButtonEllipse.h | 1 - .../GameClientState/LoginState.cpp | 42 +++++++++---------- .../EventHandler/EventButtonCollection.cpp | 1 + Code/Misc/EventHandler/EventHandler.cpp | 17 +------- Code/Misc/EventHandler/EventHandler.h | 5 ++- 5 files changed, 27 insertions(+), 39 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h index 291bf07d..4785d630 100644 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h @@ -44,7 +44,6 @@ namespace DanBias GetCursorPos(&p); ScreenToClient(WindowShell::GetHWND(), &p); GetClientRect(WindowShell::GetHWND(), &r); - //Should come from the InputClass float xMouse = (float)p.x / (float)r.right, yMouse = (float)p.y / (float)r.bottom; diff --git a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp index 70bbbbea..297335c8 100644 --- a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp @@ -25,7 +25,7 @@ struct LoginState::myData // game client* //Menu button collection - EventButtonCollection* collection; + EventButtonCollection collection; bool createGame; int testNumber; }privData; @@ -109,23 +109,23 @@ bool LoginState::Init(Oyster::Network::NetworkClient* nwClient) InitCamera(Oyster::Math::Float3(0,0,5.4f)); //Create menu buttons - privData->collection = new EventButtonCollection; - EventHandler::Instance().AddCollection(privData->collection); - privData->collection->AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.2f, 0.1f, 0.1f)); - privData->collection->AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.3f, 0.1f, 0.1f)); - privData->collection->AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.4f, 0.1f, 0.1f)); - privData->collection->AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.5f, 0.1f, 0.1f)); - - privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.15f, 0.05f, 0.1f, 0.1f)); - privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.25f, 0.05f, 0.1f, 0.1f)); - privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.35f, 0.05f, 0.1f, 0.1f)); - privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.45f, 0.05f, 0.1f, 0.1f)); - - privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Create, 0.5f, 0.5f, 0.3f, 0.3f)); - - //Incr/decr buttons - privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Incr, 0.85f, 0.2f, 0.1f, 0.1f)); - privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Decr, 0.55f, 0.2f, 0.1f, 0.1f)); + //privData->collection = new EventButtonCollection; + EventHandler::Instance().AddCollection(&privData->collection); + privData->collection.AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.2f, 0.1f, 0.1f)); + privData->collection.AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.3f, 0.1f, 0.1f)); + privData->collection.AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.4f, 0.1f, 0.1f)); + privData->collection.AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.5f, 0.1f, 0.1f)); + + privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.15f, 0.05f, 0.1f, 0.1f)); + privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.25f, 0.05f, 0.1f, 0.1f)); + privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.35f, 0.05f, 0.1f, 0.1f)); + privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.45f, 0.05f, 0.1f, 0.1f)); + + privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Create, 0.5f, 0.5f, 0.3f, 0.3f)); + + //Incr/decr buttons . + privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Incr, 0.85f, 0.2f, 0.1f, 0.1f)); + privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Decr, 0.55f, 0.2f, 0.1f, 0.1f)); privData->createGame = false; privData->testNumber = 0; @@ -198,7 +198,7 @@ GameClientState::ClientState LoginState::Update(float deltaTime, InputClass* Key // failed to connect return ClientState_Same; } - privData->collection->SetState(EventCollectionState_Disabled); + privData->collection.SetState(EventCollectionState_Disabled); return ClientState_LobbyCreated; } // join game @@ -213,7 +213,7 @@ GameClientState::ClientState LoginState::Update(float deltaTime, InputClass* Key // failed to connect return ClientState_Same; } - privData->collection->SetState(EventCollectionState_Disabled); + privData->collection.SetState(EventCollectionState_Disabled); return ClientState_Lobby; } return ClientState_Same; @@ -259,7 +259,7 @@ bool LoginState::Release() privData->object[i] = NULL; } - delete privData->collection; + EventHandler::Instance().ReleaseCollection(&privData->collection); delete privData; privData = NULL; diff --git a/Code/Misc/EventHandler/EventButtonCollection.cpp b/Code/Misc/EventHandler/EventButtonCollection.cpp index 2bd5f09a..5c1438c3 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.cpp +++ b/Code/Misc/EventHandler/EventButtonCollection.cpp @@ -20,6 +20,7 @@ EventButtonCollection::~EventButtonCollection() if(EventHandler::Instance().collections.at(i) == this) { EventHandler::Instance().collections.erase(EventHandler::Instance().collections.begin() + i); + break; } } diff --git a/Code/Misc/EventHandler/EventHandler.cpp b/Code/Misc/EventHandler/EventHandler.cpp index 4b623714..234a3935 100644 --- a/Code/Misc/EventHandler/EventHandler.cpp +++ b/Code/Misc/EventHandler/EventHandler.cpp @@ -19,22 +19,11 @@ EventHandler::EventHandler() EventHandler::~EventHandler() { - int size = collections.size(); - for(int i = 0; i < size; i++) - { - delete collections[i]; - collections[i] = NULL; - } + Clean(); } void EventHandler::Clean() { - int size = collections.size(); - for(int i = 0; i < size; i++) - { - delete collections[i]; - collections[i] = NULL; - } collections.clear(); } @@ -65,14 +54,12 @@ void EventHandler::AddCollection(EventButtonCollection* collection) collections.push_back(collection); } -void EventHandler::DeleteCollection(EventButtonCollection* collection) +void EventHandler::ReleaseCollection(EventButtonCollection* collection) { for(int i = 0; i < collections.size(); i++) { if(collections.at(i) == collection) { - delete collection; - collection = NULL; collections.erase(collections.begin() + i); break; } diff --git a/Code/Misc/EventHandler/EventHandler.h b/Code/Misc/EventHandler/EventHandler.h index 71a35ecd..a2560f0f 100644 --- a/Code/Misc/EventHandler/EventHandler.h +++ b/Code/Misc/EventHandler/EventHandler.h @@ -33,7 +33,8 @@ namespace Oyster */ void AddCollection(EventButtonCollection* collection); - void DeleteCollection(EventButtonCollection* collection); + + void ReleaseCollection(EventButtonCollection* collection); private: //Can't copy this class. @@ -43,7 +44,7 @@ namespace Oyster private: std::vector collections; - //EventButtonCollection is a firend so it can delete it self. + //EventButtonCollection is a friend so it can delete it self. friend class EventButtonCollection; }; } From 74d28d1f621532f99654cec82f72399570d234cf Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 12 Feb 2014 15:44:27 +0100 Subject: [PATCH 05/22] Misc - Changed to MouseInput struct in EventHandler update. --- Code/Game/DanBiasGame/DanBiasGame_Impl.cpp | 13 ++++++++++++- .../GameClientState/Buttons/ButtonEllipse.h | 9 ++------- .../GameClientState/Buttons/ButtonRectangle.h | 10 ++-------- Code/Misc/EventHandler/EventButton.h | 10 ++++++---- Code/Misc/EventHandler/EventButtonCollection.cpp | 4 ++-- Code/Misc/EventHandler/EventButtonCollection.h | 2 +- Code/Misc/EventHandler/EventHandler.cpp | 4 ++-- Code/Misc/EventHandler/EventHandler.h | 2 +- Code/Misc/EventHandler/IEventButton.h | 11 ++++++++++- 9 files changed, 38 insertions(+), 27 deletions(-) diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index 0b33e389..c1a893ee 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -142,8 +142,19 @@ namespace DanBias HRESULT DanBiasGame::Update(float deltaTime) { + //Get mouse pos and window size (Temporary) + POINT p; + RECT r; + GetCursorPos(&p); + ScreenToClient(WindowShell::GetHWND(), &p); + GetClientRect(WindowShell::GetHWND(), &r); + //Update menu buttons - EventHandler::Instance().Update(m_data->inputObj); + MouseInput mouseInput; + mouseInput.x = (float)p.x / (float)r.right; + mouseInput.y = (float)p.y / (float)r.bottom; + mouseInput.mouseButtonPressed = m_data->inputObj->IsMousePressed(); + EventHandler::Instance().Update(mouseInput); m_data->inputObj->Update(); diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h index 4785d630..5570fb2f 100644 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h @@ -37,15 +37,10 @@ namespace DanBias {} //Circle vs point collision - bool Collision(InputClass* inputObject) + bool Collision(Oyster::Event::MouseInput& input) { - POINT p; - RECT r; - GetCursorPos(&p); - ScreenToClient(WindowShell::GetHWND(), &p); - GetClientRect(WindowShell::GetHWND(), &r); //Should come from the InputClass - float xMouse = (float)p.x / (float)r.right, yMouse = (float)p.y / (float)r.bottom; + float xMouse = input.x, yMouse = input.y; double normx = (xMouse - xPos) / width; double normy = (yMouse - yPos) / height; diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h index a1aac005..711afdf8 100644 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h @@ -37,16 +37,10 @@ namespace DanBias {} //Circle vs point collision - bool Collision(InputClass* inputObject) + bool Collision(Oyster::Event::MouseInput& input) { - POINT p; - RECT r; - GetCursorPos(&p); - ScreenToClient(WindowShell::GetHWND(), &p); - GetClientRect(WindowShell::GetHWND(), &r); - //Should come from the InputClass - float xMouse = (float)p.x / (float)r.right, yMouse = (float)p.y / (float)r.bottom; + float xMouse = input.x, yMouse = input.y; float widthTemp = xPos - width * 0.5f; float widthTemp2 = xPos + width * 0.5f; diff --git a/Code/Misc/EventHandler/EventButton.h b/Code/Misc/EventHandler/EventButton.h index b891889d..0f197ffc 100644 --- a/Code/Misc/EventHandler/EventButton.h +++ b/Code/Misc/EventHandler/EventButton.h @@ -46,7 +46,7 @@ namespace Oyster private: //Implement this in the inherited classes for collision against that shape. - virtual bool Collision(InputClass *input) = 0; + virtual bool Collision(MouseInput& input) = 0; public: EventButton(); @@ -56,7 +56,7 @@ namespace Oyster EventButton(EventFunc func, Owner owner, void* userData); virtual ~EventButton(); - void Update(InputClass *input); + void Update(MouseInput& input); //Send event to callback function void SendEvent(ButtonState state); @@ -135,16 +135,18 @@ namespace Oyster //Checks for collision and template - void EventButton::Update(InputClass *input) + void EventButton::Update(MouseInput& input) { if(this->privData.enabled) { ButtonState currentState = ButtonState_None; static bool outside = false; static bool clicked = false; + + //Check for collision against the button. if(Collision(input)) { - if(input->IsMousePressed()) + if(input.mouseButtonPressed) { //Change state when the mouse button is pressed switch(this->privData.previousState) diff --git a/Code/Misc/EventHandler/EventButtonCollection.cpp b/Code/Misc/EventHandler/EventButtonCollection.cpp index 5c1438c3..9e52805e 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.cpp +++ b/Code/Misc/EventHandler/EventButtonCollection.cpp @@ -32,13 +32,13 @@ EventButtonCollection::~EventButtonCollection() } } -void EventButtonCollection::Update(InputClass* inputObject) +void EventButtonCollection::Update(MouseInput& input) { if(this->collectionState == EventCollectionState_Enabled) { for(int i = 0; i < (int)buttons.size(); i++) { - buttons[i]->Update(inputObject); + buttons[i]->Update(input); } } } diff --git a/Code/Misc/EventHandler/EventButtonCollection.h b/Code/Misc/EventHandler/EventButtonCollection.h index 5bcd044a..3cb3c891 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.h +++ b/Code/Misc/EventHandler/EventButtonCollection.h @@ -36,7 +36,7 @@ namespace Oyster EventButtonCollection(EventCollectionState state = EventCollectionState_Enabled); ~EventButtonCollection(); - void Update(InputClass* inputObject); + void Update(MouseInput& input); void Render(); /*Add a button to the collection when a button is added to the collection you are not allowed to delete it. diff --git a/Code/Misc/EventHandler/EventHandler.cpp b/Code/Misc/EventHandler/EventHandler.cpp index 234a3935..558b776c 100644 --- a/Code/Misc/EventHandler/EventHandler.cpp +++ b/Code/Misc/EventHandler/EventHandler.cpp @@ -27,11 +27,11 @@ void EventHandler::Clean() collections.clear(); } -void EventHandler::Update(InputClass* inputObject) +void EventHandler::Update(MouseInput& input) { for(int i = 0; i < (int)collections.size(); i++) { - collections.at(i)->Update(inputObject); + collections.at(i)->Update(input); } } diff --git a/Code/Misc/EventHandler/EventHandler.h b/Code/Misc/EventHandler/EventHandler.h index a2560f0f..79196afb 100644 --- a/Code/Misc/EventHandler/EventHandler.h +++ b/Code/Misc/EventHandler/EventHandler.h @@ -26,7 +26,7 @@ namespace Oyster void Clean(); - void Update(InputClass* inputObject); + void Update(MouseInput& input); void Render(); /*Add a collection to the EventHandler will only add collections not already present in the list. diff --git a/Code/Misc/EventHandler/IEventButton.h b/Code/Misc/EventHandler/IEventButton.h index 13e6f21b..62044eb2 100644 --- a/Code/Misc/EventHandler/IEventButton.h +++ b/Code/Misc/EventHandler/IEventButton.h @@ -19,6 +19,14 @@ namespace Oyster ButtonState_Down, ButtonState_Released, }; + + //Takes normalized device coordinates + struct MouseInput + { + //Normalized device coordinates + float x, y; + bool mouseButtonPressed; + }; class IEventButton { @@ -26,7 +34,8 @@ namespace Oyster virtual ~IEventButton(){} virtual void Render() = 0; - virtual void Update(InputClass *input) = 0; + + virtual void Update(MouseInput& input) = 0; virtual void SendEvent(ButtonState state) = 0; From 5fbb901c6971f14bbb81bf4c4f524a8d6f0857b6 Mon Sep 17 00:00:00 2001 From: lanariel Date: Wed, 12 Feb 2014 16:21:46 +0100 Subject: [PATCH 06/22] Model Tint added --- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 1 + Code/OysterGraphics/Model/Model.h | 1 + .../OysterGraphics/Render/DefaultRenderer.cpp | 4 ++++ Code/OysterGraphics/Render/GuiRenderer.cpp | 8 ++++---- Code/OysterGraphics/Render/Resources.cpp | 11 ++++++----- Code/OysterGraphics/Render/Resources.h | 4 +++- .../Shader/Passes/Gather/GatherPixel.hlsl | 2 +- .../Shader/Passes/Gather/Header.hlsli | 5 +++++ Code/Tester/MainTest.cpp | 19 ++++++++++++------- 9 files changed, 37 insertions(+), 18 deletions(-) diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index b8d8bbae..8cb80fe2 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -87,6 +87,7 @@ namespace Oyster m->WorldMatrix = Oyster::Math::Float4x4::identity; m->Visible = true; m->Animation.AnimationPlaying = NULL; + m->Tint = Math::Float3(1); m->info = (Model::ModelInfo*)Core::loader.LoadResource((Core::modelPath + filename).c_str(),Oyster::Graphics::Loading::LoadDAN, Oyster::Graphics::Loading::UnloadDAN); Model::ModelInfo* mi = (Model::ModelInfo*)m->info; diff --git a/Code/OysterGraphics/Model/Model.h b/Code/OysterGraphics/Model/Model.h index 590d7d6a..b264cf50 100644 --- a/Code/OysterGraphics/Model/Model.h +++ b/Code/OysterGraphics/Model/Model.h @@ -23,6 +23,7 @@ namespace Oyster { ModelInfo* info; Oyster::Math::Float4x4 WorldMatrix; + Oyster::Math::Float3 Tint; bool Visible; AnimationData Animation; }; diff --git a/Code/OysterGraphics/Render/DefaultRenderer.cpp b/Code/OysterGraphics/Render/DefaultRenderer.cpp index a92c54d6..8058cd60 100644 --- a/Code/OysterGraphics/Render/DefaultRenderer.cpp +++ b/Code/OysterGraphics/Render/DefaultRenderer.cpp @@ -138,6 +138,10 @@ namespace Oyster memcpy(data,&(pm),sizeof(pm)); Resources::Gather::ModelData.Unmap(); + data = Render::Resources::Color.Map(); + memcpy(data,&models[i].Tint,sizeof(Math::Float3)); + Render::Resources::Color.Unmap(); + if(info->Material.size()) { Core::deviceContext->PSSetShaderResources(0,(UINT)info->Material.size(),&(info->Material[0])); diff --git a/Code/OysterGraphics/Render/GuiRenderer.cpp b/Code/OysterGraphics/Render/GuiRenderer.cpp index fbdfa37c..7f3285e1 100644 --- a/Code/OysterGraphics/Render/GuiRenderer.cpp +++ b/Code/OysterGraphics/Render/GuiRenderer.cpp @@ -35,9 +35,9 @@ namespace Oyster memcpy(data,&gd,sizeof(Definitions::GuiData)); Render::Resources::Gui::Data.Unmap(); - data = Render::Resources::Gui::Color.Map(); + data = Render::Resources::Color.Map(); memcpy(data,&color,sizeof(Math::Float3)); - Render::Resources::Gui::Color.Unmap(); + Render::Resources::Color.Unmap(); Core::deviceContext->Draw(1,0); @@ -76,9 +76,9 @@ namespace Oyster Render::Resources::Gui::Data.Unmap(); Definitions::Text2D tmpInst; - data = Render::Resources::Gui::Color.Map(); + data = Render::Resources::Color.Map(); memcpy(data,&color,sizeof(Math::Float3)); - Render::Resources::Gui::Color.Unmap(); + Render::Resources::Color.Unmap(); void* dest = Resources::Gui::Text::Vertex.Map(); Definitions::Text2D* dataView = reinterpret_cast(dest); diff --git a/Code/OysterGraphics/Render/Resources.cpp b/Code/OysterGraphics/Render/Resources.cpp index 73834071..77988417 100644 --- a/Code/OysterGraphics/Render/Resources.cpp +++ b/Code/OysterGraphics/Render/Resources.cpp @@ -45,7 +45,7 @@ namespace Oyster Buffer Resources::Gather::AnimationData = Buffer(); Buffer Resources::Light::LightConstantsData = Buffer(); Buffer Resources::Gui::Data = Buffer(); - Buffer Resources::Gui::Color = Buffer(); + Buffer Resources::Color = Buffer(); Buffer Resources::Gui::Text::Vertex = Buffer(); Buffer Resources::Post::Data = Buffer(); @@ -121,7 +121,7 @@ namespace Oyster desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_PS; desc.ElementSize = sizeof(Math::Float3); - Gui::Color.Init(desc); + Color.Init(desc); desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_GS; desc.NumElements = 1; @@ -342,6 +342,7 @@ namespace Oyster Gather::Pass.IAStage.Topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; Gather::Pass.CBuffers.Vertex.push_back(Gather::AnimationData); Gather::Pass.CBuffers.Vertex.push_back(Gather::ModelData); + Gather::Pass.CBuffers.Pixel.push_back(Color); Gather::Pass.RenderStates.Rasterizer = RenderStates::rs; Gather::Pass.RenderStates.SampleCount = 1; Gather::Pass.RenderStates.SampleState = RenderStates::ss; @@ -383,7 +384,7 @@ namespace Oyster Gui::Pass.Shaders.Geometry = GetShader::Geometry(L"2D"); Gui::Pass.RTV.push_back(GBufferRTV[2]); Gui::Pass.CBuffers.Geometry.push_back(Gui::Data); - Gui::Pass.CBuffers.Pixel.push_back(Gui::Color); + Gui::Pass.CBuffers.Pixel.push_back(Color); D3D11_INPUT_ELEMENT_DESC indesc2D[] = { @@ -427,7 +428,7 @@ namespace Oyster Shader::CreateInputLayout(Text2Ddesc,3, GetShader::Vertex(L"2DText") ,Gui::Text::Pass.IAStage.Layout); Gui::Text::Pass.CBuffers.Geometry.push_back(Gui::Data); - Gui::Text::Pass.CBuffers.Pixel.push_back(Gui::Color); + Gui::Text::Pass.CBuffers.Pixel.push_back(Color); Gui::Text::Pass.SRV.Pixel.push_back(Gui::Text::Font); Gui::Text::Pass.RTV.push_back(GBufferRTV[2]); Gui::Text::Pass.RenderStates.SampleCount = 1; @@ -455,7 +456,7 @@ namespace Oyster Light::LightConstantsData.~Buffer(); Light::PointLightsData.~Buffer(); Gui::Data.~Buffer(); - Gui::Color.~Buffer(); + Color.~Buffer(); Gui::Text::Vertex.~Buffer(); Post::Data.~Buffer(); SAFE_RELEASE(Light::PointLightView); diff --git a/Code/OysterGraphics/Render/Resources.h b/Code/OysterGraphics/Render/Resources.h index d43b5756..684762fd 100644 --- a/Code/OysterGraphics/Render/Resources.h +++ b/Code/OysterGraphics/Render/Resources.h @@ -30,6 +30,9 @@ namespace Oyster static ID3D11UnorderedAccessView* LBufferUAV[LBufferSize]; static ID3D11ShaderResourceView* LBufferSRV[LBufferSize]; + + static Core::Buffer Color; + struct RenderStates { @@ -61,7 +64,6 @@ namespace Oyster { static Core::PipelineManager::RenderPass Pass; static Core::Buffer Data; - static Core::Buffer Color; struct Text { static Core::PipelineManager::RenderPass Pass; diff --git a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl index 464da702..542d8c54 100644 --- a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl @@ -40,7 +40,7 @@ float3 perturb_normal( float3 N, float3 V, float2 texcoord ) PixelOut main(VertexOut input) { PixelOut output; - output.DiffuseGlow = Diffuse.Sample(S1, input.UV); + output.DiffuseGlow = Diffuse.Sample(S1, input.UV) * float4(Color, 1); float3 normal = normalize(input.normal); normal = perturb_normal( normal, normalize(-input.ViewPos), input.UV ); diff --git a/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli b/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli index 14e0db5a..ea144417 100644 --- a/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli +++ b/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli @@ -41,4 +41,9 @@ cbuffer PerModel : register(b1) matrix WVP; int Animated; float3 Pad; +} + +cbuffer Tint : register(b0) +{ + float3 Color; } \ No newline at end of file diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index 3813d3e9..2915d62e 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -175,9 +175,12 @@ HRESULT InitDirect3D() m->WorldMatrix.m[1][1] = 50; m->WorldMatrix.m[2][2] = 0.00000005f; m2 = Oyster::Graphics::API::CreateModel(L"char_temporary.dan"); + m2->Tint = Oyster::Math::Float3(0.8f,0.8f,1); + m3 = Oyster::Graphics::API::CreateModel(L"char_temporary.dan"); m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(4,0,0),Oyster::Math::Float3::null); - Oyster::Graphics::API::PlayAnimation(m2, L"movement"); - + Oyster::Graphics::API::PlayAnimation(m2, L"movement", true); + Oyster::Graphics::API::PlayAnimation(m3, L"movement", true); + t = Oyster::Graphics::API::CreateTexture(L"structure_corp_mdg.png"); t2 = Oyster::Graphics::API::CreateTexture(L"whiteGui.png"); @@ -189,21 +192,21 @@ HRESULT InitDirect3D() - pl.Color = Oyster::Math::Float3(1,0,0); + pl.Color = Oyster::Math::Float3(1,1,1); pl.Bright = 1; pl.Pos = Oyster::Math::Float3(-20,0,0); pl.Radius = 90; Oyster::Graphics::API::AddLight(pl); - pl.Color = Oyster::Math::Float3(0,1,0); + pl.Color = Oyster::Math::Float3(1,1,1); pl.Bright = 1; pl.Pos = Oyster::Math::Float3(0,20,0); pl.Radius = 90; Oyster::Graphics::API::AddLight(pl); - pl.Color = Oyster::Math::Float3(0,0,1); + pl.Color = Oyster::Math::Float3(1,1,1); pl.Bright = 1; pl.Pos = Oyster::Math::Float3(0,0,20); pl.Radius = 90; @@ -218,6 +221,7 @@ HRESULT Update(float deltaTime) { //angle += Oyster::Math::pi/16 * deltaTime; m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0) * angle,Oyster::Math::Float3(4,0,0),Oyster::Math::Float3::null); + m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0) * -angle,Oyster::Math::Float3(-4,0,0),Oyster::Math::Float3::null); //Oyster::Math::Matrix ma = Oyster::Math::Matrix::identity; Oyster::Graphics::API::Update(deltaTime); //m2->Animation.data.AnimationTime += deltaTime;// * 0.5f; @@ -231,8 +235,9 @@ HRESULT Render(float deltaTime) //Oyster::Graphics::API::RenderModel(m); Oyster::Graphics::API::RenderModel(m2); - Oyster::Graphics::API::StartGuiRender(); - //Oyster::Graphics::API::RenderGuiElement(t,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1)); + Oyster::Graphics::API::RenderModel(m3); + //Oyster::Graphics::API::StartGuiRender(); + //Oyster::Graphics::API::RenderGuiElement(t,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1), Oyster::Math::Float3(0,0,1)); //Oyster::Graphics::API::RenderGuiElement(t2,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1),Oyster::Math::Float3(1,0,0)); Oyster::Graphics::API::StartTextRender(); std::wstring fps; From bd6b531418f951970e6fcd45d79cd170f306170e Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Thu, 13 Feb 2014 09:58:14 +0100 Subject: [PATCH 07/22] GL - added Portal and started on crystalformation --- Code/DanBias.sln | 31 +++++++++---------- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 19 ++++-------- Code/Game/GameLogic/CollisionManager.cpp | 16 ++++++++++ Code/Game/GameLogic/CrystalFormation.cpp | 20 ++++++++++++ Code/Game/GameLogic/CrystalFormation.h | 21 +++++++++++++ Code/Game/GameLogic/GameLogic.vcxproj | 2 ++ Code/Game/GameLogic/Portal.cpp | 22 +++++++++++++ Code/Game/GameLogic/Portal.h | 23 ++++++++++++++ 8 files changed, 125 insertions(+), 29 deletions(-) create mode 100644 Code/Game/GameLogic/CrystalFormation.cpp create mode 100644 Code/Game/GameLogic/CrystalFormation.h create mode 100644 Code/Game/GameLogic/Portal.cpp create mode 100644 Code/Game/GameLogic/Portal.h diff --git a/Code/DanBias.sln b/Code/DanBias.sln index f2bf5f98..4d512dff 100644 --- a/Code/DanBias.sln +++ b/Code/DanBias.sln @@ -68,8 +68,8 @@ Global {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|Win32.ActiveCfg = Debug|Win32 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|Win32.Build.0 = Debug|Win32 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|Win32.Deploy.0 = Debug|Win32 - {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|x64.ActiveCfg = Release|x64 - {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|x64.Build.0 = Release|x64 + {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|x64.ActiveCfg = Debug|x64 + {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|x64.Build.0 = Debug|x64 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.MinSizeRel|Mixed Platforms.ActiveCfg = Release|Win32 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.MinSizeRel|Mixed Platforms.Build.0 = Release|Win32 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.MinSizeRel|Win32.ActiveCfg = Release|Win32 @@ -93,8 +93,8 @@ Global {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|Win32.ActiveCfg = Debug|Win32 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|Win32.Build.0 = Debug|Win32 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|Win32.Deploy.0 = Debug|Win32 - {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|x64.ActiveCfg = Release|x64 - {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|x64.Build.0 = Release|x64 + {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|x64.ActiveCfg = Debug|x64 + {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|x64.Build.0 = Debug|x64 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.MinSizeRel|Mixed Platforms.ActiveCfg = Release|Win32 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.MinSizeRel|Mixed Platforms.Build.0 = Release|Win32 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.MinSizeRel|Win32.ActiveCfg = Release|Win32 @@ -113,13 +113,13 @@ Global {F10CBC03-9809-4CBA-95D8-327C287B18EE}.RelWithDebInfo|Win32.Build.0 = Release|Win32 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.RelWithDebInfo|x64.ActiveCfg = Release|x64 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.RelWithDebInfo|x64.Build.0 = Release|x64 - {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Mixed Platforms.ActiveCfg = Release|x64 - {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Mixed Platforms.Build.0 = Release|x64 + {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Mixed Platforms.ActiveCfg = Debug|x64 + {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Mixed Platforms.Build.0 = Debug|x64 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Win32.ActiveCfg = Debug|Win32 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Win32.Build.0 = Debug|Win32 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Win32.Deploy.0 = Debug|Win32 - {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|x64.ActiveCfg = Release|x64 - {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|x64.Build.0 = Release|x64 + {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|x64.ActiveCfg = Debug|x64 + {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|x64.Build.0 = Debug|x64 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.MinSizeRel|Mixed Platforms.ActiveCfg = Release|Win32 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.MinSizeRel|Mixed Platforms.Build.0 = Release|Win32 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.MinSizeRel|Win32.ActiveCfg = Release|Win32 @@ -174,8 +174,8 @@ Global {6A066806-F43F-4B31-A4E3-57179674F460}.RelWithDebInfo|Mixed Platforms.ActiveCfg = Release|Win32 {6A066806-F43F-4B31-A4E3-57179674F460}.RelWithDebInfo|Win32.ActiveCfg = Release|Win32 {6A066806-F43F-4B31-A4E3-57179674F460}.RelWithDebInfo|x64.ActiveCfg = Release|x64 - {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Mixed Platforms.ActiveCfg = Release|x64 - {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Mixed Platforms.Build.0 = Release|x64 + {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Mixed Platforms.ActiveCfg = Debug|x64 + {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Mixed Platforms.Build.0 = Debug|x64 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Win32.ActiveCfg = Debug|Win32 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Win32.Build.0 = Debug|Win32 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|x64.ActiveCfg = Release|x64 @@ -196,20 +196,19 @@ Global {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|Mixed Platforms.Build.0 = Release|Win32 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|Win32.ActiveCfg = Debug|Win32 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|Win32.Build.0 = Debug|Win32 - {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|x64.ActiveCfg = Release|Win32 - {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|x64.Build.0 = Release|Win32 + {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|x64.ActiveCfg = Debug|x64 + {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|x64.Build.0 = Debug|x64 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.MinSizeRel|Mixed Platforms.ActiveCfg = Debug|Win32 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.MinSizeRel|Win32.ActiveCfg = Debug|Win32 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.MinSizeRel|x64.ActiveCfg = Debug|Win32 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Release|Mixed Platforms.ActiveCfg = Release|Win32 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Release|Mixed Platforms.Build.0 = Release|Win32 {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 - {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Release|x64.Build.0 = Release|Win32 + {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Release|x64.ActiveCfg = Release|x64 + {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Release|x64.Build.0 = Release|x64 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.RelWithDebInfo|Mixed Platforms.ActiveCfg = Release|Win32 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.RelWithDebInfo|Win32.ActiveCfg = Release|Win32 - {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.RelWithDebInfo|x64.ActiveCfg = Release|Win32 + {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.RelWithDebInfo|x64.ActiveCfg = Release|x64 {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Mixed Platforms.Build.0 = Debug|Win32 {666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Win32.ActiveCfg = Debug|Win32 diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 1e5d0640..86560164 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -38,18 +38,14 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS: ForcePush(usage,dt); break; + case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS: - - if(hasObject) - { - //ForcePush(usage,dt);//WARNING THIS IS A CRAP TEST TO MAKE SURE YOU CAN SHOOT BOXES - break; - } ForcePull(usage,dt); - break; + break; + case WEAPON_FIRE::WEAPON_USE_UTILLITY_PRESS: ForceZip(usage,dt); - break; + break; } } @@ -117,12 +113,9 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float ********************************************************/ void AttatchmentMassDriver::ForceZip(const WEAPON_FIRE &usage, float dt) { - Oyster::Physics::Struct::CustomBodyState state = this->owner->GetRigidBody()->GetState(); + Oyster::Math::Float3 force = Oyster::Math::Float4(this->owner->GetLookDir()) * (1000); - //do something with state - //state.ApplyLinearImpulse(Oyster::Math::Float3(this->owner->GetLookDir()) * (500 * dt)); - - this->owner->GetRigidBody()->SetState(state); + this->owner->GetRigidBody()->ApplyImpulse(force); } diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 9aef6b6c..857c135c 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -7,6 +7,7 @@ #include "Game.h" #include "CollisionManager.h" #include "JumpPad.h" +#include "Portal.h" using namespace Oyster; @@ -14,6 +15,7 @@ using namespace GameLogic; void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss); void SendObjectFlying(Oyster::Physics::ICustomBody &obj, Oyster::Math::Float3 force); + void Teleport(Oyster::Physics::ICustomBody &obj, Oyster::Math::Float3 target); //Physics::ICustomBody::SubscriptMessage void Player::PlayerCollision(Oyster::Physics::ICustomBody *rigidBodyPlayer, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) @@ -63,6 +65,20 @@ using namespace GameLogic; { obj.ApplyImpulse(force); } + + void Portal::PortalActivated(Oyster::Physics::ICustomBody *rigidBodyPortal, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) + { + Portal *portal = (Portal*)(rigidBodyPortal->GetCustomTag()); + + if(obj->GetState().mass == 0) return; + + Teleport(*obj,portal->portalExit); + } + + void Teleport(Oyster::Physics::ICustomBody &obj, Oyster::Math::Float3 target) + { + obj.SetPosition(target); + } void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss) diff --git a/Code/Game/GameLogic/CrystalFormation.cpp b/Code/Game/GameLogic/CrystalFormation.cpp new file mode 100644 index 00000000..00709660 --- /dev/null +++ b/Code/Game/GameLogic/CrystalFormation.cpp @@ -0,0 +1,20 @@ +#include "CrystalFormation.h" + +using namespace GameLogic; + +CrystalFormation::CrystalFormation(void) + :StaticObject() +{ + this->shreddingDamage = 0; +} + +CrystalFormation::CrystalFormation(Oyster::Physics::ICustomBody *rigidBody, void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type, Oyster::Math::Float shreddingDamage) + :StaticObject(rigidBody, collisionFuncAfter, type) +{ + this->shreddingDamage = shreddingDamage; +} + + +CrystalFormation::~CrystalFormation(void) +{ +} diff --git a/Code/Game/GameLogic/CrystalFormation.h b/Code/Game/GameLogic/CrystalFormation.h new file mode 100644 index 00000000..693460fe --- /dev/null +++ b/Code/Game/GameLogic/CrystalFormation.h @@ -0,0 +1,21 @@ +#ifndef CRYSTALFORMATION_H +#define CRYSTALFORMATION_H +#include "StaticObject.h" +namespace GameLogic +{ + class CrystalFormation : public StaticObject + { + public: + CrystalFormation(void); + + CrystalFormation(Oyster::Physics::ICustomBody *rigidBody + ,void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss) + ,OBJECT_TYPE type, Oyster::Math::Float shreddingDamage); + + ~CrystalFormation(void); + + private: + Oyster::Math::Float shreddingDamage; + }; +} +#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index 7ae78fac..b19ffef0 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -192,6 +192,7 @@ + @@ -215,6 +216,7 @@ + diff --git a/Code/Game/GameLogic/Portal.cpp b/Code/Game/GameLogic/Portal.cpp new file mode 100644 index 00000000..ac44d529 --- /dev/null +++ b/Code/Game/GameLogic/Portal.cpp @@ -0,0 +1,22 @@ +#include "Portal.h" + +using namespace GameLogic; +using namespace Oyster::Math; + +Portal::Portal(void) + :StaticObject() +{ + this->portalExit = Float3(0,0,0); +} + +Portal::Portal(Oyster::Physics::ICustomBody *rigidBody, void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type, Oyster::Math::Float3 portalExit) + :StaticObject(rigidBody, collisionFuncAfter, type) +{ + this->portalExit = portalExit; +} + +Portal::~Portal(void) +{ + +} + diff --git a/Code/Game/GameLogic/Portal.h b/Code/Game/GameLogic/Portal.h new file mode 100644 index 00000000..5b31c8b5 --- /dev/null +++ b/Code/Game/GameLogic/Portal.h @@ -0,0 +1,23 @@ +#ifndef PORTAL_H +#define PORTAL_H +#include "StaticObject.h" +namespace GameLogic +{ + class Portal : public StaticObject + { + public: + Portal(void); + + Portal(Oyster::Physics::ICustomBody *rigidBody + ,void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss) + ,OBJECT_TYPE type, Oyster::Math::Float3 portalExit); + + ~Portal(void); + + static void PortalActivated(Oyster::Physics::ICustomBody *rigidBodyPortal, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); + + private: + Oyster::Math::Float3 portalExit; + }; +} +#endif \ No newline at end of file From 95e08e84c3a4a831beaaccb4aa26b21c01de5b63 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Thu, 13 Feb 2014 13:51:27 +0100 Subject: [PATCH 08/22] Network - Overloaded Connect in NetworkClient to use std::wstring. --- Code/Network/NetworkAPI/NetworkClient.cpp | 14 ++++++++++++++ Code/Network/NetworkAPI/NetworkClient.h | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/Code/Network/NetworkAPI/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp index 01ba495e..1f470c11 100644 --- a/Code/Network/NetworkAPI/NetworkClient.cpp +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -21,6 +21,9 @@ #include #include +//For conversion from wstring to string +#include + using namespace Oyster::Network; using namespace Oyster::Thread; using namespace Utility::DynamicMemory; @@ -293,6 +296,17 @@ bool NetworkClient::Connect(unsigned short port, const char serverIP[]) return true; } +bool NetworkClient::Connect(unsigned short port, std::wstring serverIP) +{ + //Convert from wstring to string. + typedef std::codecvt_utf8 convert_typeX; + std::wstring_convert converterX; + + std::string ip = converterX.to_bytes(serverIP); + + return this->Connect(port, ip.c_str()); +} + void NetworkClient::Disconnect() { if(!privateData) return; diff --git a/Code/Network/NetworkAPI/NetworkClient.h b/Code/Network/NetworkAPI/NetworkClient.h index a19f74e4..b7e0d6a4 100644 --- a/Code/Network/NetworkAPI/NetworkClient.h +++ b/Code/Network/NetworkAPI/NetworkClient.h @@ -88,6 +88,11 @@ namespace Oyster */ bool Connect(unsigned short port, const char serverIP[]); + /** + * + */ + bool Connect(unsigned short port, std::wstring serverIP); + /** * */ From d01acbcbe0352ce5f552a929026a085589c62b64 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Thu, 13 Feb 2014 15:21:05 +0100 Subject: [PATCH 09/22] Misc - Added text and textcolor to buttons, seperate render function. --- .../GameClientState/Buttons/ButtonEllipse.h | 20 ++--- .../GameClientState/Buttons/ButtonRectangle.h | 24 +++--- .../GameClientState/Buttons/EventButtonGUI.h | 76 +++++++++++++------ .../GameClientState/LoginState.cpp | 43 +++++++---- .../EventHandler/EventButtonCollection.cpp | 15 +++- .../Misc/EventHandler/EventButtonCollection.h | 3 +- Code/Misc/EventHandler/EventHandler.cpp | 12 ++- Code/Misc/EventHandler/EventHandler.h | 3 +- Code/Misc/EventHandler/IEventButton.h | 3 +- 9 files changed, 132 insertions(+), 67 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h index 5570fb2f..a922f141 100644 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h @@ -21,17 +21,17 @@ namespace DanBias ButtonEllipse() : EventButtonGUI(), radius(0) {} - ButtonEllipse(std::wstring textureName, Owner owner, float xPos, float yPos, float textureWidth, float textureHeight, bool resizeToScreenAspectRatio = true) - : EventButtonGUI(textureName, owner, xPos, yPos, textureWidth, textureHeight, resizeToScreenAspectRatio) + ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButtonGUI(textureName, buttonText, textColor, owner, pos, size, resize) {} - ButtonEllipse(std::wstring textureName, EventFunc func, float xPos, float yPos, float textureWidth, float textureHeight, bool resizeToScreenAspectRatio = true) - : EventButtonGUI(textureName, func, xPos, yPos, textureWidth, textureHeight, resizeToScreenAspectRatio) + ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButtonGUI(textureName, buttonText, textColor, func, pos, size, resize) {} - ButtonEllipse(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float textureWidth, float textureHeight, bool resizeToScreenAspectRatio = true) - : EventButtonGUI(textureName, func, owner, xPos, yPos, textureWidth, textureHeight, resizeToScreenAspectRatio) + ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButtonGUI(textureName, buttonText, textColor, func, owner, pos, size, resize) {} - ButtonEllipse(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float textureWidth, float textureHeight, bool resizeToScreenAspectRatio = true) - : EventButtonGUI(textureName, func, owner, userData, xPos, yPos, textureWidth, textureHeight, resizeToScreenAspectRatio) + ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButtonGUI(textureName, buttonText, textColor, func, owner, userData, pos, size, resize) {} virtual ~ButtonEllipse() {} @@ -42,8 +42,8 @@ namespace DanBias //Should come from the InputClass float xMouse = input.x, yMouse = input.y; - double normx = (xMouse - xPos) / width; - double normy = (yMouse - yPos) / height; + double normx = (xMouse - pos.x) / size.x; + double normy = (yMouse - pos.y) / size.y; return (normx * normx + normy * normy) < 0.25; } diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h index 711afdf8..a0b3e94b 100644 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h @@ -21,17 +21,17 @@ namespace DanBias ButtonRectangle() : EventButtonGUI(), width(0), height(0) {} - ButtonRectangle(std::wstring textureName, Owner owner, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true) - : EventButtonGUI(textureName, owner, xPos, yPos, width, height, resizeToScreenAspectRatio) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButtonGUI(textureName, buttonText, textColor, owner, pos, size, resize) {} - ButtonRectangle(std::wstring textureName, EventFunc func, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true) - : EventButtonGUI(textureName, func, xPos, yPos, width, height, resizeToScreenAspectRatio) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButtonGUI(textureName, buttonText, textColor, func, pos, size, resize) {} - ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true) - : EventButtonGUI(textureName, func, owner, xPos, yPos, width, height, resizeToScreenAspectRatio) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButtonGUI(textureName, buttonText, textColor, func, owner, pos, size, resize) {} - ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true) - : EventButtonGUI(textureName, func, owner, userData, xPos, yPos, width, height, resizeToScreenAspectRatio) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButtonGUI(textureName, buttonText, textColor, func, owner, userData, pos, size, resize) {} virtual ~ButtonRectangle() {} @@ -42,10 +42,10 @@ namespace DanBias //Should come from the InputClass float xMouse = input.x, yMouse = input.y; - float widthTemp = xPos - width * 0.5f; - float widthTemp2 = xPos + width * 0.5f; - float heightTemp = yPos - height * 0.5f; - float heightTemp2 = yPos + height * 0.5f; + float widthTemp = pos.x - size.x * 0.5f; + float widthTemp2 = pos.x + size.x * 0.5f; + float heightTemp = pos.y - size.y * 0.5f; + float heightTemp2 = pos.y + size.y * 0.5f; //std::cout << p.x << ' ' << p.y << ' ' << widthTemp << ' ' << heightTemp << std::endl; if(xMouse >= widthTemp && xMouse <= widthTemp2 && diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h b/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h index e71dd0fa..d4884fd7 100644 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h @@ -8,40 +8,56 @@ #include "../Misc/EventHandler/EventButton.h" #include "../OysterGraphics/DllInterfaces/GFXAPI.h" + + namespace DanBias { namespace Client { + /*Dictates if the texture should be resized based on the screen aspect ratio. + + */ + enum ResizeAspectRatio + { + ResizeAspectRatio_None, + ResizeAspectRatio_Width, + ResizeAspectRatio_Height, + + ResizeAspectRatio_Count, + ResizeAspectRatio_Unknown = -1 + }; + + template class EventButtonGUI : public Oyster::Event::EventButton { public: EventButtonGUI() - : EventButton(), xPos(0), yPos(0), width(0), height(0), texture(NULL) + : EventButton(), pos(0, 0), size(0, 0), texture(NULL), buttonText(""), textColor(0, 0, 0) {} - EventButtonGUI(std::wstring textureName, Owner owner, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true) - : EventButton(owner), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButton(owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) { CreateTexture(textureName); - if(resizeToScreenAspectRatio) ResizeWithAspectRatio(); + if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } - EventButtonGUI(std::wstring textureName, EventFunc func, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true) - : EventButton(func), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButton(func), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) { CreateTexture(textureName); - if(resizeToScreenAspectRatio) ResizeWithAspectRatio(); + if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } - EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true) - : EventButton(func, owner), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButton(func, owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) { CreateTexture(textureName); - if(resizeToScreenAspectRatio) ResizeWithAspectRatio(); + if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } - EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true) - : EventButton(func, owner, userData), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButton(func, owner, userData), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) { CreateTexture(textureName); - if(resizeToScreenAspectRatio) ResizeWithAspectRatio(); + if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } virtual ~EventButtonGUI() { @@ -55,7 +71,7 @@ namespace DanBias texture = Oyster::Graphics::API::CreateTexture(textureName); } - virtual void Render() + virtual void RenderTexture() { if(EventButton::Enabled()) { @@ -64,32 +80,48 @@ namespace DanBias if(EventButton::GetState() == ButtonState_None) { - Oyster::Graphics::API::RenderGuiElement(texture, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height), Oyster::Math::Float3(1.0f, 1.0f, 1.0f)); + Oyster::Graphics::API::RenderGuiElement(texture, pos.xy, size, Oyster::Math::Float3(1.0f, 1.0f, 1.0f)); } else if(EventButton::GetState() == ButtonState_Hover) { - Oyster::Graphics::API::RenderGuiElement(texture, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height), Oyster::Math::Float3(0.0f, 1.0f, 0.0f)); + Oyster::Graphics::API::RenderGuiElement(texture, pos.xy, size, Oyster::Math::Float3(0.0f, 1.0f, 0.0f)); } else { - Oyster::Graphics::API::RenderGuiElement(texture, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height), Oyster::Math::Float3(1.0f, 0.0f, 0.0f)); + Oyster::Graphics::API::RenderGuiElement(texture, pos.xy, size, Oyster::Math::Float3(1.0f, 0.0f, 0.0f)); } } } - void ResizeWithAspectRatio() + virtual void RenderText() + { + if(buttonText.size() > 0) + { + Oyster::Graphics::API::RenderText(buttonText, pos.xy, size, textColor); + } + } + + private: + void ResizeWithAspectRatio(ResizeAspectRatio resize) { RECT r; GetClientRect(WindowShell::GetHWND(), &r); - height *= (float)r.right/(float)r.bottom; + + if(resize == ResizeAspectRatio_Height) + size.y *= (float)r.right/(float)r.bottom; + else if(resize == ResizeAspectRatio_Width) + size.x *= (float)r.bottom/(float)r.right; } protected: - float xPos, yPos; - float width, height; - Oyster::Graphics::API::Texture texture; + Oyster::Math::Float3 pos; + Oyster::Math::Float2 size; + Oyster::Graphics::API::Texture texture; + + std::wstring buttonText; + Oyster::Math::Float3 textColor; }; } } diff --git a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp index 297335c8..37a3e951 100644 --- a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp @@ -109,23 +109,33 @@ bool LoginState::Init(Oyster::Network::NetworkClient* nwClient) InitCamera(Oyster::Math::Float3(0,0,5.4f)); //Create menu buttons - //privData->collection = new EventButtonCollection; EventHandler::Instance().AddCollection(&privData->collection); - privData->collection.AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.2f, 0.1f, 0.1f)); - privData->collection.AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.3f, 0.1f, 0.1f)); - privData->collection.AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.4f, 0.1f, 0.1f)); - privData->collection.AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.5f, 0.1f, 0.1f)); - - privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.15f, 0.05f, 0.1f, 0.1f)); - privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.25f, 0.05f, 0.1f, 0.1f)); - privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.35f, 0.05f, 0.1f, 0.1f)); - privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.45f, 0.05f, 0.1f, 0.1f)); - - privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Create, 0.5f, 0.5f, 0.3f, 0.3f)); - + privData->collection.AddButton(new ButtonEllipse(L"circle.png", L"Hej", Oyster::Math::Float3(1, 1, 0), &LoginState::ButtonCallback, this, + (void*)Options, Oyster::Math::Float3(0.2f, 0.2f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f), ResizeAspectRatio_Width)); + privData->collection.AddButton(new ButtonEllipse(L"circle.png", L"Hej", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this, + (void*)Options, Oyster::Math::Float3(0.2f, 0.3f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f), ResizeAspectRatio_Width)); + privData->collection.AddButton(new ButtonEllipse(L"circle.png", L"Hej", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this, + (void*)Options, Oyster::Math::Float3(0.2f, 0.4f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f), ResizeAspectRatio_Width)); + privData->collection.AddButton(new ButtonEllipse(L"circle.png", L"Hej", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this, + (void*)Options, Oyster::Math::Float3(0.2f, 0.5f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f), ResizeAspectRatio_Width)); + + privData->collection.AddButton(new ButtonRectangle(L"button.png", L"", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this, + (void*)Options, Oyster::Math::Float3(0.15f, 0.05f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f))); + privData->collection.AddButton(new ButtonRectangle(L"button.png", L"Hej", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this, + (void*)Options, Oyster::Math::Float3(0.25f, 0.05f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f))); + privData->collection.AddButton(new ButtonRectangle(L"button.png", L"Hej", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this, + (void*)Options, Oyster::Math::Float3(0.35f, 0.05f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f))); + privData->collection.AddButton(new ButtonRectangle(L"button.png", L"Hej", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this, + (void*)Options, Oyster::Math::Float3(0.45f, 0.05f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f))); + + privData->collection.AddButton(new ButtonRectangle(L"button.png", L"Create Game", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this, + (void*)Create, Oyster::Math::Float3(0.5f, 0.5f, 0.0f), Oyster::Math::Float2(0.3f, 0.3f))); + //Incr/decr buttons . - privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Incr, 0.85f, 0.2f, 0.1f, 0.1f)); - privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Decr, 0.55f, 0.2f, 0.1f, 0.1f)); + privData->collection.AddButton(new ButtonRectangle(L"button.png", L"Hej", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this, + (void*)Incr, Oyster::Math::Float3(0.85f, 0.2f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f))); + privData->collection.AddButton(new ButtonRectangle(L"button.png", L"Hej", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this, + (void*)Decr, Oyster::Math::Float3(0.55f, 0.2f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f))); privData->createGame = false; privData->testNumber = 0; @@ -236,7 +246,7 @@ bool LoginState::Render(float dt) //Render buttons Oyster::Graphics::API::StartGuiRender(); - EventHandler::Instance().Render(); + EventHandler::Instance().RenderTexture(); std::wstring number; wchar_t temp[10]; @@ -244,6 +254,7 @@ bool LoginState::Render(float dt) number = temp; Oyster::Graphics::API::StartTextRender(); + EventHandler::Instance().RenderText(); Oyster::Graphics::API::RenderText(number, Oyster::Math::Float2(0.7f, 0.2f), Oyster::Math::Float2(0.1f, 0.1f*(1008.0f/730.0f)), Oyster::Math::Float3(1.0f, 0.0f, 0.0f)); Oyster::Graphics::API::EndFrame(); diff --git a/Code/Misc/EventHandler/EventButtonCollection.cpp b/Code/Misc/EventHandler/EventButtonCollection.cpp index 9e52805e..72d0ba24 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.cpp +++ b/Code/Misc/EventHandler/EventButtonCollection.cpp @@ -43,13 +43,24 @@ void EventButtonCollection::Update(MouseInput& input) } } -void EventButtonCollection::Render() +void EventButtonCollection::RenderTexture() { if(this->collectionState == EventCollectionState_Enabled) { for(int i = 0; i < (int)buttons.size(); i++) { - buttons[i]->Render(); + buttons[i]->RenderTexture(); + } + } +} + +void EventButtonCollection::RenderText() +{ + if(this->collectionState == EventCollectionState_Enabled) + { + for(int i = 0; i < (int)buttons.size(); i++) + { + buttons[i]->RenderText(); } } } diff --git a/Code/Misc/EventHandler/EventButtonCollection.h b/Code/Misc/EventHandler/EventButtonCollection.h index 3cb3c891..8c39d171 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.h +++ b/Code/Misc/EventHandler/EventButtonCollection.h @@ -37,7 +37,8 @@ namespace Oyster ~EventButtonCollection(); void Update(MouseInput& input); - void Render(); + void RenderTexture(); + void RenderText(); /*Add a button to the collection when a button is added to the collection you are not allowed to delete it. */ diff --git a/Code/Misc/EventHandler/EventHandler.cpp b/Code/Misc/EventHandler/EventHandler.cpp index 558b776c..24dca38a 100644 --- a/Code/Misc/EventHandler/EventHandler.cpp +++ b/Code/Misc/EventHandler/EventHandler.cpp @@ -35,11 +35,19 @@ void EventHandler::Update(MouseInput& input) } } -void EventHandler::Render() +void EventHandler::RenderTexture() { for(int i = 0; i < (int)collections.size(); i++) { - collections.at(i)->Render(); + collections.at(i)->RenderTexture(); + } +} + +void EventHandler::RenderText() +{ + for(int i = 0; i < (int)collections.size(); i++) + { + collections.at(i)->RenderText(); } } diff --git a/Code/Misc/EventHandler/EventHandler.h b/Code/Misc/EventHandler/EventHandler.h index 79196afb..82c25e1a 100644 --- a/Code/Misc/EventHandler/EventHandler.h +++ b/Code/Misc/EventHandler/EventHandler.h @@ -27,7 +27,8 @@ namespace Oyster void Clean(); void Update(MouseInput& input); - void Render(); + void RenderTexture(); + void RenderText(); /*Add a collection to the EventHandler will only add collections not already present in the list. diff --git a/Code/Misc/EventHandler/IEventButton.h b/Code/Misc/EventHandler/IEventButton.h index 62044eb2..d0c754f9 100644 --- a/Code/Misc/EventHandler/IEventButton.h +++ b/Code/Misc/EventHandler/IEventButton.h @@ -33,7 +33,8 @@ namespace Oyster public: virtual ~IEventButton(){} - virtual void Render() = 0; + virtual void RenderTexture() = 0; + virtual void RenderText() = 0; virtual void Update(MouseInput& input) = 0; From 491dc88bd1b440cdd49dca82b5f35dfa22ed40b3 Mon Sep 17 00:00:00 2001 From: lanariel Date: Thu, 13 Feb 2014 15:24:19 +0100 Subject: [PATCH 10/22] Fixed Glow Mapping --- .../Definitions/GraphicalDefinition.h | 9 ++++ .../OysterGraphics/Render/DefaultRenderer.cpp | 46 +++++++++++++++++-- Code/OysterGraphics/Render/Resources.cpp | 18 +++++++- Code/OysterGraphics/Render/Resources.h | 2 + .../Shader/Passes/Blur/BlurHor.hlsl | 11 ++--- .../Shader/Passes/Blur/BlurSharedData.hlsli | 35 +++++++++----- .../Shader/Passes/Blur/BlurVert.hlsl | 12 ++--- .../Shader/Passes/Gather/GatherPixel.hlsl | 3 +- .../Shader/Passes/Light/LightPass.hlsl | 2 +- .../Shader/Passes/Post/PostPass.hlsl | 30 +++++++++++- Code/Tester/MainTest.cpp | 19 ++++---- 11 files changed, 145 insertions(+), 42 deletions(-) diff --git a/Code/OysterGraphics/Definitions/GraphicalDefinition.h b/Code/OysterGraphics/Definitions/GraphicalDefinition.h index 0b30ee76..958904a8 100644 --- a/Code/OysterGraphics/Definitions/GraphicalDefinition.h +++ b/Code/OysterGraphics/Definitions/GraphicalDefinition.h @@ -73,6 +73,15 @@ namespace Oyster int offset; float coff; }; + + struct BlurrData + { + unsigned int StartX; + unsigned int StartY; + unsigned int StopX; + unsigned int StopY; + Math::Float4 BlurMask; + }; } } } \ No newline at end of file diff --git a/Code/OysterGraphics/Render/DefaultRenderer.cpp b/Code/OysterGraphics/Render/DefaultRenderer.cpp index 8058cd60..c0c2990e 100644 --- a/Code/OysterGraphics/Render/DefaultRenderer.cpp +++ b/Code/OysterGraphics/Render/DefaultRenderer.cpp @@ -162,6 +162,46 @@ namespace Oyster } } + void BlurGlow() + { + Definitions::BlurrData bd; + bd.BlurMask = Math::Float4(1,1,1,1); + bd.StopX = Core::resolution.x/2; + bd.StopY = Core::resolution.y; + bd.StartX = 0; + bd.StartY = Core::resolution.y/2; + + void* data = Resources::Blur::Data.Map(); + memcpy(data,&bd,sizeof(Definitions::BlurrData)); + Resources::Blur::Data.Unmap(); + + Core::PipelineManager::SetRenderPass(Resources::Blur::HorPass); + Core::deviceContext->Dispatch((UINT)((Core::resolution.x/2 + 127U) / 128U), (UINT)(Core::resolution.y/2), 1); + + Core::PipelineManager::SetRenderPass(Resources::Blur::VertPass); + Core::deviceContext->Dispatch((UINT)(Core::resolution.x/2), (UINT)((Core::resolution.y/2 + 127U) / 128U), 1); + } + + void BlurSSAO() + { + Definitions::BlurrData bd; + bd.BlurMask = Math::Float4(0,0,0,1); + bd.StopX = Core::resolution.x/2; + bd.StopY = Core::resolution.y/2; + bd.StartX = 0; + bd.StartY = 0; + + void* data = Resources::Blur::Data.Map(); + memcpy(data,&bd,sizeof(Definitions::BlurrData)); + Resources::Blur::Data.Unmap(); + + Core::PipelineManager::SetRenderPass(Resources::Blur::HorPass); + Core::deviceContext->Dispatch((UINT)((Core::resolution.x/2 + 127U) / 128U), (UINT)(Core::resolution.y/2), 1); + + Core::PipelineManager::SetRenderPass(Resources::Blur::VertPass); + Core::deviceContext->Dispatch((UINT)(Core::resolution.x/2), (UINT)((Core::resolution.y/2 + 127U) / 128U), 1); + } + void DefaultRenderer::EndFrame() { @@ -169,11 +209,9 @@ namespace Oyster Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1); - //Core::PipelineManager::SetRenderPass(Resources::Blur::HorPass); - //Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1); + BlurGlow(); - //Core::PipelineManager::SetRenderPass(Resources::Blur::VertPass); - //Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1); + BlurSSAO(); Core::PipelineManager::SetRenderPass(Resources::Post::Pass); diff --git a/Code/OysterGraphics/Render/Resources.cpp b/Code/OysterGraphics/Render/Resources.cpp index 77988417..450a075b 100644 --- a/Code/OysterGraphics/Render/Resources.cpp +++ b/Code/OysterGraphics/Render/Resources.cpp @@ -23,8 +23,8 @@ namespace Oyster { namespace Render { - - ID3D11RenderTargetView* Resources::GBufferRTV[Resources::GBufferSize] = {0}; + #pragma region Declare Static + ID3D11RenderTargetView* Resources::GBufferRTV[Resources::GBufferSize] = {0}; ID3D11ShaderResourceView* Resources::GBufferSRV[Resources::GBufferSize] = {0}; ID3D11UnorderedAccessView* Resources::LBufferUAV[Resources::LBufferSize] = {0}; @@ -48,6 +48,7 @@ namespace Oyster Buffer Resources::Color = Buffer(); Buffer Resources::Gui::Text::Vertex = Buffer(); Buffer Resources::Post::Data = Buffer(); + Buffer Resources::Blur::Data = Buffer(); Buffer Resources::Light::PointLightsData = Buffer(); ID3D11ShaderResourceView* Resources::Light::PointLightView = NULL; @@ -61,6 +62,7 @@ namespace Oyster ID3D11BlendState* Resources::RenderStates::bs = NULL; ID3D11ShaderResourceView* Resources::Gui::Text::Font = NULL; +#pragma endregion Core::Init::State Resources::InitShaders() @@ -135,6 +137,9 @@ namespace Oyster desc.ElementSize = sizeof(Definitions::LightConstants); Light::LightConstantsData.Init(desc); + desc.ElementSize = sizeof(Definitions::BlurrData); + Blur::Data.Init(desc); + desc.ElementSize = sizeof(Definitions::Pointlight); desc.NumElements = MaxLightSize; desc.Type = Buffer::STRUCTURED_BUFFER; @@ -235,6 +240,9 @@ namespace Oyster Core::Init::CreateLinkedShaderResourceFromTexture(NULL,&LBufferSRV[i],&LBufferUAV[i]); } + //Blur + Core::Init::CreateLinkedShaderResourceFromTexture(NULL,&Blur::BufferSRV,&Blur::BufferUAV); + Buffer* b = &Light::PointLightsData; Core::Init::CreateLinkedShaderResourceFromStructuredBuffer(&b,&Light::PointLightView,NULL); @@ -377,6 +385,8 @@ namespace Oyster } Post::Pass.UAV.Compute.push_back(Core::backBufferUAV); Post::Pass.CBuffers.Compute.push_back(Post::Data); + Post::Pass.RenderStates.SampleCount = 1; + Post::Pass.RenderStates.SampleState = RenderStates::ss; ////---------------- GUI Pass Setup ---------------------------- Gui::Pass.Shaders.Vertex = GetShader::Vertex(L"2D"); @@ -412,6 +422,9 @@ namespace Oyster //And the Ambient UAV is now the output texture Blur::VertPass.UAV.Compute.push_back(LBufferUAV[2]); + Blur::HorPass.CBuffers.Compute.push_back(Blur::Data); + Blur::VertPass.CBuffers.Compute.push_back(Blur::Data); + ////---------------- 2DText Pass Setup ---------------------------- Gui::Text::Pass.Shaders.Vertex = GetShader::Vertex(L"2DText"); Gui::Text::Pass.Shaders.Geometry = GetShader::Geometry(L"2DText"); @@ -459,6 +472,7 @@ namespace Oyster Color.~Buffer(); Gui::Text::Vertex.~Buffer(); Post::Data.~Buffer(); + Blur::Data.~Buffer(); SAFE_RELEASE(Light::PointLightView); SAFE_RELEASE(Light::SSAOKernel); SAFE_RELEASE(Light::SSAORandom); diff --git a/Code/OysterGraphics/Render/Resources.h b/Code/OysterGraphics/Render/Resources.h index 684762fd..6b4e140e 100644 --- a/Code/OysterGraphics/Render/Resources.h +++ b/Code/OysterGraphics/Render/Resources.h @@ -81,6 +81,8 @@ namespace Oyster //Blur UAV and SRV static ID3D11UnorderedAccessView* BufferUAV; static ID3D11ShaderResourceView* BufferSRV; + + static Core::Buffer Data; }; struct Post diff --git a/Code/OysterGraphics/Shader/Passes/Blur/BlurHor.hlsl b/Code/OysterGraphics/Shader/Passes/Blur/BlurHor.hlsl index 7489cd41..1383514a 100644 --- a/Code/OysterGraphics/Shader/Passes/Blur/BlurHor.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Blur/BlurHor.hlsl @@ -7,14 +7,14 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID if(gThreadID.x < blurRadius) { int x = max(ThreadID.x-blurRadius,0); - gCache[gThreadID.x] = inTex[int2(x,ThreadID.y)]; + gCache[gThreadID.x] = inTex[min(int2(x,ThreadID.y) + Start, Stop-1)]; } if(gThreadID.x >= N-blurRadius) { - int x = min(ThreadID.x+blurRadius,inTex.Length.x-1); - gCache[gThreadID.x+2*blurRadius] = inTex[int2(x,ThreadID.y)]; + int x = min(ThreadID.x+blurRadius,Stop.x-1); + gCache[gThreadID.x+2*blurRadius] = inTex[int2(x,ThreadID.y) + Start]; } - gCache[gThreadID.x+blurRadius] = inTex[min(ThreadID.xy,inTex.Length.xy-1)]; + gCache[gThreadID.x+blurRadius] = inTex[min(ThreadID.xy + Start, Stop-1)]; GroupMemoryBarrierWithGroupSync(); @@ -27,7 +27,6 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID blurCol +=Weights[i + blurRadius] * gCache[k]; } - outTex[ThreadID.xy] = blurCol; - //Output[ThreadID.xy] = Diffuse[((ThreadID.xy))]; + outTex[ThreadID.xy + Start] = blurCol * BlurMask + inTex[ThreadID.xy + Start] * ( float4(1,1,1,1) - BlurMask); } diff --git a/Code/OysterGraphics/Shader/Passes/Blur/BlurSharedData.hlsli b/Code/OysterGraphics/Shader/Passes/Blur/BlurSharedData.hlsli index 8a7b5fd1..a9377560 100644 --- a/Code/OysterGraphics/Shader/Passes/Blur/BlurSharedData.hlsli +++ b/Code/OysterGraphics/Shader/Passes/Blur/BlurSharedData.hlsli @@ -3,12 +3,26 @@ -static const float Weights[9] = +cbuffer BlurrData : register(b1) { - 0.05f, 0.05f, 0.1f, 0.15f, 0.3f, 0.15f, 0.1f, 0.05f, 0.05f + //static const int blurRadius = 0; + //static const float Weights[1] = + //{ + // 1.0f + //}; + /*static const int blurRadius = 4; + static const float Weights[9] = + { + 0.05f, 0.05f, 0.1f, 0.15f, 0.3f, 0.15f, 0.1f, 0.05f, 0.05f + };*/ + static const int blurRadius = 5; + static const float Weights[11] = + { + 0.05f,0.05f,0.1f,0.1f,0.1f,0.2f,0.1f,0.1f,0.1f,0.05f,0.05f + }; }; -static const int blurRadius = 4; + #define N 128 #define gSize (N+2*blurRadius) @@ -17,14 +31,13 @@ groupshared float4 gCache[gSize]; Texture2D inTex : register(t0); RWTexture2D outTex : register(u0); -//cbuffer BlurrData : register(c0) -//{ -// static const int blurRadius = 5; -// static const float Weights[11] = -// { -// 0.05f,0.05f,0.1f,0.1f,0.1f,0.2f,0.1f,0.1f,0.1f,0.05f,0.05f -// }; -//}; +cbuffer BlurrData : register(b0) +{ + uint2 Start; + uint2 Stop; + float4 BlurMask; +}; + //[numthreads(16,16,1)] //void TryCompute(uint3 ThreadID : SV_DispatchThreadID) diff --git a/Code/OysterGraphics/Shader/Passes/Blur/BlurVert.hlsl b/Code/OysterGraphics/Shader/Passes/Blur/BlurVert.hlsl index aa5e4a27..3d6afae9 100644 --- a/Code/OysterGraphics/Shader/Passes/Blur/BlurVert.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Blur/BlurVert.hlsl @@ -7,14 +7,14 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID if(gThreadID.y < blurRadius) { int y = max(ThreadID.y-blurRadius,0); - gCache[gThreadID.y] = inTex[int2(ThreadID.x,y)]; + gCache[gThreadID.y] = inTex[min(int2(ThreadID.x,y) + Start, Stop-1)]; } if(gThreadID.y >= N-blurRadius) { - int y = min(ThreadID.y+blurRadius,inTex.Length.y-1); - gCache[gThreadID.y+2*blurRadius] = inTex[int2(ThreadID.x,y)]; + int y = min(ThreadID.y+blurRadius, Stop.y-1); + gCache[gThreadID.y+2*blurRadius] = inTex[int2(ThreadID.x,y) + Start]; } - gCache[gThreadID.y+blurRadius] = inTex[min(ThreadID.xy,inTex.Length.xy-1)]; + gCache[gThreadID.y+blurRadius] = inTex[min(ThreadID.xy + Start, Stop.xy-1)]; GroupMemoryBarrierWithGroupSync(); @@ -27,6 +27,6 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID blurCol +=Weights[i + blurRadius] * gCache[k]; } - outTex[ThreadID.xy] = blurCol; - //Output[ThreadID.xy] = inTex[((ThreadID.xy))]; + outTex[ThreadID.xy + Start] = blurCol + inTex[ThreadID.xy + Start] * ( float4(1,1,1,1) - BlurMask);; + //outTex[ThreadID.xy] = inTex[ThreadID.xy]; } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl index 542d8c54..2a6f3972 100644 --- a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl @@ -45,6 +45,7 @@ PixelOut main(VertexOut input) normal = perturb_normal( normal, normalize(-input.ViewPos), input.UV ); - output.NormalSpec = float4(normal, Normal.Sample(S1, input.UV).w*255); + //output.NormalSpec = float4(normal, Normal.Sample(S1, input.UV).w*255); + output.NormalSpec = float4(normal, Normal.Sample(S1, input.UV).w*0); return output; } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl b/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl index dc54187e..8e303455 100644 --- a/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl @@ -36,7 +36,7 @@ void main( uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID ) float AmbValue = GetSSAO(ViewPos, UV, DTid.xy, GTid.xy/2); Ambient[DTid.xy/2] = float4(DiffuseGlow[DTid.xy].xyz, AmbValue); Ambient[DTid.xy/2 + float2(Pixels.x/2, 0)] = GUI[DTid.xy]; - //Ambient[DTid.xy] = GUI[DTid.xy]; + Ambient[DTid.xy/2 + float2(0, Pixels.y/2)] = float4(DiffuseGlow[DTid.xy].xyz * DiffuseGlow[DTid.xy].w*10,1); } } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl index 53cfabb2..85c74fb7 100644 --- a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl @@ -4,23 +4,49 @@ Texture2D Ambient : register(t2); RWTexture2D Output; +SamplerState S1 : register(s0); + cbuffer Size : register(b0) { int2 Pixels; } -#define AmbFactor 0.3f; +#define AmbFactor 0.1f; + +float4 SuperSample(float4 Glow, uint3 DTid) +{ + // Line X + float2 index = (float2)(DTid.xy/2); + index += float2(0,Output.Length.y/2); + index = index / Output.Length; + Glow = Ambient.SampleLevel(S1, index,1); + //Line Y+1 + //Glow += Ambient[DTid.xy/2 + uint2(1,(Output.Length.y/2)+1)] + Ambient[DTid.xy/2 + uint2(0,(Output.Length.y/2)+1)] + Ambient[DTid.xy/2 + uint2(-1,(Output.Length.y/2)+1)]; + //Line Y-1 + //Glow += Ambient[DTid.xy/2 + uint2(1,(Output.Length.y/2)-1)] + Ambient[DTid.xy/2 + uint2(0,(Output.Length.y/2)-1)] + Ambient[DTid.xy/2 + uint2(-1,(Output.Length.y/2)-1)]; + + //Glow = Glow/9; + + return Glow; +} [numthreads(16, 16, 1)] void main( uint3 DTid : SV_DispatchThreadID ) { float4 Light = Diffuse[DTid.xy] + saturate(Specular[DTid.xy]); float4 Amb = float4(Ambient[DTid.xy/2].xyz * Ambient[DTid.xy/2].w, 0); + //float4 Glow = Ambient[DTid.xy/2 + uint2(0,Output.Length.y/2)]; + float4 Glow = Ambient[DTid.xy/2 + uint2(0,Output.Length.y/2)]; + + Glow = SuperSample(Glow,DTid); + float4 GUI; uint2 index = DTid.xy/2 + uint2((uint)Pixels.x/(uint)2,0); float3 PostLight = Amb.xyz * AmbFactor; - PostLight = PostLight + Light.xyz; + PostLight = PostLight + Light.xyz + Glow; GUI = float4(Ambient[index]); PostLight = PostLight * (1 - GUI.w); Output[DTid.xy] = float4((GUI.xyz * GUI.w) + PostLight, 1); + + //Output[DTid.xy] = Glow; } \ No newline at end of file diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index 2915d62e..f0d440d6 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -171,11 +171,11 @@ HRESULT InitDirect3D() } m = Oyster::Graphics::API::CreateModel(L"crate_colonists.dan"); - m->WorldMatrix.m[0][0] = 50; - m->WorldMatrix.m[1][1] = 50; - m->WorldMatrix.m[2][2] = 0.00000005f; + //m->WorldMatrix.m[0][0] = 50; + //m->WorldMatrix.m[1][1] = 50; + //m->WorldMatrix.m[2][2] = 0.00000005f; m2 = Oyster::Graphics::API::CreateModel(L"char_temporary.dan"); - m2->Tint = Oyster::Math::Float3(0.8f,0.8f,1); + m2->Tint = Oyster::Math::Float3(0.1f,0.1f,1); m3 = Oyster::Graphics::API::CreateModel(L"char_temporary.dan"); m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(4,0,0),Oyster::Math::Float3::null); Oyster::Graphics::API::PlayAnimation(m2, L"movement", true); @@ -193,21 +193,21 @@ HRESULT InitDirect3D() pl.Color = Oyster::Math::Float3(1,1,1); - pl.Bright = 1; + pl.Bright = 0.5f; pl.Pos = Oyster::Math::Float3(-20,0,0); pl.Radius = 90; Oyster::Graphics::API::AddLight(pl); pl.Color = Oyster::Math::Float3(1,1,1); - pl.Bright = 1; + pl.Bright = 0.5f; pl.Pos = Oyster::Math::Float3(0,20,0); pl.Radius = 90; Oyster::Graphics::API::AddLight(pl); pl.Color = Oyster::Math::Float3(1,1,1); - pl.Bright = 1; + pl.Bright = 0.5f; pl.Pos = Oyster::Math::Float3(0,0,20); pl.Radius = 90; @@ -220,6 +220,7 @@ float angle = 0; HRESULT Update(float deltaTime) { //angle += Oyster::Math::pi/16 * deltaTime; + m->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0) * angle,Oyster::Math::Float3(0,0,0),Oyster::Math::Float3::null); m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0) * angle,Oyster::Math::Float3(4,0,0),Oyster::Math::Float3::null); m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0) * -angle,Oyster::Math::Float3(-4,0,0),Oyster::Math::Float3::null); //Oyster::Math::Matrix ma = Oyster::Math::Matrix::identity; @@ -233,10 +234,10 @@ HRESULT Render(float deltaTime) Oyster::Graphics::API::SetView(V); Oyster::Graphics::API::NewFrame(); - //Oyster::Graphics::API::RenderModel(m); + Oyster::Graphics::API::RenderModel(m); Oyster::Graphics::API::RenderModel(m2); Oyster::Graphics::API::RenderModel(m3); - //Oyster::Graphics::API::StartGuiRender(); + Oyster::Graphics::API::StartGuiRender(); //Oyster::Graphics::API::RenderGuiElement(t,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1), Oyster::Math::Float3(0,0,1)); //Oyster::Graphics::API::RenderGuiElement(t2,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1),Oyster::Math::Float3(1,0,0)); Oyster::Graphics::API::StartTextRender(); From e71264b8062fd46dbc52d6ecd9a5252d1e6cb3b9 Mon Sep 17 00:00:00 2001 From: lanariel Date: Thu, 13 Feb 2014 16:27:53 +0100 Subject: [PATCH 11/22] New text render --- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 6 ++-- Code/OysterGraphics/DllInterfaces/GFXAPI.h | 4 +-- Code/OysterGraphics/Render/GuiRenderer.cpp | 31 ++++++++++++-------- Code/OysterGraphics/Render/GuiRenderer.h | 4 +-- Code/Tester/MainTest.cpp | 2 +- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index 8cb80fe2..381b12cf 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -159,7 +159,7 @@ namespace Oyster Render::Gui::Begin2DRender(); } - void API::RenderGuiElement(API::Texture tex, Math::Float2 pos, Math::Float2 size, Math::Float3 color) + void API::RenderGuiElement(API::Texture tex, Math::Float3 pos, Math::Float2 size, Math::Float3 color) { Render::Gui::Render((ID3D11ShaderResourceView*)tex,pos,size,color); } @@ -192,9 +192,9 @@ namespace Oyster Render::Gui::Begin2DTextRender(); } - void API::RenderText(std::wstring text, Math::Float2 Pos, Math::Float2 Size, Math::Float3 color) + void API::RenderText(std::wstring text, Math::Float3 Pos, Math::Float2 Size, float FontSize, Math::Float3 color) { - Render::Gui::RenderText(text,Pos,Size,color); + Render::Gui::RenderText(text, Pos, Size, FontSize, color); } } } \ No newline at end of file diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.h b/Code/OysterGraphics/DllInterfaces/GFXAPI.h index bdf70072..e2cea318 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.h +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.h @@ -57,13 +57,13 @@ namespace Oyster static void StartGuiRender(); //! @brief Renders a single GUI element using the texture provided and the Pos in the center, %based system - static void RenderGuiElement(Texture, Math::Float2 Pos, Math::Float2 Size, Math::Float3 Color = Math::Float3(1,1,1)); + static void RenderGuiElement(Texture, Math::Float3 Pos, Math::Float2 Size, Math::Float3 Color = Math::Float3(1,1,1)); //! @brief Configures Renderer to process 2D Text, data will be passed in to EndFrame() static void StartTextRender(); //! @brief Renders a single GUI string using the texture provided and the Pos in the center, %based system - static void RenderText(std::wstring, Math::Float2 Pos, Math::Float2 Size, Math::Float3 Color = Math::Float3(1,1,1)); + static void RenderText(std::wstring, Math::Float3 Pos, Math::Float2 Size, float FontSize, Math::Float3 Color = Math::Float3(1,1,1)); //! @brief Performs light calculations, post effects and presents the scene static void EndFrame(); diff --git a/Code/OysterGraphics/Render/GuiRenderer.cpp b/Code/OysterGraphics/Render/GuiRenderer.cpp index 7f3285e1..78b2f771 100644 --- a/Code/OysterGraphics/Render/GuiRenderer.cpp +++ b/Code/OysterGraphics/Render/GuiRenderer.cpp @@ -16,7 +16,7 @@ namespace Oyster Core::PipelineManager::SetRenderPass(Render::Resources::Gui::Pass); } - void Gui::Render(ID3D11ShaderResourceView* tex,Math::Float2 pos, Math::Float2 size, Math::Float3 color) + void Gui::Render(ID3D11ShaderResourceView* tex,Math::Float3 pos, Math::Float2 size, Math::Float3 color) { Core::deviceContext->PSSetShaderResources(0,1,&tex); @@ -28,6 +28,7 @@ namespace Oyster gd.Translation = Math::Matrix::identity; gd.Translation.m41 = pos.x; gd.Translation.m42 = pos.y; + gd.Translation.m43 = pos.z; gd.Translation.m11 = size.x; gd.Translation.m22 = size.y; @@ -49,10 +50,10 @@ namespace Oyster Core::PipelineManager::SetRenderPass(Resources::Gui::Text::Pass); } - void Gui::RenderText(std::wstring text, Math::Float2 pos, Math::Float2 size, Math::Float3 color) + void Gui::RenderText(std::wstring text, Math::Float3 pos, Math::Float2 size, float FontSize, Math::Float3 color) { - size.x = size.x / (text.length() * TEXT_SPACING /2); + //size.x = size.x / (text.length() * TEXT_SPACING /2); pos *= 2; @@ -60,15 +61,18 @@ namespace Oyster pos.y *= -1; - pos.x = pos.x - (size.x * (text.length()-1) * TEXT_SPACING /2); + //pos.x = pos.x - (size.x * (text.length()-1) * TEXT_SPACING /2); + pos.x = pos.x + size.x/ (text.length() * TEXT_SPACING/2); + pos.y = pos.y - size.y/2; Definitions::GuiData gd; gd.Translation = Math::Matrix::identity; gd.Translation.m41 = pos.x; gd.Translation.m42 = pos.y; - gd.Translation.m11 = size.x; - gd.Translation.m22 = size.y; + gd.Translation.m43 = pos.z; + gd.Translation.m11 = FontSize * 0.8f; + gd.Translation.m22 = FontSize; void* data = Render::Resources::Gui::Data.Map(); @@ -82,19 +86,20 @@ namespace Oyster void* dest = Resources::Gui::Text::Vertex.Map(); Definitions::Text2D* dataView = reinterpret_cast(dest); - //tmpInst.charOffset=_pos; + for (unsigned int i=0; i size.x) + { + text = text.substr(0,i-1); + break; + } dataView[i]=tmpInst; } - //TextInstances[_id].NumLetters=instances; + Resources::Gui::Text::Vertex.Unmap(); diff --git a/Code/OysterGraphics/Render/GuiRenderer.h b/Code/OysterGraphics/Render/GuiRenderer.h index f5513d2f..3e4a8de0 100644 --- a/Code/OysterGraphics/Render/GuiRenderer.h +++ b/Code/OysterGraphics/Render/GuiRenderer.h @@ -12,9 +12,9 @@ namespace Oyster { public: static void Begin2DRender(); - static void Render(ID3D11ShaderResourceView* tex, Math::Float2 pos, Math::Float2 size, Math::Float3 tint = Math::Float3(1,1,1)); + static void Render(ID3D11ShaderResourceView* tex, Math::Float3 pos, Math::Float2 size, Math::Float3 tint = Math::Float3(1,1,1)); static void Begin2DTextRender(); - static void RenderText(std::wstring text, Math::Float2 pos, Math::Float2 size, Math::Float3 tint = Math::Float3(1,1,1)); + static void RenderText(std::wstring text, Math::Float3 pos, Math::Float2 size, float FontSize, Math::Float3 tint = Math::Float3(1,1,1)); }; } } diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index f0d440d6..ad71dabb 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -246,7 +246,7 @@ HRESULT Render(float deltaTime) fps = std::to_wstring(f); //Oyster::Graphics::API::RenderText(L"Lanariel",Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f)); //Oyster::Graphics::API::RenderText(L"Lanariel WAS HERE",Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f)); - Oyster::Graphics::API::RenderText(fps,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float3(0,1,0)); + Oyster::Graphics::API::RenderText(fps,Oyster::Math::Float3(0.5f,0.1f,1.0f),Oyster::Math::Float2(0.5f,0.1f), 0.08f, Oyster::Math::Float3(0,1,0)); Oyster::Graphics::API::EndFrame(); return S_OK; From 2dee9dd084230a523ecba8aaea4fc9fa296e41d0 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Thu, 13 Feb 2014 16:33:26 +0100 Subject: [PATCH 12/22] GL - initiating ccc map from folder ../Content/Worlds. Sync with graphics content. --- .../DanBiasGame/GameClientState/GameState.cpp | 20 +- .../LevelLoader/ParseFunctions.cpp | 2 +- Code/Game/GameLogic/CollisionManager.cpp | 1 + Code/Game/GameLogic/Game.cpp | 2 +- Code/Game/GameLogic/Game_PlayerData.cpp | 4 +- Code/Game/GameLogic/Level.cpp | 302 +++++++++++------- Code/Game/GameLogic/Level.h | 5 +- .../GameLogic/LevelLoader/ParseFunctions.cpp | 2 +- Code/Game/GameLogic/Portal.cpp | 2 +- Code/Game/GameLogic/Portal.h | 2 +- 10 files changed, 212 insertions(+), 130 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 17ac3677..0a732062 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -77,10 +77,10 @@ GameState::gameStateState GameState::LoadGame() //Oyster::Graphics::API::AddLight(plight); // use level loader - //LoadModels("3bana.bias"); + LoadModels("../Content/Worlds/ccc.bias"); // hardcoded objects - LoadModels("C:/Users/Sam/Documents/GitHub/Danbias/Bin/Content/worlds/ccc.bias"); + //LoadModels(); Float3 startPos = Float3(0,0,20.0f); InitCamera(startPos); return gameStateState_playing; @@ -185,7 +185,7 @@ bool GameState::LoadModels(std::string mapFile) objects = levelLoader.LoadLevel(mapFile); int objCount = objects.size(); - int modelId = 0; + int modelId = 100; ModelInitData modelData; for (int i = 0; i < objCount; i++) { @@ -244,19 +244,19 @@ bool GameState::LoadModels(std::string mapFile) break; } } - myId += modelId++; + //myId += modelId++; // add player model //modelData.position = ; //modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(2,2,-2), 1); //modelData.scale = Oyster::Math::Float3(2,2,2); - modelData.visible = true; - modelData.modelPath = L"char_still_sizeref.dan"; - modelData.id = myId; - // load models - this->dynamicObjects.Push(new C_DynamicObj()); - this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData); + //modelData.visible = true; + //modelData.modelPath = L"char_still_sizeref.dan"; + //modelData.id = myId; + //// load models + //this->dynamicObjects.Push(new C_DynamicObj()); + //this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData); /*C_Player* obj = new C_Player(); privData->object.push_back(obj); diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.cpp b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.cpp index 7f5550d7..59f967de 100644 --- a/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.cpp @@ -147,7 +147,7 @@ namespace GameLogic //Läs in filen. int fileLength = 0; Loader loader; - char* buf = loader.LoadFile("C:/Users/Sam/Documents/GitHub/Danbias/Bin/Content/worlds/cgf/"+ fileName, fileLength); + char* buf = loader.LoadFile("../Content/Worlds/cgf/"+ fileName, fileLength); start = 0; LevelLoaderInternal::FormatVersion version; diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 857c135c..c3b70cce 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -37,6 +37,7 @@ using namespace GameLogic; PlayerVObject(*player,*realObj, kineticEnergyLoss); //player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; break; + } //return Physics::ICustomBody::SubscriptMessage_none; diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 8be3f7a8..5bf18dc4 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -82,7 +82,7 @@ Game::LevelData* Game::CreateLevel() this->level = new LevelData(); //this->level->level->InitiateLevel(1000); - this->level->level->InitiateLevel("C:/Users/Sam/Documents/GitHub/Danbias/Bin/Content/worlds/ccc.bias"); + this->level->level->InitiateLevel("../Content/Worlds/ccc.bias"); return this->level; } diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index efeab2ee..acdcd2f3 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -7,9 +7,9 @@ Game::PlayerData::PlayerData() { //set some stats that are appropriate to a player - Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(0,400,0); + Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(50,130,0); - Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,1.0f,0.5f); + Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,2.0f,0.5f); Oyster::Math::Float mass = 60; Oyster::Math::Float restitutionCoeff = 0.5; Oyster::Math::Float frictionCoeff_Static = 0.4; diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 3cdab709..9a91744e 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -16,48 +16,190 @@ Level::~Level(void) delete this->levelObj; this->levelObj = NULL; } -void Level::parseObjectType(ObjectTypeHeader* obj) +Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) { - /*switch (obj->objectTypeID) + Object* gameObj =NULL; + switch ((ObjectSpecialType)obj->specialTypeID) { - case skySphere: - // save the skysphere to be able to rotate it + case ObjectSpecialType_None: + { + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + } break; - case jumppad: - // save direction - break; - case portal: - // save portal destination - break; - case world: - // add gravitation well here - // add outer limit of the world - case spawn: - // save spawnpoint pos + case ObjectSpecialType_Sky: + { + float skySize = ((SkyAttributes*)obj)->skySize; + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + } break; + case ObjectSpecialType_World: + { + API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0)); + API::Instance().SetGravity(200); // could balance gravitation with the world size - default: + float worldSize = ((WorldAttributes*)obj)->worldSize; + float atmosphereSize = ((WorldAttributes*)obj)->atmoSphereSize; + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + } break; - }*/ + case ObjectSpecialType_Building: + { + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + } + case ObjectSpecialType_Stone: + { + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + } + break; + case ObjectSpecialType_StandarsBox: + { + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + } + break; + case ObjectSpecialType_RedExplosiveBox: + { + int dmg = 50; + //gameObj = new ExplosiveBox(rigidBody, ObjectSpecialType_RedExplosiveBox); + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + } + break; + //case ObjectSpecialType_BlueExplosiveBox: + // int dmg = 70; + // gameObj = new ExplosiveBox(rigidBody, ObjectSpecialType_BlueExplosiveBox); + // break; + case ObjectSpecialType_SpikeBox: + { + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + } + break; + case ObjectSpecialType_Spike: + { + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + } + break; + case ObjectSpecialType_CrystalFormation: + { + int dmg = 50; + //gameObj = new Crystal(rigidBody); + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + } + break; + case ObjectSpecialType_CrystalShard: + { + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + } + break; + case ObjectSpecialType_JumpPad: + { + float power = ((JumpPadAttributes*)obj)->power; + Oyster::Math::Float3 dir = ((JumpPadAttributes*)obj)->direction; + //gameObj = JumpPad(rigidBody, ); + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + } + break; + case ObjectSpecialType_Portal: + { + Oyster::Math::Float3 destination = ((PortalAttributes*)obj)->destination; + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + } + break; + case ObjectSpecialType_SpawnPoint: + { + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + } + break; + case ObjectSpecialType_Player: + { + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + } + break; + case ObjectSpecialType_Generic: + { + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + } + break; + default: + { + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + } + break; + } + return gameObj; } -void Level::parsePhysicsObj(LevelLoaderInternal::BoundingVolumeBase* obj) + +ICustomBody* Level::InitRigidBodyCube( const ObjectHeader* obj) { - // offset physObj med modelObj + ICustomBody* rigidBody = NULL; + Oyster::Math::Float3 rigidWorldPos; + Oyster::Math::Float4 rigidWorldRotation; + float rigidBodyMass; + Oyster::Math::Float3 rigidBodySize; + + //offset the rigidPosition from modelspace to worldspace; + rigidWorldPos = (Oyster::Math::Float3)obj->position + (Oyster::Math::Float3)obj->boundingVolume.box.position; + //scales the position so the collision geomentry is in the right place + rigidWorldPos = rigidWorldPos * obj->scale; + + //offset the rigidRotation from modelspace to worldspace; + Oyster::Math::Quaternion worldPosQuaternion = Oyster::Math::Quaternion(Oyster::Math::Float3(obj->rotation[0],obj->rotation[1],obj->rotation[2]), obj->rotation[3]); + Oyster::Math::Quaternion physicsPosQuaternion = Oyster::Math::Quaternion(Oyster::Math::Float3(obj->boundingVolume.sphere.rotation[0],obj->boundingVolume.sphere.rotation[1],obj->boundingVolume.sphere.rotation[2]), obj->boundingVolume.sphere.rotation[3]); + Oyster::Math::Quaternion rigidWorldQuaternion = worldPosQuaternion * physicsPosQuaternion; + + rigidWorldRotation = Oyster::Math::Float4(rigidWorldQuaternion); + + //mass scaled + rigidBodyMass = obj->scale[0] * obj->scale[1] * obj->scale[2] * obj->boundingVolume.box.mass; + + //size scaled + rigidBodySize = (Oyster::Math::Float3)obj->boundingVolume.box.size * (Oyster::Math::Float3)obj->scale; + + //create the rigid body + rigidBody = API::Instance().AddCollisionBox(rigidBodySize , rigidWorldRotation , rigidWorldPos , rigidBodyMass, obj->boundingVolume.box.restitutionCoeff , obj->boundingVolume.box.frictionCoeffStatic , obj->boundingVolume.box.frictionCoeffDynamic); + return rigidBody; +} +ICustomBody* Level::InitRigidBodySphere( const ObjectHeader* obj) +{ + ICustomBody* rigidBody = NULL; + Oyster::Math::Float3 rigidWorldPos; + Oyster::Math::Float4 rigidWorldRotation; + float rigidBodyMass; + float rigidBodyRadius; + + //offset the rigidPosition from modelspace to worldspace; + rigidWorldPos = (Oyster::Math::Float3)obj->position + (Oyster::Math::Float3)obj->boundingVolume.sphere.position; + //scales the position so the collision geomentry is in the right place + rigidWorldPos = rigidWorldPos * obj->scale; + + //offset the rigidRotation from modelspace to worldspace; + Oyster::Math::Quaternion worldPosQuaternion = Oyster::Math::Quaternion(Oyster::Math::Float3(obj->rotation[0],obj->rotation[1],obj->rotation[2]), obj->rotation[3]); + Oyster::Math::Quaternion physicsPosQuaternion = Oyster::Math::Quaternion(Oyster::Math::Float3(obj->boundingVolume.sphere.rotation[0],obj->boundingVolume.sphere.rotation[1],obj->boundingVolume.sphere.rotation[2]), obj->boundingVolume.sphere.rotation[3]); + Oyster::Math::Quaternion rigidWorldQuaternion = worldPosQuaternion * physicsPosQuaternion; + + rigidWorldRotation = Oyster::Math::Float4(rigidWorldQuaternion); + + + //mass scaled + rigidBodyMass = obj->scale[0] * obj->scale[1] * obj->scale[2] * obj->boundingVolume.sphere.mass; + + //Radius scaled + //rigidBodyRadius = (staticObjData->scale[0] * staticObjData->scale[1] * staticObjData->scale[2] / 3) * staticObjData->boundingVolume.sphere.radius; + rigidBodyRadius = (obj->scale[0] * obj->scale[1] * obj->scale[2]) * obj->boundingVolume.sphere.radius; + + //create the rigid body + rigidBody = API::Instance().AddCollisionSphere( rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, obj->boundingVolume.sphere.restitutionCoeff , obj->boundingVolume.sphere.frictionCoeffStatic , obj->boundingVolume.sphere.frictionCoeffDynamic); + return rigidBody; } void Level::InitiateLevel(std::string levelPath) { LevelLoader ll; std::vector> objects; objects = ll.LoadLevel(levelPath); + + API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0)); + API::Instance().SetGravity(200); int objCount = objects.size(); - int modelCount = 0; - int staticObjCount = 0; - int dynamicObjCount = 0; - Oyster::Math::Float3 rigidWorldPos; - Oyster::Math::Float4 rigidWorldRotation; - float rigidBodyMass; - float rigidBodyRadius; - Oyster::Math::Float3 rigidBodySize; + int modelCount = 100; + for (int i = 0; i < objCount; i++) { ObjectTypeHeader* obj = objects.at(i); @@ -75,69 +217,37 @@ void Level::InitiateLevel(std::string levelPath) { ObjectHeader* staticObjData = ((ObjectHeader*)obj); - //LevelLoaderInternal::BoundingVolumeBase* staticObjPhysicData = ((ObjectHeader*)obj); staticObjData->ModelFile; ICustomBody* rigidBody_Static = NULL; - // collision shape - // radius, rotation in world, position in world, mass, restitution, static and dynamic friction if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Sphere) { - //offset the rigidPosition from modelspace to worldspace; - rigidWorldPos = (Oyster::Math::Float3)staticObjData->position + (Oyster::Math::Float3)staticObjData->boundingVolume.sphere.position; - //scales the position so the collision geomentry is in the right place - rigidWorldPos = rigidWorldPos * staticObjData->scale; - - //offset the rigidRotation from modelspace to worldspace; - rigidWorldRotation = (Oyster::Math::Float4)staticObjData->rotation + (Oyster::Math::Float4)staticObjData->boundingVolume.sphere.rotation; - - //mass scaled - rigidBodyMass = staticObjData->scale[0] * staticObjData->scale[1] * staticObjData->scale[2] * staticObjData->boundingVolume.sphere.mass; - - //Radius scaled - rigidBodyRadius = (staticObjData->scale[0] * staticObjData->scale[1] * staticObjData->scale[2] / 3) * staticObjData->boundingVolume.sphere.radius; - - //create the rigid body - rigidBody_Static = API::Instance().AddCollisionSphere( rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, staticObjData->boundingVolume.sphere.restitutionCoeff , staticObjData->boundingVolume.sphere.frictionCoeffStatic , staticObjData->boundingVolume.sphere.frictionCoeffDynamic); + rigidBody_Static = InitRigidBodySphere(staticObjData); } else if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Box) { - //offset the rigidPosition from modelspace to worldspace; - rigidWorldPos = (Oyster::Math::Float3)staticObjData->position + (Oyster::Math::Float3)staticObjData->boundingVolume.box.position; - //scales the position so the collision geomentry is in the right place - rigidWorldPos = rigidWorldPos * staticObjData->scale; - //offset the rigidRotation from modelspace to worldspace; - rigidWorldRotation = (Oyster::Math::Float4)staticObjData->rotation + (Oyster::Math::Float4)staticObjData->boundingVolume.box.rotation; - - //mass scaled - rigidBodyMass = staticObjData->scale[0] * staticObjData->scale[1] * staticObjData->scale[2] * staticObjData->boundingVolume.box.mass; - - //size scaled - rigidBodySize = (Oyster::Math::Float3)staticObjData->boundingVolume.box.size * (Oyster::Math::Float3)staticObjData->scale; - - //create the rigid body - rigidBody_Static = API::Instance().AddCollisionBox(rigidBodySize , rigidWorldRotation , rigidWorldPos , rigidBodyMass, staticObjData->boundingVolume.box.restitutionCoeff , staticObjData->boundingVolume.box.frictionCoeffStatic , staticObjData->boundingVolume.box.frictionCoeffDynamic); + rigidBody_Static = InitRigidBodySphere(staticObjData); } else if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Cylinder) { - + //rigidBody_Static = InitRigidBodyCylinder(staticObjData); } - - // add rigidbody to the logical obj - // Object::DefaultCollisionBefore, Object::DefaultCollisionAfter for now, gamelogic will take care of this - // set object_type to objID - if(rigidBody_Static != NULL) { - this->staticObjects.Push(new StaticObject(rigidBody_Static, Object::DefaultCollisionAfter, (ObjectSpecialType)staticObjData->specialTypeID)); - this->staticObjects[staticObjCount]->objectID = modelCount++; - rigidBody_Static->SetCustomTag(this->staticObjects[staticObjCount]); + // create game object + Object* staticGameObj = createGameObj(staticObjData, rigidBody_Static); + if(staticGameObj != NULL) + { + this->staticObjects.Push((StaticObject*)staticGameObj); + this->staticObjects[this->staticObjects.Size()-1]->objectID = modelCount++; + rigidBody_Static->SetCustomTag(this->staticObjects[this->staticObjects.Size()-1]); + } } } @@ -150,61 +260,31 @@ void Level::InitiateLevel(std::string levelPath) ICustomBody* rigidBody_Dynamic = NULL; // collision shape - // radius, rotation in world, position in world, mass, restitution, static and dynamic friction if(dynamicObjData->boundingVolume.geoType == CollisionGeometryType_Sphere) { - //offset the rigidPosition from modelspace to worldspace; - rigidWorldPos = (Oyster::Math::Float3)dynamicObjData->position + (Oyster::Math::Float3)dynamicObjData->boundingVolume.sphere.position; - //scales the position so the collision geomentry is in the right place - rigidWorldPos = rigidWorldPos * dynamicObjData->scale; - - //offset the rigidRotation from modelspace to worldspace; - rigidWorldRotation = (Oyster::Math::Float4)dynamicObjData->rotation + (Oyster::Math::Float4)dynamicObjData->boundingVolume.sphere.rotation; - - //mass scaled - rigidBodyMass = dynamicObjData->scale[0] * dynamicObjData->scale[1] * dynamicObjData->scale[2] * dynamicObjData->boundingVolume.sphere.mass; - - //size scaled - rigidBodyRadius = (dynamicObjData->scale[0] * dynamicObjData->scale[1] * dynamicObjData->scale[2] / 3) * dynamicObjData->boundingVolume.sphere.radius; - - //create the rigid body - rigidBody_Dynamic = API::Instance().AddCollisionBox(rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, dynamicObjData->boundingVolume.sphere.restitutionCoeff , dynamicObjData->boundingVolume.sphere.frictionCoeffStatic , dynamicObjData->boundingVolume.sphere.frictionCoeffDynamic); + rigidBody_Dynamic = InitRigidBodySphere(dynamicObjData); } else if(dynamicObjData->boundingVolume.geoType == CollisionGeometryType_Box) { - //offset the rigidPosition from modelspace to worldspace; - rigidWorldPos = (Oyster::Math::Float3)dynamicObjData->position + (Oyster::Math::Float3)dynamicObjData->boundingVolume.box.position; - //scales the position so the collision geomentry is in the right place - rigidWorldPos = rigidWorldPos * dynamicObjData->scale; - - //offset the rigidRotation from modelspace to worldspace; - rigidWorldRotation = (Oyster::Math::Float4)dynamicObjData->rotation + (Oyster::Math::Float4)dynamicObjData->boundingVolume.box.rotation; - - //mass scaled - rigidBodyMass = dynamicObjData->scale[0] * dynamicObjData->scale[1] * dynamicObjData->scale[2] * dynamicObjData->boundingVolume.box.mass; - - //size scaled - rigidBodySize = (Oyster::Math::Float3)dynamicObjData->boundingVolume.box.size * (Oyster::Math::Float3)dynamicObjData->scale; - - //create the rigid body - rigidBody_Dynamic = API::Instance().AddCollisionBox(rigidBodySize , rigidWorldRotation , rigidWorldPos , rigidBodyMass, dynamicObjData->boundingVolume.box.restitutionCoeff , dynamicObjData->boundingVolume.box.frictionCoeffStatic , dynamicObjData->boundingVolume.box.frictionCoeffDynamic); + rigidBody_Dynamic = InitRigidBodyCube(dynamicObjData); } else if(dynamicObjData->boundingVolume.geoType == CollisionGeometryType_Cylinder) { - + //rigidBody_Dynamic = InitRigidBodyCylinder(dynamicObjData); } - - // add rigidbody to the logical obj - // Object::DefaultCollisionBefore, Object::DefaultCollisionAfter for now, gamelogic will take care of this - // set object_type to objID if(rigidBody_Dynamic != NULL) { - this->dynamicObjects.Push(new DynamicObject(rigidBody_Dynamic , Object::DefaultCollisionAfter, (ObjectSpecialType)dynamicObjData->specialTypeID)); - this->dynamicObjects[dynamicObjCount]->objectID = modelCount++; - rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[dynamicObjCount]); + // create game object + Object* dynamicGameObj = createGameObj(dynamicObjData, rigidBody_Dynamic); + if (dynamicGameObj != NULL) + { + this->dynamicObjects.Push((DynamicObject*)dynamicGameObj); + this->dynamicObjects[this->dynamicObjects.Size()-1]->objectID = modelCount++; + rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[this->dynamicObjects.Size()-1]); + } } } diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index b8c3f744..c069ac1e 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -32,9 +32,10 @@ namespace GameLogic ********************************************************/ void InitiateLevel(std::string levelPath); void InitiateLevel(float radius); + Oyster::Physics::ICustomBody* InitRigidBodyCube( const ObjectHeader* obj); + Oyster::Physics::ICustomBody* InitRigidBodySphere( const ObjectHeader* obj); - void parseObjectType(ObjectTypeHeader* obj); - void parsePhysicsObj(LevelLoaderInternal::BoundingVolumeBase* obj); + Object* createGameObj(ObjectHeader* obj, Oyster::Physics::ICustomBody* rigidBody); /******************************************************** * Creates a team in the level * @param teamSize: The size of the team you want to create diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp index 54c41b12..1caa840f 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp @@ -149,7 +149,7 @@ namespace GameLogic //Läs in filen. int fileLength = 0; Loader loader; - char* buf = loader.LoadFile("C:/Users/Sam/Documents/GitHub/Danbias/Bin/Content/worlds/cgf/"+ fileName, fileLength); + char* buf = loader.LoadFile("../Content/Worlds/cgf/"+ fileName, fileLength); start = 0; LevelLoaderInternal::FormatVersion version; diff --git a/Code/Game/GameLogic/Portal.cpp b/Code/Game/GameLogic/Portal.cpp index ac44d529..6fc787fa 100644 --- a/Code/Game/GameLogic/Portal.cpp +++ b/Code/Game/GameLogic/Portal.cpp @@ -9,7 +9,7 @@ Portal::Portal(void) this->portalExit = Float3(0,0,0); } -Portal::Portal(Oyster::Physics::ICustomBody *rigidBody, void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type, Oyster::Math::Float3 portalExit) +Portal::Portal(Oyster::Physics::ICustomBody *rigidBody, void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, Oyster::Math::Float3 portalExit) :StaticObject(rigidBody, collisionFuncAfter, type) { this->portalExit = portalExit; diff --git a/Code/Game/GameLogic/Portal.h b/Code/Game/GameLogic/Portal.h index 5b31c8b5..a8d308f4 100644 --- a/Code/Game/GameLogic/Portal.h +++ b/Code/Game/GameLogic/Portal.h @@ -10,7 +10,7 @@ namespace GameLogic Portal(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss) - ,OBJECT_TYPE type, Oyster::Math::Float3 portalExit); + ,ObjectSpecialType type, Oyster::Math::Float3 portalExit); ~Portal(void); From 06ae4d29dd0f161e021ed6a97eb207560d21e76c Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Fri, 14 Feb 2014 09:44:21 +0100 Subject: [PATCH 13/22] GL - Fixed some warnings. --- .../GameClientState/Buttons/ButtonEllipse.h | 12 ++++++++---- .../GameClientState/Buttons/ButtonRectangle.h | 12 ++++++++---- .../GameClientState/Buttons/EventButtonGUI.h | 9 ++++++--- Code/Misc/EventHandler/EventButtonCollection.cpp | 2 +- Code/Misc/EventHandler/EventHandler.cpp | 4 ++-- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h index a922f141..694683e7 100644 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h @@ -21,16 +21,20 @@ namespace DanBias ButtonEllipse() : EventButtonGUI(), radius(0) {} - ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButtonGUI(textureName, buttonText, textColor, owner, pos, size, resize) {} - ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButtonGUI(textureName, buttonText, textColor, func, pos, size, resize) {} - ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButtonGUI(textureName, buttonText, textColor, func, owner, pos, size, resize) {} - ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButtonGUI(textureName, buttonText, textColor, func, owner, userData, pos, size, resize) {} virtual ~ButtonEllipse() diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h index a0b3e94b..6afb77c1 100644 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h @@ -21,16 +21,20 @@ namespace DanBias ButtonRectangle() : EventButtonGUI(), width(0), height(0) {} - ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButtonGUI(textureName, buttonText, textColor, owner, pos, size, resize) {} - ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButtonGUI(textureName, buttonText, textColor, func, pos, size, resize) {} - ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButtonGUI(textureName, buttonText, textColor, func, owner, pos, size, resize) {} - ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButtonGUI(textureName, buttonText, textColor, func, owner, userData, pos, size, resize) {} virtual ~ButtonRectangle() diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h b/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h index d4884fd7..c6cde0ea 100644 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h @@ -35,19 +35,22 @@ namespace DanBias EventButtonGUI() : EventButton(), pos(0, 0), size(0, 0), texture(NULL), buttonText(""), textColor(0, 0, 0) {} - EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButton(owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) { CreateTexture(textureName); if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } - EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButton(func), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) { CreateTexture(textureName); if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } - EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButton(func, owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) { CreateTexture(textureName); diff --git a/Code/Misc/EventHandler/EventButtonCollection.cpp b/Code/Misc/EventHandler/EventButtonCollection.cpp index 72d0ba24..bb3a3461 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.cpp +++ b/Code/Misc/EventHandler/EventButtonCollection.cpp @@ -15,7 +15,7 @@ EventButtonCollection::EventButtonCollection(EventCollectionState state) EventButtonCollection::~EventButtonCollection() { - for(int i = 0; i < EventHandler::Instance().collections.size(); i++) + for(int i = 0; i < (int)EventHandler::Instance().collections.size(); i++) { if(EventHandler::Instance().collections.at(i) == this) { diff --git a/Code/Misc/EventHandler/EventHandler.cpp b/Code/Misc/EventHandler/EventHandler.cpp index 24dca38a..2309070e 100644 --- a/Code/Misc/EventHandler/EventHandler.cpp +++ b/Code/Misc/EventHandler/EventHandler.cpp @@ -53,7 +53,7 @@ void EventHandler::RenderText() void EventHandler::AddCollection(EventButtonCollection* collection) { - for(int i = 0; i < collections.size(); i++) + for(int i = 0; i < (int)collections.size(); i++) { //Do not add the collection if it's already in the list. if(collections.at(i) == collection) @@ -64,7 +64,7 @@ void EventHandler::AddCollection(EventButtonCollection* collection) void EventHandler::ReleaseCollection(EventButtonCollection* collection) { - for(int i = 0; i < collections.size(); i++) + for(int i = 0; i < (int)collections.size(); i++) { if(collections.at(i) == collection) { From 59697bfcea613155e719a810ee86837d91328e59 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Fri, 14 Feb 2014 09:53:02 +0100 Subject: [PATCH 14/22] GL - fixed constructors to ease creation of objects, also fixed weapon crash on destruction --- Code/Game/DanBiasGame/DanBiasGame_Impl.cpp | 10 +-- .../DanBiasGame/GameClientState/GameState.cpp | 1 - Code/Game/GameLogic/AttatchmentSocket.cpp | 6 +- Code/Game/GameLogic/CollisionManager.cpp | 86 ++++++++++++++++--- Code/Game/GameLogic/CrystalFormation.cpp | 9 +- Code/Game/GameLogic/CrystalFormation.h | 7 +- Code/Game/GameLogic/DynamicObject.cpp | 25 ++---- Code/Game/GameLogic/DynamicObject.h | 8 +- Code/Game/GameLogic/ExplosiveCrate.cpp | 29 +++++++ Code/Game/GameLogic/ExplosiveCrate.h | 24 ++++++ Code/Game/GameLogic/Game.cpp | 1 + Code/Game/GameLogic/GameLogic.vcxproj | 4 + Code/Game/GameLogic/GameLogicStates.h | 6 ++ Code/Game/GameLogic/Game_PlayerData.cpp | 3 +- Code/Game/GameLogic/JumpPad.cpp | 4 +- Code/Game/GameLogic/JumpPad.h | 5 +- Code/Game/GameLogic/Level.cpp | 42 ++++----- .../GameLogic/LevelLoader/LevelParser.cpp | 2 +- .../GameLogic/LevelLoader/ObjectDefines.h | 2 +- Code/Game/GameLogic/Object.cpp | 41 ++------- Code/Game/GameLogic/Object.h | 15 ++-- Code/Game/GameLogic/Player.cpp | 59 +++++++------ Code/Game/GameLogic/Player.h | 13 ++- Code/Game/GameLogic/Portal.cpp | 5 ++ Code/Game/GameLogic/Portal.h | 4 +- Code/Game/GameLogic/StaticObject.cpp | 27 ++---- Code/Game/GameLogic/StaticObject.h | 7 +- Code/Game/GameLogic/Weapon.cpp | 14 ++- 28 files changed, 264 insertions(+), 195 deletions(-) create mode 100644 Code/Game/GameLogic/ExplosiveCrate.cpp create mode 100644 Code/Game/GameLogic/ExplosiveCrate.h diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index c1a893ee..3d601691 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -211,6 +211,10 @@ namespace DanBias HRESULT DanBiasGame::CleanUp() { + Oyster::Graphics::API::Clean(); + EventHandler::Instance().Clean(); + GameServerAPI::ServerStop(); + m_data->recieverObj->gameClientState->Release(); delete m_data->recieverObj->gameClientState; m_data->recieverObj->Disconnect(); @@ -218,11 +222,7 @@ namespace DanBias delete m_data->inputObj; delete m_data; - EventHandler::Instance().Clean(); - - Oyster::Graphics::API::Clean(); - - GameServerAPI::ServerStop(); + return S_OK; } diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 0a732062..b060b539 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -80,7 +80,6 @@ GameState::gameStateState GameState::LoadGame() LoadModels("../Content/Worlds/ccc.bias"); // hardcoded objects - //LoadModels(); Float3 startPos = Float3(0,0,20.0f); InitCamera(startPos); return gameStateState_playing; diff --git a/Code/Game/GameLogic/AttatchmentSocket.cpp b/Code/Game/GameLogic/AttatchmentSocket.cpp index 453387fe..7a8076b1 100644 --- a/Code/Game/GameLogic/AttatchmentSocket.cpp +++ b/Code/Game/GameLogic/AttatchmentSocket.cpp @@ -14,10 +14,10 @@ AttatchmentSocket::AttatchmentSocket(void) AttatchmentSocket::~AttatchmentSocket(void) { - //if(this->attatchment) - //delete this->attatchment; + if(this->attatchment) + delete this->attatchment; - //this->attatchment = 0; + this->attatchment = 0; } IAttatchment* AttatchmentSocket::GetAttatchment() diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index c3b70cce..e254b93b 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -8,12 +8,15 @@ #include "CollisionManager.h" #include "JumpPad.h" #include "Portal.h" +#include "CrystalFormation.h" +#include "ExplosiveCrate.h" using namespace Oyster; using namespace GameLogic; void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss); + void PlayerVLethalObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss, Oyster::Math::Float ExtraDamage); void SendObjectFlying(Oyster::Physics::ICustomBody &obj, Oyster::Math::Float3 force); void Teleport(Oyster::Physics::ICustomBody &obj, Oyster::Math::Float3 target); @@ -26,18 +29,27 @@ using namespace GameLogic; switch (realObj->GetObjectType()) { - case ObjectSpecialType_StandarsBox: + case ObjectSpecialType::ObjectSpecialType_Generic: PlayerVObject(*player,*realObj, kineticEnergyLoss); //return Physics::ICustomBody::SubscriptMessage_none; break; - case ObjectSpecialType_Player: + + case ObjectSpecialType::ObjectSpecialType_StandardBox: + PlayerVObject(*player,*realObj, kineticEnergyLoss); //return Physics::ICustomBody::SubscriptMessage_none; break; - case ObjectSpecialType_World: + case ObjectSpecialType::ObjectSpecialType_Player: + //return Physics::ICustomBody::SubscriptMessage_none; + break; + case ObjectSpecialType::ObjectSpecialType_World: PlayerVObject(*player,*realObj, kineticEnergyLoss); //player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; break; - + + case ObjectSpecialType::ObjectSpecialType_CrystalFormation: + PlayerVLethalObject(*player,*realObj, kineticEnergyLoss,((CrystalFormation*)realObj)->getShreddingDamage()); + //player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; + break; } //return Physics::ICustomBody::SubscriptMessage_none; @@ -50,14 +62,13 @@ using namespace GameLogic; switch (realObj->GetObjectType()) { - case ObjectSpecialType_Generic: + case ObjectSpecialType::ObjectSpecialType_Generic: break; - case ObjectSpecialType_StandarsBox: - break; - case ObjectSpecialType_Player: + case ObjectSpecialType::ObjectSpecialType_StandardBox: SendObjectFlying(*obj, jumpPad->pushForce); break; - case ObjectSpecialType_World: + case ObjectSpecialType::ObjectSpecialType_Player: + SendObjectFlying(*obj, jumpPad->pushForce); break; } } @@ -80,7 +91,44 @@ using namespace GameLogic; { obj.SetPosition(target); } + + void ExplosiveCrate::ExplosiveCrateCollision(Oyster::Physics::ICustomBody *rigidBodyCrate, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) + { + int forceThreashHold = 200000; //how much force for the box to explode of the impact + + + + if(kineticEnergyLoss > forceThreashHold) + { + ExplosiveCrate* crate = ((ExplosiveCrate*)rigidBodyCrate->GetCustomTag()); + + + Oyster::Math::Float3 pos = rigidBodyCrate->GetState().centerPos; + Oyster::Collision3D::Sphere *hitSphere = new Oyster::Collision3D::Sphere(pos,crate->ExplosionRadius); + + Oyster::Physics::API::Instance().ApplyEffect(hitSphere,crate,Explode); + + delete hitSphere; + } + } + void ExplosiveCrate::Explode(Oyster::Physics::ICustomBody *obj, void* args) + { + Object *realObj = (Object*)obj->GetCustomTag(); + ExplosiveCrate* ExplosionSource = ((ExplosiveCrate*)args); + + + if(realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_Player) + { + Player *hitPlayer = (Player*)realObj; + + hitPlayer->DamageLife(ExplosionSource->shreddingDamage); + //do shredding damage + } + + realObj->GetRigidBody()->ApplyImpulse(ExplosionSource->pushForce); + + } void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss) { @@ -98,6 +146,20 @@ using namespace GameLogic; } + + void PlayerVLethalObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss, Oyster::Math::Float ExtraDamage) + { + int damageDone = 0; + int forceThreashHold = 200000; + + if(kineticEnergyLoss > forceThreashHold) //should only take damage if the force is high enough + { + damageDone = (int)(kineticEnergyLoss * 0.10f); + damageDone += ExtraDamage; + //player.DamageLife(damageDone); + } + } + Oyster::Physics::ICustomBody::SubscriptMessage Object::DefaultCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) { return Physics::ICustomBody::SubscriptMessage_none; @@ -123,7 +185,7 @@ using namespace GameLogic; Object *realObj = (Object*)obj->GetCustomTag(); - if(realObj->GetObjectType() == ObjectSpecialType_Player || realObj->GetObjectType() == ObjectSpecialType_World) + if(realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_Player || realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_World) return; obj->ApplyImpulse(((forcePushData*)(args))->pushForce); @@ -146,9 +208,7 @@ using namespace GameLogic; switch(realObj->GetObjectType()) { - case ObjectSpecialType_StandarsBox: - //move obj to limbo in physics to make sure it wont collide with anything -// Oyster::Physics::API::Instance().MoveToLimbo(obj); + case ObjectSpecialType::ObjectSpecialType_StandardBox: weapon->heldObject = obj; //weapon now holds the object weapon->hasObject = true; diff --git a/Code/Game/GameLogic/CrystalFormation.cpp b/Code/Game/GameLogic/CrystalFormation.cpp index 00709660..e9c6dd73 100644 --- a/Code/Game/GameLogic/CrystalFormation.cpp +++ b/Code/Game/GameLogic/CrystalFormation.cpp @@ -8,8 +8,8 @@ CrystalFormation::CrystalFormation(void) this->shreddingDamage = 0; } -CrystalFormation::CrystalFormation(Oyster::Physics::ICustomBody *rigidBody, void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type, Oyster::Math::Float shreddingDamage) - :StaticObject(rigidBody, collisionFuncAfter, type) +CrystalFormation::CrystalFormation(Oyster::Physics::ICustomBody *rigidBody, int objectID,Oyster::Math::Float shreddingDamage) + :StaticObject(rigidBody, CrystalFormation::DefaultCollisionAfter, ObjectSpecialType::ObjectSpecialType_CrystalFormation, objectID) { this->shreddingDamage = shreddingDamage; } @@ -18,3 +18,8 @@ CrystalFormation::CrystalFormation(Oyster::Physics::ICustomBody *rigidBody, void CrystalFormation::~CrystalFormation(void) { } + +Oyster::Math::Float CrystalFormation::getShreddingDamage() +{ + return this->shreddingDamage; +} diff --git a/Code/Game/GameLogic/CrystalFormation.h b/Code/Game/GameLogic/CrystalFormation.h index 693460fe..6e07942b 100644 --- a/Code/Game/GameLogic/CrystalFormation.h +++ b/Code/Game/GameLogic/CrystalFormation.h @@ -8,12 +8,13 @@ namespace GameLogic public: CrystalFormation(void); - CrystalFormation(Oyster::Physics::ICustomBody *rigidBody - ,void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss) - ,OBJECT_TYPE type, Oyster::Math::Float shreddingDamage); + CrystalFormation(Oyster::Physics::ICustomBody *rigidBody + ,int objectID,Oyster::Math::Float shreddingDamage); ~CrystalFormation(void); + Oyster::Math::Float getShreddingDamage(); + private: Oyster::Math::Float shreddingDamage; }; diff --git a/Code/Game/GameLogic/DynamicObject.cpp b/Code/Game/GameLogic/DynamicObject.cpp index b6193f30..8096b4aa 100644 --- a/Code/Game/GameLogic/DynamicObject.cpp +++ b/Code/Game/GameLogic/DynamicObject.cpp @@ -9,29 +9,14 @@ DynamicObject::DynamicObject() { } -DynamicObject::DynamicObject(ObjectSpecialType type) - :Object(type) + +DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) + :Object(rigidBody, EventOnCollision, type, objectID) { } -DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type) - :Object(rigidBody,type) -{ - -} - -DynamicObject::DynamicObject( void* collisionFuncAfter, ObjectSpecialType type) - :Object(collisionFuncAfter,type) -{ - -} -DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, ObjectSpecialType type) - :Object(rigidBody, collisionFuncAfter, type) -{ - -} -DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type) - :Object(rigidBody, collisionFuncAfter, type) +DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) + :Object(rigidBody, EventOnCollision, type, objectID) { } diff --git a/Code/Game/GameLogic/DynamicObject.h b/Code/Game/GameLogic/DynamicObject.h index e8aa25ce..3341e94d 100644 --- a/Code/Game/GameLogic/DynamicObject.h +++ b/Code/Game/GameLogic/DynamicObject.h @@ -14,12 +14,8 @@ namespace GameLogic public: DynamicObject(); - - DynamicObject(ObjectSpecialType type); - DynamicObject(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type); - DynamicObject( void* collisionFuncAfter, ObjectSpecialType type); - DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, ObjectSpecialType type); - DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type); + DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID); + DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID); ~DynamicObject(void); diff --git a/Code/Game/GameLogic/ExplosiveCrate.cpp b/Code/Game/GameLogic/ExplosiveCrate.cpp new file mode 100644 index 00000000..534fd6bb --- /dev/null +++ b/Code/Game/GameLogic/ExplosiveCrate.cpp @@ -0,0 +1,29 @@ +#include "ExplosiveCrate.h" + +using namespace GameLogic; + +ExplosiveCrate::ExplosiveCrate(void) + :DynamicObject() +{ + this->shreddingDamage = 0; + this->pushForce = 0; + this->ExplosionRadius = 0; +} + +ExplosiveCrate::ExplosiveCrate(Oyster::Physics::ICustomBody *rigidBody,ObjectSpecialType type, int objectID,Oyster::Math::Float shreddingDamage, Oyster::Math::Float3 pushForce, Oyster::Math::Float ExplosionRadius) + :DynamicObject(rigidBody,ExplosiveCrate::ExplosiveCrateCollision, type, objectID) +{ + this->shreddingDamage = shreddingDamage; + this->pushForce = pushForce; + this->ExplosionRadius = ExplosionRadius; +} + +ExplosiveCrate::~ExplosiveCrate(void) +{ + +} + + + + + diff --git a/Code/Game/GameLogic/ExplosiveCrate.h b/Code/Game/GameLogic/ExplosiveCrate.h new file mode 100644 index 00000000..3cf0c9a4 --- /dev/null +++ b/Code/Game/GameLogic/ExplosiveCrate.h @@ -0,0 +1,24 @@ +#ifndef EXPLOSIVECRATE_H +#define EXPLOSIVECRATE_H +#include "DynamicObject.h" +namespace GameLogic +{ + class ExplosiveCrate : public DynamicObject + { + public: + ExplosiveCrate(void); + + ExplosiveCrate(Oyster::Physics::ICustomBody *rigidBody,ObjectSpecialType type,int objectID,Oyster::Math::Float shreddingDamage, Oyster::Math::Float3 pushForce, Oyster::Math::Float ExplosionRadius); + + ~ExplosiveCrate(void); + + static void ExplosiveCrateCollision(Oyster::Physics::ICustomBody *rigidBodyCrate, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); + static void Explode(Oyster::Physics::ICustomBody *obj, void* args); + + private: + Oyster::Math::Float shreddingDamage; + Oyster::Math::Float3 pushForce; + Oyster::Math::Float ExplosionRadius; + }; +} +#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 5bf18dc4..900799e3 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -84,6 +84,7 @@ Game::LevelData* Game::CreateLevel() //this->level->level->InitiateLevel(1000); this->level->level->InitiateLevel("../Content/Worlds/ccc.bias"); + return this->level; } diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index b19ffef0..48af6d60 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -176,7 +176,9 @@ + + @@ -202,7 +204,9 @@ + + diff --git a/Code/Game/GameLogic/GameLogicStates.h b/Code/Game/GameLogic/GameLogicStates.h index 9ae0d482..3e9bcdf5 100644 --- a/Code/Game/GameLogic/GameLogicStates.h +++ b/Code/Game/GameLogic/GameLogicStates.h @@ -43,6 +43,12 @@ namespace GameLogic Oyster::Math::Float3 pushForce; }; + struct ExplosionData + { + Oyster::Math::Float3 pushForce; + Oyster::Math::Float3 ShreddingDamage; + }; + }; diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index acdcd2f3..30082130 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -20,13 +20,14 @@ Game::PlayerData::PlayerData() Oyster::Physics::ICustomBody* rigidBody = Oyster::Physics::API::Instance().AddCollisionBox(size, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f ); rigidBody->SetAngularFactor(0.0f); //create player with this rigid body - this->player = new Player(rigidBody, Player::PlayerCollision, ObjectSpecialType_Player); + this->player = new Player(rigidBody, Player::PlayerCollision, ObjectSpecialType_Player,0,0); this->player->GetRigidBody()->SetCustomTag(this); player->EndFrame(); } Game::PlayerData::PlayerData(int playerID,int teamID) { + Oyster::Physics::ICustomBody* rigidBody; this->player = new Player(); } Game::PlayerData::~PlayerData() diff --git a/Code/Game/GameLogic/JumpPad.cpp b/Code/Game/GameLogic/JumpPad.cpp index d52acb45..424340ad 100644 --- a/Code/Game/GameLogic/JumpPad.cpp +++ b/Code/Game/GameLogic/JumpPad.cpp @@ -8,8 +8,8 @@ JumpPad::JumpPad(void) { } -JumpPad::JumpPad(Oyster::Physics::ICustomBody *rigidBody, void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, Oyster::Math::Float3 pushForce) - :StaticObject(rigidBody, collisionFuncAfter, type) +JumpPad::JumpPad(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type,int objectID ,Oyster::Math::Float3 pushForce) + :StaticObject(rigidBody, JumpPad::JumpPadActivated, type, objectID) { this->pushForce = pushForce; } diff --git a/Code/Game/GameLogic/JumpPad.h b/Code/Game/GameLogic/JumpPad.h index 4fad54e4..a88a0cc5 100644 --- a/Code/Game/GameLogic/JumpPad.h +++ b/Code/Game/GameLogic/JumpPad.h @@ -8,9 +8,8 @@ namespace GameLogic public: JumpPad(void); - JumpPad(Oyster::Physics::ICustomBody *rigidBody - ,void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss) - ,ObjectSpecialType type, Oyster::Math::Float3 pushForce); + JumpPad(Oyster::Physics::ICustomBody *rigidBody + ,ObjectSpecialType type, int objectID,Oyster::Math::Float3 pushForce); ~JumpPad(void); diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 9a91744e..1184cc49 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -240,14 +240,9 @@ void Level::InitiateLevel(std::string levelPath) if(rigidBody_Static != NULL) { - // create game object - Object* staticGameObj = createGameObj(staticObjData, rigidBody_Static); - if(staticGameObj != NULL) - { - this->staticObjects.Push((StaticObject*)staticGameObj); - this->staticObjects[this->staticObjects.Size()-1]->objectID = modelCount++; - rigidBody_Static->SetCustomTag(this->staticObjects[this->staticObjects.Size()-1]); - } + this->staticObjects.Push(new StaticObject(rigidBody_Static, Object::DefaultCollisionAfter, (ObjectSpecialType)staticObjData->specialTypeID, 0)); + //this->staticObjects[staticObjCount]->objectID = modelCount++; + } } @@ -277,14 +272,9 @@ void Level::InitiateLevel(std::string levelPath) if(rigidBody_Dynamic != NULL) { - // create game object - Object* dynamicGameObj = createGameObj(dynamicObjData, rigidBody_Dynamic); - if (dynamicGameObj != NULL) - { - this->dynamicObjects.Push((DynamicObject*)dynamicGameObj); - this->dynamicObjects[this->dynamicObjects.Size()-1]->objectID = modelCount++; - rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[this->dynamicObjects.Size()-1]); - } + + this->dynamicObjects.Push(new DynamicObject(rigidBody_Dynamic , Object::DefaultCollisionAfter, (ObjectSpecialType)dynamicObjData->specialTypeID, 0)); + //this->dynamicObjects[dynamicObjCount]->objectID = modelCount++; } } @@ -305,9 +295,9 @@ void Level::InitiateLevel(float radius) // add level sphere ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); - levelObj = new StaticObject(rigidBody, LevelCollisionAfter, ObjectSpecialType_World); + levelObj = new StaticObject(rigidBody, LevelCollisionAfter, ObjectSpecialType_World, idCount++); - this->levelObj->objectID = idCount++; + //this->levelObj->objectID = idCount++; rigidBody->SetCustomTag(levelObj); @@ -319,9 +309,9 @@ void Level::InitiateLevel(float radius) { rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 605 + i*5, 10), 5, 0.5f, 0.8f, 0.6f); - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultCollisionAfter, ObjectSpecialType_StandarsBox)); + this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultCollisionAfter, ObjectSpecialType_StandardBox, idCount++)); - this->dynamicObjects[i]->objectID = idCount++; + //this->dynamicObjects[i]->objectID = idCount++; rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]); } /*offset += nrOfBoxex; @@ -358,24 +348,24 @@ void Level::InitiateLevel(float radius) // add crystal ICustomBody* rigidBody_Crystal = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(10, 605, 0), 5, 0.5f, 0.8f, 0.6f); - this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultCollisionAfter, ObjectSpecialType_StandarsBox)); + this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultCollisionAfter, ObjectSpecialType_StandardBox, idCount++)); rigidBody_Crystal->SetCustomTag(this->dynamicObjects[nrOfBoxex]); - this->dynamicObjects[nrOfBoxex]->objectID = idCount++; + //this->dynamicObjects[nrOfBoxex]->objectID = idCount++; // add house ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(20, 20, 20), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(-50, 590, 0), 0, 0.5f, 0.8f, 0.6f); - this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultCollisionAfter, ObjectSpecialType_Generic)); + this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultCollisionAfter, ObjectSpecialType_Generic, idCount++)); rigidBody_House->SetCustomTag(this->staticObjects[0]); - this->staticObjects[0]->objectID = idCount++; + //this->staticObjects[0]->objectID = idCount++; // add jumppad ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1, 1, 1), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(4, 600.3, 0), 5, 0.5f, 0.8f, 0.6f); - this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, JumpPad::JumpPadActivated, ObjectSpecialType_JumpPad, Oyster::Math::Float3(0,2000,0))); + this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, ObjectSpecialType_JumpPad,idCount++ ,Oyster::Math::Float3(0,2000,0))); rigidBody_Jumppad->SetCustomTag(this->staticObjects[1]); - this->staticObjects[1]->objectID = idCount++; + //this->staticObjects[1]->objectID = idCount++; } void Level::AddPlayerToTeam(Player *player, int teamID) diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp index c5dfa8cc..038b9a40 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp @@ -75,7 +75,7 @@ std::vector> LevelParser::Parse(std::string filen case ObjectSpecialType_Spike: case ObjectSpecialType_SpikeBox: case ObjectSpecialType_RedExplosiveBox: - case ObjectSpecialType_StandarsBox: + case ObjectSpecialType_StandardBox: case ObjectSpecialType_Stone: case ObjectSpecialType_Building: { diff --git a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h index 4cf34366..50c722b6 100644 --- a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h +++ b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h @@ -30,7 +30,7 @@ namespace GameLogic ObjectSpecialType_World, //Always the main celestial body ObjectSpecialType_Building, ObjectSpecialType_Stone, - ObjectSpecialType_StandarsBox, + ObjectSpecialType_StandardBox, ObjectSpecialType_RedExplosiveBox, ObjectSpecialType_SpikeBox, ObjectSpecialType_Spike, diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 80ff0ad6..cfd2d255 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -19,55 +19,28 @@ Object::Object() this->rigidBody = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.0f, 0.0f, 0.0f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); this->type = ObjectSpecialType_Unknown; - this->objectID = GID(); + this->objectID = -1; } -Object::Object(ObjectSpecialType type) -{ - this->rigidBody = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.0f, 0.0f, 0.0f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); - this->type = type; - this->objectID = GID(); -} - -Object::Object(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type) -{ - this->rigidBody = rigidBody; - this->type = type; - this->objectID = GID(); -} - -Object::Object( void* collisionFuncAfter, ObjectSpecialType type) - -{ - this->rigidBody = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.0f, 0.0f, 0.0f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); - - this->type = type; - this->objectID = GID(); -} - -Object::Object(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, ObjectSpecialType type) +Object::Object(Oyster::Physics::ICustomBody *rigidBody, void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) { this->rigidBody = rigidBody; this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter)); this->type = type; - this->objectID = GID(); + this->objectID = objectID; + this->rigidBody->SetCustomTag(this); } -Object::Object(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type) +Object::Object(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) { this->rigidBody = rigidBody; this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter)); this->type = type; - this->objectID = GID(); + this->objectID = objectID; + this->rigidBody->SetCustomTag(this); } -void Object::ApplyLinearImpulse(Oyster::Math::Float3 force) -{ - -} - - Object::~Object(void) { diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index 83e12277..7e7e3f08 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -18,11 +18,9 @@ namespace GameLogic { public: Object(); - Object(ObjectSpecialType type); - Object(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type); - Object(void* collisionFuncAfter, ObjectSpecialType type); - Object(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, ObjectSpecialType type); - Object(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type); + + Object(Oyster::Physics::ICustomBody *rigidBody, void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID); + Object(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID); ~Object(void); ObjectSpecialType GetObjectType() const override; @@ -38,7 +36,6 @@ namespace GameLogic Oyster::Physics::ICustomBody* GetRigidBody(); - void ApplyLinearImpulse(Oyster::Math::Float3 force); virtual void BeginFrame(); virtual void EndFrame(); @@ -50,8 +47,7 @@ namespace GameLogic public: //TODO: Hax This should be private when level is dynamic - ObjectSpecialType type; - int objectID; + protected: Oyster::Physics::ICustomBody *rigidBody; @@ -59,6 +55,9 @@ namespace GameLogic static const Game* gameInstance; Oyster::Math::Float3 currLook; Oyster::Math::Float3 newLook; + + ObjectSpecialType type; + int objectID; }; } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index f6dddb85..3b022220 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -13,34 +13,9 @@ Player::Player() { } -Player::Player(ObjectSpecialType type) - :DynamicObject(type) -{ - InitPlayer(); -} -Player::Player(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type) - :DynamicObject(rigidBody,type) -{ - InitPlayer(); -} -Player::Player( void* collisionFuncAfter, ObjectSpecialType type) - :DynamicObject(collisionFuncAfter,type) -{ - InitPlayer(); -} -Player::Player(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, ObjectSpecialType type) - :DynamicObject(rigidBody, collisionFuncAfter, type) -{ - InitPlayer(); -} -Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type) - :DynamicObject(rigidBody, collisionFuncAfter, type) -{ - InitPlayer(); -} - -void Player::InitPlayer() +Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) + :DynamicObject(rigidBody, EventOnCollision, type, objectID) { weapon = new Weapon(2,this); @@ -55,6 +30,36 @@ void Player::InitPlayer() key_strafeLeft = 0; } +Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) + :DynamicObject(rigidBody, EventOnCollision, type, objectID) +{ + this->rigidBody = rigidBody; + + Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(0,400,0); + + Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,1.0f,0.5f); + Oyster::Math::Float mass = 60; + Oyster::Math::Float restitutionCoeff = 0.5; + Oyster::Math::Float frictionCoeff_Static = 0.4; + Oyster::Math::Float frictionCoeff_Dynamic = 0.3; + + + this->rigidBody = Oyster::Physics::API::Instance().AddCollisionBox(size, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f ); + this->rigidBody->SetAngularFactor(0.0f); + + weapon = new Weapon(2,this); + + this->life = 100; + this->teamID = teamID; + this->playerState = PLAYER_STATE_IDLE; + this->lookDir = Oyster::Math::Float3(0,0,-1); + this->moveDir = Oyster::Math::Float3(0,0,0); + key_forward = 0; + key_backward = 0; + key_strafeRight = 0; + key_strafeLeft = 0; +} + Player::~Player(void) { if(weapon) diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index b10d1114..17ad2095 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -16,15 +16,12 @@ namespace GameLogic { public: Player(void); - Player(ObjectSpecialType type); - Player(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type); - Player( void* collisionFuncAfter, ObjectSpecialType type); - Player(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, ObjectSpecialType type); - Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type); + + Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID); + Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID); ~Player(void); - void InitPlayer(); - + /******************************************************** * Moves the player based on input * @param movement: enum value on what kind of action is to be taken @@ -81,7 +78,7 @@ namespace GameLogic void Jump(); private: - int life; + Oyster::Math::Float life; int teamID; Weapon *weapon; PLAYER_STATE playerState; diff --git a/Code/Game/GameLogic/Portal.cpp b/Code/Game/GameLogic/Portal.cpp index 6fc787fa..66671a8d 100644 --- a/Code/Game/GameLogic/Portal.cpp +++ b/Code/Game/GameLogic/Portal.cpp @@ -9,8 +9,13 @@ Portal::Portal(void) this->portalExit = Float3(0,0,0); } +<<<<<<< HEAD Portal::Portal(Oyster::Physics::ICustomBody *rigidBody, void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, Oyster::Math::Float3 portalExit) :StaticObject(rigidBody, collisionFuncAfter, type) +======= +Portal::Portal(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type,int objectID ,Oyster::Math::Float3 portalExit) + :StaticObject(rigidBody, EventOnCollision, type, objectID) +>>>>>>> GL - fixed constructors to ease creation of objects, also fixed weapon crash on destruction { this->portalExit = portalExit; } diff --git a/Code/Game/GameLogic/Portal.h b/Code/Game/GameLogic/Portal.h index a8d308f4..ab88d934 100644 --- a/Code/Game/GameLogic/Portal.h +++ b/Code/Game/GameLogic/Portal.h @@ -9,8 +9,8 @@ namespace GameLogic Portal(void); Portal(Oyster::Physics::ICustomBody *rigidBody - ,void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss) - ,ObjectSpecialType type, Oyster::Math::Float3 portalExit); + ,void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss) + ,ObjectSpecialType type,int objectID ,Oyster::Math::Float3 portalExit); ~Portal(void); diff --git a/Code/Game/GameLogic/StaticObject.cpp b/Code/Game/GameLogic/StaticObject.cpp index f9156e3c..68140cbe 100644 --- a/Code/Game/GameLogic/StaticObject.cpp +++ b/Code/Game/GameLogic/StaticObject.cpp @@ -10,32 +10,17 @@ StaticObject::StaticObject() { } -StaticObject::StaticObject(ObjectSpecialType type) - :Object(type) -{ -} -StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type) - :Object(rigidBody,type) +StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) + :Object(rigidBody, EventOnCollision, type, objectID) { - //this->rigidBody->SetGravity(true); - //this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse)(CollisionManager::IgnoreCollision)); + //use setMass(when it is made) and set the mass to 0 in order to ensure that the object is static } -StaticObject::StaticObject( void* collisionFuncAfter, ObjectSpecialType type) - :Object(collisionFuncAfter,type) +StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) + :Object(rigidBody, EventOnCollision, type, objectID) { - -} -StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, ObjectSpecialType type) - :Object(rigidBody, collisionFuncAfter, type) -{ - -} -StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type) - :Object(rigidBody, collisionFuncAfter, type) -{ - + //use setMass(when it is made) and set the mass to 0 in order to ensure that the object is static } StaticObject::~StaticObject(void) diff --git a/Code/Game/GameLogic/StaticObject.h b/Code/Game/GameLogic/StaticObject.h index 4e655808..a7b9fbff 100644 --- a/Code/Game/GameLogic/StaticObject.h +++ b/Code/Game/GameLogic/StaticObject.h @@ -18,11 +18,8 @@ namespace GameLogic public: StaticObject(); - StaticObject(ObjectSpecialType type); - StaticObject(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type); - StaticObject( void* collisionFuncAfter, ObjectSpecialType type); - StaticObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, ObjectSpecialType type); - StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type); + StaticObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID); + StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID); ~StaticObject(void); diff --git a/Code/Game/GameLogic/Weapon.cpp b/Code/Game/GameLogic/Weapon.cpp index 66de8e33..379f53dc 100644 --- a/Code/Game/GameLogic/Weapon.cpp +++ b/Code/Game/GameLogic/Weapon.cpp @@ -19,7 +19,11 @@ Weapon::Weapon() Weapon::Weapon(int MaxNrOfSockets,Player *owner) { attatchmentSockets.Resize(MaxNrOfSockets); - attatchmentSockets[0] = new AttatchmentSocket(); + for(int i = 0; i < MaxNrOfSockets; i++) + { + attatchmentSockets[i] = new AttatchmentSocket(); + } + weaponState = WEAPON_STATE_IDLE; currentNrOfAttatchments = 0; @@ -38,8 +42,12 @@ Weapon::~Weapon(void) { for (unsigned int i = 0; i < this->attatchmentSockets.Size(); i++) { - delete this->attatchmentSockets[i]; - this->attatchmentSockets[i] = 0; + if(this->attatchmentSockets[i]) + { + delete this->attatchmentSockets[i]; + this->attatchmentSockets[i] = 0; + } + } } From 5defe7c0f762f0fb0409e99ab53c5c1de2612c8b Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Fri, 14 Feb 2014 10:08:29 +0100 Subject: [PATCH 15/22] GL - fixed compile errors --- Code/Game/GameLogic/Level.cpp | 36 +++++++++++++++++----------------- Code/Game/GameLogic/Portal.cpp | 6 +----- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 1184cc49..734f3e94 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -23,13 +23,13 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) { case ObjectSpecialType_None: { - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,0); } break; case ObjectSpecialType_Sky: { float skySize = ((SkyAttributes*)obj)->skySize; - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,0); } break; case ObjectSpecialType_World: @@ -39,28 +39,28 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) float worldSize = ((WorldAttributes*)obj)->worldSize; float atmosphereSize = ((WorldAttributes*)obj)->atmoSphereSize; - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,0); } break; case ObjectSpecialType_Building: { - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,0); } case ObjectSpecialType_Stone: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,0); } break; - case ObjectSpecialType_StandarsBox: + case ObjectSpecialType_StandardBox: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,0); } break; case ObjectSpecialType_RedExplosiveBox: { int dmg = 50; //gameObj = new ExplosiveBox(rigidBody, ObjectSpecialType_RedExplosiveBox); - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,0); } break; //case ObjectSpecialType_BlueExplosiveBox: @@ -69,24 +69,24 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) // break; case ObjectSpecialType_SpikeBox: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,0); } break; case ObjectSpecialType_Spike: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,0); } break; case ObjectSpecialType_CrystalFormation: { int dmg = 50; //gameObj = new Crystal(rigidBody); - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,0); } break; case ObjectSpecialType_CrystalShard: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,0); } break; case ObjectSpecialType_JumpPad: @@ -94,33 +94,33 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) float power = ((JumpPadAttributes*)obj)->power; Oyster::Math::Float3 dir = ((JumpPadAttributes*)obj)->direction; //gameObj = JumpPad(rigidBody, ); - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,0); } break; case ObjectSpecialType_Portal: { Oyster::Math::Float3 destination = ((PortalAttributes*)obj)->destination; - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,0); } break; case ObjectSpecialType_SpawnPoint: { - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,0); } break; case ObjectSpecialType_Player: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,0); } break; case ObjectSpecialType_Generic: { - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,0); } break; default: { - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID); + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,0); } break; } diff --git a/Code/Game/GameLogic/Portal.cpp b/Code/Game/GameLogic/Portal.cpp index 66671a8d..1edd1717 100644 --- a/Code/Game/GameLogic/Portal.cpp +++ b/Code/Game/GameLogic/Portal.cpp @@ -9,13 +9,9 @@ Portal::Portal(void) this->portalExit = Float3(0,0,0); } -<<<<<<< HEAD -Portal::Portal(Oyster::Physics::ICustomBody *rigidBody, void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, Oyster::Math::Float3 portalExit) - :StaticObject(rigidBody, collisionFuncAfter, type) -======= + Portal::Portal(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type,int objectID ,Oyster::Math::Float3 portalExit) :StaticObject(rigidBody, EventOnCollision, type, objectID) ->>>>>>> GL - fixed constructors to ease creation of objects, also fixed weapon crash on destruction { this->portalExit = portalExit; } From 1fc6f16409c38806efbdaaf883398c83b1a304b2 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Fri, 14 Feb 2014 10:09:03 +0100 Subject: [PATCH 16/22] GL - rotation testing --- .../DanBiasGame/GameClientState/GameState.cpp | 74 +++++++++++-------- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 2 +- Code/Game/GameLogic/Game_PlayerData.cpp | 7 +- Code/Game/GameLogic/Level.cpp | 11 ++- Code/Game/GameLogic/Player.cpp | 7 +- 5 files changed, 58 insertions(+), 43 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 0a732062..6dc53c47 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -60,22 +60,7 @@ GameState::gameStateState GameState::LoadGame() plight.Radius = 300; plight.Bright = 0.5f; Oyster::Graphics::API::AddLight(plight); - //plight.Pos = Float3(350,350,5); - //plight.Color = Float3(0.9f,0.7f,0.3f); - //plight.Radius = 200; - //plight.Bright = 0.7f; - //Oyster::Graphics::API::AddLight(plight); - //plight.Pos = Float3(10,350,350); - //plight.Color = Float3(0.9f,0.7f,0.3f); - //plight.Radius = 200; - //plight.Bright = 0.7f; - //Oyster::Graphics::API::AddLight(plight); - //plight.Pos = Float3(10,-15,5); - //plight.Color = Float3(0,0,1); - //plight.Radius = 50; - //plight.Bright = 0.5f; - //Oyster::Graphics::API::AddLight(plight); // use level loader LoadModels("../Content/Worlds/ccc.bias"); @@ -143,7 +128,7 @@ bool GameState::LoadModels() this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); // add jumppad - modelData.position = Oyster::Math::Float3(4, 600.3, 0); + modelData.position = Oyster::Math::Float3(4, 600.3f, 0); modelData.modelPath = L"jumppad_round.dan"; modelData.id = id++; // load models @@ -244,24 +229,51 @@ bool GameState::LoadModels(std::string mapFile) break; } } - //myId += modelId++; - // add player model - //modelData.position = ; - //modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(2,2,-2), 1); - //modelData.scale = Oyster::Math::Float3(2,2,2); + + Oyster::Math::Quaternion first = Oyster::Math::Quaternion(Float3(0.3536,0.3536,-0.146), 0.8536); + Oyster::Math::Quaternion second = Oyster::Math::Quaternion(Float3(0.3536,0.3536,-0.146), 0.8536); + Oyster::Math::Quaternion result = first * second; + Oyster::Math::Quaternion total = Oyster::Math::Quaternion(Float3(0.5,0.5,-0.5), 0.5); + modelData.visible = true; + modelData.position = Oyster::Math::Float3(20, 127,0); + modelData.rotation = first; + modelData.scale = Oyster::Math::Float3(1,1,1); + modelData.modelPath = L"char_still_sizeref.dan"; + modelData.id = myId; + this->staticObjects.Push(new C_StaticObj()); + this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); - //modelData.visible = true; - //modelData.modelPath = L"char_still_sizeref.dan"; - //modelData.id = myId; - //// load models - //this->dynamicObjects.Push(new C_DynamicObj()); - //this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData); + modelData.visible = true; + modelData.position = Oyster::Math::Float3(22, 127,0); + modelData.rotation = second; + modelData.scale = Oyster::Math::Float3(1,1,1); + modelData.modelPath = L"char_still_sizeref.dan"; + modelData.id = myId; + + this->staticObjects.Push(new C_StaticObj()); + this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); + + modelData.visible = true; + modelData.position = Oyster::Math::Float3(24, 127,0); + modelData.rotation = result; + modelData.scale = Oyster::Math::Float3(1,1,1); + modelData.modelPath = L"char_still_sizeref.dan"; + modelData.id = myId; + + this->staticObjects.Push(new C_StaticObj()); + this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); + + modelData.visible = true; + modelData.position = Oyster::Math::Float3(26, 127,0); + modelData.rotation = total; + modelData.scale = Oyster::Math::Float3(1,1,1); + modelData.modelPath = L"char_still_sizeref.dan"; + modelData.id = myId; + + this->staticObjects.Push(new C_StaticObj()); + this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); - /*C_Player* obj = new C_Player(); - privData->object.push_back(obj); - privData->object[privData->object.size() -1 ]->Init(modelData); - */ return true; } diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 86560164..3102b9f2 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -61,7 +61,7 @@ void AttatchmentMassDriver::Update(float dt) Oyster::Math::Float3 ownerPos = owner->GetPosition(); Oyster::Physics::ICustomBody::State ownerState = owner->GetRigidBody()->GetState(); Oyster::Math::Float3 up = -ownerState.GetOrientation().v[2]; - up *= -0.3; + up *= -0.3f; Oyster::Math::Float3 pos = ownerPos + (owner->GetLookDir().GetNormalized()*5); //state.centerPos = pos; diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index acdcd2f3..914dd52b 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -11,9 +11,9 @@ Game::PlayerData::PlayerData() Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,2.0f,0.5f); Oyster::Math::Float mass = 60; - Oyster::Math::Float restitutionCoeff = 0.5; - Oyster::Math::Float frictionCoeff_Static = 0.4; - Oyster::Math::Float frictionCoeff_Dynamic = 0.3; + Oyster::Math::Float restitutionCoeff = 0.5f; + Oyster::Math::Float frictionCoeff_Static = 0.4f; + Oyster::Math::Float frictionCoeff_Dynamic = 0.3f; //sbDesc.quaternion = Oyster::Math::Float3(0, Oyster::Math::pi, 0); //create rigid body @@ -28,6 +28,7 @@ Game::PlayerData::PlayerData() Game::PlayerData::PlayerData(int playerID,int teamID) { this->player = new Player(); + } Game::PlayerData::~PlayerData() { diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 9a91744e..50b8ba9e 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -137,6 +137,7 @@ ICustomBody* Level::InitRigidBodyCube( const ObjectHeader* obj) //offset the rigidPosition from modelspace to worldspace; rigidWorldPos = (Oyster::Math::Float3)obj->position + (Oyster::Math::Float3)obj->boundingVolume.box.position; + //scales the position so the collision geomentry is in the right place rigidWorldPos = rigidWorldPos * obj->scale; @@ -182,7 +183,7 @@ ICustomBody* Level::InitRigidBodySphere( const ObjectHeader* obj) rigidBodyMass = obj->scale[0] * obj->scale[1] * obj->scale[2] * obj->boundingVolume.sphere.mass; //Radius scaled - //rigidBodyRadius = (staticObjData->scale[0] * staticObjData->scale[1] * staticObjData->scale[2] / 3) * staticObjData->boundingVolume.sphere.radius; + //rigidBodyRadius = (staticObjData->scale[0] + staticObjData->scale[1] + staticObjData->scale[2] / 3) * staticObjData->boundingVolume.sphere.radius; rigidBodyRadius = (obj->scale[0] * obj->scale[1] * obj->scale[2]) * obj->boundingVolume.sphere.radius; //create the rigid body @@ -230,7 +231,7 @@ void Level::InitiateLevel(std::string levelPath) else if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Box) { - rigidBody_Static = InitRigidBodySphere(staticObjData); + rigidBody_Static = InitRigidBodyCube(staticObjData); } else if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Cylinder) @@ -241,7 +242,8 @@ void Level::InitiateLevel(std::string levelPath) if(rigidBody_Static != NULL) { // create game object - Object* staticGameObj = createGameObj(staticObjData, rigidBody_Static); + //Object* staticGameObj = createGameObj(staticObjData, rigidBody_Static); + Object* staticGameObj = new StaticObject(rigidBody_Static, Object::DefaultCollisionAfter, (ObjectSpecialType)staticObjData->specialTypeID); if(staticGameObj != NULL) { this->staticObjects.Push((StaticObject*)staticGameObj); @@ -278,7 +280,8 @@ void Level::InitiateLevel(std::string levelPath) if(rigidBody_Dynamic != NULL) { // create game object - Object* dynamicGameObj = createGameObj(dynamicObjData, rigidBody_Dynamic); + //Object* dynamicGameObj = createGameObj(dynamicObjData, rigidBody_Dynamic); + Object* dynamicGameObj =new DynamicObject(rigidBody_Dynamic, Object::DefaultCollisionAfter, (ObjectSpecialType)dynamicObjData->specialTypeID); if (dynamicGameObj != NULL) { this->dynamicObjects.Push((DynamicObject*)dynamicGameObj); diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index f6dddb85..12a655da 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -6,7 +6,7 @@ using namespace GameLogic; using namespace Oyster::Physics; -const int MOVE_FORCE = 30; +const float MOVE_FORCE = 30; const float KEY_TIMER = 0.03f; Player::Player() :DynamicObject() @@ -162,8 +162,7 @@ void Player::UseWeapon(const WEAPON_FIRE &usage) } void Player::Respawn(Oyster::Math::Float3 spawnPoint) -{ - key_jump = +{ this->life = 100; this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; this->lookDir = Oyster::Math::Float4(1,0,0); @@ -184,7 +183,7 @@ void Player::Jump() { Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1].GetNormalized(); this->rigidBody->ApplyImpulse(up *1500); - this->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING; + this->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING; } bool Player::IsWalking() From f14a83aef2d8cc20250c1b41d8bbae737ef237bb Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Fri, 14 Feb 2014 10:56:38 +0100 Subject: [PATCH 17/22] GL - Explosivebox now takes a float forceMagnitude instead of a vector --- Code/Game/GameLogic/CollisionManager.cpp | 13 ++++++------ Code/Game/GameLogic/CrystalFormation.cpp | 25 ------------------------ Code/Game/GameLogic/CrystalFormation.h | 22 --------------------- Code/Game/GameLogic/ExplosiveCrate.cpp | 9 ++++----- Code/Game/GameLogic/ExplosiveCrate.h | 7 ++++--- Code/Game/GameLogic/GameLogic.vcxproj | 2 -- Code/Game/GameLogic/GameLogicStates.h | 6 ------ Code/Game/GameLogic/Object.cpp | 8 ++++++++ Code/Game/GameLogic/Object.h | 4 ++++ 9 files changed, 27 insertions(+), 69 deletions(-) delete mode 100644 Code/Game/GameLogic/CrystalFormation.cpp delete mode 100644 Code/Game/GameLogic/CrystalFormation.h diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index e254b93b..80562b2c 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -8,7 +8,6 @@ #include "CollisionManager.h" #include "JumpPad.h" #include "Portal.h" -#include "CrystalFormation.h" #include "ExplosiveCrate.h" using namespace Oyster; @@ -47,7 +46,7 @@ using namespace GameLogic; break; case ObjectSpecialType::ObjectSpecialType_CrystalFormation: - PlayerVLethalObject(*player,*realObj, kineticEnergyLoss,((CrystalFormation*)realObj)->getShreddingDamage()); + PlayerVLethalObject(*player,*realObj, kineticEnergyLoss,realObj->getExtraDamageOnCollision()); //player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; break; } @@ -97,7 +96,6 @@ using namespace GameLogic; int forceThreashHold = 200000; //how much force for the box to explode of the impact - if(kineticEnergyLoss > forceThreashHold) { ExplosiveCrate* crate = ((ExplosiveCrate*)rigidBodyCrate->GetCustomTag()); @@ -117,16 +115,19 @@ using namespace GameLogic; Object *realObj = (Object*)obj->GetCustomTag(); ExplosiveCrate* ExplosionSource = ((ExplosiveCrate*)args); - + Oyster::Math::Float3 explosionCenterPos = ExplosionSource->GetPosition(); + Oyster::Math::Float3 hitObjectPos = obj->GetState().centerPos; + Oyster::Math::Float3 force = (((hitObjectPos- explosionCenterPos).GetNormalized()) * ExplosionSource->pushForceMagnitude); + if(realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_Player) { Player *hitPlayer = (Player*)realObj; - hitPlayer->DamageLife(ExplosionSource->shreddingDamage); + hitPlayer->DamageLife(ExplosionSource->getExtraDamageOnCollision()); //do shredding damage } - realObj->GetRigidBody()->ApplyImpulse(ExplosionSource->pushForce); + realObj->GetRigidBody()->ApplyImpulse(force); } diff --git a/Code/Game/GameLogic/CrystalFormation.cpp b/Code/Game/GameLogic/CrystalFormation.cpp deleted file mode 100644 index e9c6dd73..00000000 --- a/Code/Game/GameLogic/CrystalFormation.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "CrystalFormation.h" - -using namespace GameLogic; - -CrystalFormation::CrystalFormation(void) - :StaticObject() -{ - this->shreddingDamage = 0; -} - -CrystalFormation::CrystalFormation(Oyster::Physics::ICustomBody *rigidBody, int objectID,Oyster::Math::Float shreddingDamage) - :StaticObject(rigidBody, CrystalFormation::DefaultCollisionAfter, ObjectSpecialType::ObjectSpecialType_CrystalFormation, objectID) -{ - this->shreddingDamage = shreddingDamage; -} - - -CrystalFormation::~CrystalFormation(void) -{ -} - -Oyster::Math::Float CrystalFormation::getShreddingDamage() -{ - return this->shreddingDamage; -} diff --git a/Code/Game/GameLogic/CrystalFormation.h b/Code/Game/GameLogic/CrystalFormation.h deleted file mode 100644 index 6e07942b..00000000 --- a/Code/Game/GameLogic/CrystalFormation.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef CRYSTALFORMATION_H -#define CRYSTALFORMATION_H -#include "StaticObject.h" -namespace GameLogic -{ - class CrystalFormation : public StaticObject - { - public: - CrystalFormation(void); - - CrystalFormation(Oyster::Physics::ICustomBody *rigidBody - ,int objectID,Oyster::Math::Float shreddingDamage); - - ~CrystalFormation(void); - - Oyster::Math::Float getShreddingDamage(); - - private: - Oyster::Math::Float shreddingDamage; - }; -} -#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/ExplosiveCrate.cpp b/Code/Game/GameLogic/ExplosiveCrate.cpp index 534fd6bb..d236d400 100644 --- a/Code/Game/GameLogic/ExplosiveCrate.cpp +++ b/Code/Game/GameLogic/ExplosiveCrate.cpp @@ -5,16 +5,15 @@ using namespace GameLogic; ExplosiveCrate::ExplosiveCrate(void) :DynamicObject() { - this->shreddingDamage = 0; - this->pushForce = 0; + this->pushForceMagnitude = 0; this->ExplosionRadius = 0; } -ExplosiveCrate::ExplosiveCrate(Oyster::Physics::ICustomBody *rigidBody,ObjectSpecialType type, int objectID,Oyster::Math::Float shreddingDamage, Oyster::Math::Float3 pushForce, Oyster::Math::Float ExplosionRadius) +ExplosiveCrate::ExplosiveCrate(Oyster::Physics::ICustomBody *rigidBody,ObjectSpecialType type, int objectID,Oyster::Math::Float extraDamageOnCollision, Oyster::Math::Float pushForceMagnitude, Oyster::Math::Float ExplosionRadius) :DynamicObject(rigidBody,ExplosiveCrate::ExplosiveCrateCollision, type, objectID) { - this->shreddingDamage = shreddingDamage; - this->pushForce = pushForce; + this->extraDamageOnCollision = extraDamageOnCollision; + this->pushForceMagnitude = pushForceMagnitude; this->ExplosionRadius = ExplosionRadius; } diff --git a/Code/Game/GameLogic/ExplosiveCrate.h b/Code/Game/GameLogic/ExplosiveCrate.h index 3cf0c9a4..75afdc4a 100644 --- a/Code/Game/GameLogic/ExplosiveCrate.h +++ b/Code/Game/GameLogic/ExplosiveCrate.h @@ -8,7 +8,7 @@ namespace GameLogic public: ExplosiveCrate(void); - ExplosiveCrate(Oyster::Physics::ICustomBody *rigidBody,ObjectSpecialType type,int objectID,Oyster::Math::Float shreddingDamage, Oyster::Math::Float3 pushForce, Oyster::Math::Float ExplosionRadius); + ExplosiveCrate(Oyster::Physics::ICustomBody *rigidBody,ObjectSpecialType type,int objectID,Oyster::Math::Float extraDamageOnCollision, Oyster::Math::Float pushForceMagnitude, Oyster::Math::Float ExplosionRadius); ~ExplosiveCrate(void); @@ -16,9 +16,10 @@ namespace GameLogic static void Explode(Oyster::Physics::ICustomBody *obj, void* args); private: - Oyster::Math::Float shreddingDamage; - Oyster::Math::Float3 pushForce; + Oyster::Math::Float pushForceMagnitude; Oyster::Math::Float ExplosionRadius; }; + + } #endif \ No newline at end of file diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index 48af6d60..6c026917 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -176,7 +176,6 @@ - @@ -204,7 +203,6 @@ - diff --git a/Code/Game/GameLogic/GameLogicStates.h b/Code/Game/GameLogic/GameLogicStates.h index 3e9bcdf5..9ae0d482 100644 --- a/Code/Game/GameLogic/GameLogicStates.h +++ b/Code/Game/GameLogic/GameLogicStates.h @@ -43,12 +43,6 @@ namespace GameLogic Oyster::Math::Float3 pushForce; }; - struct ExplosionData - { - Oyster::Math::Float3 pushForce; - Oyster::Math::Float3 ShreddingDamage; - }; - }; diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index cfd2d255..751dc454 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -28,6 +28,7 @@ Object::Object(Oyster::Physics::ICustomBody *rigidBody, void (*collisionFuncAfte this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter)); this->type = type; this->objectID = objectID; + this->extraDamageOnCollision = 0; this->rigidBody->SetCustomTag(this); } @@ -38,6 +39,7 @@ Object::Object(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICusto this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter)); this->type = type; this->objectID = objectID; + this->extraDamageOnCollision = 0; this->rigidBody->SetCustomTag(this); } @@ -103,4 +105,10 @@ Oyster::Math::Float4x4 Object::GetOrientation() Oyster::Physics::ICustomBody::State state; state = this->rigidBody->GetState(); return state.GetOrientation(); +} + + +Oyster::Math::Float Object::getExtraDamageOnCollision() +{ + return this->extraDamageOnCollision; } \ No newline at end of file diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index 7e7e3f08..73853bd8 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -31,6 +31,8 @@ namespace GameLogic Oyster::Math::Float3 GetScale() override; Oyster::Math::Float4x4 GetOrientation() override; + Oyster::Math::Float getExtraDamageOnCollision(); + // API overrides @@ -58,6 +60,8 @@ namespace GameLogic ObjectSpecialType type; int objectID; + + Oyster::Math::Float extraDamageOnCollision; }; } From c5e4580ada525af9aac93c1af3e54db12a7e41f2 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Fri, 14 Feb 2014 10:59:33 +0100 Subject: [PATCH 18/22] GL - include error fixed --- Code/Game/GameLogic/Level.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 1b0a0e8f..51dd6401 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -2,7 +2,6 @@ #include "CollisionManager.h" #include "Game.h" #include "JumpPad.h" -#include "CrystalFormation.h" #include "ExplosiveCrate.h" #include "Portal.h" using namespace GameLogic; From 8d8fa78da0aa979b7799dae6f4eb949611b6fb64 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Fri, 14 Feb 2014 11:04:01 +0100 Subject: [PATCH 19/22] GL - fixed portal constructor --- Code/Game/GameLogic/Portal.cpp | 4 ++-- Code/Game/GameLogic/Portal.h | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Code/Game/GameLogic/Portal.cpp b/Code/Game/GameLogic/Portal.cpp index 1edd1717..61229256 100644 --- a/Code/Game/GameLogic/Portal.cpp +++ b/Code/Game/GameLogic/Portal.cpp @@ -10,8 +10,8 @@ Portal::Portal(void) } -Portal::Portal(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type,int objectID ,Oyster::Math::Float3 portalExit) - :StaticObject(rigidBody, EventOnCollision, type, objectID) +Portal::Portal(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type,int objectID ,Oyster::Math::Float3 portalExit) + :StaticObject(rigidBody, Portal::PortalActivated, type, objectID) { this->portalExit = portalExit; } diff --git a/Code/Game/GameLogic/Portal.h b/Code/Game/GameLogic/Portal.h index ab88d934..0f228c21 100644 --- a/Code/Game/GameLogic/Portal.h +++ b/Code/Game/GameLogic/Portal.h @@ -8,8 +8,7 @@ namespace GameLogic public: Portal(void); - Portal(Oyster::Physics::ICustomBody *rigidBody - ,void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss) + Portal(Oyster::Physics::ICustomBody *rigidBody ,ObjectSpecialType type,int objectID ,Oyster::Math::Float3 portalExit); ~Portal(void); From 1a01dbd7609b4384de0a70d3d083964dd9f4068e Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Fri, 14 Feb 2014 11:07:03 +0100 Subject: [PATCH 20/22] GL - initiating objects --- Code/Game/GameLogic/Level.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 1b0a0e8f..718ef84a 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -21,7 +21,7 @@ Level::~Level(void) } Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) { - Object* gameObj =NULL; + Object* gameObj = NULL; switch ((ObjectSpecialType)obj->specialTypeID) { @@ -64,8 +64,9 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) case ObjectSpecialType_RedExplosiveBox: { int dmg = 50; - //gameObj = new ExplosiveBox(rigidBody, ObjectSpecialType_RedExplosiveBox); - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++); + Oyster::Math::Float3 force(50, 50,50); + int radie = 50; + gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID,objID++, dmg, force, radie); } break; //case ObjectSpecialType_BlueExplosiveBox: @@ -98,14 +99,14 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) { float power = ((JumpPadAttributes*)obj)->power; Oyster::Math::Float3 dir = ((JumpPadAttributes*)obj)->direction; - //gameObj = JumpPad(rigidBody, ); - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++); + Oyster::Math::Float3 pushForce = dir * power; + gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID,objID++ , pushForce); } break; case ObjectSpecialType_Portal: { Oyster::Math::Float3 destination = ((PortalAttributes*)obj)->destination; - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++); + gameObj = new Portal(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++, destination); } break; case ObjectSpecialType_SpawnPoint: From 975894b0376ae00d4e92260b8037f4d2b7d0ae4a Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Fri, 14 Feb 2014 11:11:49 +0100 Subject: [PATCH 21/22] GL - init objects --- Code/Game/GameLogic/Level.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 31c04e19..6d3de52c 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -26,14 +26,14 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) { case ObjectSpecialType_None: { - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_Sky: { float skySize = ((SkyAttributes*)obj)->skySize; - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_World: @@ -43,29 +43,29 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) float worldSize = ((WorldAttributes*)obj)->worldSize; float atmosphereSize = ((WorldAttributes*)obj)->atmoSphereSize; - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_Building: { - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); } case ObjectSpecialType_Stone: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++); + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_StandardBox: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++); + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_RedExplosiveBox: { int dmg = 50; - Oyster::Math::Float3 force(50, 50,50); + Oyster::Math::Float force = 50; int radie = 50; - gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID,objID++, dmg, force, radie); + gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++, dmg, force, radie); } break; //case ObjectSpecialType_BlueExplosiveBox: @@ -74,24 +74,24 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) // break; case ObjectSpecialType_SpikeBox: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++); + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_Spike: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++); + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_CrystalFormation: { int dmg = 50; //gameObj = new Crystal(rigidBody); - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_CrystalShard: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++); + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_JumpPad: @@ -99,19 +99,19 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) float power = ((JumpPadAttributes*)obj)->power; Oyster::Math::Float3 dir = ((JumpPadAttributes*)obj)->direction; Oyster::Math::Float3 pushForce = dir * power; - gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID,objID++ , pushForce); + gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++ , pushForce); } break; case ObjectSpecialType_Portal: { Oyster::Math::Float3 destination = ((PortalAttributes*)obj)->destination; - gameObj = new Portal(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++, destination); + gameObj = new Portal(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++, destination); } break; case ObjectSpecialType_SpawnPoint: { // save - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_Player: @@ -122,12 +122,12 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) break; case ObjectSpecialType_Generic: { - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); } break; default: { - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); } break; } From 7791dc076eddb5ca868807162ff139834d0f1316 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Fri, 14 Feb 2014 11:16:02 +0100 Subject: [PATCH 22/22] GL - static and dynamic objects can now set extraDamageOnCollision in constructor --- Code/Game/GameLogic/DynamicObject.cpp | 11 +++++++++++ Code/Game/GameLogic/DynamicObject.h | 4 +++- Code/Game/GameLogic/StaticObject.cpp | 11 +++++++++++ Code/Game/GameLogic/StaticObject.h | 3 +++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameLogic/DynamicObject.cpp b/Code/Game/GameLogic/DynamicObject.cpp index 8096b4aa..6df5bef0 100644 --- a/Code/Game/GameLogic/DynamicObject.cpp +++ b/Code/Game/GameLogic/DynamicObject.cpp @@ -21,6 +21,17 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::P } +DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision) + :Object(rigidBody, EventOnCollision, type, objectID) +{ + this->extraDamageOnCollision = extraDamageOnCollision; +} + +DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision) + :Object(rigidBody, EventOnCollision, type, objectID) +{ + this->extraDamageOnCollision = extraDamageOnCollision; +} DynamicObject::~DynamicObject(void) { diff --git a/Code/Game/GameLogic/DynamicObject.h b/Code/Game/GameLogic/DynamicObject.h index 3341e94d..2d5fa617 100644 --- a/Code/Game/GameLogic/DynamicObject.h +++ b/Code/Game/GameLogic/DynamicObject.h @@ -14,9 +14,11 @@ namespace GameLogic public: DynamicObject(); - DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID); + DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID); DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID); + DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision); + DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision); ~DynamicObject(void); diff --git a/Code/Game/GameLogic/StaticObject.cpp b/Code/Game/GameLogic/StaticObject.cpp index 68140cbe..158ee87e 100644 --- a/Code/Game/GameLogic/StaticObject.cpp +++ b/Code/Game/GameLogic/StaticObject.cpp @@ -23,6 +23,17 @@ StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Phy //use setMass(when it is made) and set the mass to 0 in order to ensure that the object is static } +StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision) +{ + this->extraDamageOnCollision = extraDamageOnCollision; + //use setMass(when it is made) and set the mass to 0 in order to ensure that the object is static +} + +StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision) +{ + this->extraDamageOnCollision = extraDamageOnCollision; + //use setMass(when it is made) and set the mass to 0 in order to ensure that the object is static +} StaticObject::~StaticObject(void) { diff --git a/Code/Game/GameLogic/StaticObject.h b/Code/Game/GameLogic/StaticObject.h index a7b9fbff..90b4fc06 100644 --- a/Code/Game/GameLogic/StaticObject.h +++ b/Code/Game/GameLogic/StaticObject.h @@ -21,6 +21,9 @@ namespace GameLogic StaticObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID); StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID); + StaticObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision); + StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision); + ~StaticObject(void); private: