Compare commits

...

18 Commits

Author SHA1 Message Date
minjaesong
ae52de85a2 it darkens because you forgot the fucking assignment, same mistake from 2013 2019-06-07 10:43:41 +09:00
minjaesong
585a20542f minor improvement 2019-05-25 01:11:42 +09:00
minjaesong
2ab1443885 a little experimets 2019-05-22 00:01:38 +09:00
minjaesong
046f2d4b6c made it work but slower?! 2019-05-21 17:52:20 +09:00
minjaesong
e3fbb57530 something's screwing up but commiting anyway 2019-05-20 23:31:43 +09:00
minjaesong
92d5cac2ff furred npc test might delete later 2019-05-20 12:07:01 +09:00
minjaesong
471b0c805d font: new redesigned hangul 2019-05-14 13:16:10 +09:00
minjaesong
16b7457d08 font: hangul redraw wip -- less "laundry line" 2019-05-12 23:52:27 +09:00
minjaesong
5c20ceeedc font: hangul redraw wip 2019-05-12 17:09:46 +09:00
minjaesong
49df5f9676 gradle script fix typo and add assertion jvm option 2019-05-12 01:03:35 +09:00
minjaesong
48ba273317 comment 2019-05-08 21:23:42 +09:00
minjaesong
52d6955ffc blocksdrawer now draws wire 2019-05-04 18:19:08 +09:00
minjaesong
08f07e566d adding missing resources/moving zip files to lfs 2019-05-04 04:11:33 +09:00
minjaesong
c423190725 block functions now share one centralised core function 2019-05-04 03:29:59 +09:00
minjaesong
61078cf5a8 debug info for upcoming wires 2019-05-02 00:56:25 +09:00
minjaesong
eafdeddc94 fixed a long bug where item would be used twice but discounted by only one on single click 2019-05-01 23:26:01 +09:00
minjaesong
9050378e81 more comments 2019-04-30 03:06:19 +09:00
minjaesong
fecb20da13 sortedarraylist update; physball breaks the actor render dunno why 2019-04-30 02:52:09 +09:00
116 changed files with 1000 additions and 504 deletions

1
.gitattributes vendored
View File

@@ -4,3 +4,4 @@
*.gz filter=lfs diff=lfs merge=lfs -text *.gz filter=lfs diff=lfs merge=lfs -text
*.opus filter=lfs diff=lfs merge=lfs -text *.opus filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text *.pdf filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text

View File

@@ -0,0 +1,23 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="ArrayEquality" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="ConstantConditionIf" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="CsvValidation" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="ExplicitThis" enabled="false" level="INFORMATION" enabled_by_default="false" />
<inspection_tool class="KotlinDoubleNegation" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="NullChecksToSafeCall" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="RedundantCompanionReference" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="RedundantExplicitType" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="RedundantGetter" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="RedundantSetter" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="RedundantUnitExpression" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="RedundantUnitReturnType" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="RemoveCurlyBracesFromTemplate" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="RemoveEmptyPrimaryConstructor" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="RemoveEmptySecondaryConstructorBody" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="RemoveRedundantBackticks" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="RemoveRedundantQualifierName" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="RemoveSingleExpressionStringTemplate" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>
</component>

View File

@@ -1,3 +1,3 @@
<component name="MarkdownNavigator.ProfileManager"> <component name="MarkdownNavigator.ProfileManager">
<settings default="" pdf-export="" /> <settings default="" pdf-export="" plain-text-search-scope="Project Files" />
</component> </component>

2
.idea/misc.xml generated
View File

@@ -38,7 +38,7 @@
<property name="caretWidth" class="java.lang.Integer" /> <property name="caretWidth" class="java.lang.Integer" />
</properties> </properties>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_10" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="false" project-jdk-name="13-incubate" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,5 +1,6 @@
"id";"classname" "id";"classname"
"8448";"net.torvald.terrarum.modulebasegame.items.PickaxeCopper" "8448";"net.torvald.terrarum.modulebasegame.gameitems.PickaxeCopper"
"8449";"net.torvald.terrarum.modulebasegame.items.PickaxeIron" "8449";"net.torvald.terrarum.modulebasegame.gameitems.PickaxeIron"
"8450";"net.torvald.terrarum.modulebasegame.items.PickaxeSteel" "8450";"net.torvald.terrarum.modulebasegame.gameitems.PickaxeSteel"
"8466";"net.torvald.terrarum.modulebasegame.items.WirePieceSignalWire" "8466";"net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire"
"8467";"net.torvald.terrarum.modulebasegame.gameitems.TikiTorchTester"
1 id classname
2 8448 net.torvald.terrarum.modulebasegame.items.PickaxeCopper net.torvald.terrarum.modulebasegame.gameitems.PickaxeCopper
3 8449 net.torvald.terrarum.modulebasegame.items.PickaxeIron net.torvald.terrarum.modulebasegame.gameitems.PickaxeIron
4 8450 net.torvald.terrarum.modulebasegame.items.PickaxeSteel net.torvald.terrarum.modulebasegame.gameitems.PickaxeSteel
5 8466 net.torvald.terrarum.modulebasegame.items.WirePieceSignalWire net.torvald.terrarum.modulebasegame.gameitems.WirePieceSignalWire
6 8467 net.torvald.terrarum.modulebasegame.gameitems.TikiTorchTester

View File

@@ -1,4 +1,4 @@
import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.Material import net.torvald.terrarum.itemproperties.Material
import org.jetbrains.annotations.NotNull import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.Nullable import org.jetbrains.annotations.Nullable

View File

@@ -9,7 +9,7 @@ import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.itemproperties.Calculate import net.torvald.terrarum.itemproperties.Calculate
import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.Material import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.blockproperties.Block
// following two are NOT UNUSED! // following two are NOT UNUSED!

View File

@@ -0,0 +1,40 @@
# complete file name is: SPRITESHEET + bodypart name + EXTENSION
SPRITESHEET=mods/basegame/sprites/test_furry/furbud_
EXTENSION=.tga
# defines frame size and origin point. Origin point is given as: (originx, size.y - 1)
# ORIGINY is deduced from the sprite size as shown in above; you only need to set ORIGINX
CONFIG=SIZE 48,56;ORIGINX 29
# note to self: don't implement skeleton hierarchy: there's too many exceptions
# besides, you have "ALL" key.
! a skeleton also defines what body parts (images) be used.
! you can also write multiline text using reverse solidus; this is a feature of .properties
! skeleton joints are ordered: foremost-drawn object comes first, which means lowermost object IN THIS LIST
! are painted first, and any object that comes before it will paint over it. In other words, this list is
! first reversed then being iterated.
! Joints' original point is defined in the document sprite_joints.psd. It also has visual representations.
# TODO right now accessory points are explicitly defined. Should they be injected in run-time?
SKELETON_STAND=HEADGEAR 0,32;HAIR_FORE 0,32;\
ARM_REST_RIGHT -7,23;HAND_REST_RIGHT -6,11;HELD_ITEM -6,11;\
HAIR 0,32;HEAD 0,32;\
UPPER_TORSO 0,23;LOWER_TORSO 0,15;\
FOOT_RIGHT -2,2;LEG_REST_RIGHT -2,7;\
FOOT_LEFT 2,2;LEG_REST_LEFT 2,7;\
ARM_REST_LEFT 5,24;HAND_REST_LEFT 6,12;\
TAIL_0 0,13;TAIL_1 0,13
# skeleton_stand is used for testing purpose
ANIM_RUN=DELAY 0.15;ROW 2;SKELETON SKELETON_STAND
ANIM_RUN_1=TAIL_0 0,-999;LEG_REST_RIGHT 1,1;FOOT_RIGHT 1,1;LEG_REST_LEFT -1,0;FOOT_LEFT -1,0
ANIM_RUN_2=TAIL_1 0,-999;ALL 0,1;LEG_REST_RIGHT 0,-1;FOOT_RIGHT 0,-1;LEG_REST_LEFT 0,1;FOOT_LEFT 0,1
ANIM_RUN_3=TAIL_1 0,-999;LEG_REST_RIGHT -1,0;FOOT_RIGHT -1,0;LEG_REST_LEFT 1,1;FOOT_LEFT 1,1
ANIM_RUN_4=TAIL_0 0,-999;ALL 0,1;LEG_REST_RIGHT 0,1;FOOT_RIGHT 0,1;LEG_REST_LEFT 0,-1;FOOT_LEFT 0,-1
ANIM_IDLE=DELAY 2;ROW 1;SKELETON SKELETON_STAND
ANIM_IDLE_1=TAIL_1 0,-999
ANIM_IDLE_2=TAIL_1 0,-999;\
UPPER_TORSO 0,-1;HEAD 0,-1;HAIR 0,-1;HELD_ITEM 0,-1;\
ARM_REST_LEFT 0,-1;ARM_REST_RIGHT 0,-1;HAND_REST_LEFT 0,-1;HAND_REST_RIGHT 0,-1;\
HAIR_FORE 0,-1;HEADGEAR 0,-1

View File

@@ -0,0 +1,40 @@
# complete file name is: SPRITESHEET + bodypart name + EXTENSION
SPRITESHEET=mods/basegame/sprites/test_furry/furbudglow_
EXTENSION=.tga
# defines frame size and origin point. Origin point is given as: (originx, size.y - 1)
# ORIGINY is deduced from the sprite size as shown in above; you only need to set ORIGINX
CONFIG=SIZE 48,56;ORIGINX 29
# note to self: don't implement skeleton hierarchy: there's too many exceptions
# besides, you have "ALL" key.
! a skeleton also defines what body parts (images) be used.
! you can also write multiline text using reverse solidus; this is a feature of .properties
! skeleton joints are ordered: foremost-drawn object comes first, which means lowermost object IN THIS LIST
! are painted first, and any object that comes before it will paint over it. In other words, this list is
! first reversed then being iterated.
! Joints' original point is defined in the document sprite_joints.psd. It also has visual representations.
# TODO right now accessory points are explicitly defined. Should they be injected in run-time?
SKELETON_STAND=HEADGEAR 0,32;HAIR_FORE 0,32;\
ARM_REST_RIGHT -7,23;HAND_REST_RIGHT -6,11;HELD_ITEM -6,11;\
HAIR 0,32;HEAD 0,32;\
UPPER_TORSO 0,23;LOWER_TORSO 0,15;\
FOOT_RIGHT -2,2;LEG_REST_RIGHT -2,7;\
FOOT_LEFT 2,2;LEG_REST_LEFT 2,7;\
ARM_REST_LEFT 5,24;HAND_REST_LEFT 6,12;\
TAIL_0 0,13;TAIL_1 0,13
# skeleton_stand is used for testing purpose
ANIM_RUN=DELAY 0.15;ROW 2;SKELETON SKELETON_STAND
ANIM_RUN_1=TAIL_0 0,-999;LEG_REST_RIGHT 1,1;FOOT_RIGHT 1,1;LEG_REST_LEFT -1,0;FOOT_LEFT -1,0
ANIM_RUN_2=TAIL_1 0,-999;ALL 0,1;LEG_REST_RIGHT 0,-1;FOOT_RIGHT 0,-1;LEG_REST_LEFT 0,1;FOOT_LEFT 0,1
ANIM_RUN_3=TAIL_1 0,-999;LEG_REST_RIGHT -1,0;FOOT_RIGHT -1,0;LEG_REST_LEFT 1,1;FOOT_LEFT 1,1
ANIM_RUN_4=TAIL_0 0,-999;ALL 0,1;LEG_REST_RIGHT 0,1;FOOT_RIGHT 0,1;LEG_REST_LEFT 0,-1;FOOT_LEFT 0,-1
ANIM_IDLE=DELAY 2;ROW 1;SKELETON SKELETON_STAND
ANIM_IDLE_1=TAIL_1 0,-999
ANIM_IDLE_2=TAIL_1 0,-999;\
UPPER_TORSO 0,-1;HEAD 0,-1;HAIR 0,-1;HELD_ITEM 0,-1;\
ARM_REST_LEFT 0,-1;ARM_REST_RIGHT 0,-1;HAND_REST_LEFT 0,-1;HAND_REST_RIGHT 0,-1;\
HAIR_FORE 0,-1;HEADGEAR 0,-1

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -2,6 +2,7 @@
SPRITESHEET=mods/basegame/sprites/sprite_assembler_test_assets/test_ SPRITESHEET=mods/basegame/sprites/sprite_assembler_test_assets/test_
EXTENSION=.tga EXTENSION=.tga
# defines frame size and origin point. Origin point is given as: (originx, size.y - 1) # defines frame size and origin point. Origin point is given as: (originx, size.y - 1)
# ORIGINY is deduced from the sprite size as shown in above; you only need to set ORIGINX
CONFIG=SIZE 48,56;ORIGINX 29 CONFIG=SIZE 48,56;ORIGINX 29
# note to self: don't implement skeleton hierarchy: there's too many exceptions # note to self: don't implement skeleton hierarchy: there's too many exceptions
@@ -13,14 +14,15 @@ CONFIG=SIZE 48,56;ORIGINX 29
! are painted first, and any object that comes before it will paint over it. In other words, this list is ! are painted first, and any object that comes before it will paint over it. In other words, this list is
! first reversed then being iterated. ! first reversed then being iterated.
! Joints' original point is defined in the document sprite_joints.psd. It also has visual representations. ! Joints' original point is defined in the document sprite_joints.psd. It also has visual representations.
# TODO right now accessory points are explicitly defined. Should they be injected in run-time? # TODO right now accessory points are explicitly defined. Should they be injected in run-time? In that case, certain names (e.g. headgear, held_item) will act as an anchor.
SKELETON_STAND=HEADGEAR 0,32;HAIR_FORE 0,32;\ SKELETON_STAND=HEADGEAR 0,32;HAIR_FORE 0,32;\
ARM_REST_RIGHT -7,23;HAND_REST_RIGHT -6,11;HELD_ITEM -6,11;\ ARM_REST_RIGHT -7,23;HAND_REST_RIGHT -6,11;HELD_ITEM -6,11;\
HAIR 0,32;HEAD 0,32;\ HAIR 0,32;HEAD 0,32;\
UPPER_TORSO 0,23;LOWER_TORSO 0,15;\ UPPER_TORSO 0,23;LOWER_TORSO 0,15;\
FOOT_RIGHT -2,2;LEG_REST_RIGHT -2,7;\ FOOT_RIGHT -2,2;LEG_REST_RIGHT -2,7;\
FOOT_LEFT 2,2;LEG_REST_LEFT 2,7;\ FOOT_LEFT 2,2;LEG_REST_LEFT 2,7;\
ARM_REST_LEFT 5,24;HAND_REST_LEFT 6,12 ARM_REST_LEFT 5,24;HAND_REST_LEFT 6,12;\
TAIL0 0,13
# skeleton_stand is used for testing purpose # skeleton_stand is used for testing purpose
ANIM_RUN=DELAY 0.15;ROW 2;SKELETON SKELETON_STAND ANIM_RUN=DELAY 0.15;ROW 2;SKELETON SKELETON_STAND

View File

@@ -40,6 +40,8 @@ uniform vec4 colourFilter = vec4(1, 1, 1, 1); // used by WALL to darken it
uniform ivec2 cameraTranslation = ivec2(0, 0); uniform ivec2 cameraTranslation = ivec2(0, 0);
uniform float drawBreakage = 1f; // set it to 0f to not draw breakage; non-zero value to draw it
ivec2 getTileXY(int tileNumber) { ivec2 getTileXY(int tileNumber) {
return ivec2(tileNumber % int(tilesInAtlas.x), tileNumber / int(tilesInAtlas.x)); return ivec2(tileNumber % int(tilesInAtlas.x), tileNumber / int(tilesInAtlas.x));
@@ -108,7 +110,13 @@ void main() {
vec4 finalTile = mix(tileCol, tileAltCol, tilesBlend); vec4 finalTile = mix(tileCol, tileAltCol, tilesBlend);
vec4 finalBreakage = texture2D(tilesAtlas, finalUVCoordForBreakage); vec4 finalBreakage;
if (drawBreakage == 0f) {
finalBreakage = vec4(0f);
}
else {
finalBreakage = texture2D(tilesAtlas, finalUVCoordForBreakage);
}
vec4 finalColor = vec4(mix(finalTile.rgb, finalBreakage.rgb, finalBreakage.a), finalTile.a); vec4 finalColor = vec4(mix(finalTile.rgb, finalBreakage.rgb, finalBreakage.a), finalTile.a);

View File

@@ -56,8 +56,9 @@ task gamedebug(type: JavaExec) {
classpath sourceSets.main.runtimeClasspath classpath sourceSets.main.runtimeClasspath
main = 'net.torvald.terrarum.AppLoader' main = 'net.torvald.terrarum.AppLoader'
group = "Application" group = "Application"
description = "Launches the game with debuy key." description = "Launches the game with the debug key."
args = ["isdev=true"] args = ["isdev=true"]
jvmArgs = ["-ea"]
} }
task spriteassembler(type: JavaExec) { task spriteassembler(type: JavaExec) {

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
lib/javadoc/lwjgl3-javadoc.zip LFS Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -11,12 +11,17 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
*/ */
interface HasAssembledSprite { interface HasAssembledSprite {
/** ADL path for main sprite. Necessary. */
var animDescPath: String var animDescPath: String
/** ADL path for glow sprite. Optional. */
var animDescPathGlow: String?
// FIXME sometimes the animmation is invisible (row and nFrames mismatch -- row is changed to 1 but it's drawing 3rd frame?) // FIXME sometimes the animmation is invisible (row and nFrames mismatch -- row is changed to 1 but it's drawing 3rd frame?)
fun reassembleSprite(sprite: SpriteAnimation) { fun reassembleSprite(sprite: SpriteAnimation, spriteGlow: SpriteAnimation? = null) {
_rebuild(ADProperties(Gdx.files.internal(animDescPath).read()), sprite) _rebuild(ADProperties(Gdx.files.internal(animDescPath).read()), sprite)
if (spriteGlow != null)
_rebuild(ADProperties(Gdx.files.internal(animDescPathGlow).read()), spriteGlow)
} }
/*fun rebuild(animDescPath: String, spriteAnimation: SpriteAnimation) { /*fun rebuild(animDescPath: String, spriteAnimation: SpriteAnimation) {

View File

@@ -95,6 +95,7 @@ class SpriteAssemblerApp(val gdxWindow: SpriteAssemblerPreview) : JFrame() {
} }
panelCode.font = Font(Font.MONOSPACED, Font.PLAIN, 12) panelCode.font = Font(Font.MONOSPACED, Font.PLAIN, 12)
panelCode.text = "Enter your descriptor code here…"
panelAnimationsList.model = DefaultListModel() panelAnimationsList.model = DefaultListModel()
panelBodypartsList.model = DefaultListModel() panelBodypartsList.model = DefaultListModel()
@@ -278,7 +279,7 @@ class SpriteAssemblerPreview: Game() {
} }
gdxClearAndSetBlend(.62f,.79f,1f,1f) gdxClearAndSetBlend(bgCol)
batch.inUse { batch.inUse {

View File

@@ -18,7 +18,6 @@ import com.github.strikerx3.jxinput.XInputDevice;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive; import com.google.gson.JsonPrimitive;
import net.torvald.util.ArrayListMap;
import net.torvald.getcpuname.GetCpuName; import net.torvald.getcpuname.GetCpuName;
import net.torvald.terrarum.blockstats.MinimapComposer; import net.torvald.terrarum.blockstats.MinimapComposer;
import net.torvald.terrarum.controller.GdxControllerAdapter; import net.torvald.terrarum.controller.GdxControllerAdapter;
@@ -34,10 +33,12 @@ import net.torvald.terrarum.worlddrawer.BlocksDrawer;
import net.torvald.terrarum.worlddrawer.LightmapRenderer; import net.torvald.terrarum.worlddrawer.LightmapRenderer;
import net.torvald.terrarumsansbitmap.gdx.GameFontBase; import net.torvald.terrarumsansbitmap.gdx.GameFontBase;
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack; import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack;
import net.torvald.util.ArrayListMap;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.Random; import java.util.Random;
import static net.torvald.terrarum.TerrarumKt.gdxClearAndSetBlend; import static net.torvald.terrarum.TerrarumKt.gdxClearAndSetBlend;
@@ -181,7 +182,7 @@ public class AppLoader implements ApplicationListener {
/** A gamepad. Multiple gamepads may controll this single virtualised gamepad. */ /** A gamepad. Multiple gamepads may controll this single virtualised gamepad. */
public static TerrarumController gamepad = null; public static TerrarumController gamepad = null;
public static float gamepadDeadzone = 0.2f; public static float gamepadDeadzone = 0.3f;
/** /**
@@ -205,9 +206,9 @@ public class AppLoader implements ApplicationListener {
try { processor = GetCpuName.getModelName(); } try { processor = GetCpuName.getModelName(); }
catch (IOException e1) { processor = "Unknown"; } catch (IOException e1) { processor = "Unknown CPU"; }
try { processorVendor = GetCpuName.getCPUID(); } try { processorVendor = GetCpuName.getCPUID(); }
catch (IOException e2) { processorVendor = "Unknown"; } catch (IOException e2) { processorVendor = "Unknown CPU"; }
ShaderProgram.pedantic = false; ShaderProgram.pedantic = false;
@@ -284,11 +285,14 @@ public class AppLoader implements ApplicationListener {
private FrameBuffer renderFBO; private FrameBuffer renderFBO;
public static CommonResourcePool resourcePool; public static CommonResourcePool resourcePool;
public static HashSet<File> tempFilePool = new HashSet();
@Override @Override
public void create() { public void create() {
resourcePool = CommonResourcePool.INSTANCE; resourcePool = CommonResourcePool.INSTANCE;
newTempFile("wenquanyi.tga"); // temp file required by the font
// set basis of draw // set basis of draw
logoBatch = new SpriteBatch(); logoBatch = new SpriteBatch();
@@ -376,13 +380,6 @@ public class AppLoader implements ApplicationListener {
} }
/**
* @link http://bilgin.esme.org/BitsAndBytes/KalmanFilterforDummies
*/
private void updateKalmanRenderDelta() {
// moved to LwjglGraphics
}
@Override @Override
public void render() { public void render() {
Gdx.gl.glDisable(GL20.GL_DITHER); Gdx.gl.glDisable(GL20.GL_DITHER);
@@ -544,8 +541,7 @@ public class AppLoader implements ApplicationListener {
ModMgr.INSTANCE.disposeMods(); ModMgr.INSTANCE.disposeMods();
// delete temp files deleteTempfiles();
new File("./tmp_wenquanyi.tga").delete(); // FIXME this is pretty much ad-hoc
} }
@Override @Override
@@ -688,6 +684,7 @@ public class AppLoader implements ApplicationListener {
System.out.println(String.format("os.name = %s (with identifier %s)", OSName, operationSystem)); System.out.println(String.format("os.name = %s (with identifier %s)", OSName, operationSystem));
System.out.println(String.format("os.version = %s", OSVersion)); System.out.println(String.format("os.version = %s", OSVersion));
System.out.println(String.format("default directory: %s", defaultDir)); System.out.println(String.format("default directory: %s", defaultDir));
System.out.println(String.format("java version = %s", System.getProperty("java.version")));
} }
private static void createDirs() { private static void createDirs() {
@@ -701,6 +698,17 @@ public class AppLoader implements ApplicationListener {
//dirs.forEach { if (!it.exists()) it.mkdirs() } //dirs.forEach { if (!it.exists()) it.mkdirs() }
} }
public static File newTempFile(String filename) {
File tempfile = new File("./tmp_" + filename);
tempFilePool.add(tempfile);
return tempfile;
}
private static void deleteTempfiles() {
for (File file : tempFilePool) {
file.delete();
}
}
// CONFIG // // CONFIG //

View File

@@ -19,9 +19,10 @@ class GdxColorMap {
height = pixmap.height height = pixmap.height
is2D = pixmap.height > 1 is2D = pixmap.height > 1
data = kotlin.IntArray(pixmap.width * pixmap.height) { dataRaw = kotlin.IntArray(pixmap.width * pixmap.height) {
pixmap.getPixel(it % pixmap.width, it / pixmap.width) pixmap.getPixel(it % pixmap.width, it / pixmap.width)
} }
dataGdxColor = dataRaw.map { Color(it) }.toTypedArray()
pixmap.dispose() pixmap.dispose()
} }
@@ -31,39 +32,46 @@ class GdxColorMap {
height = pixmap.height height = pixmap.height
is2D = pixmap.height > 1 is2D = pixmap.height > 1
data = kotlin.IntArray(pixmap.width * pixmap.height) { dataRaw = kotlin.IntArray(pixmap.width * pixmap.height) {
pixmap.getPixel(it % pixmap.width, it / pixmap.width) pixmap.getPixel(it % pixmap.width, it / pixmap.width)
} }
dataGdxColor = dataRaw.map { Color(it) }.toTypedArray()
if (disposePixmap) pixmap.dispose() if (disposePixmap) pixmap.dispose()
} }
constructor(color: Color) { constructor(color: Color) {
data = intArrayOf(color.toIntBits()) dataRaw = intArrayOf(color.toIntBits())
dataGdxColor = dataRaw.map { Color(it) }.toTypedArray()
width = 1 width = 1
height = 1 height = 1
is2D = false is2D = false
} }
constructor(gradStart: Color, gradEnd: Color) { constructor(gradStart: Color, gradEnd: Color) {
data = intArrayOf(gradStart.toIntBits(), gradEnd.toIntBits()) dataRaw = intArrayOf(gradStart.toIntBits(), gradEnd.toIntBits())
dataGdxColor = dataRaw.map { Color(it) }.toTypedArray()
width = 1 width = 1
height = 2 height = 2
is2D = true is2D = true
} }
private val data: IntArray private val dataRaw: IntArray
private val dataGdxColor: Array<Color>
//private val dataCvec: Array<Cvec>
val width: Int val width: Int
val height: Int val height: Int
val is2D: Boolean val is2D: Boolean
fun get(x: Int, y: Int): Color = Color(data[y * width + x]) fun get(x: Int, y: Int): Color = dataGdxColor[y * width + x]
operator fun get(x: Int): Color = if (is2D) throw OperationNotSupportedException("This is 2D color map") else Color(data[x]) operator fun get(x: Int): Color = if (is2D) throw OperationNotSupportedException("This is 2D color map") else dataGdxColor[x]
fun getRaw(x: Int, y: Int): RGBA8888 = data[y * width + x] fun getRaw(x: Int, y: Int): RGBA8888 = dataRaw[y * width + x]
fun getRaw(x: Int): RGBA8888 = if (is2D) throw OperationNotSupportedException("This is 2D color map") else data[x] fun getRaw(x: Int): RGBA8888 = if (is2D) throw OperationNotSupportedException("This is 2D color map") else dataRaw[x]
//fun getAsCvec(x: Int, y: Int): Cvec = dataCvec[y * width + x]
override fun toString(): String { override fun toString(): String {
val sb = StringBuilder() val sb = StringBuilder()

View File

@@ -9,7 +9,6 @@ import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import net.torvald.terrarum.realestate.LandUtil import net.torvald.terrarum.realestate.LandUtil
import net.torvald.terrarum.ui.ConsoleWindow import net.torvald.terrarum.ui.ConsoleWindow
import net.torvald.util.SortedArrayList import net.torvald.util.SortedArrayList
import java.util.*
import java.util.concurrent.locks.Lock import java.util.concurrent.locks.Lock
/** /**
@@ -127,6 +126,9 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
/** /**
* Wire version of terrainChanged() event * Wire version of terrainChanged() event
*
* @param old previous settings of conduits in bit set format.
* @param new current settings of conduits in bit set format.
*/ */
open fun queueWireChangedEvent(old: Int, new: Int, position: Long) { open fun queueWireChangedEvent(old: Int, new: Int, position: Long) {
val (x, y) = LandUtil.resolveBlockAddr(world, position) val (x, y) = LandUtil.resolveBlockAddr(world, position)
@@ -143,11 +145,11 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
if (actorContainerActive.size == 0 && actorContainerInactive.size == 0) if (actorContainerActive.size == 0 && actorContainerInactive.size == 0)
throw IllegalArgumentException("Actor with ID $ID does not exist.") throw IllegalArgumentException("Actor with ID $ID does not exist.")
var index = actorContainerActive.binarySearch(ID) var actor = actorContainerActive.searchFor(ID) { it.referenceID!! }
if (index < 0) { if (actor == null) {
index = actorContainerInactive.binarySearch(ID) actor = actorContainerInactive.searchFor(ID) { it.referenceID!! }
if (index < 0) { if (actor == null) {
/*JOptionPane.showMessageDialog( /*JOptionPane.showMessageDialog(
null, null,
"Actor with ID $ID does not exist.", "Actor with ID $ID does not exist.",
@@ -156,36 +158,14 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
throw IllegalArgumentException("Actor with ID $ID does not exist.") throw IllegalArgumentException("Actor with ID $ID does not exist.")
} }
else else
return actorContainerInactive[index] return actor
} }
else else
return actorContainerActive[index] return actor
} }
fun ArrayList<*>.binarySearch(actor: Actor) = this.binarySearch(actor.referenceID!!) //fun SortedArrayList<*>.binarySearch(actor: Actor) = this.toArrayList().binarySearch(actor.referenceID!!)
//fun SortedArrayList<*>.binarySearch(ID: Int) = this.toArrayList().binarySearch(ID)
fun ArrayList<*>.binarySearch(ID: Int): Int {
// code from collections/Collections.kt
var low = 0
var high = this.size - 1
while (low <= high) {
val mid = (low + high).ushr(1) // safe from overflows
val midVal = get(mid)!!
if (ID > midVal.hashCode())
low = mid + 1
else if (ID < midVal.hashCode())
high = mid - 1
else
return mid // key found
}
return -(low + 1) // key not found
}
fun SortedArrayList<*>.binarySearch(actor: Actor) = this.toArrayList().binarySearch(actor.referenceID!!)
fun SortedArrayList<*>.binarySearch(ID: Int) = this.toArrayList().binarySearch(ID)
open fun removeActor(ID: Int) = removeActor(getActorByID(ID)) open fun removeActor(ID: Int) = removeActor(getActorByID(ID))
/** /**
@@ -199,9 +179,9 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
open fun removeActor(actor: Actor?) { open fun removeActor(actor: Actor?) {
if (actor == null) return if (actor == null) return
val indexToDelete = actorContainerActive.binarySearch(actor.referenceID!!) val indexToDelete = actorContainerActive.searchFor(actor.referenceID!!) { it.referenceID!! }
if (indexToDelete >= 0) { if (indexToDelete != null) {
actorContainerActive.removeAt(indexToDelete) actorContainerActive.remove(indexToDelete)
} }
} }
@@ -223,13 +203,13 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
if (actorContainerActive.size == 0) if (actorContainerActive.size == 0)
false false
else else
actorContainerActive.binarySearch(ID) >= 0 actorContainerActive.searchFor(ID) { it.referenceID!! } != null
fun isInactive(ID: Int): Boolean = fun isInactive(ID: Int): Boolean =
if (actorContainerInactive.size == 0) if (actorContainerInactive.size == 0)
false false
else else
actorContainerInactive.binarySearch(ID) >= 0 actorContainerInactive.searchFor(ID) { it.referenceID!! } != null
/** /**
* actorContainerActive extensions * actorContainerActive extensions

View File

@@ -4,9 +4,9 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.files.FileHandle import com.badlogic.gdx.files.FileHandle
import net.torvald.terrarum.AppLoader.* import net.torvald.terrarum.AppLoader.*
import net.torvald.terrarum.blockproperties.BlockCodex import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.itemproperties.ItemID import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.itemproperties.MaterialCodex import net.torvald.terrarum.itemproperties.MaterialCodex
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.utils.CSVFetcher import net.torvald.terrarum.utils.CSVFetcher

View File

@@ -13,6 +13,7 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.math.Matrix4 import com.badlogic.gdx.math.Matrix4
import net.torvald.terrarum.gamecontroller.KeyToggler import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.ui.BasicDebugInfoWindow import net.torvald.terrarum.ui.BasicDebugInfoWindow
import net.torvald.terrarum.worlddrawer.BlocksDrawer
/** /**
* Must be called by the App Loader * Must be called by the App Loader
@@ -37,6 +38,8 @@ object PostProcessor {
private val debugUI = BasicDebugInfoWindow() private val debugUI = BasicDebugInfoWindow()
private var functionRowHelper = Texture(Gdx.files.internal("assets/graphics/function_row_help.png"))
fun dispose() { fun dispose() {
batch.dispose() batch.dispose()
shapeRenderer.dispose() shapeRenderer.dispose()
@@ -78,6 +81,25 @@ object PostProcessor {
drawSafeArea() drawSafeArea()
} }
if (KeyToggler.isOn(Input.Keys.F1)) {
batch.color = Color.WHITE
batch.inUse {
it.draw(functionRowHelper,
(AppLoader.screenW - functionRowHelper.width) / 2f,
functionRowHelper.height.toFloat(),
functionRowHelper.width.toFloat(),
functionRowHelper.height * -1f
)
}
}
if (KeyToggler.isOn(Input.Keys.F10)) {
batch.color = Color.WHITE
batch.inUse {
AppLoader.fontSmallNumbers.draw(it, "Wire draw bits: ${BlocksDrawer.drawWires.toString(2)}", 2f, 2f)
}
}
if (KeyToggler.isOn(Input.Keys.F3)) { if (KeyToggler.isOn(Input.Keys.F3)) {
if (!debugUI.isOpened && !debugUI.isOpening) debugUI.setAsOpen() if (!debugUI.isOpened && !debugUI.isOpening) debugUI.setAsOpen()
batch.inUse { debugUI.renderUI(batch, camera) } batch.inUse { debugUI.renderUI(batch, camera) }

View File

@@ -12,7 +12,6 @@ import com.badlogic.gdx.graphics.glutils.ShaderProgram
import com.badlogic.gdx.graphics.glutils.ShapeRenderer import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.utils.GdxRuntimeException import com.badlogic.gdx.utils.GdxRuntimeException
import com.jme3.math.FastMath import com.jme3.math.FastMath
import net.torvald.util.CircularArray
import net.torvald.random.HQRNG import net.torvald.random.HQRNG
import net.torvald.terrarum.AppLoader.* import net.torvald.terrarum.AppLoader.*
import net.torvald.terrarum.gameactors.Actor import net.torvald.terrarum.gameactors.Actor
@@ -23,6 +22,7 @@ import net.torvald.terrarum.worlddrawer.CreateTileAtlas
import net.torvald.terrarum.worlddrawer.WorldCamera import net.torvald.terrarum.worlddrawer.WorldCamera
import net.torvald.terrarumsansbitmap.gdx.GameFontBase import net.torvald.terrarumsansbitmap.gdx.GameFontBase
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import net.torvald.util.CircularArray
import org.lwjgl.BufferUtils import org.lwjgl.BufferUtils
import java.io.File import java.io.File
import kotlin.math.absoluteValue import kotlin.math.absoluteValue
@@ -196,7 +196,6 @@ object Terrarum : Screen {
init { init {
println("$NAME version ${AppLoader.getVERSION_STRING()}") println("$NAME version ${AppLoader.getVERSION_STRING()}")
println("Java Runtime version ${System.getProperty("java.version")}")
println("LibGDX version ${com.badlogic.gdx.Version.VERSION}") println("LibGDX version ${com.badlogic.gdx.Version.VERSION}")
@@ -613,6 +612,10 @@ fun blendNormal(batch: SpriteBatch) {
// - https://www.andersriggelsen.dk/glblendfunc.php // - https://www.andersriggelsen.dk/glblendfunc.php
} }
fun gdxClearAndSetBlend(color: Color) {
gdxClearAndSetBlend(color.r, color.g, color.b, color.a)
}
fun gdxClearAndSetBlend(r: Float, g: Float, b: Float, a: Float) { fun gdxClearAndSetBlend(r: Float, g: Float, b: Float, a: Float) {
Gdx.gl.glClearColor(r,g,b,a) Gdx.gl.glClearColor(r,g,b,a)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)

View File

@@ -145,7 +145,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
} }
cameraPlayer = object : HumanoidNPC(cameraAI, born = 0, usePhysics = false, forceAssignRefID = Terrarum.PLAYER_REF_ID) { cameraPlayer = object : HumanoidNPC(cameraAI, born = 0, usePhysics = false) {
init { init {
setHitboxDimension(2, 2, 0, 0) setHitboxDimension(2, 2, 0, 0)
hitbox.setPosition( hitbox.setPosition(

View File

@@ -5,7 +5,7 @@ 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 com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull

View File

@@ -5,7 +5,7 @@ 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 com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull

View File

@@ -1,6 +1,5 @@
package net.torvald.terrarum.blockproperties package net.torvald.terrarum.blockproperties
import com.badlogic.gdx.graphics.Color
import net.torvald.terrarum.AppLoader import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.AppLoader.printmsg import net.torvald.terrarum.AppLoader.printmsg
import net.torvald.terrarum.gameworld.FluidType import net.torvald.terrarum.gameworld.FluidType
@@ -8,6 +7,7 @@ import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.MapLayer import net.torvald.terrarum.gameworld.MapLayer
import net.torvald.terrarum.gameworld.PairedMapLayer import net.torvald.terrarum.gameworld.PairedMapLayer
import net.torvald.terrarum.utils.CSVFetcher import net.torvald.terrarum.utils.CSVFetcher
import net.torvald.terrarum.worlddrawer.Cvec
import net.torvald.terrarum.worlddrawer.LightmapRenderer import net.torvald.terrarum.worlddrawer.LightmapRenderer
import org.apache.commons.csv.CSVRecord import org.apache.commons.csv.CSVRecord
import java.io.IOException import java.io.IOException
@@ -110,7 +110,7 @@ object BlockCodex {
prop.shadeColG = floatVal(record, "shdg") / LightmapRenderer.MUL_FLOAT prop.shadeColG = floatVal(record, "shdg") / LightmapRenderer.MUL_FLOAT
prop.shadeColB = floatVal(record, "shdb") / LightmapRenderer.MUL_FLOAT prop.shadeColB = floatVal(record, "shdb") / LightmapRenderer.MUL_FLOAT
prop.shadeColA = floatVal(record, "shduv") / LightmapRenderer.MUL_FLOAT prop.shadeColA = floatVal(record, "shduv") / LightmapRenderer.MUL_FLOAT
prop.opacity = Color(prop.shadeColR, prop.shadeColG, prop.shadeColB, prop.shadeColA) prop.opacity = Cvec(prop.shadeColR, prop.shadeColG, prop.shadeColB, prop.shadeColA)
prop.strength = intVal(record, "str") prop.strength = intVal(record, "str")
prop.density = intVal(record, "dsty") prop.density = intVal(record, "dsty")
@@ -119,7 +119,7 @@ object BlockCodex {
prop.lumColG = floatVal(record, "lumg") / LightmapRenderer.MUL_FLOAT prop.lumColG = floatVal(record, "lumg") / LightmapRenderer.MUL_FLOAT
prop.lumColB = floatVal(record, "lumb") / LightmapRenderer.MUL_FLOAT prop.lumColB = floatVal(record, "lumb") / LightmapRenderer.MUL_FLOAT
prop.lumColA = floatVal(record, "lumuv") / LightmapRenderer.MUL_FLOAT prop.lumColA = floatVal(record, "lumuv") / LightmapRenderer.MUL_FLOAT
prop.internalLumCol = Color(prop.lumColR, prop.lumColG, prop.lumColB, prop.lumColA) prop.internalLumCol = Cvec(prop.lumColR, prop.lumColG, prop.lumColB, prop.lumColA)
prop.friction = intVal(record, "fr") prop.friction = intVal(record, "fr")
prop.viscosity = intVal(record, "vscs") prop.viscosity = intVal(record, "vscs")

View File

@@ -1,6 +1,6 @@
package net.torvald.terrarum.blockproperties package net.torvald.terrarum.blockproperties
import com.badlogic.gdx.graphics.Color import net.torvald.terrarum.worlddrawer.Cvec
/** /**
* Created by minjaesong on 2016-02-16. * Created by minjaesong on 2016-02-16.
@@ -17,7 +17,7 @@ class BlockProp {
var shadeColB = 0f var shadeColB = 0f
var shadeColA = 0f var shadeColA = 0f
lateinit var opacity: Color var opacity: Cvec = Cvec()
var strength: Int = 0 var strength: Int = 0
var density: Int = 0 var density: Int = 0
@@ -36,12 +36,12 @@ class BlockProp {
var lumColG = 0f var lumColG = 0f
var lumColB = 0f var lumColB = 0f
var lumColA = 0f var lumColA = 0f
lateinit var internalLumCol: Color var internalLumCol: Cvec = Cvec()
/** /**
* @param luminosity * @param luminosity
*/ */
inline val luminosity: Color inline val luminosity: Cvec
get() = BlockPropUtil.getDynamicLumFunc(internalLumCol, dynamicLuminosityFunction) get() = BlockPropUtil.getDynamicLumFunc(internalLumCol, dynamicLuminosityFunction)
var drop: Int = 0 var drop: Int = 0

View File

@@ -1,13 +1,13 @@
package net.torvald.terrarum.blockproperties package net.torvald.terrarum.blockproperties
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color
import com.jme3.math.FastMath import com.jme3.math.FastMath
import net.torvald.random.HQRNG import net.torvald.random.HQRNG
import net.torvald.terrarum.Second import net.torvald.terrarum.Second
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.modulebasegame.gameworld.WorldTime import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
import net.torvald.terrarum.worlddrawer.Cvec
import net.torvald.terrarum.worlddrawer.LightmapRenderer import net.torvald.terrarum.worlddrawer.LightmapRenderer
/** /**
@@ -37,7 +37,7 @@ object BlockPropUtil {
} }
private fun getTorchFlicker(baseLum: Color): Color { private fun getTorchFlicker(baseLum: Cvec): Cvec {
val funcY = FastMath.interpolateCatmullRom(0.0f, flickerFuncX / flickerFuncDomain, val funcY = FastMath.interpolateCatmullRom(0.0f, flickerFuncX / flickerFuncDomain,
flickerP0, flickerP1, flickerP2, flickerP3 flickerP0, flickerP1, flickerP2, flickerP3
) )
@@ -45,13 +45,13 @@ object BlockPropUtil {
return LightmapRenderer.alterBrightnessUniform(baseLum, funcY) return LightmapRenderer.alterBrightnessUniform(baseLum, funcY)
} }
private fun getSlowBreath(baseLum: Color): Color { private fun getSlowBreath(baseLum: Cvec): Cvec {
val funcY = FastMath.sin(FastMath.PI * breathFuncX / breathCycleDuration) * breathRange val funcY = FastMath.sin(FastMath.PI * breathFuncX / breathCycleDuration) * breathRange
return LightmapRenderer.alterBrightnessUniform(baseLum, funcY) return LightmapRenderer.alterBrightnessUniform(baseLum, funcY)
} }
private fun getPulsate(baseLum: Color): Color { private fun getPulsate(baseLum: Cvec): Cvec {
val funcY = FastMath.sin(FastMath.PI * pulsateFuncX / pulsateCycleDuration) * pulsateRange val funcY = FastMath.sin(FastMath.PI * pulsateFuncX / pulsateCycleDuration) * pulsateRange
return LightmapRenderer.alterBrightnessUniform(baseLum, funcY) return LightmapRenderer.alterBrightnessUniform(baseLum, funcY)
@@ -91,11 +91,11 @@ object BlockPropUtil {
private fun linearInterpolation1D(a: Float, b: Float, x: Float) = a * (1 - x) + b * x private fun linearInterpolation1D(a: Float, b: Float, x: Float) = a * (1 - x) + b * x
fun getDynamicLumFunc(baseLum: Color, type: Int): Color { fun getDynamicLumFunc(baseLum: Cvec, type: Int): Cvec {
return when (type) { return when (type) {
1 -> getTorchFlicker(baseLum) 1 -> getTorchFlicker(baseLum)
2 -> (Terrarum.ingame!!.world).globalLight.cpy().mul(LightmapRenderer.DIV_FLOAT) // current global light 2 -> (Terrarum.ingame!!.world).globalLight * LightmapRenderer.DIV_FLOAT // current global light
3 -> WeatherMixer.getGlobalLightOfTime(WorldTime.DAY_LENGTH / 2).cpy().mul(LightmapRenderer.DIV_FLOAT) // daylight at noon 3 -> WeatherMixer.getGlobalLightOfTime(WorldTime.DAY_LENGTH / 2) * LightmapRenderer.DIV_FLOAT // daylight at noon
4 -> getSlowBreath(baseLum) 4 -> getSlowBreath(baseLum)
5 -> getPulsate(baseLum) 5 -> getPulsate(baseLum)
else -> baseLum else -> baseLum

View File

@@ -6,21 +6,52 @@ package net.torvald.terrarum.blockproperties
object Wire { object Wire {
/* A mapping for World's conduitTypes bits */ /* A mapping for World's conduitTypes bits */
/* Must be aligned with the sprite sheet */
const val BIT_NONE = 0 const val BIT_NONE = 0
const val BIT_SIGNAL_RED = 1 const val BIT_SIGNAL_RED = 1
const val BIT_UTILITY_PROTOTYPE = 2 const val BIT_UTILITY_PROTOTYPE = 2 // logic gates/PCLs/Diodes/Caps/etc.
const val BIT_POWER_LOW = 4 const val BIT_POWER_LOW = 4
const val BIT_POWER_HIGHT = 8 const val BIT_POWER_HIGHT = 8
const val BIT_ETHERNET = 16 const val BIT_THICKNET = 16 // the actual datagramme should be represented by another means than the ConduitFills
const val BIT_PARALLEL_8B = 32 // uses bit-to-mantissa encoding
const val BIT_PARALLEL_16B = 64 // uses bit-to-mantissa encoding. 16 bit half duplex OR 8 bit full duplex
/* A mapping for World's conduitFills[] index */ /* A mapping for World's WiringNode.fills[] index */
const val FILL_ID_SIGNAL_RED = 0 /*const val FILL_ID_SIGNAL_RED = 0
const val FILL_ID_UTILITY_PROTOTYPE = 1 const val FILL_ID_UTILITY_PROTOTYPE = 1
fun bitToConduitFillID(bit: Int) = when(bit) { fun bitToConduitFillID(bit: Int) = when(bit) {
BIT_SIGNAL_RED -> FILL_ID_SIGNAL_RED BIT_SIGNAL_RED -> FILL_ID_SIGNAL_RED
BIT_UTILITY_PROTOTYPE -> FILL_ID_UTILITY_PROTOTYPE BIT_UTILITY_PROTOTYPE -> FILL_ID_UTILITY_PROTOTYPE
else -> null else -> null
} }*/
/**
* Encodes a byte to Float's mantissa. Normal value range is 1.0..1.99609375. When decoding, the sign and exponent bits
* must be ignored. (e.g. the encoded float might have not-one-point-something value after "bitwise" add/subtraction.
*
* ```
* exponent ,------- mantissa ------,
* s eeeeeeee bbbbbbbb cccccccc xxxxxxx
* s: sign (ignored)
* e: binary32 exponent (non-zero and non-255)
* b: upper octet
* c: lower octet (zero for Byte representation)
* x: not used, all zero
* ```
*
* MSB of the byte is also the highest bit in the mantissa. Therefore ```0x80``` will be encoded as ```1.5```
*/
fun Byte.toFloatMantissa(): Float = Float.fromBits(0x3F800000 or (this.toInt().and(0xFF) shl 15))
fun Short.toFloatMantissa(): Float = Float.fromBits(0x3F800000 or (this.toInt().and(0xFFFF) shl 7))
/**
* This function does the reversal calculation.
*
* @see net.torvald.terrarum.blockproperties.Wire.toFloatMantissa
*/
fun Float.fromMantissaToByte(): Byte = this.toRawBits().ushr(15).and(0xFF).toByte()
fun Float.fromMantissaToShort(): Short = this.toRawBits().ushr(7).and(0xFFFF).toShort()
} }

View File

@@ -44,7 +44,7 @@ object CommandDict {
"kill" to KillActor, "kill" to KillActor,
"money" to MoneyDisp, "money" to MoneyDisp,
"screenshot" to TakeScreenshot, "screenshot" to TakeScreenshot,
//"resize" to ResizeScreen, "resize" to ResizeScreen,
// Test codes // Test codes
"bulletintest" to SetBulletin, "bulletintest" to SetBulletin,

View File

@@ -1,12 +1,11 @@
package net.torvald.terrarum.console package net.torvald.terrarum.console
import net.torvald.terrarum.AppLoader import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Terrarum
object ResizeScreen: ConsoleCommand { object ResizeScreen: ConsoleCommand {
override fun execute(args: Array<String>) { override fun execute(args: Array<String>) {
if (args.size == 3) { if (args.size == 3) {
Terrarum.resize(args[1].toInt(), args[2].toInt()) AppLoader.resizeScreen(args[1].toInt(), args[2].toInt())
} }
else if (args.size == 2) { else if (args.size == 2) {
when (args[1]) { when (args[1]) {

View File

@@ -1,10 +1,9 @@
package net.torvald.terrarum.console package net.torvald.terrarum.console
import com.badlogic.gdx.graphics.Color
import net.torvald.terrarum.worlddrawer.LightmapRenderer
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
import net.torvald.terrarum.worlddrawer.Cvec
import net.torvald.terrarum.worlddrawer.LightmapRenderer
/** /**
* Created by minjaesong on 2016-02-17. * Created by minjaesong on 2016-02-17.
@@ -14,11 +13,12 @@ internal object SetGlobalLightOverride : ConsoleCommand {
override fun execute(args: Array<String>) { override fun execute(args: Array<String>) {
if (args.size == 5) { if (args.size == 5) {
try { try {
val r = args[1].toFloat() val GL = Cvec(
val g = args[2].toFloat() args[1].toFloat(),
val b = args[3].toFloat() args[2].toFloat(),
val a = args[4].toFloat() args[3].toFloat(),
val GL = Color(r, g, b, a) args[4].toFloat()
)
WeatherMixer.globalLightOverridden = true WeatherMixer.globalLightOverridden = true
(Terrarum.ingame!!.world).globalLight = GL (Terrarum.ingame!!.world).globalLight = GL

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.gameactors package net.torvald.terrarum.gameactors
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.itemproperties.ItemCodex.ACTORID_MIN import net.torvald.terrarum.itemproperties.ItemCodex.ACTORID_MIN
@@ -34,7 +35,7 @@ abstract class Actor(val renderOrder: RenderOrder) : Comparable<Actor>, Runnable
* Valid RefID is equal to or greater than 16777216. * Valid RefID is equal to or greater than 16777216.
* @return Reference ID. (16777216-0x7FFF_FFFF) * @return Reference ID. (16777216-0x7FFF_FFFF)
*/ */
open var referenceID: ActorID? = null open var referenceID: ActorID = Terrarum.generateUniqueReferenceID(renderOrder) // once this was nullable without initialiser. If you're going to revert to that, add the reason why this should be nullable.
var actorValue = ActorValue(this) // FIXME cyclic reference on GSON var actorValue = ActorValue(this) // FIXME cyclic reference on GSON
@Volatile var flagDespawn = false @Volatile var flagDespawn = false

View File

@@ -1,6 +1,6 @@
package net.torvald.terrarum.gameactors package net.torvald.terrarum.gameactors
import com.badlogic.gdx.graphics.Color import net.torvald.terrarum.worlddrawer.Cvec
/** /**
* Created by minjaesong on 2016-02-19. * Created by minjaesong on 2016-02-19.
@@ -26,7 +26,7 @@ interface Luminous {
actorValue[AVKey.LUMA] = value.a * LightmapRenderer.MUL_FLOAT actorValue[AVKey.LUMA] = value.a * LightmapRenderer.MUL_FLOAT
} }
*/ */
var color: Color var color: Cvec
/** /**
* Arguments: * Arguments:

View File

@@ -6,16 +6,12 @@ import com.badlogic.gdx.InputAdapter
import com.badlogic.gdx.controllers.Controllers import com.badlogic.gdx.controllers.Controllers
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.Terrarum
import net.torvald.terrarum.controller.TerrarumController import net.torvald.terrarum.controller.TerrarumController
import net.torvald.terrarum.floorInt import net.torvald.terrarum.floorInt
import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameworld.fmod import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.worlddrawer.CreateTileAtlas import net.torvald.terrarum.worlddrawer.CreateTileAtlas
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarum.worlddrawer.WorldCamera import net.torvald.terrarum.worlddrawer.WorldCamera
/** /**
@@ -57,22 +53,16 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
/////////////////// ///////////////////
// Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP) // Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP)
// don't separate Player from this! Physics will break, esp. airborne manoeuvre
if (ingame.canPlayerControl) { if (ingame.canPlayerControl) {
if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary")) || // fire world click events; the event is defined as Ingame's (or any others') WorldClick event
Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary"))) { if (ingame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary"))) {
if (player == null) return ingame.worldPrimaryClickStart(AppLoader.UPDATE_RATE.toFloat())
}
val itemOnGrip = player.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP] if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary"))) {
ingame.worldSecondaryClickStart(AppLoader.UPDATE_RATE.toFloat())
itemOnGrip?.let {
if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary"))) {
player.consumePrimary(ItemCodex[it]!!)
}
if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary"))) {
player.consumeSecondary(ItemCodex[it]!!)
}
} }
} }
} }
@@ -192,21 +182,6 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
} }
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
// don't separate Player from this! Physics will break, esp. airborne manoeuvre
if (ingame.canPlayerControl) {
// fire world click events; the event is defined as Ingame's (or any others') WorldClick event
if (ingame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
if (button == AppLoader.getConfigInt("mouseprimary")) {
ingame.worldPrimaryClickStart(AppLoader.UPDATE_RATE.toFloat())
}
if (button == AppLoader.getConfigInt("mousesecondary")) {
ingame.worldSecondaryClickStart(AppLoader.UPDATE_RATE.toFloat())
}
}
}
ingame.uiContainer.forEach { it.touchDown(screenX, screenY, pointer, button) } ingame.uiContainer.forEach { it.touchDown(screenX, screenY, pointer, button) }
return true return true
} }

View File

@@ -1,10 +1,12 @@
package net.torvald.terrarum.itemproperties package net.torvald.terrarum.gameitem
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.random.HQRNG import net.torvald.random.HQRNG
import net.torvald.terrarum.ItemValue import net.torvald.terrarum.ItemValue
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_DYNAMIC import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_DYNAMIC
import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
@@ -12,15 +14,18 @@ import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
typealias ItemID = Int typealias ItemID = Int
/** /**
* Instances of the GameItem (e.g. net.torvald.terrarum.modulebasegame.gameitems.PickaxeCopper) are preferably referenced
* from the ```<module>/items/itemid.csv``` file only, and not from the actual game code.
*
* Created by minjaesong on 2016-01-16. * Created by minjaesong on 2016-01-16.
*/ */
abstract class GameItem : Comparable<GameItem>, Cloneable { abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneable {
abstract var dynamicID: ItemID open var dynamicID: ItemID = originalID
/** /**
* if the ID is a Actor range, it's an actor contained in a pocket. * if the ID is a Actor range, it's an actor contained in a pocket.
*/ */
abstract val originalID: ItemID // WUT?! using init does not work!! //abstract val originalID: ItemID // WUT?! using init does not work!!
/** /**
@@ -268,6 +273,7 @@ abstract class GameItem : Comparable<GameItem>, Cloneable {
@JvmStatic val BLOCK = "block" @JvmStatic val BLOCK = "block"
@JvmStatic val WALL = "wall" @JvmStatic val WALL = "wall"
@JvmStatic val WIRE = "wire" @JvmStatic val WIRE = "wire"
@JvmStatic val FIXTURE = "fixture"
@JvmStatic val MISC = "misc" @JvmStatic val MISC = "misc"
} }
@@ -281,7 +287,7 @@ abstract class GameItem : Comparable<GameItem>, Cloneable {
fun generateUniqueDynamicID(inventory: ActorInventory): GameItem { fun generateUniqueDynamicID(inventory: ActorInventory): GameItem {
dynamicID = GameItem.generateUniqueDynamicID(inventory) dynamicID = Companion.generateUniqueDynamicID(inventory)
ItemCodex.registerNewDynamicItem(dynamicID, this) ItemCodex.registerNewDynamicItem(dynamicID, this)
return this return this
} }

View File

@@ -1,8 +1,6 @@
package net.torvald.terrarum.gameworld package net.torvald.terrarum.gameworld
import com.badlogic.gdx.graphics.Color
import net.torvald.util.SortedArrayList
import net.torvald.terrarum.AppLoader.printdbg import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.blockproperties.Block
@@ -11,7 +9,8 @@ import net.torvald.terrarum.blockproperties.Fluid
import net.torvald.terrarum.modulebasegame.gameworld.WorldSimulator import net.torvald.terrarum.modulebasegame.gameworld.WorldSimulator
import net.torvald.terrarum.realestate.LandUtil import net.torvald.terrarum.realestate.LandUtil
import net.torvald.terrarum.serialise.ReadLayerDataZip import net.torvald.terrarum.serialise.ReadLayerDataZip
import net.torvald.terrarum.toInt import net.torvald.terrarum.worlddrawer.Cvec
import net.torvald.util.SortedArrayList
import org.dyn4j.geometry.Vector2 import org.dyn4j.geometry.Vector2
import kotlin.math.absoluteValue import kotlin.math.absoluteValue
import kotlin.math.sign import kotlin.math.sign
@@ -74,23 +73,24 @@ open class GameWorld {
val fluidTypes: HashMap<BlockAddress, FluidType> val fluidTypes: HashMap<BlockAddress, FluidType>
@TEMzPayload("FlFL", TEMzPayload.INT48_FLOAT_PAIR) @TEMzPayload("FlFL", TEMzPayload.INT48_FLOAT_PAIR)
val fluidFills: HashMap<BlockAddress, Float> val fluidFills: HashMap<BlockAddress, Float>
@TEMzPayload("CtYP", TEMzPayload.INT48_INT_PAIR)
val conduitTypes: HashMap<BlockAddress, Int> // 1 bit = 1 conduit (pipe/wire) type
@TEMzPayload("CfL", TEMzPayload.INT48_FLOAT_PAIR)
val conduitFills: Array<HashMap<BlockAddress, Float>>
val conduitFills0: HashMap<BlockAddress, Float> // size of liquid packet on the block
get() = conduitFills[0]
val conduitFills1: HashMap<BlockAddress, Float> // size of gas packet on the block
get() = conduitFills[1]
private val wiringNodes = SortedArrayList<WiringNode>() /**
* Single block can have multiple conduits, different types of conduits are stored separately.
*/
@TEMzPayload("WiNt", TEMzPayload.EXTERNAL_JSON)
private val wirings: HashMap<BlockAddress, SortedArrayList<WiringNode>>
/**
* Used by the renderer. When wirings are updated, `wirings` and this properties must be synchronised.
*/
private val wiringBlocks: HashMap<BlockAddress, Int>
//public World physWorld = new World( new Vec2(0, -Terrarum.game.gravitationalAccel) ); //public World physWorld = new World( new Vec2(0, -Terrarum.game.gravitationalAccel) );
//physics //physics
/** Meter per second squared. Currently only the downward gravity is supported. No reverse gravity :p */ /** Meter per second squared. Currently only the downward gravity is supported. No reverse gravity :p */
var gravitation: Vector2 = Vector2(0.0, 9.80665) var gravitation: Vector2 = Vector2(0.0, 9.80665)
/** 0.0..1.0+ */ /** 0.0..1.0+ */
var globalLight = Color(0f,0f,0f,0f) var globalLight = Cvec()
var averageTemperature = 288f // 15 deg celsius; simulates global warming var averageTemperature = 288f // 15 deg celsius; simulates global warming
@@ -114,13 +114,13 @@ open class GameWorld {
layerTerrainLowBits = PairedMapLayer(width, height) layerTerrainLowBits = PairedMapLayer(width, height)
layerWallLowBits = PairedMapLayer(width, height) layerWallLowBits = PairedMapLayer(width, height)
wallDamages = HashMap<BlockAddress, Float>() wallDamages = HashMap()
terrainDamages = HashMap<BlockAddress, Float>() terrainDamages = HashMap()
fluidTypes = HashMap<BlockAddress, FluidType>() fluidTypes = HashMap()
fluidFills = HashMap<BlockAddress, Float>() fluidFills = HashMap()
conduitTypes = HashMap<BlockAddress, Int>() wiringBlocks = HashMap()
conduitFills = Array(16) { HashMap<BlockAddress, Float>() } wirings = HashMap()
// temperature layer: 2x2 is one cell // temperature layer: 2x2 is one cell
//layerThermal = MapLayerHalfFloat(width, height, averageTemperature) //layerThermal = MapLayerHalfFloat(width, height, averageTemperature)
@@ -148,8 +148,8 @@ open class GameWorld {
fluidTypes = layerData.fluidTypes fluidTypes = layerData.fluidTypes
fluidFills = layerData.fluidFills fluidFills = layerData.fluidFills
conduitTypes = HashMap<BlockAddress, Int>() wiringBlocks = HashMap()
conduitFills = Array(16) { HashMap<BlockAddress, Float>() } wirings = HashMap()
spawnX = layerData.spawnX spawnX = layerData.spawnX
spawnY = layerData.spawnY spawnY = layerData.spawnY
@@ -210,10 +210,6 @@ open class GameWorld {
terrain * PairedMapLayer.RANGE + terrainDamage terrain * PairedMapLayer.RANGE + terrainDamage
} }
fun getWires(x: Int, y: Int): Int {
return conduitTypes.getOrDefault(LandUtil.getBlockAddr(this, x, y), 0)
}
fun getWallLowBits(x: Int, y: Int): Int? { fun getWallLowBits(x: Int, y: Int): Int? {
val (x, y) = coerceXY(x, y) val (x, y) = coerceXY(x, y)
return layerWallLowBits.getData(x, y) return layerWallLowBits.getData(x, y)
@@ -230,10 +226,11 @@ open class GameWorld {
* * * *
* @param y * @param y
* * * *
* @param combinedTilenum (tilenum * 16) + damage * @param combinedTilenum Item id of the wall block. Less-than-4096-value is permitted.
*/ */
fun setTileWall(x: Int, y: Int, combinedTilenum: Int) { fun setTileWall(x: Int, y: Int, combinedTilenum: Int) {
val (x, y) = coerceXY(x, y) val (x, y) = coerceXY(x, y)
val combinedTilenum = combinedTilenum % GameWorld.TILES_SUPPORTED // does work without this, but to be safe...
setTileWall(x, y, (combinedTilenum / PairedMapLayer.RANGE).toByte(), combinedTilenum % PairedMapLayer.RANGE) setTileWall(x, y, (combinedTilenum / PairedMapLayer.RANGE).toByte(), combinedTilenum % PairedMapLayer.RANGE)
} }
@@ -243,7 +240,7 @@ open class GameWorld {
* * * *
* @param y * @param y
* * * *
* @param combinedTilenum (tilenum * 16) + damage * @param combinedTilenum Item id of the terrain block, <4096
*/ */
fun setTileTerrain(x: Int, y: Int, combinedTilenum: Int) { fun setTileTerrain(x: Int, y: Int, combinedTilenum: Int) {
val (x, y) = coerceXY(x, y) val (x, y) = coerceXY(x, y)
@@ -291,25 +288,35 @@ open class GameWorld {
Terrarum.ingame?.queueWireChangedEvent(oldWire, tile.toUint(), LandUtil.getBlockAddr(this, x, y)) Terrarum.ingame?.queueWireChangedEvent(oldWire, tile.toUint(), LandUtil.getBlockAddr(this, x, y))
}*/ }*/
/** fun getWiringBlocks(x: Int, y: Int): Int {
* Overrides entire bits with given value. DO NOT USE THIS if you don't know what this means, you'll want to use setWire(). return wiringBlocks.getOrDefault(LandUtil.getBlockAddr(this, x, y), 0)
* Besides, this function won't fire WireChangedEvent }
*/
fun setWires(x: Int, y: Int, wireBits: Int) { fun getAllConduitsFrom(x: Int, y: Int): SortedArrayList<WiringNode>? {
val (x, y) = coerceXY(x, y) return wirings.get(LandUtil.getBlockAddr(this, x, y))
conduitTypes[LandUtil.getBlockAddr(this, x, y)] = wireBits
} }
/** /**
* Sets single bit for given tile. YOU'LL WANT TO USE THIS instead of setWires() * @param conduitTypeBit defined in net.torvald.terrarum.blockproperties.Wire, always power-of-two
* @param selectedWire wire-bit to modify, must be power of two
*/ */
fun setWire(x: Int, y: Int, selectedWire: Int, bitToSet: Boolean) { fun getConduitByTypeFrom(x: Int, y: Int, conduitTypeBit: Int): WiringNode? {
val oldWireBits = getWires(x, y) val conduits = getAllConduitsFrom(x, y)
val oldStatus = getWires(x, y) or selectedWire != 0 return conduits?.searchFor(conduitTypeBit) { it.typeBitMask }
if (oldStatus != bitToSet) { }
setWires(x, y, (oldWireBits and selectedWire.inv()) or (selectedWire * oldStatus.toInt()))
Terrarum.ingame?.queueWireChangedEvent(selectedWire * oldStatus.toInt(), selectedWire * bitToSet.toInt(), LandUtil.getBlockAddr(this, x, y)) fun addNewConduitTo(x: Int, y: Int, node: WiringNode) {
val blockAddr = LandUtil.getBlockAddr(this, x, y)
// check for existing type of conduit
// if there's no duplicate...
if (getWiringBlocks(x, y) and node.typeBitMask == 0) {
// store as-is
wirings.getOrPut(blockAddr) { SortedArrayList() }.add(node)
// synchronise wiringBlocks
wiringBlocks[blockAddr] = (wiringBlocks[blockAddr] ?: 0) or node.typeBitMask
}
else {
TODO("need overwriting policy for existing conduit node")
} }
} }
@@ -321,7 +328,7 @@ open class GameWorld {
return getTileFromWall(x, y) return getTileFromWall(x, y)
} }
else if (mode == WIRE) { else if (mode == WIRE) {
return getWires(x, y) return getWiringBlocks(x, y)
} }
else else
throw IllegalArgumentException("illegal mode input: " + mode.toString()) throw IllegalArgumentException("illegal mode input: " + mode.toString())
@@ -482,12 +489,17 @@ open class GameWorld {
override fun toString() = "Fluid type: ${type.value}, amount: $amount" override fun toString() = "Fluid type: ${type.value}, amount: $amount"
} }
private data class WiringNode( /**
* Connection rules: connect to all nearby, except:
*
* If the wire allows 3- or 4-way connection, make such connection.
* If the wire does not allow them (e.g. wire bridge, thicknet), connect top-bottom and left-right nodes.
*/
data class WiringNode(
val position: BlockAddress, val position: BlockAddress,
/** One defined in WireCodex, always power of two */ /** One defined in WireCodex, always power of two */
val typeBitMask: Int, val typeBitMask: Int,
var fills: Float = 0f, var fills: Float = 0f
var connectedNodes: ArrayList<WiringNode>
) : Comparable<WiringNode> { ) : Comparable<WiringNode> {
override fun compareTo(other: WiringNode): Int { override fun compareTo(other: WiringNode): Int {
return (this.position - other.position).sign return (this.position - other.position).sign
@@ -535,6 +547,9 @@ inline class FluidType(val value: Int) {
*/ */
annotation class TEMzPayload(val payloadName: String, val arg: Int) { annotation class TEMzPayload(val payloadName: String, val arg: Int) {
companion object { companion object {
const val EXTERNAL_JAVAPROPERTIES = -3
const val EXTERNAL_CSV = -2
const val EXTERNAL_JSON = -1
const val EIGHT_MSB = 0 const val EIGHT_MSB = 0
const val FOUR_LSB = 1 const val FOUR_LSB = 1
const val INT48_FLOAT_PAIR = 2 const val INT48_FLOAT_PAIR = 2

View File

@@ -5,6 +5,8 @@ import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.AppLoader.printdbg import net.torvald.terrarum.AppLoader.printdbg
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.ItemID
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameactors.CanBeAnItem import net.torvald.terrarum.modulebasegame.gameactors.CanBeAnItem
@@ -174,9 +176,7 @@ object ItemCodex {
// test water bucket // test water bucket
itemCodex[9000] = object : GameItem() { itemCodex[9000] = object : GameItem(9000) {
override var dynamicID: ItemID = 9000
override val originalID: ItemID = 9000
override val isUnique: Boolean = true override val isUnique: Boolean = true
override val originalName: String = "Infinite Water Bucket" override val originalName: String = "Infinite Water Bucket"
@@ -203,9 +203,7 @@ object ItemCodex {
// test lava bucket // test lava bucket
itemCodex[9001] = object : GameItem() { itemCodex[9001] = object : GameItem(9001) {
override var dynamicID: ItemID = 9001
override val originalID: ItemID = 9001
override val isUnique: Boolean = true override val isUnique: Boolean = true
override val originalName: String = "Infinite Lava Bucket" override val originalName: String = "Infinite Lava Bucket"

View File

@@ -10,7 +10,7 @@ import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.blockproperties.BlockPropUtil import net.torvald.terrarum.blockproperties.BlockPropUtil
import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.itemproperties.ItemID import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.modulebasegame.gameworld.WorldTime import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
@@ -27,6 +27,7 @@ import net.torvald.terrarum.serialise.toULittle48
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UINSMenu import net.torvald.terrarum.ui.UINSMenu
import net.torvald.terrarum.worlddrawer.CreateTileAtlas.TILE_SIZE import net.torvald.terrarum.worlddrawer.CreateTileAtlas.TILE_SIZE
import net.torvald.terrarum.worlddrawer.Cvec
import net.torvald.terrarum.worlddrawer.LightmapRenderer import net.torvald.terrarum.worlddrawer.LightmapRenderer
import net.torvald.terrarum.worlddrawer.WorldCamera import net.torvald.terrarum.worlddrawer.WorldCamera
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
@@ -137,7 +138,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
internal var showSelection = true internal var showSelection = true
val blockPointingCursor = object : ActorWithBody(Actor.RenderOrder.OVERLAY) { val blockPointingCursor = object : ActorWithBody(Actor.RenderOrder.OVERLAY) {
override var referenceID: ActorID? = 1048575 // custom refID override var referenceID: ActorID = 1048575 // custom refID
override val hitbox = Hitbox(0.0, 0.0, 16.0, 16.0) override val hitbox = Hitbox(0.0, 0.0, 16.0, 16.0)
@@ -177,7 +178,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
private var _testMarkerDrawCalls = 0L private var _testMarkerDrawCalls = 0L
private fun generateNewBlockMarkerVisible(x: Int, y: Int) = object : ActorWithBody(Actor.RenderOrder.OVERLAY) { private fun generateNewBlockMarkerVisible(x: Int, y: Int) = object : ActorWithBody(Actor.RenderOrder.OVERLAY) {
override var referenceID: ActorID? = blockPosToRefID(x, y) // custom refID override var referenceID: ActorID = blockPosToRefID(x, y) // custom refID
override val hitbox = Hitbox(x * 16.0, y * 16.0, 16.0, 16.0) override val hitbox = Hitbox(x * 16.0, y * 16.0, 16.0, 16.0)
override fun drawBody(batch: SpriteBatch) { override fun drawBody(batch: SpriteBatch) {
@@ -279,7 +280,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
init { init {
gameWorld.time.setTimeOfToday(WorldTime.HOUR_SEC * 10) gameWorld.time.setTimeOfToday(WorldTime.HOUR_SEC * 10)
gameWorld.globalLight = Color(.8f,.8f,.8f,.8f) gameWorld.globalLight = Cvec(.8f)
essentialOverlays.add(blockPointingCursor) essentialOverlays.add(blockPointingCursor)

View File

@@ -1,13 +1,15 @@
package net.torvald.terrarum.modulebasegame package net.torvald.terrarum.modulebasegame
import net.torvald.terrarum.* 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.ModMgr
import net.torvald.terrarum.ModuleEntryPoint
import net.torvald.terrarum.blockproperties.BlockCodex import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.itemproperties.MaterialCodex import net.torvald.terrarum.itemproperties.MaterialCodex
import net.torvald.terrarum.modulebasegame.gameitems.BlockBase
import net.torvald.terrarum.modulebasegame.imagefont.WatchFont import net.torvald.terrarum.modulebasegame.imagefont.WatchFont
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
@@ -54,9 +56,7 @@ class EntryPoint : ModuleEntryPoint() {
val blockProp = BlockCodex.getOrNull(i % ItemCodex.ITEM_WALLS.first) val blockProp = BlockCodex.getOrNull(i % ItemCodex.ITEM_WALLS.first)
if (blockProp != null) { if (blockProp != null) {
ItemCodex.itemCodex[i] = object : GameItem() { ItemCodex.itemCodex[i] = object : GameItem(i) {
override val originalID = i
override var dynamicID = i
override val isUnique: Boolean = false override val isUnique: Boolean = false
override var baseMass: Double = blockProp.density / 1000.0 override var baseMass: Double = blockProp.density / 1000.0
override var baseToolSize: Double? = null override var baseToolSize: Double? = null
@@ -74,48 +74,11 @@ class EntryPoint : ModuleEntryPoint() {
} }
override fun startPrimaryUse(delta: Float): Boolean { override fun startPrimaryUse(delta: Float): Boolean {
val ingame = Terrarum.ingame!! as Ingame return BlockBase.blockStartPrimaryUse(this, i, delta)
}
val mousePoint = Point2d(Terrarum.mouseTileX.toDouble(), Terrarum.mouseTileY.toDouble()) override fun effectWhenEquipped(delta: Float) {
BlockBase.blockEffectWhenEquipped(delta)
// check for collision with actors (BLOCK only)
if (this.inventoryCategory == Category.BLOCK) {
var ret1 = true
ingame.actorContainerActive.forEach {
if (it is ActorWBMovable && it.hIntTilewiseHitbox.intersects(mousePoint))
ret1 = false // return is not allowed here
}
if (!ret1) return ret1
}
// return false if the tile is already there
if (this.inventoryCategory == Category.BLOCK &&
this.dynamicID == ingame.world.getTileFromTerrain(Terrarum.mouseTileX, Terrarum.mouseTileY) ||
this.inventoryCategory == Category.WALL &&
this.dynamicID - ItemCodex.ITEM_WALLS.start == ingame.world.getTileFromWall(Terrarum.mouseTileX, Terrarum.mouseTileY) ||
this.inventoryCategory == Category.WIRE &&
1.shl(this.dynamicID - ItemCodex.ITEM_WIRES.start) and (ingame.world.getWires(Terrarum.mouseTileX, Terrarum.mouseTileY) ?: 0) != 0
)
return false
// filter passed, do the job
// FIXME this is only useful for Player
if (i in ItemCodex.ITEM_TILES) {
ingame.world.setTileTerrain(
Terrarum.mouseTileX,
Terrarum.mouseTileY,
i
)
}
else {
ingame.world.setTileWall(
Terrarum.mouseTileX,
Terrarum.mouseTileY,
i
)
}
return true
} }
} }
} }

View File

@@ -15,7 +15,7 @@ import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.ActorWithBody import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gamecontroller.IngameController import net.torvald.terrarum.gamecontroller.IngameController
import net.torvald.terrarum.gamecontroller.KeyToggler import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.console.AVTracker import net.torvald.terrarum.modulebasegame.console.AVTracker
import net.torvald.terrarum.modulebasegame.console.ActorsList import net.torvald.terrarum.modulebasegame.console.ActorsList
@@ -394,7 +394,9 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
override fun worldPrimaryClickStart(delta: Float) { override fun worldPrimaryClickStart(delta: Float) {
val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP) val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
ItemCodex[itemOnGrip]?.startPrimaryUse(delta) val consumptionSuccessful = ItemCodex[itemOnGrip]?.startPrimaryUse(delta) ?: false
if (consumptionSuccessful)
actorNowPlaying?.inventory?.consumeItem(ItemCodex[itemOnGrip]!!)
} }
override fun worldPrimaryClickEnd(delta: Float) { override fun worldPrimaryClickEnd(delta: Float) {
@@ -404,7 +406,9 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
override fun worldSecondaryClickStart(delta: Float) { override fun worldSecondaryClickStart(delta: Float) {
val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP) val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
ItemCodex[itemOnGrip]?.startSecondaryUse(delta) val consumptionSuccessful = ItemCodex[itemOnGrip]?.startSecondaryUse(delta) ?: false
if (consumptionSuccessful)
actorNowPlaying?.inventory?.consumeItem(ItemCodex[itemOnGrip]!!)
} }
override fun worldSecondaryClickEnd(delta: Float) { override fun worldSecondaryClickEnd(delta: Float) {
@@ -747,8 +751,8 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
if (actor.referenceID == theRealGamer.referenceID || actor.referenceID == 0x51621D) // do not delete this magic if (actor.referenceID == theRealGamer.referenceID || actor.referenceID == 0x51621D) // do not delete this magic
throw RuntimeException("Attempted to remove player.") throw RuntimeException("Attempted to remove player.")
val indexToDelete = actorContainerActive.binarySearch(actor.referenceID!!) val indexToDelete = actorContainerActive.searchForIndex(actor.referenceID!!) { it.referenceID!! }
if (indexToDelete >= 0) { if (indexToDelete != null) {
printdbg(this, "Removing actor $actor") printdbg(this, "Removing actor $actor")
printStackTrace() printStackTrace()
@@ -783,6 +787,28 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
} }
} }
private fun ArrayList<*>.binarySearch(actor: Actor) = this.binarySearch(actor.referenceID!!)
private fun ArrayList<*>.binarySearch(ID: Int): Int {
// code from collections/Collections.kt
var low = 0
var high = this.size - 1
while (low <= high) {
val mid = (low + high).ushr(1) // safe from overflows
val midVal = get(mid)!!
if (ID > midVal.hashCode())
low = mid + 1
else if (ID < midVal.hashCode())
high = mid - 1
else
return mid // key found
}
return -(low + 1) // key not found
}
/** /**
* Check for duplicates, append actor and sort the list * Check for duplicates, append actor and sort the list
*/ */

View File

@@ -94,7 +94,7 @@ object IngameRenderer {
LightmapRenderer.fireRecalculateEvent(actorsRenderBehind, actorsRenderFront, actorsRenderMidTop, actorsRenderMiddle, actorsRenderOverlay) LightmapRenderer.fireRecalculateEvent(actorsRenderBehind, actorsRenderFront, actorsRenderMidTop, actorsRenderMiddle, actorsRenderOverlay)
prepLightmapRGBA() prepLightmapRGBA()
BlocksDrawer.renderData(selectedWireBitToDraw) BlocksDrawer.renderData()
drawToRGB(actorsRenderBehind, actorsRenderMiddle, actorsRenderMidTop, actorsRenderFront, particlesContainer) drawToRGB(actorsRenderBehind, actorsRenderMiddle, actorsRenderMidTop, actorsRenderFront, particlesContainer)
drawToA(actorsRenderBehind, actorsRenderMiddle, actorsRenderMidTop, actorsRenderFront, particlesContainer) drawToA(actorsRenderBehind, actorsRenderMiddle, actorsRenderMidTop, actorsRenderFront, particlesContainer)
drawOverlayActors(actorsRenderOverlay) drawOverlayActors(actorsRenderOverlay)
@@ -214,9 +214,6 @@ object IngameRenderer {
// works but some UI elements have wrong transparency -> should be fixed with Terrarum.gdxCleanAndSetBlend -- Torvald 2019-01-12 // works but some UI elements have wrong transparency -> should be fixed with Terrarum.gdxCleanAndSetBlend -- Torvald 2019-01-12
blendNormal(batch) blendNormal(batch)
batch.color = Color.WHITE batch.color = Color.WHITE
selectedWireBitToDraw = 0
} }

View File

@@ -1,20 +1,20 @@
package net.torvald.terrarum.modulebasegame.gameactors package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color
import com.jme3.math.FastMath import com.jme3.math.FastMath
import net.torvald.spriteanimation.HasAssembledSprite import net.torvald.spriteanimation.HasAssembledSprite
import net.torvald.terrarum.* import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameactors.faction.Faction import net.torvald.terrarum.gameactors.faction.Faction
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.itemproperties.Material import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameworld.time_t import net.torvald.terrarum.modulebasegame.gameworld.time_t
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull
import net.torvald.terrarum.realestate.LandUtil import net.torvald.terrarum.realestate.LandUtil
import net.torvald.terrarum.worlddrawer.Cvec
import net.torvald.terrarum.worlddrawer.LightmapRenderer import net.torvald.terrarum.worlddrawer.LightmapRenderer
import org.dyn4j.geometry.Vector2 import org.dyn4j.geometry.Vector2
import java.util.* import java.util.*
@@ -68,18 +68,18 @@ open class ActorHumanoid(
if (houseDesignation != null) houseDesignation!!.clear() if (houseDesignation != null) houseDesignation!!.clear()
} }
override var color: Color override var color: Cvec
get() = Color( get() = Cvec(
(actorValue.getAsFloat(AVKey.LUMR) ?: 0f) / LightmapRenderer.MUL_FLOAT, (actorValue.getAsFloat(AVKey.LUMR) ?: 0f) / LightmapRenderer.MUL_FLOAT,
(actorValue.getAsFloat(AVKey.LUMG) ?: 0f) / LightmapRenderer.MUL_FLOAT, (actorValue.getAsFloat(AVKey.LUMG) ?: 0f) / LightmapRenderer.MUL_FLOAT,
(actorValue.getAsFloat(AVKey.LUMB) ?: 0f) / LightmapRenderer.MUL_FLOAT, (actorValue.getAsFloat(AVKey.LUMB) ?: 0f) / LightmapRenderer.MUL_FLOAT,
(actorValue.getAsFloat(AVKey.LUMA) ?: 0f) / LightmapRenderer.MUL_FLOAT (actorValue.getAsFloat(AVKey.LUMA) ?: 0f) / LightmapRenderer.MUL_FLOAT
) )
set(value) { set(value) {
actorValue[AVKey.LUMR] = value.r * LightmapRenderer.MUL_FLOAT actorValue[AVKey.LUMR] = value.vec.lane(0) * LightmapRenderer.MUL_FLOAT
actorValue[AVKey.LUMG] = value.g * LightmapRenderer.MUL_FLOAT actorValue[AVKey.LUMG] = value.vec.lane(1) * LightmapRenderer.MUL_FLOAT
actorValue[AVKey.LUMB] = value.b * LightmapRenderer.MUL_FLOAT actorValue[AVKey.LUMB] = value.vec.lane(2) * LightmapRenderer.MUL_FLOAT
actorValue[AVKey.LUMA] = value.a * LightmapRenderer.MUL_FLOAT actorValue[AVKey.LUMA] = value.vec.lane(3) * LightmapRenderer.MUL_FLOAT
} }
/** /**
@@ -154,9 +154,7 @@ open class ActorHumanoid(
get() = if (Terrarum.ingame == null) false else this == Terrarum.ingame!!.actorNowPlaying get() = if (Terrarum.ingame == null) false else this == Terrarum.ingame!!.actorNowPlaying
@Transient private val nullItem = object : GameItem() { @Transient private val nullItem = object : GameItem(0) {
override var dynamicID: Int = 0
override val originalID = dynamicID
override val isUnique: Boolean = false override val isUnique: Boolean = false
override var baseMass: Double = 0.0 override var baseMass: Double = 0.0
override var baseToolSize: Double? = null override var baseToolSize: Double? = null

View File

@@ -5,11 +5,11 @@ import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.BlockCodex import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.Actor import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_DYNAMIC import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_DYNAMIC
import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_WALLS import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_WALLS
import net.torvald.terrarum.itemproperties.ItemID import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.lock import net.torvald.terrarum.lock
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar
@@ -177,7 +177,9 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c
false false
fun consumeItem(actor: Actor, item: GameItem) { fun consumeItem(item: GameItem) {
val actor = this.actor as Actor
if (item.stackable && !item.isDynamic) { if (item.stackable && !item.isDynamic) {
remove(item, 1) remove(item, 1)
} }

View File

@@ -1,6 +1,6 @@
package net.torvald.terrarum.modulebasegame.gameactors package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.gameitem.GameItem
/** /**
* Created by minjaesong on 2016-01-31. * Created by minjaesong on 2016-01-31.

View File

@@ -3,7 +3,7 @@ package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.blockproperties.BlockCodex import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
/** /**

View File

@@ -27,10 +27,11 @@ open class FixtureBase(val blockBox: BlockBox, val blockBoxProps: BlockBoxProps
/** /**
* Adds this instance of the fixture to the world * Adds this instance of the fixture to the world
* *
* @param posX top-left position of the fixture, tile-wise * @param posX tile-wise top-left position of the fixture
* @param posY top-left position of the fixture, tile-wise * @param posY tile-wise top-left position of the fixture
* @return true if successfully spawned, false if was not (e.g. occupied space)
*/ */
open fun spawn(posX: Int, posY: Int) { open fun spawn(posX: Int, posY: Int): Boolean {
// place filler blocks // place filler blocks
// place the filler blocks where: // place the filler blocks where:
// origin posX: centre-left if mouseX is on the right-half of the game window, // origin posX: centre-left if mouseX is on the right-half of the game window,
@@ -52,6 +53,9 @@ open class FixtureBase(val blockBox: BlockBox, val blockBoxProps: BlockBoxProps
this.isVisible = true this.isVisible = true
this.hitbox.setFromWidthHeight(posX * TSIZE, posY * TSIZE, blockBox.width * TSIZE, blockBox.height * TSIZE) this.hitbox.setFromWidthHeight(posX * TSIZE, posY * TSIZE, blockBox.width * TSIZE, blockBox.height * TSIZE)
return true // TODO for the tests' sake, just get fucking spawned
} }
/** /**

View File

@@ -1,12 +1,12 @@
package net.torvald.terrarum.modulebasegame.gameactors package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.graphics.Color
import net.torvald.terrarum.ModMgr import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.Hitbox import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameactors.Luminous import net.torvald.terrarum.gameactors.Luminous
import net.torvald.terrarum.worlddrawer.Cvec
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import java.util.* import java.util.*
@@ -17,7 +17,7 @@ internal class FixtureTikiTorch : FixtureBase(
BlockBox(BlockBox.NO_COLLISION, 1, 2) BlockBox(BlockBox.NO_COLLISION, 1, 2)
), Luminous { ), Luminous {
override var color: Color override var color: Cvec
get() = BlockCodex[Block.TORCH].luminosity get() = BlockCodex[Block.TORCH].luminosity
set(value) { set(value) {
throw UnsupportedOperationException() throw UnsupportedOperationException()

View File

@@ -4,7 +4,7 @@ import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AIControlled import net.torvald.terrarum.gameactors.AIControlled
import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ai.ActorAI import net.torvald.terrarum.gameactors.ai.ActorAI
import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.Material import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.modulebasegame.gameworld.time_t import net.torvald.terrarum.modulebasegame.gameworld.time_t
@@ -16,8 +16,8 @@ import net.torvald.terrarum.modulebasegame.gameworld.time_t
open class HumanoidNPC( open class HumanoidNPC(
override val ai: ActorAI, // it's there for written-in-Kotlin, "hard-wired" AIs override val ai: ActorAI, // it's there for written-in-Kotlin, "hard-wired" AIs
born: time_t, born: time_t,
usePhysics: Boolean = true, usePhysics: Boolean = true
forceAssignRefID: Int? = null //forceAssignRefID: Int? = null
) : ActorHumanoid(born, usePhysics = usePhysics), AIControlled, CanBeAnItem { ) : ActorHumanoid(born, usePhysics = usePhysics), AIControlled, CanBeAnItem {
companion object { companion object {
@@ -29,9 +29,7 @@ open class HumanoidNPC(
} }
// we're having GameItem data so that this class could be somewhat universal // we're having GameItem data so that this class could be somewhat universal
override var itemData: GameItem = object : GameItem() { override var itemData: GameItem = object : GameItem(referenceID) {//GameItem(referenceID ?: forceAssignRefID!!) {
override var dynamicID = referenceID ?: forceAssignRefID!!
override val originalID = dynamicID
override val isUnique = true override val isUnique = true
override var baseMass: Double override var baseMass: Double
get() = actorValue.getAsDouble(AVKey.BASEMASS)!! get() = actorValue.getAsDouble(AVKey.BASEMASS)!!

View File

@@ -11,7 +11,11 @@ import net.torvald.terrarum.modulebasegame.gameworld.time_t
* Created by minjaesong on 2015-12-31. * Created by minjaesong on 2015-12-31.
*/ */
class IngamePlayer(override var animDescPath: String, born: time_t) : ActorHumanoid(born), HasAssembledSprite { class IngamePlayer(
override var animDescPath: String,
override var animDescPathGlow: String? = null,
born: time_t
) : ActorHumanoid(born), HasAssembledSprite {
/** /**
* Creates new Player instance with empty elements (sprites, actorvalue, etc.). * Creates new Player instance with empty elements (sprites, actorvalue, etc.).

View File

@@ -13,7 +13,7 @@ object PlayerBuilder {
operator fun invoke(): Actor { operator fun invoke(): Actor {
val world = (Terrarum.ingame!! as Ingame).gameworld val world = (Terrarum.ingame!! as Ingame).gameworld
val p: Actor = IngamePlayer("lol", world.time.TIME_T) val p: Actor = IngamePlayer("lol", "lol_glow", world.time.TIME_T)
InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json") InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json")
// attach sprite // attach sprite

View File

@@ -14,7 +14,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
object PlayerBuilderSigrid { object PlayerBuilderSigrid {
operator fun invoke(): IngamePlayer { operator fun invoke(): IngamePlayer {
val p = IngamePlayer("lol", - 9223372036854775807L) // XD val p = IngamePlayer("lol", "lol_glow", - 9223372036854775807L) // XD
p.referenceID = 0x51621D // the only constant of this procedural universe p.referenceID = 0x51621D // the only constant of this procedural universe
@@ -82,10 +82,13 @@ object PlayerBuilderSigrid {
} }
} }
// item ids are defined in <module>/items/itemid.csv
inventory.add(8448) // copper pick inventory.add(8448) // copper pick
inventory.add(8449) // iron pick inventory.add(8449) // iron pick
inventory.add(8450) // steel pick inventory.add(8450) // steel pick
inventory.add(8466) // wire piece inventory.add(8466, 9995) // wire piece
inventory.add(8467, 9995) // test tiki torch
inventory.add(9000) // TEST water bucket inventory.add(9000) // TEST water bucket
inventory.add(9001) // TEST lava bucket inventory.add(9001) // TEST lava bucket
} }

View File

@@ -4,14 +4,17 @@ import net.torvald.spriteanimation.SpriteAnimation
import net.torvald.terrarum.ModMgr import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.worlddrawer.CreateTileAtlas import net.torvald.terrarum.worlddrawer.CreateTileAtlas
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
/** /**
* Created by minjaesong on 2017-02-10. * Created by minjaesong on 2017-02-10.
*/ */
object PlayerBuilderTestSubject1 { object PlayerBuilderTestSubject1 {
operator fun invoke(): IngamePlayer { operator fun invoke(): IngamePlayer {
val p: IngamePlayer = IngamePlayer(ModMgr.getPath("basegame", "sprites/test_sprite.properties"), -589141658L) // random value thrown val p: IngamePlayer = IngamePlayer(
ModMgr.getPath("basegame", "sprites/furry_sprite.properties"),
ModMgr.getPath("basegame", "sprites/furry_sprite_glow.properties"),
-589141658L // random value thrown
)
InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json") InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json")
@@ -26,7 +29,8 @@ object PlayerBuilderTestSubject1 {
p.sprite!!.setRowsAndFrames(2, 4)*/ p.sprite!!.setRowsAndFrames(2, 4)*/
p.sprite = SpriteAnimation(p) p.sprite = SpriteAnimation(p)
p.reassembleSprite(p.sprite!!) p.spriteGlow = SpriteAnimation(p)
p.reassembleSprite(p.sprite!!, p.spriteGlow)
p.setHitboxDimension(15, p.actorValue.getAsInt(AVKey.BASEHEIGHT) ?: ActorHumanoid.BASE_HEIGHT, 21, 0) p.setHitboxDimension(15, p.actorValue.getAsInt(AVKey.BASEHEIGHT) ?: ActorHumanoid.BASE_HEIGHT, 21, 0)
p.setPosition(3.0 * CreateTileAtlas.TILE_SIZE, 3.0 * CreateTileAtlas.TILE_SIZE) p.setPosition(3.0 * CreateTileAtlas.TILE_SIZE, 3.0 * CreateTileAtlas.TILE_SIZE)
@@ -34,10 +38,10 @@ object PlayerBuilderTestSubject1 {
PlayerBuilderSigrid.fillTestInventory(p.inventory) PlayerBuilderSigrid.fillTestInventory(p.inventory)
p.actorValue[AVKey.LUMR] = 0.84 //p.actorValue[AVKey.LUMR] = 0.84
p.actorValue[AVKey.LUMG] = 0.93 //p.actorValue[AVKey.LUMG] = 0.93
p.actorValue[AVKey.LUMB] = 1.37 //p.actorValue[AVKey.LUMB] = 1.37
p.actorValue[AVKey.LUMA] = 1.93 //p.actorValue[AVKey.LUMA] = 1.93
return p return p
} }

View File

@@ -1,10 +1,9 @@
package net.torvald.terrarum.modulebasegame.gameactors package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.AppLoader import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.gameactors.Actor import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.itemproperties.ItemID import net.torvald.terrarum.gameitem.ItemID
/** /**
* Created by minjaesong on 2016-01-15. * Created by minjaesong on 2016-01-15.
@@ -79,15 +78,4 @@ interface Pocketed {
fun hasItem(item: GameItem) = inventory.contains(item.dynamicID) fun hasItem(item: GameItem) = inventory.contains(item.dynamicID)
fun hasItem(id: Int) = inventory.contains(id) fun hasItem(id: Int) = inventory.contains(id)
fun consumePrimary(item: GameItem) {
if (item.startPrimaryUse(AppLoader.UPDATE_RATE.toFloat())) {
inventory.consumeItem(this as Actor, item) // consume on successful
}
}
fun consumeSecondary(item: GameItem) {
if (item.startSecondaryUse(AppLoader.UPDATE_RATE.toFloat()))
inventory.consumeItem(this as Actor, item) // consume on successful
}
} }

View File

@@ -9,6 +9,7 @@ import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameactors.Hitbox import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameactors.Luminous import net.torvald.terrarum.gameactors.Luminous
import net.torvald.terrarum.worlddrawer.Cvec
import org.dyn4j.geometry.Vector2 import org.dyn4j.geometry.Vector2
import java.util.* import java.util.*
@@ -31,8 +32,8 @@ open class ProjectileSimple(
val speed: Int val speed: Int
override var color: Color override var color: Cvec
get() = (bulletDatabase[type][OFFSET_LUMINOSITY] as Color).cpy() get() = (bulletDatabase[type][OFFSET_LUMINOSITY] as Cvec)
set(value) { set(value) {
} }
/** /**
@@ -118,8 +119,8 @@ open class ProjectileSimple(
val OFFSET_LUMINOSITY = 4 val OFFSET_LUMINOSITY = 4
val bulletDatabase = arrayOf( val bulletDatabase = arrayOf(
// damage, display colour, no gravity, speed // damage, display colour, no gravity, speed
arrayOf(7, Color(0xFF5429_FF.toInt()), true, 40, 32), arrayOf(7, Cvec(1f, .329f, .161f, 1f), true, 40, 32),
arrayOf(8, Color(0xFF5429_FF.toInt()), true, 20, 0) arrayOf(8, Cvec(1f, .329f, .161f, 1f), true, 20, 0)
// ... // ...
) )
} }

View File

@@ -1,10 +1,9 @@
package net.torvald.terrarum.modulebasegame.gameactors package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.graphics.Color
import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameactors.Hitbox import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameactors.Luminous import net.torvald.terrarum.gameactors.Luminous
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.worlddrawer.Cvec
/** /**
* Created by minjaesong on 2016-04-26. * Created by minjaesong on 2016-04-26.
@@ -21,7 +20,7 @@ class WeaponSwung(val itemID: Int) : ActorWBMovable(RenderOrder.MIDTOP), Luminou
actorValue[AVKey.LUMINOSITY] = value actorValue[AVKey.LUMINOSITY] = value
} }
*/ */
override var color: Color override var color: Cvec
get() = throw UnsupportedOperationException() get() = throw UnsupportedOperationException()
set(value) { set(value) {
} }

View File

@@ -0,0 +1,97 @@
package net.torvald.terrarum.modulebasegame.gameitems
import net.torvald.terrarum.Point2d
import net.torvald.terrarum.Point2i
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.IngameRenderer
import net.torvald.terrarum.realestate.LandUtil
/**
* Created by minjaesong on 2019-05-02.
*/
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(gameItem: GameItem, itemID: Int, delta: Float): Boolean {
val ingame = Terrarum.ingame!! as Ingame
val mousePoint = Point2d(Terrarum.mouseTileX.toDouble(), Terrarum.mouseTileY.toDouble())
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
// check for collision with actors (BLOCK only)
if (gameItem.inventoryCategory == GameItem.Category.BLOCK) {
var ret1 = true
ingame.actorContainerActive.forEach {
if (it is ActorWBMovable && it.hIntTilewiseHitbox.intersects(mousePoint))
ret1 = false // return is not allowed here
}
if (!ret1) return ret1
}
// return false if the tile is already there
if (gameItem.inventoryCategory == GameItem.Category.BLOCK &&
gameItem.dynamicID == ingame.world.getTileFromTerrain(mouseTile.x, mouseTile.y) ||
gameItem.inventoryCategory == GameItem.Category.WALL &&
gameItem.dynamicID - ItemCodex.ITEM_WALLS.start == ingame.world.getTileFromWall(mouseTile.x, mouseTile.y)
)
return false
// filter passed, do the job
// FIXME this is only useful for Player
if (itemID in ItemCodex.ITEM_TILES) {
ingame.world.setTileTerrain(
mouseTile.x,
mouseTile.y,
itemID
)
}
else {
ingame.world.setTileWall(
mouseTile.x,
mouseTile.y,
itemID
)
}
return true
}
fun blockEffectWhenEquipped(delta: Float) {
IngameRenderer.selectedWireBitToDraw = 0
}
fun wireStartPrimaryUse(gameItem: GameItem, wireTypeBit: Int, delta: Float): Boolean {
val ingame = Terrarum.ingame!! as Ingame
val mouseTile = Point2i(Terrarum.mouseTileX, Terrarum.mouseTileY)
// return false if the tile is already there
if (ingame.world.getWiringBlocks(mouseTile.x, mouseTile.y) and wireTypeBit != 0)
return false
// filter passed, do the job
// FIXME this is only useful for Player
ingame.world.addNewConduitTo(
mouseTile.x,
mouseTile.y,
GameWorld.WiringNode(
LandUtil.getBlockAddr(ingame.world, mouseTile.x, mouseTile.y),
wireTypeBit,
0f
)
)
return true
}
fun wireEffectWhenEquipped(typebit: Int, delta: Float) {
IngameRenderer.selectedWireBitToDraw = typebit
}
}

View File

@@ -1,4 +1,4 @@
package net.torvald.terrarum.modulebasegame.items 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.AppLoader
@@ -7,13 +7,13 @@ import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.itemproperties.Calculate import net.torvald.terrarum.itemproperties.Calculate
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemID
import net.torvald.terrarum.itemproperties.MaterialCodex import net.torvald.terrarum.itemproperties.MaterialCodex
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.items.PickaxeCore.BASE_MASS_AND_SIZE import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.BASE_MASS_AND_SIZE
import net.torvald.terrarum.modulebasegame.items.PickaxeCore.TOOL_DURABILITY_BASE import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.TOOL_DURABILITY_BASE
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import kotlin.math.roundToInt import kotlin.math.roundToInt
@@ -74,9 +74,8 @@ object PickaxeCore {
/** /**
* Created by minjaesong on 2017-07-17. * Created by minjaesong on 2017-07-17.
*/ */
class PickaxeCopper(override val originalID: ItemID) : GameItem() { class PickaxeCopper(originalID: ItemID) : GameItem(originalID) {
override var dynamicID: ItemID = originalID
override val originalName = "PACKAGED_PICK" override val originalName = "PACKAGED_PICK"
override var baseToolSize: Double? = BASE_MASS_AND_SIZE override var baseToolSize: Double? = BASE_MASS_AND_SIZE
override var stackable = true override var stackable = true
@@ -102,9 +101,8 @@ class PickaxeCopper(override val originalID: ItemID) : GameItem() {
/** /**
* Created by minjaesong on 2019-03-10. * Created by minjaesong on 2019-03-10.
*/ */
class PickaxeIron(override val originalID: ItemID) : GameItem() { class PickaxeIron(originalID: ItemID) : GameItem(originalID) {
override var dynamicID: ItemID = originalID
override val originalName = "PACKAGED_PICK" override val originalName = "PACKAGED_PICK"
override var baseToolSize: Double? = BASE_MASS_AND_SIZE override var baseToolSize: Double? = BASE_MASS_AND_SIZE
override var stackable = true override var stackable = true
@@ -130,9 +128,8 @@ class PickaxeIron(override val originalID: ItemID) : GameItem() {
/** /**
* Created by minjaesong on 2019-03-10. * Created by minjaesong on 2019-03-10.
*/ */
class PickaxeSteel(override val originalID: ItemID) : GameItem() { class PickaxeSteel(originalID: ItemID) : GameItem(originalID) {
override var dynamicID: ItemID = originalID
override val originalName = "PACKAGED_PICK" override val originalName = "PACKAGED_PICK"
override var baseToolSize: Double? = BASE_MASS_AND_SIZE override var baseToolSize: Double? = BASE_MASS_AND_SIZE
override var stackable = true override var stackable = true

View File

@@ -0,0 +1,34 @@
package net.torvald.terrarum.modulebasegame.gameitems
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.modulebasegame.gameactors.FixtureTikiTorch
/**
* Created by minjaesong on 2019-05-16.
*/
class TikiTorchTester(originalID: ItemID) : GameItem(originalID) {
override var dynamicID: ItemID = originalID
override val originalName = "Tiki Torch"
override var baseMass = 1.0
override var stackable = true
override var inventoryCategory = Category.FIXTURE
override val isUnique = false
override val isDynamic = false
override val material = Material()
override val itemImage: TextureRegion?
get() = AppLoader.resourcePool.getAsTextureRegion("itemplaceholder_48")
override var baseToolSize: Double? = baseMass
override fun startPrimaryUse(delta: Float): Boolean {
val torch = FixtureTikiTorch()
return torch.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - torch.blockBox.height + 1)
// return true when placed, false when cannot be placed
}
}

View File

@@ -1,8 +1,9 @@
package net.torvald.terrarum.modulebasegame.items package net.torvald.terrarum.modulebasegame.gameitems
import net.torvald.random.Fudge3 import net.torvald.random.Fudge3
import net.torvald.random.HQRNG import net.torvald.random.HQRNG
import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import kotlin.math.pow import kotlin.math.pow
@@ -24,6 +25,6 @@ object WeaponMeleeCore {
} }
abstract class WeaponMeleeBase : GameItem() { abstract class WeaponMeleeBase(originalID: ItemID) : GameItem(originalID) {
abstract val velocityMod: Double abstract val velocityMod: Double
} }

View File

@@ -1,18 +1,16 @@
package net.torvald.terrarum.modulebasegame.items 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.AppLoader
import net.torvald.terrarum.blockproperties.Wire import net.torvald.terrarum.blockproperties.Wire
import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.ItemID import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.itemproperties.Material import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.modulebasegame.IngameRenderer
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/** /**
* Created by minjaesong on 2019-03-10. * Created by minjaesong on 2019-03-10.
*/ */
class WirePieceSignalWire(override val originalID: ItemID) : GameItem() { class WirePieceSignalWire(originalID: ItemID) : GameItem(originalID) {
override var dynamicID: ItemID = originalID override var dynamicID: ItemID = originalID
override val originalName = "ITEM_WIRE" override val originalName = "ITEM_WIRE"
@@ -24,7 +22,7 @@ class WirePieceSignalWire(override val originalID: ItemID) : GameItem() {
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["basegame.items16"] as TextureRegionPack).get(1,9) get() = AppLoader.resourcePool.getAsTextureRegionPack("basegame.items16").get(1,9)
init { init {
super.equipPosition = GameItem.EquipPosition.HAND_GRIP super.equipPosition = GameItem.EquipPosition.HAND_GRIP
@@ -32,11 +30,10 @@ class WirePieceSignalWire(override val originalID: ItemID) : GameItem() {
} }
override fun startPrimaryUse(delta: Float): Boolean { override fun startPrimaryUse(delta: Float): Boolean {
return super.startPrimaryUse(delta) return BlockBase.wireStartPrimaryUse(this, Wire.BIT_SIGNAL_RED, delta)
} }
override fun effectWhenEquipped(delta: Float) { override fun effectWhenEquipped(delta: Float) {
IngameRenderer.selectedWireBitToDraw = Wire.BIT_SIGNAL_RED BlockBase.wireEffectWhenEquipped(Wire.BIT_SIGNAL_RED, delta)
//println("wires!")
} }
} }

View File

@@ -1,6 +1,6 @@
package net.torvald.terrarum.modulebasegame.ui package net.torvald.terrarum.modulebasegame.ui
import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid

View File

@@ -4,7 +4,7 @@ import com.badlogic.gdx.Gdx
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 com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.toInt import net.torvald.terrarum.toInt
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack

View File

@@ -6,7 +6,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.GdxColorMap import net.torvald.terrarum.GdxColorMap
import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.ui.UIItem import net.torvald.terrarum.ui.UIItem
import kotlin.math.roundToInt import kotlin.math.roundToInt

View File

@@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.* import net.torvald.terrarum.*
import net.torvald.terrarum.gameworld.fmod import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory

View File

@@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.* import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK

View File

@@ -22,6 +22,7 @@ import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
import net.torvald.terrarum.modulebasegame.worldgenerator.WorldGenerator import net.torvald.terrarum.modulebasegame.worldgenerator.WorldGenerator
import net.torvald.terrarum.utils.JsonFetcher import net.torvald.terrarum.utils.JsonFetcher
import net.torvald.terrarum.worlddrawer.CreateTileAtlas import net.torvald.terrarum.worlddrawer.CreateTileAtlas
import net.torvald.terrarum.worlddrawer.Cvec
import net.torvald.terrarum.worlddrawer.WorldCamera import net.torvald.terrarum.worlddrawer.WorldCamera
import java.io.File import java.io.File
import java.util.* import java.util.*
@@ -51,7 +52,8 @@ internal object WeatherMixer : RNGConsumer {
lateinit var mixedWeather: BaseModularWeather lateinit var mixedWeather: BaseModularWeather
val globalLightNow = Color(0) var globalLightNow = Cvec()
private set
// Weather indices // Weather indices
const val WEATHER_GENERIC = "generic" const val WEATHER_GENERIC = "generic"
@@ -133,7 +135,7 @@ internal object WeatherMixer : RNGConsumer {
// calculate global light // calculate global light
val globalLight = getGradientColour(skyboxColourMap, 2, timeNow) val globalLight = getGradientColour(skyboxColourMap, 2, timeNow)
globalLightNow.set(globalLight) globalLightNow = Cvec(globalLight.r, globalLight.g, globalLight.b, globalLight.a)
/* (copied from the shader source) /* (copied from the shader source)
@@ -178,8 +180,10 @@ internal object WeatherMixer : RNGConsumer {
/** /**
* Get a GL of specific time * Get a GL of specific time
*/ */
fun getGlobalLightOfTime(timeInSec: Int): Color = fun getGlobalLightOfTime(timeInSec: Int): Cvec {
getGradientColour(currentWeather.skyboxGradColourMap, 2, timeInSec) val c = getGradientColour(currentWeather.skyboxGradColourMap, 2, timeInSec)
return Cvec(c.r, c.g, c.b, c.a)
}
fun getGradientColour(colorMap: GdxColorMap, row: Int, timeInSec: Int): Color { fun getGradientColour(colorMap: GdxColorMap, row: Int, timeInSec: Int): Color {
val dataPointDistance = WorldTime.DAY_LENGTH / colorMap.width val dataPointDistance = WorldTime.DAY_LENGTH / colorMap.width

Binary file not shown.

View File

@@ -5,7 +5,7 @@ import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.Actor import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.* import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.*
import net.torvald.terrarum.roundInt import net.torvald.terrarum.roundInt

View File

@@ -140,21 +140,23 @@ class BasicDebugInfoWindow : UICanvas() {
val mtX = mouseTileX.toString() val mtX = mouseTileX.toString()
val mtY = mouseTileY.toString() val mtY = mouseTileY.toString()
val valRaw = LightmapRenderer.getLight(mouseTileX, mouseTileY) val valRaw = LightmapRenderer.getLight(mouseTileX, mouseTileY)
val rawR = valRaw?.r?.times(100f)?.round()?.div(100f) val rawR = valRaw?.vec?.lane(0)?.times(100f)?.round()?.div(100f)
val rawG = valRaw?.g?.times(100f)?.round()?.div(100f) val rawG = valRaw?.vec?.lane(1)?.times(100f)?.round()?.div(100f)
val rawB = valRaw?.b?.times(100f)?.round()?.div(100f) val rawB = valRaw?.vec?.lane(2)?.times(100f)?.round()?.div(100f)
val rawA = valRaw?.a?.times(100f)?.round()?.div(100f) val rawA = valRaw?.vec?.lane(3)?.times(100f)?.round()?.div(100f)
lightVal = if (valRaw == null) "" lightVal = if (valRaw == null) ""
else "$rawR $rawG $rawB $rawA" else "$rawR $rawG $rawB $rawA"
printLine(batch, 8, "light@cursor $ccG$lightVal") printLine(batch, 8, "light@cursor $ccG$lightVal")
if (ingame != null) { if (ingame != null) {
val wallNum = ingame!!.world.getTileFromWall(mouseTileX, mouseTileY) ?: -1
val tileNum = ingame!!.world.getTileFromTerrain(mouseTileX, mouseTileY) ?: -1 val tileNum = ingame!!.world.getTileFromTerrain(mouseTileX, mouseTileY) ?: -1
val wireNum = ingame!!.world.getWiringBlocks(mouseTileX, mouseTileY)
val fluid = ingame!!.world.getFluid(mouseTileX, mouseTileY) val fluid = ingame!!.world.getFluid(mouseTileX, mouseTileY)
printLine(batch, 9, "tile@cursor $ccG$tileNum ($mtX, $mtY)") printLine(batch, 9, "tile@cursor ${ccO}W$ccG$wallNum ${ccO}T$ccG$tileNum ${ccO}C$ccG${wireNum.toString(2)} $ccY($mtX, $mtY)")
printLine(batch, 10, "fluid@cursor ${ccY}Type $ccM${fluid.type.value} ${ccY}Fill $ccG${fluid.amount}f") printLine(batch, 10, "fluid@cursor ${ccO}Type $ccG${fluid.type.value} ${ccO}Fill $ccG${fluid.amount}f")
} }

View File

@@ -27,6 +27,8 @@ import kotlin.math.roundToInt
* in the shader (tiling.frag). This will not be a problem in the base game, but if you are modifying * in the shader (tiling.frag). This will not be a problem in the base game, but if you are modifying
* this engine for your project, you must edit the shader program accordingly. * this engine for your project, you must edit the shader program accordingly.
* *
* To render and draw images, modify the ```selectedWireBitToDraw``` (bitset) property from the IngameRenderer.
*
* Created by minjaesong on 2016-01-19. * Created by minjaesong on 2016-01-19.
*/ */
internal object BlocksDrawer { internal object BlocksDrawer {
@@ -121,10 +123,8 @@ internal object BlocksDrawer {
TextureRegionPack(Texture(CreateTileAtlas.atlasWinter), TILE_SIZE, TILE_SIZE) TextureRegionPack(Texture(CreateTileAtlas.atlasWinter), TILE_SIZE, TILE_SIZE)
) )
// unzip tga.gz for tilesWire and tilesFluid //TODO make wire work with the TileAtlas system
tilesWire = TextureRegionPack(ModMgr.getGdxFile("basegame", "blocks/wire.tga"), TILE_SIZE, TILE_SIZE)
//TODO
tilesWire = TextureRegionPack(Texture(8, 8, Pixmap.Format.RGBA8888), 1, 1)
tilesFluid = TextureRegionPack(Texture(CreateTileAtlas.atlasFluid), TILE_SIZE, TILE_SIZE) tilesFluid = TextureRegionPack(Texture(CreateTileAtlas.atlasFluid), TILE_SIZE, TILE_SIZE)
@@ -161,6 +161,10 @@ internal object BlocksDrawer {
private val connectLut47 = intArrayOf(17,1,17,1,2,3,2,14,17,1,17,1,2,3,2,14,9,7,9,7,4,5,4,35,9,7,9,7,16,37,16,15,17,1,17,1,2,3,2,14,17,1,17,1,2,3,2,14,9,7,9,7,4,5,4,35,9,7,9,7,16,37,16,15,8,10,8,10,0,12,0,43,8,10,8,10,0,12,0,43,11,13,11,13,6,20,6,34,11,13,11,13,36,33,36,46,8,10,8,10,0,12,0,43,8,10,8,10,0,12,0,43,30,42,30,42,38,26,38,18,30,42,30,42,23,45,23,31,17,1,17,1,2,3,2,14,17,1,17,1,2,3,2,14,9,7,9,7,4,5,4,35,9,7,9,7,16,37,16,15,17,1,17,1,2,3,2,14,17,1,17,1,2,3,2,14,9,7,9,7,4,5,4,35,9,7,9,7,16,37,16,15,8,28,8,28,0,41,0,21,8,28,8,28,0,41,0,21,11,44,11,44,6,27,6,40,11,44,11,44,36,19,36,32,8,28,8,28,0,41,0,21,8,28,8,28,0,41,0,21,30,29,30,29,38,39,38,25,30,29,30,29,23,24,23,22) private val connectLut47 = intArrayOf(17,1,17,1,2,3,2,14,17,1,17,1,2,3,2,14,9,7,9,7,4,5,4,35,9,7,9,7,16,37,16,15,17,1,17,1,2,3,2,14,17,1,17,1,2,3,2,14,9,7,9,7,4,5,4,35,9,7,9,7,16,37,16,15,8,10,8,10,0,12,0,43,8,10,8,10,0,12,0,43,11,13,11,13,6,20,6,34,11,13,11,13,36,33,36,46,8,10,8,10,0,12,0,43,8,10,8,10,0,12,0,43,30,42,30,42,38,26,38,18,30,42,30,42,23,45,23,31,17,1,17,1,2,3,2,14,17,1,17,1,2,3,2,14,9,7,9,7,4,5,4,35,9,7,9,7,16,37,16,15,17,1,17,1,2,3,2,14,17,1,17,1,2,3,2,14,9,7,9,7,4,5,4,35,9,7,9,7,16,37,16,15,8,28,8,28,0,41,0,21,8,28,8,28,0,41,0,21,11,44,11,44,6,27,6,40,11,44,11,44,36,19,36,32,8,28,8,28,0,41,0,21,8,28,8,28,0,41,0,21,30,29,30,29,38,39,38,25,30,29,30,29,23,24,23,22)
private val connectLut16 = intArrayOf(0,2,0,2,4,6,4,6,0,2,0,2,4,6,4,6,8,10,8,10,12,14,12,14,8,10,8,10,12,14,12,14,0,2,0,2,4,6,4,6,0,2,0,2,4,6,4,6,8,10,8,10,12,14,12,14,8,10,8,10,12,14,12,14,1,3,1,3,5,7,5,7,1,3,1,3,5,7,5,7,9,11,9,11,13,15,13,15,9,11,9,11,13,15,13,15,1,3,1,3,5,7,5,7,1,3,1,3,5,7,5,7,9,11,9,11,13,15,13,15,9,11,9,11,13,15,13,15,0,2,0,2,4,6,4,6,0,2,0,2,4,6,4,6,8,10,8,10,12,14,12,14,8,10,8,10,12,14,12,14,0,2,0,2,4,6,4,6,0,2,0,2,4,6,4,6,8,10,8,10,12,14,12,14,8,10,8,10,12,14,12,14,1,3,1,3,5,7,5,7,1,3,1,3,5,7,5,7,9,11,9,11,13,15,13,15,9,11,9,11,13,15,13,15,1,3,1,3,5,7,5,7,1,3,1,3,5,7,5,7,9,11,9,11,13,15,13,15,9,11,9,11,13,15,13,15) private val connectLut16 = intArrayOf(0,2,0,2,4,6,4,6,0,2,0,2,4,6,4,6,8,10,8,10,12,14,12,14,8,10,8,10,12,14,12,14,0,2,0,2,4,6,4,6,0,2,0,2,4,6,4,6,8,10,8,10,12,14,12,14,8,10,8,10,12,14,12,14,1,3,1,3,5,7,5,7,1,3,1,3,5,7,5,7,9,11,9,11,13,15,13,15,9,11,9,11,13,15,13,15,1,3,1,3,5,7,5,7,1,3,1,3,5,7,5,7,9,11,9,11,13,15,13,15,9,11,9,11,13,15,13,15,0,2,0,2,4,6,4,6,0,2,0,2,4,6,4,6,8,10,8,10,12,14,12,14,8,10,8,10,12,14,12,14,0,2,0,2,4,6,4,6,0,2,0,2,4,6,4,6,8,10,8,10,12,14,12,14,8,10,8,10,12,14,12,14,1,3,1,3,5,7,5,7,1,3,1,3,5,7,5,7,9,11,9,11,13,15,13,15,9,11,9,11,13,15,13,15,1,3,1,3,5,7,5,7,1,3,1,3,5,7,5,7,9,11,9,11,13,15,13,15,9,11,9,11,13,15,13,15)
init {
assert(256 == connectLut47.size && 256 == connectLut16.size)
}
/** /**
* Tiles that half-transparent and has hue * Tiles that half-transparent and has hue
* will blend colour using colour multiplication * will blend colour using colour multiplication
@@ -185,7 +189,7 @@ internal object BlocksDrawer {
// NO draw lightmap using colour filter, actors must also be hidden behind the darkness // NO draw lightmap using colour filter, actors must also be hidden behind the darkness
/////////////////////////////////////////// ///////////////////////////////////////////
internal fun renderData(wireBit: Int) { internal fun renderData() {
try { try {
drawTIME_T = (world as GameWorldExtension).time.TIME_T - (WorldTime.DAY_LENGTH * 15) // offset by -15 days drawTIME_T = (world as GameWorldExtension).time.TIME_T - (WorldTime.DAY_LENGTH * 15) // offset by -15 days
@@ -198,7 +202,7 @@ internal object BlocksDrawer {
drawTiles(WALL) drawTiles(WALL)
drawTiles(TERRAIN) // regular tiles drawTiles(TERRAIN) // regular tiles
drawTiles(WIRE, wireBit) drawTiles(WIRE)
drawTiles(FLUID) drawTiles(FLUID)
} }
@@ -215,6 +219,9 @@ internal object BlocksDrawer {
renderUsingBuffer(FLUID, projectionMatrix) renderUsingBuffer(FLUID, projectionMatrix)
} }
var drawWires = 0
private set
internal fun drawFront(projectionMatrix: Matrix4, drawWires: Int) { internal fun drawFront(projectionMatrix: Matrix4, drawWires: Int) {
// blend mul // blend mul
Gdx.gl.glEnable(GL20.GL_TEXTURE_2D) Gdx.gl.glEnable(GL20.GL_TEXTURE_2D)
@@ -228,8 +235,9 @@ internal object BlocksDrawer {
gdxSetBlendNormal() gdxSetBlendNormal()
this.drawWires = drawWires
if (drawWires != 0) { if (drawWires != 0) {
//println("drawing wires") //println("Wires! draw: $drawWires") // use F10 instead
renderUsingBuffer(WIRE, projectionMatrix) renderUsingBuffer(WIRE, projectionMatrix)
} }
} }
@@ -261,14 +269,12 @@ internal object BlocksDrawer {
/** /**
* Turns bitmask-with-single-bit-set into its bit index. The LSB is counted as 1, and thus the index starts at one. * Turns bitmask-with-single-bit-set into its bit index. The LSB is counted as 1, and thus the index starts at one.
* @return 0 -> null, 1 -> 0, 2 -> 1, 4 -> 2, 8 -> 3, 16 -> 4, ... * @return 0 -> -1, 1 -> 0, 2 -> 1, 4 -> 2, 8 -> 3, 16 -> 4, ...
*/ */
private fun Int.toBitOrd(): Int? = private fun Int.toBitOrd(): Int {
if (this > 0 && !FastMath.isPowerOfTwo(this)) throw IllegalArgumentException("value must be power of two: $this") val k = FastMath.intLog2(this, -1)
else { return k
val k = FastMath.intLog2(this, -1) }
if (k == -1) null else k
}
/** /**
* Writes to buffer. Actual draw code must be called after this operation. * Writes to buffer. Actual draw code must be called after this operation.
@@ -276,7 +282,7 @@ internal object BlocksDrawer {
* @param drawModeTilesBlendMul If current drawing mode is MULTIPLY. Doesn't matter if mode is FLUID. * @param drawModeTilesBlendMul If current drawing mode is MULTIPLY. Doesn't matter if mode is FLUID.
* @param wire coduitTypes bit that is selected to be drawn. Must be the power of two. * @param wire coduitTypes bit that is selected to be drawn. Must be the power of two.
*/ */
private fun drawTiles(mode: Int, wireBit: Int = 0) { private fun drawTiles(mode: Int) {
// can't be "WorldCamera.y / TILE_SIZE": // can't be "WorldCamera.y / TILE_SIZE":
// ( 3 / 16) == 0 // ( 3 / 16) == 0
// (-3 / 16) == -1 <-- We want it to be '-1', not zero // (-3 / 16) == -1 <-- We want it to be '-1', not zero
@@ -305,7 +311,7 @@ internal object BlocksDrawer {
val thisTile = when (mode) { val thisTile = when (mode) {
WALL -> world.getTileFromWall(x, y) WALL -> world.getTileFromWall(x, y)
TERRAIN -> world.getTileFromTerrain(x, y) TERRAIN -> world.getTileFromTerrain(x, y)
WIRE -> world.getWires(x, y).and(wireBit).toBitOrd() WIRE -> world.getWiringBlocks(x, y).and(drawWires).toBitOrd() * 16
FLUID -> world.getFluid(x, y).type.abs() FLUID -> world.getFluid(x, y).type.abs()
else -> throw IllegalArgumentException() else -> throw IllegalArgumentException()
} }
@@ -316,6 +322,9 @@ internal object BlocksDrawer {
val nearbyTilesInfo = if (mode == FLUID) { val nearbyTilesInfo = if (mode == FLUID) {
getNearbyTilesInfoFluids(x, y) getNearbyTilesInfoFluids(x, y)
} }
else if (mode == WIRE) {
getNearbyWiringInfo(x, y, thisTile)
}
else if (isPlatform(thisTile)) { else if (isPlatform(thisTile)) {
getNearbyTilesInfoPlatform(x, y) getNearbyTilesInfoPlatform(x, y)
} }
@@ -336,10 +345,16 @@ internal object BlocksDrawer {
val tileNumberBase = val tileNumberBase =
if (mode == FLUID) if (mode == FLUID)
CreateTileAtlas.fluidToTileNumber(world.getFluid(x, y)) CreateTileAtlas.fluidToTileNumber(world.getFluid(x, y))
else if (mode == WIRE)
thisTile
else else
renderTag.tileNumber renderTag.tileNumber
val tileNumber = if (thisTile == 0) 0 val tileNumber = if (mode != WIRE && thisTile == 0) 0
// special case: fluids
else if (mode == FLUID) tileNumberBase + connectLut47[nearbyTilesInfo] else if (mode == FLUID) tileNumberBase + connectLut47[nearbyTilesInfo]
// special case: wires
else if (mode == WIRE) tileNumberBase + connectLut16[nearbyTilesInfo]
// rest of the cases: terrain and walls
else tileNumberBase + when (renderTag.maskType) { else tileNumberBase + when (renderTag.maskType) {
CreateTileAtlas.RenderTag.MASK_NA -> 0 CreateTileAtlas.RenderTag.MASK_NA -> 0
CreateTileAtlas.RenderTag.MASK_16 -> connectLut16[nearbyTilesInfo] CreateTileAtlas.RenderTag.MASK_16 -> connectLut16[nearbyTilesInfo]
@@ -363,7 +378,11 @@ internal object BlocksDrawer {
// draw a tile // draw a tile
if (mode == FLUID) { if (mode == WIRE && thisTile < 0) {
// no wire here, draw block id 255 (bottom right)
writeToBuffer(mode, bufferX, bufferY, 15, 15, 0)
}
else if (mode == FLUID || mode == WIRE) {
writeToBuffer(mode, bufferX, bufferY, thisTileX, thisTileY, 0) writeToBuffer(mode, bufferX, bufferY, thisTileX, thisTileY, 0)
} }
else { else {
@@ -402,6 +421,25 @@ internal object BlocksDrawer {
return ret return ret
} }
/**
* @param wire -1 for none, 0 for signal red, 1 for untility prototype, 2 for low power, 3 for high power;
* log of bits defined in [net.torvald.terrarum.blockproperties.Wire]
*
* @return offset from the spritesheet's "base" tile number, 0..15.
*/
private fun getNearbyWiringInfo(x: Int, y: Int, wire: Int): Int {
val nearbyTiles = getNearbyTilesPos(x, y).map { world.getWiringBlocks(it.x, it.y).and(drawWires).toBitOrd() * 16 }
var ret = 0
for (i in 0 until nearbyTiles.size) {
if (nearbyTiles[i] == wire) {
ret += (1 shl i) // add 1, 2, 4, 8 for i = 0, 1, 2, 3
}
}
return ret
}
private fun getNearbyTilesInfoConMutual(x: Int, y: Int, mode: Int): Int { private fun getNearbyTilesInfoConMutual(x: Int, y: Int, mode: Int): Int {
val nearbyTiles = getNearbyTilesPos(x, y).map { world.getTileFrom(mode, it.x, it.y) ?: Block.NULL } val nearbyTiles = getNearbyTilesPos(x, y).map { world.getTileFrom(mode, it.x, it.y) ?: Block.NULL }
@@ -601,6 +639,7 @@ internal object BlocksDrawer {
else else
0f 0f
) )
shader.setUniformf("drawBreakage", if (mode == WIRE) 0f else 1f)
tilesQuad.render(shader, GL20.GL_TRIANGLES) tilesQuad.render(shader, GL20.GL_TRIANGLES)
shader.end() shader.end()

Some files were not shown because too many files have changed in this diff Show More