PageRenderTime 70ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/src/RaycastTest.hx

https://github.com/Glidias/Entropia-Raycaster
Haxe | 1084 lines | 859 code | 164 blank | 61 comment | 94 complexity | 4e7332d08d68955af1ea986bd9274f4d MD5 | raw file
  1. /**
  2. * @author Tyler Spaulding
  3. * @author Glenn Ko (ported over to Haxe for Flash/Fp10 AS3)
  4. *
  5. * Test-bed for any new features...
  6. *
  7. * Compiler directives include:
  8. *
  9. -D occlude To test occlusion culling/clipping
  10. -D occludeEarlyOut Whether to skip further raycast jumps if a wall covers the entire height of a screen
  11. -D clippedBottoms Whether to clip the bottom edges of walls during occlusion. (instead of drawing it's entire height)
  12. -D noMaxHeight If enabled, uses a map with no building height limits.
  13. -D testPosition To start at a recorded starting position/angle based on code ( see Start() );
  14. -D debugView To turn on debug view at the beginning ( see Start() ) which allows one to view surfaces transparently.
  15. * See SetupToggles() for a list of available key toggles at the moment.
  16. */
  17. package ;
  18. import flash.display.GraphicsPath;
  19. import flash.display.GraphicsPathCommand;
  20. import flash.display.GraphicsSolidFill;
  21. import flash.display.GraphicsStroke;
  22. import flash.display.IGraphicsData;
  23. import flash.display.Sprite;
  24. import flash.errors.Error;
  25. import flash.events.Event;
  26. import flash.events.KeyboardEvent;
  27. import flash.Lib;
  28. import flash.text.TextField;
  29. import flash.text.TextFieldAutoSize;
  30. import flash.text.TextFieldType;
  31. import flash.ui.Keyboard;
  32. import flash.ui.KeyLocation;
  33. import flash.utils.Dictionary;
  34. import flash.utils.Timer;
  35. import flash.Vector;
  36. import flash.utils.TypedDictionary;
  37. class RaycastTest extends Sprite
  38. {
  39. static inline var CHARSIZE = .3;
  40. static inline var VIEWHEIGHT = 1.5;
  41. static inline var MAX_HEIGHT = #if noMaxHeight 999 #else 4 #end;
  42. static inline var MAXSTEP = .41;
  43. // in meters per second:
  44. static inline var WALKSPEED = 5.4;
  45. static inline var RUNSPEED = 3.4;
  46. static inline var TURNSPEED = 3.8;
  47. static inline var VIEWBOB = 0.1;
  48. static inline var VIEWBOBSPEED = 10;
  49. static inline var KEY_A = 65;
  50. static inline var KEY_B = 66;
  51. static inline var KEY_D = 68;
  52. static inline var KEY_H = 72;
  53. static inline var KEY_I = 73;
  54. static inline var KEY_R = 82;
  55. static inline var KEY_S = 83;
  56. static inline var KEY_P = 80;
  57. static inline var KEY_T = 84;
  58. static inline var KEY_V = 86;
  59. static inline var KEY_W = 87;
  60. static inline var KEY_ARROW_UP = 38;
  61. static inline var KEY_ARROW_DOWN = 40;
  62. static inline var KEY_ARROW_LEFT = 37;
  63. static inline var KEY_ARROW_RIGHT = 39;
  64. static inline var KEY_WII_UP = 175;
  65. static inline var KEY_WII_DOWN = 176;
  66. static inline var KEY_WII_LEFT = 178;
  67. static inline var KEY_WII_RIGHT = 177;
  68. static inline var KEY_WII_B = 171;
  69. var player:Player;
  70. static var viewBob:Float = VIEWHEIGHT;
  71. static var bobTime:Float = 0;
  72. var pdx:Float;
  73. var pdy:Float;
  74. var dx1:Float;
  75. var dy1:Float;
  76. var dx2:Float;
  77. var dy2:Float;
  78. var ddx:Float;
  79. var ddy:Float;
  80. var playerXInt:Int;
  81. var playerYInt:Int;
  82. var raycount:Int;
  83. var outlineCount:Int;
  84. var wallcount:Int;
  85. var divCount:Int;
  86. var mapHeight:Array<Array<Float>>;
  87. var mapWallColor:Array<Array<UInt>>;
  88. var mapFloorColor:Array<Array<UInt>>;
  89. var mapDepth:Int;
  90. var mapWidth:Int;
  91. var mapWallIdxCount:Int;
  92. var wallColors:Array<Array<UInt>>;
  93. var floorColors:Array<UInt>;
  94. static var lastmousex:Float = -1;
  95. static var verbose:Bool = false;
  96. static var debugMode:Bool = false;
  97. static var renderingEnabled:Bool = true;
  98. static var showStats:Bool = false;
  99. static var showHelp:Bool = true;
  100. static var showSplits:Bool = false;
  101. static var isPaused:Bool = false;
  102. // Caching
  103. static var keys:Dictionary = new Dictionary();
  104. static var toggles:TypedDictionary<UInt,Dynamic> = new TypedDictionary();
  105. static var keysCache:Dictionary = new Dictionary();
  106. var wallCache:TypedDictionary<Int,Wall>;
  107. var wallArray:Array<Wall>;
  108. var splitList:Array<Split>;
  109. // Rendering
  110. public var graphicData:Vector<IGraphicsData>;
  111. // framerate and timer stuff
  112. static var frames:Int = 0;
  113. static var fps:Float = 0;
  114. static var lastFrameSeconds:Float = 0;
  115. static var curTime:Int;
  116. static var prevTime:Int;
  117. static var frameCountStart:Float = 0;
  118. public function new()
  119. {
  120. super();
  121. Init();
  122. }
  123. function BuildColors()
  124. {
  125. wallColors = [
  126. [0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff],
  127. [0x7f7f7f, 0x9f9f9f, 0xbfbfbf, 0x5f5f5f],
  128. [0x777777, 0x979797, 0xb7b7b7, 0x575757],
  129. [0x8f6f4f, 0x6f5f3f, 0x8f6f4f, 0x6f5f3f],
  130. [0x5f3f1f, 0x4f3f1f, 0x5f3f1f, 0x4f3f1f],
  131. [0x573717, 0x473717, 0x573717, 0x473717],
  132. [0xdf1f1f, 0xdf1f1f, 0xdf1f1f, 0xdf1f1f]];
  133. floorColors = [0x00ff00, 0x00ef00, 0x00df00, 0x00af00, 0xff00ff, 0xff0000];
  134. }
  135. ///*
  136. function BuildMap()
  137. {
  138. #if noMaxHeight
  139. mapHeight = [
  140. [4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0 ],
  141. [4.0, 0, 0, 0, 0, 0, 0,4.0,1.2,1.2,1.2,1.2,1.4,1.4,1.4,1.6,1.6,1.6,1.8,1.8,1.8,2.0,2.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,4.0 ],
  142. [4.0, 0, 0, 0, 0, 0, 0,4.0,1.2,1.2,1.2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1, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 2 ],
  300. [ 2, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 1 ],
  301. [ 1, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 2 ],
  302. [ 2, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 1 ],
  303. [ 1, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 2 ],
  304. [ 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1 ]];
  305. // depth x width
  306. mapDepth = mapHeight.length;
  307. mapWidth = mapHeight[0].length;
  308. mapWallIdxCount = mapWidth * (mapDepth + 1) + mapDepth * (mapWidth + 1);
  309. }
  310. var logField:TextField;
  311. var laggyField:TextField;
  312. inline function SetupStage():Void {
  313. addChild( (logField = new TextField() ) );
  314. logField.multiline = true;
  315. logField.width = 300;
  316. logField.autoSize = TextFieldAutoSize.LEFT;
  317. logField.selectable = true;
  318. addChild ( laggyField = new TextField() ) ;
  319. laggyField.multiline = true;
  320. laggyField.width = 300;
  321. laggyField.y = 400;
  322. laggyField.autoSize = TextFieldAutoSize.LEFT;
  323. addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
  324. }
  325. function onAddedToStage(e:Event):Void {
  326. removeEventListener(Event.ADDED, onAddedToStage);
  327. stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyDown);
  328. stage.addEventListener(KeyboardEvent.KEY_UP, KeyUp);
  329. }
  330. function AddToggle(key:UInt , func:Dynamic) {
  331. toggles[key] = func;
  332. }
  333. function SetupToggles():Void {
  334. toggles = new flash.utils.TypedDictionary();
  335. AddToggle(KEY_B, function() { debugMode = !debugMode; });
  336. //AddToggle(KEY_H, function() { showHelp = !showHelp; });
  337. AddToggle(KEY_I, function() { showStats = !showStats; });
  338. AddToggle(KEY_R, function() { renderingEnabled = !renderingEnabled; } );
  339. AddToggle(KEY_P, togglePause );
  340. AddToggle(KEY_T, togglePauseAndSplit );
  341. //AddToggle(KEY_V, function() { verbose = !verbose; } );
  342. }
  343. function Init() {
  344. BuildColors();
  345. BuildMap();
  346. SetupStage();
  347. SetupToggles();
  348. player = new Player();
  349. player.x = 1.5;
  350. player.y = 1.5;
  351. player.h = mapHeight[1][1];
  352. player.angle = Math.PI / 4.0;
  353. Start();
  354. }
  355. function Start() {
  356. #if testPosition
  357. setPosition(24.7, 24.064928781071682);
  358. setAngle(4.192212856217854);
  359. #end
  360. #if debugView
  361. debugMode = true;
  362. #end
  363. addEventListener(Event.ENTER_FRAME, Render);
  364. }
  365. function togglePause(?e:Event=null) {
  366. isPaused = !isPaused; if (isPaused) Pause() else UnPause();
  367. }
  368. function togglePauseAndSplit(?e:Event = null) {
  369. showSplits = true;
  370. Pause();
  371. laggyField.text = "Loading splits..Please wait.";
  372. stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDownResume, false, 1);
  373. _noTicks = 0;
  374. stage.addEventListener(Event.EXIT_FRAME, nextTickRender);
  375. }
  376. var _noTicks:Int;
  377. private function nextTickRender(e:Event):Void {
  378. _noTicks++;
  379. if (_noTicks > 1) {
  380. stage.removeEventListener(Event.EXIT_FRAME, nextTickRender);
  381. Render();
  382. logField.text += "\nSplits loaded....\nPress and key to continue.";
  383. laggyField.text = "";
  384. _noTicks = 0;
  385. }
  386. }
  387. private function onKeyDownResume(e:KeyboardEvent):Void {
  388. showSplits = false;
  389. stage.removeEventListener(Event.EXIT_FRAME, nextTickRender);
  390. stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDownResume);
  391. UnPause();
  392. e.stopImmediatePropagation();
  393. }
  394. inline function Pause() {
  395. isPaused = true;
  396. laggyField.text = "Paused. Controls locked. Press P to unlock again.";
  397. removeEventListener(Event.ENTER_FRAME, Render);
  398. }
  399. inline function UnPause() {
  400. isPaused = false;
  401. showSplits = false;
  402. removeEventListener(Event.ENTER_FRAME, Render);
  403. addEventListener(Event.ENTER_FRAME, Render);
  404. laggyField.text = "";
  405. }
  406. function Render(?e:Event=null):Void {
  407. frames++;
  408. outlineCount = 0;
  409. wallcount = 0;
  410. divCount = 0;
  411. // consider: buffering/caching
  412. wallCache = new TypedDictionary();
  413. splitList = [];
  414. graphicData = new Vector();
  415. wallArray = [];
  416. curTime = getTime();
  417. lastFrameSeconds = (curTime - prevTime) / 1000;
  418. if (curTime - frameCountStart > 1000) {
  419. fps = Std.int(100000 * frames / (curTime - frameCountStart)) / 100;
  420. frames = 0;
  421. frameCountStart = curTime;
  422. }
  423. prevTime = curTime;
  424. ClearLog();
  425. DoMove();
  426. DoPreCalcs();
  427. raycount = 0;
  428. RenderSky();
  429. RenderMap();
  430. SwapBuffers();
  431. if (showStats) ShowStats();
  432. //if (showHelp) ShowHelp();
  433. }
  434. inline function getTime():Int {
  435. return Lib.getTimer();
  436. }
  437. inline function DoPreCalcs():Void {
  438. if (player.angle > 2 * Math.PI) player.angle -= 2 * Math.PI;
  439. if (player.angle < 0) player.angle += 2 * Math.PI;
  440. pdx = Math.cos(player.angle);
  441. pdy = Math.sin(player.angle);
  442. dx1 = pdx + pdy; // ray for left edge of screen
  443. dy1 = pdy - pdx;
  444. dx2 = pdx - pdy; // ray for right edge of screen
  445. dy2 = pdy + pdx;
  446. ddx = (dx2 - dx1) / 1000; // difference between rays
  447. ddy = (dy2 - dy1) / 1000;
  448. playerXInt = Std.int(player.x);
  449. playerYInt = Std.int(player.y);
  450. }
  451. inline function AddDiv(left:Int, right:Int, top1:Int, top2:Int, bottom:Int, z:Float, c:UInt):Void {
  452. divCount++;
  453. graphicData.push( new GraphicsSolidFill(c, (debugMode ? .4 : 1) ) ); //
  454. var commands : flash.Vector<Int> = new flash.Vector(4, true);
  455. var data : flash.Vector<Float> = new flash.Vector(8,true);
  456. commands[0] = GraphicsPathCommand.MOVE_TO;
  457. commands[1] = GraphicsPathCommand.LINE_TO;
  458. commands[2] = GraphicsPathCommand.LINE_TO;
  459. commands[3] = GraphicsPathCommand.LINE_TO;
  460. data[0] = left; data[1] = top1;
  461. data[2] = right; data[3] = top2;
  462. data[4] = right; data[5] = bottom;
  463. data[6] = left; data[7] = bottom;
  464. graphicData.push( new GraphicsPath(commands,data) );
  465. }
  466. inline function AddSplitDiv(left:Int, right:Int, top:Int, bottom:Int, c:UInt):Void {
  467. graphics.lineStyle(0, 0xFF0000);
  468. var stroke:GraphicsStroke = new GraphicsStroke(0);
  469. stroke.fill = new GraphicsSolidFill(0xFF0000, .1);
  470. graphicData.push(stroke );
  471. var commands:Vector<Int> = new Vector(6, true);
  472. var data:Vector<Float> = new Vector(12, true);
  473. commands[0] = GraphicsPathCommand.MOVE_TO;
  474. commands[1] = GraphicsPathCommand.LINE_TO;
  475. commands[2] = GraphicsPathCommand.MOVE_TO;
  476. commands[3] = GraphicsPathCommand.LINE_TO;
  477. commands[4] = GraphicsPathCommand.MOVE_TO;
  478. commands[5] = GraphicsPathCommand.LINE_TO;
  479. data[0] = left; data[1] = top;
  480. data[2] = left; data[3] = bottom;
  481. data[4] = right; data[5] = top;
  482. data[6] = right; data[7] = bottom;
  483. var middle:Int = Math.round( (right - left) * .5);
  484. data[8] = middle; data[9] = top;
  485. data[10] = middle; data[11] = bottom;
  486. graphicData.push( new GraphicsPath(commands, data ) );
  487. }
  488. inline function SwapBuffers():Void {
  489. graphics.clear();
  490. if (debugMode) graphics.lineStyle(0, 0);
  491. graphics.drawGraphicsData(graphicData);
  492. }
  493. function RenderSky():Void {
  494. }
  495. function RenderMap():Void {
  496. var left:Ray = new Ray(0, CastRay(dx1, dy1) );
  497. var right:Ray = new Ray( 1000, CastRay(dx2, dy2) );
  498. SplitRay(left, right, 0, player.h, 500, 500);
  499. if (!renderingEnabled) return;
  500. untyped wallArray.sortOn("z");
  501. var len:Int = wallArray.length;
  502. for (i in 0...len) {
  503. var wall = wallArray[i];
  504. #if occlude
  505. var leftClipped:Bool = wall.leftNode!= null ? wall.leftNode.isClipped : false;
  506. var rightClipped:Bool = wall.rightNode != null ? wall.rightNode.isClipped : leftClipped;
  507. if (wall.dirtyFlag == 3) {
  508. if (wall.leftNode!=null) wall.top1 = Project(wall.leftNode.t, wall.leftNode.h1);
  509. if (wall.rightNode != null) wall.top2 = Project(wall.rightNode.t, wall.rightNode.h1);
  510. }
  511. var wallIsClipped:Bool = leftClipped && rightClipped && wall.dirtyFlag != 3;
  512. /*
  513. if () {
  514. if (wall.top1 > wall.top2) {
  515. wall.top2 = wall.top1;
  516. }
  517. else {
  518. wall.top1 = wall.top2;
  519. }
  520. wallIsClipped = wall.dirtyFlag != 3;
  521. }
  522. */
  523. #end
  524. #if occlude
  525. if (!wallIsClipped) {
  526. #end
  527. //wall.bottom += 16;
  528. //wall.bottom+= wallIsCl16; // for the case of step-downs, the bottoms need to be extended to fill
  529. // possible whitespaces
  530. AddDiv(wall.x1, wall.x2, wall.top1, wall.top2, wall.bottom, wall.z, wall.color);
  531. #if occlude
  532. }
  533. #end
  534. }
  535. if (showSplits) {
  536. for ( split in splitList) {
  537. AddSplitDiv(split.left, split.right, 0, 500, 0x000000);
  538. }
  539. }
  540. }
  541. inline function setPosition(x:Float, y:Float):Void {
  542. player.x = x;
  543. player.y = y;
  544. player.h = mapHeight[Std.int(player.y)][Std.int(player.x)];
  545. }
  546. inline function setAngle(ang:Float):Void {
  547. player.angle = ang;
  548. }
  549. function MoveX(ox:Float, oy:Float, vx:Float, vy:Float, size:Float) {
  550. var newx = ox + vx;
  551. var yi = Std.int(oy);
  552. var h = mapHeight[yi][Std.int(ox)];
  553. if (vx > 0){
  554. var xi = Std.int(newx + size);
  555. if (mapHeight[yi][xi] < h + MAXSTEP) {
  556. ox = newx;
  557. } else {
  558. ox = xi - size;
  559. }
  560. } else {
  561. var xi = Std.int(newx - size);
  562. if (mapHeight[yi][xi] < h + MAXSTEP) {
  563. ox = newx;
  564. } else {
  565. ox = xi + 1 + size;
  566. }
  567. }
  568. return ox;
  569. }
  570. function MoveY(ox:Float, oy:Float, vx:Float, vy:Float, size:Float) {
  571. var newy = oy + vy;
  572. var xi = Std.int(ox);
  573. var h = mapHeight[Std.int(oy)][xi];
  574. if (vy > 0) {
  575. var yi = Std.int(newy + size);
  576. if (mapHeight[yi][xi] < h + MAXSTEP) {
  577. oy = newy;
  578. } else {
  579. oy = yi - size;
  580. }
  581. } else {
  582. var yi = Std.int(newy - size);
  583. if (mapHeight[yi][xi] < h + MAXSTEP) {
  584. oy = newy;
  585. } else {
  586. oy = yi + 1 + size;
  587. }
  588. }
  589. return oy;
  590. }
  591. inline function ShowStats()
  592. {
  593. Log(raycount + " rays cast");
  594. Log(divCount + " objects rendered");
  595. Log("Position: (" + player.x + ", " + player.y +")");
  596. Log("Angle: " + player.angle);
  597. Log("Frame rate: " + fps);
  598. }
  599. inline function ClearLog()
  600. {
  601. logField.text = "";
  602. }
  603. inline function Log(text:String)
  604. {
  605. logField.appendText(text+"\n");
  606. }
  607. // Cast a ray until a wall of MAXHEIGHT is found
  608. function CastRay(dx:Float, dy:Float):Vector<Node> {
  609. raycount++;
  610. var xt:Float; // time until the next x-intersection
  611. var dxt:Float; // time between x-intersections
  612. var yt:Float; // time until the next y-intersection
  613. var dyt:Float; // time between y-intersections
  614. var dxi:Int; // direction of the x-intersection
  615. var dyi:Int; // direction of the y-intersection
  616. var xi:Int = playerXInt;
  617. var yi:Int = playerYInt;
  618. var xoff:Float = player.x - xi;
  619. var yoff:Float = player.y - yi;
  620. if (dx < 0) {
  621. xt = -xoff / dx;
  622. dxt = -1 / dx;
  623. dxi = -1;
  624. } else {
  625. xt = (1 - xoff) / dx;
  626. dxt = 1 / dx;
  627. dxi = 1;
  628. }
  629. if (dy < 0) {
  630. yt = -yoff / dy;
  631. dyt = -1 / dy;
  632. dyi = -1;
  633. } else {
  634. yt = (1 - yoff) / dy;
  635. dyt = 1 / dy;
  636. dyi = 1;
  637. }
  638. var t = .0; // intersection time
  639. var done:Bool = false;
  640. var c = 0; // intersection count
  641. var nodes = new Vector<Node>();
  642. var prevH = mapHeight[yi][xi];
  643. var h = .0;
  644. var prevFloorColor = mapFloorColor[yi][xi];
  645. var wallIdx = -1;
  646. var side:Int;
  647. var xint:Float;
  648. var yint:Float;
  649. var lastH:Float = 0;
  650. #if occlude
  651. var yProj:Int = 1000;
  652. #end
  653. while (!done) {
  654. if (xt < yt) {
  655. xi += dxi;
  656. t = xt;
  657. side = dxi > 0 ? 1 : 3;
  658. wallIdx = GetWallIndex(xi - dxi, yi, xi, yi);
  659. xt += dxt;
  660. } else {
  661. yi += dyi;
  662. t = yt;
  663. side = dyi > 0 ? 2 : 0;
  664. wallIdx = GetWallIndex(xi, yi - dyi, xi, yi);
  665. yt += dyt;
  666. }
  667. #if noMaxHeight
  668. if (yi < 0 || yi >( mapDepth-1) || xi < 0 || xi > (mapWidth-1) ) {
  669. done = true;
  670. break;
  671. }
  672. #end
  673. h = mapHeight[yi][xi];
  674. xint = player.x + t * dx;
  675. yint = player.y + t * dy;
  676. #if occlude
  677. var testProj:Int = Project( t, maxF(h, prevH) );
  678. // consider clip testProj to 0
  679. //if ( testProj <= yProj ) {
  680. var isValid:Bool = testProj <= yProj;
  681. #end
  682. var ppH:Int = Project(t, prevH );
  683. nodes.push( new Node(wallIdx, t, prevH, h, 500 -c, prevFloorColor, mapWallColor[yi][xi], side #if occlude , testProj, #if clippedBottoms min(ppH , yProj) #else ppH #end, isValid, yProj<=ppH #end ));
  684. #if occlude
  685. //}
  686. if (testProj < yProj) lastH = h;
  687. //if (prevH != h)
  688. yProj = prevH > h && prevH - h < 1.2 ? yProj : min(testProj, yProj); //2 without artifacts
  689. #end
  690. prevH = h;
  691. prevFloorColor = mapFloorColor[yi][xi];
  692. done = (h == MAX_HEIGHT #if (occlude && occludeEarlyOut) || testProj <= 0 #end ); //
  693. c += 2;
  694. if (c > 400) {
  695. t = 400;
  696. done = true;
  697. }
  698. }
  699. return nodes;
  700. }
  701. inline function Project(t:Float, h:Float):Int {
  702. return Std.int(250 - 250 * (h - player.h - viewBob) / t);
  703. }
  704. inline function diff(v1:Float, v2:Float):Float {
  705. return v1 < v2 ? v2 - v1 : v2 - v1;
  706. }
  707. function SplitRay(left:Ray, right:Ray, firstIntIdx:Int, prevH:Float, prevLeftY:Int, prevRightY:Int):Void {
  708. var leftX = left.x;
  709. var rightX = right.x;
  710. var leftNodes = left.nodes;
  711. var rightNodes = right.nodes;
  712. splitList.push( new Split(leftX, rightX, prevLeftY, prevRightY) );
  713. if (rightX - leftX > 1) {
  714. var commonIntersections:Int = min(leftNodes.length, rightNodes.length);
  715. for ( i in firstIntIdx...commonIntersections) {
  716. var leftNode = leftNodes[i];
  717. var rightNode = rightNodes[i];
  718. if (leftNode.wallIdx == rightNode.wallIdx) {
  719. var h1 = leftNode.h1;
  720. var h2 = leftNode.h2;
  721. var leftY1 = #if occlude leftNode.prevProjY; #else Project(leftNode.t, h1); #end
  722. var leftY2 = #if occlude leftNode.projY; #else Project(leftNode.t, h2); #end
  723. var rightY1 = #if occlude rightNode.prevProjY; #else Project(rightNode.t, h1); #end
  724. var rightY2 = #if occlude rightNode.projY; #else Project(rightNode.t, h2); #end
  725. #if occlude
  726. #end
  727. var z = leftNodes[i].z;
  728. #if occlude if (leftNode.isValid || rightNode.isValid) { #end
  729. if (h1 < h2) {
  730. CacheWall(leftNode.wallIdx, leftX, rightX, leftY2, rightY2, max(leftY1, rightY1) , z, wallColors[leftNode.wColor][leftNode.side] #if occlude #end );
  731. }
  732. CacheWall(mapWallIdxCount + leftNode.wallIdx, leftX, rightX, leftY1, rightY1, max(prevLeftY, prevRightY) + 2, z + 1, floorColors[leftNode.fColor] #if occlude , leftNode, rightNode #end );
  733. #if occlude } #end
  734. prevH = h2;
  735. prevLeftY = #if occlude leftNode.isValid ? #end leftY2 #if occlude : prevLeftY #end;
  736. prevRightY = #if occlude rightNode.isValid ? #end rightY2 #if occlude : prevRightY #end;
  737. } else {
  738. var middleX = Std.int((leftX + rightX) / 2);
  739. var middleDx = dx1 + ddx * middleX;
  740. var middleDy = dy1 + ddy * middleX;
  741. var middle = new Ray(middleX, CastRay(middleDx, middleDy) );
  742. var prevMiddleY = max(prevLeftY, prevRightY);
  743. SplitRay(left, middle, i, prevH, prevLeftY, prevMiddleY);
  744. SplitRay(middle, right, i, prevH, prevMiddleY, prevRightY);
  745. break;
  746. }
  747. }
  748. // if either list is longer, it'll be handled already by the above code
  749. } else {
  750. // the rays are adjacent
  751. // draw the left intersections as single-pixel-wide
  752. for (i in firstIntIdx...leftNodes.length) {
  753. var leftNode = leftNodes[i];
  754. var h1 = leftNode.h1;
  755. var h2 = leftNode.h2;
  756. var leftY1 = #if occlude leftNode.prevProjY; #else Project(leftNode.t, h1); #end
  757. var leftY2 = #if occlude leftNode.projY; #else Project(leftNode.t, h2); #end
  758. var z = leftNode.z;
  759. #if occlude if (leftNode.isValid) { #end
  760. if (h1 < h2) {
  761. CacheWall(leftNode.wallIdx, leftX, rightX, leftY2, leftY2, leftY1 , z, wallColors[leftNode.wColor][leftNode.side]);
  762. }
  763. CacheWall(mapWallIdxCount + leftNode.wallIdx, leftX, rightX, leftY1, leftY1, prevLeftY + 2, z + 1, floorColors[leftNode.fColor] #if occlude , leftNode #end);
  764. #if occlude } #end
  765. prevLeftY = #if occlude leftNode.isValid ? #end leftY2 #if occlude : prevLeftY #end;
  766. }
  767. }
  768. }
  769. /*
  770. inline function CacheWallSurface(leftNode:Node, rightNode:Node, leftX:Int, rightX:Float):Void {
  771. var wallIdx:Int = leftNode.wallIdx;
  772. var wall:Wall = wallCache[ wallIdx ] || (wallCache[wallIdx] = new Wall(leftNode.);
  773. , leftX, rightX, leftY2, rightY2, max(leftY1, rightY1) , z, wallColors[leftNode.wColor][leftNode.side]
  774. }
  775. inline function CacheGroundSurface(leftNode:Node, rightNode:Node):Void {
  776. }
  777. */
  778. function CacheWall(wallIdx:Int, x1:Int, x2:Int, top1:Int, top2:Int, bottom:Int, z:Float, color:UInt #if occlude , leftNode:Node = null, rightNode:Node = null #end):Void {
  779. var wall:Wall;
  780. //leftNode.isClipped;
  781. if ( (wall = wallCache[wallIdx]) != null ) {
  782. #if occlude
  783. wall.dirtyFlag |= leftNode != null ? leftNode.isClipped ? 2 : 1 : 0;
  784. wall.dirtyFlag |= rightNode != null ? rightNode.isClipped ? 2 : 1 : 0;
  785. #end
  786. if (x1 < wallCache[wallIdx].x1) {
  787. wall.x1 = x1;
  788. wall.top1 = top1;
  789. #if occlude
  790. if (leftNode != null) wall.leftNode = leftNode;
  791. #end
  792. }
  793. if (x2 > wall.x2) {
  794. wall.x2 = x2;
  795. wall.top2 = top2;
  796. #if occlude
  797. if (rightNode!=null) wall.rightNode = rightNode;
  798. #end
  799. }
  800. wall.bottom = max(wall.bottom, bottom);
  801. } else {
  802. wallcount++;
  803. wallArray.push (
  804. wallCache[wallIdx] = wall= new Wall(
  805. x1,
  806. x2,
  807. top1,
  808. top2,
  809. bottom,
  810. z,
  811. color )
  812. );
  813. #if occlude
  814. wall.leftNode = leftNode;
  815. wall.rightNode = rightNode;
  816. wall.dirtyFlag |= leftNode != null ? leftNode.isClipped ? 2 : 1 : 0;
  817. wall.dirtyFlag |= rightNode != null ? rightNode.isClipped ? 2 : 1 : 0;
  818. #end
  819. }
  820. }
  821. inline function GetWallIndex(x1:Int, y1:Int, x2:Int, y2:Int):Int {
  822. return x1 == x2 ? mapWidth * min(y1, y2) + x1 : mapWidth * (mapDepth + 1) + (mapWidth + 1) * y1 + min(x1, x2);
  823. }
  824. inline function min(v1:Int, v2:Int):Int {
  825. return v1 < v2 ? v1 : v2;
  826. }
  827. inline function minF(v1:Float, v2:Float):Float {
  828. return v1 < v2 ? v1 : v2;
  829. }
  830. inline function maxF(v1:Float, v2:Float):Float {
  831. return v1 < v2 ? v2 : v1;
  832. }
  833. inline function max(v1:Int, v2:Int):Int {
  834. return v1 < v2 ? v2 : v1;
  835. }
  836. inline function MoveBy(vx:Float, vy:Float) {
  837. player.x = MoveX(player.x, player.y, vx, vy, CHARSIZE);
  838. player.y = MoveY(player.x, player.y, vx, vy, CHARSIZE);
  839. player.h = mapHeight[Std.int(player.y)][Std.int(player.x)];
  840. }
  841. inline function Forward() {
  842. MoveBy(lastFrameSeconds * WALKSPEED * pdx, lastFrameSeconds * WALKSPEED * pdy);
  843. }
  844. inline function Back() {
  845. MoveBy(-lastFrameSeconds * WALKSPEED * pdx, -lastFrameSeconds * WALKSPEED * pdy);
  846. }
  847. inline function StrafeLeft() {
  848. MoveBy(lastFrameSeconds * WALKSPEED * pdy, -lastFrameSeconds * WALKSPEED * pdx);
  849. }
  850. inline function StrafeRight() {
  851. MoveBy(-lastFrameSeconds * WALKSPEED * pdy, lastFrameSeconds * WALKSPEED * pdx);
  852. }
  853. inline function Rotate(i) {
  854. player.angle += i;
  855. }
  856. inline function Left() {
  857. Rotate(-lastFrameSeconds * TURNSPEED);
  858. }
  859. inline function Right() {
  860. Rotate(lastFrameSeconds * TURNSPEED);
  861. }
  862. function KeyDown(e:KeyboardEvent) {
  863. keys[e.keyCode] = true;
  864. DoToggles();
  865. }
  866. function KeyUp(e:KeyboardEvent) {
  867. keys[e.keyCode] = false;
  868. }
  869. inline function Mouse(e) {
  870. if (lastmousex > 0) {
  871. var dmousex = e.screenX - lastmousex;
  872. Rotate(dmousex / 100);
  873. }
  874. lastmousex = e.screenX;
  875. }
  876. inline function DoToggles() {
  877. for (k in toggles) {
  878. if (keys[k]) {
  879. if (!keysCache[k]) toggles[k]();
  880. keysCache[k] = true;
  881. } else {
  882. keysCache[k] = false;
  883. }
  884. }
  885. }
  886. inline function DoMove() {
  887. var moving = false;
  888. if (keys[KEY_W] > 0 || keys[KEY_ARROW_UP] > 0 || keys[KEY_WII_UP]) {
  889. Forward();
  890. moving = true;
  891. }
  892. if (keys[KEY_S] > 0 || keys[KEY_ARROW_DOWN] > 0 || keys[KEY_WII_DOWN]) {
  893. Back();
  894. moving = true;
  895. }
  896. if (keys[KEY_ARROW_LEFT] > 0) {
  897. Left();
  898. moving = true;
  899. }
  900. if (keys[KEY_ARROW_RIGHT] > 0) {
  901. Right();
  902. moving = true;
  903. }
  904. if (keys[KEY_A] > 0 || keys[KEY_WII_LEFT]){
  905. StrafeLeft();
  906. moving = true;
  907. }
  908. if (keys[KEY_D] > 0 || keys[KEY_WII_RIGHT]) {
  909. StrafeRight();
  910. moving = true;
  911. }
  912. if (moving) {
  913. bobTime += lastFrameSeconds;
  914. viewBob = VIEWHEIGHT + VIEWBOB * Math.sin(bobTime * VIEWBOBSPEED);
  915. }
  916. }
  917. }