sandbox.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. /*
  2. An application for previewing tiles and sprites together for potential games.
  3. If you design game assets separatelly, they will often look much worse when you put them together.
  4. Unmatching scale, shadows, colors, themes, et cetera...
  5. That's why it's important to preview your assets together as early as possible while still designing them.
  6. */
  7. /*
  8. BUGS:
  9. * Certain key press events are ignored by the system after reaching a higher frame-rate.
  10. It is an existing bug that wasn't revealed or is it the system being unresponsive?
  11. * The mouse move is repeated automatically when changing pixel scale, but the same doesn't work for when the window itself moved.
  12. How can a new mouse-move event be triggered from the current location when toggling full-screen so that the window itself moves?
  13. * Tiles placed at different heights do not have synchronized rounding between each other.
  14. Try to round the Y offset separatelly from the XZ location's screen coordinate.
  15. * The light buffer gets white from point light when there's nothing drawn on the background.
  16. This prevent using other background colors than black.
  17. 3D BUGS:
  18. DRAWN:
  19. * There's an ugly seam from not connecting the other side of cylinder fields.
  20. Probably haven't created any extra triangle strip on that region.
  21. SHADOWS:
  22. * The bounding box of shadows differs from the visible pixel's bound in the config file.
  23. Expand the bound using the shadow model's points to include everything safely.
  24. * When eroding the dimensions of shadow shapes, there's gaps when placing tiles next to each other
  25. Can erosion and bias be applied in each shadow map while sampling or as a separate pass?
  26. Is this much bias even needed when using bilinear interpolation in depth divided space directly from the texture?
  27. * There's no way to close the gaps on height fields without using black pixels to create zero offset at the ends.
  28. This creates open holes when not using zero clipping.
  29. An optional triangle patch can be added along the open sides. (all for planes and excluding sides for cylinders)
  30. POSSIBLY SOLVED BUGS:
  31. * The fence shadows showed that shadow rendering were not rotated correctly.
  32. Create a test sprite with less symmetry to show if anything is rotated or mirrored wrong with new shape transforms.
  33. Try to define the coordinate systems for light in a way that makes more sense.
  34. VISUALS:
  35. * Make a directed light source that casts light and shadows from a fixed direction but can fade like a point light.
  36. Useful for street-lights and sky-lights that want to avoid normalizing and projecting light directions per pixel.
  37. Can be used both with and without casting shadows.
  38. Can use intensity maps to project patterns within the square.
  39. A rough 2D convex hull from the image can be generated for a tighter light frustum.
  40. Otherwise, one can just apply a round mask and use a cone.
  41. * Projective background decals.
  42. Used like passive lights but drawing to the diffuse layer and ignoring dynamic sprites.
  43. Will only be drawn when updating passive blocks or adding to existing background blocks.
  44. A 3D transform defines where the decal is placed like a cube in world space.
  45. The near and far clipping can use a fading threshold to allow placing explosion decals without creating hard seams.
  46. New sprites added after a decal should not be affected by an old sprite.
  47. How can this be solved without resorting to dangerous polymorphism.
  48. Allow defining decals locally for each level by loading their images from a temporary image pool of level specific content.
  49. This can be used to write instructions specific to a certain mission and give a unique look to an otherwise generic level.
  50. Billboards and signs can also be possible to reuse with custom images and text.
  51. * Static 3D models that are rendered when the background updates.
  52. These have normal resolution and can be freely rotated, scaled and colored.
  53. They draw shadows just like the pre-rendered sprites.
  54. * See if there's a shadow smoothing method worth using on the CPU.
  55. The blend filter is already quite heavy with the saturation, so it might as well do something more useful than a single multiplication as the main feature.
  56. The difficult thing is to preserve details from normal mapping and tiny details while making shadow edges look smooth.
  57. * Allow having many high-quality light sources by introducing fully passive lights.
  58. Useful for indirect light from the sky and general ambient light.
  59. The background stores RGBA light buffers to make passive lights super cheap.
  60. This light will mostly store soft light, so shadows from dynamic sprites will
  61. draw blob shadows as decals on the background before drawing themselves.
  62. This will give an illusion of dynamic ambient occlusion,
  63. especially if surface normals affect the intensity using custom shadow decals.
  64. Dynamic sprites overwrites with their own interpretation of the passive light.
  65. Dynamic lights add to the light buffer without caring about what's background and what's dynamic.
  66. A quad-tree stencil will remember which areas have foreground drawn on top of the background.
  67. This stencil is later used for a pass of dynamic light from passive light sources using stored primary cubemaps.
  68. The background will divide the light using multiple cube-maps for the same illumination by adding offset varitations in the light sampling function.
  69. * Make a reusable system for distance adaptive light sources.
  70. The same illumination filter should take multiple cubemaps rendered from slightly different locations.
  71. These can be interleaved into a unified packed look-up if the distortion
  72. of looking it up from the same offset is compensated for somehow.
  73. The first cubemap will be persistent and used later for dynamic light.
  74. The later cubemaps will be temporary when generating the background's softer light.
  75. USABILITY:
  76. * Tool for selecting and removing passive sprites.
  77. Use both unique handles for simplicity and the raw look-up for handling multiple sprites at once:
  78. Given an optional integer argument (defaulted to zero) to background sprite construction.
  79. This allow making custom filtering of sprites by category or giving a unique index to a sprite.
  80. A lookup can later return references to the sprite instances together with the key and allow custom filtering.
  81. A deletion lookup can take a function returning true when the background sprite should be deleted.
  82. The full 3D location and custom key will be returned for filtering.
  83. If the game wants to filter by direction or anything else, then encode that into the key.
  84. OPTIMIZE:
  85. * Make a tile based light culling.
  86. The background has pre-stored minimum and maximum depth for tiles of 32² pixel blocks.
  87. The screen has 64² pixel min-max blocks reading from 4-9 background blocks.
  88. Drawing active sprites will write using its own 32² max blocks to the screens depth bound.
  89. Minimum is kept because drawing can only increase and rarely covers whole areas.
  90. Each 64² block on the screen then generates a tilted cube hull of the region's visible pixels.
  91. This tells which light frustums are seen and which parts of their cube maps have to be rendered.
  92. After rendering the seen shadow-map viewports, blocks including the same set of light sources are merged horizontally.
  93. A vertical split of blocks is used for multi-threading.
  94. Example light count for square light regions (real regions will be shaped by 3D light frustums intersecting visible pixel bounds)
  95. 0--01----10-0
  96. 1--12-21-10-0
  97. 1--12-21-10-0
  98. 1-----10----0
  99. * Decrease peak time using a vertical brick pattern using a half row offset on odd background block columns.
  100. This is optimized for wide aspect ratios, which is more common than standing formats.
  101. Cutting the peak repainting area into half without increasing the minimum buffered region.
  102. Scheduling updates of nearby blocks can take one at a time when there's nothing that must be updated instantly.
  103. * Create a debug feature in spriteAPI for displaying the octree using lines.
  104. One color for the owned space and another for the sprite bounding boxes.
  105. Pressing a certain button in Sandbox should toggle the debug drawing to allow asserting that the tree is well balanced for the level's size.
  106. LATER:
  107. * Make a ground layer using height and blend maps for outdoor scenes.
  108. Each tile region will decide if ground should be drawn there.
  109. Disabling the ground on a tile will look at the main tile replacing the ground for walking heights.
  110. Grass and small stones will use a separate system, because background sprites do not adapt to the ground height.
  111. These can be generated from deterministic random values compared against blend maps to save space.
  112. Additional natural sprites can be added one by one at specific locations.
  113. * When loading the frames from an atlas, crop the images further and apply separate offsets per frame.
  114. This will significantly improve rendering speed for 8 direction sprites.
  115. */
  116. #include "../../DFPSR/includeFramework.h"
  117. #include "sprite/spriteAPI.h"
  118. #include "../../DFPSR/image/PackOrder.h"
  119. #include <assert.h>
  120. #include <limits>
  121. using namespace dsr;
  122. static const String mediaPath = string_combine(U"media", file_separator());
  123. static const String imagePath = string_combine(mediaPath, U"images", file_separator());
  124. // Variables
  125. static bool running = true;
  126. static IVector2D mousePos;
  127. static bool panorate = false;
  128. static bool tileAlign = false;
  129. static bool showOverlays = true;
  130. static int debugView = 0;
  131. static int mouseLights = 1;
  132. // The window handle
  133. static Window window;
  134. static int random(const int minimum, const int maximum) {
  135. if (maximum > minimum) {
  136. return (std::rand() % (maximum + 1 - minimum)) + minimum;
  137. } else {
  138. return minimum;
  139. }
  140. }
  141. // Variables
  142. static Sprite brush(0, dir0, IVector3D(), true);
  143. static const int brushStep = ortho_miniUnitsPerTile / 32;
  144. static int buttonPressed[4] = {0, 0, 0, 0};
  145. static IVector2D cameraMovement;
  146. static const float cameraSpeed = 1.0f;
  147. // World
  148. static SpriteWorld world;
  149. bool ambientLight = true;
  150. void sandbox_main() {
  151. // Create the world
  152. world = spriteWorld_create(OrthoSystem(string_load(string_combine(mediaPath, U"Ortho.ini"))), 256);
  153. // Create a window
  154. String title = U"David Piuva's Software Renderer - Graphics sandbox";
  155. window = window_create(title, 1600, 900);
  156. //window = window_create_fullscreen(title);
  157. // Load an interface to the window
  158. window_loadInterfaceFromFile(window, mediaPath + U"interface.lof");
  159. // Tell the application to terminate when the window is closed
  160. window_setCloseEvent(window, []() {
  161. running = false;
  162. });
  163. // Get direct window events
  164. window_setMouseEvent(window, [](const MouseEvent& event) {
  165. if (event.mouseEventType == MouseEventType::MouseMove) {
  166. if (panorate) {
  167. // Move the camera in exact pixels
  168. spriteWorld_moveCameraInPixels(world, mousePos - event.position);
  169. }
  170. mousePos = event.position;
  171. }
  172. });
  173. window_setKeyboardEvent(window, [](const KeyboardEvent& event) {
  174. DsrKey key = event.dsrKey;
  175. if (event.keyboardEventType == KeyboardEventType::KeyDown) {
  176. if (key == DsrKey_V) {
  177. debugView = 0;
  178. } else if (key == DsrKey_B) {
  179. debugView = 1;
  180. } else if (key == DsrKey_N) {
  181. debugView = 2;
  182. } else if (key == DsrKey_M) {
  183. debugView = 3;
  184. } else if (key == DsrKey_L) {
  185. debugView = 4;
  186. } else if (key >= DsrKey_1 && key <= DsrKey_9) {
  187. window_setPixelScale(window, key - DsrKey_0);
  188. } else if (key == DsrKey_R) {
  189. ambientLight = !ambientLight;
  190. } else if (key == DsrKey_T) {
  191. tileAlign = !tileAlign;
  192. } else if (key == DsrKey_F) {
  193. showOverlays = !showOverlays;
  194. } else if (key == DsrKey_K) {
  195. mouseLights = (mouseLights + 1) % 5;
  196. } else if (key == DsrKey_Q) {
  197. // Previous type
  198. brush.typeIndex = (brush.typeIndex + sprite_getTypeCount() - 1) % sprite_getTypeCount();
  199. } else if (key == DsrKey_E) {
  200. // Next type
  201. brush.typeIndex = (brush.typeIndex + 1) % sprite_getTypeCount();
  202. } else if (key == DsrKey_X) {
  203. brush.direction = correctDirection(brush.direction + dir90);
  204. } else if (key == DsrKey_C) {
  205. // Rotate the world clockwise using four camera angles
  206. spriteWorld_setCameraDirectionIndex(world, (spriteWorld_getCameraDirectionIndex(world) + 1) % 4);
  207. } else if (key == DsrKey_Z) {
  208. // Rotate the world counter-clockwise using four camera angles
  209. spriteWorld_setCameraDirectionIndex(world, (spriteWorld_getCameraDirectionIndex(world) + 3) % 4);
  210. } else if (key == DsrKey_F11) {
  211. // Toggle full-screen
  212. window_setFullScreen(window, !window_isFullScreen(window));
  213. } else if (key == DsrKey_Escape) {
  214. // Terminate safely after the next frame
  215. running = false;
  216. } else if (key == DsrKey_LeftArrow || key == DsrKey_A) {
  217. buttonPressed[0] = 1;
  218. } else if (key == DsrKey_RightArrow || key == DsrKey_D) {
  219. buttonPressed[1] = 1;
  220. } else if (key == DsrKey_UpArrow || key == DsrKey_W) {
  221. buttonPressed[2] = 1;
  222. } else if (key == DsrKey_DownArrow || key == DsrKey_S) {
  223. buttonPressed[3] = 1;
  224. }
  225. } else if (event.keyboardEventType == KeyboardEventType::KeyUp) {
  226. if (key == DsrKey_LeftArrow || key == DsrKey_A) {
  227. buttonPressed[0] = 0;
  228. } else if (key == DsrKey_RightArrow || key == DsrKey_D) {
  229. buttonPressed[1] = 0;
  230. } else if (key == DsrKey_UpArrow || key == DsrKey_W) {
  231. buttonPressed[2] = 0;
  232. } else if (key == DsrKey_DownArrow || key == DsrKey_S) {
  233. buttonPressed[3] = 0;
  234. }
  235. }
  236. cameraMovement.x = buttonPressed[1] - buttonPressed[0];
  237. cameraMovement.y = buttonPressed[3] - buttonPressed[2];
  238. });
  239. // Get component handles and assign actions
  240. Component mainPanel = window_getRoot(window);
  241. component_setMouseDownEvent(mainPanel, [](const MouseEvent& event) {
  242. if (event.key == MouseKeyEnum::Left) {
  243. // Place a new visual instance using the brush
  244. spriteWorld_addBackgroundSprite(world, brush);
  245. } else if (event.key == MouseKeyEnum::Right) {
  246. panorate = true;
  247. }
  248. });
  249. component_setMouseUpEvent(mainPanel, [](const MouseEvent& event) {
  250. if (event.key == MouseKeyEnum::Right) {
  251. panorate = false;
  252. }
  253. });
  254. component_setMouseScrollEvent(mainPanel, [](const MouseEvent& event) {
  255. if (event.key == MouseKeyEnum::ScrollUp) {
  256. brush.location.y += brushStep;
  257. } else if (event.key == MouseKeyEnum::ScrollDown) {
  258. brush.location.y -= brushStep;
  259. }
  260. });
  261. Component exitButton = window_findComponentByName(window, U"ExitButton");
  262. component_setPressedEvent(exitButton, []() {
  263. running = false;
  264. });
  265. // Create sprite types
  266. sprite_loadTypeFromFile(imagePath, U"Floor");
  267. sprite_loadTypeFromFile(imagePath, U"WoodenFloor");
  268. sprite_loadTypeFromFile(imagePath, U"WoodenFence");
  269. sprite_loadTypeFromFile(imagePath, U"WoodenBarrel");
  270. sprite_loadTypeFromFile(imagePath, U"Pillar");
  271. sprite_loadTypeFromFile(imagePath, U"Character_Mage");
  272. // Create passive sprites
  273. for (int z = -300; z < 300; z++) {
  274. for (int x = -300; x < 300; x++) {
  275. // The bottom floor does not have to throw shadows
  276. spriteWorld_addBackgroundSprite(world, Sprite(random(0, 1), random(0, 3) * dir90, IVector3D(x * ortho_miniUnitsPerTile, 0, z * ortho_miniUnitsPerTile), false));
  277. }
  278. }
  279. for (int z = -300; z < 300; z++) {
  280. for (int x = -300; x < 300; x++) {
  281. if (random(1, 4) == 1) {
  282. // Obstacles should cast shadows when possible
  283. spriteWorld_addBackgroundSprite(world, Sprite(random(2, 4), random(0, 3) * dir90, IVector3D(x * ortho_miniUnitsPerTile, 0, z * ortho_miniUnitsPerTile), true));
  284. } else if (random(1, 20) == 1) {
  285. // Characters are just static geometry for testing
  286. spriteWorld_addBackgroundSprite(world, Sprite(5, random(0, 7) * dir45, IVector3D(x * ortho_miniUnitsPerTile, 0, z * ortho_miniUnitsPerTile), true));
  287. }
  288. }
  289. }
  290. // Animation timing
  291. double frameStartTime = time_getSeconds();
  292. double secondsPerFrame = 0.0;
  293. double stepRemainder = 0.0;
  294. // Profiling
  295. double profileStartTime = time_getSeconds();
  296. int64_t profileFrameCount = 0; // Frames per second
  297. float profileFrameRate = 0.0f;
  298. double maxFrameTime = 0.0, lastMaxFrameTime = 0.0; // Peak per second
  299. while(running) {
  300. double startTime;
  301. // Execute actions
  302. window_executeEvents(window);
  303. // Request buffers after executing the events, to get newly allocated buffers after resize events
  304. AlignedImageRgbaU8 colorBuffer = window_getCanvas(window);
  305. // Calculate a number of whole millisecond ticks per frame
  306. // By performing game logic in multiples of msTicks, integer operations
  307. // can be scaled without comming to a full stop in high frame rates
  308. stepRemainder += secondsPerFrame * 1000.0;
  309. int msTicks = (int)stepRemainder;
  310. stepRemainder -= (double)msTicks;
  311. // Move the camera
  312. int cameraSteps = (int)(cameraSpeed * msTicks);
  313. // TODO: Find a way to move the camera using exact pixel offsets so that the camera's 3D location is only generating the 2D offset when rotating.
  314. // Can the brush be guaranteed to come back to the mouse location after adding and subtracting the same 2D camera offset?
  315. // A new integer coordinate system along the ground might move half a pixel vertically and a full pixel sideways in the diagonal view.
  316. // Otherwise the approximation defeats the whole purpose of using whole integers in msTicks.
  317. spriteWorld_moveCameraInPixels(world, cameraMovement * cameraSteps);
  318. // Remove temporary visuals
  319. spriteWorld_clearTemporary(world);
  320. // Place the brush
  321. IVector3D mouseWorldPos = spriteWorld_findGroundAtPixel(world, colorBuffer, mousePos);
  322. brush.location.x = mouseWorldPos.x;
  323. brush.location.z = mouseWorldPos.z;
  324. if (tileAlign) {
  325. brush.location = ortho_roundToTile(brush.location);
  326. }
  327. // Illuminate the world using soft light from the sky
  328. if (ambientLight) {
  329. spriteWorld_createTemporary_directedLight(world, FVector3D(1.0f, -1.0f, 0.0f), 0.1f, ColorRgbI32(255, 255, 255));
  330. }
  331. // Create a temporary point light over the brush
  332. // Temporary light sources are easier to use for dynamic light because they don't need any handle
  333. if (mouseLights == 1) {
  334. spriteWorld_createTemporary_pointLight(world, ortho_miniToFloatingTile(brush.location) + FVector3D(0.0f, 0.5f, 0.0f), 4.0f, 4.0f, ColorRgbI32(128, 255, 128), true);
  335. } else if (mouseLights == 2) {
  336. spriteWorld_createTemporary_pointLight(world, ortho_miniToFloatingTile(brush.location) + FVector3D(-2.0f, 0.5f, 1.0f), 4.0f, 2.0f, ColorRgbI32(255, 128, 128), true);
  337. spriteWorld_createTemporary_pointLight(world, ortho_miniToFloatingTile(brush.location) + FVector3D(2.0f, 0.52f, -1.0f), 4.0f, 2.0f, ColorRgbI32(128, 255, 128), true);
  338. } else if (mouseLights == 3) {
  339. spriteWorld_createTemporary_pointLight(world, ortho_miniToFloatingTile(brush.location) + FVector3D(-2.0f, 0.5f, 1.0f), 4.0f, 1.333f, ColorRgbI32(255, 128, 128), true);
  340. spriteWorld_createTemporary_pointLight(world, ortho_miniToFloatingTile(brush.location) + FVector3D(1.0f, 0.51f, 2.0f), 4.0f, 1.333f, ColorRgbI32(128, 255, 128), true);
  341. spriteWorld_createTemporary_pointLight(world, ortho_miniToFloatingTile(brush.location) + FVector3D(2.0f, 0.52f, -1.0f), 4.0f, 1.333f, ColorRgbI32(128, 128, 255), true);
  342. } else if (mouseLights == 4) {
  343. spriteWorld_createTemporary_pointLight(world, ortho_miniToFloatingTile(brush.location) + FVector3D(-2.0f, 0.5f, 1.0f), 4.0f, 1.0f, ColorRgbI32(255, 128, 128), true);
  344. spriteWorld_createTemporary_pointLight(world, ortho_miniToFloatingTile(brush.location) + FVector3D(1.0f, 0.51f, 2.0f), 4.0f, 1.0f, ColorRgbI32(128, 255, 128), true);
  345. spriteWorld_createTemporary_pointLight(world, ortho_miniToFloatingTile(brush.location) + FVector3D(2.0f, 0.52f, -1.0f), 4.0f, 1.0f, ColorRgbI32(128, 128, 255), true);
  346. spriteWorld_createTemporary_pointLight(world, ortho_miniToFloatingTile(brush.location) + FVector3D(-1.0f, 0.53f, -2.0f), 4.0f, 1.0f, ColorRgbI32(255, 255, 128), true);
  347. }
  348. // Show the brush
  349. spriteWorld_addTemporarySprite(world, brush);
  350. // Draw the world
  351. spriteWorld_draw(world, colorBuffer);
  352. // Debug views (Slow but failsafe)
  353. if (debugView == 1) {
  354. draw_copy(colorBuffer, spriteWorld_getDiffuseBuffer(world));
  355. } else if (debugView == 2) {
  356. draw_copy(colorBuffer, spriteWorld_getNormalBuffer(world));
  357. } else if (debugView == 3) {
  358. AlignedImageF32 heightBuffer = spriteWorld_getHeightBuffer(world);
  359. for (int y = 0; y < image_getHeight(colorBuffer); y++) {
  360. for (int x = 0; x < image_getWidth(colorBuffer); x++) {
  361. float height = image_readPixel_clamp(heightBuffer, x, y) * 255.0f;
  362. if (height < 0.0f) { height = 0.0f; }
  363. if (height > 255.0f) { height = 255.0f; }
  364. image_writePixel(colorBuffer, x, y, ColorRgbaI32(height, 0, 0, 255));
  365. }
  366. }
  367. } else if (debugView == 4) {
  368. draw_copy(colorBuffer, spriteWorld_getLightBuffer(world));
  369. }
  370. // Overlays mode
  371. if (showOverlays) {
  372. startTime = time_getSeconds();
  373. window_drawComponents(window);
  374. debugText("Draw GUI: ", (time_getSeconds() - startTime) * 1000.0, " ms\n");
  375. IVector2D writer = IVector2D(10, 55);
  376. font_printLine(colorBuffer, font_getDefault(), string_combine(U"FPS: ", profileFrameRate), writer, ColorRgbaI32(255, 255, 255, 255)); writer.y += 20;
  377. font_printLine(colorBuffer, font_getDefault(), string_combine(U"avg ms: ", 1000.0f / profileFrameRate), writer, ColorRgbaI32(255, 255, 255, 255)); writer.y += 20;
  378. font_printLine(colorBuffer, font_getDefault(), string_combine(U"max ms: ", 1000.0f * lastMaxFrameTime), writer, ColorRgbaI32(255, 255, 255, 255)); writer.y += 20;
  379. }
  380. window_showCanvas(window);
  381. double newTime = time_getSeconds();
  382. secondsPerFrame = newTime - frameStartTime;
  383. frameStartTime = newTime;
  384. debugText("Total frame: ", secondsPerFrame * 1000.0, " ms\n\n");
  385. // Profiling
  386. if (secondsPerFrame > maxFrameTime) { maxFrameTime = secondsPerFrame; }
  387. profileFrameCount++;
  388. if (newTime > profileStartTime + 1.0) {
  389. double duration = newTime - profileStartTime;
  390. profileFrameRate = (double)profileFrameCount / duration;
  391. profileStartTime = newTime;
  392. profileFrameCount = 0;
  393. lastMaxFrameTime = maxFrameTime;
  394. maxFrameTime = 0.0;
  395. }
  396. }
  397. }