/v0.8.0/Red2D_V0.8/src/red2D/system/Red2D.as
ActionScript | 408 lines | 173 code | 62 blank | 173 comment | 10 complexity | b5f95102c887bcd3733ecac9b46d8ffd MD5 | raw file
- package red2D.system
- {
- import flash.display.Sprite;
- import flash.display.Stage;
- import flash.display.Stage3D;
- import flash.display.StageAlign;
- import flash.display.StageScaleMode;
- import flash.display3D.Context3D;
- import flash.display3D.Context3DCompareMode;
- import flash.display3D.Context3DRenderMode;
- import flash.display3D.Context3DTriangleFace;
- import flash.events.ErrorEvent;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.events.TimerEvent;
- import flash.system.System;
- import flash.utils.Timer;
- import flash.utils.getTimer;
- import flash.utils.setInterval;
-
- import red2D.projectInfomation.InfoLogger;
- import red2D.util.CheckEnableStage;
- import red2D.util.RGB_separator;
-
- /**
- * <p>Red2D? ?????? ?? ??? ??? ???? Class</p>
- * Last update - Sep 10, 2011
- * @author ???(seon ki, paik) http://redcamel-studio.tistory.com
- * @langversion ActionScript 3.0
- * @playerversion Flash 11
- * @playerversion AIR 3.0
- */
- public class Red2D extends Sprite
- {
- /********************************************************************************/
- /** static ??? **/
- /********************************************************************************/
-
- /**
- * ??? ?? ?? context3D (??????? ?? ????)
- */
- public static var targetContext3d:Context3D;
-
- /**
- * ??? ?? ?? Stage3D (??????? ?? ????)
- */
- public static var targetStage3d:Stage3D;
-
- /**
- * ??? ????? ???? Scene??
- */
- public static var targetScene:Red_Scene;
-
- /**
- * Red2d????? stage? static?? ???? ?? / Red_Scene???? stage??? ????
- */
- public static var targetStage:Stage;
-
- /**
- * shader ???? ?? ??? (??????? ?? ????)
- */
- public static var targetProgramData:Red_ProgramData;
-
- /**
- * ???? ?? ?? ?????? ????? (??????? ?? ????)
- */
- public static var targetBufferData:Red_BufferData;
-
-
- /********************************************************************************/
- /** ?? ????? ??? **/
- /********************************************************************************/
-
- /**
- * ???? ??? ??
- */
- private var _checkStage:CheckEnableStage;
-
- /**
- * context3D ?????
- */
- private var _enableRed2D:Boolean=false;
-
-
- /********************************************************************************/
- /** ????? ???
- * Red2D? ?????? ??? ????? ?????.
- * ???? ??? ???? ??? ?????? ??? ??? ?????? ????? ?????? ????????.
- * ?? ???????? ???? ??, ??????? ?? ???? ?? ??? ????????.
- **/
- /********************************************************************************/
-
- /**
- * ????? - ???? ???? ???? ???? ??
- */
- private var _timer:Timer;
-
- /**
- * ?? ????? ???? MouseDown????? ?????? ?? (??????? ?? ????)
- */
- public static var currentMouseDown:Boolean;
- public static var checkTime:int;
- private var _prevNum:int;
-
- /********************************************************************************/
- /** ???? ?? ??? **/
- /********************************************************************************/
-
- /**
- * ??????
- */
- private static var _backgroundColor:int;
-
- /**
- * ????? RGB? ???? ??
- */
- private static var _backgroundColor_Data:Array;
-
-
- /********************************************************************************/
- /** ??? ??? **/
- /********************************************************************************/
- /**
- * ???
- *
- */
- public function Red2D()
- {
- InfoLogger.traceLogger()
- addEventListener(Event.ADDED_TO_STAGE, init)
- backgroundColor=0x000000
- }
-
- /**
- * red2D? ??? 1?? - stage??? ??
- * @param $event
- *
- */
- private function init( $event:Event ):void{
- stage.doubleClickEnabled = false
- stage.stageFocusRect = false
- //stage.quality = StageQuality.LOW
- stage.scaleMode = StageScaleMode.NO_SCALE
- stage.align = StageAlign.TOP_LEFT
-
- // stage?????
- _checkStage = new CheckEnableStage()
- addChild(_checkStage)
- _checkStage.addEventListener(CheckEnableStage.ENABLE_STAGE, check_contex3D)
- }
-
- /**
- * red2D? ??? 2??-1 - context3D ??? ??
- * @param event
- *
- */
- private function check_contex3D( $event:Event ):void
- {
- // context3D ????
- targetStage = stage
- targetStage3d = targetStage.stage3Ds[0]
- targetStage3d.addEventListener(Event.CONTEXT3D_CREATE, setContext3D)
- targetStage3d.addEventListener(ErrorEvent.ERROR, HD_context3D_Error)
- targetStage3d.requestContext3D(Context3DRenderMode.AUTO)
- }
-
- /**
- * red2D? ??? 2??-2 - context3D ??? ???? ??
- * @param event
- *
- */
- private function setContext3D( $event:Event ):void
- {
- trace(":::::::::: Context3D Test : Pass!!")
- _enableRed2D = true
- targetContext3d = targetStage.stage3Ds[0].context3D
-
- // targetContext3d???? ??
- resetContext3D_property()
- // ?? - ????? ??? ??? ????
- setBufferData()
- // ?? - program3D???? : ???? ProgramData ???? ???? ???? ???? program? ???? setProgram???? ?????.
- setProgramData()
-
- // ???? ???? ??? ??? ?? ?????.
- targetStage.addEventListener(Event.RESIZE, HD_Resize)
- trace(":::::::::: Start Molehill!! With red2D ::::::::::")
- }
-
-
- /**
- * red2D? ??? 3?? context3D? ?????.
- *
- */
- private function resetContext3D_property():void
- {
- targetContext3d.enableErrorChecking = false
- targetContext3d.configureBackBuffer( targetStage.stageWidth , targetStage.stageHeight ,2, false)
- targetContext3d.setCulling(Context3DTriangleFace.BACK);
- targetContext3d.setDepthTest(false, Context3DCompareMode.NEVER)
-
- // ??? ???? ??
- targetStage.addEventListener(MouseEvent.MOUSE_DOWN, HD_MouseDownCheck)
- targetStage.addEventListener(MouseEvent.MOUSE_UP, HD_MouseUpCheck)
- }
-
-
- /********************************************************************************/
- /** ??? **/
- /********************************************************************************/
-
- /**
- * ???? ?? ?????? ????.(?????)
- *
- */
-
- private function setBufferData():void{
- targetBufferData = new Red_BufferData( targetContext3d )
- }
-
- /**
- * program3d? ?????.(?????)
- *
- */
- private function setProgramData():void
- {
- targetProgramData = new Red_ProgramData( targetContext3d )
- }
-
- /**
- * Red_Scene ??
- * @param $scene
- *
- */
- public function setScene( $scene:Red_Scene ):void{
- if(hasEventListener(Event.ENTER_FRAME)){
- removeEventListener(Event.ENTER_FRAME, HD_TimeRender);
-
- }
- if(targetScene != null){
- targetScene.removeChildAll()
- }
- targetScene = null
-
-
- System.gc()
- targetScene = $scene
- checkEnableContext3D()
-
- }
-
- /**
- * Scene? ???? ???? _targetContext3D ??? ????? ????.
- *
- */
- private function checkEnableContext3D():void {
- stage.addEventListener(Event.ENTER_FRAME, tempLoop );
- }
-
- /**
- * _targetContext3D ????? ???? ????.
- * @param event
- *
- */
- private function tempLoop( $event:Event ):void {
- if ( _enableRed2D ) {
- if ( targetStage.stageWidth > 0 && targetStage.stageHeight > 0 ) {
- targetStage.removeEventListener( Event.ENTER_FRAME, tempLoop );
- setRender()
- }
- }
-
- }
-
- /**
- * targetScene? ??????.
- *
- */
- private function setRender():void
- {
- trace(":::::::::: Set New Scene ::::::::::")
-
- if(targetScene==null){
- throw new Error("target Scene? ??????")
- }
-
- targetScene.context3D = targetContext3d
- targetScene.stage = targetStage
- targetScene.setDesign()
-
- HD_Resize()
-
- addEventListener(Event.ENTER_FRAME, HD_TimeRender);
-
-
- // ??????? ???? ??????.
- // setTimer()
- }
-
- /**
- * ?????? ??? ????
- * ??? ??????
- */
- private function setTimer():void
- {
- if(_timer!=null){
- _timer.removeEventListener(TimerEvent.TIMER, HD_TimeRender)
- _timer=null
- }
- /*_timer = new Timer(1000/60)
- //TODO 1000? ?? 1100? 12000? 1300? 1400? 1500? 1600? 1700? ????....???? ??? ??? ?????.
- _timer.start()
- _timer.addEventListener(TimerEvent.TIMER, HD_TimeRender)*/
- setInterval(HD_TimeRender,1000/60)
- }
-
- /********************************************************************************/
- /** ??? ??? **/
- /********************************************************************************/
- private function HD_TimeRender($e:Event=null):void
- {
- $e.stopImmediatePropagation();
- checkTime = int((getTimer())/10%100)
- if(_prevNum != checkTime){
- // * Context3d? ??
- targetContext3d.clear(_backgroundColor_Data[0],_backgroundColor_Data[1],_backgroundColor_Data[2])
- // * Context3D? ??? ????? ??? ??? ?? ?? ???? ???.
- // * ??? scene? setRenderList??? ???
- targetScene.setRenderList()
- // * context3d? ???
- _prevNum = checkTime
- targetContext3d.present()
- }
- }
-
- /**
- * red2D? ??? 2?? - context3D ???? ?????? ???
- * @param event
- *
- */
- private function HD_context3D_Error(event:Event):void
- {
- trace(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
- trace(":::::::::: Context3D Test : Fail!! - Check Your wmode, set wmode=direct or gpu")
- trace(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
- }
-
-
- /********************************************************************************/
- /** ??? ??? **/
- /********************************************************************************/
-
- /**
- * ????
- * @param event
- *
- */
- private function HD_Resize( $event:Event=null ):void
- {
- trace(":::::::::: Stage Resize!! reset configureBackBuffer ::::::::::")
- resetContext3D_property()
- // ?????? ?????? ??????.
- targetScene.resetVcsAndWcs()
- }
-
- /**
- * ???? MouseDown????? ??
- * @param event
- *
- */
- private function HD_MouseDownCheck(event:MouseEvent):void
- {
- currentMouseDown = true
- }
-
- /**
- * ???? MouseUp????? ??
- * @param event
- *
- */
- private function HD_MouseUpCheck(event:MouseEvent):void
- {
- currentMouseDown = false
- }
-
- /********************************************************************************/
- /** get / set **/
- /********************************************************************************/
-
- /**
- * ?????? ??/?????.
- */
- public static function get backgroundColor():int
- {
- return _backgroundColor;
- }
-
- /**
- * ?????? ??/?????.
- */
- public static function set backgroundColor( $color:int):void
- {
- _backgroundColor_Data = RGB_separator.divide($color)
- _backgroundColor = $color;
- }
- }
- }
-