From 015b2cf882f1c029d42c7c0a2b78b58e7f46899b Mon Sep 17 00:00:00 2001 From: Daniil Bubnov Date: Sun, 6 Nov 2022 23:19:31 +0100 Subject: [PATCH] #74: Split edict into compoments +prethink --- game/src/main/java/jake2/game/GameExportsImpl.java | 4 ++-- game/src/main/java/jake2/game/GameMisc.java | 2 +- game/src/main/java/jake2/game/SV.java | 1 + game/src/main/java/jake2/game/SubgameEntity.java | 11 ++++++----- .../java/jake2/game/components/ThinkComponent.java | 7 +++++++ 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/game/src/main/java/jake2/game/GameExportsImpl.java b/game/src/main/java/jake2/game/GameExportsImpl.java index cfe423b8..38e642fe 100644 --- a/game/src/main/java/jake2/game/GameExportsImpl.java +++ b/game/src/main/java/jake2/game/GameExportsImpl.java @@ -1210,8 +1210,8 @@ private void spectatorRespawn(SubgameEntity ent) { private void runEntity(SubgameEntity ent) { // call prethink handler - if (ent.prethink != null) - ent.prethink.think(ent, this); + if (ent.think.prethink != null) + ent.think.prethink.think(ent, this); switch (ent.movetype) { case GameDefines.MOVETYPE_PUSH: diff --git a/game/src/main/java/jake2/game/GameMisc.java b/game/src/main/java/jake2/game/GameMisc.java index 59b9ec49..bb06c13f 100644 --- a/game/src/main/java/jake2/game/GameMisc.java +++ b/game/src/main/java/jake2/game/GameMisc.java @@ -1619,7 +1619,7 @@ public void use(SubgameEntity self, SubgameEntity other, SubgameEntity activator self.s.effects |= Defines.EF_ROCKET; self.use = null; self.movetype = GameDefines.MOVETYPE_TOSS; - self.prethink = misc_viper_bomb_prethink; + self.think.prethink = misc_viper_bomb_prethink; self.touch = misc_viper_bomb_touch; self.activator = activator; diff --git a/game/src/main/java/jake2/game/SV.java b/game/src/main/java/jake2/game/SV.java index 48bb1b73..bc6b29a9 100644 --- a/game/src/main/java/jake2/game/SV.java +++ b/game/src/main/java/jake2/game/SV.java @@ -106,6 +106,7 @@ private static void SV_Impact(SubgameEntity e1, trace_t trace, GameExportsImpl g if (e1.touch != null && e1.solid != Defines.SOLID_NOT) e1.touch.touch(e1, e2, trace.plane, trace.surface, gameExports); + // fixme: why trace plane & surface are not passed here? if (e2.touch != null && e2.solid != Defines.SOLID_NOT) e2.touch.touch(e2, e1, GameBase.dummyplane, null, gameExports); } diff --git a/game/src/main/java/jake2/game/SubgameEntity.java b/game/src/main/java/jake2/game/SubgameEntity.java index fcb3fb34..3641c042 100644 --- a/game/src/main/java/jake2/game/SubgameEntity.java +++ b/game/src/main/java/jake2/game/SubgameEntity.java @@ -113,7 +113,6 @@ public SubgameEntity(int i) { public float ideal_yaw; public ThinkComponent think = new ThinkComponent(); - public EntThinkAdapter prethink = null; public EntBlockedAdapter blocked = null; @@ -451,10 +450,11 @@ public void write(QuakeFile f) throws IOException { f.writeFloat(yaw_speed); f.writeFloat(ideal_yaw); + // Think Component f.writeFloat(think.nextTime); - - SuperAdapter.writeAdapter(f, prethink); + SuperAdapter.writeAdapter(f, think.prethink); SuperAdapter.writeAdapter(f, think.action); + SuperAdapter.writeAdapter(f, blocked); SuperAdapter.writeAdapter(f, touch); SuperAdapter.writeAdapter(f, use); @@ -611,10 +611,11 @@ public void read(QuakeFile f, edict_t[] g_edicts, gclient_t[] clients, GameExpor yaw_speed = f.readFloat(); ideal_yaw = f.readFloat(); + // Think Component think.nextTime = f.readFloat(); - - prethink = (EntThinkAdapter) SuperAdapter.readAdapter(f); + think.prethink = (EntThinkAdapter) SuperAdapter.readAdapter(f); think.action = (EntThinkAdapter) SuperAdapter.readAdapter(f); + blocked = (EntBlockedAdapter) SuperAdapter.readAdapter(f); touch = (EntTouchAdapter) SuperAdapter.readAdapter(f); diff --git a/game/src/main/java/jake2/game/components/ThinkComponent.java b/game/src/main/java/jake2/game/components/ThinkComponent.java index a06487b3..55b83780 100644 --- a/game/src/main/java/jake2/game/components/ThinkComponent.java +++ b/game/src/main/java/jake2/game/components/ThinkComponent.java @@ -6,4 +6,11 @@ public class ThinkComponent { public EntThinkAdapter action; // todo: switch to relative to game level time public float nextTime; + + /** + * Called in the beginning of the physics & other interaction logic + * fixme: used only for the viper bomb for rotation, is there a better way to implement this? + */ + public EntThinkAdapter prethink; + }