diff --git a/Makefile b/Makefile index 8ed49c2..ee13a83 100644 --- a/Makefile +++ b/Makefile @@ -161,6 +161,7 @@ build/src/scene/elevator.o: build/assets/models/props/round_elevator_collision.h # MODEL_LIST = assets/models/cube/cube.blend \ + assets/models/player/chell.blend \ assets/models/portal_gun/v_portalgun.blend \ assets/models/portal_gun/w_portalgun.blend \ assets/models/props/button.blend \ diff --git a/assets/materials/chell.smk.yaml b/assets/materials/chell.smk.yaml new file mode 100644 index 0000000..d75a437 --- /dev/null +++ b/assets/materials/chell.smk.yaml @@ -0,0 +1,135 @@ +materials: + chell_face: + gDPSetTile: + filename: ./models/player/chell_face.png + siz: G_IM_SIZ_16b + + gDPSetCombineMode: G_CC_MODULATEI + gDPSetCycleType: G_CYC_1CYCLE + + gSPGeometryMode: + set: [G_LIGHTING, G_SHADE] + + chell_head: + gDPSetTile: + filename: ./models/player/chell_head.png + siz: G_IM_SIZ_16b + + gDPSetCombineMode: G_CC_MODULATEI + gDPSetCycleType: G_CYC_1CYCLE + + gSPGeometryMode: + set: [G_LIGHTING, G_SHADE] + + chell_pants: + gDPSetTile: + filename: ./models/player/chell_pants.png + siz: G_IM_SIZ_16b + + gDPSetCombineMode: G_CC_MODULATEI + gDPSetCycleType: G_CYC_1CYCLE + + gSPGeometryMode: + set: [G_LIGHTING, G_SHADE] + + chell_shirt: + gDPSetTile: + filename: ./models/player/chell_shirt.png + siz: G_IM_SIZ_16b + + gDPSetCombineMode: G_CC_MODULATEI + gDPSetCycleType: G_CYC_1CYCLE + + gSPGeometryMode: + set: [G_LIGHTING, G_SHADE] + + chell_neck: + gDPSetCombineMode: + color: [PRIMITIVE, "0", SHADE, "0"] + alpha: ["0", "0", "0", PRIMITIVE] + gDPSetCycleType: G_CYC_1CYCLE + + gDPSetPrimColor: + r: 184 + g: 127 + b: 101 + a: 255 + + gSPGeometryMode: + set: [G_LIGHTING, G_SHADE] + + chell_arm: + gDPSetTile: + filename: ./models/player/chell_shirt.png + siz: G_IM_SIZ_16b + + gDPSetCombineMode: + color: [PRIMITIVE, "0", SHADE, "0"] + alpha: ["0", "0", "0", PRIMITIVE] + gDPSetCycleType: G_CYC_1CYCLE + + gDPSetPrimColor: + r: 184 + g: 127 + b: 101 + a: 255 + + gSPGeometryMode: + set: [G_LIGHTING, G_SHADE] + + chell_leg: + gDPSetTile: + filename: ./models/player/chell_pants.png + siz: G_IM_SIZ_16b + + gDPSetCombineMode: + color: [PRIMITIVE, "0", SHADE, "0"] + alpha: ["0", "0", "0", PRIMITIVE] + gDPSetCycleType: G_CYC_1CYCLE + + gDPSetPrimColor: + r: 184 + g: 127 + b: 101 + a: 255 + + gSPGeometryMode: + set: [G_LIGHTING, G_SHADE] + + chell_boots_white: + gDPSetTile: + filename: ./models/player/chell_pants.png + siz: G_IM_SIZ_16b + + gDPSetCombineMode: + color: [PRIMITIVE, "0", SHADE, "0"] + alpha: ["0", "0", "0", PRIMITIVE] + gDPSetCycleType: G_CYC_1CYCLE + + gDPSetPrimColor: + r: 220 + g: 220 + b: 220 + a: 255 + + gSPGeometryMode: + set: [G_LIGHTING, G_SHADE] + + chell_boots_black: + gDPSetTile: + filename: ./models/player/chell_pants.png + siz: G_IM_SIZ_16b + + gDPSetCombineMode: + color: [PRIMITIVE, "0", SHADE, "0"] + alpha: ["0", "0", "0", PRIMITIVE] + gDPSetCycleType: G_CYC_1CYCLE + + gDPSetPrimColor: + r: 20 + g: 20 + b: 20 + a: 20 + + gSPGeometryMode: + set: [G_LIGHTING, G_SHADE] \ No newline at end of file diff --git a/assets/materials/models/player/chell_face.png b/assets/materials/models/player/chell_face.png new file mode 100755 index 0000000..eacc0ad Binary files /dev/null and b/assets/materials/models/player/chell_face.png differ diff --git a/assets/materials/models/player/chell_head.png b/assets/materials/models/player/chell_head.png new file mode 100755 index 0000000..4bf2863 Binary files /dev/null and b/assets/materials/models/player/chell_head.png differ diff --git a/assets/materials/models/player/chell_pants.png b/assets/materials/models/player/chell_pants.png new file mode 100755 index 0000000..be28695 Binary files /dev/null and b/assets/materials/models/player/chell_pants.png differ diff --git a/assets/materials/models/player/chell_shirt.png b/assets/materials/models/player/chell_shirt.png new file mode 100755 index 0000000..19655cc Binary files /dev/null and b/assets/materials/models/player/chell_shirt.png differ diff --git a/assets/models/player/chell.blend b/assets/models/player/chell.blend new file mode 100644 index 0000000..e13f187 Binary files /dev/null and b/assets/models/player/chell.blend differ diff --git a/assets/models/player/chell.flags b/assets/models/player/chell.flags new file mode 100644 index 0000000..19104f9 --- /dev/null +++ b/assets/models/player/chell.flags @@ -0,0 +1 @@ +-m assets/materials/static.skm.yaml -m assets/materials/chell.skm.yaml --default-material default \ No newline at end of file diff --git a/skelatool64/src/RenderChunkOrder.cpp b/skelatool64/src/RenderChunkOrder.cpp index 4c177b6..e5e75f4 100644 --- a/skelatool64/src/RenderChunkOrder.cpp +++ b/skelatool64/src/RenderChunkOrder.cpp @@ -8,6 +8,19 @@ #include #include +EstimatedTime::EstimatedTime(): materialSwitching(0.0), matrixSwitching(0.0) { + +} + +EstimatedTime::EstimatedTime(double total, double materialSwitching, double matrixSwitching): + materialSwitching(materialSwitching), matrixSwitching(matrixSwitching) { + +} + +double EstimatedTime::GetTotal() const { + return matrixSwitching + materialSwitching; +} + struct RenderChunkPath { RenderChunkPath(int size); @@ -64,6 +77,8 @@ struct RenderChunkDistanceGraph { RenderChunkDistanceGraph(int numberOfEdges); std::vector edgeDistance; + std::vector materialDistance; + std::vector matrixDistance; std::vector minDistanceTo; std::vector maxDistanceTo; double bestWorstCase; @@ -72,7 +87,9 @@ struct RenderChunkDistanceGraph { std::priority_queue, std::vector>, RenderChunkPathCompare> currentChunks; double GetDistance(int from, int to) const; - void SetDistance(int from, int to, double value); + double GetMaterialDistance(int from, int to) const; + double GetMatrixDistance(int from, int to) const; + void SetDistance(int from, int to, struct EstimatedTime estimatedTime); std::shared_ptr currentBest; }; @@ -82,6 +99,8 @@ RenderChunkDistanceGraph::RenderChunkDistanceGraph(int numberOfEdges) : numberOfEdges(numberOfEdges), currentBest(nullptr) { edgeDistance.resize(numberOfEdges * numberOfEdges); + materialDistance.resize(numberOfEdges * numberOfEdges); + matrixDistance.resize(numberOfEdges * numberOfEdges); maxDistanceTo.resize(numberOfEdges); minDistanceTo.resize(numberOfEdges); } @@ -91,8 +110,18 @@ double RenderChunkDistanceGraph::GetDistance(int from, int to) const { return edgeDistance[from * numberOfEdges + to]; } -void RenderChunkDistanceGraph::SetDistance(int from, int to, double value) { - edgeDistance[from * numberOfEdges + to] = value; +double RenderChunkDistanceGraph::GetMaterialDistance(int from, int to) const{ + return materialDistance[from * numberOfEdges + to]; +} + +double RenderChunkDistanceGraph::GetMatrixDistance(int from, int to) const { + return matrixDistance[from * numberOfEdges + to]; +} + +void RenderChunkDistanceGraph::SetDistance(int from, int to, struct EstimatedTime estimatedTime) { + edgeDistance[from * numberOfEdges + to] = estimatedTime.GetTotal(); + materialDistance[from * numberOfEdges + to] = estimatedTime.materialSwitching; + matrixDistance[from * numberOfEdges + to] = estimatedTime.matrixSwitching; } void orderRenderGreedy(struct RenderChunkDistanceGraph& graph, struct RenderChunkPath& path); @@ -179,6 +208,8 @@ void orderRenderBnB(struct RenderChunkDistanceGraph& graph, int maxIterations) { orderRenderGreedy(graph, *graph.currentBest); graph.bestWorstCase = graph.currentBest->worstCase; + double greedyLength = graph.currentBest->currentLength; + orderRenderPopulateNext(graph, first); int iteration = 0; @@ -195,6 +226,12 @@ void orderRenderBnB(struct RenderChunkDistanceGraph& graph, int maxIterations) { iteration += 1; } + + if (graph.currentBest->currentLength == greedyLength) { + std::cout << "Branch and bound could not find a better solution" << std::endl; + } else { + std::cout << "Branch and bound found a solution better by " << (graph.currentBest->currentLength / greedyLength) << std::endl; + } } void orderRenderGreedy(struct RenderChunkDistanceGraph& graph, struct RenderChunkPath& path) { @@ -242,11 +279,11 @@ void orderRenderGreedy(struct RenderChunkDistanceGraph& graph, struct RenderChun path.worstCase = path.currentLength; } -double orderRenderDistance(const RenderChunk& from, const RenderChunk& to) { - double result = 0.0; +struct EstimatedTime orderRenderDistance(const RenderChunk& from, const RenderChunk& to) { + struct EstimatedTime result; if (from.mMaterial && to.mMaterial) { - result += materialTransitionTime(from.mMaterial->mState, to.mMaterial->mState); + result.materialSwitching += materialTransitionTime(from.mMaterial->mState, to.mMaterial->mState); }; Bone* ancestor = Bone::FindCommonAncestor(from.mBonePair.second, to.mBonePair.first); @@ -268,10 +305,10 @@ double orderRenderDistance(const RenderChunk& from, const RenderChunk& to) { } if (fromBoneHeight) { - result += TIMING_DP_MATRIX_POP; + result.matrixSwitching += TIMING_DP_MATRIX_POP; } - result += toBoneHeight * TIMING_DP_MATRIX_MUL; + result.matrixSwitching += toBoneHeight * TIMING_DP_MATRIX_MUL; return result; } @@ -330,9 +367,11 @@ void orderRenderChunks(std::vector& chunks, const DisplayListSettin continue;; } - double distance = orderRenderDistance(chunks[from], chunks[to]); + EstimatedTime time = orderRenderDistance(chunks[from], chunks[to]); - graph.SetDistance(from, to, distance); + graph.SetDistance(from, to, time); + + double distance = time.GetTotal(); if (from == 0 || distance < graph.minDistanceTo[to]) { graph.minDistanceTo[to] = distance; diff --git a/skelatool64/src/RenderChunkOrder.h b/skelatool64/src/RenderChunkOrder.h index b6ad8cf..10646a4 100644 --- a/skelatool64/src/RenderChunkOrder.h +++ b/skelatool64/src/RenderChunkOrder.h @@ -6,6 +6,16 @@ #include "CFileDefinition.h" #include "DisplayListSettings.h" +struct EstimatedTime { + EstimatedTime(); + EstimatedTime(double total, double materialSwitching, double matrixSwitching); + + double GetTotal() const; + + double materialSwitching; + double matrixSwitching; +}; + void orderRenderChunks(std::vector& chunks, const DisplayListSettings& settings); #endif \ No newline at end of file