fixture ghost test

This commit is contained in:
minjaesong
2021-12-13 00:57:55 +09:00
parent 578208d112
commit 63a29df733
15 changed files with 124 additions and 39 deletions

View File

@@ -8,7 +8,7 @@ import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameitems.inInteractableRange
import net.torvald.terrarum.gameitems.mouseInInteractableRange
import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.modulecomputers.gameactors.FixtureHomeComputer
@@ -42,7 +42,7 @@ class ItemHomeComputer(originalID: ItemID) : GameItem(originalID) {
equipPosition = EquipPosition.HAND_GRIP
}
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = inInteractableRange(actor) {
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) {
val item = FixtureHomeComputer()
item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - item.blockBox.height + 1)

View File

@@ -0,0 +1,13 @@
varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
vec2 boolean = vec2(0.0, 1.0);
vec4 desaturate = vec4(0.2126, 0.7152, 0.0722, 0.0);
void main(void) {
vec4 incolour = texture2D(u_texture, v_texCoords);
float lum = dot(incolour * desaturate, boolean.yyyx) * 0.5 + 0.5;
gl_FragColor = v_color * (vec4(lum) * boolean.yyyx + incolour * boolean.xxxy);
}

View File

@@ -228,6 +228,7 @@ public class App implements ApplicationListener {
public static ShaderProgram shaderDitherRGBA;
public static ShaderProgram shaderColLUT;
public static ShaderProgram shaderReflect;
public static ShaderProgram shaderGhastlyWhite;
public static Mesh fullscreenQuad;
private static OrthographicCamera camera;
@@ -435,6 +436,7 @@ public class App implements ApplicationListener {
shaderDitherRGBA = loadShaderFromFile("assets/shaders/4096.vert", "assets/shaders/4096_bayer.frag"); // always load the shader regardless of config because the config may cange
shaderColLUT = loadShaderFromFile("assets/shaders/4096.vert", "assets/shaders/passthrurgb.frag");
shaderReflect = loadShaderFromFile("assets/shaders/4096.vert", "assets/shaders/reflect.frag");
shaderGhastlyWhite = loadShaderFromFile("assets/shaders/4096.vert", "assets/shaders/ghastlywhite.frag");
fullscreenQuad = new Mesh(
true, 4, 6,
@@ -780,6 +782,7 @@ public class App implements ApplicationListener {
shaderPassthruRGBA.dispose();
shaderColLUT.dispose();
shaderReflect.dispose();
shaderGhastlyWhite.dispose();
CommonResourcePool.INSTANCE.dispose();
fullscreenQuad.dispose();
@@ -794,13 +797,6 @@ public class App implements ApplicationListener {
logo.getTexture().dispose();
disposables.forEach((it) -> {
try {
it.dispose();
}
catch (NullPointerException | IllegalArgumentException | GdxRuntimeException e) { }
});
ModMgr.INSTANCE.disposeMods();
GameWorld.Companion.makeNullWorld().dispose();
@@ -810,6 +806,13 @@ public class App implements ApplicationListener {
inputStrober.dispose();
deleteTempfiles();
disposables.forEach((it) -> {
try {
it.dispose();
}
catch (NullPointerException | IllegalArgumentException | GdxRuntimeException | ConcurrentModificationException e) { }
});
}
@Override

View File

@@ -131,6 +131,9 @@ open class IngameInstance(val batch: SpriteBatch, val isMultiplayer: Boolean = f
var loadedTime_t = App.getTIME_T()
protected set
val blockMarkingActor: BlockMarkerActor
get() = CommonResourcePool.get("blockmarking_actor") as BlockMarkerActor
override fun hide() {
}
@@ -146,7 +149,6 @@ open class IngameInstance(val batch: SpriteBatch, val isMultiplayer: Boolean = f
try { addNewActor(it) } catch (e: ReferencedActorAlreadyExistsException) {}
}
gameInitialised = true
}

View File

@@ -2,6 +2,8 @@ package net.torvald.terrarum.gameactors
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.spriteanimation.SpriteAnimation
import net.torvald.terrarum.App
import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.ReferencingRanges
import net.torvald.terrarum.Terrarum
@@ -9,28 +11,51 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
class BlockMarkerActor : ActorWithBody(Actor.RenderOrder.OVERLAY, physProp = PhysProperties.MOBILE_OBJECT) {
override var referenceID: ActorID = 1048575 // custom refID
private val defaultSize = 16.0
override var referenceID: ActorID = ReferencingRanges.ACTORS_OVERLAY.last // custom refID
override val hitbox = Hitbox(0.0, 0.0, 16.0, 16.0)
var color = Color.YELLOW
var shape = 0
var markerColour = Color.YELLOW
var markerShape = 0
private val blockMarkings: TextureRegionPack
get() = CommonResourcePool.getAsTextureRegionPack("blockmarkings_common")
private var ghost: SpriteAnimation? = null
private var hasGhost = false
var ghostColour = Color.WHITE
init {
this.referenceID = ReferencingRanges.ACTORS_OVERLAY.last
this.isVisible = false
renderOrder = Actor.RenderOrder.OVERLAY // for some reason the constructor didn't work
}
override fun drawBody(batch: SpriteBatch) {
if (isVisible) {
batch.color = color
batch.draw(blockMarkings.get(shape, 0), hitbox.startX.toFloat(), hitbox.startY.toFloat())
if (hasGhost) {
batch.shader = App.shaderGhastlyWhite
if (ghost != null) {
batch.color = ghostColour
drawSpriteInGoodPosition(ghost!!, batch)
}
}
else {
batch.shader = null
batch.color = markerColour
batch.draw(blockMarkings.get(markerShape, 0), hitbox.startX.toFloat(), hitbox.startY.toFloat())
}
}
batch.shader = null
batch.color = Color.WHITE
}
override fun drawGlow(batch: SpriteBatch) { }
override fun drawGlow(batch: SpriteBatch) {
batch.color = Color.WHITE
}
override fun dispose() {
}
@@ -46,4 +71,19 @@ class BlockMarkerActor : ActorWithBody(Actor.RenderOrder.OVERLAY, physProp = Phy
override fun onActorValueChange(key: String, value: Any?) { }
fun setGhost(actor: ActorWithBody) {
ghost = actor.sprite
hasGhost = true
}
fun unsetGhost() {
ghost = null
hasGhost = false
setGhostColourNone()
}
fun setGhostColourNone() { ghostColour = Color.WHITE }
fun setGhostColourAllow() { ghostColour = Color(-1) }
fun setGhostColourBlock() { ghostColour = Color(0) }
}

View File

@@ -328,7 +328,7 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
* @param actor actor to check the reach
* @param action returns true if the action was successfully performed
*/
fun inInteractableRange(actor: ActorWithBody, action: () -> Boolean): Boolean {
fun mouseInInteractableRange(actor: ActorWithBody, action: () -> Boolean): Boolean {
val mousePos1 = Vector2(Terrarum.mouseX, Terrarum.mouseY)
val mousePos2 = Vector2(Terrarum.mouseX + INGAME.world.width * TILE_SIZED, Terrarum.mouseY)
val mousePos3 = Vector2(Terrarum.mouseX - INGAME.world.width * TILE_SIZED, Terrarum.mouseY)

View File

@@ -238,6 +238,9 @@ object IngameRenderer : Disposable {
drawToA(actorsRenderBehind, actorsRenderMiddle, actorsRenderMidTop, actorsRenderFront, particlesContainer)
drawOverlayActors(actorsRenderOverlay)
}
batch.color = Color.WHITE
// clear main or whatever super-FBO being used
//clearBuffer()
gdxClearAndSetBlend(.64f, .754f, .84f, 0f)

View File

@@ -22,7 +22,7 @@ import net.torvald.terrarum.gamecontroller.IngameController
import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.inInteractableRange
import net.torvald.terrarum.gameitems.mouseInInteractableRange
import net.torvald.terrarum.gameparticles.ParticleBase
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.WorldSimulator
@@ -604,7 +604,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
// what if there's multiple of such fixtures? whatever, you are supposed to DISALLOW such situation.
if (itemOnGrip?.inventoryCategory != GameItem.Category.TOOL) { // don't open the UI when player's holding a tool
for (kk in actorsUnderMouse.indices) {
if (inInteractableRange(actor) {
if (mouseInInteractableRange(actor) {
actorsUnderMouse[kk].mainUI?.let {
uiOpened = true
@@ -632,7 +632,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
}
// #3. If I'm not holding any item and I can do barehandaction (size big enough that barehandactionminheight check passes), perform it
else if (itemOnGrip == null && canPerformBarehandAction) {
inInteractableRange(actor) {
mouseInInteractableRange(actor) {
performBarehandAction(actor, delta)
true
}

View File

@@ -40,7 +40,7 @@ internal class FixtureTikiTorch : FixtureBase, Luminous {
// loading textures
CommonResourcePool.addToLoadingList("sprites-fixtures-tiki_torch.tga") {
TextureRegionPack(ModMgr.getGdxFile("basegame", "sprites/fixtures/tiki_torch.tga"), 16, 32)
TextureRegionPack(ModMgr.getGdxFile("basegame", "sprites/fixtures/tiki_torch.tga"), 16, 32, flipY = true)
}
CommonResourcePool.addToLoadingList("particles-tiki_smoke.tga") {
TextureRegionPack(ModMgr.getGdxFile("basegame", "particles/bigger_smoke.tga"), 16, 16)

View File

@@ -4,7 +4,7 @@ import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameitems.inInteractableRange
import net.torvald.terrarum.gameitems.mouseInInteractableRange
import net.torvald.terrarum.modulebasegame.TerrarumIngame
/**
@@ -16,7 +16,7 @@ object BlockBase {
* @param dontEncaseActors when set to true, blocks won't be placed where Actors are. You will want to set it false
* for wire items, otherwise you want it to be true.
*/
fun blockStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, itemID: ItemID, delta: Float) = inInteractableRange(actor) {
fun blockStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, itemID: ItemID, delta: Float) = mouseInInteractableRange(actor) {
val ingame = Terrarum.ingame!! as TerrarumIngame
val mousePoint = Point2d(Terrarum.mouseTileX.toDouble(), Terrarum.mouseTileY.toDouble())
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
@@ -34,7 +34,7 @@ object BlockBase {
if (it is ActorWithBody && it.physProp.usePhysics && it.intTilewiseHitbox.intersects(mousePoint))
ret1 = false // return is not allowed here
}
if (!ret1) return@inInteractableRange ret1
if (!ret1) return@mouseInInteractableRange ret1
}
// return false if the tile underneath is:
@@ -46,7 +46,7 @@ object BlockBase {
gameItem.dynamicID == "wall@" + ingame.world.getTileFromWall(mouseTile.x, mouseTile.y) ||
BlockCodex[ingame.world.getTileFromTerrain(mouseTile.x, mouseTile.y)].nameKey.contains("ACTORBLOCK_")
)
return@inInteractableRange false
return@mouseInInteractableRange false
// filter passed, do the job
// FIXME this is only useful for Player
@@ -74,14 +74,14 @@ object BlockBase {
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = ""
}
fun wireStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, delta: Float) = inInteractableRange(actor) {
fun wireStartPrimaryUse(actor: ActorWithBody, gameItem: GameItem, delta: Float) = mouseInInteractableRange(actor) {
val itemID = gameItem.originalID
val ingame = Terrarum.ingame!! as TerrarumIngame
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
// return false if the tile is already there
if (ingame.world.getAllWiresFrom(mouseTile.x, mouseTile.y)?.searchFor(itemID) != null)
return@inInteractableRange false
return@mouseInInteractableRange false
// filter passed, do the job
ingame.world.setTileWire(

View File

@@ -6,7 +6,7 @@ import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameitems.inInteractableRange
import net.torvald.terrarum.gameitems.mouseInInteractableRange
import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.modulebasegame.gameactors.FixtureStorageChest
import net.torvald.terrarum.modulebasegame.gameactors.FixtureTikiTorch
@@ -32,7 +32,7 @@ class ItemStorageChest(originalID: ItemID) : GameItem(originalID) {
equipPosition = EquipPosition.HAND_GRIP
}
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = inInteractableRange(actor) {
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) {
val item = FixtureStorageChest()
item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - item.blockBox.height + 1)

View File

@@ -2,13 +2,15 @@ package net.torvald.terrarum.modulebasegame.gameitems
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.CommonResourcePool
import net.torvald.terrarum.INGAME
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameitems.inInteractableRange
import net.torvald.terrarum.gameitems.mouseInInteractableRange
import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.FixtureTikiTorch
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
@@ -17,6 +19,10 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
*/
class ItemTikiTorch(originalID: ItemID) : GameItem(originalID) {
companion object {
private val ghostTorch = FixtureTikiTorch()
}
init {
CommonResourcePool.addToLoadingList("sprites-fixtures-tiki_torch.tga") {
TextureRegionPack(ModMgr.getGdxFile("basegame", "sprites/fixtures/tiki_torch.tga"), 16, 32, flipY = true)
@@ -40,7 +46,25 @@ class ItemTikiTorch(originalID: ItemID) : GameItem(originalID) {
equipPosition = EquipPosition.HAND_GRIP
}
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = inInteractableRange(actor) {
override fun effectWhenEquipped(actor: ActorWithBody, delta: Float) {
(INGAME as TerrarumIngame).blockMarkingActor.let {
it.setGhost(ghostTorch)
it.isVisible = true
it.update(delta)
it.setGhostColourBlock()
mouseInInteractableRange(actor) { it.setGhostColourAllow(); true }
}
}
override fun effectOnUnequip(actor: ActorWithBody, delta: Float) {
(INGAME as TerrarumIngame).blockMarkingActor.let {
it.unsetGhost()
it.isVisible = false
it.setGhostColourNone()
}
}
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) {
val item = FixtureTikiTorch()
item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - item.blockBox.height + 1)

View File

@@ -9,7 +9,7 @@ import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameitems.inInteractableRange
import net.torvald.terrarum.gameitems.mouseInInteractableRange
import net.torvald.terrarum.itemproperties.Calculate
import net.torvald.terrarum.modulebasegame.gameactors.DroppedItem
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.BASE_MASS_AND_SIZE
@@ -29,7 +29,7 @@ object PickaxeCore {
fun startPrimaryUse(
actor: ActorWithBody, delta: Float, item: GameItem?, mx: Int, my: Int,
dropProbability: Double = 1.0, mw: Int = 1, mh: Int = 1, attackActorBlocks: Boolean = true
) = inInteractableRange(actor) {
) = mouseInInteractableRange(actor) {
// un-round the mx
val ww = INGAME.world.width
val apos = actor.centrePosPoint

View File

@@ -8,7 +8,7 @@ import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameitems.inInteractableRange
import net.torvald.terrarum.gameitems.mouseInInteractableRange
import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.DroppedItem
@@ -36,7 +36,7 @@ class WireCutterAll(originalID: ItemID) : GameItem(originalID) {
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
}
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = inInteractableRange(actor) {
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = mouseInInteractableRange(actor) {
val ingame = Terrarum.ingame!! as TerrarumIngame
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
val wires = ingame.world.getAllWiresFrom(mouseTile.x, mouseTile.y)?.cloneToList()
@@ -44,7 +44,7 @@ class WireCutterAll(originalID: ItemID) : GameItem(originalID) {
wires?.forEach {
ingame.world.removeTileWire(mouseTile.x, mouseTile.y, it, false)
ingame.addNewActor(DroppedItem(it, mouseTile.x * TILE_SIZE, mouseTile.y * TILE_SIZE))
} ?: return@inInteractableRange false
} ?: return@mouseInInteractableRange false
true
}

View File

@@ -34,8 +34,8 @@ class WireGraphDebugger(originalID: ItemID) : GameItem(originalID) {
override fun effectWhenEquipped(actor: ActorWithBody, delta: Float) {
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = "wire_render_all"
blockMarker.shape = 3
blockMarker.color = Color.YELLOW
blockMarker.markerShape = 3
blockMarker.markerColour = Color.YELLOW
blockMarker.isVisible = true
blockMarker.update(delta)