<commit_before>/* bzflag
 * Copyright (c) 1993 - 2003 <NAME>
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named COPYING that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#include "common.h"
#include "bzfgl.h"
#include "SceneRenderer.h"
#include "BackgroundRenderer.h"
#include "HUDRenderer.h"
#include "SceneDatabase.h"
#include "SceneNode.h"
#include "MainWindow.h"
#include "LocalPlayer.h"
#include "daylight.h"
#include "OpenGLGState.h"
#include "RenderNode.h"
#include "BzfWindow.h"
#include "TankSceneNode.h"
#include "StateDatabase.h"
#include "texture.h"
#include <string.h>

const GLint		SceneRenderer::SunLight = 0;	// also for the moon

#ifdef GL_ABGR_EXT
static int		strrncmp(const char* s1, const char* s2, int num)
{
  int len1 = strlen(s1) - 1;
  int len2 = strlen(s2) - 1;
  for (; len1 >= 0 && len2 >= 0 && num > 0; len1--, len2--, num--) {
    const int d = (int)s1[len1] - (int)s2[len2];
    if (d != 0) return d;
  }
  return 0;
}
#endif

//
// FlareLight
//

FlareLight::FlareLight(const float* _pos, const float* _color)
{
  pos[0] = _pos[0];
  pos[1] = _pos[1];
  pos[2] = _pos[2];
  color[0] = _color[0];
  color[1] = _color[1];
  color[2] = _color[2];
}

FlareLight::~FlareLight()
{
  // do nothing
}

//
// SceneRenderer
//

SceneRenderer*		SceneRenderer::instance = NULL;

SceneRenderer::SceneRenderer(MainWindow& _window) :
				window(_window),
				blank(false),
				invert(false),
				sunBrightness(1.0f),
				scene(NULL),
				background(NULL),
				abgr(false),
				useQualityValue(2),
				useDepthComplexityOn(false),
				useWireframeOn(false),
				useHiddenLineOn(false),
				panelOpacity(0.3f),
				radarSize(4),
				maxMotionFactor(5),
				useFogHack(false),
				viewType(Normal),
				inOrder(false),
				style(0),
				sceneIterator(NULL),
				depthRange(0),
				numDepthRanges(1),
				depthRangeSize(1.0),
				useDimming(false),
				canUseHiddenLine(false),
				exposed(true),
				lastFrame(true),
				sameFrame(false)
{
  instance = this;

  // get visual info
  window.getWindow()->makeCurrent();
  GLint bits;
  if (!BZDB->isSet("zbuffer")) {
    glGetIntegerv(GL_DEPTH_BITS, &bits);
    BZDB->set("zbuffer", (bits > 0) ? "1" : "0");
  }
  glGetIntegerv(GL_STENCIL_BITS, &bits);
  useStencilOn = (bits > 0);

  // see if abgr extention is available and system is known to be
  // faster with abgr.
  const char* vendor = (const char*)glGetString(GL_VENDOR);
  const char* renderer = (const char*)glGetString(GL_RENDERER);
  const char* version = (const char*)glGetString(GL_VERSION);
  const char* extensions = (const char*)glGetString(GL_EXTENSIONS);
  (void)vendor; (void)renderer; (void)version; (void)extensions; // silence g++
#ifdef GL_ABGR_EXT
  if (extensions != NULL && strstr(extensions, "GL_EXT_abgr") != NULL
  && vendor != NULL && strcmp(vendor, "SGI") == 0) {
    // old hardware is faster with ABGR.  new hardware isn't.
    if (strncmp(renderer, "GR1", 3) == 0 ||
	strncmp(renderer, "VGX", 3) == 0 ||
	strncmp(renderer, "LIGHT", 5) == 0 ||
	strrncmp(renderer, "-XS", 3) == 0 ||
	strrncmp(renderer, "-XSM", 4) == 0 ||
	strrncmp(renderer, "-XS24", 5) == 0 ||
	strrncmp(renderer, "-XS24-Z", 7) == 0 ||
	strrncmp(renderer, "-XZ", 3) == 0 ||
	strrncmp(renderer, "-Elan", 5) == 0 ||
	strrncmp(renderer, "-Extreme", 8) == 0)
      abgr = true;
  }
#endif

  // can only do hidden line if polygon offset is available
#if defined(GL_VERSION_1_1)
  canUseHiddenLine = true;
#elif defined(GL_EXT_polygon_offset)
  canUseHiddenLine = (extensions != NULL && strstr(extensions, "GL_EXT_polygon_offset") != NULL);
#endif

  // check if we're running OpenGL 1.1.  if so we'll use the fog hack
  // to fade the screen;  otherwise fall back on a full screen blended
  // polygon.
  if (version != NULL && strncmp(version, "1.1", 3) == 0)
    useFogHack = true;
/* IMPACT at 1.0 used to allow fog hack but not after patch 1935
  if (strncmp(renderer, "IMPACT", 6) == 0)
    useFogHack = true;
*/

  // prepare context with stuff that'll never change
  glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
  glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
  glGetIntegerv(GL_MAX_LIGHTS, &maxLights);
  reservedLights = 1;			// only one light between sun and moon
  maxLights -= reservedLights;		// can't use the reserved lights

  // prepare sun
  setTimeOfDay(unixEpoch);

/* FIXME
  // load flare light texture
  OpenGLGStateBuilder builder;
  builder.setTexture(getTexture("flare", OpenGLTexture::Max));
  flareGState = builder.getState();
*/

  // force nodes to update their styles
  notifyStyleChange();
}

SceneRenderer::~SceneRenderer()
{
  // free scene iterator
  delete sceneIterator;
<commit_msg>applies a fix for sf bug tracker 699227 where a null char pointer is getting dereferenced<commit_after>/* bzflag
 * Copyright (c) 1993 - 2003 <NAME>
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named COPYING that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#include "common.h"
#include "bzfgl.h"
#include "SceneRenderer.h"
#include "BackgroundRenderer.h"
#include "HUDRenderer.h"
#include "SceneDatabase.h"
#include "SceneNode.h"
#include "MainWindow.h"
#include "LocalPlayer.h"
#include "daylight.h"
#include "OpenGLGState.h"
#include "RenderNode.h"
#include "BzfWindow.h"
#include "TankSceneNode.h"
#include "StateDatabase.h"
#include "texture.h"
#include <string.h>

const GLint		SceneRenderer::SunLight = 0;	// also for the moon

#ifdef GL_ABGR_EXT
static int		strrncmp(const char* s1, const char* s2, int num)
{
  int len1 = strlen(s1) - 1;
  int len2 = strlen(s2) - 1;
  for (; len1 >= 0 && len2 >= 0 && num > 0; len1--, len2--, num--) {
    const int d = (int)s1[len1] - (int)s2[len2];
    if (d != 0) return d;
  }
  return 0;
}
#endif

//
// FlareLight
//

FlareLight::FlareLight(const float* _pos, const float* _color)
{
  pos[0] = _pos[0];
  pos[1] = _pos[1];
  pos[2] = _pos[2];
  color[0] = _color[0];
  color[1] = _color[1];
  color[2] = _color[2];
}

FlareLight::~FlareLight()
{
  // do nothing
}

//
// SceneRenderer
//

SceneRenderer*		SceneRenderer::instance = NULL;

SceneRenderer::SceneRenderer(MainWindow& _window) :
				window(_window),
				blank(false),
				invert(false),
				sunBrightness(1.0f),
				scene(NULL),
				background(NULL),
				abgr(false),
				useQualityValue(2),
				useDepthComplexityOn(false),
				useWireframeOn(false),
				useHiddenLineOn(false),
				panelOpacity(0.3f),
				radarSize(4),
				maxMotionFactor(5),
				useFogHack(false),
				viewType(Normal),
				inOrder(false),
				style(0),
				sceneIterator(NULL),
				depthRange(0),
				numDepthRanges(1),
				depthRangeSize(1.0),
				useDimming(false),
				canUseHiddenLine(false),
				exposed(true),
				lastFrame(true),
				sameFrame(false)
{
  instance = this;

  // get visual info
  window.getWindow()->makeCurrent();
  GLint bits;
  if (!BZDB->isSet("zbuffer")) {
    glGetIntegerv(GL_DEPTH_BITS, &bits);
    BZDB->set("zbuffer", (bits > 0) ? "1" : "0");
  }
  glGetIntegerv(GL_STENCIL_BITS, &bits);
  useStencilOn = (bits > 0);

  // see if abgr extention is available and system is known to be
  // faster with abgr.
  const char* vendor = (const char*)glGetString(GL_VENDOR);
  const char* renderer = (const char*)glGetString(GL_RENDERER);
  const char* version = (const char*)glGetString(GL_VERSION);
  const char* extensions = (const char*)glGetString(GL_EXTENSIONS);
  (void)vendor; (void)renderer; (void)version; (void)extensions; // silence g++
#ifdef GL_ABGR_EXT
  if ((extensions != NULL && strstr(extensions, "GL_EXT_abgr") != NULL) &&
      (vendor != NULL && strcmp(vendor, "SGI") == 0)) {
    // old hardware is faster with ABGR.  new hardware isn't.
    if ((renderer != NULL) && 
	(strncmp(renderer, "GR1", 3) == 0 ||
	 strncmp(renderer, "VGX", 3) == 0 ||
	 strncmp(renderer, "LIGHT", 5) == 0 ||
	 strrncmp(renderer, "-XS", 3) == 0 ||
	 strrncmp(renderer, "-XSM", 4) == 0 ||
	 strrncmp(renderer, "-XS24", 5) == 0 ||
	 strrncmp(renderer, "-XS24-Z", 7) == 0 ||
	 strrncmp(renderer, "-XZ", 3) == 0 ||
	 strrncmp(renderer, "-Elan", 5) == 0 ||
	 strrncmp(renderer, "-Extreme", 8) == 0))
      abgr = true;
  }
#endif

  // can only do hidden line if polygon offset is available
#if defined(GL_VERSION_1_1)
  canUseHiddenLine = true;
#elif defined(GL_EXT_polygon_offset)
  canUseHiddenLine = (extensions != NULL && strstr(extensions, "GL_EXT_polygon_offset") != NULL);
#endif

  // check if we're running OpenGL 1.1.  if so we'll use the fog hack
  // to fade the screen;  otherwise fall back on a full screen blended
  // polygon.
  if (version != NULL && strncmp(version, "1.1", 3) == 0)
    useFogHack = true;

  // prepare context with stuff that'll never change
  glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
  glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
  glGetIntegerv(GL_MAX_LIGHTS, &maxLights);
  reservedLights = 1;			// only one light between sun and moon
  maxLights -= reservedLights;		// can't use the reserved lights

  // prepare sun
  setTimeOfDay(unixEpoch);

/* FIXME
  // load flare light texture
  OpenGLGStateBuilder builder;
  builder.setTexture(getTexture("flare", OpenGLTexture::Max));
  flareGState = builder.getState();
*/

  // force nodes to update their styles
  notifyStyleChange();
}

SceneRenderer::~SceneRenderer()
{
  // free scene iterator
  delete sceneIterator;

{'fraction_non_alphanumeric': 0.14610620367550006, 'fraction_numerical': 0.02030663011473246, 'mean_word_length': 3.8956262425447314, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6860302', 'n_tokens_mistral': 3843, 'n_tokens_neox': 3550, 'n_words': 931}