Cleaned up some code

This commit is contained in:
NeeEoo
2023-03-20 20:34:50 +01:00
parent 7c091445c2
commit c95c1e2975
28 changed files with 1390 additions and 1361 deletions
+103 -103
View File
@@ -51,12 +51,12 @@ class Stage3DProxy extends EventDispatcher
public var bufferClear(get, set):Bool;
public var mouse3DManager(get, set):Mouse3DManager;
public var touch3DManager(get, set):Touch3DManager;
private static var _frameEventDriver:Shape = new Shape();
@:allow(away3d) private var _context3D:Context3D;
@:allow(away3d) private var _stage3DIndex:Int = -1;
private var _usesSoftwareRendering:Bool;
private var _profile:String;
private var _stage3D:Stage3D;
@@ -83,46 +83,46 @@ class Stage3DProxy extends EventDispatcher
private var _bufferClear:Bool;
private var _mouse3DManager:Mouse3DManager;
private var _touch3DManager:Touch3DManager;
private function notifyViewportUpdated():Void
{
if (_viewportDirty)
return;
_viewportDirty = true;
if (!hasEventListener(Stage3DEvent.VIEWPORT_UPDATED))
return;
//TODO: investigate bug causing coercion error
//if (!_viewportUpdated)
_viewportUpdated = new Stage3DEvent(Stage3DEvent.VIEWPORT_UPDATED);
dispatchEvent(_viewportUpdated);
}
private function notifyEnterFrame():Void
{
if (!hasEventListener(Event.ENTER_FRAME))
return;
if (_enterFrame == null)
_enterFrame = new Event(Event.ENTER_FRAME);
dispatchEvent(_enterFrame);
}
private function notifyExitFrame():Void
{
if (!hasEventListener(Event.EXIT_FRAME))
return;
if (_exitFrame == null)
_exitFrame = new Event(Event.EXIT_FRAME);
dispatchEvent(_exitFrame);
}
/**
* Creates a Stage3DProxy object. This method should not be called directly. Creation of Stage3DProxy objects should
* be handled by Stage3DManager.
@@ -134,7 +134,7 @@ class Stage3DProxy extends EventDispatcher
public function new(stage3DIndex:Int, stage3D:Stage3D, stage3DManager:Stage3DManager, forceSoftware:Bool = false, profile:String = "baseline")
{
vertexBufferCount = indexBufferCount = drawTriangleCount = 0;
_stage3DIndex = stage3DIndex;
_stage3D = stage3D;
_stage3D.x = 0;
@@ -143,15 +143,15 @@ class Stage3DProxy extends EventDispatcher
_stage3DManager = stage3DManager;
_viewPort = new Rectangle();
_enableDepthAndStencil = true;
super();
// whatever happens, be sure this has highest priority
_stage3D.addEventListener(Event.CONTEXT3D_CREATE, onContext3DUpdate, false, 1000, false);
this.forceSoftware = forceSoftware;
this._profile = profile;
if (_stage3D.context3D != null) {
onContext3DUpdate(null);
}
@@ -159,14 +159,14 @@ class Stage3DProxy extends EventDispatcher
requestContext(forceSoftware, _profile);
}
}
private var forceSoftware:Bool;
private function get_profile():String
{
return _profile;
}
/**
* Disposes the Stage3DProxy object, freeing the Context3D attached to the Stage3D.
*/
@@ -193,22 +193,22 @@ class Stage3DProxy extends EventDispatcher
if(backBufferHeight<50) backBufferHeight = 50;
var oldWidth:Int = _backBufferWidth;
var oldHeight:Int = _backBufferHeight;
_backBufferWidth = backBufferWidth;
_backBufferHeight = backBufferHeight;
_viewPort.width = backBufferWidth;
_viewPort.height = backBufferHeight;
if (oldWidth != _backBufferWidth || oldHeight != _backBufferHeight)
notifyViewportUpdated();
_antiAlias = antiAlias;
_enableDepthAndStencil = enableDepthAndStencil;
if (_context3D != null)
_context3D.configureBackBuffer(backBufferWidth, backBufferHeight, antiAlias, enableDepthAndStencil, true, true);
}
/*
* Indicates whether the depth and stencil buffer is used
*/
@@ -216,24 +216,24 @@ class Stage3DProxy extends EventDispatcher
{
return _enableDepthAndStencil;
}
private function set_enableDepthAndStencil(enableDepthAndStencil:Bool):Bool
{
_enableDepthAndStencil = enableDepthAndStencil;
_backBufferDirty = true;
return enableDepthAndStencil;
}
private function get_renderTarget():TextureBase
{
return _renderTarget;
}
private function get_renderSurfaceSelector():Int
{
return _renderSurfaceSelector;
}
public function setRenderTarget(target:TextureBase, enableDepthAndStencil:Bool = false, surfaceSelector:Int = 0):Void
{
if (_renderTarget == target && surfaceSelector == _renderSurfaceSelector && _enableDepthAndStencil == enableDepthAndStencil)
@@ -241,13 +241,13 @@ class Stage3DProxy extends EventDispatcher
_renderTarget = target;
_renderSurfaceSelector = surfaceSelector;
_enableDepthAndStencil = enableDepthAndStencil;
if (target != null)
_context3D.setRenderToTexture(target, enableDepthAndStencil, _antiAlias, surfaceSelector);
else
_context3D.setRenderToBackBuffer();
}
/*
* Clear and reset the back buffer when using a shared context
*/
@@ -255,21 +255,21 @@ class Stage3DProxy extends EventDispatcher
{
if (_context3D == null)
return;
if (_backBufferDirty) {
configureBackBuffer(_backBufferWidth, _backBufferHeight, _antiAlias, _enableDepthAndStencil);
_backBufferDirty = false;
}
_context3D.clear(
((_color >> 16) & 0xff)/255.0,
((_color >> 8) & 0xff)/255.0,
(_color & 0xff)/255.0,
((_color >> 24) & 0xff)/255.0);
_bufferClear = true;
}
/*
* Display the back rendering buffer
*/
@@ -277,15 +277,15 @@ class Stage3DProxy extends EventDispatcher
{
if (_context3D == null)
return;
_context3D.present();
_activeProgram3D = null;
if (_mouse3DManager != null)
_mouse3DManager.fireMouseEvents();
}
/**
* Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event. Special case for enterframe and exitframe events - will switch Stage3DProxy into automatic render mode.
* You can register event listeners on all nodes in the display list for a specific type of event, phase, and priority.
@@ -299,11 +299,11 @@ class Stage3DProxy extends EventDispatcher
override public function addEventListener(type:String, listener:Dynamic -> Void, useCapture:Bool = false, priority:Int = 0, useWeakReference:Bool = false):Void
{
super.addEventListener(type, listener, useCapture, priority, useWeakReference);
if ((type == Event.ENTER_FRAME || type == Event.EXIT_FRAME) && !_frameEventDriver.hasEventListener(Event.ENTER_FRAME))
_frameEventDriver.addEventListener(Event.ENTER_FRAME, onEnterFrame, useCapture, priority, useWeakReference);
}
/**
* Removes a listener from the EventDispatcher object. Special case for enterframe and exitframe events - will switch Stage3DProxy out of automatic render mode.
* If there is no matching listener registered with the EventDispatcher object, a call to this method has no effect.
@@ -315,24 +315,24 @@ class Stage3DProxy extends EventDispatcher
override public function removeEventListener(type:String, listener:Dynamic -> Void, useCapture:Bool = false):Void
{
super.removeEventListener(type, listener, useCapture);
// Remove the main rendering listener if no EnterFrame listeners remain
if (!hasEventListener(Event.ENTER_FRAME) && !hasEventListener(Event.EXIT_FRAME) && _frameEventDriver.hasEventListener(Event.ENTER_FRAME))
_frameEventDriver.removeEventListener(Event.ENTER_FRAME, onEnterFrame, useCapture);
}
private function get_scissorRect():Rectangle
{
return _scissorRect;
}
private function set_scissorRect(value:Rectangle):Rectangle
{
_scissorRect = value;
_context3D.setScissorRectangle(_scissorRect);
return value;
}
/**
* The index of the Stage3D which is managed by this instance of Stage3DProxy.
*/
@@ -340,7 +340,7 @@ class Stage3DProxy extends EventDispatcher
{
return _stage3DIndex;
}
/**
* The base Stage3D object associated with this proxy.
*/
@@ -348,7 +348,7 @@ class Stage3DProxy extends EventDispatcher
{
return _stage3D;
}
/**
* The Context3D object associated with the given Stage3D object.
*/
@@ -356,7 +356,7 @@ class Stage3DProxy extends EventDispatcher
{
return _context3D;
}
/**
* The driver information as reported by the Context3D object (if any)
*/
@@ -364,7 +364,7 @@ class Stage3DProxy extends EventDispatcher
{
return (_context3D != null)? _context3D.driverInfo : null;
}
/**
* Indicates whether the Stage3D managed by this proxy is running in software mode.
* Remember to wait for the CONTEXT3D_CREATED event before checking this property,
@@ -374,7 +374,7 @@ class Stage3DProxy extends EventDispatcher
{
return _usesSoftwareRendering;
}
/**
* The x position of the Stage3D.
*/
@@ -382,18 +382,18 @@ class Stage3DProxy extends EventDispatcher
{
return _stage3D.x;
}
private function set_x(value:Float):Float
{
if (_viewPort.x == value)
return value;
_stage3D.x = _viewPort.x = value;
notifyViewportUpdated();
return value;
}
/**
* The y position of the Stage3D.
*/
@@ -401,18 +401,18 @@ class Stage3DProxy extends EventDispatcher
{
return _stage3D.y;
}
private function set_y(value:Float):Float
{
if (_viewPort.y == value)
return value;
_stage3D.y = _viewPort.y = value;
notifyViewportUpdated();
return value;
}
/**
* The width of the Stage3D.
*/
@@ -420,7 +420,7 @@ class Stage3DProxy extends EventDispatcher
{
return _backBufferWidth;
}
private function set_width(width:Int):Int
{
if (_viewPort.width == width)
@@ -433,7 +433,7 @@ class Stage3DProxy extends EventDispatcher
notifyViewportUpdated();
return width;
}
/**
* The height of the Stage3D.
*/
@@ -441,7 +441,7 @@ class Stage3DProxy extends EventDispatcher
{
return _backBufferHeight;
}
private function set_height(height:Int):Int
{
if (_viewPort.height == height)
@@ -450,11 +450,11 @@ class Stage3DProxy extends EventDispatcher
if(height<50) height = 50;
_viewPort.height = _backBufferHeight = height;
_backBufferDirty = true;
notifyViewportUpdated();
return height;
}
/**
* The antiAliasing of the Stage3D.
*/
@@ -462,24 +462,24 @@ class Stage3DProxy extends EventDispatcher
{
return _antiAlias;
}
private function set_antiAlias(antiAlias:Int):Int
{
_antiAlias = antiAlias;
_backBufferDirty = true;
return antiAlias;
}
/**
* A viewPort rectangle equivalent of the Stage3D size and position.
*/
private function get_viewPort():Rectangle
{
_viewportDirty = false;
return _viewPort;
}
/**
* The background color of the Stage3D.
*/
@@ -487,13 +487,13 @@ class Stage3DProxy extends EventDispatcher
{
return _color;
}
private function set_color(color:Int):Int
{
_color = color;
return color;
}
/**
* The visibility of the Stage3D.
*/
@@ -501,13 +501,13 @@ class Stage3DProxy extends EventDispatcher
{
return _stage3D.visible;
}
private function set_visible(value:Bool):Bool
{
_stage3D.visible = value;
return value;
}
/**
* The freshly cleared state of the backbuffer before any rendering
*/
@@ -515,13 +515,13 @@ class Stage3DProxy extends EventDispatcher
{
return _bufferClear;
}
private function set_bufferClear(newBufferClear:Bool):Bool
{
_bufferClear = newBufferClear;
return newBufferClear;
}
/*
* Access to fire mouseevents across multiple layered view3D instances
*/
@@ -529,24 +529,24 @@ class Stage3DProxy extends EventDispatcher
{
return _mouse3DManager;
}
private function set_mouse3DManager(value:Mouse3DManager):Mouse3DManager
{
_mouse3DManager = value;
return value;
}
private function get_touch3DManager():Touch3DManager
{
return _touch3DManager;
}
private function set_touch3DManager(value:Touch3DManager):Touch3DManager
{
_touch3DManager = value;
return value;
}
/**
* Frees the Context3D associated with this Stage3DProxy.
*/
@@ -554,11 +554,11 @@ class Stage3DProxy extends EventDispatcher
{
if (_context3D != null) {
dispatchEvent(new Stage3DEvent(Stage3DEvent.CONTEXT3D_DISPOSED));
_context3D.dispose();
_context3D.dispose();
}
_context3D = null;
}
/*
* Called whenever the Context3D is retrieved or lost.
* @param event The event dispatched.
@@ -569,7 +569,7 @@ class Stage3DProxy extends EventDispatcher
var hadContext:Bool = (_context3D != null);
_context3D = _stage3D.context3D;
_context3D.enableErrorChecking = Debug.active;
_usesSoftwareRendering = (_context3D.driverInfo.indexOf('Software') == 0);
// Only configure back buffer if width and height have been set,
@@ -577,15 +577,15 @@ class Stage3DProxy extends EventDispatcher
// invoked for the first time.
if (_backBufferWidth > 0 && _backBufferHeight > 0)
_context3D.configureBackBuffer(_backBufferWidth, _backBufferHeight, _antiAlias, _enableDepthAndStencil, true, true);
// Dispatch the appropriate event depending on whether context was
// created for the first time or recreated after a device loss.
dispatchEvent(new Stage3DEvent(hadContext? Stage3DEvent.CONTEXT3D_RECREATED : Stage3DEvent.CONTEXT3D_CREATED));
} else
throw new Error("Rendering context lost!");
}
/**
* Requests a Context3D object to attach to the managed Stage3D.
*/
@@ -598,7 +598,7 @@ class Stage3DProxy extends EventDispatcher
if (!_usesSoftwareRendering)
_usesSoftwareRendering = forceSoftware;
_profile = profile;
// ugly stuff for backward compatibility
var renderMode:Context3DRenderMode = forceSoftware? Context3DRenderMode.SOFTWARE : Context3DRenderMode.AUTO;
if (profile == "baseline")
@@ -610,10 +610,10 @@ class Stage3DProxy extends EventDispatcher
throw "An error occurred creating a context using the given profile. Profiles are not supported for the SDK this was compiled with.";
}
}
_contextRequested = true;
}
/**
* The Enter_Frame handler for processing the proxy.ENTER_FRAME and proxy.EXIT_FRAME event handlers.
* Typically the proxy.ENTER_FRAME listener would render the layers for this Stage3D instance.
@@ -622,20 +622,20 @@ class Stage3DProxy extends EventDispatcher
{
if (_context3D == null)
return;
// Clear the stage3D instance
clear();
//notify the enterframe listeners
notifyEnterFrame();
// Call the present() to render the frame
present();
//notify the exitframe listeners
notifyExitFrame();
}
public function recoverFromDisposal():Bool
{
if (_context3D == null)
@@ -647,29 +647,29 @@ class Stage3DProxy extends EventDispatcher
}
return true;
}
public function clearDepthBuffer():Void
{
if (_context3D == null)
return;
_context3D.clear(0, 0, 0, 1, 1, 0, cast Context3DClearMask.DEPTH);
}
/*
Moving all creation methods here, so we can trace the usages of vertexbuffers or indexbuffers.
Flash will throw the ERROR, when the vertexbuffer creation reached 4096..
*/
public static var vertexBufferCount(default, default) : UInt;
public static var indexBufferCount(default, default) : UInt;
public static var drawTriangleCount(default, default) : UInt;
private static var _vbUploadCount : UInt = 0;
private static var _ibUploadCount : UInt = 0;
private static var _bmpUploadCount : UInt = 0;
private static var _atfUploadCount : UInt = 0;
public function createVertexBuffer(numVertices:Int, data32PerVertex:Int):VertexBuffer3D
{
vertexBufferCount++;
@@ -681,31 +681,31 @@ class Stage3DProxy extends EventDispatcher
vb.dispose();
vertexBufferCount--;
}
public function createIndexBuffer(numIndices:Int):IndexBuffer3D
{
indexBufferCount++;
return _context3D.createIndexBuffer(numIndices);
}
public static function disposeIndexBuffer(ib:IndexBuffer3D):Void
{
ib.dispose();
indexBufferCount--;
}
public function drawTriangles(indexBuffer:IndexBuffer3D, firstIndex:Int = 0, numTriangles:Int = -1)
{
drawTriangleCount++;
_context3D.drawTriangles(indexBuffer, firstIndex, numTriangles);
}
public static function uploadVertexBufferFromVector(vb:VertexBuffer3D, data:Vector<Float>, startVertex:Int, numVertices:Int):Void
{
vb.uploadFromVector(data, startVertex, numVertices);
_vbUploadCount++;
}
public static function uploadIndexBufferFromVector(ib:IndexBuffer3D, data:Vector<UInt>, startOffset:Int, count:Int):Void
{
ib.uploadFromVector(data, startOffset, count);