⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sv_init.java

📁 Jake2是一个Java 3D游戏引擎.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 1997-2001 Id Software, Inc. *  * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. *  * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. *  * See the GNU General Public License for more details. *  * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place - Suite 330, Boston, MA 02111-1307, USA. *   */// Created on 14.01.2004 by RST.// $Id: SV_INIT.java,v 1.17 2006/01/20 22:44:07 salomo Exp $package jake2.server;import jake2.Defines;import jake2.Globals;import jake2.client.CL;import jake2.client.SCR;import jake2.game.*;import jake2.qcommon.*;import jake2.sys.NET;import jake2.util.Lib;import jake2.util.Math3D;import java.io.IOException;import java.io.RandomAccessFile;public class SV_INIT {    /**     * SV_FindIndex.     */    public static int SV_FindIndex(String name, int start, int max,            boolean create) {        int i;        if (name == null || name.length() == 0)            return 0;        for (i = 1; i < max && sv.configstrings[start + i] != null; i++)            if (0 == Lib.strcmp(sv.configstrings[start + i], name))                return i;        if (!create)            return 0;        if (i == max)            Com.Error(Defines.ERR_DROP, "*Index: overflow");        sv.configstrings[start + i] = name;        if (sv.state != Defines.ss_loading) {             // send the update to everyone            SZ.Clear(sv.multicast);            MSG.WriteChar(sv.multicast, Defines.svc_configstring);            MSG.WriteShort(sv.multicast, start + i);            MSG.WriteString(sv.multicast, name);            SV_SEND.SV_Multicast(Globals.vec3_origin, Defines.MULTICAST_ALL_R);        }        return i;    }    public static int SV_ModelIndex(String name) {        return SV_FindIndex(name, Defines.CS_MODELS, Defines.MAX_MODELS, true);    }    public static int SV_SoundIndex(String name) {        return SV_FindIndex(name, Defines.CS_SOUNDS, Defines.MAX_SOUNDS, true);    }    public static int SV_ImageIndex(String name) {        return SV_FindIndex(name, Defines.CS_IMAGES, Defines.MAX_IMAGES, true);    }    /**     * SV_CreateBaseline     *      * Entity baselines are used to compress the update messages to the clients --     * only the fields that differ from the baseline will be transmitted.     */    public static void SV_CreateBaseline() {        edict_t svent;        int entnum;        for (entnum = 1; entnum < GameBase.num_edicts; entnum++) {            svent = GameBase.g_edicts[entnum];            if (!svent.inuse)                continue;            if (0 == svent.s.modelindex && 0 == svent.s.sound                    && 0 == svent.s.effects)                continue;                        svent.s.number = entnum;            // take current state as baseline            Math3D.VectorCopy(svent.s.origin, svent.s.old_origin);            sv.baselines[entnum].set(svent.s);        }    }    /**      * SV_CheckForSavegame.     */    public static void SV_CheckForSavegame() {        String name;        RandomAccessFile f;        int i;        if (SV_MAIN.sv_noreload.value != 0)            return;        if (Cvar.VariableValue("deathmatch") != 0)            return;        name = FS.Gamedir() + "/save/current/" + sv.name + ".sav";        try {            f = new RandomAccessFile(name, "r");        }        catch (Exception e) {            return;        }        try {            f.close();        } catch (IOException e1) {            e1.printStackTrace();        }        SV_WORLD.SV_ClearWorld();        // get configstrings and areaportals        SV_CCMDS.SV_ReadLevelFile();        if (!sv.loadgame) {             // coming back to a level after being in a different            // level, so run it for ten seconds            // rlava2 was sending too many lightstyles, and overflowing the            // reliable data. temporarily changing the server state to loading            // prevents these from being passed down.            int previousState; // PGM            previousState = sv.state; // PGM            sv.state = Defines.ss_loading; // PGM            for (i = 0; i < 100; i++)                GameBase.G_RunFrame();            sv.state = previousState; // PGM        }    }    /**     * SV_SpawnServer.     *      * Change the server to a new map, taking all connected clients along with     * it.     */    public static void SV_SpawnServer(String server, String spawnpoint,            int serverstate, boolean attractloop, boolean loadgame) {        int i;        int checksum = 0;        if (attractloop)            Cvar.Set("paused", "0");        Com.Printf("------- Server Initialization -------\n");        Com.DPrintf("SpawnServer: " + server + "\n");        if (sv.demofile != null)            try {                sv.demofile.close();            }         	catch (Exception e) {            }        // any partially connected client will be restarted        svs.spawncount++;                sv.state = Defines.ss_dead;        Globals.server_state = sv.state;        // wipe the entire per-level structure        sv = new server_t();        svs.realtime = 0;        sv.loadgame = loadgame;        sv.attractloop = attractloop;        // save name for levels that don't set message        sv.configstrings[Defines.CS_NAME] = server;        if (Cvar.VariableValue("deathmatch") != 0) {            sv.configstrings[Defines.CS_AIRACCEL] = ""                    + SV_MAIN.sv_airaccelerate.value;            PMove.pm_airaccelerate = SV_MAIN.sv_airaccelerate.value;        } else {            sv.configstrings[Defines.CS_AIRACCEL] = "0";            PMove.pm_airaccelerate = 0;        }        SZ.Init(sv.multicast, sv.multicast_buf, sv.multicast_buf.length);        sv.name = server;        // leave slots at start for clients only        for (i = 0; i < SV_MAIN.maxclients.value; i++) {            // needs to reconnect            if (svs.clients[i].state > Defines.cs_connected)                svs.clients[i].state = Defines.cs_connected;            svs.clients[i].lastframe = -1;        }        sv.time = 1000;        sv.name = server;        sv.configstrings[Defines.CS_NAME] = server;        int iw[] = { checksum };        if (serverstate != Defines.ss_game) {            sv.models[1] = CM.CM_LoadMap("", false, iw); // no real map        } else {            sv.configstrings[Defines.CS_MODELS + 1] = "maps/" + server + ".bsp";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -