IEnumerator DownLoadBuildingEnum(Transform buildPos) { string msg = "username="******"samplename" + "&location=" + "testlocation0"; using (UnityWebRequest www = UnityWebRequest.Get(url + "getBuild.php?" + msg)) { //www.chunkedTransfer = false; Debug.Log(url + "getBuild.php?" + msg); yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); string defData = "{\"shipName\":\"defaultName\",\"cubeDatas\":[{\"cubeName\":\"Cube0\",\"materialName\":\"Material0\",\"transformDatas\":{\"position\":{\"x\":0.0,\"y\":0.0,\"z\":0.0},\"rotation\":{\"x\":0.0,\"y\":0.0,\"z\":0.0,\"w\":1.0},\"scale\":{\"x\":1.0,\"y\":1.0,\"z\":1.0}}},{\"cubeName\":\"WindowRoom\",\"materialName\":\"Material0\",\"transformDatas\":{\"position\":{\"x\":0.0,\"y\":5.0,\"z\":0.0},\"rotation\":{\"x\":0.0,\"y\":0.0,\"z\":0.0,\"w\":1.0},\"scale\":{\"x\":1.0,\"y\":1.0,\"z\":1.0}}},{\"cubeName\":\"WindowRoom\",\"materialName\":\"Material0\",\"transformDatas\":{\"position\":{\"x\":5.0,\"y\":5.0,\"z\":0.0},\"rotation\":{\"x\":0.0,\"y\":0.0,\"z\":0.0,\"w\":1.0},\"scale\":{\"x\":1.0,\"y\":1.0,\"z\":1.0}}}]}"; HelperFuns.LoadShipFromJson(buildPos, defData, 0.01f); } else { string response = www.downloadHandler.text; Debug.Log(response); respData = response.Split(new[] { "||" }, System.StringSplitOptions.None); //write code to show author name here, the author name is respData[USERNAME] } } }
IEnumerator UploadBuildingEnum(string buildData, string buildName, string userName, string location, string privacy, string avatar) { HelperFuns.WordCenser(ref buildName); WWWForm form = new WWWForm(); form.AddField("buildData", buildData); form.AddField("buildName", buildName); form.AddField("userName", userName); form.AddField("location", location); form.AddField("privacy", privacy); form.AddField("avatar", avatar); //string msg = "buildData=" + "simplestr" + "&buildName=" + buildName + "&userName="******"&location=" + location + "&privacy=" + privacy + "&avatar=" + avatar; Debug.Log(buildData + "\n"); using (UnityWebRequest www = UnityWebRequest.Post(url + "uploadBuild.php", form)) { //www.chunkedTransfer = false; yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { Debug.Log(www.downloadHandler.text); } } }
IEnumerator DownLoadBuildingEnum() { string msg = "download"; using (UnityWebRequest www = UnityWebRequest.Get(url + "addChatMessage.php?message=\n" + msg)) { //www.chunkedTransfer = false; yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { string response = www.downloadHandler.text; Debug.Log(response); string[] respData = response.Split('-'); //load the build on the gaven transform HelperFuns.LoadShipFromJson(buildPos, respData[BUILDDATA]); //write code to show author name here, the author name is respData[USERNAME] } } }
public void LoadShip() { Debug.Log("enterLoad"); Transform theshipTrans = theBulid.transform; HelperFuns.LoadShip(theshipTrans, shipNameInput.text); }
public VCExpr Let(VCExpr body, params VCExprLetBinding[] bindings) { Contract.Requires(body != null); Contract.Requires((cce.NonNullElements(bindings))); Contract.Ensures(Contract.Result <VCExpr>() != null); return(Let(HelperFuns.ToNonNullList(bindings), body)); }
public static bool LoadShip(Transform theShipTrans, string shipName) { string path = Application.persistentDataPath + "/" + shipName + ".json"; Debug.Log(path); if (!File.Exists(path)) { return(false); } foreach (Transform cube in theShipTrans) { MonoBehaviour.Destroy(cube.gameObject); } string json = File.ReadAllText(path); ShipData loadedShipData = JsonUtility.FromJson <ShipData>(json); foreach (CubeData c in loadedShipData.cubeDatas) { GameObject o = (GameObject)MonoBehaviour.Instantiate(Resources.Load(c.cubeName), c.transformDatas.position, c.transformDatas.rotation, theShipTrans); o.transform.localScale = c.transformDatas.scale; //Debug.Log(c.materialName + "<<<<<"); //Debug.Log("Mass>>>>>"+o.GetComponent<PhysicalProperty>().mass); if (Resources.Load(c.materialName)) { //Debug.Log(c.materialName); HelperFuns.SetCubeMaterial(o, (Material)Resources.Load(c.materialName)); } } return(true); }
public VCTrigger Trigger(bool pos, params VCExpr[] exprs) { Contract.Requires(exprs != null); Contract.Requires((Contract.ForAll(0, exprs.Length, i => exprs[i] != null))); Contract.Ensures(Contract.Result <VCTrigger>() != null); return(Trigger(pos, HelperFuns.ToNonNullList(exprs))); }
public VCExpr Exists(VCExprVar var, VCTrigger trigger, VCExpr body) { Contract.Requires(body != null); Contract.Requires(trigger != null); Contract.Requires(var != null); Contract.Ensures(Contract.Result <VCExpr>() != null); return(Exists(HelperFuns.ToNonNullList(var), HelperFuns.ToNonNullList(trigger), body)); }
public VCExpr /*!*/ Function(VCExprOp /*!*/ op, params VCExpr[] /*!*/ arguments) { Contract.Requires(op != null); Contract.Requires(cce.NonNullElements(arguments)); return(Function(op, HelperFuns.ToNonNullList(arguments), VCExprNAry.EMPTY_TYPE_LIST)); }
public VCExpr Store(params VCExpr[] allArgs) { Contract.Requires(allArgs != null); Contract.Requires(cce.NonNullElements(allArgs)); Contract.Ensures(Contract.Result <VCExpr>() != null); return(Function(new VCExprStoreOp(allArgs.Length - 2, 0), HelperFuns.ToNonNullList(allArgs), VCExprNAry.EMPTY_TYPE_LIST)); }
/////////////////////////////////////////////////////////////////////////////// // generate axioms of the kind "forall x:U. {Int2U(U2Int(x))} Int2U(U2Int(x))==x" // (this makes use of the assumption that only well-typed terms are generated // by the SMT-solver, i.e., that U2Int is only applied to terms that actually // are of type int) protected override VCExpr GenReverseCastAxiom(Function castToU, Function castFromU) { //Contract.Requires(castFromU != null); //Contract.Requires(castToU != null); Contract.Ensures(Contract.Result <VCExpr>() != null); VCExpr /*!*/ eq = GenReverseCastEq(castToU, castFromU, out var var, out var triggers); return(Gen.Forall(HelperFuns.ToList(var), triggers, "cast:" + castFromU.Name, 1, eq)); }
public VCExpr /*!*/ Function(VCExprOp /*!*/ op, VCExpr[] /*!*/ arguments, Type[] /*!*/ typeArguments) { Contract.Requires(op != null); Contract.Requires(cce.NonNullElements(arguments)); Contract.Requires(cce.NonNullElements(typeArguments)); Contract.Ensures(Contract.Result <VCExpr>() != null); return(Function(op, HelperFuns.ToNonNullList(arguments), HelperFuns.ToNonNullList(typeArguments))); }
private VCExpr /*!*/ GenMapAxiom0(Function /*!*/ select, Function /*!*/ store, // bound type variables in the map type int mapTypeParamNum, // free type variables in the map // type (abstraction) int mapAbstractionVarNum) { Contract.Requires(select != null); Contract.Requires(store != null); Contract.Ensures(Contract.Result <VCExpr>() != null); int arity = select.InParams.Count - 1 - mapTypeParamNum - mapAbstractionVarNum; List <VCExprVar /*!*/> /*!*/ types = HelperFuns.VarVector("t", mapTypeParamNum + mapAbstractionVarNum, AxBuilder.T, Gen); List <Type /*!*/> indexTypes = new List <Type /*!*/>(); for (int i = mapTypeParamNum + mapAbstractionVarNum + 1; i < select.InParams.Count; i++) { indexTypes.Add(cce.NonNull(select.InParams[i]).TypedIdent.Type); } Contract.Assert(arity == indexTypes.Count); List <VCExprVar /*!*/> /*!*/ indexes = HelperFuns.VarVector("x", indexTypes, Gen); VCExprVar /*!*/ m = Gen.Variable("m", AxBuilder.U); Contract.Assert(m != null); VCExprVar /*!*/ val = Gen.Variable("val", cce.NonNull(select.OutParams[0]).TypedIdent.Type); Contract.Assert(val != null); VCExpr /*!*/ storeExpr = Store(store, types, m, indexes, val); Contract.Assert(storeExpr != null); VCExpr /*!*/ selectExpr = Select(select, types, storeExpr, indexes); Contract.Assert(selectExpr != null); List <VCExprVar /*!*/> /*!*/ quantifiedVars = new List <VCExprVar /*!*/>(); quantifiedVars.AddRange(types); quantifiedVars.Add(val); quantifiedVars.Add(m); quantifiedVars.AddRange(indexes); VCExpr /*!*/ eq = Gen.Eq(selectExpr, val); Contract.Assert(eq != null); return(Gen.Forall(quantifiedVars, new List <VCTrigger /*!*/>(), "mapAx0:" + select.Name, 0, eq)); }
/////////////////////////////////////////////////////////////////////////// // The normal axioms of the theory of arrays (right now without extensionality) private VCExpr Select(Function select, List <VCExprVar /*!*/> /*!*/ types, VCExpr map, List <VCExprVar /*!*/> /*!*/ indexes) { Contract.Requires(map != null); Contract.Requires(select != null); Contract.Requires(cce.NonNullElements(indexes)); Contract.Requires(cce.NonNullElements(types)); Contract.Ensures(Contract.Result <VCExpr>() != null); List <VCExpr /*!*/> /*!*/ selectArgs = new List <VCExpr /*!*/>(); selectArgs.AddRange(HelperFuns.ToVCExprList(types)); selectArgs.Add(map); selectArgs.AddRange(HelperFuns.ToVCExprList(indexes)); return(Gen.Function(select, selectArgs)); }
public Function Typed2Untyped(Function fun) { Contract.Requires(fun != null); Contract.Ensures(Contract.Result <Function>() != null); Function res; if (!Typed2UntypedFunctions.TryGetValue(fun, out res)) { Contract.Assert(fun.OutParams.Count == 1); // if all of the parameters are int or bool, the function does // not have to be changed if (fun.InParams.All(param => UnchangedType(cce.NonNull(param).TypedIdent.Type)) && UnchangedType(cce.NonNull(fun.OutParams[0]).TypedIdent.Type)) { res = fun; } else { Type[] /*!*/ types = new Type[fun.TypeParameters.Count + fun.InParams.Count + 1]; int i = 0; // the first arguments are the explicit type parameters for (int j = 0; j < fun.TypeParameters.Count; ++j) { types[i] = T; i = i + 1; } // followed by the actual parameters foreach (Variable /*!*/ x in fun.InParams) { Contract.Assert(x != null); types[i] = TypeAfterErasure(x.TypedIdent.Type); i = i + 1; } types[types.Length - 1] = TypeAfterErasure(cce.NonNull(fun.OutParams[0]).TypedIdent.Type); res = HelperFuns.BoogieFunction(fun.Name, types); res.Attributes = fun.Attributes; } Typed2UntypedFunctions.Add(fun, res); } return(cce.NonNull(res)); }
public static void LoadShipFromJson(Transform theShipTrans, string json) { ShipData loadedShipData = JsonUtility.FromJson <ShipData>(json); foreach (CubeData c in loadedShipData.cubeDatas) { GameObject o = (GameObject)MonoBehaviour.Instantiate(Resources.Load(c.cubeName), c.transformDatas.position, c.transformDatas.rotation, theShipTrans); o.transform.localScale = c.transformDatas.scale; if (Resources.Load(c.materialName)) { //Debug.Log(c.materialName); HelperFuns.SetCubeMaterial(o, (Material)Resources.Load(c.materialName)); } } }
private Function SelectFun(MapType m, TypeCtorDecl ctorDecl) { var ctorTypeParams = m.FreeVariables.Select(tv => (Type)tv).ToList(); var ctorType = new CtorType(Token.NoToken, ctorDecl, ctorTypeParams); var valueTypes = new List <Type> { ctorType }; valueTypes.AddRange(m.Arguments); valueTypes.Add(m.Result); List <TypeVariable> typeParams = new List <TypeVariable> (m.TypeParameters); typeParams.AddRange(m.FreeVariables); return(HelperFuns.BoogieFunction("select_" + ctorDecl.Name, typeParams, valueTypes.ToArray())); }
private VCExpr Store(Function store, List <VCExprVar /*!*/> /*!*/ types, VCExpr map, List <VCExprVar /*!*/> /*!*/ indexes, VCExpr val) { Contract.Requires(val != null); Contract.Requires(map != null); Contract.Requires(store != null); Contract.Requires(cce.NonNullElements(indexes)); Contract.Requires(cce.NonNullElements(types)); Contract.Ensures(Contract.Result <VCExpr>() != null); List <VCExpr /*!*/> /*!*/ storeArgs = new List <VCExpr /*!*/>(); storeArgs.AddRange(HelperFuns.ToVCExprList(types)); storeArgs.Add(map); storeArgs.AddRange(HelperFuns.ToVCExprList(indexes)); storeArgs.Add(val); return(Gen.Function(store, storeArgs)); }
IEnumerator DownLoadBuildingEnum(Transform buildPos) { string msg = "username="******"&location=" + currLocation; using (UnityWebRequest www = UnityWebRequest.Get(url + "getBuild.php?" + msg)) { Debug.Log(url + "getBuild.php?" + msg); yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { string response = www.downloadHandler.text; Debug.Log(response); respData = response.Split(new[] { "||" }, System.StringSplitOptions.None); /*load the build on the gaven transform, the third arguement is the scale of * the build, initial block demision is 5m*5m*5m */ respData[0] = HelperFuns.jsonParse(respData[0], false); Debug.Log(respData[0] + "\n'"); try { HelperFuns.LoadShipFromJson(buildPos, respData[0], 0.01f); //code to show author name, buildname and upvotes buildNameText.text = respData[BUILDNAME]; authorNameText.text = respData[AUTHORNAME]; upvoteButton.GetComponent <Text>().text = respData[UPVOTES]; int avatarIndex = 0; int.TryParse(respData[AVATAR], out avatarIndex); avatar = avatars[avatarIndex]; } finally { //add code here. When there is no buildings in the database, show a notifucation } } } }
IEnumerator TestUpvoteEnum() { string defData = "{\"shipName\":\"defaultName\",\"cubeDatas\":[{\"cubeName\":\"Cube0\",\"materialName\":\"Material0\",\"transformDatas\":{\"position\":{\"x\":0.0,\"y\":0.0,\"z\":0.0},\"rotation\":{\"x\":0.0,\"y\":0.0,\"z\":0.0,\"w\":1.0},\"scale\":{\"x\":1.0,\"y\":1.0,\"z\":1.0}}},{\"cubeName\":\"WindowRoom\",\"materialName\":\"Material0\",\"transformDatas\":{\"position\":{\"x\":0.0,\"y\":5.0,\"z\":0.0},\"rotation\":{\"x\":0.0,\"y\":0.0,\"z\":0.0,\"w\":1.0},\"scale\":{\"x\":1.0,\"y\":1.0,\"z\":1.0}}},{\"cubeName\":\"WindowRoom\",\"materialName\":\"Material0\",\"transformDatas\":{\"position\":{\"x\":5.0,\"y\":5.0,\"z\":0.0},\"rotation\":{\"x\":0.0,\"y\":0.0,\"z\":0.0,\"w\":1.0},\"scale\":{\"x\":1.0,\"y\":1.0,\"z\":1.0}}}]}"; defData = HelperFuns.jsonParse(defData, true); //yield return StartCoroutine(UploadBuildingEnum(defData, "upvoteTest", "samplename", "testlocation0", "0", "0")); yield return(StartCoroutine(DownLoadBuildingEnum(theBuild.transform))); int initUpvote; if (int.TryParse(respData[UPVOTES], out initUpvote)) { Debug.Log("initupvote: " + initUpvote); } else { Debug.Log("upvote test failed: downloading request error"); } yield return(StartCoroutine(UpvoteEnum())); Debug.Log("downloading upvoted building"); yield return(StartCoroutine(DownLoadBuildingEnum(theBuild.transform))); int upvote; if (int.TryParse(respData[UPVOTES], out upvote)) { Debug.Log("upvotes after upvote: " + upvote); if (upvote - initUpvote == 1) { Debug.Log("upvotetest pass"); } else { Debug.Log("upvote test failed: upvotes not updating"); } } else { Debug.Log("upvote test failed: downloading request error"); } }
private VCExpr /*!*/ GenMapAxiom1(Function /*!*/ select, Function /*!*/ store, // bound type variables in the map // type int mapTypeParamNum, // free type variables in the map // type (abstraction) int mapAbstractionVarNum) { Contract.Requires(select != null); Contract.Requires(store != null); Contract.Ensures(Contract.Result <VCExpr>() != null); int arity = select.InParams.Count - 1 - mapTypeParamNum - mapAbstractionVarNum; List <VCExprVar /*!*/> /*!*/ freeTypeVars = HelperFuns.VarVector("u", mapAbstractionVarNum, AxBuilder.T, Gen); List <VCExprVar /*!*/> /*!*/ boundTypeVars0 = HelperFuns.VarVector("s", mapTypeParamNum, AxBuilder.T, Gen); List <VCExprVar /*!*/> /*!*/ boundTypeVars1 = HelperFuns.VarVector("t", mapTypeParamNum, AxBuilder.T, Gen); List <VCExprVar /*!*/> /*!*/ types0 = new List <VCExprVar /*!*/>(boundTypeVars0); types0.AddRange(freeTypeVars); List <VCExprVar /*!*/> /*!*/ types1 = new List <VCExprVar /*!*/>(boundTypeVars1); types1.AddRange(freeTypeVars); List <Type /*!*/> indexTypes = new List <Type /*!*/>(); for (int i = mapTypeParamNum + mapAbstractionVarNum + 1; i < select.InParams.Count; i++) { indexTypes.Add(cce.NonNull(select.InParams[i]).TypedIdent.Type); } Contract.Assert(arity == indexTypes.Count); List <VCExprVar /*!*/> /*!*/ indexes0 = HelperFuns.VarVector("x", indexTypes, Gen); List <VCExprVar /*!*/> /*!*/ indexes1 = HelperFuns.VarVector("y", indexTypes, Gen); VCExprVar /*!*/ m = Gen.Variable("m", AxBuilder.U); Contract.Assert(m != null); VCExprVar /*!*/ val = Gen.Variable("val", cce.NonNull(select.OutParams[0]).TypedIdent.Type); Contract.Assert(val != null); VCExpr /*!*/ storeExpr = Store(store, types0, m, indexes0, val); Contract.Assert(storeExpr != null); VCExpr /*!*/ selectWithoutStoreExpr = Select(select, types1, m, indexes1); Contract.Assert(selectWithoutStoreExpr != null); VCExpr /*!*/ selectExpr = Select(select, types1, storeExpr, indexes1); Contract.Assert(selectExpr != null); VCExpr /*!*/ selectEq = Gen.Eq(selectExpr, selectWithoutStoreExpr); Contract.Assert(selectEq != null); List <VCExprVar /*!*/> /*!*/ quantifiedVars = new List <VCExprVar /*!*/>(); quantifiedVars.AddRange(freeTypeVars); quantifiedVars.AddRange(boundTypeVars0); quantifiedVars.AddRange(boundTypeVars1); quantifiedVars.Add(val); quantifiedVars.Add(m); quantifiedVars.AddRange(indexes0); quantifiedVars.AddRange(indexes1); List <VCTrigger /*!*/> /*!*/ triggers = new List <VCTrigger /*!*/>(); // different value arguments or different type arguments are sufficient // to conclude that that value of the map at some point (after an update) // has not changed List <VCExpr /*!*/> /*!*/ indexEqs = new List <VCExpr /*!*/>(); for (int i = 0; i < mapTypeParamNum; ++i) { indexEqs.Add(Gen.Eq(boundTypeVars0[i], boundTypeVars1[i])); } for (int i = 0; i < arity; ++i) { indexEqs.Add(Gen.Eq(indexes0[i], indexes1[i])); } VCExpr /*!*/ axiom = VCExpressionGenerator.True; int n = 0; foreach (VCExpr /*!*/ indexesEq in indexEqs) { Contract.Assert(indexesEq != null); VCExpr /*!*/ matrix = Gen.Or(indexesEq, selectEq); Contract.Assert(matrix != null); VCExpr /*!*/ conjunct = Gen.Forall(quantifiedVars, triggers, "mapAx1:" + select.Name + ":" + n, 0, matrix); Contract.Assert(conjunct != null); axiom = Gen.AndSimp(axiom, conjunct); n = n + 1; } return(axiom); }
//////////////////////////////////////////////////////////////////////////// protected override void GenSelectStoreFunctions(MapType abstractedType, TypeCtorDecl synonym, out Function /*!*/ select, out Function /*!*/ store) { //Contract.Requires(synonym != null); //Contract.Requires(abstractedType != null); Contract.Ensures(Contract.ValueAtReturn(out select) != null); Contract.Ensures(Contract.ValueAtReturn(out store) != null); Contract.Assert(synonym.Name != null); string /*!*/ baseName = synonym.Name; int typeParamNum = abstractedType.FreeVariables.Count + abstractedType.TypeParameters.Count; int arity = typeParamNum + abstractedType.Arguments.Count; Type /*!*/[] /*!*/ selectTypes = new Type /*!*/ [arity + 2]; Type /*!*/[] /*!*/ storeTypes = new Type /*!*/ [arity + 3]; int i = 0; // Fill in the free variables and type parameters for (; i < typeParamNum; i++) { selectTypes[i] = AxBuilder.T; storeTypes[i] = AxBuilder.T; } // Fill in the map type selectTypes[i] = AxBuilder.U; storeTypes[i] = AxBuilder.U; i++; // Fill in the index types foreach (Type /*!*/ type in abstractedType.Arguments) { Contract.Assert(type != null); selectTypes[i] = AxBuilder.U; storeTypes[i] = AxBuilder.U; i++; } // Fill in the output type for select function which also happens // to be the type of the last argument to the store function selectTypes[i] = AxBuilder.U; storeTypes[i] = AxBuilder.U; i++; // Fill in the map type which is the output of the store function storeTypes[i] = AxBuilder.U; Contract.Assert(cce.NonNullElements <Type>(selectTypes)); Contract.Assert(cce.NonNullElements <Type>(storeTypes)); select = HelperFuns.BoogieFunction(baseName + "Select", selectTypes); store = HelperFuns.BoogieFunction(baseName + "Store", storeTypes); if (CommandLineOptions.Clo.UseArrayTheory) { select.AddAttribute("builtin", "select"); store.AddAttribute("builtin", "store"); } else { AxBuilder.AddTypeAxiom(GenMapAxiom0(select, store, abstractedType.TypeParameters.Count, abstractedType.FreeVariables.Count)); AxBuilder.AddTypeAxiom(GenMapAxiom1(select, store, abstractedType.TypeParameters.Count, abstractedType.FreeVariables.Count)); } }