mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 19:14:05 +09:00
grass tex revert to smooth
This commit is contained in:
Binary file not shown.
BIN
assets/mods/basegame/blocks/33 - Copy.tga
LFS
Normal file
BIN
assets/mods/basegame/blocks/33 - Copy.tga
LFS
Normal file
Binary file not shown.
Binary file not shown.
@@ -29,6 +29,7 @@ import net.torvald.terrarum.gameworld.GameWorld;
|
|||||||
import net.torvald.terrarum.imagefont.TinyAlphNum;
|
import net.torvald.terrarum.imagefont.TinyAlphNum;
|
||||||
import net.torvald.terrarum.modulebasegame.IngameRenderer;
|
import net.torvald.terrarum.modulebasegame.IngameRenderer;
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame;
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame;
|
||||||
|
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory;
|
||||||
import net.torvald.terrarum.utils.JsonFetcher;
|
import net.torvald.terrarum.utils.JsonFetcher;
|
||||||
import net.torvald.terrarum.utils.JsonWriter;
|
import net.torvald.terrarum.utils.JsonWriter;
|
||||||
import net.torvald.terrarumsansbitmap.gdx.GameFontBase;
|
import net.torvald.terrarumsansbitmap.gdx.GameFontBase;
|
||||||
@@ -254,7 +255,7 @@ public class AppLoader implements ApplicationListener {
|
|||||||
|
|
||||||
private void initViewPort(int width, int height) {
|
private void initViewPort(int width, int height) {
|
||||||
// Set Y to point downwards
|
// Set Y to point downwards
|
||||||
camera.setToOrtho(true, width, height);
|
camera.setToOrtho(true, width, height); // some elements are pre-flipped, while some are not. The statement itself is absolutely necessary to make edge of the screen as the origin
|
||||||
|
|
||||||
// Update camera matrix
|
// Update camera matrix
|
||||||
camera.update();
|
camera.update();
|
||||||
@@ -648,6 +649,7 @@ public class AppLoader implements ApplicationListener {
|
|||||||
|
|
||||||
fontGame.dispose();
|
fontGame.dispose();
|
||||||
fontSmallNumbers.dispose();
|
fontSmallNumbers.dispose();
|
||||||
|
ItemSlotImageFactory.INSTANCE.dispose();
|
||||||
|
|
||||||
textureWhiteSquare.dispose();
|
textureWhiteSquare.dispose();
|
||||||
textureWhiteCircle.dispose();
|
textureWhiteCircle.dispose();
|
||||||
@@ -734,7 +736,7 @@ public class AppLoader implements ApplicationListener {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ModMgr.INSTANCE.invoke(); // invoke Module Manager
|
ModMgr.INSTANCE.invoke(); // invoke Module Manager
|
||||||
AppLoader.resourcePool.loadAll();
|
CommonResourcePool.INSTANCE.loadAll();
|
||||||
printdbg(this, "all modules loaded successfully");
|
printdbg(this, "all modules loaded successfully");
|
||||||
IngameRenderer.initialise();
|
IngameRenderer.initialise();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Texture
|
|||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import com.badlogic.gdx.utils.Disposable
|
import com.badlogic.gdx.utils.Disposable
|
||||||
import com.badlogic.gdx.utils.Queue
|
import com.badlogic.gdx.utils.Queue
|
||||||
|
import net.torvald.UnsafePtr
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -11,8 +12,9 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
|||||||
*/
|
*/
|
||||||
object CommonResourcePool {
|
object CommonResourcePool {
|
||||||
|
|
||||||
private val loadingList = Queue<Pair<String, () -> Any>>()
|
private val loadingList = Queue<ResourceLoadingDescriptor>()
|
||||||
private val pool = HashMap<String, Any>()
|
private val pool = HashMap<String, Any>()
|
||||||
|
private val poolKillFun = HashMap<String, (() -> Unit)?>()
|
||||||
//private val typesMap = HashMap<String, Class<*>>()
|
//private val typesMap = HashMap<String, Class<*>>()
|
||||||
private var loadCounter = -1 // using counters so that the loading can be done on separate thread (gg if the asset requires GL context to be loaded)
|
private var loadCounter = -1 // using counters so that the loading can be done on separate thread (gg if the asset requires GL context to be loaded)
|
||||||
val loaded: Boolean
|
val loaded: Boolean
|
||||||
@@ -46,8 +48,26 @@ object CommonResourcePool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Following objects doesn't need destroy function:
|
||||||
|
* - com.badlogic.gdx.utils.Disposable
|
||||||
|
* - com.badlogic.gdx.graphics.Texture
|
||||||
|
* - com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
|
* - net.torvald.UnsafePtr
|
||||||
|
*/
|
||||||
fun addToLoadingList(identifier: String, loadFunction: () -> Any) {
|
fun addToLoadingList(identifier: String, loadFunction: () -> Any) {
|
||||||
loadingList.addFirst(identifier to loadFunction)
|
CommonResourcePool.addToLoadingList(identifier, loadFunction, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Following objects doesn't need destroy function:
|
||||||
|
* - com.badlogic.gdx.utils.Disposable
|
||||||
|
* - com.badlogic.gdx.graphics.Texture
|
||||||
|
* - com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
|
* - net.torvald.UnsafePtr
|
||||||
|
*/
|
||||||
|
fun addToLoadingList(identifier: String, loadFunction: () -> Any, destroyFunction: (() -> Unit)?) {
|
||||||
|
loadingList.addFirst(ResourceLoadingDescriptor(identifier, loadFunction, destroyFunction))
|
||||||
|
|
||||||
if (loadCounter == -1)
|
if (loadCounter == -1)
|
||||||
loadCounter = 1
|
loadCounter = 1
|
||||||
@@ -56,13 +76,13 @@ object CommonResourcePool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* You are supposed to call this function only once.
|
* Consumes the loading list. After the load, the list will be empty
|
||||||
*/
|
*/
|
||||||
fun loadAll() {
|
fun loadAll() {
|
||||||
if (loaded) throw IllegalStateException("Assets are already loaded and shipped out :p")
|
if (loaded) throw IllegalStateException("Assets are already loaded and shipped out :p")
|
||||||
|
|
||||||
while (!loadingList.isEmpty) {
|
while (!loadingList.isEmpty) {
|
||||||
val (name, loadfun) = loadingList.removeFirst()
|
val (name, loadfun, killfun) = loadingList.removeFirst()
|
||||||
|
|
||||||
if (pool.containsKey(name)) {
|
if (pool.containsKey(name)) {
|
||||||
throw IllegalArgumentException("Assets with identifier '$name' already exists.")
|
throw IllegalArgumentException("Assets with identifier '$name' already exists.")
|
||||||
@@ -70,6 +90,7 @@ object CommonResourcePool {
|
|||||||
|
|
||||||
//typesMap[name] = type
|
//typesMap[name] = type
|
||||||
pool[name] = loadfun.invoke()
|
pool[name] = loadfun.invoke()
|
||||||
|
poolKillFun[name] = killfun
|
||||||
|
|
||||||
loadCounter -= 1
|
loadCounter -= 1
|
||||||
}
|
}
|
||||||
@@ -85,19 +106,25 @@ object CommonResourcePool {
|
|||||||
fun getAsTexture(identifier: String) = getAs<Texture>(identifier)
|
fun getAsTexture(identifier: String) = getAs<Texture>(identifier)
|
||||||
|
|
||||||
fun dispose() {
|
fun dispose() {
|
||||||
pool.forEach { _, u ->
|
pool.forEach { name, u ->
|
||||||
try {
|
try {
|
||||||
if (u is Disposable)
|
when {
|
||||||
u.dispose()
|
u is Disposable -> u.dispose()
|
||||||
else if (u is Texture)
|
u is Texture -> u.dispose()
|
||||||
u.dispose()
|
u is TextureRegion -> u.texture.dispose()
|
||||||
else if (u is TextureRegion)
|
u is UnsafePtr -> u.destroy()
|
||||||
u.texture.dispose()
|
else -> poolKillFun[name]?.invoke()
|
||||||
// TODO
|
}
|
||||||
}
|
}
|
||||||
catch (e: Throwable) {
|
catch (e: Throwable) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private data class ResourceLoadingDescriptor(
|
||||||
|
val name: String,
|
||||||
|
val loadfun: () -> Any,
|
||||||
|
val killfun: (() -> Unit)? = null
|
||||||
|
)
|
||||||
}
|
}
|
||||||
@@ -1430,7 +1430,7 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
|||||||
|
|
||||||
// debug display of hIntTilewiseHitbox
|
// debug display of hIntTilewiseHitbox
|
||||||
if (KeyToggler.isOn(Input.Keys.F9)) {
|
if (KeyToggler.isOn(Input.Keys.F9)) {
|
||||||
val blockMark = AppLoader.resourcePool.getAsTextureRegionPack("blockmarkings_common").get(0, 0)
|
val blockMark = CommonResourcePool.getAsTextureRegionPack("blockmarkings_common").get(0, 0)
|
||||||
|
|
||||||
batch.color = HITBOX_COLOURS0
|
batch.color = HITBOX_COLOURS0
|
||||||
for (y in 0..intTilewiseHitbox.height.toInt()) {
|
for (y in 0..intTilewiseHitbox.height.toInt()) {
|
||||||
|
|||||||
@@ -6,12 +6,19 @@ import net.torvald.UnsafePtr
|
|||||||
import net.torvald.terrarum.AppLoader.printdbg
|
import net.torvald.terrarum.AppLoader.printdbg
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Memory layout:
|
||||||
|
* ```
|
||||||
|
* a7 a6 a5 a4 a3 a2 a1 a0 | xx xx xx xx aB aA a9 a8 ||
|
||||||
|
* ```
|
||||||
|
* where a_n is a tile number
|
||||||
|
*
|
||||||
* Original version Created by minjaesong on 2016-01-17.
|
* Original version Created by minjaesong on 2016-01-17.
|
||||||
* Unsafe version Created by minjaesong on 2019-06-08.
|
* Unsafe version Created by minjaesong on 2019-06-08.
|
||||||
*
|
*
|
||||||
* Note to self: refrain from using shorts--just do away with two bytes: different system have different endianness
|
* Note to self: refrain from using shorts--just do away with two bytes: different system have different endianness
|
||||||
*/
|
*/
|
||||||
open class BlockLayer(val width: Int, val height: Int) : Disposable {
|
open class BlockLayer(val width: Int, val height: Int) : Disposable {
|
||||||
|
// for some reason, all the efforts of saving the memory space were futile.
|
||||||
|
|
||||||
// using unsafe pointer gets you 100 fps, whereas using directbytebuffer gets you 90
|
// using unsafe pointer gets you 100 fps, whereas using directbytebuffer gets you 90
|
||||||
internal val ptr: UnsafePtr = UnsafeHelper.allocate(width * height * BYTES_PER_BLOCK)
|
internal val ptr: UnsafePtr = UnsafeHelper.allocate(width * height * BYTES_PER_BLOCK)
|
||||||
@@ -21,18 +28,7 @@ open class BlockLayer(val width: Int, val height: Int) : Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param data Byte array representation of the layer, where:
|
* @param data Byte array representation of the layer
|
||||||
* - every 2n-th byte is lowermost 8 bits of the tile number
|
|
||||||
* - every (2n+1)th byte is uppermost 4 (4096 blocks) or 8 (65536 blocks) bits of the tile number.
|
|
||||||
*
|
|
||||||
* When 4096-block mode is being used, every (2n+1)th byte is filled in this format:
|
|
||||||
* ```
|
|
||||||
* (MSB) 0 0 0 0 a b c d (LSB)
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* In other words, the valid range for the every (2n+1)th byte is 0..15.
|
|
||||||
*
|
|
||||||
* TL;DR: LITTLE ENDIAN PLEASE
|
|
||||||
*/
|
*/
|
||||||
constructor(width: Int, height: Int, data: ByteArray) : this(width, height) {
|
constructor(width: Int, height: Int, data: ByteArray) : this(width, height) {
|
||||||
TODO()
|
TODO()
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package net.torvald.terrarum.itemproperties
|
|||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import net.torvald.terrarum.AppLoader
|
import net.torvald.terrarum.AppLoader
|
||||||
import net.torvald.terrarum.AppLoader.printdbg
|
import net.torvald.terrarum.AppLoader.printdbg
|
||||||
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.blockproperties.Fluid
|
import net.torvald.terrarum.blockproperties.Fluid
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
@@ -34,7 +35,7 @@ object ItemCodex {
|
|||||||
val ACTORID_MIN = ITEM_DYNAMIC.endInclusive + 1
|
val ACTORID_MIN = ITEM_DYNAMIC.endInclusive + 1
|
||||||
|
|
||||||
private val itemImagePlaceholder: TextureRegion
|
private val itemImagePlaceholder: TextureRegion
|
||||||
get() = AppLoader.resourcePool.getAsTextureRegion("itemplaceholder_24") // copper pickaxe
|
get() = CommonResourcePool.getAsTextureRegion("itemplaceholder_24") // copper pickaxe
|
||||||
|
|
||||||
|
|
||||||
// TODO: when generalised, there's no guarantee that blocks will be used as an item. Write customised item prop loader and init it on the Ingame
|
// TODO: when generalised, there's no guarantee that blocks will be used as an item. Write customised item prop loader and init it on the Ingame
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
val selection = ArrayList<Point2i>()
|
val selection = ArrayList<Point2i>()
|
||||||
|
|
||||||
val blockMarkings = AppLoader.resourcePool.getAsTextureRegionPack("blockmarkings_common")
|
val blockMarkings = CommonResourcePool.getAsTextureRegionPack("blockmarkings_common")
|
||||||
internal var showSelection = true
|
internal var showSelection = true
|
||||||
val blockPointingCursor = object : ActorWithBody(Actor.RenderOrder.OVERLAY) {
|
val blockPointingCursor = object : ActorWithBody(Actor.RenderOrder.OVERLAY) {
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package net.torvald.terrarum.modulebasegame
|
package net.torvald.terrarum.modulebasegame
|
||||||
|
|
||||||
import net.torvald.terrarum.AppLoader
|
|
||||||
import net.torvald.terrarum.AppLoader.IS_DEVELOPMENT_BUILD
|
import net.torvald.terrarum.AppLoader.IS_DEVELOPMENT_BUILD
|
||||||
import net.torvald.terrarum.AppLoader.printdbg
|
import net.torvald.terrarum.AppLoader.printdbg
|
||||||
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.ModMgr
|
import net.torvald.terrarum.ModMgr
|
||||||
import net.torvald.terrarum.ModuleEntryPoint
|
import net.torvald.terrarum.ModuleEntryPoint
|
||||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||||
@@ -33,13 +33,13 @@ class EntryPoint : ModuleEntryPoint() {
|
|||||||
|
|
||||||
|
|
||||||
// load common resources to the AssetsManager
|
// load common resources to the AssetsManager
|
||||||
AppLoader.resourcePool.addToLoadingList("$moduleName.items16") {
|
CommonResourcePool.addToLoadingList("$moduleName.items16") {
|
||||||
TextureRegionPack(ModMgr.getGdxFile(moduleName, "items/items.tga"), 16, 16)
|
TextureRegionPack(ModMgr.getGdxFile(moduleName, "items/items.tga"), 16, 16)
|
||||||
}
|
}
|
||||||
AppLoader.resourcePool.addToLoadingList("$moduleName.items24") {
|
CommonResourcePool.addToLoadingList("$moduleName.items24") {
|
||||||
TextureRegionPack(ModMgr.getGdxFile(moduleName, "items/items24.tga"), 24, 24)
|
TextureRegionPack(ModMgr.getGdxFile(moduleName, "items/items24.tga"), 24, 24)
|
||||||
}
|
}
|
||||||
AppLoader.resourcePool.addToLoadingList("$moduleName.items48") {
|
CommonResourcePool.addToLoadingList("$moduleName.items48") {
|
||||||
TextureRegionPack(ModMgr.getGdxFile(moduleName, "items/items48.tga"), 48, 48)
|
TextureRegionPack(ModMgr.getGdxFile(moduleName, "items/items48.tga"), 48, 48)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package net.torvald.terrarum.modulebasegame.gameactors
|
|||||||
import com.badlogic.gdx.graphics.Camera
|
import com.badlogic.gdx.graphics.Camera
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.AppLoader
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.Second
|
import net.torvald.terrarum.Second
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
@@ -21,7 +21,7 @@ internal class FixtureCraftingTable : FixtureBase(
|
|||||||
init {
|
init {
|
||||||
setHitboxDimension(16, 16, 0, 0)
|
setHitboxDimension(16, 16, 0, 0)
|
||||||
|
|
||||||
makeNewSprite(TextureRegionPack(AppLoader.resourcePool.getAsTextureRegion("itemplaceholder_16").texture, 16, 16))
|
makeNewSprite(TextureRegionPack(CommonResourcePool.getAsTextureRegion("itemplaceholder_16").texture, 16, 16))
|
||||||
sprite!!.setRowsAndFrames(1, 1)
|
sprite!!.setRowsAndFrames(1, 1)
|
||||||
|
|
||||||
actorValue[AVKey.BASEMASS] = MASS
|
actorValue[AVKey.BASEMASS] = MASS
|
||||||
@@ -49,7 +49,7 @@ internal object UICraftingTable : UICanvas() {
|
|||||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||||
|
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
batch.draw(AppLoader.resourcePool.getAsTextureRegion("test_texture"), 0f, 0f)
|
batch.draw(CommonResourcePool.getAsTextureRegion("test_texture"), 0f, 0f)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.gameitems
|
package net.torvald.terrarum.modulebasegame.gameitems
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import net.torvald.terrarum.AppLoader
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
import net.torvald.terrarum.gameitem.ItemID
|
import net.torvald.terrarum.gameitem.ItemID
|
||||||
@@ -23,7 +23,7 @@ class ItemCraftingTable(originalID: ItemID) : GameItem(originalID) {
|
|||||||
override val isDynamic = false
|
override val isDynamic = false
|
||||||
override val material = Material()
|
override val material = Material()
|
||||||
override val itemImage: TextureRegion?
|
override val itemImage: TextureRegion?
|
||||||
get() = AppLoader.resourcePool.getAsTextureRegion("itemplaceholder_16")
|
get() = CommonResourcePool.getAsTextureRegion("itemplaceholder_16")
|
||||||
override var baseToolSize: Double? = baseMass
|
override var baseToolSize: Double? = baseMass
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.gameitems
|
package net.torvald.terrarum.modulebasegame.gameitems
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import net.torvald.terrarum.AppLoader
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.Point2d
|
import net.torvald.terrarum.Point2d
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.blockproperties.Block
|
import net.torvald.terrarum.blockproperties.Block
|
||||||
@@ -14,7 +14,6 @@ import net.torvald.terrarum.itemproperties.MaterialCodex
|
|||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.BASE_MASS_AND_SIZE
|
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.BASE_MASS_AND_SIZE
|
||||||
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.TOOL_DURABILITY_BASE
|
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.TOOL_DURABILITY_BASE
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,7 +84,7 @@ class PickaxeCopper(originalID: ItemID) : GameItem(originalID) {
|
|||||||
override val material = MaterialCodex["CUPR"]
|
override val material = MaterialCodex["CUPR"]
|
||||||
override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE
|
override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE
|
||||||
override val itemImage: TextureRegion?
|
override val itemImage: TextureRegion?
|
||||||
get() = (AppLoader.resourcePool["basegame.items24"] as TextureRegionPack).get(0,0)
|
get() = CommonResourcePool.getAsTextureRegionPack("basegame.items24").get(0,0)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
|
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
|
||||||
@@ -112,7 +111,7 @@ class PickaxeIron(originalID: ItemID) : GameItem(originalID) {
|
|||||||
override val material = MaterialCodex["IRON"]
|
override val material = MaterialCodex["IRON"]
|
||||||
override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE
|
override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE
|
||||||
override val itemImage: TextureRegion?
|
override val itemImage: TextureRegion?
|
||||||
get() = (AppLoader.resourcePool["basegame.items24"] as TextureRegionPack).get(1,0)
|
get() = CommonResourcePool.getAsTextureRegionPack("basegame.items24").get(1,0)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
|
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
|
||||||
@@ -139,7 +138,7 @@ class PickaxeSteel(originalID: ItemID) : GameItem(originalID) {
|
|||||||
override val material = MaterialCodex["STAL"]
|
override val material = MaterialCodex["STAL"]
|
||||||
override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE
|
override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE
|
||||||
override val itemImage: TextureRegion?
|
override val itemImage: TextureRegion?
|
||||||
get() = (AppLoader.resourcePool["basegame.items24"] as TextureRegionPack).get(2,0)
|
get() = CommonResourcePool.getAsTextureRegionPack("basegame.items24").get(2,0)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
|
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.gameitems
|
package net.torvald.terrarum.modulebasegame.gameitems
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import net.torvald.terrarum.AppLoader
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
import net.torvald.terrarum.gameitem.ItemID
|
import net.torvald.terrarum.gameitem.ItemID
|
||||||
@@ -22,7 +22,7 @@ class TikiTorchTester(originalID: ItemID) : GameItem(originalID) {
|
|||||||
override val isDynamic = false
|
override val isDynamic = false
|
||||||
override val material = Material()
|
override val material = Material()
|
||||||
override val itemImage: TextureRegion?
|
override val itemImage: TextureRegion?
|
||||||
get() = AppLoader.resourcePool.getAsTextureRegion("itemplaceholder_48")
|
get() = CommonResourcePool.getAsTextureRegion("itemplaceholder_48")
|
||||||
override var baseToolSize: Double? = baseMass
|
override var baseToolSize: Double? = baseMass
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.gameitems
|
package net.torvald.terrarum.modulebasegame.gameitems
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import net.torvald.terrarum.AppLoader
|
import net.torvald.terrarum.CommonResourcePool
|
||||||
import net.torvald.terrarum.blockproperties.Wire
|
import net.torvald.terrarum.blockproperties.Wire
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
import net.torvald.terrarum.gameitem.ItemID
|
import net.torvald.terrarum.gameitem.ItemID
|
||||||
@@ -22,7 +22,7 @@ class WirePieceSignalWire(originalID: ItemID) : GameItem(originalID) {
|
|||||||
override val isDynamic = false
|
override val isDynamic = false
|
||||||
override val material = Material()
|
override val material = Material()
|
||||||
override val itemImage: TextureRegion?
|
override val itemImage: TextureRegion?
|
||||||
get() = AppLoader.resourcePool.getAsTextureRegionPack("basegame.items16").get(1,9)
|
get() = CommonResourcePool.getAsTextureRegionPack("basegame.items16").get(1,9)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
|
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
|
||||||
|
|||||||
@@ -45,9 +45,13 @@ class UIInventoryFull(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
handler.allowESCtoClose = true
|
handler.allowESCtoClose = true
|
||||||
|
CommonResourcePool.addToLoadingList("inventory_caticons") {
|
||||||
|
TextureRegionPack("./assets/graphics/gui/inventory/category.tga", 20, 20)
|
||||||
|
}
|
||||||
|
CommonResourcePool.loadAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal val catIcons: TextureRegionPack = TextureRegionPack("./assets/graphics/gui/inventory/category.tga", 20, 20)
|
internal val catIcons: TextureRegionPack = CommonResourcePool.getAsTextureRegionPack("inventory_caticons")
|
||||||
internal val catArrangement: IntArray = intArrayOf(9,6,7,1,0,2,3,4,5,8)
|
internal val catArrangement: IntArray = intArrayOf(9,6,7,1,0,2,3,4,5,8)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ class UIItemInventoryEquippedView(
|
|||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
itemGrid.forEach { it.dispose() }
|
itemGrid.forEach { it.dispose() }
|
||||||
|
equipPosIcon.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||||
|
|||||||
139
src/net/torvald/terrarum/tests/WorldgenNoiseSandbox.kt
Normal file
139
src/net/torvald/terrarum/tests/WorldgenNoiseSandbox.kt
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
package net.torvald.terrarum.tests
|
||||||
|
|
||||||
|
import com.badlogic.gdx.ApplicationAdapter
|
||||||
|
import com.badlogic.gdx.Gdx
|
||||||
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplication
|
||||||
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
|
||||||
|
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||||
|
import com.badlogic.gdx.graphics.Pixmap
|
||||||
|
import com.badlogic.gdx.graphics.Texture
|
||||||
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram
|
||||||
|
import com.sudoplay.joise.Joise
|
||||||
|
import com.sudoplay.joise.module.ModuleAutoCorrect
|
||||||
|
import com.sudoplay.joise.module.ModuleBasisFunction
|
||||||
|
import com.sudoplay.joise.module.ModuleFractal
|
||||||
|
import com.sudoplay.joise.module.ModuleScaleDomain
|
||||||
|
import net.torvald.random.HQRNG
|
||||||
|
import net.torvald.terrarum.gameworld.fmod
|
||||||
|
import net.torvald.terrarum.inUse
|
||||||
|
import kotlin.math.cos
|
||||||
|
import kotlin.math.sin
|
||||||
|
|
||||||
|
const val WIDTH = 1536
|
||||||
|
const val HEIGHT = 512
|
||||||
|
const val TWO_PI = Math.PI * 2
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 2019-07-23.
|
||||||
|
*/
|
||||||
|
class WorldgenNoiseSandbox : ApplicationAdapter() {
|
||||||
|
|
||||||
|
private lateinit var batch: SpriteBatch
|
||||||
|
private lateinit var camera: OrthographicCamera
|
||||||
|
|
||||||
|
private lateinit var testTex: Pixmap
|
||||||
|
private lateinit var tempTex: Texture
|
||||||
|
|
||||||
|
private lateinit var joise: Joise
|
||||||
|
|
||||||
|
override fun create() {
|
||||||
|
batch = SpriteBatch()
|
||||||
|
camera = OrthographicCamera(WIDTH.toFloat(), HEIGHT.toFloat())
|
||||||
|
camera.setToOrtho(false) // some elements are pre-flipped, while some are not. The statement itself is absolutely necessary to make edge of the screen as the origin
|
||||||
|
camera.update()
|
||||||
|
batch.projectionMatrix = camera.combined
|
||||||
|
Gdx.gl20.glViewport(0, 0, WIDTH, HEIGHT)
|
||||||
|
|
||||||
|
testTex = Pixmap(WIDTH, HEIGHT, Pixmap.Format.RGBA8888)
|
||||||
|
tempTex = Texture(1, 1, Pixmap.Format.RGBA8888)
|
||||||
|
|
||||||
|
joise = generateNoise()
|
||||||
|
renderNoise()
|
||||||
|
|
||||||
|
println("Init done")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun render() {
|
||||||
|
// draw using pixmap
|
||||||
|
batch.inUse {
|
||||||
|
tempTex.dispose()
|
||||||
|
tempTex = Texture(testTex)
|
||||||
|
batch.draw(tempTex, 0f, 0f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val RNG = HQRNG()
|
||||||
|
private var seed = RNG.nextLong()
|
||||||
|
|
||||||
|
private fun generateNoise(): Joise {
|
||||||
|
//val biome = ModuleBasisFunction()
|
||||||
|
//biome.setType(ModuleBasisFunction.BasisType.SIMPLEX)
|
||||||
|
|
||||||
|
// simplex AND fractal for more noisy edges, mmmm..!
|
||||||
|
val fractal = ModuleFractal()
|
||||||
|
fractal.setType(ModuleFractal.FractalType.MULTI)
|
||||||
|
fractal.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.SIMPLEX)
|
||||||
|
fractal.setNumOctaves(4)
|
||||||
|
fractal.setFrequency(1.0)
|
||||||
|
|
||||||
|
val autocorrect = ModuleAutoCorrect()
|
||||||
|
autocorrect.setSource(fractal)
|
||||||
|
autocorrect.setRange(0.0, 1.0)
|
||||||
|
|
||||||
|
val scale = ModuleScaleDomain()
|
||||||
|
scale.setSource(autocorrect)
|
||||||
|
scale.setScaleX(0.3)
|
||||||
|
scale.setScaleY(0.3)
|
||||||
|
scale.setScaleZ(0.3)
|
||||||
|
|
||||||
|
val last = scale
|
||||||
|
|
||||||
|
return Joise(last)
|
||||||
|
}
|
||||||
|
|
||||||
|
// with this method, only TWO distinct (not bland) biomes are possible. CLUT order is important here.
|
||||||
|
private val biomeColors = intArrayOf(
|
||||||
|
//0x2288ccff.toInt(), // ísland
|
||||||
|
0x229944ff.toInt(), // woodlands
|
||||||
|
0x77bb77ff.toInt(), // shrubland
|
||||||
|
0x88bb66ff.toInt(), // plains
|
||||||
|
0x888888ff.toInt() // rockyland
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun renderNoise() {
|
||||||
|
// render noisemap to pixmap
|
||||||
|
for (y in 0 until HEIGHT) {
|
||||||
|
for (x in 0 until WIDTH) {
|
||||||
|
val sampleDensity = 48.0 / 2 // 48.0: magic number from old code
|
||||||
|
val sampleTheta = (x.toDouble() / WIDTH) * TWO_PI
|
||||||
|
val sampleOffset = (WIDTH / sampleDensity) / 8.0
|
||||||
|
val sampleX = sin(sampleTheta) * sampleOffset + sampleOffset // plus sampleOffset to make only
|
||||||
|
val sampleZ = cos(sampleTheta) * sampleOffset + sampleOffset // positive points are to be sampled
|
||||||
|
val sampleY = y / sampleDensity
|
||||||
|
val noise: Float = joise.get(sampleX, sampleY, sampleZ).toFloat()
|
||||||
|
|
||||||
|
val control = noise.times(biomeColors.size).minus(0.00001f).toInt().fmod(biomeColors.size)
|
||||||
|
|
||||||
|
testTex.setColor(biomeColors[control])
|
||||||
|
//testTex.setColor(RNG.nextFloat(), RNG.nextFloat(), RNG.nextFloat(), 1f)
|
||||||
|
testTex.drawPixel(x, y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
ShaderProgram.pedantic = false
|
||||||
|
|
||||||
|
val appConfig = LwjglApplicationConfiguration()
|
||||||
|
appConfig.vSyncEnabled = false
|
||||||
|
appConfig.resizable = false
|
||||||
|
appConfig.width = WIDTH
|
||||||
|
appConfig.height = HEIGHT
|
||||||
|
appConfig.backgroundFPS = 10
|
||||||
|
appConfig.foregroundFPS = 10
|
||||||
|
appConfig.forceExit = false
|
||||||
|
|
||||||
|
LwjglApplication(WorldgenNoiseSandbox(), appConfig)
|
||||||
|
}
|
||||||
BIN
work_files/graphics/sprites/fixtures/workbench.psd
LFS
Normal file
BIN
work_files/graphics/sprites/fixtures/workbench.psd
LFS
Normal file
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user