/ source / blood / src / globals.cpp
globals.cpp
  1  //-------------------------------------------------------------------------
  2  /*
  3  Copyright (C) 2010-2019 EDuke32 developers and contributors
  4  Copyright (C) 2019 Nuke.YKT
  5  
  6  This file is part of NBlood.
  7  
  8  NBlood is free software; you can redistribute it and/or
  9  modify it under the terms of the GNU General Public License version 2
 10  as published by the Free Software Foundation.
 11  
 12  This program is distributed in the hope that it will be useful,
 13  but WITHOUT ANY WARRANTY; without even the implied warranty of
 14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 15  
 16  See the GNU General Public License for more details.
 17  
 18  You should have received a copy of the GNU General Public License
 19  along with this program; if not, write to the Free Software
 20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 21  */
 22  //-------------------------------------------------------------------------
 23  #include <stdlib.h>
 24  
 25  #include "compat.h"
 26  #include "build.h"
 27  #include "common_game.h"
 28  #include "globals.h"
 29  #include "resource.h"
 30  #include "renderlayer.h"
 31  
 32  
 33  ud_setup_t gSetup;
 34  ClockTicks gFrameClock;
 35  ClockTicks gFrameTicks;
 36  int gFrame;
 37  int gFrameRate;
 38  int gGamma = 0;
 39  
 40  char *gVersionString;
 41  char gVersionStringBuf[16];
 42  
 43  Resource gSysRes;
 44  
 45  static const char *_module;
 46  static int _line;
 47  
 48  void _SetErrorLoc(const char *pzFile, int nLine)
 49  {
 50      _module = pzFile;
 51      _line = nLine;
 52  }
 53  
 54  void _ThrowError(const char *pzFormat, ...)
 55  {
 56      char buffer[256];
 57      va_list args;
 58      va_start(args, pzFormat);
 59      vsprintf(buffer, pzFormat, args);
 60      LOG_F(ERROR, "%s(%i): %s", _module, _line, buffer);
 61  
 62      // NOTE: if NDEBUG is defined, this is a no-op (handled in build/include/compat.h)
 63      debug_break();
 64  
 65  #ifdef WM_MSGBOX_WINDOW
 66      char titlebuf[256];
 67      Bsprintf(titlebuf, APPNAME " %s", s_buildRev);
 68      wm_msgbox(titlebuf, "%s(%i): %s\n", _module, _line, buffer);
 69  #endif
 70  
 71      Bfflush(NULL);
 72      QuitGame();
 73  }
 74  
 75  // by NoOne: show warning msgs in game instead of throwing errors (in some cases)
 76  void _consoleSysMsg(const char* pzFormat, ...) {
 77  
 78      char buffer[1024];
 79      va_list args;
 80      va_start(args, pzFormat);
 81      vsprintf(buffer, pzFormat, args);
 82      OSD_Printf(OSDTEXT_RED "%s(%i): %s\n", _module, _line, buffer);
 83  }
 84  
 85  void __dassert(const char * pzExpr, const char * pzFile, int nLine)
 86  {
 87      LOG_F(ERROR, "Assertion failed: %s in file %s at line %i", pzExpr, pzFile, nLine);
 88  
 89      // NOTE: if NDEBUG is defined, this is a no-op (handled in build/include/compat.h)
 90      debug_break();
 91  
 92  #ifdef WM_MSGBOX_WINDOW
 93      char titlebuf[256];
 94      Bsprintf(titlebuf, APPNAME " %s", s_buildRev);
 95      wm_msgbox(titlebuf, "Assertion failed: %s in file %s at line %i\n", pzExpr, pzFile, nLine);
 96  #endif
 97  
 98      Bfflush(NULL);
 99      exit(0);
100  }
101  
102  const char *GetVersionString(void)
103  {
104      if (!gVersionString)
105      {
106          gVersionString = gVersionStringBuf;
107          if (!gVersionString)
108              return NULL;
109  
110          sprintf(gVersionString, "%d.%02d", BYTEVERSION / 100, BYTEVERSION % 100);
111      }
112      return gVersionString;
113  }