/** * 卸载ram,如果并没有安装过ram,则什么也不会发生 * @param type 需要卸载的内存类型 */ public void uninstall(int type) { Ram.Ram ram = null; switch (type) { case RamConst.RAM_RUNTIME_TYPE: ram = runRam; runRam = null; break; case RamConst.RAM_GRAPH_TYPE: ram = graphRam; graphRam = null; break; case RamConst.RAM_BUFFER_TYPE: ram = bufferRam; bufferRam = null; break; case RamConst.RAM_STRING_TYPE: ram = strRam; strRam = null; break; case RamConst.RAM_TEXT_TYPE: ram = textRam; textRam = null; break; } if (ram != null) { resetRamAddress(); } }
public ScreenModelImp() { graphData = new sbyte[BUFFER_SIZE]; bufferData = new sbyte[BUFFER_SIZE]; graphRam = new ScreenRam(this, graphData, RamConst.RAM_GRAPH_TYPE); bufferRam = new ScreenRam(this, bufferData, RamConst.RAM_BUFFER_TYPE); }
/** * 往里面添加内存模块,每种类型的内存最多只能安装一个.<p> * ram为null不会抛出异常,且不会改变RamManager的任何状态 * @param ram 需要安装的内存 * @throws IllegalStateException 已经安装了这种类型的内存 * @see #uninstall */ public void install(Ram.Ram ram) { if (ram == null) { return; } switch (ram.getRamType()) { case RamConst.RAM_RUNTIME_TYPE: if (runRam != null) { //throw new IllegalStateException("Runtime Ram was installed!"); } runRam = (RuntimeRam)ram; break; case RamConst.RAM_GRAPH_TYPE: if (graphRam != null) { //throw new IllegalStateException("Graph Ram was installed!"); } graphRam = (RelativeRam)ram; screen = graphRam.getScreenModel(); break; case RamConst.RAM_BUFFER_TYPE: if (bufferRam != null) { //throw new IllegalStateException("Buffer Ram was installed!"); } bufferRam = (RelativeRam)ram; break; case RamConst.RAM_STRING_TYPE: if (strRam != null) { //throw new IllegalStateException("String Ram was installed!"); } strRam = (StringRam)ram; break; case RamConst.RAM_TEXT_TYPE: if (textRam != null) { //throw new IllegalStateException("Text Ram was installed!"); } textRam = (RelativeRam)ram; break; } resetRamAddress(); }
/// <summary> /// 设置用于显示的ScreenModel,并作适当的初始化 /// </summary> /// <param name="screen"></param> public void setScreenModel(ScreenModel screen) { if (screen == null) { //throw new IllegalArgumentException("Screen must't be null!"); } if (this.screen != screen) { this.screen = screen; this.buffer = new sbyte[(screen.getWidth() / 6) * (screen.getHeight() / 13)]; this.getter = new ByteArrayGetter(buffer); this.ram = new ByteArrayRam(buffer, screen); this.render = screen.getRender(); } else { ram.Clear(); } this.curCol = this.curRow = 0; this.isBigMode = true; this.maxCol = screen.getWidth() / 8; this.maxRow = screen.getHeight() / 16; }