Пример #1
0
        public void mousePressed(object sender, RsMouseInputEventArgs e)
        {
            int i = e.ScreenCoordX;
            int j = e.ScreenCoordY;

            idleTime       = 0;
            eventClickX    = i;
            eventClickY    = j;
            eventClickTime = TimeService.CurrentTimeInMilliseconds();
            if (e.IsRightClick)
            {
                eventMouseButton = 2;
                mouseButton      = 2;
            }
            else
            {
                eventMouseButton = 1;
                mouseButton      = 1;
            }
        }
Пример #2
0
        private IEnumerator DrawFlamesCoroutine()
        {
            Debug.Log($"Starting flame drawing.");
            drawingFlames = true;

            long startTime   = TimeService.CurrentTimeInMilliseconds();
            int  currentLoop = 0;
            int  interval    = 20;

            while (currentlyDrawingFlames)
            {
                flameCycle++;
                calcFlamesPosition();
                yield return(null);                //these exist to reduce the greed on the main thread in WebGL.

                calcFlamesPosition();
                yield return(null);                //these exist to reduce the greed on the main thread in WebGL.

                doFlamesDrawing();
                yield return(null);                //these exist to reduce the greed on the main thread in WebGL.

                if (++currentLoop > 10)
                {
                    long currentTime = TimeService.CurrentTimeInMilliseconds();
                    int  difference  = (int)(currentTime - startTime) / 10 - interval;
                    interval = 40 - difference;
                    if (interval < 5)
                    {
                        interval = 5;
                    }
                    currentLoop = 0;
                    startTime   = currentTime;
                }

                yield return(new WaitForSeconds((float)interval / 1000.0f));
            }

            drawingFlames = false;
        }
Пример #3
0
        public virtual void run()
        {
            drawLoadingText(0, "Loading...");
            startUp();
            int opos  = 0;
            int ratio = 256;
            int delay = 1;
            int count = 0;
            int intex = 0;

            for (int otim = 0; otim < 10; otim++)
            {
                otims[otim] = TimeService.CurrentTimeInMilliseconds();
            }

            while (gameState >= 0)
            {
                if (gameState > 0)
                {
                    gameState--;
                    if (gameState == 0)
                    {
                        exit();
                        return;
                    }
                }

                int i2 = ratio;
                int j2 = delay;
                ratio = 300;
                delay = 1;
                long currentTime = TimeService.CurrentTimeInMilliseconds();
                if (otims[opos] == 0L)
                {
                    ratio = i2;
                    delay = j2;
                }
                else if (currentTime > otims[opos])
                {
                    ratio = (int)(2560 * delayTime / (currentTime - otims[opos]));
                }

                if (ratio < 25)
                {
                    ratio = 25;
                }
                if (ratio > 256)
                {
                    ratio = 256;
                    delay = (int)(delayTime - (currentTime - otims[opos]) / 10L);
                }

                if (delay > delayTime)
                {
                    delay = delayTime;
                }
                otims[opos] = currentTime;
                opos        = (opos + 1) % 10;
                if (delay > 1)
                {
                    for (int otim = 0; otim < 10; otim++)
                    {
                        if (otims[otim] != 0L)
                        {
                            otims[otim] += delay;
                        }
                    }
                }

                if (delay < minDelay)
                {
                    delay = minDelay;
                }
                try
                {
                    Thread.Sleep(delay);
                }
                catch (Exception _ex)                 //TODO: Log
                {
                    intex++;
                }

                for (; count < 256; count += ratio)
                {
                    clickType        = eventMouseButton;
                    clickX           = eventClickX;
                    clickY           = eventClickY;
                    clickTime        = eventClickTime;
                    eventMouseButton = 0;
                    processGameLoop();
                    readIndex = writeIndex;
                }

                count &= 0xff;
                if (delayTime > 0)
                {
                    fps = (1000 * ratio) / (delayTime * 256);
                }
                processDrawing();
                if (debugRequested)
                {
                    Console.WriteLine("ntime:" + currentTime);
                    for (int i = 0; i < 10; i++)
                    {
                        int otim = ((opos - i - 1) + 20) % 10;
                        Console.WriteLine("otim" + otim + ":" + otims[otim]);
                    }

                    Console.WriteLine("fps:" + fps + " ratio:" + ratio + " count:" + count);
                    Console.WriteLine("del:" + delay + " deltime:" + delayTime + " mindel:" + minDelay);
                    Console.WriteLine("intex:" + intex + " opos:" + opos);
                    debugRequested = false;
                    intex          = 0;
                }
            }

            if (gameState == -1)
            {
                exit();
            }
        }
Пример #4
0
        private async Task AppletRunCoroutine()
        {
            Console.WriteLine($"Loading.");
            drawLoadingText(0, "Loading...");

            await StartupCoroutine();
            await LoadMediaContentAsync();

            await HandlePendingInterfaceUnpackingAsync();

            await PostLoadEngineInitializationAsync();

            int opos  = 0;
            int ratio = 256;
            int delay = 1;
            int count = 0;
            int intex = 0;

            for (int otim = 0; otim < 10; otim++)
            {
                otims[otim] = TimeService.CurrentTimeInMilliseconds();
            }

            while (gameState >= 0)
            {
                if (gameState > 0)
                {
                    gameState--;
                    if (gameState == 0)
                    {
                        exit();
                        return;
                    }
                }

                int i2 = ratio;
                int j2 = delay;
                ratio = 300;
                delay = 1;
                long currentTime = TimeService.CurrentTimeInMilliseconds();
                if (otims[opos] == 0L)
                {
                    ratio = i2;
                    delay = j2;
                }
                else if (currentTime > otims[opos])
                {
                    ratio = (int)(2560 * delayTime / (currentTime - otims[opos]));
                }

                if (ratio < 25)
                {
                    ratio = 25;
                }
                if (ratio > 256)
                {
                    ratio = 256;
                    delay = (int)(delayTime - (currentTime - otims[opos]) / 10L);
                }

                if (delay > delayTime)
                {
                    delay = delayTime;
                }
                otims[opos] = currentTime;
                opos        = (opos + 1) % 10;
                if (delay > 1)
                {
                    for (int otim = 0; otim < 10; otim++)
                    {
                        if (otims[otim] != 0L)
                        {
                            otims[otim] += delay;
                        }
                    }
                }

                if (delay < minDelay)
                {
                    delay = minDelay;
                }

                //Always await, mindelay is at least one ms and that'll be 1 frame minimum for us
                //if we never yield frame time then critical things in WebGL enviroment can't run
                await TaskDelayFactory.Create(delay);

                for (; count < 256; count += ratio)
                {
                    clickType        = eventMouseButton;
                    clickX           = eventClickX;
                    clickY           = eventClickY;
                    clickTime        = eventClickTime;
                    eventMouseButton = 0;
                    await processGameLoop();

                    readIndex = writeIndex;
                }

                count &= 0xff;
                if (delayTime > 0)
                {
                    fps = (1000 * ratio) / (delayTime * 256);
                }
                processDrawing();
                if (debugRequested)
                {
                    Console.WriteLine("ntime:" + currentTime);
                    for (int i = 0; i < 10; i++)
                    {
                        int otim = ((opos - i - 1) + 20) % 10;
                        Console.WriteLine("otim" + otim + ":" + otims[otim]);
                    }

                    Console.WriteLine("fps:" + fps + " ratio:" + ratio + " count:" + count);
                    Console.WriteLine("del:" + delay + " deltime:" + delayTime + " mindel:" + minDelay);
                    Console.WriteLine("intex:" + intex + " opos:" + opos);
                    debugRequested = false;
                    intex          = 0;
                }
            }

            if (gameState == -1)
            {
                exit();
            }
        }
Пример #5
0
        private void closeRequest(OnDemandData request)
        {
            try
            {
                if (socket == null)
                {
                    long currentTime = TimeService.CurrentTimeInMilliseconds();
                    if (currentTime - lastRequestTime < 4000L)
                    {
                        return;
                    }
                    lastRequestTime = currentTime;
                    socket          = clientInstance.openSocket(43594).ConfigureAwait(false).GetAwaiter().GetResult();
                    inputStream     = socket.GetStream();
                    outputStream    = socket.GetStream();
                    outputStream.WriteByte(15);
                    for (int j = 0; j < 8; j++)
                    {
                        inputStream.ReadByte();
                    }

                    loopCycle = 0;
                }

                payload[0] = (byte)request.dataType;
                payload[1] = (byte)(request.id >> 8);
                payload[2] = (byte)request.id;
                if (request.incomplete)
                {
                    payload[3] = 2;
                }
                else if (!clientInstance.isLoggedIn)
                {
                    payload[3] = 1;
                }
                else
                {
                    payload[3] = 0;
                }
                outputStream.Write(payload, 0, 4);
                writeLoopCycle = 0;
                failedRequests = -10000;
                return;
            }
            catch (SocketException ioexception)
            {
            }

            try
            {
                socket.Close();
            }
            catch (Exception _ex)
            {
            }

            socket       = null;
            inputStream  = null;
            outputStream = null;
            expectedSize = 0;
            failedRequests++;
        }
Пример #6
0
        protected async Task StartGameEngineLoop()
        {
            try
            {
                GameEngineThreadId = Thread.CurrentThread.ManagedThreadId;
                Console.WriteLine($"Loading.");
                drawLoadingText(0, "Loading...");
                startUp();
                int opos  = 0;
                int ratio = 256;
                int delay = 1;
                int count = 0;
                int intex = 0;
                for (int otim = 0; otim < 10; otim++)
                {
                    otims[otim] = TimeService.CurrentTimeInMilliseconds();
                }

                while (gameState >= 0)
                {
                    if (gameState > 0)
                    {
                        gameState--;
                        if (gameState == 0)
                        {
                            exit();
                            return;
                        }
                    }

                    int i2 = ratio;
                    int j2 = delay;
                    ratio = 300;
                    delay = 1;
                    long currentTime = TimeService.CurrentTimeInMilliseconds();
                    if (otims[opos] == 0L)
                    {
                        ratio = i2;
                        delay = j2;
                    }
                    else if (currentTime > otims[opos])
                    {
                        ratio = (int)(2560 * delayTime / (currentTime - otims[opos]));
                    }

                    if (ratio < 25)
                    {
                        ratio = 25;
                    }
                    if (ratio > 256)
                    {
                        ratio = 256;
                        delay = (int)(delayTime - (currentTime - otims[opos]) / 10L);
                    }

                    if (delay > delayTime)
                    {
                        delay = delayTime;
                    }
                    otims[opos] = currentTime;
                    opos        = (opos + 1) % 10;
                    if (delay > 1)
                    {
                        for (int otim = 0; otim < 10; otim++)
                        {
                            if (otims[otim] != 0L)
                            {
                                otims[otim] += delay;
                            }
                        }
                    }

                    if (delay < minDelay)
                    {
                        delay = minDelay;
                    }
                    try
                    {
                        Thread.Sleep(delay);
                    }
                    catch (Exception _ex)                     //TODO: Log
                    {
                        intex++;
                    }

                    for (; count < 256; count += ratio)
                    {
                        //Important to sync input copy otherwise we
                        //have a race condition in multi-threaded input
                        lock (InputSyncObj)
                        {
                            clickType        = eventMouseButton;
                            clickX           = eventClickX;
                            clickY           = eventClickY;
                            clickTime        = eventClickTime;
                            eventMouseButton = 0;
                        }

                        await processGameLoop();

                        readIndex = writeIndex;
                    }

                    count &= 0xff;
                    if (delayTime > 0)
                    {
                        fps = (1000 * ratio) / (delayTime * 256);
                    }
                    processDrawing();
                    if (debugRequested)
                    {
                        Console.WriteLine("ntime:" + currentTime);
                        for (int i = 0; i < 10; i++)
                        {
                            int otim = ((opos - i - 1) + 20) % 10;
                            Console.WriteLine("otim" + otim + ":" + otims[otim]);
                        }

                        Console.WriteLine("fps:" + fps + " ratio:" + ratio + " count:" + count);
                        Console.WriteLine("del:" + delay + " deltime:" + delayTime + " mindel:" + minDelay);
                        Console.WriteLine("intex:" + intex + " opos:" + opos);
                        debugRequested = false;
                        intex          = 0;
                    }
                }

                if (gameState == -1)
                {
                    exit();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Encountered Exception in Game Run. Reason: {e.ToString()}");
                throw;
            }
        }
Пример #7
0
        private IEnumerator AppletRunCoroutine()
        {
            Console.WriteLine($"Loading.");
            drawLoadingText(0, "Loading...");
            yield return(StartupCoroutine());

            int opos  = 0;
            int ratio = 256;
            int delay = 1;
            int count = 0;
            int intex = 0;

            for (int otim = 0; otim < 10; otim++)
            {
                otims[otim] = TimeService.CurrentTimeInMilliseconds();
            }

            while (gameState >= 0)
            {
                if (gameState > 0)
                {
                    gameState--;
                    if (gameState == 0)
                    {
                        exit();
                        yield break;
                    }
                }

                int i2 = ratio;
                int j2 = delay;
                ratio = 300;
                delay = 1;
                long currentTime = TimeService.CurrentTimeInMilliseconds();
                if (otims[opos] == 0L)
                {
                    ratio = i2;
                    delay = j2;
                }
                else if (currentTime > otims[opos])
                {
                    ratio = (int)(2560 * delayTime / (currentTime - otims[opos]));
                }

                if (ratio < 25)
                {
                    ratio = 25;
                }
                if (ratio > 256)
                {
                    ratio = 256;
                    delay = (int)(delayTime - (currentTime - otims[opos]) / 10L);
                }

                if (delay > delayTime)
                {
                    delay = delayTime;
                }
                otims[opos] = currentTime;
                opos        = (opos + 1) % 10;
                if (delay > 1)
                {
                    for (int otim = 0; otim < 10; otim++)
                    {
                        if (otims[otim] != 0L)
                        {
                            otims[otim] += delay;
                        }
                    }
                }

                if (delay < minDelay)
                {
                    delay = minDelay;
                }

                if (delay > 1)
                {
                    //Delay is in milliseconds, so we need to convert to seconds.
                    yield return(new WaitForSeconds((float)delay / 1000.0f));
                }
                else if (delay == 1)
                {
                    yield return(new WaitForEndOfFrame());
                }

                for (; count < 256; count += ratio)
                {
                    clickType        = eventMouseButton;
                    clickX           = eventClickX;
                    clickY           = eventClickY;
                    clickTime        = eventClickTime;
                    eventMouseButton = 0;
                    processGameLoop();
                    readIndex = writeIndex;
                }

                count &= 0xff;
                if (delayTime > 0)
                {
                    fps = (1000 * ratio) / (delayTime * 256);
                }
                processDrawing();
                if (debugRequested)
                {
                    Console.WriteLine("ntime:" + currentTime);
                    for (int i = 0; i < 10; i++)
                    {
                        int otim = ((opos - i - 1) + 20) % 10;
                        Console.WriteLine("otim" + otim + ":" + otims[otim]);
                    }

                    Console.WriteLine("fps:" + fps + " ratio:" + ratio + " count:" + count);
                    Console.WriteLine("del:" + delay + " deltime:" + delayTime + " mindel:" + minDelay);
                    Console.WriteLine("intex:" + intex + " opos:" + opos);
                    debugRequested = false;
                    intex          = 0;
                }
            }

            if (gameState == -1)
            {
                exit();
            }
        }