diff --git a/res/books/polyglot_test_2.txt b/res/books/polyglot_test_2.txt new file mode 100644 index 000000000..3839d757b --- /dev/null +++ b/res/books/polyglot_test_2.txt @@ -0,0 +1,29 @@ +"APP_WARNING_HEALTH_AND_SAFETY": "" + +bgBG ВНИМАНИЕ-ЗДРАВЕ И БЕЗОПАСНОСТ +csCZ POZOR-ZDRAVÍ A BEZPEČNOST +daDK ADVARSEL-SUNDHED OG SIKKERHED +de WARNUNG-GESUNDHEIT UND SICHERHEIT +elGR ΠΡΟΣΟΧΗ-ΥΓΕΙΑ ΚΑΙ ΑΣΦΑΛΕΙΑ +en WARNING-HEALTH AND SAFETY +es ADVERTENCIA-SALUD Y SEGURIDAD +fiFI VAROITUS-TERVEYS JA TURVALLISUUS +fr ATTENTION-SANTÉ ET SÉCURITÉ +huHU VIGYÁZAT-EGÉSZSÉGÜGYI ÉS BIZTONSÁGI +isIC VIÐVÖRUN-HEILSA OG ÖRYGGI +it ATTENZIONE-SALUTE E SICUREZZA +jaJP 警告ー健康と安全のために +jakana けいこくーけんこうと あんぜんの ために +koKR 경고—건강과 안전을 위하여 +nlNL WAARSCHUWING-GEZONDHEID EN VEILIGHEID +noNB ADVARSEL-HELSE OG SIKKERHET +plPL UWAGA-ZDROWIE I BEZPIECZEŃSTWO +ptBR ATENÇÃO-SAÚDE E SEGURANÇA +ptPT ATENÇÃO-SAÚDE E SEGURANÇA +roRO ATENȚIONARE-SĂNĂTATE ȘI SIGURANȚĂ +ruRU ПРЕДУПРЕЖДЕНИЕ-ЗДОРОВЬЕ И БЕЗОПАСНОСТЬ +svSE VARNING-HÄLSA OCH SÄKERHET +thTH คำเตือน-อนามัยและความปลอดภัย +trTR UYARI-SAĞLIK VE GÜVENLİK +zhCN 警告ー健康和安全 +zhTW 警告ー健康和安全 \ No newline at end of file diff --git a/res/graphics/fonts/ascii_majuscule.png b/res/graphics/fonts/ascii_majuscule.png index bb2adcc07..1476cf22c 100644 Binary files a/res/graphics/fonts/ascii_majuscule.png and b/res/graphics/fonts/ascii_majuscule.png differ diff --git a/res/graphics/fonts/cyrilic_majuscule.png b/res/graphics/fonts/cyrilic_majuscule.png index e284256b9..50a6da465 100644 Binary files a/res/graphics/fonts/cyrilic_majuscule.png and b/res/graphics/fonts/cyrilic_majuscule.png differ diff --git a/res/graphics/fonts/greek_ef.png b/res/graphics/fonts/greek_ef.png new file mode 100644 index 000000000..928d49059 Binary files /dev/null and b/res/graphics/fonts/greek_ef.png differ diff --git a/res/graphics/fonts/greek_majuscule.png b/res/graphics/fonts/greek_majuscule.png new file mode 100644 index 000000000..c9d54c1e4 Binary files /dev/null and b/res/graphics/fonts/greek_majuscule.png differ diff --git a/res/graphics/fonts/han_johab.png b/res/graphics/fonts/han_johab.png index 351d61d73..9793c376e 100644 Binary files a/res/graphics/fonts/han_johab.png and b/res/graphics/fonts/han_johab.png differ diff --git a/res/graphics/weathers/generic_light.png b/res/graphics/weathers/generic_light.png new file mode 100644 index 000000000..da689f918 Binary files /dev/null and b/res/graphics/weathers/generic_light.png differ diff --git a/res/graphics/weathers/generic_skybox.png b/res/graphics/weathers/generic_skybox.png new file mode 100644 index 000000000..15762dab4 Binary files /dev/null and b/res/graphics/weathers/generic_skybox.png differ diff --git a/res/locales/jakanaJP/game.json b/res/locales/jakanaJP/game.json index 9dc0922b0..c8e097621 100644 --- a/res/locales/jakanaJP/game.json +++ b/res/locales/jakanaJP/game.json @@ -4,6 +4,6 @@ "COPYRIGHT_ALL_RIGHTS_RESERVED": "ぜんちょさくけん しょゆう。", "APP_ADJUST_YOUR_MONITOR": "このゲームは、てきせつにちょうせいした モニターから さいこうのプレイができます。ちょうせいして いなかったら、プレイするまえに ちょうせいしてください。", - "APP_WARNING_HEALTH_AND_SAFETY": "けいこくーけんこうと あんぜんを ために" + "APP_WARNING_HEALTH_AND_SAFETY": "けいこくーけんこうと あんぜんの ために" } \ No newline at end of file diff --git a/res/raw/Creature_raw_doc.md b/res/raw/Creature_raw_doc.md new file mode 100644 index 000000000..3412e1aa5 --- /dev/null +++ b/res/raw/Creature_raw_doc.md @@ -0,0 +1,46 @@ +Creature raw documentation + +## Physical properties ## + +* 1 m = 24 px +* mult: Multiplier. e.g. 1.0, 0.85, 1.25, ... + +|name|unit|description| +|----|----|-----------| +|baseheight|pixels|Base height for hitbox. Also used for attack point bonus calculation| +|basemass|kg|Base mass for creature| +|accel|px per TARGET_FPS^2|Acceleration for walking| +|speed|px per TARGET_FPS|Walk speed| +|jumppower|neg. px per TARGET_FPS^2|Self-explanatory| +|scale|unit|Creature body scale. Mass/strength/accel/etc. will be changed accordingly, hence the prefix “base” for some raw tokens| +|dragcoeff|unit|Drag coefficient| +|speedmult, accelmult, jumppowermult|array of percentiles (Int)|Variability factor| +|physiquemult|mult|Breadth variation for mobs| + +## Creature properties ## + +|name|unit|description| +|----|----|-----------| +|strength|unit|Strength value, no significant unit is given. The value for regular human is fixed to 1 000| +|encumbrance|kg or itemcount|Capacity of carrying| +|basedefence|unit|Base defence value of body. Sterner body composition (material) == higher value| +|armourdefence|unit|Current defence point of armour worn| +|armourdefencemult|mult|Bonus point for armour defence| +|toolsize|kg|Base tool size for the creature. See MECHANICS file for more information| + +## Aesthetic properties ## + +|name|unit|description| +|----|----|-----------| +|luminosity|30-bit RGB (Int)|Self-glow. Set to 0 for not glowing| +|name|String|Given (perhaps customised) name| +|racename|STRING_ID|Racename token in language CSV| +|racenameplural|STRING_ID|Racename token in language CSV| + +* Note: luminosity uses customised 30-bit RGB. The format specifies ```1.0``` luminosity of white (```#FFFFFF```) be ```0000_0011111111_0011111111_0011111111```, and can hold luminosity range of 0.0-4.0 + +## Flags ## + +|name|unit|description| +|----|----|-----------| +|intelligent|Boolean|Whether the creature can speak and talk.| diff --git a/res/raw/Creature_raw_doc.txt b/res/raw/Creature_raw_doc.txt deleted file mode 100644 index 67a29c1ce..000000000 --- a/res/raw/Creature_raw_doc.txt +++ /dev/null @@ -1,27 +0,0 @@ -Creature raw documentation - -== string values == - -racename(plural) : Racename token in language CSV - -baseheight : base height for hitbox. [px] (24 px == 1 metre) -basemass : base mass for creature. [kg] - -== number values == - -strength : strength value, no significant unit is given. The value for regular human is fixed to 1 000. -accel : acceleration for walking. [px / TARGET_FPS^2] -speed : walk speed. [px / TARGET_FPS] -jumppower : self-explanatory. [-px / TARGET_FPS^2] -scale : creature body scale. Mass/strength/accel/etc. will be changed accordingly, hence the prefix “base” for some raw tokens. - --mass : variability factor. [array of percentiles] - -encumbrance : capacity of carrying. [kg] -basedefence : base defence value of body. Sterner body material == higher value - -toolsize : base tool size for the creature. See MECHANICS file for more information. - -== boolean values == - -intelligent : can speak and talk. diff --git a/res/raw/creatures/CreatureHuman.json b/res/raw/creatures/CreatureHuman.json index 85d309e35..e5ff88986 100644 --- a/res/raw/creatures/CreatureHuman.json +++ b/res/raw/creatures/CreatureHuman.json @@ -1,28 +1,28 @@ { - "racename" : "RACE_HUMAN", - "racenameplural" : "RACE_HUMAN_PLURAL", - "baseheight" : 40, - "basemass" : 60.0, + "racename": "RACE_HUMAN", + "racenameplural": "RACE_HUMAN_PLURAL", + "baseheight": 40, + "basemass": 60.0, - "strength" : 1000, - "strengthmult" : [100,100,100,100,100,100,100], + "strength": 1000, + "strengthmult": [100,100,100,100,100,100,100], - "accel" : 0.32, + "accel": 0.32, - "speed" : 3.0, - "speedmult" : [100,100,100,100,100,100,100], + "speed": 3.0, + "speedmult": [100,100,100,100,100,100,100], - "jumppower" : 4.3, - "jumppowermult" : [100,100,100,100,100,100,100], + "jumppower": 4.3, + "jumppowermult": [100,100,100,100,100,100,100], - "scale" : 1.0, - "scalemult" : [100,100,100,100,100,100,100], + "scale": 1.0, + "physiquemult": [100,100,100,100,100,100,100], - "encumbrance" : 1000, - "basedefence" : 100, + "encumbrance": 1000, + "basedefence": 100, - "toolsize" : 15, + "toolsize": 15, - "intelligent" : true + "intelligent": true } \ No newline at end of file diff --git a/res/raw/weathers/WeatherGeneric.json b/res/raw/weathers/WeatherGeneric.json new file mode 100644 index 000000000..ab55c383d --- /dev/null +++ b/res/raw/weathers/WeatherGeneric.json @@ -0,0 +1,8 @@ +{ + "globalLight": "generic_light.png", + "skyboxGradColourMap": "generic_skybox.png", + "classification": "generic", + "extraImages": [ + + ] +} \ No newline at end of file diff --git a/res/sounds/ambient/klankbeeld-freesound/.gitattributes b/res/sounds/ambient/.gitattributes similarity index 100% rename from res/sounds/ambient/klankbeeld-freesound/.gitattributes rename to res/sounds/ambient/.gitattributes diff --git a/res/sounds/ambient/klankbeeld-freesound/ambient_forest_01.ogg b/res/sounds/ambient/ambient_forest_01.ogg similarity index 100% rename from res/sounds/ambient/klankbeeld-freesound/ambient_forest_01.ogg rename to res/sounds/ambient/ambient_forest_01.ogg diff --git a/res/sounds/ambient/klankbeeld-freesound/ambient_meadow_01.ogg b/res/sounds/ambient/ambient_meadow_01.ogg similarity index 100% rename from res/sounds/ambient/klankbeeld-freesound/ambient_meadow_01.ogg rename to res/sounds/ambient/ambient_meadow_01.ogg diff --git a/res/sounds/ambient/klankbeeld-freesound/ambient_windy_01.ogg b/res/sounds/ambient/ambient_windy_01.ogg similarity index 100% rename from res/sounds/ambient/klankbeeld-freesound/ambient_windy_01.ogg rename to res/sounds/ambient/ambient_windy_01.ogg diff --git a/res/sounds/ambient/klankbeeld-freesound/ambient_woods_01.ogg b/res/sounds/ambient/ambient_woods_01.ogg similarity index 100% rename from res/sounds/ambient/klankbeeld-freesound/ambient_woods_01.ogg rename to res/sounds/ambient/ambient_woods_01.ogg diff --git a/res/sounds/ambient/klankbeeld-freesound/crickets_01.ogg b/res/sounds/ambient/crickets_01.ogg similarity index 100% rename from res/sounds/ambient/klankbeeld-freesound/crickets_01.ogg rename to res/sounds/ambient/crickets_01.ogg diff --git a/res/sounds/ambient/klankbeeld-freesound/crickets_02.ogg b/res/sounds/ambient/crickets_02.ogg similarity index 100% rename from res/sounds/ambient/klankbeeld-freesound/crickets_02.ogg rename to res/sounds/ambient/crickets_02.ogg diff --git a/src/net/torvald/gadgets/HistoryArray.kt b/src/net/torvald/gadgets/HistoryArray.kt new file mode 100644 index 000000000..433d2bb3f --- /dev/null +++ b/src/net/torvald/gadgets/HistoryArray.kt @@ -0,0 +1,57 @@ +package net.torvald.gadgets + +import java.util.* +import java.util.function.Consumer + +/** + * Simple ArrayList wrapper that acts as history keeper. You can append any data but cannot delete. + * Created by minjaesong on 16-07-13. + */ +class HistoryArray(val historyMax: Int) { + + val history = ArrayList(Math.min(historyMax, 256)) // 256: arbitrary-set upper bound + + fun add(value: T) { + if (history.size == 0) { + history.add(value) + return + } + // push existing values to back 1 index + else { + for (i in history.size - 1 downTo 0) { + // if history.size is smaller than historyMax, make room by appending + if (i == history.size - 1 && i < historyMax - 1) + history.add(history[i]) + // actually move if we have some room + else if (i < historyMax - 1) + history[i + 1] = history[i] + } + } + // add new value to the room + history[0] = value + } + + /** + * Get certain index from history. NOTE: index 0 means latest! + */ + operator fun get(index: Int): T? = + if (index >= history.size) null + else history[index] + + /** + * Iterate from latest to oldest + */ + fun iterator() = history.iterator() + + /** + * Iterate from latest to oldest + */ + fun forEach(action: Consumer) = history.forEach(action) + + val latest: T? + get() = this[0] + + val oldest: T? + get() = this[history.size - 1] + +} \ No newline at end of file diff --git a/src/net/torvald/imagefont/GameFontBase.kt b/src/net/torvald/imagefont/GameFontBase.kt index 4dee7436f..39891bd1c 100644 --- a/src/net/torvald/imagefont/GameFontBase.kt +++ b/src/net/torvald/imagefont/GameFontBase.kt @@ -55,34 +55,22 @@ constructor() : Font { } private fun isAsciiEF(c: Char) = asciiEFList.contains(c) - private fun isExtAEF(c: Char) = extAEFList.contains(c) - private fun isHangul(c: Char) = c.toInt() >= 0xAC00 && c.toInt() < 0xD7A4 - private fun isAscii(c: Char) = c.toInt() > 0x20 && c.toInt() <= 0xFF - private fun isRunic(c: Char) = runicList.contains(c) - private fun isExtA(c: Char) = c.toInt() >= 0x100 && c.toInt() < 0x180 - private fun isKana(c: Char) = c.toInt() >= 0x3040 && c.toInt() < 0x3100 - private fun isCJKPunct(c: Char) = c.toInt() >= 0x3000 && c.toInt() < 0x3040 - private fun isUniHan(c: Char) = c.toInt() >= 0x3400 && c.toInt() < 0xA000 - private fun isCyrilic(c: Char) = c.toInt() >= 0x400 && c.toInt() < 0x460 - private fun isCyrilicEF(c: Char) = cyrilecEFList.contains(c) - private fun isFullwidthUni(c: Char) = c.toInt() >= 0xFF00 && c.toInt() < 0xFF20 - private fun isUniPunct(c: Char) = c.toInt() >= 0x2000 && c.toInt() < 0x2070 - private fun isWenQuanYi1(c: Char) = c.toInt() >= 0x33F3 && c.toInt() <= 0x69FC - private fun isWenQuanYi2(c: Char) = c.toInt() >= 0x69FD && c.toInt() <= 0x9FDC + private fun isGreek(c: Char) = c.toInt() >= 0x370 && c.toInt() <= 0x3CE + private fun isGreekEF(c: Char) = greekEFList.contains(c) @@ -121,37 +109,65 @@ constructor() : Font { private fun wenQuanYi1IndexY(c: Char) = (c.toInt() - (0x33F3 + 0x4A)) / 32 private fun wenQuanYi2IndexY(c: Char) = (c.toInt() - 0x69FD) / 32 - override fun getWidth(s: String) = getWidthSubstr(s, s.length) + private fun greekIndexX(c: Char) = (c.toInt() - 0x370) % 16 + private fun greekIndexY(c: Char) = (c.toInt() - 0x370) / 16 + private fun greekEFIndexX(c: Char) = greekEFList.indexOf(c) % 16 + private fun greekEFIndexY(c: Char) = greekEFList.indexOf(c) / 16 + + + private val narrowWidthSheets = arrayOf( + SHEET_ASCII_EF, + SHEET_EXTA_EF, + SHEET_CYRILIC_EF, + SHEET_GREEK_EF + ) + private val unihanWidthSheets = arrayOf( + SHEET_UNIHAN, + SHEET_FW_UNI, + SHEET_WENQUANYI_1, + SHEET_WENQUANYI_2 + ) + private val zeroWidthSheets = arrayOf( + SHEET_COLOURCODE + ) + private val cjkWidthSheets = arrayOf( + SHEET_KANA, + SHEET_HANGUL, + SHEET_CJK_PUNCT + ) + + + override fun getWidth(s: String) = getWidthSubstr(s, s.length) private fun getWidthSubstr(s: String, endIndex: Int): Int { var len = 0 for (i in 0..endIndex - 1) { - val c = getSheetType(s[i]) + val ctype = getSheetType(s[i]) if (i > 0 && s[i].toInt() > 0x20) { - // Kerning + // Unihan-hangul Kerning val cpre = getSheetType(s[i - 1]) - if ((cpre == SHEET_UNIHAN || cpre == SHEET_HANGUL) && !(c == SHEET_UNIHAN || c == SHEET_HANGUL) + if ((unihanWidthSheets.contains(cpre) || cpre == SHEET_HANGUL) && !(unihanWidthSheets.contains(ctype) || ctype == SHEET_HANGUL) - || (c == SHEET_UNIHAN || c == SHEET_HANGUL) && !(cpre == SHEET_UNIHAN || cpre == SHEET_HANGUL)) { + || (unihanWidthSheets.contains(ctype) || ctype == SHEET_HANGUL) && !(unihanWidthSheets.contains(cpre) || cpre == SHEET_HANGUL)) { // margin after/before hangul/unihan len += 2 } - else if ((c == SHEET_HANGUL || c == SHEET_KANA) && (cpre == SHEET_HANGUL || cpre == SHEET_KANA)) { + else if ((ctype == SHEET_HANGUL || ctype == SHEET_KANA) && (cpre == SHEET_HANGUL || cpre == SHEET_KANA)) { // margin between hangul/kana len += 1 } } - if (c == SHEET_COLOURCODE) + if (zeroWidthSheets.contains(ctype)) len += 0 - else if (c == SHEET_ASCII_EF || c == SHEET_EXTA_EF || c == SHEET_CYRILIC_EF) + else if (narrowWidthSheets.contains(ctype)) len += W_LATIN_NARROW - else if (c == SHEET_KANA || c == SHEET_HANGUL || c == SHEET_CJK_PUNCT) + else if (cjkWidthSheets.contains(ctype)) len += W_CJK - else if (c == SHEET_UNIHAN || c == SHEET_FW_UNI || c == SHEET_WENQUANYI_1 || c == SHEET_WENQUANYI_2) + else if (unihanWidthSheets.contains(ctype)) len += W_UNIHAN else len += W_LATIN_WIDE @@ -375,6 +391,14 @@ constructor() : Font { sheetX = uniPunctIndexX(ch) sheetY = uniPunctIndexY(ch) } + SHEET_GREEK_EM -> { + sheetX = greekIndexX(ch) + sheetY = greekIndexY(ch) + } + SHEET_GREEK_EF -> { + sheetX = greekEFIndexX(ch) + sheetY = greekEFIndexY(ch) + } else -> { sheetX = ch.toInt() % 16 sheetY = ch.toInt() / 16 @@ -406,6 +430,10 @@ constructor() : Font { catch (e: ArrayIndexOutOfBoundsException) { // character that does not exist in the sheet. No render, pass. } + catch (e1: RuntimeException) { + // System.err.println("[GameFontBase] RuntimeException raised while processing character '$ch' (U+${Integer.toHexString(ch.toInt()).toUpperCase()})") + // e1.printStackTrack() + } } } @@ -424,6 +452,8 @@ constructor() : Font { return SHEET_EXTA_EF else if (isCyrilicEF(c)) return SHEET_CYRILIC_EF + else if (isGreekEF(c)) + return SHEET_GREEK_EF else if (isRunic(c)) return SHEET_RUNIC else if (isHangul(c)) @@ -444,6 +474,8 @@ constructor() : Font { return SHEET_CJK_PUNCT else if (isFullwidthUni(c)) return SHEET_FW_UNI + else if (isGreek(c)) + return SHEET_GREEK_EM else if (c.isColourCode()) return SHEET_COLOURCODE else @@ -516,6 +548,8 @@ constructor() : Font { lateinit internal var uniPunct: SpriteSheet lateinit internal var wenQuanYi_1: SpriteSheet lateinit internal var wenQuanYi_2: SpriteSheet + lateinit internal var greekSheet: SpriteSheet + lateinit internal var greekSheetEF: SpriteSheet internal val JUNG_COUNT = 21 internal val JONG_COUNT = 28 @@ -544,12 +578,12 @@ constructor() : Font { internal val SHEET_UNI_PUNCT = 12 internal val SHEET_WENQUANYI_1 = 13 internal val SHEET_WENQUANYI_2 = 14 - + internal val SHEET_GREEK_EM = 15 + internal val SHEET_GREEK_EF = 16 internal val SHEET_COLOURCODE = 255 lateinit internal var sheetKey: Array internal val asciiEFList = arrayOf(' ', '!', '"', '\'', '(', ')', ',', '.', ':', ';', 'I', '[', ']', '`', 'f', 'i', 'j', 'l', 't', '{', '|', '}', 0xA1.toChar(), 'Ì', 'Í', 'Î', 'Ï', 'ì', 'í', 'î', 'ï', '·') - internal val extAEFList = arrayOf( 0x12E.toChar(), 0x12F.toChar(), @@ -563,7 +597,6 @@ constructor() : Font { 0x167.toChar(), 0x17F.toChar() ) - internal val cyrilecEFList = arrayOf( 0x406.toChar(), 0x407.toChar(), @@ -571,6 +604,14 @@ constructor() : Font { 0x457.toChar(), 0x458.toChar() ) + internal val greekEFList = arrayOf( + 0x390.toChar(), + 0x399.toChar(), + 0x3AA.toChar(), + 0x3AF.toChar(), + 0x3B9.toChar(), + 0x3CA.toChar() + ) /** * Runic letters list used for game. The set is diff --git a/src/net/torvald/imagefont/GameFontWhite.kt b/src/net/torvald/imagefont/GameFontWhite.kt index 0edee3336..622f3494c 100644 --- a/src/net/torvald/imagefont/GameFontWhite.kt +++ b/src/net/torvald/imagefont/GameFontWhite.kt @@ -46,6 +46,10 @@ constructor() : GameFontBase() { "./res/graphics/fonts/wenquanyi_11pt_part1.png", 16, 18, 2) GameFontBase.wenQuanYi_2 = SpriteSheet( "./res/graphics/fonts/wenquanyi_11pt_part2.png", 16, 18, 2) + GameFontBase.greekSheet = SpriteSheet( + "./res/graphics/fonts/greek_majuscule.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H) + GameFontBase.greekSheetEF = SpriteSheet( + "./res/graphics/fonts/greek_ef.png", GameFontBase.W_LATIN_NARROW, GameFontBase.H) val shk = arrayOf( GameFontBase.asciiSheet, @@ -62,7 +66,10 @@ constructor() : GameFontBase() { GameFontBase.fullwidthForms, GameFontBase.uniPunct, GameFontBase.wenQuanYi_1, - GameFontBase.wenQuanYi_2)//, uniHan + GameFontBase.wenQuanYi_2, // uniHan + GameFontBase.greekSheet, + GameFontBase.greekSheetEF + ) GameFontBase.sheetKey = shk } diff --git a/src/net/torvald/serialise/WriteGameMapData.kt b/src/net/torvald/serialise/WriteGameMapData.kt index de29491c3..b8fa0fcee 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.GameMap +import net.torvald.terrarum.gamemap.GameWorld import net.torvald.terrarum.Terrarum import java.io.IOException import java.nio.file.Files @@ -29,14 +29,14 @@ object WriteGameMapData { val path = Paths.get("${Terrarum.defaultSaveDir}" + "/$saveDirectoryName/${WriteMeta.META_FILENAME}") val tempPath = Files.createTempFile(path.toString(), "_temp") - val map = Terrarum.ingame.map + val map = Terrarum.ingame.world // TODO gzip // write binary Files.write(tempPath, MAGIC) - Files.write(tempPath, byteArrayOf(GameMap.BITS)) - Files.write(tempPath, byteArrayOf(GameMap.LAYERS)) + Files.write(tempPath, byteArrayOf(GameWorld.BITS)) + Files.write(tempPath, byteArrayOf(GameWorld.LAYERS)) Files.write(tempPath, byteArrayOf(BYTE_NULL)) Files.write(tempPath, byteArrayOf(BYTE_NULL)) Files.write(tempPath, toByteArray(map.width)) diff --git a/src/net/torvald/terrarum/COPYING.md b/src/net/torvald/terrarum/COPYING.md index 8fdb43032..f5bcebe7b 100644 --- a/src/net/torvald/terrarum/COPYING.md +++ b/src/net/torvald/terrarum/COPYING.md @@ -58,9 +58,14 @@ All rights reserved. --- -Amazing ambient sound recordings in ```sound/ambient/klankbeeld-freesound``` +Amazing ambient sound recordings: -Samples used: 173111, 183181, 185290, 195287, 240108, 326914, 337691, 347753 + ambient_forest_01.ogg + ambient_meadow_01.ogg + ambient_windy_01.ogg + ambient_woods_01.ogg + crickets_01.ogg + crickets_02.ogg Copyright (C) 2012, 2013, 2015, 2016 Klankbeeld Sound from http://www.freesound.org/people/klankbeeld/ \ No newline at end of file diff --git a/src/net/torvald/terrarum/DefaultConfig.kt b/src/net/torvald/terrarum/DefaultConfig.kt index c73fa35aa..d8acdf035 100644 --- a/src/net/torvald/terrarum/DefaultConfig.kt +++ b/src/net/torvald/terrarum/DefaultConfig.kt @@ -1,6 +1,9 @@ package net.torvald.terrarum +import com.google.gson.JsonArray +import com.google.gson.JsonElement import com.google.gson.JsonObject +import net.torvald.terrarum.gamecontroller.Key /** * Created by minjaesong on 16-03-12. @@ -15,6 +18,53 @@ object DefaultConfig { jsonObject.addProperty("notificationshowuptime", 6500) jsonObject.addProperty("multithread", true) // experimental! + // control-gamepad + jsonObject.addProperty("joypadkeyn", 4) + jsonObject.addProperty("joypadkeyw", 1) + jsonObject.addProperty("joypadkeys", 2) + jsonObject.addProperty("joypadkeye", 3) // logitech indices + + jsonObject.addProperty("joypadlup", 4) + jsonObject.addProperty("joypadrup", 5) + jsonObject.addProperty("joypadldown", 6) + jsonObject.addProperty("joypadrdown", 7) // logitech indices + + jsonObject.addProperty("joypadlstickx", 0) + jsonObject.addProperty("joypadlsticky", 1) + jsonObject.addProperty("joypadrstickx", 2) + jsonObject.addProperty("joypadrsticky", 3) // logitech indices + + // control-keyboard (Java key index. This is what Minecraft also uses) + jsonObject.addProperty("keyup", Key.E) + jsonObject.addProperty("keyleft", Key.S) + jsonObject.addProperty("keydown", Key.D) + jsonObject.addProperty("keyright", Key.F) + + jsonObject.addProperty("keymovementaux", Key.A) // movement-auxiliary, or hookshot + jsonObject.addProperty("keyinventory", Key.W) + jsonObject.addProperty("keyinteract", Key.R) + jsonObject.addProperty("keyclose", Key.C) + + jsonObject.addProperty("keygamemenu", Key.TAB) + jsonObject.addProperty("keyquicksel", Key.CAPS_LOCK) // pie menu + val keyquickselalt = JsonArray(); keyquickselalt.add(Key.BACKSPACE); keyquickselalt.add(Key.L_COMMAND); keyquickselalt.add(Key.L_CONTROL) + // some pro typers assign CapsLock to Backspace, LControl, or LCommand (Mac). Honestly, Control (Command for mac) and CapsLock must swap their places! + jsonObject.add("keyquickselalt", keyquickselalt) + + jsonObject.addProperty("keyjump", Key.SPACE) + + val keyquickbars = JsonArray(); for (i in 2..11) keyquickbars.add(i) // NUM_1 to NUM_0 + jsonObject.add("keyquickbars", keyquickbars) + + + + return jsonObject } -} \ No newline at end of file +} + +/* + +Additional description goes here + + */ \ No newline at end of file diff --git a/src/net/torvald/terrarum/StateInGame.kt b/src/net/torvald/terrarum/StateInGame.kt index bd58f3f12..6e29fdf64 100644 --- a/src/net/torvald/terrarum/StateInGame.kt +++ b/src/net/torvald/terrarum/StateInGame.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum import net.torvald.imagefont.GameFontBase +import net.torvald.terrarum.audio.AudioResourceLibrary import net.torvald.terrarum.concurrent.ThreadPool import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.console.Authenticator @@ -9,7 +10,7 @@ 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.GameMap +import net.torvald.terrarum.gamemap.GameWorld import net.torvald.terrarum.gamemap.WorldTime import net.torvald.terrarum.mapdrawer.LightmapRenderer import net.torvald.terrarum.mapdrawer.MapCamera @@ -22,6 +23,7 @@ import net.torvald.terrarum.ui.BasicDebugInfoWindow import net.torvald.terrarum.ui.ConsoleWindow import net.torvald.terrarum.ui.Notification import net.torvald.terrarum.ui.UIHandler +import net.torvald.terrarum.weather.WeatherMixer import org.lwjgl.opengl.GL11 import org.newdawn.slick.* import org.newdawn.slick.fills.GradientFill @@ -41,7 +43,7 @@ constructor() : BasicGameState() { internal var game_mode = 0 - lateinit var map: GameMap + lateinit var world: GameWorld /** * list of Actors that is sorted by Actors' referenceID @@ -57,8 +59,8 @@ constructor() : BasicGameState() { lateinit internal var player: Player - private var GRADIENT_IMAGE: Image? = null - private var skyBox: Rectangle? = null + //private var GRADIENT_IMAGE: Image? = null + //private var skyBox: Rectangle? = null var screenZoom = 1.0f val ZOOM_MAX = 2.0f @@ -92,15 +94,11 @@ constructor() : BasicGameState() { shaderBlurH = Shader.makeShader("./res/blurH.vrt", "./res/blur.frg") shaderBlurV = Shader.makeShader("./res/blurV.vrt", "./res/blur.frg") - // init skybox - GRADIENT_IMAGE = Image("res/graphics/colourmap/sky_colour.png") - skyBox = Rectangle(0f, 0f, Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat()) - // init map as chosen size - map = GameMap(8192, 2048) + world = GameWorld(8192, 2048) // generate terrain for the map - MapGenerator.attachMap(map) + MapGenerator.attachMap(world) MapGenerator.SEED = 0x51621D2 //mapgenerator.setSeed(new HQRNG().nextLong()); MapGenerator.generateMap() @@ -132,6 +130,11 @@ constructor() : BasicGameState() { // set smooth lighting as in config KeyToggler.forceSet(KEY_LIGHTMAP_SMOOTH, Terrarum.getConfigBoolean("smoothlighting")) + + + + // audio test + //AudioResourceLibrary.ambientsWoods[0].play() } override fun update(gc: GameContainer, sbg: StateBasedGame, delta: Int) { @@ -139,8 +142,11 @@ constructor() : BasicGameState() { setAppTitle() - map.updateWorldTime(delta) - map.globalLight = globalLightByTime + world.updateWorldTime(delta) + + WeatherMixer.update(gc, delta) + + world.globalLight = globalLightByTime.toInt() GameController.processInput(gc.input) @@ -258,30 +264,6 @@ constructor() : BasicGameState() { } } - private fun getGradientColour(row: Int, phase: Int) = GRADIENT_IMAGE!!.getColor(phase, row) - - private fun getGradientColour(row: Int): Color { - val gradMapWidth = GRADIENT_IMAGE!!.width - val phase = Math.round( - map.worldTime.elapsedSeconds().toFloat() / WorldTime.DAY_LENGTH.toFloat() * gradMapWidth - ) - - //update in every INTERNAL_FRAME frames - return getGradientColour(row, phase) - } - - /** - * @param time in seconds - */ - private fun getGradientColourByTime(row: Int, time: Int): Color { - val gradMapWidth = GRADIENT_IMAGE!!.width - val phase = Math.round( - time.toFloat() / WorldTime.DAY_LENGTH.toFloat() * gradMapWidth - ) - - return getGradientColour(row, phase) - } - override fun keyPressed(key: Int, c: Char) { GameController.keyPressed(key, c) } @@ -320,13 +302,7 @@ constructor() : BasicGameState() { override fun getID(): Int = Terrarum.SCENE_ID_GAME - private fun drawSkybox(g: Graphics) { - val skyColourFill = GradientFill( - 0f, 0f, getGradientColour(0), - 0f, Terrarum.HEIGHT.toFloat(), getGradientColour(1) - ) - g.fill(skyBox, skyColourFill) - } + private fun drawSkybox(g: Graphics) = WeatherMixer.render(g) /** Send message to notifier UI and toggle the UI as opened. */ fun sendNotification(msg: Array) { @@ -399,15 +375,7 @@ constructor() : BasicGameState() { } } - private val globalLightByTime: Int - get() = getGradientColour(2).getRGB24().rgb24ExpandToRgb30() - fun globalLightByTime(t: Int): Int = getGradientColourByTime(2, t).getRGB24().rgb24ExpandToRgb30() - - fun Color.getRGB24(): Int = this.redByte.shl(16) or this.greenByte.shl(8) or this.blueByte - /** Remap 8-bit value (0.0-1.0) to 10-bit value (0.0-4.0) by prepending two bits of zero for each R, G and B. */ - fun Int.rgb24ExpandToRgb30(): Int = (this and 0xff) or - (this and 0xff00).ushr(8).shl(10) or - (this and 0xff0000).ushr(16).shl(20) + private val globalLightByTime = WeatherMixer.globalLightNow fun Double.sqr() = this * this fun Int.sqr() = this * this diff --git a/src/net/torvald/terrarum/audio/AudioMixer.kt b/src/net/torvald/terrarum/audio/AudioMixer.kt new file mode 100644 index 000000000..7eeef68e2 --- /dev/null +++ b/src/net/torvald/terrarum/audio/AudioMixer.kt @@ -0,0 +1,48 @@ +package net.torvald.terrarum.audio + +import org.lwjgl.openal.AL10 +import org.newdawn.slick.openal.Audio +import org.newdawn.slick.openal.AudioImpl +import org.newdawn.slick.openal.MODSound +import java.util.* + +/** + * Created by minjaesong on 16-07-08. + */ +object AudioMixer { + const val TRACK_COUNT = 32 + + const val TRACK_AMBIENT_ONE = 0 + const val TRACK_AMBIENT_ONE_NEXT = 1 + const val TRACK_AMBIENT_TWO = 2 + const val TRACK_AMBIENT_TWO_NEXT = 3 + + const val TRACK_UI_ONE = 8 + const val TRACK_UI_TWO = 9 + + const val TRACK_SFX_START = 16 + const val TRACK_SFX_END = 31 + + val tracks = ArrayList(TRACK_COUNT) + + init { + + } + + fun getAudio(track: Int) = tracks[track] + + /** + * Queue an SFX to any empty SFX track and play it. + */ + fun queueSfx(audio: Audio) { + + } + + fun update() { + + } + + class MixerTrack(val audio: Audio, var volume: Float, var pan: Float) { + + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/audio/AudioResourceLibrary.kt b/src/net/torvald/terrarum/audio/AudioResourceLibrary.kt new file mode 100644 index 000000000..566be4a3b --- /dev/null +++ b/src/net/torvald/terrarum/audio/AudioResourceLibrary.kt @@ -0,0 +1,31 @@ +package net.torvald.terrarum.audio + +import org.newdawn.slick.openal.Audio +import org.newdawn.slick.openal.AudioLoader +import java.io.FileInputStream +import java.util.* + +/** + * Created by minjaesong on 16-07-08. + */ +object AudioResourceLibrary { + + val ambientsForest = ArrayList