<commit_before>/* bzflag
 * Copyright (c) 1993-2010 <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 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

// bzflag common header
#include "common.h"

// interface header
#include "BoltSceneNode.h"

// system headers
#include <stdlib.h>
#include <string.h>
#include <math.h>

// common headers
#include "bzfgl.h"
#include "StateDatabase.h"
#include "BZDBCache.h"
#include "SceneRenderer.h" // FIXME (SceneRenderer.cxx is in src/bzflag)
#include "TextureManager.h"

// local headers
#include "ViewFrustum.h"


BoltSceneNode::BoltSceneNode(const fvec3& pos, const fvec3& vel)
  : phasingShot(false)
  , drawFlares(false)
  , invisible(false)
  , texturing(false)
  , colorblind(false)
  , size(1.0f)
  , renderNode(this)
  , azimuth(0)
  , elevation(0)
  , length(1.0f)
{
  OpenGLGStateBuilder builder(gstate);
  builder.setBlending();
  builder.setAlphaFunc();
  //builder.setTextureEnvMode(GL_DECAL);
  gstate = builder.getState();

  // prepare light
  light.setAttenuation(0, 0.05f);
  light.setAttenuation(1, 0.0f);
  light.setAttenuation(2, 0.03f);

  // prepare geometry
  move(pos, vel);
  setSize(size);
  setColor(1.0f, 1.0f, 1.0f);
}


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


void BoltSceneNode::setFlares(bool on)
{
  drawFlares = on;
}


void BoltSceneNode::setSize(float radius)
{
  size = radius;
  setRadius(size * size);
}


void BoltSceneNode::setTextureColor(float r, float g, float b, float a)
{
  color = fvec4(r, g, b, a);
  light.setColor(1.5f * r, 1.5f * g, 1.5f * b);
  renderNode.setTextureColor(color);
}


void BoltSceneNode::setColor(float r, float g, float b, float a)
{
  color = fvec4(r, g, b, a);
  light.setColor(1.5f * r, 1.5f * g, 1.5f * b);
  renderNode.setColor(color);
}


void BoltSceneNode::setColor(const fvec4& rgba)
{
  setColor(rgba.r, rgba.g, rgba.b, rgba.a);
}


bool BoltSceneNode::getColorblind() const
{
  return colorblind;
}


void BoltSceneNode::setColorblind(bool _colorblind)
{
  colorblind = _colorblind;
}


bool BoltSceneNode::getInvisible() const
{
  return invisible;
}


void BoltSceneNode::setInvisible(bool _invisible)
{
  invisible = _invisible;
}


void BoltSceneNode::setTexture(const int texture)
{
  OpenGLGStateBuilder builder(gstate);
  builder.setTexture(texture);
  builder.enableTexture(texture>=0);
  gstate = builder.getState();
}


void BoltSceneNode::setTextureAnimation(int cu, int cv)
{
  renderNode.setAnimation(cu, cv);
}


void BoltSceneNode::move(const fvec3& pos, const fvec3& vel)
{
  setCenter(pos);
  light.setPosition(pos);

  velocity = vel;
  length = vel.length();

  azimuth   = (float)(+RAD2DEG * atan2f(vel.y, vel.x));
  elevation = (float)(-RAD2DEG * atan2f(vel.z, vel.xy().length()));
}


void BoltSceneNode::addLight(SceneRenderer& renderer)
{
  renderer.addLight(light);
}


void BoltSceneNode::notifyStyleChange()
{
  texturing = BZDBCache::texture && BZDBCache::blend;
  OpenGLGStateBuilder builder(gstate);
  builder.enableTexture(texturing);
  if (BZDBCache::blend) {
    const int shotLength = (int)(BZDBCache::shotLength * 3.0f);
    if ((shotLength > 0) || (RENDERER.useQuality() >= _EXPERIMENTAL_QUALITY)) {<commit_msg>* invisible shots do not add lights<commit_after>/* bzflag
 * Copyright (c) 1993-2010 <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 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

// bzflag common header
#include "common.h"

// interface header
#include "BoltSceneNode.h"

// system headers
#include <stdlib.h>
#include <string.h>
#include <math.h>

// common headers
#include "bzfgl.h"
#include "StateDatabase.h"
#include "BZDBCache.h"
#include "SceneRenderer.h" // FIXME (SceneRenderer.cxx is in src/bzflag)
#include "TextureManager.h"

// local headers
#include "ViewFrustum.h"


BoltSceneNode::BoltSceneNode(const fvec3& pos, const fvec3& vel)
  : phasingShot(false)
  , drawFlares(false)
  , invisible(false)
  , texturing(false)
  , colorblind(false)
  , size(1.0f)
  , renderNode(this)
  , azimuth(0)
  , elevation(0)
  , length(1.0f)
{
  OpenGLGStateBuilder builder(gstate);
  builder.setBlending();
  builder.setAlphaFunc();
  //builder.setTextureEnvMode(GL_DECAL);
  gstate = builder.getState();

  // prepare light
  light.setAttenuation(0, 0.05f);
  light.setAttenuation(1, 0.0f);
  light.setAttenuation(2, 0.03f);

  // prepare geometry
  move(pos, vel);
  setSize(size);
  setColor(1.0f, 1.0f, 1.0f);
}


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


void BoltSceneNode::setFlares(bool on)
{
  drawFlares = on;
}


void BoltSceneNode::setSize(float radius)
{
  size = radius;
  setRadius(size * size);
}


void BoltSceneNode::setTextureColor(float r, float g, float b, float a)
{
  color = fvec4(r, g, b, a);
  light.setColor(1.5f * r, 1.5f * g, 1.5f * b);
  renderNode.setTextureColor(color);
}


void BoltSceneNode::setColor(float r, float g, float b, float a)
{
  color = fvec4(r, g, b, a);
  light.setColor(1.5f * r, 1.5f * g, 1.5f * b);
  renderNode.setColor(color);
}


void BoltSceneNode::setColor(const fvec4& rgba)
{
  setColor(rgba.r, rgba.g, rgba.b, rgba.a);
}


bool BoltSceneNode::getColorblind() const
{
  return colorblind;
}


void BoltSceneNode::setColorblind(bool _colorblind)
{
  colorblind = _colorblind;
}


bool BoltSceneNode::getInvisible() const
{
  return invisible;
}


void BoltSceneNode::setInvisible(bool _invisible)
{
  invisible = _invisible;
}


void BoltSceneNode::setTexture(const int texture)
{
  OpenGLGStateBuilder builder(gstate);
  builder.setTexture(texture);
  builder.enableTexture(texture>=0);
  gstate = builder.getState();
}


void BoltSceneNode::setTextureAnimation(int cu, int cv)
{
  renderNode.setAnimation(cu, cv);
}


void BoltSceneNode::move(const fvec3& pos, const fvec3& vel)
{
  setCenter(pos);
  light.setPosition(pos);

  velocity = vel;
  length = vel.length();

  azimuth   = (float)(+RAD2DEG * atan2f(vel.y, vel.x));
  elevation = (float)(-RAD2DEG * atan2f(vel.z, vel.xy().length()));
}


void BoltSceneNode::addLight(SceneRenderer& renderer)
{
  if (!invisible) {
    renderer.addLight(light);
  }
}


void BoltSceneNode::notifyStyleChange()
{
  texturing = BZDBCache::texture && BZDBCache::blend;
  OpenGLGStateBuilder builder(gstate);
  builder.enableTexture(texturing);
  if (BZDBCache::blend) {
    const int shotLength = (int)(BZDBCache::shotLength * 3.0f);
    if ((shotLength > 0) || (RENDERER.useQuality() >= _EXPERIMENTAL_QUALITY)) {
{'fraction_non_alphanumeric': 0.13838268792710706, 'fraction_numerical': 0.01651480637813212, 'mean_word_length': 4.501174628034455, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '3805711', 'n_tokens_mistral': 2708, 'n_tokens_neox': 2587, 'n_words': 582}