Esempio n. 1
0
        public bool Enq(Interaction interactionAdd)           //Enqueue
        {
            string sVerb = "before starting to add interaction";

            if (!IsFull)
            {
                sVerb = "after finding space in add interaction";
                try {
                    if (interactionAdd != null)
                    {
                        sVerb = "after checking variable in add interaction";
                        if (iNew >= iactionarr.Length)
                        {
                            sVerb = "after finding full array in add interaction";
                            RReporting.ShowErr("Program error in InteractionQ Enqueue.");
                            return(false);
                        }
                        sVerb = "after finding room in array in add interation";
                        if (iactionarr[iNew] == null)
                        {
                            sVerb            = "after finding null array item in add interaction";
                            iactionarr[iNew] = new Interaction();
                            sVerb            = "after creating array item in add interaction";
                        }
                        else
                        {
                            sVerb = "after finding non-null array item in add interaction";
                        }
                        iactionarr[iNew] = interactionAdd;                      //interactionAdd.CopyTo(ref iactionarr[iNew]); //debug performance (change iactionarr to refiactionarr (& rewrite call logic!)(?))
                        sVerb            = "after copying interaction in add interaction";
                        iCount++;
                        //sLogLine="debug enq iCount="+iCount.ToString();
                        return(true);
                    }
                    else
                    {
                        sVerb = "after skipping null parameter in add interaction";
                        RReporting.ShowErr("Tried to add a null Interaction to the queue");
                        return(false);
                    }
                }
                catch (Exception exn) {
                    RReporting.ShowExn(exn, "InteractionQ Enq", sVerb + " {interactionAdd.iType:" + VarMessage(interactionAdd) + "; interactionq:" + VarMessage(iactionarr) + "; iNew:" + iNew.ToString() + "; iactionq[iNew]:" + VarMessage(iactionarr[iNew]) + "}");
                }
                return(false);
            }
            else
            {
                RReporting.ShowErr("InteractionQ is full, with " + iCount.ToString() + " interactions", "InteractionQ Enq(" + ((interactionAdd == null)?"null interaction":"non-null") + ")");
                return(false);
            }
        }
Esempio n. 2
0
        }        //end Fill6

        /// <summary>
        /// Loops through source to fill destination
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="src"></param>
        /// <param name="iTotalBytes"></param>
        public static unsafe void Fill(ref byte[] destination, byte[] byarrSrc, int iDestByte, int iBytesTotal)
        {
            try {
                int iSloppyChunks = iBytesTotal / byarrSrc.Length;
                int iRemainder    = iBytesTotal % byarrSrc.Length;
                if (byarrSrc.Length == 8)
                {
                    Fill8ByteChunksByUnitCount(ref destination, ref byarrSrc, iDestByte, 0, iSloppyChunks);
                }
                else if (byarrSrc.Length == 6)
                {
                    Fill6ByteChunksByUnitCount(ref destination, ref byarrSrc, iDestByte, 0, iSloppyChunks);
                }
                else if (byarrSrc.Length == 4)
                {
                    Fill4ByteChunksByUnitCount(ref destination, ref byarrSrc, iDestByte, 0, iSloppyChunks);
                }
                else
                {
                    iRemainder = iBytesTotal;
                }
                if (iRemainder > 0)
                {
                    //int iAbs=iDestByte+iTotalBytes-iRemainder;
                    fixed(byte *lpDest = destination, lpSrc = byarrSrc)                    //keeps GC at bay
                    {
                        byte *lpDestNow = lpDest;
                        byte *lpSrcNow  = lpSrc;

                        lpDestNow += iDestByte + iBytesTotal - iRemainder;                  //+=iAbs;
                        int iSrcAbs = 0;

                        for (int iDestRel = 0; iDestRel < iRemainder; iDestRel++)
                        {
                            *lpDestNow = *lpSrcNow;
                            lpDestNow++;                            //iAbs++;
                            lpSrcNow++;
                            iSrcAbs++;
                            if (iSrcAbs == byarrSrc.Length)
                            {
                                lpSrcNow = lpSrc;
                                iSrcAbs  = 0;
                            }
                        }
                    }
                }                //end if remainder
            }
            catch (Exception e) {
                RReporting.ShowExn(e, "", "Memory Fill(array,array,iDest,count)");
                return;
            }
        }        //end fill by looping through source array
Esempio n. 3
0
        /// <summary>
        /// Saves the image in the format from which it was loaded.
        /// </summary>
        /// <param name="sFileName">File name, make sure extension is same as loaded file.</param>
        /// <returns>false if exception</returns>
        public bool SaveInternalBitmap(string sFileName)
        {
            bool bGood = true;

            try {
                bmpLoaded.Save(sFileName);
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "SaveInternalBitmap(\"" + sFileName + "\")");
                bGood = false;
            }
            return(bGood);
        }
Esempio n. 4
0
 public string Peek(int iRel)
 {
     try {
         if (iRel < iCount_PlusFirstIsOneAfterLast)
         {
             return(arrobjects[Wrap(iFirst + iRel)]);
         }
     }
     catch (Exception exn) {
         RReporting.ShowExn(exn);
     }
     return(null);
 }
Esempio n. 5
0
 public RImage Glyph(char cNow, int iGlyphType)
 {
     try {
         if (animarrGlyphType[iGlyphType] != null)
         {
             return(animarrGlyphType[iGlyphType].Frame((long)cNow));
         }
     }
     catch (Exception exn) {
         RReporting.ShowExn(exn, "getting font glyph", "RFont Glyph {cNow:'" + char.ToString(cNow) + "'; ascii:" + ((int)cNow).ToString() + "; iGlyphType:" + GlyphTypeToString(iGlyphType) + "}");
     }
     return(null);
 }        //end Glyph(cNow,iGlyphType)
Esempio n. 6
0
 public static int SafeLength(PictureBox[] val)
 {
     try {
         if (val != null)
         {
             return(val.Length);
         }
     }
     catch (Exception e) {
         RReporting.Debug(e, "", "Base SafeLength(PictureBox[])");
     }
     return(0);
 }
Esempio n. 7
0
 public void Set(int index, string val)
 {
     try {
         if (vsData == null)
         {
             vsData = new Variables(2);                            //debug performance - small initial maximum variables (sizes automatically)
         }
         vsData.ForceSet(index, "", val);
     }
     catch (Exception exn) {
         RReporting.ShowExn(exn, "packet Set(" + index.ToString() + "," + val + ")");
     }
 }
Esempio n. 8
0
 public string PeekAbs(int iAbs)
 {
     try {
         if (InUsedRange(iAbs))
         {
             return(arrobjects[iAbs]);
         }
     }
     catch (Exception exn) {
         RReporting.ShowExn(exn);
     }
     return(null);
 }
Esempio n. 9
0
        }        //end CopyFrameFromInternalBitmap

        public bool SaveInternalBitmap(string sFileName, System.Drawing.Imaging.ImageFormat imageformat)
        {
            bool bGood = true;

            try {
                bmpLoaded.Save(sFileName, imageformat);
            }
            catch (Exception exn) {
                bGood = false;
                RReporting.ShowExn(exn, "SaveInternalBitmap(\"" + sFileName + "\"," + imageformat.ToString() + ")");
            }
            return(bGood);
        }
Esempio n. 10
0
        /// <summary>
        /// Use this constructor instead of the default constructor,
        /// otherwise the client will not be able to initialize
        /// </summary>
        Client(string sServerURL1, ref RetroEngine ParentX)
        {
            sFuncNow  = "Client(" + sServerURL1 + ",...)";
            Parent    = ParentX;
            bContinue = true;
            try {
                packetOut = new Packet();
                //Script scriptIni = new Script();//srNow=File.OpenText(sFile);
                //scriptIni.ReadScript("Client.ini");
                //if (!scriptIni.bErr) {

                if (sServerURL1.StartsWith("http://"))                 //debug if non-http
                {
                    sServerURL = sServerURL1;
                }
                else
                {
                    RReporting.Error_WriteLine("-sServerURL defaulted to " + sServerURL);
                }


                //Create and register remoting channel
                HttpChannel chanRetroEngine = new HttpChannel();
                ChannelServices.RegisterChannel(chanRetroEngine);
                bServer = ClientConnectServer();                 //Init the remoting system
                if (!bServer)
                {
                    RReporting.Error_WriteLine("Couldn't connect to server or single-player game. Both require that you check your firewall settings.");
                }

                //string sOS = Environment.OSVersion.ToString;
                //System.PlatformID platformidOS = Environment.OSVersion.Platform;
                //System.Version versionOS = Environment.OSVersion.Version;
                //System.Type typeOS = Environment.OSVersion.GetType;
                portServer       = new Port();           //new Port("client");
                tsClientPacketer = new ThreadStart(ClientPacketer);
                tClientPacketer  = new Thread(tsClientPacketer);
                tClientPacketer.Start();
                coreInClient = new Core();                 //this is just the mapper not the server
                coreInClient.Start();
            }
            catch (Exception exn) {
                if (bServer)
                {
                    RReporting.WriteLine("Couldn't initialize client");
                    RReporting.ShowExn(exn, "Client constructor", "initializing client");
                }
                //bContinue==false;
            }
            //ProgramMain();
        }
		}//end RowToCSVLine
		public string RowToCSVLine(int AtInternalRowIndex, bool bReplaceNewLineWithTabInsteadOfHTMLBrWithMarkerProperty, int ColumnStart, int ColumnCount) {
			int iAbs=ColumnStart;
			string sReturn="";
			try {
				for (int ColRel=0; ColRel<ColumnCount&&iAbs<this.Columns; ColRel++) {
					sReturn+=((ColRel!=0)?",":"")+RTable.LiteralFieldToCSVField(tearr[AtInternalRowIndex].Field(iAbs),this.cFieldDelimiter,this.cTextDelimiter,bReplaceNewLineWithTabInsteadOfHTMLBrWithMarkerProperty);
					iAbs++;
				}
			}
			catch (Exception exn) {
				RReporting.ShowExn(exn,"converting row to csv line","rtable RowToCSVLine(AtInternalRowIndex="+AtInternalRowIndex+",bTabsAsNewLines="+(bReplaceNewLineWithTabInsteadOfHTMLBrWithMarkerProperty?"true":"false")+",ColumnStart="+ColumnStart+",ColumnCount="+ColumnCount+")");
			}
			return sReturn;
		}
		public RTable CopyTitlesOnly() {
			RTable tReturn=null;
			try {
				if (this.teTitles!=null&&this.teTitles.Columns>0) {
					tReturn=new RTable(this.teTitles.Copy(),true);
				}
				else tReturn=new RTable();
			}
			catch (Exception exn) {
				tReturn=null;
				RReporting.ShowExn(exn,RReporting.sParticiple,"rtable CopyTitlesOnly()");
			}
			return tReturn;
		}//end CopyTitlesTo
Esempio n. 13
0
 private void Scenarior()
 {
     //runs as a Thread to put core.scenario into motion.
     //thread should be used by server AND client (but does client use server???) (?)
     RReporting.WriteLine("Scenario manager started");
     while (bContinue)
     {
         //if (bShuttingDown) {
         //if (iPacketsSending==0) bContinue=false; //debug this statement should be fixed and used
         //	if (RetroEngine.TickCount-iTickShutdown>iTicksToShutdown) bContinue=false;
         //}
     }
     RReporting.WriteLine("Scenario manager stopped");
 }
Esempio n. 14
0
        }        //end Fill

        public static unsafe void Fill(ref byte[] destination, byte byFill, int iDestByte, int iBytes)
        {
            try {
                bool bFillManually = false;
                if (iBytes >= 16)                 //SINCE FillX cases only save time when there is a long string of filling
                {
                    if (iBytes % 8 == 0)
                    {
                        byte[] src = new byte[8];
                        for (int iNow = 0; iNow < 8; iNow++)
                        {
                            src[iNow] = byFill;                                                    //debug performance--does this really save time?
                        }
                        Fill8ByteChunksByUnitCount(ref destination, ref src, iDestByte, 0, iBytes / 8);
                    }
                    else if (iBytes % 4 == 0)
                    {
                        byte[] src = new byte[4];
                        Fill4ByteChunksByUnitCount(ref destination, ref src, iDestByte, 0, iBytes / 4);
                    }
                    else
                    {
                        bFillManually = true;
                    }
                }                //end if enough bytes for optimizations above to help
                else
                {
                    bFillManually = true;
                }
                if (bFillManually)
                {
                    fixed(byte *lpDest = destination)                      //keeps GC at bay
                    {
                        byte *lpDestNow = lpDest;

                        lpDestNow += iDestByte;
                        for (int i = 0; i < iBytes; i++)
                        {
                            *lpDestNow = byFill;
                            lpDestNow++;
                        }
                    }
                }
            }
            catch (Exception e) {
                RReporting.ShowExn(e, "Memory Fill(array,byte,iDest,count");
                return;
            }
            return;
        }        //end Fill
Esempio n. 15
0
        public bool ResetGlyphTypeArray()
        {
            bool bGood = false;

            try {
                animarrGlyphType = new Anim[iGlyphTypes];
                bGood            = true;
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "GFont ResetGlyphArray");
                bGood = false;
            }
            return(bGood);
        }
Esempio n. 16
0
		}//end SubSection
		///<summary>
		///Elements in this array--if not array, returns 0
		///</summary>
		public int Elements() {
			int iFound=0;
			bool bFound=false;
			try {
				int iReturnStart=0, iReturnLen;
				if (sVal.StartsWith("{")&&sVal.EndsWith("}")) {
					iFound=SubSections(sVal,0,sVal.Length,"{","}","\"",",");
				}
			}
			catch (Exception exn) {
				RReporting.ShowExn(exn,"Variable Elements","getting script array size");
			}
			return iFound;
		}//end Elements
Esempio n. 17
0
 private void Init(int iMax1)           //always called by Constructor
 {
     iCount = 0;
     try {
         objectarr = new Var[iMax1];
     }
     catch {
         objectarr = null;
     }
     if (objectarr == null)
     {
         RReporting.ShowErr("VarStack constructor couldn't create objectarr array");
     }
 }
Esempio n. 18
0
 public bool Poke(int iRel, string objectVal)
 {
     try {
         if (iRel < iCount_PlusFirstIsOneAfterLast)
         {
             arrobjects[Wrap(iFirst + iRel)] = objectVal;
             return(true);
         }
     }
     catch (Exception exn) {
         RReporting.ShowExn(exn);
     }
     return(false);
 }
Esempio n. 19
0
        public Packet Deq()           //Dequeue
        //sLogLine=("debug deq iCount="+iCount.ToString()+" and "+(IsEmpty?"is":"is not")+" empty.");
        {
            if (IsEmpty)
            {
                RReporting.ShowErr("No packets to return so returned null packet", "Deq");
                return(null);
            }
            int iReturn = iFirst;

            iFirst = Wrap(iFirst + 1);
            iCount--;
            return(packetarr[iReturn]);
        }
Esempio n. 20
0
 public bool PokeAbs(int iAbs, string objectVal)
 {
     try {
         if (InUsedRange(iAbs))
         {
             arrobjects[iAbs] = objectVal;
             return(true);
         }
     }
     catch (Exception exn) {
         RReporting.ShowExn(exn);
     }
     return(false);
 }
Esempio n. 21
0
        //private void ClientThread() { //puts the CLIENT-SIDE copy of the game world into motion
        //eventually this should use the same event loop as the server for consistency
        //}
        private void ClientPacketer()
        {
            //debug NYI need to start this thread and make it manage client packet queues
            //Packet packetAck=null;
            Parent.WriteLine("ClientPacketer started");

            iTickLastIdle = RetroEngine.TickCount;
            while (bContinue)
            {
                if ((RetroEngine.TickCount - iTickLastIdle) > 333)
                {
                    iTickLastIdle = RetroEngine.TickCount;
                    //Send Keepalive if last was 333ms ago:
                    try {
                        if (bLogin)
                        {
                            if (packetOut != null)
                            {
                                packetAck = portServer.ClientGets(packetOut);                                              //get whatever packets are available,
                            }
                            // using packetOut for security credentials
                            else
                            {
                                Parent.WriteLine("Idle packet is null so it couldn't be sent.");
                                packetAck = null;
                            }
                            if (packetAck != null)
                            {
                                RunPacket(packetAck);
                            }
                        }
                        else
                        {
                            Parent.WriteLine("not logged in. ");
                        }
                    }
                    catch (Exception exn) {
                        sLastErr = "Not connected to server address \"" + sServerURL + "\"--" + exn.ToString();
                        bServer  = false;
                        break;
                    }
                }                //if time since lastidle > 333
                else
                {
                    //Parent.WriteLine(RetroEngine.TickCount.ToString()+" was "+iTickLastIdle.ToString());
                }
            }
            RReporting.Error_WriteLine("The client packet manager stopped.");
        }
Esempio n. 22
0
		public Packet Deq(Packet packetAuth) { //debug performance make this a reference???
			Packet packetLogin;
			try {
				if (packetAuth==null) {
					packetLogin=new Packet();
					packetLogin.iType=PacketType.ServerMessage;
					packetLogin.Set(0,"The server detected that your software sent a null authorization");
					return packetLogin; 
				}
				else if (packetAuth.iType==PacketType.Login) {
					packetLogin=new Packet();
					packetLogin.iType=PacketType.ServerMessage;
					packetLogin.Set(0,"Server failed to process the login");
					RReporting.Error_WriteLine("*Deq login response packet"); //got packet
					RunLoginPacket(ref packetLogin, ref packetAuth);
					return packetLogin;
				}
				else {
					if (accountant.IsValidPacket(ref packetAuth)) { // && packetAuth.sFrom==userarr[packetAuth.iTokenNum].sTo) {
						if (packetqarr[packetAuth.iTokenNum]!=null) {
							if (!packetqarr[packetAuth.iTokenNum].IsEmpty) {
								return packetqarr[packetAuth.iTokenNum].Deq();//userarr[packetAuth.iTokenNum].packetq.Deq();
							}
							else {
								return null;
							}
						}
						else {
							RReporting.Error_WriteLine("*  -request was made to an user token that wasn't logged in."); 
							packetTemp.Reset();
							packetTemp.iType=PacketType.ServerMessage;
							packetTemp.Set(0,"Server couldn't find your login data, try logging in again");
							return packetTemp;
						}
					}
					else {
						RReporting.Error_WriteLine("*  -an invalid authentication packet was received");
						return packetCorrupt; //i.exn. user is not authenticated
						//debug NYI increment watch level of ALL players (do iLogins-iCorruptions and players with lowest diff are suspects)
					}
				}
			}
			catch (Exception exn) {
				RReporting.ShowExn(exn,"Packeter Deq","user getting packet");
				return packetCorrupt;
			}
			//RReporting.ShowErr("Didn't return a packet","Packeter Deq");
			//return packetCorrupt;
		}//end Deq
Esempio n. 23
0
		public void Set(string val) {
			if (val!=null&&val.Length>0) {
				if (val!="%") {
					if (val[val.Length-1]=='%') Set(  double.Parse( val.Substring(0,val.Length-1) )  );
					else Set( double.Parse(val) );
				}
				else {
					iInternalValue=0;
					RReporting.Warning("Warning: Set Percent using the string \"%\" so setting to 0!");
				}
			}
			else {
				RReporting.Warning("Warning: Set Percent to "+(val==null?"null":(val.Length.ToString()+"-length"))+" string!");
			}
		}
Esempio n. 24
0
        public bool TypeHTML(ref RImage riDest, ref IPoint ipAt, IRect irectReturn, string sText, bool bVisible)
        {
            int  iNextTag;
            int  iLength;
            bool bGood = true;

            try {
                //TODO: finish TypeHTML
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "", "TypeHTML(...,\"" + sText + "\",...)");
                bGood = false;
            }
            return(bGood);
        }
Esempio n. 25
0
        public int WidthOf(string sText, int iFirst, int iLast)
        {
            int iReturn = 0;

            try {
                for (int iNow = iFirst; iNow <= iLast; iNow++)
                {
                    iReturn += WidthOf(sText[iNow]);
                }
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "", "RFont WidthOf(char array,iFirst,iLast)");
            }
            return(iReturn);
        }
Esempio n. 26
0
        public int WidthOf(string sText, int iGlyphType)
        {
            int iReturn = 0;

            try {
                for (int iChar = 0; iChar < sText.Length; iChar++)
                {
                    iReturn += WidthOf(sText[iChar]);
                }
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "", "RFont WidthOf(string,...)");
            }
            return(iReturn);
        }
Esempio n. 27
0
 private void Init(int iSetMax)           //always called by Constructor
 {
     iFirst = 0;
     iMax   = iSetMax;
     iCount_PlusFirstIsOneAfterLast = 0;
     arrobjects = new string[iMax];
     for (int iNow = 0; iNow < iMax; iNow++)
     {
         arrobjects[iNow] = null;
     }
     if (arrobjects == null)
     {
         RReporting.ShowErr("Queue constructor couldn't initialize arrobjects");
     }
 }
Esempio n. 28
0
        public string GetStatus()
        {
            bool   bGood   = true;
            string sReturn = "";

            try {
                sReturn = sLast;
                //sReturn=sbX.Text;
            }
            catch (Exception exn) {
                RReporting.IgnoreExn(exn, "MyCallback GetStatus");
                return("Can't get status.");
            }
            return(sReturn);
        }
Esempio n. 29
0
 public string Pop()
 {
     //sLogLine=("debug deq iCount="+iCount.ToString()+" and "+(IsEmpty?"is":"is not")+" empty.");
     if (!IsEmpty)
     {
         int iReturn = LastIndex;
         iCount--;
         return(sarr[iReturn]);
     }
     else
     {
         RReporting.Warning("no strings to return so returned null", "", "StringStack Pop");
     }
     return(null);
 }
Esempio n. 30
0
        public Pixel32Struct PixelFromTop()
        {
            Pixel32Struct pxReturn = new Pixel32Struct();

            try {
                pxReturn.B = by2dGrad[iGrad - 1][0];
                pxReturn.G = by2dGrad[iGrad - 1][1];
                pxReturn.R = by2dGrad[iGrad - 1][2];
                pxReturn.A = by2dGrad[iGrad - 1][3];
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "getting top gradient pixel", "RImage PixelFromTop");
            }
            return(pxReturn);
        }