mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
new item type, "Dynamic Item"; working text terminal
Former-commit-id: 81e6d836f5f1e6490027d38146a32d404cf9ce3e Former-commit-id: af6557340f9cd0ea0b67eb7a8825aeffe75f9d82
This commit is contained in:
2
.idea/libraries/lib.xml
generated
2
.idea/libraries/lib.xml
generated
@@ -15,6 +15,8 @@
|
|||||||
<root url="jar://$PROJECT_DIR$/lib/lwjgl.jar!/" />
|
<root url="jar://$PROJECT_DIR$/lib/lwjgl.jar!/" />
|
||||||
<root url="jar://$PROJECT_DIR$/lib/lwjgl_util.jar!/" />
|
<root url="jar://$PROJECT_DIR$/lib/lwjgl_util.jar!/" />
|
||||||
<root url="jar://$PROJECT_DIR$/lib/slick.jar!/" />
|
<root url="jar://$PROJECT_DIR$/lib/slick.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/OpenComputers-JNLua.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/OpenComputers-LuaJ.jar!/" />
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
<JAVADOC>
|
<JAVADOC>
|
||||||
<root url="http://slick.ninjacave.com/javadoc/" />
|
<root url="http://slick.ninjacave.com/javadoc/" />
|
||||||
|
|||||||
BIN
assets/graphics/fonts/MDA.png
Normal file
BIN
assets/graphics/fonts/MDA.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
BIN
assets/graphics/fonts/MDA.png.0.png
Normal file
BIN
assets/graphics/fonts/MDA.png.0.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
BIN
assets/graphics/fonts/MDA.png.1.png
Normal file
BIN
assets/graphics/fonts/MDA.png.1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 KiB |
BIN
assets/graphics/fonts/MDA.png.2.png
Normal file
BIN
assets/graphics/fonts/MDA.png.2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
BIN
assets/graphics/fonts/MDA.png.3.png
Normal file
BIN
assets/graphics/fonts/MDA.png.3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
BIN
lib/OpenComputers-JNLua.jar
Normal file
BIN
lib/OpenComputers-JNLua.jar
Normal file
Binary file not shown.
BIN
lib/OpenComputers-LuaJ.jar
Normal file
BIN
lib/OpenComputers-LuaJ.jar
Normal file
Binary file not shown.
BIN
lib/natives/native.32.bsd.so
Executable file
BIN
lib/natives/native.32.bsd.so
Executable file
Binary file not shown.
BIN
lib/natives/native.32.dll
Executable file
BIN
lib/natives/native.32.dll
Executable file
Binary file not shown.
BIN
lib/natives/native.32.dylib
Executable file
BIN
lib/natives/native.32.dylib
Executable file
Binary file not shown.
BIN
lib/natives/native.32.so
Executable file
BIN
lib/natives/native.32.so
Executable file
Binary file not shown.
BIN
lib/natives/native.64.bsd.so
Executable file
BIN
lib/natives/native.64.bsd.so
Executable file
Binary file not shown.
BIN
lib/natives/native.64.dll
Executable file
BIN
lib/natives/native.64.dll
Executable file
Binary file not shown.
BIN
lib/natives/native.64.dylib
Executable file
BIN
lib/natives/native.64.dylib
Executable file
Binary file not shown.
BIN
lib/natives/native.64.so
Executable file
BIN
lib/natives/native.64.so
Executable file
Binary file not shown.
@@ -85,7 +85,7 @@ public class ModuleBrightContrast extends SourcedModule {
|
|||||||
@Override
|
@Override
|
||||||
public double get(double x, double y) {
|
public double get(double x, double y) {
|
||||||
double val = source.get(x, y);
|
double val = source.get(x, y);
|
||||||
// apply brightness
|
// apply colourKey
|
||||||
val += bright.get(x, y);
|
val += bright.get(x, y);
|
||||||
// subtract threshold, scale by factor, add threshold
|
// subtract threshold, scale by factor, add threshold
|
||||||
double t = threshold.get(x, y);
|
double t = threshold.get(x, y);
|
||||||
@@ -98,7 +98,7 @@ public class ModuleBrightContrast extends SourcedModule {
|
|||||||
@Override
|
@Override
|
||||||
public double get(double x, double y, double z) {
|
public double get(double x, double y, double z) {
|
||||||
double val = source.get(x, y, z);
|
double val = source.get(x, y, z);
|
||||||
// apply brightness
|
// apply colourKey
|
||||||
val += bright.get(x, y, z);
|
val += bright.get(x, y, z);
|
||||||
// subtract threshold, scale by factor, add threshold
|
// subtract threshold, scale by factor, add threshold
|
||||||
double t = threshold.get(x, y, z);
|
double t = threshold.get(x, y, z);
|
||||||
@@ -111,7 +111,7 @@ public class ModuleBrightContrast extends SourcedModule {
|
|||||||
@Override
|
@Override
|
||||||
public double get(double x, double y, double z, double w) {
|
public double get(double x, double y, double z, double w) {
|
||||||
double val = source.get(x, y, z, w);
|
double val = source.get(x, y, z, w);
|
||||||
// apply brightness
|
// apply colourKey
|
||||||
val += bright.get(x, y, z, w);
|
val += bright.get(x, y, z, w);
|
||||||
// subtract threshold, scale by factor, add threshold
|
// subtract threshold, scale by factor, add threshold
|
||||||
double t = threshold.get(x, y, z, w);
|
double t = threshold.get(x, y, z, w);
|
||||||
@@ -124,7 +124,7 @@ public class ModuleBrightContrast extends SourcedModule {
|
|||||||
@Override
|
@Override
|
||||||
public double get(double x, double y, double z, double w, double u, double v) {
|
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);
|
double val = source.get(x, y, z, w, u, v);
|
||||||
// apply brightness
|
// apply colourKey
|
||||||
val += bright.get(x, y, z, w, u, v);
|
val += bright.get(x, y, z, w, u, v);
|
||||||
// subtract threshold, scale by factor, add threshold
|
// subtract threshold, scale by factor, add threshold
|
||||||
double t = threshold.get(x, y, z, w, u, v);
|
double t = threshold.get(x, y, z, w, u, v);
|
||||||
@@ -139,7 +139,7 @@ public class ModuleBrightContrast extends SourcedModule {
|
|||||||
|
|
||||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||||
|
|
||||||
writeScalar("brightness", bright, props, map);
|
writeScalar("colourKey", bright, props, map);
|
||||||
writeScalar("contrastFactor", factor, props, map);
|
writeScalar("contrastFactor", factor, props, map);
|
||||||
writeScalar("contrastThreshold", threshold, props, map);
|
writeScalar("contrastThreshold", threshold, props, map);
|
||||||
writeSource(props, map);
|
writeSource(props, map);
|
||||||
@@ -152,7 +152,7 @@ public class ModuleBrightContrast extends SourcedModule {
|
|||||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||||
ModuleInstanceMap map) {
|
ModuleInstanceMap map) {
|
||||||
|
|
||||||
readScalar("brightness", "setBrightness", props, map);
|
readScalar("colourKey", "setBrightness", props, map);
|
||||||
readScalar("contrastFactor", "setContrastFactor", props, map);
|
readScalar("contrastFactor", "setContrastFactor", props, map);
|
||||||
readScalar("contrastThreshold", "setContrastThreshold", props, map);
|
readScalar("contrastThreshold", "setContrastThreshold", props, map);
|
||||||
readSource(props, map);
|
readSource(props, map);
|
||||||
|
|||||||
86
src/net/torvald/aa/AAFrame.kt
Normal file
86
src/net/torvald/aa/AAFrame.kt
Normal file
@@ -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)
|
||||||
|
}
|
||||||
102
src/net/torvald/aa/ColouredFastFont.kt
Normal file
102
src/net/torvald/aa/ColouredFastFont.kt
Normal file
@@ -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<SpriteSheet>() // 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()
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.torvald.serialise
|
package net.torvald.serialise
|
||||||
|
|
||||||
import net.torvald.terrarum.gamemap.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
*Terrarum* by Torvald
|
*Terrarum* by Minjaesong (Torvald)
|
||||||
|
|
||||||
Copyright (C) 2013-2016 Torvald. All rights reserved.
|
Copyright (C) 2013-2016 Torvald. All rights reserved.
|
||||||
mailto: alswo9628 *at* __gmail__ *dot* __com__
|
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
|
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.
|
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
|
crickets_02.ogg
|
||||||
|
|
||||||
Copyright (C) 2012, 2013, 2015, 2016 Klankbeeld
|
Copyright (C) 2012, 2013, 2015, 2016 Klankbeeld
|
||||||
Sound from http://www.freesound.org/people/klankbeeld/
|
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.
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
|Range|Description|
|
|Range|Description|
|
||||||
|-----|-----------|
|
|-----|-----------|
|
||||||
|0..4095|Tiles|
|
|0..4095|Tiles|
|
||||||
|4096..32767|Items|
|
|4096..32767|Items (static)|
|
||||||
|32768..0x7FFFFFFF|Actors|
|
|32768..16777215|Items (dynamic\*)|
|
||||||
|0x80000000..0xFFFFFFFF (all negative number)|Faction|
|
|16777216..0x7FFFFFFF|Actors|
|
||||||
|
|0x80000000..0xFFFFFFFF (all negative numbers)|Faction|
|
||||||
|
|
||||||
|
* dynamic items can have their own properties that will persist through savegame.
|
||||||
@@ -44,8 +44,8 @@
|
|||||||
Directory:
|
Directory:
|
||||||
|
|
||||||
+--- <save1>
|
+--- <save1>
|
||||||
--- 2a93bc5fd...f823 Actor/Faction/etc. data
|
--- 2a93bc5fd...f823 Actor/DynamicItem/Faction/etc. data (JSON)
|
||||||
--- 423bdc838...93bd Actor/Faction/etc. data
|
--- 423bdc838...93bd Actor/DynamicItem/Faction/etc. data (JSON)
|
||||||
--- Items_list.txt Human-readable
|
--- Items_list.txt Human-readable
|
||||||
--- Materials_list.txt Human-readable
|
--- Materials_list.txt Human-readable
|
||||||
--- Tiles_list.txt Human-readable
|
--- Tiles_list.txt Human-readable
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ import net.torvald.terrarum.gamecontroller.GameController
|
|||||||
import net.torvald.terrarum.gamecontroller.Key
|
import net.torvald.terrarum.gamecontroller.Key
|
||||||
import net.torvald.terrarum.gamecontroller.KeyMap
|
import net.torvald.terrarum.gamecontroller.KeyMap
|
||||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||||
import net.torvald.terrarum.gamemap.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
import net.torvald.terrarum.gamemap.WorldSimulator
|
import net.torvald.terrarum.gameworld.WorldSimulator
|
||||||
import net.torvald.terrarum.gamemap.WorldTime
|
import net.torvald.terrarum.gameworld.WorldTime
|
||||||
import net.torvald.terrarum.mapdrawer.LightmapRenderer
|
import net.torvald.terrarum.mapdrawer.LightmapRenderer
|
||||||
import net.torvald.terrarum.mapdrawer.LightmapRenderer.constructRGBFromInt
|
import net.torvald.terrarum.mapdrawer.LightmapRenderer.constructRGBFromInt
|
||||||
import net.torvald.terrarum.mapdrawer.MapCamera
|
import net.torvald.terrarum.mapdrawer.MapCamera
|
||||||
@@ -179,9 +179,9 @@ constructor() : BasicGameState() {
|
|||||||
TileStats.update()
|
TileStats.update()
|
||||||
if (!(CommandDict["setgl"] as SetGlobalLightOverride).lightOverride)
|
if (!(CommandDict["setgl"] as SetGlobalLightOverride).lightOverride)
|
||||||
world.globalLight = constructRGBFromInt(
|
world.globalLight = constructRGBFromInt(
|
||||||
globalLightByTime.redByte,
|
WeatherMixer.globalLightNow.redByte,
|
||||||
globalLightByTime.greenByte,
|
WeatherMixer.globalLightNow.greenByte,
|
||||||
globalLightByTime.blueByte
|
WeatherMixer.globalLightNow.blueByte
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -237,7 +237,7 @@ constructor() : BasicGameState() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun render(gc: GameContainer, sbg: StateBasedGame, g: Graphics) {
|
override fun render(gc: GameContainer, sbg: StateBasedGame, g: Graphics) {
|
||||||
setBlendNormal()
|
blendNormal()
|
||||||
|
|
||||||
|
|
||||||
drawSkybox(g)
|
drawSkybox(g)
|
||||||
@@ -274,12 +274,12 @@ constructor() : BasicGameState() {
|
|||||||
MapDrawer.render(gc, g)
|
MapDrawer.render(gc, g)
|
||||||
|
|
||||||
|
|
||||||
setBlendMul()
|
blendMul()
|
||||||
MapDrawer.drawEnvOverlay(g)
|
MapDrawer.drawEnvOverlay(g)
|
||||||
|
|
||||||
if (!KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) setBlendMul() else setBlendNormal()
|
if (!KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendMul() else blendNormal()
|
||||||
LightmapRenderer.draw(g)
|
LightmapRenderer.draw(g)
|
||||||
setBlendNormal()
|
blendNormal()
|
||||||
|
|
||||||
|
|
||||||
//////////////////////
|
//////////////////////
|
||||||
@@ -482,8 +482,6 @@ constructor() : BasicGameState() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val globalLightByTime = WeatherMixer.globalLightNow
|
|
||||||
|
|
||||||
fun Double.sqr() = this * this
|
fun Double.sqr() = this * this
|
||||||
fun Int.sqr() = this * this
|
fun Int.sqr() = this * this
|
||||||
private fun distToActorSqr(a: Visible, p: Player): Double =
|
private fun distToActorSqr(a: Visible, p: Player): Double =
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
package net.torvald.terrarum
|
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.GameContainer
|
||||||
import org.newdawn.slick.Graphics
|
import org.newdawn.slick.Graphics
|
||||||
|
import org.newdawn.slick.Image
|
||||||
import org.newdawn.slick.state.BasicGameState
|
import org.newdawn.slick.state.BasicGameState
|
||||||
import org.newdawn.slick.state.StateBasedGame
|
import org.newdawn.slick.state.StateBasedGame
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ComputerCraft/OpenComputers like-alike, just for fun!
|
* ComputerCraft/OpenComputers like-alike, just for fun!
|
||||||
@@ -11,17 +16,40 @@ import org.newdawn.slick.state.StateBasedGame
|
|||||||
* Created by minjaesong on 16-09-07.
|
* Created by minjaesong on 16-09-07.
|
||||||
*/
|
*/
|
||||||
class StateVTTest : BasicGameState() {
|
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) {
|
override fun update(container: GameContainer, game: StateBasedGame, delta: Int) {
|
||||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
Terrarum.appgc.setTitle("VT — F: ${container.fps}")
|
||||||
|
vt.update(container, delta)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getID() = Terrarum.STATE_ID_TEST_TTY
|
override fun getID() = Terrarum.STATE_ID_TEST_TTY
|
||||||
|
|
||||||
override fun render(container: GameContainer?, game: StateBasedGame?, g: Graphics?) {
|
override fun render(container: GameContainer, game: StateBasedGame, g: Graphics) {
|
||||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,6 +99,7 @@ constructor(gamename: String) : StateBasedGame(gamename) {
|
|||||||
|
|
||||||
gc.graphics.clear() // clean up any 'dust' in the buffer
|
gc.graphics.clear() // clean up any 'dust' in the buffer
|
||||||
|
|
||||||
|
addState(StateVTTest())
|
||||||
//addState(StateTestingSandbox())
|
//addState(StateTestingSandbox())
|
||||||
//addState(StateSplash())
|
//addState(StateSplash())
|
||||||
//addState(StateMonitorCheck())
|
//addState(StateMonitorCheck())
|
||||||
@@ -409,29 +410,29 @@ constructor(gamename: String) : StateBasedGame(gamename) {
|
|||||||
|
|
||||||
fun main(args: Array<String>) = Terrarum.main(args)
|
fun main(args: Array<String>) = Terrarum.main(args)
|
||||||
|
|
||||||
fun setBlendMul() {
|
fun blendMul() {
|
||||||
GL11.glEnable(GL11.GL_BLEND)
|
GL11.glEnable(GL11.GL_BLEND)
|
||||||
GL11.glColorMask(true, true, true, true)
|
GL11.glColorMask(true, true, true, true)
|
||||||
GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA)
|
GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setBlendNormal() {
|
fun blendNormal() {
|
||||||
GL11.glEnable(GL11.GL_BLEND)
|
GL11.glEnable(GL11.GL_BLEND)
|
||||||
GL11.glColorMask(true, true, true, true)
|
GL11.glColorMask(true, true, true, true)
|
||||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
|
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setBlendAlphaMap() {
|
fun blendAlphaMap() {
|
||||||
GL11.glDisable(GL11.GL_BLEND)
|
GL11.glDisable(GL11.GL_BLEND)
|
||||||
GL11.glColorMask(false, false, false, true)
|
GL11.glColorMask(false, false, false, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setBlendScreen() {
|
fun blendScreen() {
|
||||||
GL11.glEnable(GL11.GL_BLEND)
|
GL11.glEnable(GL11.GL_BLEND)
|
||||||
GL11.glColorMask(true, true, true, true)
|
GL11.glColorMask(true, true, true, true)
|
||||||
GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_COLOR)}
|
GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_COLOR)}
|
||||||
|
|
||||||
fun setBlendDisable() {
|
fun blendDisable() {
|
||||||
GL11.glDisable(GL11.GL_BLEND)
|
GL11.glDisable(GL11.GL_BLEND)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.torvald.terrarum.console
|
package net.torvald.terrarum.console
|
||||||
|
|
||||||
import net.torvald.terrarum.gamemap.WorldTime
|
import net.torvald.terrarum.gameworld.WorldTime
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -78,6 +78,12 @@ object AVKey {
|
|||||||
const val MAGICREGENRATEMULT = "$MAGICREGENRATE$MULT"
|
const val MAGICREGENRATEMULT = "$MAGICREGENRATE$MULT"
|
||||||
|
|
||||||
|
|
||||||
|
/** String
|
||||||
|
* UUID for certain fixtures
|
||||||
|
*/
|
||||||
|
const val UUID = "uuid"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const val __PLAYER_QUICKBARSEL = "__quickbarselection"
|
const val __PLAYER_QUICKBARSEL = "__quickbarselection"
|
||||||
}
|
}
|
||||||
@@ -13,8 +13,8 @@ abstract class Actor : Comparable<Actor>, Runnable {
|
|||||||
abstract fun update(gc: GameContainer, delta: Int)
|
abstract fun update(gc: GameContainer, delta: Int)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Valid RefID is equal to or greater than 32768.
|
* Valid RefID is equal to or greater than 16777216.
|
||||||
* @return Reference ID. (32768-0x7FFF_FFFF)
|
* @return Reference ID. (16777216-0x7FFF_FFFF)
|
||||||
*/
|
*/
|
||||||
abstract var referenceID: Int
|
abstract var referenceID: Int
|
||||||
abstract var actorValue: ActorValue
|
abstract var actorValue: ActorValue
|
||||||
@@ -40,7 +40,7 @@ abstract class Actor : Comparable<Actor>, Runnable {
|
|||||||
var ret: Int
|
var ret: Int
|
||||||
do {
|
do {
|
||||||
ret = HQRNG().nextInt().and(0x7FFFFFFF) // set new ID
|
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
|
return ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ package net.torvald.terrarum.gameactors
|
|||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.point.Point2d
|
import net.torvald.point.Point2d
|
||||||
import net.torvald.terrarum.*
|
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.mapdrawer.MapDrawer
|
||||||
import net.torvald.terrarum.tileproperties.TilePropCodex
|
import net.torvald.terrarum.tileproperties.TilePropCodex
|
||||||
import net.torvald.spriteanimation.SpriteAnimation
|
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
|
@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]
|
* [m / s^2]
|
||||||
* s^2 = 1/FPS = 1/60 if FPS is targeted to 60
|
* s^2 = 1/FPS = 1/60 if FPS is targeted to 60
|
||||||
* meter to pixel : 24/FPS
|
* meter to pixel : 24/FPS
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.torvald.terrarum.gameactors
|
package net.torvald.terrarum.gameactors
|
||||||
|
|
||||||
|
import net.torvald.terrarum.gameitem.InventoryItem
|
||||||
import net.torvald.terrarum.itemproperties.ItemPropCodex
|
import net.torvald.terrarum.itemproperties.ItemPropCodex
|
||||||
import net.torvald.terrarum.tileproperties.TilePropCodex
|
import net.torvald.terrarum.tileproperties.TilePropCodex
|
||||||
import org.newdawn.slick.GameContainer
|
import org.newdawn.slick.GameContainer
|
||||||
@@ -8,22 +9,24 @@ import org.newdawn.slick.Graphics
|
|||||||
/**
|
/**
|
||||||
* Created by minjaesong on 16-03-15.
|
* Created by minjaesong on 16-03-15.
|
||||||
*/
|
*/
|
||||||
class DroppedItem constructor(itemID: Int) : ActorWithBody() {
|
class DroppedItem(private val item: InventoryItem) : ActorWithBody() {
|
||||||
|
|
||||||
init {
|
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.")
|
throw RuntimeException("Attempted to create DroppedItem actor of a real actor; the real actor must be dropped instead.")
|
||||||
|
|
||||||
isVisible = true
|
isVisible = true
|
||||||
|
|
||||||
mass = if (itemID < TilePropCodex.TILE_UNIQUE_MAX)
|
mass = if (item.itemID < TilePropCodex.TILE_UNIQUE_MAX)
|
||||||
TilePropCodex.getProp(itemID).density / 1000.0
|
TilePropCodex.getProp(item.itemID).density / 1000.0
|
||||||
else
|
else
|
||||||
ItemPropCodex.getProp(itemID).mass
|
ItemPropCodex.getProp(item.itemID).mass
|
||||||
|
|
||||||
|
scale = ItemPropCodex.getProp(item.itemID).scale
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun update(gc: GameContainer, delta: Int) {
|
override fun update(gc: GameContainer, delta: Int) {
|
||||||
|
item.worldActorEffect(gc, delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun drawBody(gc: GameContainer, g: Graphics) {
|
override fun drawBody(gc: GameContainer, g: Graphics) {
|
||||||
|
|||||||
@@ -6,21 +6,29 @@ import net.torvald.spriteanimation.SpriteAnimation
|
|||||||
* Created by minjaesong on 16-06-17.
|
* Created by minjaesong on 16-06-17.
|
||||||
*/
|
*/
|
||||||
open class FixturesBase : ActorWithBody() {
|
open class FixturesBase : ActorWithBody() {
|
||||||
/** Binary flags. Indicates that other actor (player) can pass in the direction.
|
/**
|
||||||
* - (0: No collision)
|
* 0: Open
|
||||||
* - 1: Top
|
* 1: Blocked
|
||||||
* - 2: Right
|
* 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)
|
||||||
* - 4: Bottom
|
* 3: Wall_left; blocks rightward movement
|
||||||
* - 8: Left
|
* 4: Wall_right: blocks leftward movement
|
||||||
* For example, flag of 4 is good for tables; player can stand on, which means
|
* For example, flag of 4 is good for tables; player can stand on, which means
|
||||||
* downward movement is blocked within the fixtures' AABB.
|
* downward movement is blocked within the fixtures' AABB.
|
||||||
*/
|
*/
|
||||||
var collisionFlag: Int = 0
|
var collisionFlag: Int = 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normally if player is standing on the fixtures (with flag 4), pressing DOWN wiil allow
|
* Normally if player is standing on the fixtures (with flag 2 -- COLLISION_PLATFORM),
|
||||||
* player to get down. Setting this flag TRUE will block such movement (player cannot get down)
|
* pressing DOWN wiil allow player to get down.
|
||||||
|
* Setting this flag TRUE will block such movement (player cannot get down)
|
||||||
*/
|
*/
|
||||||
var cannotPassThru = false
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,12 @@ open class NPCIntelligentBase : ActorWithBody()
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun effectWhenThrown(gc: GameContainer, delta_t: Int) {
|
override fun effectWhenThrown(gc: GameContainer, delta_t: Int) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun effectWhenTakenOut(gc: GameContainer, delta: Int) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun worldActorEffect(gc: GameContainer, delta: Int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ package net.torvald.terrarum.gamecontroller
|
|||||||
*/
|
*/
|
||||||
object Key {
|
object Key {
|
||||||
|
|
||||||
val RET = 28
|
val RETURN = 28
|
||||||
val BACKSPACE = 14
|
val BACKSPACE = 14
|
||||||
val GRAVE = 41
|
val GRAVE = 41
|
||||||
val TAB = 15
|
val TAB = 15
|
||||||
|
|||||||
99
src/net/torvald/terrarum/gameitem/DynamicItem.kt
Normal file
99
src/net/torvald/terrarum/gameitem/DynamicItem.kt
Normal file
@@ -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) { }
|
||||||
|
}
|
||||||
@@ -9,58 +9,58 @@ interface InventoryItem {
|
|||||||
/**
|
/**
|
||||||
* Internal ID of an Item, Long
|
* Internal ID of an Item, Long
|
||||||
* 0-4096: Tiles
|
* 0-4096: Tiles
|
||||||
* 4097-32767: Various items
|
* 4097-32767: Static items
|
||||||
* >=32768: Actor RefID
|
* 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
|
var mass: Double
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scale of the item. Real mass: mass * (scale^3)
|
* 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
|
var scale: Double
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Effects applied continuously while in pocket
|
* 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
|
* 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
|
* 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
|
* 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
|
* 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)
|
||||||
}
|
}
|
||||||
10
src/net/torvald/terrarum/gameitem/ItemInfoKey.kt
Normal file
10
src/net/torvald/terrarum/gameitem/ItemInfoKey.kt
Normal file
@@ -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"
|
||||||
|
}
|
||||||
@@ -36,4 +36,19 @@ class TileAsItem(tileNum: Int) : InventoryItem {
|
|||||||
override fun effectWhenThrown(gc: GameContainer, delta_t: Int) {
|
override fun effectWhenThrown(gc: GameContainer, delta_t: Int) {
|
||||||
throw UnsupportedOperationException()
|
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.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.torvald.terrarum.gamemap
|
package net.torvald.terrarum.gameworld
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 16-08-06.
|
* Created by minjaesong on 16-08-06.
|
||||||
@@ -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.Player
|
||||||
import net.torvald.terrarum.gameactors.roundInt
|
import net.torvald.terrarum.gameactors.roundInt
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.torvald.terrarum.gamemap
|
package net.torvald.terrarum.gameworld
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 16-01-17.
|
* Created by minjaesong on 16-01-17.
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.torvald.terrarum.gamemap
|
package net.torvald.terrarum.gameworld
|
||||||
|
|
||||||
import net.torvald.point.Point2d
|
import net.torvald.point.Point2d
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.torvald.terrarum.gamemap
|
package net.torvald.terrarum.gameworld
|
||||||
|
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
import java.util.Spliterator
|
import java.util.Spliterator
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package net.torvald.terrarum.gamemap
|
package net.torvald.terrarum.gameworld
|
||||||
|
|
||||||
import net.torvald.random.HQRNG
|
import net.torvald.random.HQRNG
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gameactors.Player
|
import net.torvald.terrarum.gameactors.Player
|
||||||
import net.torvald.terrarum.gameactors.roundInt
|
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.MapCamera
|
||||||
import net.torvald.terrarum.mapdrawer.MapDrawer
|
import net.torvald.terrarum.mapdrawer.MapDrawer
|
||||||
import net.torvald.terrarum.tileproperties.TileNameCode
|
import net.torvald.terrarum.tileproperties.TileNameCode
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.torvald.terrarum.gamemap
|
package net.torvald.terrarum.gameworld
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 16-01-24.
|
* Created by minjaesong on 16-01-24.
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
package net.torvald.terrarum.itemproperties
|
package net.torvald.terrarum.itemproperties
|
||||||
|
|
||||||
import net.torvald.random.HQRNG
|
import net.torvald.random.HQRNG
|
||||||
|
import net.torvald.terrarum.KVHashMap
|
||||||
import net.torvald.terrarum.gameactors.CanBeAnItem
|
import net.torvald.terrarum.gameactors.CanBeAnItem
|
||||||
import net.torvald.terrarum.gameitem.InventoryItem
|
import net.torvald.terrarum.gameitem.InventoryItem
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gamemap.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
import org.newdawn.slick.GameContainer
|
import org.newdawn.slick.GameContainer
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -17,23 +18,30 @@ object ItemPropCodex {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* <ItemID or RefID for Actor, TheItem>
|
* <ItemID or RefID for Actor, TheItem>
|
||||||
* Will return corresponding Actor if ID >= 32768
|
* Will return corresponding Actor if ID >= 16777216
|
||||||
*/
|
*/
|
||||||
private lateinit var itemCodex: Array<InventoryItem>
|
private val itemCodex = ArrayList<InventoryItem>()
|
||||||
|
private val dynamicItemDescription = HashMap<Int, KVHashMap>()
|
||||||
|
|
||||||
const val ITEM_UNIQUE_MAX = 32768
|
val ITEM_TILE_MAX = GameWorld.TILES_SUPPORTED
|
||||||
val 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 {
|
init {
|
||||||
itemCodex = arrayOf<InventoryItem>()
|
// read prop in csv and fill itemCodex
|
||||||
|
|
||||||
// read prop in csv
|
|
||||||
|
|
||||||
|
// read from save (if applicable) and fill dynamicItemDescription
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getProp(code: Int): InventoryItem {
|
fun getProp(code: Int): InventoryItem {
|
||||||
if (code < ITEM_UNIQUE_MAX) // generic item
|
if (code < ITEM_STATIC_MAX) // generic item
|
||||||
return itemCodex[code]
|
return itemCodex[code] // from CSV
|
||||||
|
else if (code < ITEM_DYNAMIC_MAX) {
|
||||||
|
TODO("read from dynamicitem description (JSON)")
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
val a = Terrarum.ingame.getActorByID(code) // actor item
|
val a = Terrarum.ingame.getActorByID(code) // actor item
|
||||||
if (a is CanBeAnItem) return a.itemData
|
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)")
|
throw IllegalArgumentException("Attempted to get item data of actor that cannot be an item. ($a)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun hasItem(itemID: Int): Boolean = dynamicItemDescription.containsKey(itemID)
|
||||||
}
|
}
|
||||||
@@ -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 {
|
try {
|
||||||
// Round 1
|
// Round 1
|
||||||
for (y in for_y_start - overscan_open..for_y_end) {
|
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): Int = calculate(x, y, false)
|
||||||
|
|
||||||
private fun calculate(x: Int, y: Int, doNotCalculateAmbient: Boolean): Int {
|
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
|
var lightLevelThis: Int = 0
|
||||||
val thisTerrain = Terrarum.ingame.world.getTileFromTerrain(x, y)
|
val thisTerrain = Terrarum.ingame.world.getTileFromTerrain(x, y)
|
||||||
val thisWall = Terrarum.ingame.world.getTileFromWall(x, y)
|
val thisWall = Terrarum.ingame.world.getTileFromWall(x, y)
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package net.torvald.terrarum.mapdrawer
|
package net.torvald.terrarum.mapdrawer
|
||||||
|
|
||||||
import net.torvald.terrarum.gamemap.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
import net.torvald.terrarum.gamemap.PairedMapLayer
|
import net.torvald.terrarum.gameworld.PairedMapLayer
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.tileproperties.TileNameCode
|
import net.torvald.terrarum.tileproperties.TileNameCode
|
||||||
import net.torvald.terrarum.tileproperties.TilePropCodex
|
import net.torvald.terrarum.tileproperties.TilePropCodex
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.terrarum.concurrent.ThreadPool
|
import net.torvald.terrarum.concurrent.ThreadPool
|
||||||
import net.torvald.terrarum.setBlendMul
|
import net.torvald.terrarum.blendMul
|
||||||
import net.torvald.terrarum.setBlendNormal
|
import net.torvald.terrarum.blendNormal
|
||||||
import org.lwjgl.opengl.GL11
|
import org.lwjgl.opengl.GL11
|
||||||
import org.newdawn.slick.GameContainer
|
import org.newdawn.slick.GameContainer
|
||||||
import org.newdawn.slick.Graphics
|
import org.newdawn.slick.Graphics
|
||||||
@@ -247,15 +247,15 @@ object MapCamera {
|
|||||||
/**
|
/**
|
||||||
* render to camera
|
* render to camera
|
||||||
*/
|
*/
|
||||||
setBlendNormal()
|
blendNormal()
|
||||||
drawTiles(WALL, false)
|
drawTiles(WALL, false)
|
||||||
drawTiles(TERRAIN, false)
|
drawTiles(TERRAIN, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun renderFront(gc: GameContainer, g: Graphics) {
|
fun renderFront(gc: GameContainer, g: Graphics) {
|
||||||
setBlendMul()
|
blendMul()
|
||||||
drawTiles(TERRAIN, true)
|
drawTiles(TERRAIN, true)
|
||||||
setBlendNormal()
|
blendNormal()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun drawTiles(mode: Int, drawModeTilesBlendMul: Boolean) {
|
private fun drawTiles(mode: Int, drawModeTilesBlendMul: Boolean) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.torvald.terrarum.mapdrawer
|
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.Terrarum
|
||||||
import net.torvald.terrarum.tileproperties.TileNameCode
|
import net.torvald.terrarum.tileproperties.TileNameCode
|
||||||
import net.torvald.terrarum.tilestats.TileStats
|
import net.torvald.terrarum.tilestats.TileStats
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.torvald.terrarum.mapgenerator
|
package net.torvald.terrarum.mapgenerator
|
||||||
|
|
||||||
import net.torvald.random.HQRNG
|
import net.torvald.random.HQRNG
|
||||||
import net.torvald.terrarum.gamemap.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
import net.torvald.terrarum.tileproperties.TileNameCode
|
import net.torvald.terrarum.tileproperties.TileNameCode
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import com.sudoplay.joise.Joise
|
import com.sudoplay.joise.Joise
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.torvald.terrarum.tileproperties
|
package net.torvald.terrarum.tileproperties
|
||||||
|
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gamemap.WorldTime
|
import net.torvald.terrarum.gameworld.WorldTime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 16-02-16.
|
* Created by minjaesong on 16-02-16.
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package net.torvald.terrarum.tileproperties
|
package net.torvald.terrarum.tileproperties
|
||||||
|
|
||||||
import net.torvald.CSVFetcher
|
import net.torvald.CSVFetcher
|
||||||
import net.torvald.terrarum.gamemap.MapLayer
|
import net.torvald.terrarum.gameworld.MapLayer
|
||||||
import net.torvald.terrarum.gamemap.PairedMapLayer
|
import net.torvald.terrarum.gameworld.PairedMapLayer
|
||||||
import org.apache.commons.csv.CSVRecord
|
import org.apache.commons.csv.CSVRecord
|
||||||
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package net.torvald.terrarum.tileproperties
|
|||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.random.HQRNG
|
import net.torvald.random.HQRNG
|
||||||
import net.torvald.terrarum.Terrarum
|
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.mapdrawer.LightmapRenderer
|
||||||
import net.torvald.terrarum.toInt
|
import net.torvald.terrarum.toInt
|
||||||
import net.torvald.terrarum.weather.WeatherMixer
|
import net.torvald.terrarum.weather.WeatherMixer
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package net.torvald.terrarum.tilestats
|
package net.torvald.terrarum.tilestats
|
||||||
|
|
||||||
import net.torvald.terrarum.gameactors.Player
|
import net.torvald.terrarum.gameactors.Player
|
||||||
import net.torvald.terrarum.gamemap.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
import net.torvald.terrarum.gamemap.MapLayer
|
import net.torvald.terrarum.gameworld.MapLayer
|
||||||
import net.torvald.terrarum.mapdrawer.MapCamera
|
import net.torvald.terrarum.mapdrawer.MapCamera
|
||||||
import net.torvald.terrarum.mapdrawer.MapDrawer
|
import net.torvald.terrarum.mapdrawer.MapDrawer
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ package net.torvald.terrarum.ui
|
|||||||
|
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.imagefont.GameFontBase
|
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.langpack.Lang
|
||||||
import net.torvald.terrarum.mapdrawer.LightmapRenderer
|
import net.torvald.terrarum.mapdrawer.LightmapRenderer
|
||||||
import net.torvald.terrarum.mapdrawer.MapCamera
|
import net.torvald.terrarum.mapdrawer.MapCamera
|
||||||
import net.torvald.terrarum.mapdrawer.MapDrawer
|
import net.torvald.terrarum.mapdrawer.MapDrawer
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.setBlendNormal
|
import net.torvald.terrarum.blendNormal
|
||||||
import net.torvald.terrarum.setBlendScreen
|
import net.torvald.terrarum.blendScreen
|
||||||
import org.newdawn.slick.Color
|
import org.newdawn.slick.Color
|
||||||
import org.newdawn.slick.GameContainer
|
import org.newdawn.slick.GameContainer
|
||||||
import org.newdawn.slick.Graphics
|
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("255", x.toFloat() + w + 1 - 8*3, y.toFloat() + h + 2)
|
||||||
g.drawString("Histogramme", x + w / 2 - 5.5f * 8, 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 (c in 0..2) {
|
||||||
for (i in 0..255) {
|
for (i in 0..255) {
|
||||||
var histogram_value = if (i == 255) 0 else histogram.get(c)[i]
|
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)
|
g.fillRect(bar_x, bar_y, bar_w, bar_h)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setBlendNormal()
|
blendNormal()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun line(i: Int): Float = i * 10f
|
private fun line(i: Int): Float = i * 10f
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class ConsoleWindow : UICanvas, KeyboardControlled {
|
|||||||
historyIndex = -1
|
historyIndex = -1
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
if (key == Key.RET && commandInputPool!!.length > 0) {
|
if (key == Key.RETURN && commandInputPool!!.length > 0) {
|
||||||
commandHistory.add(commandInputPool!!.toString())
|
commandHistory.add(commandInputPool!!.toString())
|
||||||
executeCommand()
|
executeCommand()
|
||||||
commandInputPool = StringBuilder()
|
commandInputPool = StringBuilder()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.torvald.terrarum.ui
|
package net.torvald.terrarum.ui
|
||||||
|
|
||||||
import net.torvald.terrarum.setBlendNormal
|
import net.torvald.terrarum.blendNormal
|
||||||
import org.newdawn.slick.Color
|
import org.newdawn.slick.Color
|
||||||
import org.newdawn.slick.Image
|
import org.newdawn.slick.Image
|
||||||
import org.newdawn.slick.SpriteSheet
|
import org.newdawn.slick.SpriteSheet
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package net.torvald.terrarum.ui
|
|||||||
|
|
||||||
import net.torvald.imagefont.GameFontWhite
|
import net.torvald.imagefont.GameFontWhite
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.terrarum.setBlendDisable
|
import net.torvald.terrarum.blendDisable
|
||||||
import net.torvald.terrarum.setBlendNormal
|
import net.torvald.terrarum.blendNormal
|
||||||
import org.lwjgl.opengl.GL11
|
import org.lwjgl.opengl.GL11
|
||||||
import org.newdawn.slick.*
|
import org.newdawn.slick.*
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ constructor(override var width: Int, isBlackVariant: Boolean) : UICanvas {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun render(gc: GameContainer, g: Graphics) {
|
override fun render(gc: GameContainer, g: Graphics) {
|
||||||
setBlendDisable()
|
blendDisable()
|
||||||
|
|
||||||
drawSegments(g)
|
drawSegments(g)
|
||||||
g.setDrawMode(Graphics.MODE_ALPHA_MAP)
|
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())
|
g.drawString(messagesList[i], (messageWindowRadius + 4).toFloat(), (messageWindowRadius + GLYPH_HEIGHT * i).toFloat())
|
||||||
}
|
}
|
||||||
|
|
||||||
setBlendNormal()
|
blendNormal()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun processInput(input: Input) {
|
override fun processInput(input: Input) {
|
||||||
|
|||||||
@@ -49,4 +49,6 @@ interface UICanvas {
|
|||||||
* Do not modify handler!!.openCloseCounter here.
|
* Do not modify handler!!.openCloseCounter here.
|
||||||
*/
|
*/
|
||||||
fun endClosing(gc: GameContainer, delta: Int)
|
fun endClosing(gc: GameContainer, delta: Int)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const val OPENCLOSE_GENERIC = 200
|
||||||
10
src/net/torvald/terrarum/virtualcomputers/API.kt
Normal file
10
src/net/torvald/terrarum/virtualcomputers/API.kt
Normal file
@@ -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()
|
||||||
|
}
|
||||||
@@ -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.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* The console collects input until a line with the sole content of the word
|
||||||
|
* <i>go</i> 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
|
||||||
|
* <code>System.nanoTime()</code> measurement. Otherwise, the console shows the
|
||||||
|
* error that has occurred.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Expressions can be printed by prepending <i>=</i> to the expression at the
|
||||||
|
* beginning of a chunk. The console translates <i>=</i> into
|
||||||
|
* <code>return</code> followed by a space and executes the chunk immediately.
|
||||||
|
* No separate <i>go</i> is required. Therefore, expressions printed this way
|
||||||
|
* must be entered on a single line.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
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 <code>argv</code> 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 =<expression> 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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)
|
||||||
|
}
|
||||||
@@ -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<Int, Int>() // itemID, capacity in bytes (0 bytes - 8 GBytes)
|
||||||
|
val processors = HashMap<Int, Int>() // 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
|
||||||
|
}
|
||||||
@@ -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()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ import net.torvald.colourutil.CIELChUtil
|
|||||||
import net.torvald.colourutil.ColourUtil
|
import net.torvald.colourutil.ColourUtil
|
||||||
import net.torvald.random.HQRNG
|
import net.torvald.random.HQRNG
|
||||||
import net.torvald.terrarum.Terrarum
|
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.Color
|
||||||
import org.newdawn.slick.GameContainer
|
import org.newdawn.slick.GameContainer
|
||||||
import org.newdawn.slick.Graphics
|
import org.newdawn.slick.Graphics
|
||||||
@@ -96,6 +96,9 @@ object WeatherMixer {
|
|||||||
globalLightNow.b = gradCol.b
|
globalLightNow.b = gradCol.b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a GL of specific time
|
||||||
|
*/
|
||||||
fun getGlobalLightOfTime(timeInSec: Int): Color =
|
fun getGlobalLightOfTime(timeInSec: Int): Color =
|
||||||
getGradientColour(currentWeather.globalLightColourMap, 0, timeInSec)
|
getGradientColour(currentWeather.globalLightColourMap, 0, timeInSec)
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* 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
|
package org.dyn4j.geometry
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user