示例#1
0
  /*
   * ============== SCR_CenterPrint
   *
   * Called for important messages that should stay in the center of the
   * screen for a few moments ==============
   */
  static void CenterPrint(String str) {
    // char *s;
    int s;
    StringBuffer line = new StringBuffer(64);
    int i, j, l;

    // strncpy (scr_centerstring, str, sizeof(scr_centerstring)-1);
    scr_centerstring = str;
    scr_centertime_off = scr_centertime.value;
    scr_centertime_start = cl.time;

    // count the number of lines for centering
    scr_center_lines = 1;
    s = 0;
    while (s < str.length()) {
      if (str.charAt(s) == '\n') scr_center_lines++;
      s++;
    }

    // echo it to the console
    Com.Printf(
        "\n\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37\n\n");

    s = 0;

    if (str.length() != 0) {
      do {
        // scan the width of the line

        for (l = 0; l < 40 && (l + s) < str.length(); l++)
          if (str.charAt(s + l) == '\n' || str.charAt(s + l) == 0) break;
        for (i = 0; i < (40 - l) / 2; i++) line.append(' ');

        for (j = 0; j < l; j++) {
          line.append(str.charAt(s + j));
        }

        line.append('\n');

        Com.Printf(line.toString());

        while (s < str.length() && str.charAt(s) != '\n') s++;

        if (s == str.length()) break;
        s++; // skip the \n
      } while (true);
    }
    Com.Printf(
        "\n\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37\n\n");
    Console.ClearNotify();
  }
示例#2
0
  public static void Error(int code, String fmt, Vargs vargs) throws LongJmpException {
    // va_list argptr;
    // static char msg[MAXPRINTMSG];

    if (recursive) {
      Sys.Error("recursive error after: " + msg);
    }
    recursive = true;

    msg = sprintf(fmt, vargs);

    if (code == Constants.ERR_DISCONNECT) {
      Client.drop();
      recursive = false;
      throw new LongJmpException();
    } else if (code == Constants.ERR_DROP) {
      Com.Printf("********************\nERROR: " + msg + "\n********************\n");
      ServerMain.SV_Shutdown("Server crashed: " + msg + "\n", false);
      Client.drop();
      recursive = false;
      throw new LongJmpException();
    } else {
      ServerMain.SV_Shutdown("Server fatal crashed: %s" + msg + "\n", false);
      Client.shutdown();
    }

    Sys.Error(msg);
  }
示例#3
0
  /** @see com.googlecode.gwtquake.shared.client.Renderer#DrawFill */
  public void DrawFill(int x, int y, int w, int h, int colorIndex) {

    if (colorIndex > 255) Com.Error(Constants.ERR_FATAL, "Draw_Fill: bad color");

    GlState.gl.glDisable(Gl1Context.GL_TEXTURE_2D);

    int color = QuakeImage.PALETTE_ABGR[colorIndex];

    GlState.gl.glColor3ub(
        (byte) ((color >> 0) & 0xff), // r
        (byte) ((color >> 8) & 0xff), // g
        (byte) ((color >> 16) & 0xff) // b
        );

    GlState.gl.glBegin(Gl1Context._GL_QUADS);

    GlState.gl.glVertex2f(x, y);
    GlState.gl.glVertex2f(x + w, y);
    GlState.gl.glVertex2f(x + w, y + h);
    GlState.gl.glVertex2f(x, y + h);

    GlState.gl.glEnd();
    GlState.gl.glColor3f(1, 1, 1);
    GlState.gl.glEnable(Gl1Context.GL_TEXTURE_2D);
  }
示例#4
0
  /*
   * ================ SCR_TimeRefresh_f ================
   */
  static void TimeRefresh_f() {
    int i;
    int start, stop;
    float time;

    if (cls.state != ca_active) return;

    start = Timer.Milliseconds();

    if (Commands.Argc() == 2) { // run without page flipping
      re.BeginFrame(0);
      for (i = 0; i < 128; i++) {
        cl.refdef.viewangles[1] = i / 128.0f * 360.0f;
        re.RenderFrame(cl.refdef);
      }
      re.EndFrame();
    } else {
      for (i = 0; i < 128; i++) {
        cl.refdef.viewangles[1] = i / 128.0f * 360.0f;

        re.BeginFrame(0);
        re.RenderFrame(cl.refdef);
        re.EndFrame();
      }
    }

    stop = Timer.Milliseconds();
    time = (stop - start) / 1000.0f;
    Com.Printf("%f seconds (%f fps)\n", new Vargs(2).add(time).add(128.0f / time));
  }
示例#5
0
  /**
   * Com_InitArgv checks the number of command line arguments and copies all arguments with valid
   * length into com_argv.
   */
  static void InitArgv(String[] args) throws LongJmpException {

    if (args.length > Constants.MAX_NUM_ARGVS) {
      Com.Error(Constants.ERR_FATAL, "argc > MAX_NUM_ARGVS");
    }

    Com.com_argc = args.length;
    for (int i = 0; i < Com.com_argc; i++) {
      if (args[i].length() >= Constants.MAX_TOKEN_CHARS) Com.com_argv[i] = "";
      else Com.com_argv[i] = args[i];
    }
  }
示例#6
0
  /*
   * ================= SCR_Sky_f
   *
   * Set a specific sky and rotation speed =================
   */
  static void Sky_f() {
    float rotate;
    float[] axis = {0, 0, 0};

    if (Commands.Argc() < 2) {
      Com.Printf("Usage: sky <basename> <rotate> <axis x y z>\n");
      return;
    }
    if (Commands.Argc() > 2) rotate = Float.parseFloat(Commands.Argv(2));
    else rotate = 0;
    if (Commands.Argc() == 6) {
      axis[0] = Float.parseFloat(Commands.Argv(3));
      axis[1] = Float.parseFloat(Commands.Argv(4));
      axis[2] = Float.parseFloat(Commands.Argv(5));
    } else {
      axis[0] = 0;
      axis[1] = 0;
      axis[2] = 1;
    }

    re.SetSky(Commands.Argv(1), rotate, axis);
  }
示例#7
0
  // See GameSpanw.ED_ParseEdict() to see how to use it now.
  public static String Parse(ParseHelp hlp) {
    int c;
    int len = 0;

    if (hlp.data == null) {
      return "";
    }

    while (true) {
      //	   skip whitespace
      hlp.skipwhites();
      if (hlp.isEof()) {
        hlp.data = null;
        return "";
      }

      //	   skip // comments
      if (hlp.getchar() == '/') {
        if (hlp.nextchar() == '/') {
          hlp.skiptoeol();
          // goto skip whitespace
          continue;
        } else {
          hlp.prevchar();
          break;
        }
      } else break;
    }

    //	   handle quoted strings specially
    if (hlp.getchar() == '\"') {
      hlp.nextchar();
      while (true) {
        c = hlp.getchar();
        hlp.nextchar();
        if (c == '\"' || c == 0) {
          return new String(com_token, 0, len);
        }
        if (len < Constants.MAX_TOKEN_CHARS) {
          com_token[len] = (char) c;
          len++;
        }
      }
    }

    //	   parse a regular word
    c = hlp.getchar();
    do {
      if (len < Constants.MAX_TOKEN_CHARS) {
        com_token[len] = (char) c;
        len++;
      }
      c = hlp.nextchar();
    } while (c > 32);

    if (len == Constants.MAX_TOKEN_CHARS) {
      Com.Printf("Token exceeded " + Constants.MAX_TOKEN_CHARS + " chars, discarded.\n");
      len = 0;
    }

    return new String(com_token, 0, len);
  }
示例#8
0
  /*
   * ================ SCR_ExecuteLayoutString
   *
   * ================
   */
  static void ExecuteLayoutString(String s) {
    int x, y;
    int value;
    String token;
    int width;
    int index;
    ClientInfo ci;

    if (cls.state != ca_active || !cl.refresh_prepped) return;

    //		if (!s[0])
    if (s == null || s.length() == 0) return;

    x = 0;
    y = 0;
    width = 3;

    Com.ParseHelp ph = new Com.ParseHelp(s);

    while (!ph.isEof()) {
      token = Com.Parse(ph);
      if (token.equals("xl")) {
        token = Com.Parse(ph);
        x = Lib.atoi(token);
        continue;
      }
      if (token.equals("xr")) {
        token = Com.Parse(ph);
        x = viddef.width + Lib.atoi(token);
        continue;
      }
      if (token.equals("xv")) {
        token = Com.Parse(ph);
        x = viddef.width / 2 - 160 + Lib.atoi(token);
        continue;
      }

      if (token.equals("yt")) {
        token = Com.Parse(ph);
        y = Lib.atoi(token);
        continue;
      }
      if (token.equals("yb")) {
        token = Com.Parse(ph);
        y = viddef.height + Lib.atoi(token);
        continue;
      }
      if (token.equals("yv")) {
        token = Com.Parse(ph);
        y = viddef.height / 2 - 120 + Lib.atoi(token);
        continue;
      }

      if (token.equals("pic")) { // draw a pic from a stat number
        token = Com.Parse(ph);
        value = cl.frame.playerstate.stats[Lib.atoi(token)];
        if (value >= MAX_IMAGES) Com.Error(ERR_DROP, "Pic >= MAX_IMAGES");
        if (cl.configstrings[CS_IMAGES + value] != null) {
          AddDirtyPoint(x, y);
          AddDirtyPoint(x + 23, y + 23);
          re.DrawPic(x, y, cl.configstrings[CS_IMAGES + value]);
        }
        continue;
      }

      if (token.equals("client")) { // draw a deathmatch client block
        int score, ping, time;

        token = Com.Parse(ph);
        x = viddef.width / 2 - 160 + Lib.atoi(token);
        token = Com.Parse(ph);
        y = viddef.height / 2 - 120 + Lib.atoi(token);
        AddDirtyPoint(x, y);
        AddDirtyPoint(x + 159, y + 31);

        token = Com.Parse(ph);
        value = Lib.atoi(token);
        if (value >= MAX_CLIENTS || value < 0) Com.Error(ERR_DROP, "client >= MAX_CLIENTS");
        ci = cl.clientinfo[value];

        token = Com.Parse(ph);
        score = Lib.atoi(token);

        token = Com.Parse(ph);
        ping = Lib.atoi(token);

        token = Com.Parse(ph);
        time = Lib.atoi(token);

        Globals.re.DrawString(x + 32, y, ci.name, true);
        Globals.re.DrawString(x + 32, y + 8, "Score: ");
        Globals.re.DrawString(x + 32 + 7 * 8, y + 8, "" + score, true);
        Globals.re.DrawString(x + 32, y + 16, "Ping:  " + ping);
        Globals.re.DrawString(x + 32, y + 24, "Time:  " + time);

        if (ci.icon == null) ci = cl.baseclientinfo;
        re.DrawPic(x, y, ci.iconname);
        continue;
      }

      if (token.equals("ctf")) { // draw a ctf client block
        int score, ping;

        token = Com.Parse(ph);
        x = viddef.width / 2 - 160 + Lib.atoi(token);
        token = Com.Parse(ph);
        y = viddef.height / 2 - 120 + Lib.atoi(token);
        AddDirtyPoint(x, y);
        AddDirtyPoint(x + 159, y + 31);

        token = Com.Parse(ph);
        value = Lib.atoi(token);
        if (value >= MAX_CLIENTS || value < 0) Com.Error(ERR_DROP, "client >= MAX_CLIENTS");
        ci = cl.clientinfo[value];

        token = Com.Parse(ph);
        score = Lib.atoi(token);

        token = Com.Parse(ph);
        ping = Lib.atoi(token);
        if (ping > 999) ping = 999;

        // sprintf(block, "%3d %3d %-12.12s", score, ping, ci->name);
        String block =
            Com.sprintf("%3d %3d %-12.12s", new Vargs(3).add(score).add(ping).add(ci.name));

        if (value == cl.playernum) Globals.re.DrawString(x, y, block, true);
        else Globals.re.DrawString(x, y, block);
        continue;
      }

      if (token.equals("picn")) { // draw a pic from a name
        token = Com.Parse(ph);
        AddDirtyPoint(x, y);
        AddDirtyPoint(x + 23, y + 23);
        re.DrawPic(x, y, token);
        continue;
      }

      if (token.equals("num")) { // draw a number
        token = Com.Parse(ph);
        width = Lib.atoi(token);
        token = Com.Parse(ph);
        value = cl.frame.playerstate.stats[Lib.atoi(token)];
        DrawField(x, y, 0, width, value);
        continue;
      }

      if (token.equals("hnum")) { // health number
        int color;

        width = 3;
        value = cl.frame.playerstate.stats[STAT_HEALTH];
        if (value > 25) color = 0; // green
        else if (value > 0) color = (cl.frame.serverframe >> 2) & 1; // flash
        else color = 1;

        if ((cl.frame.playerstate.stats[STAT_FLASHES] & 1) != 0) re.DrawPic(x, y, "field_3");

        DrawField(x, y, color, width, value);
        continue;
      }

      if (token.equals("anum")) { // ammo number
        int color;

        width = 3;
        value = cl.frame.playerstate.stats[STAT_AMMO];
        if (value > 5) color = 0; // green
        else if (value >= 0) color = (cl.frame.serverframe >> 2) & 1; // flash
        else continue; // negative number = don't show

        if ((cl.frame.playerstate.stats[STAT_FLASHES] & 4) != 0) re.DrawPic(x, y, "field_3");

        DrawField(x, y, color, width, value);
        continue;
      }

      if (token.equals("rnum")) { // armor number
        int color;

        width = 3;
        value = cl.frame.playerstate.stats[STAT_ARMOR];
        if (value < 1) continue;

        color = 0; // green

        if ((cl.frame.playerstate.stats[STAT_FLASHES] & 2) != 0) re.DrawPic(x, y, "field_3");

        DrawField(x, y, color, width, value);
        continue;
      }

      if (token.equals("stat_string")) {
        token = Com.Parse(ph);
        index = Lib.atoi(token);
        if (index < 0 || index >= MAX_CONFIGSTRINGS) Com.Error(ERR_DROP, "Bad stat_string index");
        index = cl.frame.playerstate.stats[index];
        if (index < 0 || index >= MAX_CONFIGSTRINGS) Com.Error(ERR_DROP, "Bad stat_string index");
        Globals.re.DrawString(x, y, cl.configstrings[index]);
        continue;
      }

      if (token.equals("cstring")) {
        token = Com.Parse(ph);
        DrawHUDString(token, x, y, 320, false);
        continue;
      }

      if (token.equals("string")) {
        token = Com.Parse(ph);
        Globals.re.DrawString(x, y, token);
        continue;
      }

      if (token.equals("cstring2")) {
        token = Com.Parse(ph);
        DrawHUDString(token, x, y, 320, true);
        continue;
      }

      if (token.equals("string2")) {
        token = Com.Parse(ph);
        Globals.re.DrawString(x, y, token, true);
        continue;
      }

      if (token.equals("if")) { // draw a number
        token = Com.Parse(ph);
        value = cl.frame.playerstate.stats[Lib.atoi(token)];
        if (value == 0) {
          // skip to endif
          while (!ph.isEof() && !(token = Com.Parse(ph)).equals("endif")) ;
        }
        continue;
      }
    }
  }
示例#9
0
  public static void UpdateScreen2() {
    int numframes;
    int i;
    // if the screen is disabled (loading plaque is up, or vid mode
    // changing)
    // do nothing at all
    if (cls.disable_screen != 0) {
      if (Timer.Milliseconds() - cls.disable_screen > 120000) {
        cls.disable_screen = 0;
        Com.Printf("Loading plaque timed out.\n");
      }
      DrawConsole();
      DrawLoading();
      return;
    }

    if (!scr_initialized || !con.initialized) return; // not initialized yet

    /*
     * * range check cl_camera_separation so we don't inadvertently fry
     * someone's * brain
     */
    if (cl_stereo_separation.value > 1.0) ConsoleVariables.SetValue("cl_stereo_separation", 1.0f);
    else if (cl_stereo_separation.value < 0)
      ConsoleVariables.SetValue("cl_stereo_separation", 0.0f);

    if (cl_stereo.value != 0) {
      numframes = 2;
      separation[0] = -cl_stereo_separation.value / 2;
      separation[1] = cl_stereo_separation.value / 2;
    } else {
      separation[0] = 0;
      separation[1] = 0;
      numframes = 1;
    }

    for (i = 0; i < numframes; i++) {
      re.BeginFrame(separation[i]);

      if (scr_draw_loading == 2) { //  loading plaque over black screen
        Dimension dim = new Dimension();

        re.CinematicSetPalette(null);
        scr_draw_loading = 0; // false
        re.DrawGetPicSize(dim, "loading");
        re.DrawPic((viddef.width - dim.width) / 2, (viddef.height - dim.height) / 2, "loading");
      }
      // if a cinematic is supposed to be running, handle menus
      // and console specially
      else if (cl.cinematictime > 0) {
        if (cls.key_dest == key_menu) {
          if (cl.cinematicpalette_active) {
            re.CinematicSetPalette(null);
            cl.cinematicpalette_active = false;
          }
          Menu.Draw();
        } else if (cls.key_dest == key_console) {
          if (cl.cinematicpalette_active) {
            re.CinematicSetPalette(null);
            cl.cinematicpalette_active = false;
          }
          DrawConsole();
        } else {
          DrawCinematic();
        }
      } else if (ResourceLoader.Pump()) {
        TileClear();
        DrawStats();
        CheckDrawCenterString();
        DrawPause();
        DrawConsole();
        Menu.Draw();
        DrawLoading();
      } else {
        // make sure the game palette is active
        if (cl.cinematicpalette_active) {
          re.CinematicSetPalette(null);
          cl.cinematicpalette_active = false;
        }
        // do 3D refresh drawing, and then update the screen
        CalcVrect();

        // clear any dirty part of the background
        TileClear();

        Video.RenderView(separation[i]);

        DrawStats();

        if ((cl.frame.playerstate.stats[STAT_LAYOUTS] & 1) != 0) DrawLayout();
        if ((cl.frame.playerstate.stats[STAT_LAYOUTS] & 2) != 0) ClientInventory.DrawInventory();

        DrawNet();
        CheckDrawCenterString();
        DrawFPS();

        //
        //				if (scr_timegraph->value)
        //					SCR_DebugGraph (cls.frametime*300, 0);
        //
        //				if (scr_debuggraph->value || scr_timegraph->value ||
        // scr_netgraph->value)
        //					SCR_DrawDebugGraph ();
        //
        DrawPause();
        DrawConsole();
        Menu.Draw();
        DrawLoading();
      }
    }

    Globals.re.EndFrame();
  }
示例#10
0
  /**
   * tries to send an unreliable message to a connection, and handles the transmition /
   * retransmition of the reliable messages.
   *
   * <p>A 0 length will still generate a packet and deal with the reliable messages.
   */
  public static void Transmit(NetworkChannel chan, int length, byte data[]) {
    int send_reliable;
    int w1, w2;

    // check for message overflow
    if (chan.message.overflowed) {
      chan.fatal_error = true;
      Com.Printf(NET.AdrToString(chan.remote_address) + ":Outgoing message overflow\n");
      return;
    }

    send_reliable = chan.Netchan_NeedReliable() ? 1 : 0;

    if (chan.reliable_length == 0 && chan.message.cursize != 0) {
      System.arraycopy(chan.message_buf, 0, chan.reliable_buf, 0, chan.message.cursize);
      chan.reliable_length = chan.message.cursize;
      chan.message.cursize = 0;
      chan.reliable_sequence ^= 1;
    }

    // write the packet header
    Buffer send = Buffer.wrap(send_buf).order(ByteOrder.LITTLE_ENDIAN);

    w1 = (chan.outgoing_sequence & ~(1 << 31)) | (send_reliable << 31);
    w2 = (chan.incoming_sequence & ~(1 << 31)) | (chan.incoming_reliable_sequence << 31);

    chan.outgoing_sequence++;
    chan.last_sent = (int) Globals.curtime;

    send.putInt(w1);
    send.putInt(w2);

    // send the qport if we are a client
    if (chan.sock == Constants.NS_CLIENT) send.WriteShort((int) consoleQport.value);

    // copy the reliable message to the packet first
    if (send_reliable != 0) {
      Buffers.Write(send, chan.reliable_buf, chan.reliable_length);
      chan.last_reliable_sequence = chan.outgoing_sequence;
    }

    // add the unreliable part if space is available
    if (send.maxsize - send.cursize >= length) Buffers.Write(send, data, length);
    else Com.Printf("Netchan_Transmit: dumped unreliable\n");

    // send the datagram
    NET.SendPacket(chan.sock, send.cursize, send.data, chan.remote_address);

    if (showpackets.value != 0) {
      if (send_reliable != 0)
        Com.Printf(
            // "send %4i : s=%i reliable=%i ack=%i rack=%i\n"
            "send "
                + send.cursize
                + " : s="
                + (chan.outgoing_sequence - 1)
                + " reliable="
                + chan.reliable_sequence
                + " ack="
                + chan.incoming_sequence
                + " rack="
                + chan.incoming_reliable_sequence
                + "\n");
      else
        Com.Printf(
            // "send %4i : s=%i ack=%i rack=%i\n"
            "send "
                + send.cursize
                + " : s="
                + (chan.outgoing_sequence - 1)
                + " ack="
                + chan.incoming_sequence
                + " rack="
                + chan.incoming_reliable_sequence
                + "\n");
    }
  }
示例#11
0
  /**
   * called when the current net_message is from remote_address modifies net_message so that it
   * points to the packet payload =================
   */
  public static boolean Process(NetworkChannel chan, Buffer msg) {
    int sequence, sequence_ack;
    int reliable_ack, reliable_message;
    int qport;

    // get sequence numbers
    msg.reset();
    sequence = msg.getInt();
    sequence_ack = msg.getInt();

    // read the qport if we are a server
    if (chan.sock == Constants.NS_SERVER) qport = msg.getShort();

    // achtung unsigned int
    reliable_message = sequence >>> 31;
    reliable_ack = sequence_ack >>> 31;

    sequence &= ~(1 << 31);
    sequence_ack &= ~(1 << 31);

    if (showpackets.value != 0) {
      if (reliable_message != 0)
        Com.Printf(
            // "recv %4i : s=%i reliable=%i ack=%i rack=%i\n"
            "recv "
                + msg.cursize
                + " : s="
                + sequence
                + " reliable="
                + (chan.incoming_reliable_sequence ^ 1)
                + " ack="
                + sequence_ack
                + " rack="
                + reliable_ack
                + "\n");
      else
        Com.Printf(
            // "recv %4i : s=%i ack=%i rack=%i\n"
            "recv "
                + msg.cursize
                + " : s="
                + sequence
                + " ack="
                + sequence_ack
                + " rack="
                + reliable_ack
                + "\n");
    }

    //
    // discard stale or duplicated packets
    //
    if (sequence <= chan.incoming_sequence) {
      if (showdrop.value != 0)
        Com.Printf(
            NET.AdrToString(chan.remote_address)
                + ":Out of order packet "
                + sequence
                + " at "
                + chan.incoming_sequence
                + "\n");
      return false;
    }

    //
    // dropped packets don't keep the message from being used
    //
    chan.dropped = sequence - (chan.incoming_sequence + 1);
    if (chan.dropped > 0) {
      if (showdrop.value != 0)
        Com.Printf(
            NET.AdrToString(chan.remote_address)
                + ":Dropped "
                + chan.dropped
                + " packets at "
                + sequence
                + "\n");
    }

    //
    // if the current outgoing reliable message has been acknowledged
    // clear the buffer to make way for the next
    //
    if (reliable_ack == chan.reliable_sequence) chan.reliable_length = 0; // it has been received

    //
    // if this message contains a reliable message, bump
    // incoming_reliable_sequence
    //
    chan.incoming_sequence = sequence;
    chan.incoming_acknowledged = sequence_ack;
    chan.incoming_reliable_acknowledged = reliable_ack;
    if (reliable_message != 0) {
      chan.incoming_reliable_sequence ^= 1;
    }

    //
    // the message can now be read from the current message pointer
    //
    chan.last_received = (int) Globals.curtime;

    return true;
  }