Yami_dgn

DX issues

Nov 24th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.03 KB | None | 0 0
  1. using DxLibDLL;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using static DxLibDLL.DX;
  9.  
  10. namespace ConsoleApplication3
  11. {
  12.     class Program
  13.     {
  14.         public static bool CloseFlag = false;
  15.         private static int mStartTime = 0;
  16.         private static int mCount = 0;
  17.         private static float mFps = 0;
  18.         private static int N = 60;
  19.         public static int FPS = 60;
  20.         public static bool DrawFPS = true;
  21.         private static int sleepCount = 0;
  22.         private static long lastUpdateTick = 0;
  23.  
  24.         private static int screen1;
  25.         private static int screen2;
  26.         static void Main(string[] args)
  27.         {
  28.             DX.SetUseDirect3DVersion(DX.DX_DIRECT3D_9EX);
  29.             DX.SetUseVramFlag(DX.TRUE);
  30.             DX.ChangeWindowMode(DX.TRUE);
  31.             DX.SetMultiThreadFlag(DX.TRUE);
  32.             DX.SetDrawScreen(DX.DX_SCREEN_BACK);
  33.             DX.SetChangeScreenModeGraphicsSystemResetFlag(DX.TRUE);
  34.             DX.DxLib_Init();
  35.             DX.MakeKeyInput(0, 0, 0, 0);
  36.             screen1 = DX.MakeScreen(640, 480);
  37.             screen2 = DX.MakeScreen(640, 480);
  38.             sleepCount = 0;
  39.             while (!CloseFlag && DX.ProcessMessage() == 0 && DX.CheckHitKey(DX.KEY_INPUT_ESCAPE) == 0)
  40.             {
  41.                 Tick();
  42.                 Thread.Sleep(1);
  43.             }
  44.             CloseFlag = true;
  45.             DX.DxLib_End();
  46.         }
  47.         static void Tick()
  48.         {
  49.             if (lastUpdateTick == 0) lastUpdateTick = DX.GetNowCount();
  50.             if (DX.ClearDrawScreen() == 0 && sleepCount <= 0)
  51.             {
  52.                 if (mStartTime == 0)
  53.                     mStartTime = DX.GetNowCount();
  54.                 if (mCount == N)
  55.                 {
  56.                     int t = DX.GetNowCount();
  57.                     mFps = 1000f / ((t - mStartTime) / (float)N);
  58.                     mCount = 0;
  59.                     mStartTime = t;
  60.                 }
  61.                 mCount++;
  62.                 Update(DX.GetNowCount() - lastUpdateTick);
  63.                 lastUpdateTick = DX.GetNowCount();
  64.                 Draw();
  65.                 int tookTime = DX.GetNowCount() - mStartTime;
  66.                 int waitTime = mCount * 1000 / FPS - tookTime;
  67.                 if (waitTime > 0)
  68.                 {
  69.                     sleepCount = 0;
  70.                 }
  71.             }
  72.             if (sleepCount > 0) sleepCount--;
  73.         }
  74.         static void Draw()
  75.         {
  76.             DX.SetDrawScreen(screen1);
  77.             DX.FillGraph(screen1, 0, 0, 0, 0);
  78.             DX.DrawCircleAA(200, 200, 60, 100, DX.GetColor(128, 100, 0), DX.TRUE);
  79.             DX.SetDrawScreen(screen2);
  80.             DX.FillGraph(screen2, 0, 0, 0, 0);
  81.             DX.SetDrawScreen(DX.DX_SCREEN_BACK);
  82.             DX.DrawGraph(0, 0, screen1, DX.TRUE);
  83.             DX.DrawGraph(0, 0, screen2, DX.TRUE);
  84.             DX.ScreenFlip();
  85.  
  86.         }
  87.         static void Update(long tick)
  88.         {
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment