diff options
author | Rene Stoeckel <[email protected]> | 2004-08-20 21:29:58 +0000 |
---|---|---|
committer | Rene Stoeckel <[email protected]> | 2004-08-20 21:29:58 +0000 |
commit | 93a1cb6d6bfa9d7a80c004100125c829f1f36e86 (patch) | |
tree | 4ca88afc7718f8e63bd7f91aeccfe3c0fe66634e /src/jake2/game | |
parent | a1a1c7334c9b03113344078d2d7977193a1d7b5e (diff) |
savegames now seem to work.
Diffstat (limited to 'src/jake2/game')
-rw-r--r-- | src/jake2/game/GameBase.java | 5 | ||||
-rw-r--r-- | src/jake2/game/GameSave.java | 721 | ||||
-rw-r--r-- | src/jake2/game/GameUtil.java | 3 | ||||
-rw-r--r-- | src/jake2/game/PlayerClient.java | 11 | ||||
-rw-r--r-- | src/jake2/game/PlayerClientAdapters.java | 106 | ||||
-rw-r--r-- | src/jake2/game/SuperAdapter.java | 87 | ||||
-rw-r--r-- | src/jake2/game/client_persistant_t.java | 89 | ||||
-rw-r--r-- | src/jake2/game/client_respawn_t.java | 62 | ||||
-rw-r--r-- | src/jake2/game/edict_t.java | 781 | ||||
-rw-r--r-- | src/jake2/game/entity_state_t.java | 80 | ||||
-rw-r--r-- | src/jake2/game/game_export_t.java | 35 | ||||
-rw-r--r-- | src/jake2/game/game_locals_t.java | 58 | ||||
-rw-r--r-- | src/jake2/game/gclient_t.java | 340 | ||||
-rw-r--r-- | src/jake2/game/gitem_t.java | 4 | ||||
-rw-r--r-- | src/jake2/game/level_locals_t.java | 98 | ||||
-rw-r--r-- | src/jake2/game/mframe_t.java | 32 | ||||
-rw-r--r-- | src/jake2/game/mmove_t.java | 46 | ||||
-rw-r--r-- | src/jake2/game/monsterinfo_t.java | 101 | ||||
-rw-r--r-- | src/jake2/game/moveinfo_t.java | 64 | ||||
-rw-r--r-- | src/jake2/game/player_state_t.java | 179 | ||||
-rw-r--r-- | src/jake2/game/pmove_state_t.java | 74 |
21 files changed, 1791 insertions, 1185 deletions
diff --git a/src/jake2/game/GameBase.java b/src/jake2/game/GameBase.java index 871e084..db2b3f0 100644 --- a/src/jake2/game/GameBase.java +++ b/src/jake2/game/GameBase.java @@ -19,9 +19,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 30.11.2003 by RST. -// $Id: GameBase.java,v 1.3 2004-07-09 06:50:49 hzi Exp $ +// $Id: GameBase.java,v 1.4 2004-08-20 21:29:58 salomo Exp $ -/** Father of all Objects. */ +/** Father of all GameObjects. */ package jake2.game; @@ -441,6 +441,7 @@ public class GameBase extends Globals */ public static void G_RunEntity(edict_t ent) { + if (ent.prethink != null) ent.prethink.think(ent); diff --git a/src/jake2/game/GameSave.java b/src/jake2/game/GameSave.java index d399b8c..ba36e06 100644 --- a/src/jake2/game/GameSave.java +++ b/src/jake2/game/GameSave.java @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 29.12.2003 by RST. -// $Id: GameSave.java,v 1.1 2004-07-07 19:59:01 hzi Exp $ +// $Id: GameSave.java,v 1.2 2004-08-20 21:29:57 salomo Exp $ package jake2.game; @@ -57,6 +57,7 @@ public class GameSave extends GameFunc { g_edicts = new edict_t[game.maxentities]; for (int i = 0; i < game.maxentities; i++) g_edicts[i] = new edict_t(i); + SV_GAME.ge.edicts = g_edicts; } public static void CreateClients() { @@ -131,16 +132,11 @@ public class GameSave extends GameFunc { // items InitItems(); - //Com_sprintf (game.helpmessage1, sizeof(game.helpmessage1), ""); game.helpmessage1 = ""; - - //Com_sprintf (game.helpmessage2, sizeof(game.helpmessage2), ""); game.helpmessage2 = ""; // initialize all entities for this game game.maxentities = (int) maxentities.value; - - //g_edicts = gi.TagMalloc(game.maxentities * sizeof(g_edicts[0]), TAG_GAME); CreateEdicts(); globals.edicts = g_edicts; @@ -149,585 +145,196 @@ public class GameSave extends GameFunc { // initialize all clients for this game game.maxclients = (int) maxclients.value; - //game.clients = gi.TagMalloc(game.maxclients * sizeof(game.clients[0]), TAG_GAME); CreateClients(); - + globals.num_edicts = game.maxclients + 1; } - ////========================================================= - // - //public static void WriteField1 (FILE *f, field_t field, byte base) - //{ - // void *p; - // int len; - // int index; - // - // if (field.flags & FFL_SPAWNTEMP) - // return; - // - // p = (void *)(base + field.ofs); - // switch (field.type) - // { - // case F_INT: - // case F_FLOAT: - // case F_ANGLEHACK: - // case F_VECTOR: - // case F_IGNORE: - // break; - // - // case F_LSTRING: - // case F_GSTRING: - // if ( *(char **)p ) - // len = strlen(*(char **)p) + 1; - // else - // len = 0; - // *(int *)p = len; - // break; - // case F_EDICT: - // if ( *(edict_t **)p == NULL) - // index = -1; - // else - // index = *(edict_t **)p - g_edicts; - // *(int *)p = index; - // break; - // case F_CLIENT: - // if ( *(gclient_t **)p == NULL) - // index = -1; - // else - // index = *(gclient_t **)p - game.clients; - // *(int *)p = index; - // break; - // case F_ITEM: - // if ( *(edict_t **)p == NULL) - // index = -1; - // else - // index = *(gitem_t **)p - itemlist; - // *(int *)p = index; - // break; - // - // //relative to code segment - // case F_FUNCTION: - // if (*(byte **)p == NULL) - // index = 0; - // else - // index = *(byte **)p - ((byte *)InitGame); - // *(int *)p = index; - // break; - // - // //relative to data segment - // case F_MMOVE: - // if (*(byte **)p == NULL) - // index = 0; - // else - // index = *(byte **)p - (byte *)&mmove_reloc; - // *(int *)p = index; - // break; - // - // default: - // gi.error ("WriteEdict: unknown field type"); - // } - //} - // - // - //void WriteField2 (FILE *f, field_t *field, byte *base) - //{ - // int len; - // void *p; - // - // if (field.flags & FFL_SPAWNTEMP) - // return; - // - // p = (void *)(base + field.ofs); - // switch (field.type) - // { - // case F_LSTRING: - // if ( *(char **)p ) - // { - // len = strlen(*(char **)p) + 1; - // fwrite (*(char **)p, len, 1, f); - // } - // break; - // } - //} - // - //void ReadField (FILE *f, field_t *field, byte *base) - //{ - // void *p; - // int len; - // int index; - // - // if (field.flags & FFL_SPAWNTEMP) - // return; - // - // p = (void *)(base + field.ofs); - // switch (field.type) - // { - // case F_INT: - // case F_FLOAT: - // case F_ANGLEHACK: - // case F_VECTOR: - // case F_IGNORE: - // break; - // - // case F_LSTRING: - // len = *(int *)p; - // if (!len) - // *(char **)p = NULL; - // else - // { - // *(char **)p = gi.TagMalloc (len, TAG_LEVEL); - // fread (*(char **)p, len, 1, f); - // } - // break; - // case F_EDICT: - // index = *(int *)p; - // if ( index == -1 ) - // *(edict_t **)p = NULL; - // else - // *(edict_t **)p = &g_edicts[index]; - // break; - // case F_CLIENT: - // index = *(int *)p; - // if ( index == -1 ) - // *(gclient_t **)p = NULL; - // else - // *(gclient_t **)p = &game.clients[index]; - // break; - // case F_ITEM: - // index = *(int *)p; - // if ( index == -1 ) - // *(gitem_t **)p = NULL; - // else - // *(gitem_t **)p = &itemlist[index]; - // break; - // - // //relative to code segment - // case F_FUNCTION: - // index = *(int *)p; - // if ( index == 0 ) - // *(byte **)p = NULL; - // else - // *(byte **)p = ((byte *)InitGame) + index; - // break; - // - // //relative to data segment - // case F_MMOVE: - // index = *(int *)p; - // if (index == 0) - // *(byte **)p = NULL; - // else - // *(byte **)p = (byte *)&mmove_reloc + index; - // break; - // - // default: - // gi.error ("ReadEdict: unknown field type"); - // } - //} - // - ////========================================================= - // - ///* - //============== - //WriteClient - // - //All pointer variables (except function pointers) must be handled specially. - //============== - //*/ - //void WriteClient (FILE *f, gclient_t *client) - //{ - // field_t *field; - // gclient_t temp; - // - // // all of the ints, floats, and vectors stay as they are - // temp = *client; - // - // // change the pointers to lengths or indexes - // for (field=clientfields ; field.name ; field++) - // { - // WriteField1 (f, field, (byte *)&temp); - // } - // - // // write the block - // fwrite (&temp, sizeof(temp), 1, f); - // - // // now write any allocated data following the edict - // for (field=clientfields ; field.name ; field++) - // { - // WriteField2 (f, field, (byte *)client); - // } - //} - // /* - ============== - ReadClient + ============ + WriteGame + + This will be called whenever the game goes to a new level, + and when the user explicitly saves the game. - All pointer variables (except function pointers) must be handled specially. - ============== + Game information include cross level data, like multi level + triggers, help computer info, and all client states. + + A single player death will automatically restore from the + last save position. + ============ */ - - //} // - - /* - //============ - //WriteGame - // - //This will be called whenever the game goes to a new level, - //and when the user explicitly saves the game. - // - //Game information include cross level data, like multi level - //triggers, help computer info, and all client states. - // - //A single player death will automatically restore from the - //last save position. - //============ - //*/ - //public static void WriteGame (String filename, boolean autosave) - //{ - // FILE *f; - // int i; - // char str[16]; - // - // if (!autosave) - // SaveClientData (); - // - // f = fopen (filename, "rw"); - // if (!f) - // gi.error ("Couldn't open %s", filename); - // - // memset (str, 0, sizeof(str)); - // strcpy (str, __DATE__); - // fwrite (str, sizeof(str), 1, f); - // - // game.autosaved = autosave; - // fwrite (&game, sizeof(game), 1, f); - // game.autosaved = false; - // - // for (i=0 ; i<game.maxclients ; i++) - // WriteClient (f, &game.clients[i]); - // - // fclose (f); - //} - // + public static void WriteGame (String filename, boolean autosave) + { + try + { + QuakeFile f; + + if (!autosave) + SaveClientData(); + + f = new QuakeFile(filename, "rw"); + + if (f == null) + gi.error ("Couldn't write to " + filename); + + game.autosaved = autosave; + game.write(f); + game.autosaved = false; + + for (int i=0 ; i<game.maxclients ; i++) + game.clients[i]. write(f); + + fclose (f); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + public static void ReadGame(String filename) { - RandomAccessFile f = null; + QuakeFile f = null; try { - f = new RandomAccessFile(filename, "r"); - - byte buf[] = new byte[(int) f.length()]; - + f = new QuakeFile(filename, "r"); Com.Printf("loading game:" + filename); - - f.readFully(buf); - - ByteBuffer bb = ByteBuffer.wrap(buf); - - bb.order(ByteOrder.LITTLE_ENDIAN); - CreateEdicts(); - game.load(bb); - //game.dump(); + game.load(f); for (int i = 0; i < game.maxclients; i++) { game.clients[i] = new gclient_t(i); - game.clients[i].load(bb); + game.clients[i].read(f); } - Com.Println(""); - Com.Println("file length:" + f.length()); - Com.Println("processed bytes:" + bb.position()); - + f.close(); } catch (Exception e) { e.printStackTrace(); - //gi.error ("File problems in "+ filename); - } //if (!f) - // gi.error ("Couldn't open %s", filename); - // - // fread (str, sizeof(str), 1, f); - // if (strcmp (str, __DATE__)) - // { - // fclose (f); - // gi.error ("Savegame from an older version.\n"); - // } - // - // CreateEdicts(); - // - // fread (game, sizeof(game), 1, f); - // - // CreateClients(); - // - // for (i=0 ; i<game.maxclients ; i++) - // ReadClient (f, game.clients[i]); - // - // fclose (f); - try { + } + } + + /* + ================= + WriteLevel + + ================= + */ + static void WriteLevel (String filename) + { + try + { + int i; + edict_t ent; + QuakeFile f; + + f= new QuakeFile(filename, "rw"); + if (f==null) + gi.error("Couldn't open for writing: " + filename); + + // write out level_locals_t + level.write(f); + + // write out all the entities + for (i= 0; i < globals.num_edicts; i++) + { + ent= g_edicts[i]; + if (!ent.inuse) + continue; + f.writeInt(i); + ent.write(f); + + } + + i= -1; + f.writeInt(-1); + f.close(); } - catch (IOException e) { - Com.Error(Defines.ERR_DROP, "Unable to load savegame"); + catch (Exception e) + { + e.printStackTrace(); } } + + + /* + ================= + ReadLevel + + SpawnEntities will allready have been called on the + level the same way it was when the level was saved. + + That is necessary to get the baselines + set up identically. + + The server will have cleared all of the world links before + calling ReadLevel. + + No clients are connected yet. + ================= + */ + static void ReadLevel (String filename) throws IOException + { + edict_t ent; + + QuakeFile f = new QuakeFile(filename, "r"); + + if (f==null) + gi.error ("Couldn't read level file " + filename); + + // wipe all the entities + Game.CreateEdicts(); + + globals.num_edicts = (int) maxclients.value + 1; - // - ////========================================================== - // - // - ///* - //============== - //WriteEdict - // - //All pointer variables (except function pointers) must be handled specially. - //============== - //*/ - //void WriteEdict (FILE *f, edict_t *ent) - //{ - // field_t *field; - // edict_t temp; - // - // // all of the ints, floats, and vectors stay as they are - // temp = *ent; - // - // // change the pointers to lengths or indexes - // for (field=fields ; field.name ; field++) - // { - // WriteField1 (f, field, (byte *)&temp); - // } - // - // // write the block - // fwrite (&temp, sizeof(temp), 1, f); - // - // // now write any allocated data following the edict - // for (field=fields ; field.name ; field++) - // { - // WriteField2 (f, field, (byte *)ent); - // } - // - //} - // - ///* - //============== - //WriteLevelLocals - // - //All pointer variables (except function pointers) must be handled specially. - //============== - //*/ - //void WriteLevelLocals (FILE *f) - //{ - // field_t *field; - // level_locals_t temp; - // - // // all of the ints, floats, and vectors stay as they are - // temp = level; - // - // // change the pointers to lengths or indexes - // for (field=levelfields ; field.name ; field++) - // { - // WriteField1 (f, field, (byte *)&temp); - // } - // - // // write the block - // fwrite (&temp, sizeof(temp), 1, f); - // - // // now write any allocated data following the edict - // for (field=levelfields ; field.name ; field++) - // { - // WriteField2 (f, field, (byte *)&level); - // } - //} - // - // - ///* - //============== - //ReadEdict - // - //All pointer variables (except function pointers) must be handled specially. - //============== - //*/ - //void ReadEdict (FILE *f, edict_t *ent) - //{ - // field_t *field; - // - // fread (ent, sizeof(*ent), 1, f); - // - // for (field=fields ; field.name ; field++) - // { - // ReadField (f, field, (byte *)ent); - // } - //} - // - ///* - //============== - //ReadLevelLocals - // - //All pointer variables (except function pointers) must be handled specially. - //============== - //*/ - //void ReadLevelLocals (FILE *f) - //{ - // field_t *field; - // - // fread (&level, sizeof(level), 1, f); - // - // for (field=levelfields ; field.name ; field++) - // { - // ReadField (f, field, (byte *)&level); - // } - //} - // - ///* - //================= - //WriteLevel - // - //================= - //*/ - //void WriteLevel (char *filename) - //{ - // int i; - // edict_t *ent; - // FILE *f; - // void *base; - // - // f = fopen (filename, "rw"); - // if (!f) - // gi.error ("Couldn't open %s", filename); - // - // // write out edict size for checking - // i = sizeof(edict_t); - // fwrite (&i, sizeof(i), 1, f); - // - // // write out a function pointer for checking - // base = (void *)InitGame; - // fwrite (&base, sizeof(base), 1, f); - // - // // write out level_locals_t - // WriteLevelLocals (f); - // - // // write out all the entities - // for (i=0 ; i<globals.num_edicts ; i++) - // { - // ent = &g_edicts[i]; - // if (!ent.inuse) - // continue; - // fwrite (&i, sizeof(i), 1, f); - // WriteEdict (f, ent); - // } - // i = -1; - // fwrite (&i, sizeof(i), 1, f); - // - // fclose (f); - //} - // - // - ///* - //================= - //ReadLevel - // - //SpawnEntities will allready have been called on the - //level the same way it was when the level was saved. - // - //That is necessary to get the baselines - //set up identically. - // - //The server will have cleared all of the world links before - //calling ReadLevel. - // - //No clients are connected yet. - //================= - //*/ - //void ReadLevel (char *filename) - //{ - // int entnum; - // FILE *f; - // int i; - // void *base; - // edict_t *ent; - // - // f = fopen (filename, "r"); - // if (!f) - // gi.error ("Couldn't open %s", filename); - // - // // free any dynamic memory allocated by loading the level - // // base state - // gi.FreeTags (TAG_LEVEL); - // - // // wipe all the entities - // memset (g_edicts, 0, game.maxentities*sizeof(g_edicts[0])); - // globals.num_edicts = maxclients.value+1; - // - // // check edict size - // fread (&i, sizeof(i), 1, f); - // if (i != sizeof(edict_t)) - // { - // fclose (f); - // gi.error ("ReadLevel: mismatched edict size"); - // } - // - // // check function pointer base address - // fread (&base, sizeof(base), 1, f); - //#ifdef _WIN32 - // if (base != (void *)InitGame) - // { - // fclose (f); - // gi.error ("ReadLevel: function pointers have moved"); - // } - //#else - // gi.dprintf("Function offsets %d\n", ((byte *)base) - ((byte *)InitGame)); - //#endif - // - // // load the level locals - // ReadLevelLocals (f); - // - // // load all the entities - // while (1) - // { - // if (fread (&entnum, sizeof(entnum), 1, f) != 1) - // { - // fclose (f); - // gi.error ("ReadLevel: failed to read entnum"); - // } - // if (entnum == -1) - // break; - // if (entnum >= globals.num_edicts) - // globals.num_edicts = entnum+1; - // - // ent = &g_edicts[entnum]; - // ReadEdict (f, ent); - // - // // let the server rebuild world links for this ent - // memset (&ent.area, 0, sizeof(ent.area)); - // gi.linkentity (ent); - // } - // - // fclose (f); - // - // // mark all clients as unconnected - // for (i=0 ; i<maxclients.value ; i++) - // { - // ent = &g_edicts[i+1]; - // ent.client = game.clients + i; - // ent.client.pers.connected = false; - // } - // - // // do any load time things at this point - // for (i=0 ; i<globals.num_edicts ; i++) - // { - // ent = &g_edicts[i]; - // - // if (!ent.inuse) - // continue; - // - // // fire any cross-level triggers - // if (ent.classname) - // if (strcmp(ent.classname, "target_crosslevel_target") == 0) - // ent.nextthink = level.time + ent.delay; - // } - //} - + // load the level locals + level.read(f); + + // load all the entities + while (true) + { + int entnum = f.readInt(); + if (entnum == -1) + break; + + if (entnum >= globals.num_edicts) + globals.num_edicts = entnum + 1; + + ent = g_edicts[entnum]; + System.out.println("readint ent" + entnum); + ent.read(f); + ent.cleararealinks(); + gi.linkentity(ent); + } + + fclose (f); + + // mark all clients as unconnected + for (int i=0 ; i<maxclients.value ; i++) + { + ent = g_edicts[i+1]; + ent.client = game.clients[i]; + ent.client.pers.connected = false; + } + + // do any load time things at this point + for (int i=0 ; i<globals.num_edicts ; i++) + { + ent = g_edicts[i]; + + if (!ent.inuse) + continue; + + // fire any cross-level triggers + if (ent.classname != null) + if (strcmp(ent.classname, "target_crosslevel_target") == 0) + ent.nextthink = level.time + ent.delay; + } + } } diff --git a/src/jake2/game/GameUtil.java b/src/jake2/game/GameUtil.java index a5d81ad..5769564 100644 --- a/src/jake2/game/GameUtil.java +++ b/src/jake2/game/GameUtil.java @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 01.11.2003 by RST. -// $Id: GameUtil.java,v 1.3 2004-07-09 06:50:49 hzi Exp $ +// $Id: GameUtil.java,v 1.4 2004-08-20 21:29:57 salomo Exp $ package jake2.game; @@ -887,7 +887,6 @@ public class GameUtil extends GameBase //geht. static gitem_t FindItem(String pickup_name) { - //Com.Printf("FindItem:" + pickup_name + "\n"); for (int i = 1; i < game.num_items; i++) { gitem_t it = GameAI.itemlist[i]; diff --git a/src/jake2/game/PlayerClient.java b/src/jake2/game/PlayerClient.java index a7d06dd..3bb09f0 100644 --- a/src/jake2/game/PlayerClient.java +++ b/src/jake2/game/PlayerClient.java @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 28.12.2003 by RST. -// $Id: PlayerClient.java,v 1.3 2004-07-08 20:24:29 hzi Exp $ +// $Id: PlayerClient.java,v 1.4 2004-08-20 21:29:58 salomo Exp $ package jake2.game; @@ -355,9 +355,11 @@ public class PlayerClient extends PlayerHud { ent = g_edicts[1 + i]; if (!ent.inuse) continue; + game.clients[i].pers.health = ent.health; game.clients[i].pers.max_health = ent.max_health; game.clients[i].pers.savedFlags = (ent.flags & (FL_GODMODE | FL_NOTARGET | FL_POWER_ARMOR)); + if (coop.value != 0) game.clients[i].pers.score = ent.client.resp.score; } @@ -371,13 +373,6 @@ public class PlayerClient extends PlayerHud { ent.client.resp.score = ent.client.pers.score; } - /* - ======================================================================= - - SelectSpawnPoint - - ======================================================================= - */ /* ================ diff --git a/src/jake2/game/PlayerClientAdapters.java b/src/jake2/game/PlayerClientAdapters.java index 1f29b88..f6d1e8d 100644 --- a/src/jake2/game/PlayerClientAdapters.java +++ b/src/jake2/game/PlayerClientAdapters.java @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 26.02.2004 by RST. -// $Id: PlayerClientAdapters.java,v 1.1 2004-07-08 15:58:43 hzi Exp $ +// $Id: PlayerClientAdapters.java,v 1.2 2004-08-20 21:29:58 salomo Exp $ package jake2.game; @@ -34,7 +34,7 @@ public class PlayerClientAdapters extends PlayerClient { // // Gross, ugly, disgustuing hack section // - + // this function is an ugly as hell hack to fix some map flaws // // the coop spawn spots on some maps are SNAFU. There are coop spots @@ -42,19 +42,19 @@ public class PlayerClientAdapters extends PlayerClient { // // we use carnal knowledge of the maps to fix the coop spot targetnames to match // that of the nearest named single player spot - - static EntThinkAdapter SP_FixCoopSpots = new EntThinkAdapter() { + + static EntThinkAdapter SP_FixCoopSpots= new EntThinkAdapter() { public boolean think(edict_t self) { - + edict_t spot; - float[] d = { 0, 0, 0 }; - - spot = null; - EdictIterator es = null; - + float[] d= { 0, 0, 0 }; + + spot= null; + EdictIterator es= null; + while (true) { - es = GameBase.G_Find(es, GameBase.findByClass, "info_player_start"); - spot = es.o; + es= GameBase.G_Find(es, GameBase.findByClass, "info_player_start"); + spot= es.o; if (spot == null) return true; if (spot.targetname == null) @@ -63,7 +63,7 @@ public class PlayerClientAdapters extends PlayerClient { if (Math3D.VectorLength(d) < 384) { if ((self.targetname == null) || Lib.Q_stricmp(self.targetname, spot.targetname) != 0) { // gi.dprintf("FixCoopSpots changed %s at %s targetname from %s to %s\n", self.classname, vtos(self.s.origin), self.targetname, spot.targetname); - self.targetname = spot.targetname; + self.targetname= spot.targetname; } return true; } @@ -73,74 +73,74 @@ public class PlayerClientAdapters extends PlayerClient { // now if that one wasn't ugly enough for you then try this one on for size // some maps don't have any coop spots at all, so we need to create them // where they should have been - - static EntThinkAdapter SP_CreateCoopSpots = new EntThinkAdapter() { + + static EntThinkAdapter SP_CreateCoopSpots= new EntThinkAdapter() { public boolean think(edict_t self) { - + edict_t spot; - + if (Lib.Q_stricmp(GameBase.level.mapname, "security") == 0) { - spot = GameUtil.G_Spawn(); - spot.classname = "info_player_coop"; - spot.s.origin[0] = 188 - 64; - spot.s.origin[1] = -164; - spot.s.origin[2] = 80; - spot.targetname = "jail3"; - spot.s.angles[1] = 90; - - spot = GameUtil.G_Spawn(); - spot.classname = "info_player_coop"; - spot.s.origin[0] = 188 + 64; - spot.s.origin[1] = -164; - spot.s.origin[2] = 80; - spot.targetname = "jail3"; - spot.s.angles[1] = 90; - - spot = GameUtil.G_Spawn(); - spot.classname = "info_player_coop"; - spot.s.origin[0] = 188 + 128; - spot.s.origin[1] = -164; - spot.s.origin[2] = 80; - spot.targetname = "jail3"; - spot.s.angles[1] = 90; + spot= GameUtil.G_Spawn(); + spot.classname= "info_player_coop"; + spot.s.origin[0]= 188 - 64; + spot.s.origin[1]= -164; + spot.s.origin[2]= 80; + spot.targetname= "jail3"; + spot.s.angles[1]= 90; + + spot= GameUtil.G_Spawn(); + spot.classname= "info_player_coop"; + spot.s.origin[0]= 188 + 64; + spot.s.origin[1]= -164; + spot.s.origin[2]= 80; + spot.targetname= "jail3"; + spot.s.angles[1]= 90; + + spot= GameUtil.G_Spawn(); + spot.classname= "info_player_coop"; + spot.s.origin[0]= 188 + 128; + spot.s.origin[1]= -164; + spot.s.origin[2]= 80; + spot.targetname= "jail3"; + spot.s.angles[1]= 90; } return true; } }; //======================================================================= - - static EntPainAdapter player_pain = new EntPainAdapter() { + + // player pain is handled at the end of the frame in P_DamageFeedback + static EntPainAdapter player_pain= new EntPainAdapter() { public void pain(edict_t self, edict_t other, float kick, int damage) { - // player pain is handled at the end of the frame in P_DamageFeedback - } + } }; - static EntDieAdapter body_die = new EntDieAdapter() { + static EntDieAdapter body_die= new EntDieAdapter() { public void die(edict_t self, edict_t inflictor, edict_t attacker, int damage, float[] point) { - + int n; - + if (self.health < -40) { GameBase.gi.sound(self, Defines.CHAN_BODY, GameBase.gi.soundindex("misc/udeath.wav"), 1, Defines.ATTN_NORM, 0); - for (n = 0; n < 4; n++) + for (n= 0; n < 4; n++) GameAI.ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, Defines.GIB_ORGANIC); self.s.origin[2] -= 48; GameAI.ThrowClientHead(self, damage); - self.takedamage = Defines.DAMAGE_NO; + self.takedamage= Defines.DAMAGE_NO; } } }; //============================================================== - + static edict_t pm_passent; // pmove doesn't need to know about passent and contentmask - public static pmove_t.TraceAdapter PM_trace = new pmove_t.TraceAdapter() { - + public static pmove_t.TraceAdapter PM_trace= new pmove_t.TraceAdapter() { + public trace_t trace(float[] start, float[] mins, float[] maxs, float[] end) { if (pm_passent.health > 0) return GameBase.gi.trace(start, mins, maxs, end, pm_passent, Defines.MASK_PLAYERSOLID); else return GameBase.gi.trace(start, mins, maxs, end, pm_passent, Defines.MASK_DEADSOLID); } - + }; } diff --git a/src/jake2/game/SuperAdapter.java b/src/jake2/game/SuperAdapter.java index 67285aa..29dcfb5 100644 --- a/src/jake2/game/SuperAdapter.java +++ b/src/jake2/game/SuperAdapter.java @@ -19,51 +19,80 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 09.01.2004 by RST. -// $Id: SuperAdapter.java,v 1.1 2004-07-07 19:59:24 hzi Exp $ +// $Id: SuperAdapter.java,v 1.2 2004-08-20 21:29:58 salomo Exp $ package jake2.game; import jake2.qcommon.Com; +import java.util.Hashtable; import java.util.Vector; +public class SuperAdapter +{ -// import jake2.*; -// import jake2.client.*; -// import jake2.game.*; -// import jake2.qcommon.*; -// import jake2.render.*; -// import jake2.server.*; - -public class SuperAdapter { - - // registration - private static void register(SuperAdapter sa) + /** Adapter registration. */ + private static void register(SuperAdapter sa, String id) { - adapters.add(sa); - //Com.Println("registering adapter " + sa.getID() + " (" + sa.getClass().getSuperclass() + ")"); + adapters.put(id, sa); } - - private static int id=0; - private static Vector adapters = new Vector(); - - - private static SuperAdapter find(int num) + + /** Adapter repository. */ + private static Hashtable adapters= new Hashtable(); + + /** Returns the adapter from the repository given by its ID. */ + public static SuperAdapter getFromID(String key) { - return (SuperAdapter) adapters.elementAt(num); + System.out.println("SuperAdapter.getFromID(\"" + key + "\")"); + SuperAdapter sa = (SuperAdapter) adapters.get(key); + + // try to create the adapter + if (sa == null) + { + System.out.println("adapter not found:" + key); + int pos = key.indexOf('$'); + String classname = key; + if (pos != -1) + classname = key.substring(0, pos); + + // load class and instantiate + try + { + System.err.println("loading class " + classname); + Class.forName(classname).newInstance(); + } + catch(Exception e) + { + System.err.println("jake2: class not found:" + classname); + } + + // try it again... + sa = (SuperAdapter) adapters.get(key); + + if (sa == null) + System.err.println("jake2: could not load adapter:" + key); + } + + return sa; } - - // constructor + + /** Constructor, does the adapter registration. */ public SuperAdapter() - { - adapterid = id++; - register(this); + { + StackTraceElement tr[] = new Throwable().getStackTrace(); + adapterid= tr[2].getClassName(); + if (adapterid == "") + new Throwable("error in creating an adapter id!").printStackTrace(); + else + register(this, adapterid); } - - public int getID() + + /** Returns the Adapter-ID. */ + public String getID() { return adapterid; } - private int adapterid; + /** Adapter id. */ + private String adapterid; } diff --git a/src/jake2/game/client_persistant_t.java b/src/jake2/game/client_persistant_t.java index 774cfa4..126d5d5 100644 --- a/src/jake2/game/client_persistant_t.java +++ b/src/jake2/game/client_persistant_t.java @@ -19,13 +19,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 31.10.2003 by RST. -// $Id: client_persistant_t.java,v 1.4 2004-07-12 20:47:01 hzi Exp $ +// $Id: client_persistant_t.java,v 1.5 2004-08-20 21:29:58 salomo Exp $ package jake2.game; import jake2.Defines; import jake2.util.Lib; +import jake2.util.QuakeFile; +import java.io.IOException; +import java.io.RandomAccessFile; import java.nio.ByteBuffer; public class client_persistant_t { @@ -89,42 +92,78 @@ public class client_persistant_t { int helpchanged; boolean spectator; // client is a spectator - public void load(ByteBuffer bb) { - // client persistant_t - userinfo = Lib.readString(bb, Defines.MAX_INFO_STRING); - netname = Lib.readString(bb, 16); + /** Reads a client_persistant structure from a file. */ + public void read(QuakeFile f) throws IOException { + + userinfo = f.readString(); + netname = f.readString(); - hand = bb.getInt(); + hand = f.readInt(); - connected = bb.getInt() != 0; - health = bb.getInt(); + connected = f.readInt() != 0; + health = f.readInt(); - max_health = bb.getInt(); - savedFlags = bb.getInt(); - selected_item = bb.getInt(); + max_health = f.readInt(); + savedFlags = f.readInt(); + selected_item = f.readInt(); for (int n = 0; n < Defines.MAX_ITEMS; n++) - inventory[n] = bb.getInt(); + inventory[n] = f.readInt(); + + max_bullets = f.readInt(); + max_shells = f.readInt(); + max_rockets = f.readInt(); + max_grenades = f.readInt(); + max_cells = f.readInt(); + max_slugs = f.readInt(); + + weapon = f.readItem(); + lastweapon = f.readItem(); + power_cubes = f.readInt(); + score = f.readInt(); + + game_helpchanged = f.readInt(); + helpchanged = f.readInt(); + spectator = f.readInt() != 0; + } - max_bullets = bb.getInt(); - max_shells = bb.getInt(); - max_rockets = bb.getInt(); - max_grenades = bb.getInt(); - max_cells = bb.getInt(); - max_slugs = bb.getInt(); + /** Writes a client_persistant structure to a file. */ + public void write(QuakeFile f) throws IOException { + // client persistant_t + f.writeString(userinfo); + f.writeString(netname); - weapon = GameAI.itemlist[bb.getInt()]; - lastweapon = GameAI.itemlist[bb.getInt()]; - power_cubes = bb.getInt(); - score = bb.getInt(); + f.writeInt(hand); - game_helpchanged = bb.getInt(); - helpchanged = bb.getInt(); - spectator = bb.getInt() != 0; + f.writeInt(connected ? 1:0); + f.writeInt(health); + f.writeInt(max_health); + f.writeInt(savedFlags); + f.writeInt(selected_item); + + for (int n = 0; n < Defines.MAX_ITEMS; n++) + f.writeInt(inventory[n]); + + f.writeInt(max_bullets); + f.writeInt(max_shells); + f.writeInt(max_rockets); + f.writeInt(max_grenades); + f.writeInt(max_cells); + f.writeInt(max_slugs); + + f.writeItem(weapon); + f.writeItem(lastweapon); + f.writeInt(power_cubes); + f.writeInt(score); + + f.writeInt(game_helpchanged); + f.writeInt(helpchanged); + f.writeInt(spectator?1:0); } + public void dump() { // client persistant_t diff --git a/src/jake2/game/client_respawn_t.java b/src/jake2/game/client_respawn_t.java index 722d609..26e69a2 100644 --- a/src/jake2/game/client_respawn_t.java +++ b/src/jake2/game/client_respawn_t.java @@ -18,26 +18,40 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 31.10.2003 by RST. -// $Id: client_respawn_t.java,v 1.4 2004-07-12 20:47:01 hzi Exp $ +// $Id: client_respawn_t.java,v 1.5 2004-08-20 21:29:57 salomo Exp $ package jake2.game; import jake2.qcommon.Com; import jake2.util.Lib; import jake2.util.Math3D; +import jake2.util.QuakeFile; import java.io.IOException; +import java.io.RandomAccessFile; import java.nio.ByteBuffer; +/** Client data that stays across deathmatch respawns.*/ public class client_respawn_t -// client data that stays across deathmatch respawns + { - client_persistant_t coop_respawn = new client_persistant_t(); // what to set client->pers to on a respawn - int enterframe; // level.framenum the client entered the game - int score; // frags, etc - float cmd_angles[] = { 0, 0, 0 }; // angles sent over in the last command - boolean spectator; // client is a spectator + /** What to set client->pers to on a respawn */ + protected client_persistant_t coop_respawn = new client_persistant_t(); + + /** Level.framenum the client entered the game. */ + protected int enterframe; + + /** frags, etc. */ + protected int score; + + /** angles sent over in the last command. */ + protected float cmd_angles[] = { 0, 0, 0 }; + + /** client is a spectator. */ + protected boolean spectator; + + /** Copies the client respawn data. */ public void set(client_respawn_t from) { coop_respawn.set(from.coop_respawn); @@ -47,7 +61,7 @@ public class client_respawn_t spectator = from.spectator; } - //ok + /** Clears the client reaspawn informations. */ public void clear() { coop_respawn = new client_persistant_t(); @@ -57,17 +71,33 @@ public class client_respawn_t spectator = false; } - public void load(ByteBuffer bb) throws IOException + /** Reads a client_respawn from a file. */ + public void read(QuakeFile f) throws IOException + { + coop_respawn.read(f); + enterframe = f.readInt(); + score = f.readInt(); + cmd_angles[0] = f.readFloat(); + cmd_angles[1] = f.readFloat(); + cmd_angles[2] = f.readFloat(); + spectator = f.readInt() != 0; + } + + /** Writes a client_respawn to a file. */ + public void write(QuakeFile f) throws IOException { - coop_respawn.load(bb); - enterframe = bb.getInt(); - score = bb.getInt(); - cmd_angles[0] = bb.getFloat(); - cmd_angles[1] = bb.getFloat(); - cmd_angles[2] = bb.getFloat(); - spectator = bb.getInt() != 0; + coop_respawn.write(f); + f.writeInt(enterframe); + f.writeInt(score); + f.writeFloat(cmd_angles[0]); + f.writeFloat(cmd_angles[1]); + f.writeFloat(cmd_angles[2]); + f.writeInt(spectator?1:0); } + + + /** Prints out a client_respawn_t to the quake console.*/ public void dump() { coop_respawn.dump(); diff --git a/src/jake2/game/edict_t.java b/src/jake2/game/edict_t.java index 229b18b..a132072 100644 --- a/src/jake2/game/edict_t.java +++ b/src/jake2/game/edict_t.java @@ -18,111 +18,130 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +// Created on 04.11.2003 by RST. +// $Id: edict_t.java,v 1.3 2004-08-20 21:29:57 salomo Exp $ + package jake2.game; +import java.io.IOException; +import java.io.RandomAccessFile; + import jake2.*; import jake2.util.*; -public class edict_t { - - public edict_t(int i) { - s.number = i; - index = i; +public class edict_t +{ + + /** Constructor. */ + public edict_t(int i) + { + s.number= i; + index= i; } - public void clear() { + /** Used during level loading. */ + public void cleararealinks() + { + area= new link_t(this); } - // integrated entity state - public entity_state_t s = new entity_state_t(this); + /** Integrated entity state. */ + public entity_state_t s= new entity_state_t(this); public boolean inuse; public int linkcount; - // FIXME: move these fields to a server private sv_entity_t - public link_t area = new link_t(this); // linked to a division node or leaf + /** FIXME: move these fields to a server private sv_entity_t. + * linked to a division node or leaf. */ + public link_t area= new link_t(this); + + /** if -1, use headnode instead.*/ + public int num_clusters; + public int clusternums[]= new int[Defines.MAX_ENT_CLUSTERS]; - public int num_clusters; // if -1, use headnode instead - public int clusternums[] = new int[Defines.MAX_ENT_CLUSTERS]; - public int headnode; // unused if num_clusters != -1 + /** unused if num_clusters != -1. */ + public int headnode; public int areanum, areanum2; //================================ - public int svflags; // SVF_NOCLIENT, SVF_DEADMONSTER, SVF_MONSTER, etc - public float[] mins = { 0, 0, 0 }; - public float[] maxs = { 0, 0, 0 }; - public float[] absmin = { 0, 0, 0 }; - public float[] absmax = { 0, 0, 0 }; - public float[] size = { 0, 0, 0 }; + /** SVF_NOCLIENT, SVF_DEADMONSTER, SVF_MONSTER, etc. */ + public int svflags; + public float[] mins= { 0, 0, 0 }; + public float[] maxs= { 0, 0, 0 }; + public float[] absmin= { 0, 0, 0 }; + public float[] absmax= { 0, 0, 0 }; + public float[] size= { 0, 0, 0 }; public int solid; public int clipmask; - // the game dll can add anything it wants after - // this point in the structure - // DO NOT MODIFY ANYTHING ABOVE THIS, THE SERVER - // EXPECTS THE FIELDS IN THAT ORDER! - //================================ public int movetype; public int flags; - public String model = null; - public float freetime; // sv.time when the object was freed + public String model= null; + + /** sv.time when the object was freed. */ + public float freetime; // // only used locally in game, not by server // - public String message = null; - public String classname = ""; + public String message= null; + public String classname= ""; public int spawnflags; public float timestamp; - // set in qe3, -1 = up, -2 = down + /** set in qe3, -1 = up, -2 = down */ public float angle; - public String target = null; - public String targetname = null; - public String killtarget = null; - public String team = null; - public String pathtarget = null; - public String deathtarget = null; - public String combattarget = null; + public String target= null; + public String targetname= null; + public String killtarget= null; + public String team= null; + public String pathtarget= null; + public String deathtarget= null; + public String combattarget= null; - public edict_t target_ent = null; + public edict_t target_ent= null; public float speed, accel, decel; - public float[] movedir = { 0, 0, 0 }; + public float[] movedir= { 0, 0, 0 }; - public float[] pos1 = { 0, 0, 0 }; - public float[] pos2 = { 0, 0, 0 }; + public float[] pos1= { 0, 0, 0 }; + public float[] pos2= { 0, 0, 0 }; - public float[] velocity = { 0, 0, 0 }; - public float[] avelocity = { 0, 0, 0 }; + public float[] velocity= { 0, 0, 0 }; + public float[] avelocity= { 0, 0, 0 }; public int mass; public float air_finished; - public float gravity; // per entity gravity multiplier (1.0 is normal) - // use for lowgrav artifact, flares - public edict_t goalentity = null; - public edict_t movetarget = null; + /** per entity gravity multiplier (1.0 is normal). */ + public float gravity; + /** use for lowgrav artifact, flares. */ + + public edict_t goalentity= null; + public edict_t movetarget= null; public float yaw_speed; public float ideal_yaw; public float nextthink; - public EntThinkAdapter prethink = null; - public EntThinkAdapter think = null; - public EntBlockedAdapter blocked = null; - public EntTouchAdapter touch = null; - public EntUseAdapter use = null; - public EntPainAdapter pain = null; - public EntDieAdapter die = null; + public EntThinkAdapter prethink= null; + public EntThinkAdapter think= null; + public EntBlockedAdapter blocked= null; + public EntTouchAdapter touch= null; + public EntUseAdapter use= null; + public EntPainAdapter pain= null; + public EntDieAdapter die= null; - public float touch_debounce_time; // are all these legit? do we need more/less of them? + /** Are all these legit? do we need more/less of them? */ + public float touch_debounce_time; public float pain_debounce_time; public float damage_debounce_time; - public float fly_sound_debounce_time; //move to clientinfo + + /** Move to clientinfo.*/ + public float fly_sound_debounce_time; public float last_move_time; public int health; @@ -133,37 +152,42 @@ public class edict_t { public float powerarmor_time; - public String map = null; - ; // target_changelevel + /** target_changelevel. */ + public String map= null; - public int viewheight; // height above origin where eyesight is determined + /** Height above origin where eyesight is determined. */ + public int viewheight; public int takedamage; public int dmg; public int radius_dmg; public float dmg_radius; - public int sounds; //make this a spawntemp var? + + /** make this a spawntemp var? */ + public int sounds; public int count; - public edict_t chain = null; - public edict_t enemy = null; - public edict_t oldenemy = null; - public edict_t activator = null; - public edict_t groundentity = null; + public edict_t chain= null; + public edict_t enemy= null; + public edict_t oldenemy= null; + public edict_t activator= null; + public edict_t groundentity= null; public int groundentity_linkcount; - public edict_t teamchain = null; - public edict_t teammaster = null; + public edict_t teamchain= null; + public edict_t teammaster= null; - public edict_t mynoise = null; // can go in client only - public edict_t mynoise2 = null; + /** can go in client only. */ + public edict_t mynoise= null; + public edict_t mynoise2= null; public int noise_index; public int noise_index2; public float volume; public float attenuation; - // timing variables + /** Timing variables. */ public float wait; - public float delay; // before firing targets + /** before firing targets...*/ + public float delay; public float random; public float teleport_time; @@ -171,298 +195,557 @@ public class edict_t { public int watertype; public int waterlevel; - public float[] move_origin = { 0, 0, 0 }; + public float[] move_origin= { 0, 0, 0 }; - public float[] move_angles = { 0, 0, 0 }; + public float[] move_angles= { 0, 0, 0 }; - // move this to clientinfo? + /** move this to clientinfo? .*/ public int light_level; - public int style; // also used as areaportal number + /** also used as areaportal number. */ + public int style; public gitem_t item; // for bonus items - // common integrated data blocks - public moveinfo_t moveinfo = new moveinfo_t(); - public monsterinfo_t monsterinfo = new monsterinfo_t(); + /** common integrated data blocks. */ + public moveinfo_t moveinfo= new moveinfo_t(); + public monsterinfo_t monsterinfo= new monsterinfo_t(); public gclient_t client; public edict_t owner; - - public int index; //introduced by rst - + + /** Introduced by rst. */ + public int index; ///////////////////////////////////////////////// - public boolean set(String key, String value) { + public boolean set(String key, String value) + { - if (key.equals("classname")) { - classname = GameSpawn.ED_NewString(value); + if (key.equals("classname")) + { + classname= GameSpawn.ED_NewString(value); return true; } // F_LSTRING), - if (key.equals("model")) { - model = GameSpawn.ED_NewString(value); + if (key.equals("model")) + { + model= GameSpawn.ED_NewString(value); return true; } // F_LSTRING), - if (key.equals("spawnflags")) { - spawnflags = Lib.atoi(value); + if (key.equals("spawnflags")) + { + spawnflags= Lib.atoi(value); return true; } // F_INT), - if (key.equals("speed")) { - speed = Lib.atof(value); + if (key.equals("speed")) + { + speed= Lib.atof(value); return true; } // F_FLOAT), - if (key.equals("accel")) { - accel = Lib.atof(value); + if (key.equals("accel")) + { + accel= Lib.atof(value); return true; } // F_FLOAT), - if (key.equals("decel")) { - decel = Lib.atof(value); + if (key.equals("decel")) + { + decel= Lib.atof(value); return true; } // F_FLOAT), - if (key.equals("target")) { - target = GameSpawn.ED_NewString(value); + if (key.equals("target")) + { + target= GameSpawn.ED_NewString(value); return true; } // F_LSTRING), - if (key.equals("targetname")) { - targetname = GameSpawn.ED_NewString(value); + if (key.equals("targetname")) + { + targetname= GameSpawn.ED_NewString(value); return true; } // F_LSTRING), - if (key.equals("pathtarget")) { - pathtarget = GameSpawn.ED_NewString(value); + if (key.equals("pathtarget")) + { + pathtarget= GameSpawn.ED_NewString(value); return true; } // F_LSTRING), - if (key.equals("deathtarget")) { - deathtarget = GameSpawn.ED_NewString(value); + if (key.equals("deathtarget")) + { + deathtarget= GameSpawn.ED_NewString(value); return true; } // F_LSTRING), - if (key.equals("killtarget")) { - killtarget = GameSpawn.ED_NewString(value); + if (key.equals("killtarget")) + { + killtarget= GameSpawn.ED_NewString(value); return true; } // F_LSTRING), - if (key.equals("combattarget")) { - combattarget = GameSpawn.ED_NewString(value); + if (key.equals("combattarget")) + { + combattarget= GameSpawn.ED_NewString(value); return true; } // F_LSTRING), - if (key.equals("message")) { - message = GameSpawn.ED_NewString(value); + if (key.equals("message")) + { + message= GameSpawn.ED_NewString(value); return true; } // F_LSTRING), - if (key.equals("team")) { - team = GameSpawn.ED_NewString(value); + if (key.equals("team")) + { + team= GameSpawn.ED_NewString(value); return true; } // F_LSTRING), - if (key.equals("wait")) { - wait = Lib.atof(value); + if (key.equals("wait")) + { + wait= Lib.atof(value); return true; } // F_FLOAT), - if (key.equals("delay")) { - delay = Lib.atof(value); + if (key.equals("delay")) + { + delay= Lib.atof(value); return true; } // F_FLOAT), - if (key.equals("random")) { - random = Lib.atof(value); + if (key.equals("random")) + { + random= Lib.atof(value); return true; } // F_FLOAT), - if (key.equals("move_origin")) { - move_origin = Lib.atov(value); + if (key.equals("move_origin")) + { + move_origin= Lib.atov(value); return true; } // F_VECTOR), - if (key.equals("move_angles")) { - move_angles = Lib.atov(value); + if (key.equals("move_angles")) + { + move_angles= Lib.atov(value); return true; } // F_VECTOR), - if (key.equals("style")) { - style = Lib.atoi(value); + if (key.equals("style")) + { + style= Lib.atoi(value); return true; } // F_INT), - if (key.equals("count")) { - count = Lib.atoi(value); + if (key.equals("count")) + { + count= Lib.atoi(value); return true; } // F_INT), - if (key.equals("health")) { - health = Lib.atoi(value); + if (key.equals("health")) + { + health= Lib.atoi(value); return true; } // F_INT), - if (key.equals("sounds")) { - sounds = Lib.atoi(value); + if (key.equals("sounds")) + { + sounds= Lib.atoi(value); return true; } // F_INT), - if (key.equals("light")) { + if (key.equals("light")) + { return true; } // F_IGNORE), - if (key.equals("dmg")) { - dmg = Lib.atoi(value); + if (key.equals("dmg")) + { + dmg= Lib.atoi(value); return true; } // F_INT), - if (key.equals("mass")) { - mass = Lib.atoi(value); + if (key.equals("mass")) + { + mass= Lib.atoi(value); return true; } // F_INT), - if (key.equals("volume")) { - volume = Lib.atof(value); + if (key.equals("volume")) + { + volume= Lib.atof(value); return true; } // F_FLOAT), - if (key.equals("attenuation")) { - attenuation = Lib.atof(value); + if (key.equals("attenuation")) + { + attenuation= Lib.atof(value); return true; } // F_FLOAT), - if (key.equals("map")) { - map = GameSpawn.ED_NewString(value); + if (key.equals("map")) + { + map= GameSpawn.ED_NewString(value); return true; } // F_LSTRING), - if (key.equals("origin")) { - s.origin = Lib.atov(value); + if (key.equals("origin")) + { + s.origin= Lib.atov(value); return true; } // F_VECTOR), - if (key.equals("angles")) { - s.angles = Lib.atov(value); + if (key.equals("angles")) + { + s.angles= Lib.atov(value); return true; } // F_VECTOR), - if (key.equals("angle")) { - s.angles = new float[] { 0, Lib.atof(value), 0 }; + if (key.equals("angle")) + { + s.angles= new float[] { 0, Lib.atof(value), 0 }; return true; } // F_ANGLEHACK), - /* --- NOSPAWN --- - if (key.equals("goalentity")) { - return true; - } // F_EDICT, FFL_NOSPAWN), - - if (key.equals("movetarget")) { - return true; - } // F_EDICT, FFL_NOSPAWN), - - if (key.equals("enemy")) { - return true; - } // F_EDICT, FFL_NOSPAWN), - - if (key.equals("oldenemy")) { - return true; - } // F_EDICT, FFL_NOSPAWN), - - if (key.equals("activator")) { - return true; - } // F_EDICT, FFL_NOSPAWN), - - if (key.equals("groundentity")) { - return true; - } // F_EDICT, FFL_NOSPAWN), - if (key.equals("teamchain")) { - return true; - } // F_EDICT, FFL_NOSPAWN), - if (key.equals("teammaster")) { - return true; - } // F_EDICT, FFL_NOSPAWN), - if (key.equals("owner")) { - return true; - } // F_EDICT, FFL_NOSPAWN), - if (key.equals("mynoise")) { - return true; - } // F_EDICT, FFL_NOSPAWN), - if (key.equals("mynoise2")) { - return true; - } // F_EDICT, FFL_NOSPAWN), - if (key.equals("target_ent")) { - return true; - } // F_EDICT, FFL_NOSPAWN), - if (key.equals("chain")) { - return true; - } // F_EDICT, FFL_NOSPAWN), - if (key.equals("prethink")) { - return true; - } // F_FUNCTION, FFL_NOSPAWN), - if (key.equals("think")) { - return true; - } // F_FUNCTION, FFL_NOSPAWN), - if (key.equals("blocked")) { - return true; - } // F_FUNCTION, FFL_NOSPAWN), - if (key.equals("touch")) { - return true; - } // F_FUNCTION, FFL_NOSPAWN), - if (key.equals("use")) { - return true; - } // F_FUNCTION, FFL_NOSPAWN), - if (key.equals("pain")) { - return true; - } // F_FUNCTION, FFL_NOSPAWN), - if (key.equals("die")) { - return true; - } // F_FUNCTION, FFL_NOSPAWN), - if (key.equals("stand")) { - return true; - } // F_FUNCTION, FFL_NOSPAWN), - if (key.equals("idle")) { - return true; - } // F_FUNCTION, FFL_NOSPAWN), - if (key.equals("search")) { - return true; - } // F_FUNCTION, FFL_NOSPAWN), - if (key.equals("walk")) { - return true; - } // F_FUNCTION, FFL_NOSPAWN), - if (key.equals("run")) { - return true; - } // F_FUNCTION, FFL_NOSPAWN), - if (key.equals("dodge")) { - return true; - } // F_FUNCTION, FFL_NOSPAWN), - if (key.equals("attack")) { - return true; - } // F_FUNCTION, FFL_NOSPAWN), - if (key.equals("melee")) { - return true; - } // F_FUNCTION, FFL_NOSPAWN), - if (key.equals("sight")) { - return true; - } // F_FUNCTION, FFL_NOSPAWN), - if (key.equals("checkattack")) { - return true; - } // F_FUNCTION, FFL_NOSPAWN), - if (key.equals("currentmove")) { - return true; - } // F_MMOVE, FFL_NOSPAWN), - if (key.equals("endfunc")) { - return true; - } // F_FUNCTION, FFL_NOSPAWN), - - */ - if (key.equals("item")) { + if (key.equals("item")) + { Game.gi.error("ent.set(\"item\") called."); return true; } // F_ITEM) return false; } + + /** Writes the entity to the file. */ + public void write(QuakeFile f) throws IOException + { + + s.write(f); + f.writeBoolean(inuse); + f.writeInt(linkcount); + f.writeInt(num_clusters); + + f.writeInt(9999); + + if (clusternums == null) + f.writeInt(-1); + else + { + f.writeInt(Defines.MAX_ENT_CLUSTERS); + for (int n= 0; n < Defines.MAX_ENT_CLUSTERS; n++) + f.writeInt(clusternums[n]); + + } + f.writeInt(headnode); + f.writeInt(areanum); + f.writeInt(areanum2); + f.writeInt(svflags); + f.writeVector(mins); + f.writeVector(maxs); + f.writeVector(absmin); + f.writeVector(absmax); + f.writeVector(size); + f.writeInt(solid); + f.writeInt(clipmask); + + f.writeInt(movetype); + f.writeInt(flags); + + f.writeString(model); + f.writeFloat(freetime); + f.writeString(message); + f.writeString(classname); + f.writeInt(spawnflags); + f.writeFloat(timestamp); + + f.writeFloat(angle); + + f.writeString(target); + f.writeString(targetname); + f.writeString(team); + f.writeString(pathtarget); + f.writeString(deathtarget); + f.writeString(combattarget); + + f.writeEdictRef(target_ent); + + f.writeFloat(speed); + f.writeFloat(accel); + f.writeFloat(decel); + + f.writeVector(movedir); + + f.writeVector(pos1); + f.writeVector(pos2); + + f.writeVector(velocity); + f.writeVector(avelocity); + + f.writeInt(mass); + f.writeFloat(air_finished); + + f.writeFloat(gravity); + + f.writeEdictRef(goalentity); + f.writeEdictRef(movetarget); + + f.writeFloat(yaw_speed); + f.writeFloat(ideal_yaw); + + f.writeFloat(nextthink); + + f.writeAdapter(prethink); + f.writeAdapter(think); + f.writeAdapter(blocked); + + f.writeAdapter(touch); + f.writeAdapter(use); + f.writeAdapter(pain); + f.writeAdapter(die); + + f.writeFloat(touch_debounce_time); + f.writeFloat(pain_debounce_time); + f.writeFloat(damage_debounce_time); + + f.writeFloat(fly_sound_debounce_time); + f.writeFloat(last_move_time); + + f.writeInt(health); + f.writeInt(max_health); + + f.writeInt(gib_health); + f.writeInt(deadflag); + f.writeInt(show_hostile); + + f.writeFloat(powerarmor_time); + + f.writeString(map); + + f.writeInt(viewheight); + f.writeInt(takedamage); + f.writeInt(dmg); + f.writeInt(radius_dmg); + f.writeFloat(dmg_radius); + + f.writeInt(sounds); + f.writeInt(count); + + f.writeEdictRef(chain); + f.writeEdictRef(enemy); + f.writeEdictRef(oldenemy); + f.writeEdictRef(activator); + f.writeEdictRef(groundentity); + f.writeInt(groundentity_linkcount); + f.writeEdictRef(teamchain); + f.writeEdictRef(teammaster); + + f.writeEdictRef(mynoise); + f.writeEdictRef(mynoise2); + + f.writeInt(noise_index); + f.writeInt(noise_index2); + + f.writeFloat(volume); + f.writeFloat(attenuation); + f.writeFloat(wait); + f.writeFloat(delay); + f.writeFloat(random); + + f.writeFloat(teleport_time); + + f.writeInt(watertype); + f.writeInt(waterlevel); + f.writeVector(move_origin); + f.writeVector(move_angles); + + f.writeInt(light_level); + f.writeInt(style); + + f.writeItem(item); + + moveinfo.write(f); + monsterinfo.write(f); + if (client == null) + f.writeInt(-1); + else + f.writeInt(client.index); + + f.writeEdictRef(owner); + + // rst's checker :-) + f.writeInt(9876); + } + + /** Reads the entity from the file.*/ + public void read(QuakeFile f) throws IOException + { + s.read(f); + inuse= f.readBoolean(); + linkcount= f.readInt(); + num_clusters= f.readInt(); + + if (f.readInt() != 9999) + new Throwable("wrong read pos!").printStackTrace(); + + int len= f.readInt(); + + if (len == -1) + clusternums= null; + else + { + clusternums= new int[Defines.MAX_ENT_CLUSTERS]; + for (int n= 0; n < Defines.MAX_ENT_CLUSTERS; n++) + clusternums[n]= f.readInt(); + } + + headnode= f.readInt(); + areanum= f.readInt(); + areanum2= f.readInt(); + svflags= f.readInt(); + mins= f.readVector(); + maxs= f.readVector(); + absmin= f.readVector(); + absmax= f.readVector(); + size= f.readVector(); + solid= f.readInt(); + clipmask= f.readInt(); + + movetype= f.readInt(); + flags= f.readInt(); + + model= f.readString(); + freetime= f.readFloat(); + message= f.readString(); + classname= f.readString(); + spawnflags= f.readInt(); + timestamp= f.readFloat(); + + angle= f.readFloat(); + + target= f.readString(); + targetname= f.readString(); + team= f.readString(); + pathtarget= f.readString(); + deathtarget= f.readString(); + combattarget= f.readString(); + + target_ent= f.readEdictRef(); + + speed= f.readFloat(); + accel= f.readFloat(); + decel= f.readFloat(); + + movedir= f.readVector(); + + pos1= f.readVector(); + pos2= f.readVector(); + + velocity= f.readVector(); + avelocity= f.readVector(); + + mass= f.readInt(); + air_finished= f.readFloat(); + + gravity= f.readFloat(); + + goalentity= f.readEdictRef(); + movetarget= f.readEdictRef(); + + yaw_speed= f.readFloat(); + ideal_yaw= f.readFloat(); + + nextthink= f.readFloat(); + + prethink= (EntThinkAdapter) f.readAdapter(); + think= (EntThinkAdapter) f.readAdapter(); + blocked= (EntBlockedAdapter) f.readAdapter(); + + touch= (EntTouchAdapter) f.readAdapter(); + use= (EntUseAdapter) f.readAdapter(); + pain= (EntPainAdapter) f.readAdapter(); + die= (EntDieAdapter) f.readAdapter(); + + touch_debounce_time= f.readFloat(); + pain_debounce_time= f.readFloat(); + damage_debounce_time= f.readFloat(); + + fly_sound_debounce_time= f.readFloat(); + last_move_time= f.readFloat(); + + health= f.readInt(); + max_health= f.readInt(); + + gib_health= f.readInt(); + deadflag= f.readInt(); + show_hostile= f.readInt(); + + powerarmor_time= f.readFloat(); + + map= f.readString(); + + viewheight= f.readInt(); + takedamage= f.readInt(); + dmg= f.readInt(); + radius_dmg= f.readInt(); + dmg_radius= f.readFloat(); + + sounds= f.readInt(); + count= f.readInt(); + + chain= f.readEdictRef(); + enemy= f.readEdictRef(); + + oldenemy= f.readEdictRef(); + activator= f.readEdictRef(); + groundentity= f.readEdictRef(); + if (index == 145) + System.out.println("loadground:" + groundentity); + groundentity_linkcount= f.readInt(); + teamchain= f.readEdictRef(); + teammaster= f.readEdictRef(); + + mynoise= f.readEdictRef(); + mynoise2= f.readEdictRef(); + + noise_index= f.readInt(); + noise_index2= f.readInt(); + + volume= f.readFloat(); + attenuation= f.readFloat(); + wait= f.readFloat(); + delay= f.readFloat(); + random= f.readFloat(); + + teleport_time= f.readFloat(); + + watertype= f.readInt(); + waterlevel= f.readInt(); + move_origin= f.readVector(); + move_angles= f.readVector(); + + light_level= f.readInt(); + style= f.readInt(); + + item= f.readItem(); + + moveinfo.read(f); + monsterinfo.read(f); + + int ndx= f.readInt(); + if (ndx == -1) + client= null; + else + client= Game.game.clients[ndx]; + + owner= f.readEdictRef(); + + // rst's checker :-) + if (f.readInt() != 9876) + System.err.println("ent load check failed for num " + index); + } } diff --git a/src/jake2/game/entity_state_t.java b/src/jake2/game/entity_state_t.java index 25c3162..e4e7b68 100644 --- a/src/jake2/game/entity_state_t.java +++ b/src/jake2/game/entity_state_t.java @@ -19,33 +19,41 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 08.11.2003 by RST. -// $Id: entity_state_t.java,v 1.2 2004-07-08 15:58:43 hzi Exp $ +// $Id: entity_state_t.java,v 1.3 2004-08-20 21:29:58 salomo Exp $ package jake2.game; +import java.io.IOException; +import java.io.RandomAccessFile; + import jake2.util.Math3D; +import jake2.util.QuakeFile; public class entity_state_t implements Cloneable { - // entity_state_t is the information conveyed from the server - // in an update message about entities that the client will - // need to render in some way - + /** entity_state_t is the information conveyed from the server + in an update message about entities that the client will + need to render in some way. */ public entity_state_t(edict_t ent) { this.surrounding_ent = ent; } - public int number = -99999; // edict index + /** edict index. */ + public int number = -99999; public edict_t surrounding_ent = null; public float[] origin = { 0, 0, 0 }; public float[] angles = { 0, 0, 0 }; - public float[] old_origin = { 0, 0, 0 }; // for lerping + + /** for lerping. */ + public float[] old_origin = { 0, 0, 0 }; public int modelindex; - public int modelindex2, modelindex3, modelindex4; // weapons, CTF flags, etc. + /** weapons, CTF flags, etc. */ + public int modelindex2, modelindex3, modelindex4; public int frame; public int skinnum; - public int effects; // PGM - we're filling it, so it needs to be unsigned + /** PGM - we're filling it, so it needs to be unsigned. */ + public int effects; public int renderfx; public int solid; // for client side prediction, 8*(bits 0-4) is x/y radius @@ -56,6 +64,60 @@ public class entity_state_t implements Cloneable // events only go out for a single frame, they // are automatically cleared each frame + /** Writes the entity state to the file. */ + public void write(QuakeFile f) throws IOException + { + f.writeEdictRef(surrounding_ent); + f.writeVector(origin); + f.writeVector(angles); + f.writeVector(old_origin); + + f.writeInt(modelindex); + + f.writeInt(modelindex2); + f.writeInt(modelindex3); + f.writeInt(modelindex4); + + f.writeInt(frame); + f.writeInt(skinnum); + + f.writeInt(effects); + f.writeInt(renderfx); + f.writeInt(solid); + + f.writeInt(sound); + f.writeInt(event); + + } + + /** Reads the entity state from the file. */ + public void read(QuakeFile f) throws IOException + { + surrounding_ent = f.readEdictRef(); + origin = f.readVector(); + angles = f.readVector(); + old_origin = f.readVector(); + + modelindex = f.readInt(); + + modelindex2= f.readInt(); + modelindex3= f.readInt(); + modelindex4= f.readInt(); + + frame = f.readInt(); + skinnum = f.readInt(); + + effects = f.readInt(); + renderfx = f.readInt(); + solid = f.readInt(); + + sound = f.readInt(); + event = f.readInt(); + + + } + + public entity_state_t getClone() { entity_state_t out = new entity_state_t(this.surrounding_ent); diff --git a/src/jake2/game/game_export_t.java b/src/jake2/game/game_export_t.java index 9dabf51..38df9db 100644 --- a/src/jake2/game/game_export_t.java +++ b/src/jake2/game/game_export_t.java @@ -19,11 +19,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 31.10.2003 by RST. -// $Id: game_export_t.java,v 1.3 2004-07-09 06:50:49 hzi Exp $ +// $Id: game_export_t.java,v 1.4 2004-08-20 21:29:58 salomo Exp $ package jake2.game; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; + import jake2.qcommon.Com; +import jake2.util.QuakeFile; // //functions exported by the game subsystem @@ -58,8 +63,7 @@ public class game_export_t // ReadGame is called on a loadgame. public void WriteGame(String filename, boolean autosave) { - // TODO WriteGame not implemented. - Com.Println("WriteGame not implemented."); + GameSave.WriteGame(filename, autosave); } public void ReadGame(String filename) @@ -71,28 +75,43 @@ public class game_export_t // loaded with SpawnEntities public void WriteLevel(String filename) { - // TODO WriteLevel not implemented. - Com.Println("WriteLevel not implemented."); + try + { + GameSave.WriteLevel(filename); + } + catch (IOException e) + { + e.printStackTrace(); + } } public void ReadLevel(String filename) { - // TODO ReadLevel not implemented. - Com.Println("ReadLevel not implemented."); + try + { + GameSave.ReadLevel(filename); + } + catch (IOException e) + { + e.printStackTrace(); + } } public boolean ClientConnect(edict_t ent, String userinfo) { return PlayerClient.ClientConnect(ent, userinfo); } + public void ClientBegin(edict_t ent) { PlayerClient.ClientBegin(ent); } + public void ClientUserinfoChanged(edict_t ent, String userinfo) { PlayerClient.ClientUserinfoChanged(ent, userinfo); } + public void ClientDisconnect(edict_t ent) { PlayerClient.ClientDisconnect(ent); @@ -132,4 +151,4 @@ public class game_export_t public edict_t edicts[] = Game.g_edicts; public int num_edicts; // current number, <= max_edicts public int max_edicts; -} +}
\ No newline at end of file diff --git a/src/jake2/game/game_locals_t.java b/src/jake2/game/game_locals_t.java index e638195..cbc109f 100644 --- a/src/jake2/game/game_locals_t.java +++ b/src/jake2/game/game_locals_t.java @@ -19,15 +19,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 31.10.2003 by RST. -// $Id: game_locals_t.java,v 1.3 2004-07-12 20:47:01 hzi Exp $ +// $Id: game_locals_t.java,v 1.4 2004-08-20 21:29:58 salomo Exp $ package jake2.game; import jake2.Defines; import jake2.qcommon.Com; import jake2.util.Lib; +import jake2.util.QuakeFile; +import java.io.IOException; +import java.io.RandomAccessFile; import java.nio.ByteBuffer; +import java.util.Date; public class game_locals_t extends Defines { @@ -59,28 +63,54 @@ public class game_locals_t extends Defines public int num_items; public boolean autosaved; - public void load(ByteBuffer bb) + /** Reads the game locals from a file. */ + public void load(QuakeFile f) throws IOException { - String date = Lib.readString(bb, 16); + String date = f.readString(); - helpmessage1 = Lib.readString(bb, 512); - helpmessage2 = Lib.readString(bb, 512); + helpmessage1 = f.readString(); + helpmessage2 = f.readString(); - helpchanged = bb.getInt(); + helpchanged = f.readInt(); // gclient_t* - bb.getInt(); - spawnpoint = Lib.readString(bb, 512); - maxclients = bb.getInt(); - maxentities = bb.getInt(); - serverflags = bb.getInt(); - num_items = bb.getInt(); - autosaved = bb.getInt() != 0; + + spawnpoint = f.readString(); + maxclients = f.readInt(); + maxentities = f.readInt(); + serverflags = f.readInt(); + num_items = f.readInt(); + autosaved = f.readInt() != 0; + + // rst's checker :-) + if (f.readInt()!=1928) + System.err.println("error in loading game_locals."); + + } + + /** Writes the game locals to a file. */ + public void write(QuakeFile f) throws IOException + { + f.writeString(new Date().toString()); + f.writeString(helpmessage1); + f.writeString(helpmessage2); + + f.writeInt(helpchanged); + // gclient_t* + + f.writeString(spawnpoint); + f.writeInt(maxclients); + f.writeInt(maxentities); + f.writeInt(serverflags); + f.writeInt(num_items); + f.writeInt(autosaved?1:0); + // rst's checker :-) + f.writeInt(1928); } + /** Prints the game locals.*/ public void dump() { - Com.Println("String helpmessage1: " + helpmessage1); Com.Println("String helpmessage2: " + helpmessage2); diff --git a/src/jake2/game/gclient_t.java b/src/jake2/game/gclient_t.java index ce0a491..2cbda59 100644 --- a/src/jake2/game/gclient_t.java +++ b/src/jake2/game/gclient_t.java @@ -19,15 +19,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 31.10.2003 by RST. -// $Id: gclient_t.java,v 1.2 2004-07-08 15:58:44 hzi Exp $ +// $Id: gclient_t.java,v 1.3 2004-08-20 21:29:58 salomo Exp $ package jake2.game; import jake2.qcommon.Com; import jake2.util.Lib; +import jake2.util.QuakeFile; import java.awt.event.ItemListener; import java.io.IOException; +import java.io.RandomAccessFile; import java.nio.ByteBuffer; public class gclient_t @@ -123,6 +125,9 @@ public class gclient_t public int index; + + + public void clear() { player_state_t ps = new player_state_t(); @@ -163,116 +168,233 @@ public class gclient_t } - public void load(ByteBuffer bb) throws IOException + /** Reads a game client from the file. */ + public void read(QuakeFile f) throws IOException { - ps.load(bb); - - ping = bb.getInt(); - - pers.load(bb); - resp.load(bb); - - old_pmove.load(bb); - - showscores = bb.getInt() != 0; - showinventory = bb.getInt() != 0; - showhelp = bb.getInt() != 0; - showhelpicon = bb.getInt() != 0; - ammo_index = bb.getInt(); - - buttons = bb.getInt(); - oldbuttons = bb.getInt(); - latched_buttons = bb.getInt(); - - //weapon_thunk=bb.getInt()!=0; - bb.getInt(); - //newweapon=GameTarget.itemlist[bb.getInt()]; - bb.getInt(); - - damage_armor = bb.getInt(); - damage_parmor = bb.getInt(); - damage_blood = bb.getInt(); - damage_knockback = bb.getInt(); - - damage_from[0] = bb.getFloat(); - damage_from[1] = bb.getFloat(); - damage_from[2] = bb.getFloat(); - - killer_yaw = bb.getFloat(); - - weaponstate = bb.getInt(); - - kick_angles[0] = bb.getFloat(); - kick_angles[1] = bb.getFloat(); - kick_angles[2] = bb.getFloat(); - - kick_origin[0] = bb.getFloat(); - kick_origin[1] = bb.getFloat(); - kick_origin[2] = bb.getFloat(); - - v_dmg_roll = bb.getFloat(); - v_dmg_pitch = bb.getFloat(); - v_dmg_time = bb.getFloat(); - fall_time = bb.getFloat(); - fall_value = bb.getFloat(); - damage_alpha = bb.getFloat(); - bonus_alpha = bb.getFloat(); - - damage_blend[0] = bb.getFloat(); - damage_blend[1] = bb.getFloat(); - damage_blend[2] = bb.getFloat(); - - v_angle[0] = bb.getFloat(); - v_angle[1] = bb.getFloat(); - v_angle[2] = bb.getFloat(); - - bobtime = bb.getFloat(); - - oldviewangles[0] = bb.getFloat(); - oldviewangles[1] = bb.getFloat(); - oldviewangles[2] = bb.getFloat(); - - oldvelocity[0] = bb.getFloat(); - oldvelocity[1] = bb.getFloat(); - oldvelocity[2] = bb.getFloat(); - - next_drown_time = bb.getFloat(); - - old_waterlevel = bb.getInt(); - breather_sound = bb.getInt(); - machinegun_shots = bb.getInt(); - anim_end = bb.getInt(); - anim_priority = bb.getInt(); - anim_duck = bb.getInt() != 0; - anim_run = bb.getInt() != 0; - - quad_framenum = bb.getFloat(); - invincible_framenum = bb.getFloat(); - breather_framenum = bb.getFloat(); - enviro_framenum = bb.getFloat(); - - grenade_blew_up = bb.getInt() != 0; - grenade_time = bb.getFloat(); - silencer_shots = bb.getInt(); - weapon_sound = bb.getInt(); - pickup_msg_time = bb.getFloat(); - flood_locktill = bb.getFloat(); - flood_when[0] = bb.getFloat(); - flood_when[1] = bb.getFloat(); - flood_when[2] = bb.getFloat(); - flood_when[3] = bb.getFloat(); - flood_when[4] = bb.getFloat(); - flood_when[5] = bb.getFloat(); - flood_when[6] = bb.getFloat(); - flood_when[7] = bb.getFloat(); - flood_when[8] = bb.getFloat(); - flood_when[9] = bb.getFloat(); - flood_whenhead = bb.getInt(); - respawn_time = bb.getFloat(); - chase_target = GameUtil.g_edicts[bb.getInt()]; - update_chase = bb.getInt() != 0; + ps.load(f); + + ping = f.readInt(); + + pers.read(f); + resp.read(f); + + old_pmove.load(f); + + showscores = f.readInt() != 0; + showinventory = f.readInt() != 0; + showhelp = f.readInt() != 0; + showhelpicon = f.readInt() != 0; + ammo_index = f.readInt(); + + buttons = f.readInt(); + oldbuttons = f.readInt(); + latched_buttons = f.readInt(); + + weapon_thunk=f.readInt()!=0; + + newweapon=f.readItem(); + + + damage_armor = f.readInt(); + damage_parmor = f.readInt(); + damage_blood = f.readInt(); + damage_knockback = f.readInt(); + + damage_from[0] = f.readFloat(); + damage_from[1] = f.readFloat(); + damage_from[2] = f.readFloat(); + + killer_yaw = f.readFloat(); + + weaponstate = f.readInt(); + + kick_angles[0] = f.readFloat(); + kick_angles[1] = f.readFloat(); + kick_angles[2] = f.readFloat(); + + kick_origin[0] = f.readFloat(); + kick_origin[1] = f.readFloat(); + kick_origin[2] = f.readFloat(); + + v_dmg_roll = f.readFloat(); + v_dmg_pitch = f.readFloat(); + v_dmg_time = f.readFloat(); + fall_time = f.readFloat(); + fall_value = f.readFloat(); + damage_alpha = f.readFloat(); + bonus_alpha = f.readFloat(); + + damage_blend[0] = f.readFloat(); + damage_blend[1] = f.readFloat(); + damage_blend[2] = f.readFloat(); + + v_angle[0] = f.readFloat(); + v_angle[1] = f.readFloat(); + v_angle[2] = f.readFloat(); + + bobtime = f.readFloat(); + + oldviewangles[0] = f.readFloat(); + oldviewangles[1] = f.readFloat(); + oldviewangles[2] = f.readFloat(); + + oldvelocity[0] = f.readFloat(); + oldvelocity[1] = f.readFloat(); + oldvelocity[2] = f.readFloat(); + + next_drown_time = f.readFloat(); + + old_waterlevel = f.readInt(); + breather_sound = f.readInt(); + machinegun_shots = f.readInt(); + anim_end = f.readInt(); + anim_priority = f.readInt(); + anim_duck = f.readInt() != 0; + anim_run = f.readInt() != 0; + + quad_framenum = f.readFloat(); + invincible_framenum = f.readFloat(); + breather_framenum = f.readFloat(); + enviro_framenum = f.readFloat(); + + grenade_blew_up = f.readInt() != 0; + grenade_time = f.readFloat(); + silencer_shots = f.readInt(); + weapon_sound = f.readInt(); + pickup_msg_time = f.readFloat(); + flood_locktill = f.readFloat(); + flood_when[0] = f.readFloat(); + flood_when[1] = f.readFloat(); + flood_when[2] = f.readFloat(); + flood_when[3] = f.readFloat(); + flood_when[4] = f.readFloat(); + flood_when[5] = f.readFloat(); + flood_when[6] = f.readFloat(); + flood_when[7] = f.readFloat(); + flood_when[8] = f.readFloat(); + flood_when[9] = f.readFloat(); + flood_whenhead = f.readInt(); + respawn_time = f.readFloat(); + chase_target = f.readEdictRef(); + update_chase = f.readInt() != 0; + + if (f.readInt() != 8765) + System.err.println("game client load failed for num=" + index); } + + /** Writes a game_client_t (a player) to a file. */ + public void write(QuakeFile f) throws IOException + { + ps.write(f); + + f.writeInt(ping); + + pers.write(f); + resp.write(f); + + old_pmove.write(f); + + f.writeInt(showscores?1:0); + f.writeInt(showinventory?1:0); + f.writeInt(showhelp?1:0); + f.writeInt(showhelpicon?1:0); + f.writeInt(ammo_index); + + f.writeInt(buttons); + f.writeInt(oldbuttons); + f.writeInt(latched_buttons); + + f.writeInt(weapon_thunk?1:0); + f.writeItem(newweapon); + + + f.writeInt(damage_armor); + f.writeInt(damage_parmor); + f.writeInt(damage_blood); + f.writeInt(damage_knockback); + + f.writeFloat(damage_from[0]); + f.writeFloat(damage_from[1]); + f.writeFloat(damage_from[2]); + + f.writeFloat(killer_yaw); + + f.writeInt(weaponstate); + + f.writeFloat(kick_angles[0]); + f.writeFloat(kick_angles[1]); + f.writeFloat(kick_angles[2]); + + f.writeFloat(kick_origin[0]); + f.writeFloat(kick_origin[1]); + f.writeFloat(kick_origin[2]); + + f.writeFloat(v_dmg_roll); + f.writeFloat(v_dmg_pitch); + f.writeFloat(v_dmg_time); + f.writeFloat(fall_time); + f.writeFloat(fall_value); + f.writeFloat(damage_alpha); + f.writeFloat(bonus_alpha); + + f.writeFloat(damage_blend[0]); + f.writeFloat(damage_blend[1]); + f.writeFloat(damage_blend[2]); + + f.writeFloat(v_angle[0]); + f.writeFloat(v_angle[1]); + f.writeFloat(v_angle[2]); + + f.writeFloat(bobtime); + + f.writeFloat(oldviewangles[0]); + f.writeFloat(oldviewangles[1]); + f.writeFloat(oldviewangles[2]); + + f.writeFloat(oldvelocity[0]); + f.writeFloat(oldvelocity[1]); + f.writeFloat(oldvelocity[2]); + + f.writeFloat(next_drown_time); + + f.writeInt(old_waterlevel); + f.writeInt(breather_sound); + f.writeInt(machinegun_shots); + f.writeInt(anim_end); + f.writeInt(anim_priority); + f.writeInt(anim_duck?1:0); + f.writeInt(anim_run?1:0); + + f.writeFloat(quad_framenum); + f.writeFloat(invincible_framenum); + f.writeFloat(breather_framenum); + f.writeFloat(enviro_framenum); + + f.writeInt(grenade_blew_up?1:0); + f.writeFloat(grenade_time); + f.writeInt(silencer_shots); + f.writeInt(weapon_sound); + f.writeFloat(pickup_msg_time); + f.writeFloat(flood_locktill); + f.writeFloat(flood_when[0]); + f.writeFloat(flood_when[1]); + f.writeFloat(flood_when[2]); + f.writeFloat(flood_when[3]); + f.writeFloat(flood_when[4]); + f.writeFloat(flood_when[5]); + f.writeFloat(flood_when[6]); + f.writeFloat(flood_when[7]); + f.writeFloat(flood_when[8]); + f.writeFloat(flood_when[9]); + f.writeInt(flood_whenhead); + f.writeFloat(respawn_time); + f.writeEdictRef(chase_target); + f.writeInt(update_chase?1:0); + + f.writeInt(8765); + } + public void dump() { @@ -357,7 +479,5 @@ public class gclient_t Com.Println("respawn_time: " + respawn_time); Com.Println("chase_target: " + chase_target); Com.Println("update_chase: " + update_chase); - } - } diff --git a/src/jake2/game/gitem_t.java b/src/jake2/game/gitem_t.java index 6849809..f478f34 100644 --- a/src/jake2/game/gitem_t.java +++ b/src/jake2/game/gitem_t.java @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 20.11.2003 by RST. -// $Id: gitem_t.java,v 1.2 2004-07-08 15:58:44 hzi Exp $ +// $Id: gitem_t.java,v 1.3 2004-08-20 21:29:57 salomo Exp $ package jake2.game; @@ -141,5 +141,5 @@ public class gitem_t ""); } - int index; + public int index; } diff --git a/src/jake2/game/level_locals_t.java b/src/jake2/game/level_locals_t.java index 18038bf..dc12cab 100644 --- a/src/jake2/game/level_locals_t.java +++ b/src/jake2/game/level_locals_t.java @@ -19,12 +19,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 20.11.2003 by RST -// $Id: level_locals_t.java,v 1.1 2004-07-07 19:59:25 hzi Exp $ +// $Id: level_locals_t.java,v 1.2 2004-08-20 21:29:57 salomo Exp $ package jake2.game; -public class level_locals_t { - // +import jake2.util.Lib; +import jake2.util.QuakeFile; + +import java.io.IOException; +import java.io.RandomAccessFile; + +public class level_locals_t +{ + // this structure is cleared as each map is entered // it is read/written to the level.sav file for savegames // @@ -46,8 +53,10 @@ public class level_locals_t { public edict_t sight_entity; public int sight_entity_framenum; + public edict_t sound_entity; public int sound_entity_framenum; + public edict_t sound2_entity; public int sound2_entity_framenum; @@ -66,4 +75,87 @@ public class level_locals_t { public int body_que; // dead bodies public int power_cubes; // ugly necessity for coop + + /** Writes the levellocales to the file.*/ + public void write(QuakeFile f) throws IOException + { + f.writeInt(framenum); + f.writeFloat(time); + f.writeString(level_name); + f.writeString(mapname); + f.writeString(nextmap); + f.writeFloat(intermissiontime); + f.writeString(changemap); + f.writeBoolean(exitintermission); + f.writeVector(intermission_origin); + f.writeVector(intermission_angle); + f.writeEdictRef(sight_client); + + f.writeEdictRef(sight_entity); + f.writeInt(sight_entity_framenum); + + f.writeEdictRef(sound_entity); + f.writeInt(sound_entity_framenum); + f.writeEdictRef(sound2_entity); + f.writeInt(sound2_entity_framenum); + + f.writeInt(pic_health); + + f.writeInt(total_secrets); + f.writeInt(found_secrets); + + f.writeInt(total_goals); + f.writeInt(found_goals); + f.writeInt(total_monsters); + f.writeInt(killed_monsters); + + f.writeEdictRef(current_entity); + f.writeInt(body_que); // dead bodies + f.writeInt(power_cubes); // ugly necessity for coop + + // rst's checker :-) + f.writeInt(4711); + } + + /** Reads the level locals from the file. */ + public void read(QuakeFile f) throws IOException + { + framenum = f.readInt(); + time = f.readFloat(); + level_name = f.readString(); + mapname = f.readString(); + nextmap = f.readString(); + intermissiontime = f.readFloat(); + changemap = f.readString(); + exitintermission = f.readBoolean(); + intermission_origin = f.readVector(); + intermission_angle = f.readVector(); + sight_client = f.readEdictRef(); + + sight_entity = f.readEdictRef(); + sight_entity_framenum = f.readInt(); + + sound_entity = f.readEdictRef(); + sound_entity_framenum = f.readInt(); + sound2_entity = f.readEdictRef(); + sound2_entity_framenum = f.readInt(); + + pic_health = f.readInt(); + + total_secrets = f.readInt(); + found_secrets = f.readInt(); + + total_goals = f.readInt(); + found_goals = f.readInt(); + total_monsters = f.readInt(); + killed_monsters = f.readInt(); + + current_entity = f.readEdictRef(); + body_que = f.readInt(); // dead bodies + power_cubes = f.readInt(); // ugly necessity for coop + + // rst's checker :-) + if (f.readInt()!= 4711) + System.out.println("error in reading level_locals."); + } } diff --git a/src/jake2/game/mframe_t.java b/src/jake2/game/mframe_t.java index 6e81af4..af5f095 100644 --- a/src/jake2/game/mframe_t.java +++ b/src/jake2/game/mframe_t.java @@ -19,18 +19,44 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 11.11.2003 by RST. -// $Id: mframe_t.java,v 1.1 2004-07-07 19:59:26 hzi Exp $ +// $Id: mframe_t.java,v 1.2 2004-08-20 21:29:58 salomo Exp $ package jake2.game; -public class mframe_t { - public mframe_t(AIAdapter ai, float dist, EntThinkAdapter think) { +import jake2.util.Lib; +import jake2.util.QuakeFile; + +import java.io.IOException; +import java.io.RandomAccessFile; + +public class mframe_t +{ + public mframe_t(AIAdapter ai, float dist, EntThinkAdapter think) + { this.ai= ai; this.dist= dist; this.think= think; } + + /** Empty constructor. */ + public mframe_t() + {} public AIAdapter ai; public float dist; public EntThinkAdapter think; + + public void write(QuakeFile f) throws IOException + { + f.writeAdapter(ai); + f.writeFloat(dist); + f.writeAdapter(think); + } + + public void read(QuakeFile f) throws IOException + { + ai= (AIAdapter) f.readAdapter(); + dist= f.readFloat(); + think= (EntThinkAdapter) f.readAdapter(); + } } diff --git a/src/jake2/game/mmove_t.java b/src/jake2/game/mmove_t.java index b0c19d0..cf8b2c2 100644 --- a/src/jake2/game/mmove_t.java +++ b/src/jake2/game/mmove_t.java @@ -19,20 +19,64 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 11.11.2003 by RST. -// $Id: mmove_t.java,v 1.1 2004-07-07 19:59:26 hzi Exp $ +// $Id: mmove_t.java,v 1.2 2004-08-20 21:29:57 salomo Exp $ package jake2.game; +import jake2.util.Lib; +import jake2.util.QuakeFile; + +import java.io.IOException; +import java.io.RandomAccessFile; + public class mmove_t { public mmove_t(int firstframe, int lastframe, mframe_t frame[], EntThinkAdapter endfunc) { + this.firstframe= firstframe; this.lastframe= lastframe; this.frame= frame; this.endfunc= endfunc; } + public mmove_t() + {} + public int firstframe; public int lastframe; public mframe_t frame[]; //ptr public EntThinkAdapter endfunc; + + + /** Writes the structure to a random acccess file. */ + public void write(QuakeFile f) throws IOException + { + f.writeInt(firstframe); + f.writeInt(lastframe); + if (frame == null) + f.writeInt(-1); + else + { + f. writeInt(frame.length); + for (int n=0; n < frame.length; n++) + frame[n].write(f); + } + f.writeAdapter(endfunc); + } + + /** Read the mmove_t from the RandomAccessFile. */ + public void read(QuakeFile f) throws IOException + { + firstframe = f.readInt(); + lastframe = f.readInt(); + + int len = f.readInt(); + + frame = new mframe_t[len]; + for (int n=0; n < len ; n++) + { + frame[n] = new mframe_t(); + frame[n].read(f); + } + endfunc = (EntThinkAdapter) f.readAdapter(); + } } diff --git a/src/jake2/game/monsterinfo_t.java b/src/jake2/game/monsterinfo_t.java index 48b96f0..4a98213 100644 --- a/src/jake2/game/monsterinfo_t.java +++ b/src/jake2/game/monsterinfo_t.java @@ -19,10 +19,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 31.10.2003 by RST. -// $Id: monsterinfo_t.java,v 1.1 2004-07-07 19:59:26 hzi Exp $ +// $Id: monsterinfo_t.java,v 1.2 2004-08-20 21:29:58 salomo Exp $ package jake2.game; +import jake2.util.QuakeFile; + +import java.io.IOException; +import java.io.RandomAccessFile; + public class monsterinfo_t { public mmove_t currentmove; @@ -60,4 +65,98 @@ public class monsterinfo_t { public int power_armor_type; public int power_armor_power; + /** Writes the monsterinfo to the file.*/ + public void write(QuakeFile f) throws IOException + { + f.writeBoolean(currentmove != null); + if (currentmove != null) + currentmove.write(f); + f.writeInt(aiflags); + f.writeInt(nextframe); + f.writeFloat(scale); + f.writeAdapter(stand); + f.writeAdapter(idle); + f.writeAdapter(search); + f.writeAdapter(walk); + f.writeAdapter(run); + + f.writeAdapter(dodge); + + f.writeAdapter(attack); + f.writeAdapter(melee); + + f.writeAdapter(sight); + + f.writeAdapter(checkattack); + + f.writeFloat(pausetime); + f.writeFloat(attack_finished); + + f.writeVector(saved_goal); + + f.writeFloat(search_time); + f.writeFloat(trail_time); + + f.writeVector(last_sighting); + + f.writeInt(attack_state); + f.writeInt(lefty); + + f.writeFloat(idle_time); + f.writeInt(linkcount); + + f.writeInt(power_armor_power); + f.writeInt(power_armor_type); + } + + /** Writes the monsterinfo to the file.*/ + public void read(QuakeFile f) throws IOException + { + if (f.readBoolean()) + { + currentmove= new mmove_t(); + currentmove.read(f); + } + else + currentmove= null; + aiflags = f.readInt(); + nextframe = f.readInt(); + scale = f.readFloat(); + stand = (EntThinkAdapter) f.readAdapter(); + idle = (EntThinkAdapter) f.readAdapter(); + search = (EntThinkAdapter) f.readAdapter(); + walk = (EntThinkAdapter) f.readAdapter(); + run = (EntThinkAdapter) f.readAdapter(); + + dodge = (EntDodgeAdapter) f.readAdapter(); + + attack = (EntThinkAdapter) f.readAdapter(); + melee = (EntThinkAdapter) f.readAdapter(); + + sight = (EntInteractAdapter) f.readAdapter(); + + checkattack = (EntThinkAdapter) f.readAdapter(); + + pausetime = f.readFloat(); + attack_finished = f.readFloat(); + + saved_goal = f.readVector(); + + search_time = f.readFloat(); + trail_time = f.readFloat(); + + last_sighting = f.readVector(); + + attack_state = f.readInt(); + lefty = f.readInt(); + + idle_time = f.readFloat(); + linkcount = f.readInt(); + + power_armor_power = f.readInt(); + power_armor_type = f.readInt(); + + } + + } diff --git a/src/jake2/game/moveinfo_t.java b/src/jake2/game/moveinfo_t.java index 16b0b50..864051d 100644 --- a/src/jake2/game/moveinfo_t.java +++ b/src/jake2/game/moveinfo_t.java @@ -19,10 +19,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 31.10.2003 by RST. -// $Id: moveinfo_t.java,v 1.1 2004-07-07 19:59:26 hzi Exp $ +// $Id: moveinfo_t.java,v 1.2 2004-08-20 21:29:58 salomo Exp $ package jake2.game; +import java.io.IOException; + +import jake2.util.QuakeFile; + public class moveinfo_t { // fixed data float[] start_origin= { 0, 0, 0 }; @@ -51,4 +55,62 @@ public class moveinfo_t { float remaining_distance; float decel_distance; EntThinkAdapter endfunc; + + /** saves the moveinfo to the file.*/ + public void write(QuakeFile f) throws IOException { + f.writeVector(start_origin); + f.writeVector(start_angles); + f.writeVector(end_origin); + f.writeVector(end_angles); + + f.writeInt(sound_start); + f.writeInt(sound_middle); + f.writeInt(sound_end); + + f.writeFloat(accel); + f.writeFloat(speed); + f.writeFloat(decel); + f.writeFloat(distance); + + f.writeFloat(wait); + + f.writeInt(state); + f.writeVector(dir); + + f.writeFloat(current_speed); + f.writeFloat(move_speed); + f.writeFloat(next_speed); + f.writeFloat(remaining_distance); + f.writeFloat(decel_distance); + f.writeAdapter(endfunc); + } + + /** Reads the moveinfo from a file. */ + public void read(QuakeFile f) throws IOException { + start_origin= f.readVector(); + start_angles= f.readVector(); + end_origin= f.readVector(); + end_angles= f.readVector(); + + sound_start= f.readInt(); + sound_middle= f.readInt(); + sound_end= f.readInt(); + + accel= f.readFloat(); + speed= f.readFloat(); + decel= f.readFloat(); + distance= f.readFloat(); + + wait= f.readFloat(); + + state= f.readInt(); + dir= f.readVector(); + + current_speed= f.readFloat(); + move_speed= f.readFloat(); + next_speed= f.readFloat(); + remaining_distance= f.readFloat(); + decel_distance= f.readFloat(); + endfunc= (EntThinkAdapter) f.readAdapter(); + } } diff --git a/src/jake2/game/player_state_t.java b/src/jake2/game/player_state_t.java index d4ecc72..cf4daf4 100644 --- a/src/jake2/game/player_state_t.java +++ b/src/jake2/game/player_state_t.java @@ -19,11 +19,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 31.10.2003 by RST. -// $Id: player_state_t.java,v 1.3 2004-07-09 06:50:49 hzi Exp $ +// $Id: player_state_t.java,v 1.4 2004-08-20 21:29:58 salomo Exp $ package jake2.game; import java.io.IOException; +import java.io.RandomAccessFile; import java.nio.ByteBuffer; import jake2.*; @@ -32,114 +33,156 @@ import jake2.qcommon.Com; import jake2.util.Lib; import jake2.util.Math3D; +/** + Player_state_t is the information needed in addition to pmove_state_t + to rendered a view. There will only be 10 player_state_t sent each second, + but the number of pmove_state_t changes will be relative to client + frame rates. +*/ + public class player_state_t { - // player_state_t is the information needed in addition to pmove_state_t - // to rendered a view. There will only be 10 player_state_t sent each second, - // but the number of pmove_state_t changes will be reletive to client - // frame rates - public pmove_state_t pmove = new pmove_state_t(); // for prediction + public pmove_state_t pmove= new pmove_state_t(); // for prediction // these fields do not need to be communicated bit-precise - public float[] viewangles = { 0, 0, 0 }; // for fixed views - public float[] viewoffset = { 0, 0, 0 }; // add to pmovestate->origin - public float[] kick_angles = { 0, 0, 0 }; // add to view direction to get render angles + public float[] viewangles= { 0, 0, 0 }; // for fixed views + public float[] viewoffset= { 0, 0, 0 }; // add to pmovestate->origin + public float[] kick_angles= { 0, 0, 0 }; // add to view direction to get render angles // set by weapon kicks, pain effects, etc - public float[] gunangles = { 0, 0, 0 }; - public float[] gunoffset = { 0, 0, 0 }; + public float[] gunangles= { 0, 0, 0 }; + public float[] gunoffset= { 0, 0, 0 }; public int gunindex; public int gunframe; - public float blend[] = new float[4]; // rgba full screen effect + public float blend[]= new float[4]; // rgba full screen effect public float fov; // horizontal field of view public int rdflags; // refdef flags - public short stats[] = new short[Defines.MAX_STATS]; + public short stats[]= new short[Defines.MAX_STATS]; + + /** Lets cleverly reset the structure. */ + private static player_state_t prototype= new player_state_t(); - /** - * - */ - private static player_state_t prototype = new player_state_t(); - + /** Clears the player_state.*/ public void clear() { this.set(prototype); } - - public player_state_t getClone() - { + + /** Clones the object.*/ + public player_state_t getClone() { return new player_state_t().set(this); } - - public player_state_t set(player_state_t from) - { + + /** Copies the player state data. */ + public player_state_t set(player_state_t from) { pmove.set(from.pmove); Math3D.VectorCopy(from.viewangles, viewangles); - Math3D.VectorCopy(from.viewoffset,viewoffset); + Math3D.VectorCopy(from.viewoffset, viewoffset); Math3D.VectorCopy(from.kick_angles, kick_angles); - Math3D.VectorCopy(from.gunangles,gunangles); + Math3D.VectorCopy(from.gunangles, gunangles); Math3D.VectorCopy(from.gunoffset, gunoffset); - gunindex = from.gunindex; - gunframe = from.gunframe; - - blend[0] = from.blend[0]; - blend[1] = from.blend[1]; - blend[2] = from.blend[2]; - blend[3] = from.blend[3]; - - fov = from.fov; - rdflags = from.rdflags; - - //stats = new short[Defines.MAX_STATS]; - System.arraycopy(from.stats, 0, stats,0, Defines.MAX_STATS); - + gunindex= from.gunindex; + gunframe= from.gunframe; + + blend[0]= from.blend[0]; + blend[1]= from.blend[1]; + blend[2]= from.blend[2]; + blend[3]= from.blend[3]; + + fov= from.fov; + rdflags= from.rdflags; + + System.arraycopy(from.stats, 0, stats, 0, Defines.MAX_STATS); + return this; } - public void load(ByteBuffer bb) throws IOException { - pmove.load(bb); + /** Reads a player_state from a file.*/ + public void load(RandomAccessFile f) throws IOException { + pmove.load(f); + + viewangles[0]= f.readFloat(); + viewangles[1]= f.readFloat(); + viewangles[2]= f.readFloat(); + + viewoffset[0]= f.readFloat(); + viewoffset[1]= f.readFloat(); + viewoffset[2]= f.readFloat(); + + kick_angles[0]= f.readFloat(); + kick_angles[1]= f.readFloat(); + kick_angles[2]= f.readFloat(); + + gunangles[0]= f.readFloat(); + gunangles[1]= f.readFloat(); + gunangles[2]= f.readFloat(); + + gunoffset[0]= f.readFloat(); + gunoffset[1]= f.readFloat(); + gunoffset[2]= f.readFloat(); + + gunindex= f.readInt(); + gunframe= f.readInt(); + + blend[0]= f.readFloat(); + blend[1]= f.readFloat(); + blend[2]= f.readFloat(); + blend[3]= f.readFloat(); + + fov= f.readFloat(); + + rdflags= f.readInt(); + + for (int n= 0; n < Defines.MAX_STATS; n++) + stats[n]= f.readShort(); + } - viewangles[0] = bb.getFloat(); - viewangles[1] = bb.getFloat(); - viewangles[2] = bb.getFloat(); + /** Writes a player_state to a file.*/ + public void write(RandomAccessFile f) throws IOException { + pmove.write(f); - viewoffset[0] = bb.getFloat(); - viewoffset[1] = bb.getFloat(); - viewoffset[2] = bb.getFloat(); + f.writeFloat(viewangles[0]); + f.writeFloat(viewangles[1]); + f.writeFloat(viewangles[2]); - kick_angles[0] = bb.getFloat(); - kick_angles[1] = bb.getFloat(); - kick_angles[2] = bb.getFloat(); + f.writeFloat(viewoffset[0]); + f.writeFloat(viewoffset[1]); + f.writeFloat(viewoffset[2]); - gunangles[0] = bb.getFloat(); - gunangles[1] = bb.getFloat(); - gunangles[2] = bb.getFloat(); + f.writeFloat(kick_angles[0]); + f.writeFloat(kick_angles[1]); + f.writeFloat(kick_angles[2]); - gunoffset[0] = bb.getFloat(); - gunoffset[1] = bb.getFloat(); - gunoffset[2] = bb.getFloat(); + f.writeFloat(gunangles[0]); + f.writeFloat(gunangles[1]); + f.writeFloat(gunangles[2]); - gunindex = bb.getInt(); - gunframe = bb.getInt(); + f.writeFloat(gunoffset[0]); + f.writeFloat(gunoffset[1]); + f.writeFloat(gunoffset[2]); - blend[0] = bb.getFloat(); - blend[1] = bb.getFloat(); - blend[2] = bb.getFloat(); - blend[3] = bb.getFloat(); + f.writeInt(gunindex); + f.writeInt(gunframe); - fov = bb.getFloat(); + f.writeFloat(blend[0]); + f.writeFloat(blend[1]); + f.writeFloat(blend[2]); + f.writeFloat(blend[3]); - rdflags = bb.getInt(); + f.writeFloat(fov); - for (int n = 0; n < Defines.MAX_STATS; n++) - stats[n] = bb.getShort(); + f.writeInt(rdflags); + for (int n= 0; n < Defines.MAX_STATS; n++) + f.writeShort(stats[n]); } + /** Prints the player state. */ public void dump() { pmove.dump(); @@ -158,7 +201,7 @@ public class player_state_t { Com.Println("rdflags: " + rdflags); - for (int n = 0; n < Defines.MAX_STATS; n++) + for (int n= 0; n < Defines.MAX_STATS; n++) System.out.println("stats[" + n + "]: " + stats[n]); } } diff --git a/src/jake2/game/pmove_state_t.java b/src/jake2/game/pmove_state_t.java index 6c0906e..01b0bf6 100644 --- a/src/jake2/game/pmove_state_t.java +++ b/src/jake2/game/pmove_state_t.java @@ -19,13 +19,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 31.10.2003 by RST. -// $Id: pmove_state_t.java,v 1.1 2004-07-07 19:59:26 hzi Exp $ +// $Id: pmove_state_t.java,v 1.2 2004-08-20 21:29:58 salomo Exp $ package jake2.game; import jake2.qcommon.Com; import jake2.util.Math3D; import java.io.IOException; +import java.io.RandomAccessFile; import java.nio.ByteBuffer; public class pmove_state_t { @@ -39,12 +40,15 @@ public class pmove_state_t { public short origin[] = { 0, 0, 0 }; // 12.3 public short velocity[] = { 0, 0, 0 }; // 12.3 - public byte pm_flags; // ducked, jump_held, etc - public byte pm_time; // each unit = 8 ms + /** ducked, jump_held, etc. */ + public byte pm_flags; + /** each unit = 8 ms. */ + public byte pm_time; public short gravity; - public short delta_angles[] = { 0, 0, 0 }; // add to command angles to get view direction - // changed by spawns, rotating objects, and teleporters - + /** add to command angles to get view direction. */ + public short delta_angles[] = { 0, 0, 0 }; + /** changed by spawns, rotating objects, and teleporters.*/ + private static pmove_state_t prototype = new pmove_state_t(); public void reset() @@ -81,28 +85,53 @@ public class pmove_state_t { return false; } - public void load(ByteBuffer bb) throws IOException { + /** Reads the playermove from the file.*/ + public void load(RandomAccessFile f) throws IOException { + + pm_type = f.readInt(); + + origin[0] = f.readShort(); + origin[1] = f.readShort(); + origin[2] = f.readShort(); + + velocity[0] = f.readShort(); + velocity[1] = f.readShort(); + velocity[2] = f.readShort(); + + pm_flags = f.readByte(); + pm_time = f.readByte(); + gravity = f.readShort(); - pm_type = bb.getInt(); + f.readShort(); - origin[0] = bb.getShort(); - origin[1] = bb.getShort(); - origin[2] = bb.getShort(); + delta_angles[0] = f.readShort(); + delta_angles[1] = f.readShort(); + delta_angles[2] = f.readShort(); - velocity[0] = bb.getShort(); - velocity[1] = bb.getShort(); - velocity[2] = bb.getShort(); + } + + /** Writes the playermove to the file. */ + public void write (RandomAccessFile f) throws IOException { + + f.writeInt(pm_type); - pm_flags = bb.get(); - pm_time = bb.get(); - gravity = bb.getShort(); + f.writeShort(origin[0]); + f.writeShort(origin[1]); + f.writeShort(origin[2]); - bb.getShort(); + f.writeShort(velocity[0]); + f.writeShort(velocity[1]); + f.writeShort(velocity[2]); - delta_angles[0] = bb.getShort(); - delta_angles[1] = bb.getShort(); - delta_angles[2] = bb.getShort(); + f.writeByte(pm_flags); + f.writeByte(pm_time); + f.writeShort(gravity); + f.writeShort(0); + + f.writeShort(delta_angles[0]); + f.writeShort(delta_angles[1]); + f.writeShort(delta_angles[2]); } public void dump() { @@ -124,7 +153,4 @@ public class pmove_state_t { Com.Println("delta-angle[1]: " + delta_angles[0]); Com.Println("delta-angle[2]: " + delta_angles[0]); } - - - }
\ No newline at end of file |