From 991639709c4284f5d659856e987801daaa572dc0 Mon Sep 17 00:00:00 2001 From: juanjp600 Date: Mon, 25 Mar 2019 10:57:38 -0300 Subject: [PATCH] (2da6c898b) Added 'pretty' merge script --- .../BarotraumaClient/Source/Map/Hull.cs | 52 ++++-- .../BarotraumaServer/Source/Map/Hull.cs | 4 +- .../BarotraumaShared/Source/Map/FireSource.cs | 26 +-- .../Source/Networking/NetConfig.cs | 2 +- git-strip-merge-pretty | 164 ++++++++++++++++++ 5 files changed, 224 insertions(+), 24 deletions(-) create mode 100644 git-strip-merge-pretty diff --git a/Barotrauma/BarotraumaClient/Source/Map/Hull.cs b/Barotrauma/BarotraumaClient/Source/Map/Hull.cs index 8dc7700f0..f295160c6 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Hull.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Hull.cs @@ -1,13 +1,14 @@ using Barotrauma.Networking; using Barotrauma.Particles; using Barotrauma.Sounds; -using Lidgren.Network; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using System; using System.Collections.Generic; +using Microsoft.Xna.Framework.Input; using System.Linq; +using Lidgren.Network; namespace Barotrauma { @@ -18,8 +19,6 @@ namespace Barotrauma private List decals = new List(); private float serverUpdateDelay; - private float remoteWaterVolume, remoteOxygenPercentage; - private List remoteFireSources; private bool networkUpdatePending; private float networkUpdateTimer; @@ -140,10 +139,6 @@ namespace Barotrauma partial void UpdateProjSpecific(float deltaTime, Camera cam) { serverUpdateDelay -= deltaTime; - if (serverUpdateDelay <= 0.0f) - { - ApplyRemoteState(); - } if (networkUpdatePending) { @@ -552,18 +547,18 @@ namespace Barotrauma public void ClientRead(ServerNetObject type, NetBuffer message, float sendingTime) { - remoteWaterVolume = message.ReadRangedSingle(0.0f, 1.5f, 8) * Volume; - remoteOxygenPercentage = message.ReadRangedSingle(0.0f, 100.0f, 8); + float newWaterVolume = message.ReadRangedSingle(0.0f, 1.5f, 8) * Volume; + float newOxygenPercentage = message.ReadRangedSingle(0.0f, 100.0f, 8); bool hasFireSources = message.ReadBoolean(); int fireSourceCount = 0; - remoteFireSources = new List(); + List newFireSources = new List(); if (hasFireSources) { fireSourceCount = message.ReadRangedInteger(0, 16); for (int i = 0; i < fireSourceCount; i++) { - remoteFireSources.Add(new Vector3( + newFireSources.Add(new Vector3( MathHelper.Clamp(message.ReadRangedSingle(0.0f, 1.0f, 8), 0.05f, 0.95f), MathHelper.Clamp(message.ReadRangedSingle(0.0f, 1.0f, 8), 0.05f, 0.95f), message.ReadRangedSingle(0.0f, 1.0f, 8))); @@ -572,6 +567,41 @@ namespace Barotrauma if (serverUpdateDelay > 0.0f) { return; } + WaterVolume = newWaterVolume; + OxygenPercentage = newOxygenPercentage; + + for (int i = 0; i < fireSourceCount; i++) + { + Vector2 pos = new Vector2( + rect.X + rect.Width * newFireSources[i].X, + rect.Y - rect.Height + (rect.Height * newFireSources[i].Y)); + float size = newFireSources[i].Z * rect.Width; + + var newFire = i < FireSources.Count ? + FireSources[i] : + new FireSource(Submarine == null ? pos : pos + Submarine.Position, null, true); + newFire.Position = pos; + newFire.Size = new Vector2(size, newFire.Size.Y); + + //ignore if the fire wasn't added to this room (invalid position)? + if (!FireSources.Contains(newFire)) + { + newFire.Remove(); + continue; + } + } + + for (int i = FireSources.Count - 1; i >= fireSourceCount; i--) + { + FireSources[i].Remove(); + if (i < FireSources.Count) + { + FireSources.RemoveAt(i); + } + } + + if (serverUpdateDelay > 0.0f) { return; } + ApplyRemoteState(); } diff --git a/Barotrauma/BarotraumaServer/Source/Map/Hull.cs b/Barotrauma/BarotraumaServer/Source/Map/Hull.cs index 5f9257b42..907ba6f45 100644 --- a/Barotrauma/BarotraumaServer/Source/Map/Hull.cs +++ b/Barotrauma/BarotraumaServer/Source/Map/Hull.cs @@ -31,8 +31,8 @@ namespace Barotrauma GameMain.NetworkMember.CreateEntityEvent(this); lastSentVolume = waterVolume; lastSentOxygen = OxygenPercentage; - sendUpdateTimer = NetConfig.HullUpdateInterval; - } + sendUpdateTimer = NetworkUpdateInterval; + } } } diff --git a/Barotrauma/BarotraumaShared/Source/Map/FireSource.cs b/Barotrauma/BarotraumaShared/Source/Map/FireSource.cs index c252c399a..83ea002c0 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/FireSource.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/FireSource.cs @@ -175,11 +175,12 @@ namespace Barotrauma LimitSize(); UpdateProjSpecific(growModifier); - - if (size.X < 1.0f && (GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer)) - { - Remove(); - } + +#if CLIENT + if (GameMain.Client != null) return; +#endif + + if (size.X < 1.0f) Remove(); } partial void UpdateProjSpecific(float growModifier); @@ -292,6 +293,10 @@ namespace Barotrauma //evaporate some of the water hull.WaterVolume -= extinguishAmount; +#if CLIENT + if (GameMain.Client != null) return; +#endif + if (size.X < 1.0f && (GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer)) { Remove(); @@ -320,11 +325,12 @@ namespace Barotrauma size.X -= extinguishAmount; hull.WaterVolume -= extinguishAmount; - - if (size.X < 1.0f && (GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer)) - { - Remove(); - } + +#if CLIENT + if (GameMain.Client != null) return; +#endif + + if (size.X < 1.0f) Remove(); } public void Extinguish(float deltaTime, float amount, Vector2 worldPosition) diff --git a/Barotrauma/BarotraumaShared/Source/Networking/NetConfig.cs b/Barotrauma/BarotraumaShared/Source/Networking/NetConfig.cs index 219b4d55e..2e2d01dc0 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/NetConfig.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/NetConfig.cs @@ -35,8 +35,8 @@ namespace Barotrauma.Networking public const float DeleteDisconnectedTime = 20.0f; public const float ItemConditionUpdateInterval = 0.15f; + public const float LevelObjectUpdateInterval = 0.5f; - public const float HullUpdateInterval = 0.5f; public const int MaxEventPacketsPerUpdate = 4; diff --git a/git-strip-merge-pretty b/git-strip-merge-pretty new file mode 100644 index 000000000..50f715efc --- /dev/null +++ b/git-strip-merge-pretty @@ -0,0 +1,164 @@ +#!/usr/bin/env bash +# +# git-strip-merge - a git-merge that delete files on branch before merging +# +# Copyright (C) 2012 Rodrigo Silva (MestreLion) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not see +# +# Answer for "How to setup a git driver to ignore a folder on merge?" +# See http://stackoverflow.com/questions/3111515 + +#Defaults: +msgcommit="remove files from '' before merge" +msgmerge="Merge stripped branch ''" +verbose=0 +quiet=(--quiet) + +usage() { + cat <<- USAGE + Usage: $myname [git-merge options] [-M ] FILE... + USAGE + if [[ "$1" ]] ; then + cat >&2 <<- USAGE + Try '$myname --help' for more information. + USAGE + exit 1 + fi + cat <<-USAGE + git-merge that delete files on "foreign" before merging + Useful for ignoring a folder in before merging it with + current branch. Works by deleting FILE(S) in a detached commit based + on , and then performing the merge of this new commit in the + current branch. Note that is not changed by this procedure. + Also note that may actually be any reference, like a tag, + or a remote branch, or even a commit SHA. + For more information, see + Options: + -h, --help + show this page. + -v, --verbose + do not use -q to suppress normal output of internal steps from git + checkout, rm, commit. By default, only git merge output is shown. + Errors, however, are never suppressed + -M , --msgcommit= + message for the removal commit in . Not to be confused + with the message of the merge commit, which is set by -m. Default + message is: "$msgcommit" + -m , --message= + message for the merge commit. Since we are not merging + directly, but rather a detached commit based on it, we forge a + message similar to git's default for a branch merge. Otherwise + git would use in message the full and ugly SHA1 of our commit. + Default message is: "$msgmerge" + For both commit messages, the token "" is replaced for the + actual name. + Additional options are passed unchecked to git merge. + All options must precede and FILE(s), except -h and --help + that may appear anywhere on the command line. + Example: + $myname design "photoshop/*" + Copyright (C) 2012 Rodrigo Silva (MestreLion) + License: GPLv3 or later. See + USAGE + exit 0 +} + +# Helper functions +myname="${0##*/}" +argerr() { printf "%s: %s\n" "${0##*/}" "${1:-error}" >&2 ; usage 1 ; } +invalid() { argerr "invalid option: $1" ; } +missing() { argerr "missing ${2:+$2 }operand${1:+ from $1}." ; } + +# Option handling +files=() +mergeopts=() +for arg in "$@"; do case "$arg" in -h|--help) usage ;; esac; done +while (( $# )); do + case "$1" in + -v|--verbose ) verbose=1 ;; + -M ) shift ; msgcommit=$1 ;; + -m ) shift ; msgmerge=$1 ;; + --msgcommit=* ) msgcommit=${1#*=} ;; + --message=* ) msgmerge=${1#*=} ;; + -* ) mergeopts+=( "$1" ) ;; + * ) branch="$1" + shift ; break ;; + esac + shift +done +files+=( "$@" ) + +# Argument handling + +msgcommit=${msgcommit///$branch} +msgmerge=${msgmerge///$branch} + +[[ "$msgcommit" ]] || missing "msgcommit" "MSG" +[[ "$branch" ]] || missing "" "" +(( ${#files[@]} )) || missing "" "FILE" + +((verbose)) && quiet=() + +# Here the fun begins... +gitsha() { git rev-parse "$1" ; } +gitbranch() { + git symbolic-ref "$1" 2> /dev/null | sed 's/refs\/heads\///' || + gitsha "$1" +} + +original=$(gitbranch HEAD) +branchsha=$(gitsha "$branch") +branchshortsha="${branchsha:0:7}" + +#get the hash of the last merged remote commit from the latest commit msg in this repo +#assumes that the commit message starts with hash1...hash2 +prevcommitmsg="$(git log -1 --pretty=%B)" +prevcommitsha="${prevcommitmsg:10:7}" + +#create a commit message for out new "merge commit" +# hash1...hash2 + logs of the merged commits +logmsg="$(git log "$prevcommitsha"..."$branchsha" --pretty=oneline --abbrev-commit --reverse)" + +rm -rf temp.txt + +echo "$logmsg" >> "temp.txt" + +trap 'git checkout --quiet "$original"' EXIT + +while read p; do + currHash="$(echo ${p%% *})" + echo "$currHash" + + currMsg="$(echo ${p#* })" + echo "$currMsg" + + echo "" + echo "********" + + git checkout "$currHash" "${quiet[@]}" && + git rm -rf -r "${files[@]}" "${quiet[@]}" && + git commit -m "$msgcommit" "${quiet[@]}" && + newsha=$(gitsha HEAD) && + git checkout "$original" "${quiet[@]}" && + + git merge -m "$msgmerge" -X theirs "--squash" "$newsha" + git checkout HEAD .gitignore + git commit -m "$currMsg" +done < "temp.txt" + +rm -rf temp.txt + +#example usage +#./git-strip-merge-pretty barotrauma-development/dev -f Barotrauma/BarotraumaShared/Content/*