diff --git a/.idea/libraries/lib.xml b/.idea/libraries/lib.xml index 55e200d17..2c0db4dd7 100644 --- a/.idea/libraries/lib.xml +++ b/.idea/libraries/lib.xml @@ -15,6 +15,8 @@ + + diff --git a/assets/graphics/fonts/MDA.png b/assets/graphics/fonts/MDA.png new file mode 100644 index 000000000..842e0e595 Binary files /dev/null and b/assets/graphics/fonts/MDA.png differ diff --git a/assets/graphics/fonts/MDA.png.0.png b/assets/graphics/fonts/MDA.png.0.png new file mode 100644 index 000000000..4a503cbce Binary files /dev/null and b/assets/graphics/fonts/MDA.png.0.png differ diff --git a/assets/graphics/fonts/MDA.png.1.png b/assets/graphics/fonts/MDA.png.1.png new file mode 100644 index 000000000..af6ec9412 Binary files /dev/null and b/assets/graphics/fonts/MDA.png.1.png differ diff --git a/assets/graphics/fonts/MDA.png.2.png b/assets/graphics/fonts/MDA.png.2.png new file mode 100644 index 000000000..bf778cfe3 Binary files /dev/null and b/assets/graphics/fonts/MDA.png.2.png differ diff --git a/assets/graphics/fonts/MDA.png.3.png b/assets/graphics/fonts/MDA.png.3.png new file mode 100644 index 000000000..f7a7c4789 Binary files /dev/null and b/assets/graphics/fonts/MDA.png.3.png differ diff --git a/lib/OpenComputers-JNLua.jar b/lib/OpenComputers-JNLua.jar new file mode 100644 index 000000000..f3abfe1f4 Binary files /dev/null and b/lib/OpenComputers-JNLua.jar differ diff --git a/lib/OpenComputers-LuaJ.jar b/lib/OpenComputers-LuaJ.jar new file mode 100644 index 000000000..70c315e47 Binary files /dev/null and b/lib/OpenComputers-LuaJ.jar differ diff --git a/lib/natives/native.32.bsd.so b/lib/natives/native.32.bsd.so new file mode 100755 index 000000000..572568d56 Binary files /dev/null and b/lib/natives/native.32.bsd.so differ diff --git a/lib/natives/native.32.dll b/lib/natives/native.32.dll new file mode 100755 index 000000000..168b7a112 Binary files /dev/null and b/lib/natives/native.32.dll differ diff --git a/lib/natives/native.32.dylib b/lib/natives/native.32.dylib new file mode 100755 index 000000000..255c63e08 Binary files /dev/null and b/lib/natives/native.32.dylib differ diff --git a/lib/natives/native.32.so b/lib/natives/native.32.so new file mode 100755 index 000000000..06e4e6e0c Binary files /dev/null and b/lib/natives/native.32.so differ diff --git a/lib/natives/native.64.bsd.so b/lib/natives/native.64.bsd.so new file mode 100755 index 000000000..eab8829a2 Binary files /dev/null and b/lib/natives/native.64.bsd.so differ diff --git a/lib/natives/native.64.dll b/lib/natives/native.64.dll new file mode 100755 index 000000000..83022b5b7 Binary files /dev/null and b/lib/natives/native.64.dll differ diff --git a/lib/natives/native.64.dylib b/lib/natives/native.64.dylib new file mode 100755 index 000000000..fcf9084bf Binary files /dev/null and b/lib/natives/native.64.dylib differ diff --git a/lib/natives/native.64.so b/lib/natives/native.64.so new file mode 100755 index 000000000..baf1c7d30 Binary files /dev/null and b/lib/natives/native.64.so differ diff --git a/src/com/sudoplay/joise/module/ModuleBrightContrast.java b/src/com/sudoplay/joise/module/ModuleBrightContrast.java index f80d975eb..dae122e48 100755 --- a/src/com/sudoplay/joise/module/ModuleBrightContrast.java +++ b/src/com/sudoplay/joise/module/ModuleBrightContrast.java @@ -85,7 +85,7 @@ public class ModuleBrightContrast extends SourcedModule { @Override public double get(double x, double y) { double val = source.get(x, y); - // apply brightness + // apply colourKey val += bright.get(x, y); // subtract threshold, scale by factor, add threshold double t = threshold.get(x, y); @@ -98,7 +98,7 @@ public class ModuleBrightContrast extends SourcedModule { @Override public double get(double x, double y, double z) { double val = source.get(x, y, z); - // apply brightness + // apply colourKey val += bright.get(x, y, z); // subtract threshold, scale by factor, add threshold double t = threshold.get(x, y, z); @@ -111,7 +111,7 @@ public class ModuleBrightContrast extends SourcedModule { @Override public double get(double x, double y, double z, double w) { double val = source.get(x, y, z, w); - // apply brightness + // apply colourKey val += bright.get(x, y, z, w); // subtract threshold, scale by factor, add threshold double t = threshold.get(x, y, z, w); @@ -124,7 +124,7 @@ public class ModuleBrightContrast extends SourcedModule { @Override public double get(double x, double y, double z, double w, double u, double v) { double val = source.get(x, y, z, w, u, v); - // apply brightness + // apply colourKey val += bright.get(x, y, z, w, u, v); // subtract threshold, scale by factor, add threshold double t = threshold.get(x, y, z, w, u, v); @@ -139,7 +139,7 @@ public class ModuleBrightContrast extends SourcedModule { ModulePropertyMap props = new ModulePropertyMap(this); - writeScalar("brightness", bright, props, map); + writeScalar("colourKey", bright, props, map); writeScalar("contrastFactor", factor, props, map); writeScalar("contrastThreshold", threshold, props, map); writeSource(props, map); @@ -152,7 +152,7 @@ public class ModuleBrightContrast extends SourcedModule { public Module buildFromPropertyMap(ModulePropertyMap props, ModuleInstanceMap map) { - readScalar("brightness", "setBrightness", props, map); + readScalar("colourKey", "setBrightness", props, map); readScalar("contrastFactor", "setContrastFactor", props, map); readScalar("contrastThreshold", "setContrastThreshold", props, map); readSource(props, map); diff --git a/src/net/torvald/aa/AAFrame.kt b/src/net/torvald/aa/AAFrame.kt new file mode 100644 index 000000000..64101da44 --- /dev/null +++ b/src/net/torvald/aa/AAFrame.kt @@ -0,0 +1,86 @@ +package net.torvald.aa + +import net.torvald.terrarum.gameworld.toUint +import org.newdawn.slick.* + +/** + * Created by minjaesong on 16-08-10. + */ +class AAFrame @Throws(SlickException::class) +constructor(var width: Int, var height: Int) { + + /** + * 0000_0000_00000000 + + * Upper bits: Background colour 0 black 1 dark grey 2 grey 3 white + * Middle bits: Foreground colour ditto. + * Lower 8 bits: CP437 + */ + internal val frameBuffer: CharArray + + val sizeof = 2 * width * height // magic number 2: indicator that we're using char + + init { + frameBuffer = CharArray(width * height) + } + + fun drawBuffer(x: Int, y: Int, c: Char, colourKey: Int) { + if (y * width + x >= frameBuffer.size) + throw ArrayIndexOutOfBoundsException("x: $x, y; $y") + frameBuffer[y * width + x] = ((c.toInt().and(0xFF)) + colourKey.shl(8)).toChar() + } + + fun drawBuffer(x: Int, y: Int, raw: Char): Boolean = + if (checkOOB(x, y)) + false + else { + frameBuffer[y * width + x] = raw + true + } + + fun drawFromBytes(other: ByteArray) { + for (i in 0..other.size - 1 step 2) { + val char = (other[i].toUint().shl(8) + other[i + 1].toUint()).toChar() + frameBuffer[i.ushr(1)] = char + } + } + + fun getBackgroundColour(x: Int, y: Int): Int { + return frameBuffer[y * width + x].toInt().ushr(12) and 0xF + } + + fun getForegroundColour(x: Int, y: Int): Int { + return frameBuffer[y * width + x].toInt().ushr(8) and 0xF + } + + fun getChar(x: Int, y: Int): Char { + return (frameBuffer[y * width + x].toInt() and 0xFF).toChar() + } + + fun getRaw(x: Int, y: Int): Char? = + if (checkOOB(x, y)) + null + else + frameBuffer[y * width + x] + + fun clear(background: Int = 0) { + for (y in 0..height - 1) { + for (x in 0..width - 1) { + drawBuffer(x, y, 0.toChar(), background.shl(4)) + } + } + } + + fun drawFromOther(other: AAFrame) { + //this.framebuffer = other.getFrameBuffer(); + for (y in 0..height - 1) { + for (x in 0..width - 1) { + frameBuffer[y * width + x] = other.getRaw(x, y)!! + } + } + } + + private fun checkOOB(x: Int, y: Int) = (x < 0 || y < 0 || x >= width || y >= height) + + fun getColourKey(x: Int, y: Int): Int = frameBuffer[y * width + x].toInt().ushr(8).and(0xFF) +} diff --git a/src/net/torvald/aa/ColouredFastFont.kt b/src/net/torvald/aa/ColouredFastFont.kt new file mode 100644 index 000000000..925348e11 --- /dev/null +++ b/src/net/torvald/aa/ColouredFastFont.kt @@ -0,0 +1,102 @@ +package net.torvald.aa + +import net.torvald.terrarum.virtualcomputers.terminal.Terminal +import org.newdawn.slick.Color +import org.newdawn.slick.Font +import org.newdawn.slick.Image +import org.newdawn.slick.SpriteSheet +import java.util.* + +/** + * Based on multisheet slick spritesheef font (net.torvald.imagefont.GameFontBase) of my game project. + * Again, based on my Ba-AA project (github.com/minjaesong/ba-aa) + * + * Created by minjaesong on 16-08-12. + * Adopted by minjaesong on 16-09-07. + */ +class ColouredFastFont(val vt: Terminal, fontRef: String, val fontW: Int, val fontH: Int) : Font { + + val colouredSheet = ArrayList() // index zero: dark grey + private var sheetW = 0 + private var sheetH = 0 + + + private lateinit var sheetImageBuffer: Image + + init { + val getSizeImg = Image(fontRef) + sheetW = getSizeImg.width + sheetH = getSizeImg.height + + getSizeImg.destroy() + + sheetImageBuffer = Image(sheetW, sheetH) + + for (i in 0..vt.coloursCount - 1) { + val sheet = SpriteSheet("$fontRef.$i.png", fontW, fontH) + colouredSheet.add(sheet) + + //sheetImageBuffer.graphics.clear() + } + + sheetImageBuffer.destroy() + } + + private fun getIndexX(ch: Char) = ch.toInt() % (sheetW / fontW) + private fun getIndexY(ch: Char) = ch.toInt() / (sheetW / fontW) + + override fun getHeight(p0: String): Int = fontH + + override fun getWidth(p0: String): Int { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun getLineHeight(): Int = fontH + + override fun drawString(p0: Float, p1: Float, p2: String) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + + override fun drawString(p0: Float, p1: Float, p2: String, p3: Color) { + //search colour + var colourIndex = -1 + for (i in 0..vt.coloursCount - 1) { + if (vt.getColor(i) == p3) { + colourIndex = i + break + } + } + + if (colourIndex >= 0) { + + + colouredSheet[colourIndex].startUse() + + + for (i in 0..p2.length - 1) { + val ch = p2[i] + + colouredSheet[colourIndex].renderInUse( + p0.floorInt() + (i * fontW), + p1.floorInt(), + getIndexX(ch), + getIndexY(ch) + ) + } + + + colouredSheet[colourIndex].endUse() + } + else { + //System.err.println("[ColouredFastFont] unmatched colour! $p3") + } + + } + + override fun drawString(p0: Float, p1: Float, p2: String, p3: Color, p4: Int, p5: Int) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + fun Float.floorInt() = this.toInt() +} diff --git a/src/net/torvald/serialise/WriteGameMapData.kt b/src/net/torvald/serialise/WriteGameMapData.kt index 053f00a42..de1d73932 100644 --- a/src/net/torvald/serialise/WriteGameMapData.kt +++ b/src/net/torvald/serialise/WriteGameMapData.kt @@ -1,6 +1,6 @@ package net.torvald.serialise -import net.torvald.terrarum.gamemap.GameWorld +import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.Terrarum import java.io.IOException import java.nio.file.Files diff --git a/src/net/torvald/terrarum/COPYING.md b/src/net/torvald/terrarum/COPYING.md index 9ae6a91bb..26ac5e040 100644 --- a/src/net/torvald/terrarum/COPYING.md +++ b/src/net/torvald/terrarum/COPYING.md @@ -1,9 +1,9 @@ -*Terrarum* by Torvald +*Terrarum* by Minjaesong (Torvald) Copyright (C) 2013-2016 Torvald. All rights reserved. mailto: alswo9628 *at* __gmail__ *dot* __com__ -You can use any assets (sprites, fonts and tiles) for your own goods (e.g. texture pack for Minecraft), provided that you gave necessary credit to this game and me. +You can use any assets (sprites, fonts, tiles and codes) for your own goods (e.g. texture pack for Minecraft), provided that you gave necessary credit to this game and me, and also notified me. ---- @@ -56,7 +56,7 @@ All rights reserved. IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - Kotlin translated and modified code Copyright (C) 2016 Torvald aka skyhi14. + Kotlin translated and modified code Copyright (C) 2016 Minjaesong (Torvald) --- @@ -70,4 +70,84 @@ Amazing ambient sound recordings: crickets_02.ogg Copyright (C) 2012, 2013, 2015, 2016 Klankbeeld -Sound from http://www.freesound.org/people/klankbeeld/ \ No newline at end of file +Sound from http://www.freesound.org/people/klankbeeld/ + +--- + +*OpenComputers* + +Copyright (c) 2013-2015 Florian "Sangar" Nücke + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + +--- + +Modified JNLua from *OpenComputers* + +Copyright (c) 2013-2015 Florian "Sangar" Nücke + + OpenComputers uses the JNLua library, with a patch to allow memory limits: + + http://code.google.com/p/jnlua/issues/detail?id=9 + + JNLua is copyrighted and licensed as follows: + + Copyright (C) 2008,2012 Andre Naef + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + +--- + +LuaJ + +Copyright (c) 2007 LuaJ. All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. diff --git a/src/net/torvald/terrarum/REFERENCING.md b/src/net/torvald/terrarum/REFERENCING.md index 1f25ac357..9bd9749a5 100644 --- a/src/net/torvald/terrarum/REFERENCING.md +++ b/src/net/torvald/terrarum/REFERENCING.md @@ -1,6 +1,9 @@ |Range|Description| |-----|-----------| |0..4095|Tiles| -|4096..32767|Items| -|32768..0x7FFFFFFF|Actors| -|0x80000000..0xFFFFFFFF (all negative number)|Faction| +|4096..32767|Items (static)| +|32768..16777215|Items (dynamic\*)| +|16777216..0x7FFFFFFF|Actors| +|0x80000000..0xFFFFFFFF (all negative numbers)|Faction| + +* dynamic items can have their own properties that will persist through savegame. \ No newline at end of file diff --git a/src/net/torvald/terrarum/SAVE_FORMAT.md b/src/net/torvald/terrarum/SAVE_FORMAT.md index 2c4efc757..552cade25 100644 --- a/src/net/torvald/terrarum/SAVE_FORMAT.md +++ b/src/net/torvald/terrarum/SAVE_FORMAT.md @@ -44,8 +44,8 @@ Directory: +--- - --- 2a93bc5fd...f823 Actor/Faction/etc. data - --- 423bdc838...93bd Actor/Faction/etc. data + --- 2a93bc5fd...f823 Actor/DynamicItem/Faction/etc. data (JSON) + --- 423bdc838...93bd Actor/DynamicItem/Faction/etc. data (JSON) --- Items_list.txt Human-readable --- Materials_list.txt Human-readable --- Tiles_list.txt Human-readable diff --git a/src/net/torvald/terrarum/StateInGame.kt b/src/net/torvald/terrarum/StateInGame.kt index 1ee6a6862..149db53be 100644 --- a/src/net/torvald/terrarum/StateInGame.kt +++ b/src/net/torvald/terrarum/StateInGame.kt @@ -12,9 +12,9 @@ import net.torvald.terrarum.gamecontroller.GameController import net.torvald.terrarum.gamecontroller.Key import net.torvald.terrarum.gamecontroller.KeyMap import net.torvald.terrarum.gamecontroller.KeyToggler -import net.torvald.terrarum.gamemap.GameWorld -import net.torvald.terrarum.gamemap.WorldSimulator -import net.torvald.terrarum.gamemap.WorldTime +import net.torvald.terrarum.gameworld.GameWorld +import net.torvald.terrarum.gameworld.WorldSimulator +import net.torvald.terrarum.gameworld.WorldTime import net.torvald.terrarum.mapdrawer.LightmapRenderer import net.torvald.terrarum.mapdrawer.LightmapRenderer.constructRGBFromInt import net.torvald.terrarum.mapdrawer.MapCamera @@ -179,9 +179,9 @@ constructor() : BasicGameState() { TileStats.update() if (!(CommandDict["setgl"] as SetGlobalLightOverride).lightOverride) world.globalLight = constructRGBFromInt( - globalLightByTime.redByte, - globalLightByTime.greenByte, - globalLightByTime.blueByte + WeatherMixer.globalLightNow.redByte, + WeatherMixer.globalLightNow.greenByte, + WeatherMixer.globalLightNow.blueByte ) @@ -237,7 +237,7 @@ constructor() : BasicGameState() { } override fun render(gc: GameContainer, sbg: StateBasedGame, g: Graphics) { - setBlendNormal() + blendNormal() drawSkybox(g) @@ -274,12 +274,12 @@ constructor() : BasicGameState() { MapDrawer.render(gc, g) - setBlendMul() + blendMul() MapDrawer.drawEnvOverlay(g) - if (!KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) setBlendMul() else setBlendNormal() + if (!KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendMul() else blendNormal() LightmapRenderer.draw(g) - setBlendNormal() + blendNormal() ////////////////////// @@ -482,8 +482,6 @@ constructor() : BasicGameState() { } } - private val globalLightByTime = WeatherMixer.globalLightNow - fun Double.sqr() = this * this fun Int.sqr() = this * this private fun distToActorSqr(a: Visible, p: Player): Double = diff --git a/src/net/torvald/terrarum/StateVTTest.kt b/src/net/torvald/terrarum/StateVTTest.kt index 17ee59b1f..c0664e491 100644 --- a/src/net/torvald/terrarum/StateVTTest.kt +++ b/src/net/torvald/terrarum/StateVTTest.kt @@ -1,9 +1,14 @@ package net.torvald.terrarum +import net.torvald.terrarum.gamecontroller.Key +import net.torvald.terrarum.virtualcomputers.terminal.SimpleTextTerminal +import org.newdawn.slick.Color import org.newdawn.slick.GameContainer import org.newdawn.slick.Graphics +import org.newdawn.slick.Image import org.newdawn.slick.state.BasicGameState import org.newdawn.slick.state.StateBasedGame +import java.util.* /** * ComputerCraft/OpenComputers like-alike, just for fun! @@ -11,17 +16,40 @@ import org.newdawn.slick.state.StateBasedGame * Created by minjaesong on 16-09-07. */ class StateVTTest : BasicGameState() { - override fun init(container: GameContainer?, game: StateBasedGame?) { - throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + + val vt = SimpleTextTerminal(SimpleTextTerminal.ELECTRIC_BLUE, 80, 25) + + val vtUI = Image(vt.displayW, vt.displayH) + + override fun init(container: GameContainer, game: StateBasedGame) { + } - override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) { - throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + override fun update(container: GameContainer, game: StateBasedGame, delta: Int) { + Terrarum.appgc.setTitle("VT — F: ${container.fps}") + vt.update(container, delta) + + } override fun getID() = Terrarum.STATE_ID_TEST_TTY - override fun render(container: GameContainer?, game: StateBasedGame?, g: Graphics?) { - throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + override fun render(container: GameContainer, game: StateBasedGame, g: Graphics) { + vt.render(container, vtUI.graphics) + + g.drawImage(vtUI, + Terrarum.WIDTH.minus(vtUI.width).div(2f), + Terrarum.HEIGHT.minus(vtUI.height).div(2f)) + + //vtUI.graphics.flush() + } + + override fun keyPressed(key: Int, c: Char) { + super.keyPressed(key, c) + + if (key == Key.RETURN) + vt.printChar(10.toChar()) + else + vt.printChar(c) } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index d260710d3..d00b2c85b 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -99,6 +99,7 @@ constructor(gamename: String) : StateBasedGame(gamename) { gc.graphics.clear() // clean up any 'dust' in the buffer + addState(StateVTTest()) //addState(StateTestingSandbox()) //addState(StateSplash()) //addState(StateMonitorCheck()) @@ -409,29 +410,29 @@ constructor(gamename: String) : StateBasedGame(gamename) { fun main(args: Array) = Terrarum.main(args) -fun setBlendMul() { +fun blendMul() { GL11.glEnable(GL11.GL_BLEND) GL11.glColorMask(true, true, true, true) GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA) } -fun setBlendNormal() { +fun blendNormal() { GL11.glEnable(GL11.GL_BLEND) GL11.glColorMask(true, true, true, true) GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA) } -fun setBlendAlphaMap() { +fun blendAlphaMap() { GL11.glDisable(GL11.GL_BLEND) GL11.glColorMask(false, false, false, true) } -fun setBlendScreen() { +fun blendScreen() { GL11.glEnable(GL11.GL_BLEND) GL11.glColorMask(true, true, true, true) GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_COLOR)} -fun setBlendDisable() { +fun blendDisable() { GL11.glDisable(GL11.GL_BLEND) } diff --git a/src/net/torvald/terrarum/console/SetTime.kt b/src/net/torvald/terrarum/console/SetTime.kt index d7deba44a..f7ec7b589 100644 --- a/src/net/torvald/terrarum/console/SetTime.kt +++ b/src/net/torvald/terrarum/console/SetTime.kt @@ -1,6 +1,6 @@ package net.torvald.terrarum.console -import net.torvald.terrarum.gamemap.WorldTime +import net.torvald.terrarum.gameworld.WorldTime import net.torvald.terrarum.Terrarum /** diff --git a/src/net/torvald/terrarum/gameactors/AVKey.kt b/src/net/torvald/terrarum/gameactors/AVKey.kt index cda5547c0..d64307874 100644 --- a/src/net/torvald/terrarum/gameactors/AVKey.kt +++ b/src/net/torvald/terrarum/gameactors/AVKey.kt @@ -78,6 +78,12 @@ object AVKey { const val MAGICREGENRATEMULT = "$MAGICREGENRATE$MULT" + /** String + * UUID for certain fixtures + */ + const val UUID = "uuid" + + const val __PLAYER_QUICKBARSEL = "__quickbarselection" } \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameactors/Actor.kt b/src/net/torvald/terrarum/gameactors/Actor.kt index 0ddc4208c..b349010c9 100644 --- a/src/net/torvald/terrarum/gameactors/Actor.kt +++ b/src/net/torvald/terrarum/gameactors/Actor.kt @@ -13,8 +13,8 @@ abstract class Actor : Comparable, Runnable { abstract fun update(gc: GameContainer, delta: Int) /** - * Valid RefID is equal to or greater than 32768. - * @return Reference ID. (32768-0x7FFF_FFFF) + * Valid RefID is equal to or greater than 16777216. + * @return Reference ID. (16777216-0x7FFF_FFFF) */ abstract var referenceID: Int abstract var actorValue: ActorValue @@ -40,7 +40,7 @@ abstract class Actor : Comparable, Runnable { var ret: Int do { ret = HQRNG().nextInt().and(0x7FFFFFFF) // set new ID - } while (Terrarum.ingame.hasActor(ret) || ret < ItemPropCodex.ITEM_UNIQUE_MAX) // check for collision + } while (Terrarum.ingame.hasActor(ret) || ret < ItemPropCodex.ITEM_COUNT_MAX) // check for collision return ret } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt index 46586d851..86d306020 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt @@ -3,7 +3,7 @@ package net.torvald.terrarum.gameactors import com.jme3.math.FastMath import net.torvald.point.Point2d import net.torvald.terrarum.* -import net.torvald.terrarum.gamemap.GameWorld +import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.mapdrawer.MapDrawer import net.torvald.terrarum.tileproperties.TilePropCodex import net.torvald.spriteanimation.SpriteAnimation @@ -162,7 +162,7 @@ open class ActorWithBody : Actor(), Visible { */ @Transient private val SI_TO_GAME_VEL = METER / Terrarum.TARGET_FPS /** - * Gravitational Constant G. Load from gamemap. + * Gravitational Constant G. Load from gameworld. * [m / s^2] * s^2 = 1/FPS = 1/60 if FPS is targeted to 60 * meter to pixel : 24/FPS diff --git a/src/net/torvald/terrarum/gameactors/DroppedItem.kt b/src/net/torvald/terrarum/gameactors/DroppedItem.kt index 1789cd19b..1e5c5e703 100644 --- a/src/net/torvald/terrarum/gameactors/DroppedItem.kt +++ b/src/net/torvald/terrarum/gameactors/DroppedItem.kt @@ -1,5 +1,6 @@ package net.torvald.terrarum.gameactors +import net.torvald.terrarum.gameitem.InventoryItem import net.torvald.terrarum.itemproperties.ItemPropCodex import net.torvald.terrarum.tileproperties.TilePropCodex import org.newdawn.slick.GameContainer @@ -8,22 +9,24 @@ import org.newdawn.slick.Graphics /** * Created by minjaesong on 16-03-15. */ -class DroppedItem constructor(itemID: Int) : ActorWithBody() { +class DroppedItem(private val item: InventoryItem) : ActorWithBody() { init { - if (itemID >= ItemPropCodex.ITEM_UNIQUE_MAX) + if (item.itemID >= ItemPropCodex.ITEM_COUNT_MAX) throw RuntimeException("Attempted to create DroppedItem actor of a real actor; the real actor must be dropped instead.") isVisible = true - mass = if (itemID < TilePropCodex.TILE_UNIQUE_MAX) - TilePropCodex.getProp(itemID).density / 1000.0 + mass = if (item.itemID < TilePropCodex.TILE_UNIQUE_MAX) + TilePropCodex.getProp(item.itemID).density / 1000.0 else - ItemPropCodex.getProp(itemID).mass + ItemPropCodex.getProp(item.itemID).mass + + scale = ItemPropCodex.getProp(item.itemID).scale } override fun update(gc: GameContainer, delta: Int) { - + item.worldActorEffect(gc, delta) } override fun drawBody(gc: GameContainer, g: Graphics) { diff --git a/src/net/torvald/terrarum/gameactors/FixturesBase.kt b/src/net/torvald/terrarum/gameactors/FixturesBase.kt index 7a04fe260..d41e082bc 100644 --- a/src/net/torvald/terrarum/gameactors/FixturesBase.kt +++ b/src/net/torvald/terrarum/gameactors/FixturesBase.kt @@ -6,21 +6,29 @@ import net.torvald.spriteanimation.SpriteAnimation * Created by minjaesong on 16-06-17. */ open class FixturesBase : ActorWithBody() { - /** Binary flags. Indicates that other actor (player) can pass in the direction. - * - (0: No collision) - * - 1: Top - * - 2: Right - * - 4: Bottom - * - 8: Left + /** + * 0: Open + * 1: Blocked + * 2: Platform; can be stood on, press DOWN to go down. Also allows other blocks can be places on top of it (e.g. torch) + * 3: Wall_left; blocks rightward movement + * 4: Wall_right: blocks leftward movement * For example, flag of 4 is good for tables; player can stand on, which means * downward movement is blocked within the fixtures' AABB. */ var collisionFlag: Int = 0 /** - * Normally if player is standing on the fixtures (with flag 4), pressing DOWN wiil allow - * player to get down. Setting this flag TRUE will block such movement (player cannot get down) + * Normally if player is standing on the fixtures (with flag 2 -- COLLISION_PLATFORM), + * pressing DOWN wiil allow player to get down. + * Setting this flag TRUE will block such movement (player cannot get down) */ var cannotPassThru = false + companion object { + val COLLISION_OPEN = 0 + val COLLISION_BLOCKED = 1 + val COLLISION_PLATFORM = 2 + val COLLISION_WALL_LEFT = 3 + val COLLISION_WALL_RIGHT = 4 + } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameactors/NPCIntelligentBase.kt b/src/net/torvald/terrarum/gameactors/NPCIntelligentBase.kt index 79612ffd9..629f12edc 100644 --- a/src/net/torvald/terrarum/gameactors/NPCIntelligentBase.kt +++ b/src/net/torvald/terrarum/gameactors/NPCIntelligentBase.kt @@ -53,7 +53,12 @@ open class NPCIntelligentBase : ActorWithBody() } override fun effectWhenThrown(gc: GameContainer, delta_t: Int) { + } + override fun effectWhenTakenOut(gc: GameContainer, delta: Int) { + } + + override fun worldActorEffect(gc: GameContainer, delta: Int) { } } diff --git a/src/net/torvald/terrarum/gamecontroller/Key.kt b/src/net/torvald/terrarum/gamecontroller/Key.kt index 1cb533adb..6cb45bb44 100644 --- a/src/net/torvald/terrarum/gamecontroller/Key.kt +++ b/src/net/torvald/terrarum/gamecontroller/Key.kt @@ -5,7 +5,7 @@ package net.torvald.terrarum.gamecontroller */ object Key { - val RET = 28 + val RETURN = 28 val BACKSPACE = 14 val GRAVE = 41 val TAB = 15 diff --git a/src/net/torvald/terrarum/gameitem/DynamicItem.kt b/src/net/torvald/terrarum/gameitem/DynamicItem.kt new file mode 100644 index 000000000..93e778483 --- /dev/null +++ b/src/net/torvald/terrarum/gameitem/DynamicItem.kt @@ -0,0 +1,99 @@ +package net.torvald.terrarum.gameitem + +import net.torvald.random.HQRNG +import net.torvald.terrarum.KVHashMap +import net.torvald.terrarum.itemproperties.ItemPropCodex +import org.newdawn.slick.GameContainer + +/** + * Items that has some more information (like floppy disk that contains UUID) + * + * @param baseItemID ID of the item that this item is based on + * + * Created by minjaesong on 16-09-08. + */ +open class DynamicItem(val baseItemID: Int, val newMass: Double? = null, val newScale: Double? = null) : InventoryItem { + /** + * Effects applied (continuously or not) while thrown to the world, + * called by the proxy Actor + */ + override fun worldActorEffect(gc: GameContainer, delta: Int) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + /** + * Internal ID of an Item, Long + * 0-4096: Tiles + * 4097-32767: Static items + * 32768-16777215: Dynamic items + * >= 16777216: Actor RefID + */ + override val itemID: Int = generateUniqueDynamicItemID() + + private fun generateUniqueDynamicItemID(): Int { + var ret: Int + do { + ret = HQRNG().nextInt().and(0x7FFFFFFF) // set new ID + } while (ItemPropCodex.hasItem(ret) || ret < ItemPropCodex.ITEM_DYNAMIC_MIN || ret > ItemPropCodex.ITEM_DYNAMIC_MAX) // check for collision + return ret + } + + /** + * Weight of the item + */ + override var mass: Double + get() = itemInfo.getAsDouble(ItemInfoKey.MASS)!! + set(value) { + itemInfo[ItemInfoKey.MASS] = value + } + /** + * Scale of the item. Real mass: mass * (scale^3) + * + * For static item, it must be 1.0. If you tinkered the item to be bigger, + * it must be re-assigned as Dynamic Item + */ + override var scale: Double + get() = itemInfo.getAsDouble(ItemInfoKey.SCALE) ?: 1.0 + set(value) { + itemInfo[ItemInfoKey.SCALE] = value + } + + val itemInfo = KVHashMap() + + init { + // set mass to the value from item codex using baseItemID + // if you forget this, the game will throw NullPointerException! + if (newMass != null) mass = newMass + if (newScale != null) scale = newScale + } + + /** + * Effects applied continuously while in pocket + */ + override fun effectWhileInPocket(gc: GameContainer, delta: Int) { } + + /** + * Effects applied immediately only once if picked up + */ + override fun effectWhenPickedUp(gc: GameContainer, delta: Int) { } + + /** + * Effects applied (continuously or not) while primary button (usually left mouse button) is down + */ + override fun primaryUse(gc: GameContainer, delta: Int) { } + + /** + * Effects applied (continuously or not) while secondary button (usually right mouse button) is down + */ + override fun secondaryUse(gc: GameContainer, delta: Int) { } + + /** + * Effects applied immediately only once if thrown from pocket + */ + override fun effectWhenThrown(gc: GameContainer, delta: Int) { } + + /** + * Effects applied (continuously or not) while thrown to the world + */ + override fun effectWhenTakenOut(gc: GameContainer, delta: Int) { } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameitem/InventoryItem.kt b/src/net/torvald/terrarum/gameitem/InventoryItem.kt index 8ae9b9e77..8298ce675 100644 --- a/src/net/torvald/terrarum/gameitem/InventoryItem.kt +++ b/src/net/torvald/terrarum/gameitem/InventoryItem.kt @@ -9,58 +9,58 @@ interface InventoryItem { /** * Internal ID of an Item, Long * 0-4096: Tiles - * 4097-32767: Various items - * >=32768: Actor RefID + * 4097-32767: Static items + * 32768-16777215: Dynamic items + * >= 16777216: Actor RefID */ - var itemID: Int + val itemID: Int /** - * Weight of the item, Float + * Weight of the item */ var mass: Double /** * Scale of the item. Real mass: mass * (scale^3) + * + * For static item, it must be 1.0. If you tinkered the item to be bigger, + * it must be re-assigned as Dynamic Item */ var scale: Double /** * Effects applied continuously while in pocket - * @param gc - * * - * @param delta_t */ - fun effectWhileInPocket(gc: GameContainer, delta_t: Int) + fun effectWhileInPocket(gc: GameContainer, delta: Int) /** * Effects applied immediately only once if picked up - * @param gc - * * - * @param delta_t */ - fun effectWhenPickedUp(gc: GameContainer, delta_t: Int) + fun effectWhenPickedUp(gc: GameContainer, delta: Int) /** * Effects applied (continuously or not) while primary button (usually left mouse button) is down - * @param gc - * * - * @param delta_t */ - fun primaryUse(gc: GameContainer, delta_t: Int) + fun primaryUse(gc: GameContainer, delta: Int) /** * Effects applied (continuously or not) while secondary button (usually right mouse button) is down - * @param gc - * * - * @param delta_t */ - fun secondaryUse(gc: GameContainer, delta_t: Int) + fun secondaryUse(gc: GameContainer, delta: Int) /** * Effects applied immediately only once if thrown from pocket - * @param gc - * * - * @param delta_t */ - fun effectWhenThrown(gc: GameContainer, delta_t: Int) + fun effectWhenThrown(gc: GameContainer, delta: Int) + + /** + * Effects applied (continuously or not) while thrown to the world + */ + fun effectWhenTakenOut(gc: GameContainer, delta: Int) + + /** + * Effects applied (continuously or not) while thrown to the world, + * called by the proxy Actor + */ + fun worldActorEffect(gc: GameContainer, delta: Int) } \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameitem/ItemInfoKey.kt b/src/net/torvald/terrarum/gameitem/ItemInfoKey.kt new file mode 100644 index 000000000..a87c646c8 --- /dev/null +++ b/src/net/torvald/terrarum/gameitem/ItemInfoKey.kt @@ -0,0 +1,10 @@ +package net.torvald.terrarum.gameitem + +/** + * Created by minjaesong on 16-09-09. + */ +object ItemInfoKey { + const val SCALE = "scale" + const val MASS = "mass" + const val UUID = "uuid" +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameitem/TileAsItem.kt b/src/net/torvald/terrarum/gameitem/TileAsItem.kt index c4ae3b87d..e6294d3ba 100644 --- a/src/net/torvald/terrarum/gameitem/TileAsItem.kt +++ b/src/net/torvald/terrarum/gameitem/TileAsItem.kt @@ -36,4 +36,19 @@ class TileAsItem(tileNum: Int) : InventoryItem { override fun effectWhenThrown(gc: GameContainer, delta_t: Int) { throw UnsupportedOperationException() } + + /** + * Effects applied (continuously or not) while thrown to the world + */ + override fun effectWhenTakenOut(gc: GameContainer, delta: Int) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + /** + * Effects applied (continuously or not) while thrown to the world, + * called by the proxy Actor + */ + override fun worldActorEffect(gc: GameContainer, delta: Int) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/gamemap/FluidCodex.kt b/src/net/torvald/terrarum/gameworld/FluidCodex.kt similarity index 79% rename from src/net/torvald/terrarum/gamemap/FluidCodex.kt rename to src/net/torvald/terrarum/gameworld/FluidCodex.kt index d9d7e3c1b..0925f2ce7 100644 --- a/src/net/torvald/terrarum/gamemap/FluidCodex.kt +++ b/src/net/torvald/terrarum/gameworld/FluidCodex.kt @@ -1,4 +1,4 @@ -package net.torvald.terrarum.gamemap +package net.torvald.terrarum.gameworld /** * Created by minjaesong on 16-08-06. diff --git a/src/net/torvald/terrarum/gamemap/GameWorld.kt b/src/net/torvald/terrarum/gameworld/GameWorld.kt similarity index 99% rename from src/net/torvald/terrarum/gamemap/GameWorld.kt rename to src/net/torvald/terrarum/gameworld/GameWorld.kt index 4a6c4f05a..a8e6abcca 100644 --- a/src/net/torvald/terrarum/gamemap/GameWorld.kt +++ b/src/net/torvald/terrarum/gameworld/GameWorld.kt @@ -1,5 +1,5 @@ -package net.torvald.terrarum.gamemap +package net.torvald.terrarum.gameworld import net.torvald.terrarum.gameactors.Player import net.torvald.terrarum.gameactors.roundInt diff --git a/src/net/torvald/terrarum/gamemap/MapLayer.kt b/src/net/torvald/terrarum/gameworld/MapLayer.kt similarity index 97% rename from src/net/torvald/terrarum/gamemap/MapLayer.kt rename to src/net/torvald/terrarum/gameworld/MapLayer.kt index a619c8e1a..a00d5f496 100644 --- a/src/net/torvald/terrarum/gamemap/MapLayer.kt +++ b/src/net/torvald/terrarum/gameworld/MapLayer.kt @@ -1,4 +1,4 @@ -package net.torvald.terrarum.gamemap +package net.torvald.terrarum.gameworld /** * Created by minjaesong on 16-01-17. diff --git a/src/net/torvald/terrarum/gamemap/MapPoint.kt b/src/net/torvald/terrarum/gameworld/MapPoint.kt similarity index 94% rename from src/net/torvald/terrarum/gamemap/MapPoint.kt rename to src/net/torvald/terrarum/gameworld/MapPoint.kt index cbf2dac3d..bbd977670 100644 --- a/src/net/torvald/terrarum/gamemap/MapPoint.kt +++ b/src/net/torvald/terrarum/gameworld/MapPoint.kt @@ -1,4 +1,4 @@ -package net.torvald.terrarum.gamemap +package net.torvald.terrarum.gameworld import net.torvald.point.Point2d diff --git a/src/net/torvald/terrarum/gamemap/PairedMapLayer.kt b/src/net/torvald/terrarum/gameworld/PairedMapLayer.kt similarity index 98% rename from src/net/torvald/terrarum/gamemap/PairedMapLayer.kt rename to src/net/torvald/terrarum/gameworld/PairedMapLayer.kt index 30a82308d..91790b998 100644 --- a/src/net/torvald/terrarum/gamemap/PairedMapLayer.kt +++ b/src/net/torvald/terrarum/gameworld/PairedMapLayer.kt @@ -1,4 +1,4 @@ -package net.torvald.terrarum.gamemap +package net.torvald.terrarum.gameworld import java.io.Serializable import java.util.Spliterator diff --git a/src/net/torvald/terrarum/gamemap/WorldSimulator.kt b/src/net/torvald/terrarum/gameworld/WorldSimulator.kt similarity index 99% rename from src/net/torvald/terrarum/gamemap/WorldSimulator.kt rename to src/net/torvald/terrarum/gameworld/WorldSimulator.kt index 48d9274e3..0751dea06 100644 --- a/src/net/torvald/terrarum/gamemap/WorldSimulator.kt +++ b/src/net/torvald/terrarum/gameworld/WorldSimulator.kt @@ -1,10 +1,10 @@ -package net.torvald.terrarum.gamemap +package net.torvald.terrarum.gameworld import net.torvald.random.HQRNG import net.torvald.terrarum.Terrarum import net.torvald.terrarum.gameactors.Player import net.torvald.terrarum.gameactors.roundInt -import net.torvald.terrarum.gamemap.WorldSimulator.isSolid +import net.torvald.terrarum.gameworld.WorldSimulator.isSolid import net.torvald.terrarum.mapdrawer.MapCamera import net.torvald.terrarum.mapdrawer.MapDrawer import net.torvald.terrarum.tileproperties.TileNameCode diff --git a/src/net/torvald/terrarum/gamemap/WorldTime.kt b/src/net/torvald/terrarum/gameworld/WorldTime.kt similarity index 99% rename from src/net/torvald/terrarum/gamemap/WorldTime.kt rename to src/net/torvald/terrarum/gameworld/WorldTime.kt index 203fa0fdd..5820f59db 100644 --- a/src/net/torvald/terrarum/gamemap/WorldTime.kt +++ b/src/net/torvald/terrarum/gameworld/WorldTime.kt @@ -1,4 +1,4 @@ -package net.torvald.terrarum.gamemap +package net.torvald.terrarum.gameworld /** * Created by minjaesong on 16-01-24. diff --git a/src/net/torvald/terrarum/itemproperties/ItemPropCodex.kt b/src/net/torvald/terrarum/itemproperties/ItemPropCodex.kt index 26f908655..29ebdc377 100644 --- a/src/net/torvald/terrarum/itemproperties/ItemPropCodex.kt +++ b/src/net/torvald/terrarum/itemproperties/ItemPropCodex.kt @@ -1,10 +1,11 @@ package net.torvald.terrarum.itemproperties import net.torvald.random.HQRNG +import net.torvald.terrarum.KVHashMap import net.torvald.terrarum.gameactors.CanBeAnItem import net.torvald.terrarum.gameitem.InventoryItem import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.gamemap.GameWorld +import net.torvald.terrarum.gameworld.GameWorld import org.newdawn.slick.GameContainer import java.util.* @@ -17,23 +18,30 @@ object ItemPropCodex { /** * - * Will return corresponding Actor if ID >= 32768 + * Will return corresponding Actor if ID >= 16777216 */ - private lateinit var itemCodex: Array + private val itemCodex = ArrayList() + private val dynamicItemDescription = HashMap() - const val ITEM_UNIQUE_MAX = 32768 - val TILE_MAX = GameWorld.TILES_SUPPORTED + val ITEM_TILE_MAX = GameWorld.TILES_SUPPORTED + val ITEM_COUNT_MAX = 16777216 + val ITEM_DYNAMIC_MAX = ITEM_COUNT_MAX - 1 + val ITEM_STATIC_MAX = 32767 + val ITEM_DYNAMIC_MIN = ITEM_STATIC_MAX + 1 + val ITEM_STATIC_MIN = ITEM_TILE_MAX init { - itemCodex = arrayOf() - - // read prop in csv + // read prop in csv and fill itemCodex + // read from save (if applicable) and fill dynamicItemDescription } fun getProp(code: Int): InventoryItem { - if (code < ITEM_UNIQUE_MAX) // generic item - return itemCodex[code] + if (code < ITEM_STATIC_MAX) // generic item + return itemCodex[code] // from CSV + else if (code < ITEM_DYNAMIC_MAX) { + TODO("read from dynamicitem description (JSON)") + } else { val a = Terrarum.ingame.getActorByID(code) // actor item if (a is CanBeAnItem) return a.itemData @@ -41,4 +49,6 @@ object ItemPropCodex { throw IllegalArgumentException("Attempted to get item data of actor that cannot be an item. ($a)") } } + + fun hasItem(itemID: Int): Boolean = dynamicItemDescription.containsKey(itemID) } \ No newline at end of file diff --git a/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt b/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt index 314101280..1253f7d9a 100644 --- a/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt +++ b/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt @@ -191,6 +191,8 @@ object LightmapRenderer { } } + // O(36n) == O(n) where n is a size of the map. + // Because of inevitable overlaps on the area, it only works with ADDITIVE blend (aka maxblend) try { // Round 1 for (y in for_y_start - overscan_open..for_y_end) { @@ -230,6 +232,8 @@ object LightmapRenderer { private fun calculate(x: Int, y: Int): Int = calculate(x, y, false) private fun calculate(x: Int, y: Int, doNotCalculateAmbient: Boolean): Int { + // O(9n) == O(n) where n is a size of the map. + var lightLevelThis: Int = 0 val thisTerrain = Terrarum.ingame.world.getTileFromTerrain(x, y) val thisWall = Terrarum.ingame.world.getTileFromWall(x, y) diff --git a/src/net/torvald/terrarum/mapdrawer/MapCamera.kt b/src/net/torvald/terrarum/mapdrawer/MapCamera.kt index 40b84f2be..ff2796077 100644 --- a/src/net/torvald/terrarum/mapdrawer/MapCamera.kt +++ b/src/net/torvald/terrarum/mapdrawer/MapCamera.kt @@ -1,14 +1,14 @@ package net.torvald.terrarum.mapdrawer -import net.torvald.terrarum.gamemap.GameWorld -import net.torvald.terrarum.gamemap.PairedMapLayer +import net.torvald.terrarum.gameworld.GameWorld +import net.torvald.terrarum.gameworld.PairedMapLayer import net.torvald.terrarum.Terrarum import net.torvald.terrarum.tileproperties.TileNameCode import net.torvald.terrarum.tileproperties.TilePropCodex import com.jme3.math.FastMath import net.torvald.terrarum.concurrent.ThreadPool -import net.torvald.terrarum.setBlendMul -import net.torvald.terrarum.setBlendNormal +import net.torvald.terrarum.blendMul +import net.torvald.terrarum.blendNormal import org.lwjgl.opengl.GL11 import org.newdawn.slick.GameContainer import org.newdawn.slick.Graphics @@ -247,15 +247,15 @@ object MapCamera { /** * render to camera */ - setBlendNormal() + blendNormal() drawTiles(WALL, false) drawTiles(TERRAIN, false) } fun renderFront(gc: GameContainer, g: Graphics) { - setBlendMul() + blendMul() drawTiles(TERRAIN, true) - setBlendNormal() + blendNormal() } private fun drawTiles(mode: Int, drawModeTilesBlendMul: Boolean) { diff --git a/src/net/torvald/terrarum/mapdrawer/MapDrawer.kt b/src/net/torvald/terrarum/mapdrawer/MapDrawer.kt index 1e3369187..552d5720c 100644 --- a/src/net/torvald/terrarum/mapdrawer/MapDrawer.kt +++ b/src/net/torvald/terrarum/mapdrawer/MapDrawer.kt @@ -1,6 +1,6 @@ package net.torvald.terrarum.mapdrawer -import net.torvald.terrarum.gamemap.GameWorld +import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.Terrarum import net.torvald.terrarum.tileproperties.TileNameCode import net.torvald.terrarum.tilestats.TileStats diff --git a/src/net/torvald/terrarum/mapgenerator/WorldGenerator.kt b/src/net/torvald/terrarum/mapgenerator/WorldGenerator.kt index 88a87c653..119c84f3d 100644 --- a/src/net/torvald/terrarum/mapgenerator/WorldGenerator.kt +++ b/src/net/torvald/terrarum/mapgenerator/WorldGenerator.kt @@ -1,7 +1,7 @@ package net.torvald.terrarum.mapgenerator import net.torvald.random.HQRNG -import net.torvald.terrarum.gamemap.GameWorld +import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.tileproperties.TileNameCode import com.jme3.math.FastMath import com.sudoplay.joise.Joise diff --git a/src/net/torvald/terrarum/tileproperties/TileProp.kt b/src/net/torvald/terrarum/tileproperties/TileProp.kt index 8811a6a3f..935672d19 100644 --- a/src/net/torvald/terrarum/tileproperties/TileProp.kt +++ b/src/net/torvald/terrarum/tileproperties/TileProp.kt @@ -1,7 +1,7 @@ package net.torvald.terrarum.tileproperties import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.gamemap.WorldTime +import net.torvald.terrarum.gameworld.WorldTime /** * Created by minjaesong on 16-02-16. diff --git a/src/net/torvald/terrarum/tileproperties/TilePropCodex.kt b/src/net/torvald/terrarum/tileproperties/TilePropCodex.kt index 1af0fa1b2..6fb9611e8 100644 --- a/src/net/torvald/terrarum/tileproperties/TilePropCodex.kt +++ b/src/net/torvald/terrarum/tileproperties/TilePropCodex.kt @@ -1,8 +1,8 @@ package net.torvald.terrarum.tileproperties import net.torvald.CSVFetcher -import net.torvald.terrarum.gamemap.MapLayer -import net.torvald.terrarum.gamemap.PairedMapLayer +import net.torvald.terrarum.gameworld.MapLayer +import net.torvald.terrarum.gameworld.PairedMapLayer import org.apache.commons.csv.CSVRecord import java.io.IOException diff --git a/src/net/torvald/terrarum/tileproperties/TilePropUtil.kt b/src/net/torvald/terrarum/tileproperties/TilePropUtil.kt index c4f8a7129..10f5b1261 100644 --- a/src/net/torvald/terrarum/tileproperties/TilePropUtil.kt +++ b/src/net/torvald/terrarum/tileproperties/TilePropUtil.kt @@ -3,7 +3,7 @@ package net.torvald.terrarum.tileproperties import com.jme3.math.FastMath import net.torvald.random.HQRNG import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.gamemap.WorldTime +import net.torvald.terrarum.gameworld.WorldTime import net.torvald.terrarum.mapdrawer.LightmapRenderer import net.torvald.terrarum.toInt import net.torvald.terrarum.weather.WeatherMixer diff --git a/src/net/torvald/terrarum/tilestats/TileStats.kt b/src/net/torvald/terrarum/tilestats/TileStats.kt index 747d17d4f..30e2afbd4 100644 --- a/src/net/torvald/terrarum/tilestats/TileStats.kt +++ b/src/net/torvald/terrarum/tilestats/TileStats.kt @@ -1,8 +1,8 @@ package net.torvald.terrarum.tilestats import net.torvald.terrarum.gameactors.Player -import net.torvald.terrarum.gamemap.GameWorld -import net.torvald.terrarum.gamemap.MapLayer +import net.torvald.terrarum.gameworld.GameWorld +import net.torvald.terrarum.gameworld.MapLayer import net.torvald.terrarum.mapdrawer.MapCamera import net.torvald.terrarum.mapdrawer.MapDrawer import net.torvald.terrarum.Terrarum diff --git a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt index 59d009ebe..3c0af8471 100644 --- a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt +++ b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt @@ -2,14 +2,14 @@ package net.torvald.terrarum.ui import com.jme3.math.FastMath import net.torvald.imagefont.GameFontBase -import net.torvald.terrarum.gamemap.PairedMapLayer +import net.torvald.terrarum.gameworld.PairedMapLayer import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.mapdrawer.LightmapRenderer import net.torvald.terrarum.mapdrawer.MapCamera import net.torvald.terrarum.mapdrawer.MapDrawer import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.setBlendNormal -import net.torvald.terrarum.setBlendScreen +import net.torvald.terrarum.blendNormal +import net.torvald.terrarum.blendScreen import org.newdawn.slick.Color import org.newdawn.slick.GameContainer import org.newdawn.slick.Graphics @@ -201,7 +201,7 @@ class BasicDebugInfoWindow : UICanvas { g.drawString("255", x.toFloat() + w + 1 - 8*3, y.toFloat() + h + 2) g.drawString("Histogramme", x + w / 2 - 5.5f * 8, y.toFloat() + h + 2) - setBlendScreen() + blendScreen() for (c in 0..2) { for (i in 0..255) { var histogram_value = if (i == 255) 0 else histogram.get(c)[i] @@ -220,7 +220,7 @@ class BasicDebugInfoWindow : UICanvas { g.fillRect(bar_x, bar_y, bar_w, bar_h) } } - setBlendNormal() + blendNormal() } private fun line(i: Int): Float = i * 10f diff --git a/src/net/torvald/terrarum/ui/ConsoleWindow.kt b/src/net/torvald/terrarum/ui/ConsoleWindow.kt index 2e4fd1890..3b1418185 100644 --- a/src/net/torvald/terrarum/ui/ConsoleWindow.kt +++ b/src/net/torvald/terrarum/ui/ConsoleWindow.kt @@ -84,7 +84,7 @@ class ConsoleWindow : UICanvas, KeyboardControlled { historyIndex = -1 // execute - if (key == Key.RET && commandInputPool!!.length > 0) { + if (key == Key.RETURN && commandInputPool!!.length > 0) { commandHistory.add(commandInputPool!!.toString()) executeCommand() commandInputPool = StringBuilder() diff --git a/src/net/torvald/terrarum/ui/ItemSlotImageBuilder.kt b/src/net/torvald/terrarum/ui/ItemSlotImageBuilder.kt index 6c447e9b0..0afe31d2b 100644 --- a/src/net/torvald/terrarum/ui/ItemSlotImageBuilder.kt +++ b/src/net/torvald/terrarum/ui/ItemSlotImageBuilder.kt @@ -1,6 +1,6 @@ package net.torvald.terrarum.ui -import net.torvald.terrarum.setBlendNormal +import net.torvald.terrarum.blendNormal import org.newdawn.slick.Color import org.newdawn.slick.Image import org.newdawn.slick.SpriteSheet diff --git a/src/net/torvald/terrarum/ui/MessageWindow.kt b/src/net/torvald/terrarum/ui/MessageWindow.kt index d035e2dd6..47b8ad152 100644 --- a/src/net/torvald/terrarum/ui/MessageWindow.kt +++ b/src/net/torvald/terrarum/ui/MessageWindow.kt @@ -2,8 +2,8 @@ package net.torvald.terrarum.ui import net.torvald.imagefont.GameFontWhite import com.jme3.math.FastMath -import net.torvald.terrarum.setBlendDisable -import net.torvald.terrarum.setBlendNormal +import net.torvald.terrarum.blendDisable +import net.torvald.terrarum.blendNormal import org.lwjgl.opengl.GL11 import org.newdawn.slick.* @@ -55,7 +55,7 @@ constructor(override var width: Int, isBlackVariant: Boolean) : UICanvas { } override fun render(gc: GameContainer, g: Graphics) { - setBlendDisable() + blendDisable() drawSegments(g) g.setDrawMode(Graphics.MODE_ALPHA_MAP) @@ -69,7 +69,7 @@ constructor(override var width: Int, isBlackVariant: Boolean) : UICanvas { g.drawString(messagesList[i], (messageWindowRadius + 4).toFloat(), (messageWindowRadius + GLYPH_HEIGHT * i).toFloat()) } - setBlendNormal() + blendNormal() } override fun processInput(input: Input) { diff --git a/src/net/torvald/terrarum/ui/UICanvas.kt b/src/net/torvald/terrarum/ui/UICanvas.kt index 085204df5..ee8b63512 100644 --- a/src/net/torvald/terrarum/ui/UICanvas.kt +++ b/src/net/torvald/terrarum/ui/UICanvas.kt @@ -49,4 +49,6 @@ interface UICanvas { * Do not modify handler!!.openCloseCounter here. */ fun endClosing(gc: GameContainer, delta: Int) -} \ No newline at end of file +} + +const val OPENCLOSE_GENERIC = 200 \ No newline at end of file diff --git a/src/net/torvald/terrarum/virtualcomputers/API.kt b/src/net/torvald/terrarum/virtualcomputers/API.kt new file mode 100644 index 000000000..f1976bd45 --- /dev/null +++ b/src/net/torvald/terrarum/virtualcomputers/API.kt @@ -0,0 +1,10 @@ +package net.torvald.terrarum.virtualcomputers + +/** + * Reference: https://github.com/MightyPirates/OpenComputers/blob/master-MC1.7.10/src/main/java/li/cil/oc/api/API.java + * + * Created by minjaesong on 16-09-07. + */ +object API { + // val filesystem = Filesystem() +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/virtualcomputers/terminal/LuaConsole.java b/src/net/torvald/terrarum/virtualcomputers/terminal/LuaConsole.java new file mode 100644 index 000000000..c42a0eeb8 --- /dev/null +++ b/src/net/torvald/terrarum/virtualcomputers/terminal/LuaConsole.java @@ -0,0 +1,194 @@ +/* + * $Id: LuaConsole.java 79 2012-01-08 11:08:32Z andre@naef.com $ + * See LICENSE.txt for license terms. + */ + +package net.torvald.terrarum.virtualcomputers.terminal; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; + +import li.cil.repack.com.naef.jnlua.LuaException; +import li.cil.repack.com.naef.jnlua.LuaRuntimeException; +import li.cil.repack.com.naef.jnlua.LuaState; + +/** + * A simple Lua console. + * + *

+ * The console collects input until a line with the sole content of the word + * go is encountered. At that point, the collected input is run as a Lua + * chunk. If the Lua chunk loads and runs successfully, the console displays the + * returned values of the chunk as well as the execution time based on a + * System.nanoTime() measurement. Otherwise, the console shows the + * error that has occurred. + *

+ * + *

+ * Expressions can be printed by prepending = to the expression at the + * beginning of a chunk. The console translates = into + * return followed by a space and executes the chunk immediately. + * No separate go is required. Therefore, expressions printed this way + * must be entered on a single line. + *

+ */ +public class LuaConsole { + // -- Static + private static final String[] EMPTY_ARGS = new String[0]; + + /** + * Main routine. + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + LuaConsole luaConsole = new LuaConsole(args); + luaConsole.run(); + System.exit(0); + } + + // -- State + private LuaState luaState; + + // -- Construction + /** + * Creates a new instance. + */ + public LuaConsole() { + this(EMPTY_ARGS); + } + + /** + * Creates a new instance with the specified command line arguments. The + * arguments are passed to Lua as the argv global variable. + * + * @param args + */ + public LuaConsole(String[] args) { + luaState = new LuaState(); + + // Process arguments + luaState.newTable(args.length, 0); + for (int i = 0; i < args.length; i++) { + luaState.pushString(args[i]); + luaState.rawSet(-2, i + 1); + } + luaState.setGlobal("argv"); + + // Open standard libraries + luaState.openLibs(); + + // Set buffer mode + luaState.load("io.stdout:setvbuf(\"no\")", "=consoleInitStdout"); + luaState.call(0, 0); + luaState.load("io.stderr:setvbuf(\"no\")", "=consoleInitStderr"); + luaState.call(0, 0); + } + + // -- Properties + /** + * Returns the Lua state of this console. + * + * @return the Lua state + */ + public LuaState getLuaState() { + return luaState; + } + + // -- Operations + /** + * Runs the console. + */ + public void run() { + // Banner + System.out.println(String.format("JNLua %s Console using Lua %s.", + LuaState.VERSION, LuaState.LUA_VERSION)); + System.out.print("Type 'go' on an empty line to evaluate a chunk. "); + System.out.println("Type = to print an expression."); + + // Prepare reader + BufferedReader bufferedReader = new BufferedReader( + new InputStreamReader(System.in)); + try { + // Process chunks + chunk: while (true) { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + OutputStreamWriter outWriter = new OutputStreamWriter(out, + "UTF-8"); + boolean firstLine = true; + + // Process lines + while (true) { + String line = bufferedReader.readLine(); + if (line == null) { + break chunk; + } + if (line.equals("go")) { + outWriter.flush(); + InputStream in = new ByteArrayInputStream(out + .toByteArray()); + runChunk(in); + continue chunk; + } + if (firstLine && line.startsWith("=")) { + outWriter.write("return " + line.substring(1)); + outWriter.flush(); + InputStream in = new ByteArrayInputStream(out + .toByteArray()); + runChunk(in); + continue chunk; + } + outWriter.write(line); + outWriter.write('\n'); + firstLine = false; + } + } + } catch (IOException e) { + System.out.print("IO error: "); + System.out.print(e.getMessage()); + System.out.println(); + } + } + + /** + * Runs a chunk of Lua code from an input stream. + */ + protected void runChunk(InputStream in) throws IOException { + try { + long start = System.nanoTime(); + luaState.setTop(0); + luaState.load(in, "=console", "t"); + luaState.call(0, LuaState.MULTRET); + long stop = System.nanoTime(); + for (int i = 1; i <= luaState.getTop(); i++) { + if (i > 1) { + System.out.print(", "); + } + switch (luaState.type(i)) { + case BOOLEAN: + System.out.print(Boolean.valueOf(luaState.toBoolean(i))); + break; + case NUMBER: + case STRING: + System.out.print(luaState.toString(i)); + break; + default: + System.out.print(luaState.typeName(i)); + } + } + System.out.print("\t#msec="); + System.out.print(String.format("%.3f", (stop - start) / 1000000.0)); + System.out.println(); + } catch (LuaRuntimeException e) { + e.printLuaStackTrace(); + } catch (LuaException e) { + System.err.println(e.getMessage()); + } + } +} diff --git a/src/net/torvald/terrarum/virtualcomputers/terminal/SimpleTextTerminal.kt b/src/net/torvald/terrarum/virtualcomputers/terminal/SimpleTextTerminal.kt new file mode 100644 index 000000000..7c001f380 --- /dev/null +++ b/src/net/torvald/terrarum/virtualcomputers/terminal/SimpleTextTerminal.kt @@ -0,0 +1,259 @@ +package net.torvald.terrarum.virtualcomputers.terminal + +import net.torvald.aa.AAFrame +import net.torvald.aa.ColouredFastFont +import net.torvald.terrarum.blendNormal +import net.torvald.terrarum.blendMul +import org.newdawn.slick.* + +/** + * Default text terminal, four text colours (black, grey, lgrey, white). + * + * Created by minjaesong on 16-09-07. + */ +open class SimpleTextTerminal( + val phosphor: Color, override val width: Int, override val height: Int +) : Terminal { + override val coloursCount = 4 + + private val colors = arrayOf( + Color(0x19, 0x19, 0x19), + Color(0xff, 0xff, 0xff), + Color(0x55, 0x55, 0x55), + Color(0xaa, 0xaa, 0xaa) + ) + + private val backDefault = 0 + private val foreDefault = colors.size - 1 + + override var backColour = backDefault + override var foreColour = foreDefault + private val colourKey: Int + get() = backColour.shl(4).plus(foreColour).and(0xFF) + + override var cursorX = 0 + override var cursorY = 0 + override var cursorBlink = true + + val screenBuffer = AAFrame(width, height) + + private val fontRef = "./assets/graphics/fonts/MDA.png" + private val fontImg = Image(fontRef) + private val fontW = fontImg.width / 16 + private val fontH = fontImg.height / 16 + private val font = ColouredFastFont(this, fontRef, fontW, fontH) + + override var isInputStreamOpen: Boolean + get() = throw UnsupportedOperationException() + set(value) { + } + + override val displayW = fontW * width + override val displayH = fontH * height + + private val TABSIZE = 4 + + private val ASCII_NUL = 0.toChar() + + private val ASCII_BEL = 7.toChar() // *BEEP!* + private val ASCII_BS = 8.toChar() // x = x - 1 + private val ASCII_TAB = 9.toChar() // move cursor to next (TABSIZE * yy) pos (5 -> 8, 3- > 4, 4 -> 8) + private val ASCII_LF = 10.toChar() // new line + private val ASCII_FF = 12.toChar() // new page + private val ASCII_CR = 13.toChar() // x <- 0 + private val ASCII_DEL = 127.toChar() // backspace and delete char + + private var cursorBlinkTimer = 0 + private val cursorBlinkLen = 250 + private var cursorBlinkOn = true + + override fun getColor(index: Int): Color = colors[index] + + override fun update(gc: GameContainer, delta: Int) { + cursorBlinkTimer = cursorBlinkTimer.plus(delta) + if (cursorBlinkTimer > cursorBlinkLen) { + cursorBlinkTimer -= cursorBlinkLen + cursorBlinkOn = !cursorBlinkOn + } + + wrap() + } + + private fun wrap() { + // wrap cursor + if (cursorX < 0 && cursorY <= 0) { + setCursor(0, 0) + } + else if (cursorX >= width) { + setCursor(0, cursorY + 1) + } + else if (cursorX < 0) { + setCursor(width - 1, cursorY - 1) + } + // auto scroll up + if (cursorY >= height) { + scroll() + } + } + + /** + * pass UIcanvas to the parameter "g" + */ + override fun render(gc: GameContainer, g: Graphics) { + g.font = font + + blendNormal() + + for (y in 0..height - 1) { + for (x in 0..width - 1) { + val ch = screenBuffer.getChar(x, y) + + // background + g.color = getColor(screenBuffer.getBackgroundColour(x, y)) + g.fillRect(fontW * x.toFloat(), fontH * y.toFloat(), fontW.toFloat(), fontH.toFloat()) + + // foreground + if (ch.toInt() != 0 && ch.toInt() != 32) { + g.color = getColor(screenBuffer.getForegroundColour(x, y)) + g.drawString( + Character.toString(ch), + fontW * x.toFloat(), fontH * y.toFloat()) + } + } + } + + + // cursor + g.color = getColor(foreColour) + if (cursorBlinkOn && cursorBlink) + g.fillRect( + fontW * cursorX.toFloat(), + fontH * cursorY.toFloat(), + fontW.toFloat(), + fontH.toFloat() + ) + + + + // colour overlay + g.color = phosphor + blendMul() + g.fillRect(0f, 0f, displayW.toFloat(), displayH.toFloat()) + + + blendNormal() + + } + + override fun setCursor(x: Int, y: Int) { + cursorX = x + cursorY = y + } + + /** Emits a bufferChar. Does not move cursor */ + override fun emitChar(bufferChar: Int) { + screenBuffer.drawBuffer(cursorX, cursorY, bufferChar.toChar()) + } + + /** Emits a char. Does not move cursor */ + override fun emitChar(c: Char) { + screenBuffer.drawBuffer(cursorX, cursorY, c.toInt().and(0xFF).toChar(), colourKey) + } + + val asciiControlInUse = charArrayOf( + ASCII_BEL, + ASCII_BS, + ASCII_TAB, + ASCII_LF, + ASCII_FF, + ASCII_CR, + ASCII_DEL + ) + + /** Prints a char and move cursor accordingly. */ + override fun printChar(c: Char) { + wrap() + if (c >= ' ' && c.toInt() != 127) { + emitChar(c) + cursorX += 1 + } + else { + when (c) { + ASCII_BEL -> beep() + ASCII_BS -> { cursorX -= 1; wrap() } + ASCII_TAB -> { cursorX = (cursorX).div(TABSIZE).times(TABSIZE) + TABSIZE } + ASCII_LF -> { cursorX = 0; cursorY += 1; wrap() } + ASCII_FF -> clear() + ASCII_CR -> { cursorX = 0 } + ASCII_DEL -> { cursorX -= 1; wrap(); emitChar(colourKey.shl(8)) } + } + } + } + + /** Emits a string and move cursor accordingly. */ + override fun printString(s: String, x: Int, y: Int) { + setCursor(x, y) + emitString(s) + val absCursorPos = cursorX + cursorY * width + s.length + setCursor(x % width, y / width) + } + + /** Emits a string. Does not move cursor */ + override fun emitString(s: String) { + val x = cursorX + val y = cursorY + + for (i in 0..s.length - 1) + printChar(s[i]) + + setCursor(x, y) + } + + override fun clear() { + screenBuffer.clear(backColour) + cursorX = 0 + cursorY = 0 + } + + override fun clearLine() { + for (i in 0..width - 1) + screenBuffer.drawBuffer(i, cursorY, 0.toChar(), colourKey) + } + + override fun scroll(amount: Int) { + val offset = amount * width + for (i in offset..screenBuffer.sizeof.ushr(1) - 1) { + screenBuffer.frameBuffer[i - offset] = screenBuffer.frameBuffer[i] + } + for (c in 1..amount) { + cursorY -= 1 + clearLine() + } + } + + override fun setColour(back: Int, fore: Int) { + backColour = back + foreColour = fore + } + + override fun resetColour() { + backColour = backDefault + foreColour = foreDefault + } + + override fun beep(freq: Int, duration: Int) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + private fun isOOB(x: Int, y: Int) = + (x < 0 || y < 0 || x >= width || y >= height) + + companion object { + val AMBER = Color(255, 183, 0) // P3, 602 nm + val IBM_GREEN = Color(74, 255, 0) // P39, 525 nm + val WHITE = Color(228, 234, 255) // P4, 7 500 K + val ELECTRIC_BLUE = Color(0, 239, 255) // imaginary, 486 nm + val RED = Color(250, 0, 0) // <= 645 nm + } + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/virtualcomputers/terminal/Terminal.kt b/src/net/torvald/terrarum/virtualcomputers/terminal/Terminal.kt new file mode 100644 index 000000000..11c995e59 --- /dev/null +++ b/src/net/torvald/terrarum/virtualcomputers/terminal/Terminal.kt @@ -0,0 +1,56 @@ +package net.torvald.terrarum.virtualcomputers.terminal + +import org.newdawn.slick.Color +import org.newdawn.slick.GameContainer +import org.newdawn.slick.Graphics +import org.newdawn.slick.Input + +/** + * A tty (terminal) + * + * Framebuffer : use net.torvald.aa.AAFrame + * + * Background color is fixed; text color is variable + * + * Created by minjaesong on 16-09-07. + */ +interface Terminal { + val width: Int + val height: Int + val coloursCount: Int + var cursorX: Int + var cursorY: Int + var cursorBlink: Boolean + var backColour: Int + var foreColour: Int + + // to be used in UI + val displayW: Int + val displayH: Int + + // more technical + var isInputStreamOpen: Boolean + + fun getColor(index: Int): Color + fun update(gc: GameContainer, delta: Int) + fun render(gc: GameContainer, g: Graphics) + + // API calls + fun setCursor(x: Int, y: Int) + /** Emits a bufferChar. Does not move cursor */ + fun emitChar(bufferChar: Int) + /** Emits a char. Does not move cursor */ + fun emitChar(c: Char) + /** Prints a char and move cursor accordingly. */ + fun printChar(c: Char) + /** Emits a string. Does not move cursor */ + fun emitString(s: String) + /** Emits a string and move cursor accordingly. */ + fun printString(s: String, x: Int = cursorX, y: Int = cursorY) + fun clear() + fun clearLine() + fun scroll(amount: Int = 1) + fun setColour(back: Int, fore: Int) + fun resetColour() + fun beep(freq: Int = 1000, duration: Int = 200) +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/virtualcomputers/worldobject/ComputerPartsCodex.kt b/src/net/torvald/terrarum/virtualcomputers/worldobject/ComputerPartsCodex.kt new file mode 100644 index 000000000..be02165ea --- /dev/null +++ b/src/net/torvald/terrarum/virtualcomputers/worldobject/ComputerPartsCodex.kt @@ -0,0 +1,29 @@ +package net.torvald.terrarum.virtualcomputers.worldobject + +import java.util.* + +/** + * Created by minjaesong on 16-09-08. + */ +object ComputerPartsCodex { + val rams = HashMap() // itemID, capacity in bytes (0 bytes - 8 GBytes) + val processors = HashMap() // itemID, cycles + + init { + rams.put(4864, 128.shr(20)) + rams.put(4865, 192.shr(20)) + rams.put(4866, 256.shr(20)) + rams.put(4867, 320.shr(20)) + rams.put(4868, 480.shr(20)) + rams.put(4869, 512.shr(20)) + // two more? + + processors.put(4872, 1000) + processors.put(4873, 2000) + processors.put(4874, 4000) + processors.put(4875, 8000) + } + + fun getRamSize(itemIndex: Int): Int = rams[itemIndex] ?: 0 + fun getProcessorCycles(itemIndex: Int): Int = processors[itemIndex] ?: 0 +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/virtualcomputers/worldobject/FixturesBasicTerminal.kt b/src/net/torvald/terrarum/virtualcomputers/worldobject/FixturesBasicTerminal.kt new file mode 100644 index 000000000..5a88f0cd3 --- /dev/null +++ b/src/net/torvald/terrarum/virtualcomputers/worldobject/FixturesBasicTerminal.kt @@ -0,0 +1,25 @@ +package net.torvald.terrarum.virtualcomputers.worldobject + +import net.torvald.terrarum.gameactors.AVKey +import net.torvald.terrarum.gameactors.FixturesBase +import net.torvald.terrarum.virtualcomputers.terminal.SimpleTextTerminal +import net.torvald.terrarum.virtualcomputers.terminal.Terminal +import net.torvald.terrarum.virtualcomputers.worldobject.ui.UITextTerminal +import org.newdawn.slick.Color +import java.util.* + +/** + * Created by minjaesong on 16-09-08. + */ +class FixturesBasicTerminal(phosphor: Color) : FixturesBase() { + + val terminal: Terminal = SimpleTextTerminal(phosphor, 80, 25) + val ui = UITextTerminal(terminal) + + init { + collisionFlag = COLLISION_PLATFORM + + actorValue[AVKey.UUID] = UUID.randomUUID().toString() + } + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/virtualcomputers/worldobject/FixturesComputerBase.kt b/src/net/torvald/terrarum/virtualcomputers/worldobject/FixturesComputerBase.kt new file mode 100644 index 000000000..7d30d7da7 --- /dev/null +++ b/src/net/torvald/terrarum/virtualcomputers/worldobject/FixturesComputerBase.kt @@ -0,0 +1,51 @@ +package net.torvald.terrarum.virtualcomputers.worldobject + +import net.torvald.terrarum.gameactors.FixturesBase +import java.security.SecureRandom +import java.util.* + +/** + * Created by minjaesong on 16-09-08. + */ +abstract class FixturesComputerBase() : FixturesBase() { + + init { + actorValue["memslot0"] = -1 // -1 indicates mem slot is empty + actorValue["memslot1"] = -1 // put index of item here + actorValue["memslot2"] = -1 // ditto. + actorValue["memslot3"] = -1 // do. + + actorValue["processor"] = -1 // do. + + actorValue["sda0"] = "none" // 'UUID rendered as String' or "none" + actorValue["sda1"] = "none" + actorValue["sda2"] = "none" + actorValue["sda3"] = "none" + actorValue["fd1"] = "none" + actorValue["fd2"] = "none" + actorValue["fd3"] = "none" + actorValue["fd4"] = "none" + + actorValue["uuid"] = UUID.randomUUID().toString() + + collisionFlag = COLLISION_PLATFORM + } + + val processorCycle: Int // number of Lua statement to process per tick (1/100 s) + get() = ComputerPartsCodex.getProcessorCycles(actorValue.getAsInt("processor") ?: -1) + val memSize: Int // max: 8 GB + get() { + var size = 0 + for (i in 0..3) + size += ComputerPartsCodex.getRamSize(actorValue.getAsInt("memSlot$i") ?: -1) + + return size + } + + var terminal: FixturesBase? = null + + + // API-specific + + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/virtualcomputers/worldobject/ui/UITextTerminal.kt b/src/net/torvald/terrarum/virtualcomputers/worldobject/ui/UITextTerminal.kt new file mode 100644 index 000000000..381e871f2 --- /dev/null +++ b/src/net/torvald/terrarum/virtualcomputers/worldobject/ui/UITextTerminal.kt @@ -0,0 +1,90 @@ +package net.torvald.terrarum.virtualcomputers.worldobject.ui + +import net.torvald.terrarum.ui.* +import net.torvald.terrarum.virtualcomputers.terminal.Terminal +import org.newdawn.slick.GameContainer +import org.newdawn.slick.Graphics +import org.newdawn.slick.Image +import org.newdawn.slick.Input + +/** + * Created by minjaesong on 16-09-08. + */ +class UITextTerminal(val terminal: Terminal) : UICanvas, KeyboardControlled, MouseControlled { + override fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun keyPressed(key: Int, c: Char) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun keyReleased(key: Int, c: Char) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override var width: Int = terminal.displayW// + some + override var height: Int = terminal.displayH// + frame + private var terminalDisplay = Image(terminal.displayW, terminal.displayH) + + override fun mousePressed(button: Int, x: Int, y: Int) { + // monitor on/off, reset switch + } + + override fun mouseReleased(button: Int, x: Int, y: Int) { + } + + override fun mouseWheelMoved(change: Int) { + } + + /** + * Usage: (in StateInGame:) uiHandlerField.ui.handler = uiHandlerField + */ + override var handler: UIHandler? = null + + /** + * In milliseconds + * + * Timer itself is implemented in the handler. + */ + override var openCloseTime: Int = OPENCLOSE_GENERIC + + override fun update(gc: GameContainer, delta: Int) { + terminal.update(gc, delta) + } + + override fun render(gc: GameContainer, g: Graphics) { + terminal.render(gc, terminalDisplay.graphics) + } + + override fun processInput(input: Input) { + } + + /** + * Do not modify handler!!.openCloseCounter here. + */ + override fun doOpening(gc: GameContainer, delta: Int) { + } + + /** + * Do not modify handler!!.openCloseCounter here. + */ + override fun doClosing(gc: GameContainer, delta: Int) { + } + + /** + * Do not modify handler!!.openCloseCounter here. + */ + override fun endOpening(gc: GameContainer, delta: Int) { + } + + /** + * Do not modify handler!!.openCloseCounter here. + */ + override fun endClosing(gc: GameContainer, delta: Int) { + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/weather/WeatherMixer.kt b/src/net/torvald/terrarum/weather/WeatherMixer.kt index 360722320..121c3ca62 100644 --- a/src/net/torvald/terrarum/weather/WeatherMixer.kt +++ b/src/net/torvald/terrarum/weather/WeatherMixer.kt @@ -6,7 +6,7 @@ import net.torvald.colourutil.CIELChUtil import net.torvald.colourutil.ColourUtil import net.torvald.random.HQRNG import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.gamemap.WorldTime +import net.torvald.terrarum.gameworld.WorldTime import org.newdawn.slick.Color import org.newdawn.slick.GameContainer import org.newdawn.slick.Graphics @@ -96,6 +96,9 @@ object WeatherMixer { globalLightNow.b = gradCol.b } + /** + * Get a GL of specific time + */ fun getGlobalLightOfTime(timeInSec: Int): Color = getGradientColour(currentWeather.globalLightColourMap, 0, timeInSec) diff --git a/src/org/dyn4j/geometry/Vector2.kt b/src/org/dyn4j/geometry/Vector2.kt index 95902b369..114a4b664 100644 --- a/src/org/dyn4j/geometry/Vector2.kt +++ b/src/org/dyn4j/geometry/Vector2.kt @@ -23,7 +23,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* - * Kotlin translated and modified code Copyright (c) 2016 Torvald aka skyhi14. + * Kotlin translated and modified code Copyright (c) 2016 Minjaesong (Torvald). */ package org.dyn4j.geometry