Skip to content

Commit

Permalink
#74: Split edict into compoments
Browse files Browse the repository at this point in the history
+prethink
  • Loading branch information
demoth committed Nov 6, 2022
1 parent 3e82aeb commit 015b2cf
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions game/src/main/java/jake2/game/GameExportsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion game/src/main/java/jake2/game/GameMisc.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions game/src/main/java/jake2/game/SV.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 6 additions & 5 deletions game/src/main/java/jake2/game/SubgameEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions game/src/main/java/jake2/game/components/ThinkComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}

0 comments on commit 015b2cf

Please sign in to comment.