Coverage report

  %line %branch
tsukuba_bunko.peko.scenario.ScenarioProcessor
0% 
0% 

 1  
 /*
 2  
  * "Peko" Visual Novel System
 3  
  *
 4  
  * All Rights Reserved.
 5  
  * Copyright (c) 1999-2003 Tsukuba Bunko.
 6  
  *
 7  
  * $Id: ScenarioProcessor.java,v 1.2 2005/11/23 05:42:55 ppoi Exp $
 8  
  */
 9  
 package tsukuba_bunko.peko.scenario;
 10  
 
 11  
 import	java.util.ArrayList;
 12  
 
 13  
 import	tsukuba_bunko.peko.ActionControler;
 14  
 import	tsukuba_bunko.peko.Logger;
 15  
 import	tsukuba_bunko.peko.PekoSystem;
 16  
 
 17  
 import	tsukuba_bunko.peko.session.Session;
 18  
 
 19  
 import	tsukuba_bunko.peko.scenario.select.SelectCoordinator;
 20  
 
 21  
 import	tsukuba_bunko.peko.scenario.stage.StageCoordinator;
 22  
 
 23  
 import	tsukuba_bunko.peko.scenario.text.TextCoordinator;
 24  
 
 25  
 
 26  
 /**
 27  
  * シナリオの処理を行うプロセッサモジュールです。
 28  
  * @author	$Author: ppoi $
 29  
  * @version	$Revision: 1.2 $
 30  
  */
 31  
 public class ScenarioProcessor	{
 32  
 
 33  
 	/**
 34  
 	 * キュー
 35  
 	 */
 36  0
 	protected ArrayList	_queue = new ArrayList( 5 );
 37  
 
 38  
 	/**
 39  
 	 * キューの最大値
 40  
 	 */
 41  0
 	protected int	_maxQueueSize = 4;
 42  
 
 43  
 	/**
 44  
 	 * 生成した SceneProcessor 数
 45  
 	 */
 46  0
 	protected int	_processorCount = 0;
 47  
 
 48  
 	/**
 49  
 	 * 現在シーンを処理中の SceneProcessor
 50  
 	 */
 51  0
 	protected SceneProcessor	_currentSceneProcessor = null;
 52  
 
 53  
 	/**
 54  
 	 * 現在のコンテクスト
 55  
 	 */
 56  0
 	protected Session	_session = null;
 57  
 
 58  
 
 59  
 	/**
 60  
 	 * TextCanvas コーディネータ
 61  
 	 */
 62  0
 	protected TextCoordinator	_textCooridnator = null;
 63  
 
 64  
 	/**
 65  
 	 * StageCanvas コーディネータ
 66  
 	 */
 67  0
 	protected StageCoordinator	_stageCoordinator = null;
 68  
 
 69  
 	/**
 70  
 	 * SelectCanvas コーディネータ
 71  
 	 */
 72  0
 	protected SelectCoordinator	_selectCoordinator = null;
 73  
 
 74  
 
 75  
 	/**
 76  
 	 * <code>ScenarioProcessor</code> のインスタンスを生成します。
 77  
 	 */
 78  
 	public ScenarioProcessor()
 79  
 	{
 80  0
 		super();
 81  0
 		_queue.add( new SceneProcessor(this) );
 82  0
 		_queue.add( new SceneProcessor(this) );
 83  
 
 84  0
 		_textCooridnator = new TextCoordinator();
 85  0
 		_stageCoordinator = new StageCoordinator();
 86  0
 		_selectCoordinator = new SelectCoordinator();
 87  0
 	}
 88  
 
 89  
 
 90  
 	/**
 91  
 	 * 指定された第1シーン、セッションでシナリオの再生を開始します。
 92  
 	 * @param	sceneName	第1シーン名
 93  
 	 * @param	session	セッション
 94  
 	 */
 95  
 	public synchronized void playScenario( String sceneName, Session session )
 96  
 	{
 97  0
 		if( _currentSceneProcessor != null )	{
 98  0
 			Logger.error( "[scene] BUG! current scene processor is still alive!" );
 99  0
 			exit();
 100  
 		}
 101  0
 		SceneProcessor	processor = getSceneProcessor();
 102  0
 		processor.setTextCoordinator( _textCooridnator );
 103  0
 		processor.setStageCoordinator( _stageCoordinator );
 104  0
 		processor.setSelectCoordinator( _selectCoordinator );
 105  0
 		_currentSceneProcessor = processor;
 106  0
 		_session = session;
 107  
 
 108  0
 		ActionControler	controler = PekoSystem.getInstance().getActionControler();
 109  0
 		controler.setActive( true );
 110  0
 		processor.process( sceneName, session );
 111  0
 	}
 112  
 
 113  
 	/**
 114  
 	 * シナリオの再生を終了します。
 115  
 	 */
 116  
 	public synchronized void exit()
 117  
 	{
 118  0
 		if( _currentSceneProcessor != null )	{
 119  0
 			Logger.debug( "[scenario] exit ScenarioProcessor" );
 120  0
 			_currentSceneProcessor.abort();
 121  0
 			_currentSceneProcessor = null;
 122  0
 			_session = null;
 123  
 
 124  0
 			ActionControler	controler = PekoSystem.getInstance().getActionControler();
 125  0
 			controler.start();
 126  
 		}
 127  0
 	}
 128  
 
 129  
 	/**
 130  
 	 * シーンを処理するシーンプロセッサを取得します。
 131  
 	 * @return	シーンプロセッサ
 132  
 	 */
 133  
 	protected synchronized SceneProcessor getSceneProcessor()
 134  
 	{
 135  
 		try	{
 136  0
 			if( _queue.isEmpty() )	{
 137  0
 				if( _processorCount < _maxQueueSize )	{
 138  0
 					SceneProcessor	processor = new SceneProcessor( this );
 139  0
 					_processorCount++;
 140  0
 					return processor;
 141  
 				}
 142  
 				else	{
 143  0
 					while( _queue.isEmpty() )	{
 144  0
 						wait( 50 );
 145  0
 					}
 146  
 				}
 147  
 			}
 148  0
 			return (SceneProcessor)_queue.remove( 0 );
 149  
 		}
 150  0
 		catch( InterruptedException ie )	{
 151  0
 			Logger.debug( "[scene] interrupted", ie );
 152  0
 			return null;
 153  
 		}
 154  
 	}
 155  
 
 156  
 	/**
 157  
 	 * 処理が終了した SceneProcessor をキューに戻します。
 158  
 	 * @param	processor	キューに戻すシーンプロセッサ
 159  
 	 */
 160  
 	protected synchronized void pushSceneProcessor( SceneProcessor processor )
 161  
 	{
 162  0
 		_queue.add( processor );
 163  0
 	}
 164  
 
 165  
 	/**
 166  
 	 * シーンの終了を通知します。
 167  
 	 * @param	processor	終了の通知を発行したシーンプロセッサ
 168  
 	 */
 169  
 	protected synchronized void sceneEnded( SceneProcessor processor )
 170  
 	{
 171  0
 		if( _currentSceneProcessor == processor )	{
 172  0
 			SceneContext	context = processor.getSceneContext();
 173  0
 			String	nextSceneName = context.getNextSceneName();
 174  0
 			if( nextSceneName != null )	{
 175  0
 				if( "peko:end".equals(nextSceneName) )	{
 176  0
 					exit();
 177  0
 					returnTitle();
 178  0
 				}
 179  
 				else	{
 180  0
 					_currentSceneProcessor.abort();
 181  0
 					_session.setSceneContext( null );
 182  0
 					PekoSystem.getInstance().getCanvasManager().advancesNewPage();
 183  0
 					PekoSystem.getInstance().getCanvasManager().getCurrentPage().commit();
 184  0
 					_currentSceneProcessor = getSceneProcessor();
 185  0
 					_currentSceneProcessor.setTextCoordinator( _textCooridnator );
 186  0
 					_currentSceneProcessor.setStageCoordinator( _stageCoordinator );
 187  0
 					_currentSceneProcessor.setSelectCoordinator( _selectCoordinator );
 188  0
 					_currentSceneProcessor.process( context.getNextSceneName(), _session );
 189  
 				}
 190  0
 			}
 191  
 			else	{
 192  0
 				Logger.error( MessageIDs.SCN0012E );
 193  0
 				exit();
 194  0
 				returnTitle();
 195  
 			}
 196  
 		}
 197  0
 	}
 198  
 
 199  
 	/**
 200  
 	 * タイトル画面へ戻ります。
 201  
 	 */
 202  
 	private void returnTitle()
 203  
 	{
 204  0
 		new Thread()	{
 205  
 			public void run() {
 206  
 				ActionControler	controler = PekoSystem.getInstance().getActionControler();
 207  
 				controler.returnTitle( true );
 208  
 			};
 209  
 		}.start();
 210  0
 	}
 211  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.